GoodRun_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: GoodRun
3 // Module Type: Analyzer
4 // File: GoodRun_module.cc
5 //
6 // Module written by Karl Warburton to compare the timings for RCE, SSP
7 // and PTB data streams.
8 ////////////////////////////////////////////////////////////////////////
9 
15 #include "art_root_io/TFileService.h"
16 #include "fhiclcpp/ParameterSet.h"
18 
21 #include "lardataobj/RawData/raw.h"
24 
27 
28 #include <memory>
29 #include <iostream>
30 #include <fstream>
31 #include <sstream>
32 #include <vector>
33 #include <list>
34 #include "TTree.h"
35 #include "TH2D.h"
36 #include "TList.h"
37 #include "TMatrixF.h"
38 #include "TVectorF.h"
39 #include "TVectorD.h"
40 
41 //const unsigned int MaxChannels = 2048; // unused
42 
43 namespace DAQToOffline {
44  class GoodRun;
45 }
46 
48 public:
49  explicit GoodRun(fhicl::ParameterSet const & p);
50  virtual ~GoodRun();
51 
52  void analyze(art::Event const & evt) override;
53  void beginJob() override;
54  void beginRun(const art::Run& r) override;
55  void endRun(const art::Run& r) override;
56  void endJob() override;
57  void printParameterSet();
58 
59 private:
60 
61  // Information for good run list histogram
62  TTree* fTree;
63  int RunNumber;
64  int TotEvents;
66  double FracRCEs;
67  double AvADCPedDiff;
68  double FracWaveforms;
69  double FracOpHits;
77 
78  //TH2D* ADCDiff;
79  //TH2D* ADCPed;
80 
81 
82  TTree* FlatTree;
83  int Event;
84  unsigned int DigSize;
85  unsigned int NSamples;
86  std::vector<int > ChanNum;
87  std::vector<float> ADCVec;
88 
91  short unsigned int fMaxSamples;
92 
93  std::vector<int> MyUsefulChans;
94 };
95 
97  : EDAnalyzer(pset)
98  , fMakeFlatTree (pset.get<bool>("MakeFlatTree"))
99  //---------------------------RCE--------------------------------------
100  , fCounterModuleLabel (pset.get<std::string>("CounterModuleLabel"))
101  , fWaveformModuleLabel(pset.get<std::string>("WaveformModuleLabel"))
102  , fRawDigitModuleLabel(pset.get<std::string>("RawDigitModuleLabel"))
103  , fOpHitModuleLabel (pset.get<std::string>("OpHitModuleLabel"))
104  , fMaxSamples (pset.get<short unsigned int>("MaxSamples", 2048))
105  //---------------------------SSP--------------------------------------
106 // ,fSSPFragType ( pset.get<std::string>("SSPFragType"))
107 // ,fSSPRawDataLabel ( pset.get<std::string>("SSPRawDataLabel"))
108  //---------------------------PTB--------------------------------------
109 // ,fPTBFragType ( pset.get<std::string>("PTBFragType"))
110 // ,fPTBRawDataLabel ( pset.get<std::string>("PTBRawDataLabel"))
111  //--------------------------------------------------------------------
112 {
113 }
114 
116 }
117 
119 
121 
122  if (!fMakeFlatTree) {
123  fTree = tfs->make<TTree>("RunList","RunList Information");
124  fTree->Branch("RunNumber" ,&RunNumber );
125  fTree->Branch("TotEvents" ,&TotEvents );
126  fTree->Branch("NumberOfRCEs" ,&NumberOfRCEs );
127  fTree->Branch("FracRCEs" ,&FracRCEs );
128  fTree->Branch("AvADCPedDiff" ,&AvADCPedDiff );
129  fTree->Branch("FracWaveforms" ,&FracWaveforms );
130  fTree->Branch("FracOpHits" ,&FracOpHits );
131  fTree->Branch("nPTBTrigsOn110",&nPTBTrigsOn110);
132  fTree->Branch("nPTBTrigsOn111",&nPTBTrigsOn111);
133  fTree->Branch("nPTBTrigsOn112",&nPTBTrigsOn112);
134  fTree->Branch("nPTBTrigsOn113",&nPTBTrigsOn113);
135  fTree->Branch("nPTBTrigsOn114",&nPTBTrigsOn114);
136  fTree->Branch("nPTBTrigsOn115",&nPTBTrigsOn115);
137  fTree->Branch("EvJustSSPs" ,&EvJustSSPs );
138  //ADCDiff = tfs->make<TH2D>("ADCDiff","Difference in average ADC value and pedestal; Channel number; Difference (ADCs)", 2049,0,2048, 400,-50,50);
139  //ADCPed = tfs->make<TH2D>("ADCPed" ,"Comparison of Average ADC values, and pedestal; Average ADC; Pedestal", 1200, 400, 1000, 1200, 400, 1000);
140 
141  } else {
142 
143  // I need to choose which channels I want to look at.....
144  // Runs 18407 - 18411 used RCEs 0, 4, 12, 15
145  // Runs 18412 - 18422 used RCEs 0, 4, 11, 12, 13, 15
146  // Runs 18423 - 18430 used RCEs 0, 4, 11
147 
148  // To convert from the RCE number to the channels I want to store, look at Mikes detailed channel map here:
149  // https://cdcvs.fnal.gov/redmine/projects/35ton/wiki/Channel_map
150  FlatTree = tfs->make<TTree>("FlatDigitTree","FlatDigitTree");
151  FlatTree->Branch("Event" ,&Event ,"Event/I" );
152  FlatTree->Branch("NSamples",&NSamples,"NSamples/I");
153  FlatTree->Branch("DigSize" ,&DigSize ,"DigSize/I" );
154  FlatTree->Branch("ChanNum" ,&ChanNum);
155  FlatTree->Branch("ADCVec" ,&ADCVec );
156  }
157 }
158 
160 
162  std::cout << "At the start of the run....going to reset all the variables. " << std::endl;
163 
164 }
165 
167 {
168  if (TotEvents==0) {
169  RunNumber = evt.run();
170  std::cout << "Got runNumber it is " << RunNumber << std::endl;
171  }
172  ++TotEvents;
173 
174  // get raw::RawDigits
175  art::Handle< std::vector< raw::RawDigit> > externalRawDigitListHandle;
176  std::vector< art::Ptr< raw::RawDigit> > digits;
177  if (evt.getByLabel(fRawDigitModuleLabel, externalRawDigitListHandle) )
178  art::fill_ptr_vector(digits,externalRawDigitListHandle);
179 
180  if (fMakeFlatTree) {
181  Event = evt.event();
182  DigSize = digits.size();
183  NSamples = digits[0]->Samples();
185  // skip this because types may be different: NSamples = std::min( digits[0]->Samples(), fMaxSamples );
186 
187  ADCVec.clear();
188  for (unsigned int dig=0; dig<DigSize; ++dig ) {
189  ChanNum.push_back( digits[dig]->Channel() );
190  unsigned int Samp=0;
191  while ( Samp < NSamples ) {
192  //std::cerr << "Looking at digit " << dig << ", sample " << Samp << ", my value is " << digits[dig]->ADC(Samp) << std::endl;
193  ADCVec.push_back ( digits[dig]->ADC(Samp) );
194  ++Samp;
195  }
196  //std::cout << "Looking at Event " << Event << ", DigSize " << DigSize << ", ChanNum " << ChanNum[dig] << ", NSamples " << NSamples << ", ADCVec.size() " << ADCVec.size() << std::endl;
197  }
198  FlatTree->Fill();
199  } else {
200  // get raw::ExternalTriggers
201  art::Handle< std::vector< raw::ExternalTrigger> > externalTriggerListHandle;
202  std::vector< art::Ptr< raw::ExternalTrigger> > trigs;
203  if (evt.getByLabel(fCounterModuleLabel, externalTriggerListHandle) )
204  art::fill_ptr_vector(trigs,externalTriggerListHandle);
205 
206  // get raw::OpDetWaveforms
207  art::Handle< std::vector< raw::OpDetWaveform> > externalWaveformListHandle;
208  std::vector< art::Ptr< raw::OpDetWaveform> > waveforms;
209  if (evt.getByLabel(fWaveformModuleLabel, externalWaveformListHandle) )
210  art::fill_ptr_vector(waveforms,externalWaveformListHandle);
211 
212  // get recob::OpHits
213  art::Handle< std::vector< recob::OpHit> > externalOpHitListHandle;
214  std::vector< art::Ptr< recob::OpHit> > ophits;
215  if (evt.getByLabel(fOpHitModuleLabel, externalOpHitListHandle) )
216  art::fill_ptr_vector(ophits,externalOpHitListHandle);
217 
218  bool RCEsPresent = false;
219  //bool PTBPresent = false;
220  bool WavePresent = false;
221  //bool OHitPresent = false;
222 
223  // RCEs
224  if (digits.size()) {
225  RCEsPresent = true;
226  ++FracRCEs;
227  if (NumberOfRCEs == 0) {
228  NumberOfRCEs = digits.size() / 128;
229 
230  //GET THE LIST OF BAD CHANNELS.
232  lariov::ChannelStatusProvider::ChannelSet_t const BadChannels = channelStatus.BadChannels();
233 
234  for (size_t dig=0; dig<digits.size(); ++dig) {
235  double AvADC = 0;
236  unsigned int Channel = digits[dig]->Channel();
237  double Pedestal = digits[dig]->GetPedestal();
238  for (size_t samp=0; samp<digits[dig]->Samples(); ++samp)
239  AvADC += digits[dig]->ADC(samp);
240  AvADC = AvADC / digits[dig]->Samples();
241  // Do I want to use this channel? Both AvADC and Pedestal, plus not a 'bad' channel...
242  bool UseChan = true;
243  if ( AvADC == 0 && Pedestal == 0)
244  UseChan = false;
245  for (auto it = BadChannels.begin(); it != BadChannels.end(); it++) {
246  if(Channel==*it) {
247  UseChan = false;
248  break;
249  }
250  } // Loop through bad chans.
251  if ( UseChan ) {
252  double ADCPedDiff = AvADC - Pedestal;
253  //ADCDiff->Fill( Channel, ADCPedDiff );
254  //ADCPed ->Fill( AvADC , Pedestal );
255  AvADCPedDiff += fabs(ADCPedDiff);
256  } // If have data for this tick, ie not turned off.
257  } // Loop over digits
258  AvADCPedDiff = AvADCPedDiff / digits.size();
259  } // NumberOfRCEs == 0
260  }
261 
262  // PTB
263  if (trigs.size()) {
264  //PTBPresent = true;
265  for (size_t tr=0; tr<trigs.size(); ++tr) {
266  if (trigs[tr]->GetTrigID() < 100) continue;
267  if (trigs[tr]->GetTrigID() == 110) ++nPTBTrigsOn110;
268  if (trigs[tr]->GetTrigID() == 111) ++nPTBTrigsOn111;
269  if (trigs[tr]->GetTrigID() == 112) ++nPTBTrigsOn112;
270  if (trigs[tr]->GetTrigID() == 113) ++nPTBTrigsOn113;
271  if (trigs[tr]->GetTrigID() == 114) ++nPTBTrigsOn114;
272  if (trigs[tr]->GetTrigID() == 115) ++nPTBTrigsOn115;
273  }
274  }
275 
276  // Waveforms
277  if (waveforms.size()) {
278  WavePresent = true;
279  ++FracWaveforms;
280  if (!RCEsPresent) ++EvJustSSPs;
281  }
282 
283  // OpHits
284  if (ophits.size()) {
285  //OHitPresent = true;
286  ++FracOpHits;
287  if (!RCEsPresent && !WavePresent) ++EvJustSSPs;
288  }
289  }
290 }
291 
293 {
294  if (!fMakeFlatTree) {
298  std::cout << "At the end of the run, I am putting the following into the TTree:\n"
299  << RunNumber << " " << TotEvents << " " << NumberOfRCEs << " " << FracRCEs << " " << AvADCPedDiff << " " << FracWaveforms << " " << FracOpHits << " "
300  << nPTBTrigsOn110 << " " << nPTBTrigsOn111 << " " << nPTBTrigsOn112 << " " << nPTBTrigsOn113 << " " << nPTBTrigsOn114 << " " << nPTBTrigsOn115 << " " << EvJustSSPs
301  << std::endl;
302  fTree->Fill();
303  }
304 }
305 
307 }
308 
std::vector< float > ADCVec
std::string fCounterModuleLabel
virtual ChannelSet_t BadChannels() const =0
Returns a copy of set of bad channel IDs for the current run.
EventNumber_t event() const
Definition: DataViewImpl.cc:96
std::set< raw::ChannelID_t > ChannelSet_t
Type of set of channel IDs.
short unsigned int fMaxSamples
std::vector< int > MyUsefulChans
std::string string
Definition: nybbler.cc:12
GoodRun(fhicl::ParameterSet const &p)
STL namespace.
Definition of basic raw digits.
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:27
Definition: Run.h:21
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Definition: DataViewImpl.h:446
std::string fWaveformModuleLabel
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:69
void endJob() override
void beginRun(const art::Run &r) override
Collect all the RawData header files together.
Class providing information about the quality of channels.
RunNumber_t run() const
Definition: DataViewImpl.cc:82
std::string fOpHitModuleLabel
void analyze(art::Event const &evt) override
p
Definition: test.py:223
void endRun(const art::Run &r) override
ChannelMappingService::Channel Channel
Interface for experiment-specific channel quality info provider.
std::string fRawDigitModuleLabel
TCEvent evt
Definition: DataStructs.cxx:7
auto const & get(AssnsNode< L, R, D > const &r)
Definition: AssnsNode.h:115
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
Definition: Ptr.h:291
Interface for experiment-specific service for channel quality info.
void beginJob() override
int bool
Definition: qglobal.h:345
QTextStream & endl(QTextStream &s)
std::vector< int > ChanNum