Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_L1_online.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_L1_online.cc
4 // Created: Fri Mar 20 16:32:04 EDT 2015
5 //
6 #include <iostream>
7 #include <sstream>
9 
10 using namespace std;
11 using namespace jana;
12 
13 #include <JANA/JApplication.h>
14 #include <JANA/JFactory.h>
15 #include <TDirectory.h>
16 #include <TH1.h>
17 #include <TH2.h>
18 #include <TProfile.h>
19 
20 #include <TRIGGER/DL1Trigger.h>
21 
22 #include <DAQ/Df250WindowRawData.h>
23 #include <DAQ/Df250PulseIntegral.h>
24 #include <DAQ/Df250PulsePedestal.h>
25 
26 #include <FCAL/DFCALDigiHit.h>
27 #include <BCAL/DBCALDigiHit.h>
28 
29 #include "START_COUNTER/DSCHit.h"
30 
31 #include <TAGGER/DTAGHDigiHit.h>
32 
33 
34 // root hist pointers
35 static TH1I *htrig_bit;
36 static TH1I *htrig_bit_fp;
37 
38 static TH1I *htrig_type;
39 
40 static TH1F *hrate_gtp[8];
41 // static TH1F *hrate_fp[16];
42 
43 static TH1I *hfcal_time1;
44 static TH1I *hfcal_time6;
45 static TH1I *hfcal_time7;
46 
47 static TH1I *hbcal_time1;
48 static TH1I *hbcal_time3;
49 static TH1I *hbcal_time6;
50 
51 static TH1I *htagh_time2;
52 static TH1I *htagh_occup2;
53 
54 static TH1I *hfcal_en1;
55 static TH1I *hfcal_en6;
56 static TH1I *hfcal_en7;
57 
58 static TH1I *hfcal_en2;
59 
60 static TH1I *hbcal_en1;
61 static TH1I *hbcal_en3;
62 static TH1I *hbcal_en6;
63 
64 static TH2I *hfcal_bcal_en1;
65 static TH2I *hfcal_bcal_en6;
66 
67 static TH2I *hfcal_bcal_en1_3;
68 
69 static TH2I *hfcal_bcal_type1;
70 static TH2I *hfcal_bcal_type3;
71 static TH2I *hfcal_bcal_type5;
72 static TH2I *hfcal_bcal_type7;
73 
74 static TH1I *hst_hit2;
75 static TH1I *hst_hit7;
76 
77 static TProfile *hrate_bit[8];
78 
79 
80 // static TH2F *hfcal_row_col;
81 
82 //-------------------------
83 // Routine used to create our JEventProcessor
84 extern "C"{
85  void InitPlugin(JApplication *app){
86  InitJANAPlugin(app);
87  app->AddProcessor(new JEventProcessor_L1_online());
88 
89  }
90 } // "C"
91 
92 
93 //------------------
94 // JEventProcessor_L1_online (Constructor)
95 //------------------
97 {
98 
99 }
100 
101 //------------------
102 // ~JEventProcessor_L1_online (Destructor)
103 //------------------
105 {
106 
107 }
108 
109 //------------------
110 // init
111 //------------------
113 {
114 
115  const int bin_time = 100;
116  const int bin_fcal_1d = 500;
117  const int bin_fcal = 200;
118  const int bin_bcal = 200;
119 
120 
121  // create root folder for pspair and cd to it, store main dir
122  TDirectory *mainDir = gDirectory;
123  TDirectory *L1Dir = gDirectory->mkdir("L1");
124  L1Dir->cd();
125 
126  // book hists
127  htrig_bit = new TH1I("trig_bit","trig_bit", 32, 0.5, 32.5);
128  htrig_bit_fp = new TH1I("trig_bit_fp","trig_bit_fp", 32, 0.5, 32.5);
129 
130  htrig_type = new TH1I("trig_type","trig_type", 257, -0.5, 256.5);
131 
132  for(Int_t ii = 0; ii < 8; ii++){
133 
134  // char title[30];
135  // sprintf(title,"live_gtp_%d",ii);
136  // hlive_gtp[ii] = new TH1F(title,title,100,0.,100);
137 
138  char title[30];
139  sprintf(title,"rate_gtp_%d",ii);
140  hrate_gtp[ii] = new TH1F(title,title,1000,0.,100.);
141 
142  // char title1[30];
143  // sprintf(title1,"rate_fp_%d",ii);
144  // hrate_fp[ii] = new TH1F(title1,title1,800,0.,400);
145 
146 
147  char title2[30];
148  sprintf(title2,"rate_time_%d",ii);
149  hrate_bit[ii] = new TProfile(title2,title2, 502 ,-0.5,501.5,"s");
150 
151  }
152 
153 
154 
155  hfcal_time1 = new TH1I("fcal_time1","fcal_time1", bin_time, -0.5, 99.5);
156  hfcal_time6 = new TH1I("fcal_time6","fcal_time6", bin_time, -0.5, 99.5);
157  hfcal_time7 = new TH1I("fcal_time7","fcal_time7", bin_time, -0.5, 99.5);
158 
159  hbcal_time1 = new TH1I("bcal_time1","bcal_time1", bin_time, -0.5, 99.5);
160  hbcal_time3 = new TH1I("bcal_time3","bcal_time3", bin_time, -0.5, 99.5);
161  hbcal_time6 = new TH1I("bcal_time6","bcal_time6", bin_time, -0.5, 99.5);
162 
163  htagh_time2 = new TH1I("tagh_time2","tagh_time2", bin_time, -0.5, 99.5);
164 
165  htagh_occup2 = new TH1I("tagh_occup2","tagh_occup2", 250, -0.5, 249.5);
166 
167  hfcal_en1 = new TH1I("fcal_en1", "fcal_en1", bin_fcal_1d, 0., 20000.);
168  hfcal_en2 = new TH1I("fcal_en2", "fcal_en2", bin_fcal_1d, 0., 20000.);
169 
170  hfcal_en6 = new TH1I("fcal_en6", "fcal_en6", bin_fcal_1d, 0., 20000.);
171  hfcal_en7 = new TH1I("fcal_en7", "fcal_en7", bin_fcal_1d, 0., 20000.);
172 
173  hbcal_en1 = new TH1I("bcal_en1", "bcal_en1", bin_bcal, 0., 50000.);
174  hbcal_en3 = new TH1I("bcal_en3", "bcal_en3", bin_bcal, 0., 50000.);
175  hbcal_en6 = new TH1I("bcal_en6", "bcal_en6", bin_bcal, 0., 50000.);
176 
177  hfcal_bcal_en1 = new TH2I("fcal_bcal_en1","fcal_bcal_en1", bin_fcal, 0., 10000, bin_bcal, 0., 50000);
178  hfcal_bcal_en6 = new TH2I("fcal_bcal_en6","fcal_bcal_en6", bin_fcal, 0., 10000, bin_bcal, 0., 50000);
179 
180  hfcal_bcal_en1_3 = new TH2I("fcal_bcal_en_type1_3","fcal_bcal_en1_3", 100, 0., 10000, 200, 0., 50000);
181 
182  hfcal_bcal_type1 = new TH2I("fcal_bcal_type1","fcal_bcal_type1", bin_fcal, 0., 10000, bin_bcal, 0., 50000);
183  hfcal_bcal_type3 = new TH2I("fcal_bcal_type3","fcal_bcal_type3", bin_fcal, 0., 10000, bin_bcal, 0., 50000);
184  hfcal_bcal_type5 = new TH2I("fcal_bcal_type5","fcal_bcal_type5", bin_fcal, 0., 10000, bin_bcal, 0., 50000);
185  hfcal_bcal_type7 = new TH2I("fcal_bcal_type7","fcal_bcal_type7", bin_fcal, 0., 10000, bin_bcal, 0., 50000);
186 
187  hst_hit7 = new TH1I("st_hit7", "st_hit7", 100, -0.5, 99.5);
188  hst_hit2 = new TH1I("st_hit2", "st_hit2", 100, -0.5, 99.5);
189 
190  // hfcal_row_col = new TH2F("fcal_row_col","fcal_row_col", 60, 0.5, 60.5, 60, 0.5, 60.5);
191 
192  mainDir->cd();
193 
194  return NOERROR;
195 }
196 
197 //------------------
198 // brun
199 //------------------
200 jerror_t JEventProcessor_L1_online::brun(JEventLoop *eventLoop, int32_t runnumber)
201 {
202 
203 
204  // FCAL constants - will be retrieved from the RCDB
205 
206  fcal_cell_thr = 64;
207  bcal_cell_thr = 20;
208 
209  fcal_row_mask_min = 26;
210  fcal_row_mask_max = 32;
211  fcal_col_mask_min = 26;
212  fcal_col_mask_max = 32;
213 
214 
215  if( runnumber < 11127 ){
216  fcal_row_mask_min = 24;
217  fcal_row_mask_max = 34;
218  fcal_col_mask_min = 24;
219  fcal_col_mask_max = 34;
220  }
221 
222  run_number = runnumber;
223 
224  return NOERROR;
225 }
226 
227 //------------------
228 // evnt
229 //------------------
230 jerror_t JEventProcessor_L1_online::evnt(JEventLoop *loop, uint64_t eventnumber) {
231  // This is called for every event. Use of common resources like writing
232  // to a file or filling a histogram should be mutex protected. Using
233  // loop->Get(...) to get reconstructed objects (and thereby activating the
234  // reconstruction algorithm) should be done outside of any mutex lock
235  // since multiple threads may call this method at the same time.
236 
237  unsigned int trig_bit[33], trig_bit_fp[33];
238 
239  uint32_t fcal_adc_time[33], bcal_adc_time[33];
240 
241 
242  memset(trig_bit,0,sizeof(trig_bit));
243  memset(trig_bit_fp,0,sizeof(trig_bit_fp));
244 
245  memset(fcal_adc_time,0,sizeof(fcal_adc_time));
246  memset(bcal_adc_time,0,sizeof(bcal_adc_time));
247 
248 
249  vector<uint16_t> fcal_adc_time1;
250  vector<uint16_t> fcal_adc_time6;
251  vector<uint16_t> fcal_adc_time7;
252 
253  vector<uint16_t> bcal_adc_time1;
254  vector<uint16_t> bcal_adc_time3;
255  vector<uint16_t> bcal_adc_time6;
256 
257  vector<uint16_t> tagh_adc_time2;
258  vector<int> tagh_counter2;
259 
260 
261  vector<const DL1Trigger*> l1trig;
262 
263  vector<const DBCALDigiHit*> bcal_hits;
264  vector<const DFCALDigiHit*> fcal_hits;
265 
266  vector<const DSCHit*> st_hits;
267 
268  vector<const DTAGHDigiHit*> tagh_hits;
269 
270 
271  loop->Get(l1trig);
272  loop->Get(bcal_hits);
273  loop->Get(fcal_hits);
274 
275  loop->Get(st_hits);
276 
277  loop->Get(tagh_hits);
278 
279 
280 
281  if( l1trig.size() > 0 ){
282  for(unsigned int bit = 0; bit < 32; bit++){
283  trig_bit[bit + 1] = (l1trig[0]->trig_mask & (1 << bit)) ? 1 : 0;
284  }
285 
286  for(unsigned int bit = 0; bit < 32; bit++){
287  trig_bit_fp[bit + 1] = (l1trig[0]->fp_trig_mask & (1 << bit)) ? 1 : 0;
288  }
289  }
290 
291 
292  //------------------- FCAL ----------------------------
293 
294  int fcal_debug = 0;
295  int fcal_tot_en = 0;
296 
297 
298  if(fcal_debug){
299  cout << " Number of FCAL hits = " << fcal_hits.size() << endl;
300  }
301 
302 
303  for(unsigned int jj = 0; jj < fcal_hits.size(); jj++){
304 
305  const DFCALDigiHit *fcal_hit = fcal_hits[jj];
306 
307  uint32_t adc_time = 0;
308  Int_t pulse_int = -10;
309  Int_t pulse_peak = -10;
310 
311 
312  adc_time = (fcal_hit->pulse_time & 0x7FC0) >> 6;
313 
314  pulse_int = fcal_hit->pulse_integral - fcal_hit->nsamples_integral*100;
315 
316  pulse_peak = fcal_hit->pulse_peak - 100;
317 
318  if(fcal_debug){
319  cout << " Pulse peak = " << pulse_peak << endl;
320  cout << " Pulse integral = " << pulse_int << endl;
321  cout << " Pulse time = " << adc_time << endl;
322  }
323 
324  int fcal_cell_used = 1;
325 
326  int row = fcal_hit->row;
327  int col = fcal_hit->column;
328 
329 
330  if( (row >= fcal_row_mask_min && row <= fcal_row_mask_max)
331  && (col >= fcal_col_mask_min && col <= fcal_col_mask_max)) fcal_cell_used = 0;
332 
333  // if(trig_bit[7] == 1)
334  // hfcal_row_col->Fill(Float_t(fcal_hit->row),Float_t(fcal_hit->column));
335 
336 
337  if(fcal_cell_used == 0) continue;
338 
339 
340  if(pulse_peak > fcal_cell_thr){
341 
342  if( (adc_time > 20) && (adc_time < 70)){
343  if(pulse_int < 0) pulse_int = 0;
344  fcal_tot_en += pulse_int;
345  }
346 
347  if(trig_bit[1] == 1) fcal_adc_time1.push_back(adc_time);
348  if(trig_bit[6] == 1) fcal_adc_time6.push_back(adc_time);
349  if(trig_bit[7] == 1) fcal_adc_time7.push_back(adc_time);
350 
351  }
352 
353  } // Loop over FCAL hits
354 
355 
356 
357  //------------------- BCAL ----------------------------
358 
359  int bcal_debug = 0;
360  int bcal_tot_en = 0;
361 
362  if(bcal_debug){
363  cout << " Number of BCAL hits = " << bcal_hits.size() << endl;
364  }
365 
366 
367  for(unsigned int jj = 0; jj < bcal_hits.size(); jj++){
368 
369  const DBCALDigiHit *bcal_hit = bcal_hits[jj];
370 
371  uint32_t adc_time = 0;
372  Int_t pulse_int = -10;
373  Int_t pulse_peak = -10;
374 
375  adc_time = (bcal_hit->pulse_time & 0x7FC0) >> 6;
376 
377  pulse_int = bcal_hit->pulse_integral - bcal_hit->nsamples_integral*100;
378 
379 
380  pulse_peak = bcal_hit->pulse_peak - 100;
381 
382  if(bcal_debug){
383  cout << " Pulse peak = " << pulse_peak << endl;
384  cout << " Pulse integral = " << pulse_int << endl;
385  cout << " Pulse time = " << adc_time << endl;
386  }
387 
388  if(pulse_peak > bcal_cell_thr){
389 
390  if(trig_bit[1] == 1) bcal_adc_time1.push_back(adc_time);
391  if(trig_bit[3] == 1) bcal_adc_time3.push_back(adc_time);
392  if(trig_bit[6] == 1) bcal_adc_time6.push_back(adc_time);
393 
394  bcal_tot_en += pulse_int;
395  }
396  } // Loop over BCAL hits
397 
398 
399 
400  //------------------- TAGH & ST ----------------------------
401 
402  for(unsigned int kk = 0; kk < tagh_hits.size(); kk++){
403  const DTAGHDigiHit *tagh_hit = tagh_hits[kk];
404  //const Df250PulseIntegral *pulseintegral;
405 
406  //tagh_hit->GetSingle(pulseintegral);
407  //const Df250WindowRawData *windorawdata;
408  //pulseintegral->GetSingle(windorawdata);
409 
410  int counter_id = tagh_hit->counter_id;
411 
412 
413  uint32_t adc_time = (tagh_hit->pulse_time & 0x7FC0) >> 6;
414 
415  if(trig_bit[2] == 1){
416 
417  if(counter_id < 100)
418  tagh_adc_time2.push_back(adc_time);
419 
420  if( (adc_time > 5) && (adc_time < 15))
421  tagh_counter2.push_back(counter_id);
422  }
423 
424  }
425 
426 
427 
428  // FILL HISTOGRAMS
429  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
430 
431 
432  if( l1trig.size() > 0 ){
433 
434  for(unsigned int bit = 0; bit < 32; bit++){
435  if(trig_bit[bit + 1] == 1) htrig_bit->Fill(Float_t(bit+1));
436  }
437 
438  for(unsigned int bit = 0; bit < 32; bit++){
439  if(trig_bit_fp[bit + 1] == 1) htrig_bit_fp->Fill(Float_t(bit+1));
440  }
441 
442  htrig_type->Fill(Float_t(l1trig[0]->trig_mask));
443 
444 
445  // Sync Events
446  if( l1trig[0]->gtp_rate.size() > 0 ){
447 
448  for(unsigned int ii = 0; ii < 8; ii++){
449  hrate_gtp[ii]->Fill(Float_t(l1trig[0]->gtp_rate[ii]/1000.));
450  if( (l1trig[0]->nsync) > 0 && (l1trig[0]->nsync) < 500){
451  hrate_bit[ii]->Fill(Float_t(l1trig[0]->nsync),Float_t(l1trig[0]->gtp_rate[ii]/1000.));
452  }
453  }
454 
455  // for(unsigned int ii = 0; ii < 16; ii++){
456  // hrate_fp[ii]->Fill(Float_t(l1trig[0]->fp_rate[ii]));
457  // }
458 
459  }
460  }
461 
462 
463 
464  if(trig_bit[1] == 1){
465  hfcal_en1->Fill(Float_t(fcal_tot_en));
466  hbcal_en1->Fill(Float_t(bcal_tot_en));
467  hfcal_bcal_en1->Fill(Float_t(fcal_tot_en), Float_t(bcal_tot_en));
468  }
469 
470  if(trig_bit[6] == 1){
471  hfcal_en6->Fill(Float_t(fcal_tot_en));
472  hbcal_en6->Fill(Float_t(bcal_tot_en));
473  hfcal_bcal_en6->Fill(Float_t(fcal_tot_en), Float_t(bcal_tot_en));
474  }
475 
476  if( (trig_bit[1] == 1) && (trig_bit[3] == 1) ){
477  hfcal_bcal_en1_3->Fill(Float_t(fcal_tot_en), Float_t(bcal_tot_en));
478  }
479 
480  if(trig_bit[7] == 1){
481  hfcal_en7->Fill(Float_t(fcal_tot_en));
482  hst_hit7->Fill(Float_t(st_hits.size()));
483  }
484 
485  if(trig_bit[3] == 1){
486  hbcal_en3->Fill(Float_t(bcal_tot_en));
487  }
488 
489 
490  if(trig_bit[2] == 1){
491  hfcal_en2->Fill(Float_t(fcal_tot_en));
492  }
493 
494  if( l1trig.size() > 0 ){
495  if(l1trig[0]->trig_mask == 1) hfcal_bcal_type1->Fill(Float_t(fcal_tot_en), Float_t(bcal_tot_en));
496  if(l1trig[0]->trig_mask == 3) hfcal_bcal_type3->Fill(Float_t(fcal_tot_en), Float_t(bcal_tot_en));
497  if(l1trig[0]->trig_mask == 5) hfcal_bcal_type5->Fill(Float_t(fcal_tot_en), Float_t(bcal_tot_en));
498  if(l1trig[0]->trig_mask == 7) hfcal_bcal_type7->Fill(Float_t(fcal_tot_en), Float_t(bcal_tot_en));
499  }
500 
501 
502  // FADC time
503  if(trig_bit[1] == 1)
504  for(unsigned int ii = 0; ii < fcal_adc_time1.size(); ii++) hfcal_time1->Fill(Float_t(fcal_adc_time1[ii]));
505  if(trig_bit[6] == 1)
506  for(unsigned int ii = 0; ii < fcal_adc_time6.size(); ii++) hfcal_time6->Fill(Float_t(fcal_adc_time6[ii]));
507  if(trig_bit[7] == 1)
508  for(unsigned int ii = 0; ii < fcal_adc_time7.size(); ii++) hfcal_time7->Fill(Float_t(fcal_adc_time7[ii]));
509 
510  if(trig_bit[1] == 1)
511  for(unsigned int ii = 0; ii < bcal_adc_time1.size(); ii++) hbcal_time1->Fill(Float_t(bcal_adc_time1[ii]));
512  if(trig_bit[3] == 1)
513  for(unsigned int ii = 0; ii < bcal_adc_time3.size(); ii++) hbcal_time3->Fill(Float_t(bcal_adc_time3[ii]));
514  if(trig_bit[6] == 1)
515  for(unsigned int ii = 0; ii < bcal_adc_time6.size(); ii++) hbcal_time6->Fill(Float_t(bcal_adc_time6[ii]));
516 
517 
518 
519 
520 
521  if(trig_bit[2] == 1){
522  hst_hit2->Fill(Float_t(st_hits.size()));
523 
524  for(unsigned int ii = 0; ii < tagh_adc_time2.size(); ii++) htagh_time2->Fill(Float_t(tagh_adc_time2[ii]));
525  for(unsigned int ii = 0; ii < tagh_counter2.size(); ii++) htagh_occup2->Fill(Float_t(tagh_counter2[ii]));
526  }
527 
528 
529 
530 
531 
532 
533  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
534 
535  return NOERROR;
536 }
537 
538 //------------------
539 // erun
540 //------------------
542 {
543  // This is called whenever the run number changes, before it is
544  // changed to give you a chance to clean up before processing
545  // events from the next run number.
546  return NOERROR;
547 }
548 
549 //------------------
550 // fini
551 //------------------
553 {
554  // Called before program exit after event processing is finished.
555  return NOERROR;
556 }
557 
static TH1I * hfcal_time1
int counter_id
counter id 1-274
Definition: DTAGHDigiHit.h:18
static TH1I * hfcal_en2
static TH1I * hbcal_en6
static TH1I * hbcal_time3
static TH1I * htrig_bit
static TH1I * hbcal_time6
uint32_t pulse_peak
maximum sample in pulse
Definition: DFCALDigiHit.h:26
static TH1I * hst_hit2
uint32_t nsamples_integral
number of samples used in integral
Definition: DFCALDigiHit.h:24
sprintf(text,"Post KinFit Cut")
static TH1I * hst_hit7
uint32_t nsamples_integral
number of samples used in integral
Definition: DBCALDigiHit.h:34
TDirectory * mainDir
Definition: p2k_hists.C:2
static TH1I * hfcal_time7
static TH2I * hfcal_bcal_type7
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
Definition: DFCALDigiHit.h:21
JApplication * japp
uint32_t pulse_peak
identified pulse height as returned by FPGA algorithm
Definition: DBCALDigiHit.h:30
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
Definition: DBCALDigiHit.h:29
static TH1I * htrig_type
static TH1I * hfcal_en6
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
Definition: DTAGHDigiHit.h:20
static TH1I * htagh_time2
InitPlugin_t InitPlugin
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
static TH1I * hbcal_time1
static TProfile * hrate_bit[8]
static TH1I * hbcal_en3
static TH1I * hbcal_en1
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
Definition: DFCALDigiHit.h:20
static TH1I * hfcal_time6
static TH1I * htagh_occup2
static TH2I * hfcal_bcal_en1
static TH2I * hfcal_bcal_en1_3
jerror_t fini(void)
Called after last event of last event source has been processed.
static TH1I * htrig_bit_fp
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static TH2I * hfcal_bcal_en6
static TH1I * hfcal_en7
static TH2I * hfcal_bcal_type3
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
Definition: DBCALDigiHit.h:31
static TH1I * hfcal_en1
static TH2I * hfcal_bcal_type5
jerror_t init(void)
Called once at program start.
static TH2I * hfcal_bcal_type1
static TH1F * hrate_gtp[8]
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.