All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GausHitFinderAna_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Gaus(s)HitFinder class designed to analyze signal on a wire in the TPC
4 //
5 // jaasaadi@syr.edu
6 //
7 // Note: This is a rework of the original hit finder ana module
8 // The only histograms that are saved are ones that can be used
9 // to make sure the hit finder is functioning...the rest is
10 // outputted to a TTree for offline analysis.
11 ////////////////////////////////////////////////////////////////////////
12 
13 // LArSoft includes
21 
22 // ROOT includes
23 #include "TH1.h"
24 #include "TH2.h"
25 #include "TTree.h"
26 
27 // C++ includes
28 #include <string>
29 
30 // Framework includes
31 #include "art/Framework/Core/EDAnalyzer.h"
32 #include "art/Framework/Core/ModuleMacros.h"
33 #include "art/Framework/Principal/Event.h"
34 #include "art/Framework/Principal/Handle.h"
35 #include "art/Framework/Services/Registry/ServiceHandle.h"
36 #include "art_root_io/TFileService.h"
37 #include "canvas/Persistency/Common/Ptr.h"
38 #include "fhiclcpp/ParameterSet.h"
39 #include "messagefacility/MessageLogger/MessageLogger.h"
40 
41 constexpr int kMaxHits = 20000;
42 
43 namespace hit {
44 
45  /// Base class for creation of raw signals on wires.
46  class GausHitFinderAna : public art::EDAnalyzer {
47  public:
48  explicit GausHitFinderAna(fhicl::ParameterSet const& pset);
49 
50  private:
51  void analyze(const art::Event& evt) override;
52  void beginJob() override;
53 
54  std::string fHitFinderModuleLabel;
55  std::string fLArG4ModuleLabel;
56  std::string fCalDataModuleLabel;
57 
62 
63  // ### TTree for offline analysis ###
64  TTree* fHTree;
65 
66  // === Event Information ===
67  Int_t fRun; // Run Number
68  Int_t fEvt; // Event Number
69 
70  // === Wire Information ====
71  Float_t fWireTotalCharge; // Charge on all wires
72 
73  // === Hit Information ===
74  Int_t fnHits; // Number of Hits in the Event
75  Int_t fWire[kMaxHits]; // Wire Number
76  Float_t fStartTime[kMaxHits]; // Start Time
77  Float_t fEndTime[kMaxHits]; // End Time
78  Float_t fPeakTime[kMaxHits]; // Peak Time
79  Float_t fPeakTimeUncert[kMaxHits]; // Peak Time Uncertainty
80  Float_t fCharge[kMaxHits]; // Charge of this hit
81  Float_t fChargeUncert[kMaxHits]; // Charge Uncertainty of this hit
82  Int_t fMultiplicity[kMaxHits]; // Hit pulse multiplicity
83  Float_t fGOF[kMaxHits]; // Goodness of Fit (Chi2/NDF)
84 
85  // === Total Hit Information ===
86  Float_t fTotalHitChargePerEvent; //Total charge recorded in each event
87 
88  // === Truth Hit Info from BackTrackerService ===
89  Float_t fTruePeakPos[kMaxHits]; // Truth Time Tick info from BackTrackerService
90 
91  }; // class GausHitFinderAna
92 
93  //-------------------------------------------------
94  GausHitFinderAna::GausHitFinderAna(fhicl::ParameterSet const& pset) : EDAnalyzer(pset)
95  {
96  fHitFinderModuleLabel = pset.get<std::string>("HitsModuleLabel");
97  fLArG4ModuleLabel = pset.get<std::string>("LArGeantModuleLabel");
98  fCalDataModuleLabel = pset.get<std::string>("CalDataModuleLabel");
99  }
100 
101  //-------------------------------------------------
102  void
104  {
105  art::ServiceHandle<art::TFileService const> tfs;
106  fHitResidualAll = tfs->make<TH1F>("fHitResidualAll", "Hit Residual All", 1600, -400, 400);
107  fHitResidualAllAlt = tfs->make<TH1F>("fHitResidualAllAlt", "Hit Residual All", 1600, -400, 400);
109  tfs->make<TH1F>("fNumberOfHitsPerEvent", "Number of Hits in Each Event", 10000, 0, 10000);
111  tfs->make<TH2F>("fPeakTimeVsWire", "Peak Time vs Wire Number", 3200, 0, 3200, 9500, 0, 9500);
112 
113  fHTree = tfs->make<TTree>("HTree", "HTree");
114  fHTree->Branch("Evt", &fEvt, "Evt/I");
115  fHTree->Branch("Run", &fRun, "Run/I");
116  fHTree->Branch("WireTotalCharge", &fWireTotalCharge, "WireTotalCharge/F");
117 
118  // === Hit Info ===
119  fHTree->Branch("nHits", &fnHits, "nHits/I");
120  fHTree->Branch("Wire", &fWire, "Wire[nHits]/I");
121  fHTree->Branch("StartTime", &fStartTime, "fStartTime[nHits]/F");
122  fHTree->Branch("EndTime", &fEndTime, "fEndTime[nHits]/F");
123  fHTree->Branch("PeakTime", &fPeakTime, "fPeakTime[nHits]/F");
124  fHTree->Branch("PeakTimeUncert", &fPeakTimeUncert, "fPeakTimeUncert[nHits]/F");
125  fHTree->Branch("Charge", &fCharge, "fCharge[nHits]/F");
126  fHTree->Branch("ChargeUncert", &fChargeUncert, "fChargeUncert[nHits]/F");
127  fHTree->Branch("Multiplicity", &fMultiplicity, "fMultiplicity[nHits]/I");
128  fHTree->Branch("GOF", &fGOF, "fGOF[nHits]/F");
129 
130  // === Total Hit Information ===
131  fHTree->Branch("TotalHitChargePerEvent", &fTotalHitChargePerEvent, "TotalHitChargePerEvent/F");
132 
133  // === Truth Hit Information from BackTrackerService ===
134  fHTree->Branch("TruePeakPos", &fTruePeakPos, "fTruePeakPos[nHits]/F");
135  }
136 
137  //-------------------------------------------------
138  void
139  GausHitFinderAna::analyze(const art::Event& evt)
140  {
141  // ### TTree Run/Event ###
142  fEvt = evt.id().event();
143  fRun = evt.run();
144 
145  art::ServiceHandle<geo::Geometry const> geom;
146  auto const clock_data =
147  art::ServiceHandle<detinfo::DetectorClocksService const>()->DataFor(evt);
148  auto const det_prop =
149  art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataFor(evt, clock_data);
150 
151  art::Handle<std::vector<recob::Wire>> wireVecHandle;
152  evt.getByLabel(fCalDataModuleLabel, wireVecHandle);
153 
154  // Charge directly from wire info
155  float TotWireCharge = 0;
156 
157  for (size_t wireIter = 0; wireIter < wireVecHandle->size(); wireIter++) {
158  art::Ptr<recob::Wire> wire(wireVecHandle, wireIter);
159  std::vector<float> signal(wire->Signal());
160 
161  for (auto timeIter = signal.begin(); timeIter + 2 < signal.end(); timeIter++) {
162 
163  if (*timeIter < 2) { continue; }
164 
165  TotWireCharge += *timeIter;
166  }
167  }
168 
169  fWireTotalCharge = TotWireCharge;
170 
171  // Reconstructed hit information
172  art::Handle<std::vector<recob::Hit>> hitHandle;
173  evt.getByLabel(fHitFinderModuleLabel, hitHandle);
174 
175  std::vector<art::Ptr<recob::Hit>> hits;
176  art::fill_ptr_vector(hits, hitHandle);
177 
178  float TotCharge = 0;
179  int hitCount = 0;
180  fnHits = hitHandle->size();
181  fNumberOfHitsPerEvent->Fill(hitHandle->size());
182 
183  for (size_t numHit = 0; numHit < hitHandle->size(); ++numHit) {
184  // === Finding Channel associated with the hit ===
185  art::Ptr<recob::Hit> hit(hitHandle, numHit);
186 
187  fWire[hitCount] = hit->WireID().Wire;
188  fStartTime[hitCount] = hit->PeakTimeMinusRMS();
189  fEndTime[hitCount] = hit->PeakTimePlusRMS();
190  fPeakTime[hitCount] = hit->PeakTime();
191  fPeakTimeUncert[hitCount] = hit->SigmaPeakTime();
192  fCharge[hitCount] = hit->Integral();
193  fChargeUncert[hitCount] = hit->SigmaIntegral();
194  fMultiplicity[hitCount] = hit->Multiplicity();
195  fGOF[hitCount] = hit->GoodnessOfFit();
196 
197  hitCount++;
198  TotCharge += hit->Integral();
199 
200  fPeakTimeVsWire->Fill(hit->WireID().Wire, hit->PeakTime());
201  } //<---End numHit
202  fTotalHitChargePerEvent = TotCharge;
203 
204  // Truth hit info from BackTracker
205 
206  unsigned int plane = 0;
207  Float_t TruthHitTime = 0, TruthHitCalculated = 0;
208  int count = 0;
209 
210  double time_tick = sampling_rate(clock_data) / 1000.;
211  double drift_velocity = det_prop.DriftVelocity(det_prop.Efield(), det_prop.Temperature());
212 
213  for (size_t nh = 0; nh < hitHandle->size(); nh++) {
214  // === Finding Channel associated with the hit ===
215  art::Ptr<recob::Hit> hitPoint(hitHandle, nh);
216  plane = hitPoint->WireID().Plane;
217 
218  // ===================================================================
219  // Using Track IDE's to locate the XYZ location from truth information
220  // ===================================================================
221  std::vector<sim::TrackIDE> trackides;
222  std::vector<double> xyz;
223  try {
224  art::ServiceHandle<cheat::BackTrackerService const> bt_serv;
225  trackides = bt_serv->HitToTrackIDEs(clock_data, hitPoint);
226  xyz = bt_serv->HitToXYZ(clock_data, hitPoint);
227  }
228  catch (cet::exception const&) {
229  mf::LogWarning("GausHitFinderAna") << "BackTrackerService Failed";
230  continue;
231  }
232 
233  // ==============================================================
234  // Calculating the truth tick position of the hit using 2 methods
235  // Method 1: ConvertXtoTicks from the detector properties package
236  // Method 2: Actually do the calculation myself to double check things
237  // ==============================================================
238 
239  // ### Method 1 ###
240  TruthHitTime = det_prop.ConvertXToTicks(
241  xyz[0], plane, hitPoint->WireID().TPC, hitPoint->WireID().Cryostat);
242 
243  // ### Method 2 ###
244  // ================================================
245  // Establishing the x-position of the current plane
246  // ================================================
247  const double origin[3] = {0.};
248  double pos[3];
249  geom->Plane(plane).LocalToWorld(origin, pos);
250  double planePos_timeCorr = (pos[0] / drift_velocity) * (1. / time_tick) + 60;
251  //<---x position of plane / drift velocity + 60 (Trigger offset)
252 
253  TruthHitCalculated = ((xyz[0]) / (drift_velocity * time_tick)) + planePos_timeCorr;
254 
255  fTruePeakPos[count] = TruthHitTime;
256  count++;
257  double hitresid = ((TruthHitTime - hitPoint->PeakTime()) / hitPoint->SigmaPeakTime());
258  fHitResidualAll->Fill(hitresid);
259 
260  double hitresidAlt =
261  ((TruthHitCalculated - hitPoint->PeakTime()) / hitPoint->SigmaPeakTime());
262  fHitResidualAllAlt->Fill(hitresidAlt);
263 
264  } //<---End nh loop
265 
266  fHTree->Fill();
267  } // end analyze method
268 
269  DEFINE_ART_MODULE(GausHitFinderAna)
270 
271 } // end of hit namespace
Declaration of signal hit object.
process_name hit
Definition: cheaterreco.fcl:51
Float_t fPeakTimeUncert[kMaxHits]
GausHitFinderAna(fhicl::ParameterSet const &pset)
Encapsulate the construction of a single detector plane.
Declaration of basic channel signal object.
Base class for creation of raw signals on wires.
art::ServiceHandle< art::TFileService > tfs
TCEvent evt
Definition: DataStructs.cxx:8
std::size_t count(Cont const &cont)
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
void analyze(const art::Event &evt) override
art framework interface to geometry description
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227