LDMX Software
HcalPedestalAnalyzer.cxx
4#include "Hcal/HcalPedestalAnalyzer.h"
5
6#include <cmath>
7
9
10namespace hcal {
11
13 auto const& digis{
14 event.getObject<ldmx::HgcrocDigiCollection>(input_name_, input_pass_)};
15
16 for (std::size_t i_digi{0}; i_digi < digis.size(); i_digi++) {
17 auto d{digis.getDigi(i_digi)};
18 ldmx::HcalDigiID detid(d.id());
19
20 Channel& chan = pedestal_data_[detid];
21
22 bool has_tot = false;
23 bool has_toa = false;
24 bool has_under = false;
25 bool has_over = false;
26
27 for (int i = 0; i < digis.getNumSamplesPerDigi(); i++) {
28 if (d.at(i).tot() > 0) has_tot = true;
29 if (d.at(i).toa() > 0) has_toa = true;
30 if (d.at(i).adcT() < low_cutoff_) has_under = true;
31 if (d.at(i).adcT() > high_cutoff_) has_over = true;
32 }
33
34 if (has_tot && filter_no_tot_) chan.rejects_[0]++;
35 if (has_toa && filter_no_toa_) chan.rejects_[1]++;
36 if (has_under) chan.rejects_[2]++;
37 if (has_over) chan.rejects_[3]++;
38
39 if (has_tot && filter_no_tot_) continue; // ignore this
40 if (has_toa && filter_no_toa_) continue; // ignore this
41 if (has_under)
42 continue; // ignore this, set threshold to zero to disable requirement
43 if (has_over)
44 continue; // ignore this, set threshold larger than 1024 to disable
45 // requirement
46
47 for (int i = 0; i < digis.getNumSamplesPerDigi(); i++) {
48 int adc = d.at(i).adcT();
49
50 chan.sum_ += adc;
51 chan.sum_sq_ += adc * adc;
52 chan.entries_++;
53 if (chan.hist_)
54 chan.hist_->Fill(adc);
55 else if (make_histos_)
56 chan.adcs_.push_back(adc);
57 }
58
59 // histogram-related business
60 if (make_histos_ && !chan.hist_ && chan.entries_ > 250)
61 createAndFill(chan, detid);
62 }
63}
64
65void HcalPedestalAnalyzer::createAndFill(Channel& chan,
66 ldmx::HcalDigiID detid) {
67 if (chan.entries_ == 0) return;
68
69 TDirectory* hdir = getHistoDirectory();
70 hdir->cd();
71 char hname[120];
72 sprintf(hname, "pedestal_%d_%d_%d_%d", detid.section(), detid.layer(),
73 detid.strip(), detid.end());
74 // logic: 100 bins to +/- 5 sigma based on first 250 events.
75 double mean = (chan.sum_ * 1.0) / chan.entries_;
76 double rms = sqrt(chan.sum_sq_ / chan.entries_ - mean * mean);
77 if (rms * 5 < 50)
78 chan.hist_ = new TH1D(hname, hname, 30, int(mean) - 15, int(mean) + 15);
79 else
80 chan.hist_ = new TH1D(hname, hname, 100, mean - 5 * rms, mean + 5 * rms);
81 for (auto x : chan.adcs_) chan.hist_->Fill(x);
82 chan.adcs_.clear();
83}
84
86 FILE* fout = fopen(output_file_.c_str(), "w");
87
88 time_t t = time(NULL);
89 struct tm* gmtm = gmtime(&t);
90 char times[1024];
91 strftime(times, sizeof(times), "%Y-%m-%d %H:%M:%S GMT", gmtm);
92 fprintf(fout, "# %s\n", comments_.c_str());
93 fprintf(fout, "# Produced %s\n", times);
94 fprintf(fout, "DetID,PEDESTAL_ADC,PEDESTAL_RMS_ADC\n");
95
96 for (auto ichan : pedestal_data_) {
97 if (ichan.second.entries_ == 0) {
98 std::cout << "All entries filtered for " << ichan.first << " for TOT "
99 << ichan.second.rejects_[0] << " for TOA "
100 << ichan.second.rejects_[1] << " for underthreshold "
101 << ichan.second.rejects_[2] << " for overthreshold "
102 << ichan.second.rejects_[3] << std::endl;
103 continue; // all entries were filtered out
104 }
105
106 double mean = ichan.second.sum_ * 1.0 / ichan.second.entries_;
107 double rms =
108 sqrt(ichan.second.sum_sq_ / ichan.second.entries_ - mean * mean);
109 fprintf(fout, "0x%08x,%9.3f,%9.3f\n", ichan.first.raw(), mean, rms);
110 }
111
112 fclose(fout);
113}
114
115} // namespace hcal
116
#define DECLARE_ANALYZER(CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Class that represents a digitized hit in a calorimeter cell readout by an HGCROC.
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:40
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.
double sum_sq_
Sum of values squared.
std::vector< int > adcs_
collection of hits accumulated to produce appropriately-binned histograms
std::vector< int > rejects_
counts of various rejections