LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
ShowerCalorimetry_module.cc
Go to the documentation of this file.
1 // Class: ShowerCalorimetry
3 // Plugin Type: producer (art v3_02_06)
4 // File: ShowerCalorimetry_module.cc
5 // Authors: calcuttj@msu.edu
6 // ahiguera@Central.UH.EDU
7 // tjyang@fnal.gov
8 // Generated at Fri Jul 12 14:14:46 2019 by Jacob Calcutt using cetskelgen
9 // from cetlib version v3_07_02.
10 //
12 
22 #include "fhiclcpp/ParameterSet.h"
24 
38 
39 #include <TVector3.h>
40 
41 #include <memory>
42 #include <utility>
43 #include <vector>
44 
45 namespace calo {
46  class ShowerCalorimetry;
47 }
48 
50 public:
51  explicit ShowerCalorimetry(fhicl::ParameterSet const& p);
52 
53 private:
54  void produce(art::Event& e) override;
55 
58  bool fSCE;
60 };
61 
63  : EDProducer{p}
64  , fShowerTag(p.get<art::InputTag>("ShowerTag"))
65  , fSpacePointTag(p.get<art::InputTag>("SpacePointTag"))
66  , fSCE(p.get<bool>("CorrectSCE"))
67  , caloAlg(p.get<fhicl::ParameterSet>("CalorimetryAlg"))
68 {
69  produces<std::vector<anab::Calorimetry>>();
70  produces<art::Assns<recob::Shower, anab::Calorimetry>>();
71 }
72 
74 {
75  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout>()->Get();
76 
77  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
78  auto const detProp =
80  auto const* sce = lar::providerFrom<spacecharge::SpaceChargeService>();
81 
82  //Make the container for the calo product to put onto the event.
83  auto caloPtr = std::make_unique<std::vector<anab::Calorimetry>>();
84  auto& caloVector = *caloPtr;
85 
86  //Make a container for the track<-->calo associations.
87  //One entry per track, with entry equal to index in calorimetry collection of associated object.
88  std::vector<size_t> assnShowerCaloVector;
89  auto associationPtr = std::make_unique<art::Assns<recob::Shower, anab::Calorimetry>>();
90 
91  auto showerHandle = e.getValidHandle<std::vector<recob::Shower>>(fShowerTag);
92 
93  //Turn it into a vector of art pointers
94  std::vector<art::Ptr<recob::Shower>> recoShowers;
95  art::fill_ptr_vector(recoShowers, showerHandle);
96 
97  //Also get the hits from all the showers
98  art::FindManyP<recob::Hit> findHitsFromShowers(showerHandle, e, fShowerTag);
99 
100  //Go through all of the reconstructed showers in the event
101  for (size_t i = 0; i < recoShowers.size(); ++i) {
102  auto& shower = recoShowers[i];
103 
104  int shower_index = shower.key();
105  MF_LOG_INFO("ShowerCalorimetry") << "Getting Calorimetry info for " << shower_index << "\n";
106 
107  //This wil be used in the calorimetry object later
108  float shower_length = shower->Length();
109  //Get the hits from this shower
110  auto const& hits = findHitsFromShowers.at(shower_index);
111 
113 
114  //Sort the hits by their plane
115  //This vector stores the index of each hit on each plane
116  std::vector<std::vector<size_t>> hit_indices_per_plane(wireReadoutGeom.Nplanes());
117  for (size_t j = 0; j < hits.size(); ++j) {
118  hit_indices_per_plane[hits[j]->WireID().Plane].push_back(j);
119  }
120 
121  //Go through each plane and make calorimetry objects
122  for (size_t j = 0; j < wireReadoutGeom.Nplanes(); ++j) {
123 
124  size_t hits_in_plane = hit_indices_per_plane[j].size();
125 
126  //Reserve vectors for each part of the calorimetry object
127  std::vector<float> dEdx(hits_in_plane);
128  std::vector<float> dQdx(hits_in_plane);
129  std::vector<float> pitch(hits_in_plane);
130 
131  //residual range, xyz, and deadwire default for now
132  std::vector<float> resRange(hits_in_plane, 0.);
133  std::vector<TVector3> xyz(hits_in_plane, TVector3(0., 0., 0.));
134  std::vector<float> deadwires(hits_in_plane, 0.);
135  std::vector<size_t> hitIndex(hits_in_plane);
136 
137  geo::PlaneID planeID;
138 
139  float kineticEnergy = 0.;
140 
141  for (size_t k = 0; k < hits_in_plane; ++k) {
142 
143  size_t hit_index = hit_indices_per_plane[j][k];
144  auto& theHit = hits[hit_index];
145  if (!planeID.isValid) { planeID = theHit->WireID(); }
146  hitIndex[k] = theHit.key();
147  float wire_pitch = wireReadoutGeom.Plane({0, 0, theHit->View()}).WirePitch();
148 
149  float theHit_Xpos = -999.;
150  float theHit_Ypos = -999.;
151  float theHit_Zpos = -999.;
152 
153  auto const& sp = spFromShowerHits.at(hit_index);
154  if (!sp.empty()) {
155  //only use first space point
156  theHit_Xpos = sp[0]->XYZ()[0];
157  theHit_Ypos = sp[0]->XYZ()[1];
158  theHit_Zpos = sp[0]->XYZ()[2];
159  }
160  else {
161  MF_LOG_INFO("ShowerCalorimetry")
162  << "no sp associated w/this hit ... we will skip this hit";
163  continue;
164  }
165 
166  TVector3 pos(theHit_Xpos, theHit_Ypos, theHit_Zpos);
167  //correct pitch for hit direction
168  float this_pitch = wire_pitch;
169  float angleToVert = wireReadoutGeom.WireAngleToVertical(theHit->View(), theHit->WireID());
170  angleToVert -= 0.5 * ::util::pi<>();
171 
172  float cosgamma = std::abs(sin(angleToVert) * shower->Direction().Y() +
173  cos(angleToVert) * shower->Direction().Z());
174  if (cosgamma > 0) this_pitch /= cosgamma;
175  if (this_pitch < wire_pitch) this_pitch = wire_pitch;
176  pitch[k] = this_pitch;
177 
178  //Correct for SCE
179  if (fSCE && sce->EnableCalSpatialSCE()) {
180 
181  geo::Vector_t posOffsets = {0., 0., 0.};
182  geo::Vector_t dirOffsets = {0., 0., 0.};
183 
184  posOffsets = sce->GetCalPosOffsets(geo::Point_t(pos), theHit->WireID().TPC);
185 
186  //For now, use the shower direction from Pandora...a better idea?
187  dirOffsets =
188  sce->GetCalPosOffsets(geo::Point_t{pos.X() + this_pitch * shower->Direction().X(),
189  pos.Y() + this_pitch * shower->Direction().Y(),
190  pos.Z() + this_pitch * shower->Direction().Z()},
191  theHit->WireID().TPC);
192 
193  TVector3 dir_corr = {
194  this_pitch * shower->Direction().X() - dirOffsets.X() + posOffsets.X(),
195  this_pitch * shower->Direction().Y() + dirOffsets.Y() - posOffsets.Y(),
196  this_pitch * shower->Direction().Z() + dirOffsets.Z() - posOffsets.Z()};
197 
198  pitch[k] = dir_corr.Mag();
199  //correct position for SCE
200  theHit_Xpos -= posOffsets.X();
201  theHit_Ypos += posOffsets.Y();
202  theHit_Zpos += posOffsets.Z();
203  }
204  xyz[k].SetXYZ(theHit_Xpos, theHit_Ypos, theHit_Zpos);
205  resRange[k] = std::hypot(theHit_Xpos - shower->ShowerStart().X(),
206  theHit_Ypos - shower->ShowerStart().Y(),
207  theHit_Zpos - shower->ShowerStart().Z());
208 
209  dQdx[k] = theHit->Integral() / pitch[k];
210 
211  // Just for now, use dQdx for dEdx
212  // dEdx[k] = theHit->Integral() / this_pitch;
213  dEdx[k] = caloAlg.dEdx_AREA(clockData, detProp, *theHit, pitch[k]),
214 
215  kineticEnergy += dEdx[k];
216  }
217 
218  //Make a calo object in the vector
219  caloVector.emplace_back(kineticEnergy,
220  dEdx,
221  dQdx,
222  resRange,
223  deadwires,
224  shower_length,
225  pitch,
227  hitIndex,
228  planeID);
229 
230  //Place the shower index in the association object
231  assnShowerCaloVector.emplace_back(shower_index);
232  }
233  }
234 
235  //Make the associations for ART
236  for (size_t i = 0; i < assnShowerCaloVector.size(); i++) {
237  if (assnShowerCaloVector[i] == std::numeric_limits<size_t>::max()) continue;
238 
239  art::Ptr<recob::Shower> shower_ptr(showerHandle, assnShowerCaloVector[i]);
240  util::CreateAssn(e, caloVector, shower_ptr, *associationPtr, i);
241  }
242 
243  //Finish up: Put the objects into the event
244  e.put(std::move(caloPtr));
245  e.put(std::move(associationPtr));
246 }
247 
Utilities related to art service access.
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:160
Declaration of signal hit object.
EDProducer(fhicl::ParameterSet const &pset)
Definition: EDProducer.cc:6
The data type to uniquely identify a Plane.
Definition: geo_types.h:364
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:194
constexpr auto abs(T v)
Returns the absolute value of the argument.
ShowerCalorimetry(fhicl::ParameterSet const &p)
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
void produce(art::Event &e) override
void hits()
Definition: readHits.C:15
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
Definition: TrackingTypes.h:68
#define MF_LOG_INFO(category)
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
Definition: PFPUtils.cxx:2671
bool CreateAssn(art::Event &evt, std::vector< T > const &a, art::Ptr< U > const &b, art::Assns< U, T > &assn, std::string a_instance, size_t index=UINT_MAX)
Creates a single one-to-one association.
ROOT::Math::PositionVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Point_t
Type for representation of position in physical 3D space.
Definition: geo_vectors.h:180
ValidHandle< PROD > getValidHandle(InputTag const &tag) const
Utility object to perform functions of association.
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:306
Float_t e
Definition: plot.C:35
calorimetry