Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
factory.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file factory.cpp
1 
9 #include "factory.h"
10 
11 #include <TBranch.h>
12 #include <TLorentzVector.h>
13 #include <TTree.h>
14 #include <TVector3.h>
15 
16 #include <eicsmear/erhic/EventPythia.h>
17 #include <eicsmear/erhic/Kinematics.h>
18 
19 #include "pythia_commons.h"
20 #include "pythia_erhic.h"
21 
22 // =====================================================================
23 // =====================================================================
25 : mEvent(new erhic::EventPythia()) {
26 }
27 
28 // =====================================================================
29 // =====================================================================
31  if(mEvent) {
32  delete mEvent;
33  mEvent = NULL;
34  } // if
35 }
36 
37 // =====================================================================
38 // Populate the stored event with the current contents of
39 // PYTHIA and return a pointer to the event.
40 // Do not delete this pointer!
41 // =====================================================================
42 erhic::EventPythia* Factory::Create() {
43  mEvent->Clear("");
44  // See the PYTHIA manual for more details about the meaning
45  // of the various msti(), pari(), vint() variables.
46  mEvent->SetGenEvent(__pythia6_MOD_genevent);
47  mEvent->SetProcess(msti(1));
48  mEvent->SetNucleon(msti(12));
49  mEvent->SetTargetParton(msti(16));
50  mEvent->SetBeamParton(msti(15));
51  mEvent->SetTargetPartonX(pari(34));
52  mEvent->SetBeamPartonX(pari(33));
53  mEvent->SetBeamPartonTheta(pari(53));
54  mEvent->SetLeptonPhi(vint(313));
55  mEvent->SetF1(__pythia6_MOD_f1);
56  mEvent->SetF2(__pythia6_MOD_f2);
57  mEvent->SetSigmaRad(__pythia6_MOD_sigma_rad);
58  mEvent->SetHardS(pari(14));
59  mEvent->SetHardT(pari(15));
60  mEvent->SetHardU(pari(16));
61  mEvent->SetHardQ2(pari(22));
62  mEvent->SetHardPt2(pari(18));
63  mEvent->SetSigRadCor(__pythia6_MOD_sigradcor);
64  mEvent->SetEBrems(__pythia6_MOD_ebrems);
65  mEvent->SetPhotonFlux(vint(319));
66  mEvent->SetTrueY(vint(309));
67  mEvent->SetTrueQ2(vint(307));
68  mEvent->SetTrueX(__pythia6_MOD_truex);
69  mEvent->SetTrueW2(__pythia6_MOD_truew2);
70  mEvent->SetTrueNu(__pythia6_MOD_truenu);
71  mEvent->SetR(__pythia6_MOD_r);
72  static std::stringstream stream;
73  const int ntracks = pyjets_.n;
74  // Loop with indices from [1, N] as per Fortran convention.
75  // Accessor functions k(), p(), v() take care of correct indexing
76  // of the equivalent C++ arrays.
77  for(int i(1); i <= ntracks; ++i) {
78  erhic::ParticleMC* track = new erhic::ParticleMC;
79  track->SetIndex(i);
80  track->SetStatus(k(i, 1));
81  track->SetId(k(i, 2));
82  track->SetParentIndex(k(i, 3));
83  track->SetChild1Index(k(i, 4));
84  track->SetChildNIndex(k(i, 5));
85  track->Set4Vector(TLorentzVector(p(i, 1), p(i, 2),
86  p(i, 3), p(i, 4)));
87  track->SetM(p(i, 5));
88  track->SetVertex(TVector3(v(i, 1), v(i, 2), v(i, 3)));
89  track->SetEvent(mEvent);
90  mEvent->AddLast(track);
91  } // for
92  // If a radiative photon was generated append it to the track record.
93  if(__pythia6_MOD_ebrems > 0.) {
94  erhic::ParticleMC* track = new erhic::ParticleMC;
95  track->SetIndex(mEvent->GetNTracks() + 1);
96  track->SetStatus(55);
97  track->SetId(22);
98  track->SetParentIndex(1);
99  track->SetChild1Index(0);
100  track->SetChildNIndex(0);
101  track->Set4Vector(TLorentzVector(__pythia6_MOD_radgamp[0],
105  track->SetVertex(TVector3(0., 0., 0.));
106  track->SetEvent(mEvent);
107  mEvent->AddLast(track);
108  } // if
109  // After adding all tracks, compute event kinematics.
110  // Compute using all three methods: electron, Jacquet-Blondel
111  // and double angle.
112  erhic::DisKinematics* nm =
113  erhic::LeptonKinematicsComputer(*mEvent).Calculate();
114  erhic::DisKinematics* jb =
115  erhic::JacquetBlondelComputer(*mEvent).Calculate();
116  erhic::DisKinematics* da =
117  erhic::DoubleAngleComputer(*mEvent).Calculate();
118  if(nm) {
119  mEvent->SetLeptonKinematics(*nm);
120  delete nm;
121  } // if
122  if(jb) {
123  mEvent->SetJacquetBlondelKinematics(*jb);
124  delete jb;
125  } // if
126  if(da) {
127  mEvent->SetDoubleAngleKinematics(*da);
128  delete da;
129  } // if
130  // Set particle properties that depend on other particles.
131  // This has to come last as some of these properties depend
132  // on the computed event kinematics.
133  for(unsigned i(0); i < mEvent->GetNTracks(); ++i) {
134  mEvent->GetTrack(i)->ComputeEventDependentQuantities(*mEvent);
135  } // for
136  return mEvent;
137 }
138 
139 // =====================================================================
140 // Returns a string with the full (including namespace) class name
141 // of the event type produced.
142 // This is important for use with ROOT TTree to ensure the correct
143 // event type in branches.
144 // =====================================================================
146  return mEvent->Class()->GetName();
147 }
148 
149 // =====================================================================
150 // Add a branch named "name" for the event type generated
151 // by this factory to a ROOT TTree.
152 // Returns a pointer to the branch, or NULL in the case of an error.
153 // =====================================================================
154 TBranch* Factory::Branch(TTree& tree, const std::string& name) {
155  return tree.Branch(name.c_str(), &mEvent);
156 }