Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DEventProcessor_B3pi_eff_missgamma.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DEventProcessor_B3pi_eff_missgamma.cc
4 // Created: Fri Jun 30 00:38:23 EDT 2017
5 // Creator: jmhardin (on Linux ifarm1402.jlab.org 3.10.0-327.el7.x86_64 x86_64)
6 //
7 
9 // Routine used to create our DEventProcessor
10 
11 extern "C"
12 {
13  void InitPlugin(JApplication *locApplication)
14  {
15  InitJANAPlugin(locApplication);
16  locApplication->AddProcessor(new DEventProcessor_B3pi_eff_missgamma()); //register this plugin
17  locApplication->AddFactoryGenerator(new DFactoryGenerator_B3pi_eff_missgamma()); //register the factory generator
18  }
19 } // "C"
20 
21 //------------------
22 // init
23 //------------------
25 {
26  // This is called once at program startup.
27 
28  /*
29  //OPTIONAL: Create an EventStore skim.
30  string locSkimFileName = "B3pi_eff_missgamma.idxa";
31  dEventStoreSkimStream.open(locSkimFileName.c_str());
32  dEventStoreSkimStream << "IDXA" << endl;
33  */
34 
35  return NOERROR;
36 }
37 
38 //------------------
39 // brun
40 //------------------
41 jerror_t DEventProcessor_B3pi_eff_missgamma::brun(jana::JEventLoop* locEventLoop, int32_t locRunNumber)
42 {
43  // This is called whenever the run number changes
44 
45  return NOERROR;
46 }
47 
48 //------------------
49 // evnt
50 //------------------
51 jerror_t DEventProcessor_B3pi_eff_missgamma::evnt(jana::JEventLoop* locEventLoop, uint64_t locEventNumber)
52 {
53  // This is called for every event. Use of common resources like writing
54  // to a file or filling a histogram should be mutex protected. Using
55  // locEventLoop->Get(...) to get reconstructed objects (and thereby activating the
56  // reconstruction algorithm) should be done outside of any mutex lock
57  // since multiple threads may call this method at the same time.
58  //
59  // Here's an example:
60  //
61  // vector<const MyDataClass*> mydataclasses;
62  // locEventLoop->Get(mydataclasses);
63  //
64  // japp->RootFillLock(this);
65  // ... fill historgrams or trees ...
66  // japp->RootFillUnLock(this);
67 
68  // DOCUMENTATION:
69  // ANALYSIS library: https://halldweb1.jlab.org/wiki/index.php/GlueX_Analysis_Software
70 
71  /*********************************************************** REQUIRED ***********************************************************/
72 
73  //REQUIRED: To run an analysis, You MUST call one at least of the below code fragments.
74  //JANA is on-demand, so if you don't call one of these, then your analysis won't run.
75 
76 
77 
78 
79 
80  //Recommended: Write surviving particle combinations (if any) to output ROOT TTree
81  //If no cuts are performed by the analysis actions added to a DReaction, then this saves all of its particle combinations.
82  //The event writer gets the DAnalysisResults objects from JANA, performing the analysis.
83  // string is DReaction factory tag: will fill trees for all DReactions that are defined in the specified factory
84  const DEventWriterROOT* locEventWriterROOT = NULL;
85  locEventLoop->GetSingle(locEventWriterROOT);
86 
87  vector<const DMCThrown*> locMCThrowns;
88  locEventLoop->Get(locMCThrowns);
89  bool has_omega = false;
90  for (unsigned int i = 0; i < locMCThrowns.size(); i++)
91  {
92  has_omega = has_omega || (locMCThrowns[i]->PID() == omega);
93  }
94 
95  //only write events with real omega
96  //if (has_omega == true)
97  //{
98  locEventWriterROOT->Fill_DataTrees(locEventLoop, "B3pi_eff_missgamma");
99  //}
100 
101  /*
102  //Optional: Get the analysis results for all DReactions.
103  //Getting these objects triggers the analysis, if it wasn't performed already.
104  //These objects contain the DParticleCombo objects that survived the DAnalysisAction cuts that were added to the DReactions
105  vector<const DAnalysisResults*> locAnalysisResultsVector;
106  locEventLoop->Get(locAnalysisResultsVector);
107  */
108 
109  /************************************************** OPTIONAL: FURTHER ANALYSIS **************************************************/
110  /*
111  //Optional: Get all particle combinations for all DReactions.
112  //If kinematic fits were requested, these contain both the measured and kinematic-fit track parameters
113  //No cuts from DAnalysisActions are placed on these combos
114  vector<const DParticleCombo*> locParticleCombos;
115  locEventLoop->Get(locParticleCombos);
116  for(size_t loc_i = 0; loc_i < locParticleCombos.size(); ++loc_i)
117  {
118  const DParticleCombo* locParticleCombo = locParticleCombos[loc_i];
119  if(locParticleCombo->Get_Reaction()->Get_ReactionName() != "B3pi_eff_missgamma")
120  continue; // particle combination was for a different reaction
121  //perform further analysis steps here...
122  }
123  */
124 
125  /*
126  //Optional: Perform further cuts on the particle combos in the analysis results.
127  for(size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); ++loc_i)
128  {
129  const DAnalysisResults* locAnalysisResults = locAnalysisResultsVector[loc_i];
130  if(locAnalysisResults->Get_Reaction()->Get_ReactionName() != "B3pi_eff_missgamma")
131  continue; // analysis results were for a different reaction
132  //get the DParticleCombo objects for this DReaction that survived all of the DAnalysisAction cuts
133  deque<const DParticleCombo*> locPassedParticleCombos;
134  locAnalysisResults->Get_PassedParticleCombos(locPassedParticleCombos);
135  for(size_t loc_j = 0; loc_j < locPassedParticleCombos.size(); ++loc_j)
136  {
137  const DParticleCombo* locPassedParticleCombo = locPassedParticleCombos[loc_j];
138  //perform further analysis steps here...
139  }
140  }
141  */
142 
143  /******************************************************** OPTIONAL: SKIMS *******************************************************/
144 
145  /*
146  //Optional: Save event to output REST file. Use this to create physical skims.
147  const DEventWriterREST* locEventWriterREST = NULL;
148  locEventLoop->GetSingle(locEventWriterREST);
149  for(size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); ++loc_i)
150  {
151  const DAnalysisResults* locAnalysisResults = locAnalysisResultsVector[loc_i];
152  if(locAnalysisResults->Get_Reaction()->Get_ReactionName() != "B3pi_eff_missgamma")
153  continue; // analysis results were for a different reaction
154 
155  //get the DParticleCombo objects for this DReaction that survived all of the DAnalysisAction cuts
156  deque<const DParticleCombo*> locPassedParticleCombos;
157  locAnalysisResults->Get_PassedParticleCombos(locPassedParticleCombos);
158 
159  if(!locPassedParticleCombos.empty())
160  locEventWriterREST->Write_RESTEvent(locEventLoop, "B3pi_eff_missgamma"); //string is part of output file name
161  }
162  */
163 
164 
165  //Optional: Create an EventStore skim.
166 
167  // See whether this is MC data or real data
168 /*
169  vector<const DMCThrown*> locMCThrowns;
170  locEventLoop->Get(locMCThrowns);
171  printf("\n");
172  for (unsigned int i = 0; i < locMCThrowns.size(); i++)
173  {
174  printf("%4d: %5d\n",locMCThrowns[i]->PID());
175  }
176 */
177 /*
178  unsigned int locRunNumber = locEventLoop->GetJEvent().GetRunNumber();
179  unsigned int locUniqueID = locMCThrowns.empty() ? 1 : Get_FileNumber(locEventLoop);
180 
181  // If a particle combo passed the cuts, save the event info in the output file
182  for(size_t loc_i = 0; loc_i < locAnalysisResultsVector.size(); ++loc_i)
183  {
184  const DAnalysisResults* locAnalysisResults = locAnalysisResultsVector[loc_i];
185  if(locAnalysisResults->Get_Reaction()->Get_ReactionName() != "B3pi_eff_missgamma")
186  continue; // analysis results were for a different reaction
187  if(locAnalysisResults->Get_NumPassedParticleCombos() == 0)
188  continue; // no combos passed
189 
190  //MUST LOCK AROUND MODIFICATION OF MEMBER VARIABLES IN brun() or evnt().
191  japp->WriteLock("B3pi_eff_missgamma.idxa"); //Lock is unique to this output file
192  {
193  dEventStoreSkimStream << locRunNumber << " " << locEventNumber << " " << locUniqueID << endl;
194  }
195  japp->Unlock("B3pi_eff_missgamma.idxa");
196  }
197  */
198 
199  return NOERROR;
200 }
201 
202 int DEventProcessor_B3pi_eff_missgamma::Get_FileNumber(JEventLoop* locEventLoop) const
203 {
204  //Assume that the file name is in the format: *_X.ext, where:
205  //X is the file number (a string of numbers of any length)
206  //ext is the file extension (probably .evio or .hddm)
207 
208  //get the event source
209  JEventSource* locEventSource = locEventLoop->GetJEvent().GetJEventSource();
210  if(locEventSource == NULL)
211  return -1;
212 
213  //get the source file name (strip the path)
214  string locSourceFileName = locEventSource->GetSourceName();
215 
216  //find the last "_" & "." indices
217  size_t locUnderscoreIndex = locSourceFileName.rfind("_");
218  size_t locDotIndex = locSourceFileName.rfind(".");
219  if((locUnderscoreIndex == string::npos) || (locDotIndex == string::npos))
220  return -1;
221 
222  size_t locNumberLength = locDotIndex - locUnderscoreIndex - 1;
223  string locFileNumberString = locSourceFileName.substr(locUnderscoreIndex + 1, locNumberLength);
224 
225  int locFileNumber = -1;
226  istringstream locFileNumberStream(locFileNumberString);
227  locFileNumberStream >> locFileNumber;
228 
229  return locFileNumber;
230 }
231 
232 //------------------
233 // erun
234 //------------------
236 {
237  // This is called whenever the run number changes, before it is
238  // changed to give you a chance to clean up before processing
239  // events from the next run number.
240  return NOERROR;
241 }
242 
243 //------------------
244 // fini
245 //------------------
247 {
248  // Called before program exit after event processing is finished.
249  if(dEventStoreSkimStream.is_open())
250  dEventStoreSkimStream.close();
251  return NOERROR;
252 }
253 
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t locEventNumber)
Called every event.
int Get_FileNumber(JEventLoop *locEventLoop) const
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t init(void)
Called once at program start.
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t locRunNumber)
Called every time a new run number is detected.
InitPlugin_t InitPlugin
void Fill_DataTrees(JEventLoop *locEventLoop, string locDReactionTag) const
jerror_t erun(void)
Called every time run number changes, provided brun has been called.