LDMX Software
HcalPedestalAnalyzer.cxx
4#include "Hcal/HcalPedestalAnalyzer.h"
5
6namespace hcal {
7
9 auto const& digis{
10 event.getObject<ldmx::HgcrocDigiCollection>(input_name_, input_pass_)};
11
12 for (std::size_t i_digi{0}; i_digi < digis.size(); i_digi++) {
13 auto d{digis.getDigi(i_digi)};
14 ldmx::HcalDigiID detid(d.id());
15
16 Channel& chan = pedestal_data_[detid];
17
18 bool has_tot = false;
19 bool has_toa = false;
20 bool has_under = false;
21 bool has_over = false;
22
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).adc_t() < low_cutoff_) has_under = true;
27 if (d.at(i).adc_t() > high_cutoff_) has_over = true;
28 }
29
30 if (has_tot && filter_noTOT) chan.rejects[0]++;
31 if (has_toa && filter_noTOA) chan.rejects[1]++;
32 if (has_under) chan.rejects[2]++;
33 if (has_over) chan.rejects[3]++;
34
35 if (has_tot && filter_noTOT) continue; // ignore this
36 if (has_toa && filter_noTOA) continue; // ignore this
37 if (has_under)
38 continue; // ignore this, set threshold to zero to disable requirement
39 if (has_over)
40 continue; // ignore this, set threshold larger than 1024 to disable
41 // requirement
42
43 for (int i = 0; i < digis.getNumSamplesPerDigi(); i++) {
44 int adc = d.at(i).adc_t();
45
46 chan.sum += adc;
47 chan.sum_sq += adc * adc;
48 chan.entries++;
49 if (chan.hist)
50 chan.hist->Fill(adc);
51 else if (make_histos_)
52 chan.adcs.push_back(adc);
53 }
54
55 // histogram-related business
56 if (make_histos_ && !chan.hist && chan.entries > 250)
57 create_and_fill(chan, detid);
58 }
59}
60
61void HcalPedestalAnalyzer::create_and_fill(Channel& chan,
62 ldmx::HcalDigiID detid) {
63 if (chan.entries == 0) return;
64
65 TDirectory* hdir = getHistoDirectory();
66 hdir->cd();
67 char hname[120];
68 sprintf(hname, "pedestal_%d_%d_%d_%d", detid.section(), detid.layer(),
69 detid.strip(), detid.end());
70 // logic: 100 bins to +/- 5 sigma based on first 250 events.
71 double mean = (chan.sum * 1.0) / chan.entries;
72 double rms = sqrt(chan.sum_sq / chan.entries - mean * mean);
73 if (rms * 5 < 50)
74 chan.hist = new TH1D(hname, hname, 30, int(mean) - 15, int(mean) + 15);
75 else
76 chan.hist = new TH1D(hname, hname, 100, mean - 5 * rms, mean + 5 * rms);
77 for (auto x : chan.adcs) chan.hist->Fill(x);
78 chan.adcs.clear();
79}
80
82 FILE* fout = fopen(output_file_.c_str(), "w");
83
84 time_t t = time(NULL);
85 struct tm* gmtm = gmtime(&t);
86 char times[1024];
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");
91
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;
99 continue; // all entries were filtered out
100 }
101
102 double mean = ichan.second.sum * 1.0 / ichan.second.entries;
103 double rms = sqrt(ichan.second.sum_sq / ichan.second.entries - mean * mean);
104 fprintf(fout, "0x%08x,%9.3f,%9.3f\n", ichan.first.raw(), mean, rms);
105 }
106
107 fclose(fout);
108}
109
110} // namespace hcal
111
112DECLARE_ANALYZER_NS(hcal, HcalPedestalAnalyzer);
#define DECLARE_ANALYZER_NS(NS, 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.
Definition Event.h:41
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.
Definition HcalDigiID.h:13
int strip() const
Get the value of the 'strip' field from the ID.
Definition HcalDigiID.h:99
int section() const
Get the value of the 'section' field from the ID.
Definition HcalDigiID.h:75
int layer() const
Get the value of the layer field from the ID.
Definition HcalDigiID.h:81
int end() const
Get the value of the 'end' field from the ID.
Definition HcalDigiID.h:105
Represents a collection of the digi hits readout by an HGCROC.
const HgcrocDigi getDigi(unsigned int digiIndex) const
Get samples for the input digi index.
double sum_sq
Sum of values squared.
std::vector< int > rejects
counts of various rejections
std::vector< int > adcs
collection of hits accumulated to produce appropriately-binned histograms