TimeOfFlightReco_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TimeOfFlightReco
3 // Plugin Type: producer (art v2_12_01)
4 // File: TimeOfFlightReco_module.cc
5 //
6 // Generated at Mon Jun 3 11:11:10 2019 by Aidan Medcalf using cetskelgen
7 // from cetlib version v3_06_00.
8 //
9 // Description: ToF reco from BeamlineDigits
10 ////////////////////////////////////////////////////////////////////////
11 
12 // framework
19 #include "fhiclcpp/ParameterSet.h"
20 
21 // nova
23 #include "BeamlineRecoBase/ToF.h"
26 #include "Utilities/AssociationUtil.h"
27 
28 // stl
29 #include <iostream>
30 #include <memory>
31 
32 namespace beamlinereco {
33 
35  public:
36  explicit TimeOfFlightReco(fhicl::ParameterSet const &p);
37 
38  void reconfigure(const fhicl::ParameterSet &p);
39  void produce(art::Event &e) override;
40 
41  private:
42 
47 
48  double calculateTime(ToFPulseCluster c, std::string method) const;
49  double calculateTimeOfFlight(double ustime, double dstime) const;
50  };
51 
52 }
53 
54 // Calculate single time for a cluster
56  if (c.pulses.size() == 0) {
57  return std::numeric_limits<double>::quiet_NaN();
58  }
59 
60  double t = std::numeric_limits<double>::quiet_NaN();
61 
62  if (method == "Mean") {
63  t = 0;
64  for (auto p : c.pulses) { t += p->StartTimeInNanoSec(); }
65  t = t / (double(c.pulses.size()));
66 
67  } else if (method == "First") {
68  auto d = *std::min_element(c.pulses.begin(), c.pulses.end(),
70  return p1->StartTimeInNanoSec() < p2->StartTimeInNanoSec();
71  });
72  t = d->StartTimeInNanoSec();
73 
74  } else {
76  << "Unknown time of flight cluster time calculation method: " << method << "." << std::endl;
77  }
78 
79  return t;
80 }
81 
82 // Calculate time of flight
83 double beamlinereco::TimeOfFlightReco::calculateTimeOfFlight(double ustime, double dstime) const {
84  return dstime - ustime;
85 }
86 
88 {
89  produces<std::vector<brb::ToF>>();
90  produces<art::Assns<brb::ToF, brb::BeamlineDigit>>();
91 
92  reconfigure(p);
93 }
94 
96  fBeamlineToFDataLabel = p.get<art::InputTag>("BeamlineToFDataLabel");
97  fHitClusterWindow = p.get<double>("HitClusterWindow", 10);
98  fUseSiPMForDS = p.get<bool>("UseSiPMForDS", false);
99  fClusterTimeMethod = p.get<std::string>("ClusterTimeMethod", "First");
100 }
101 
103 {
104  // Producer
105  std::unique_ptr<std::vector<brb::ToF>>
106  tof_reco(new std::vector<brb::ToF>);
107  std::unique_ptr<art::Assns<brb::ToF, brb::BeamlineDigit>>
109 
110  // Get ToF digits
112  std::vector<art::Ptr<brb::BeamlineDigit>> digits;
113  if (e.getByLabel(fBeamlineToFDataLabel, digitHandle))
114  art::fill_ptr_vector(digits, digitHandle);
115 
116  // Find clusters
117  ToFClusterAlg clusterAlg;
118  clusterAlg.FindClusters(digits, fHitClusterWindow);
119 
120  std::vector<ToFPulseCluster> usclusters = clusterAlg.GetClusters(beamlinegeo::ToFCounter::US);
121  std::vector<ToFPulseCluster> dsclusters = clusterAlg.GetClusters(beamlinegeo::ToFCounter::DS);
122  std::vector<ToFPulseCluster> sipmclusters = clusterAlg.GetClusters(beamlinegeo::ToFCounter::DSSiPM);
123 
124  std::vector<ToFPulseCluster> dscounterclusters = dsclusters;
125  if (fUseSiPMForDS) dscounterclusters = sipmclusters;
126 
127  // Make tofs
128  for (auto usc : usclusters) {
129  for (auto dsc : dscounterclusters) {
130  double ustime = calculateTime(usc, fClusterTimeMethod);
131  double dstime = calculateTime(dsc, fClusterTimeMethod);
132  double time = calculateTimeOfFlight(ustime, dstime);
133  if (time > 0) {
134  brb::ToF tof;
135  tof.SetTimestamps(std::make_pair(ustime, dstime));
136  tof.SetTime(time);
137  tof_reco->push_back(tof);
138  util::CreateAssn(*this, e, *(tof_reco.get()), usc.pulses, *(tof_assn.get()), tof_reco->size()-1);
139  util::CreateAssn(*this, e, *(tof_reco.get()), dsc.pulses, *(tof_assn.get()), tof_reco->size()-1);
140  }
141  }
142  }
143 
144  e.put(std::move(tof_reco));
145  e.put(std::move(tof_assn));
146 }
147 
static bool CreateAssn(art::EDProducer const &prod, art::Event &evt, std::vector< T > &a, art::Ptr< U > b, art::Assns< T, U > &assn, size_t indx=UINT_MAX, std::string const &instance=std::string())
Create a 1 to 1 association between a new product and one already in the event.
std::vector< ToFPulseCluster > GetClusters(beamlinegeo::ToFCounter counter) const
Definition: ToFClusterAlg.h:75
void SetTimestamps(std::pair< float, float > timestamps)
Definition: ToF.cxx:47
const char * p
Definition: xmltok.h:285
void SetTime(float time)
Definition: ToF.cxx:41
double StartTimeInNanoSec() const
void FindClusters(std::vector< art::Ptr< brb::BeamlineDigit >> digits, double clusterWindow)
Definition: ToFClusterAlg.h:43
std::pair< Spectrum *, CheatDecomp * > make_pair(SpectrumLoaderBase &loader_data, SpectrumLoaderBase &loader_mc, HistAxis *axis, Cut *cut, const SystShifts &shift, const Var &wei)
Definition: DataMCLoad.C:336
Definition of the beamline offline geometry. Also implementation of a service to obtain this informat...
DEFINE_ART_MODULE(TestTMapFile)
TimeOfFlightReco(fhicl::ParameterSet const &p)
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
void reconfigure(const fhicl::ParameterSet &p)
Encapsulation of reconstructed digitizer &#39;hits&#39;. Used for ToF PMTs and SiPMs, and Cherenkov and Muon ...
Definition: ToF.h:25
void produce(art::Event &e) override
T get(std::string const &key) const
Definition: ParameterSet.h:231
Encapsulation of reconstructed Time-of-Flight (ToF) information. Part of beamline reconstruction for ...
Float_t d
Definition: plot.C:236
double calculateTime(ToFPulseCluster c, std::string method) const
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
Definition: DataViewImpl.h:344
std::vector< art::Ptr< brb::BeamlineDigit > > pulses
Definition: ToFClusterAlg.h:16
double calculateTimeOfFlight(double ustime, double dstime) const
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:464
Float_t e
Definition: plot.C:35
Definition: fwd.h:28
size_t size() const