All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SpacePointAnalysis::SpacePointAnalysis Class Reference
Inheritance diagram for SpacePointAnalysis::SpacePointAnalysis:
IHitEfficiencyHistogramTool

Public Member Functions

 SpacePointAnalysis (fhicl::ParameterSet const &pset)
 Constructor. More...
 
 ~SpacePointAnalysis ()
 Destructor. More...
 
void configure (fhicl::ParameterSet const &pset) override
 
void initializeHists (art::ServiceHandle< art::TFileService > &, const std::string &) override
 Interface for initializing the histograms to be filled. More...
 
void initializeTuple (TTree *) override
 Interface for initializing the tuple variables. More...
 
void endJob (int numEvents) override
 Interface for method to executve at the end of run processing. More...
 
void fillHistograms (const art::Event &) const override
 Interface for filling histograms. More...
 
- Public Member Functions inherited from IHitEfficiencyHistogramTool
virtual ~IHitEfficiencyHistogramTool () noexcept=default
 Virtual Destructor. More...
 
virtual ~IHitEfficiencyHistogramTool () noexcept=default
 Virtual Destructor. More...
 

Private Types

using HitPointerVec = std::vector< const recob::Hit * >
 
using PlaneToT0OffsetMap = std::map< geo::PlaneID, float >
 
using HitTuplebjVec = std::vector< HitTupleObj >
 

Private Member Functions

void clear () const
 
void processSpacePoints (const art::Event &, const detinfo::DetectorClocksData &) const
 

Private Attributes

std::vector< art::InputTag > fSpacePointLabelVec
 
art::InputTag fBadChannelProducerLabel
 
bool fUseT0Offsets
 
TTree * fTree
 
std::vector< int > fTPCVec
 
std::vector< int > fCryoVec
 
std::vector< int > fPlaneVec
 
PlaneToT0OffsetMap fPlaneToT0OffsetMap
 
HitTuplebjVec fHitTupleObjVec
 
HitSpacePointObj fHitSpacePointObj
 
const geo::GeometryCorefGeometry
 pointer to Geometry service More...
 

Detailed Description

Definition at line 264 of file SpacePointAnalysis_tool.cc.

Member Typedef Documentation

Definition at line 317 of file SpacePointAnalysis_tool.cc.

Definition at line 335 of file SpacePointAnalysis_tool.cc.

Definition at line 320 of file SpacePointAnalysis_tool.cc.

Constructor & Destructor Documentation

SpacePointAnalysis::SpacePointAnalysis::SpacePointAnalysis ( fhicl::ParameterSet const &  pset)
explicit

Constructor.

Parameters
psetConstructor.

Arguments:

pset - Fcl parameters.

Definition at line 351 of file SpacePointAnalysis_tool.cc.

351  : fTree(nullptr)
352 {
353  fGeometry = lar::providerFrom<geo::Geometry>();
354 
355  configure(pset);
356 
357  // Report.
358  mf::LogInfo("SpacePointAnalysis") << "SpacePointAnalysis configured\n";
359 }
void configure(fhicl::ParameterSet const &pset) override
const geo::GeometryCore * fGeometry
pointer to Geometry service
SpacePointAnalysis::SpacePointAnalysis::~SpacePointAnalysis ( )

Destructor.

Definition at line 363 of file SpacePointAnalysis_tool.cc.

364 {}

Member Function Documentation

void SpacePointAnalysis::SpacePointAnalysis::clear ( ) const
private

Definition at line 423 of file SpacePointAnalysis_tool.cc.

424 {
425  fTPCVec.clear();
426  fCryoVec.clear();
427  fPlaneVec.clear();
428 
430 
431  for(auto& hitObj : fHitTupleObjVec) hitObj.clear();
432 
433  return;
434 }
void SpacePointAnalysis::SpacePointAnalysis::configure ( fhicl::ParameterSet const &  pset)
overridevirtual

Reconfigure method.

Arguments:

pset - Fcl parameter set.

Implements IHitEfficiencyHistogramTool.

Definition at line 373 of file SpacePointAnalysis_tool.cc.

374 {
375  fSpacePointLabelVec = pset.get< std::vector<art::InputTag>>("SpacePointLabelVec", {"cluster3d"});
376  fUseT0Offsets = pset.get< bool >("UseT0Offsets", false);
377 
378  return;
379 }
std::vector< art::InputTag > fSpacePointLabelVec
void SpacePointAnalysis::SpacePointAnalysis::endJob ( int  numEvents)
overridevirtual

Interface for method to executve at the end of run processing.

Parameters
intnumber of events to use for normalization

Implements IHitEfficiencyHistogramTool.

Definition at line 690 of file SpacePointAnalysis_tool.cc.

691 {
692  return;
693 }
void SpacePointAnalysis::SpacePointAnalysis::fillHistograms ( const art::Event &  event) const
overridevirtual

Interface for filling histograms.

Implements IHitEfficiencyHistogramTool.

Definition at line 436 of file SpacePointAnalysis_tool.cc.

437 {
438  // Ok... this is starting to grow too much and get out of control... we will need to break it up directly...
439 
440  // Always clear the tuple
441  clear();
442 
443  mf::LogDebug("SpacePointAnalysis") << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
444 
445  // Now do the space points
446  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(event);
447  processSpacePoints(event, clockData);
448 
449  // Make sure the output tuples are filled
451 
452  for(auto& hitObj : fHitTupleObjVec) hitObj.fill();
453 
454  return;
455 }
void processSpacePoints(const art::Event &, const detinfo::DetectorClocksData &) const
void SpacePointAnalysis::SpacePointAnalysis::initializeHists ( art::ServiceHandle< art::TFileService > &  tfs,
const std::string &  dirName 
)
overridevirtual

Interface for initializing the histograms to be filled.

Begin job method.

Parameters
TFileServicehandle to the TFile service
stringsubdirectory to store the hists in

Implements IHitEfficiencyHistogramTool.

Definition at line 383 of file SpacePointAnalysis_tool.cc.

384 {
385  // Make a directory for these histograms
386 // art::TFileDirectory dir = tfs->mkdir(dirName.c_str());
387 
388  return;
389 }
void SpacePointAnalysis::SpacePointAnalysis::initializeTuple ( TTree *  tree)
overridevirtual

Interface for initializing the tuple variables.

Parameters
TTreepointer to a TTree object to which to add variables

Implements IHitEfficiencyHistogramTool.

Definition at line 391 of file SpacePointAnalysis_tool.cc.

392 {
393  // Access ART's TFileService, which will handle creating and writing
394  // histograms and n-tuples for us.
395  art::ServiceHandle<art::TFileService> tfs;
396 
397  fTree = tree;
398 
399  fTree->Branch("CryostataVec", "std::vector<int>", &fCryoVec);
400  fTree->Branch("TPCVec", "std::vector<int>", &fTPCVec);
401  fTree->Branch("PlaneVec", "std::vector<int>", &fPlaneVec);
402 
403  // Set up specific branch for space points
404  TTree* locTree = tfs->makeAndRegister<TTree>("SpacePoint_t","SpacePoint Tuple");
405 
407 
408  fHitTupleObjVec.resize(fGeometry->Nplanes());
409 
410  for(size_t plane = 0; plane < fGeometry->Nplanes(); plane++)
411  {
412  // Set up specific branch for space points
413  locTree = tfs->makeAndRegister<TTree>("MatchedHits_P"+std::to_string(plane),"Matched Hits Tuple plane "+std::to_string(plane));
414 
415  fHitTupleObjVec[plane].setBranches(locTree);
416  }
417 
418  clear();
419 
420  return;
421 }
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::string to_string(WindowPattern const &pattern)
art::ServiceHandle< art::TFileService > tfs
void SpacePointAnalysis::SpacePointAnalysis::processSpacePoints ( const art::Event &  event,
const detinfo::DetectorClocksData clockData 
) const
private

Definition at line 457 of file SpacePointAnalysis_tool.cc.

459 {
460  // One time initialization done?
461 
462  // Do the one time initialization of the tick offsets.
463  if (fPlaneToT0OffsetMap.empty())
464  {
465  // Need the detector properties which needs the clocks
466  auto const det_prop = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(event, clockData);
467 
468  for(size_t cryoIdx = 0; cryoIdx < fGeometry->Ncryostats(); cryoIdx++)
469  {
470  for(size_t tpcIdx = 0; tpcIdx < fGeometry->NTPC(); tpcIdx++)
471  {
472  for(size_t planeIdx = 0; planeIdx < fGeometry->Nplanes(); planeIdx++)
473  {
474  geo::PlaneID planeID(cryoIdx,tpcIdx,planeIdx);
475 
476 // if (fUseT0Offsets) fPlaneToT0OffsetMap[planeID] = int(det_prop.GetXTicksOffset(planeID) - det_prop.GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,0)));
477  if (fUseT0Offsets) fPlaneToT0OffsetMap[planeID] = det_prop.GetXTicksOffset(planeID) - det_prop.GetXTicksOffset(geo::PlaneID(cryoIdx,tpcIdx,0));
478  else fPlaneToT0OffsetMap[planeID] = 0.;
479 
480  std::cout << "--PlaneID: " << planeID << ", has T0 offset: " << fPlaneToT0OffsetMap.find(planeID)->second << std::endl;
481  }
482  }
483  }
484  }
485 
486  // Diagnostics
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*>>;
489 
490  TripletMap tripletMap;
491 
492  // detector properties
493  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
494 
495  // So now we loop through the various SpacePoint sources
496  for(const auto& collectionLabel : fSpacePointLabelVec)
497  {
498  art::Handle<std::vector<recob::PFParticle>> pfParticleHandle;
499  event.getByLabel(collectionLabel, pfParticleHandle);
500 
501  if (!pfParticleHandle.isValid()) continue;
502 
503  art::Handle< std::vector<recob::SpacePoint>> spacePointHandle;
504  event.getByLabel(collectionLabel, spacePointHandle);
505 
506  if (!spacePointHandle.isValid()) continue;
507 
508  // Recover the collection of associations between tracks and hits
509  art::FindManyP<recob::SpacePoint> pfPartSpacePointAssns(pfParticleHandle, event, collectionLabel);
510 
511  // Look up assocations between pfparticles and space points
512  art::FindManyP<recob::Hit> spHitAssnVec(spacePointHandle, event, collectionLabel);
513 
514  // Use this to build a map between PFParticles and the number of associated space points
515  using PFParticleToNumSPMap = std::map<const recob::PFParticle*,int>;
516 
517  PFParticleToNumSPMap pfParticleToNumSPMap;
518 
519  for(size_t idx = 0; idx < pfParticleHandle->size(); idx++)
520  {
521  art::Ptr<recob::PFParticle> pfParticle(pfParticleHandle,idx);
522 
523  std::vector<art::Ptr<recob::SpacePoint>> spacePointVec(pfPartSpacePointAssns.at(pfParticle.key()));
524 
525  pfParticleToNumSPMap[pfParticle.get()] = spacePointVec.size();
526 
527 // if (spacePointVec.size() > 50000) std::cout << "SpacePointAnalysis finds PFParticle with " << spacePointVec.size() << " associated space points, run/event: " << event.id() << std::endl;
528  }
529 
530  // Ok now we want the reverse look up
531  art::FindManyP<recob::PFParticle> spacePointPFPartAssns(spacePointHandle, event, collectionLabel);
532 
533  std::unordered_map<const recob::Hit*,int> uniqueHitMap;
534 
535  // And now, without further adieu, here we begin the loop that will actually produce some useful output.
536  // Loop over all space points and find out their true nature
537  for(size_t idx = 0; idx < spacePointHandle->size(); idx++)
538  {
539  // Recover space point
540  art::Ptr<recob::SpacePoint> spacePointPtr(spacePointHandle,idx);
541 
542  std::vector<art::Ptr<recob::Hit>> associatedHits(spHitAssnVec.at(spacePointPtr.key()));
543 
544  if (associatedHits.size() < 2)
545  {
546  mf::LogDebug("SpacePointAnalysis") << "I am certain this cannot happen... but here you go, space point with " << associatedHits.size() << " hits" << std::endl;
547  continue;
548  }
549 
550  // Recover the PFParticle associated to this space point and get the number of associated hits
551  int nSpacePointsInPFParticle(0);
552 
553  std::vector<art::Ptr<recob::PFParticle>> pfParticleVec(spacePointPFPartAssns.at(spacePointPtr.key()));
554 
555  if (pfParticleVec.size() == 1) nSpacePointsInPFParticle = pfParticleToNumSPMap.at(pfParticleVec[0].get());
556 
557  mf::LogDebug("SpacePointAnalysis") << "==> pfPartVec size: " << pfParticleVec.size() << ", # space points: " << nSpacePointsInPFParticle << std::endl;
558 
559  // Retrieve the magic numbers from the space point
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.;
566  int numHits = 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;
574  int numLongHits(0);
575  int numIntersections(0);
576  int cryostat(-1);
577  int tpc(-1);
578 
579  std::vector<const recob::Hit*> recobHitVec(3,nullptr);
580 
581  std::vector<float> peakAmpVec;
582 
583  // Now we can use our maps to find out if the hits making up the SpacePoint are truly related...
584  for(const auto& hitPtr : associatedHits)
585  {
586  float peakAmplitude = hitPtr->PeakAmplitude();
587  float peakTime = hitPtr->PeakTime();
588  float rms = hitPtr->RMS();
589  int plane = hitPtr->WireID().Plane;
590 
591  peakAmpVec.emplace_back(peakAmplitude);
592 
593  // Add to the set
594  uniqueHitMap[hitPtr.get()] = nSpacePointsInPFParticle;
595 
596  recobHitVec[plane] = hitPtr.get();
597  numHits++;
598  averagePH += peakAmplitude;
599  smallestPH = std::min(peakAmplitude,smallestPH);
600  largestPH = std::max(peakAmplitude,largestPH);
601 
602  hitMultProduct *= hitPtr->Multiplicity();
603 
604  if (hitPtr->DegreesOfFreedom() < 2) numLongHits++;
605 
606  hitPeakTimeVec[plane] = peakTime - fPlaneToT0OffsetMap.find(hitPtr->WireID().planeID())->second;
607  hitPeakRMSVec[plane] = rms;
608  averagePT += hitPeakTimeVec[plane];
609 
610  cryostat = hitPtr->WireID().Cryostat;
611  tpc = hitPtr->WireID().TPC;
612  }
613 
614  Triplet hitTriplet(recobHitVec[0],recobHitVec[1],recobHitVec[2]);
615 
616  tripletMap[hitTriplet].emplace_back(spacePointPtr.get());
617 
618  averagePH /= float(numHits);
619  averagePT /= float(numHits);
620 
621  for(size_t planeIdx = 0; planeIdx < 3; planeIdx++)
622  {
623  // Skip if hit missing
624  if (hitPeakTimeVec[planeIdx] < 0) continue;
625 
626  float delT = hitPeakTimeVec[planeIdx] - averagePT;
627  if (std::abs(delT) > std::abs(largestDelT)) largestDelT = delT;
628  if (std::abs(delT) < std::abs(smallestDelT)) smallestDelT = delT;
629  }
630 
631  // Fill for "all" cases
632  fHitSpacePointObj.fSPCryostatVec.emplace_back(cryostat);
633  fHitSpacePointObj.fSPTPCVec.emplace_back(tpc);
634  fHitSpacePointObj.fSPQualityVec.emplace_back(spQuality);
635  fHitSpacePointObj.fSPTotalChargeVec.emplace_back(spCharge);
636  fHitSpacePointObj.fSPAsymmetryVec.emplace_back(spAsymmetry);
637  fHitSpacePointObj.fSmallestPHVec.emplace_back(smallestPH);
638  fHitSpacePointObj.fLargestPHVec.emplace_back(largestPH);
639  fHitSpacePointObj.fAveragePHVec.emplace_back(averagePH);
640  fHitSpacePointObj.fLargestDelTVec.emplace_back(largestDelT);
641  fHitSpacePointObj.fSmallestDelTVec.emplace_back(smallestDelT);
642  fHitSpacePointObj.fNum2DHitsVec.emplace_back(numHits);
643  fHitSpacePointObj.fNumLongHitsVec.emplace_back(numLongHits);
644  fHitSpacePointObj.fNumIntersectSetVec.emplace_back(numIntersections);
645  fHitSpacePointObj.fClusterNSPVec.emplace_back(nSpacePointsInPFParticle);
646  fHitSpacePointObj.fHitDelta10Vec.emplace_back(hitPeakTimeVec[1] - hitPeakTimeVec[0]);
647  fHitSpacePointObj.fHitSigma10Vec.emplace_back(std::sqrt(std::pow(hitPeakRMSVec[1],2) + std::pow(hitPeakRMSVec[0],2)));
648  fHitSpacePointObj.fHitDelta21Vec.emplace_back(hitPeakTimeVec[2] - hitPeakTimeVec[1]);
649  fHitSpacePointObj.fHitSigma21Vec.emplace_back(std::sqrt(std::pow(hitPeakRMSVec[2],2) + std::pow(hitPeakRMSVec[1],2)));
650  fHitSpacePointObj.fHitDelta20Vec.emplace_back(hitPeakTimeVec[2] - hitPeakTimeVec[0]);
651  fHitSpacePointObj.fHitSigma20Vec.emplace_back(std::sqrt(std::pow(hitPeakRMSVec[2],2) + std::pow(hitPeakRMSVec[0],2)));
652  fHitSpacePointObj.fHitMultProductVec.emplace_back(hitMultProduct);
653 
654  fHitSpacePointObj.fSP_x.emplace_back(spPosition[0]);
655  fHitSpacePointObj.fSP_y.emplace_back(spPosition[1]);
656  fHitSpacePointObj.fSP_z.emplace_back(spPosition[2]);
657  }
658 
659  // Now include hit information for unique hits
660  for(const auto& hitItr : uniqueHitMap)
661  {
662  // Recover hit time range (in ticks), cast a wide net here
663  const recob::Hit* hit = hitItr.first;
664 
665  float peakTime = hit->PeakTime();
666  float rms = hit->PeakTime();
667  int startTick = std::max( 0,int(std::floor(peakTime - 3. * rms)));
668  int endTick = std::min(4096,int(std::ceil( peakTime + 3. * rms)));
669 
670  fHitTupleObjVec[hit->WireID().Plane].fillHitInfo(hit,endTick-startTick+1,hitItr.second);
671 
672  }
673  }
674  // Can we check to see if we have duplicates?
675  std::vector<int> numSpacePointVec = {0,0,0,0,0};
676  for(const auto& tripletPair : tripletMap)
677  {
678  int numSpacePoints = std::min(numSpacePointVec.size()-1,tripletPair.second.size());
679  numSpacePointVec[numSpacePoints]++;
680  }
681  std::cout << "====>> Found " << tripletMap.size() << " SpacePoints, numbers: ";
682  for(const auto& count : numSpacePointVec) std::cout << count << " ";
683  std::cout << std::endl;
684 
685  return;
686 }
geo::WireID WireID() const
Definition: Hit.h:233
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
process_name hit
Definition: cheaterreco.fcl:51
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
std::vector< art::InputTag > fSpacePointLabelVec
T abs(T value)
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
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:48
std::size_t count(Cont const &cont)
BEGIN_PROLOG could also be cout
auto const detProp

Member Data Documentation

art::InputTag SpacePointAnalysis::SpacePointAnalysis::fBadChannelProducerLabel
private

Definition at line 323 of file SpacePointAnalysis_tool.cc.

std::vector<int> SpacePointAnalysis::SpacePointAnalysis::fCryoVec
mutableprivate

Definition at line 330 of file SpacePointAnalysis_tool.cc.

const geo::GeometryCore* SpacePointAnalysis::SpacePointAnalysis::fGeometry
private

pointer to Geometry service

Definition at line 341 of file SpacePointAnalysis_tool.cc.

HitSpacePointObj SpacePointAnalysis::SpacePointAnalysis::fHitSpacePointObj
mutableprivate

Definition at line 338 of file SpacePointAnalysis_tool.cc.

HitTuplebjVec SpacePointAnalysis::SpacePointAnalysis::fHitTupleObjVec
mutableprivate

Definition at line 337 of file SpacePointAnalysis_tool.cc.

PlaneToT0OffsetMap SpacePointAnalysis::SpacePointAnalysis::fPlaneToT0OffsetMap
mutableprivate

Definition at line 333 of file SpacePointAnalysis_tool.cc.

std::vector<int> SpacePointAnalysis::SpacePointAnalysis::fPlaneVec
mutableprivate

Definition at line 331 of file SpacePointAnalysis_tool.cc.

std::vector<art::InputTag> SpacePointAnalysis::SpacePointAnalysis::fSpacePointLabelVec
private

Definition at line 322 of file SpacePointAnalysis_tool.cc.

std::vector<int> SpacePointAnalysis::SpacePointAnalysis::fTPCVec
mutableprivate

Definition at line 329 of file SpacePointAnalysis_tool.cc.

TTree* SpacePointAnalysis::SpacePointAnalysis::fTree
mutableprivate

Definition at line 327 of file SpacePointAnalysis_tool.cc.

bool SpacePointAnalysis::SpacePointAnalysis::fUseT0Offsets
private

Definition at line 324 of file SpacePointAnalysis_tool.cc.


The documentation for this class was generated from the following file: