22 #include "canvas/Persistency/Common/FindOneP.h" 24 #include "art_root_io/TFileService.h" 39 #include <boost/format.hpp> 107 int last_hitend,
int this_hitstart );
110 int last_hitend,
int this_hitstart,
float pedestal );
113 const std::vector<float> &wire,
118 int pstart,
int pend,
float pedestal );
120 template<
typename Iterator >
122 unsigned eve,
unsigned chan,
unsigned hit,
123 int roi_start,
float ped,
127 unsigned evid,
unsigned chid,
unsigned hitid ){
129 fmt % roi_type; fmt % evid; fmt % chid; fmt %
hitid;
163 fDump(
p.get<
int >(
"Dump") )
170 const string myname =
"test::HitNormCheck::analyze: ";
179 cout<<myname<<
"The event contains "<<
Hits->
size() <<
" hits\n";
197 auto wireIt = Wires->begin();
200 std::vector< hitinfo_t > hitInfoVec;
203 for(
size_t hitIter = 0; hitIter <
Hits->
size(); hitIter++ ){
208 cout<<myname<<
"Hit "<<hitIter<<*
hit;
215 hInfo.
hitid = hitIter;
225 cout<<myname<<
"Process multi hit group"<<
endl;
232 cerr<<myname<<
"Hit index is wrong: "<<multiHit->
LocalIndex() <<
" != "<<hitIdx <<
endl;
245 cout<<myname<<
"This should not happen"<<
endl;
251 auto wire = HitToWires.at(hitIter);
254 auto signal = wire->Signal();
256 if( wire_start < 0 ) wire_start = 0;
258 if( wire_end > (
int)signal.size() ) wire_end = (
int)signal.size() - 1;
259 hInfo.
adcsumpad = std::accumulate( signal.begin() + wire_start,
260 signal.begin() + wire_end, 0. );
267 if( wireChannel != hit->
Channel() ){
268 cerr<<myname<<
"ERROR mismatch in hit and wire channel"<<
endl;
273 for( ;wireIt != Wires->end(); ++wireIt )
275 if( wireIt->Channel() == wireChannel ){
281 if (wireIt == Wires->end()){
282 cerr<<myname<<
"Could not find recob::Wire for channel for the hit"<<wireChannel<<
endl;
286 auto digit = WireToDigits.at(
std::distance(Wires->begin(), wireIt) );
287 if( digit->Channel() != wireChannel ) {
288 cout<<myname<<
"There is a channel mismatch with the RawDigit "<<wireChannel
289 <<
" "<<digit->Channel()<<
endl;
294 cerr<<myname<<
"ERROR: compression flag is set on raw data"<<
endl;
299 auto adc = digit->ADCs();
302 if( curChannel != wireChannel ){
303 curChannel = wireChannel;
317 cout<<myname<<
"Could not calculate pedestal for the hit group "<<
endl;
322 cout<<myname<<
"Pedestal for this hit group in channel " 323 <<curChannel<<
" : "<<hInfo.
rawped<<
" ADC"<<
endl;
328 if( pend > (
int)digit->NADC() ) {
330 cout<<myname<<
"Skipping hit group at the end of the readout window"<<
endl;
338 cout<<myname<<
"Raw pulse sum "<<
fRawSum <<
" ADC"<<
endl;
341 if( dumped <
fDump ){
348 signal.begin() + pstart,
349 signal.begin() + hit->
EndTick() );
354 adc.begin() + pstart,
355 adc.begin() + pend );
360 hitInfoVec.push_back( hInfo );
372 for(
auto it = hitInfoVec.begin(); it!=hitInfoVec.end(); ++it )
374 auto nx = std::next( it, 1 );
377 if( nx != hitInfoVec.end() )
379 if( it->chan == nx->chan ){
380 dt = nx->start - it->start;
385 cout<<myname<<
"Skip hits that are separated "<<dt<<
" ticks"<<
endl;
391 if( it->rawped < 0 ) {
416 cout<<myname<<
"Processed "<<
Hits->
size()<<
" hits and skipped "<<iSkip<<
endl;
424 fTree = tfs->make<TTree>(
"hitCheck",
"Check hit charge");
447 int last_hitend,
int this_hitstart )
449 int istart = last_hitend;
453 int delta = this_hitstart - istart;
458 return TMath::Mean( digi.begin() + pedstart, digi.begin() + this_hitstart );
463 int last_hitend,
int this_hitstart )
465 int istart = last_hitend;
469 int delta = this_hitstart - istart;
474 return TMath::RMS( digi.begin() + pedstart, digi.begin() + this_hitstart );
479 int last_hitend,
int this_hitstart,
float pedestal )
481 int istart = last_hitend;
485 int delta = this_hitstart - istart;
494 float sum = std::accumulate(digi.begin() + pedstart, digi.begin() + pedend, 0.);
495 int nsa = pedend - pedstart;
496 sum -= (pedestal * nsa);
503 const std::vector<float> &wire,
507 const string myname =
"test::HitNormCheck::PedestalProperties: ";
512 if( wire.size() != digi.size() ){
513 cerr<<myname<<
"size mismatch"<<
endl;
518 for(
int i = this_hitstart; i>=0; --i)
525 if( pedend < 0 )
return;
528 if( (this_hitstart - pedend) >
fMaxPadRoi )
return;
531 for(
int i= pedend; i>=0; --i )
533 if( wire[i] != 0 )
break;
537 if( pedstart < 0 )
return;
541 hinfo.
rawped = TMath::Mean( digi.begin() + pedstart, digi.begin() + pedend );
542 hinfo.
rawpedrms = TMath::RMS( digi.begin() + pedstart, digi.begin() + pedend );
545 float sum = std::accumulate(digi.begin() + pedstart, digi.begin() + pedstart +
fPadRawRight, 0.);
557 int pstart,
int pend,
float pedestal )
560 float sum = std::accumulate(digi.begin() + pstart, digi.begin() + pend, 0.);
561 int nsa = pend - pstart;
562 sum -= (pedestal * nsa);
567 template<
typename Iterator >
569 unsigned eve,
unsigned chan,
unsigned hit,
570 int roi_start,
float ped,
577 TH1F *
h = fs->make<TH1F>( hname.c_str(), hname.c_str(),
nbins,
578 roi_start, roi_start +
nbins );
579 h->GetXaxis()->SetTitle(
"ticks");
582 for(
auto it = begin; it !=
end; ++it ){
583 h->SetBinContent( ibin, *it - ped );
short int LocalIndex() const
How well do we believe we know this hit?
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
void analyze(art::Event const &e) override
HitNormCheck & operator=(HitNormCheck const &)=delete
struct test::HitNormCheck::hitinfo_t hitinfo_t
float Pedestal(const raw::RawDigit::ADCvector_t &digi, int last_hitend, int this_hitstart)
static bool format(QChar::Decomposition tag, QString &str, int index, int len)
static constexpr double fs
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
std::string fHitModuleLabel
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
void PedestalProperties(const raw::RawDigit::ADCvector_t &digi, const std::vector< float > &wire, int this_hitstart, hitinfo_t &hinfo)
EDAnalyzer(fhicl::ParameterSet const &pset)
float PulseSumNoSignal(const raw::RawDigit::ADCvector_t &digi, int last_hitend, int this_hitstart, float pedestal)
short int Multiplicity() const
How many hits could this one be shared with.
float PeakAmplitude() const
The estimated amplitude of the hit at its peak, in ADC units.
std::string fWireModuleLabel
constexpr ChannelID_t InvalidChannelID
ID of an invalid channel.
HitNormCheck(fhicl::ParameterSet const &p)
#define DEFINE_ART_MODULE(klass)
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
string makeHistoName(const std::string roi_type, unsigned evid, unsigned chid, unsigned hitid)
float PulseSum(const raw::RawDigit::ADCvector_t &digi, int pstart, int pend, float pedestal)
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
raw::TDCtick_t StartTick() const
Initial tdc tick for hit.
Detector simulation of raw signals on wires.
void DumpRoi(const std::string roi_type, unsigned eve, unsigned chan, unsigned hit, int roi_start, float ped, Iterator begin, Iterator end)
raw::TDCtick_t EndTick() const
Final tdc tick for hit.
art::PtrVector< recob::Hit > Hits
Declaration of signal hit object.
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
EventNumber_t event() const
float PedestalRMS(const raw::RawDigit::ADCvector_t &digi, int last_hitend, int this_hitstart)
Declaration of basic channel signal object.
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
unsigned int ChannelID_t
Type representing the ID of a readout channel.
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
QTextStream & endl(QTextStream &s)