Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
JEventProcessor_pi0calib.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: JEventProcessor_pi0calib.cc
4 // Created: Wed May 24 13:46:12 EDT 2017
5 // Creator: mashephe (on Linux stanley.physics.indiana.edu 2.6.32-642.6.2.el6.x86_64 unknown)
6 //
7 
10 
11 using namespace jana;
12 
14 
17 
18 // Routine used to create our JEventProcessor
19 #include <JANA/JApplication.h>
20 #include <JANA/JFactory.h>
21 extern "C"{
22  void InitPlugin(JApplication *app){
23  InitJANAPlugin(app);
24  app->AddProcessor(new JEventProcessor_pi0calib());
25  app->AddFactoryGenerator( new DFactoryGenerator_pi0calib() );
26  }
27 } // "C"
28 
29 
30 //------------------
31 // JEventProcessor_pi0calib (Constructor)
32 //------------------
34 {
35 
36  WRITE_EVIO_FILE = 1;
37  gPARMS->SetDefaultParameter( "WRITE_EVIO_FILE", WRITE_EVIO_FILE );
38 
39  WRITE_ROOT_TREE = 0;
40  gPARMS->SetDefaultParameter( "WRITE_ROOT_TREE", WRITE_ROOT_TREE );
41 }
42 
43 //------------------
44 // ~JEventProcessor_pi0calib (Destructor)
45 //------------------
47 {
48 
49 }
50 
51 //------------------
52 // init
53 //------------------
55 {
56  // This is called once at program startup.
57 
58  return NOERROR;
59 }
60 
61 //------------------
62 // brun
63 //------------------
64 jerror_t JEventProcessor_pi0calib::brun(JEventLoop *eventLoop, int32_t runnumber)
65 {
66  // This is called whenever the run number changes
67  return NOERROR;
68 }
69 
70 //------------------
71 // evnt
72 //------------------
73 jerror_t JEventProcessor_pi0calib::evnt(JEventLoop *loop, uint64_t eventnumber)
74 {
75 
76  vector<const DAnalysisResults*> locAnalysisResultsVector;
77  loop->Get( locAnalysisResultsVector );
78 
79  if( WRITE_EVIO_FILE ){
80 
81  const DEventWriterEVIO* eventWriterEVIO = NULL;
82  loop->GetSingle(eventWriterEVIO);
83 
84  // write out BOR events
85  if(loop->GetJEvent().GetStatusBit(kSTATUS_BOR_EVENT)) {
86 
87  eventWriterEVIO->Write_EVIOEvent(loop, "exclusivepi0");
88  return NOERROR;
89  }
90 
91  //Make sure that there are combos that survived for ****THIS**** CHANNEL!!!
92  bool locSuccessFlag = false;
93  for(size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); ++loc_i) {
94  const DReaction* locReaction = locAnalysisResultsVector[loc_i]->Get_Reaction();
95  if(locReaction->Get_ReactionName() != "excl_pi0calib")
96  continue;
97 
98  deque<const DParticleCombo*> locPassedParticleCombos;
99  locAnalysisResultsVector[loc_i]->Get_PassedParticleCombos(locPassedParticleCombos);
100  locSuccessFlag = !locPassedParticleCombos.empty();
101  break;
102  }
103 
104  if( (locAnalysisResultsVector.size() > 0) && locSuccessFlag) { // there are combos that satisfy our reaction
105  //if( (locAnalysisResultsVector.size() > 0) && (locAnalysisResultsVector[0]->Get_NumPassedParticleCombos() != 0) ) {
106  // SIMPLE - write out the full event
107  //eventWriterEVIO->Write_EVIOEvent(loop, "exclusivepi0");
108 
109  // Instead: Write out each combo as an "event", only saving the combo vertex, RF bunch, and showers associated with the combo
110  // This should be a lot smaller
111 
112  vector< const JObject* > locObjectsToSave;
113 
114  vector<const DEventRFBunch*> locEventRFBunches;
115  loop->Get(locEventRFBunches);
116  //locObjectsToSave.push_back(static_cast<const JObject *>(locEventRFBunches));
117  locObjectsToSave.push_back(locEventRFBunches[0]);
118 
119  vector<const DVertex*> kinfitVertex;
120  loop->Get(kinfitVertex);
121  locObjectsToSave.push_back(kinfitVertex[0]);
122 
123  if(kinfitVertex.size() > 0) { // pretty sure this should always be true if we have a combo....
124  for( auto result : locAnalysisResultsVector ) {
125  deque<const DParticleCombo*> combos;
126  result->Get_PassedParticleCombos(combos);
127  for( auto combo : combos ) {
128  // need to save the RF bunch info
129  //locObjectsToSave.push_back(static_cast<const JObject *>(combo->Get_EventRFBunch()));
130 
131  // need to make a new vertex object - base it on the old one
132  // we probably don'e need most of this information, but keep it reasonable I guess
133  //DVertex *comboVertex = new DVertex(*(kinfitVertex[0]));
134  //comboVertex->dSpacetimeVertex = combo->Get_EventVertex();
135 
136  // Save the actual showers - the EVIO writer will only write out the associated hits
137  //set< const JObject *> bcalShowers;
138  auto particles = combo->Get_FinalParticles_Measured(result->Get_Reaction());
139  for( auto particle : particles ) {
140  if(ParticleCharge(particle->PID()) == 0) {
141  auto locNeutralParticleHypothesis = static_cast<const DNeutralParticleHypothesis*>(particle);
142  auto locNeutralShower = locNeutralParticleHypothesis->Get_NeutralShower();
143  if(find(locObjectsToSave.begin(),locObjectsToSave.end(),locNeutralShower->dBCALFCALShower) == locObjectsToSave.end())
144  locObjectsToSave.push_back(locNeutralShower->dBCALFCALShower);
145  //bcalShowers.insert(locNeutralShower->dBCALFCALShower);
146  }
147  }
148 
149  // actually write the event out
150  //eventWriterEVIO->Write_EVIOEvent( loop, "exclusivepi0", locObjectsToSave );
151  }
152  }
153  }
154 
155  // actually write the event out
156  eventWriterEVIO->Write_EVIOEvent( loop, "exclusivepi0", locObjectsToSave );
157 
158  //}
159 
160  //for( auto *shower_ptr : bcalShowers ) {
161  // locObjectsToSave.push_back(static_cast<const JObject *>(shower_ptr));
162  //}
163 
164  }
165  }
166 
167  if( WRITE_ROOT_TREE ){
168 
169  //Recommended: Write surviving particle combinations (if any) to output ROOT TTree
170  //If no cuts are performed by the analysis actions added to a DReaction, then this saves all of its particle combinations.
171  //The event writer gets the DAnalysisResults objects from JANA, performing the analysis.
172  // string is DReaction factory tag: will fill trees for all DReactions that are defined in the specified factory
173 
174  const DEventWriterROOT* eventWriterROOT = NULL;
175  loop->GetSingle(eventWriterROOT);
176  eventWriterROOT->Fill_DataTrees(loop, "excl_pi0calib");
177  }
178 
179  return NOERROR;
180 }
181 
182 //------------------
183 // erun
184 //------------------
186 {
187  // This is called whenever the run number changes, before it is
188  // changed to give you a chance to clean up before processing
189  // events from the next run number.
190  return NOERROR;
191 }
192 
193 //------------------
194 // fini
195 //------------------
197 {
198  // Called before program exit after event processing is finished.
199  return NOERROR;
200 }
201 
jerror_t brun(jana::JEventLoop *eventLoop, int32_t runnumber)
Called everytime a new run number is detected.
jerror_t init(void)
Called once at program start.
static int ParticleCharge(Particle_t p)
const DNeutralShower * Get_NeutralShower(void) const
jerror_t fini(void)
Called after last event of last event source has been processed.
InitPlugin_t InitPlugin
jerror_t evnt(jana::JEventLoop *eventLoop, uint64_t eventnumber)
Called every event.
string Get_ReactionName(void) const
Definition: DReaction.h:75
jerror_t erun(void)
Called everytime run number changes, provided brun has been called.
void Fill_DataTrees(JEventLoop *locEventLoop, string locDReactionTag) const
bool Write_EVIOEvent(JEventLoop *locEventLoop, string locOutputFileNameSubString) const