17 #include "cetlib/cpu_timer.h" 
   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" 
   42 #include "icarus_signal_processing/Filters/ICARUSFFT.h" 
   92   using FFTPointer = std::unique_ptr<icarus_signal_processing::ICARUSFFT<double>>;
 
  174   auto const detProp = art::ServiceHandle<detinfo::DetectorPropertiesService const>()->DataForJob();
 
  184 std::cout << 
" after resizing " << std::endl;
 
  190 std::cout << 
" after resizing " << std::endl;
 
  197 std::cout << 
" after resizing " << std::endl;
 
  203 std::cout << 
" after resizing " << std::endl;
 
  209 std::cout << 
" after resizing " << std::endl;
 
  220 std::cout << 
" after resizing " << std::endl;
 
  226 std::cout << 
" after resizing " << std::endl;
 
  232 std::cout << 
" after intrinsic i2 resizing " << std::endl;
 
  236 double freqBin=0.6103515625;
 
  237 fRawPowerHistoC=
new TH1D(
"rawpowerC",
"rawpowerC",2048,0.,2048*freqBin);
 
  259 std::cout << 
" end constructor " << std::endl;
 
  264 std::cout << 
" begin analyze " << std::endl;
 
  265    art::ServiceHandle<geo::Geometry> geom;
 
  269 std::cout << 
" after clearing " << std::endl;
 
  275   fCoherentRMSC.clear();
 
  278   fCoherentRMSI1.clear();
 
  280   fCoherentRMSI2.clear();
 
  281   fIntrinsicMean.clear();
 
  282   fIntrinsicRMSC.clear();
 
  283 fIntrinsicRMSI1.clear();
 
  284 fIntrinsicRMSI2.clear();
 
  285   fIntrinsicRMSTrim.clear();
 
  286 std::cout << 
" after clearing " << std::endl;
 
  289   fEvent = e.id().event();
 
  290 std::cout << 
" event " << fEvent << std::endl;
 
  292 std::cout << 
" run " << fRun << std::endl;
 
  293   fSubRun = e.id().subRun();
 
  294   std::cout << 
" subrun " << fSubRun << std::endl;
 
  295   std::cout << 
"Processing event " << NEvents+1 << 
" for TPC Noise Analysis " << 
" Run " << fRun << 
", " << 
"Event " << fEvent << 
"." << std::endl;
 
  302   art::Handle< std::vector<raw::RawDigit> > RawDigitHandle;
 
  303   e.getByLabel(fRawDigitModuleLabel, fRawDigitInstance,fRawDigitProcess, RawDigitHandle);
 
  306   for(
const auto& RawDigit : *RawDigitHandle)
 
  309       unsigned int DataSize = RawDigit.Samples();
 
  310       std::vector<short> RawADC;
 
  311       RawADC.resize(DataSize);
 
  315       std::vector<short> SortedADC(RawADC);
 
  316       std::sort(SortedADC.begin(),SortedADC.end(),[](
const auto& 
left, 
const auto& 
right){
return std::fabs(
left) < std::fabs(
right);});
 
  317       float median(SortedADC.at(SortedADC.size()/2));
 
  320       float mean(
float(std::accumulate(SortedADC.begin(),SortedADC.end(),0))/float(SortedADC.size()));
 
  321 std::vector<geo::WireID> widVec = geom->ChannelToWire(RawDigit.Channel());
 
  322         size_t                   plane  = widVec[0].Plane;
 
  323  size_t                   wire  = widVec[0].Wire;
 
  324 size_t                   tpc  = widVec[0].TPC;
 
  325 size_t                   cryostat  = widVec[0].Cryostat;
 
  326 std::cout << 
" cryo " << cryostat << 
" tpc " << tpc << 
" plane " << plane <<
" wire " << wire << std::endl; 
 
  328       std::vector<float> ADCLessPed;
 
  329       ADCLessPed.resize(SortedADC.size());
 
  330       std::transform(SortedADC.begin(),SortedADC.end(),ADCLessPed.begin(),std::bind(std::minus<float>(),std::placeholders::_1,median));
 
  333       float rms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.end(), ADCLessPed.begin(), 0.) / float(ADCLessPed.size())));
 
  336       unsigned int MinBins((1.0 - 0.01)*ADCLessPed.size());
 
  343       float truncrms(std::sqrt(std::inner_product(ADCLessPed.begin(), ADCLessPed.begin() + MinBins, ADCLessPed.begin(), 0.) / float(MinBins)));
 
  346       std::vector<double> power(DataSize);
 
  347       std::vector<double> RawLessPed;
 
  348       RawLessPed.resize(RawADC.size());
 
  349       std::transform(RawADC.begin(),RawADC.end(),RawLessPed.begin(),std::bind(std::minus<double>(),std::placeholders::_1,median));
 
  350       fFFT->getFFTPower(RawLessPed, power);
 
  353 std::transform(fRawPowerI1.at(0).begin(), fRawPowerI1.at(0).end(), power.begin(), fRawPowerI1.at(0).begin(), std::plus<float>());  }
 
  354 if(plane==1)  { 
std::transform(fRawPowerI2.at(0).begin(), fRawPowerI2.at(0).end(), power.begin(), fRawPowerI2.at(0).begin(), std::plus<float>()); }
 
  355 if(plane==2)  { 
std::transform(fRawPowerC.at(0).begin(), fRawPowerC.at(0).end(), power.begin(), fRawPowerC.at(0).begin(), std::plus<float>()); }  
 
  358       fPed.push_back(median);
 
  359    if(plane==2)   fRawMeanC.push_back(mean);
 
  360 if(plane==1)   fRawMeanI2.push_back(mean);
 
  361 if(plane==0)   fRawMeanI1.push_back(mean);
 
  362   if(plane==2)   { fRawRMSC.push_back(rms);}
 
  363  if(plane==0) {  fRawRMSI1.push_back(rms);   }
 
  364  if(plane==1) { fRawRMSI2.push_back(rms);
if(wire==0) 
for(
int j=0;j<4096;j++) 
std::cout << 
" wire 0 tick " << j << 
" signal " << RawADC.at(j) << std::endl;
 
  366       fRawRMSTrim.push_back(truncrms);
 
  368       fChannel.push_back(RawDigit.Channel());
 
  384   fRawDigitModuleLabel = p.get< std::string >(
"RawDigitModuleLabel", std::string(
"daqTPC"));
 
  386   fRawDigitProcess = p.get< std::string >(
"RawDigitProcess", std::string(
"decode"));
 
  388   fRawDigitInstance = p.get< std::string >(
"RawDigitInstance", std::string(
""));
 
  389 fHistoFileName = p.get< std::string >(
"HistoFileName");
 
  397   art::ServiceHandle<art::TFileService> 
tfs;
 
  399   fNoiseTree = tfs->makeAndRegister<TTree>(
"TPCNoiseMC_t", 
"TPC Noise");
 
  400   fRawPowerTree = tfs->makeAndRegister<TTree>(
"TPCRawPower_t", 
"TPC Raw Power");
 
  401   fIntrinsicPowerTree = tfs->makeAndRegister<TTree>(
"TPCIntrinsicPower_t", 
"TPC Intrinsic Power");
 
  402 fCoherentPowerTree = tfs->makeAndRegister<TTree>(
"TPCCoherentPower_t", 
"TPC Coherent Power");
 
  405   fNoiseTree->Branch(
"Event", &fEvent, 
"Event/I");
 
  406   fNoiseTree->Branch(
"Run", &fRun, 
"Run/I");
 
  407   fNoiseTree->Branch(
"SubRun", &fSubRun, 
"SubRun/I");
 
  408   fNoiseTree->Branch(
"Channel", &fChannel);
 
  409   fNoiseTree->Branch(
"Pedestal", &fPed);
 
  410   fNoiseTree->Branch(
"RawMeanC", &fRawMeanC);
 
  411   fNoiseTree->Branch(
"RawRMSC", &fRawRMSC);
 
  413   fNoiseTree->Branch(
"RawTrimmedRMS", &fRawRMSTrim);
 
  414   fNoiseTree->Branch(
"IntrinsicMean", &fIntrinsicMean);
 
  415   fNoiseTree->Branch(
"IntrinsicRMSC", &fIntrinsicRMSC);
 
  416   fNoiseTree->Branch(
"IntrinsicTrimmedRMS", &fIntrinsicRMSTrim);
 
  423 double freqBin=0.6103515625;
 
  425   std::cout << 
"Averaging power vectors..." << std::endl;
 
  426   std::vector<float> TMPVect;
 
  427   fRawPowerTree->Branch(
"Power", &TMPVect);
 
  428   for(
auto &it : fRawPowerC)
 
  430       std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
 
  433      std::cout << 
" tmpvect size " << TMPVect.size() << std::endl;
 
  434 for(
unsigned int jv=0;jv<TMPVect.size();jv++)
 
  435   fRawPowerHistoC->Fill(jv*freqBin,TMPVect[jv]);
 
  437 std::cout << 
" after filling raw power histo " << std::endl;
 
  440 std::cout << 
" frawrmsc size " << fRawRMSC.size() << std::endl;
 
  441  for(
unsigned int jj=0;jj<fRawRMSC.size();jj++)
 
  442   fRawRMSHistoC->Fill(fRawRMSC.at(jj));
 
  443 std::cout << 
" after filling raw rms histo " << std::endl;
 
  444 for(
unsigned int j=0;j<fRawMeanC.size(); j++) {
 
  445 std::cout << 
" filling media " << std::endl;
 
  446   fMediaHistoC->Fill(fRawMeanC.at(j));
 
  448 std::cout << 
" after filling media histo " << std::endl;
 
  451   std::cout << 
"Averaging power vectors..." << std::endl;
 
  453   fRawPowerTree->Branch(
"Power", &TMPVect);
 
  455   for(
auto &it : fRawPowerI1)
 
  457      std::cout << 
" i1 counter " << count++ << std::endl;
 
  458       std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
 
  462 for(
unsigned int jv=0;jv<TMPVect.size();jv++)
 
  463   fRawPowerHistoI1->Fill(jv*freqBin,TMPVect[jv]);
 
  465 std::cout << 
" after filling raw power histo " << std::endl;
 
  468 std::cout << 
" rawrmsi1 size " << fRawRMSI1.size() << std::endl;
 
  469  for(
unsigned int jj=0;jj<fRawRMSI1.size();jj++) {
 
  470 std::cout << 
" filling rawrmsi1 value " << fRawRMSI1.at(jj) << std::endl;
 
  471   fRawRMSHistoI1->Fill(fRawRMSI1.at(jj));
 
  473 std::cout << 
" after filling raw rms histo entries " << fRawRMSHistoI1->GetEntries() <<  std::endl;
 
  474 for(
unsigned int j=0;j<fRawMeanI1.size(); j++) {
 
  476   fMediaHistoI1->Fill(fRawMeanI1.at(j));
 
  478 std::cout << 
" after filling media histo " << std::endl;
 
  480 for(
unsigned int jj=0;jj<fIntrinsicRMSI1.size();jj++)
 
  481   fIntrinsicRMSHistoI1->Fill(fIntrinsicRMSI1.at(jj));
 
  483 std::cout << 
" fillhisto cohrms size " << fCoherentRMSI1.size() << std::endl;
 
  485 for(
unsigned int j=0;j<fCoherentRMSI1.size();j++) {
 
  486 std::cout << 
" filling coherent RMS " << fCoherentRMSI1.at(j) << std::endl;
 
  487   fCoherentRMSHistoI1->Fill(fCoherentRMSI1.at(j));
 
  491   std::cout << 
"Averaging power vectors..." << std::endl;
 
  493   fRawPowerTree->Branch(
"Power", &TMPVect);
 
  494   for(
auto &it : fRawPowerI2)
 
  496       std::transform(it.begin(), it.end(), it.begin(), std::bind(std::divides<float>(), std::placeholders::_1, NEvents));
 
  499      std::cout << 
" tmpvect size " << TMPVect.size() << std::endl;
 
  500 for(
unsigned int jv=0;jv<TMPVect.size();jv++)
 
  501   fRawPowerHistoI2->Fill(jv*freqBin,TMPVect[jv]);
 
  503 std::cout << 
" after filling raw power histo " << std::endl;
 
  505  for(
unsigned int jj=0;jj<fRawRMSI2.size();jj++)
 
  506   fRawRMSHistoI2->Fill(fRawRMSI2.at(jj));
 
  507 std::cout << 
" after filling raw rms histo " << std::endl;
 
  508 for(
unsigned int j=0;j<fRawMeanI2.size(); j++) {
 
  510   fMediaHistoI2->Fill(fRawMeanI2.at(j));
 
  512 std::cout << 
" after filling media histo " << std::endl;
 
  514  TFile *f = 
new TFile(fHistoFileName.c_str(),
"RECREATE");
 
  516 std::cout << 
" coherent rms histo entries "<< std::endl;
 
  518   fRawPowerHistoI2->Write();
 
  520  fRawRMSHistoI2->Write();
 
  521 fMediaHistoI2->Write();
 
  524 std::cout << 
" after filling i2 histos " << std::endl;
 
  526   fRawPowerHistoI1->Write();
 
  528  fRawRMSHistoI1->Write();
 
  529 fMediaHistoI1->Write();
 
  532 std::cout << 
" after filling i1 histos " << std::endl;
 
  534   fRawPowerHistoC->Write();
 
  536  fRawRMSHistoC->Write();
 
  537 fMediaHistoC->Write();
 
  541 std::cout << 
" after filling c histos " << std::endl;
 
  542   std::cout << 
"Ending job..." << std::endl;
 
std::string fRawDigitProcess
 
std::unique_ptr< icarus_signal_processing::ICARUSFFT< double >> FFTPointer
 
std::vector< std::vector< float > > fRawPowerC
 
std::vector< double > fCoherentRMSC
 
std::vector< float > fRawMeanC
 
std::vector< std::vector< float > > fCoherentPowerI1
 
TH1D * fIntrinsicPowerHistoI2
 
std::vector< std::vector< float > > fRawPowerI2
 
std::vector< float > fRawMeanI2
 
std::vector< double > fIntrinsicRMSC
 
std::vector< double > fCoherentRMSTrim
 
std::vector< float > fRawMeanI1
 
Definition of basic raw digits. 
 
TPCNoiseMC(fhicl::ParameterSet const &p)
 
std::vector< double > fIntrinsicRMSTrim
 
std::vector< std::vector< float > > fCoherentPowerC
 
std::string fRawDigitModuleLabel
 
void analyze(const art::Event &e)
 
std::vector< double > fCoherentRMSI2
 
void reconfigure(fhicl::ParameterSet const &pset)
 
TH1D * fCoherentRMSHistoI2
 
std::vector< std::vector< float > > fCoherentPowerI2
 
TH1D * fCoherentRMSHistoC
 
std::vector< std::vector< float > > fRawPowerI1
 
std::vector< double > fRawRMSC
 
std::vector< double > fIntrinsicRMSI1
 
std::string fHistoFileName
 
std::string fRawDigitInstance
 
TH1D * fCoherentPowerHistoC
 
std::vector< double > fCoherentRMSI1
 
Collect all the RawData header files together. 
 
std::vector< float > fCoherentMean
 
std::vector< std::vector< float > > fIntrinsicPowerI1
 
TH1D * fIntrinsicRMSHistoC
 
TH1D * fCoherentPowerHistoI1
 
TH1D * fIntrinsicPowerHistoC
 
Definition of data types for geometry description. 
 
TTree * fCoherentPowerTree
 
TH1D * fCoherentPowerHistoI2
 
std::vector< double > fRawRMSI2
 
double mean(const std::vector< short > &wf, size_t start, size_t nsample)
 
std::vector< float > fIntrinsicMean
 
TH1D * fCoherentRMSHistoI1
 
std::vector< unsigned short int > fChannel
 
std::vector< std::vector< float > > fIntrinsicPowerC
 
TH1D * fIntrinsicRMSHistoI1
 
std::vector< double > fRawRMSTrim
 
art::ServiceHandle< art::TFileService > tfs
 
TH1D * fIntrinsicPowerHistoI1
 
std::size_t count(Cont const &cont)
 
TTree * fIntrinsicPowerTree
 
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer. 
 
std::vector< double > fIntrinsicRMSI2
 
std::vector< double > fRawRMSI1
 
art framework interface to geometry description 
 
BEGIN_PROLOG could also be cout
 
std::vector< float > fPed
 
std::vector< std::vector< float > > fIntrinsicPowerI2
 
TH1D * fIntrinsicRMSHistoI2