Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_event_size.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_event_size.cc
4 // Created: Tue Jun 7 10:07:36 EDT 2011
5 // Creator: davidl (on Darwin eleanor.jlab.org 10.7.0 i386)
6 //
7 
9 using namespace jana;
10 
11 // From level1_trigger plugin
13 
14 #include <PID/DBeamPhoton.h>
15 #include <BCAL/DBCALHit.h>
16 #include <FCAL/DFCALHit.h>
17 #include <CCAL/DCCALHit.h>
18 #include <CDC/DCDCHit.h>
19 #include <FDC/DFDCHit.h>
20 #include <TOF/DTOFRawHit.h>
21 #include <START_COUNTER/DSCHit.h>
22 #include <TAGGER/DTAGMHit.h>
23 #include <TAGGER/DTAGHHit.h>
24 
25 // Routine used to create our JEventProcessor
26 #include <JANA/JApplication.h>
27 extern "C"{
28 void InitPlugin(JApplication *app){
29  InitJANAPlugin(app);
30  app->AddProcessor(new JEventProcessor_event_size());
31 }
32 } // "C"
33 
34 
35 //------------------
36 // JEventProcessor_event_size (Constructor)
37 //------------------
39 {
40 
41 }
42 
43 //------------------
44 // ~JEventProcessor_event_size (Destructor)
45 //------------------
47 {
48 
49 }
50 
51 //------------------
52 // init
53 //------------------
55 {
56  evt_tree = new TTree("event","Event Size info");
57  evt = new Event();
58  evt_tree->Branch("A", &evt);
59  pthread_mutex_init(&evt_mutex, NULL);
60 
61  fdc_cathode_tree = new TTree("fdc_cathode","FDC Cathode hit info");
62  fdc_cathode = new FDC_cathode();
63  fdc_cathode_tree->Branch("A", &fdc_cathode);
64  pthread_mutex_init(&fdc_mutex, NULL);
65 
66  fdc_anode_tree = new TTree("fdc_anode","FDC Anode hit info");
67  fdc_anode = new FDC_anode();
68  fdc_anode_tree->Branch("A", &fdc_anode);
69 
70  cdc_tree = new TTree("cdc","CDC hit info");
71  cdc = new CDC();
72  cdc_tree->Branch("A", &cdc);
73  pthread_mutex_init(&cdc_mutex, NULL);
74 
75  fcal_tree = new TTree("fcal","FCAL hit info");
76  fcal = new FCAL();
77  fcal_tree->Branch("A", &fcal);
78  pthread_mutex_init(&fcal_mutex, NULL);
79 
80  tof_tree = new TTree("tof","TOF hit info");
81  tof = new TOF();
82  tof_tree->Branch("A", &tof);
83  pthread_mutex_init(&tof_mutex, NULL);
84 
85  toffset_bcal = 25.0; // ns (lead time before trigger)
86  twindow_bcal = 125.0; // ns (full window width)
87  toffset_fcal = 25.0; // ns (lead time before trigger)
88  twindow_fcal = 125.0; // ns (full window width)
89  toffset_ccal = 25.0; // ns (lead time before trigger)
90  twindow_ccal = 125.0; // ns (full window width)
91  toffset_cdc = 25.0; // ns (lead time before trigger)
92  twindow_cdc = 500.0; // ns (full window width)
93  toffset_fdc = 25.0; // ns (lead time before trigger)
94  twindow_fdc = 500.0; // ns (full window width)
95  toffset_tof = 25.0; // ns (lead time before trigger)
96  twindow_tof = 125.0; // ns (full window width)
97  toffset_sc = 25.0; // ns (lead time before trigger)
98  twindow_sc = 125.0; // ns (full window width)
99  toffset_tagger = 25.0; // ns (lead time before trigger)
100  twindow_tagger = 125.0; // ns (full window width)
101 
102  gPARMS->SetDefaultParameter("EVENTSIZE:toffset_bcal", toffset_bcal, "Time offset used to determine BCAL event size");
103  gPARMS->SetDefaultParameter("EVENTSIZE:twindow_bcal", twindow_bcal, "Time window used to determine BCAL event size");
104  gPARMS->SetDefaultParameter("EVENTSIZE:toffset_fcal", toffset_fcal, "Time offset used to determine FCAL event size");
105  gPARMS->SetDefaultParameter("EVENTSIZE:twindow_fcal", twindow_fcal, "Time window used to determine FCAL event size");
106  gPARMS->SetDefaultParameter("EVENTSIZE:toffset_ccal", toffset_ccal, "Time offset used to determine CCAL event size");
107  gPARMS->SetDefaultParameter("EVENTSIZE:twindow_ccal", twindow_ccal, "Time window used to determine CCAL event size");
108  gPARMS->SetDefaultParameter("EVENTSIZE:toffset_cdc", toffset_cdc, "Time offset used to determine CDC event size");
109  gPARMS->SetDefaultParameter("EVENTSIZE:twindow_cdc", twindow_cdc, "Time window used to determine CDC event size");
110  gPARMS->SetDefaultParameter("EVENTSIZE:toffset_fdc", toffset_fdc, "Time offset used to determine FDC event size");
111  gPARMS->SetDefaultParameter("EVENTSIZE:twindow_fdc", twindow_fdc, "Time window used to determine FDC event size");
112  gPARMS->SetDefaultParameter("EVENTSIZE:toffset_tof", toffset_tof, "Time offset used to determine TOF event size");
113  gPARMS->SetDefaultParameter("EVENTSIZE:twindow_tof", twindow_tof, "Time window used to determine TOF event size");
114  gPARMS->SetDefaultParameter("EVENTSIZE:toffset_sc", toffset_sc, "Time offset used to determine Start Counter event size");
115  gPARMS->SetDefaultParameter("EVENTSIZE:twindow_sc", twindow_sc, "Time window used to determine Start Counter event size");
116  gPARMS->SetDefaultParameter("EVENTSIZE:toffset_tagger", toffset_tagger, "Time offset used to determine TAGGER event size");
117  gPARMS->SetDefaultParameter("EVENTSIZE:twindow_tagger", twindow_tagger, "Time window used to determine TAGGER event size");
118 
119  // Calculate limits from offset and window width
120  tmin_bcal = -toffset_bcal;
121  tmax_bcal = tmin_bcal + twindow_bcal;
122  tmin_fcal = -toffset_fcal;
123  tmax_fcal = tmin_fcal + twindow_fcal;
124  tmin_ccal = -toffset_ccal;
125  tmax_ccal = tmin_ccal + twindow_ccal;
126  tmin_cdc = -toffset_cdc;
127  tmax_cdc = tmin_cdc + twindow_cdc;
128  tmin_fdc = -toffset_fdc;
129  tmax_fdc = tmin_fdc + twindow_fdc;
130  tmin_tof = -toffset_tof;
131  tmax_tof = tmin_tof + twindow_tof;
132  tmin_sc = -toffset_sc;
133  tmax_sc = tmin_sc + twindow_sc;
134  tmin_tagger = -toffset_tagger;
135  tmax_tagger = tmin_tagger + twindow_tagger;
136 
137  return NOERROR;
138 }
139 
140 //------------------
141 // brun
142 //------------------
143 jerror_t JEventProcessor_event_size::brun(JEventLoop *eventLoop, int32_t runnumber)
144 {
145  // load BCAL geometry
146  vector<const DBCALGeometry *> BCALGeomVec;
147  loop->Get(BCALGeomVec);
148  if(BCALGeomVec.size() == 0)
149  throw JException("Could not load DBCALGeometry object!");
150  const DBCALGeometry *dBCALGeom = BCALGeomVec[0];
151 
152  dBCALMid = dBCALGeom->GetBCAL_middle_cell(); // THIS IS PROBABLY WRONG!!!
153  // This is called whenever the run number changes
154  return NOERROR;
155 }
156 
157 //------------------
158 // evnt
159 //------------------
160 jerror_t JEventProcessor_event_size::evnt(JEventLoop *loop, uint64_t eventnumber)
161 {
162  // Ignore events with no Level 1 trigger info
163  const DTrigger *trig=NULL;
164  try{
165  loop->GetSingle(trig);
166  }catch(...){
167  return NOERROR;
168  };
169 
170  // Get hit data objects
171  vector<const DBeamPhoton*> beamphotons;
172  vector<const DBCALHit*> bcalhits;
173  vector<const DFCALHit*> fcalhits;
174  vector<const DCCALHit*> ccalhits;
175  vector<const DCDCHit*> cdchits;
176  vector<const DFDCHit*> fdchits;
177  vector<const DTOFRawHit*> tofhits;
178  vector<const DSCHit*> schits;
179  vector<const DTAGMHit*> tagmhits;
180  vector<const DTAGHHit*> taghhits;
181 
182  loop->Get(beamphotons);
183  loop->Get(bcalhits);
184  loop->Get(fcalhits);
185  loop->Get(ccalhits);
186  loop->Get(cdchits);
187  loop->Get(fdchits);
188  loop->Get(tofhits);
189  loop->Get(schits);
190  loop->Get(tagmhits);
191  loop->Get(taghhits);
192 
193  // Count inner and outer BCAL hits
194  unsigned int Nbcalhits_inner = 0;
195  unsigned int Nbcalhits_outer = 0;
196  for(unsigned int i=0; i<bcalhits.size(); i++){
197 
198  // Apply time window
199  if(bcalhits[i]->t < tmin_bcal)continue;
200  if(bcalhits[i]->t > tmax_bcal)continue;
201 
202  if(bcalhits[i]->layer < dBCALMid){
203  Nbcalhits_inner++;
204  }else{
205  Nbcalhits_outer++;
206  }
207  }
208 
209  // Although we are only filling objects local to this plugin, TTree::Fill() periodically writes to file: Global ROOT lock
210  japp->RootWriteLock(); //ACQUIRE ROOT LOCK
211 
212  // Count FCAL hits
213  unsigned int Nfcalhits = 0;
214  for(unsigned int i=0; i<fcalhits.size(); i++){
215  // Apply time window
216  if(fcalhits[i]->t < tmin_fcal)continue;
217  if(fcalhits[i]->t > tmax_fcal)continue;
218 
219  fcal->L1a_fired = trig->L1a_fired;
220  fcal->L1b_fired = trig->L1b_fired;
221  fcal->row = fcalhits[i]->row;
222  fcal->column = fcalhits[i]->column;
223  fcal_tree->Fill();
224 
225  Nfcalhits++;
226  }
227 
228  // Count CCAL hits
229  unsigned int Nccalhits = 0;
230  for(unsigned int i=0; i<ccalhits.size(); i++){
231  // Apply time window
232  if(ccalhits[i]->t < tmin_ccal)continue;
233  if(ccalhits[i]->t > tmax_ccal)continue;
234 
235  Nccalhits++;
236  }
237 
238  // Count CDC hits
239  unsigned int Ncdchits = 0;
240  for(unsigned int i=0; i<cdchits.size(); i++){
241  // Apply time window
242  if(cdchits[i]->t < tmin_cdc)continue;
243  if(cdchits[i]->t > tmax_cdc)continue;
244 
245  cdc->L1a_fired = trig->L1a_fired;
246  cdc->L1b_fired = trig->L1b_fired;
247  cdc->ring = cdchits[i]->ring;
248  cdc->straw = cdchits[i]->straw;
249  cdc_tree->Fill();
250 
251  Ncdchits++;
252  }
253 
254  // Count FDC wire and FDC strip hits
255  unsigned int Nfdchits_anode = 0;
256  unsigned int Nfdchits_cathode = 0;
257  for(unsigned int i=0; i<fdchits.size(); i++){
258 
259  // Apply time window
260  if(fdchits[i]->t < tmin_fdc)continue;
261  if(fdchits[i]->t > tmax_fdc)continue;
262 
263  if(fdchits[i]->type == 1){
264  Nfdchits_cathode++;
265 
266  fdc_cathode->L1a_fired = trig->L1a_fired;
267  fdc_cathode->L1b_fired = trig->L1b_fired;
268  fdc_cathode->gPlane = fdchits[i]->gPlane;
269  fdc_cathode->element = fdchits[i]->element;
270  fdc_cathode_tree->Fill();
271  }else{
272  fdc_anode->L1a_fired = trig->L1a_fired;
273  fdc_anode->L1b_fired = trig->L1b_fired;
274  fdc_anode->gPlane = fdchits[i]->gPlane;
275  fdc_anode->element = fdchits[i]->element;
276  fdc_anode_tree->Fill();
277  Nfdchits_anode++;
278  }
279  }
280 
281  // Count TOF hits
282  unsigned int Ntofhits = 0;
283  for(unsigned int i=0; i<tofhits.size(); i++){
284  // Apply time window
285  if(tofhits[i]->t < tmin_tof)continue;
286  if(tofhits[i]->t > tmax_tof)continue;
287 
288  tof->plane = tofhits[i]->plane;
289  tof->bar = tofhits[i]->bar;
290  tof->lr = tofhits[i]->lr;
291  tof_tree->Fill();
292 
293  Ntofhits++;
294  }
295 
296  // Count Start Counter hits
297  unsigned int Nschits = 0;
298  for(unsigned int i=0; i<schits.size(); i++){
299  // Apply time window
300  if(schits[i]->t < tmin_sc)continue;
301  if(schits[i]->t > tmax_sc)continue;
302 
303  Nschits++;
304  }
305 
306  // Count Tagger hits
307  unsigned int Ntagmhits = 0;
308  for(unsigned int i=0; i<tagmhits.size(); i++){
309  // Apply time window
310  if(tagmhits[i]->t < tmin_tagger)continue;
311  if(tagmhits[i]->t > tmax_tagger)continue;
312 
313  Ntagmhits++;
314  }
315  unsigned int Ntaghhits = 0;
316  for(unsigned int i=0; i<taghhits.size(); i++){
317  // Apply time window
318  if(taghhits[i]->t < tmin_tagger)continue;
319  if(taghhits[i]->t > tmax_tagger)continue;
320 
321  Ntaghhits++;
322  }
323 
324  evt->event = eventnumber;
325  evt->Egamma = beamphotons.size()>0 ? beamphotons[0]->momentum().Mag():0.0;
326  evt->L1a_fired = trig->L1a_fired;
327  evt->L1b_fired = trig->L1b_fired;
328  evt->Ebcal_trig = trig->Ebcal;
329  evt->Efcal_trig = trig->Efcal;
330  evt->Nsc_trig = trig->Nschits;
331 
332  evt->Nbcalhits_inner = Nbcalhits_inner;
333  evt->Nbcalhits_outer = Nbcalhits_outer;
334  evt->Nfcalhits = Nfcalhits;
335  evt->Nccalhits = Nccalhits;
336  evt->Ncdchits = Ncdchits;
337  evt->Nfdchits_anode = Nfdchits_anode;
338  evt->Nfdchits_cathode = Nfdchits_cathode;
339  evt->Ntofhits = Ntofhits;
340  evt->Nschits = Nschits;
341  evt->Ntagmhits = Ntagmhits;
342  evt->Ntaghhits = Ntaghhits;
343 
344  evt->Ndigitized_values = 0;
345  evt->Ndigitized_values += 3*evt->Nbcalhits_inner; // fADC and TDC
346  evt->Ndigitized_values += 2*evt->Nbcalhits_outer; // fADC only
347  evt->Ndigitized_values += 2*evt->Nfcalhits; // fADC only
348  evt->Ndigitized_values += 2*evt->Nccalhits; // fADC only
349  evt->Ndigitized_values += 2*evt->Ncdchits; // fADC only
350  evt->Ndigitized_values += 1*evt->Nfdchits_anode; // TDC only
351  evt->Ndigitized_values += 2*evt->Nfdchits_cathode; // fADC only
352  evt->Ndigitized_values += 3*evt->Ntofhits; // fADC and TDC
353  evt->Ndigitized_values += 3*evt->Nschits; // fADC and TDC
354  evt->Ndigitized_values += 3*evt->Ntagmhits; // fADC and TDC
355  evt->Ndigitized_values += 3*evt->Ntaghhits; // fADC and TDC
356 
357  // Fill event tree
358  evt_tree->Fill();
359 
360  japp->RootUnLock(); //RELEASE ROOT LOCK
361 
362  return NOERROR;
363 }
364 
365 //------------------
366 // erun
367 //------------------
369 {
370  // This is called whenever the run number changes, before it is
371  // changed to give you a chance to clean up before processing
372  // events from the next run number.
373  return NOERROR;
374 }
375 
376 //------------------
377 // fini
378 //------------------
380 {
381  // Called before program exit after event processing is finished.
382  return NOERROR;
383 }
384 
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
Int_t layer
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
trig[33-1]
Definition: CDC.h:14
JApplication * japp
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
InitPlugin_t InitPlugin
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t init(void)
Called once at program start.
Definition: FCAL.h:14
float GetBCAL_middle_cell() const
Definition: DBCALGeometry.h:45
Definition: TOF.h:14