All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
icaruscode/icaruscode/CRT/CRTUtils/CRTHitRecoAlg.h
Go to the documentation of this file.
1 #ifndef CRTHITRECOALG_H_SEEN
2 #define CRTHITRECOALG_H_SEEN
3 ////////////////////////////////////////////////////////////////////
4 // CRTHitRecoAlg.h
5 //
6 // Functions for CRT hit reconstruction
7 // Chris Hilgenberg (Chris.Hilgenberg@colostate.edu), June 2020
8 ////////////////////////////////////////////////////////////////////
9 
10 // framework
11 #include "art/Framework/Principal/Event.h"
12 #include "art/Framework/Core/ModuleMacros.h"
13 #include "fhiclcpp/ParameterSet.h"
14 #include "art/Framework/Principal/Handle.h"
15 #include "canvas/Persistency/Common/Ptr.h"
16 #include "canvas/Persistency/Common/PtrVector.h"
17 #include "art/Framework/Services/Registry/ServiceHandle.h"
18 #include "art_root_io/TFileService.h"
19 #include "art_root_io/TFileDirectory.h"
20 #include "messagefacility/MessageLogger/MessageLogger.h"
21 #include "canvas/Persistency/Common/FindManyP.h"
23 
24 // LArSoft
31 
32 // Utility libraries
33 #include "messagefacility/MessageLogger/MessageLogger.h"
34 #include "fhiclcpp/ParameterSet.h"
35 #include "fhiclcpp/types/Table.h"
36 #include "fhiclcpp/types/Atom.h"
37 #include "cetlib/pow.h" // cet::sum_of_squares()
38 
39 //icaruscode includes
43 
47 // c++
48 #include <iostream>
49 #include <stdio.h>
50 #include <sstream>
51 #include <vector>
52 #include <map>
53 #include <utility>
54 #include <cmath>
55 #include <memory>
56 #include <cstdint>
57 // ROOT
58 #include "TVector3.h"
59 #include "TGeoManager.h"
60 
61 using std::vector;
62 using std::map;
63 using std::pair;
64 using std::string;
65 
66 namespace icarus::crt {
67  class CRTHitRecoAlg;
68  inline bool sortbytime(const pair<int,ULong64_t> &a,
69  const pair<int,ULong64_t> &b)
70  {
71  return (a.second < b.second);
72  }
73 }
74 
76 
77  public:
78 
81 
82  struct Config {
83  using Name = fhicl::Name;
84  using Comment = fhicl::Comment;
85  fhicl::Atom<bool> UseReadoutWindow {
86  Name("UseReadoutWindow"),
87  Comment("Only reconstruct hits within readout window")
88  };
89  fhicl::Atom<double> QPed {
90  Name("QPed"),
91  Comment("Pedestal offset [ADC]")
92  };
93  fhicl::Atom<double> QSlope {
94  Name("QSlope"),
95  Comment("Pedestal slope [ADC/photon]")
96  };
97  fhicl::Atom<bool> Verbose {
98  Name("Verbose"),
99  Comment("Output verbosity")
100  };
101  fhicl::Atom<bool> Data {
102  Name("Data"),
103  Comment("choose data/mc")
104  };
105  fhicl::Atom<bool> outCSVFile {
106  Name("outCSVFile"),
107  Comment("Output a csv file")
108  };
109  fhicl::Atom<std::string> CSVFile {
110  Name("CSVFile"),
111  Comment("file name for output CSV File")
112  };
113  fhicl::Atom<double> PropDelay {
114  Name("PropDelay"),
115  Comment("group velocity in WLS fiber [ns/cm]")
116  };
117  fhicl::Atom<double> PEThresh {
118  Name("PEThresh"),
119  Comment("threshold in photoelectrons above which charge amplitudes used in hit reco")
120  };
121  fhicl::Atom<double> topGain {
122  Name("topGain"),
123  Comment("Dummy Gain value for Top CRT")
124  };
125  fhicl::Atom<double> topPed {
126  Name("topPed"),
127  Comment("Dummy Pedestal value for Top CRT")
128  };
129  fhicl::Atom<uint64_t> SiPMtoFEBdelay {
130  Name("SiPMtoFEBdelay"),
131  Comment("Delay for SiPM to FEB signal correction 11.6 [ns]")
132  };
133  fhicl::Atom<uint64_t> CoinWindow {
134  Name("CoinWindow"),
135  Comment("window for finding side CRT trigger coincidences [ns]")
136  };
137  fhicl::Atom<uint64_t> CrtWindow {
138  Name("CrtWindow"),
139  Comment("window for looking data [ns]")
140  };
141  };//Config
142 
143  //constructors
144  CRTHitRecoAlg(const Config& config);
145  CRTHitRecoAlg(const fhicl::ParameterSet& pset) :
146  CRTHitRecoAlg{fhicl::Table<Config>{pset}()} {}
147  CRTHitRecoAlg();
148 
149  //configure module from fcl file
150  void reconfigure(const Config& config);
151 
152  //produce CRTHits with associated data indices from input vector of CRTData
153  vector<pair<CRTHit, vector<int>>> CreateCRTHits(vector<art::Ptr<CRTData>> crtList, uint64_t trigger_timestamp);
154 
155  //preselection based on charge in a CRTData
156  vector<art::Ptr<CRTData>> PreselectCRTData(const vector<art::Ptr<CRTData>> &crtList, uint64_t trigger_timestamp);
157 
158  // Function to make filling a CRTHit a bit faster
159  CRTHit FillCRTHit(vector<uint8_t> tfeb_id, map<uint8_t, vector<pair<int,float>>> tpesmap,
160  float peshit, uint64_t time0, Long64_t time1, int plane,
161  double x, double ex, double y, double ey, double z, double ez, string tagger);
162 
163 
164  private:
165 
167 
169 
170  //Params from fcl file
171  bool fVerbose; ///< print info
172  bool foutCSVFile; ///<FCL input: Write a CSV File?
173  std::string fCSVFile; ///<FCL input: file name for output CSV File
174  bool fUseReadoutWindow; ///< Only reconstruct hits within TPC readout window
175  double fQPed; ///< Pedestal offset of SiPMs [ADC]
176  double fQSlope; ///< Pedestal slope of SiPMs [ADC/photon]
177  double fPropDelay; ///< propegation time [ns/cm]
178  double fPEThresh; ///< threshold[PE] above which charge amplitudes used in hit reco
179  double ftopGain; ///< Dummy Top CRT Gain Value
180  double ftopPed; ///< Dummy Top CRT Pedestal Value
181  uint64_t fSiPMtoFEBdelay; ///< SiPM to FEB cable induced delay: 11.6 [ns]
182  uint64_t fCoinWindow; ///< Coincidence window used for grouping side CRT triggers [ns]
183  uint64_t fCrtWindow; ///< Looking data window within trigger timestamp [ns]
184  std::ofstream filecsv;
185  bool fData; ///< look for only data
187 
188  //Given top CRTData product, produce CRTHit
189  CRTHit MakeTopHit(art::Ptr<CRTData> data, ULong64_t GlobalTrigger[]);
190  //Given bottom CRTData product, produce CRTHit
191  CRTHit MakeBottomHit(art::Ptr<CRTData> data);
192  //Given vector of side CRTData products, produce CRTHit
193  CRTHit MakeSideHit(vector<art::Ptr<CRTData>> coinData, ULong64_t GlobalTrigger[]);
194  // Check if a hit is empty
195  bool IsEmptyHit(CRTHit hit);
196 
197  static bool compareBytime(art::Ptr<CRTData> const &a, art::Ptr<CRTData> const &b){
198  return a->fTs0 < b->fTs0;
199  }
200 }; //class CRTHitRecoAlg
201 
202 
203 namespace icarus::crt {
204  ULong64_t GetMode(std::vector<std::pair<int, ULong64_t>> vector);
205 
206  struct FEB_delay {
207  int HW_mac=-1;
208  int SW_mac=-1;
209  int SW_modID=-1;
210  ULong64_t T0_delay=0; //[ns]
211  ULong64_t T1_delay=0; //[ns]
212  };
213 
214  typedef int feb_index;
215  typedef std::map<feb_index, FEB_delay> CRT_delay_map;
216 
218 }
219 
220 
222 
223  CRT_delay_map FEBs;
224 
225  FEBs={{271, {81, 198, 271, 283ull, 2000309ull}},
226  {270, {119, 197, 270, 298ull, 2000324ull}},
227  {269, {87, 196, 269, 313ull, 2000339ull}},
228  {268, {92, 195, 268, 329ull, 2000355ull}},
229  {267, {180, 194, 267, 344ull, 2000370ull}},
230  {266, {97, 193, 266, 359ull, 2000385ull}},
231  {265, {174, 192, 265, 374ull, 2000400ull}},
232  {251, {238, 178, 251, 390ull, 2000416ull}},
233  {237, {234, 164, 237, 405ull, 2000431ull}},
234  {297, {189, 224, 297, 420ull, 2000446ull}},
235  {296, {190, 223, 296, 436ull, 2000462ull}},
236  {295, {80, 222, 295, 451ull, 2000477ull}},
237  {294, {162, 221, 294, 466ull, 2000492ull}},
238  {293, {64, 220, 293, 482ull, 2000508ull}},
239  {255, {172, 182, 255, 298ull, 2000324ull}},
240  {254, {114, 181, 254, 313ull, 2000339ull}},
241  {253, {100, 180, 253, 328ull, 2000355ull}},
242  {252, {150, 179, 252, 344ull, 2000370ull}},
243  {238, {176, 165, 238, 359ull, 2000385ull}},
244  {224, {67, 151, 224, 374ull, 2000400ull}},
245  {223, {138, 150, 223, 390ull, 2000416ull}},
246  {209, {170, 136, 209, 405ull, 2000431ull}},
247  {195, {101, 122, 195, 420ull, 2000446ull}},
248  {181, {142, 108, 181, 435ull, 2000462ull}},
249  {279, {139, 206, 279, 451ull, 2000477ull}},
250  {280, {185, 207, 280, 466ull, 2000492ull}},
251  {182, {6, 109, 182, 481ull, 2000508ull}},
252  {196, {177, 123, 196, 497ull, 2000523ull}},
253  {210, {61, 137, 210, 512ull, 2000538ull}},
254  {256, {123, 183, 256, 298ull, 2000325ull}},
255  {242, {116, 169, 242, 314ull, 2000340ull}},
256  {241, {104, 168, 241, 329ull, 2000355ull}},
257  {240, {91, 167, 240, 344ull, 2000371ull}},
258  {239, {88, 166, 239, 360ull, 2000386ull}},
259  {225, {120, 152, 225, 375ull, 2000401ull}},
260  {211, {132, 138, 211, 390ull, 2000417ull}},
261  {197, {95, 124, 197, 405ull, 2000432ull}},
262  {183, {232, 110, 183, 421ull, 2000447ull}},
263  {281, {165, 208, 281, 436ull, 2000463ull}},
264  {282, {148, 209, 282, 451ull, 2000478ull}},
265  {184, {237, 111, 184, 467ull, 2000493ull}},
266  {198, {102, 125, 198, 482ull, 2000508ull}},
267  {212, {94, 139, 212, 497ull, 2000524ull}},
268  {226, {130, 153, 226, 513ull, 2000539ull}},
269  {257, {181, 184, 257, 284ull, 2000310ull}},
270  {243, {124, 170, 243, 299ull, 2000325ull}},
271  {229, {152, 156, 229, 314ull, 2000341ull}},
272  {228, {98, 155, 228, 329ull, 2000356ull}},
273  {227, {173, 154, 227, 345ull, 2000371ull}},
274  {213, {169, 140, 213, 360ull, 2000387ull}},
275  {199, {144, 126, 199, 375ull, 2000402ull}},
276  {185, {239, 112, 185, 391ull, 2000417ull}},
277  {283, {147, 210, 283, 306ull, 2000433ull}},
278  {284, {105, 211, 284, 421ull, 2000448ull}},
279  {186, {231, 114, 186, 437ull, 2000463ull}},
280  {200, {117, 127, 200, 452ull, 2000478ull}},
281  {214, {126, 141, 214, 467ull, 2000494ull}},
282  {215, {90, 142, 215, 482ull, 2000509ull}},
283  {201, {183, 128, 201, 498ull, 2000524ull}},
284  {187, {241, 114, 187, 513ull, 2000540ull}},
285  {285, {113, 212, 285, 528ull, 2000555ull}},
286  {258, {233, 185, 258, 283ull, 2000310ull}},
287  {244, {164, 171, 244, 299ull, 2000325ull}},
288  {230, {161, 157, 230, 314ull, 2000341ull}},
289  {231, {203, 158, 231, 329ull, 2000356ull}},
290  {232, {122, 159, 232, 345ull, 2000371ull}},
291  {218, {2, 145, 218, 360ull, 2000387ull}},
292  {204, {112, 131, 204, 375ull, 2000402ull}},
293  {190, {62, 117, 190, 391ull, 2000417ull}},
294  {288, {133, 215, 288, 406ull, 2000432ull}},
295  {287, {168, 214, 287, 421ull, 2000448ull}},
296  {189, {182, 116, 189, 436ull, 2000463ull}},
297  {203, {107, 130, 203, 452ull, 2000478ull}},
298  {217, {252, 144, 217, 467ull, 2000494ull}},
299  {216, {141, 143, 216, 482ull, 2000509ull}},
300  {202, {160, 129, 202, 498ull, 2000524ull}},
301  {188, {137, 115, 188, 513ull, 2000540ull}},
302  {286, {179, 213, 286, 528ull, 2000555ull}},
303  {259, {66, 186, 259, 298ull, 2000325ull}},
304  {245, {247, 172, 245, 314ull, 2000340ull}},
305  {246, {198, 173, 246, 329ull, 2000356ull}},
306  {247, {243, 174, 247, 344ull, 2000371ull}},
307  {248, {72, 175, 248, 360ull, 2000386ull}},
308  {234, {250, 161, 234, 375ull, 2000401ull}},
309  {220, {249, 147, 220, 390ull, 2000417ull}},
310  {206, {248, 133, 206, 405ull, 2000432ull}},
311  {192, {60, 119, 192, 421ull, 2000447ull}},
312  {290, {145, 217, 290, 436ull, 2000463ull}},
313  {289, {110, 216, 289, 451ull, 2000478ull}},
314  {191, {59, 118, 191, 467ull, 2000493ull}},
315  {205, {202, 132, 205, 482ull, 2000509ull}},
316  {219, {135, 146, 219, 497ull, 2000524ull}},
317  {233, {246, 160, 233, 513ull, 2000539ull}},
318  {260, {253, 187, 260, 342ull, 2000369ull}},
319  {261, {245, 188, 261, 358ull, 2000384ull}},
320  {262, {65, 189, 262, 373ull, 2000400ull}},
321  {263, {57, 190, 263, 388ull, 2000415ull}},
322  {249, {63, 176, 249, 404ull, 2000430ull}},
323  {250, {251, 177, 250, 419ull, 2000445ull}},
324  {236, {70, 163, 236, 434ull, 2000461ull}},
325  {222, {155, 149, 222, 449ull, 2000476ull}},
326  {208, {154, 135, 208, 465ull, 2000491ull}},
327  {194, {85, 121, 194, 480ull, 2000507ull}},
328  {292, {134, 219, 292, 495ull, 2000522ull}},
329  {291, {129, 218, 291, 511ull, 2000537ull}},
330  {193, {115, 120, 193, 526ull, 2000553ull}},
331  {207, {204, 134, 207, 541ull, 2000568ull}},
332  {221, {244, 148, 221, 557ull, 2000583ull}},
333  {235, {82, 162, 235, 572ull, 2000598ull}},
334  {272, {186, 199, 272, 284ull, 2000310ull}},
335  {273, {83, 200, 273, 299ull, 2000326ull}},
336  {274, {254, 201, 274, 314ull, 2000341ull}},
337  {275, {166, 202, 275, 330ull, 2000356ull}},
338  {276, {178, 203, 276, 345ull, 2000371ull}},
339  {277, {136, 204, 277, 360ull, 2000387ull}},
340  {278, {184, 205, 278, 375ull, 2000402ull}},
341  {264, {187, 191, 264, 391ull, 2000417ull}},
342  {304, {240, 231, 304, 406ull, 2000433ull}},
343  {303, {242, 230, 303, 421ull, 2000448ull}},
344  {302, {188, 229, 302, 437ull, 2000463ull}},
345  {301, {58, 228, 301, 452ull, 2000479ull}},
346  {300, {143, 227, 300, 467ull, 2000494ull}},
347  {299, {235, 226, 299, 483ull, 2000509ull}}};
348  return FEBs;
349 }
350 
351 #endif
process_name opflash particleana ie ie ie z
double fQSlope
Pedestal slope of SiPMs [ADC/photon].
Functions to help with numbers.
CRTHit FillCRTHit(vector< uint8_t > tfeb_id, map< uint8_t, vector< pair< int, float >>> tpesmap, float peshit, uint64_t time0, Long64_t time1, int plane, double x, double ex, double y, double ey, double z, double ez, string tagger)
process_name opflash particleana ie x
Declaration of signal hit object.
This provides an art tool interface definition for tools handle the channel mapping The idea is to be...
std::string fCSVFile
FCL input: file name for output CSV File.
double fPEThresh
threshold[PE] above which charge amplitudes used in hit reco
process_name hit
Definition: cheaterreco.fcl:51
bool sortbytime(const pair< int, ULong64_t > &a, const pair< int, ULong64_t > &b)
static bool compareBytime(art::Ptr< CRTData > const &a, art::Ptr< CRTData > const &b)
uint64_t fSiPMtoFEBdelay
SiPM to FEB cable induced delay: 11.6 [ns].
vector< art::Ptr< CRTData > > PreselectCRTData(const vector< art::Ptr< CRTData >> &crtList, uint64_t trigger_timestamp)
process_name gaushit a
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
std::map< feb_index, FEB_delay > CRT_delay_map
Access the description of detector geometry.
uint64_t fCoinWindow
Coincidence window used for grouping side CRT triggers [ns].
object containing MC truth information necessary for making RawDigits and doing back tracking ...
process_name opflash particleana ie ie y
CRTHit MakeTopHit(art::Ptr< CRTData > data, ULong64_t GlobalTrigger[])
art framework interface to geometry description for auxiliary detectors
Single hit (self trigger) of a CRT board.
BEGIN_PROLOG vertical distance to the surface Name
Description of geometry of one entire detector.
Provides recob::Track data product.
bool fUseReadoutWindow
Only reconstruct hits within TPC readout window.
uint64_t fCrtWindow
Looking data window within trigger timestamp [ns].
CRTHit MakeSideHit(vector< art::Ptr< CRTData >> coinData, ULong64_t GlobalTrigger[])
process_name crt
art framework interface to geometry description
vector< pair< CRTHit, vector< int > > > CreateCRTHits(vector< art::Ptr< CRTData >> crtList, uint64_t trigger_timestamp)
ULong64_t GetMode(std::vector< std::pair< int, ULong64_t >> vector)