24 #include "art_root_io/TFileService.h" 25 #include "art_root_io/TFileDirectory.h" 32 #include "TSpectrum.h" 40 #include "lbne-raw-data/Overlays/SSPFragment.hh" 41 #include "lbne-raw-data/Overlays/anlTypes.hh" 42 #include "artdaq-core/Data/Fragment.hh" 56 class SSPDiagnosticAna;
143 auto const* timeService = lar::providerFrom<detinfo::DetectorClocksService>();
144 fSampleFreq = timeService->OpticalClock().Frequency();
153 mf::LogDebug(
"SSPDiagnosticAna") <<
"====================================" <<
"\n" 154 <<
"Parameter Set" <<
"\n" 155 <<
"====================================" <<
"\n" 158 <<
"====================================" <<
"\n";
166 fPulseAmplitude = tfs->make<TH1D>(
"pulseamplitude",
"Pulse Amplitude;leading-edge amplitude [ADC]",125,-50,200);
207 double freq = ((double)itr->second) / deltaTus * 1000.;
229 for (
int i = 0; i < 100; ++i ) {
246 for (
int i = 0; i < 100; ++i ) {
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 ) {
266 ADCperPE /= double(nDiffs);
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 ) {
284 INTperPE /= double(nDiffs);
286 std::cout <<
"OpDet Channel " << i <<
" :\t LE " << ADCperPE <<
" ADC/PE" <<
"\t IC " << INTperPE <<
" charge/PE" <<
std::endl;
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 ) {
298 TString histTitle =
TString::Format(
"Average Waveform FFT for OP Channel %03i;f (MHz);power", i);
300 double Fmax = 1. / (2*dt);
311 for (
int i = 0; i < 100; ++i ) {
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 );
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;
340 std::cout <<
"Filling histogram with " << run.
run() <<
" " << amp <<
" " << val <<
"( PulseAmplitudePerChannel bin " << binY <<
" )" <<
std::endl;
352 for (
int i = 0; i < 100; ++i ) {
368 art::TFileDirectory RunDir = tfs->mkdir(
TString::Format(
"r%03i", evt.
run()).
Data(),
"SSP Diagnostics by Run" );
374 mf::LogInfo(
"SSPDiagnosticAna") <<
"Starting event analysis";
378 try { rawFragments->size(); }
380 mf::LogWarning(
"SSPDiagnosticAna") <<
"WARNING: Raw SSP data not found in event " << evt.
event();
387 <<
", SubRun: " << evt.
subRun()
388 <<
", Event: " << evt.
event()
394 mf::LogInfo(
"SSPDiagnosticAna") <<
"Data is valid!";
400 for (
size_t i = 0; i < waveformHandle->size(); i++)
412 TString histName =
TString::Format(
"avgwaveform_channel_%03i", channel);
414 TString histTitle =
TString::Format(
"Average Waveform for OP Channel %03i;t (us);amplitude (ADC)", channel);
430 unsigned int numFragments = rawFragments->size();
431 mf::LogInfo(
"SSPDiagnosticAna") <<
"Number of fragments = " << numFragments;
433 for (
size_t idx = 0; idx < numFragments; ++idx) {
435 mf::LogInfo(
"SSPDiagnosticAna") <<
"Number of fragments = " << idx;
437 const auto& frag((*rawFragments)[idx]);
438 lbne::SSPFragment sspf(frag);
442 mf::LogInfo(
"SSPDiagnosticAna") <<
"Triggers = " << nTriggers;
444 const unsigned int* dataPointer = sspf.dataBegin();
447 for (
unsigned int triggersProcessed = 0;
448 (nTriggers==0 || triggersProcessed < nTriggers) && dataPointer < sspf.dataEnd();
449 ++triggersProcessed) {
454 unsigned short OpChannel = -1;
455 unsigned long FirstSample = 0;
459 const SSPDAQ::EventHeader* daqHeader=
reinterpret_cast<const SSPDAQ::EventHeader*
>(dataPointer);
460 dataPointer +=
sizeof(SSPDAQ::EventHeader)/
sizeof(
unsigned int);
463 unsigned int nADC=(daqHeader->length-
sizeof(SSPDAQ::EventHeader)/
sizeof(
unsigned int))*2;
491 mf::LogInfo(
"SSPDiagnosticAna") <<
"Pulse Amplitude: " << PulseAmplitude;
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);
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);
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);
523 if (FirstSample < 1e16) {
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
EventNumber_t event() const
void endEvent(art::EventNumber_t eventNumber)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
void analyze(art::Event const &evt) override
SSPDiagnosticAna(fhicl::ParameterSet const &pset)
void endRun(art::Run const &run) override
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
std::map< int, TH1D * > waveformFFTs
std::map< int, TH1D * > PulseAmplitudePerChannel
unsigned long int lastTime
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
#define DEFINE_ART_MODULE(klass)
SSPDiagnosticAna & operator=(SSPDiagnosticAna const &)=delete
Collect all the RawData header files together.
T get(std::string const &key) const
std::map< int, long int > triggerCount
std::map< int, TH1D * > IntegratedChargePerChannel
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
SubRunNumber_t subRun() const
std::string fRawDataLabel
static int max(int a, int b)
Q_EXPORT QTSManip setw(int w)
void beginRun(art::Run const &run) override
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
std::map< int, TH2D * > PulseAmpVsRun
MaybeLogger_< ELseverityLevel::ELsev_success, false > LogDebug
std::map< int, TH2D * > PulseAmplitudeVsIntegratedChargePerChannel
std::map< int, TH2D * > averageWaveforms
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
IDNumber_t< Level::Event > EventNumber_t
void beginEvent(art::EventNumber_t eventNumber)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
unsigned long int firstTime
auto const & get(AssnsNode< L, R, D > const &r)
void reconfigure(fhicl::ParameterSet const &pset)
std::string fOutputDataLabel
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
SSPReformatterAlgs sspReform