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_root_io/TFileDirectory.h"
9 #include "messagefacility/MessageLogger/MessageLogger.h"
11 #include "canvas/Persistency/Common/FindManyP.h"
12 #include "canvas/Persistency/Common/FindOneP.h"
28 #include <Eigen/Dense>
33 #include "TProfile2D.h"
60 using HitPtrVec = std::vector<art::Ptr<recob::Hit>>;
72 tree->Branch(
"Cryostat",
"std::vector<int>", &
fCryostatVec);
73 tree->Branch(
"TPC",
"std::vector<int>", &
fTPCVec);
75 tree->Branch(
"Tick",
"std::vector<int>", &
fTicksVec);
76 tree->Branch(
"NDF",
"std::vector<int>", &
fNDFHitVec);
82 tree->Branch(
"PulseHeight",
"std::vector<float>", &
fPHHitVec);
83 tree->Branch(
"RMS",
"std::vector<float>", &
fRMSHitVec);
161 tree->Branch(
"SPTPC",
"std::vector<int>", &
fSPTPCVec);
162 tree->Branch(
"SPQuality",
"std::vector<float>", &
fSPQualityVec);
165 tree->Branch(
"SmallestPH",
"std::vector<float>", &
fSmallestPHVec);
166 tree->Branch(
"LargestPH",
"std::vector<float>", &
fLargestPHVec);
167 tree->Branch(
"AveragePH",
"std::vector<float>", &
fAveragePHVec);
171 tree->Branch(
"SP_x",
"std::vector<float>", &
fSP_x);
172 tree->Branch(
"SP_y",
"std::vector<float>", &
fSP_y);
173 tree->Branch(
"SP_z",
"std::vector<float>", &
fSP_z);
175 tree->Branch(
"Num2DHits",
"std::vector<int>", &
fNum2DHitsVec);
180 tree->Branch(
"HitDeltaT10",
"std::vector<float>", &
fHitDelta10Vec);
181 tree->Branch(
"HitSigmaT10",
"std::vector<float>", &
fHitSigma10Vec);
182 tree->Branch(
"HitDeltaT21",
"std::vector<float>", &
fHitDelta21Vec);
183 tree->Branch(
"HitSigmaT21",
"std::vector<float>", &
fHitSigma21Vec);
184 tree->Branch(
"HitDeltaT20",
"std::vector<float>", &
fHitDelta20Vec);
185 tree->Branch(
"HitSigmaT20",
"std::vector<float>", &
fHitSigma20Vec);
280 void configure(fhicl::ParameterSet
const & pset)
override;
288 void initializeHists(art::ServiceHandle<art::TFileService>&,
const std::string&)
override;
302 void endJob(
int numEvents)
override;
353 fGeometry = lar::providerFrom<geo::Geometry>();
358 mf::LogInfo(
"SpacePointAnalysis") <<
"SpacePointAnalysis configured\n";
363 SpacePointAnalysis::~SpacePointAnalysis()
373 void SpacePointAnalysis::configure(fhicl::ParameterSet
const & pset)
375 fSpacePointLabelVec = pset.get< std::vector<art::InputTag>>(
"SpacePointLabelVec", {
"cluster3d"});
383 void SpacePointAnalysis::initializeHists(art::ServiceHandle<art::TFileService>&
tfs,
const std::string& dirName)
391 void SpacePointAnalysis::initializeTuple(TTree* tree)
395 art::ServiceHandle<art::TFileService>
tfs;
399 fTree->Branch(
"CryostataVec",
"std::vector<int>", &
fCryoVec);
404 TTree* locTree = tfs->makeAndRegister<TTree>(
"SpacePoint_t",
"SpacePoint Tuple");
423 void SpacePointAnalysis::clear()
const
436 void SpacePointAnalysis::fillHistograms(
const art::Event& event)
const
443 mf::LogDebug(
"SpacePointAnalysis") <<
"+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
446 auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
457 void SpacePointAnalysis::processSpacePoints(
const art::Event& event,
466 auto const det_prop = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
487 using Triplet = std::tuple<const recob::Hit*, const recob::Hit*, const recob::Hit*>;
488 using TripletMap = std::map<Triplet, std::vector<const recob::SpacePoint*>>;
490 TripletMap tripletMap;
493 auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
498 art::Handle<std::vector<recob::PFParticle>> pfParticleHandle;
499 event.getByLabel(collectionLabel, pfParticleHandle);
501 if (!pfParticleHandle.isValid())
continue;
503 art::Handle< std::vector<recob::SpacePoint>> spacePointHandle;
504 event.getByLabel(collectionLabel, spacePointHandle);
506 if (!spacePointHandle.isValid())
continue;
509 art::FindManyP<recob::SpacePoint> pfPartSpacePointAssns(pfParticleHandle, event, collectionLabel);
512 art::FindManyP<recob::Hit> spHitAssnVec(spacePointHandle, event, collectionLabel);
515 using PFParticleToNumSPMap = std::map<const recob::PFParticle*,int>;
517 PFParticleToNumSPMap pfParticleToNumSPMap;
519 for(
size_t idx = 0; idx < pfParticleHandle->size(); idx++)
521 art::Ptr<recob::PFParticle> pfParticle(pfParticleHandle,idx);
523 std::vector<art::Ptr<recob::SpacePoint>> spacePointVec(pfPartSpacePointAssns.at(pfParticle.key()));
525 pfParticleToNumSPMap[pfParticle.get()] = spacePointVec.size();
531 art::FindManyP<recob::PFParticle> spacePointPFPartAssns(spacePointHandle, event, collectionLabel);
533 std::unordered_map<const recob::Hit*,int> uniqueHitMap;
537 for(
size_t idx = 0; idx < spacePointHandle->size(); idx++)
540 art::Ptr<recob::SpacePoint> spacePointPtr(spacePointHandle,idx);
542 std::vector<art::Ptr<recob::Hit>> associatedHits(spHitAssnVec.at(spacePointPtr.key()));
544 if (associatedHits.size() < 2)
546 mf::LogDebug(
"SpacePointAnalysis") <<
"I am certain this cannot happen... but here you go, space point with " << associatedHits.size() <<
" hits" << std::endl;
551 int nSpacePointsInPFParticle(0);
553 std::vector<art::Ptr<recob::PFParticle>> pfParticleVec(spacePointPFPartAssns.at(spacePointPtr.key()));
555 if (pfParticleVec.size() == 1) nSpacePointsInPFParticle = pfParticleToNumSPMap.at(pfParticleVec[0].get());
557 mf::LogDebug(
"SpacePointAnalysis") <<
"==> pfPartVec size: " << pfParticleVec.size() <<
", # space points: " << nSpacePointsInPFParticle << std::endl;
560 float spQuality = spacePointPtr->Chisq();
561 float spCharge = spacePointPtr->ErrXYZ()[1];
562 float spAsymmetry = spacePointPtr->ErrXYZ()[3];
563 const Double32_t* spPosition = spacePointPtr->XYZ();
564 float smallestPH = std::numeric_limits<float>::max();
565 float largestPH = 0.;
567 float averagePH = 0.;
568 float averagePT = 0.;
569 float largestDelT = 0.;
570 float smallestDelT = 100000.;
571 std::vector<float> hitPeakTimeVec = {-10000.,-20000.,-30000.};
572 std::vector<float> hitPeakRMSVec = {1000.,1000.,1000.};
573 int hitMultProduct = 1;
575 int numIntersections(0);
579 std::vector<const recob::Hit*> recobHitVec(3,
nullptr);
581 std::vector<float> peakAmpVec;
584 for(
const auto& hitPtr : associatedHits)
586 float peakAmplitude = hitPtr->PeakAmplitude();
587 float peakTime = hitPtr->PeakTime();
588 float rms = hitPtr->RMS();
589 int plane = hitPtr->WireID().Plane;
591 peakAmpVec.emplace_back(peakAmplitude);
594 uniqueHitMap[hitPtr.get()] = nSpacePointsInPFParticle;
596 recobHitVec[plane] = hitPtr.get();
598 averagePH += peakAmplitude;
599 smallestPH = std::min(peakAmplitude,smallestPH);
600 largestPH = std::max(peakAmplitude,largestPH);
602 hitMultProduct *= hitPtr->Multiplicity();
604 if (hitPtr->DegreesOfFreedom() < 2) numLongHits++;
607 hitPeakRMSVec[plane] = rms;
608 averagePT += hitPeakTimeVec[plane];
610 cryostat = hitPtr->WireID().Cryostat;
611 tpc = hitPtr->WireID().TPC;
614 Triplet hitTriplet(recobHitVec[0],recobHitVec[1],recobHitVec[2]);
616 tripletMap[hitTriplet].emplace_back(spacePointPtr.get());
618 averagePH /= float(numHits);
619 averagePT /= float(numHits);
621 for(
size_t planeIdx = 0; planeIdx < 3; planeIdx++)
624 if (hitPeakTimeVec[planeIdx] < 0)
continue;
626 float delT = hitPeakTimeVec[planeIdx] - averagePT;
660 for(
const auto& hitItr : uniqueHitMap)
667 int startTick = std::max( 0,
int(std::floor(peakTime - 3. * rms)));
668 int endTick = std::min(4096,
int(std::ceil( peakTime + 3. * rms)));
675 std::vector<int> numSpacePointVec = {0,0,0,0,0};
676 for(
const auto& tripletPair : tripletMap)
678 int numSpacePoints = std::min(numSpacePointVec.size()-1,tripletPair.second.size());
679 numSpacePointVec[numSpacePoints]++;
681 std::cout <<
"====>> Found " << tripletMap.size() <<
" SpacePoints, numbers: ";
690 void SpacePointAnalysis::endJob(
int numEvents)
short int LocalIndex() const
How well do we believe we know this hit?
std::vector< float > fHitSigma20Vec
std::vector< int > fClusterNSPVec
std::vector< float > fSPAsymmetryVec
art::InputTag fBadChannelProducerLabel
std::vector< int > fPlaneVec
Utilities related to art service access.
std::vector< float > fHitDelta21Vec
std::vector< int > fTicksTotHitVec
std::map< int, ViewHitMap > TrackViewHitMap
std::vector< float > fChiSquareHitVec
std::vector< float > fHitDelta10Vec
std::vector< float > fHitSigma10Vec
std::vector< int > fNDFHitVec
std::vector< int > fCryostatVec
std::vector< float > fSmallestDelTVec
std::vector< float > fSummedADCHitVec
std::vector< float > fHitSigma21Vec
geo::WireID WireID() const
float RMS() const
RMS of the hit shape, in tick units.
Declaration of signal hit object.
std::vector< float > fPHHitVec
The data type to uniquely identify a Plane.
void fillHitInfo(const recob::Hit *hit, int hitWidth, int clusterSize)
int DegreesOfFreedom() const
void initializeHists(art::ServiceHandle< art::TFileService > &, const std::string &) override
Interface for initializing the histograms to be filled.
CryostatID_t Cryostat
Index of cryostat.
Definition of basic raw digits.
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
std::vector< int > fHitMultProductVec
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
float GoodnessOfFit() const
Degrees of freedom in the determination of the hit signal shape (-1 by default)
short int Multiplicity() const
How many hits could this one be shared with.
std::vector< float > fSPTotalChargeVec
std::vector< int > fPHOrderHitVec
std::vector< int > fTPCVec
float PeakAmplitude() const
The estimated amplitude of the hit at its peak, in ADC units.
std::vector< art::InputTag > fSpacePointLabelVec
std::vector< float > fIntegralHitVec
std::vector< int > fSPCryostatVec
std::vector< int > fCryoVec
void configure(fhicl::ParameterSet const &pset) override
std::vector< int > fLocalIndexHitVec
unsigned int Nplanes(unsigned int tpc=0, unsigned int cstat=0) const
Returns the total number of wire planes in the specified TPC.
const geo::GeometryCore * fGeometry
pointer to Geometry service
std::map< size_t, HitPtrVec > ViewHitMap
~SpacePointAnalysis()
Destructor.
std::vector< float > fSP_y
void endJob(int numEvents) override
Interface for method to executve at the end of run processing.
std::vector< const recob::Hit * > HitPointerVec
HitSpacePointObj fHitSpacePointObj
PlaneToT0OffsetMap fPlaneToT0OffsetMap
std::vector< float > fSP_x
std::vector< int > fTPCVec
PlaneID_t Plane
Index of the plane within its TPC.
Description of geometry of one entire detector.
std::vector< float > fSPQualityVec
std::vector< float > fLargestPHVec
std::vector< int > fNum2DHitsVec
std::vector< float > fAveragePHVec
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
void setBranches(TTree *tree)
std::vector< HitTupleObj > HitTuplebjVec
void initializeTuple(TTree *) override
Interface for initializing the tuple variables.
float PeakTime() const
Time of the signal peak, in tick units.
std::map< geo::PlaneID, float > PlaneToT0OffsetMap
std::vector< int > fNumIntersectSetVec
SpacePointAnalysis(fhicl::ParameterSet const &pset)
Constructor.
std::vector< float > fSP_z
Contains all timing reference information for the detector.
void fillHistograms(const art::Event &) const override
Interface for filling histograms.
void processSpacePoints(const art::Event &, const detinfo::DetectorClocksData &) const
std::string to_string(WindowPattern const &pattern)
std::vector< int > fMultiplicityHitVec
void setBranches(TTree *tree)
Interface for experiment-specific channel quality info provider.
float SummedADC() const
The sum of calibrated ADC counts of the hit (0. by default)
std::vector< int > fClusterSizeVec
Declaration of basic channel signal object.
std::vector< float > fLargestDelTVec
std::vector< art::Ptr< recob::Hit >> HitPtrVec
2D representation of charge deposited in the TDC/wire plane
art::ServiceHandle< art::TFileService > tfs
std::size_t count(Cont const &cont)
TPCID_t TPC
Index of the TPC within its cryostat.
Interface for experiment-specific service for channel quality info.
std::vector< int > fTicksVec
HitTuplebjVec fHitTupleObjVec
std::vector< int > fNumLongHitsVec
std::vector< float > fRMSHitVec
std::vector< int > fSPTPCVec
std::vector< float > fHitDelta20Vec
art framework interface to geometry description
BEGIN_PROLOG could also be cout
std::vector< float > fSmallestPHVec