1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | #include "JEventProcessor_ST_online_lowlevel.h" |
8 | #include "TRIGGER/DTrigger.h" |
9 | |
10 | |
11 | #include <JANA/JApplication.h> |
12 | #include <JANA/JFactory.h> |
13 | extern "C"{ |
14 | void InitPlugin(JApplication *app){ |
15 | InitJANAPlugin(app); |
16 | app->AddProcessor(new JEventProcessor_ST_online_lowlevel()); |
17 | } |
18 | } |
19 | |
20 | |
21 | |
22 | |
23 | JEventProcessor_ST_online_lowlevel::JEventProcessor_ST_online_lowlevel() |
24 | { |
25 | |
26 | } |
27 | |
28 | |
29 | |
30 | |
31 | JEventProcessor_ST_online_lowlevel::~JEventProcessor_ST_online_lowlevel() |
32 | { |
33 | |
34 | } |
35 | bool DSCHit_fadc_cmp(const DSCDigiHit *a, const DSCDigiHit *b) |
36 | { |
37 | if (a->sector == b->sector) return (a->pulse_time < b->pulse_time); |
38 | return (a->sector < b->sector); |
39 | } |
40 | |
41 | bool DSCHit_tdc_cmp(const DSCTDCDigiHit *a, const DSCTDCDigiHit *b) |
42 | { |
43 | if (a->sector == b->sector) return (a->time < b->time); |
44 | return (a->sector < b->sector); |
45 | } |
46 | |
47 | bool DSCHit_thit_cmp(const DSCHit *a, const DSCHit *b) |
48 | { |
49 | if (a->sector == b->sector) return (a->t < b->t); |
50 | return (a->sector < b->sector); |
51 | } |
52 | |
53 | |
54 | |
55 | jerror_t JEventProcessor_ST_online_lowlevel::init(void) |
56 | { |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | TDirectory *main = gDirectory(TDirectory::CurrentDirectory()); |
68 | gDirectory(TDirectory::CurrentDirectory())->mkdir("st_lowlevel")->cd(); |
69 | |
70 | st_num_events = new TH1I("st_num_events","ST Number of events",1, 0.5, 1.5); |
71 | |
72 | |
73 | |
74 | h1_adc_sec = new TH1I("h1_adc_sec", "ST fADC250 DigiHit Occupancy; Channel Number; fADC250 Counts", NCHANNELS, 0.5, NCHANNELS + 0.5); |
75 | h1_tdc_sec = new TH1I("h1_tdc_sec", "ST TDC DigiHit Occupancy; Channel Number; TDC Counts", NCHANNELS, 0.5, NCHANNELS + 0.5); |
76 | h1_hit_sec = new TH1I("h1_hit_sec", "ST Hit Occupancy; Channel Number; Hit Counts", NCHANNELS, 0.5, NCHANNELS + 0.5); |
77 | |
78 | |
79 | |
80 | h2_st_adc_tdc_multi = new TH2I("h2_st_adc_tdc_multi", "ST Total Multiplicity: TDC vs ADC; f1TDC Multiplicity; fADC250 Multiplicity", TDC_MULTI_BINS, TDC_MULTI_MIN + 0.5, TDC_MULTI_MAX + 0.5, ADC_MULTI_BINS, ADC_MULTI_MIN + 0.5, ADC_MULTI_MAX + 0.5); |
81 | h2_st_adc_hit_multi = new TH2I("h2_st_adc_hit_multi", "ST Total Multiplicity: HIT vs ADC; Hit Multiplicity; fADC250 Multiplicity", TDC_MULTI_BINS, TDC_MULTI_MIN + 0.5, TDC_MULTI_MAX + 0.5, ADC_MULTI_BINS, ADC_MULTI_MIN + 0.5, ADC_MULTI_MAX + 0.5); |
82 | |
83 | |
84 | |
85 | h2_raw_pi_sector = new TH2I("h2_raw_pi_sector", "ST fADC250 Pulse Integral; Channel Number; Pulse Integral(au)", NCHANNELS, 0.5, NCHANNELS + 0.5, PI_BINS, PI_MIN, PI_MAX); |
86 | h2_raw_ped_sector = new TH2I("h2_raw_ped_sector", "ST fADC250 Pulse Pedestal; Channel Number;Pulse Pedestal(au)", NCHANNELS, 0.5, NCHANNELS + 0.5, PED_BINS, PED_MIN, PED_MAX); |
87 | h2_raw_pt_sector = new TH2I("h2_raw_pt_sector", "ST fADC250 Pulse Time; Channel Number; Pulse Time(ns)", NCHANNELS, 0.5, NCHANNELS + 0.5, PT_BINS, PT_MIN, PT_MAX); |
88 | h2_tdcTime_sec = new TH2I("h2_tdcTime_sec", "ST TDC Sector vs Time (While ADC hit); Channel Number; TDC Time(ns)", NCHANNELS, 0.5, NCHANNELS + 0.5, TDC_DHIT_BINS, TDC_DHIT_MIN, TDC_DHIT_MAX); |
89 | |
90 | |
91 | |
92 | h2_adc_pp_sector = new TH2I("h2_adc_pp_sector","Pulse peak vs sector;Channel number; Pulse Peak (channels) ",NCHANNELS, 0.5, NCHANNELS + 0.5,300,0,3000); |
93 | h2_adc_pcpi_sector = new TH2I("h2_adc_pcpi_sector", "ST fADC250 Pedstal corrected Pulse Integral; Channel Number; fADC250 Pulse Integral (au)", NCHANNELS, 0.5, NCHANNELS + 0.5, PI_BINS, PI_MIN, PI_MAX); |
94 | h2_adc_pt_sector = new TH2I("h2_adc_pt_sector", "ST fADC250 Pulse Time; Channel Number; fADC250 Pulse Time (ns)", NCHANNELS, 0.5, NCHANNELS + 0.5, 320, -80., 80); |
95 | h2_adc_ped_sector = new TH2I("h2_adc_ped_sector", "ST fADC250 Pedestal; Channel Number; fADC250 Pedestal", NCHANNELS, 0.5, NCHANNELS + 0.5, 100, 1000., 7000.); |
96 | h2_st_time_vs_pcpi = new TH2I("h2_st_time_vs_pcpi","Ped Corrected Pulse Integral vs #delta (t_{TDC} - t_{ADC});Pulse Integral(cahnnels) ;#delta (t_{TDC} - t_{ADC}) (ns)",PI_BINS, PI_MIN, PI_MAX,32, -4., 4.); |
97 | h2_st_time_vs_pp = new TH2I("h2_st_time_vs_pp","Pulse Peak vs #delta (t_{TDC} - t_{ADC});Pulse Peak (cahnnels);#delta (t_{TDC} - t_{ADC}) (ns)",300,0,3000,32, -4., 4.); |
98 | |
99 | |
100 | |
101 | h2_raw_tdcTime_sec = new TH2I("h2_raw_tdcTime_sec", "ST TDC Sector vs Time; Channel Number; TDC Time(ns)", NCHANNELS, 0.5, NCHANNELS + 0.5, TDC_DHIT_BINS, TDC_DHIT_MIN, TDC_DHIT_MAX); |
102 | |
103 | |
104 | |
105 | h2_t_sec = new TH2I("h2_t_sec", "ST Hit Sector vs Time (walk corrected); Channel Number; TDC Time(ns)", NCHANNELS, 0.5, NCHANNELS + 0.5, T_HIT_BINS, T_HIT_MIN, T_HIT_MAX); |
106 | h2_tTDC_sec = new TH2I("h2_tTDC_sec", "ST Hit Sector vs Time(No walk corrected); Channel Number; TDC Time(ns)", NCHANNELS, 0.5, NCHANNELS + 0.5, T_HIT_BINS, T_HIT_MIN, T_HIT_MAX); |
107 | h2_tfADC_sec= new TH2I("h2_tfADC_sec", "ST Hit Sector vs ADC-Time; Channel Number; ADC Time(ns)", NCHANNELS, 0.5, NCHANNELS + 0.5, T_HIT_BINS, T_HIT_MIN, T_HIT_MAX); |
108 | h2_dE_sec = new TH2I("h2_dE_sec", "ST Hit Sector vs dE; Channel Number; dE(GeV)", NCHANNELS, 0.5, NCHANNELS + 0.5, 80, 0.0, 0.004); |
109 | |
110 | |
111 | |
112 | gDirectory(TDirectory::CurrentDirectory())->mkdir("waveforms")->cd(); |
113 | |
114 | |
115 | |
116 | for(unsigned int i = 0; i < NCHANNELS; i++) |
117 | { |
118 | h_amp_vs_sampl_chan[i] = new TH1I(Form("amp_vs_sampl_chan_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; fADC250 Sample Number; fADC250 Pulse Height (au)", i+1, 0+12*i, 12+12*i), 100, 0, 100); |
119 | h_amp_vs_sampl_chan150[i] = new TH1I(Form("amp_vs_sampl_chan150_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; fADC250 Sample Number; fADC250 Pulse Height (au)", i+1, 0+12*i, 12+12*i), 100, 0, 100); |
120 | |
121 | h_amp_vs_sampl_chan1000[i] = new TH1I(Form("amp_vs_sampl_chan1000_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; fADC250 Sample Number; fADC250 Pulse Height (au)", i+1, 0+12*i, 12+12*i), 100, 0, 100); |
122 | |
123 | h_amp_vs_sampl_chan2000[i] = new TH1I(Form("amp_vs_sampl_chan2000_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; fADC250 Sample Number; fADC250 Pulse Height (au)", i+1, 0+12*i, 12+12*i), 100, 0, 100); |
124 | |
125 | h_amp_vs_sampl_chan3000[i] = new TH1I(Form("amp_vs_sampl_chan3000_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; fADC250 Sample Number; fADC250 Pulse Height (au)", i+1, 0+12*i, 12+12*i), 100, 0, 100); |
126 | |
127 | h_amp_vs_sampl_chan4000[i] = new TH1I(Form("amp_vs_sampl_chan4000_%i", i+1), Form("Channel %i, #phi #in [%i^{#circ}, %i^{#circ}]; fADC250 Sample Number; fADC250 Pulse Height (au)", i+1, 0+12*i, 12+12*i), 100, 0, 100); |
128 | |
129 | bool_sec[i] = false; |
130 | bool_sec150[i] = false; |
131 | bool_sec1000[i] = false; |
132 | bool_sec2000[i] = false; |
133 | bool_sec3000[i] = false; |
134 | bool_sec4000[i] = false; |
135 | |
136 | } |
137 | |
138 | main->cd(); |
139 | |
140 | return NOERROR; |
141 | } |
142 | |
143 | |
144 | |
145 | |
146 | jerror_t JEventProcessor_ST_online_lowlevel::brun(JEventLoop *eventLoop, int32_t runnumber) |
147 | { |
148 | |
149 | map<string,double> scale_factors; |
150 | if (eventLoop->GetCalib("/START_COUNTER/digi_scales", scale_factors)) |
151 | jout << "Error loading /START_COUNTER/digi_scales !" << endl; |
152 | |
153 | if (scale_factors.find("SC_ADC_TSCALE") != scale_factors.end()) |
154 | t_scale = scale_factors["SC_ADC_TSCALE"]; |
155 | else |
156 | jerr << "Unable to get SC_ADC_TSCALE from /START_COUNTER/digi_scales !" |
157 | << endl; |
158 | |
159 | |
160 | map<string,double> base_time_offset; |
161 | |
162 | if (eventLoop->GetCalib("/START_COUNTER/base_time_offset",base_time_offset)) |
163 | jout << "Error loading /START_COUNTER/base_time_offset !" << endl; |
164 | if (base_time_offset.find("SC_BASE_TIME_OFFSET") != base_time_offset.end()) |
165 | t_base = base_time_offset["SC_BASE_TIME_OFFSET"]; |
166 | else |
167 | jerr << "Unable to get SC_BASE_TIME_OFFSET from /START_COUNTER/base_time_offset !" << endl; |
168 | |
169 | if (base_time_offset.find("SC_TDC_BASE_TIME_OFFSET") != base_time_offset.end()) |
170 | t_tdc_base = base_time_offset["SC_TDC_BASE_TIME_OFFSET"]; |
171 | else |
172 | jerr << "Unable to get SC_BASE_TIME_OFFSET from /START_COUNTER/base_time_offset !" << endl; |
173 | |
174 | |
175 | if (eventLoop->GetCalib("/START_COUNTER/pedestals", a_pedestals)) |
176 | jout << "Error loading /START_COUNTER/pedestals !" << endl; |
177 | |
178 | if (eventLoop->GetCalib("/START_COUNTER/adc_timing_offsets", adc_time_offsets)) |
179 | jout << "Error loading /START_COUNTER/adc_timing_offsets !" << endl; |
180 | |
181 | if (eventLoop->GetCalib("/START_COUNTER/tdc_timing_offsets", tdc_time_offsets)) jout << "Error loading /START_COUNTER/tdc_timing_offsets !" << endl; |
182 | |
183 | return NOERROR; |
184 | } |
185 | |
186 | |
187 | |
188 | |
189 | jerror_t JEventProcessor_ST_online_lowlevel::evnt(JEventLoop *loop, uint64_t eventnumber) |
190 | { |
191 | |
192 | vector<const DSCDigiHit*> dscdigihits; |
193 | vector<const DSCTDCDigiHit*> dsctdcdigihits; |
194 | vector<const DSCHit*> dschits; |
195 | const DTTabUtilities* TTabUtilities = NULL__null; |
196 | |
197 | const DTrigger* locTrigger = NULL__null; |
198 | loop->GetSingle(locTrigger); |
199 | if(locTrigger->Get_L1FrontPanelTriggerBits() != 0) |
200 | return NOERROR; |
201 | |
202 | loop->Get(dscdigihits); |
203 | loop->Get(dsctdcdigihits); |
204 | loop->Get(dschits); |
205 | loop->GetSingle(TTabUtilities); |
206 | uint32_t ADC_hits = dscdigihits.size(); |
207 | uint32_t TDC_hits = dsctdcdigihits.size(); |
208 | uint32_t Hits = dschits.size(); |
209 | |
210 | |
211 | |
212 | japp->RootFillLock(this); |
213 | |
214 | if( (dscdigihits.size()>0) || (dsctdcdigihits.size()>0) || (dschits.size()>0) ) |
215 | st_num_events->Fill(1); |
216 | |
217 | h2_st_adc_tdc_multi->Fill(TDC_hits, ADC_hits); |
218 | h2_st_adc_hit_multi->Fill(Hits, ADC_hits); |
219 | |
220 | |
221 | for(uint32_t i = 0; i < ADC_hits; i++) { |
222 | |
223 | |
224 | |
225 | |
226 | const Df250PulseIntegral *pulseintegral = nullptr; |
227 | const Df250WindowRawData *windowrawdata = nullptr; |
228 | |
229 | vector<uint16_t> samples; |
230 | |
231 | Int_t hit_sector_adc = dscdigihits[i]->sector; |
232 | Int_t hit_sector_adc_index = hit_sector_adc - 1; |
233 | |
234 | dscdigihits[i]->GetSingle(pulseintegral); |
235 | dscdigihits[i]->GetSingle(windowrawdata); |
236 | |
237 | if (pulseintegral != nullptr) { |
238 | pulseintegral->GetSingle(windowrawdata); |
239 | } |
240 | |
241 | if (windowrawdata != nullptr) { |
242 | adc_pp = dscdigihits[i]->pulse_peak; |
243 | if ((100 < adc_pp) && (adc_pp <= 150)) { |
244 | if (!bool_sec150[hit_sector_adc_index]) { |
245 | |
246 | bool_sec150[hit_sector_adc_index] = true; |
247 | if (bool_sec150[hit_sector_adc_index]) { |
248 | for (uint32_t j = 0; j < windowrawdata->samples.size(); j++) { |
249 | samples.push_back(windowrawdata->samples[j]); |
250 | h_amp_vs_sampl_chan150[hit_sector_adc_index]->Fill(j, samples[j]); |
251 | } |
252 | } |
253 | } |
254 | } |
255 | if ((150 < adc_pp) && (adc_pp <= 1000)) { |
256 | if (!bool_sec[hit_sector_adc_index]) { |
257 | bool_sec[hit_sector_adc_index] = true; |
258 | if (bool_sec[hit_sector_adc_index]) { |
259 | for (uint32_t j = 0; j < windowrawdata->samples.size(); j++) { |
260 | samples.push_back(windowrawdata->samples[j]); |
261 | h_amp_vs_sampl_chan[hit_sector_adc_index]->Fill(j, samples[j]); |
262 | } |
263 | } |
264 | } |
265 | } |
266 | if ( (1000 < adc_pp) && (adc_pp <= 2000)) { |
267 | if (!bool_sec1000[hit_sector_adc_index]) { |
268 | bool_sec1000[hit_sector_adc_index] = true; |
269 | if (bool_sec1000[hit_sector_adc_index]) { |
270 | for (uint32_t j = 0; j < windowrawdata->samples.size(); j++) { |
271 | samples.push_back(windowrawdata->samples[j]); |
272 | h_amp_vs_sampl_chan1000[hit_sector_adc_index]->Fill(j, samples[j]); |
273 | } |
274 | } |
275 | } |
276 | } |
277 | if ( (2000 < adc_pp) && (adc_pp <= 3000)) { |
278 | if (!bool_sec2000[hit_sector_adc_index]) { |
279 | bool_sec2000[hit_sector_adc_index] = true; |
280 | if (bool_sec2000[hit_sector_adc_index]) { |
281 | for (uint32_t j = 0; j < windowrawdata->samples.size(); j++) { |
282 | samples.push_back(windowrawdata->samples[j]); |
283 | h_amp_vs_sampl_chan2000[hit_sector_adc_index]->Fill(j, samples[j]); |
284 | } |
285 | } |
286 | } |
287 | } |
288 | if ( (3000 < adc_pp) && (adc_pp <= 4000)) { |
289 | if (!bool_sec3000[hit_sector_adc_index]) { |
290 | bool_sec3000[hit_sector_adc_index] = true; |
291 | if (bool_sec3000[hit_sector_adc_index]) { |
292 | for (uint32_t j = 0; j < windowrawdata->samples.size(); j++) { |
293 | samples.push_back(windowrawdata->samples[j]); |
294 | h_amp_vs_sampl_chan3000[hit_sector_adc_index]->Fill(j, samples[j]); |
295 | } |
296 | } |
297 | } |
298 | } |
299 | if ( (4000 < adc_pp)) { |
300 | if (!bool_sec4000[hit_sector_adc_index]) { |
301 | bool_sec4000[hit_sector_adc_index] = true; |
302 | if (bool_sec4000[hit_sector_adc_index]) { |
303 | for (uint32_t j = 0; j < windowrawdata->samples.size(); j++) { |
304 | samples.push_back(windowrawdata->samples[j]); |
305 | h_amp_vs_sampl_chan4000[hit_sector_adc_index]->Fill(j, samples[j]); |
306 | } |
307 | } |
308 | } |
309 | } |
310 | } |
311 | |
312 | |
313 | |
314 | int hit_channel = dscdigihits[i]->sector - 1; |
315 | int adc_sector = dscdigihits[i]->sector ; |
316 | uint32_t avg_pedestal = (dscdigihits[i]->nsamples_pedestal == 0 ) ? 0.0 : dscdigihits[i]->pedestal/dscdigihits[i]->nsamples_pedestal; |
317 | uint32_t pulse_time = dscdigihits[i]->pulse_time*ADC_PT_RES; |
318 | uint32_t pulse_integral= dscdigihits[i]->pulse_integral; |
319 | |
320 | h1_adc_sec->Fill(adc_sector); |
321 | |
322 | h2_raw_pi_sector->Fill(adc_sector,pulse_integral); |
323 | h2_raw_ped_sector->Fill(adc_sector,avg_pedestal); |
324 | h2_raw_pt_sector->Fill(adc_sector,pulse_time); |
325 | |
326 | |
327 | |
328 | |
329 | |
330 | |
331 | double pedestal = a_pedestals[hit_channel]; |
| Value stored to 'pedestal' during its initialization is never read |
332 | double single_sample_ped = (double)dscdigihits[i]->pedestal; |
333 | double nsamples_integral = (double)dscdigihits[i]->nsamples_integral; |
334 | double nsamples_pedestal = (double)dscdigihits[i]->nsamples_pedestal; |
335 | pedestal = single_sample_ped * nsamples_integral/nsamples_pedestal; |
336 | |
337 | |
338 | adc_ped = pedestal; |
339 | adc_pi = dscdigihits[i]->pulse_integral; |
340 | adc_pcpi = adc_pi - adc_ped; |
341 | adc_pp = dscdigihits[i]->pulse_peak; |
342 | adc_t = dscdigihits[i]->pulse_time * t_scale - adc_time_offsets[hit_channel] + t_base; |
343 | |
344 | h2_adc_pp_sector->Fill(adc_sector,adc_pp); |
345 | h2_adc_pcpi_sector->Fill(adc_sector,adc_pcpi); |
346 | h2_adc_pt_sector->Fill(adc_sector,adc_t); |
347 | h2_adc_ped_sector->Fill(adc_sector,adc_ped); |
348 | |
349 | |
350 | |
351 | for(uint32_t i = 0; i < TDC_hits; i++) { |
352 | |
353 | const DSCTDCDigiHit *tdc_dhit = dsctdcdigihits[i]; |
354 | float tdc_dhit_time = TTabUtilities->Convert_DigiTimeToNs_F1TDC(tdc_dhit); |
355 | int tdc_sector = tdc_dhit->sector; |
356 | if (adc_sector == tdc_sector) { |
357 | h2_tdcTime_sec->Fill(tdc_sector,tdc_dhit_time); |
358 | tdc_t = TTabUtilities->Convert_DigiTimeToNs_F1TDC(tdc_dhit) - tdc_time_offsets[tdc_sector] + t_tdc_base; |
359 | st_time = tdc_t - adc_t; |
360 | h2_st_time_vs_pcpi->Fill(adc_pcpi,st_time); |
361 | h2_st_time_vs_pp->Fill(adc_pp,st_time); |
362 | } |
363 | } |
364 | } |
365 | |
366 | |
367 | |
368 | for(uint32_t i = 0; i < TDC_hits; i++) |
369 | { |
370 | const DSCTDCDigiHit *tdc_dhit = dsctdcdigihits[i]; |
371 | float tdc_dhit_time = TTabUtilities->Convert_DigiTimeToNs_F1TDC(tdc_dhit); |
372 | int tdc_sec = tdc_dhit->sector; |
373 | |
374 | h1_tdc_sec->Fill(tdc_sec); |
375 | |
376 | h2_raw_tdcTime_sec->Fill(tdc_sec,tdc_dhit_time); |
377 | |
378 | } |
379 | |
380 | |
381 | |
382 | for(uint32_t i = 0; i < dschits.size(); i++) |
383 | { |
384 | const DSCHit *hit = dschits[i]; |
385 | int hit_sector = hit->sector; |
386 | float dE = hit->dE; |
387 | float t = hit->t; |
388 | float t_TDC = hit->t_TDC; |
389 | float t_fADC = hit->t_fADC; |
390 | |
391 | h1_hit_sec->Fill(hit_sector); |
392 | |
393 | h2_t_sec->Fill(hit_sector,t); |
394 | h2_tTDC_sec->Fill(hit_sector,t_TDC); |
395 | h2_tfADC_sec->Fill(hit_sector,t_fADC); |
396 | h2_dE_sec->Fill(hit_sector,dE); |
397 | |
398 | } |
399 | |
400 | japp->RootFillUnLock(this); |
401 | |
402 | return NOERROR; |
403 | } |
404 | |
405 | |
406 | |
407 | |
408 | jerror_t JEventProcessor_ST_online_lowlevel::erun(void) |
409 | { |
410 | |
411 | |
412 | |
413 | return NOERROR; |
414 | } |
415 | |
416 | |
417 | |
418 | |
419 | jerror_t JEventProcessor_ST_online_lowlevel::fini(void) |
420 | { |
421 | |
422 | return NOERROR; |
423 | } |