Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_cal_high_energy_skim.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_cal_high_energy_skim.cc
4 // Created: Mon Dec 1 14:57:11 EST 2014 (copied structure from pi0fcalskim plugin)
5 // Creator: wmcginle (on Linux ifarm1101 2.6.32-220.7.1.el6.x86_64 x86_64)
6 //
7 
8 #include <math.h>
9 #include <TLorentzVector.h>
10 #include <vector>
11 #include <deque>
12 #include <string>
13 #include <iostream>
14 #include <algorithm>
15 #include <stdio.h>
16 #include <stdlib.h>
18 
19 
20 #include "TRACKING/DMCThrown.h"
21 // Routine used to create our JEventProcessor
22 #include "PID/DVertex.h"
23 #include "DANA/DApplication.h"
24 #include "JANA/JApplication.h"
25 #include "JANA/JFactory.h"
26 #include "BCAL/DBCALShower.h"
27 #include "FCAL/DFCALShower.h"
28 #include "FCAL/DFCALCluster.h"
29 #include "RF/DRFTime.h"
30 #include "PID/DEventRFBunch.h"
31 #include "TRIGGER/DTrigger.h"
32 
33 #include "DLorentzVector.h"
34 #include "TTree.h"
35 #include "units.h"
37 
38 extern "C"{
39  void InitPlugin(JApplication *app){
40  InitJANAPlugin(app);
41  app->AddProcessor(new JEventProcessor_cal_high_energy_skim());
42  }
43 } // "C"
44 
45 
46 //------------------
47 // JEventProcessor_cal_high_energy_skim (Constructor)
48 //------------------
50 {
51 
52  MIN_BCAL_E = 2.;
53  MIN_FCAL_E = 5.;
54 
55  //WRITE_EVIO = 1;
56  MAKE_DIAGNOSTICS = 0; // only save ROOT histograms if we need to
57 
58  //gPARMS->SetDefaultParameter("CALHIGHENERGY:WRITE_EVIO", WRITE_EVIO );
59  gPARMS->SetDefaultParameter("CALHIGHENERGY:DIAGNOSTICS", MAKE_DIAGNOSTICS );
60  gPARMS->SetDefaultParameter("CALHIGHENERGY:MIN_BCAL_E" , MIN_BCAL_E );
61  gPARMS->SetDefaultParameter("CALHIGHENERGY:MIN_FCAL_E" , MIN_FCAL_E );
62 
63  num_epics_events = 0;
64 
65 }
66 
67 //------------------
68 // ~JEventProcessor_cal_high_energy_skim (Destructor)
69 //------------------
71 {
72 
73 }
74 
75 //------------------
76 // init
77 //------------------
79 {
80  h_FCAL_shen = new TH1F("FCAL_cluster_energy", "FCAL Cluster Energy; E(cluster), Gev; Counts", 120, 0, 12.);
81  h_BCAL_shen = new TH1F("BCAL_shower_energy", "BCAL Shower Energy; E(shower), Gev; Counts", 120, 0, 6.);
82 
83  return NOERROR;
84 }
85 
86 //------------------
87 // brun
88 //------------------
89 jerror_t JEventProcessor_cal_high_energy_skim::brun(JEventLoop *eventLoop, int32_t runnumber)
90 {
91  return NOERROR;
92 }
93 
94 //------------------
95 // evnt
96 //------------------
97 jerror_t JEventProcessor_cal_high_energy_skim::evnt(JEventLoop *loop, uint64_t eventnumber)
98 {
99  vector< const DBCALShower* > locBCALShowers;
100  vector< const DFCALShower* > locFCALShowers;
101  vector< const DFCALCluster* > locFCALClusters;
102  //vector< const DTrackTimeBased*> locTrackTimeBased;
103  //loop->Get(locTrackTimeBased);
104  //vector<const DVertex*> kinfitVertex;
105  //loop->Get(kinfitVertex);
106 
107  // initialization
108  bool to_save_event = false;
109  const DEventWriterEVIO* locEventWriterEVIO = NULL;
110  loop->GetSingle(locEventWriterEVIO);
111 
112  // always write out BOR events
113  if(loop->GetJEvent().GetStatusBit(kSTATUS_BOR_EVENT)) {
114  //jout << "Found BOR!" << endl;
115  locEventWriterEVIO->Write_EVIOEvent( loop, "cal_high_energy_skim" );
116  return NOERROR;
117  }
118 
119  // write out the first few EPICS events to save run number & other meta info
120  if(loop->GetJEvent().GetStatusBit(kSTATUS_EPICS_EVENT) && (num_epics_events<5)) {
121  //jout << "Found EPICS!" << endl;
122  locEventWriterEVIO->Write_EVIOEvent( loop, "cal_high_energy_skim" );
124  return NOERROR;
125  }
126 
127  // only look at potential physics events
128  const DTrigger* locTrigger = NULL;
129  loop->GetSingle(locTrigger);
130  if(!locTrigger->Get_IsPhysicsEvent())
131  return NOERROR;
132 
133  // Check to see if we have a high energy BCAL shower
134  loop->Get(locBCALShowers);
135 
136  if(MAKE_DIAGNOSTICS) japp->RootWriteLock();
137  for(unsigned int j = 0; j < locBCALShowers.size(); ++j) {
138 
139  if(MAKE_DIAGNOSTICS) h_BCAL_shen->Fill( locBCALShowers[j]->E_raw );
140 
141  if( locBCALShowers[j]->E_raw > MIN_BCAL_E )
142  to_save_event = true;
143 
144  if(to_save_event)
145  break;
146  }
147  if(MAKE_DIAGNOSTICS) japp->RootUnLock();
148 
149 
150  // if we aren't already going to save these events, save ones with a high energy FCAL shower
151  if(!to_save_event || MAKE_DIAGNOSTICS) {
152 
153  loop->Get(locFCALClusters);
154  if(MAKE_DIAGNOSTICS) japp->RootWriteLock();
155  for(unsigned int j = 0; j < locFCALClusters.size(); ++j) {
156 
157  if(MAKE_DIAGNOSTICS) h_FCAL_shen->Fill( locFCALClusters[j]->getEnergy() );
158 
159  if( locFCALClusters[j]->getEnergy() > MIN_FCAL_E )
160  to_save_event = true;
161 
162  if(to_save_event)
163  break;
164  }
165  if(MAKE_DIAGNOSTICS) japp->RootUnLock();
166  }
167 
168  if(to_save_event) {
169  locEventWriterEVIO->Write_EVIOEvent( loop, "cal_high_energy_skim" );
170  }
171 
172 
173  return NOERROR;
174 }
175 
176 //------------------
177 // erun
178 //------------------
180 {
181  // This is called whenever the run number changes, before it is
182  // changed to give you a chance to clean up before processing
183  // events from the next run number.
184  return NOERROR;
185 }
186 
187 //------------------
188 // Fin
189 //------------------
191 {
192  // Called before program exit after event processing is finished.
193  return NOERROR;
194 }
195 
jerror_t init(void)
Called once at program start.
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
JApplication * japp
bool Get_IsPhysicsEvent(void) const
InitPlugin_t InitPlugin
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
bool Write_EVIOEvent(JEventLoop *locEventLoop, string locOutputFileNameSubString) const
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.