Public Member Functions | Private Member Functions | Private Attributes | List of all members
DAQToOffline::SSPDiagnosticAna Class Reference
Inheritance diagram for DAQToOffline::SSPDiagnosticAna:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

Public Member Functions

 SSPDiagnosticAna (fhicl::ParameterSet const &pset)
 
void analyze (art::Event const &evt) override
 
void reconfigure (fhicl::ParameterSet const &pset)
 
void printParameterSet ()
 
 SSPDiagnosticAna (SSPDiagnosticAna const &)=delete
 
 SSPDiagnosticAna (SSPDiagnosticAna &&)=delete
 
SSPDiagnosticAnaoperator= (SSPDiagnosticAna const &)=delete
 
SSPDiagnosticAnaoperator= (SSPDiagnosticAna &&)=delete
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob ()
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
std::string const & processName () const
 
bool wantAllEvents () const
 
bool wantEvent (Event const &e)
 
fhicl::ParameterSetID selectorConfig () const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

Private Member Functions

void beginJob () override
 
void endJob () override
 
void beginRun (art::Run const &run) override
 
void endRun (art::Run const &run) override
 
void beginEvent (art::EventNumber_t eventNumber)
 
void endEvent (art::EventNumber_t eventNumber)
 

Private Attributes

std::string fFragType
 
std::string fRawDataLabel
 
std::string fOutputDataLabel
 
std::string fInputModule
 
std::string fInputLabel
 
double fSampleFreq
 
const int m1_window = 10
 
const int i1_window = 500
 
const int i2_window = 500
 
std::map< int, TH2D * > averageWaveforms
 
std::map< int, TH1D * > waveformFFTs
 
TH1D * fPulseAmplitude
 
std::map< int, TH1D * > PulseAmplitudePerChannel
 
std::map< int, TH1D * > IntegratedChargePerChannel
 
std::map< int, TH2D * > PulseAmplitudeVsIntegratedChargePerChannel
 
std::map< int, TH2D * > PulseAmpVsRun
 
TSpectrum * specAnalyzer = new TSpectrum( 100 )
 
SSPReformatterAlgs sspReform
 
unsigned long int firstTime
 
unsigned long int lastTime
 
std::map< int, long int > triggerCount
 

Additional Inherited Members

- Public Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 
- Protected Member Functions inherited from art::Observer
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &paths, fhicl::ParameterSet const &config)
 
detail::ProcessAndEventSelectorsprocessAndEventSelectors ()
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

Detailed Description

Definition at line 59 of file SSPDiagnosticAna_module.cc.

Constructor & Destructor Documentation

DAQToOffline::SSPDiagnosticAna::SSPDiagnosticAna ( fhicl::ParameterSet const &  pset)
explicit

Definition at line 118 of file SSPDiagnosticAna_module.cc.

119  : art::EDAnalyzer(pset),
120  sspReform(pset.get<fhicl::ParameterSet>("SSPReformatter"))
121 {
122 
123  this->reconfigure(pset);
124 
125  //first_FirstSample = -1;
126  //first_TimeStamp = -1;
127 }
void reconfigure(fhicl::ParameterSet const &pset)
DAQToOffline::SSPDiagnosticAna::SSPDiagnosticAna ( SSPDiagnosticAna const &  )
delete
DAQToOffline::SSPDiagnosticAna::SSPDiagnosticAna ( SSPDiagnosticAna &&  )
delete

Member Function Documentation

void DAQToOffline::SSPDiagnosticAna::analyze ( art::Event const &  evt)
overridevirtual

< Derived Optical channel

< first sample time in ticks

Implements art::EDAnalyzer.

Definition at line 364 of file SSPDiagnosticAna_module.cc.

365 {
366 
368  art::TFileDirectory RunDir = tfs->mkdir( TString::Format("r%03i", evt.run()).Data(), "SSP Diagnostics by Run" );
369  //art::ServiceHandle<geo::Geometry> geo;
370 
371  art::Handle<artdaq::Fragments> rawFragments;
372  evt.getByLabel(fRawDataLabel, fFragType, rawFragments);
373 
374  mf::LogInfo("SSPDiagnosticAna") << "Starting event analysis";
375 
376  // Check if there is SSP data in this event
377  // Don't crash code if not present, just don't save anything
378  try { rawFragments->size(); }
379  catch(std::exception const&) {
380  mf::LogWarning("SSPDiagnosticAna") << "WARNING: Raw SSP data not found in event " << evt.event();
381  return;
382  }
383 
384  // Check that the data is valid
385  if(!rawFragments.isValid()){
386  mf::LogError("SSPDiagnosticAna") << "Run: " << evt.run()
387  << ", SubRun: " << evt.subRun()
388  << ", Event: " << evt.event()
389  << " is NOT VALID";
390  throw cet::exception("raw NOT VALID");
391  return;
392  }
393 
394  mf::LogInfo("SSPDiagnosticAna") << "Data is valid!";
395 
396  // Get OpDetWaveforms from the event
398  evt.getByLabel(fInputModule, fInputLabel, waveformHandle);
399 
400  for (size_t i = 0; i < waveformHandle->size(); i++)
401  {
402 
403  // This was probably required to overcome the "const" problem
404  // with OpDetPulse::Waveform()
405  art::Ptr< raw::OpDetWaveform > waveformPtr(waveformHandle, i);
406  raw::OpDetWaveform pulse = *waveformPtr;
407  int channel = pulse.ChannelNumber();
408 
409  // Create the TH1 if it doesn't exist
410  auto waveform = averageWaveforms.find( channel );
411  if ( waveform == averageWaveforms.end() ) {
412  TString histName = TString::Format("avgwaveform_channel_%03i", channel);
413  //averageWaveforms[channel] = RunDir.make< TH1D >(histName, ";t (us);", pulse.size(), 0, double(pulse.size()) / fSampleFreq);
414  TString histTitle = TString::Format("Average Waveform for OP Channel %03i;t (us);amplitude (ADC)", channel);
415  averageWaveforms[channel] = RunDir.make< TH2D >(histName, histTitle, pulse.size(), 0, double(pulse.size()) / fSampleFreq, 2000, 1200, 5200);
416  }
417 
418  // Add this waveform to this histogram
419  for (size_t tick = 0; tick < pulse.size(); tick++) {
420  averageWaveforms[channel]->Fill(double(tick)/fSampleFreq, pulse[tick]);
421 
422  }
423  // // Count number of waveforms on each channel
424  // waveformCount[channel]++;
425 
426 
427  }
428 
429 
430  unsigned int numFragments = rawFragments->size();
431  mf::LogInfo("SSPDiagnosticAna") << "Number of fragments = " << numFragments;
432 
433  for (size_t idx = 0; idx < numFragments; ++idx) {
434 
435  mf::LogInfo("SSPDiagnosticAna") << "Number of fragments = " << idx;
436 
437  const auto& frag((*rawFragments)[idx]);
438  lbne::SSPFragment sspf(frag);
439 
440  unsigned int nTriggers = sspReform.CheckAndGetNTriggers(frag, sspf);
441 
442  mf::LogInfo("SSPDiagnosticAna") << "Triggers = " << nTriggers;
443 
444  const unsigned int* dataPointer = sspf.dataBegin();
445 
446 
447  for (unsigned int triggersProcessed = 0;
448  (nTriggers==0 || triggersProcessed < nTriggers) && dataPointer < sspf.dataEnd();
449  ++triggersProcessed) {
450 
451  //
452  // The elements of the OpDet Pulse
453  //
454  unsigned short OpChannel = -1; ///< Derived Optical channel
455  unsigned long FirstSample = 0; ///< first sample time in ticks
456 
457 
458  // Load the event header, advance the pointer
459  const SSPDAQ::EventHeader* daqHeader=reinterpret_cast<const SSPDAQ::EventHeader*>(dataPointer);
460  dataPointer += sizeof(SSPDAQ::EventHeader)/sizeof(unsigned int);
461 
462  // Get ADC Count, create pointer to adcs
463  unsigned int nADC=(daqHeader->length-sizeof(SSPDAQ::EventHeader)/sizeof(unsigned int))*2;
464 
465  //get the information from the header
466  try {
467  OpChannel = sspReform.GetOpChannel(daqHeader);
468 
469  FirstSample = sspReform.GetGlobalFirstSample(daqHeader);
470  //TimeStamp = ((double)FirstSample)/fNOvAClockFrequency;
471 
472  double peakSum = sspReform.GetPeakSum(daqHeader);
473  double prerise = sspReform.GetBaselineSum(daqHeader);
474  double integratedSum = sspReform.GetIntegratedSum(daqHeader);
475 
476  double PulseAmplitude = -prerise/i2_window*1.0 + peakSum/m1_window*1.0;
477 
478  int channel = (int) OpChannel;
479 
480  // if(channel==94){
481  // if(PulseAmplitude>50&&PulseAmplitude<55)//event with 5 p.e. peak in channel 94
482  // std::cout << "Channel 94 has 5 p.e. peak in event" << evt.event() << std::endl;
483 
484  // if(PulseAmplitude>75&&PulseAmplitude<85)//event with 5 p.e. peak in channel 94
485  // std::cout << "Channel 94 has 7 p.e. peak in event" << evt.event() << std::endl;
486  // }
487 
488  double IntegratedCharge = integratedSum - prerise/i2_window*i1_window*1.0;
489 
490  fPulseAmplitude->Fill(PulseAmplitude);
491  mf::LogInfo("SSPDiagnosticAna") << "Pulse Amplitude: " << PulseAmplitude;
492 
493 
494  auto pulse_amplitude_per_channel = PulseAmplitudePerChannel.find( channel);
495  if( pulse_amplitude_per_channel == PulseAmplitudePerChannel.end() ) {
496  TString histName = TString::Format("pulse_amplitude_channel_%03i", channel);
497  TString histTitle = TString::Format("Pulse Amplitude for OP Channel %03i;leading-edge amplitude [ADC]", channel);
498  PulseAmplitudePerChannel[channel] = RunDir.make< TH1D >(histName, histTitle ,125,-20,230);
499  }
500 
501  PulseAmplitudePerChannel[channel]->Fill(PulseAmplitude);
502 
503  auto integrated_charge_per_channel = IntegratedChargePerChannel.find( channel);
504  if( integrated_charge_per_channel == IntegratedChargePerChannel.end() ) {
505  TString histName = TString::Format("integrated_charge_channel_%03i", channel);
506  TString histTitle = TString::Format("Integrated Charge on OP Channel %03i;integrated charge [ADC*tick]", channel);
507  IntegratedChargePerChannel[channel] = RunDir.make< TH1D >(histName, histTitle ,300,0,3e4);
508  }
509 
510  IntegratedChargePerChannel[channel]->Fill(IntegratedCharge);
511 
512  auto pulse_amplitude_vs_integrated_charge_per_channel = PulseAmplitudeVsIntegratedChargePerChannel.find( channel);
513  if( pulse_amplitude_vs_integrated_charge_per_channel == PulseAmplitudeVsIntegratedChargePerChannel.end() ) {
514  TString histName = TString::Format("pulse_amplitude_vs_integrated_charge_channel_%03i", channel);
515  TString histTitle = TString::Format("Pulse Amplitude vs. Integrated Charge on OP Channel %03i;integrated charge [ADC*tick];leading-edge amplitude [ADC]", channel);
516  PulseAmplitudeVsIntegratedChargePerChannel[channel] = RunDir.make< TH2D >(histName, histTitle ,300,0,3e4,125,-20,230);
517  }
518 
519  PulseAmplitudeVsIntegratedChargePerChannel[channel]->Fill(IntegratedCharge,PulseAmplitude);
520 
521 
522 
523  if (FirstSample < 1e16) {
524  sspReform.PrintHeaderInfo(daqHeader);
525  mf::LogInfo("SSPDiagnosticAna") << "Problem timestamp at " << FirstSample << std::endl;
526  continue;
527  }
528  }
529  catch (cet::exception const&) {
530  continue;
531  }
532 
533  firstTime = std::min(firstTime, FirstSample);
534  lastTime = std::max(lastTime, FirstSample);
535  triggerCount[OpChannel]++;
536 
537  // Advance the dataPointer to the next header
538  dataPointer+=nADC/2;
539 
540  } // End of loop over triggers
541  } // End of loop over fragments (rawFragments)
542 
543 }
uint32_t GetPeakSum(const SSPDAQ::EventHeader *daqHeader)
unsigned int event
Definition: DataStructs.h:574
Channel_t ChannelNumber() const
Definition: OpDetWaveform.h:69
unsigned int run
Definition: DataStructs.h:575
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
unsigned int CheckAndGetNTriggers(const artdaq::Fragment &frag, const lbne::SSPFragment sspf)
Load the milislice.
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
std::map< int, TH1D * > PulseAmplitudePerChannel
bool isValid() const
Definition: Handle.h:183
unsigned long GetBaselineSum(const SSPDAQ::EventHeader *daqHeader)
unsigned long GetIntegratedSum(const SSPDAQ::EventHeader *daqHeader)
unsigned long GetGlobalFirstSample(const SSPDAQ::EventHeader *daqHeader)
std::map< int, long int > triggerCount
std::map< int, TH1D * > IntegratedChargePerChannel
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:74
static int max(int a, int b)
unsigned short GetOpChannel(const SSPDAQ::EventHeader *daqHeader)
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
std::map< int, TH2D * > PulseAmplitudeVsIntegratedChargePerChannel
std::map< int, TH2D * > averageWaveforms
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
unsigned int subRun
Definition: DataStructs.h:576
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
TCEvent evt
Definition: DataStructs.cxx:7
void PrintHeaderInfo(const SSPDAQ::EventHeader *daqHeader)
Print out header information.
Definition: fwd.h:29
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
QTextStream & endl(QTextStream &s)
void DAQToOffline::SSPDiagnosticAna::beginEvent ( art::EventNumber_t  eventNumber)
private

Definition at line 179 of file SSPDiagnosticAna_module.cc.

180 {
181  //reset ADC histogram
182  //adc_values_->Reset();
183  //reset counters
184  //n_adc_counter_ = 0;
185  //adc_cumulative_ = 0;
186 }
void DAQToOffline::SSPDiagnosticAna::beginJob ( )
overrideprivatevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 161 of file SSPDiagnosticAna_module.cc.

162 {
164  //adc_values_ = tfs->make<TH1D>("adc_values","adc_values",4096,-0.5,4095.5);
165 
166  fPulseAmplitude = tfs->make<TH1D>("pulseamplitude","Pulse Amplitude;leading-edge amplitude [ADC]",125,-50,200);
167 
168  firstTime = (((unsigned long int)1)<<63);
169  lastTime = 0;
170 }
void DAQToOffline::SSPDiagnosticAna::beginRun ( art::Run const &  run)
overrideprivatevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 172 of file SSPDiagnosticAna_module.cc.

173 {
174  PulseAmplitudePerChannel.clear();
177 }
std::map< int, TH1D * > PulseAmplitudePerChannel
std::map< int, TH1D * > IntegratedChargePerChannel
std::map< int, TH2D * > PulseAmplitudeVsIntegratedChargePerChannel
void DAQToOffline::SSPDiagnosticAna::endEvent ( art::EventNumber_t  eventNumber)
private

Definition at line 188 of file SSPDiagnosticAna_module.cc.

189 {
190  //write the ADC histogram for the given event
191  //if(n_adc_counter_)
192  // adc_values_->Write(Form("adc_values:event_%d", eventNumber));
193 }
void DAQToOffline::SSPDiagnosticAna::endJob ( )
overrideprivatevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 348 of file SSPDiagnosticAna_module.cc.

349 {
350  // Register all vs-run histograms.
352  for ( int i = 0; i < 100; ++i ) {
353  auto histo = PulseAmpVsRun.find( i );
354  if ( histo == PulseAmpVsRun.end() ) continue;
355  TH2D *newHist = tfs->make< TH2D >( PulseAmpVsRun[i]->GetName(), PulseAmpVsRun[i]->GetTitle(),
356  PulseAmpVsRun[i]->GetNbinsX(), PulseAmpVsRun[i]->GetXaxis()->GetBinLowEdge(1), PulseAmpVsRun[i]->GetXaxis()->GetBinLowEdge(PulseAmpVsRun[i]->GetNbinsX()+1),
357  PulseAmpVsRun[i]->GetNbinsY(), PulseAmpVsRun[i]->GetYaxis()->GetBinLowEdge(1), PulseAmpVsRun[i]->GetYaxis()->GetBinLowEdge(PulseAmpVsRun[i]->GetNbinsY()+1) );
358  newHist->Add( PulseAmpVsRun[i] );
359  }
360 }
void DAQToOffline::SSPDiagnosticAna::endRun ( art::Run const &  run)
overrideprivatevirtual

Reimplemented from art::EDAnalyzer.

Definition at line 195 of file SSPDiagnosticAna_module.cc.

196 {
197  //delete adc_values_;
198 
199  long int deltaT = lastTime-firstTime;
200  double deltaTus = ((double)deltaT)/sspReform.ClockFrequency();
201 
202 
203  mf::LogVerbatim("SSPDiagnosticAna") << "!! Diagnostic Rate Report." << std::endl;
204  mf::LogVerbatim("SSPDiagnosticAna") << "!! Time: " << deltaTus / 60.e6 << " minutes." << std::endl;
205 
206  for (auto itr = triggerCount.begin(); itr != triggerCount.end(); itr++) {
207  double freq = ((double)itr->second) / deltaTus * 1000.;
208  mf::LogVerbatim("SSPDiagnosticAna") << "!! Channel " << std::setw(3) << itr->first << ": " << freq << " kHz" << std::endl;
209  }
210 
211 
212  /*
213  mf::LogInfo("SSPDiagnosticAna") << "firstSample: " << firstTime << " samples\n"
214  << "lastSample: " << lastTime << " samples\n"
215  << "totalSamples: " << deltaT << " samples\n"
216  << "totalTime: " << deltaTus << " us\n"
217  << "# Channels: " << channels.size() << "\n"
218  << "# Triggers: " << triggerCount << "\n"
219  << "Frequency: " << freq << "kHz\n";
220  */
221 
222  // for (auto iter = averageWaveforms.begin(); iter != averageWaveforms.end(); iter++)
223  // {
224  // mf::LogInfo("Scaling down channel ") << iter->first << " by 1./" << waveformCount[iter->first] << std::endl;
225  // iter->second->Scale(1./waveformCount[iter->first]);
226  // }
227 
228  // Format output plots
229  for ( int i = 0; i < 100; ++i ) {
230  if ( PulseAmplitudePerChannel.find(i) == PulseAmplitudePerChannel.end() ) continue;
231  PulseAmplitudePerChannel[i]->SetStats(false);
232  PulseAmplitudePerChannel[i]->GetXaxis()->SetTitleSize(0.045);
233  IntegratedChargePerChannel[i]->SetStats(false);
234  IntegratedChargePerChannel[i]->GetXaxis()->SetTitleSize(0.045);
235  PulseAmplitudeVsIntegratedChargePerChannel[i]->SetStats(false);
236  PulseAmplitudeVsIntegratedChargePerChannel[i]->SetOption("colz");
237  PulseAmplitudeVsIntegratedChargePerChannel[i]->GetXaxis()->SetTitleSize(0.045);
238  PulseAmplitudeVsIntegratedChargePerChannel[i]->GetYaxis()->SetTitleSize(0.045);
239  averageWaveforms[i]->SetStats(false);
240  averageWaveforms[i]->SetOption("colz");
241  averageWaveforms[i]->GetXaxis()->SetTitleSize(0.045);
242  averageWaveforms[i]->GetYaxis()->SetTitleSize(0.045);
243  }
244 
245  // Analyze plots
246  for ( int i = 0; i < 100; ++i ) {
247  if ( PulseAmplitudePerChannel.find(i) == PulseAmplitudePerChannel.end() ) continue;
248  double ADCperPE(0);
249  double INTperPE(0);
250  { // Calculate leading-edge amplitude per photoelectron
251  int nDiffs(0);
252  int nPeaks = specAnalyzer->Search( PulseAmplitudePerChannel[i], 1.5/*sigma*/, "", 0.001 );
253  auto *peaks = specAnalyzer->GetPositionX(); // ordered by height!
254  std::vector<float> peakVec;
255  for ( int p = 0; p < nPeaks; ++p ) peakVec.push_back(peaks[p]);
256  std::sort(peakVec.begin(),peakVec.end());
257  for ( int p = 1; p < nPeaks-1; ++p ) {
258  double diff = peakVec.at(p+1) - peakVec.at(p);
259  if ( diff > 20 || diff < 10 ) {
260  //std::cout << "Caution! Outlier peak difference at " << p << "/" << p+1 << ". This pair will be skipped." << std::endl;
261  continue;
262  }
263  ADCperPE += diff;
264  nDiffs++;
265  }
266  ADCperPE /= double(nDiffs);
267  }
268  { // Calculate integrated charge per photoelectron
269  int nDiffs(0);
270  int nPeaks = specAnalyzer->Search( IntegratedChargePerChannel[i], 2.5/*sigma*/, "", 0.001 );
271  auto *peaks = specAnalyzer->GetPositionX(); // ordered by height!
272  std::vector<float> peakVec;
273  for ( int p = 0; p < nPeaks; ++p ) peakVec.push_back(peaks[p]);
274  std::sort(peakVec.begin(),peakVec.end());
275  for ( int p = 1; p < nPeaks-1; ++p ) {
276  double diff = peakVec.at(p+1) - peakVec.at(p);
277  if ( diff > 1800 || diff < 1000 ) {
278  //std::cout << "Caution! Outlier peak difference at " << p << "/" << p+1 << ". This pair will be skipped." << std::endl;
279  continue;
280  }
281  INTperPE += diff;
282  nDiffs++;
283  }
284  INTperPE /= double(nDiffs);
285  }
286  std::cout << "OpDet Channel " << i << " :\t LE " << ADCperPE << " ADC/PE" << "\t IC " << INTperPE << " charge/PE" << std::endl;
287  }
288 
289  // FFT of average waveforms
291  art::TFileDirectory RunDir = tfs->mkdir( TString::Format("r%03i", run.run()).Data(), "SSP Diagnostics by Run" );
292  for ( int i = 0; i < 100; ++i ) {
293  if ( PulseAmplitudePerChannel.find(i) == PulseAmplitudePerChannel.end() ) continue;
294  TProfile *profile = averageWaveforms[i]->ProfileX();
295  auto fft = waveformFFTs.find( i );
296  if ( fft == waveformFFTs.end() ) {
297  TString histName = TString::Format("waveformFFT_channel_%03i", i);
298  TString histTitle = TString::Format("Average Waveform FFT for OP Channel %03i;f (MHz);power", i);
299  double dt = averageWaveforms[i]->GetXaxis()->GetBinLowEdge(2) - averageWaveforms[i]->GetXaxis()->GetBinLowEdge(1);
300  double Fmax = 1. / (2*dt);
301  waveformFFTs[i] = RunDir.make< TH1D >(histName, histTitle, averageWaveforms[i]->GetNbinsX()/2, 0., Fmax);
302  }
303  profile->FFT( waveformFFTs[i], "MAG" );
304  waveformFFTs[i]->SetStats(false);
305  waveformFFTs[i]->GetXaxis()->SetTitleSize(0.045);
306  waveformFFTs[i]->GetYaxis()->SetTitleSize(0.045);
307  delete profile;
308  }
309 
310  // Add pulse amplitude histos to pulse amp vs run histograms
311  for ( int i = 0; i < 100; ++i ) {
312  if ( PulseAmplitudePerChannel.find(i) == PulseAmplitudePerChannel.end() ) continue;
313  auto histo = PulseAmpVsRun.find( i );
314  // Make a new histogram if it doesn't already exist.
315  if ( histo == PulseAmpVsRun.end() ) {
316  TString histName = TString::Format("PulseAmpDistVsRun_channel_%03i", i);
317  TString histTitle = TString::Format("Pulse Amplitude Distribution vs Run Number for OP Channel %03i;run number;leading-edge amplitude [ADC]", i);
318  PulseAmpVsRun[i] = new TH2D( histName, histTitle, 1, run.run(), run.run()+1, 125, -20, 230 );
319  } else {
320  // Remake the histogram with extended range
321  TH2D* oldHist = PulseAmpVsRun[i];
322  int firstRun = (int)std::min( double(run.run()), oldHist->GetXaxis()->GetBinLowEdge(1) );
323  int lastRun = (int)std::max( double(run.run()), oldHist->GetXaxis()->GetBinLowEdge( oldHist->GetNbinsX() ) );
324  PulseAmpVsRun[i] = new TH2D( oldHist->GetName(), oldHist->GetTitle(), lastRun-firstRun+1, firstRun, lastRun+1, 125, -20, 230 );
325  for ( int binX = 0; binX <= oldHist->GetNbinsX(); ++binX ) {
326  for ( int binY = 0; binY <= oldHist->GetNbinsY(); ++binY ) {
327  double oldVal = oldHist->GetBinContent( binX, binY );
328  int runNum = oldHist->GetXaxis()->GetBinLowEdge( binX );
329  int targBin = PulseAmpVsRun[i]->GetXaxis()->FindBin( runNum );
330  std::cout << "Transferring into new histogram: " << targBin << " " << binY << " " << oldVal << std::endl;
331  PulseAmpVsRun[i]->SetBinContent( targBin, binY, oldVal );
332  }
333  }
334  delete oldHist;
335  }
336  // Add the new data
337  for ( int binY = 0; binY <= PulseAmplitudePerChannel[i]->GetNbinsX(); ++binY ) {
338  double val = PulseAmplitudePerChannel[i]->GetBinContent(binY);
339  double amp = PulseAmplitudePerChannel[i]->GetBinCenter(binY);
340  std::cout << "Filling histogram with " << run.run() << " " << amp << " " << val << "( PulseAmplitudePerChannel bin " << binY << " )" << std::endl;
341  PulseAmpVsRun[i]->Fill( run.run(), amp, val );
342  }
343 
344  }
345 
346 }
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::map< int, TH1D * > PulseAmplitudePerChannel
std::map< int, long int > triggerCount
std::map< int, TH1D * > IntegratedChargePerChannel
static int max(int a, int b)
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
p
Definition: test.py:223
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
std::map< int, TH2D * > PulseAmplitudeVsIntegratedChargePerChannel
std::map< int, TH2D * > averageWaveforms
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
double ClockFrequency()
Return the NOvAClockFrequency.
QTextStream & endl(QTextStream &s)
unsigned int run
SSPDiagnosticAna& DAQToOffline::SSPDiagnosticAna::operator= ( SSPDiagnosticAna const &  )
delete
SSPDiagnosticAna& DAQToOffline::SSPDiagnosticAna::operator= ( SSPDiagnosticAna &&  )
delete
void DAQToOffline::SSPDiagnosticAna::printParameterSet ( )

Definition at line 151 of file SSPDiagnosticAna_module.cc.

151  {
152 
153  mf::LogDebug("SSPDiagnosticAna") << "====================================" << "\n"
154  << "Parameter Set" << "\n"
155  << "====================================" << "\n"
156  << "fFragType: " << fFragType << "\n"
157  << "fRawDataLabel: " << fRawDataLabel << "\n"
158  << "====================================" << "\n";
159 }
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
void DAQToOffline::SSPDiagnosticAna::reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 129 of file SSPDiagnosticAna_module.cc.

129  {
130 
131  fFragType = pset.get<std::string>("FragType");
132  fRawDataLabel = pset.get<std::string>("RawDataLabel");
133  fInputModule = pset.get<std::string>("InputModule");
134  fInputLabel = pset.get<std::string>("InputLabel");
135  // m1_window = pset.get<int>("SSPm1");
136  // i1_window = pset.get<int>("SSPi1");
137  // i2_window = pset.get<int>("SSPi2");
138 
139  //fDebug = pset.get<bool>("Debug");
140  //fZeroThreshold=0;
141  //fCompression=raw::kNone;
142  // Obtain parameters from TimeService
143  auto const* timeService = lar::providerFrom<detinfo::DetectorClocksService>();
144  fSampleFreq = timeService->OpticalClock().Frequency();
145 
146 
148 
149 }
std::string string
Definition: nybbler.cc:12

Member Data Documentation

std::map< int, TH2D* > DAQToOffline::SSPDiagnosticAna::averageWaveforms
private

Definition at line 96 of file SSPDiagnosticAna_module.cc.

std::string DAQToOffline::SSPDiagnosticAna::fFragType
private

Definition at line 84 of file SSPDiagnosticAna_module.cc.

std::string DAQToOffline::SSPDiagnosticAna::fInputLabel
private

Definition at line 88 of file SSPDiagnosticAna_module.cc.

std::string DAQToOffline::SSPDiagnosticAna::fInputModule
private

Definition at line 87 of file SSPDiagnosticAna_module.cc.

unsigned long int DAQToOffline::SSPDiagnosticAna::firstTime
private

Definition at line 111 of file SSPDiagnosticAna_module.cc.

std::string DAQToOffline::SSPDiagnosticAna::fOutputDataLabel
private

Definition at line 86 of file SSPDiagnosticAna_module.cc.

TH1D* DAQToOffline::SSPDiagnosticAna::fPulseAmplitude
private

Definition at line 100 of file SSPDiagnosticAna_module.cc.

std::string DAQToOffline::SSPDiagnosticAna::fRawDataLabel
private

Definition at line 85 of file SSPDiagnosticAna_module.cc.

double DAQToOffline::SSPDiagnosticAna::fSampleFreq
private

Definition at line 89 of file SSPDiagnosticAna_module.cc.

const int DAQToOffline::SSPDiagnosticAna::i1_window = 500
private

Definition at line 91 of file SSPDiagnosticAna_module.cc.

const int DAQToOffline::SSPDiagnosticAna::i2_window = 500
private

Definition at line 92 of file SSPDiagnosticAna_module.cc.

std::map< int, TH1D* > DAQToOffline::SSPDiagnosticAna::IntegratedChargePerChannel
private

Definition at line 102 of file SSPDiagnosticAna_module.cc.

unsigned long int DAQToOffline::SSPDiagnosticAna::lastTime
private

Definition at line 112 of file SSPDiagnosticAna_module.cc.

const int DAQToOffline::SSPDiagnosticAna::m1_window = 10
private

Definition at line 90 of file SSPDiagnosticAna_module.cc.

std::map< int, TH1D* > DAQToOffline::SSPDiagnosticAna::PulseAmplitudePerChannel
private

Definition at line 101 of file SSPDiagnosticAna_module.cc.

std::map< int, TH2D* > DAQToOffline::SSPDiagnosticAna::PulseAmplitudeVsIntegratedChargePerChannel
private

Definition at line 103 of file SSPDiagnosticAna_module.cc.

std::map< int, TH2D* > DAQToOffline::SSPDiagnosticAna::PulseAmpVsRun
private

Definition at line 105 of file SSPDiagnosticAna_module.cc.

TSpectrum* DAQToOffline::SSPDiagnosticAna::specAnalyzer = new TSpectrum( 100 )
private

Definition at line 107 of file SSPDiagnosticAna_module.cc.

SSPReformatterAlgs DAQToOffline::SSPDiagnosticAna::sspReform
private

Definition at line 109 of file SSPDiagnosticAna_module.cc.

std::map<int, long int> DAQToOffline::SSPDiagnosticAna::triggerCount
private

Definition at line 113 of file SSPDiagnosticAna_module.cc.

std::map< int, TH1D* > DAQToOffline::SSPDiagnosticAna::waveformFFTs
private

Definition at line 98 of file SSPDiagnosticAna_module.cc.


The documentation for this class was generated from the following file: