19 #include "art_root_io/TFileService.h" 27 #include "TTimeStamp.h" 150 logInfo <<
"NearlineAna" <<
"\n";
163 logInfo <<
"reconfigure" <<
"\n";
196 logInfo <<
"fVerboseOutput: " << (
fVerboseOutput ?
"true" :
"false") <<
"\n";
198 logInfo <<
"fHitsTag: " <<
fHitsTag <<
"\n";
203 logInfo <<
"fHitsPerEventChannels";
205 else logInfo <<
"(offline): ";
215 logInfo <<
"fPedestalPerEventChannels";
217 else logInfo <<
"(offline): ";
230 logInfo <<
"fPedestalPerTickChannels";
232 else logInfo <<
"(offline): ";
250 logInfo <<
"beginJob" <<
"\n";
254 fHeader = tfs->make<TTree>(
"Header",
"Subrun Information");
271 fHistNearlineVersion = tfs->make<TH1I>(
"hist_nearline_version",
"hist_nearline_version", 2, 0, 2);
294 unsigned int hour, minute,
second;
307 const unsigned long int mask32 = 0xFFFFFFFFUL;
313 unsigned long int llo = (
fStartTime >> 32 ) & mask32;
315 TTimeStamp ts1(lup, (
int)llo);
317 ts1.GetTime(kTRUE,0,&hour,&minute,&second);
318 nano = ts1.GetNanoSec();
319 double sec = ((double)second + (
double)nano/1.0e9);
320 fStartHour = (double)hour + (
double)minute/60.0 + sec/3600.0;
327 TTimeStamp ts2(lup, (
int)llo);
329 ts2.GetTime(kTRUE,0,&hour,&minute,&second);
330 nano = ts2.GetNanoSec();
331 sec = ((double)second + (
double)nano/1.0e9);
332 fEndHour = (double)hour + (
double)minute/60.0 + sec/3600.0;
351 unsigned int run = e.
run();
353 unsigned int event = e.
id().
event();
385 try { digitHandle->size(); }
387 mf::LogError(
"NearlineAna::getRawDigits") <<
"WARNING: Issue with digitHandle for RawDigits" <<
std::endl;
391 if(!digitHandle.isValid()){
393 <<
", SubRun: " << e.
subRun()
394 <<
", Event: " << e.
event()
400 return digitHandle->size();
412 try { hitsHandle->size(); }
418 if(!hitsHandle.isValid()){
420 <<
", SubRun: " << e.
subRun()
421 <<
", Event: " << e.
event()
427 return hitsHandle->size();
435 mf::LogInfo logInfo(
"NearlineAna::makeHitsPerEventPlots");
445 std::string hist_title =
"Hits Per Event - Channel " 450 TH1I* histTemp = tfs->make<TH1I>(hist_name.c_str(), hist_title.c_str(), numBins, xmin, xmax);
451 histTemp->GetXaxis()->SetTitle(
"Hits per Event");
452 histTemp->GetYaxis()->SetTitle(
"Events");
454 if(
fVerboseOutput) logInfo <<
"channel: " <<
channel <<
" hist_name: " << hist_name <<
" hist_title: " << hist_title <<
"\n";
465 mf::LogInfo logInfo(
"NearlineAna::makePedestalPerEventPlots");
466 if(
fVerboseOutput) logInfo <<
"fPedestalPerEventChannels:" <<
"\n";
475 std::string hist_title =
"Average ADC Per Event - Channel " 480 TH1I* histTemp = tfs->make<TH1I>(hist_name.c_str(), hist_title.c_str(), numBins, xmin, xmax);
481 histTemp->GetXaxis()->SetTitle(
"ADC");
482 histTemp->GetYaxis()->SetTitle(
"Events");
484 if(
fVerboseOutput) logInfo <<
"channel: " <<
channel <<
" hist_name: " << hist_name <<
" hist_title: " << hist_title <<
"\n";
495 mf::LogInfo logInfo(
"NearlineAna::makePedestalPerTickPlots");
496 if(
fVerboseOutput) logInfo <<
"fPedestalPerTickChannels:" <<
"\n";
511 TH1I* histTemp = tfs->make<TH1I>(hist_name.c_str(), hist_title.c_str(), numBins, xmin, xmax);
512 histTemp->GetXaxis()->SetTitle(
"ADC");
513 histTemp->GetYaxis()->SetTitle(
"Events");
515 if(
fVerboseOutput) logInfo <<
"channel: " <<
channel <<
" hist_name: " << hist_name <<
" hist_title: " << hist_title <<
"\n";
526 mf::LogInfo logInfo(
"NearlineAna::fillHistPerEventPlots");
528 size_t numHits =
getHits(e, hitHandle);
533 if(numHits==0)
return;
535 for(
size_t hitIter=0;hitIter<numHits;hitIter++){
548 if(this_channel!=channel)
continue;
549 numHitsPerChannel.at(
index) += 1;
556 histTemp->Fill(numHitsPerChannel.at(
index));
560 logInfo <<
"Channel (Number of Hits): \n";
574 mf::LogInfo logInfo(
"NearlineAna::fillPedestalPerEventPlots");
590 for(
size_t rdIter=0;rdIter<numDigitChans;rdIter++){
597 if(this_channel!=
channel)
continue;
602 auto numSamples = digitVec->
Samples();
606 if(numSamples==0)
continue;
614 for(
unsigned int sample=0;sample<numSamples;sample++){
615 averageADC+=ADCsUncompressed[sample];
618 averageADC/=numSamples;
621 histTemp->Fill(averageADC);
633 mf::LogInfo logInfo(
"NearlineAna::fillPedestalPerTickPlots");
649 for(
size_t rdIter=0;rdIter<numDigitChans;rdIter++){
656 if(this_channel!=
channel)
continue;
661 auto numSamples = digitVec->
Samples();
665 if(numSamples==0)
continue;
673 for(
unsigned int sample=0;sample<numSamples;sample++){
674 histTemp->Fill(ADCsUncompressed[sample]);
684 std::ostringstream my_ostream;
685 my_ostream <<
"online_channel " <<
"offline_channel " <<
"pedestal_mean " <<
"pedestal_rms " <<
"\n";
688 auto online_channel = -1;
695 double mean = histTemp->GetMean();
696 double rms = histTemp->GetRMS();
697 my_ostream << online_channel <<
" " << offline_channel <<
" " << mean <<
" " << rms <<
"\n";
700 std::ofstream outFile(fileName);
701 if(outFile.is_open()) outFile << my_ostream.str();
702 else mf::LogWarning(
"writePedestalPerEventSummaryFile") <<
"FAILED to open file: " << fileName;
706 mf::LogInfo(
"writePedestalPerEventSummaryFile") << my_ostream.str();
712 std::ostringstream my_ostream;
713 my_ostream <<
"online_channel " <<
"offline_channel " <<
"pedestal_mean " <<
"pedestal_rms " <<
"\n";
716 auto online_channel = -1;
723 double mean = histTemp->GetMean();
724 double rms = histTemp->GetRMS();
725 my_ostream << online_channel <<
" " << offline_channel <<
" " << mean <<
" " << rms <<
"\n";
728 std::ofstream outFile(fileName);
729 if(outFile.is_open()) outFile << my_ostream.str();
730 else mf::LogWarning(
"writePedestalPerEventSummaryFile") <<
"FAILED to open file: " << fileName;
734 mf::LogInfo(
"writePedestalPerTickSummaryFile") << my_ostream.str();
754 if (fullname.empty())
755 mf::LogWarning(
"DAQToOffline") <<
"Input TPC channel map file " << channelMapFile <<
" not found in FW_SEARCH_PATH. Using online channel numbers!" <<
std::endl;
758 mf::LogVerbatim(
"DAQToOffline") <<
"Build TPC Online->Offline channel Map from " << fullname;
759 std::ifstream
infile(fullname);
760 while (infile.good()) {
761 infile >> onlineChannel >> offlineChannel;
762 channelMap.insert(std::make_pair(onlineChannel,offlineChannel));
763 mf::LogVerbatim(
"DAQToOffline") <<
" " << onlineChannel <<
" -> " << offlineChannel;
765 std::cout <<
"channelMap has size " << channelMap.size() <<
". If this is 2048, then it's fine even if the above lines skipped a 'few' channels..." <<
std::endl;
void analyze(art::Event const &e) override
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
EventNumber_t event() const
void fillPedestalPerTickPlots(art::Event const &e)
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
art::InputTag fRawDigitsTag
const int NearlineMajorVersion
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
size_t getHits(art::Event const &e, art::Handle< std::vector< recob::Hit >> &hitsHandle)
NearlineAna & operator=(NearlineAna const &)=delete
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
Declaration of signal hit object.
bool fMakePedestalPerTickPlots
void fillPedestalPerEventPlots(art::Event const &e)
std::vector< TH1I * > fVecPedestalPerEventPlots
ChannelID_t Channel() const
DAQ channel this raw data was read from.
std::vector< short > ADCvector_t
Type representing a (compressed) vector of ADC counts.
void makeHitsPerEventPlots()
Definition of basic raw digits.
std::vector< unsigned int > fPedestalPerTickChannels
void fillHitsPerEventPlots(art::Event const &e)
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
EDAnalyzer(fhicl::ParameterSet const &pset)
constexpr TimeValue_t value() const
void makePedestalPerTickPlots()
std::vector< unsigned int > fPedestalPerEventChannels
void reconfigure(fhicl::ParameterSet const &p)
std::string fPedestalPerTickFileName
const int NearlineMinorVersion
TH1I * fHistNearlineVersion
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
bool fWritePedestalPerTickFile
#define DEFINE_ART_MODULE(klass)
std::vector< TH1I * > fVecHitsPerEventPlots
std::string fChannelMapFile
size_t getRawDigits(art::Event const &e, art::Handle< std::vector< raw::RawDigit >> &digitHandle)
Collect all the RawData header files together.
T get(std::string const &key) const
void makePedestalPerEventPlots()
unsigned long long int fStartTime
SubRunNumber_t subRun() const
std::map< int, int > fChannelMap
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
NearlineAna(fhicl::ParameterSet const &p)
static constexpr Timestamp invalidTimestamp()
bool fMakeHitsPerEventPlots
bool fMakePedestalPerEventPlots
bool fWritePedestalPerEventFile
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
std::string find_file(std::string const &filename) const
std::string fPedestalPerEventFileName
std::vector< unsigned int > fHitsPerEventChannels
EventNumber_t event() const
unsigned long long int fEndTime
void writePedestalPerTickSummaryFile(std::string fileName)
unsigned int ChannelID_t
Type representing the ID of a readout channel.
std::vector< TH1I * > fVecPedestalPerTickPlots
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
second_as<> second
Type of time stored in seconds, in double precision.
void writePedestalPerEventSummaryFile(std::string fileName)
void BuildTPCChannelMap(std::string channelMapFile, std::map< int, int > &channelMap)
raw::ChannelID_t Channel() const
ID of the readout channel the hit was extracted from.
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
std::string to_string(ModuleType const mt)
cet::coded_exception< error, detail::translate > exception
QTextStream & endl(QTextStream &s)
Event finding and building.