Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DBeamPhoton_factory_MCGEN.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 using namespace std;
4 
6 using namespace jana;
7 
8 //------------------
9 // brun
10 //------------------
11 jerror_t DBeamPhoton_factory_MCGEN::brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
12 {
13  //Setting this flag makes it so that JANA does not delete the objects in _data. This factory will manage this memory.
14  //This is because some/all of these pointers are just copied from earlier objects, and should not be deleted.
15  bool locIsRESTEvent = locEventLoop->GetJEvent().GetStatusBit(kSTATUS_REST);
16  if(!locIsRESTEvent) //If REST, will grab from file: IS owner
17  SetFactoryFlag(NOT_OBJECT_OWNER);
18  return NOERROR;
19 }
20 
21 //------------------
22 // evnt
23 //------------------
24 jerror_t DBeamPhoton_factory_MCGEN::evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
25 {
26  if(!_data.empty())
27  {
28  if(_data[0]->dSystem == SYS_NULL)
29  delete _data[0]; //CREATED BY THIS FACTORY //else copied from TRUTH factory!
30  _data.clear();
31  }
32 
33  //Check if MC
34  vector<const DMCReaction*> locMCReactions;
35  locEventLoop->Get(locMCReactions);
36  if(locMCReactions.empty())
37  return NOERROR; //Not a thrown event
38 
39  //First see if it was tagged: If so, use truth DBeamPhoton
40  vector<const DBeamPhoton*> locTruthPhotons;
41  locEventLoop->Get(locTruthPhotons, "TRUTH");
42  for(auto locBeamPhoton : locTruthPhotons)
43  {
44  vector<const DTAGMHit*> locTAGMHits;
45  locBeamPhoton->Get(locTAGMHits);
46  for(auto locTAGMHit : locTAGMHits)
47  {
48  if(locTAGMHit->bg != 0)
49  continue;
50  _data.push_back(const_cast<DBeamPhoton*>(locBeamPhoton));
51  return NOERROR;
52  }
53 
54  vector<const DTAGHHit*> locTAGHHits;
55  locBeamPhoton->Get(locTAGHHits);
56  for(auto locTAGHHit : locTAGHHits)
57  {
58  if(locTAGHHit->bg != 0)
59  continue;
60  _data.push_back(const_cast<DBeamPhoton*>(locBeamPhoton));
61  return NOERROR;
62  }
63  }
64 
65  //Photon is NOT TAGGED //Create a beam object from the DMCReaction
66  auto *locBeamPhoton = new DBeamPhoton;
67  *(DKinematicData*)locBeamPhoton = locMCReactions[0]->beam;
68  _data.push_back(locBeamPhoton);
69 
70  return NOERROR;
71 }
72 
73 //------------------
74 // fini
75 //------------------
77 {
78  if(!_data.empty())
79  {
80  if(_data[0]->dSystem == SYS_NULL)
81  delete _data[0]; //CREATED BY THIS FACTORY //else copied from TRUTH factory!
82  _data.clear();
83  }
84 
85  return NOERROR;
86 }
87 
jerror_t brun(jana::JEventLoop *locEventLoop, int32_t runnumber)
Definition: GlueX.h:16
jerror_t fini(void)
Called after last event of last event source has been processed.
jerror_t evnt(jana::JEventLoop *locEventLoop, uint64_t eventnumber)
Called every event.