LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
ShowerReco_module.cc
Go to the documentation of this file.
1 //
3 // \file ShowerReco_module.cc
4 //
5 // biagio.rossi@lhep.unibe.ch (FWMK : argoslope.resize(fNPlanes);neut specific)
6 // thomas.strauss@lhep.unibe.ch (ART : general detector)
7 //
8 // andrzej.szelc@yale.edu (port to detector agnostic version)
9 // jasaadi@fnal.gov (Try to rewrite the code to make it more readable and to be able to handle
10 // multiple TPC's and cryostats and more than one cluster per plane.)
11 //
12 // This algorithm is designed to reconstruct showers
13 //
15 
16 // ### Generic C++ includes ###
17 #include <cmath> // std::tan() ...
18 #include <string>
19 #include <vector>
20 
21 // ### Framework includes ###
27 #include "art_root_io/TFileService.h"
31 #include "fhiclcpp/ParameterSet.h"
33 
34 // ### ROOT includes ###
35 #include "TMath.h"
36 #include "TTree.h"
37 
38 // ### LArSoft includes ###
54 
55 #include "range/v3/view.hpp"
56 
57 #include <cmath>
58 
59 namespace shwf {
60 
61  class ShowerReco : public art::EDProducer {
62  public:
63  explicit ShowerReco(fhicl::ParameterSet const& pset);
64 
65  private:
66  void beginJob();
67  void beginRun(art::Run& run);
68  void produce(art::Event& evt);
71  unsigned int plane); // Get shower vertex and slopes.
72 
73  void LongTransEnergy(geo::GeometryCore const* geom,
74  geo::WireReadoutGeom const& wireReadoutGeom,
75  detinfo::DetectorClocksData const& clockData,
76  detinfo::DetectorPropertiesData const& detProp,
77  unsigned int set,
78  std::vector<art::Ptr<recob::Hit>> hitlist); // Longitudinal
79 
80  void ClearandResizeVectors(unsigned int nPlanes);
81 
83  // input labels:
84  float slope[3]; // in cm, cm
85  float angle[3]; // in radians
86 
87  std::string fClusterModuleLabel;
88 
89  float ftimetick; // time sample in us
90 
91  double fMean_wire_pitch; // wire pitch in cm
93 
94  std::vector<double> fRMS_2cm;
95  std::vector<int> fNpoints_2cm;
96  std::vector<double> fCorr_MeV_2cm;
97  std::vector<double> fCorr_Charge_2cm;
98 
99  std::vector<int> fNpoints_corr_ADC_2cm;
100  std::vector<int> fNpoints_corr_MeV_2cm;
101 
102  std::vector<double> fTotChargeADC; //Total charge in ADC/cm for each plane
103  std::vector<double> fTotChargeMeV; //Total charge in MeV/cm for each plane
104  std::vector<double> fTotChargeMeV_MIPs; //Total charge in MeV/cm for each plane
105 
106  std::vector<double> fChargeADC_2cm; //Initial charge in ADC/cm for each plane first 4cm
107  std::vector<double> fChargeMeV_2cm; //initial charge in MeV/cm for each plane first 4cm
108 
109  std::vector<double> fChargeMeV_2cm_refined;
110  std::vector<double> fChargeMeV_2cm_axsum;
111 
112  std::vector<std::vector<double>> fDistribChargeADC; //vector with the first De/Dx points ADC
113  std::vector<std::vector<double>>
114  fDistribChargeMeV; //vector with the first De/Dx points converted energy
115  std::vector<std::vector<double>> fDistribHalfChargeMeV;
116  std::vector<std::vector<double>>
117  fDistribChargeposition; //vector with the first De/Dx points' positions
118 
119  std::vector<std::vector<double>> fSingleEvtAngle; //vector with the first De/Dx points
120  std::vector<std::vector<double>> fSingleEvtAngleVal; //vector with the first De/Dx points
121 
122  std::vector<unsigned int> fWire_vertex; // wire coordinate of vertex for each plane
123  std::vector<double> fTime_vertex; // time coordinate of vertex for each plane
124 
125  std::vector<double> fWire_vertexError; // wire coordinate of vertex for each plane
126  std::vector<double> fTime_vertexError; // time coordinate of vertex for each plane
127 
128  std::vector<unsigned int> fWire_last; // wire coordinate of last point for each plane
129  std::vector<double> fTime_last; // time coordinate of last point for each plane
130 
131  // reconstructed 3D position of shower start
132  std::vector<double> xyz_vertex_fit;
133 
134  std::vector<std::vector<double>>
135  fNPitch; // double array, to use each plane for each set of angles
136 
137  // calorimetry variables
138  float Kin_En;
139  std::vector<float> vdEdx;
140  std::vector<float> vresRange;
141  std::vector<float> vdQdx;
142  std::vector<float> deadwire; // residual range for dead wires
143  float Trk_Length;
144  float fTrkPitchC;
145  float fdEdxlength; // distance that gets used to determine e/gamma
146  // separation
147  float fcalodEdxlength; // cutoff distance for hits saved to the calo object.
148  bool fUseArea;
149 
150  double xphi, xtheta; // new calculated angles.
151  unsigned int fNPlanes; // number of planes
152  unsigned int fNAngles;
153  TTree* ftree_shwf;
154 
155  // conversion and useful constants
156  double fWirePitch; // wire pitch in cm
157  double fTimeTick;
160 
161  std::vector<int> fNhitsperplane;
162  std::vector<double> fTotADCperplane;
163  }; // class ShowerReco
164 
165  //------------------------------------------------------------------------------
167  {
168  fClusterModuleLabel = pset.get<std::string>("ClusterModuleLabel");
169  fCaloPSet = pset.get<fhicl::ParameterSet>("CaloAlg");
170 
171  fdEdxlength =
172  pset.get<double>("dEdxlength"); // distance that gets used to determine e/gamma separation
174  pset.get<double>("calodEdxlength"); // cutoff distance for hits saved to the calo object.
175  fUseArea = pset.get<bool>("UseArea");
176 
177  produces<std::vector<recob::Shower>>();
178  produces<art::Assns<recob::Shower, recob::Cluster>>();
179  produces<art::Assns<recob::Shower, recob::Hit>>();
180  produces<std::vector<anab::Calorimetry>>();
181  produces<art::Assns<recob::Shower, anab::Calorimetry>>();
182  }
183 
184  // ***************** //
186  {
189  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
190  fNPlanes = wireReadoutGeom.Nplanes();
191  fMean_wire_pitch = wireReadoutGeom.Plane({0, 0, 0}).WirePitch(); // wire pitch in cm
192 
193  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
194  ftimetick = sampling_rate(clockData) / 1000.;
195 
198 
199  ftree_shwf = tfs->make<TTree>("ShowerReco",
200  "Results");
201  ftree_shwf->Branch("run", &fRun, "run/I");
202  ftree_shwf->Branch("subrun", &fSubRun, "subrun/I");
203  ftree_shwf->Branch("event", &fEvent, "event/I");
204  ftree_shwf->Branch("nplanes", &fNPlanes, "nplanes/I");
205  ftree_shwf->Branch("nangles", &fNAngles, "nangles/I");
206  ftree_shwf->Branch("xtheta", &xtheta, "xtheta/D");
207  ftree_shwf->Branch("xphi", &xphi, "xphi/D");
208  ftree_shwf->Branch("ftotChargeADC", "std::vector<double>", &fTotChargeADC);
209  ftree_shwf->Branch("ftotChargeMeV", "std::vector<double>", &fTotChargeMeV);
210  ftree_shwf->Branch("fTotChargeMeV_MIPs", "std::vector<double>", &fTotChargeMeV_MIPs);
211  ftree_shwf->Branch("NPitch", "std::vector< std::vector<double> >", &fNPitch);
212 
213  // this should be temporary - until the omega is sorted out.
214  ftree_shwf->Branch("RMS_2cm", "std::vector<double>", &fRMS_2cm);
215  ftree_shwf->Branch("Npoints_2cm", "std::vector<int>", &fNpoints_2cm);
216  ftree_shwf->Branch("ChargeADC_2cm", "std::vector<double>", &fChargeADC_2cm);
217  ftree_shwf->Branch("ChargeMeV_2cm", "std::vector<double>", &fChargeMeV_2cm);
218  ftree_shwf->Branch("ChargeMeV_2cm_refined", "std::vector<double>", &fChargeMeV_2cm_refined);
219  ftree_shwf->Branch("ChargeMeV_2cm_axsum", "std::vector<double>", &fChargeMeV_2cm_axsum);
220  ftree_shwf->Branch("fNhitsperplane", "std::vector<int>", &fNhitsperplane);
221  ftree_shwf->Branch("fTotADCperplane", "std::vector<double>", &fTotADCperplane);
222  ftree_shwf->Branch(
223  "ChargedistributionADC", "std::vector<std::vector<double>>", &fDistribChargeADC);
224  ftree_shwf->Branch(
225  "ChargedistributionMeV", "std::vector<std::vector<double>>", &fDistribChargeMeV);
226  ftree_shwf->Branch(
227  "DistribHalfChargeMeV", "std::vector<std::vector<double>>", &fDistribHalfChargeMeV);
228  ftree_shwf->Branch(
229  "ChargedistributionPosition", "std::vector<std::vector<double>>", &fDistribChargeposition);
230  ftree_shwf->Branch("xyz_vertex_fit", "std::vector<double>", &xyz_vertex_fit);
231  }
232 
234  {
235  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
236  auto const detProp =
238 
240  ->Get()
241  .Plane({0, 0, 0})
242  .WirePitch(); // wire pitch in cm
243  fTimeTick = sampling_rate(clockData) / 1000.;
244  fDriftVelocity = detProp.DriftVelocity(detProp.Efield(), detProp.Temperature());
246  }
247 
248  void ShowerReco::ShowerReco::ClearandResizeVectors(unsigned int /*nPlanes*/)
249  {
250  //calculate factorial for number of angles
251  int fact = 1;
252  for (unsigned int i = 1; i <= fNPlanes; ++i)
253  fact *= i;
254 
255  fNAngles = fact / 2;
256 
257  fDistribChargeADC.clear();
258  fDistribChargeMeV.clear();
259  fDistribChargeposition.clear();
260 
261  fDistribChargeADC.resize(fNPlanes);
262  fDistribChargeMeV.resize(fNPlanes);
264 
265  fNPitch.clear();
266  fDistribChargeADC.clear();
267  fDistribChargeMeV.clear();
268  fDistribHalfChargeMeV.clear();
269  fDistribChargeposition.clear();
270 
271  fNPitch.resize(fNAngles);
272  fDistribChargeADC.resize(fNPlanes);
273  fDistribChargeMeV.resize(fNPlanes);
276 
277  for (unsigned int ii = 0; ii < fNAngles; ii++) {
278  fNPitch[ii].resize(fNPlanes, -1);
279  }
280 
281  fNpoints_corr_ADC_2cm.clear();
282  fNpoints_corr_MeV_2cm.clear();
283 
284  fNpoints_corr_ADC_2cm.resize(fNAngles, -1);
285  fNpoints_corr_MeV_2cm.resize(fNAngles, -1);
286 
287  for (unsigned int ii = 0; ii < fNPlanes; ii++) {
288  fDistribChargeADC[ii].resize(0); //vector with the first De/Dx points
289  fDistribChargeMeV[ii].resize(0); //vector with the first De/Dx points
290  fDistribHalfChargeMeV[ii].resize(0);
291  fDistribChargeposition[ii].resize(0); //vector with the first De/Dx points' positions
292  }
293 
294  fWire_vertex.clear();
295  fTime_vertex.clear();
296  fWire_vertexError.clear();
297  fTime_vertexError.clear();
298  fWire_last.clear();
299  fTime_last.clear();
300  fTotChargeADC.clear();
301  fTotChargeMeV.clear();
302  fTotChargeMeV_MIPs.clear();
303  fRMS_2cm.clear();
304  fNpoints_2cm.clear();
305 
306  fNhitsperplane.clear();
307  fTotADCperplane.clear();
308 
309  fWire_vertex.resize(fNAngles, -1);
310  fTime_vertex.resize(fNAngles, -1);
311  fWire_vertexError.resize(fNPlanes, -1);
312  fTime_vertexError.resize(fNPlanes, -1);
313  fWire_last.resize(fNAngles, -1);
314  fTime_last.resize(fNAngles, -1);
315  fTotChargeADC.resize(fNAngles, 0);
316  fTotChargeMeV.resize(fNAngles, 0);
317  fTotChargeMeV_MIPs.resize(fNAngles, 0);
318  fRMS_2cm.resize(fNAngles, 0);
319  fNpoints_2cm.resize(fNAngles, 0);
320 
321  fCorr_MeV_2cm.clear();
322  fCorr_Charge_2cm.clear();
323  xyz_vertex_fit.clear();
324 
325  fChargeADC_2cm.clear();
326  fChargeMeV_2cm.clear();
327  fChargeMeV_2cm_refined.clear();
328  fChargeMeV_2cm_refined.clear();
329  fChargeMeV_2cm_axsum.clear();
330 
331  fCorr_MeV_2cm.resize(fNAngles, 0);
332  fCorr_Charge_2cm.resize(fNAngles, 0);
333  xyz_vertex_fit.resize(3);
334 
335  fChargeADC_2cm.resize(fNAngles,
336  0); //Initial charge in ADC/cm for each plane angle calculation 4cm
337  fChargeMeV_2cm.resize(fNAngles,
338  0); //initial charge in MeV/cm for each angle calculation first 4cm
339  fChargeMeV_2cm_refined.resize(0);
340  fChargeMeV_2cm_refined.resize(fNAngles, 0);
341  fChargeMeV_2cm_axsum.resize(fNAngles, 0);
342 
343  fNhitsperplane.resize(fNPlanes, -1);
344  fTotADCperplane.resize(fNPlanes, -1);
345 
346  vdEdx.clear();
347  vresRange.clear();
348  vdQdx.clear();
349  }
350 
351  // ***************** //
353  {
354  auto const* geom = lar::providerFrom<geo::Geometry>();
355  auto const& wireReadoutGeom = art::ServiceHandle<geo::WireReadout const>()->Get();
356  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
357  auto const detProp =
359 
360  util::GeometryUtilities const gser{*geom, wireReadoutGeom, clockData, detProp};
361  constexpr geo::TPCID tpcid{0, 0};
362  fNPlanes = wireReadoutGeom.Nplanes(tpcid);
363  auto Shower3DVector = std::make_unique<std::vector<recob::Shower>>();
364  auto cassn = std::make_unique<art::Assns<recob::Shower, recob::Cluster>>();
365  auto hassn = std::make_unique<art::Assns<recob::Shower, recob::Hit>>();
366  auto calorimetrycol = std::make_unique<std::vector<anab::Calorimetry>>();
367  auto calassn = std::make_unique<art::Assns<anab::Calorimetry, recob::Shower>>();
368 
371  art::Handle<std::vector<recob::Cluster>> clusterListHandle;
372  evt.getByLabel(fClusterModuleLabel, clusterListHandle);
373 
375  evt.getByLabel(fClusterModuleLabel, clusterAssociationHandle);
376 
377  art::FindManyP<recob::Hit> fmh(clusterListHandle, evt, fClusterModuleLabel);
378 
379  fRun = evt.id().run();
380  fSubRun = evt.id().subRun();
381  fEvent = evt.id().event();
382 
383  // find all the hits associated to all the clusters (once and for all);
384  // the index of the query matches the index of the cluster in the collection
385  // (conveniently carried around in its art pointer)
386  art::FindManyP<recob::Hit> ClusterHits(clusterListHandle, evt, fClusterModuleLabel);
387 
388  std::vector<art::PtrVector<recob::Cluster>>::const_iterator clusterSet =
389  clusterAssociationHandle->begin();
390 
391  // loop over vector of vectors (each size of NPlanes) and reconstruct showers from each of those
392  for (size_t iClustSet = 0; iClustSet < clusterAssociationHandle->size(); iClustSet++) {
393 
394  const art::PtrVector<recob::Cluster> CurrentClusters = (*(clusterSet++));
395 
396  // do some error checking - i.e. are the clusters themselves present.
397  if (clusterListHandle->size() < 2 || CurrentClusters.size() < 2) {
398  ftree_shwf->Fill();
399  return;
400  }
401 
403 
404  std::vector<std::vector<art::Ptr<recob::Hit>>> hitlist_all;
405  hitlist_all.resize(fNPlanes);
406 
407  for (size_t iClust = 0; iClust < CurrentClusters.size(); iClust++) {
408  art::Ptr<recob::Cluster> const& pclust = CurrentClusters[iClust];
409 
410  // get all the hits for this cluster;
411  // pclust is a art::Ptr to the original cluster collection stored in the event;
412  // its key corresponds to its index in the collection
413  // (and therefore to the index in the query)
414  std::vector<art::Ptr<recob::Hit>> const& hitlist = ClusterHits.at(pclust.key());
415 
416  unsigned int p(0); //c=channel, p=plane, w=wire
417 
418  if (hitlist.size() == 0) continue;
419 
420  p = (*hitlist.begin())->WireID().Plane;
421  // get vertex position and slope information to start with - ii is the
422  // posistion of the correct cluster:
424 
425  double ADCcharge = 0;
426  //loop over cluster hits
427  for (art::Ptr<recob::Hit> const& hit : hitlist) {
428  p = hit->WireID().Plane;
429  hitlist_all[p].push_back(hit);
430  ADCcharge += hit->PeakAmplitude();
431  }
432  fNhitsperplane[p] = hitlist_all[p].size();
433  fTotADCperplane[p] = ADCcharge;
434  } // End loop on clusters.
435  // Now I have the Hitlists and the relevent clusters parameters saved.
436 
437  // find best set:
438  unsigned int bp1 = 0, bp2 = 0;
439  double minerror1 = 99999999, minerror2 = 9999999;
440  for (unsigned int ii = 0; ii < fNPlanes; ++ii) {
441  double locerror =
443  fTime_vertexError[ii] * fTime_vertexError[ii]; // time coordinate of vertex for each plane
444 
445  if (minerror1 >= locerror) // the >= sign is to favorize collection
446  {
447  minerror1 = locerror;
448  bp1 = ii;
449  }
450  }
451  for (unsigned int ij = 0; ij < fNPlanes; ++ij) {
452  double locerror =
454  fTime_vertexError[ij] * fTime_vertexError[ij]; // time coordinate of vertex for each plane
455 
456  if (minerror2 >= locerror && ij != bp1) {
457  minerror2 = locerror;
458  bp2 = ij;
459  }
460  }
461 
462  gser.Get3DaxisN(bp1, bp2, angle[bp1], angle[bp2], xphi, xtheta);
463 
465  std::vector<geo::Point_t> position;
466  position.reserve(fNPlanes);
467  // get starting positions for all planes -- FIXME: only position[0] is used.
468  for (auto const& plane : wireReadoutGeom.Iterate<geo::PlaneGeo>(tpcid)) {
469  position.push_back(plane.GetBoxCenter());
470  }
471 
472  // Assuming there is no problem ( and we found the best pair that comes
473  // close in time ) we try to get the Y and Z coordinates for the start of
474  // the shower.
475  double fTimeTick = sampling_rate(clockData) / 1000.;
476  double fDriftVelocity = detProp.DriftVelocity(detProp.Efield(), detProp.Temperature());
477  try {
478  int chan1 = wireReadoutGeom.PlaneWireToChannel({0, 0, bp1, fWire_vertex[bp1]});
479  int chan2 = wireReadoutGeom.PlaneWireToChannel({0, 0, bp2, fWire_vertex[bp2]});
480 
481  auto const intersection = wireReadoutGeom.ChannelsIntersect(chan1, chan2).value();
482  xyz_vertex_fit[1] = intersection.y;
483  xyz_vertex_fit[2] = intersection.z;
484  xyz_vertex_fit[0] =
485  (fTime_vertex[bp1] - trigger_offset(clockData)) * fDriftVelocity * fTimeTick +
486  position[0].X();
487  }
488  catch (cet::exception const& e) {
489  mf::LogWarning("ShowerReco") << "caught exception \n" << e;
490  xyz_vertex_fit[1] = 0;
491  xyz_vertex_fit[2] = 0;
492  xyz_vertex_fit[0] = 0;
493  }
494 
495  // if collection is not best plane, project starting point from that
496  if (bp1 != fNPlanes - 1 && bp2 != fNPlanes - 1) {
497  geo::PlaneID const lastPlaneID{0, 0, fNPlanes - 1};
498  auto const& plane = wireReadoutGeom.Plane(lastPlaneID);
499  auto pos = plane.GetBoxCenter();
500  pos.SetY(xyz_vertex_fit[1]);
501  pos.SetZ(xyz_vertex_fit[2]);
502  auto const wirevertex = plane.NearestWireID(pos).Wire;
503 
504  double drifttick =
505  (xyz_vertex_fit[0] / detProp.DriftVelocity(detProp.Efield(), detProp.Temperature())) *
506  (1. / fTimeTick);
507  fWire_vertex[fNPlanes - 1] = wirevertex; // wire coordinate of vertex for each plane
508  fTime_vertex[fNPlanes - 1] =
509  drifttick -
510  (pos.X() / detProp.DriftVelocity(detProp.Efield(), detProp.Temperature())) *
511  (1. / fTimeTick) +
512  trigger_offset(clockData);
513  }
514 
515  if (fabs(xphi) < 5.) {
516  xtheta = gser.Get3DSpecialCaseTheta(
517  bp1, bp2, fWire_last[bp1] - fWire_vertex[bp1], fWire_last[bp2] - fWire_vertex[bp2]);
518  }
519 
520  // zero the arrays just to make sure
521  for (unsigned int i = 0; i < fNAngles; ++i) {
522  fTotChargeADC[i] = 0;
523  fTotChargeMeV[i] = 0;
524  fTotChargeMeV_MIPs[i] = 0;
525  fNpoints_corr_ADC_2cm[i] = 0;
526  fNpoints_corr_MeV_2cm[i] = 0;
527 
528  fRMS_2cm[i] = 0;
529  fNpoints_2cm[i] = 0;
530 
531  fCorr_MeV_2cm[i] = 0;
532  fCorr_Charge_2cm[i] = 0;
533 
534  fChargeADC_2cm[i] = 0; //Initial charge in ADC/cm for each plane angle calculation 4cm
535  fChargeMeV_2cm[i] = 0; //initial charge in MeV/cm for each angle calculation first 4cm
536  }
537 
538  // do loop and choose Collection. With ful calorimetry can do all.
539  if (!(fabs(xphi) > 89 && fabs(xphi) < 91)) // do not calculate pitch for extreme angles
540  LongTransEnergy(geom,
541  wireReadoutGeom,
542  clockData,
543  detProp,
544  0,
545  hitlist_all[fNPlanes - 1]); // temporary only plane 2.
546 
548 
549  // make an art::PtrVector of the clusters
551  for (unsigned int i = 0; i < clusterListHandle->size(); ++i) {
552  art::Ptr<recob::Cluster> prod(clusterListHandle, i);
553  prodvec.push_back(prod);
554  }
555 
556  //create a singleSpacePoint at vertex.
557  std::vector<recob::SpacePoint> spcpts;
558 
559  //get direction cosines and set them for the shower
560  // TBD determine which angle to use for the actual shower
561  double fPhi = xphi;
562  double fTheta = xtheta;
563 
564  TVector3 dcosVtx(std::cos(fPhi * TMath::Pi() / 180) * std::sin(fTheta * TMath::Pi() / 180),
565  std::cos(fTheta * TMath::Pi() / 180),
566  std::sin(fPhi * TMath::Pi() / 180) * std::sin(fTheta * TMath::Pi() / 180));
569  // fill with bogus values for now
570  TVector3 dcosVtxErr(util::kBogusD, util::kBogusD, util::kBogusD);
571  recob::Shower singShower;
572  singShower.set_direction(dcosVtx);
573  singShower.set_direction_err(dcosVtxErr);
574 
575  Shower3DVector->push_back(singShower);
576  // associate the shower with its clusters
577  util::CreateAssn(evt, *Shower3DVector, prodvec, *cassn);
578 
579  // get the hits associated with each cluster and associate those with the shower
580  for (size_t p = 0; p < prodvec.size(); ++p) {
581  std::vector<art::Ptr<recob::Hit>> hits = fmh.at(p);
582  util::CreateAssn(evt, *Shower3DVector, hits, *hassn);
583  }
584 
585  geo::PlaneID planeID(0, 0, fNPlanes - 1);
586  calorimetrycol->emplace_back(
588 
590 
591  art::ProductID aid = evt.getProductID<std::vector<recob::Shower>>();
592  art::Ptr<recob::Shower> aptr(aid, 0, evt.productGetter(aid));
593  ssvec.push_back(aptr);
594 
595  util::CreateAssn(evt, *calorimetrycol, ssvec, *calassn);
596  ftree_shwf->Fill();
597  } // end loop on Vectors of "Associated clusters"
598 
599  evt.put(std::move(Shower3DVector));
600  evt.put(std::move(cassn));
601  evt.put(std::move(hassn));
602  evt.put(std::move(calorimetrycol));
603  evt.put(std::move(calassn));
604  }
605 
606  //------------------------------------------------------------------------------
608  geo::WireReadoutGeom const& wireReadoutGeom,
609  detinfo::DetectorClocksData const& clockData,
610  detinfo::DetectorPropertiesData const& detProp,
611  unsigned int set,
613  {
614  // alogorithm for energy vs dx of the shower (roto-translation) COLLECTION
615  // VIEW
616 
618 
619  double totCnrg = 0,
620  totCnrg_corr = 0; // tot enegry of the shower in collection
621 
622  double time;
623  unsigned int wire = 0, plane = fNPlanes - 1;
624 
625  double mevav2cm = 0.;
626  double npoints_calo = 0;
627 
628  int direction = -1;
629 
630  //override direction if phi (XZ angle) is less than 90 degrees
631  if (fabs(xphi) < 90) direction = 1;
632 
633  //variables to check whether a hit is close to the shower axis.
634  double ortdist, linedist;
635  double wire_on_line, time_on_line;
636 
637  //get effective pitch using 3D angles
638  util::GeometryUtilities const gser{*geom, wireReadoutGeom, clockData, detProp};
639  double newpitch = gser.PitchInView(plane, xphi, xtheta);
640 
641  using lar::to_element;
642  using ranges::views::transform;
643  for (auto const& hit : hitlist | transform(to_element)) {
644  time = hit.PeakTime();
645  wire = hit.WireID().Wire;
646  plane = hit.WireID().Plane;
647 
648  double dEdx_new;
649 
650  if (fUseArea) { dEdx_new = calalg.dEdx_AREA(clockData, detProp, hit, newpitch); }
651  else // this will hopefully go away, once all of the calibration factors
652  // are calculated.
653  {
654  dEdx_new = calalg.dEdx_AMP(clockData, detProp, hit, newpitch);
655  }
656 
657  //calculate total energy.
658  totCnrg_corr += dEdx_new;
659 
660  // calculate the wire,time coordinates of the hit projection on to the 2D shower axis
661  gser.GetPointOnLine(slope[plane] / fWireTimetoCmCm,
662  fWire_vertex[plane],
663  fTime_vertex[plane],
664  wire,
665  time,
666  wire_on_line,
667  time_on_line);
668  linedist =
669  gser.Get2DDistance(wire_on_line, time_on_line, fWire_vertex[plane], fTime_vertex[plane]);
670  ortdist = gser.Get2DDistance(wire_on_line, time_on_line, wire, time);
671 
672  //calculate the distance from the vertex using the effective pitch metric
673  double wdist = (((double)wire - (double)fWire_vertex[plane]) * newpitch) *
674  direction; //wdist is always positive
675 
676  if ((wdist < fcalodEdxlength) && (wdist > 0.2)) {
677 
678  vdEdx.push_back(dEdx_new);
679  vresRange.push_back(fabs(wdist));
680  vdQdx.push_back(hit.PeakAmplitude() / newpitch);
681  Trk_Length = wdist;
682  fTrkPitchC = fNPitch[set][plane];
683  Kin_En += dEdx_new * newpitch;
684  npoints_calo++;
685 
686  if (wdist < fdEdxlength &&
687  ((direction == 1 && wire > fWire_vertex[plane]) // take no hits before vertex
688  // (depending on direction)
689  || (direction == -1 && wire < fWire_vertex[plane])) &&
690  ortdist < 4.5 && linedist < fdEdxlength) {
691  fChargeMeV_2cm[set] += dEdx_new;
692  fNpoints_2cm[set]++;
693  }
694 
695  // fill out for 4cm preshower
696 
697  fDistribChargeMeV[set].push_back(dEdx_new); // vector with the first De/Dx points
698  fDistribChargeposition[set].push_back(
699  wdist); // vector with the first De/Dx points' positions
700 
701  } // end inside range if statement
702 
703  } // end first loop on hits.
704 
705  auto const signalType =
706  hitlist.empty() ? geo::kMysteryType : wireReadoutGeom.SignalType(hitlist.front()->WireID());
707 
708  if (signalType == geo::kCollection) {
709  fTotChargeADC[set] = totCnrg * newpitch;
710  fTotChargeMeV[set] = totCnrg_corr * newpitch;
711  }
712 
713  // calculate average dE/dx
714  if (fNpoints_2cm[set] > 0) { mevav2cm = fChargeMeV_2cm[set] / fNpoints_2cm[set]; }
715 
716  // second loop to calculate RMS
717  for (auto const& hit : hitlist | transform(to_element)) {
718  time = hit.PeakTime();
719  wire = hit.WireID().Wire;
720  plane = hit.WireID().Plane;
721  double dEdx = 0;
722 
723  if (fUseArea) { dEdx = calalg.dEdx_AREA(clockData, detProp, hit, newpitch); }
724  else // this will hopefully go away, once all of the calibration factors
725  // are calculated.
726  {
727  dEdx = calalg.dEdx_AMP(clockData, detProp, hit, newpitch);
728  }
729 
730  gser.GetPointOnLine(slope[plane] / fWireTimetoCmCm,
731  fWire_vertex[plane],
732  fTime_vertex[plane],
733  wire,
734  time,
735  wire_on_line,
736  time_on_line);
737  linedist =
738  gser.Get2DDistance(wire_on_line, time_on_line, fWire_vertex[plane], fTime_vertex[plane]);
739  ortdist = gser.Get2DDistance(wire_on_line, time_on_line, wire, time);
740 
741  double wdist = (((double)wire - (double)fWire_vertex[plane]) * newpitch) * direction;
742 
743  if ((wdist < fcalodEdxlength) && (wdist > 0.2)) {
744  if (wdist < fdEdxlength &&
745  ((direction == 1 && wire > fWire_vertex[plane]) ||
746  (direction == -1 && wire < fWire_vertex[plane])) &&
747  ortdist < 4.5 && linedist < fdEdxlength) {
748  fRMS_2cm[set] += (dEdx - mevav2cm) * (dEdx - mevav2cm);
749  }
750 
751  } // end if on correct hits.
752  } // end RMS_calculating loop.
753 
754  if (fNpoints_2cm[set] > 0) { fRMS_2cm[set] = TMath::Sqrt(fRMS_2cm[set] / fNpoints_2cm[set]); }
755 
757 
758  for (auto const& hit : hitlist | transform(to_element)) {
759  time = hit.PeakTime();
760  wire = hit.WireID().Wire;
761  plane = hit.WireID().Plane;
762 
763  double dEdx = 0;
764  if (fUseArea) { dEdx = calalg.dEdx_AREA(clockData, detProp, hit, newpitch); }
765  else // this will hopefully go away, once all of the calibration factors
766  // are calculated.
767  {
768  dEdx = calalg.dEdx_AMP(clockData, detProp, hit, newpitch);
769  }
770 
771  gser.GetPointOnLine(slope[plane] / fWireTimetoCmCm,
772  fWire_vertex[plane],
773  fTime_vertex[plane],
774  wire,
775  time,
776  wire_on_line,
777  time_on_line);
778  linedist =
779  gser.Get2DDistance(wire_on_line, time_on_line, fWire_vertex[plane], fTime_vertex[plane]);
780  ortdist = gser.Get2DDistance(wire_on_line, time_on_line, wire, time);
781 
782  double wdist = (((double)wire - (double)fWire_vertex[plane]) * newpitch) * direction;
783 
784  if ((wdist < fcalodEdxlength) && (wdist > 0.2 &&
785  ((direction == 1 && wire > fWire_vertex[plane]) ||
786  (direction == -1 && wire < fWire_vertex[plane])) &&
787  ortdist < 4.5 && linedist < fdEdxlength)) {
788  if (wdist < fdEdxlength) {
789  if (((dEdx > (mevav2cm - fRMS_2cm[set])) && (dEdx < (mevav2cm + fRMS_2cm[set]))) ||
790  (newpitch > 0.3 * fdEdxlength)) {
791  fCorr_MeV_2cm[set] += dEdx;
792  fNpoints_corr_MeV_2cm[set]++;
793  }
794 
795  } // end if on good hits
796  }
797  } // end of third loop on hits
798 
799  if (fNpoints_corr_MeV_2cm[set] > 0) {
802  }
803  }
804 
805  //------------------------------------------------------------------------------------//
807  // Get shower vertex and slopes.
808  {
809  // convert to cm/cm units needed in the calculation
810  angle[plane] = clust->StartAngle();
811  slope[plane] = std::tan(clust->StartAngle());
812  fWire_vertex[plane] = clust->StartWire();
813  fTime_vertex[plane] = clust->StartTick();
814 
815  fWire_vertexError[plane] = clust->SigmaStartWire(); // wire coordinate of vertex for each plane
816  fTime_vertexError[plane] = clust->SigmaStartTick(); // time coordinate of vertex for each plane
817 
818  fWire_last[plane] = clust->EndWire(); // wire coordinate of last point for each plane
819  fTime_last[plane] = clust->EndTick();
820  }
821 
823 }
std::vector< double > fTime_last
fhicl::ParameterSet fCaloPSet
std::vector< double > fWire_vertexError
ShowerReco(fhicl::ParameterSet const &pset)
std::vector< double > fTotChargeADC
std::vector< double > fCorr_Charge_2cm
void set_direction_err(const TVector3 &dir_e)
Definition: Shower.h:135
Utilities related to art service access.
constexpr to_element_t to_element
Definition: ToElement.h:25
Who knows?
Definition: geo_types.h:149
std::vector< int > fNhitsperplane
ProductID getProductID(std::string const &instance_name="") const
std::vector< std::vector< double > > fNPitch
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
std::vector< std::vector< double > > fDistribChargeMeV
float StartWire() const
Returns the wire coordinate of the start of the cluster.
Definition: Cluster.h:276
std::vector< int > fNpoints_corr_MeV_2cm
std::vector< std::vector< double > > fSingleEvtAngle
shower finding
std::vector< double > fTime_vertex
cout<< "Opened file "<< fin<< " ixs= "<< ixs<< endl;if(ixs==0) hhh=(TH1F *) fff-> Get("h1")
Definition: AddMC.C:8
float EndTick() const
Returns the tick coordinate of the end of the cluster.
Definition: Cluster.h:331
std::vector< double > fTotADCperplane
SigType_t SignalType(PlaneID const &pid) const
Returns the type of signal on the channels of specified TPC plane.
std::vector< unsigned int > fWire_last
std::vector< std::vector< double > > fDistribHalfChargeMeV
float StartAngle() const
Returns the starting angle of the cluster.
Definition: Cluster.h:461
std::vector< double > fChargeMeV_2cm_refined
std::vector< float > vdEdx
RunNumber_t run() const
Definition: EventID.h:98
void GetVertexAndAnglesFromCluster(art::Ptr< recob::Cluster > clust, unsigned int plane)
Definition: Run.h:37
std::vector< float > vdQdx
PutHandle< PROD > put(std::unique_ptr< PROD > &&edp, std::string const &instance={})
Definition: Event.h:77
std::vector< int > fNpoints_2cm
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:289
std::vector< double > fTime_vertexError
std::vector< std::vector< double > > fSingleEvtAngleVal
void hits()
Definition: readHits.C:15
void set_direction(const TVector3 &dir)
Definition: Shower.h:134
EDProductGetter const * productGetter(ProductID const pid) const
double dEdx_AMP(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:65
void LongTransEnergy(geo::GeometryCore const *geom, geo::WireReadoutGeom const &wireReadoutGeom, detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, unsigned int set, std::vector< art::Ptr< recob::Hit >> hitlist)
IDparameter< geo::WireID > WireID
Member type of validated geo::WireID parameter.
void push_back(Ptr< U > const &p)
Definition: PtrVector.h:435
std::vector< float > vresRange
Interface for a class providing readout channel mapping to geometry.
key_type key() const noexcept
Definition: Ptr.h:166
T get(std::string const &key) const
Definition: ParameterSet.h:314
Geometry information for a single wire plane.The plane is represented in the geometry by a solid whic...
Definition: PlaneGeo.h:67
std::vector< double > fRMS_2cm
void produce(art::Event &evt)
float SigmaStartWire() const
Returns the uncertainty on wire coordinate of the start of the cluster.
Definition: Cluster.h:296
The data type to uniquely identify a TPC.
Definition: geo_types.h:306
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:373
Description of the physical geometry of one entire detector.
Definition: GeometryCore.h:91
Declaration of cluster object.
float dEdx(detinfo::DetectorClocksData const &clockData, detinfo::DetectorPropertiesData const &detProp, const TCSlice &slc, TP3D &tp3d)
Definition: PFPUtils.cxx:2671
size_type size() const
Definition: PtrVector.h:302
Detector simulation of raw signals on wires.
std::vector< double > fCorr_MeV_2cm
std::string fClusterModuleLabel
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.
std::vector< double > xyz_vertex_fit
void beginRun(art::Run &run)
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Utility object to perform functions of association.
Encapsulate the construction of a single detector plane .
Contains all timing reference information for the detector.
std::vector< double > fChargeMeV_2cm
std::vector< double > fTotChargeMeV_MIPs
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
float SigmaStartTick() const
Returns the uncertainty on tick coordinate of the start of the cluster.
Definition: Cluster.h:305
std::vector< double > fChargeADC_2cm
double dEdx_AREA(detinfo::DetectorClocksData const &clock_data, detinfo::DetectorPropertiesData const &det_prop, recob::Hit const &hit, double pitch, double T0=0) const
std::vector< float > deadwire
int trigger_offset(DetectorClocksData const &data)
std::vector< std::vector< double > > fDistribChargeADC
EventNumber_t event() const
Definition: EventID.h:116
constexpr double kBogusD
obviously bogus double value
std::vector< double > fChargeMeV_2cm_axsum
void ClearandResizeVectors(unsigned int nPlanes)
TCEvent evt
Definition: DataStructs.cxx:8
Float_t e
Definition: plot.C:35
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
std::vector< int > fNpoints_corr_ADC_2cm
Float_t X
Definition: plot.C:37
std::vector< std::vector< double > > fDistribChargeposition
float StartTick() const
Returns the tick coordinate of the start of the cluster.
Definition: Cluster.h:287
std::vector< unsigned int > fWire_vertex
SubRunNumber_t subRun() const
Definition: EventID.h:110
EventID id() const
Definition: Event.cc:23
art framework interface to geometry description
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::vector< double > fTotChargeMeV
Signal from collection planes.
Definition: geo_types.h:148
float EndWire() const
Returns the wire coordinate of the end of the cluster.
Definition: Cluster.h:318