4#include "Hcal/HcalPedestalAnalyzer.h"
12 for (std::size_t i_digi{0}; i_digi < digis.size(); i_digi++) {
13 auto d{digis.getDigi(i_digi)};
16 Channel& chan = pedestal_data_[detid];
20 bool has_under =
false;
21 bool has_over =
false;
23 for (
int i = 0; i < digis.getNumSamplesPerDigi(); i++) {
24 if (d.at(i).tot() > 0) has_tot =
true;
25 if (d.at(i).toa() > 0) has_toa =
true;
26 if (d.at(i).adcT() < low_cutoff_) has_under =
true;
27 if (d.at(i).adcT() > high_cutoff_) has_over =
true;
30 if (has_tot && filter_no_tot_) chan.
rejects_[0]++;
31 if (has_toa && filter_no_toa_) chan.
rejects_[1]++;
35 if (has_tot && filter_no_tot_)
continue;
36 if (has_toa && filter_no_toa_)
continue;
43 for (
int i = 0; i < digis.getNumSamplesPerDigi(); i++) {
44 int adc = d.at(i).adcT();
50 chan.
hist_->Fill(adc);
51 else if (make_histos_)
52 chan.
adcs_.push_back(adc);
57 createAndFill(chan, detid);
61void HcalPedestalAnalyzer::createAndFill(Channel& chan,
63 if (chan.entries_ == 0)
return;
68 sprintf(hname,
"pedestal_%d_%d_%d_%d", detid.
section(), detid.
layer(),
71 double mean = (chan.sum_ * 1.0) / chan.entries_;
72 double rms = sqrt(chan.sum_sq_ / chan.entries_ - mean * mean);
74 chan.hist_ =
new TH1D(hname, hname, 30,
int(mean) - 15,
int(mean) + 15);
76 chan.hist_ =
new TH1D(hname, hname, 100, mean - 5 * rms, mean + 5 * rms);
77 for (
auto x : chan.adcs_) chan.hist_->Fill(x);
82 FILE* fout = fopen(output_file_.c_str(),
"w");
84 time_t t = time(NULL);
85 struct tm* gmtm = gmtime(&t);
87 strftime(times,
sizeof(times),
"%Y-%m-%d %H:%M:%S GMT", gmtm);
88 fprintf(fout,
"# %s\n", comments_.c_str());
89 fprintf(fout,
"# Produced %s\n", times);
90 fprintf(fout,
"DetID,PEDESTAL_ADC,PEDESTAL_RMS_ADC\n");
92 for (
auto ichan : pedestal_data_) {
93 if (ichan.second.entries_ == 0) {
94 std::cout <<
"All entries filtered for " << ichan.first <<
" for TOT "
95 << ichan.second.rejects_[0] <<
" for TOA "
96 << ichan.second.rejects_[1] <<
" for underthreshold "
97 << ichan.second.rejects_[2] <<
" for overthreshold "
98 << ichan.second.rejects_[3] << std::endl;
102 double mean = ichan.second.sum_ * 1.0 / ichan.second.entries_;
104 sqrt(ichan.second.sum_sq_ / ichan.second.entries_ - mean * mean);
105 fprintf(fout,
"0x%08x,%9.3f,%9.3f\n", ichan.first.raw(), mean, rms);
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
TDirectory * getHistoDirectory()
Access/create a directory in the histogram file for this event processor to create histograms and ana...
Implements an event buffer system for storing event data.
void analyze(const framework::Event &event) override
Process the event and make histograms or summaries.
void onProcessEnd() override
Callback for the EventProcessor to take any necessary action when the processing of events finishes,...
Extension of HcalAbstractID providing access to HCal digi information.
int strip() const
Get the value of the 'strip' field from the ID.
int section() const
Get the value of the 'section' field from the ID.
int layer() const
Get the value of the layer field from the ID.
int end() const
Get the value of the 'end' field from the ID.
Represents a collection of the digi hits readout by an HGCROC.
double sum_sq_
Sum of values squared.
std::vector< int > adcs_
collection of hits accumulated to produce appropriately-binned histograms
TH1 * hist_
Histogram, if used.
std::vector< int > rejects_
counts of various rejections
int entries_
Number of entries.
uint64_t sum_
Sum of values.