Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_TOF_online.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_FCAL_online.cc
4 // Created: Fri Nov 9 11:58:09 EST 2012
5 // Creator: wolin (on Linux stan.jlab.org 2.6.32-279.11.1.el6.x86_64 x86_64)
6 
7 
8 #include <stdint.h>
9 #include <vector>
10 #include <limits>
11 
13 #include <JANA/JApplication.h>
14 
15 using namespace std;
16 using namespace jana;
17 #include <DAQ/DCODAEventInfo.h>
18 #include <DAQ/DCODAROCInfo.h>
19 #include <DAQ/DCAEN1290TDCHit.h>
20 
21 #include "TOF/DTOFHit.h"
22 #include "TOF/DTOFDigiHit.h"
23 #include "TOF/DTOFTDCDigiHit.h"
24 
25 #include <TDirectory.h>
26 #include <TH2.h>
27 #include <TH1.h>
28 #include <TCanvas.h>
29 #include <TPolyLine.h>
30 
31 
32 // root hist pointers
33 static TH1I *tofe;
34 static TH1I *toft;
35 static TH2I *tofo1;
36 static TH2I *tofo2;
37 
38 static TH1I *tdcOccS;
39 static TH1I *tdcOccN;
40 static TH1I *tdcOccU;
41 static TH1I *tdcOccD;
42 
43 static TH1I *adcOccS;
44 static TH1I *adcOccN;
45 static TH1I *adcOccU;
46 static TH1I *adcOccD;
47 
48 static TH2I *planeHor;
49 static TH2I *planeVer;
50 
51 static TH1I *tof_num_events;
52 
53 static TH1I *histPed;
54 static TH1I *hTimeAdc;
55 static TH1I *hTimeTdc;
56 
57 static TH2F *TOFPedestalsPlane0;
58 static TH2F *TOFPedestalsPlane1;
59 static TH2F *TOFSignalsRawPlane0;
60 static TH2F *TOFSignalsRawPlane1;
61 static TH2F *TOFTimesPlane0;
62 static TH2F *TOFTimesPlane1;
63 
64 static TH2F *TOFWalkExample;
65 
66 
67 //----------------------------------------------------------------------------------
68 
69 
70 // Routine used to create our JEventProcessor
71 extern "C"{
72  void InitPlugin(JApplication *app){
73  InitJANAPlugin(app);
74  app->AddProcessor(new JEventProcessor_TOF_online());
75  }
76 }
77 
78 
79 //----------------------------------------------------------------------------------
80 
81 
83 }
84 
85 
86 //----------------------------------------------------------------------------------
87 
88 
90 }
91 
92 
93 //----------------------------------------------------------------------------------
94 
96 
97  // create root folder for tof and cd to it, store main dir
98  TDirectory *main = gDirectory;
99  gDirectory->mkdir("tof")->cd();
100 
101 
102  // book hist
103  tof_num_events = new TH1I("tof_num_events","TOF Number of events",1, 0.5, 1.5);
104 
105  tofe = new TH1I("tofe","TOF energy in keV",100,0,15000);
106  toft = new TH1I("toft","TOF time in ns",200,0,200);
107  tofo1 = new TH2I("tofo1","TOF occupancy plane 1 by bar,top/bottom",50,0,50,2,0,2);
108  tofo2 = new TH2I("tofo2","TOF occupancy plane 2 by left/right,bar",2,0,2,50,0,50);
109 
110  tdcOccS = new TH1I("tdcOccS","TOF, TDC Occupancy",86,1,44);
111  tdcOccN = new TH1I("tdcOccN","TOF, TDC Occupancy",86,1,44);
112  tdcOccU = new TH1I("tdcOccU","TOF, TDC Occupancy",86,1,44);
113  tdcOccD = new TH1I("tdcOccD","TOF, TDC Occupancy",86,1,44);
114 
115  adcOccS = new TH1I("adcOccS","TOF, fADC Occupancy",86,1,44);
116  adcOccN = new TH1I("adcOccN","TOF, fADC Occupancy",86,1,44);
117  adcOccU = new TH1I("adcOccU","TOF, fADC Occupancy",86,1,44);
118  adcOccD = new TH1I("adcOccD","TOF, fADC Occupancy",86,1,44);
119 
120  histPed = new TH1I("histPed","TOF, Pedestals",100, 0, 500);
121 
122  hTimeAdc = new TH1I("hTimeAdc","TOF, fADC time",100,0,400);
123  hTimeTdc = new TH1I("hTimeTdc","TOF, TDC time",100,0,750);
124 
125  planeHor = new TH2I("planeHor","TOF Upstream, Hit position, Horizontal Plane",84,-126,126,84,-126,126);
126  planeVer = new TH2I("planeVer","TOF Upstream, Hit position, Vertical Plane",84,-126,126,84,-126,126);
127 
128 
129  TOFPedestalsPlane0 = new TH2F("TOFPedestalsPlane0","TOF Pedestals Plane 0 all PMTs",
130  100,0.,500., 88, 0., 88.);
131  TOFPedestalsPlane1 = new TH2F("TOFPedestalsPlane1","TOF Pedestals Plane 1 all PMTs",
132  100,0.,500., 88, 0., 88.);
133  TOFSignalsRawPlane0 = new TH2F("TOFSignalsRawPlane0","TOF ADC Integral Plane 0 all PMTs",
134  300,0.,10000., 88, 0., 88.);
135  TOFSignalsRawPlane1 = new TH2F("TOFSignalsRawPlane1","TOF ADC Integral Plane 1 all PMTs",
136  300,0.,10000., 88, 0., 88.);
137 
138  TOFTimesPlane0 = new TH2F("TOFTimesPlane0","TOF TDC times Plane 0 all PMTs",
139  800,0.,1000., 88, 0., 88.);
140  TOFTimesPlane1 = new TH2F("TOFTimesPlane1","TOF TDC times Plane 1 all PMTs",
141  800,0.,1000., 88, 0., 88.);
142 
143  TOFWalkExample = new TH2F("TOFWalkEXample", "TOF T-vs-E walk correction example", 200, 10., 24000., 500, 200.,350.);
144 
145  // back to main dir
146  main->cd();
147 
148  return NOERROR;
149 }
150 
151 
152 //----------------------------------------------------------------------------------
153 
154 
155 jerror_t JEventProcessor_TOF_online::brun(JEventLoop *eventLoop, int32_t runnumber) {
156  // This is called whenever the run number changes
157 
158  map<string,double> tdcshift;
159  if (!eventLoop->GetCalib("/TOF/tdc_shift", tdcshift)){
160  TOF_TDC_SHIFT = tdcshift["TOF_TDC_SHIFT"];
161  }
162 
163 
164  return NOERROR;
165 }
166 
167 
168 //----------------------------------------------------------------------------------
169 
170 
171 jerror_t JEventProcessor_TOF_online::evnt(JEventLoop *eventLoop, uint64_t eventnumber) {
172  // This is called for every event. Use of common resources like writing
173  // to a file or filling a histogram should be mutex protected. Using
174  // loop-Get(...) to get reconstructed objects (and thereby activating the
175  // reconstruction algorithm) should be done outside of any mutex lock
176  // since multiple threads may call this method at the same time.
177 
178  uint32_t E,t,pedestal;
179  int plane,bar,end;
180  int count_tdc = 0;
181  int count_adc = 0;
182  double tdc_time,pulse_time;
183 
184  int ExamplePlane = 0;
185  int ExampleBar = 10;
186  int ExampleEnd = 0;
187  int RefFound = 0;
188  float tADC = 0.;
189  float tTDC = 0.;
190  float EADC = 0.;
191 
192  double hit_north[45];
193  double hit_south[45];
194  double hit_up[45];
195  double hit_down[45];
196  double position, time, width;
197  float integral;
198 
199  Float_t distY_Horz = -126; // Horizontal plane start counting from the Bottom to Top
200  Float_t distX_Vert = -126; // Vertical plane start counting from the North to South
201 
202  memset(hit_north,0,sizeof(hit_north));
203  memset(hit_south,0,sizeof(hit_south));
204  memset(hit_up,0,sizeof(hit_up));
205  memset(hit_down,0,sizeof(hit_down));
206 
207  // First determine timing shift to resolve 6-fold ambiguity
208  /*
209  vector<const DCODAEventInfo*> locCODAEventInfo;
210  eventLoop->Get(locCODAEventInfo);
211 
212  if (locCODAEventInfo.size() == 0){
213  return NOERROR;
214  }
215  */
216 
217  vector< const DCAEN1290TDCHit*> CAENHits;
218  eventLoop->Get(CAENHits);
219  if (CAENHits.size()<=0){
220  return NOERROR;
221  }
222  uint32_t locROCID = CAENHits[0]->rocid; // this is the crate we want the trigger time from
223  int indx = -1;
224  vector <const DCODAROCInfo*> ROCS;
225  eventLoop->Get(ROCS);
226  for ( unsigned int n=0; n<ROCS.size(); n++) {
227  if (locROCID == ROCS[n]->rocid){
228  indx = n;
229  break;
230  }
231  }
232  if (indx<0){
233  return NOERROR;
234  }
235 
236  uint64_t TriggerTime = ROCS[indx]->timestamp;
237  int TriggerBIT = TriggerTime%6;
238  float TimingShift = TOF_TDC_SHIFT - (float)TriggerBIT;
239  //cout<<TOF_TDC_SHIFT<<endl;
240  //float TimingShift = -(float)TriggerBIT;
241  if(TimingShift <= 0) {
242  TimingShift += 6.;
243  }
244  TimingShift *= 4. ;
245 
246  // get data for tof
247  vector<const DTOFHit*> dtofhits;
248  eventLoop->Get(dtofhits);
249 
250  // FILL HISTOGRAMS
251  // Since we are filling histograms local to this plugin, it will not interfere with other ROOT operations: can use plugin-wide ROOT fill lock
252  japp->RootFillLock(this); //ACQUIRE ROOT FILL LOCK
253 
254  if(dtofhits.size() > 0)
255  tof_num_events->Fill(1);
256 
257  for(unsigned int i=0; i<dtofhits.size(); i++) {
258  const DTOFHit *dtofhit = dtofhits[i];
259 
260  plane = dtofhit->plane;
261  bar = dtofhit->bar;
262  end = dtofhit->end;
263  E = dtofhit->dE*1000000.; // in MeV
264  t = dtofhit->t; // in nanoseconds
265  time = dtofhit->t; // in nanoseconds
266 
267  const DTOFDigiHit *digi = NULL;
268  const DTOFTDCDigiHit *tdig = NULL;
269 
270  dtofhit->GetSingle(tdig);
271  tdc_time = std::numeric_limits<double>::quiet_NaN(); //updated below if good
272  pulse_time = std::numeric_limits<double>::quiet_NaN(); //updated below if good
273  if(tdig){
274  const uint32_t &Rtdc_time = tdig->time;
275  if(Rtdc_time!=0xFFFF){
276  tdc_time = 0.025*(double)Rtdc_time;
277  if (plane){
278  TOFTimesPlane1->Fill((float)tdc_time, (float)bar-1+end*44);
279  } else {
280  TOFTimesPlane0->Fill((float)tdc_time, (float)bar-1+end*44);
281  }
282  }
283 
284  if ( (plane == ExamplePlane) &&
285  (bar == ExampleBar) &&
286  (end == ExampleEnd)){
287  tTDC = (float)tdig->time * 0.0234375;
288  RefFound++;
289  }
290 
291  }
292 
293  dtofhit->GetSingle(digi);
294  pedestal = 0xFFFF;
295  if (digi){
296  const uint32_t &Rpedestal = digi->pedestal;
297  const uint32_t &Rpulse_time = digi->pulse_time;
298  if(Rpedestal!=0xFFFF && Rpulse_time!=0xFFFF){
299  pedestal = Rpedestal;
300  pulse_time = 0.0625*(double)Rpulse_time;
301  integral = (float)digi->pulse_integral - (float)digi->pedestal*
302  (float)digi->nsamples_integral/(float)digi->nsamples_pedestal;
303  integral /= (float)digi->nsamples_integral;
304  integral *=10.;
305  if (plane){
306  TOFPedestalsPlane1->Fill((float)pedestal,(float)bar-1+end*44);
307  TOFSignalsRawPlane1->Fill(integral, (float)bar-1+end*44);
308  } else {
309  TOFPedestalsPlane0->Fill((float)pedestal,(float)bar-1+end*44);
310  TOFSignalsRawPlane0->Fill(integral, (float)bar-1+end*44);
311  }
312  }
313 
314  if ( (plane == ExamplePlane) &&
315  (bar == ExampleBar) &&
316  (end == ExampleEnd)){
317  tADC = (float)digi->pulse_time * 0.0625;
318  EADC = (float)digi->pulse_integral - (float)digi->pedestal*
319  (float)digi->nsamples_integral/(float)digi->nsamples_pedestal;
320  RefFound++;
321  }
322  }
323 
324 
325  if(dtofhits[i]->dE>0.0) {
326 
327 
328  // fill hist
329 
330  tofe->Fill(E);
331  toft->Fill(t);
332  if(plane==0) { // vertical, North is 0
333  tofo1->Fill(bar,end);
334  } else {
335  tofo2->Fill(end,bar);
336  }
337 
338  } // close if E>0
339 
340  if (dtofhit->has_fADC) hTimeAdc->Fill(pulse_time);
341  if (dtofhit->has_TDC) hTimeTdc->Fill(tdc_time);
342 
343  switch(plane)
344  {
345  case 0:
346  if(end == 1){
347  //cout << "Down : " << bar << endl;
348  if (dtofhit->has_fADC){
349  if (pedestal!=0xFFFF) histPed->Fill(pedestal);
350  adcOccD->Fill(bar);
351  count_adc++;
352  }
353  if (dtofhit->has_TDC){
354  tdcOccD->Fill(bar);
355  count_tdc++;
356  if ( ( (hit_down[bar]<=0) || (t < hit_down[bar]) ) && (bar!=22 || bar!=23) ){
357  hit_down[bar] = time;
358  }
359  }
360  }
361  else if(end == 0){
362  //cout << "Up : " << bar << endl;
363  if (dtofhit->has_fADC){
364  if (pedestal!=0xFFFF) histPed->Fill(pedestal);
365  adcOccU->Fill(bar);
366  count_adc++;
367  }
368  if (dtofhit->has_TDC){
369  tdcOccU->Fill(bar);
370  count_tdc++;
371  if ( ( (hit_up[bar]<=0) || (t < hit_up[bar]) ) && (bar!=22 || bar!=23) ){
372  hit_up[bar] = time;
373  }
374  }
375  }
376  break;
377  case 1:
378  if(end == 0){
379  //cout << "North : " << bar << endl;
380  if (dtofhit->has_fADC){
381  if (pedestal!=0xFFFF) histPed->Fill(pedestal);
382  adcOccN->Fill(bar);
383  count_adc++;
384  }
385  if (dtofhit->has_TDC){
386  tdcOccN->Fill(bar);
387  count_tdc++;
388  if ( ( (hit_north[bar]<=0) || (t < hit_north[bar]) ) && (bar!=22 || bar!=23) ){
389  hit_north[bar] = time;
390  }
391  }
392  }
393  else if(end == 1){
394  //cout << "South : " << bar << endl;
395  if (dtofhit->has_fADC){
396  if (pedestal!=0xFFFF) histPed->Fill(pedestal);
397  adcOccS->Fill(bar);
398  count_adc++;
399  }
400  if (dtofhit->has_TDC){
401  tdcOccS->Fill(bar);
402  count_tdc++;
403  if ( ( (hit_south[bar]<=0) || (t < hit_south[bar]) ) && (bar!=22 || bar!=23) ){
404  hit_south[bar] = time;
405  }
406  }
407  }
408  break;
409  }
410 
411  } // close DTOFHit size
412 
413  if (RefFound>1){
414  TOFWalkExample->Fill(EADC, (tTDC-tADC+TimingShift));
415  }
416 
417 
418  for (int i=1; i<45; i++)
419  {
420 
421  if ( i == 20 || i == 21 || i == 24 || i == 25 ){
422  distY_Horz = distY_Horz + 1.5;
423  distX_Vert = distX_Vert + 1.5;
424  width = 3.0;
425  }
426  else{
427  distY_Horz = distY_Horz + 3;
428  distX_Vert = distX_Vert + 3;
429  width = 6.0;
430  }
431 
432  if( hit_south[i]>0 && hit_north[i]>0 )
433  {
434  position = (15.2*(Float_t(hit_south[i] - hit_north[i])/2) );
435  distY_Horz = distY_Horz + (drand48()-0.5)*width;
436  if (position )planeHor->Fill(position,distY_Horz);
437  }
438 
439  if( hit_up[i]>0 && hit_down[i]>0 )
440  {
441  position = (15.2*(Float_t(hit_up[i] - hit_down[i])/2) );
442  distX_Vert = distX_Vert + (drand48()-0.5)*width;
443  planeVer->Fill(distX_Vert,position);
444  }
445 
446  if ( i == 20 || i == 21 || i == 24 || i == 25 ){
447  distY_Horz = distY_Horz + 1.5;
448  distX_Vert = distX_Vert + 1.5;
449  }
450  else{
451  distY_Horz = distY_Horz + 3;
452  distX_Vert = distX_Vert + 3;
453  }
454 
455  }
456 
457  japp->RootFillUnLock(this); //RELEASE ROOT FILL LOCK
458 
459  return NOERROR;
460 }
461 
462 
463 //----------------------------------------------------------------------------------
464 
465 
467  // This is called whenever the run number changes, before it is
468  // changed to give you a chance to clean up before processing
469  // events from the next run number.
470  return NOERROR;
471 }
472 
473 
474 //----------------------------------------------------------------------------------
475 
476 
478  // Called before program exit after event processing is finished.
479  return NOERROR;
480 }
481 
482 
483 //----------------------------------------------------------------------------------
484 //----------------------------------------------------------------------------------
static TH1I * tdcOccN
static TH2F * TOFSignalsRawPlane0
static TH2F * TOFTimesPlane0
static TH2I * tofo1
static TH1I * adcOccD
int end
Definition: DTOFHit.h:23
if(locHist_BCALShowerPhiVsZ!=NULL)
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
static TH1I * adcOccN
static TH1I * hTimeTdc
uint32_t pedestal
pedestal info used by FPGA (if any)
Definition: DTOFDigiHit.h:23
static TH1I * adcOccU
int plane
Definition: DTOFHit.h:21
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
bool has_fADC
Definition: DTOFHit.h:29
static TH2F * TOFWalkExample
static TH2I * tofo2
static TH2F * TOFSignalsRawPlane1
uint32_t nsamples_integral
number of samples used in integral
Definition: DTOFDigiHit.h:25
static TH1I * tdcOccD
static TH1I * tof_num_events
static TH2I * planeHor
float t
Definition: DTOFHit.h:28
JApplication * japp
static TH2F * TOFPedestalsPlane1
static TH1I * tdcOccS
InitPlugin_t InitPlugin
static TH1I * hTimeAdc
uint32_t nsamples_pedestal
number of samples used in pedestal
Definition: DTOFDigiHit.h:26
static TH2F * TOFTimesPlane1
bool has_TDC
Definition: DTOFHit.h:30
int bar
Definition: DTOFHit.h:22
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
static TH2I * planeVer
static TH1I * pedestal[nChan]
uint32_t pulse_time
identified pulse time as returned by FPGA algorithm
Definition: DTOFDigiHit.h:22
static TH1I * adcOccS
File: DTOFHit.h Created: Tue Jan 18 16:15:26 EST 2011 Creator: B. Zihlmann Purpose: Container class t...
Definition: DTOFHit.h:16
jerror_t fini(void)
Called after last event of last event source has been processed.
static TH1I * tofe
jerror_t init(void)
Called once at program start.
uint32_t time
hit time
static TH2F * TOFPedestalsPlane0
float dE
Definition: DTOFHit.h:24
int main(int argc, char *argv[])
Definition: gendoc.cc:6
static TH1I * tdcOccU
static TH1I * histPed
static TH1I * toft
uint32_t pulse_integral
identified pulse integral as returned by FPGA algorithm
Definition: DTOFDigiHit.h:21