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
36 #include "art_root_io/TFileService.h"
38 #include "fhiclcpp/ParameterSet.h"
40 
41 constexpr int kMaxHits = 20000;
42 
43 namespace hit {
44 
45  /// Base class for creation of raw signals on wires.
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 
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  //-------------------------------------------------
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  {
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
140  {
141  // ### TTree Run/Event ###
142  fEvt = evt.id().event();
143  fRun = evt.run();
144 
146  auto const clock_data =
148  auto const det_prop =
150 
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
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 {
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 
270 
271 } // end of hit namespace
constexpr int kMaxHits
PlaneGeo const & Plane(unsigned int const p, unsigned int const tpc=0, unsigned int const cstat=0) const
Returns the specified wire.
std::vector< sim::TrackIDE > HitToTrackIDEs(detinfo::DetectorClocksData const &clockData, recob::Hit const &hit) const
std::string string
Definition: nybbler.cc:12
geo::WireID WireID() const
Definition: Hit.h:233
float SigmaIntegral() const
Definition: Hit.h:225
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
WireID_t Wire
Index of the wire within its plane.
Definition: geo_types.h:580
std::vector< double > HitToXYZ(detinfo::DetectorClocksData const &clockData, const recob::Hit &hit) const
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
float GoodnessOfFit() const
Degrees of freedom in the determination of the hit signal shape (-1 by default)
Definition: Hit.h:228
short int Multiplicity() const
How many hits could this one be shared with.
Definition: Hit.h:226
art framework interface to geometry description
Float_t fPeakTimeUncert[kMaxHits]
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:633
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
GausHitFinderAna(fhicl::ParameterSet const &pset)
RunNumber_t run() const
Definition: DataViewImpl.cc:71
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
float PeakTimeMinusRMS(float sigmas=+1.) const
Definition: Hit.h:239
Detector simulation of raw signals on wires.
std::vector< float > Signal() const
Return a zero-padded full length vector filled with RoI signal.
Definition: Wire.cxx:47
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
Declaration of signal hit object.
Encapsulate the construction of a single detector plane.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
EventNumber_t event() const
Definition: EventID.h:116
Declaration of basic channel signal object.
Base class for creation of raw signals on wires.
float SigmaPeakTime() const
Uncertainty for the signal peak, in tick units.
Definition: Hit.h:219
float PeakTimePlusRMS(float sigmas=+1.) const
Returns a time sigmas RMS away from the peak time.
Definition: Hit.h:236
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
TPCID_t TPC
Index of the TPC within its cryostat.
Definition: geo_types.h:406
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
void LocalToWorld(const double *plane, double *world) const
Transform point from local plane frame to world frame.
Definition: PlaneGeo.h:1343
EventID id() const
Definition: Event.cc:34
void analyze(const art::Event &evt) override
constexpr Point origin()
Returns a origin position with a point of the specified type.
Definition: geo_vectors.h:227
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33