LDMX Software
QualityFlagAnalyzer.cxx
Go to the documentation of this file.
1
9
10namespace trigscint {
11
12QualityFlagAnalyzer::QualityFlagAnalyzer(const std::string& name,
13 framework::Process& process)
14 : Analyzer(name, process) {}
15
16void QualityFlagAnalyzer::configure(framework::config::Parameters& parameters) {
17 inputEventCol_ = parameters.getParameter<std::string>("inputEventCollection");
18 inputEventPassName_ =
19 parameters.getParameter<std::string>("inputEventPassName");
20 inputHitCol_ = parameters.getParameter<std::string>("inputHitCollection");
21 inputHitPassName_ = parameters.getParameter<std::string>("inputHitPassName");
22 peds_ = parameters.getParameter<std::vector<double> >("pedestals");
23 gain_ = parameters.getParameter<std::vector<double> >("gain");
24 startSample_ = parameters.getParameter<int>("startSample");
25
26 std::cout << " [ QualityFlagAnalyzer ] In configure(), got parameters "
27 << "\n\t inputEventCollection = " << inputEventCol_
28 << "\n\t inputEventPassName = " << inputEventPassName_
29 << "\n\t inputHitCollection = " << inputHitCol_
30 << "\n\t inputHitPassName = " << inputHitPassName_
31 << "\n\t startSample = " << startSample_
32 << "\n\t pedestals[0] = " << peds_[0]
33 << "\n\t gain[0] = " << gain_[0] << "\t." << std::endl;
34
35 return;
36}
37
38void QualityFlagAnalyzer::analyze(const framework::Event& event) {
39 const auto channels{event.getCollection<trigscint::EventReadout>(
40 inputEventCol_, inputEventPassName_)};
41 const auto hits{event.getCollection<trigscint::TestBeamHit>(
42 inputHitCol_, inputHitPassName_)};
43
44 int evNb = event.getEventNumber();
45 // while (evNb < 0 ) {
46 // ldmx_log(debug) << "event number = " << evNb << " < 0; incrementing event
47 // number "; evNb++;
48 //}
49 int nChan = channels.size();
50 ldmx_log(debug) << "in event " << evNb << "; nChannels = " << nChan;
51
52 bool existsIntermediatePE = false;
53 float hitPEs[nChannels] = {0.};
54
55 // ok. get each channel, and find the associated hit, using bar nb.
56
57 for (auto chan : channels) {
58 std::vector<float> q = chan.getQ();
59 std::vector<float> qErr = chan.getQError();
60 std::vector<int> tdc = chan.getTDC();
61 // int nTimeSamp = q.size();
62 int bar = chan.getChanID();
63
64 int flag = chan.getQualityFlag();
65
66 // check if this is messing up flag
67 for (auto hit : hits) { // we will be ok even if there is no match
68 if (hit.getBarID() == bar) { //
69 flag = hit.getQualityFlag();
70 hitPEs[bar] = hit.getPE();
71 if (flag == 0 && bar < 12 && 15 < hit.getPE() && hit.getPE() < 40)
72 existsIntermediatePE = true;
73 }
74 }
75
76 ldmx_log(debug) << "Got event flag " << flag;
77
78 // if flag = 0, fill for clean versions of the usual event displays
79 if (flag == 0 && evNb < nEv &&
80 bar < nChannels) { // stick within the predefined histogram array
81 for (int iT = 0; iT < q.size(); iT++) {
82 ldmx_log(debug) << "in event " << evNb << "; channel " << bar
83 << ", got charge[" << iT << "] = " << q.at(iT);
84 hOut[evNb][bar]->SetBinContent(iT + startSample_, q.at(iT));
85 hOut[evNb][bar]->SetBinError(iT + startSample_, fabs(qErr.at(iT)));
86 } // if within the number of events to plot individually
87 } // over time samples
88
89 // now select on flags
90 // special case: flag = 0 (this will happen to all eventually, so catch it
91 // now
92 if (flag == 0 && nEvDrawn[nFlags - 1] <
93 nEv) { // then draw if we haven't collected enough
94 int fillNb = nEvDrawn[nFlags - 1];
95 for (int iT = 0; iT < q.size(); iT++) { // fill this plot with all q
96 hOutFlag[nFlags - 1][fillNb][bar]->SetBinContent(iT + startSample_,
97 q.at(iT));
98 hOutFlag[nFlags - 1][fillNb][bar]->SetBinError(iT + startSample_,
99 fabs(qErr.at(iT)));
100 }
101 // keep track of actual event number
102 hOutFlag[nFlags - 1][fillNb][bar]->GetYaxis()->SetTitle(
103 Form("Q, flag 0, chan %i, ev %i [fC]", bar, evNb));
104 nEvDrawn[nFlags - 1]++; // update filled event counter for this flag (0)
105 } // if nothing was flagged
106 else { // hit was flagged somehow
107 for (int iF = 0; iF < nFlags - 1; iF++) { // do all but the last
108 int fillNb = nEvDrawn[iF];
109 ldmx_log(debug) << "Checking flag " << flags[iF];
110 // we're starting from the high numbers and iteratively subtracting
111 if (flag >= flags[iF]) {
112 ldmx_log(debug) << "Checking flag " << flags[iF];
113 if (fillNb < nEv) { // then 1. this flag must be raised 2. draw if we
114 // haven't collected enough
115 for (int iT = 0; iT < q.size(); iT++) { // fill this plot with all
116 // q
117 hOutFlag[iF][fillNb][bar]->SetBinContent(iT + startSample_,
118 q.at(iT));
119 hOutFlag[iF][fillNb][bar]->SetBinError(iT + startSample_,
120 fabs(qErr.at(iT)));
121 } // over time samples
122 hOutFlag[iF][fillNb][bar]->GetYaxis()->SetTitle(
123 Form("Q, flag %i, chan %i, ev %i [fC]", flags[iF], bar, evNb));
124 nEvDrawn[iF]++; // update filled event counter for this flag
125 }
126 flag -= flags[iF]; // subtract that flag from sum
127 } // if this flag
128 } // over flags
129 } // if any non-zero flag
130 } // over channels
131
132 // select 15 < PE < 40 events
133 if (existsIntermediatePE &&
134 peFillNb < nEv) { // then 1. this flag must be raised 2. draw if we
135 // haven't collected enough
136 ldmx_log(debug) << "Got at least one intermediate PE channel";
137 for (auto chan : channels) {
138 std::vector<float> q = chan.getQ();
139 std::vector<float> qErr = chan.getQError();
140 std::vector<int> tdc = chan.getTDC();
141 // int nTimeSamp = q.size();
142 int bar = chan.getChanID();
143 for (int iT = 0; iT < q.size(); iT++) { // fill this plot with all q
144 hOutPE[peFillNb][bar]->SetBinContent(iT + startSample_, q.at(iT));
145 hOutPE[peFillNb][bar]->SetBinError(iT + startSample_,
146 fabs(qErr.at(iT)));
147 } // over time samples
148 hOutPE[peFillNb][bar]->GetYaxis()->SetTitle(
149 Form("Q, chan %i, ev %i, PE %.2f", bar, evNb, hitPEs[bar]));
150 } // over channels
151 peFillNb++; // update filled event counter for this flag
152 } // if fill
153
154 return;
155}
156
157void QualityFlagAnalyzer::onProcessStart() {
158 std::cout << "\n\n Process starts! My analyzer should do something -- like "
159 "print this \n\n"
160 << std::endl;
161 getHistoDirectory();
162
163 int nTimeSamp = 40;
164 int PEmax = 100;
165 int nPEbins = 5 * PEmax;
166 // float Qmax = PEmax / (6250. / 4.e6);
167 // float Qmin = -10;
168 // int nQbins = (Qmax - Qmin) / 4;
169
170 ldmx_log(debug) << "Setting up histograms... ";
171
172 for (int iB = 0; iB < nChannels; iB++) {
173 hPE[iB] = new TH1F(Form("hPE_chan%i", iB), Form(";PE, chan%i", iB), nPEbins,
174 0, PEmax);
175 }
176
177 for (int iE = 0; iE < nEv; iE++) {
178 for (int iB = 0; iB < nChannels; iB++) {
179 hOut[iE][iB] =
180 new TH1F(Form("hCharge_chan%i_ev%i", iB, iE),
181 Form(";time sample; Q, channel %i, event %i [fC]", iB, iE),
182 nTimeSamp, -0.5, nTimeSamp - 0.5);
183 hOutPE[iE][iB] =
184 new TH1F(Form("hCharge_PEcut_chan%i_nb%i", iB, iE),
185 Form(";time sample; Q, channel %i, event %i [fC]", iB, iE),
186 nTimeSamp, -0.5, nTimeSamp - 0.5);
187 for (int iF = 0; iF < nFlags; iF++) {
188 hOutFlag[iF][iE][iB] = new TH1F(
189 Form("hCharge_flag%i_chan%i_nb%i", flags[iF], iB, iE),
190 Form(";time sample; Q, flag %i, chan %i, ev %i [fC]", iF, iB, iE),
191 nTimeSamp, -0.5,
192 nTimeSamp - 0.5); // less confusing to name them upon actual use
193 // hOutFlag[iF][iE][iB] = new TH1F("hCharge_flag", "",
194 // nTimeSamp,-0.5,nTimeSamp-0.5);
195 }
196 }
197 }
198
199 hTDCfireChanvsEvent =
200 new TH2F("hTDCfireChanvsEvent", ";channel with TDC < 63;event number",
201 nChannels, -0.5, nChannels - 0.5, nEv, 0, nEv);
202
203 peFillNb = 0;
204 ldmx_log(debug) << "done setting up histograms";
205
206 return;
207}
208
209void QualityFlagAnalyzer::onProcessEnd() { return; }
210
211} // namespace trigscint
212
213DECLARE_ANALYZER_NS(trigscint, QualityFlagAnalyzer)
#define DECLARE_ANALYZER_NS(NS, CLASS)
Macro which allows the framework to construct an analyzer given its name during configuration.
Implements an event buffer system for storing event data.
Definition Event.h:41
Class which represents the process under execution.
Definition Process.h:36
Class encapsulating parameters for configuring a processor.
Definition Parameters.h:27
T getParameter(const std::string &name) const
Retrieve the parameter of the given name.
Definition Parameters.h:89
This class represents the linearised QIE output from the trigger scintillator, in charge (fC).
This class represents the linearised QIE output from the trigger scintillator, in charge (fC).
Definition TestBeamHit.h:24