PDSPHitMonitor_module.cc
Go to the documentation of this file.
1 /////////////////////////////////////////////
2 // Hit Monitor Module //
3 // June 2018 //
4 // georgios.christodoulou <at> cern.ch //
5 /////////////////////////////////////////////
6 
7 #ifndef PDSPHitMonitor_module
8 #define PDSPHitMonitor_module
9 
10 // Framework includes
15 #include "art_root_io/TFileService.h"
19 #include "canvas/Persistency/Common/FindManyP.h"
20 #include "fhiclcpp/ParameterSet.h"
27 
28 // Data type includes
29 #include "lardataobj/RawData/raw.h"
31 
32 // ROOT includes
33 #include "TTree.h"
34 #include "TH1.h"
35 #include "TFile.h"
36 #include "TString.h"
37 #include "TProfile.h"
38 
39 // C++ Includes
40 #include <fstream>
41 #include <string>
42 #include <sstream>
43 #include <cmath>
44 #include <algorithm>
45 #include <iostream>
46 #include <vector>
47 
49 
51  public:
52 
53  explicit PDSPHitMonitorModule(fhicl::ParameterSet const& pset);
54  virtual ~PDSPHitMonitorModule();
55 
56  void beginJob();
57  void analyze(const art::Event& evt);
58  void reconfigure(fhicl::ParameterSet const & p);
59 
60  private:
62 
63  unsigned int fChansPerAPA;
64  unsigned int fNofAPA;
65 
66  unsigned int fUChanMin;
67  unsigned int fVChanMin;
68  unsigned int fUChanMax;
69  unsigned int fVChanMax;
70  unsigned int fZ0ChanMax;
71  unsigned int fZ0ChanMin;
72  unsigned int fZ1ChanMin;
73  unsigned int fZ1ChanMax;
74 
75  // Histograms
76  TH1I *fTotalNHits;
77  TH1F *fHitCharge;
78  TH1F *fHitRMS;
79  TH1F *fHitPeakTime;
80 
81  std::vector<TH1I*> fNHitsAPAViewU;
82  std::vector<TH1I*> fNHitsAPAViewV;
83  std::vector<TH1I*> fNHitsAPAViewZ;
84 
85  std::vector<TH1F*> fChargeAPAViewU;
86  std::vector<TH1F*> fChargeAPAViewV;
87  std::vector<TH1F*> fChargeAPAViewZ;
88 
89  std::vector<TH1F*> fRMSAPAViewU;
90  std::vector<TH1F*> fRMSAPAViewV;
91  std::vector<TH1F*> fRMSAPAViewZ;
92 
93  std::vector<TH1F*> fHitPeakTimeAPAViewU;
94  std::vector<TH1F*> fHitPeakTimeAPAViewV;
95  std::vector<TH1F*> fHitPeakTimeAPAViewZ;
96 
97  // Profiles
98  std::vector<TProfile*> fNHitsAPAViewU_prof;
99  std::vector<TProfile*> fNHitsAPAViewV_prof;
100  std::vector<TProfile*> fNHitsAPAViewZ_prof;
101 
102  std::vector<TProfile*> fChargeAPAViewU_prof;
103  std::vector<TProfile*> fChargeAPAViewV_prof;
104  std::vector<TProfile*> fChargeAPAViewZ_prof;
105 
106  std::vector<TProfile*> fRMSAPAViewU_prof;
107  std::vector<TProfile*> fRMSAPAViewV_prof;
108  std::vector<TProfile*> fRMSAPAViewZ_prof;
109 
111 
112  std::vector<unsigned int> fApaLabelNum;
113 
114  };
115 
116  //-----------------------------------------------------------------------
118 
119  fTPCHitTag = p.get<art::InputTag>("TPCHitTag", "a:b:c");
120 
121  }
122 
123  //-----------------------------------------------------------------------
125  this->reconfigure(pset);
126  }
127 
128  //-----------------------------------------------------------------------
130 
131  //-----------------------------------------------------------------------
133 
135 
136  // Accquiring geometry data
139  mf::LogVerbatim("HitMonitor") << " NTPCs = " << fGeom->NTPC() << " , Ncryostats = " << fGeom->Ncryostats() << " , NofAPA = " << fNofAPA << " , ChansPerAPA = " << fChansPerAPA << std::endl;
140 
141  // loop through channels in the first APA to find the channel boundaries for each view
142  // will adjust for desired APA after
143  fUChanMin = 0;
144  fVChanMin = 0;
145  fUChanMax = 0;
146  fVChanMax = 0;
147  fZ0ChanMax = 0;
148  fZ0ChanMin = 0;
149  fZ1ChanMin = 0;
150  fZ1ChanMax = fChansPerAPA - 1;
151  for(unsigned int c = fUChanMin + 1; c < fZ1ChanMax; c++){
152  if(fGeom->View(c) == geo::kV && fGeom->View(c-1) == geo::kU){
153  fVChanMin = c;
154  fUChanMax = c - 1;
155  }
156  if(fGeom->View(c) == geo::kZ && fGeom->View(c-1) == geo::kV){
157  fZ0ChanMin = c;
158  fVChanMax = c-1;
159  }
160  if(fGeom->View(c) == geo::kZ && fGeom->ChannelToWire(c)[0].TPC == fGeom->ChannelToWire(c-1)[0].TPC + 1){
161  fZ1ChanMin = c;
162  fZ0ChanMax = c-1;
163  }
164  }
165 
166  //unsigned int fNUCh=fUChanMax-fUChanMin+1;
167  //unsigned int fNVCh=fVChanMax-fVChanMin+1;
168  //unsigned int fNZ0Ch=fZ0ChanMax-fZ0ChanMin+1;
169  //unsigned int fNZ1Ch=fZ1ChanMax-fZ1ChanMin+1;
170 
171  //mf::LogVerbatim("HitMonitor") << " U: "<< fNUCh <<" V: "<< fNVCh << " Z0: "<< fNZ0Ch << " Z1: " << fNZ1Ch << std::endl;
172 
173  for(unsigned int i=0;i<fNofAPA;i++){
174 
175  unsigned int j=fApaLabelNum.at(i);
176 
177  unsigned int UChMin=fUChanMin + i*fChansPerAPA;
178  unsigned int UChMax=fUChanMax + i*fChansPerAPA;
179  unsigned int VChMin=fVChanMin + i*fChansPerAPA;
180  unsigned int VChMax=fVChanMax + i*fChansPerAPA;
181  unsigned int ZChMin=fZ0ChanMin + i*fChansPerAPA;
182  //unsigned int ZChMax=fZ0ChanMax + i*fChansPerAPA;
183  unsigned int ZChMax=fZ1ChanMax + i*fChansPerAPA; //including unused channels
184 
185  //std::cout<< "UCh: " << UChMin << " - " << UChMax << std::endl;
186  //std::cout<< "VCh: " << VChMin << " - " << VChMax << std::endl;
187  //std::cout<< "ZCh: " << ZChMin << " - " << ZChMax << std::endl;
188 
189  fNHitsAPAViewU.push_back(tfs->make<TH1I>(Form("NHitsAPA%d_U",j),Form("Number of hits APA%d-U",j),1000,0,20000));
190  fNHitsAPAViewV.push_back(tfs->make<TH1I>(Form("NHitsAPA%d_V",j),Form("Number of hits APA%d-V",j),1000,0,20000));
191  fNHitsAPAViewZ.push_back(tfs->make<TH1I>(Form("NHitsAPA%d_Z",j),Form("Number of hits APA%d-Z",j),1000,0,20000));
192 
193  fChargeAPAViewU.push_back(tfs->make<TH1F>(Form("HitChargeAPA%d_U",j),Form("Hit Charge APA%d-U",j),100,0,1500));
194  fChargeAPAViewV.push_back(tfs->make<TH1F>(Form("HitChargeAPA%d_V",j),Form("Hit Charge APA%d-V",j),100,0,1500));
195  fChargeAPAViewZ.push_back(tfs->make<TH1F>(Form("HitChargeAPA%d_Z",j),Form("Hit Charge APA%d-Z",j),100,0,1500));
196 
197  fRMSAPAViewU.push_back(tfs->make<TH1F>(Form("HitRMSAPA%d_U",j),Form("Hit RMS APA%d-U",j),100,0,10));
198  fRMSAPAViewV.push_back(tfs->make<TH1F>(Form("HitRMSAPA%d_V",j),Form("Hit RMS APA%d-V",j),100,0,10));
199  fRMSAPAViewZ.push_back(tfs->make<TH1F>(Form("HitRMSAPA%d_Z",j),Form("Hit RMS APA%d-Z",j),100,0,10));
200 
201  fHitPeakTimeAPAViewU.push_back(tfs->make<TH1F>(Form("HitPeakTimeAPA%d_U",j),Form("Hit Peak Time APA%d-U",j),100,0,10000));
202  fHitPeakTimeAPAViewV.push_back(tfs->make<TH1F>(Form("HitPeakTimeAPA%d_V",j),Form("Hit Peak Time APA%d-V",j),100,0,10000));
203  fHitPeakTimeAPAViewZ.push_back(tfs->make<TH1F>(Form("HitPeakTimeAPA%d_Z",j),Form("Hit Peak Time APA%d-Z",j),100,0,10000));
204 
205  // U view
206  fNHitsAPAViewU_prof.push_back(tfs->make<TProfile>(Form("fNHitsViewU%d_prof", j),Form("Number of hits distribution vs Channel(Plane U, APA%d)", j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5, "s"));
207  fChargeAPAViewU_prof.push_back(tfs->make<TProfile>(Form("fChargeViewU%d_prof", j),Form("Profiled Hit Charge distribution vs Channel(Plane U, APA%d)", j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5, "s"));
208  fRMSAPAViewU_prof.push_back(tfs->make<TProfile>(Form("fRMSViewU%d_prof", j),Form("Profiled Hit RMS distribution vs Channel(Plane U, APA%d)", j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5, "s"));
209 
210  // V view
211  fNHitsAPAViewV_prof.push_back(tfs->make<TProfile>(Form("fNHitsViewV%d_prof",j),Form("Number of hits distribution vs Channel(Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5, "s"));
212  fChargeAPAViewV_prof.push_back(tfs->make<TProfile>(Form("fChargeViewV%d_prof",j),Form("Profiled Hit Charge distribution vs Channel(Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5, "s"));
213  fRMSAPAViewV_prof.push_back(tfs->make<TProfile>(Form("fRMSViewV%d_prof",j),Form("Profiled Hit RMS distribution vs Channel(Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5, "s"));
214 
215  // Z view
216  fNHitsAPAViewZ_prof.push_back(tfs->make<TProfile>(Form("fNHitsViewZ%d_prof",j),Form("Number of hits distribution vs Channel(Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5, "s"));
217  fChargeAPAViewZ_prof.push_back(tfs->make<TProfile>(Form("fChargeViewZ%d_prof",j),Form("Profiled Hit Charge distribution vs Channel(Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5, "s"));
218  fRMSAPAViewZ_prof.push_back(tfs->make<TProfile>(Form("fRMSViewZ%d_prof",j),Form("Profiled Hit RMS distribution vs Channel(Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5, "s"));
219 
220  // Set titles
221  fNHitsAPAViewU[i]->GetXaxis()->SetTitle("NHits");
222  fNHitsAPAViewV[i]->GetXaxis()->SetTitle("NHits");
223  fNHitsAPAViewZ[i]->GetXaxis()->SetTitle("NHits");
224 
225  fChargeAPAViewU[i]->GetXaxis()->SetTitle("Charge (ADC units)");
226  fChargeAPAViewV[i]->GetXaxis()->SetTitle("Charge (ADC units)");
227  fChargeAPAViewZ[i]->GetXaxis()->SetTitle("Charge (ADC units)");
228 
229  fRMSAPAViewU[i]->GetXaxis()->SetTitle("Hit RMS");
230  fRMSAPAViewV[i]->GetXaxis()->SetTitle("Hit RMS");
231  fRMSAPAViewZ[i]->GetXaxis()->SetTitle("Hit RMS");
232 
233  fHitPeakTimeAPAViewU[i]->GetXaxis()->SetTitle("Hit Peak Time");
234  fHitPeakTimeAPAViewV[i]->GetXaxis()->SetTitle("Hit Peak Time");
235  fHitPeakTimeAPAViewZ[i]->GetXaxis()->SetTitle("Hit Peak Time");
236 
237  fNHitsAPAViewU_prof[i]->GetXaxis()->SetTitle("Channel ID"); fNHitsAPAViewU_prof[i]->GetYaxis()->SetTitle("NHits");
238  fNHitsAPAViewV_prof[i]->GetXaxis()->SetTitle("Channel ID"); fNHitsAPAViewV_prof[i]->GetYaxis()->SetTitle("NHits");
239  fNHitsAPAViewZ_prof[i]->GetXaxis()->SetTitle("Channel ID"); fNHitsAPAViewZ_prof[i]->GetYaxis()->SetTitle("NHits");
240 
241  fChargeAPAViewU_prof[i]->GetXaxis()->SetTitle("Channel ID"); fChargeAPAViewU_prof[i]->GetYaxis()->SetTitle("Charge (ADC units)");
242  fChargeAPAViewV_prof[i]->GetXaxis()->SetTitle("Channel ID"); fChargeAPAViewV_prof[i]->GetYaxis()->SetTitle("Charge (ADC units)");
243  fChargeAPAViewZ_prof[i]->GetXaxis()->SetTitle("Channel ID"); fChargeAPAViewZ_prof[i]->GetYaxis()->SetTitle("Charge (ADC units)");
244 
245  fRMSAPAViewU_prof[i]->GetXaxis()->SetTitle("Channel ID"); fRMSAPAViewU_prof[i]->GetYaxis()->SetTitle("Hit RMS");
246  fRMSAPAViewV_prof[i]->GetXaxis()->SetTitle("Channel ID"); fRMSAPAViewV_prof[i]->GetYaxis()->SetTitle("Hit RMS");
247  fRMSAPAViewZ_prof[i]->GetXaxis()->SetTitle("Channel ID"); fRMSAPAViewZ_prof[i]->GetYaxis()->SetTitle("Hit RMS");
248  }
249 
250  // Summary histograms from all APAs
251  fTotalNHits = tfs->make<TH1I>("fTotalNHits" ,"Total number of hits" ,1000,0,1000000);
252  fHitCharge = tfs->make<TH1F>("fHitCharge" ,"Hit Charge" ,100 ,0,1500);
253  fHitRMS = tfs->make<TH1F>("fHitChargeRMS" ,"Hit RMS" ,100 ,0,10);
254  fHitPeakTime = tfs->make<TH1F>("fHitPeakTime" ,"Hit Peak Time" ,100 ,0,10000);
255 
256  // Set titles
257  fTotalNHits->GetXaxis()->SetTitle("NHits");
258  fHitCharge->GetXaxis()->SetTitle("Charge (ADC units)");
259  fHitRMS->GetXaxis()->SetTitle("Hit RMS");
260  fHitPeakTime->GetXaxis()->SetTitle("Hit Peak Time");
261 
262  }
263 
264  //-----------------------------------------------------------------------
266 
267  // Many options here: gaushit, hitfd, linecluster, lineclusterdc, robusthit, fasthit, etc.
268  auto hitHandle = evt.getHandle<std::vector<recob::Hit> >(fTPCHitTag);
269  if (!hitHandle) {
270  mf::LogWarning("HitMonitor") << " Getting Hits FAIL: " << fTPCHitTag << std::endl;
271  return;
272  }
273 
274  std::vector<art::Ptr<recob::Hit> > hitlist;
275  art::fill_ptr_vector(hitlist, hitHandle);
276 
277  int NHits = hitlist.size();
278 
279  // Arrays ot store number of hits per APA
280  int NHitsPerApa[10][3];
281  for(unsigned int j=0; j<10; j++){
282  for(int k=0; k<3; k++){
283  NHitsPerApa[j][k] = 0;
284  }
285  }
286 
287  int NHitsChannel[20000];
288  for(unsigned int j=0; j<20000; j++){
289  NHitsChannel[j] = 0;
290  }
291 
292  mf::LogVerbatim("HitMonitor") << " Number of hits = " << NHits << std::endl;
293 
294  fTotalNHits->Fill(NHits);
295  for(int i=0; i<NHits; i++){
296  art::Ptr<recob::Hit> hit = hitlist[i];
297 
298  int hit_channel = hit->Channel();
299  unsigned int apa = std::floor(hit->WireID().TPC/2);
300  //unsigned int apa = std::floor(hit_channel/fChansPerAPA);
301 
302  // Protection
303  if(apa > fNofAPA){
304  mf::LogWarning("HitMonitor") << "APA number found (" << apa << ") larger than maximum (" << fNofAPA << "). Skipping hit!" << std::endl;
305  continue;
306  }
307 
308  float hit_charge = hit->Integral();
309  //float hit_chargeSigma = hit->SigmaIntegral();
310  float hit_rms = hit->RMS();
311  float hit_peakT = hit->PeakTime();
312  //float hit_wireID = hit->WireID().Wire;
313  int hit_plane = (int)hit->WireID().Plane;
314 
315  fHitCharge->Fill(hit_charge);
316  fHitRMS->Fill(hit_rms);
317  fHitPeakTime->Fill(hit_peakT);
318 
319  NHitsPerApa[apa][hit_plane]++;
320  NHitsChannel[hit_channel]++;
321 
322  if(hit_plane == 0){
323  fChargeAPAViewU[apa]->Fill(hit_charge);
324  fRMSAPAViewU[apa]->Fill(hit_rms);
325  fHitPeakTimeAPAViewU[apa]->Fill(hit_peakT);
326 
327  fChargeAPAViewU_prof[apa]->Fill(hit_channel, hit_charge, 1);
328  fRMSAPAViewU_prof[apa]->Fill(hit_channel, hit_rms, 1);
329  }
330  else if(hit_plane == 1){
331  fChargeAPAViewV[apa]->Fill(hit_charge);
332  fRMSAPAViewV[apa]->Fill(hit_rms);
333  fHitPeakTimeAPAViewV[apa]->Fill(hit_peakT);
334 
335  fChargeAPAViewV_prof[apa]->Fill(hit_channel, hit_charge, 1);
336  fRMSAPAViewV_prof[apa]->Fill(hit_channel, hit_rms, 1);
337  }
338  else if(hit_plane == 2){
339  fChargeAPAViewZ[apa]->Fill(hit_charge);
340  fRMSAPAViewZ[apa]->Fill(hit_rms);
341  fHitPeakTimeAPAViewZ[apa]->Fill(hit_peakT);
342 
343  fChargeAPAViewZ_prof[apa]->Fill(hit_channel, hit_charge, 1);
344  fRMSAPAViewZ_prof[apa]->Fill(hit_channel, hit_rms, 1);
345  }
346  }
347 
348  // Now fill th number of hits histograms
349  for(unsigned int j=0; j<fNofAPA; j++){
350  fNHitsAPAViewU[j]->Fill(NHitsPerApa[j][0]);
351  fNHitsAPAViewV[j]->Fill(NHitsPerApa[j][1]);
352  fNHitsAPAViewZ[j]->Fill(NHitsPerApa[j][2]);
353 
354  unsigned int UChMin=fUChanMin + j*fChansPerAPA;
355  unsigned int UChMax=fUChanMax + j*fChansPerAPA;
356  unsigned int VChMin=fVChanMin + j*fChansPerAPA;
357  unsigned int VChMax=fVChanMax + j*fChansPerAPA;
358  unsigned int ZChMin=fZ0ChanMin + j*fChansPerAPA;
359  //unsigned int ZChMax=fZ0ChanMax + j*fChansPerAPA;
360  unsigned int ZChMax=fZ1ChanMax + j*fChansPerAPA; //including unused channels
361 
362  for(unsigned int k=UChMin; k<UChMax; k++){
363  fNHitsAPAViewU_prof[j]->Fill(k, NHitsChannel[k], 1);
364  }
365 
366  for(unsigned int k=VChMin; k<VChMax; k++){
367  fNHitsAPAViewV_prof[j]->Fill(k, NHitsChannel[k], 1);
368  }
369 
370  for(unsigned int k=ZChMin; k<ZChMax; k++){
371  fNHitsAPAViewZ_prof[j]->Fill(k, NHitsChannel[k], 1);
372  }
373  }
374 
375  }
376 
377 } // namespace
378 
380 
381 #endif
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
PDSPHitMonitorModule(fhicl::ParameterSet const &pset)
Handle< PROD > getHandle(SelectorBase const &) const
Definition: DataViewImpl.h:382
Planes which measure V.
Definition: geo_types.h:130
geo::WireID WireID() const
Definition: Hit.h:233
float RMS() const
RMS of the hit shape, in tick units.
Definition: Hit.h:220
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
void reconfigure(fhicl::ParameterSet const &p)
Planes which measure Z direction.
Definition: geo_types.h:132
float Integral() const
Integral under the calibrated signal waveform of the hit, in tick x ADC units.
Definition: Hit.h:224
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
art framework interface to geometry description
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
Planes which measure U.
Definition: geo_types.h:129
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
T get(std::string const &key) const
Definition: ParameterSet.h:271
p
Definition: test.py:223
PlaneID_t Plane
Index of the plane within its TPC.
Definition: geo_types.h:493
Description of geometry of one entire detector.
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Definition of data types for geometry description.
Detector simulation of raw signals on wires.
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
float PeakTime() const
Time of the signal peak, in tick units.
Definition: Hit.h:218
Declaration of signal hit object.
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
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
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
Definition: Hit.h:230
QTextStream & endl(QTextStream &s)