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