Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_L3BDTtree.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_L3BDTtree.cc
4 // Created: Wed May 11 22:26:46 EDT 2016
5 // Creator: davidl (on Linux gluon49.jlab.org 2.6.32-431.20.3.el6.x86_64 x86_64)
6 //
7 
8 
10 using namespace jana;
11 
12 #include <TMath.h>
13 
14 
15 
16 // Routine used to create our JEventProcessor
17 #include <JANA/JApplication.h>
18 #include <JANA/JFactory.h>
19 extern "C"{
20 void InitPlugin(JApplication *app){
21  InitJANAPlugin(app);
22  app->AddProcessor(new JEventProcessor_L3BDTtree());
23 }
24 } // "C"
25 
26 
27 
28 
29 //------------------
30 // JEventProcessor_L3BDTtree (Constructor)
31 //------------------
33 {
34 
35 }
36 
37 //------------------
38 // ~JEventProcessor_L3BDTtree (Destructor)
39 //------------------
41 {
42 
43 }
44 
45 //------------------
46 // init
47 //------------------
49 {
50 
51  // Create Tree
52  l3tree = new TTree("l3tree", "L3 tree for BDT");
53 
54  // Add branches for all JANA object counts
55  #define AddNBranch(A) l3tree->Branch("N" #A, &bdt.N##A, #A "/F");
57 
58  // Add branches for all sorted float types
59  #define AddBranch(A) l3tree->Branch(#A, &bdt.A, #A "/F");
61 
62  return NOERROR;
63 }
64 
65 //------------------
66 // brun
67 //------------------
68 jerror_t JEventProcessor_L3BDTtree::brun(JEventLoop *eventLoop, int32_t runnumber)
69 {
70  // This is called whenever the run number changes
71  return NOERROR;
72 }
73 
74 //------------------
75 // evnt
76 //------------------
77 jerror_t JEventProcessor_L3BDTtree::evnt(JEventLoop *loop, uint64_t eventnumber)
78 {
79 
80  // Get all JANA objects of interest
81  #define GetObjs(A) vector<const A*> v##A; loop->Get(v##A);
83 
84  // Trigger
85  Int_t trig_mask = 0;
86  Int_t fp_trig_mask = 0;
87  Float_t trig1 = 0.0;
88  Float_t trig3 = 0.0;
89  Float_t trig4 = 0.0;
90  if(!vDL1Trigger.empty()){
91  auto trig = vDL1Trigger[0];
92  trig_mask = trig->trig_mask;
93  fp_trig_mask = trig->fp_trig_mask;
94  if(trig_mask&0x01) trig1 = 1.0;
95  if(trig_mask&0x04) trig3 = 1.0;
96  if(trig_mask&0x08) trig4 = 1.0;
97  }
98 
99  // CDC hits by superlayer
100  Int_t NCDC_superlayer[5] = {0,0,0,0,0};
101  vector<int> superlayer_maxring = { 4, 12, 16, 24, 28 };
102  for(auto hit : vDCDCDigiHit){
103  for(int superlayer=0; superlayer<5; superlayer++){
104  if(hit->ring <= superlayer_maxring[superlayer]){
105  NCDC_superlayer[superlayer]++;
106  break;
107  }
108  }
109  }
110 
111  // FDC wire hits by package
112  Int_t NFDCWire_package[4] = {0,0,0,0};
113  for(auto hit : vDFDCWireDigiHit){
114  if(hit->package>=1 && hit->package<=4) NFDCWire_package[hit->package-1]++;
115  }
116 
117  // FDC cathode hits by package
118  Int_t NFDCCathodes_package[4] = {0,0,0,0};
119  for(auto hit : vDFDCCathodeDigiHit){
120  if(hit->package>=1 && hit->package<=4) NFDCCathodes_package[hit->package-1]++;
121  }
122 
123  // TOF half-length, half-width bars
124  Int_t NTOF_half_length = 0;
125  Int_t NTOF_half_width = 0;
126  for(auto hit : vDTOFDigiHit){
127  auto &bar = hit->bar;
128  if(bar==22 || bar==23 || bar==45 || bar==46) NTOF_half_length++;
129  if(bar==20 || bar==21 || bar==24 || bar==25) NTOF_half_width++;
130  }
131 
132  // Various total energies
133  Float_t Esc_tot = 0.0;
134  Float_t Etof_tot = 0.0;
135  Float_t Ebcal_points = 0.0;
136  Float_t Ebcal_clusters = 0.0;
137  Float_t Efcal_clusters = 0.0;
138  for(auto sc : vDSCHit ) Esc_tot += sc->dE;
139  for(auto th : vDTOFPoint ) Etof_tot += th->dE;
140  for(auto bp : vDBCALPoint ) Ebcal_points += bp->E();
141  for(auto bc : vDBCALCluster) Ebcal_clusters += bc->E();
142  for(auto fc : vDFCALCluster) Efcal_clusters += fc->getEnergy();
143 
144  // FCAL Rmin and Rmax (for Eugene)
145  Float_t Rfcal_min = 10000.0;
146  Float_t Rfcal_max = 0.0;
147  for(auto fc : vDFCALCluster){
148  Float_t r = fc->getCentroid().Perp();
149  if( r < Rfcal_min ) Rfcal_min = r;
150  if( r > Rfcal_max ) Rfcal_max = r;
151  }
152 
153  // Beam photons
154  Int_t Nbeam_photons_coherent = 0.0;
155  vector<Int_t> Nbeam_photons(13, 0.0);
156  double Eelectron = 11.668;
157  double Ecoherent_min = 8.4*Eelectron/12.0;
158  double Ecoherent_max = 9.0*Eelectron/12.0;
159  for(auto p : vDBeamPhoton){
160  double Ephoton = p->energy();
161  int idx = floor(Ephoton);
162  if(idx>=0 && idx<=12) Nbeam_photons[idx]++;
163  if( (Ephoton>=Ecoherent_min) && (Ephoton<=Ecoherent_max) ) Nbeam_photons_coherent++;
164  }
165 
166  // Ptot for candidates
167  double Ptot_candidates = 0.0;
168  for(auto tc : vDTrackCandidate) Ptot_candidates += tc->momentum().Mag();
169 
170  // Visible energy
171  Float_t Evisible_neutrals = 0.0;
172  Float_t Evisible_tracks = 0.0;
173  Float_t Evisible_charged_Kaons = 0.0;
174  Float_t Evisible_charged_pions = 0.0;
175  Float_t Evisible_protons = 0.0;
176  Float_t Evisible = 0.0;
177  for(auto ct : vDChargedTrack){
178  auto cth = ct->Get_BestTrackingFOM();
179  double confidence_level = TMath::Prob((double)cth->dChiSq, (double)cth->dNDF);
180  if(confidence_level > 0.0001){
181  Float_t E = cth->energy();
182  switch(cth->PID()){
183  case PiPlus:
184  case PiMinus:
185  Evisible_charged_pions += E;
186  break;
187  case KPlus:
188  case KMinus:
189  Evisible_charged_Kaons += E;
190  break;
191  case Proton:
192  Evisible -= cth->mass(); // Do not include proton mass in visible energy
193  case AntiProton:
194  Evisible_protons += E;
195  break;
196  default:
197  break;
198  }
199 
200  Evisible_tracks += E;
201  Evisible += E;
202  }
203  }
204 
205  // Add neutral energy
206  for(auto ns : vDNeutralShower){
207  Evisible_neutrals += ns->dEnergy;
208  Evisible += ns->dEnergy;
209  }
210 
211  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
212  // Get ROOT lock
213  japp->RootWriteLock();
214 
215  // Copy all object counts
216  #define CopyNobjs(A) bdt.N##A = (Float_t)v##A.size();
218 
219  // L1 trigger
220  bdt.trig_mask = (Float_t)trig_mask;
221  bdt.fp_trig_mask = (Float_t)fp_trig_mask;
222  bdt.trig1 = trig1;
223  bdt.trig3 = trig3;
224  bdt.trig4 = trig4;
225 
226  // CDC hits by superlayer
227  bdt.NCDC_superlayer1 = (Float_t)NCDC_superlayer[0];
228  bdt.NCDC_superlayer2 = (Float_t)NCDC_superlayer[1];
229  bdt.NCDC_superlayer3 = (Float_t)NCDC_superlayer[2];
230  bdt.NCDC_superlayer4 = (Float_t)NCDC_superlayer[3];
231  bdt.NCDC_superlayer5 = (Float_t)NCDC_superlayer[4];
232 
233  // FDC wire hits by package
234  bdt.NFDCwires_package1 = (Float_t)NFDCWire_package[0];
235  bdt.NFDCwires_package2 = (Float_t)NFDCWire_package[1];
236  bdt.NFDCwires_package3 = (Float_t)NFDCWire_package[2];
237  bdt.NFDCwires_package4 = (Float_t)NFDCWire_package[3];
238 
239  // FDC cathode hits by package
240  bdt.NFDCCathodes_package1 = (Float_t)NFDCCathodes_package[0];
241  bdt.NFDCCathodes_package2 = (Float_t)NFDCCathodes_package[1];
242  bdt.NFDCCathodes_package3 = (Float_t)NFDCCathodes_package[2];
243  bdt.NFDCCathodes_package4 = (Float_t)NFDCCathodes_package[3];
244 
245  // TOF half-length, half-width bars
246  bdt.NTOF_half_length = (Float_t)NTOF_half_length;
247  bdt.NTOF_half_width = (Float_t)NTOF_half_width;
248 
249  // Various total energies
250  bdt.Esc_tot = Esc_tot;
251  bdt.Etof_tot = Etof_tot;
252  bdt.Ebcal_points = Ebcal_points;
253  bdt.Ebcal_clusters = Ebcal_clusters;
254  bdt.Efcal_clusters = Efcal_clusters;
255 
256  // FCAL Rmin and Rmax (for Eugene)
257  bdt.Rfcal_min = Rfcal_min;
258  bdt.Rfcal_max = Rfcal_max;
259 
260  // Beam photons
261  bdt.Nbeam_photons_coherent = Nbeam_photons_coherent;
262  bdt.Nbeam_photons_3_4 = (Float_t)Nbeam_photons[ 3];
263  bdt.Nbeam_photons_4_5 = (Float_t)Nbeam_photons[ 4];
264  bdt.Nbeam_photons_5_6 = (Float_t)Nbeam_photons[ 5];
265  bdt.Nbeam_photons_6_7 = (Float_t)Nbeam_photons[ 6];
266  bdt.Nbeam_photons_7_8 = (Float_t)Nbeam_photons[ 7];
267  bdt.Nbeam_photons_8_9 = (Float_t)Nbeam_photons[ 8];
268  bdt.Nbeam_photons_9_10 = (Float_t)Nbeam_photons[ 9];
269  bdt.Nbeam_photons_10_11 = (Float_t)Nbeam_photons[10];
270  bdt.Nbeam_photons_11_12 = (Float_t)Nbeam_photons[11];
271 
272  // Ptot for candidates
273  bdt.Ptot_candidates = Ptot_candidates;
274 
275  // Visible energy
276  bdt.Evisible_neutrals = Evisible_neutrals;
277  bdt.Evisible_tracks = Evisible_tracks;
278  bdt.Evisible_charged_Kaons = Evisible_charged_Kaons;
279  bdt.Evisible_charged_pions = Evisible_charged_pions;
280  bdt.Evisible_protons = Evisible_protons;
281  bdt.Evisible = Evisible;
282 
283  // Fill tree
284  l3tree->Fill();
285 
286  // Release ROOT lock
287  japp->RootUnLock();
288 
289  //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
290 
291 
292  return NOERROR;
293 }
294 
295 //------------------
296 // erun
297 //------------------
299 {
300  japp->RootWriteLock();
301  l3tree->FlushBaskets();
302  japp->RootUnLock();
303 
304  return NOERROR;
305 }
306 
307 //------------------
308 // fini
309 //------------------
311 {
312  japp->RootWriteLock();
313  l3tree->FlushBaskets();
314  japp->RootUnLock();
315 
316  return NOERROR;
317 }
318 
jerror_t init(void)
Called once at program start.
#define AddNBranch(A)
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
trig[33-1]
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
#define AddBranch(A)
#define CopyNobjs(A)
JApplication * japp
#define GetObjs(A)
InitPlugin_t InitPlugin
#define MyDerivedTypes(X)
Definition: DParsedEvent.h:116
#define MyTypes(X)
Definition: DParsedEvent.h:77
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.