eic-smear  1.0.3
A collection of ROOT classes for Monte Carlo events and a fast-smearing code simulating detector effects for the Electron-Ion Collider task force
smear/EventFactory.h
Go to the documentation of this file.
1 
10 #ifndef INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_
11 #define INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_
12 
13 #include <string>
14 
15 #include <TClass.h>
16 #include <TTree.h>
17 #include <TBranch.h>
18 
20 
21 namespace Smear {
22 
29 template<typename T>
31  public:
32  typedef T EventType;
36  virtual ~EventFactory() { }
37 
38  virtual T* Create() = 0;
39 
43  virtual std::string EventName() const {
44  return T::Class()->GetName();
45  }
46 
50  virtual TBranch* Branch(TTree& tree, const std::string& name) {
51  T* event(NULL); // Temporary, just to pass to TTree::Branch()
52  TBranch* branch = tree.Branch(name.c_str(), EventName().c_str(),
53  &event, 32000, 99);
54  branch->ResetAddress();
55  if (event) {
56  delete event;
57  } // if
58  return branch;
59  }
60 
64  virtual void Fill(TBranch& branch) {
65  T* event = Create();
66  branch.ResetAddress();
67  branch.SetAddress(&event);
68  branch.GetTree()->Fill();
69  if (event) {
70  delete event;
71  } // if
72  }
73 };
74 
75 } // namespace Smear
76 
77 #endif // INCLUDE_EICSMEAR_SMEAR_EVENTFACTORY_H_
Smear::EventFactory::Fill
virtual void Fill(TBranch &branch)
Create() the new event and fill the requested tree branch with it.
Definition: smear/EventFactory.h:64
Smear
Definition: Acceptance.cxx:16
Smear::EventFactory::~EventFactory
virtual ~EventFactory()
Destructor.
Definition: smear/EventFactory.h:36
Smear::EventFactory::Branch
virtual TBranch * Branch(TTree &tree, const std::string &name)
Create and configure the output branch for smeared events in the tree.
Definition: smear/EventFactory.h:50
tree
Definition: tree.py:1
Smear::EventFactory
Event factory for events of a particular type.
Definition: smear/EventFactory.h:30
erhic::VirtualEventFactory
Abstract base class for event builders.
Definition: erhic/EventFactory.h:35
Smear::EventFactory::EventName
virtual std::string EventName() const
Returns the name of the branch object type (Smear::Event).
Definition: smear/EventFactory.h:43
Smear::EventFactory::EventType
T EventType
Definition: smear/EventFactory.h:32
EventFactory.h
Smear::EventFactory::Create
virtual T * Create()=0
Returns a new event instance.