All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShowerCalorimetry_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // 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 //
11 ////////////////////////////////////////////////////////////////////////
12 
13 #include "art/Framework/Core/EDProducer.h"
14 #include "art/Framework/Core/ModuleMacros.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "art/Framework/Principal/Handle.h"
17 #include "art/Framework/Principal/Run.h"
18 #include "art/Framework/Principal/SubRun.h"
19 #include "art/Framework/Services/Registry/ServiceHandle.h"
20 #include "canvas/Persistency/Common/FindManyP.h"
21 #include "canvas/Utilities/InputTag.h"
22 #include "fhiclcpp/ParameterSet.h"
23 #include "messagefacility/MessageLogger/MessageLogger.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 
49 class calo::ShowerCalorimetry : public art::EDProducer {
50 public:
51  explicit ShowerCalorimetry(fhicl::ParameterSet const& p);
52 
53 private:
54  void produce(art::Event& e) override;
55 
56  art::InputTag fShowerTag;
57  art::InputTag fSpacePointTag;
58  bool fSCE;
60 };
61 
62 calo::ShowerCalorimetry::ShowerCalorimetry(fhicl::ParameterSet const& p)
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 
73 void
75 {
76 
77  art::ServiceHandle<geo::Geometry> geom;
78 
79  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(e);
80  auto const detProp =
81  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(e, clockData);
82  auto const* sce = lar::providerFrom<spacecharge::SpaceChargeService>();
83 
84  //Make the container for the calo product to put onto the event.
85  auto caloPtr = std::make_unique<std::vector<anab::Calorimetry>>();
86  auto& caloVector = *caloPtr;
87 
88  //Make a container for the track<-->calo associations.
89  //One entry per track, with entry equal to index in calorimetry collection of associated object.
90  std::vector<size_t> assnShowerCaloVector;
91  auto associationPtr = std::make_unique<art::Assns<recob::Shower, anab::Calorimetry>>();
92 
93  auto showerHandle = e.getValidHandle<std::vector<recob::Shower>>(fShowerTag);
94 
95  //Turn it into a vector of art pointers
96  std::vector<art::Ptr<recob::Shower>> recoShowers;
97  art::fill_ptr_vector(recoShowers, showerHandle);
98 
99  //Also get the hits from all the showers
100  art::FindManyP<recob::Hit> findHitsFromShowers(showerHandle, e, fShowerTag);
101 
102  //Go through all of the reconstructed showers in the event
103  for (size_t i = 0; i < recoShowers.size(); ++i) {
104  auto& shower = recoShowers[i];
105 
106  int shower_index = shower.key();
107  MF_LOG_INFO("ShowerCalorimetry") << "Getting Calorimetry info for " << shower_index << "\n";
108 
109  //This wil be used in the calorimetry object later
110  float shower_length = shower->Length();
111  //Get the hits from this shower
112  auto const& hits = findHitsFromShowers.at(shower_index);
113 
114  art::FindManyP<recob::SpacePoint> spFromShowerHits(hits, e, fSpacePointTag);
115 
116  //Sort the hits by their plane
117  //This vector stores the index of each hit on each plane
118  std::vector<std::vector<size_t>> hit_indices_per_plane(geom->Nplanes());
119  for (size_t j = 0; j < hits.size(); ++j) {
120  hit_indices_per_plane[hits[j]->WireID().Plane].push_back(j);
121  }
122 
123  //Go through each plane and make calorimetry objects
124  for (size_t j = 0; j < geom->Nplanes(); ++j) {
125 
126  size_t hits_in_plane = hit_indices_per_plane[j].size();
127 
128  //Reserve vectors for each part of the calorimetry object
129  std::vector<float> dEdx(hits_in_plane);
130  std::vector<float> dQdx(hits_in_plane);
131  std::vector<float> pitch(hits_in_plane);
132 
133  //residual range, xyz, and deadwire default for now
134  std::vector<float> resRange(hits_in_plane, 0.);
135  std::vector<TVector3> xyz(hits_in_plane, TVector3(0., 0., 0.));
136  std::vector<float> deadwires(hits_in_plane, 0.);
137  std::vector<size_t> hitIndex(hits_in_plane);
138 
139  geo::PlaneID planeID;
140 
141  float kineticEnergy = 0.;
142 
143  for (size_t k = 0; k < hits_in_plane; ++k) {
144 
145  size_t hit_index = hit_indices_per_plane[j][k];
146  auto& theHit = hits[hit_index];
147  if (!planeID.isValid) { planeID = theHit->WireID(); }
148  hitIndex[k] = theHit.key();
149  float wire_pitch = geom->WirePitch(theHit->View());
150 
151  float theHit_Xpos = -999.;
152  float theHit_Ypos = -999.;
153  float theHit_Zpos = -999.;
154 
155  auto const& sp = spFromShowerHits.at(hit_index);
156  if (!sp.empty()) {
157  //only use first space point
158  theHit_Xpos = sp[0]->XYZ()[0];
159  theHit_Ypos = sp[0]->XYZ()[1];
160  theHit_Zpos = sp[0]->XYZ()[2];
161  }
162  else {
163  MF_LOG_INFO("ShowerCalorimetry")
164  << "no sp associated w/this hit ... we will skip this hit";
165  continue;
166  }
167 
168  TVector3 pos(theHit_Xpos, theHit_Ypos, theHit_Zpos);
169  //correct pitch for hit direction
170  float this_pitch = wire_pitch;
171  float angleToVert = geom->WireAngleToVertical(theHit->View(), theHit->WireID());
172  angleToVert -= 0.5 * ::util::pi<>();
173 
174  float cosgamma = std::abs(sin(angleToVert) * shower->Direction().Y() +
175  cos(angleToVert) * shower->Direction().Z());
176  if (cosgamma > 0) this_pitch /= cosgamma;
177  if (this_pitch < wire_pitch) this_pitch = wire_pitch;
178  pitch[k] = this_pitch;
179 
180  //Correct for SCE
181  if (fSCE && sce->EnableCalSpatialSCE()) {
182 
183  geo::Vector_t posOffsets = {0., 0., 0.};
184  geo::Vector_t dirOffsets = {0., 0., 0.};
185 
186  posOffsets = sce->GetCalPosOffsets(geo::Point_t(pos), theHit->WireID().TPC);
187 
188  //For now, use the shower direction from Pandora...a better idea?
189  dirOffsets =
190  sce->GetCalPosOffsets(geo::Point_t{pos.X() + this_pitch * shower->Direction().X(),
191  pos.Y() + this_pitch * shower->Direction().Y(),
192  pos.Z() + this_pitch * shower->Direction().Z()},
193  theHit->WireID().TPC);
194 
195  TVector3 dir_corr = {
196  this_pitch * shower->Direction().X() - dirOffsets.X() + posOffsets.X(),
197  this_pitch * shower->Direction().Y() + dirOffsets.Y() - posOffsets.Y(),
198  this_pitch * shower->Direction().Z() + dirOffsets.Z() - posOffsets.Z()};
199 
200  pitch[k] = dir_corr.Mag();
201  //correct position for SCE
202  theHit_Xpos -= posOffsets.X();
203  theHit_Ypos += posOffsets.Y();
204  theHit_Zpos += posOffsets.Z();
205  }
206  xyz[k].SetXYZ(theHit_Xpos, theHit_Ypos, theHit_Zpos);
207  resRange[k] = std::hypot(theHit_Xpos - shower->ShowerStart().X(),
208  theHit_Ypos - shower->ShowerStart().Y(),
209  theHit_Zpos - shower->ShowerStart().Z());
210 
211  dQdx[k] = theHit->Integral() / pitch[k];
212 
213  // Just for now, use dQdx for dEdx
214  // dEdx[k] = theHit->Integral() / this_pitch;
215  dEdx[k] = caloAlg.dEdx_AREA(clockData, detProp, *theHit, pitch[k]),
216 
217  kineticEnergy += dEdx[k];
218  }
219 
220  //Make a calo object in the vector
221  caloVector.emplace_back(kineticEnergy,
222  dEdx,
223  dQdx,
224  resRange,
225  deadwires,
226  shower_length,
227  pitch,
229  hitIndex,
230  planeID);
231 
232  //Place the shower index in the association object
233  assnShowerCaloVector.emplace_back(shower_index);
234  }
235  }
236 
237  //Make the associations for ART
238  for (size_t i = 0; i < assnShowerCaloVector.size(); i++) {
239  if (assnShowerCaloVector[i] == std::numeric_limits<size_t>::max()) continue;
240 
241  art::Ptr<recob::Shower> shower_ptr(showerHandle, assnShowerCaloVector[i]);
242  util::CreateAssn(e, caloVector, shower_ptr, *associationPtr, i);
243  }
244 
245  //Finish up: Put the objects into the event
246  e.put(std::move(caloPtr));
247  e.put(std::move(associationPtr));
248 }
249 
250 DEFINE_ART_MODULE(calo::ShowerCalorimetry)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double >, ROOT::Math::GlobalCoordinateSystemTag > Vector_t
Type for representation of momenta in 3D space.
Definition: geo_vectors.h:164
Utilities related to art service access.
Declaration of signal hit object.
pdgs p
Definition: selectors.fcl:22
The data type to uniquely identify a Plane.
Definition: geo_types.h:472
bool isValid
Whether this ID points to a valid element.
Definition: geo_types.h:211
ShowerCalorimetry(fhicl::ParameterSet const &p)
process_name shower
Definition: cheaterreco.fcl:51
void produce(art::Event &e) override
process_name can override from command line with o or output calo
Definition: pid.fcl:40
T abs(T value)
std::vector< Point_t > convertCollToPoint(std::vector< Point > const &coll)
Definition: TrackingTypes.h:55
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
Definition: PFPUtils.cxx:2687
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.
do i e
pdgs k
Definition: selectors.fcl:22
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:184
art framework interface to geometry description
auto const detProp