LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
ShowerRecoTools::ShowerLinearEnergy Class Reference
Inheritance diagram for ShowerRecoTools::ShowerLinearEnergy:
ShowerRecoTools::IShowerTool

Public Member Functions

 ShowerLinearEnergy (const fhicl::ParameterSet &pset)
 
int CalculateElement (const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerElementHolder) override
 

Private Member Functions

double CalculateEnergy (const detinfo::DetectorClocksData &clockData, const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Hit >> &hits, const geo::PlaneID::PlaneID_t plane) const
 
int RunShowerTool (const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder, std::string evd_display_name_append="")
 
virtual void InitialiseProducers ()
 
void SetPtr (art::ProducesCollector *collector)
 
void InitaliseProducerPtr (reco::shower::ShowerProducedPtrsHolder &uniqueproducerPtrs)
 
virtual int AddAssociations (const art::Ptr< recob::PFParticle > &pfpPtr, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)
 
const shower::LArPandoraShowerAlgGetLArPandoraShowerAlg () const
 
template<class T >
art::Ptr< T > GetProducedElementPtr (std::string Name, reco::shower::ShowerElementHolder &ShowerEleHolder, int iter=-1)
 
template<class T >
void InitialiseProduct (std::string Name, std::string InstanceName="")
 
template<class T , class A , class B >
void AddSingle (A &a, B &b, std::string Name)
 
int GetVectorPtrSize (std::string Name)
 
void PrintPtrs ()
 
void PrintPtr (std::string Name)
 

Private Attributes

unsigned int fNumPlanes
 
std::vector< double > fGradients
 
std::vector< double > fIntercepts
 
art::InputTag fPFParticleLabel
 
int fVerbose
 
std::string fShowerEnergyOutputLabel
 
std::string fShowerBestPlaneOutputLabel
 
art::ServiceHandle< geo::GeometryfGeom
 

Detailed Description

Definition at line 23 of file ShowerLinearEnergy_tool.cc.

Constructor & Destructor Documentation

ShowerRecoTools::ShowerLinearEnergy::ShowerLinearEnergy ( const fhicl::ParameterSet pset)

Definition at line 54 of file ShowerLinearEnergy_tool.cc.

References fGeom, fGradients, fIntercepts, fNumPlanes, and geo::GeometryCore::Nplanes().

55  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
56  , fGradients(pset.get<std::vector<double>>("Gradients"))
57  , fIntercepts(pset.get<std::vector<double>>("Intercepts"))
58  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
59  , fVerbose(pset.get<int>("Verbose"))
60  , fShowerEnergyOutputLabel(pset.get<std::string>("ShowerEnergyOutputLabel"))
61  , fShowerBestPlaneOutputLabel(pset.get<std::string>("ShowerBestPlaneOutputLabel"))
62  {
64  if (fNumPlanes != fGradients.size() || fNumPlanes != fIntercepts.size()) {
65  throw cet::exception("ShowerLinearEnergy")
66  << "The number of planes does not match the size of the fcl parametes passed: Num Planes: "
67  << fNumPlanes << ", Gradients size: " << fGradients.size()
68  << ", Intercpts size: " << fIntercepts.size();
69  }
70  }
art::ServiceHandle< geo::Geometry > fGeom
T get(std::string const &key) const
Definition: ParameterSet.h:314
IShowerTool(const fhicl::ParameterSet &pset)
Definition: IShowerTool.h:33
unsigned int Nplanes(TPCID const &tpcid=tpc_zero) const
Returns the total number of planes in the specified TPC.
Definition: GeometryCore.h:977
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33

Member Function Documentation

virtual int ShowerRecoTools::IShowerTool::AddAssociations ( const art::Ptr< recob::PFParticle > &  pfpPtr,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder 
)
inlinevirtualinherited
template<class T , class A , class B >
void ShowerRecoTools::IShowerTool::AddSingle ( A &  a,
B &  b,
std::string  Name 
)
inlineprotectedinherited

Definition at line 152 of file IShowerTool.h.

References reco::shower::ShowerProducedPtrsHolder::AddSingle().

153  {
154  UniquePtrs->AddSingle<T>(a, b, Name);
155  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
void AddSingle(A &a, B &b, const std::string &Name)
int ShowerRecoTools::ShowerLinearEnergy::CalculateElement ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerElementHolder 
)
overridevirtual

Implements ShowerRecoTools::IShowerTool.

Definition at line 72 of file ShowerLinearEnergy_tool.cc.

References CalculateEnergy(), util::end(), fNumPlanes, fPFParticleLabel, fShowerBestPlaneOutputLabel, fShowerEnergyOutputLabel, reco::shower::ShowerElementHolder::GetFindManyP(), art::ProductRetriever::getValidHandle(), hits(), art::Ptr< T >::key(), and reco::shower::ShowerElementHolder::SetElement().

75  {
76 
77  // Get the assocated pfParicle vertex PFParticles
78  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
79 
80  //Get the clusters
81  auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
82 
84  ShowerEleHolder.GetFindManyP<recob::Cluster>(pfpHandle, Event, fPFParticleLabel);
85  // art::FindManyP<recob::Cluster> fmc(pfpHandle, Event, fPFParticleLabel);
86  std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
87 
88  //Get the hit association
89  const art::FindManyP<recob::Hit>& fmhc =
90  ShowerEleHolder.GetFindManyP<recob::Hit>(clusHandle, Event, fPFParticleLabel);
91  // art::FindManyP<recob::Hit> fmhc(clusHandle, Event, fPFParticleLabel);
92 
93  std::map<geo::PlaneID::PlaneID_t, std::vector<art::Ptr<recob::Hit>>> planeHits;
94 
95  //Loop over the clusters in the plane and get the hits
96  for (auto const& cluster : clusters) {
97 
98  //Get the hits
99  std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(cluster.key());
100 
101  //Get the plane.
102  const geo::PlaneID::PlaneID_t plane(cluster->Plane().Plane);
103 
104  planeHits[plane].insert(planeHits[plane].end(), hits.begin(), hits.end());
105  }
106 
107  // Calculate the energy for each plane && best plane
108  geo::PlaneID::PlaneID_t bestPlane = std::numeric_limits<geo::PlaneID::PlaneID_t>::max();
109  unsigned int bestPlaneNumHits = 0;
110 
111  //Holder for the final product
112  std::vector<double> energyVec(fNumPlanes, -999.);
113  std::vector<double> energyError(fNumPlanes, -999.);
114 
115  auto const clockData =
117  auto const detProp =
119 
120  for (auto const& [plane, hits] : planeHits) {
121 
122  unsigned int planeNumHits = hits.size();
123 
124  //Calculate the Energy for
125  double Energy = CalculateEnergy(clockData, detProp, hits, plane);
126  // If the energy is negative, leave it at -999
127  if (Energy > 0) energyVec.at(plane) = Energy;
128 
129  if (planeNumHits > bestPlaneNumHits) {
130  bestPlane = plane;
131  bestPlaneNumHits = planeNumHits;
132  }
133  }
134 
135  ShowerEleHolder.SetElement(energyVec, energyError, fShowerEnergyOutputLabel);
136  // Only set the best plane if it has some hits in it
137  if (bestPlane < fGeom->Nplanes()) {
138  // Need to cast as an int for legacy default of -999
139  // have to define a new variable as we pass-by-reference when filling
140  int bestPlaneVal(bestPlane);
141  ShowerEleHolder.SetElement(bestPlaneVal, fShowerBestPlaneOutputLabel);
142  }
143 
144  return 0;
145  }
double CalculateEnergy(const detinfo::DetectorClocksData &clockData, const detinfo::DetectorPropertiesData &detProp, const std::vector< art::Ptr< recob::Hit >> &hits, const geo::PlaneID::PlaneID_t plane) const
unsigned int PlaneID_t
Type for the ID number.
Definition: geo_types.h:464
Set of hits with a 2D structure.
Definition: Cluster.h:69
Cluster finding and building.
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
void hits()
Definition: readHits.C:15
key_type key() const noexcept
Definition: Ptr.h:166
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
double ShowerRecoTools::ShowerLinearEnergy::CalculateEnergy ( const detinfo::DetectorClocksData clockData,
const detinfo::DetectorPropertiesData detProp,
const std::vector< art::Ptr< recob::Hit >> &  hits,
const geo::PlaneID::PlaneID_t  plane 
) const
private

Definition at line 149 of file ShowerLinearEnergy_tool.cc.

References DEFINE_ART_CLASS_TOOL, detinfo::DetectorPropertiesData::ElectronLifetime(), fGradients, fIntercepts, hits(), and detinfo::sampling_rate().

Referenced by CalculateElement().

153  {
154 
155  double totalCharge = 0, totalEnergy = 0;
156 
157  for (auto const& hit : hits) {
158  totalCharge += (hit->Integral() * std::exp((sampling_rate(clockData) * hit->PeakTime()) /
159  (detProp.ElectronLifetime() * 1e3)));
160  }
161 
162  totalEnergy = (totalCharge * fGradients.at(plane)) + fIntercepts.at(plane);
163 
164  return totalEnergy;
165  }
Detector simulation of raw signals on wires.
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
const shower::LArPandoraShowerAlg& ShowerRecoTools::IShowerTool::GetLArPandoraShowerAlg ( ) const
inlineprotectedinherited

Definition at line 82 of file IShowerTool.h.

Referenced by ShowerRecoTools::ShowerLengthPercentile::CalculateElement(), ShowerRecoTools::ShowerUnidirectiondEdx::CalculateElement(), ShowerRecoTools::Shower3DCylinderTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerPCAPropergationStartPosition::CalculateElement(), ShowerRecoTools::Shower2DLinearRegressionTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerPFPVertexStartPosition::CalculateElement(), ShowerRecoTools::ShowerDirectionCheater::CalculateElement(), ShowerRecoTools::ShowerPCADirection::CalculateElement(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerTrajPointdEdx::CalculateElement(), ShowerRecoTools::ShowerPCADirection::CalculateShowerPCA(), ShowerRecoTools::Shower2DLinearRegressionTrackHitFinder::FindInitialTrackHits(), ShowerRecoTools::Shower3DCylinderTrackHitFinder::FindTrackSpacePoints(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::FitSegmentAndCalculateResidual(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::PruneFrontOfSPSPool(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::PruneTrack(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::RunTestOfIncrementalSpacePointFinder(), ShowerRecoTools::ShowerTrackPCADirection::ShowerPCAVector(), and ShowerRecoTools::ShowerIncrementalTrackHitFinder::ShowerPCAVector().

83  {
84  return fLArPandoraShowerAlg;
85  };
shower::LArPandoraShowerAlg fLArPandoraShowerAlg
Definition: IShowerTool.h:92
template<class T >
art::Ptr<T> ShowerRecoTools::IShowerTool::GetProducedElementPtr ( std::string  Name,
reco::shower::ShowerElementHolder ShowerEleHolder,
int  iter = -1 
)
inlineprotectedinherited

Definition at line 102 of file IShowerTool.h.

References reco::shower::ShowerElementHolder::CheckElement(), reco::shower::ShowerProducedPtrsHolder::CheckUniqueProduerPtr(), reco::shower::ShowerProducedPtrsHolder::GetArtPtr(), and reco::shower::ShowerElementHolder::GetShowerNumber().

105  {
106 
107  //Check the element has been set
108  bool check_element = ShowerEleHolder.CheckElement(Name);
109  if (!check_element) {
110  throw cet::exception("IShowerTool") << "tried to get a element that does not exist. Failed "
111  "at making the art ptr for Element: "
112  << Name << std::endl;
113  }
114 
115  //Check the unique ptr has been set.
116  bool check_ptr = UniquePtrs->CheckUniqueProduerPtr(Name);
117  if (!check_ptr) {
118  throw cet::exception("IShowerTool")
119  << "tried to get a ptr that does not exist. Failed at making the art ptr for Element"
120  << Name;
121  }
122 
123  //Check if the user has defined an index if not just use the current shower index/
124  int index;
125  if (iter != -1) { index = iter; }
126  else {
127  index = ShowerEleHolder.GetShowerNumber();
128  }
129 
130  //Make the ptr
131  return UniquePtrs->GetArtPtr<T>(Name, index);
132  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
bool CheckUniqueProduerPtr(const std::string &Name) const
bool CheckElement(const std::string &Name) const
art::Ptr< T > GetArtPtr(const std::string &Name, const int &iter) const
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
int ShowerRecoTools::IShowerTool::GetVectorPtrSize ( std::string  Name)
inlineprotectedinherited
void ShowerRecoTools::IShowerTool::InitaliseProducerPtr ( reco::shower::ShowerProducedPtrsHolder uniqueproducerPtrs)
inlineinherited

Definition at line 68 of file IShowerTool.h.

69  {
70  UniquePtrs = &uniqueproducerPtrs;
71  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
virtual void ShowerRecoTools::IShowerTool::InitialiseProducers ( )
inlinevirtualinherited
template<class T >
void ShowerRecoTools::IShowerTool::InitialiseProduct ( std::string  Name,
std::string  InstanceName = "" 
)
inlineprotectedinherited

Definition at line 137 of file IShowerTool.h.

References art::ProducesCollector::produces(), and reco::shower::ShowerProducedPtrsHolder::SetShowerUniqueProduerPtr().

138  {
139 
140  if (collectorPtr == nullptr) {
141  mf::LogWarning("IShowerTool") << "The art::ProducesCollector ptr has not been set";
142  return;
143  }
144 
145  collectorPtr->produces<T>(InstanceName);
146  UniquePtrs->SetShowerUniqueProduerPtr(type<T>(), Name, InstanceName);
147  }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
art::ProducesCollector * collectorPtr
Definition: IShowerTool.h:97
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
int SetShowerUniqueProduerPtr(type< T >, const std::string &Name, const std::string &Instance="")
void ShowerRecoTools::IShowerTool::PrintPtr ( std::string  Name)
inlineprotectedinherited

Definition at line 162 of file IShowerTool.h.

References reco::shower::ShowerProducedPtrsHolder::PrintPtr().

Referenced by ShowerRecoTools::ShowerExampleTool::CalculateElement().

162 { UniquePtrs->PrintPtr(Name); }
reco::shower::ShowerProducedPtrsHolder * UniquePtrs
Definition: IShowerTool.h:85
void PrintPtr(const std::string &Name) const
void ShowerRecoTools::IShowerTool::PrintPtrs ( )
inlineprotectedinherited
int ShowerRecoTools::IShowerTool::RunShowerTool ( const art::Ptr< recob::PFParticle > &  pfparticle,
art::Event Event,
reco::shower::ShowerElementHolder ShowerEleHolder,
std::string  evd_display_name_append = "" 
)
inlineinherited

Definition at line 46 of file IShowerTool.h.

50  {
51 
52  int calculation_status = CalculateElement(pfparticle, Event, ShowerEleHolder);
53  if (calculation_status != 0) return calculation_status;
54  if (fRunEventDisplay) {
56  pfparticle, Event, ShowerEleHolder, evd_display_name_append);
57  }
58  return calculation_status;
59  }
void DebugEVD(art::Ptr< recob::PFParticle > const &pfparticle, art::Event const &Event, const reco::shower::ShowerElementHolder &ShowerEleHolder, std::string const &evd_disp_name_append="") const
virtual int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerEleHolder)=0
const shower::LArPandoraShowerAlg & GetLArPandoraShowerAlg() const
Definition: IShowerTool.h:82
void ShowerRecoTools::IShowerTool::SetPtr ( art::ProducesCollector collector)
inlineinherited

Definition at line 65 of file IShowerTool.h.

65 { collectorPtr = collector; }
art::ProducesCollector * collectorPtr
Definition: IShowerTool.h:97

Member Data Documentation

art::ServiceHandle<geo::Geometry> ShowerRecoTools::ShowerLinearEnergy::fGeom
private

Definition at line 51 of file ShowerLinearEnergy_tool.cc.

Referenced by ShowerLinearEnergy().

std::vector<double> ShowerRecoTools::ShowerLinearEnergy::fGradients
private

Definition at line 41 of file ShowerLinearEnergy_tool.cc.

Referenced by CalculateEnergy(), and ShowerLinearEnergy().

std::vector<double> ShowerRecoTools::ShowerLinearEnergy::fIntercepts
private

Definition at line 42 of file ShowerLinearEnergy_tool.cc.

Referenced by CalculateEnergy(), and ShowerLinearEnergy().

unsigned int ShowerRecoTools::ShowerLinearEnergy::fNumPlanes
private

Definition at line 40 of file ShowerLinearEnergy_tool.cc.

Referenced by CalculateElement(), and ShowerLinearEnergy().

art::InputTag ShowerRecoTools::ShowerLinearEnergy::fPFParticleLabel
private

Definition at line 44 of file ShowerLinearEnergy_tool.cc.

Referenced by CalculateElement().

std::string ShowerRecoTools::ShowerLinearEnergy::fShowerBestPlaneOutputLabel
private

Definition at line 48 of file ShowerLinearEnergy_tool.cc.

Referenced by CalculateElement().

std::string ShowerRecoTools::ShowerLinearEnergy::fShowerEnergyOutputLabel
private

Definition at line 47 of file ShowerLinearEnergy_tool.cc.

Referenced by CalculateElement().

int ShowerRecoTools::ShowerLinearEnergy::fVerbose
private

Definition at line 45 of file ShowerLinearEnergy_tool.cc.


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