Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
duneopdet
duneopdet
OpticalDetector
AverageWaveform_module.cc
Go to the documentation of this file.
1
//==========================================================
2
// AverageWaveform_module.cc
3
// This module finds the average waveform on each channel.
4
//
5
// Alex Himmel, ahimmel@fnal.gov
6
// Based on OpDigiAna_module.cc
7
//==========================================================
8
9
#ifndef AVERAGEWAVEFORM_H
10
#define AVERAGEWAVEFORM_H 1
11
12
// Framework includes
13
14
#include "
art/Framework/Core/EDAnalyzer.h
"
15
#include "
art/Framework/Core/ModuleMacros.h
"
16
#include "
art/Framework/Principal/Event.h
"
17
#include "
art/Framework/Principal/Handle.h
"
18
#include "
art/Framework/Services/Registry/ServiceHandle.h
"
19
#include "art_root_io/TFileService.h"
20
#include "art_root_io/TFileDirectory.h"
21
#include "
canvas/Persistency/Common/Ptr.h
"
22
#include "
fhiclcpp/ParameterSet.h
"
23
#include "
messagefacility/MessageLogger/MessageLogger.h
"
24
25
// LArSoft includes
26
27
#include "
larcore/CoreUtils/ServiceUtil.h
"
28
#include "
lardata/DetectorInfoServices/DetectorClocksService.h
"
29
#include "
lardataobj/RawData/OpDetWaveform.h
"
30
31
// ROOT includes
32
33
#include "TH1.h"
34
35
// C++ includes
36
37
#include <vector>
38
#include <map>
39
#include <cstring>
40
41
namespace
opdet
{
42
43
class
AverageWaveform
:
public
art::EDAnalyzer
{
44
45
public
:
46
47
// Standard constructor and destructor for an ART module
48
AverageWaveform
(
fhicl::ParameterSet
const
&);
49
virtual
~AverageWaveform
();
50
51
// The analyzer routine, called once per event
52
void
analyze
(
art::Event
const
&)
override
;
53
54
private
:
55
void
beginJob
()
override
;
56
void
endJob
()
override
;
57
58
// Parameters we'll read from the fcl-file
59
std::string
fInputModule
;
// Module used to create OpDetWaveforms
60
std::string
fInstanceName
;
// Input tag for OpDetWaveforms collection
61
double
fSampleFreq
;
// Sampling frequency in MHz
62
double
fTimeBegin
;
// Beginning of sample in us
63
int
fBaselineSubtract
;
// Baseline to subtract from each waveform
64
int
fNticks
;
65
66
// Map to store how many waveforms are on one optical channel
67
std::map< int, TH1D* >
averageWaveforms
;
68
std::map< int, int >
waveformCount
;
69
TH1D*
averageWaveformAll
;
70
int
eventCount
;
71
72
73
};
74
75
}
76
77
#endif
78
79
namespace
opdet
{
80
81
DEFINE_ART_MODULE
(
AverageWaveform
)
82
83
}
84
85
namespace
opdet
{
86
87
//---------------------------------------------------------------------------
88
// Constructor
89
AverageWaveform::AverageWaveform
(
fhicl::ParameterSet
const
& pset)
90
:
EDAnalyzer
(pset)
91
,
fInputModule
{ pset.
get
<
std::string
>(
"InputModule"
) }
92
,
fInstanceName
{ pset.get<
std::string
>(
"InstanceName"
) }
93
,
fTimeBegin
{ 0 }
94
,
fBaselineSubtract
{ pset.get<
int
>(
"BaselineSubtract"
, 0) }
95
,
fNticks
{ pset.get<
int
>(
"Nticks"
, 0) }
96
,
averageWaveformAll
{ NULL }
97
,
eventCount
{ 0 }
98
{
99
100
// Obtain parameters from TimeService
101
auto
const
clockData =
art::ServiceHandle<detinfo::DetectorClocksService const>
()->DataForJob();
102
fSampleFreq
= clockData.OpticalClock().Frequency();
103
104
// Assume starting at 0
105
fTimeBegin
= 0;
106
107
}
108
109
//---------------------------------------------------------------------------
110
// Destructor
111
AverageWaveform::~AverageWaveform
()
112
{
113
}
114
115
116
//---------------------------------------------------------------------------
117
void
AverageWaveform::beginJob
()
118
{
119
}
120
121
//---------------------------------------------------------------------------
122
void
AverageWaveform::endJob
()
123
{
124
double
waveformCountAll = 0;
125
for
(
auto
iter =
averageWaveforms
.begin(); iter !=
averageWaveforms
.end(); iter++)
126
{
127
waveformCountAll +=
waveformCount
[iter->first];
128
mf::LogInfo
(
"AverageWaveform"
) <<
"Scaling down channel "
<< iter->first <<
" by 1./"
<<
waveformCount
[iter->first] <<
std::endl
;
129
iter->second->Scale(1./
waveformCount
[iter->first]);
130
}
131
mf::LogInfo
(
"AverageWaveform"
) <<
"Scaling down all channels by 1./"
<<
eventCount
<<
std::endl
;
132
averageWaveformAll
->Scale(1./
eventCount
);
133
}
134
135
136
//---------------------------------------------------------------------------
137
void
AverageWaveform::analyze
(
art::Event
const
&
evt
)
138
{
139
140
// Get OpDetWaveforms from the event
141
art::InputTag
itag1(
fInputModule
,
fInstanceName
);
142
auto
waveformHandle = evt.
getHandle
< std::vector< raw::OpDetWaveform > >(itag1);
143
144
// Access ART's TFileService, which will handle creating and writing
145
// histograms for us
146
art::ServiceHandle< art::TFileService >
tfs;
147
148
for
(
size_t
i = 0; i < waveformHandle->size(); i++)
149
{
150
151
152
// This was probably required to overcome the "const" problem
153
// with OpDetPulse::Waveform()
154
art::Ptr< raw::OpDetWaveform >
waveformPtr(waveformHandle, i);
155
raw::OpDetWaveform
pulse = *waveformPtr;
156
int
channel
= pulse.
ChannelNumber
();
157
158
if
(
fNticks
== 0)
fNticks
= pulse.size();
159
160
161
// Create the TH1 if it doesn't exist
162
auto
waveform =
averageWaveforms
.find( channel );
163
if
( waveform ==
averageWaveforms
.end() ) {
164
TString histName =
TString::Format
(
"avgwaveform_channel_%03i"
, channel);
165
averageWaveforms
[
channel
] = tfs->make< TH1D >(histName,
";t (us);"
,
fNticks
, 0,
float
(fNticks+1) /
fSampleFreq
);
166
}
167
if
(!
averageWaveformAll
) {
168
averageWaveformAll
= tfs->make< TH1D >(
"avgwaveform_channel_all"
,
";t (us);"
,
fNticks
, 0,
float
(fNticks+1) /
fSampleFreq
);
169
}
170
171
// Add this waveform to this histogram
172
for
(
size_t
tick
= 0;
tick
< pulse.size();
tick
++) {
173
averageWaveforms
[
channel
]->Fill(
double
(
tick
)/
fSampleFreq
, pulse[
tick
] -
fBaselineSubtract
);
174
averageWaveformAll
->Fill(
double
(
tick
)/
fSampleFreq
, pulse[
tick
] -
fBaselineSubtract
);
175
}
176
177
// Count number of waveforms on each channel
178
waveformCount
[
channel
]++;
179
}
180
eventCount
++;
181
182
}
183
184
}
art::ServiceHandle
Definition:
ServiceHandle.h:37
VLN::Format
Format
Definition:
utils.h:7
opdet::AverageWaveform::analyze
void analyze(art::Event const &) override
Definition:
AverageWaveform_module.cc:137
opdet
Definition:
AverageWaveform_module.cc:41
raw::OpDetWaveform::ChannelNumber
Channel_t ChannelNumber() const
Definition:
OpDetWaveform.h:65
Handle.h
raw::OpDetWaveform
Definition:
OpDetWaveform.h:25
opdet::AverageWaveform::fNticks
int fNticks
Definition:
AverageWaveform_module.cc:64
reco_momentum_tuples.float
float
Definition:
reco_momentum_tuples.py:12
art::DataViewImpl::getHandle
Handle< PROD > getHandle(SelectorBase const &) const
Definition:
DataViewImpl.h:382
string
std::string string
Definition:
nybbler.cc:12
mf::LogInfo
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Definition:
MessageLogger.h:209
opdet::AverageWaveform::waveformCount
std::map< int, int > waveformCount
Definition:
AverageWaveform_module.cc:68
opdet::AverageWaveform::fInputModule
std::string fInputModule
Definition:
AverageWaveform_module.cc:59
opdet::AverageWaveform::averageWaveforms
std::map< int, TH1D * > averageWaveforms
Definition:
AverageWaveform_module.cc:67
opdet::AverageWaveform
Definition:
AverageWaveform_module.cc:43
opdet::AverageWaveform::AverageWaveform
AverageWaveform(fhicl::ParameterSet const &)
Definition:
AverageWaveform_module.cc:89
channel
uint8_t channel
Definition:
CRTFragment.hh:201
art::EDAnalyzer::EDAnalyzer
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition:
EDAnalyzer.h:25
opdet::AverageWaveform::fInstanceName
std::string fInstanceName
Definition:
AverageWaveform_module.cc:60
MessageLogger.h
ParameterSet.h
ServiceHandle.h
opdet::AverageWaveform::averageWaveformAll
TH1D * averageWaveformAll
Definition:
AverageWaveform_module.cc:69
opdet::AverageWaveform::fSampleFreq
double fSampleFreq
Definition:
AverageWaveform_module.cc:61
DEFINE_ART_MODULE
#define DEFINE_ART_MODULE(klass)
Definition:
ModuleMacros.h:67
opdet::AverageWaveform::beginJob
void beginJob() override
Definition:
AverageWaveform_module.cc:117
opdet::AverageWaveform::~AverageWaveform
virtual ~AverageWaveform()
Definition:
AverageWaveform_module.cc:111
opdet::AverageWaveform::fTimeBegin
double fTimeBegin
Definition:
AverageWaveform_module.cc:62
fhicl::ParameterSet::get
T get(std::string const &key) const
Definition:
ParameterSet.h:271
art::InputTag
Definition:
InputTag.h:12
Ptr.h
opdet::AverageWaveform::eventCount
int eventCount
Definition:
AverageWaveform_module.cc:70
util::quantities::tick
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition:
electronics.h:75
ServiceUtil.h
EDAnalyzer.h
ModuleMacros.h
art::Event
Definition:
Event.h:22
OpDetWaveform.h
art::EDAnalyzer
Definition:
EDAnalyzer.h:20
DetectorClocksService.h
tca::evt
TCEvent evt
Definition:
DataStructs.cxx:7
Event.h
opdet::AverageWaveform::endJob
void endJob() override
Definition:
AverageWaveform_module.cc:122
art::Ptr
Definition:
fwd.h:31
opdet::AverageWaveform::fBaselineSubtract
int fBaselineSubtract
Definition:
AverageWaveform_module.cc:63
endl
QTextStream & endl(QTextStream &s)
Definition:
qtextstream.cpp:2030
fhicl::ParameterSet
Definition:
ParameterSet.h:36
Generated by
1.8.11