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 | } |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | JEventProcessor_CDC_online::~JEventProcessor_CDC_online() { |
86 | } |
87 | |
88 | |
89 | |
90 | |
91 | jerror_t JEventProcessor_CDC_online::init(void) { |
92 | |
93 | |
94 | |
95 | |
96 | |
97 | japp->RootWriteLock(); |
98 | |
99 | |
100 | |
101 | TDirectory *main = gDirectory(TDirectory::CurrentDirectory()); |
102 | gDirectory(TDirectory::CurrentDirectory())->mkdir("CDC")->cd(); |
103 | |
104 | |
105 | cdc_num_events = new TH1I("cdc_num_events","CDC number of events",1, 0.5, 1.5); |
106 | |
107 | cdc_o = new TH2I("cdc_o","CDC occupancy by straw, ring;straw;ring",209,0.5,209.5,28,0.5,28.5); |
108 | |
109 | |
110 | gDirectory(TDirectory::CurrentDirectory())->mkdir("rings_occupancy","CDC rings: occupancy")->cd(); |
111 | |
112 | |
113 | |
114 | 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}; |
115 | 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}; |
116 | 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}; |
117 | |
118 | |
119 | for(int iring=0; iring<28; iring++){ |
120 | double r_start = radius[iring] - 0.8; |
121 | double r_end = radius[iring] + 0.8; |
122 | double phi_start = phi[iring]; |
123 | double phi_end = phi_start + TMath::TwoPi(); |
124 | |
125 | char hname[256]; |
126 | sprintf(hname, "cdc_occ_ring[%d]", iring+1); |
127 | cdc_occ_ring[iring+1] = new TH2D(hname, "", Nstraws[iring], phi_start, phi_end, 1, r_start, r_end); |
128 | } |
129 | |
130 | |
131 | |
132 | main->cd(); |
133 | |
134 | japp->RootUnLock(); |
135 | |
136 | return NOERROR; |
137 | } |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | jerror_t JEventProcessor_CDC_online::brun(JEventLoop *eventLoop, int32_t runnumber) { |
144 | |
145 | |
146 | japp->RootWriteLock(); |
147 | |
148 | |
149 | |
150 | |
151 | Int_t AMAX = 4096; |
152 | |
153 | |
154 | Int_t IMAX = 400000; |
155 | |
156 | Int_t PMAX = 512; |
157 | |
158 | Int_t RTMAX = 12000; |
159 | |
160 | Char_t rtunits[8] = "0.125ns"; |
161 | |
162 | |
163 | |
164 | if (runnumber > 3675) { |
165 | |
166 | |
167 | |
168 | |
169 | |
170 | |
171 | |
172 | |
173 | |
174 | |
175 | |
176 | |
177 | IMAX = 16384; |
178 | PMAX = 256; |
179 | RTMAX = 2048; |
180 | AMAX = 512; |
181 | |
182 | sprintf(rtunits,"0.8ns"); |
183 | |
184 | } |
185 | |
186 | |
187 | const Int_t NSTRAWS = 3522; |
188 | const Float_t HALF = 0.5; |
189 | const Float_t NSTRAWSPH = 3522.5; |
190 | |
191 | japp->RootWriteLock(); |
192 | |
193 | |
194 | |
195 | |
196 | |
197 | gDirectory(TDirectory::CurrentDirectory())->cd("CDC"); |
198 | |
199 | |
200 | |
201 | |
202 | |
203 | cdc_raw_amp = new TH1I("cdc_raw_amp","CDC amplitude (ADC units, scaled); ADC units",AMAX,0,AMAX); |
204 | 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); |
205 | |
206 | cdc_raw_t = new TH1I("cdc_raw_t",Form("CDC raw time (units of %s); raw time (%s)",rtunits,rtunits),200,0,RTMAX); |
207 | 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); |
208 | |
209 | |
210 | |
211 | cdc_raw_int = new TH1I("cdc_raw_int","CDC integral (ADC units, scaled), pedestal subtracted; ADC units",200,0,IMAX); |
212 | 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); |
213 | |
214 | |
215 | cdc_raw_intpp = new TH1I("cdc_raw_intpp","CDC integral (ADC units, scaled), includes pedestal; ADC units",200,0,IMAX); |
216 | 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); |
217 | |
218 | |
219 | cdc_ped = new TH1I("cdc_ped","CDC pedestal (ADC units);pedestal (ADC units)",(Int_t)(PMAX/2),0,PMAX); |
220 | 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); |
221 | |
222 | |
223 | |
224 | 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); |
225 | 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); |
226 | |
227 | |
228 | |
229 | |
230 | return NOERROR; |
231 | } |
232 | |
233 | |
234 | |
235 | |
236 | |
237 | jerror_t JEventProcessor_CDC_online::evnt(JEventLoop *eventLoop, uint64_t eventnumber) { |
238 | |
239 | |
240 | |
241 | |
242 | |
243 | |
244 | |
245 | uint32_t tr,p,a; |
246 | uint32_t integral; |
247 | uint32_t integ; |
248 | |
249 | uint16_t ring,straw; |
250 | uint16_t n; |
251 | |
252 | uint32_t total_ped; |
253 | |
254 | Bool_t PED_SUB; |
255 | |
256 | |
257 | uint32_t nsamples_integral=0; |
258 | uint32_t nsamples_pedestal=0; |
259 | |
260 | const uint16_t NPEDSAMPLES=16; |
261 | |
262 | |
263 | |
264 | |
265 | 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}; |
266 | |
267 | |
268 | vector<const DCDCDigiHit*> digihits; |
269 | eventLoop->Get(digihits); |
270 | |
271 | |
272 | vector<const Df125WindowRawData*> wrdvector; |
273 | eventLoop->Get(wrdvector); |
274 | |
275 | |
276 | |
277 | japp->RootWriteLock(); |
278 | |
279 | if(digihits.size() > 0) |
280 | cdc_num_events->Fill(1); |
281 | |
282 | for(uint32_t i=0; i<digihits.size(); i++) { |
283 | |
284 | const DCDCDigiHit *digihit = digihits[i]; |
285 | |
286 | |
287 | const Df125PulseIntegral *pi = NULL__null; |
288 | const Df125PulsePedestal *pp = NULL__null; |
289 | const Df125WindowRawData *windat = NULL__null; |
290 | const Df125CDCPulse *cp = NULL__null; |
291 | const Df125Config *cf = NULL__null; |
292 | |
293 | vector<uint16_t> samples; |
294 | uint32_t winped=0; |
295 | |
296 | |
297 | |
298 | PED_SUB = kFALSE; |
299 | total_ped = 0; |
| Value stored to 'total_ped' is never read |
300 | a = 0; |
301 | |
302 | |
303 | digihit->GetSingle(pi); |
304 | if (pi) { |
305 | pi->GetSingle(windat); |
306 | |
307 | nsamples_integral = pi ? pi->nsamples_integral : 0; |
308 | nsamples_pedestal = pi ? pi->nsamples_pedestal : 0; |
309 | |
310 | if ((nsamples_integral > 0) && (nsamples_pedestal > 0)) PED_SUB = kTRUE; |
311 | |
312 | } else if (i < (uint32_t)wrdvector.size()) { |
313 | windat = wrdvector[i]; |
314 | } |
315 | |
316 | |
317 | digihit->GetSingle(pp); |
318 | if (pp) a = pp->pulse_peak; |
319 | |
320 | |
321 | digihit->GetSingle(cp); |
322 | if (cp) a = cp->first_max_amp; |
323 | |
324 | |
325 | digihit->GetSingle(cf); |
326 | if (cf) nsamples_integral = cf->IE - (int)(0.1*digihit->pulse_time); |
327 | |
328 | |
329 | ring = digihit->ring; |
330 | straw = digihit->straw; |
331 | n = straw_offset[ring] + straw; |
332 | |
333 | if ((digihit->pulse_integral > 0)||(digihit->pulse_time > 0)) { |
334 | |
335 | p = digihit->pedestal; |
336 | tr = digihit->pulse_time; |
337 | integral = digihit->pulse_integral; |
338 | |
339 | |
340 | cdc_o->Fill(straw,ring); |
341 | |
342 | Double_t w = cdc_occ_ring[ring]->GetBinContent(straw, 1) + 1.0; |
343 | cdc_occ_ring[ring]->SetBinContent(straw, 1, w); |
344 | |
345 | |
346 | integ = 0; |
347 | |
348 | |
349 | |
350 | if (PED_SUB) { |
351 | total_ped = p*nsamples_integral/nsamples_pedestal; |
352 | integ = integral - total_ped; |
353 | } |
354 | |
355 | if (tr>0) { |
356 | cdc_raw_t->Fill(tr); |
357 | cdc_raw_t_vs_n->Fill(n,tr); |
358 | } |
359 | |
360 | |
361 | if (PED_SUB && (integ>0)) { |
362 | cdc_raw_int->Fill(integ); |
363 | cdc_raw_int_vs_n->Fill(n,integ); |
364 | } |
365 | |
366 | if (integral>0) { |
367 | cdc_raw_intpp->Fill(integral); |
368 | cdc_raw_intpp_vs_n->Fill(n,integral); |
369 | } |
370 | |
371 | if (p > 0) { |
372 | cdc_ped->Fill(p); |
373 | cdc_ped_vs_n->Fill(n,p); |
374 | } |
375 | |
376 | if (a > 0) { |
377 | |
378 | cdc_raw_amp->Fill(a); |
379 | cdc_raw_amp_vs_n->Fill(n,a); |
380 | } |
381 | |
382 | |
383 | } |
384 | |
385 | |
386 | |
387 | if (windat) { |
388 | |
389 | if (windat->samples.size()>=NPEDSAMPLES) { |
390 | |
391 | |
392 | |
393 | winped = 0; |
394 | |
395 | for (uint16_t i=0; i<NPEDSAMPLES; i++) winped += (uint32_t)windat->samples[i]; |
396 | |
397 | winped = (uint32_t)winped/16.0; |
398 | |
399 | if (winped > 0) { |
400 | cdc_windata_ped->Fill(winped); |
401 | cdc_windata_ped_vs_n->Fill(n,winped); |
402 | } |
403 | |
404 | } |
405 | } |
406 | |
407 | } |
408 | |
409 | japp->RootUnLock(); |
410 | |
411 | |
412 | |
413 | return NOERROR; |
414 | } |
415 | |
416 | |
417 | |
418 | |
419 | |
420 | jerror_t JEventProcessor_CDC_online::erun(void) { |
421 | |
422 | |
423 | |
424 | return NOERROR; |
425 | } |
426 | |
427 | |
428 | |
429 | |
430 | |
431 | jerror_t JEventProcessor_CDC_online::fini(void) { |
432 | |
433 | |
434 | |
435 | |
436 | return NOERROR; |
437 | } |
438 | |
439 | |
440 | |
441 | |