All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TPCNoise_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: TPCNoise
3 // Plugin Type: producer (art v3_05_01)
4 // File: TPCNoise_module.cc
5 //
6 // Generated at Thu Jan 21 16:22:15 2021 by Justin Mueller using cetskelgen
7 // from cetlib version v3_10_00.
8 ////////////////////////////////////////////////////////////////////////
9 
10 // LArSoft Includes
14 #include "lardataobj/RawData/raw.h"
17 #include "cetlib/cpu_timer.h"
22 
23 #include "art/Framework/Core/EDAnalyzer.h"
24 #include "art/Framework/Core/ModuleMacros.h"
25 #include "art/Framework/Principal/Event.h"
26 #include "art/Framework/Principal/Handle.h"
27 #include "art/Framework/Principal/Run.h"
28 #include "art/Framework/Principal/SubRun.h"
29 #include "art_root_io/TFileService.h"
30 #include "art/Framework/Core/ModuleMacros.h"
31 #include "art/Utilities/make_tool.h"
32 #include "canvas/Utilities/InputTag.h"
33 #include "canvas/Persistency/Common/FindManyP.h"
34 #include "messagefacility/MessageLogger/MessageLogger.h"
35 #include "fhiclcpp/ParameterSet.h"
36 #include "cetlib_except/exception.h"
37 
38 // icaruscode Includes
40 
41 // icarus_signal_processing Includes
42 #include "icarus_signal_processing/Filters/ICARUSFFT.h"
43 
44 // ROOT Includes
45 #include "TTree.h"
46 #include "TFile.h"
47 // C++ Includes
48 #include <map>
49 #include <vector>
50 #include <tuple>
51 #include <algorithm>
52 #include <iostream>
53 #include <string>
54 #include <cmath>
55 #include <iostream>
56 #include <fstream>
57 #include <memory>
58 #include <numeric> // std::accumulate
59 
60 namespace tpcnoise {
61  class TPCNoise;
62 }
63 
64 
65 class tpcnoise::TPCNoise : public art::EDAnalyzer {
66 public:
67  explicit TPCNoise(fhicl::ParameterSet const& p);
68  // The compiler-generated destructor is fine for non-base
69  // classes without bare pointers or other resource use.
70 
71  // Plugins should not be copied or assigned.
72  //TPCNoise(TPCNoise const&) = delete;
73  //TPCNoise(TPCNoise&&) = delete;
74  //TPCNoise& operator=(TPCNoise const&) = delete;
75  //TPCNoise& operator=(TPCNoise&&) = delete;
76 
77  void analyze(const art::Event& e);
78  void reconfigure(fhicl::ParameterSet const& pset);
79  void beginJob();
80 // void beginRun();
81  void endJob();
82  // void endRun();
83 
84 private:
85  // Various FHiCL parameters.
86  std::string fRawDigitModuleLabel;
87  std::string fRawDigitProcess;
88  std::string fRawInstance;
89  std::string fIntrinsicInstance;
90 std::string fCoherentInstance;
91 std::string fHistoFileName;
92 
93 
94  // FFT calculation.
95  using FFTPointer = std::unique_ptr<icarus_signal_processing::ICARUSFFT<double>>;
98 
99  // FFT variables.
100  std::vector< std::vector<float> > fRawPowerC;
101  std::vector< std::vector<float> > fIntrinsicPowerC;
102 std::vector< std::vector<float> > fCoherentPowerC;
103  // FFT variables.
104  std::vector< std::vector<float> > fRawPowerI1;
105  std::vector< std::vector<float> > fIntrinsicPowerI1;
106 std::vector< std::vector<float> > fCoherentPowerI1;
107  // FFT variables.
108  std::vector< std::vector<float> > fRawPowerI2;
109  std::vector< std::vector<float> > fIntrinsicPowerI2;
110 std::vector< std::vector<float> > fCoherentPowerI2;
111 
112 int ctI1, ctI2, ctC;
113 
114 
115 
116 
117 
118 // average FFT histos
126 // average FFT histos
134 // average FFT histos
142  // The variables that will go into the n-tuple.
143  int fEvent;
144  int fRun;
145  int fSubRun;
146  std::vector<float> fPed;
147  std::vector<float> fRawMeanC;
148  std::vector<float> fRawMeanI1;
149  std::vector<float> fRawMeanI2;
150  std::vector<double> fRawRMSC;
151  std::vector<double> fRawRMSI1;
152  std::vector<double> fRawRMSI2;
153  std::vector<double> fRawRMSTrim;
154  std::vector<float> fIntrinsicMean;
155  std::vector<double> fIntrinsicRMSC;
156  std::vector<double> fIntrinsicRMSI1;
157  std::vector<double> fIntrinsicRMSI2;
158  std::vector<double> fIntrinsicRMSTrim;
159  std::vector<float> fCoherentMean;
160  std::vector<double> fCoherentRMSC;
161  std::vector<double> fCoherentRMSI1;
162  std::vector<double> fCoherentRMSI2;
163  std::vector<double> fCoherentRMSTrim;
164  std::vector<unsigned short int> fChannel;
165 
166  // The variables that will go into the power n-tuple.
167  //std::vector< std::vector<float> > fPower;
168  unsigned int NEvents;
169 
170  // The output trees.
171  TTree* fNoiseTree;
175 };
176 
177 
178 tpcnoise::TPCNoise::TPCNoise(fhicl::ParameterSet const& p)
179  : EDAnalyzer(p),
180  NEvents(0)
181 {
182  // Retrieve proper number of time samples.
183  auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
184  NumberTimeSamples = detProp.NumberTimeSamples();
185 
186  std::cout << "Number of time samples: " << NumberTimeSamples << std::endl;
187 ctI1=0; ctI2=0; ctC=0;
188 
189  fRawPowerC.resize(1);
190  for(auto &it : fRawPowerC)
191  {
192  it.resize(NumberTimeSamples);
193  }
194 std::cout << " after resizing " << std::endl;
195  fIntrinsicPowerC.resize(1);
196  for(auto &it : fIntrinsicPowerC)
197  {
198  it.resize(NumberTimeSamples);
199  }
200 std::cout << " after resizing " << std::endl;
201  fCoherentPowerC.resize(1);
202  for(auto &it : fCoherentPowerC)
203  {
204  it.resize(NumberTimeSamples);
205  }
206 
207 std::cout << " after resizing " << std::endl;
208  fRawPowerI1.resize(1);
209  for(auto &it : fRawPowerI1)
210  {
211  it.resize(NumberTimeSamples);
212  }
213 std::cout << " after resizing " << std::endl;
214  fIntrinsicPowerI1.resize(1);
215  for(auto &it : fIntrinsicPowerI1)
216  {
217  it.resize(NumberTimeSamples);
218  }
219 std::cout << " after resizing " << std::endl;
220  fCoherentPowerI1.resize(1);
221  for(auto &it : fCoherentPowerI1)
222  {
223  it.resize(NumberTimeSamples);
224  }
225 fCoherentPowerI2.resize(1);
226  for(auto &it : fCoherentPowerI2)
227  {
228  it.resize(NumberTimeSamples);
229  }
230 std::cout << " after resizing " << std::endl;
231  fRawPowerI2.resize(1);
232  for(auto &it : fRawPowerI2)
233  {
234  it.resize(NumberTimeSamples);
235  }
236 std::cout << " after resizing " << std::endl;
237  fIntrinsicPowerI2.resize(1);
238  for(auto &it : fIntrinsicPowerI2)
239  {
240  it.resize(NumberTimeSamples);
241  }
242 std::cout << " after intrinsic i2 resizing " << std::endl;
243 
244  fFFT = std::make_unique<icarus_signal_processing::ICARUSFFT<double>>(NumberTimeSamples);
245  this->reconfigure(p);
246 double freqBin=0.6103515625;
247 fRawPowerHistoC=new TH1D("rawpowerC","rawpowerC",2048,0.,2048*freqBin);
248 fIntrinsicPowerHistoC=new TH1D("intpowerC","intpowerC",2048,0.,2048*freqBin);
249 fCoherentPowerHistoC=new TH1D("cohpowerC","cohpowerC",2048,0.,2048*freqBin);
250 fRawRMSHistoC=new TH1D("rawRMSC","rawRMSC",100,0.,30.);
251 fMediaHistoC=new TH1D("mediaC","mediaC",100,-10.,10.);
252 fIntrinsicRMSHistoC=new TH1D("intRMSC","intRMSC",100,0.,30.);
253 fCoherentRMSHistoC=new TH1D("cohRMSC","cohRMSC",100,0.,30.);
254 fRawPowerHistoI1=new TH1D("rawpowerI1","rawpowerI1",2048,0.,2048*freqBin);
255 fIntrinsicPowerHistoI1=new TH1D("intpowerI1","intpowerI1",2048,0.,2048*freqBin);
256 fCoherentPowerHistoI1=new TH1D("cohpowerI1","cohpowerI1",2048,0.,2048*freqBin);
257 fRawRMSHistoI1=new TH1D("rawRMSI1","rawRMSI1",100,0.,30.);
258 fMediaHistoI1=new TH1D("mediaI1","mediaI1",100,-10.,10.);
259 fIntrinsicRMSHistoI1=new TH1D("intRMSI1","intRMSI1",100,0.,30.);
260 fCoherentRMSHistoI1=new TH1D("cohRMSI1","cohRMSI1",100,0.,30.);
261 fRawPowerHistoI2=new TH1D("rawpowerI2","rawpowerI2",2048,0.,2048*freqBin);
262 fIntrinsicPowerHistoI2=new TH1D("intpowerI2","intpowerI2",2048,0.,2048*freqBin);
263 fCoherentPowerHistoI2=new TH1D("cohpowerI2","cohpowerI2",2048,0.,2048*freqBin);
264 fRawRMSHistoI2=new TH1D("rawRMSI2","rawRMSI2",100,0.,30.);
265 fMediaHistoI2=new TH1D("mediaI2","mediaI2",100,-10.,10.);
266 fIntrinsicRMSHistoI2=new TH1D("intRMSI2","intRMSI2",100,0.,30.);
267 fCoherentRMSHistoI2=new TH1D("cohRMSI2","cohRMSI2",100,0.,30.);
268 
269 
270  fRawRMSC.clear();
271  fCoherentRMSC.clear();
272  fRawRMSTrim.clear();
273 fRawRMSI1.clear();
274  fCoherentRMSI1.clear();
275 fRawRMSI2.clear();
276  fCoherentRMSI2.clear();
277  fIntrinsicMean.clear();
278  fIntrinsicRMSC.clear();
279 fIntrinsicRMSI1.clear();
280 fIntrinsicRMSI2.clear();
281  fIntrinsicRMSTrim.clear();
282 
283 std::cout << " end constructor " << std::endl;
284 }
285 
286 void tpcnoise::TPCNoise::analyze(const art::Event& e)
287 {
288 std::cout << " begin analyze " << std::endl;
289  art::ServiceHandle<geo::Geometry> geom;
290 
291  // Clear vectors before filling for this event.
292  fChannel.clear();
293 std::cout << " after clearing " << std::endl;
294  fPed.clear();
295  fRawMeanC.clear();
296 fRawMeanI1.clear();
297 fRawMeanI2.clear();
298 std::cout << " after clearing " << std::endl;
299 
300  // Fill event level variables.
301  fEvent = e.id().event();
302 std::cout << " event " << fEvent << std::endl;
303  fRun = e.id().run();
304 std::cout << " run " << fRun << std::endl;
305  fSubRun = e.id().subRun();
306  std::cout << " subrun " << fSubRun << std::endl;
307  std::cout << "Processing event " << NEvents+1 << " for TPC Noise Analysis " << " Run " << fRun << ", " << "Event " << fEvent << "." << std::endl;
308 
309 
310  ///////////////////////////
311  // "Raw" RawDigits.
312  ///////////////////////////
313 
314  art::Handle< std::vector<raw::RawDigit> > RawDigitHandle;
315  e.getByLabel(fRawDigitModuleLabel, fRawInstance, fRawDigitProcess, RawDigitHandle);
316 
317  std::cout << " raw instance " << fRawInstance << std::endl;
318 
319  for(const auto& RawDigit : *RawDigitHandle)
320  {
321  // Grab raw waveform, ensuring that the size is set appropriately.
322  unsigned int DataSize = RawDigit.Samples();
323  std::vector<short> RawADC;
324  RawADC.resize(DataSize);
325  raw::Uncompress(RawDigit.ADCs(), RawADC, RawDigit.Compression());
326 
327  // We need a sorted waveform (by absolute value) for the truncated RMS and median calculation.
328  std::vector<short> SortedADC(RawADC);
329  std::sort(SortedADC.begin(),SortedADC.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
330  float median(SortedADC.at(SortedADC.size()/2));
331 
332  // Calculate mean values.
333  float mean(float(std::accumulate(SortedADC.begin(),SortedADC.end(),0))/float(SortedADC.size()));
334 std::vector<geo::WireID> widVec = geom->ChannelToWire(RawDigit.Channel());
335  size_t plane = widVec[0].Plane;
336  size_t wire = widVec[0].Wire;
337 
338 
339  // Remove pedestal of waveform.
340  std::vector<float> ADCLessPed;
341  ADCLessPed.resize(SortedADC.size());
342  std::transform(SortedADC.begin(),SortedADC.end(),ADCLessPed.begin(),std::bind(std::minus<float>(),std::placeholders::_1,median));
343 
344  // Calculate full RMS.
345  float rms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.end(), ADCLessPed.begin(), 0.) / float(ADCLessPed.size())));
346 
347  // Calculate the truncated RMS.
348  unsigned int MinBins((1.0 - 0.01)*ADCLessPed.size());
349  //unsigned int BinsToKeep;
350  //for(BinsToKeep = 0; BinsToKeep < ADCLessPed.size(); ++BinsToKeep)
351  //{
352  // if(std::fabs(ADCLessPed.at(BinsToKeep)) >= 3*rms) break;
353  //}
354  //float truncrms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.begin() + BinsToKeep, ADCLessPed.begin(), 0.) / float(BinsToKeep)));
355  float truncrms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.begin() + MinBins, ADCLessPed.begin(), 0.) / float(MinBins)));
356 
357  // Calculate the power.
358  std::vector<double> power(DataSize);
359  std::vector<double> RawLessPed;
360  RawLessPed.resize(RawADC.size());
361  std::transform(RawADC.begin(),RawADC.end(),RawLessPed.begin(),std::bind(std::minus<double>(),std::placeholders::_1,median));
362  fFFT->getFFTPower(RawLessPed, power);
363 
364 
365 
366 if(plane==0&&wire!=32&&wire<3000) {
367 std::transform(fRawPowerI1.at(0).begin(), fRawPowerI1.at(0).end(), power.begin(), fRawPowerI1.at(0).begin(), std::plus<float>()); ctI1++; }
368 if(plane==1) { std::transform(fRawPowerI2.at(0).begin(), fRawPowerI2.at(0).end(), power.begin(), fRawPowerI2.at(0).begin(), std::plus<float>()); ctI2++; }
369 
370 if(plane==2) { std::transform(fRawPowerC.at(0).begin(), fRawPowerC.at(0).end(), power.begin(), fRawPowerC.at(0).begin(), std::plus<float>()); ctC++; }
371 
372 
373  fPed.push_back(median);
374  if(plane==2) fRawMeanC.push_back(mean);
375 if(plane==1) fRawMeanI2.push_back(mean);
376 if(plane==0) fRawMeanI1.push_back(mean);
377  if(plane==2) { fRawRMSC.push_back(rms); }
378 if(plane==0&&wire!=32&&wire<3000) { fRawRMSI1.push_back(rms); }
379  if(plane==1) { fRawRMSI2.push_back(rms); }
380  fRawRMSTrim.push_back(truncrms);
381 
382  fChannel.push_back(RawDigit.Channel());
383 
384  }
385 float intI1=0, intI2=0, intC=0;
386 std::vector<float> rpi1=fRawPowerI1.at(0);
387 std::vector<float> rpi2=fRawPowerI2.at(0);
388 std::vector<float> rpc=fRawPowerC.at(0);
389 for (unsigned int j=0; j< rpi1.size(); j++) intI1+=rpi1.at(j);
390 for (unsigned int j=0; j< rpi2.size(); j++) intI2+=rpi2.at(j);
391 for (unsigned int j=0; j< rpc.size(); j++) intC+=rpc.at(j);
392 
393 std::cout << " integral i1 " << intI1 << " integral i2 " << intI2 << " integral c " << intC << std::endl;
394  ///////////////////////////
395  // "Intrinsic" RawDigits.
396  ///////////////////////////
397  art::Handle< std::vector<raw::RawDigit> > IntrinsicHandle;
398  e.getByLabel(fRawDigitModuleLabel, fIntrinsicInstance, fRawDigitProcess, IntrinsicHandle);
399 
400  //std::cerr << RawDigitHandle << std::endl;
401  //ctI1=0; ctI2=0; ctC=0;
402 std::cout << " intrinsic instance " << fIntrinsicInstance << std::endl;
403  for(const auto& RawDigit : *IntrinsicHandle)
404  {
405  // Grab raw waveform, ensuring that the size is set appropriately.
406  unsigned int DataSize = RawDigit.Samples();
407  std::vector<short> RawADC;
408  RawADC.resize(DataSize);
409  raw::Uncompress(RawDigit.ADCs(), RawADC, RawDigit.Compression());
410 
411  // We need a sorted waveform (by absolute value) for the truncated RMS and median calculation.
412  std::vector<short> SortedADC(RawADC);
413  std::sort(SortedADC.begin(),SortedADC.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
414  float median(SortedADC.at(SortedADC.size()/2));
415 
416  // Calculate mean values.
417  float mean(float(std::accumulate(SortedADC.begin(),SortedADC.end(),0))/float(SortedADC.size()));
418 
419  // Remove pedestal of waveform.
420  std::vector<short> ADCLessPed;
421  ADCLessPed.resize(SortedADC.size());
422  std::transform(SortedADC.begin(),SortedADC.end(),ADCLessPed.begin(),std::bind(std::minus<float>(),std::placeholders::_1,median));
423 
424  // Calculate full RMS.
425  float rms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.end(), ADCLessPed.begin(), 0.) / float(ADCLessPed.size())));
426 
427  // Calculate the truncated RMS.
428  unsigned int MinBins((1.0 - 0.2)*ADCLessPed.size());
429  //unsigned int BinsToKeep;
430  //for(BinsToKeep = 0; BinsToKeep < ADCLessPed.size(); ++BinsToKeep)
431  //{
432  // if(std::fabs(ADCLessPed.at(BinsToKeep)) >= 3*rms) break;
433  //}
434  //float truncrms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.begin() + BinsToKeep, ADCLessPed.begin(), 0.) / float(BinsToKeep)));
435  float truncrms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.begin() + MinBins, ADCLessPed.begin(), 0.) / float(MinBins)));
436 
437  // Calculate the power.
438  std::vector<double> power(DataSize);
439  std::vector<double> RawLessPed;
440  RawLessPed.resize(RawADC.size());
441  std::transform(RawADC.begin(),RawADC.end(),RawLessPed.begin(),std::bind(std::minus<double>(),std::placeholders::_1,median));
442  fFFT->getFFTPower(RawLessPed, power);
443 std::vector<geo::WireID> widVec = geom->ChannelToWire(RawDigit.Channel());
444  size_t plane = widVec[0].Plane;
445 
446 if(plane==0) { std::transform(fIntrinsicPowerI1.at(0).begin(), fIntrinsicPowerI1.at(0).end(), power.begin(), fIntrinsicPowerI1.at(0).begin(), std::plus<float>()); }
447 if(plane==1) { std::transform(fIntrinsicPowerI2.at(0).begin(), fIntrinsicPowerI2.at(0).end(), power.begin(), fIntrinsicPowerI2.at(0).begin(), std::plus<float>()); }
448 if(plane==2) { std::transform(fIntrinsicPowerC.at(0).begin(), fIntrinsicPowerC.at(0).end(), power.begin(), fIntrinsicPowerC.at(0).begin(), std::plus<float>()); }
449  // std::transform(fIntrinsicPower.at(RawDigit.Channel()).begin(), fIntrinsicPower.at(RawDigit.Channel()).end(), power.begin(), fIntrinsicPower.at(RawDigit.Channel()).begin(), std::plus<float>());
450 
451  fIntrinsicMean.push_back(mean);
452  if(plane==2) { fIntrinsicRMSC.push_back(rms);}
453  if(plane==0)fIntrinsicRMSI1.push_back(rms);
454  if(plane==1) {fIntrinsicRMSI2.push_back(rms); }
455 
456  fIntrinsicRMSTrim.push_back(truncrms);
457  }
458 
459  ///////////////////////////
460  // "Coherent" RawDigits.
461  ///////////////////////////
462 
463  //RawDigitHandle.clear();
464  //e.getByLabel(art::InputTag(fRawDigitModuleLabel), RawDigitHandle);
465 
466  art::Handle< std::vector<raw::RawDigit> > CoherentHandle;
467  e.getByLabel(fRawDigitModuleLabel, fCoherentInstance, fRawDigitProcess, CoherentHandle);
468 std::cout << " coherent instance " << fCoherentInstance << std::endl;
469  //std::cerr << RawDigitHandle << std::endl;
470 //ctI1=0; ctI2=0; ctC=0;
471  for(const auto& RawDigit : *CoherentHandle)
472  {
473 
474  // Grab raw waveform, ensuring that the size is set appropriately.
475  unsigned int DataSize = RawDigit.Samples();
476  std::vector<short> RawADC;
477  RawADC.resize(DataSize);
478  raw::Uncompress(RawDigit.ADCs(), RawADC, RawDigit.Compression());
479 
480  // We need a sorted waveform (by absolute value) for the truncated RMS and median calculation.
481  std::vector<short> SortedADC(RawADC);
482  std::sort(SortedADC.begin(),SortedADC.end(),[](const auto& left, const auto& right){return std::fabs(left) < std::fabs(right);});
483  float median(SortedADC.at(SortedADC.size()/2));
484 //for(unsigned int jadc=0;jadc<SortedADC.size();jadc++)
485  //if(SortedADC.at(jadc))
486  //std::cout << " sorted adc " << SortedADC.at(jadc) << std::endl;
487 
488  // Calculate mean values.
489  float mean(float(std::accumulate(SortedADC.begin(),SortedADC.end(),0))/float(SortedADC.size()));
490 
491  // Remove pedestal of waveform.
492  std::vector<short> ADCLessPed;
493  ADCLessPed.resize(SortedADC.size());
494  std::transform(SortedADC.begin(),SortedADC.end(),ADCLessPed.begin(),std::bind(std::minus<float>(),std::placeholders::_1,median));
495 
496  // Calculate full RMS.
497  float rms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.end(), ADCLessPed.begin(), 0.) / float(ADCLessPed.size())));
498 
499  // Calculate the truncated RMS.
500  unsigned int MinBins((1.0 - 0.2)*ADCLessPed.size());
501  //unsigned int BinsToKeep;
502  //for(BinsToKeep = 0; BinsToKeep < ADCLessPed.size(); ++BinsToKeep)
503  //{
504  // if(std::fabs(ADCLessPed.at(BinsToKeep)) >= 3*rms) break;
505  //}
506  //float truncrms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.begin() + BinsToKeep, ADCLessPed.begin(), 0.) / float(BinsToKeep)));
507  float truncrms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.begin() + MinBins, ADCLessPed.begin(), 0.) / float(MinBins)));
508 
509  // Calculate the power.
510  std::vector<double> power(DataSize);
511  std::vector<double> RawLessPed;
512  RawLessPed.resize(RawADC.size());
513  std::transform(RawADC.begin(),RawADC.end(),RawLessPed.begin(),std::bind(std::minus<double>(),std::placeholders::_1,median));
514  fFFT->getFFTPower(RawLessPed, power);
515 std::vector<geo::WireID> widVec = geom->ChannelToWire(RawDigit.Channel());
516  size_t plane = widVec[0].Plane;
517 
518 if(plane==0) { std::transform(fCoherentPowerI1.at(0).begin(), fCoherentPowerI1.at(0).end(), power.begin(), fCoherentPowerI1.at(0).begin(), std::plus<float>()); }
519 if(plane==1) { std::transform(fCoherentPowerI2.at(0).begin(), fCoherentPowerI2.at(0).end(), power.begin(), fCoherentPowerI2.at(0).begin(), std::plus<float>()); }
520 if(plane==2) { std::transform(fCoherentPowerC.at(0).begin(), fCoherentPowerC.at(0).end(), power.begin(), fCoherentPowerC.at(0).begin(), std::plus<float>()); }
521 
522 //if(rms) std::cout << " coherent mean " << mean << " rms " << rms << std::endl;
523  fCoherentMean.push_back(mean);
524 if(rms) {
525  if(plane==2) { fCoherentRMSC.push_back(rms);}
526  if(plane==0)fCoherentRMSI1.push_back(rms);
527  if(plane==1) { fCoherentRMSI2.push_back(rms); }
528  fCoherentRMSTrim.push_back(truncrms);
529 }
530  }
531 //std::cout << " cohrms size " << fCoherentRMSC.size() << std::endl;
532 //for(int j=0;j<10;j++) std::cout << " j " << j << " cohrms C " << fCoherentRMSC.at(j) << " cohrms I2 " << fCoherentRMSI2.at(j) << std::endl;
533  fNoiseTree->Fill();
534 
535 
536  ++NEvents;
537 
538  return;
539 
540 }
541 
542 void tpcnoise::TPCNoise::reconfigure(fhicl::ParameterSet const& p)
543 {
544  fRawDigitModuleLabel = p.get< std::string >("RawDigitModuleLabel", std::string("daqTPC"));
545  //std::cerr << "fRawDigitModuleLabel: " << fRawDigitModuleLabel << std::endl;
546  fRawDigitProcess = p.get< std::string >("RawDigitProcess", std::string("decode"));
547  //std::cerr << "fRawDigitProcess: " << fRawDigitProcess << std::endl;
548  fRawInstance = p.get< std::string >("RawInstance", std::string("RAW"));
549  //std::cerr << "fRawInstance: " << fRawInstance << std::endl;
550  fIntrinsicInstance = p.get< std::string >("IntrinsicInstance", std::string("."));
551  //std::cerr << "fIntrinsicInstance: " << fIntrinsicInstance << std::endl;
552 fCoherentInstance = p.get< std::string >("CoherentInstance", std::string("Cor"));
553  // std::cout << "fCoherentInstance: " << fCoherentInstance << std::endl;
554 fHistoFileName = p.get< std::string >("HistoFileName");
555 
556  return;
557 
558 }
559 
561 {
562  art::ServiceHandle<art::TFileService> tfs;
563 
564  fNoiseTree = tfs->makeAndRegister<TTree>("TPCNoise_t", "TPC Noise");
565  fRawPowerTree = tfs->makeAndRegister<TTree>("TPCRawPower_t", "TPC Raw Power");
566  fIntrinsicPowerTree = tfs->makeAndRegister<TTree>("TPCIntrinsicPower_t", "TPC Intrinsic Power");
567 fCoherentPowerTree = tfs->makeAndRegister<TTree>("TPCCoherentPower_t", "TPC Coherent Power");
568 
569  // Initialize branches of the noise TTree.
570  fNoiseTree->Branch("Event", &fEvent, "Event/I");
571  fNoiseTree->Branch("Run", &fRun, "Run/I");
572  fNoiseTree->Branch("SubRun", &fSubRun, "SubRun/I");
573  fNoiseTree->Branch("Channel", &fChannel);
574  fNoiseTree->Branch("Pedestal", &fPed);
575  fNoiseTree->Branch("RawMeanC", &fRawMeanC);
576  fNoiseTree->Branch("RawRMSC", &fRawRMSC);
577 
578  fNoiseTree->Branch("RawTrimmedRMS", &fRawRMSTrim);
579  fNoiseTree->Branch("IntrinsicMean", &fIntrinsicMean);
580  fNoiseTree->Branch("IntrinsicRMSC", &fIntrinsicRMSC);
581  fNoiseTree->Branch("IntrinsicTrimmedRMS", &fIntrinsicRMSTrim);
582 
583  return;
584 }
585 
587 {
588 double freqBin=0.6103515625;
589 
590 
591 std::cout << " ctI1 " << ctI1 << " ctI2 " << ctI2 << " ctC " << ctC << std::endl;
592 
593 for(unsigned int j=0;j<(fRawPowerI1.at(0)).size();j++) {(fRawPowerI1.at(0)).at(j)/=2110;}
594 for(unsigned int j=0;j<(fCoherentPowerI1.at(0)).size();j++) {(fCoherentPowerI1.at(0)).at(j)/=2110;}
595 for(unsigned int j=0;j<(fIntrinsicPowerI1.at(0)).size();j++) {(fIntrinsicPowerI1.at(0)).at(j)/=2110;}
596 for(unsigned int j=0;j<(fRawPowerI2.at(0)).size();j++) {(fRawPowerI2.at(0)).at(j)/=5600;}
597 for(unsigned int j=0;j<(fCoherentPowerI2.at(0)).size();j++) {(fCoherentPowerI2.at(0)).at(j)/=5600;}
598 for(unsigned int j=0;j<(fIntrinsicPowerI2.at(0)).size();j++) {(fIntrinsicPowerI2.at(0)).at(j)/=5600;}
599 for(unsigned int j=0;j<(fRawPowerC.at(0)).size();j++) {(fRawPowerC.at(0)).at(j)/=5600;}
600 for(unsigned int j=0;j<(fCoherentPowerC.at(0)).size();j++) {(fCoherentPowerC.at(0)).at(j)/=5600;}
601 for(unsigned int j=0;j<(fIntrinsicPowerC.at(0)).size();j++) {(fIntrinsicPowerC.at(0)).at(j)/=5600;}
602 
603 
604  // Average the power vectors.
605  std::cout << "Averaging power vectors..." << std::endl;
606  std::vector<float> TMPVect;
607  fRawPowerTree->Branch("Power", &TMPVect);
608 int count=0;
609  for(auto &it : fRawPowerC)
610  {
611 count++;
612  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
613  TMPVect = it;
614  // fRawPowerTree->Fill();
615  std::cout << " tmpvect size " << TMPVect.size() << std::endl;
616 for(unsigned int jv=0;jv<TMPVect.size();jv++) {
617  std::cout << " filling raw power " << jv*freqBin << std::endl;
618 //if(jv==100)
619  fRawPowerHistoC->Fill(jv*freqBin,TMPVect[jv]);
620 
621  }
622 }
623 std::cout << " raw power entries " << fRawPowerHistoC->GetEntries() << std::endl;
624 std::cout << " raw power count " << count << std::endl;
625 fRawPowerHistoC->Scale(1./count);
626 std::cout << " after filling raw power histo " << std::endl;
627  fIntrinsicPowerTree->Branch("Power", &TMPVect);
628 count=0;
629  for(auto &it : fIntrinsicPowerC)
630  {
631 count++;
632  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
633  TMPVect = it;
634  std::cout << " tmpvect size " << TMPVect.size() << std::endl;
635  // fIntrinsicPowerTree->Fill();
636  std::cout << " after fill tmpvect size " << TMPVect.size() << std::endl;
637 for(unsigned int jv=0;jv<TMPVect.size();jv++) {
638 //std::cout << " filling jv " << jv << std::endl;
639 
640  fIntrinsicPowerHistoC->Fill(jv*freqBin,TMPVect[jv]);
641 }
642 fIntrinsicPowerHistoC->Scale(1./count);
643 std::cout << " after filling intrinsic power histo " << std::endl;
644  }
645 
646  fCoherentPowerTree->Branch("Power", &TMPVect);
647 count=0;
648  for(auto &it : fCoherentPowerC)
649  {
650 count++;
651  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
652  TMPVect = it;
653 
654  // fCoherentPowerTree->Fill();
655 
656 for(unsigned int jv=0;jv<TMPVect.size();jv++)
657  fCoherentPowerHistoC->Fill(jv*freqBin,TMPVect[jv]);
658  }
659 fCoherentPowerHistoC->Scale(1./count);
660 std::cout << " frawrmsc size " << fRawRMSC.size() << std::endl;
661  for(unsigned int jj=0;jj<fRawRMSC.size();jj++)
662  fRawRMSHistoC->Fill(fRawRMSC.at(jj));
663 std::cout << " after filling raw rms histo " << std::endl;
664 for(unsigned int j=0;j<fRawMeanC.size(); j++) {
665 std::cout << " filling media " << std::endl;
666  fMediaHistoC->Fill(fRawMeanC.at(j));
667 }
668 std::cout << " after filling media histo " << std::endl;
669 
670 for(unsigned int jj=0;jj<fIntrinsicRMSC.size();jj++)
671  fIntrinsicRMSHistoC->Fill(fIntrinsicRMSC.at(jj));
672 
673 std::cout << " fillhisto cohrms size " << fCoherentRMSC.size() << std::endl;
674 
675 for(unsigned int j=0;j<fCoherentRMSC.size();j++) {
676 //std::cout << " filling coherent RMS " << fCoherentRMSC.at(j) << std::endl;
677  fCoherentRMSHistoC->Fill(fCoherentRMSC.at(j));
678 }
679 
680  // Average the power vectors.
681  std::cout << "Averaging power vectors..." << std::endl;
682  //std::vector<float> TMPVect;
683  fRawPowerTree->Branch("Power", &TMPVect);
684 count=0;
685  for(auto &it : fRawPowerI1)
686  {
687  std::cout << " i1 counter " << count++ << std::endl;
688  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
689  TMPVect = it;
690  // fRawPowerTree->Fill();
691  // std::cout << " tmpvect size " << TMPVect.size() << std::endl;
692 for(unsigned int jv=0;jv<TMPVect.size();jv++)
693 //if(jv==100)
694  fRawPowerHistoI1->Fill(jv*freqBin,TMPVect[jv]);
695  }
696 fRawPowerHistoI1->Scale(1./count);
697 std::cout << " after filling raw power histo " << std::endl;
698  fIntrinsicPowerTree->Branch("Power", &TMPVect);
699 count=0;
700  for(auto &it : fIntrinsicPowerI1)
701  {
702  std::cout << " i1 counter " << count++ << std::endl;
703  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
704  TMPVect = it;
705  //astd::cout << " tmpvect size " << TMPVect.size() << std::endl;
706  // fIntrinsicPowerTree->Fill();
707  // std::cout << " after fill tmpvect size " << TMPVect.size() << std::endl;
708 for(unsigned int jv=0;jv<TMPVect.size();jv++) {
709 //std::cout << " filling jv " << jv << std::endl;
710  fIntrinsicPowerHistoI1->Fill(jv*freqBin,TMPVect[jv]);
711 }
712 fIntrinsicPowerHistoI1->Scale(1./count);
713 std::cout << " after filling intrinsic power histo " << std::endl;
714  }
715 
716  fCoherentPowerTree->Branch("Power", &TMPVect);
717 count=0;
718  for(auto &it : fCoherentPowerI1)
719  {
720  std::cout << " i1 counter " << count++ << std::endl;
721  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
722  TMPVect = it;
723 
724  // fCoherentPowerTree->Fill();
725 
726 for(unsigned int jv=0;jv<TMPVect.size();jv++)
727  fCoherentPowerHistoI1->Fill(jv*freqBin,TMPVect[jv]);
728  }
729 fCoherentPowerHistoI1->Scale(1./count);
730 std::cout << " rawrmsi1 size " << fRawRMSI1.size() << std::endl;
731  for(unsigned int jj=0;jj<fRawRMSI1.size();jj++) {
732 std::cout << " filling rawrmsi1 value " << fRawRMSI1.at(jj) << std::endl;
733  fRawRMSHistoI1->Fill(fRawRMSI1.at(jj));
734 }
735 std::cout << " after filling raw rms histo entries " << fRawRMSHistoI1->GetEntries() << std::endl;
736 for(unsigned int j=0;j<fRawMeanI1.size(); j++) {
737 //std::cout << " filling media " << std::endl;
738  fMediaHistoI1->Fill(fRawMeanI1.at(j));
739 }
740 std::cout << " after filling media histo " << std::endl;
741 
742 for(unsigned int jj=0;jj<fIntrinsicRMSI1.size();jj++)
743  fIntrinsicRMSHistoI1->Fill(fIntrinsicRMSI1.at(jj));
744 
745 std::cout << " fillhisto cohrms size " << fCoherentRMSI1.size() << std::endl;
746 
747 for(unsigned int j=0;j<fCoherentRMSI1.size();j++) {
748 std::cout << " filling coherent RMS " << fCoherentRMSI1.at(j) << std::endl;
749  fCoherentRMSHistoI1->Fill(fCoherentRMSI1.at(j));
750 }
751 
752  // Average the power vectors.
753  std::cout << "Averaging power vectors..." << std::endl;
754  //std::vector<float> TMPVect;
755  fRawPowerTree->Branch("Power", &TMPVect);
756 count=0;
757  for(auto &it : fRawPowerI2)
758  {
759 count++;
760  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
761  TMPVect = it;
762  // fRawPowerTree->Fill();
763  std::cout << " tmpvect size " << TMPVect.size() << std::endl;
764 for(unsigned int jv=0;jv<TMPVect.size();jv++)
765 //if(jv==100)
766  fRawPowerHistoI2->Fill(jv*freqBin,TMPVect[jv]);
767  }
768 std::cout << " after filling raw power histo " << std::endl;
769 fRawPowerHistoI2->Scale(1./count);
770  fIntrinsicPowerTree->Branch("Power", &TMPVect);
771 count=0;
772  for(auto &it : fIntrinsicPowerI2)
773  {
774 count++;
775  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
776  TMPVect = it;
777  std::cout << " tmpvect size " << TMPVect.size() << std::endl;
778  // fIntrinsicPowerTree->Fill();
779  std::cout << " after fill tmpvect size " << TMPVect.size() << std::endl;
780 for(unsigned int jv=0;jv<TMPVect.size();jv++) {
781 //std::cout << " filling jv " << jv << std::endl;
782  fIntrinsicPowerHistoI2->Fill(jv*freqBin,TMPVect[jv]);
783 }
784 fIntrinsicPowerHistoI2->Scale(1./count);
785 std::cout << " after filling intrinsic power histo " << std::endl;
786  }
787 
788  fCoherentPowerTree->Branch("Power", &TMPVect);
789 count=0;
790  for(auto &it : fCoherentPowerI2)
791  {
792 count++;
793  std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
794  TMPVect = it;
795 
796  // fCoherentPowerTree->Fill();
797 
798 for(unsigned int jv=0;jv<TMPVect.size();jv++)
799  fCoherentPowerHistoI2->Fill(jv*freqBin,TMPVect[jv]);
800  }
801 fCoherentPowerHistoI2->Scale(1./count);
802 std::cout << " after filling coherent power histo " << std::endl;
803  for(unsigned int jj=0;jj<fRawRMSI2.size();jj++)
804  fRawRMSHistoI2->Fill(fRawRMSI2.at(jj));
805 std::cout << " after filling raw rms histo " << std::endl;
806 for(unsigned int j=0;j<fRawMeanI2.size(); j++) {
807 //std::cout << " filling media " << std::endl;
808  fMediaHistoI2->Fill(fRawMeanI2.at(j));
809 }
810 std::cout << " after filling media histo " << std::endl;
811 
812 for(unsigned int jj=0;jj<fIntrinsicRMSI2.size();jj++)
813  fIntrinsicRMSHistoI2->Fill(fIntrinsicRMSI2.at(jj));
814 
815 std::cout << " fillhisto cohrms size " << fCoherentRMSI2.size() << std::endl;
816 
817 for(unsigned int j=0;j<fCoherentRMSI2.size();j++) {
818 std::cout << " filling coherent RMS " << fCoherentRMSI2.at(j) << std::endl;
819  fCoherentRMSHistoI2->Fill(fCoherentRMSI2.at(j));
820 }
821 
822  TFile *f = new TFile(fHistoFileName.c_str(),"RECREATE");
823 
824 std::cout << " coherent rms histo entries "<< std::endl;
825 
826  fRawPowerHistoI2->Write();
827 fIntrinsicPowerHistoI2->Write();
828 fCoherentPowerHistoI2->Write();
829  fRawRMSHistoI2->Write();
830 fMediaHistoI2->Write();
831 fIntrinsicRMSHistoI2->Write();
832 fCoherentRMSHistoI2->Write();
833 
834 std::cout << " after filling i2 histos " << std::endl;
835 
836  fRawPowerHistoI1->Write();
837 fIntrinsicPowerHistoI1->Write();
838 fCoherentPowerHistoI1->Write();
839  fRawRMSHistoI1->Write();
840 fMediaHistoI1->Write();
841 fIntrinsicRMSHistoI1->Write();
842 fCoherentRMSHistoI1->Write();
843 
844 std::cout << " after filling i1 histos " << std::endl;
845 
846  fRawPowerHistoC->Write();
847 fIntrinsicPowerHistoC->Write();
848 fCoherentPowerHistoC->Write();
849  fRawRMSHistoC->Write();
850 fMediaHistoC->Write();
851 fIntrinsicRMSHistoC->Write();
852 fCoherentRMSHistoC->Write();
853  f->Close();
854  f->Delete();
855 std::cout << " after filling c histos " << std::endl;
856  std::cout << "Ending job..." << std::endl;
857 //exit(11);
858  return;
859 }
860 
861 DEFINE_ART_MODULE(tpcnoise::TPCNoise)
std::string fRawDigitModuleLabel
std::vector< double > fCoherentRMSI1
std::vector< float > fRawMeanI1
std::vector< double > fIntrinsicRMSI1
std::string fHistoFileName
std::vector< double > fCoherentRMSI2
std::vector< float > fRawMeanI2
std::vector< double > fIntrinsicRMSC
static constexpr Sample_t transform(Sample_t sample)
walls no right
Definition: selectors.fcl:105
void reconfigure(fhicl::ParameterSet const &pset)
pdgs p
Definition: selectors.fcl:22
std::vector< std::vector< float > > fCoherentPowerI2
Definition of basic raw digits.
std::size_t size(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:561
void analyze(const art::Event &e)
std::vector< std::vector< float > > fRawPowerI1
std::string fRawInstance
std::string fIntrinsicInstance
std::vector< double > fCoherentRMSC
std::vector< unsigned short int > fChannel
TPCNoise(fhicl::ParameterSet const &p)
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double >> FFTPointer
std::vector< double > fRawRMSC
std::vector< double > fRawRMSI2
std::vector< std::vector< float > > fRawPowerI2
std::vector< double > fRawRMSTrim
std::vector< float > fPed
std::vector< double > fIntrinsicRMSTrim
Collect all the RawData header files together.
walls no left
Definition: selectors.fcl:105
std::string fCoherentInstance
Definition of data types for geometry description.
std::vector< float > fRawMeanC
std::vector< std::vector< float > > fCoherentPowerI1
std::vector< std::vector< float > > fIntrinsicPowerC
std::vector< double > fIntrinsicRMSI2
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
Definition: UtilFunc.cxx:13
std::vector< double > fCoherentRMSTrim
std::vector< float > fIntrinsicMean
do i e
std::vector< std::vector< float > > fRawPowerC
std::vector< float > fCoherentMean
art::ServiceHandle< art::TFileService > tfs
std::vector< std::vector< float > > fIntrinsicPowerI2
std::size_t count(Cont const &cont)
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
Definition: raw.cxx:776
std::vector< std::vector< float > > fCoherentPowerC
std::vector< std::vector< float > > fIntrinsicPowerI1
std::vector< double > fRawRMSI1
art framework interface to geometry description
BEGIN_PROLOG could also be cout
auto const detProp
std::string fRawDigitProcess