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