ToFClusterAlg.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <map>
5 #include <string>
6 
11 
12 namespace beamlinereco {
13 
14  struct ToFPulseCluster {
16  std::vector<art::Ptr<brb::BeamlineDigit>> pulses;
17  double time;
18  };
19 
20  class ToFClusterAlg {
21  public:
23  void Reset();
24 
25  void FindClusters(std::vector<art::Ptr<brb::BeamlineDigit>> digits, double clusterWindow);
26  std::vector<ToFPulseCluster> GetClusters(beamlinegeo::ToFCounter counter) const;
27 
28  private:
29  std::vector<ToFPulseCluster> _dsClusters;
30  std::vector<ToFPulseCluster> _usClusters;
31  std::vector<ToFPulseCluster> _sipmClusters;
33 
34  };
35 
37  _usClusters.clear();
38  _dsClusters.clear();
39  _sipmClusters.clear();
40  _clusterWindow = -999;
41  }
42 
43  void ToFClusterAlg::FindClusters(std::vector<art::Ptr<brb::BeamlineDigit>> digits, double clusterWindow) {
44  _clusterWindow = clusterWindow;
45 
46  for (auto d : digits) {
47  // Get correct cluster list for digit
48  std::vector<ToFPulseCluster> *clusters;
49  switch (d->ChannelID().Detector) {
50  case beamlinegeo::ToFCounter::US: clusters = &_usClusters; break;
51  case beamlinegeo::ToFCounter::DS: clusters = &_dsClusters; break;
52  case beamlinegeo::ToFCounter::DSSiPM: clusters = &_sipmClusters; break;
53  default: continue;
54  }
55  // Find cluster containing pulse (if any)
56  double starttime = d->StartTimeInNanoSec();
57  auto clusterit = std::find_if(clusters->begin(), clusters->end(),
58  [starttime,clusterWindow](ToFPulseCluster &cluster){
59  return fabs(starttime - cluster.time) < clusterWindow;
60  });
61 
62  if (clusterit == clusters->end()) { // Could not find one
63  // insert new cluster
64  ToFPulseCluster cluster;
65  cluster.time = starttime;
66  cluster.counter = beamlinegeo::ToFCounter(d->ChannelID().Detector);
67  cluster.pulses.push_back(d);
68  clusters->push_back(cluster);
69  } else { // Found cluster
70  clusterit->pulses.push_back(d);
71  }
72  }
73  }
74 
75  std::vector<ToFPulseCluster> ToFClusterAlg::GetClusters(beamlinegeo::ToFCounter counter) const {
76  switch(counter) {
77  case beamlinegeo::ToFCounter::US: return _usClusters;
78  case beamlinegeo::ToFCounter::DS: return _dsClusters;
79  case beamlinegeo::ToFCounter::DSSiPM: return _sipmClusters;
81  << "Bad time of flight counter: " << counter << "." << std::endl;
82  }
83  }
84 }
std::vector< ToFPulseCluster > GetClusters(beamlinegeo::ToFCounter counter) const
Definition: ToFClusterAlg.h:75
std::vector< ToFPulseCluster > _usClusters
Definition: ToFClusterAlg.h:30
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
void FindClusters(std::vector< art::Ptr< brb::BeamlineDigit >> digits, double clusterWindow)
Definition: ToFClusterAlg.h:43
Definition of the beamline offline geometry. Also implementation of a service to obtain this informat...
Encapsulation of reconstructed digitizer &#39;hits&#39;. Used for ToF PMTs and SiPMs, and Cherenkov and Muon ...
void Reset()
Float_t d
Definition: plot.C:236
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< ToFPulseCluster > _dsClusters
Definition: ToFClusterAlg.h:29
std::vector< art::Ptr< brb::BeamlineDigit > > pulses
Definition: ToFClusterAlg.h:16
std::vector< ToFPulseCluster > _sipmClusters
Definition: ToFClusterAlg.h:31
Definition: fwd.h:28
beamlinegeo::ToFCounter counter
Definition: ToFClusterAlg.h:15