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