13 #ifndef IcebergTpcMonitor_module 14 #define IcebergTpcMonitor_module 31 #include "art_root_io/TFileService.h" 33 #include "canvas/Persistency/Common/FindManyP.h" 43 #include "TLorentzVector.h" 49 #include "TProfile2D.h" 61 #pragma link C++ class vector<vector<int> >+; 198 float rmsADC(std::vector< short > & uncompressed);
199 float meanADC(std::vector< short > & uncompressed);
200 void calculateFFT(TH1D* hist_waveform, TH1D* graph_frequency);
201 void FillChannelHistos(TProfile*
h1,
double mean,
double sigma,
int& ndeadchannels,
int& nnoisychannels_sigma,
int& nnoisychannels_counts);
267 for(
unsigned int i=0;i<
fNofAPA;i++)
285 fStuckCodeOffFrac.push_back(tfs->make<TH1F>(Form(
"fStuckCodeOffFrac%d",j),Form(
"Stuck-Off Code Fraction APA%d",j),100,0,1));
286 fStuckCodeOnFrac.push_back(tfs->make<TH1F>(Form(
"fStuckCodeOnFrac%d",j),Form(
"Stuck-On Code Fraction APA%d",j),100,0,1));
289 fChanRMSU_pfx.push_back(tfs->make<TProfile>(Form(
"fChanRMSU%d_pfx", j),Form(
"Profiled RMS vs Channel(Plane U, APA%d)", j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5,
"s"));
290 fChanMeanU_pfx.push_back(tfs->make<TProfile>(Form(
"fChanMeanU%d_pfx",j),Form(
"Profiled MEAN vs Channel(Plane U, APA%d)",j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5,
"s"));
291 fChanFFTU.push_back(tfs->make<TH2F>(Form(
"fChanFFTU%d", j),Form(
"fChanFFT (Plane U, APA%d)", j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5,
fNticks/2,0,
fNticks/2*
fBinWidth));
292 fChanMeanDistU.push_back(tfs->make<TH1F>(Form(
"fChanMeanDistU%d",j),Form(
"Means of Channels in (Plane U, APA%d)",j), 1000, 0, 16383));
293 fChanRMSDistU.push_back(tfs->make<TH1F>(Form(
"fChanRMSDistU%d",j),Form(
"RMSs of Channels in (Plane U, APA%d)",j), 100, 0, 50));
294 fChanStuckCodeOffFracU.push_back(tfs->make<TProfile>(Form(
"fChanStuckCodeOffFracU%d",j),Form(
"Stuck-Off Code Fraction (Plane U, APA%d)",j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5,
"s"));
295 fChanStuckCodeOnFracU.push_back(tfs->make<TProfile>(Form(
"fChanStuckCodeOnFracU%d",j),Form(
"Stuck-On Code Fraction (Plane U, APA%d)",j), UChMax - UChMin + 1, UChMin-0.5, UChMax+0.5,
"s"));
298 fChanRMSV_pfx.push_back(tfs->make<TProfile>(Form(
"fChanRMSV%d_pfx",j),Form(
"Profiled RMS vs Channel(Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5,
"s"));
299 fChanMeanV_pfx.push_back(tfs->make<TProfile>(Form(
"fChanMeanV%d_pfx",j),Form(
"Profiled Mean vs Channel(Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5,
"s"));
300 fChanFFTV.push_back(tfs->make<TH2F>(Form(
"fChanFFTV%d", j),Form(
"fChanFFT (Plane V, APA%d)", j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5,
fNticks/2,0,
fNticks/2*
fBinWidth));
301 fChanMeanDistV.push_back(tfs->make<TH1F>(Form(
"fChanMeanDistV%d",j),Form(
"Means of Channels in (Plane V, APA%d)",j), 1000, 0, 16383));
302 fChanRMSDistV.push_back(tfs->make<TH1F>(Form(
"fChanRMSDistV%d",j),Form(
"RMSs of Channels in (Plane V, APA%d)",j), 100, 0, 50));
303 fChanStuckCodeOffFracV.push_back(tfs->make<TProfile>(Form(
"fChanStuckCodeOffFracV%d",j),Form(
"Stuck-Off Code Fraction (Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5,
"s"));
304 fChanStuckCodeOnFracV.push_back(tfs->make<TProfile>(Form(
"fChanStuckCodeOnFracV%d",j),Form(
"Stuck-On Code Fraction (Plane V, APA%d)",j), VChMax - VChMin + 1, VChMin-0.5, VChMax+0.5,
"s"));
307 fChanRMSZ_pfx.push_back(tfs->make<TProfile>(Form(
"fChanRMSZ%d_pfx",j),Form(
"Profiled RMS vs Channel(Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5,
"s"));
308 fChanMeanZ_pfx.push_back(tfs->make<TProfile>(Form(
"fChanMeanZ%d_pfx",j),Form(
"Profiled Mean vs Channel(Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5,
"s"));
309 fChanFFTZ.push_back(tfs->make<TH2F>(Form(
"fChanFFTZ%d", j),Form(
"fChanFFT (Plane Z, APA%d)", j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5,
fNticks/2,0,
fNticks/2*
fBinWidth));
310 fChanMeanDistZ.push_back(tfs->make<TH1F>(Form(
"fChanMeanDistZ%d",j),Form(
"Means of Channels in (Plane Z, APA%d)",j), 1000, 0, 16383));
311 fChanRMSDistZ.push_back(tfs->make<TH1F>(Form(
"fChanRMSDistZ%d",j),Form(
"RMSs of Channels in (Plane Z, APA%d)",j), 100, 0, 50));
312 fChanStuckCodeOffFracZ.push_back(tfs->make<TProfile>(Form(
"fChanStuckCodeOffFracZ%d",j),Form(
"Stuck-Off Code Fraction (Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5,
"s"));
313 fChanStuckCodeOnFracZ.push_back(tfs->make<TProfile>(Form(
"fChanStuckCodeOnFracZ%d",j),Form(
"Stuck-On Code Fraction (Plane Z, APA%d)",j), ZChMax - ZChMin + 1, ZChMin-0.5, ZChMax+0.5,
"s"));
322 fChanFFTU[i]->GetXaxis()->SetTitle(
"Chan");
fChanFFTU[i]->GetYaxis()->SetTitle(
"kHz");
323 fChanFFTV[i]->GetXaxis()->SetTitle(
"Chan");
fChanFFTV[i]->GetYaxis()->SetTitle(
"kHz");
324 fChanFFTZ[i]->GetXaxis()->SetTitle(
"Chan");
fChanFFTZ[i]->GetYaxis()->SetTitle(
"kHz");
356 std::pair<std::string, std::string> fembmapstr_by_fiberID[10] =
358 {
"727",
"WIB1-FEMB1"}, {
"726",
"WIB3-FEMB1"},{
"716",
"WIB2-FEMB1"},{
"723",
"WIB1-FEMB2"},{
"703",
"WIB3-FEMB3"},
359 {
"FM015",
"WIB1-FEMB4"},{
"FM012",
"WIB2-FEMB4"},{
"FM140",
"WIB3-FEMB4"},{
"721",
"WIB1-FEMB3"},{
"706",
"WIB2-FEMB3"}
364 for(
int i=0;i<10;i++) {
366 unsigned int z_i = (i > 4) ? 14 - i : i;
368 std::pair<std::string, std::string> fembstr = fembmapstr_by_fiberID[i];
373 fFFT_by_Fiber_pfx.push_back(tfs->make<TProfile>(Form(
"Profiled_FFT_FEMB_%02d", z_i+1), Form(
"Profiled FFT FEMB_%s %s", fembstr.first.c_str(), fembstr.second.c_str()),
fNticks/2, 0,
fNticks/2*
fBinWidth, -100, 50));
377 for (
unsigned int i=0;i<
fNofAPA;++i)
384 fNTicksTPC = tfs->make<TH1F>(
"NTicksTPC",
"NTicks in TPC Channels",100,0,20000);
387 fNDeadChannelsHisto = tfs->make<TH1F>(
"fNDeadChannelsHisto",
"Number of dead channels",fNofAPA+1,0,fNofAPA+1);
388 fNDeadChannelsHisto->GetYaxis()->SetTitle(
"Number of dead channels");
394 fNDeadChannelsHistoU = tfs->make<TH1F>(
"fNDeadChannelsHistoU",
"Number of dead channels (Plane U)",fNofAPA+1,0,fNofAPA+1);
401 fNDeadChannelsHistoV = tfs->make<TH1F>(
"fNDeadChannelsHistoV",
"Number of dead channels (Plane V)",fNofAPA+1,0,fNofAPA+1);
408 fNDeadChannelsHistoZ = tfs->make<TH1F>(
"fNDeadChannelsHistoZ",
"Number of dead channels (Plane Z)",fNofAPA+1,0,fNofAPA+1);
422 for(
unsigned int i=0;i<
fNofAPA;i++){
424 TString apastring = Form(
"APA %i", j);
425 fNDeadChannelsHisto->GetXaxis()->SetBinLabel(j+1, apastring.Data());
463 fNticks = detProp.NumberTimeSamples();
482 <<
"-------------------- TPC IcebergTpcMonitor -------------------";
486 fEvent =
event.id().event();
493 auto RawTPC =
event.getHandle< std::vector<raw::RawDigit> >(itag1);
497 auto RDStatusHandle =
event.getHandle< std::vector<raw::RDStatus> >(itag1);
501 std::vector< art::Ptr<raw::RawDigit> >
RawDigits;
506 for (
auto const& rdstatus : (*RDStatusHandle) )
508 if (rdstatus.GetCorruptDataDroppedFlag())
510 MF_LOG_INFO(
"IcebergTpcMonitor_module: ") <<
"Corrupt Data Dropped Flag set in RDStatus";
518 for(
auto const & dptr : RawDigits) {
522 uint32_t chan = digit.
Channel();
524 int nSamples = digit.
Samples();
530 std::vector<short> uncompressed(nSamples);
539 std::vector<short> uncompPed(nSamples);
543 for (
int i=0; i<nSamples; i++)
545 auto adc=uncompressed.at(i);
546 auto adcl6b =
adc & 0x3F;
547 if (adcl6b == 0) ++nstuckoff;
548 if (adcl6b == 0x3F) ++nstuckon;
549 uncompPed.at(i) =
adc - pedestal;
551 float fracstuckoff = ((
float) nstuckoff)/((
float) nSamples);
552 float fracstuckon = ((
float) nstuckon)/((
float) nSamples);
559 TH1D* histwav=
new TH1D(Form(
"wav%d",(
int)chan),Form(
"wav%d",(
int)chan),nSamples,0,nSamples);
562 histwav->SetBinContent(
k+1, uncompPed.at(
k));
568 TH1D* histfft=
new TH1D(Form(
"fft%d",(
int)chan),Form(
"fft%d",(
int)chan),nSamples,0,nSamples*
fBinWidth);
595 for(
int l=0;
l<nSamples/2;
l++) {
597 fChanFFTU[apa]->Fill(chan, (
l+0.5)*fBinWidth, histfft->GetBinContent(
l+1));
612 for(
int l=0;
l<nSamples/2;
l++) {
614 fChanFFTV[apa]->Fill(chan, (
l+0.5)*fBinWidth, histfft->GetBinContent(
l+1));
629 for(
int l=0;
l<nSamples/2;
l++) {
631 fChanFFTZ[apa]->Fill(chan, (
l+0.5)*fBinWidth, histfft->GetBinContent(
l+1));
648 int n = uncomp.size();
650 for(
int i = 0; i <
n; i++){
651 if(uncomp[i]!=0) sum += uncomp[i];
653 float mean = sum /
n;
655 for(
int i = 0; i <
n; i++)
657 if (uncomp[i]!=0) sum += (uncomp[i]-
mean)*(uncomp[i]-mean);
659 return sqrt(sum / n);
666 int n = uncomp.size();
668 for(
int i = 0; i <
n; i++)
670 if (uncomp[i]!=0) sum +=
abs(uncomp[i]);
679 int n_bins = hist_waveform->GetNbinsX();
680 TH1* hist_transform = 0;
683 hist_transform = hist_waveform->FFT(hist_transform,
"MAG");
684 hist_transform ->
Scale (1.0 /
float(n_bins));
685 int nFFT=hist_transform->GetNbinsX();
692 for (
int k = 0;
k < nFFT/2;
k++){
695 amplitude = hist_transform->GetBinContent(
k+1);
696 amplitudeLog = 20*log10(amplitude);
697 hist_frequency->Fill(frequency, amplitudeLog);
700 hist_transform->Delete();
709 TString htitle = h1->GetTitle();
711 for(Int_t j=1; j <= h1->GetNbinsX(); j++){
713 int fChannelID = h1->GetBinCenter(j);
714 double fChannelValue = h1->GetBinContent(j);
716 if(fChannelValue == 0){
721 if(fChannelValue > rms_threshold){
722 nnoisychannels_sigma++;
725 if(htitle.Contains(
"Plane U"))
729 nnoisychannels_counts++;
733 else if(htitle.Contains(
"Plane V"))
737 nnoisychannels_counts++;
741 else if(htitle.Contains(
"Plane Z"))
745 nnoisychannels_counts++;
751 <<
" Unknown histogram title: " << htitle.Data() <<
std::endl;
764 int FEMBchanToHistogram[128][2] = { {0,0},{0,1},{0,2},{0,3},{0,4},
765 {0,10},{0,11},{0,12},{0,13},{0,14},
766 {0,20},{0,21},{0,22},{0,23},{0,24},{0,25},
767 {0,5},{0,6},{0,7},{0,8},{0,9},
768 {0,15},{0,16},{0,17},{0,18},{0,19},
769 {0,26},{0,27},{0,28},{0,29},{0,30},{0,31},
770 {1,20},{1,21},{1,22},{1,23},{1,24},{1,25},
771 {1,10},{1,11},{1,12},{1,13},{1,14},
772 {1,0},{1,1},{1,2},{1,3},{1,4},
773 {1,26},{1,27},{1,28},{1,29},{1,30},{1,31},
774 {1,15},{1,16},{1,17},{1,18},{1,19},
775 {1,5},{1,6},{1,7},{1,8},{1,9},
776 {2,0},{2,1},{2,2},{2,3},{2,4},
777 {2,10},{2,11},{2,12},{2,13},{2,14},
778 {2,20},{2,21},{2,22},{2,23},{2,24},{2,25},
779 {2,5},{2,6},{2,7},{2,8},{2,9},
780 {2,15},{2,16},{2,17},{2,18},{2,19},
781 {2,26},{2,27},{2,28},{2,29},{2,30},{2,31},
782 {3,20},{3,21},{3,22},{3,23},{3,24},{3,25},
783 {3,10},{3,11},{3,12},{3,13},{3,14},
784 {3,0},{3,1},{3,2},{3,3},{3,4},
785 {3,26},{3,27},{3,28},{3,29},{3,30},{3,31},
786 {3,15},{3,16},{3,17},{3,18},{3,19},
787 {3,5},{3,6},{3,7},{3,8},{3,9} };
788 return FEMBchanToHistogram[FEMBchan][
coord];
795 std::vector<double> fURMS_mean; std::vector<double> fURMS_sigma;
796 std::vector<double> fVRMS_mean; std::vector<double> fVRMS_sigma;
797 std::vector<double> fZRMS_mean; std::vector<double> fZRMS_sigma;
798 for(
unsigned int i = 0; i <
fNofAPA; i++){
801 fURMS_mean.push_back(h1->GetMean());
802 fURMS_sigma.push_back(h1->GetRMS());
805 fVRMS_mean.push_back(h2->GetMean());
806 fVRMS_sigma.push_back(h2->GetRMS());
809 fZRMS_mean.push_back(h3->GetMean());
810 fZRMS_sigma.push_back(h3->GetRMS());
813 std::vector<int> fUdch_vec; std::vector<int> fUnch_vec; std::vector<int> fUcch_vec;
814 std::vector<int> fVdch_vec; std::vector<int> fVnch_vec; std::vector<int> fVcch_vec;
815 std::vector<int> fZdch_vec; std::vector<int> fZnch_vec; std::vector<int> fZcch_vec;
817 for(
unsigned int i = 0; i <
fNofAPA; i++){
818 int ndeadchannels = 0;
int nnoisychannels = 0;
int nnoisychannels_counts = 0;
822 FillChannelHistos(h1, fURMS_mean.at(i), fURMS_sigma.at(i), ndeadchannels, nnoisychannels, nnoisychannels_counts);
823 fUdch_vec.push_back(ndeadchannels);
824 fUnch_vec.push_back(nnoisychannels);
825 fUcch_vec.push_back(nnoisychannels_counts);
828 ndeadchannels = 0; nnoisychannels = 0; nnoisychannels_counts = 0;
830 FillChannelHistos(h2, fVRMS_mean.at(i), fVRMS_sigma.at(i), ndeadchannels, nnoisychannels, nnoisychannels_counts);
831 fVdch_vec.push_back(ndeadchannels);
832 fVnch_vec.push_back(nnoisychannels);
833 fVcch_vec.push_back(nnoisychannels_counts);
836 ndeadchannels = 0; nnoisychannels = 0; nnoisychannels_counts = 0;
838 FillChannelHistos(h3, fZRMS_mean.at(i), fZRMS_sigma.at(i), ndeadchannels, nnoisychannels, nnoisychannels_counts);
839 fZdch_vec.push_back(ndeadchannels);
840 fZnch_vec.push_back(nnoisychannels);
841 fZcch_vec.push_back(nnoisychannels_counts);
845 for(
unsigned int i = 0; i <
fNofAPA; i++){
847 int nch = fUdch_vec.at(i) + fVdch_vec.at(i) + fZdch_vec.at(i);
849 nch = fUnch_vec.at(i) + fVnch_vec.at(i) + fZnch_vec.at(i);
851 nch = fUcch_vec.at(i) + fVcch_vec.at(i) + fZcch_vec.at(i);
879 #endif // IcebergTpcMonitore_module std::vector< TH1F * > fChanMeanDistV
std::vector< TH1F * > fChanRMSDistU
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
const ADCvector_t & ADCs() const
Reference to the compressed ADC count vector.
virtual ~IcebergTpcMonitor()
std::vector< TProfile * > fFFT_by_Fiber_pfx
void calculateFFT(TH1D *hist_waveform, TH1D *graph_frequency)
float rmsADC(std::vector< short > &uncompressed)
ULong64_t Samples() const
Number of samples in the uncompressed ADC data.
Collection of charge vs time digitized from a single readout channel.
TH1F * fNNoisyChannelsHistoFromNCountsZ
TH1F * fNNoisyChannelsListFromNSigma
std::vector< TH2F * > fChanFFTZ
double rms(sqlite3 *db, std::string const &table_name, std::string const &column_name)
TH1F * fNNoisyChannelsHistoFromNCountsV
auto coord(Vector &v, unsigned int n) noexcept
Returns an object to manage the coordinate n of a vector.
std::vector< TProfile * > fChanStuckCodeOnFracV
std::vector< TProfile * > fChanRMSZ_pfx
TH1F * fNDeadChannelsHisto
std::vector< TH1F * > fStuckCodeOnFrac
TH1F * fNNoisyChannelsHistoFromNCountsU
TH1F * fNNoisyChannelsHistoFromNSigmaZ
IcebergTpcMonitor(fhicl::ParameterSet const &pset)
void reconfigure(fhicl::ParameterSet const &pset)
ChannelID_t Channel() const
DAQ channel this raw data was read from.
std::vector< raw::RawDigit > RawDigits
std::vector< geo::WireID > ChannelToWire(raw::ChannelID_t const channel) const
Returns a list of wires connected to the specified TPC channel.
TH1F * fNNoisyChannelsListFromNCounts
Planes which measure Z direction.
Scale(size_t pos, T factor) -> Scale< T >
EDAnalyzer(fhicl::ParameterSet const &pset)
unsigned int Ncryostats() const
Returns the number of cryostats in the detector.
void beginRun(const art::Run &run)
unsigned int fChansPerAPA
unsigned int FiberIdFromOfflineChannel(unsigned int offlineChannel) const
Returns global fiber ID.
std::vector< TProfile * > fChanRMSU_pfx
int fNoiseLevelMinNCountsU
void FillChannelHistos(TProfile *h1, double mean, double sigma, int &ndeadchannels, int &nnoisychannels_sigma, int &nnoisychannels_counts)
art framework interface to geometry description
unsigned int Nchannels() const
Returns the number of TPC readout channels in the detector.
int fNoiseLevelMinNCountsZ
std::vector< unsigned int > fApaLabelNum
std::vector< TH1F * > fChanMeanDistU
#define DEFINE_ART_MODULE(klass)
std::vector< TProfile * > fChanMeanU_pfx
TH1F * fNNoisyChannelsHistoFromNSigmaU
T get(std::string const &key) const
std::vector< TProfile * > fChanStuckCodeOnFracU
size_t NADC() const
Number of elements in the compressed ADC sample vector.
std::vector< TH2F * > fPersistentFFT_by_APA
std::vector< TH1F * > fChanRMSDistV
TH1F * fNNoisyChannelsHistoFromNSigmaV
int FEMBchanToHistogramMap(int, int)
Description of geometry of one entire detector.
int fNoiseLevelMinNCountsV
#define MF_LOG_INFO(category)
std::vector< TH1F * > fStuckCodeOffFrac
View_t View(geo::PlaneID const &pid) const
Returns the view (wire orientation) on the channels of specified TPC plane.
Definition of data types for geometry description.
void analyze(const art::Event &evt)
TH1F * fNDeadChannelsHistoU
float meanADC(std::vector< short > &uncompressed)
unsigned int NTPC(unsigned int cstat=0) const
Returns the total number of TPCs in the specified cryostat.
raw::Compress_t Compression() const
Compression algorithm used to store the ADC counts.
TH1F * fNDeadChannelsHistoV
std::vector< TH1F * > fChanMeanDistZ
std::vector< TProfile * > fChanStuckCodeOnFracZ
unsigned int nADC_uncompPed
std::vector< TProfile * > fChanRMSV_pfx
std::vector< TH2F * > fChanFFTU
std::vector< TH2F * > fChanFFTV
std::string fRawDigitLabel
std::vector< TH1F * > fChanRMSDistZ
TH1F * fNDeadChannelsList
std::vector< TProfile * > fChanStuckCodeOffFracZ
std::vector< TProfile * > fChanStuckCodeOffFracU
void fill_ptr_vector(std::vector< Ptr< T >> &ptrs, H const &h)
void Uncompress(const std::vector< short > &adc, std::vector< short > &uncompressed, raw::Compress_t compress)
Uncompresses a raw data buffer.
std::vector< TProfile * > fChanMeanV_pfx
double sampling_rate(DetectorClocksData const &data)
Returns the period of the TPC readout electronics clock.
TH1F * fNNoisyChannelsHistoFromNCounts
std::vector< TProfile * > fChanStuckCodeOffFracV
std::vector< TProfile * > fChanMeanZ_pfx
double mean(sqlite3 *db, std::string const &table_name, std::string const &column_name)
QTextStream & endl(QTextStream &s)
Event finding and building.
TH1F * fNNoisyChannelsHistoFromNSigma
geo::GeometryCore const * fGeom
TH1F * fNDeadChannelsHistoZ