TpcMonitor_module.cc
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Class: TpcMonitor_module
4 // Module type: analyzer
5 // File: TpcMonitor_module.cc
6 // Author: Jingbo Wang (jiowang@ucdavis.edu), February 2018. Modifications by Tom Junk
7 //
8 // Modification: Maggie Greenwood July, 2018
9 // Added large summary histograms.
10 ///////////////////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef TpcMonitor_module
14 #define TpcMonitor_module
15 
16 // LArSoft includes
20 
21 // Data type includes
22 #include "lardataobj/RawData/raw.h"
25 
26 // Framework includes
31 #include "art_root_io/TFileService.h"
33 #include "canvas/Persistency/Common/FindManyP.h"
35 #include "fhiclcpp/ParameterSet.h"
37 
38 // ROOT includes.
39 #include "TH1.h"
40 #include "TH2.h"
41 #include "TH2F.h"
42 #include "TTree.h"
43 #include "TLorentzVector.h"
44 #include "TVector3.h"
45 #include "TCanvas.h"
46 #include "TPad.h"
47 #include "TFile.h"
48 #include "TProfile.h"
49 #include "TProfile2D.h"
50 
51 // C++ Includes
52 #include <vector>
53 #include <algorithm>
54 #include <fstream>
55 #include <iostream>
56 #include <string>
57 #include <sstream>
58 #include <cmath>
59 
60 #ifdef __MAKECINT__
61 #pragma link C++ class vector<vector<int> >+;
62 #endif
63 
64 namespace tpc_monitor{
65 
66  class TpcMonitor : public art::EDAnalyzer{
67 
68  public:
69 
70  explicit TpcMonitor(fhicl::ParameterSet const& pset);
71  virtual ~TpcMonitor();
72 
73  void beginJob();
74  void beginRun(const art::Run& run);
75  void reconfigure(fhicl::ParameterSet const& pset);
76  void analyze(const art::Event& evt);
77  int FEMBchanToHistogramMap(int, int);
78 
79  void endJob();
80 
81  private:
82  // Parameters in .fcl file
86 
87  // Branch variables for tree
88  unsigned int fEvent;
89  unsigned int fRun;
90  unsigned int fSubRun;
91 
92  //int NumberOfRCEs; // unused
93 
94  // TPC
95  unsigned int fNUCh;
96  unsigned int fNVCh;
97  unsigned int fNZ0Ch;
98  unsigned int fNZ1Ch;
99  // find channel boundaries for each view
100  unsigned int fUChanMin;
101  unsigned int fUChanMax;
102  unsigned int fVChanMin;
103  unsigned int fVChanMax;
104  unsigned int fZ0ChanMin;
105  unsigned int fZ0ChanMax;
106  unsigned int fZ1ChanMin;
107  unsigned int fZ1ChanMax;
108  unsigned int fNticks;
109 
110  unsigned int fNofAPA;
111  unsigned int fChansPerAPA;
112 
113  // sampling rate
114  float fSampleRate;
115 
116  // bin width in kHz
117  float fBinWidth;
118 
119  // Mean and RMS distributions by offline channel in each plane -- the vector indexes over APA number
120  std::vector<TH1F*> fChanMeanDistU;
121  std::vector<TH1F*> fChanRMSDistU;
122  std::vector<TH1F*> fChanMeanDistV;
123  std::vector<TH1F*> fChanRMSDistV;
124  std::vector<TH1F*> fChanMeanDistZ;
125  std::vector<TH1F*> fChanRMSDistZ;
126 
127  // stuck code fraction histograms by APA
128  std::vector<TH1F*> fStuckCodeOffFrac;
129  std::vector<TH1F*> fStuckCodeOnFrac;
130 
131  // stuck code fraction histograms by channel and plane
132  std::vector<TProfile*> fChanStuckCodeOffFracU;
133  std::vector<TProfile*> fChanStuckCodeOnFracU;
134  std::vector<TProfile*> fChanStuckCodeOffFracV;
135  std::vector<TProfile*> fChanStuckCodeOnFracV;
136  std::vector<TProfile*> fChanStuckCodeOffFracZ;
137  std::vector<TProfile*> fChanStuckCodeOnFracZ;
138 
139  // FFT by channel in each plane -- the vector indexes over APA number
140  std::vector<TH2F*> fChanFFTU;
141  std::vector<TH2F*> fChanFFTV;
142  std::vector<TH2F*> fChanFFTZ;
143 
144  // profiled Mean/RMS by offline channel
145  std::vector<TProfile*> fChanRMSU_pfx;
146  std::vector<TProfile*> fChanMeanU_pfx;
147  std::vector<TProfile*> fChanRMSV_pfx;
148  std::vector<TProfile*> fChanMeanV_pfx;
149  std::vector<TProfile*> fChanRMSZ_pfx;
150  std::vector<TProfile*> fChanMeanZ_pfx;
151 
152  // 2D histograms of all Mean/RMS by offline channel number
153  // Intended as a color map with each bin to represent a single channel
154  TProfile2D* fAllChanMean;
155  TProfile2D* fAllChanRMS;
156 
157  //2Dhistograms of bits, using same mapping as the fAllChan histos
158  //vector indexes over 0-11 bit numbers
159  std::vector<TProfile2D*> fBitValue;
160 
161 
162  // profiled over events Mean/RMS by slot number
163  std::vector<TProfile*> fSlotChanMean_pfx;
164  std::vector<TProfile*> fSlotChanRMS_pfx;
165 
166  // FFT by slot number
167  //std::vector<TH2F*> fSlotChanFFT;
168 
169  // Persistent and overlay wavefroms by fiber
170  //std::vector<TH2F*> fPersistentFFT_by_Fiber;
171  // change to only saving these for each APA
172  std::vector<TH2F*> fPersistentFFT_by_APA;
173 
174  // Profiled fft by fiber
175  std::vector<TProfile*> fFFT_by_Fiber_pfx;
176 
177  // Rebin factor
178  int fRebinX;
179  int fRebinY;
180 
181  // define nADC counts for uncompressed vs compressed
182  unsigned int nADC_comp;
183  unsigned int nADC_uncomp;
184  unsigned int nADC_uncompPed;
185 
186  TH1F *fNTicksTPC;
187 
188  // Noise level cut parameters
193 
194  // Histograms to save dead/noisy channels
201 
205 
209 
213 
214  // define functions
215  float rmsADC(std::vector< short > & uncompressed);
216  float meanADC(std::vector< short > & uncompressed);
217  void calculateFFT(TH1D* hist_waveform, TH1D* graph_frequency);
218  void FillChannelHistos(TProfile* h1, double mean, double sigma, int& ndeadchannels, int& nnoisychannels_sigma, int& nnoisychannels_counts);
220 
221  std::vector<unsigned int> fApaLabelNum;
222 
223 
224  }; // TpcMonitor
225 
226  //-----------------------------------------------------------------------
227 
229  : EDAnalyzer(parameterSet), fRebinX(1), fRebinY(1), fApaLabelNum{3,5,2,6,1,4} {
230  this->reconfigure(parameterSet);
231  }
232 
233  //-----------------------------------------------------------------------
234 
235 
237 
238 
239  //-----------------------------------------------------------------------
240 
243  unsigned int UChMin;
244  unsigned int UChMax;
245  unsigned int VChMin;
246  unsigned int VChMax;
247  unsigned int ZChMin;
248  unsigned int ZChMax;
249 
250  // Accquiring geometry data
253 
254  // loop through channels in the first APA to find the channel boundaries for each view
255  // will adjust for desired APA after
256  fUChanMin = 0;
257  fZ1ChanMax = fChansPerAPA - 1;
258  for ( unsigned int c = fUChanMin + 1; c < fZ1ChanMax; c++ ){
259  if ( fGeom->View(c) == geo::kV && fGeom->View(c-1) == geo::kU ){
260  fVChanMin = c;
261  fUChanMax = c - 1;
262  }
263  if ( fGeom->View(c) == geo::kZ && fGeom->View(c-1) == geo::kV ){
264  fZ0ChanMin = c;
265  fVChanMax = c-1;
266  }
267  if ( fGeom->View(c) == geo::kZ && fGeom->ChannelToWire(c)[0].TPC == fGeom->ChannelToWire(c-1)[0].TPC + 1 ){
268  fZ1ChanMin = c;
269  fZ0ChanMax = c-1;
270  }
271  }
272 
273 
277  fNZ1Ch=fZ1ChanMax-fZ1ChanMin+1;
278 
279  mf::LogVerbatim("TpcMonitor")
280  <<"U: "<< fNUCh<<" V: "<<fNVCh<<" Z0: "<<fNZ0Ch << " Z1: " <<fNZ1Ch << std::endl;
281 
282  //Mean/RMS by offline channel for each view in each APA
283  for(unsigned int i=0;i<fNofAPA;i++)
284  {
285  UChMin=fUChanMin + i*fChansPerAPA;
286  UChMax=fUChanMax + i*fChansPerAPA;
287  VChMin=fVChanMin + i*fChansPerAPA;
288  VChMax=fVChanMax + i*fChansPerAPA;
289  ZChMin=fZ0ChanMin + i*fChansPerAPA;
290  //ZChMax=fZ0ChanMax + i*fChansPerAPA;
291  ZChMax=fZ1ChanMax + i*fChansPerAPA; //including unused channels
292 
293  //std::cout<<"UCh:"<<UChMin<<" - "<<UChMax<<std::endl;
294  //std::cout<<"VCh:"<<VChMin<<" - "<<VChMax<<std::endl;
295  //std::cout<<"ZCh:"<<ZChMin<<" - "<<ZChMax<<std::endl;
296 
297  // summaries for all views
298 
299  unsigned int j=fApaLabelNum.at(i);
300 
301  fStuckCodeOffFrac.push_back(tfs->make<TH1F>(Form("fStuckCodeOffFrac%d",j),Form("Stuck-Off Code Fraction APA%d",j),100,0,1));
302  fStuckCodeOnFrac.push_back(tfs->make<TH1F>(Form("fStuckCodeOnFrac%d",j),Form("Stuck-On Code Fraction APA%d",j),100,0,1));
303 
304  // U view
305  fChanRMSU_pfx.push_back(tfs->make<TProfile>(Form("fChanRMSU%d_pfx", j),Form("Profiled raw-ped RMS vs Channel(Plane U, APA%d)", j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5, "s"));
306  fChanMeanU_pfx.push_back(tfs->make<TProfile>(Form("fChanMeanU%d_pfx",j),Form("Profiled raw-ped MEAN vs Channel(Plane U, APA%d)",j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5, "s"));
307  fChanFFTU.push_back(tfs->make<TH2F>(Form("fChanFFTU%d", j),Form("fChanFFT (Plane U, APA%d)", j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5, fNticks/2,0,fNticks/2*fBinWidth));
308  fChanMeanDistU.push_back(tfs->make<TH1F>(Form("fChanMeanDistU%d",j),Form("Means of Channels in (Plane U, APA%d)",j), 4096, -0.5, 4095.5));
309  fChanRMSDistU.push_back(tfs->make<TH1F>(Form("fChanRMSDistU%d",j),Form("RMSs of Channels in (Plane U, APA%d)",j), 100, 0, 50));
310  fChanStuckCodeOffFracU.push_back(tfs->make<TProfile>(Form("fChanStuckCodeOffFracU%d",j),Form("Stuck-Off Code Fraction (Plane U, APA%d)",j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5, "s"));
311  fChanStuckCodeOnFracU.push_back(tfs->make<TProfile>(Form("fChanStuckCodeOnFracU%d",j),Form("Stuck-On Code Fraction (Plane U, APA%d)",j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5, "s"));
312 
313  // V view
314  fChanRMSV_pfx.push_back(tfs->make<TProfile>(Form("fChanRMSV%d_pfx",j),Form("Profiled raw-ped RMS vs Channel(Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5, "s"));
315  fChanMeanV_pfx.push_back(tfs->make<TProfile>(Form("fChanMeanV%d_pfx",j),Form("Profiled raw-ped Mean vs Channel(Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5, "s"));
316  fChanFFTV.push_back(tfs->make<TH2F>(Form("fChanFFTV%d", j),Form("fChanFFT (Plane V, APA%d)", j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5, fNticks/2,0,fNticks/2*fBinWidth));
317  fChanMeanDistV.push_back(tfs->make<TH1F>(Form("fChanMeanDistV%d",j),Form("Means of Channels in (Plane V, APA%d)",j), 4096, -0.5, 4095.5));
318  fChanRMSDistV.push_back(tfs->make<TH1F>(Form("fChanRMSDistV%d",j),Form("RMSs of Channels in (Plane V, APA%d)",j), 100, 0, 50));
319  fChanStuckCodeOffFracV.push_back(tfs->make<TProfile>(Form("fChanStuckCodeOffFracV%d",j),Form("Stuck-Off Code Fraction (Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5, "s"));
320  fChanStuckCodeOnFracV.push_back(tfs->make<TProfile>(Form("fChanStuckCodeOnFracV%d",j),Form("Stuck-On Code Fraction (Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5, "s"));
321 
322  // Z view
323  fChanRMSZ_pfx.push_back(tfs->make<TProfile>(Form("fChanRMSZ%d_pfx",j),Form("Profiled raw-ped RMS vs Channel(Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5, "s"));
324  fChanMeanZ_pfx.push_back(tfs->make<TProfile>(Form("fChanMeanZ%d_pfx",j),Form("Profiled raw-ped Mean vs Channel(Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5, "s"));
325  fChanFFTZ.push_back(tfs->make<TH2F>(Form("fChanFFTZ%d", j),Form("fChanFFT (Plane Z, APA%d)", j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5, fNticks/2,0,fNticks/2*fBinWidth));
326  fChanMeanDistZ.push_back(tfs->make<TH1F>(Form("fChanMeanDistZ%d",j),Form("Means of Channels in (Plane Z, APA%d)",j), 4096, -0.5, 4095.5));
327  fChanRMSDistZ.push_back(tfs->make<TH1F>(Form("fChanRMSDistZ%d",j),Form("RMSs of Channels in (Plane Z, APA%d)",j), 100, 0, 50));
328  fChanStuckCodeOffFracZ.push_back(tfs->make<TProfile>(Form("fChanStuckCodeOffFracZ%d",j),Form("Stuck-Off Code Fraction (Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5, "s"));
329  fChanStuckCodeOnFracZ.push_back(tfs->make<TProfile>(Form("fChanStuckCodeOnFracZ%d",j),Form("Stuck-On Code Fraction (Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5, "s"));
330 
331  // Set titles
332  fChanRMSU_pfx[i]->GetXaxis()->SetTitle("Chan"); fChanRMSU_pfx[i]->GetYaxis()->SetTitle("raw RMS");
333  fChanMeanU_pfx[i]->GetXaxis()->SetTitle("Chan"); fChanMeanU_pfx[i]->GetYaxis()->SetTitle("raw Mean");
334  fChanRMSV_pfx[i]->GetXaxis()->SetTitle("Chan"); fChanRMSV_pfx[i]->GetYaxis()->SetTitle("raw RMS");
335  fChanMeanV_pfx[i]->GetXaxis()->SetTitle("Chan"); fChanMeanV_pfx[i]->GetYaxis()->SetTitle("raw Mean");
336  fChanRMSZ_pfx[i]->GetXaxis()->SetTitle("Chan"); fChanRMSZ_pfx[i]->GetYaxis()->SetTitle("raw RMS");
337  fChanMeanZ_pfx[i]->GetXaxis()->SetTitle("Chan"); fChanMeanZ_pfx[i]->GetYaxis()->SetTitle("raw Mean");
338  fChanFFTU[i]->GetXaxis()->SetTitle("Chan"); fChanFFTU[i]->GetYaxis()->SetTitle("kHz");
339  fChanFFTV[i]->GetXaxis()->SetTitle("Chan"); fChanFFTV[i]->GetYaxis()->SetTitle("kHz");
340  fChanFFTZ[i]->GetXaxis()->SetTitle("Chan"); fChanFFTZ[i]->GetYaxis()->SetTitle("kHz");
341  fChanStuckCodeOffFracU[i]->GetXaxis()->SetTitle("Chan"); fChanStuckCodeOffFracZ[i]->GetYaxis()->SetTitle("Fraction");
342  fChanStuckCodeOnFracU[i]->GetXaxis()->SetTitle("Chan"); fChanStuckCodeOnFracZ[i]->GetYaxis()->SetTitle("Fraction");
343  fChanStuckCodeOffFracV[i]->GetXaxis()->SetTitle("Chan"); fChanStuckCodeOffFracZ[i]->GetYaxis()->SetTitle("Fraction");
344  fChanStuckCodeOnFracV[i]->GetXaxis()->SetTitle("Chan"); fChanStuckCodeOnFracZ[i]->GetYaxis()->SetTitle("Fraction");
345  fChanStuckCodeOffFracZ[i]->GetXaxis()->SetTitle("Chan"); fChanStuckCodeOffFracZ[i]->GetYaxis()->SetTitle("Fraction");
346  fChanStuckCodeOnFracZ[i]->GetXaxis()->SetTitle("Chan"); fChanStuckCodeOnFracZ[i]->GetYaxis()->SetTitle("Fraction");
347 
348  fChanMeanDistU[i]->GetXaxis()->SetTitle("Mean (ADC counts)");
349  fChanRMSDistU[i]->GetXaxis()->SetTitle("RMS (ADC counts)");
350  fChanMeanDistV[i]->GetXaxis()->SetTitle("Mean (ADC counts)");
351  fChanRMSDistV[i]->GetXaxis()->SetTitle("RMS (ADC counts)");
352  fChanMeanDistZ[i]->GetXaxis()->SetTitle("Mean (ADC counts)");
353  fChanRMSDistZ[i]->GetXaxis()->SetTitle("RMS (ADC counts)");
354 
355  // Rebin histograms
356  //std::cout<<"RebinX = "<<fRebinX<<" RebinY = "<<fRebinY<<std::endl;
357  fChanFFTU[i]->Rebin2D(fRebinX, fRebinY);
358  fChanFFTV[i]->Rebin2D(fRebinX, fRebinY);
359  fChanFFTZ[i]->Rebin2D(fRebinX, fRebinY);
360  }
361 
362  //All in one view
363  //make the histograms
364  fAllChanMean = tfs->make<TProfile2D>("fAllChanMean", "Means for all channels", 240, -0.5, 239.5, 64, -0.5, 63.5);
365  fAllChanRMS = tfs->make<TProfile2D>("fAllChanRMS", "RMS for all channels", 240, -0.5, 239.5, 64, -0.5, 63.5);
366  //set titles and bin labels
367  fAllChanMean->GetXaxis()->SetTitle("APA Number (online)"); fAllChanMean->GetYaxis()->SetTitle("Plane"); fAllChanMean->GetZaxis()->SetTitle("Raw Mean");
368  fAllChanRMS->GetXaxis()->SetTitle("APA Number (online)"); fAllChanRMS->GetYaxis()->SetTitle("Plane"); fAllChanRMS->GetZaxis()->SetTitle("Raw RMS");
369  fAllChanMean->GetXaxis()->SetLabelSize(.075); fAllChanMean->GetYaxis()->SetLabelSize(.05);
370  fAllChanRMS->GetXaxis()->SetLabelSize(.075); fAllChanRMS->GetYaxis()->SetLabelSize(.05);
371  fAllChanMean->GetXaxis()->SetBinLabel(40, "3"); fAllChanMean->GetXaxis()->SetBinLabel(120, "2"); fAllChanMean->GetXaxis()->SetBinLabel(200, "1");
372  fAllChanRMS->GetXaxis()->SetBinLabel(40, "3"); fAllChanRMS->GetXaxis()->SetBinLabel(120, "2"); fAllChanRMS->GetXaxis()->SetBinLabel(200, "1");
373  fAllChanMean->GetYaxis()->SetBinLabel(5, "U"); fAllChanMean->GetYaxis()->SetBinLabel(15, "V"); fAllChanMean->GetYaxis()->SetBinLabel(26, "Z");
374  fAllChanMean->GetYaxis()->SetBinLabel(37, "U"); fAllChanMean->GetYaxis()->SetBinLabel(47, "V"); fAllChanMean->GetYaxis()->SetBinLabel(58, "Z");
375  fAllChanRMS->GetYaxis()->SetBinLabel(5, "U"); fAllChanRMS->GetYaxis()->SetBinLabel(15, "V"); fAllChanRMS->GetYaxis()->SetBinLabel(26, "Z");
376  fAllChanRMS->GetYaxis()->SetBinLabel(37, "U"); fAllChanRMS->GetYaxis()->SetBinLabel(47, "V"); fAllChanRMS->GetYaxis()->SetBinLabel(58, "Z");
377 
378  for(int i=0;i<12;i++)
379  {
380  fBitValue.push_back(tfs->make<TProfile2D>(Form("fBitValue%d",i),Form("Values for bit %d",i),240,-0.5,239.5,64,-0.5,63.5,0,1));
381  fBitValue[i]->SetStats(false);
382  fBitValue[i]->GetXaxis()->SetTitle("APA Number (online)"); fBitValue[i]->GetYaxis()->SetTitle("Plane"); fBitValue[i]->GetZaxis()->SetTitle("Bit Fraction On");
383  fBitValue[i]->GetXaxis()->SetLabelSize(.075); fBitValue[i]->GetYaxis()->SetLabelSize(.05);
384  fBitValue[i]->GetXaxis()->SetBinLabel(40, "3"); fBitValue[i]->GetXaxis()->SetBinLabel(120, "2"); fBitValue[i]->GetXaxis()->SetBinLabel(200, "1");
385  fBitValue[i]->GetYaxis()->SetBinLabel(5, "U"); fBitValue[i]->GetYaxis()->SetBinLabel(15, "V"); fBitValue[i]->GetYaxis()->SetBinLabel(26, "Z");
386  fBitValue[i]->GetYaxis()->SetBinLabel(37, "U"); fBitValue[i]->GetYaxis()->SetBinLabel(47, "V"); fBitValue[i]->GetYaxis()->SetBinLabel(58, "Z");
387  }
388 
389  // Mean/RMS by slot channel number for each slot
390  for(int i=0;i<30;i++) {
391  int apaloc = fApaLabelNum[i/5];
392  int slotloc = i % 5;
393 
394  fSlotChanMean_pfx.push_back(tfs->make<TProfile>(Form("APA%d_Slot%d_Mean", apaloc, slotloc), Form("APA %d Slot%d Mean_vs_SlotChannel", apaloc, slotloc), 512, 0, 512, "s"));
395  fSlotChanRMS_pfx.push_back(tfs->make<TProfile>(Form("APA%d_Slot%d_RMS", apaloc, slotloc), Form("APA %d Slot %d RMS_vs_SlotChannel", apaloc, slotloc), 512, 0, 512, "s"));
396  //fSlotChanFFT.push_back(tfs->make<TH2F>(Form("APA%d_Slot%d_FFT", apaloc, slotloc), Form("APA %d Slot %d FFT_vs_SlotChannel", apaloc, slotloc), 512, 0, 512, fNticks/2, 0, fNticks/2*fBinWidth));
397 
398  fSlotChanMean_pfx[i]->GetXaxis()->SetTitle("Slot Channel"); fSlotChanMean_pfx[i]->GetYaxis()->SetTitle("Profiled Mean");
399  fSlotChanRMS_pfx[i]->GetXaxis()->SetTitle("Slot Channel"); fSlotChanRMS_pfx[i]->GetYaxis()->SetTitle("Profiled RMS");
400  //fSlotChanFFT[i]->GetXaxis()->SetTitle("Slot Channel"); fSlotChanFFT[i]->GetYaxis()->SetTitle("kHz");
401  }
402 
403  unsigned int fembmap_by_fiberID[120] =
404  {
405  320,315,310,305,319,314,309,304,318,313,308,303,317,312,307,302,316,311,306,301,505,510,515,520,504,509,514,519,503,508,513,518,502,507,512,517,501,506,511,516,220,215,210,205,219,
406  214,209,204,218,213,208,203,217,212,207,202,216,211,206,201,605,610,615,620,604,609,614,619,603,608,613,618,602,607,612,617,601,606,611,616,120,115,110,105,119,114,109,104,118,113,
407  108,103,117,112,107,102,116,111,106,101,405,410,415,420,404,409,414,419,403,408,413,418,402,407,412,417,401,406,411,416
408  };
409 
410 
411  // FFT's by fiber
412  for(int i=0;i<120;i++) {
413  unsigned int imb = fembmap_by_fiberID[i];
414  //fPersistentFFT_by_Fiber.push_back(tfs->make<TH2F>(Form("Persistent_FFT_FEMB_%d", imb), Form("FFT FEMB%d WIB%d", imb, ( (i/4) % 5)+1), fNticks/2, 0, fNticks/2*fBinWidth, 150, -100, 50));
415  //fPersistentFFT_by_Fiber[i]->GetXaxis()->SetTitle("Frequency [kHz]"); fPersistentFFT_by_Fiber[i]->GetYaxis()->SetTitle("Amplitude [dB]");
416  // still keep the profiled FFT's by FEMB
417  fFFT_by_Fiber_pfx.push_back(tfs->make<TProfile>(Form("Profiled_FFT_FEMB_%d", imb), Form("Profiled FFT FEMB_%d WIB%d", imb, ( (i/4) %5)+1), fNticks/2, 0, fNticks/2*fBinWidth, -100, 50));
418  fFFT_by_Fiber_pfx[i]->GetXaxis()->SetTitle("Frequency [kHz]"); fFFT_by_Fiber_pfx[i]->GetYaxis()->SetTitle("Amplitude [dB]");
419  }
420  // persistent FFT now by APA
421  for (int i=0;i<6;++i)
422  {
423  fPersistentFFT_by_APA.push_back(tfs->make<TH2F>(Form("Persistent_FFT_APA_%d", fApaLabelNum[i]), Form("FFT APA%d ", fApaLabelNum[i]), fNticks/2, 0, fNticks/2*fBinWidth, 150, -100, 50));
424  fPersistentFFT_by_APA[i]->GetXaxis()->SetTitle("Frequency [kHz]");
425  fPersistentFFT_by_APA[i]->GetYaxis()->SetTitle("Amplitude [dB]");
426  }
427 
428  fNTicksTPC = tfs->make<TH1F>("NTicksTPC","NTicks in TPC Channels",100,0,20000);
429 
430  // Dead/noisy channels
431  fNDeadChannelsHisto = tfs->make<TH1F>("fNDeadChannelsHisto","Number of dead channels",fNofAPA+1,0,fNofAPA+1);
432  fNDeadChannelsHisto->GetYaxis()->SetTitle("Number of dead channels");
433  fNNoisyChannelsHistoFromNSigma = tfs->make<TH1F>("fNNoisyChannelsHistoFromNSigma","Number of noisy channels",fNofAPA+1,0,fNofAPA+1);
434  fNNoisyChannelsHistoFromNSigma->GetYaxis()->SetTitle("Number of noisy channels");
435  fNNoisyChannelsHistoFromNCounts = tfs->make<TH1F>("fNNoisyChannelsHistoFromNCounts",Form("Number of noisy channels above counts %i-%i-%i (U-V-Z)", fNoiseLevelMinNCountsU, fNoiseLevelMinNCountsV, fNoiseLevelMinNCountsZ), fNofAPA+1,0,fNofAPA+1);
436  fNNoisyChannelsHistoFromNCounts->GetYaxis()->SetTitle("Number of noisy channels");
437 
438  fNDeadChannelsHistoU = tfs->make<TH1F>("fNDeadChannelsHistoU","Number of dead channels (Plane U)",fNofAPA+1,0,fNofAPA+1);
439  fNDeadChannelsHistoU->GetYaxis()->SetTitle("Number of dead channels (Plane U)");
440  fNNoisyChannelsHistoFromNSigmaU = tfs->make<TH1F>("fNNoisyChannelsHistoFromNSigmaU","Number of noisy channels (Plane U)",fNofAPA+1,0,fNofAPA+1);
441  fNNoisyChannelsHistoFromNSigmaU->GetYaxis()->SetTitle("Number of noisy channels (Plane U)");
442  fNNoisyChannelsHistoFromNCountsU = tfs->make<TH1F>("fNNoisyChannelsHistoFromNCountsU",Form("Number of noisy channels above %i counts (Plane U)", fNoiseLevelMinNCountsU), fNofAPA+1,0,fNofAPA+1);
443  fNNoisyChannelsHistoFromNCountsU->GetYaxis()->SetTitle("Number of noisy channels (Plane U)");
444 
445  fNDeadChannelsHistoV = tfs->make<TH1F>("fNDeadChannelsHistoV","Number of dead channels (Plane V)",fNofAPA+1,0,fNofAPA+1);
446  fNDeadChannelsHistoV->GetYaxis()->SetTitle("Number of dead channels (Plane V)");
447  fNNoisyChannelsHistoFromNSigmaV = tfs->make<TH1F>("fNNoisyChannelsHistoFromNSigmaV","Number of noisy channels (Plane V)",fNofAPA+1,0,fNofAPA+1);
448  fNNoisyChannelsHistoFromNSigmaV->GetYaxis()->SetTitle("Number of noisy channels (Plane V)");
449  fNNoisyChannelsHistoFromNCountsV = tfs->make<TH1F>("fNNoisyChannelsHistoFromNCountsV",Form("Number of noisy channels above %i counts (Plane V)", fNoiseLevelMinNCountsV), fNofAPA+1,0,fNofAPA+1);
450  fNNoisyChannelsHistoFromNCountsV->GetYaxis()->SetTitle("Number of noisy channels (Plane V)");
451 
452  fNDeadChannelsHistoZ = tfs->make<TH1F>("fNDeadChannelsHistoZ","Number of dead channels (Plane Z)",fNofAPA+1,0,fNofAPA+1);
453  fNDeadChannelsHistoZ->GetYaxis()->SetTitle("Number of dead channels (Plane Z)");
454  fNNoisyChannelsHistoFromNSigmaZ = tfs->make<TH1F>("fNNoisyChannelsHistoFromNSigmaZ","Number of noisy channels (Plane Z)",fNofAPA+1,0,fNofAPA+1);
455  fNNoisyChannelsHistoFromNSigmaZ->GetYaxis()->SetTitle("Number of noisy channels (Plane Z)");
456  fNNoisyChannelsHistoFromNCountsZ = tfs->make<TH1F>("fNNoisyChannelsHistoFromNCountsZ",Form("Number of noisy channels above %i counts (Plane Z)", fNoiseLevelMinNCountsZ), fNofAPA+1,0,fNofAPA+1);
457  fNNoisyChannelsHistoFromNCountsZ->GetYaxis()->SetTitle("Number of noisy channels (Plane Z)");
458 
459  fNDeadChannelsList = tfs->make<TH1F>("fNDeadChannelsList","List of dead channels",fGeom->Nchannels()+1,fUChanMin,fGeom->Nchannels()+1);
460  fNDeadChannelsList->GetXaxis()->SetTitle("Channel ID");
461  fNNoisyChannelsListFromNSigma = tfs->make<TH1F>("fNNoisyChannelsListFromNSigma","List of noisy channels",fGeom->Nchannels()+1,fUChanMin,fGeom->Nchannels()+1);
462  fNNoisyChannelsListFromNSigma->GetXaxis()->SetTitle("Channel ID");
463  fNNoisyChannelsListFromNCounts = tfs->make<TH1F>("fNNoisyChannelsListFromNCounts",Form("Number of noisy channels above counts %i-%i-%i (U-V-Z)", fNoiseLevelMinNCountsU, fNoiseLevelMinNCountsV, fNoiseLevelMinNCountsZ),fGeom->Nchannels()+1,fUChanMin,fGeom->Nchannels()+1);
464  fNNoisyChannelsListFromNCounts->GetXaxis()->SetTitle("Channel ID");
465 
466  for(unsigned int i=0;i<fNofAPA;i++){
467  unsigned int j=fApaLabelNum.at(i);
468  TString apastring = Form("APA %i", j);
469  fNDeadChannelsHisto->GetXaxis()->SetBinLabel(j+1, apastring.Data());
470  fNNoisyChannelsHistoFromNSigma->GetXaxis()->SetBinLabel(j+1, apastring.Data());
471  fNNoisyChannelsHistoFromNCounts->GetXaxis()->SetBinLabel(j+1, apastring.Data());
472 
473  fNDeadChannelsHistoU->GetXaxis()->SetBinLabel(j+1, apastring.Data());
474  fNNoisyChannelsHistoFromNSigmaU->GetXaxis()->SetBinLabel(j+1, apastring.Data());
475  fNNoisyChannelsHistoFromNCountsU->GetXaxis()->SetBinLabel(j+1, apastring.Data());
476  fNDeadChannelsHistoV->GetXaxis()->SetBinLabel(j+1, apastring.Data());
477  fNNoisyChannelsHistoFromNSigmaV->GetXaxis()->SetBinLabel(j+1, apastring.Data());
478  fNNoisyChannelsHistoFromNCountsV->GetXaxis()->SetBinLabel(j+1, apastring.Data());
479  fNDeadChannelsHistoZ->GetXaxis()->SetBinLabel(j+1, apastring.Data());
480  fNNoisyChannelsHistoFromNSigmaZ->GetXaxis()->SetBinLabel(j+1, apastring.Data());
481  fNNoisyChannelsHistoFromNCountsZ->GetXaxis()->SetBinLabel(j+1, apastring.Data());
482  }
483  }
484 
485  //-----------------------------------------------------------------------
487  // place to read databases or run independent info
488  }
489  //-----------------------------------------------------------------------
490 
492 
493  // reconfigure without recompiling
494  // read in the parameters from the .fcl file
495  // allows for interactive changes of the parameter values
496 
497  fTPCInput = p.get< std::string >("TPCInputModule");
498  fTPCInstance = p.get< std::string >("TPCInstanceName");
499  fRebinX = p.get<int>("RebinFactorX");
500  fRebinY = p.get<int>("RebinFactorY");
501  fNoiseLevelMinNCountsU = p.get<int>("NoiseLevelMinNCountsU");
502  fNoiseLevelMinNCountsV = p.get<int>("NoiseLevelMinNCountsV");
503  fNoiseLevelMinNCountsZ = p.get<int>("NoiseLevelMinNCountsZ");
504  fNoiseLevelNSigma = p.get<double>("NoiseLevelNSigma");
505  auto const clockData = art::ServiceHandle<detinfo::DetectorClocksService const>()->DataForJob();
506  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob(clockData);
507  fNticks = detProp.NumberTimeSamples();
508 
509  std::cout<< "Number of Ticks = "<< fNticks <<std::endl;
510  //get sampling rate
511  fSampleRate = sampling_rate(clockData);
512  std::cout<<"Sampling rate = "<<fSampleRate<<std::endl;
513  // width of frequencyBin in kHz
514  fBinWidth = 1.0/(fNticks*fSampleRate*1.0e-6);
515  std::cout<<"Bin Width (kHz) = "<<fBinWidth<<std::endl;
516  return;
517  }
518 
519  //-----------------------------------------------------------------------
520 
522  // Get channel map
524  // TODO Use MF_LOG_DEBUG
525  MF_LOG_INFO("TpcMonitor")
526  << "-------------------- TPC TpcMonitor -------------------";
527 
528  // called once per event
529 
530  fEvent = event.id().event();
531  fRun = event.run();
532  fSubRun = event.subRun();
533  std::cout << "EventNumber = " << fEvent << std::endl;
534 
535  // Get the objects holding raw information: RawDigit for TPC data
537  auto RawTPC = event.getHandle< std::vector<raw::RawDigit> >(itag1);
538 
539  // Get RDStatus handle
540 
541  auto RDStatusHandle = event.getHandle< std::vector<raw::RDStatus> >(itag1);
542 
543  // Fill pointer vectors - more useful form for the raw data
544  // a more usable form
545  std::vector< art::Ptr<raw::RawDigit> > RawDigits;
546  art::fill_ptr_vector(RawDigits, RawTPC);
547 
548  //for the large all channel summary histograms these are key points for bin mapping
549  //for each offline numbered apa, the left most bin should be at the x value:
550  int xEdgeAPA[6] = {0,0,80,80,160,160}; //these numbers may be adjusted to horizontally space out the histogram
551  //for each of the apas, the bottom most bin should be at the y value:
552  int yEdgeAPA[2] = {0,32}; //these numbers may be adjusted to vertically space out the histograms
553 
554  // example of retrieving RDStatus word and flags
555 
556  for ( auto const& rdstatus : (*RDStatusHandle) )
557  {
558  if (rdstatus.GetCorruptDataDroppedFlag())
559  {
560  MF_LOG_INFO("TpcMonitor_module: ") << "Corrupt Data Dropped Flag set in RDStatus";
561  }
562  //std::cout << "RDStatus: Corrupt Data dropped " << rdstatus.GetCorruptDataDroppedFlag() << std::endl;
563  //std::cout << "RDStatus: Corrupt Data kept " << rdstatus.GetCorruptDataKeptFlag() << std::endl;
564  //std::cout << "RDStatus: Status Word " << rdstatus.GetStatWord() << std::endl;
565  }
566 
567  // Loop over all RawRCEDigits (entire channels)
568  for(auto const & dptr : RawDigits) {
569  const raw::RawDigit & digit = *dptr;
570 
571  // Get the channel number for this digit
572  uint32_t chan = digit.Channel();
573  // number of samples in uncompressed ADC
574  int nSamples = digit.Samples();
575  fNTicksTPC->Fill(nSamples);
576  unsigned int apa = std::floor( chan/fChansPerAPA );
577  //int pedestal = (int)digit.GetPedestal();
578  int pedestal = 0;
579 
580  std::vector<short> uncompressed(nSamples);
581  // with pedestal
582  raw::Uncompress(digit.ADCs(), uncompressed, pedestal, digit.Compression());
583 
584  // number of compressed ADCs
585  nADC_comp=digit.NADC();
586  // number of ADC uncompressed
587  nADC_uncomp=uncompressed.size();
588  // subtract pedestals
589  std::vector<short> uncompPed(nSamples);
590 
591  int nstuckoff=0;
592  int nstuckon=0;
593  for (int i=0; i<nSamples; i++)
594  {
595  auto adc=uncompressed.at(i);
596  auto adcl6b = adc & 0x3F;
597  if (adcl6b == 0) ++nstuckoff;
598  if (adcl6b == 0x3F) ++nstuckon;
599  uncompPed.at(i) = adc - pedestal;
600  }
601  float fracstuckoff = ((float) nstuckoff)/((float) nSamples);
602  float fracstuckon = ((float) nstuckon)/((float) nSamples);
603 
604  // number of ADC uncompressed without pedestal
605  nADC_uncompPed=uncompPed.size();
606 
607  // wavefrom histogram
608  int FiberID = channelMap->FiberIdFromOfflineChannel(chan);
609  TH1D* histwav=new TH1D(Form("wav%d",(int)chan),Form("wav%d",(int)chan),nSamples,0,nSamples);
610 
611  for(int k=0;k<(int)nADC_uncompPed;k++) {
612  histwav->SetBinContent(k+1, uncompPed.at(k));
613  // Fill Persistent waveform by fiber -- skip as it takes too much RAM
614  //fPersistentWav_by_Fiber.at(FiberID)->Fill(k+1, uncompPed.at(k));
615  }
616 
617  // Do FFT for single waveforms
618  TH1D* histfft=new TH1D(Form("fft%d",(int)chan),Form("fft%d",(int)chan),nSamples,0,nSamples*fBinWidth);
619  calculateFFT(histwav, histfft);
620  // Fill persistent/overlay FFT for each fiber/FEMB
621  for(int k=0;k<(int)nADC_uncompPed/2;k++) {
622  fPersistentFFT_by_APA.at(apa)->Fill((k+0.5)*fBinWidth, histfft->GetBinContent(k+1)); // offline apa number. Plot labels are online
623  fFFT_by_Fiber_pfx.at(FiberID % 120)->Fill((k+0.5)*fBinWidth, histfft->GetBinContent(k+1));
624  }
625 
626  // summary stuck code fraction distributions by APA -- here the APA is the offline APA number. The plot labels contain the mapping
627 
628  fStuckCodeOffFrac[apa]->Fill(fracstuckoff);
629  fStuckCodeOnFrac[apa]->Fill(fracstuckon);
630 
631  // Mean and RMS
632  float mean = meanADC(uncompPed);
633  float rms = rmsADC(uncompPed);
634 
635  //get ready to fill the summary plots
636  //get the channel's FEMB and WIB
637  int WIB = channelMap->WIBFromOfflineChannel(chan); //0-4
638  int FEMB = channelMap->FEMBFromOfflineChannel(chan); //1-4
639  int FEMBchan = channelMap->FEMBChannelFromOfflineChannel(chan);
640  int iFEMB = ((WIB*4)+(FEMB-1)); //index of the FEMB 0-19
641  //Get the location of any FEMBchan in the hitogram
642  //put as a function for clenliness.
643  int xBin = ((FEMBchanToHistogramMap(FEMBchan,0))+(iFEMB*4)+xEdgeAPA[apa]); // (fembchan location on histogram) + shift from mobo + shift from apa
644  int yBin = ((FEMBchanToHistogramMap(FEMBchan,1))+yEdgeAPA[(apa%2)]); //(fembchan location on histogram) + shift from apa
645 
646  fAllChanMean->Fill(xBin,yBin,mean); //histogram the mean
647  fAllChanRMS->Fill(xBin,yBin,rms); //histogram the rms
648 
649  for (int i=0; i<nSamples; i++) //histogram the 12 bits
650  {
651  auto adc=uncompressed.at(i);
652  int bitstring = adc;
653  for(int mm=0;mm<12;mm++)
654  {
655  // get the bit value from the adc
656  int bit = (bitstring%2);
657  fBitValue[mm]->Fill(xBin,yBin,bit);
658  bitstring = (bitstring/2);
659  }
660  }
661 
662 
663  // U View, induction Plane
664  if( fGeom->View(chan) == geo::kU){
665  fChanMeanU_pfx[apa]->Fill(chan, mean, 1);
666  fChanRMSU_pfx[apa]->Fill(chan, rms, 1);
667  fChanMeanDistU[apa]->Fill(mean);
668  fChanRMSDistU[apa]->Fill(rms);
669  fChanStuckCodeOffFracU[apa]->Fill(chan,fracstuckoff,1);
670  fChanStuckCodeOnFracU[apa]->Fill(chan,fracstuckon,1);
671 
672  //fft
673  for(int l=0;l<nSamples/2;l++) {
674  //for the 2D histos
675  fChanFFTU[apa]->Fill(chan, (l+0.5)*fBinWidth, histfft->GetBinContent(l+1));
676  }
677 
678  }// end of U View
679 
680  // V View, induction Plane
681  if( fGeom->View(chan) == geo::kV){
682  fChanRMSV_pfx[apa]->Fill(chan, rms, 1);
683  fChanMeanV_pfx[apa]->Fill(chan, mean, 1);
684  fChanMeanDistV[apa]->Fill(mean);
685  fChanRMSDistV[apa]->Fill(rms);
686  fChanStuckCodeOffFracV[apa]->Fill(chan,fracstuckoff,1);
687  fChanStuckCodeOnFracV[apa]->Fill(chan,fracstuckon,1);
688 
689  //fft
690  for(int l=0;l<nSamples/2;l++) {
691  //for the 2D histos
692  fChanFFTV[apa]->Fill(chan, (l+0.5)*fBinWidth, histfft->GetBinContent(l+1));
693  }
694 
695  }// end of V View
696 
697  // Z View, collection Plane
698  if( fGeom->View(chan) == geo::kZ){
699  fChanMeanZ_pfx[apa]->Fill(chan, mean, 1);
700  fChanRMSZ_pfx[apa]->Fill(chan, rms, 1);
701  fChanMeanDistZ[apa]->Fill(mean);
702  fChanRMSDistZ[apa]->Fill(rms);
703  fChanStuckCodeOffFracZ[apa]->Fill(chan,fracstuckoff,1);
704  fChanStuckCodeOnFracZ[apa]->Fill(chan,fracstuckon,1);
705 
706  //fft
707  for(int l=0;l<nSamples/2;l++) {
708  //for the 2D histos
709  fChanFFTZ[apa]->Fill(chan, (l+0.5)*fBinWidth, histfft->GetBinContent(l+1));
710  }
711 
712  }// end of Z View
713 
714  // Mean/RMS by slot
715  int SlotID = channelMap->SlotIdFromOfflineChannel(chan);
716  int FiberNumber = channelMap->FEMBFromOfflineChannel(chan) - 1;
717  int FiberChannelNumber = channelMap->FEMBChannelFromOfflineChannel(chan);
718  uint32_t SlotChannelNumber = FiberNumber*128 + FiberChannelNumber; //128 channels per fiber
719  fSlotChanMean_pfx.at(SlotID)->Fill(SlotChannelNumber, mean, 1);
720  fSlotChanRMS_pfx.at(SlotID)->Fill(SlotChannelNumber, rms, 1);
721 
722  // FFT by slot
723  for(int l=0;l<nSamples/2;l++) {
724  //for the 2D histos
725  // fSlotChanFFT.at(SlotID)->Fill(SlotChannelNumber, (l+0.5)*fBinWidth, histfft->GetBinContent(l+1));
726  }
727 
728  histwav->Delete();
729  histfft->Delete();
730 
731  } // RawDigits
732 
733  return;
734  }
735 
736  //-----------------------------------------------------------------------
737  // define RMS
738  float TpcMonitor::rmsADC(std::vector< short > &uncomp)
739  {
740  int n = uncomp.size();
741  float sum = 0.;
742  for(int i = 0; i < n; i++){
743  if(uncomp[i]!=0) sum += uncomp[i];
744  }
745  float mean = sum / n;
746  sum = 0;
747  for(int i = 0; i < n; i++)
748  {
749  if (uncomp[i]!=0) sum += (uncomp[i]-mean)*(uncomp[i]-mean);
750  }
751  return sqrt(sum / n);
752  }
753 
754  //-----------------------------------------------------------------------
755  //define Mean
756  float TpcMonitor::meanADC(std::vector< short > &uncomp)
757  {
758  int n = uncomp.size();
759  float sum = 0.;
760  for(int i = 0; i < n; i++)
761  {
762  if (uncomp[i]!=0) sum += abs(uncomp[i]);
763  }
764  return sum / n;
765  }
766 
767  //-----------------------------------------------------------------------
768  //calculate FFT
769  void TpcMonitor::calculateFFT(TH1D* hist_waveform, TH1D* hist_frequency) {
770 
771  int n_bins = hist_waveform->GetNbinsX();
772  TH1* hist_transform = 0;
773 
774  // Create hist_transform from the input hist_waveform
775  hist_transform = hist_waveform->FFT(hist_transform, "MAG");
776  hist_transform -> Scale (1.0 / float(n_bins));
777  int nFFT=hist_transform->GetNbinsX();
778 
779  double frequency;
780  double amplitude;
781  double amplitudeLog;
782 
783  // Loop on the hist_transform to fill the hist_transform_frequency
784  for (int k = 0; k < nFFT/2; k++){
785 
786  frequency = (k+0.5)*fBinWidth; // kHz
787  amplitude = hist_transform->GetBinContent(k+1);
788  amplitudeLog = 20*log10(amplitude); // dB
789  hist_frequency->Fill(frequency, amplitudeLog);
790  }
791 
792  hist_transform->Delete();
793 
794  }
795 
796  //-----------------------------------------------------------------------
797  // Fill dead/noisy channels tree
798  void TpcMonitor::FillChannelHistos(TProfile* h1, double mean, double sigma, int& ndeadchannels, int& nnoisychannels_sigma, int& nnoisychannels_counts){
799 
800  double rms_threshold = mean + fNoiseLevelNSigma*sigma;
801  TString htitle = h1->GetTitle();
802 
803  for(Int_t j=1; j <= h1->GetNbinsX(); j++){
804 
805  int fChannelID = h1->GetBinCenter(j);
806  double fChannelValue = h1->GetBinContent(j);
807 
808  if(fChannelValue == 0){ // dead channel
809  ndeadchannels++;
810  fNDeadChannelsList->SetBinContent(fChannelID, 1.0);
811  }
812  else{
813  if(fChannelValue > rms_threshold){ // noisy channel far away from mean
814  nnoisychannels_sigma++;
815  fNNoisyChannelsListFromNSigma->SetBinContent(fChannelID, 1.0);
816  }
817  if(htitle.Contains("Plane U"))
818  {
819  if (fChannelValue > fNoiseLevelMinNCountsU)
820  { // noisy U channel above count threshold
821  nnoisychannels_counts++;
822  fNNoisyChannelsListFromNCounts->SetBinContent(fChannelID, 1.0);
823  }
824  }
825  else if(htitle.Contains("Plane V"))
826  {
827  if (fChannelValue > fNoiseLevelMinNCountsV)
828  { // noisy V channel above count threshold
829  nnoisychannels_counts++;
830  fNNoisyChannelsListFromNCounts->SetBinContent(fChannelID, 1.0);
831  }
832  }
833  else if(htitle.Contains("Plane Z"))
834  {
835  if (fChannelValue > fNoiseLevelMinNCountsZ)
836  { // noisy Z channel above count threshold
837  nnoisychannels_counts++;
838  fNNoisyChannelsListFromNCounts->SetBinContent(fChannelID, 1.0);
839  }
840  }
841  else{
842  mf::LogVerbatim("TpcMonitor::FillChannelHistos")
843  << " Unknown histogram title: " << htitle.Data() << std::endl;
844  }
845  }
846  }
847 
848  return;
849  }
850 
851  //----------------------------------------------------------------------
852  //define the mapping of FEMBchans to the histogram.
854  //to see the reason for this channel mapping, check DocDB 4064 Table 5
855  //for one FEMB, this dictates the coordinates on the histogram as a 4X32 block.
856  int FEMBchanToHistogram[128][2] = { {0,0},{0,1},{0,2},{0,3},{0,4},//for U
857  {0,10},{0,11},{0,12},{0,13},{0,14},//for V
858  {0,20},{0,21},{0,22},{0,23},{0,24},{0,25},//for Z
859  {0,5},{0,6},{0,7},{0,8},{0,9},//for U
860  {0,15},{0,16},{0,17},{0,18},{0,19},//for V
861  {0,26},{0,27},{0,28},{0,29},{0,30},{0,31},//for Z
862  {1,20},{1,21},{1,22},{1,23},{1,24},{1,25},//for Z
863  {1,10},{1,11},{1,12},{1,13},{1,14},//for V
864  {1,0},{1,1},{1,2},{1,3},{1,4},//for U
865  {1,26},{1,27},{1,28},{1,29},{1,30},{1,31},//for Z
866  {1,15},{1,16},{1,17},{1,18},{1,19},//for V
867  {1,5},{1,6},{1,7},{1,8},{1,9},//for U
868  {2,0},{2,1},{2,2},{2,3},{2,4},//for U
869  {2,10},{2,11},{2,12},{2,13},{2,14},//for V
870  {2,20},{2,21},{2,22},{2,23},{2,24},{2,25},//for Z
871  {2,5},{2,6},{2,7},{2,8},{2,9},//for U
872  {2,15},{2,16},{2,17},{2,18},{2,19},//for V
873  {2,26},{2,27},{2,28},{2,29},{2,30},{2,31},//for Z
874  {3,20},{3,21},{3,22},{3,23},{3,24},{3,25},//for Z
875  {3,10},{3,11},{3,12},{3,13},{3,14},//for V
876  {3,0},{3,1},{3,2},{3,3},{3,4},//for U
877  {3,26},{3,27},{3,28},{3,29},{3,30},{3,31},//for Z
878  {3,15},{3,16},{3,17},{3,18},{3,19},//for V
879  {3,5},{3,6},{3,7},{3,8},{3,9} };//for U
880  return FEMBchanToHistogram[FEMBchan][coord];
881  }
882 
883  //-----------------------------------------------------------------------
885 
886  // Find dead/noisy channels. Do this separately for each APA and for each view.
887  std::vector<double> fURMS_mean; std::vector<double> fURMS_sigma;
888  std::vector<double> fVRMS_mean; std::vector<double> fVRMS_sigma;
889  std::vector<double> fZRMS_mean; std::vector<double> fZRMS_sigma;
890  for(unsigned int i = 0; i < fNofAPA; i++){
891  // U plane
892  TH1F* h1 = (TH1F*)fChanRMSDistU.at(i);
893  fURMS_mean.push_back(h1->GetMean());
894  fURMS_sigma.push_back(h1->GetRMS());
895  // V plane
896  TH1F* h2 = (TH1F*)fChanRMSDistV.at(i);
897  fVRMS_mean.push_back(h2->GetMean());
898  fVRMS_sigma.push_back(h2->GetRMS());
899  // Z plane
900  TH1F* h3 = (TH1F*)fChanRMSDistZ.at(i);
901  fZRMS_mean.push_back(h3->GetMean());
902  fZRMS_sigma.push_back(h3->GetRMS());
903  }
904 
905  std::vector<int> fUdch_vec; std::vector<int> fUnch_vec; std::vector<int> fUcch_vec;
906  std::vector<int> fVdch_vec; std::vector<int> fVnch_vec; std::vector<int> fVcch_vec;
907  std::vector<int> fZdch_vec; std::vector<int> fZnch_vec; std::vector<int> fZcch_vec;
908 
909  for(unsigned int i = 0; i < fNofAPA; i++){
910  int ndeadchannels = 0; int nnoisychannels = 0; int nnoisychannels_counts = 0;
911 
912  // U plane
913  TProfile* h1 = (TProfile*)fChanRMSU_pfx.at(i);
914  FillChannelHistos(h1, fURMS_mean.at(i), fURMS_sigma.at(i), ndeadchannels, nnoisychannels, nnoisychannels_counts);
915  fUdch_vec.push_back(ndeadchannels);
916  fUnch_vec.push_back(nnoisychannels);
917  fUcch_vec.push_back(nnoisychannels_counts);
918 
919  // V plane
920  ndeadchannels = 0; nnoisychannels = 0; nnoisychannels_counts = 0;
921  TProfile* h2 = (TProfile*)fChanRMSV_pfx.at(i);
922  FillChannelHistos(h2, fVRMS_mean.at(i), fVRMS_sigma.at(i), ndeadchannels, nnoisychannels, nnoisychannels_counts);
923  fVdch_vec.push_back(ndeadchannels);
924  fVnch_vec.push_back(nnoisychannels);
925  fVcch_vec.push_back(nnoisychannels_counts);
926 
927  // Z plane
928  ndeadchannels = 0; nnoisychannels = 0; nnoisychannels_counts = 0;
929  TProfile* h3 = (TProfile*)fChanRMSZ_pfx.at(i);
930  FillChannelHistos(h3, fZRMS_mean.at(i), fZRMS_sigma.at(i), ndeadchannels, nnoisychannels, nnoisychannels_counts);
931  fZdch_vec.push_back(ndeadchannels);
932  fZnch_vec.push_back(nnoisychannels);
933  fZcch_vec.push_back(nnoisychannels_counts);
934  }
935 
936  // Fill summary histograms
937  for(unsigned int i = 0; i < fNofAPA; i++){
938  unsigned int j=fApaLabelNum.at(i);
939  int nch = fUdch_vec.at(i) + fVdch_vec.at(i) + fZdch_vec.at(i);
940  fNDeadChannelsHisto->SetBinContent(j+1, nch);
941  nch = fUnch_vec.at(i) + fVnch_vec.at(i) + fZnch_vec.at(i);
942  fNNoisyChannelsHistoFromNSigma->SetBinContent(j+1, nch);
943  nch = fUcch_vec.at(i) + fVcch_vec.at(i) + fZcch_vec.at(i);
944  fNNoisyChannelsHistoFromNCounts->SetBinContent(j+1, nch);
945 
946  fNDeadChannelsHistoU->SetBinContent(j+1, fUdch_vec.at(i));
947  fNDeadChannelsHistoV->SetBinContent(j+1, fVdch_vec.at(i));
948  fNDeadChannelsHistoZ->SetBinContent(j+1, fZdch_vec.at(i));
949 
950  fNNoisyChannelsHistoFromNSigmaU->SetBinContent(j+1, fUnch_vec.at(i));
951  fNNoisyChannelsHistoFromNSigmaV->SetBinContent(j+1, fVnch_vec.at(i));
952  fNNoisyChannelsHistoFromNSigmaZ->SetBinContent(j+1, fZnch_vec.at(i));
953 
954  fNNoisyChannelsHistoFromNCountsU->SetBinContent(j+1, fUcch_vec.at(i));
955  fNNoisyChannelsHistoFromNCountsV->SetBinContent(j+1, fVcch_vec.at(i));
956  fNNoisyChannelsHistoFromNCountsZ->SetBinContent(j+1, fZcch_vec.at(i));
957  }
958 
959  // myfileU.close();
960  // myfileV.close();
961  // myfileZ.close();
962  return;
963  }
964 
965 }
966 
968 
969 
970 
971 #endif // TpcMonitore_module
std::vector< TProfile * > fChanStuckCodeOnFracZ
std::vector< TH2F * > fChanFFTV
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
Definition: RawDigit.h:210
std::vector< TH2F * > fChanFFTU
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Definition: RawDigit.h:213
Collection of charge vs time digitized from a single readout channel.
Definition: RawDigit.h:69
std::vector< TProfile * > fFFT_by_Fiber_pfx
std::vector< TH1F * > fStuckCodeOffFrac
unsigned int FiberIdFromOfflineChannel(unsigned int offlineChannel) const
Returns global fiber ID.
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:40
unsigned int FEMBChannelFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB channel.
std::vector< TProfile * > fChanStuckCodeOffFracU
float meanADC(std::vector< short > &uncompressed)
std::vector< TProfile * > fChanMeanZ_pfx
std::string string
Definition: nybbler.cc:12
Planes which measure V.
Definition: geo_types.h:130
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
std::vector< TProfile * > fChanStuckCodeOnFracV
ChannelID_t Channel() const
DAQ channel this raw data was read from.
Definition: RawDigit.h:212
std::vector< raw::RawDigit > RawDigits
Definition: HDF5Utils.h:23
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
int16_t adc
Definition: CRTFragment.hh:202
Planes which measure Z direction.
Definition: geo_types.h:132
std::vector< TProfile * > fChanMeanV_pfx
std::vector< TH1F * > fChanMeanDistU
Scale(size_t pos, T factor) -> Scale< T >
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
void beginRun(const art::Run &run)
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
std::vector< TH2F * > fPersistentFFT_by_APA
static QStrList * l
Definition: config.cpp:1044
art framework interface to geometry description
Definition: Run.h:17
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
std::vector< TH1F * > fChanRMSDistU
std::vector< TProfile * > fChanStuckCodeOffFracV
T abs(T value)
Planes which measure U.
Definition: geo_types.h:129
unsigned int SlotIdFromOfflineChannel(unsigned int offlineChannel) const
Returns global slot ID.
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:67
std::vector< TProfile * > fChanStuckCodeOnFracU
std::vector< TProfile * > fChanRMSZ_pfx
std::vector< TProfile * > fSlotChanRMS_pfx
TpcMonitor(fhicl::ParameterSet const &pset)
std::void_t< T > n
int FEMBchanToHistogramMap(int, int)
T get(std::string const &key) const
Definition: ParameterSet.h:271
std::vector< TH1F * > fChanRMSDistZ
size_t NADC() const
Number of elements in the compressed ADC sample vector.
Definition: RawDigit.h:207
std::vector< unsigned int > fApaLabelNum
p
Definition: test.py:223
void reconfigure(fhicl::ParameterSet const &pset)
std::vector< TProfile2D * > fBitValue
Description of geometry of one entire detector.
std::vector< TH1F * > fChanMeanDistZ
#define MF_LOG_INFO(category)
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.
float rmsADC(std::vector< short > &uncompressed)
geo::GeometryCore const * fGeom
std::vector< TProfile * > fChanMeanU_pfx
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
Definition: RawDigit.h:216
unsigned int WIBFromOfflineChannel(unsigned int offlineChannel) const
Returns WIB/slot.
void FillChannelHistos(TProfile *h1, double mean, double sigma, int &ndeadchannels, int &nnoisychannels_sigma, int &nnoisychannels_counts)
std::vector< TH1F * > fChanMeanDistV
std::vector< TProfile * > fChanRMSV_pfx
void analyze(const art::Event &evt)
std::vector< TH2F * > fChanFFTZ
void calculateFFT(TH1D *hist_waveform, TH1D *graph_frequency)
unsigned int FEMBFromOfflineChannel(unsigned int offlineChannel) const
Returns FEMB/fiber.
static constexpr double mm
Definition: Units.h:65
std::vector< TProfile * > fChanStuckCodeOffFracZ
std::vector< TH1F * > fChanRMSDistV
TCEvent evt
Definition: DataStructs.cxx:7
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:297
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
Definition: statistics.cc:16
std::vector< TProfile * > fChanRMSU_pfx
QTextStream & endl(QTextStream &s)
Event finding and building.
std::vector< TProfile * > fSlotChanMean_pfx
std::vector< TH1F * > fStuckCodeOnFrac