All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlashT0SelectedChannels_tool.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////
2 /// File: FlashT0SelectedChannels_tool.cc
3 ///
4 /// Base class: FlashT0Base.hh
5 ///
6 /// Algorithm description: it averages the OpHit times
7 /// for the photon detectors (PDs) containing a certain fraction (PDFraction)
8 /// of the integrated signal. Only OpHit in the interval
9 /// [FlashPeakTime-PreWindow, FlashPeakTime-PostWindow] and above
10 /// MinHitPE are taken into account
11 ///
12 /// Created by Fran Nicolas, June 2022
13 ////////////////////////////////////////////////////////////////////////
14 
15 #include "fhiclcpp/types/Atom.h"
16 #include "art/Utilities/ToolMacros.h"
17 #include "art/Utilities/make_tool.h"
18 #include "art/Utilities/ToolConfigTable.h"
19 
20 #include "FlashT0Base.hh"
21 
22 namespace lightana{
23 
25  {
26 
27  public:
28 
29  //Configuration parameters
30  struct Config {
31 
32  fhicl::Atom<double> PDFraction {
33  fhicl::Name("PDFraction"),
34  fhicl::Comment("Consider PDs containg a PDFraction of the signal.")
35  };
36 
37  fhicl::Atom<double> PreWindow {
38  fhicl::Name("PreWindow"),
39  fhicl::Comment("Consider OpHits in the interval [FlashPeakTime-PreWindow, FlashPeakTime-PostWindow]")
40  };
41 
42  fhicl::Atom<double> PostWindow {
43  fhicl::Name("PostWindow"),
44  fhicl::Comment("Consider OpHits in the interval [FlashPeakTime-PreWindow, FlashPeakTime-PostWindow]")
45  };
46 
47  fhicl::Atom<double> MinHitPE {
48  fhicl::Name("MinHitPE"),
49  fhicl::Comment("Minimum number of reconstructed PE to consider the OpHit for the t0 calculation")
50  };
51 
52  };
53 
54  // Default constructor
55  explicit FlashT0SelectedChannels(art::ToolConfigTable<Config> const& config);
56 
57  // Method to calculate the OpFlash t0
58  double GetFlashT0(double flash_peaktime, LiteOpHitArray_t ophit_list) override;
59 
60  private:
61 
62  double fPDFraction;
63  double fPreWindow;
64  double fPostWindow;
65  double fMinHitPE;
66 
67  };
68 
69  FlashT0SelectedChannels::FlashT0SelectedChannels(art::ToolConfigTable<Config> const& config)
70  : fPDFraction { config().PDFraction() },
71  fPreWindow { config().PreWindow() },
72  fPostWindow { config().PostWindow() },
73  fMinHitPE { config().MinHitPE() }
74  {
75  }
76 
77  double FlashT0SelectedChannels::GetFlashT0(double flash_time, LiteOpHitArray_t ophit_list){
78 
79  std::vector< std::pair<double, double> > selected_hits;
80  double pe_sum = 0;
81 
82  // fill vector with selected hits in the specified window
83  for(auto const& hit : ophit_list) {
84  if( hit.peak_time<flash_time+fPostWindow && hit.peak_time>flash_time-fPreWindow && hit.pe>fMinHitPE){
85  selected_hits.push_back( std::make_pair(hit.pe, hit.peak_time));
86  pe_sum += hit.pe ;
87  }
88  }
89 
90  if(pe_sum>0){
91  // sort vector by number of #PE (ascending order)
92  std::sort( selected_hits.begin(), selected_hits.end(), std::greater< std::pair<double, double> >() );
93 
94  double flasht0_mean=0, pe_count=0;
95  int nophits=0;
96 
97  // loop over selected ophits
98  for (size_t ix=0; ix<selected_hits.size(); ix++) {
99  pe_count += selected_hits[ix].first;
100  flasht0_mean += selected_hits[ix].second;
101  nophits++;
102  if( pe_count/pe_sum>fPDFraction ) break;
103  }
104 
105  return flasht0_mean/nophits;
106  }
107  else
108  return flash_time;
109  }
110 
111 }
112 
113 DEFINE_ART_CLASS_TOOL(lightana::FlashT0SelectedChannels)
process_name hit
Definition: cheaterreco.fcl:51
double GetFlashT0(double flash_peaktime, LiteOpHitArray_t ophit_list) override
std::vector< lightana::LiteOpHit_t > LiteOpHitArray_t
BEGIN_PROLOG vertical distance to the surface Name
FlashT0SelectedChannels(art::ToolConfigTable< Config > const &config)