Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_BCAL_LEDonline.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_FCAL_LEDonline.cc
4 //
5 
6 #include <stdint.h>
7 #include <vector>
9 #include <JANA/JApplication.h>
10 
11 using namespace std;
12 using namespace jana;
13 
14 #include "BCAL/DBCALDigiHit.h"
15 #include "BCAL/DBCALTDCDigiHit.h"
16 #include "BCAL/DBCALHit.h"
17 #include "BCAL/DBCALTDCHit.h"
18 #include "BCAL/DBCALUnifiedHit.h"
19 #include "BCAL/DBCALGeometry.h"
20 #include "DAQ/DF1TDCHit.h"
21 #include "DAQ/Df250PulseData.h"
22 #include "DAQ/Df250PulseIntegral.h"
23 #include "DAQ/Df250WindowRawData.h"
24 #include "TRIGGER/DL1Trigger.h"
25 
26 #include <TDirectory.h>
27 #include <TH2.h>
28 #include <TH1.h>
29 #include <TProfile2D.h>
30 #include <TStyle.h>
31 
32 
33 // root hist pointers
34 static TH1I *bcal_fadc_digi_time = NULL;
35 static TH2I *bcal_fadc_digi_occ = NULL;
36 static TProfile2D *bcal_fadc_digi_pedestal_ave = NULL;
39 static TH1I *bcal_fadc_digi_occ_layer1 = NULL;
40 static TH1I *bcal_fadc_digi_occ_layer2 = NULL;
41 static TH1I *bcal_fadc_digi_occ_layer3 = NULL;
42 static TH1I *bcal_fadc_digi_occ_layer4 = NULL;
43 // static TH1I *bcal_fadc_digi_nhits_chan = NULL;
44 static TH1I *bcal_fadc_digi_nhits_evnt = NULL;
45 static TProfile *bcal_fadc_digi_pedestal_vevent = NULL;
46 static TProfile *bcal_fadc_digi_peak_vevent = NULL;
47 static TProfile *bcal_fadc_digi_pedsubint_vevent = NULL;
48 static TProfile *bcal_fadc_digi_integral_vevent = NULL;
49 static TProfile *bcal_fadc_digi_pedsubpeak_vevent = NULL;
50 static TProfile *bcal_fadc_digi_pedestal_vchannel = NULL;
51 static TProfile *bcal_fadc_digi_peak_vchannel = NULL;
52 static TProfile *bcal_fadc_digi_pedsubint_vchannel = NULL;
53 static TProfile *bcal_fadc_digi_integral_vchannel = NULL;
54 static TProfile *bcal_fadc_digi_pedsubpeak_vchannel = NULL;
55 
56 static TH1I *bcal_tdc_digi_time = NULL;
57 static TH2I *bcal_tdc_digi_reltime = NULL;
58 static TH2I *bcal_tdc_digi_occ = NULL;
59 static TH1I *bcal_tdc_digi_occ_layer1 = NULL;
60 static TH1I *bcal_tdc_digi_occ_layer2 = NULL;
61 static TH1I *bcal_tdc_digi_occ_layer3 = NULL;
62 // static TH1I *bcal_tdc_digi_nhits_chan = NULL;
63 static TH1I *bcal_tdc_digi_nhits_evnt = NULL;
64 
65 static TH1I *bcal_fadc_E = NULL;
66 static TH1I *bcal_fadc_t = NULL;
67 static TH2I *bcal_fadc_occ = NULL;
68 // keep track of the integrated energy in each channel so that
69 // we can calculate the average energy per hit
70 static TH2D *bcal_fadc_avgE = NULL;
71 static TH2I *bcal_fadc_saturated = NULL;
72 
73 static TH1I *bcal_tdc_t = NULL;
74 static TH2I *bcal_tdc_occ = NULL;
75 
76 static TH1I *bcal_num_hits = NULL;
77 static TH1I *bcal_Uhit_E = NULL;
78 static TH1I *bcal_Uhit_t = NULL;
79 static TH1I *bcal_Uhit_t_ADC = NULL;
80 static TH1I *bcal_Uhit_t_TDC = NULL;
81 static TH1I *bcal_Uhit_tdiff = NULL;
82 static TH1I *bcal_Uhit_tTDC_twalk = NULL;
83 static TH1I *bcal_Uhit_noTDC_E = NULL;
84 static TH2I *bcal_Uhit_tTDC_tADC = NULL;
85 static TH2I *bcal_Uhit_tTDC_E = NULL;
86 static TH2I *bcal_Uhit_tADC_E = NULL;
87 static TProfile2D *bcal_Uhit_tdiff_ave = NULL;
88 
89 static TH1I *bcal_num_events;
90 
91 
92 
93 //----------------------------------------------------------------------------------
94 
95 
96 // Routine used to create our JEventProcessor
97 extern "C"{
98  void InitPlugin(JApplication *app){
99  InitJANAPlugin(app);
100  app->AddProcessor(new JEventProcessor_BCAL_LEDonline());
101  }
102 }
103 
104 
105 //----------------------------------------------------------------------------------
106 
107 
109 }
110 
111 
112 //----------------------------------------------------------------------------------
113 
114 
116 }
117 
118 
119 //----------------------------------------------------------------------------------
120 
122 
123  if(bcal_fadc_digi_time != NULL){
124  return NOERROR;
125  }
126 
127  NOtrig=0; FPtrig=0; GTPtrig=0; FPGTPtrig=0; trigUS=0; trigDS=0; trigCosmic=0;
128 
129  // create root folder for bcal and cd to it, store main dir
130  TDirectory *main = gDirectory;
131  gDirectory->mkdir("bcalLED")->cd();
132  //gStyle->SetOptStat(111110);
133 
134  // book hists
135  int timemin_ns = -200;
136  int timemax_ns = 400;
137  int timeminTDC_ns = -300;
138  int timemaxTDC_ns = 900;
139  float Ehit_min = -0.2;
140  float Ehit_max = 2.0;
141 
142  gStyle->SetTitleOffset(1, "Y");
143  gStyle->SetTitleSize(0.05,"xyz");
144  gStyle->SetTitleSize(0.08,"h");
145  gStyle->SetLabelSize(0.05,"xyz");
146  gStyle->SetTitleX(0);
147  gStyle->SetTitleAlign(13);
148  gStyle->SetNdivisions(505,"xy");
149 
150  bcal_num_events = new TH1I("bcal_num_events","BCAL Number of LEDevents",1, 0.5, 1.5);
151 
152  bcal_fadc_digi_time = new TH1I("bcal_fadc_digi_time","ADC Time (DBCALDigiHit);Time (fADC time/62.5 ps)", 550, -600, 6000);
153  bcal_fadc_digi_occ = new TH2I("bcal_fadc_digi_occ","ADC occupancy (DBCALDigiHit);Module", 48, 0.5, 48.5, 33, 0.5, 33.5);
154  bcal_fadc_digi_pedestal_ave = new TProfile2D("bcal_fadc_digi_pedestal_ave",
155  "Mean pedestal per cell (DBCALDigiHit);Module",
156  48, 0.5, 48.5, 33, 0.5, 33.5);
157  bcal_fadc_digi_nsamples_integral = new TH1I("bcal_fadc_digi_nsamples_integral","Number of samples: Integral (DBCALDigiHit);Number of samples",
158  100, 0, 100);
159  bcal_fadc_digi_nsamples_pedestal = new TH1I("bcal_fadc_digi_nsamples_pedestal","Number of samples: Pedestal (DBCALDigiHit);Number of samples",
160  10, 0, 10);
161  bcal_fadc_digi_occ_layer1 = new TH1I("bcal_fadc_digi_occ_layer1","Occupancy in layer 1 (DBCALDigiHit);global sector (4 x module + sector)",192, 0.5, 192.5);
162  bcal_fadc_digi_occ_layer2 = new TH1I("bcal_fadc_digi_occ_layer2","Occupancy in layer 2 (DBCALDigiHit);global sector (4 x module + sector)",192, 0.5, 192.5);
163  bcal_fadc_digi_occ_layer3 = new TH1I("bcal_fadc_digi_occ_layer3","Occupancy in layer 3 (DBCALDigiHit);global sector (4 x module + sector)",192, 0.5, 192.5);
164  bcal_fadc_digi_occ_layer4 = new TH1I("bcal_fadc_digi_occ_layer4","Occupancy in layer 4 (DBCALDigiHit);global sector (4 x module + sector)",192, 0.5, 192.5);
165  // bcal_fadc_digi_nhits_chan = new TH1I("bcal_fadc_digi_nhits_chan","ADC hits per channel;hits per channel",5,-0.5,4.5);
166  bcal_fadc_digi_nhits_evnt = new TH1I("bcal_fadc_digi_nhits_evnt","ADC hits per event;hits per event",200,0,0);
167 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
168  bcal_fadc_digi_nhits_evnt->SetCanExtend(TH1::kXaxis);
169 #else
170  bcal_fadc_digi_nhits_evnt->SetBit(TH1::kCanRebin);
171 #endif
172 
173  bcal_fadc_digi_pedestal_vevent = new TProfile("bcal_fadc_digi_pedestal_vevent","Avg BCAL pedestal vs event;event num;pedestal (all chan avg)",200,0.0,10000.0);
174  bcal_fadc_digi_integral_vevent = new TProfile("bcal_fadc_digi_integral_vevent","Avg BCAL integral vs event;event num;integral (all chan avg)",200,0.0,10000.0);
175  bcal_fadc_digi_peak_vevent = new TProfile("bcal_fadc_digi_peak_vevent","Avg BCAL peak vs event;event num;peak (all chan avg)",200,0.0,10000.0);
176  bcal_fadc_digi_pedsubint_vevent = new TProfile("bcal_fadc_digi_pedsubint_vevent","Avg BCAL ped sub integral vs event;event num;integral - pedestal (all chan avg)",200,0.0,10000.0);
177  bcal_fadc_digi_pedsubpeak_vevent = new TProfile("bcal_fadc_digi_pedsubpeak_vevent","Avg BCAL ped sub peak vs event;event num;peak - pedestal (all chan avg)",200,0.0,10000.0);
178 #if ROOT_VERSION_CODE >= ROOT_VERSION(6,0,0)
179  bcal_fadc_digi_pedestal_vevent->SetCanExtend(TH1::kXaxis);
180  bcal_fadc_digi_integral_vevent->SetCanExtend(TH1::kXaxis);
181  bcal_fadc_digi_peak_vevent->SetCanExtend(TH1::kXaxis);
182  bcal_fadc_digi_pedsubint_vevent->SetCanExtend(TH1::kXaxis);
183  bcal_fadc_digi_pedsubpeak_vevent->SetCanExtend(TH1::kXaxis);
184 #else
185  bcal_fadc_digi_pedestal_vevent->SetBit(TH1::kCanRebin);
186  bcal_fadc_digi_integral_vevent->SetBit(TH1::kCanRebin);
187  bcal_fadc_digi_peak_vevent->SetBit(TH1::kCanRebin);
188  bcal_fadc_digi_pedsubint_vevent->SetBit(TH1::kCanRebin);
189  bcal_fadc_digi_pedsubpeak_vevent->SetBit(TH1::kCanRebin);
190 #endif
191  bcal_fadc_digi_pedestal_vchannel = new TProfile("bcal_fadc_digi_pedestal_vchannel","Avg BCAL pedestal vs channel;channel num;pedestal (all chan avg)",1536,0,1536);
192  bcal_fadc_digi_integral_vchannel = new TProfile("bcal_fadc_digi_integral_vchannel","Avg BCAL integral vs channel;channel num;integral (all chan avg)",1536,0,1536);
193  bcal_fadc_digi_peak_vchannel = new TProfile("bcal_fadc_digi_peak_vchannel","Avg BCAL peak vs channel;channel num;peak (all chan avg)",1536,0,1536);
194  bcal_fadc_digi_pedsubint_vchannel = new TProfile("bcal_fadc_digi_pedsubint_vchannel","Avg BCAL ped sub integral vs channel;channel num;integral - pedestal (all chan avg)",1536,0,1536);
195  bcal_fadc_digi_pedsubpeak_vchannel = new TProfile("bcal_fadc_digi_pedsubpeak_vchannel","Avg BCAL ped sub peak vs channel;channel num;peak - pedestal (all chan avg)",1536,0,1536);
196  bcal_tdc_digi_time = new TH1I("bcal_tdc_digi_time","TDC Time (DBCALDigiTDCHit);Time (F1TDC counts)", 500, 0, 66000);
197  bcal_tdc_digi_reltime = new TH2I("bcal_tdc_digi_reltime","Relative TDC Time (DBCALDigiTDCHit);Time (F1TDC counts); TDC trig time",
198  100, 0, 70000, 100, 0, 600);
199  bcal_tdc_digi_occ = new TH2I("bcal_tdc_digi_occ","TDC occupancy (DBCALDigiTDCHit);Module", 48, 0.5, 48.5, 25, 0.5, 25.5);
200 
201  bcal_tdc_digi_occ_layer1 = new TH1I("bcal_tdc_digi_occ_layer1","Occupancy in layer 1 (DBCALDigiTDCHit);global sector (4 x module + sector)",192, 0.5, 192.5);
202  bcal_tdc_digi_occ_layer2 = new TH1I("bcal_tdc_digi_occ_layer2","Occupancy in layer 2 (DBCALDigiTDCHit);global sector (4 x module + sector)",192, 0.5, 192.5);
203  bcal_tdc_digi_occ_layer3 = new TH1I("bcal_tdc_digi_occ_layer3","Occupancy in layer 3 (DBCALDigiTDCHit);global sector (4 x module + sector)",192, 0.5, 192.5);
204  // bcal_tdc_digi_nhits_chan = new TH1I("bcal_tdc_digi_nhits_chan","TDC hits per channel;hits per channel",5,-0.5,4.5);
205  bcal_tdc_digi_nhits_evnt = new TH1I("bcal_tdc_digi_nhits_evnt","TDC hits per event;hits per event",125,-0.5,124.5);
206 
207  bcal_fadc_E = new TH1I("bcal_fadc_E","Uncorrected Energy (DBCALHit);Energy, not atten. corr. (GeV)", 500, Ehit_min, Ehit_max);
208  bcal_fadc_t = new TH1I("bcal_fadc_t","ADC Time (DBCALHit);Time (ns)", 1200, timemin_ns, timemax_ns);
209  bcal_fadc_occ = new TH2I("bcal_fadc_occ","ADC occupancy (DBCALHit);Module", 48, 0.5, 48.5, 33, 0.5, 33.5);
210  bcal_fadc_avgE = new TH2D("bcal_fadc_avgE","Average Energy x Occupancy (DBCALHit);Module", 48, 0.5, 48.5, 33, 0.5, 33.5);
211  bcal_fadc_saturated = new TH2I("bcal_fadc_saturated","Saturated Occupancy (DBCALHit);Module", 48, 0.5, 48.5, 33, 0.5, 33.5);
212 
213  bcal_tdc_t = new TH1I("bcal_tdc_t","TDC Time (DBCALTDCHit);Time (ns)", 1200, timeminTDC_ns, timemaxTDC_ns);
214  bcal_tdc_occ = new TH2I("bcal_tdc_occ","TDC occupancy (DBCALTDCHit);Module", 48, 0.5, 48.5, 25, 0.5, 25.5);
215 
216  bcal_num_hits = new TH1I("bcal_num_hits","Number of BCAL hits;Number of hits per event", 250, 0, 250);
217  bcal_Uhit_E = new TH1I("bcal_Uhit_E","Uncorrected Energy (DBCALUnifiedHit);Energy, not atten. corr. (GeV)", 500, Ehit_min, Ehit_max);
218  bcal_Uhit_t = new TH1I("bcal_Uhit_t","Unified time (DBCALUnifiedHit);time (ns)", 1200, timeminTDC_ns, timemaxTDC_ns);
219  bcal_Uhit_t_TDC = new TH1I("bcal_Uhit_t_TDC","TDC time (DBCALUnifiedHit);Timewalk corrected TDC time (ns)", 1200, timeminTDC_ns, timemaxTDC_ns);
220  bcal_Uhit_t_ADC = new TH1I("bcal_Uhit_t_ADC","ADC time (DBCALUnifiedHit);ADC time (ns)", 1000, timemin_ns, timemax_ns);
221  bcal_Uhit_noTDC_E = new TH1I("bcal_Uhit_noTDC_E","Energy for no TDC (DBCALUnifiedHit);Energy", 500, Ehit_min, Ehit_max);
222  bcal_Uhit_tTDC_tADC = new TH2I("bcal_Uhit_tTDC_tADC","ADC vs TDC time (DBCALUnifiedHit);TDC time;ADC time (ns)",
223  100, timemin_ns, timemax_ns, 100, timemin_ns, timemax_ns);
224  bcal_Uhit_tdiff = new TH1I("bcal_Uhit_tdiff","time diff. (ADC-TDC) (DBCALUnifiedHit);(TDC - ADC) time (ns)",
225  200, -300, 300);
226  bcal_Uhit_tTDC_E = new TH2I("bcal_Uhit_tTDC_E","TDC time vs Energy (DBCALUnifiedHit);Energy, not atten. corr. (GeV);Timewalk corrected TDC time",
227  100, Ehit_min, Ehit_max, 100, timeminTDC_ns, timemaxTDC_ns);
228  bcal_Uhit_tADC_E = new TH2I("bcal_Uhit_tADC_E","ADC time vs Energy (DBCALUnifiedHit);Energy, not atten. corr. (GeV);ADC time (ns)",
229  100, Ehit_min, Ehit_max, 100, timemin_ns, timemax_ns);
230  bcal_Uhit_tTDC_twalk = new TH1I("bcal_Uhit_tTDC_twalk","TDC timewalk correction (DBCALUnifiedHit);Timewalk correction (ns)",
231  150, -140, 10);
232  bcal_Uhit_tdiff_ave = new TProfile2D("bcal_Uhit_tdiff_ave", "Mean time diff. (TDC-ADC) (DBCALDigiHit);Module",
233  48, 0.5, 48.5, 33, 0.5, 33.5);
234 
235  // Turn off stats window for occupancy plots
236  bcal_fadc_digi_occ->SetStats(0);
237  bcal_tdc_digi_occ->SetStats(0);
238  bcal_tdc_digi_reltime->SetStats(0);
239  bcal_fadc_occ->SetStats(0);
240  bcal_fadc_avgE->SetStats(0);
241  bcal_fadc_saturated->SetStats(0);
242  bcal_fadc_digi_pedestal_vevent->SetStats(0);
243  bcal_fadc_digi_integral_vevent->SetStats(0);
244  bcal_fadc_digi_peak_vevent->SetStats(0);
245  bcal_fadc_digi_pedsubint_vevent->SetStats(0);
249  bcal_fadc_digi_peak_vchannel->SetStats(0);
252  bcal_tdc_occ->SetStats(0);
253  bcal_Uhit_tTDC_tADC->SetStats(0);
254  bcal_Uhit_tTDC_E->SetStats(0);
255  bcal_Uhit_tADC_E->SetStats(0);
256  bcal_Uhit_tTDC_twalk->SetStats(0);
257  bcal_fadc_digi_pedestal_ave->SetStats(0);
258  bcal_Uhit_tdiff_ave->SetStats(0);
259 
260  // Set y-axis labels for occupancy plots
261  for(int ibin=1; ibin<=16; ibin++){
262  int idy = ibin-1; // convenient to use index that starts from zero!
263 
264  int layer = 1 + (idy%4);
265  int sector = 1 + idy/4;
266 
267  stringstream ss;
268  ss<<"D ";
269  ss << "S"<<sector<<" L"<<layer;
270  bcal_fadc_digi_occ->GetYaxis()->SetBinLabel(ibin, ss.str().c_str());
271  bcal_fadc_occ->GetYaxis()->SetBinLabel(ibin, ss.str().c_str());
272  bcal_fadc_avgE->GetYaxis()->SetBinLabel(ibin, ss.str().c_str());
273  bcal_fadc_saturated->GetYaxis()->SetBinLabel(ibin, ss.str().c_str());
274  bcal_fadc_digi_pedestal_ave->GetYaxis()->SetBinLabel(ibin, ss.str().c_str());
275  bcal_Uhit_tdiff_ave->GetYaxis()->SetBinLabel(ibin, ss.str().c_str());
276 
277  ss.str("");
278  ss.clear();
279  ss<<"U ";
280  ss << "S"<<sector<<" L"<<layer;
281  bcal_fadc_digi_occ->GetYaxis()->SetBinLabel(ibin+17, ss.str().c_str());
282  bcal_fadc_occ->GetYaxis()->SetBinLabel(ibin+17, ss.str().c_str());
283  bcal_fadc_avgE->GetYaxis()->SetBinLabel(ibin+17, ss.str().c_str());
284  bcal_fadc_saturated->GetYaxis()->SetBinLabel(ibin+17, ss.str().c_str());
285  bcal_fadc_digi_pedestal_ave->GetYaxis()->SetBinLabel(ibin+17, ss.str().c_str());
286  bcal_Uhit_tdiff_ave->GetYaxis()->SetBinLabel(ibin+17, ss.str().c_str());
287  }
288 
289  // Occupancy plots for TDC (without layer 4)
290  // Set y-axis labels for occupancy plots
291  for(int ibin=1; ibin<=12; ibin++){
292  int idy = ibin-1; // convenient to use index that starts from zero!
293 
294  int layer = 1 + (idy%3);
295  int sector = 1 + idy/3;
296 
297  stringstream ss;
298  ss<<"D ";
299  ss << "S"<<sector<<" L"<<layer;
300  bcal_tdc_digi_occ->GetYaxis()->SetBinLabel(ibin, ss.str().c_str());
301  bcal_tdc_occ->GetYaxis()->SetBinLabel(ibin, ss.str().c_str());
302 
303  ss.str("");
304  ss.clear();
305  ss<<"U ";
306  ss << "S"<<sector<<" L"<<layer;
307  bcal_tdc_digi_occ->GetYaxis()->SetBinLabel(ibin+13, ss.str().c_str());
308  bcal_tdc_occ->GetYaxis()->SetBinLabel(ibin+13, ss.str().c_str());
309  }
310 
311  // back to main dir
312  main->cd();
313 
314  return NOERROR;
315 }
316 
317 
318 //----------------------------------------------------------------------------------
319 
320 
321 jerror_t JEventProcessor_BCAL_LEDonline::brun(JEventLoop *eventLoop, int32_t runnumber) {
322 
323  return NOERROR;
324 }
325 
326 
327 //----------------------------------------------------------------------------------
328 
329 
330 jerror_t JEventProcessor_BCAL_LEDonline::evnt(JEventLoop *loop, uint64_t eventnumber) {
331  // This is called for every event. Use of common resources like writing
332  // to a file or filling a histogram should be mutex protected. Using
333  // loop-Get(...) to get reconstructed objects (and thereby activating the
334  // reconstruction algorithm) should be done outside of any mutex lock
335  // since multiple threads may call this method at the same time.
336 
337  // This is called whenever the run number changes
338  // load BCAL geometry
339  vector<const DBCALGeometry *> BCALGeomVec;
340  loop->Get(BCALGeomVec);
341  if(BCALGeomVec.size() == 0)
342  throw JException("Could not load locBCALGeometry object!");
343  const DBCALGeometry *locBCALGeom = BCALGeomVec[0];
344 
345 
346  vector<const DBCALDigiHit*> dbcaldigihits;
347  vector<const DBCALTDCDigiHit*> dbcaltdcdigihits;
348  vector<const DBCALHit*> dbcalhits;
349  vector<const DBCALTDCHit*> dbcaltdchits;
350  vector<const DBCALUnifiedHit*> dbcaluhits;
351 
352  bool LED_US=0, LED_DS=0;
353 
354  const DL1Trigger *trig = NULL;
355  try {
356  loop->GetSingle(trig);
357  } catch (...) {}
358  if (trig) {
359  //printf("%5i %5i | %5i %5i %5i | %i\n",
360  // trig->trig_mask,trig->trig_mask & 0x1,
361  // trig->fp_trig_mask, trig->fp_trig_mask & 0x100,trig->fp_trig_mask & 0x200,
362  // trig->trig_mask && trig->fp_trig_mask);
363 
364  if (trig->trig_mask){
365  // GTP tigger
366  GTPtrig++;
367  }
368  if (trig->fp_trig_mask){
369  // Front panel trigger
370  FPtrig++;
371  }
372  if (trig->trig_mask && trig->fp_trig_mask){
373  // Both GTP and front panel trigger
374  FPGTPtrig++;
375  }
376  if (trig->trig_mask & 0x1){
377  // Cosmic trigger fired
378  trigCosmic++;
379  }
380  if (trig->fp_trig_mask & 0x100){
381  // Upstream LED trigger fired
382  trigUS++;
383  LED_US=1;
384  }
385  if (trig->fp_trig_mask & 0x200){
386  // Downstream LED trigger fired
387  trigDS++;
388  LED_DS=1;
389  }
390  } else {
391  NOtrig++;
392  }
393 
394  if (LED_US || LED_DS) {
395 
396  loop->Get(dbcaldigihits);
397  loop->Get(dbcaltdcdigihits);
398  loop->Get(dbcalhits);
399  loop->Get(dbcaltdchits);
400  loop->Get(dbcaluhits);
401 
402  // FILL HISTOGRAMS
403  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
404  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
405 
406  if( (dbcaldigihits.size() > 0) || (dbcaltdcdigihits.size() > 0) )
407  bcal_num_events->Fill(1);
408 
409  bcal_fadc_digi_nhits_evnt->Fill(dbcaldigihits.size());
410  bcal_tdc_digi_nhits_evnt->Fill(dbcaltdcdigihits.size());
411 
412  // The map is created to get the nunmber of hits per cell
413  // map<readout_channel, cellHits> cellHitMap;
414  // for( vector<const DBCALDigiHit*>::const_iterator hitPtr = dbcaldigihits.begin();
415  // hitPtr != dbcaldigihits.end();
416  // ++hitPtr ){
417 
418  // const DBCALDigiHit& hit = (**hitPtr);
419 
420  // int id = DBCALGeometry::cellId( hit.module, hit.layer, hit.sector );
421  // readout_channel chan(id, hit.end);
422 
423  // //this will create cellHitMap[chan] if it doesn't already exist
424  // cellHitMap[chan].hits.push_back(*hitPtr);
425  // }
426 
427 
428  // Digitized fADC hits for bcal
429  for(unsigned int i=0; i<dbcaldigihits.size(); i++) {
430  const DBCALDigiHit *hit = dbcaldigihits[i];
431 
432  bcal_fadc_digi_time->Fill(hit->pulse_time);
435  int layer = hit->layer;
436  int glosect = locBCALGeom->getglobalsector(hit->module, hit->sector);
437  if (layer==1) bcal_fadc_digi_occ_layer1->Fill(glosect);
438  if (layer==2) bcal_fadc_digi_occ_layer2->Fill(glosect);
439  if (layer==3) bcal_fadc_digi_occ_layer3->Fill(glosect);
440  if (layer==4) bcal_fadc_digi_occ_layer4->Fill(glosect);
441 
442  int channelnumber = locBCALGeom->getglobalchannelnumber(hit->module, hit->layer, hit->sector, hit->end);
443  if ( hit->pedestal > 0 ) {
444  double pedsubint = hit->pulse_integral-((float)hit->nsamples_integral/(float)hit->nsamples_pedestal)*hit->pedestal;
445  double pedsubpeak = hit->pulse_peak-hit->pedestal;
446  bcal_fadc_digi_pedestal_vevent->Fill(eventnumber,hit->pedestal);
447  bcal_fadc_digi_integral_vevent->Fill(eventnumber,hit->pulse_integral);
448  bcal_fadc_digi_peak_vevent->Fill(eventnumber,hit->pulse_peak);
449  bcal_fadc_digi_pedsubint_vevent->Fill(eventnumber,pedsubint);
450  bcal_fadc_digi_pedsubpeak_vevent->Fill(eventnumber,pedsubpeak);
451  bcal_fadc_digi_pedestal_vchannel->Fill(channelnumber,hit->pedestal);
452  bcal_fadc_digi_integral_vchannel->Fill(channelnumber,hit->pulse_integral);
453  bcal_fadc_digi_peak_vchannel->Fill(channelnumber,hit->pulse_peak);
454  bcal_fadc_digi_pedsubint_vchannel->Fill(channelnumber,pedsubint);
455  bcal_fadc_digi_pedsubpeak_vchannel->Fill(channelnumber,pedsubpeak);
456  }
457 
458  // Occupancy histogram defined to give better aspect ratio
459  int ix = hit->module;
460  int iy = (hit->sector-1)*4 + hit->layer;
461  if(hit->end == DBCALGeometry::kUpstream) {
462  bcal_fadc_digi_occ->Fill(ix, iy+17);
463  if ( hit->pedestal > 0 ) {
464  bcal_fadc_digi_pedestal_ave->Fill(ix, iy+17, hit->pedestal);
465  }
466  }
467  if(hit->end == DBCALGeometry::kDownstream) {
468  bcal_fadc_digi_occ->Fill(ix, iy);
469  if ( hit->pedestal > 0 ) {
470  bcal_fadc_digi_pedestal_ave->Fill(ix, iy, hit->pedestal);
471  }
472  }
473 
474  }
475 
476  // Digitized TDC hits for bcal
477  for(unsigned int i=0; i<dbcaltdcdigihits.size(); i++) {
478  const DBCALTDCDigiHit *hit = dbcaltdcdigihits[i];
479 
480  bcal_tdc_digi_time->Fill(hit->time);
481  vector<const DF1TDCHit*> f1tdchits;
482  hit->Get(f1tdchits);
483  if(f1tdchits.size() > 0)
484  bcal_tdc_digi_reltime->Fill(f1tdchits[0]->time,f1tdchits[0]->trig_time);
485 
486  int layer = hit->layer;
487  int glosect = locBCALGeom->getglobalsector(hit->module, hit->sector);
488  if (layer==1) bcal_tdc_digi_occ_layer1->Fill(glosect);
489  if (layer==2) bcal_tdc_digi_occ_layer2->Fill(glosect);
490  if (layer==3) bcal_tdc_digi_occ_layer3->Fill(glosect);
491 
492  // Occupancy histogram defined to give better aspect ratio
493  int ix = hit->module;
494  int iy = (hit->sector-1)*3 + hit->layer; // TDC has 3 layers per sector
495  if(hit->end == DBCALGeometry::kUpstream) bcal_tdc_digi_occ->Fill(ix, iy+13);
496  if(hit->end == DBCALGeometry::kDownstream) bcal_tdc_digi_occ->Fill(ix, iy);
497  }
498 
499  // Calibrated fADC hits for bcal
500  for(unsigned int i=0; i<dbcalhits.size(); i++) {
501  const DBCALHit *hit = dbcalhits[i];
502 
503  bool saturated=0;
504  vector<const DBCALDigiHit*> assoc_BCALDigiHit;
505  hit->Get(assoc_BCALDigiHit);
506  if (assoc_BCALDigiHit.size()>0) {
507  vector<const Df250PulseIntegral*> f250PulseIntegral;
508  assoc_BCALDigiHit[0]->Get(f250PulseIntegral);
509  //printf("got %i DBCALDigiHit %i f250PulseIntegral\n", assoc_BCALDigiHit.size(),f250PulseIntegral.size());
510  if (f250PulseIntegral.size()>0) {
511  vector<const Df250WindowRawData*> f250WindowRawData;
512  f250PulseIntegral[0]->Get(f250WindowRawData);
513  if (f250WindowRawData.size()>0) {
514  //printf("got Df250WindowRawData\n");
515  if (f250WindowRawData[0]->overflow==1) {
516  saturated=1;
517  }
518  }
519  }
520 
521  // post-Fall 2016 firmware
522  vector<const Df250PulseData*> f250PulseData;
523  assoc_BCALDigiHit[0]->Get(f250PulseData);
524  //printf("got %i DBCALDigiHit %i f250PulseData\n", assoc_BCALDigiHit.size(),f250PulseData.size());
525  if (f250PulseData.size()>0) {
526  vector<const Df250WindowRawData*> f250WindowRawData;
527  f250PulseData[0]->Get(f250WindowRawData);
528  if (f250WindowRawData.size()>0) {
529  //printf("got Df250WindowRawData\n");
530  if (f250WindowRawData[0]->overflow==1) {
531  saturated=1;
532  }
533  }
534  }
535  }
536 
537  // Occupancy histogram defined to give better aspect ratio
538  int ix = hit->module;
539  int iy = (hit->sector-1)*4 + hit->layer;
540  if (!saturated) {
541  bcal_fadc_E->Fill(hit->E);
542  bcal_fadc_t->Fill(hit->t);
543  if(hit->end == DBCALGeometry::kUpstream) {
544  bcal_fadc_occ->Fill(ix, iy+17);
545  bcal_fadc_avgE->Fill(ix, iy+17, hit->E);
546  }
547  if(hit->end == DBCALGeometry::kDownstream) {
548  bcal_fadc_occ->Fill(ix, iy);
549  bcal_fadc_avgE->Fill(ix, iy, hit->E);
550  }
551  } else {
552  if(hit->end == DBCALGeometry::kUpstream) {
553  bcal_fadc_saturated->Fill(ix, iy+17);
554  }
555  if(hit->end == DBCALGeometry::kDownstream) {
556  bcal_fadc_saturated->Fill(ix, iy);
557  }
558  }
559  }
560 
561  // Calibrated TDC hits for bcal
562  for(unsigned int i=0; i<dbcaltdchits.size(); i++) {
563  const DBCALTDCHit *hit = dbcaltdchits[i];
564 
565  bcal_tdc_t->Fill(hit->t);
566 
567  // Occupancy histogram defined to give better aspect ratio
568  int ix = hit->module;
569  int iy = (hit->sector-1)*3 + hit->layer; // TDC has 3 layers per sector
570  if(hit->end == DBCALGeometry::kUpstream) bcal_tdc_occ->Fill(ix, iy+13);
571  if(hit->end == DBCALGeometry::kDownstream) bcal_tdc_occ->Fill(ix, iy);
572  }
573 
574  // BCAL Unified Hit (combined ADC and TDC info)
575  bcal_num_hits->Fill(dbcaluhits.size());
576  for(unsigned int i=0; i<dbcaluhits.size(); i++) {
577  const DBCALUnifiedHit *Uhit = dbcaluhits[i];
578  bcal_Uhit_E->Fill(Uhit->E);
579  bcal_Uhit_t->Fill(Uhit->t);
580  bcal_Uhit_t_ADC->Fill(Uhit->t_ADC);
581  bcal_Uhit_tADC_E->Fill(Uhit->E,Uhit->t_ADC);
582  if (Uhit->t_TDC != 0) {
583  bcal_Uhit_t_TDC->Fill(Uhit->t_TDC);
584  float t_diff = Uhit->t_TDC - Uhit->t_ADC;
585  bcal_Uhit_tdiff->Fill(t_diff);
586  bcal_Uhit_tTDC_E->Fill(Uhit->E,Uhit->t_TDC);
587  bcal_Uhit_tTDC_tADC->Fill(Uhit->t_TDC,Uhit->t_ADC);
588  vector<const DBCALTDCHit*> tdchits;
589  Uhit->Get(tdchits);
590  bcal_Uhit_tTDC_twalk->Fill(Uhit->t_TDC - tdchits[0]->t);
591 
592  int ix = Uhit->module;
593  int iy = (Uhit->sector-1)*4 + Uhit->layer;
594  if(Uhit->end == DBCALGeometry::kUpstream) {
595  bcal_Uhit_tdiff_ave->Fill(ix, iy+17, t_diff);
596  }
597  if(Uhit->end == DBCALGeometry::kDownstream) {
598  bcal_Uhit_tdiff_ave->Fill(ix, iy, t_diff);
599  }
600  } else {
601  bcal_Uhit_noTDC_E->Fill(Uhit->E);
602  }
603  }
604 
605  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
606  }
607 
608  return NOERROR;
609 }
610 
611 
612 //----------------------------------------------------------------------------------
613 
614 
616  // This is called whenever the run number changes, before it is
617  // changed to give you a chance to clean up before processing
618  // events from the next run number.
619 
620  printf("\nTrigger statistics");
621  printf("------------------------\n");
622  printf("%20s: %10i\n","no triggers",NOtrig);
623  printf("%20s: %10i\n","Front Panel",FPtrig);
624  printf("%20s: %10i\n","GTP",GTPtrig);
625  printf("%20s: %10i\n","FP && GTP",FPGTPtrig);
626  printf("%20s: %10i\n","US LED",trigUS);
627  printf("%20s: %10i\n","DS LED",trigDS);
628  printf("%20s: %10i\n","BCAL",trigCosmic);
629 
631  bcal_fadc_digi_integral_vevent->SetMinimum(bcal_fadc_digi_integral_vevent->GetMinimum(0.1));
632  bcal_fadc_digi_peak_vevent->SetMinimum(bcal_fadc_digi_peak_vevent->GetMinimum(0.1));
637  bcal_fadc_digi_peak_vchannel->SetMinimum(bcal_fadc_digi_peak_vchannel->GetMinimum(0.1));
638 
639  return NOERROR;
640 }
641 
642 
643 //----------------------------------------------------------------------------------
644 
645 
647  // Called before program exit after event processing is finished.
648  return NOERROR;
649 }
650 
651 
652 //----------------------------------------------------------------------------------
653 //----------------------------------------------------------------------------------
static TH1I * bcal_tdc_digi_occ_layer2
static TH1I * bcal_fadc_digi_occ_layer3
float E
Definition: DBCALHit.h:30
static TProfile * bcal_fadc_digi_integral_vchannel
static TH2I * bcal_tdc_digi_occ
static TH1I * bcal_Uhit_t
if(locHist_BCALShowerPhiVsZ!=NULL)
float t_TDC
Time of TDC hit that is closes t to the ADC time.
static TH1I * bcal_Uhit_t_ADC
Int_t layer
static TH1I * bcal_Uhit_E
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
uint32_t trig_mask
Definition: DL1Trigger.h:18
static TProfile * bcal_fadc_digi_integral_vevent
int module
Definition: DBCALHit.h:25
static TH1I * bcal_Uhit_noTDC_E
static TProfile2D * bcal_fadc_digi_pedestal_ave
uint32_t fp_trig_mask
Definition: DL1Trigger.h:19
static TH2I * bcal_Uhit_tADC_E
static TH1I * bcal_fadc_digi_occ_layer4
static TH2I * bcal_tdc_occ
static TH2I * bcal_fadc_occ
uint32_t nsamples_integral
number of samples used in integral
Definition: DBCALDigiHit.h:34
static TH1I * bcal_fadc_t
static TH2I * bcal_fadc_digi_occ
int layer
Definition: DBCALHit.h:26
trig[33-1]
jerror_t fini(void)
Called after last event of last event source has been processed.
JApplication * japp
static TH1I * bcal_fadc_digi_nsamples_integral
DBCALGeometry::End end
Definition: DBCALDigiHit.h:28
uint32_t pulse_peak
identified pulse height as returned by FPGA algorithm
Definition: DBCALDigiHit.h:30
DBCALGeometry::End end
Definition: DBCALHit.h:28
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
Definition: DBCALDigiHit.h:29
int getglobalchannelnumber(int module, int layer, int sector, int end) const
Return a BCAL channel number, in order of significance (module, layer, sector, end).
static TH1I * bcal_tdc_digi_occ_layer3
jerror_t init(void)
Called once at program start.
static TProfile * bcal_fadc_digi_pedsubint_vevent
InitPlugin_t InitPlugin
static TH1I * bcal_fadc_digi_nhits_evnt
static TH1I * bcal_Uhit_t_TDC
static TH1I * bcal_fadc_digi_time
uint32_t nsamples_pedestal
number of samples used in pedestal
Definition: DBCALDigiHit.h:35
static TProfile * bcal_fadc_digi_pedsubpeak_vchannel
float t_ADC
Time from fADC.
static TH1I * bcal_tdc_t
static TH1I * bcal_fadc_E
DBCALGeometry::End end
static TH1I * bcal_num_events
static TH1I * bcal_tdc_digi_nhits_evnt
static TH2I * bcal_Uhit_tTDC_tADC
DBCALGeometry::End end
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
static TProfile * bcal_fadc_digi_peak_vchannel
float t
Definition: DBCALHit.h:31
int sector
Definition: DBCALHit.h:27
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
int getglobalsector(int module, int sector) const
static TH2I * bcal_tdc_digi_reltime
static TH1I * bcal_num_hits
uint32_t pedestal
pedestal info used by FPGA (if any)
Definition: DBCALDigiHit.h:32
static TProfile * bcal_fadc_digi_peak_vevent
static TProfile * bcal_fadc_digi_pedsubpeak_vevent
static TH2I * bcal_fadc_saturated
static TH1I * bcal_tdc_digi_time
static TProfile * bcal_fadc_digi_pedsubint_vchannel
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
Definition: DBCALDigiHit.h:31
static TProfile2D * bcal_Uhit_tdiff_ave
static TH1I * bcal_fadc_digi_nsamples_pedestal
DBCALGeometry::End end
Definition: DBCALTDCHit.h:25
static TH1I * bcal_fadc_digi_occ_layer2
static TH1I * bcal_tdc_digi_occ_layer1
static TH2D * bcal_fadc_avgE
static TProfile * bcal_fadc_digi_pedestal_vevent
printf("string=%s", string)
static TProfile * bcal_fadc_digi_pedestal_vchannel
static TH1I * bcal_fadc_digi_occ_layer1
static TH1I * bcal_Uhit_tTDC_twalk
int main(int argc, char *argv[])
Definition: gendoc.cc:6
static TH1I * bcal_Uhit_tdiff
static TH2I * bcal_Uhit_tTDC_E
float t
Unified time, obtained from ADC and/or TDC and used for further analysis.