3 #include "fhiclcpp/ParameterSet.h"
4 #include "art/Utilities/ToolMacros.h"
5 #include "art/Framework/Services/Registry/ServiceHandle.h"
6 #include "art_root_io/TFileService.h"
7 #include "art/Framework/Core/ModuleMacros.h"
8 #include "art/Utilities/make_tool.h"
9 #include "art_root_io/TFileDirectory.h"
10 #include "messagefacility/MessageLogger/MessageLogger.h"
23 #include "TProfile2D.h"
25 #include "TVirtualFFT.h"
65 void configure(fhicl::ParameterSet
const & pset)
override;
73 void initializeHists(art::ServiceHandle<art::TFileService>&,
const std::string&)
override;
80 void endJob(
int numEvents)
override;
110 Waveform::const_iterator,
115 Waveform::const_iterator,
116 Waveform::const_iterator,
117 Waveform::const_iterator,
123 Waveform::const_iterator
findNearestMax(Waveform::const_iterator, Waveform::const_iterator)
const;
124 Waveform::const_iterator
findNearestMin(Waveform::const_iterator, Waveform::const_iterator)
const;
127 Waveform::const_iterator
findStartTick(Waveform::const_iterator, Waveform::const_iterator)
const;
128 Waveform::const_iterator
findStopTick(Waveform::const_iterator, Waveform::const_iterator)
const;
167 fSignalServices(*art::ServiceHandle<icarusutil::SignalShapingICARUSService>()),
168 fPedestalRetrievalAlg(*lar::
providerFrom<lariov::DetPedestalService>())
173 mf::LogInfo(
"BasicWireAnalysis") <<
"BasicWireAnalysis configured\n";
178 BasicWireAnalysis::~BasicWireAnalysis()
188 void BasicWireAnalysis::configure(fhicl::ParameterSet
const & pset)
190 fMinDeltaTicks = pset.get<std::vector<int> >(
"MinDeltaTicks", std::vector<int>() = { 0, 0, 0});
191 fMaxDeltaTicks = pset.get<std::vector<int> >(
"MaxDeltaTicks", std::vector<int>() = { 30, 30, 30});
192 fMinDeltaPeaks = pset.get<std::vector<float> >(
"MinDeltaPeaks", std::vector<float>() = {0.025, 0.025, 0.025});
198 fhicl::ParameterSet waveformToolParams;
200 waveformToolParams.put<std::string>(
"tool_type",
"WaveformTools");
202 fWaveformTool = art::make_tool<reco_tool::IWaveformTool>(waveformToolParams);
207 void BasicWireAnalysis::initializeHists(art::ServiceHandle<art::TFileService>&
tfs,
const std::string& dirName)
212 art::TFileDirectory
dir = tfs->mkdir(dirName.c_str());
229 fTruncMeanHist[plane] = dir.make<TH1D>(histName.c_str(),
";ADC", 200, -50., 50.);
233 fTruncRmsHist[plane] = dir.make<TH1D>(histName.c_str(),
";ADC", 100, 0., 20.);
237 fFullRmsHist[plane] = dir.make<TH1D>(histName.c_str(),
";ADC", 100, 0., 20.);
241 fNumTruncHist[plane] = dir.make<TH1D>(histName.c_str(),
";Truncated Fraction", 100, 0., 1.);
245 fDeltaTicksHist[plane] = dir.make<TH1D>(histName.c_str(),
";Delta", 500, 0., 500.);
249 fRangeHist[plane] = dir.make<TH1D>(histName.c_str(),
";Range", 200, 0., 200.);
261 std::vector<const recob::Wire*> wireVec;
264 for(
size_t idx = 0; idx < wirePtrVec.size(); idx++) wireVec.push_back(wirePtrVec.at(idx).get());
270 for(
const auto& wire : wireVec)
276 size_t cryo = wids[0].Cryostat;
277 size_t tpc = wids[0].TPC;
278 size_t plane = wids[0].Plane;
279 size_t wireNum = wids[0].Wire;
282 art::TFileDirectory
dir =
fHistDirectory->mkdir(Form(
"WavePlane_%1zu/c%1zu/c%1zut%1zuwire_%05zu",plane,
size_t(eventNum),cryo,tpc,wireNum));
285 bool hasSignal = channelMap.find(channel) != channelMap.end();
287 if (!hasSignal)
continue;
291 for(
const auto& range : signalROI.
get_ranges())
293 const Waveform& waveform = range.data();
301 fWaveformTool->getTruncatedMeanRMS(waveform, truncMean, fullRMS, truncRMS, nTrunc);
306 fNumTruncHist.at(plane)->Fill(
float(nTrunc)/
float(waveform.size()),1.);
319 fWaveformTool->triangleSmooth(rawDerivativeVec,derivativeVec);
323 dir.make<TProfile>(Form(
"WWfm_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Waveform", waveform.size(), 0, waveform.size(), -500., 500.);
324 TProfile* derivHist =
325 dir.make<TProfile>(Form(
"WDer_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Derivative", waveform.size(), 0, waveform.size(), -500., 500.);
326 TProfile* candHitHist =
327 dir.make<TProfile>(Form(
"WPeak_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Peaks", waveform.size(), 0, waveform.size(), -500., 500.);
328 TProfile* edgeHitHist =
329 dir.make<TProfile>(Form(
"WEdge_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Edges", waveform.size(), 0, waveform.size(), -500., 500.);
331 for(
size_t idx = 0; idx < waveform.size(); idx++)
333 waveHist->Fill(idx, waveform.at(idx), 1.);
334 derivHist->Fill(idx, derivativeVec.at(idx), 1.);
338 findHitCandidates(derivativeVec.begin(),derivativeVec.end(),0,plane,hitCandidateVec);
341 for(
auto& hitCandidate : hitCandidateVec)
343 size_t centerIdx = hitCandidate.hitCenter;
345 candHitHist->Fill(hitCandidate.maxTick, hitCandidate.maxDerivative, 1.);
346 candHitHist->Fill(hitCandidate.minTick, hitCandidate.minDerivative, 1.);
347 edgeHitHist->Fill(hitCandidate.startTick, 1.);
348 edgeHitHist->Fill(hitCandidate.stopTick, 1.);
350 hitCandidate.hitHeight = waveform.at(centerIdx);
366 dir.make<TProfile>(Form(
"WEro_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Erosion", waveform.size(), 0, waveform.size(), -500., 500.);
368 dir.make<TProfile>(Form(
"WDil_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Dilation", waveform.size(), 0, waveform.size(), -500., 500.);
370 dir.make<TProfile>(Form(
"WAve_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Average", waveform.size(), 0, waveform.size(), -500., 500.);
372 dir.make<TProfile>(Form(
"WDif_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Difference", waveform.size(), 0, waveform.size(), -500., 500.);
374 dir.make<TProfile>(Form(
"WClo_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Closing", waveform.size(), 0, waveform.size(), -500., 500.);
376 dir.make<TProfile>(Form(
"WOpe_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Opening", waveform.size(), 0, waveform.size(), -500., 500.);
378 dir.make<TProfile>(Form(
"WDOC_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Difference", waveform.size(), 0, waveform.size(), -500., 500.);
390 findHitCandidates(openingVec.begin(),openingVec.end(),differenceVec.begin(),differenceVec.end(),0,plane,hitCandidateMorphVec);
392 TProfile* candMorphHist =
393 dir.make<TProfile>(Form(
"MPeak_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Peaks", waveform.size(), 0, waveform.size(), -500., 500.);
394 TProfile* edgeMorphHist =
395 dir.make<TProfile>(Form(
"MEdge_%03zu_ctw%01zu-%01zu-%01zu-%05zu-%05zu",
size_t(eventNum),cryo,tpc,plane,wireNum,
size_t(roiStartTick)),
"Edges", waveform.size(), 0, waveform.size(), -500., 500.);
398 for(
auto& hitCandidate : hitCandidateMorphVec)
400 size_t centerIdx = hitCandidate.hitCenter;
402 candMorphHist->Fill(hitCandidate.maxTick, hitCandidate.maxDerivative, 1.);
403 candMorphHist->Fill(hitCandidate.minTick, hitCandidate.minDerivative, 1.);
404 candMorphHist->Fill(hitCandidate.hitCenter, waveform.at(hitCandidate.hitCenter), 1.);
405 edgeMorphHist->Fill(hitCandidate.startTick, 1.);
406 edgeMorphHist->Fill(hitCandidate.stopTick, 1.);
408 hitCandidate.hitHeight = waveform.at(centerIdx);
416 void BasicWireAnalysis::findHitCandidates(Waveform::const_iterator startItr,
417 Waveform::const_iterator stopItr,
426 std::pair<Waveform::const_iterator, Waveform::const_iterator> minMaxPair = std::minmax_element(startItr, stopItr);
428 Waveform::const_iterator maxItr = minMaxPair.second;
429 Waveform::const_iterator minItr = minMaxPair.first;
432 if (std::fabs(*maxItr) > std::fabs(*minItr)) minItr =
findNearestMin(maxItr, stopItr);
436 float range = *maxItr - *minItr;
448 Waveform::const_iterator newEndItr =
findStartTick(maxItr, startItr);
454 Waveform::const_iterator newStartItr =
findStopTick(minItr, stopItr);
459 if (startTick > 2)
findHitCandidates(startItr,newEndItr,roiStartTick,planeIdx,hitCandidateVec);
464 Waveform::const_iterator peakItr = std::min_element(maxItr,minItr,[](
const auto&
left,
const auto&
right){
return std::fabs(
left) < std::fabs(
right);});
470 hitCandidate.startTick = roiStartTick + startTick;
471 hitCandidate.stopTick = roiStartTick +
stopTick;
472 hitCandidate.maxTick = roiStartTick +
std::distance(startItr,maxItr);
473 hitCandidate.minTick = roiStartTick +
std::distance(startItr,minItr);
474 hitCandidate.maxDerivative = maxItr != stopItr ? *maxItr : 0.;
475 hitCandidate.minDerivative = minItr != stopItr ? *minItr : 0.;
476 hitCandidate.hitCenter = roiStartTick +
std::distance(startItr,peakItr) + 0.5;
477 hitCandidate.hitSigma = 0.5 * float(hitCandidate.minTick - hitCandidate.maxTick);
478 hitCandidate.hitHeight = hitCandidate.hitSigma * (hitCandidate.maxDerivative - hitCandidate.minDerivative) / 1.2130;
480 hitCandidateVec.push_back(hitCandidate);
483 if (std::distance(newStartItr,stopItr) > 2)
findHitCandidates(newStartItr,stopItr,roiStartTick + stopTick,planeIdx,hitCandidateVec);
489 void BasicWireAnalysis::findHitCandidates(Waveform::const_iterator eroStartItr,
490 Waveform::const_iterator eroStopItr,
491 Waveform::const_iterator diffStartItr,
492 Waveform::const_iterator diffStopItr,
499 std::pair<Waveform::const_iterator,Waveform::const_iterator> diffMinMaxPair = std::minmax_element(diffStartItr,diffStopItr);
501 float deltaDiff = *diffMinMaxPair.second - *diffMinMaxPair.first;
503 if (deltaDiff < 7)
return;
508 Waveform::const_iterator peakLeftItr = std::max_element(eroStartItr,eroStopItr);
509 Waveform::const_iterator peakRightItr = peakLeftItr;
510 Waveform::const_iterator diffLeftItr = diffStartItr;
512 std::advance(diffLeftItr,
std::distance(eroStartItr,peakLeftItr));
514 Waveform::const_iterator diffRightItr = diffLeftItr;
517 if (*diffLeftItr < *peakLeftItr)
521 while(
std::distance(eroStartItr,peakLeftItr) > 0 && *diffLeftItr - 1. < *peakLeftItr) {diffLeftItr--; peakLeftItr--;}
522 while(
std::distance(peakRightItr,eroStopItr) > 0 && *diffRightItr - 1. < *peakRightItr) {diffRightItr++; peakRightItr++;}
526 Waveform::const_iterator leftMaxItr = diffLeftItr;
527 float leftMaxVal = *leftMaxItr;
529 while(
std::distance(diffStartItr,leftMaxItr) > 0 && *(leftMaxItr - 1) >= leftMaxVal) leftMaxVal = *(--leftMaxItr);
532 Waveform::const_iterator leftRiseItr = leftMaxItr;
533 float leftRiseVal = *leftRiseItr;
535 while(
std::distance(diffStartItr,leftRiseItr) >= 0 && *(leftRiseItr - 1) < leftRiseVal) leftRiseVal = *(--leftRiseItr);
538 Waveform::const_iterator rightMaxItr = diffRightItr;
539 float rightMaxVal = *rightMaxItr;
541 while(
std::distance(rightMaxItr,diffStopItr) > 0 && *(rightMaxItr + 1) >= rightMaxVal) rightMaxVal = *(++rightMaxItr);
544 Waveform::const_iterator rightRiseItr = rightMaxItr;
545 float rightRiseVal = *rightRiseItr;
547 while(
std::distance(rightRiseItr,diffStopItr) > 0 && *(rightRiseItr + 1) < rightRiseVal) rightRiseVal = *(++rightRiseItr);
552 Waveform::const_iterator newEroStopItr = eroStartItr;
554 std::advance(newEroStopItr,
std::distance(diffStartItr,leftRiseItr));
556 findHitCandidates(eroStartItr,newEroStopItr,diffStartItr,leftRiseItr,roiStartTick,planeIdx,hitCandidateVec);
562 hitCandidate.startTick = roiStartTick +
std::distance(diffStartItr,leftRiseItr);
563 hitCandidate.stopTick = roiStartTick +
std::distance(diffStartItr,rightRiseItr);
564 hitCandidate.maxTick = roiStartTick +
std::distance(diffStartItr,leftMaxItr);
565 hitCandidate.minTick = roiStartTick +
std::distance(diffStartItr,rightMaxItr);
566 hitCandidate.maxDerivative = *leftMaxItr;
567 hitCandidate.minDerivative = *rightMaxItr;
568 hitCandidate.hitCenter = roiStartTick + (
std::distance(eroStartItr,peakLeftItr) +
std::distance(eroStartItr,peakRightItr) + 0.5)/2;
569 hitCandidate.hitSigma = 0.5 * float(hitCandidate.minTick - hitCandidate.maxTick);
570 hitCandidate.hitHeight = hitCandidate.hitSigma * (hitCandidate.maxDerivative - hitCandidate.minDerivative) / 1.2130;
572 hitCandidateVec.push_back(hitCandidate);
575 if (std::distance(rightRiseItr,diffStopItr) > 4)
577 Waveform::const_iterator newEroStartItr = eroStartItr;
580 std::advance(newEroStartItr, newStartTick);
582 findHitCandidates(newEroStartItr,eroStopItr,rightRiseItr,diffStopItr,roiStartTick + newStartTick,planeIdx,hitCandidateVec);
589 void BasicWireAnalysis::endJob(
int numEvents)
597 BasicWireAnalysis::Waveform::const_iterator BasicWireAnalysis::findNearestMin(Waveform::const_iterator maxItr, Waveform::const_iterator stopItr)
const
600 Waveform::const_iterator lastItr = maxItr;
603 while((lastItr + 1) != stopItr)
605 if (*(lastItr + 1) > *lastItr)
break;
614 BasicWireAnalysis::Waveform::const_iterator BasicWireAnalysis::findNearestMax(Waveform::const_iterator minItr, Waveform::const_iterator startItr)
const
617 Waveform::const_iterator lastItr = minItr;
623 while((lastItr - 1) != startItr)
625 if (*(lastItr - 1) < *lastItr)
break;
634 BasicWireAnalysis::Waveform::const_iterator BasicWireAnalysis::findStartTick(Waveform::const_iterator maxItr, Waveform::const_iterator startItr)
const
636 Waveform::const_iterator lastItr = maxItr;
646 Waveform::const_iterator loopItr = lastItr - 1;
648 while(loopItr != startItr)
651 if (*loopItr < 0. || !(*loopItr < *lastItr))
break;
656 else lastItr = startItr;
661 BasicWireAnalysis::Waveform::const_iterator BasicWireAnalysis::findStopTick(Waveform::const_iterator minItr, Waveform::const_iterator stopItr)
const
663 Waveform::const_iterator lastItr = minItr;
669 Waveform::const_iterator loopItr = lastItr + 1;
671 while(loopItr != stopItr)
674 if (*loopItr > 0. || !(*loopItr > *lastItr))
break;
Utilities related to art service access.
BasicWireAnalysis(fhicl::ParameterSet const &pset)
Constructor.
std::vector< HitCandidate_t > HitCandidateVec
T::provider_type const * providerFrom()
Returns a constant pointer to the provider of specified service.
std::vector< float > Waveform
std::vector< int > fMaxDeltaTicks
std::vector< TH1D * > fNumTruncHist
std::vector< TH1D * > fRangeHist
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
const range_list_t & get_ranges() const
Returns the internal list of non-void ranges.
Waveform::const_iterator findNearestMax(Waveform::const_iterator, Waveform::const_iterator) const
void configure(fhicl::ParameterSet const &pset) override
icarusutil::SignalShapingICARUSService & fSignalServices
The signal shaping service.
int TDCtick_t
Type representing a TDC tick.
void initializeHists(art::ServiceHandle< art::TFileService > &, const std::string &) override
Interface for initializing the histograms to be filled.
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
std::vector< int > fMinDeltaTicks
std::vector< TH1D * > fFullRmsHist
double distance(geo::Point_t const &point, CathodeDesc_t const &cathode)
Returns the distance of a point from the cathode.
raw::ChannelID_t Channel() const
Returns the ID of the channel (or InvalidChannelID)
~BasicWireAnalysis()
Destructor.
std::unique_ptr< reco_tool::IWaveformTool > fWaveformTool
const lariov::DetPedestalProvider & fPedestalRetrievalAlg
Keep track of an instance to the pedestal retrieval alg.
size_t fNumInterveningTicks
Description of geometry of one entire detector.
void endJob(int numEvents) override
Interface for method to executve at the end of run processing.
Waveform::const_iterator findNearestMin(Waveform::const_iterator, Waveform::const_iterator) const
art::TFileDirectory * fHistDirectory
std::vector< float > fMinDeltaPeaks
struct HitCandidate{size_t startTick HitCandidate_t
Waveform::const_iterator findStopTick(Waveform::const_iterator, Waveform::const_iterator) const
std::string to_string(WindowPattern const &pattern)
std::vector< TH1D * > fTruncMeanHist
void fillHistograms(const IWireHistogramTool::WirePtrVec &, const IWireHistogramTool::SimChannelMap &, int) const override
Interface for filling histograms.
Class holding the regions of interest of signal from a channel.
const geo::GeometryCore & fGeometry
pointer to Geometry service
art::ServiceHandle< art::TFileService > tfs
std::vector< TH1D * > fDeltaTicksHist
void findHitCandidates(Waveform::const_iterator, Waveform::const_iterator, size_t, size_t, HitCandidateVec &) const
unsigned int ChannelID_t
Type representing the ID of a readout channel.
art framework interface to geometry description
Waveform::const_iterator findStartTick(Waveform::const_iterator, Waveform::const_iterator) const
std::vector< TH1D * > fTruncRmsHist