EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Pythia6EventFactory.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Pythia6EventFactory.cxx
1 
11 
12 #include <iostream>
13 #include <memory>
14 #include <string>
15 
16 #include <TBranch.h>
17 #include <TClass.h>
18 #include <TCollection.h> // For TIter
19 #include <TMCParticle.h>
20 #include <TObjArray.h>
21 #include <TProcessID.h>
22 #include <TPythia6.h>
23 #include <TTree.h>
24 
25 namespace erhic {
26 namespace hadronic {
27 
29 }
30 
32 : mFilter(filter)
33 , mEvent(NULL) {
34 }
35 
37  std::unique_ptr<EventPythiaPP> event(BuildEvent());
38  if (mFilter.get()) {
39  while (!mFilter->Accept(*event)) {
40  event.reset(BuildEvent());
41  } // while
42  } // if
43  return event.release();
44 }
45 
47  // Save current object count
48  int objectNumber = TProcessID::GetObjectCount();
49  // Generate a new PYTHIA event
50  // Read the event kinematics from PYTHIA and create an event
51  TPythia6* pythia = TPythia6::Instance();
52  pythia->GenerateEvent();
53  double Q2 = pythia->GetPARI(22);
54  double x1 = pythia->GetPARI(33);
55  double x2 = pythia->GetPARI(34);
56  std::unique_ptr<EventPythiaPP> event(new EventPythiaPP(Q2, x1, x2));
57  // Get the particles from the current PYTHIA event.
58  // Build a ParticleMC from each and add to the event's list
59  TObjArray* particles = pythia->ImportParticles("All");
60  TIter iter(particles);
61  TMCParticle* mc(NULL);
62  // Populate particle list
63  while ((mc = static_cast<TMCParticle*>(iter.Next()))) {
64  if (mc) {
65  std::unique_ptr<ParticleMC> p(new ParticleMC(*mc));
66  p->SetParentIndex(mc->GetParent());
67  event->Add(p.get());
68  } // if
69  } // while
70  // Test against filter and exit loop if the event passes the filter.
71  // Restore Object count
72  // See example in $ROOTSYS/test/Event.cxx
73  // To save space in the table keeping track of all referenced objects
74  // we assume that our events do not address each other. We reset the
75  // object count to what it was at the beginning of the event.
76  TProcessID::SetObjectCount(objectNumber);
77  return event.release();
78 }
79 
80 std::string Pythia6EventFactory::EventName() const {
81  return EventPythiaPP::Class()->GetName();
82 }
83 
84 TBranch* Pythia6EventFactory::Branch(TTree& tree, const std::string& name) {
85  EventPythiaPP* event(NULL);
86  TBranch* branch =
87  tree.Branch(name.c_str(), EventName().c_str(), &event, 32000, 99);
88  tree.ResetBranchAddress(branch);
89  return branch;
90 }
91 
92 void Pythia6EventFactory::Fill(TBranch& branch) {
93  if (mEvent) {
94  branch.ResetAddress();
95  delete mEvent;
96  mEvent = NULL;
97  } // if
98  mEvent = Create();
99  branch.SetAddress(&mEvent);
100 }
101 
102 } // namespace hadronic
103 } // namespace erhic