Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DBeamPhoton_factory_TAGGEDMCGEN.cc
Go to the documentation of this file.
1 // $Id$
2 //
3 // File: DBeamPhoton_factory_TAGGEDMCGEN.cc
4 // Created: Thu Dec 3 17:27:55 EST 2009
5 // Creator: staylor (on Linux ifarml6 2.6.18-128.el5 x86_64)
6 //
7 
8 #include <iostream>
9 #include <iomanip>
10 using namespace std;
11 
13 using namespace jana;
14 
15 //------------------
16 // evnt
17 //------------------
18 jerror_t DBeamPhoton_factory_TAGGEDMCGEN::evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
19 {
20  _data.clear();
21 
22  //Check if MC
23  vector<const DMCReaction*> locMCReactions;
24  locEventLoop->Get(locMCReactions);
25  if(locMCReactions.empty())
26  return NOERROR; //Not a thrown event
27 
28  //Get the MCGEN beam
29  const DBeamPhoton* locMCGenBeam;
30  locEventLoop->GetSingle(locMCGenBeam, "MCGEN");
31 
32  //See if it was tagged
33  auto locSystem = locMCGenBeam->dSystem;
34  if(locSystem == SYS_NULL)
35  return NOERROR; //Nope, no objects to create
36 
37  //Get reconstructed beam photons
38  vector<const DBeamPhoton*> locBeamPhotons;
39  locEventLoop->Get(locBeamPhotons);
40 
41  //Loop over beam photons
42  double locBestDeltaT = 9.9E9;
43  const DBeamPhoton* locBestPhoton = nullptr;
44  for(auto& locBeamPhoton : locBeamPhotons)
45  {
46  if(locBeamPhoton->dSystem != locSystem)
47  continue;
48  if(locBeamPhoton->dCounter != locMCGenBeam->dCounter)
49  continue;
50 
51  auto locDeltaT = fabs(locMCGenBeam->time() - locBeamPhoton->time());
52  if(locDeltaT >= locBestDeltaT)
53  continue;
54  locBestDeltaT = locDeltaT;
55  locBestPhoton = locBeamPhoton;
56  }
57 
58  if(locBestPhoton == nullptr)
59  return NOERROR; //Uh oh. Shouldn't be possible.
60 
61  _data.push_back(new DBeamPhoton(*locBestPhoton));
62  return NOERROR;
63 }
64 
unsigned int dCounter
Definition: DBeamPhoton.h:18
Definition: GlueX.h:16
double time(void) const
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
Called every event.
DetectorSystem_t dSystem
Definition: DBeamPhoton.h:19