1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | #include <stdint.h> |
9 | #include <vector> |
10 | |
11 | #include <TMath.h> |
12 | |
13 | |
14 | #include "JEventProcessor_CDC_online.h" |
15 | #include <JANA/JApplication.h> |
16 | |
17 | |
18 | using namespace std; |
19 | using namespace jana; |
20 | |
21 | |
22 | #include "CDC/DCDCHit.h" |
23 | #include "CDC/DCDCDigiHit.h" |
24 | #include "DAQ/Df125PulseIntegral.h" |
25 | #include "DAQ/Df125PulsePedestal.h" |
26 | #include "DAQ/Df125WindowRawData.h" |
27 | #include "DAQ/Df125CDCPulse.h" |
28 | #include "DAQ/Df125Config.h" |
29 | |
30 | #include <TDirectory.h> |
31 | #include <TH2.h> |
32 | #include <TH1.h> |
33 | |
34 | |
35 | |
36 | |
37 | static TH1I *cdc_num_events = NULL__null; |
38 | |
39 | static TH2I *cdc_o = NULL__null; |
40 | static TH2D *cdc_occ_ring[29]; |
41 | |
42 | static TH1I *cdc_raw_amp = NULL__null; |
43 | static TH2I *cdc_raw_amp_vs_n = NULL__null; |
44 | |
45 | static TH1I *cdc_raw_t; |
46 | static TH2I *cdc_raw_t_vs_n; |
47 | |
48 | static TH1I *cdc_raw_intpp; |
49 | static TH2I *cdc_raw_intpp_vs_n; |
50 | |
51 | static TH1I *cdc_raw_int; |
52 | static TH2I *cdc_raw_int_vs_n; |
53 | |
54 | static TH1I *cdc_ped = NULL__null; |
55 | static TH2I *cdc_ped_vs_n = NULL__null; |
56 | |
57 | static TH1I *cdc_windata_ped = NULL__null; |
58 | static TH2I *cdc_windata_ped_vs_n = NULL__null; |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | extern "C"{ |
68 | void InitPlugin(JApplication *app){ |
69 | InitJANAPlugin(app); |
70 | app->AddProcessor(new JEventProcessor_CDC_online()); |
71 | } |
72 | } |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | JEventProcessor_CDC_online::JEventProcessor_CDC_online() { |
79 | initialized_histograms = false; |
80 | } |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | JEventProcessor_CDC_online::~JEventProcessor_CDC_online() { |
87 | } |
88 | |
89 | |
90 | |
91 | |
92 | jerror_t JEventProcessor_CDC_online::init(void) { |
93 | |
94 | |
95 | |
96 | |
97 | |
98 | |
99 | TDirectory *main = gDirectory(TDirectory::CurrentDirectory()); |
100 | gDirectory(TDirectory::CurrentDirectory())->mkdir("CDC")->cd(); |
101 | |
102 | |
103 | cdc_num_events = new TH1I("cdc_num_events","CDC number of events",1, 0.5, 1.5); |
104 | |
105 | cdc_o = new TH2I("cdc_o","CDC occupancy by straw, ring;straw;ring",209,0.5,209.5,28,0.5,28.5); |
106 | |
107 | |
108 | gDirectory(TDirectory::CurrentDirectory())->mkdir("rings_occupancy","CDC rings: occupancy")->cd(); |
109 | |
110 | |
111 | |
112 | int Nstraws[28] = {42, 42, 54, 54, 66, 66, 80, 80, 93, 93, 106, 106, 123, 123, 135, 135, 146, 146, 158, 158, 170, 170, 182, 182, 197, 197, 209, 209}; |
113 | double radius[28] = {10.72134, 12.08024, 13.7795, 15.14602, 18.71726, 20.2438, 22.01672, 23.50008, 25.15616, 26.61158, 28.33624, 29.77388, 31.3817, 32.75838, 34.43478, 35.81146, 38.28542, 39.7002, 41.31564, 42.73042, 44.34078, 45.75302, 47.36084, 48.77054, 50.37582, 51.76012, 53.36286, 54.74716}; |
114 | double phi[28] = {0, 0.074707844, 0.038166294, 0.096247609, 0.05966371, 0.012001551, 0.040721951, 0.001334527, 0.014963808, 0.048683644, 0.002092645, 0.031681749, 0.040719354, 0.015197341, 0.006786058, 0.030005892, 0.019704045, -0.001782064, -0.001306618, 0.018592421, 0.003686784, 0.022132975, 0.019600866, 0.002343723, 0.021301449, 0.005348855, 0.005997358, 0.021018761}; |
115 | |
116 | |
117 | for(int iring=0; iring<28; iring++){ |
118 | double r_start = radius[iring] - 0.8; |
119 | double r_end = radius[iring] + 0.8; |
120 | double phi_start = phi[iring]; |
121 | double phi_end = phi_start + TMath::TwoPi(); |
122 | |
123 | char hname[256]; |
124 | sprintf(hname, "cdc_occ_ring[%d]", iring+1); |
125 | cdc_occ_ring[iring+1] = new TH2D(hname, "", Nstraws[iring], phi_start, phi_end, 1, r_start, r_end); |
126 | } |
127 | |
128 | |
129 | |
130 | main->cd(); |
131 | |
132 | |
133 | return NOERROR; |
134 | } |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | jerror_t JEventProcessor_CDC_online::brun(JEventLoop *eventLoop, int32_t runnumber) { |
141 | |
142 | |
143 | |
144 | |
145 | |
146 | Int_t AMAX = 4096; |
147 | |
148 | |
149 | Int_t IMAX = 400000; |
150 | |
151 | Int_t PMAX = 512; |
152 | |
153 | Int_t RTMAX = 12000; |
154 | |
155 | Char_t rtunits[8] = "0.125ns"; |
156 | |
157 | |
158 | |
159 | if (runnumber > 3675) { |
160 | |
161 | |
162 | |
163 | |
164 | |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | IMAX = 16384; |
173 | PMAX = 256; |
174 | RTMAX = 2048; |
175 | AMAX = 512; |
176 | |
177 | sprintf(rtunits,"0.8ns"); |
178 | |
179 | } |
180 | |
181 | |
182 | const Int_t NSTRAWS = 3522; |
183 | const Float_t HALF = 0.5; |
184 | const Float_t NSTRAWSPH = 3522.5; |
185 | |
186 | japp->RootWriteLock(); |
187 | |
188 | if(initialized_histograms) |
189 | { |
190 | japp->RootUnLock(); |
191 | return NOERROR; |
192 | } |
193 | |
194 | gDirectory(TDirectory::CurrentDirectory())->cd("CDC"); |
195 | |
196 | |
197 | |
198 | cdc_raw_amp = new TH1I("cdc_raw_amp","CDC amplitude (ADC units, scaled); ADC units",AMAX,0,AMAX); |
199 | |
200 | cdc_raw_amp_vs_n = new TH2I("cdc_raw_amp_vs_n","CDC amplitude (ADC units, scaled) vs straw number;straw;ADC units",NSTRAWS,HALF,NSTRAWSPH,128,0,AMAX); |
201 | |
202 | cdc_raw_t = new TH1I("cdc_raw_t",Form("CDC raw time (units of %s); raw time (%s)",rtunits,rtunits),200,0,RTMAX); |
203 | |
204 | cdc_raw_t_vs_n = new TH2I("cdc_raw_t_vs_n",Form("CDC raw time (units of %s) vs straw number;straw;time (%s)",rtunits,rtunits),NSTRAWS,HALF,NSTRAWSPH,100,0,RTMAX); |
205 | |
206 | cdc_raw_int = new TH1I("cdc_raw_int","CDC integral (ADC units, scaled), pedestal subtracted; ADC units",200,0,IMAX); |
207 | |
208 | cdc_raw_int_vs_n = new TH2I("cdc_raw_int_vs_n","CDC integral (ADC units,scaled), pedestal subtracted, vs straw number;straw;ADC units",NSTRAWS,HALF,NSTRAWSPH,100,0,IMAX); |
209 | |
210 | cdc_raw_intpp = new TH1I("cdc_raw_intpp","CDC integral (ADC units, scaled), includes pedestal; ADC units",200,0,IMAX); |
211 | |
212 | cdc_raw_intpp_vs_n = new TH2I("cdc_raw_intpp_vs_n","CDC integral (ADC units, scaled), including pedestal, vs straw number;straw;ADC units",NSTRAWS,HALF,NSTRAWSPH,100,0,IMAX); |
213 | |
214 | cdc_ped = new TH1I("cdc_ped","CDC pedestal (ADC units);pedestal (ADC units)",(Int_t)(PMAX/2),0,PMAX); |
215 | |
216 | cdc_ped_vs_n = new TH2I("cdc_ped_vs_n","CDC pedestal (ADC units) vs straw number;straw;pedestal (ADC units)",NSTRAWS,HALF,NSTRAWSPH,(Int_t)(PMAX/4),0,PMAX); |
217 | |
218 | cdc_windata_ped = new TH1I("cdc_windata_ped","CDC pedestal (ADC units) from raw window data;pedestal (ADC units)",(Int_t)(PMAX/2),0,PMAX); |
219 | |
220 | cdc_windata_ped_vs_n = new TH2I("cdc_windata_ped_vs_n","CDC pedestal (ADC units) from raw window data vs straw number;straw;pedestal (ADC units)",NSTRAWS,HALF,NSTRAWSPH,(Int_t)(PMAX/4),0,PMAX); |
221 | |
222 | gDirectory(TDirectory::CurrentDirectory())->cd(".."); |
223 | |
224 | initialized_histograms = true; |
225 | |
226 | japp->RootUnLock(); |
227 | |
228 | |
229 | return NOERROR; |
230 | } |
231 | |
232 | |
233 | |
234 | |
235 | |
236 | jerror_t JEventProcessor_CDC_online::evnt(JEventLoop *eventLoop, uint64_t eventnumber) { |
237 | |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | uint32_t tr,p,a; |
245 | uint32_t integral; |
246 | uint32_t integ; |
247 | |
248 | uint16_t ring,straw; |
249 | uint16_t n; |
250 | |
251 | uint32_t total_ped; |
252 | |
253 | Bool_t PED_SUB; |
254 | |
255 | |
256 | uint32_t nsamples_integral=0; |
257 | uint32_t nsamples_pedestal=0; |
258 | |
259 | const uint16_t NPEDSAMPLES=16; |
260 | |
261 | |
262 | |
263 | |
264 | int straw_offset[29] = {0,0,42,84,138,192,258,324,404,484,577,670,776,882,1005,1128,1263,1398,1544,1690,1848,2006,2176,2346,2528,2710,2907,3104,3313}; |
265 | |
266 | |
267 | vector<const DCDCDigiHit*> digihits; |
268 | eventLoop->Get(digihits); |
269 | |
270 | |
271 | vector<const Df125WindowRawData*> wrdvector; |
272 | eventLoop->Get(wrdvector); |
273 | |
274 | |
275 | |
276 | |
277 | |
278 | japp->RootFillLock(this); |
279 | |
280 | if(digihits.size() > 0) |
281 | cdc_num_events->Fill(1); |
282 | |
283 | for(uint32_t i=0; i<digihits.size(); i++) { |
284 | |
285 | const DCDCDigiHit *digihit = digihits[i]; |
286 | |
287 | |
288 | const Df125PulseIntegral *pi = NULL__null; |
289 | const Df125PulsePedestal *pp = NULL__null; |
290 | const Df125WindowRawData *windat = NULL__null; |
291 | const Df125CDCPulse *cp = NULL__null; |
292 | const Df125Config *cf = NULL__null; |
293 | |
294 | vector<uint16_t> samples; |
295 | uint32_t winped=0; |
296 | |
297 | |
298 | |
299 | PED_SUB = kFALSE; |
300 | total_ped = 0; |
| Value stored to 'total_ped' is never read |
301 | a = 0; |
302 | |
303 | |
304 | digihit->GetSingle(pi); |
305 | if (pi) { |
306 | pi->GetSingle(windat); |
307 | |
308 | nsamples_integral = pi ? pi->nsamples_integral : 0; |
309 | nsamples_pedestal = pi ? pi->nsamples_pedestal : 0; |
310 | |
311 | if ((nsamples_integral > 0) && (nsamples_pedestal > 0)) PED_SUB = kTRUE; |
312 | |
313 | } else if (i < (uint32_t)wrdvector.size()) { |
314 | windat = wrdvector[i]; |
315 | } |
316 | |
317 | |
318 | digihit->GetSingle(pp); |
319 | if (pp) a = pp->pulse_peak; |
320 | |
321 | |
322 | digihit->GetSingle(cp); |
323 | if (cp) a = cp->first_max_amp; |
324 | |
325 | |
326 | digihit->GetSingle(cf); |
327 | if (cf) nsamples_integral = cf->IE - (int)(0.1*digihit->pulse_time); |
328 | |
329 | |
330 | ring = digihit->ring; |
331 | straw = digihit->straw; |
332 | n = straw_offset[ring] + straw; |
333 | |
334 | if ((digihit->pulse_integral > 0)||(digihit->pulse_time > 0)) { |
335 | |
336 | p = digihit->pedestal; |
337 | tr = digihit->pulse_time; |
338 | integral = digihit->pulse_integral; |
339 | |
340 | |
341 | cdc_o->Fill(straw,ring); |
342 | |
343 | Double_t w = cdc_occ_ring[ring]->GetBinContent(straw, 1) + 1.0; |
344 | cdc_occ_ring[ring]->SetBinContent(straw, 1, w); |
345 | |
346 | |
347 | integ = 0; |
348 | |
349 | |
350 | |
351 | if (PED_SUB) { |
352 | total_ped = p*nsamples_integral/nsamples_pedestal; |
353 | integ = integral - total_ped; |
354 | } |
355 | |
356 | if (tr>0) { |
357 | cdc_raw_t->Fill(tr); |
358 | cdc_raw_t_vs_n->Fill(n,tr); |
359 | } |
360 | |
361 | |
362 | if (PED_SUB && (integ>0)) { |
363 | cdc_raw_int->Fill(integ); |
364 | cdc_raw_int_vs_n->Fill(n,integ); |
365 | } |
366 | |
367 | if (integral>0) { |
368 | cdc_raw_intpp->Fill(integral); |
369 | cdc_raw_intpp_vs_n->Fill(n,integral); |
370 | } |
371 | |
372 | if (p > 0) { |
373 | cdc_ped->Fill(p); |
374 | cdc_ped_vs_n->Fill(n,p); |
375 | } |
376 | |
377 | if (a > 0) { |
378 | |
379 | cdc_raw_amp->Fill(a); |
380 | cdc_raw_amp_vs_n->Fill(n,a); |
381 | } |
382 | |
383 | |
384 | } |
385 | |
386 | |
387 | |
388 | if (windat) { |
389 | |
390 | if (windat->samples.size()>=NPEDSAMPLES) { |
391 | |
392 | |
393 | |
394 | winped = 0; |
395 | |
396 | for (uint16_t i=0; i<NPEDSAMPLES; i++) winped += (uint32_t)windat->samples[i]; |
397 | |
398 | winped = (uint32_t)winped/16.0; |
399 | |
400 | if (winped > 0) { |
401 | cdc_windata_ped->Fill(winped); |
402 | cdc_windata_ped_vs_n->Fill(n,winped); |
403 | } |
404 | |
405 | } |
406 | } |
407 | |
408 | } |
409 | |
410 | japp->RootFillUnLock(this); |
411 | |
412 | return NOERROR; |
413 | } |
414 | |
415 | |
416 | |
417 | |
418 | |
419 | jerror_t JEventProcessor_CDC_online::erun(void) { |
420 | |
421 | |
422 | |
423 | return NOERROR; |
424 | } |
425 | |
426 | |
427 | |
428 | |
429 | |
430 | jerror_t JEventProcessor_CDC_online::fini(void) { |
431 | |
432 | |
433 | |
434 | |
435 | return NOERROR; |
436 | } |
437 | |
438 | |
439 | |
440 | |