10 #include "art/Framework/Core/EDAnalyzer.h"
11 #include "art/Framework/Core/ModuleMacros.h"
12 #include "art/Framework/Principal/Event.h"
13 #include "art/Framework/Principal/Handle.h"
14 #include "art/Framework/Principal/Run.h"
15 #include "art/Framework/Principal/SubRun.h"
16 #include "art_root_io/TFileService.h"
17 #include "fhiclcpp/ParameterSet.h"
18 #include "messagefacility/MessageLogger/MessageLogger.h"
45 void analyze(art::Event
const &
e)
override;
50 float&
mean,
float& rms,
float& min,
float& max,
51 int& argmin,
int& argmax);
76 std::vector<float>
_wf;
92 float&
mean,
float& std_dev,
float& min,
float& max,
93 int& argmin,
int& argmax)
96 min = std::numeric_limits<float>::max();
97 max = std::numeric_limits<float>::min();
98 for(
size_t idx=0; idx<wf.size(); ++idx)
100 auto const& v = wf[idx];
101 if(v < min) { min = v; argmin=idx; }
102 if(v > max) { max = v; argmax=idx; }
105 mean /= (float)(wf.size());
106 for(
auto const& v : wf)
107 std_dev += pow(v - mean,2);
108 std_dev = sqrt(std_dev / (
float)(wf.size()));
114 , _wire_tree(nullptr)
115 , _raw_digit_tree(nullptr)
116 , _filtered_digit_tree(nullptr)
118 _verbose = p.get<
bool> (
"Verbose",
false);
128 std::cerr <<
"\033[93m[ERROR]\033[00m waveform size will be less than 1 tick ..." << std::endl;
129 throw std::exception();
135 art::ServiceHandle<art::TFileService>
tfs;
137 TTree* tree = tfs->make<TTree>(name.c_str(),
"");
139 tree->Branch(
"run",&
_run,
"run/I");
140 tree->Branch(
"subrun",&
_subrun,
"subrun/I");
141 tree->Branch(
"event",&
_event,
"event/I");
142 tree->Branch(
"ch",&
_ch,
"ch/I");
143 tree->Branch(
"wire",&
_wire,
"wire/I");
144 tree->Branch(
"plane",&
_plane,
"plane/I");
145 tree->Branch(
"signal_id",&
_signal_id,
"signal_id/I");
146 tree->Branch(
"start_tick",&
_start_tick,
"start_tick/I");
147 tree->Branch(
"tick_offset",&
_tick_offset,
"tick_offset/I");
148 tree->Branch(
"wf",
"std::vector<float>",&
_wf);
149 tree->Branch(
"mean",&
_mean,
"mean/F");
150 tree->Branch(
"std",&
_std_dev,
"std/F");
151 tree->Branch(
"min",&
_min,
"min/F");
152 tree->Branch(
"max",&
_max,
"max/F");
153 tree->Branch(
"argmax",&
_argmax,
"argmax/I");
154 tree->Branch(
"argmin",&
_argmin,
"argmin/I");
160 art::ServiceHandle<art::TFileService>
tfs;
162 TTree* tree = tfs->make<TTree>(name.c_str(),
"");
164 tree->Branch(
"run",&
_run,
"run/I");
165 tree->Branch(
"subrun",&
_subrun,
"subrun/I");
166 tree->Branch(
"event",&
_event,
"event/I");
167 tree->Branch(
"ch",&
_ch,
"ch/I");
168 tree->Branch(
"wire",&
_wire,
"wire/I");
169 tree->Branch(
"plane",&
_plane,
"plane/I");
170 tree->Branch(
"signal_id",&
_signal_id,
"signal_id/I");
171 tree->Branch(
"peakTime",&
_peakTime,
"peakTime/F");
173 tree->Branch(
"rms",&
_rms,
"rms/F");
174 tree->Branch(
"summedADC",&
_summedADC,
"summedADC/F");
175 tree->Branch(
"integral",&
_integral,
"integral/F");
176 tree->Branch(
"chisquare",&
_chisquare,
"chisquare/F");
177 tree->Branch(
"baseline",&
_baseline,
"baseline/F");
196 art::ServiceHandle<geo::Geometry> geo;
203 for(
auto const&
hit : hit_array)
207 std::cout <<
"[IMBECILE!] Skipping truth charge deposition ID " <<
hit.signal_id <<
" @ tick " <<
hit.tick << std::endl;
219 art::Handle<std::vector<raw::RawDigit> > digit_h;
223 for(
auto const& ch :
hit.channel_list) {
225 auto const wid = geo->ChannelToWire(ch).front();
226 _wire = (int)(wid.Wire);
229 for(
auto const& digit : *digit_h) {
230 if((
int)(digit.Channel()) != ch)
continue;
232 auto const& adcs = digit.ADCs();
236 _wf.resize(end-start+1);
237 for(
size_t index=start; index<=
end; ++index)
_wf[index-start] = adcs[index];
244 <<
" ... " << adcs.size() <<
" ADC samples start @ tick=" <<
_start_tick
245 <<
" ... mean=" <<
_mean
255 if(!found)
std::cout <<
"[IMBECILE!] Could not find target channel " <<
_ch
256 <<
" or wire " <<
_wire
269 art::Handle<std::vector<raw::RawDigit> > digit_h;
273 for(
auto const& ch :
hit.channel_list) {
275 auto const wid = geo->ChannelToWire(ch).front();
279 for(
auto const& digit : *digit_h) {
280 if((
int)(digit.Channel()) != ch)
continue;
282 auto const& adcs = digit.ADCs();
285 _wf.resize(end-start+1);
287 for(
size_t index=start; index<=
end; ++index)
_wf[index-start] = adcs[index];
294 <<
" ... " << adcs.size() <<
" ADC samples start @ tick=" <<
_start_tick
295 <<
" ... mean=" <<
_mean
305 if(!found)
std::cout <<
"[IMBECILE!] Could not find target channel " <<
_ch
306 <<
" or wire " <<
_wire
319 art::Handle<std::vector<recob::Wire> > wire_h;
321 if(!wire_h.isValid())
std::cerr <<
"[IMBECILE!] Failed to fetch Wire with label " <<
_wire_producer << std::endl;
323 for(
auto const& ch :
hit.channel_list)
326 auto const wid = geo->ChannelToWire(ch).front();
330 for(
auto const& wire : *wire_h)
332 if((
int)(wire.Channel()) != ch)
continue;
334 auto const& signalROI = wire.SignalROI();
336 for(
const auto& range : signalROI.get_ranges())
339 if(signal_tick < (
int)(range.begin_index()) || signal_tick > (
int)(range.begin_index() + range.data().size()))
343 _wf.reserve(range.data().size());
344 for(
auto const& v : range.data())
_wf.push_back(v);
352 <<
" ... " << range.data().size() <<
" ADC samples start @ tick=" <<
_start_tick
353 <<
" ... mean=" <<
_mean
365 if(!found)
std::cout <<
"[IMBECILE!] Could not find target channel " <<
_ch
366 <<
" or wire " <<
_wire
377 art::Handle<std::vector<recob::Hit> > hit_h;
379 if(!hit_h.isValid())
std::cerr <<
"[IMBECILE!] Failed to fetch Wire with label " <<
_hit_producer << std::endl;
381 for(
auto const& ch :
hit.channel_list)
384 auto const wid = geo->ChannelToWire(ch).front();
389 float diffPeakTime(1000.);
391 for(
auto const& recoHit : *hit_h)
394 if((
int)(recoHit.Channel()) != ch)
continue;
397 if(signal_tick < (
int)(recoHit.PeakTime() - 3.*recoHit.RMS()) || signal_tick > (
int)(recoHit.PeakTime() + 3.*recoHit.RMS()))
continue;
399 if (
std::abs(recoHit.PeakTime() - signal_tick) < diffPeakTime)
405 _rms = recoHit.RMS();
417 if(!found)
std::cout <<
"[IMBECILE!] Could not find target channel " <<
_ch
418 <<
" or wire " <<
_wire
art::InputTag _raw_digit_producer
art::InputTag _hit_producer
static ParamHolder & get()
BEGIN_PROLOG could also be cerr
Declaration of signal hit object.
Definition of basic raw digits.
TTree * CreateTree(std::string name)
SimTestPulseAna(fhicl::ParameterSet const &p)
Access the description of detector geometry.
void compute_params(const std::vector< float > &wf, float &mean, float &rms, float &min, float &max, int &argmin, int &argmax)
SimTestPulseAna & operator=(SimTestPulseAna const &)=delete
auto end(FixedBins< T, C > const &) noexcept
TTree * CreateHitTree(std::string name)
const std::vector< alternative::TruthHit > & TruthHitArray() const
void analyze(art::Event const &e) override
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Declaration of basic channel signal object.
art::ServiceHandle< art::TFileService > tfs
art::InputTag _filtered_digit_producer
TTree * _filtered_digit_tree
art::InputTag _wire_producer
art framework interface to geometry description
BEGIN_PROLOG could also be cout