LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
ShowerLinearEnergy_tool.cc
Go to the documentation of this file.
1 //############################################################################
2 //### Name: ShowerLinearEnergy ###
3 //### Author: Dominic Barker ###
4 //### Date: 13.05.19 ###
5 //### Description: Tool for finding the Energy of the shower. Derived ###
6 //### from the linear energy algorithm, written for ###
7 //### the EMShower_module.cc ###
8 //############################################################################
9 
10 //Framework Includes
12 
13 //LArSoft Includes
21 
22 namespace ShowerRecoTools {
23 
25 
26  public:
28 
29  //Physics Function. Calculate the shower Energy.
30  int CalculateElement(const art::Ptr<recob::PFParticle>& pfparticle,
31  art::Event& Event,
32  reco::shower::ShowerElementHolder& ShowerElementHolder) override;
33 
34  private:
35  double CalculateEnergy(const detinfo::DetectorClocksData& clockData,
36  const detinfo::DetectorPropertiesData& detProp,
38  const geo::PlaneID::PlaneID_t plane) const;
39 
40  //fcl parameters
41  unsigned int fNumPlanes;
42  std::vector<double> fGradients; //Gradient of the linear fit of total charge to total energy
43  std::vector<double> fIntercepts; //Intercept of the linear fit of total charge to total energy
44 
46  int fVerbose;
47 
50 
51  //Services
53  };
54 
56  : IShowerTool(pset.get<fhicl::ParameterSet>("BaseTools"))
57  , fGradients(pset.get<std::vector<double>>("Gradients"))
58  , fIntercepts(pset.get<std::vector<double>>("Intercepts"))
59  , fPFParticleLabel(pset.get<art::InputTag>("PFParticleLabel"))
60  , fVerbose(pset.get<int>("Verbose"))
61  , fShowerEnergyOutputLabel(pset.get<std::string>("ShowerEnergyOutputLabel"))
62  , fShowerBestPlaneOutputLabel(pset.get<std::string>("ShowerBestPlaneOutputLabel"))
63  {
65  if (fNumPlanes != fGradients.size() || fNumPlanes != fIntercepts.size()) {
66  throw cet::exception("ShowerLinearEnergy")
67  << "The number of planes does not match the size of the fcl parametes passed: Num Planes: "
68  << fNumPlanes << ", Gradients size: " << fGradients.size()
69  << ", Intercpts size: " << fIntercepts.size();
70  }
71  }
72 
74  art::Event& Event,
75  reco::shower::ShowerElementHolder& ShowerEleHolder)
76  {
77 
78  // Get the assocated pfParicle vertex PFParticles
79  auto const pfpHandle = Event.getValidHandle<std::vector<recob::PFParticle>>(fPFParticleLabel);
80 
81  //Get the clusters
82  auto const clusHandle = Event.getValidHandle<std::vector<recob::Cluster>>(fPFParticleLabel);
83 
85  ShowerEleHolder.GetFindManyP<recob::Cluster>(pfpHandle, Event, fPFParticleLabel);
86  // art::FindManyP<recob::Cluster> fmc(pfpHandle, Event, fPFParticleLabel);
87  std::vector<art::Ptr<recob::Cluster>> clusters = fmc.at(pfparticle.key());
88 
89  //Get the hit association
90  const art::FindManyP<recob::Hit>& fmhc =
91  ShowerEleHolder.GetFindManyP<recob::Hit>(clusHandle, Event, fPFParticleLabel);
92  // art::FindManyP<recob::Hit> fmhc(clusHandle, Event, fPFParticleLabel);
93 
94  std::map<geo::PlaneID::PlaneID_t, std::vector<art::Ptr<recob::Hit>>> planeHits;
95 
96  //Loop over the clusters in the plane and get the hits
97  for (auto const& cluster : clusters) {
98 
99  //Get the hits
100  std::vector<art::Ptr<recob::Hit>> hits = fmhc.at(cluster.key());
101 
102  //Get the plane.
103  const geo::PlaneID::PlaneID_t plane(cluster->Plane().Plane);
104 
105  planeHits[plane].insert(planeHits[plane].end(), hits.begin(), hits.end());
106  }
107 
108  // Calculate the energy for each plane && best plane
109  geo::PlaneID::PlaneID_t bestPlane = std::numeric_limits<geo::PlaneID::PlaneID_t>::max();
110  unsigned int bestPlaneNumHits = 0;
111 
112  //Holder for the final product
113  std::vector<double> energyVec(fNumPlanes, -999.);
114  std::vector<double> energyError(fNumPlanes, -999.);
115 
116  auto const clockData =
118  auto const detProp =
120 
121  for (auto const& [plane, hits] : planeHits) {
122 
123  unsigned int planeNumHits = hits.size();
124 
125  //Calculate the Energy for
126  double Energy = CalculateEnergy(clockData, detProp, hits, plane);
127  // If the energy is negative, leave it at -999
128  if (Energy > 0) energyVec.at(plane) = Energy;
129 
130  if (planeNumHits > bestPlaneNumHits) {
131  bestPlane = plane;
132  bestPlaneNumHits = planeNumHits;
133  }
134  }
135 
136  ShowerEleHolder.SetElement(energyVec, energyError, fShowerEnergyOutputLabel);
137  // Only set the best plane if it has some hits in it
138  if (bestPlane < fChannelMap.Nplanes()) {
139  // Need to cast as an int for legacy default of -999
140  // have to define a new variable as we pass-by-reference when filling
141  int bestPlaneVal(bestPlane);
142  ShowerEleHolder.SetElement(bestPlaneVal, fShowerBestPlaneOutputLabel);
143  }
144 
145  return 0;
146  }
147 
148  //Function to calculate the energy of a shower in a plane. Using a linear map between charge and Energy.
149  //Exactly the same method as the ShowerEnergyAlg.cxx. Thanks Mike.
151  const detinfo::DetectorPropertiesData& detProp,
153  const geo::PlaneID::PlaneID_t plane) const
154  {
155 
156  double totalCharge = 0, totalEnergy = 0;
157 
158  for (auto const& hit : hits) {
159  totalCharge += (hit->Integral() * std::exp((sampling_rate(clockData) * hit->PeakTime()) /
160  (detProp.ElectronLifetime() * 1e3)));
161  }
162 
163  totalEnergy = (totalCharge * fGradients.at(plane)) + fIntercepts.at(plane);
164 
165  return totalEnergy;
166  }
167 }
168 
#define DEFINE_ART_CLASS_TOOL(tool)
Definition: ToolMacros.h:42
ShowerLinearEnergy(const fhicl::ParameterSet &pset)
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
Declaration of signal hit object.
unsigned int PlaneID_t
Type for the ID number.
Definition: geo_types.h:365
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
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
geo::WireReadoutGeom const & fChannelMap
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.
int CalculateElement(const art::Ptr< recob::PFParticle > &pfparticle, art::Event &Event, reco::shower::ShowerElementHolder &ShowerElementHolder) override
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
Definition: StdUtils.h:120
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
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
const art::FindManyP< T1 > & GetFindManyP(const art::ValidHandle< std::vector< T2 >> &handle, const art::Event &evt, const art::InputTag &moduleTag)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33