LDMX Software
QIEAnalyzer.cxx
Go to the documentation of this file.
1
9
10namespace trigscint {
11
12QIEAnalyzer::QIEAnalyzer(const std::string& name, framework::Process& process)
13 : Analyzer(name, process) {}
14
15void QIEAnalyzer::configure(framework::config::Parameters& parameters) {
16 inputCol_ = parameters.getParameter<std::string>("inputCollection");
17 inputPassName_ = parameters.getParameter<std::string>("inputPassName");
18 peds_ = parameters.getParameter<std::vector<double> >("pedestals");
19 gain_ = parameters.getParameter<std::vector<double> >("gain");
20 startSample_ = parameters.getParameter<int>("startSample");
21
22 std::cout << " [ QIEAnalyzer ] In configure(), got parameters "
23 << "\n\t inputCollection = " << inputCol_
24 << "\n\t inputPassName = " << inputPassName_
25 << "\n\t startSample = " << startSample_
26 << "\n\t pedestals[0] = " << peds_[0]
27 << "\n\t gain[0] = " << gain_[0] << "\t." << std::endl;
28
29 return;
30}
31
32void QIEAnalyzer::analyze(const framework::Event& event) {
33 const auto channels{
34 event.getCollection<trigscint::EventReadout>(inputCol_, inputPassName_)};
35
36 int evNb = event.getEventNumber();
37 // while (evNb < 0 ) {
38 // ldmx_log(debug) << "event number = " << evNb << " < 0; incrementing event
39 // number "; evNb++;
40 //}
41 int nChan = channels.size();
42 ldmx_log(debug) << "in event " << evNb << "; nChannels = " << nChan;
43
44 for (auto chan : channels) {
45 std::vector<float> q = chan.getQ();
46 std::vector<float> qErr = chan.getQError();
47 std::vector<int> tdc = chan.getTDC();
48 // int nTimeSamp = q.size();
49 int bar = chan.getChanID();
50 float qTot = 0;
51 float qPedSubtractedAvg = 0;
52 int firstT = startSample_ - 1;
53 int nSampAbove = 0;
54 int nSampAboveEventPed = 0;
55 float subtrPE = 0;
56 float subtrQ = 0;
57 float ped = chan.getPedestal();
58 for (int iT = 0; iT < q.size(); iT++) {
59 ldmx_log(debug) << "in event " << evNb << "; channel " << bar
60 << ", got charge[" << iT << "] = " << q.at(iT);
61 if (evNb < nEv &&
62 bar < nChannels) { // stick within the predefined histogram array
63 // hOut[evNb][bar]->Fill(iT+startSample_, q.at(iT));
64 hOut[evNb][bar]->SetBinContent(iT + startSample_, q.at(iT));
65 hOut[evNb][bar]->SetBinError(iT + startSample_, fabs(qErr.at(iT)));
66 if (tdc.at(iT) < 63) {
67 ldmx_log(info) << "Found fired TDC = " << tdc.at(iT)
68 << " at time sample " << iT << " in channel " << bar
69 << " and event " << evNb;
70 // for some reason, the style settings are washed out later...
71 hOut[evNb][bar]->SetLineColor(kRed + 1);
72 hOut[evNb][bar]->SetMarkerColor(hOut[evNb][bar]->GetLineColor());
73 hOut[evNb][bar]->SetMarkerSize(0.2);
74
75 if (iT + startSample_ > 0)
76 hTDCfireChanvsEvent->Fill(bar, evNb, iT + startSample_);
77 else
78 hTDCfireChanvsEvent->Fill(bar, evNb);
79 }
80 } // if within the number of events to plot individually
81 if (q.at(iT) > 2 * fabs(peds_[bar])) { // integrate all charge well above
82 // ped to convert to a PE count
83 qTot += q.at(iT);
84 qPedSubtractedAvg += q.at(iT) - chan.getPedestal(); // peds_[ bar ];
85 nSampAbove++;
86 ldmx_log(debug) << " above channel overall pedestal: " << q.at(iT)
87 << " > " << 2 * fabs(peds_[bar]);
88
89 // keep track of first time sample above threshold
90 if (firstT == startSample_ - 1) firstT = startSample_ + iT;
91 } // if above threshold
92 if (q.at(iT) > ped) {
93 subtrQ += q.at(iT) - peds_[bar];
94 nSampAboveEventPed++;
95 ldmx_log(debug) << " above channel event pedestal: " << q.at(iT)
96 << " > " << ped;
97 } // if above channel event pedestal
98 } // over time samples
99 float PE = qTot * 6250. / gain_[bar];
100 subtrPE = subtrQ * 6250. / gain_[bar];
101 hTotQvsPed[bar]->Fill(ped, qTot);
102 hPE[bar]->Fill(PE);
103 hPEvsT[bar]->Fill(firstT, PE);
104 if (nSampAbove > 0) {
105 qPedSubtractedAvg /= nSampAbove;
106 hPedSubtractedAvgQvsT[bar]->Fill(firstT, qPedSubtractedAvg);
107 hAvgQvsT[bar]->Fill(firstT, qTot / nSampAbove);
108 }
109 // if (chan.getPedestal() < 40. ) {
110 // subtrQ = subtrPE/(6250./4.e6); //undo conversion
111 ldmx_log(debug) << "filling qTot histograms";
112 hPedSubtractedTotQvsPed[bar]->Fill(ped, subtrQ);
113 if (ped < 40) // avoid case where we have saturation and a plateau as much
114 // as possible
115 hPedSubtractedTotQvsN[bar]->Fill(nSampAboveEventPed, subtrQ);
116 hPedSubtractedPEvsN[bar]->Fill(nSampAboveEventPed, subtrPE);
117 hPedSubtractedPEvsT[bar]->Fill(firstT, subtrPE);
118 ldmx_log(debug) << " done filling qTot histograms";
119 // }
120 } // over channels
121
122 return;
123}
124
125void QIEAnalyzer::onProcessStart() {
126 std::cout << "\n\n Process starts! My analyzer should do something -- like "
127 "print this \n\n"
128 << std::endl;
129 getHistoDirectory();
130
131 int nTimeSamp = 40;
132 int PEmax = 100;
133 int nPEbins = 5 * PEmax;
134 float Qmax = PEmax / (6250. / 4.e6);
135 float Qmin = -10;
136 int nQbins = (Qmax - Qmin) / 4;
137
138 ldmx_log(debug) << "Setting up histograms... ";
139
140 for (int iB = 0; iB < nChannels; iB++) {
141 hPE[iB] = new TH1F(Form("hPE_chan%i", iB), Form(";PE, chan%i", iB), nPEbins,
142 0, PEmax);
143 hPEvsT[iB] = new TH2F(
144 Form("hPEvsT_chan%i", iB),
145 Form(";First time sample above summing threshold;PE, chan%i", iB),
146 nTimeSamp + 1, -1.5, nTimeSamp - 0.5, nPEbins, 0, PEmax);
147 hPedSubtractedAvgQvsT[iB] = new TH2F(
148 Form("hPedSubtrAvgQvsT_chan%i", iB),
149 Form(";First time sample above threshold;Pedestal subtracted average "
150 "Q, chan%i [fC]",
151 iB),
152 nTimeSamp + 1, -1.5, nTimeSamp - 0.5, nQbins / 10, Qmin, Qmax / 10.);
153 hPedSubtractedTotQvsPed[iB] =
154 new TH2F(Form("hPedSubtrTotQvsPed_chan%i", iB),
155 Form(";Channel event pedestal [fC];Event pedestal subtracted "
156 "total Q, chan%i [fC]",
157 iB),
158 1010, Qmin, 1000, 10010, -10,
159 10000); // nQbins/2,Qmin,Qmax/5., nQbins,Qmin,2*Qmax);
160 hPedSubtractedTotQvsN[iB] =
161 new TH2F(Form("hPedSubtrTotQvsN_chan%i", iB),
162 Form(";Number of time samples added; Event pedestal "
163 "subtracted total Q, chan%i [fC]",
164 iB),
165 nTimeSamp + 1, -1.5, nTimeSamp - 0.5, 10010, -10, 10000);
166 hTotQvsPed[iB] = new TH2F(
167 Form("hTotQvsPed_chan%i", iB),
168 Form(";Channel event pedestal [fC];Event total Q, chan%i [fC]", iB),
169 1010, Qmin, 1000, 10010, -10,
170 10000); // nQbins/2,Qmin,Qmax/5., nQbins,Qmin,2*Qmax);
171 hPedSubtractedPEvsN[iB] =
172 new TH2F(Form("hPedSubtrPEvsN_chan%i", iB),
173 Form(";Number of time samples above threshold;Pedestal "
174 "subtracted PE, chan%i [fC]",
175 iB),
176 nTimeSamp + 1, -1.5, nTimeSamp - 0.5, nPEbins, 0, PEmax);
177 hPedSubtractedPEvsT[iB] =
178 new TH2F(Form("hPedSubtrPEvsT_chan%i", iB),
179 Form(";First time sample above threshold;Pedestal subtracted "
180 "PE, chan%i [fC]",
181 iB),
182 nTimeSamp + 1, -1.5, nTimeSamp - 0.5, nPEbins, 0, PEmax);
183 hAvgQvsT[iB] = new TH2F(
184 Form("hAvgQvsT_chan%i", iB),
185 Form(";First time sample above threshold;Average Q, chan%i [fC]", iB),
186 nTimeSamp + 1, -1.5, nTimeSamp - 0.5, nQbins / 10, Qmin, Qmax / 10);
187 }
188
189 for (int iE = 0; iE < nEv; iE++) {
190 for (int iB = 0; iB < nChannels; iB++) {
191 hOut[iE][iB] =
192 new TH1F(Form("hCharge_chan%i_ev%i", iB, iE),
193 Form(";time sample; Q, channel %i, event %i [fC]", iB, iE),
194 nTimeSamp, -0.5, nTimeSamp - 0.5);
195 }
196 }
197
198 hTDCfireChanvsEvent =
199 new TH2F("hTDCfireChanvsEvent", ";channel with TDC < 63;event number",
200 nChannels, -0.5, nChannels - 0.5, nEv, 0, nEv);
201
202 ldmx_log(debug) << "done setting up histograms";
203
204 return;
205}
206
207void QIEAnalyzer::onProcessEnd() { return; }
208
209} // namespace trigscint
210
211DECLARE_ANALYZER_NS(trigscint, QIEAnalyzer)
#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).