LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
ShowerNumElectronsEnergy_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: ShowerNumElectronsEnergy ###
3 //### Author: Tom Ham ###
4 //### Date: 01/04/2020 ###
5 //### Description: Tool for finding the Energy of the shower by going ###
6 //### from number of hits -> number of electrons -> energy. ###
7 //### Derived from the linear energy algorithm, written for ###
8 //### the EMShower_module.cc ###
9 //############################################################################
10 
11 //Framework Includes
13 
14 //LArSoft Includes
23 
24 //C++ Includes
25 #include <tuple>
26 
27 namespace ShowerRecoTools {
28 
30 
31  public:
33 
34  //Physics Function. Calculate the shower Energy.
35  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
36  art::Event& Event,
37  reco::shower::ShowerElementHolder& ShowerElementHolder) override;
38 
39  private:
40  double CalculateEnergy(const detinfo::DetectorClocksData& clockData,
41  const detinfo::DetectorPropertiesData& detProp,
43  const geo::PlaneID::PlaneID_t plane) const;
44 
46  int fVerbose;
47 
50 
51  //Services
54 
55  // Declare stuff
57  };
58 
60  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
61  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
62  , fVerbose(pset.get<int>("Verbose"))
63  , fShowerEnergyOutputLabel(pset.get<std::string>("ShowerEnergyOutputLabel"))
64  , fShowerBestPlaneOutputLabel(pset.get<std::string>("ShowerBestPlaneOutputLabel"))
65  , fCalorimetryAlg(pset.get<fhicl::ParameterSet>("CalorimetryAlg"))
66  , fRecombinationFactor(pset.get<double>("RecombinationFactor"))
67  {}
68 
70  art::Event& Event,
71  reco::shower::ShowerElementHolder& ShowerEleHolder)
72  {
73 
74  if (fVerbose)
75  std::cout
76  << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Shower Reco Energy Tool ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
77  << std::endl;
78 
79  // Get the assocated pfParicle vertex PFParticles
80  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
81 
82  //Get the clusters
83  auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
84 
86  ShowerEleHolder.GetFindManyP<recob::Cluster>(pfpHandle, Event, fPFParticleLabel);
87  // art::FindManyP<recob::Cluster> fmc(pfpHandle, Event, fPFParticleLabel);
88  std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
89 
90  //Get the hit association
91  const art::FindManyP<recob::Hit>& fmhc =
92  ShowerEleHolder.GetFindManyP<recob::Hit>(clusHandle, Event, fPFParticleLabel);
93  // art::FindManyP<recob::Hit> fmhc(clusHandle, Event, fPFParticleLabel);
94 
95  std::map<geo::PlaneID::PlaneID_t, std::vector<art::Ptr<recob::Hit>>> planeHits;
96 
97  //Loop over the clusters in the plane and get the hits
98  for (auto const& cluster : clusters) {
99 
100  //Get the hits
101  std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(cluster.key());
102 
103  //Get the plane.
104  const geo::PlaneID::PlaneID_t plane(cluster->Plane().Plane);
105 
106  planeHits[plane].insert(planeHits[plane].end(), hits.begin(), hits.end());
107  }
108 
109  // Calculate the energy for each plane && best plane
110  geo::PlaneID::PlaneID_t bestPlane = std::numeric_limits<geo::PlaneID::PlaneID_t>::max();
111  unsigned int bestPlaneNumHits = 0;
112 
113  //Holder for the final product
114  std::vector<double> energyVec(fChannelMap.Nplanes(), -999.);
115  std::vector<double> energyError(fChannelMap.Nplanes(), -999.);
116 
117  auto const clockData =
119  auto const detProp =
121 
122  for (auto const& [plane, hits] : planeHits) {
123 
124  unsigned int planeNumHits = hits.size();
125 
126  //Calculate the Energy for
127  double Energy = CalculateEnergy(clockData, detProp, hits, plane);
128  // If the energy is negative, leave it at -999
129  if (Energy > 0) energyVec.at(plane) = Energy;
130 
131  if (planeNumHits > bestPlaneNumHits) {
132  bestPlane = plane;
133  bestPlaneNumHits = planeNumHits;
134  }
135  }
136 
137  ShowerEleHolder.SetElement(energyVec, energyError, fShowerEnergyOutputLabel);
138  // Only set the best plane if it has some hits in it
139  if (bestPlane < fChannelMap.Nplanes()) {
140  // Need to cast as an int for legacy default of -999
141  // have to define a new variable as we pass-by-reference when filling
142  int bestPlaneVal(bestPlane);
143  ShowerEleHolder.SetElement(bestPlaneVal, fShowerBestPlaneOutputLabel);
144  }
145 
146  return 0;
147  }
148 
149  // function to calculate the reco energy
151  const detinfo::DetectorPropertiesData& detProp,
153  const geo::PlaneID::PlaneID_t plane) const
154  {
155 
156  double totalCharge = 0;
157  double totalEnergy = 0;
158  double correctedtotalCharge = 0;
159  double nElectrons = 0;
160 
161  for (auto const& hit : hits) {
162  totalCharge +=
163  hit->Integral() *
165  clockData, detProp, hit->PeakTime()); // obtain charge and correct for lifetime
166  }
167 
168  // correct charge due to recombination
169  correctedtotalCharge = totalCharge / fRecombinationFactor;
170  // calculate # of electrons and the corresponding energy
171  nElectrons = fCalorimetryAlg.ElectronsFromADCArea(correctedtotalCharge, plane);
172  totalEnergy = (nElectrons / util::kGeVToElectrons) * 1000; // energy in MeV
173  return totalEnergy;
174  }
175 }
176 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
unsigned int PlaneID_t
Type for the ID number.
Definition: geo_types.h:365
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
void SetElement(T &dataproduct, const std::string &Name, bool checktag=false)
STL namespace.
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
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
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
double ElectronsFromADCArea(double area, unsigned short plane) const
constexpr double kGeVToElectrons
23.6eV per ion pair, 1e9 eV/GeV
void hits()
Definition: readHits.C:15
Interface for a class providing readout channel mapping to geometry.
parameter set interface
key_type key() const noexcept
Definition: Ptr.h:166
Declaration of cluster object.
Detector simulation of raw signals on wires.
unsigned int Nplanes(TPCID const &tpcid=details::tpc_zero) const
Returns the total number of planes in the specified TPC.
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerElementHolder) override
Contains all timing reference information for the detector.
Definition: MVAAlg.h:12
2D representation of charge deposited in the TDC/wire plane
Definition: Hit.h:46
ShowerNumElectronsEnergy(const fhicl::ParameterSet &pset)
double LifetimeCorrection(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, double time, double T0=0) const
Collection of Physical constants used in LArSoft.
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)