Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hijbkg_upc.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file hijbkg_upc.cc
1 #include "hijbkg_upc.h"
2 
4 
6 #include <phool/getClass.h>
7 
9 #include <g4main/PHG4Particle.h>
10 #include <ffaobjects/EventHeader.h>
11 
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
16 #include <HepMC/GenEvent.h>
17 #include <HepMC/GenParticle.h>
18 #include <HepMC/GenVertex.h>
19 #include <HepMC/IteratorRange.h>
20 #include <HepMC/SimpleVector.h>
21 #include <HepMC/GenParticle.h>
22 #pragma GCC diagnostic pop
23 
24 #include <TTree.h>
25 #include <TFile.h>
26 
27 //____________________________________________________________________________..
29  SubsysReco(name),
30  Outfile(name)
31 {
32  std::cout << "hijbkg_upc::hijbkg_upc(const std::string &name) Calling ctor" << std::endl;
33 }
34 //____________________________________________________________________________..
36 {
37  std::cout << "hijbkg_upc::~hijbkg_upc() Calling dtor" << std::endl;
38 }
39 
40 //____________________________________________________________________________..
42 {
43  std::cout << "hijbkg_upc::Init(PHCompositeNode *topNode) Initializing" << std::endl;
44 
45  out = new TFile("hijbkg.root","RECREATE");
46 
47  T = new TTree("T","T");
48  T -> Branch("evt",&m_evt);
49  T -> Branch("b",&m_b);
50  T -> Branch("cent",&m_cent);
51  T -> Branch("part0",&m_part[0]);
52  T -> Branch("part1",&m_part[1]);
53  /*
54  T -> Branch("pid",&m_pid);
55  T -> Branch("pt",&m_pt);
56  T -> Branch("eta",&m_eta);
57  T -> Branch("phi",&m_phi);
58  T -> Branch("e",&m_e);
59  T -> Branch("psi2",&m_psi2);
60  T -> Branch("p",&m_p);
61  */
62 
63 
65 }
66 
67 //____________________________________________________________________________..
69 {
70  std::cout << "hijbkg_upc::InitRun(PHCompositeNode *topNode) Initializing for Run XXX" << std::endl;
72 }
73 
74 //____________________________________________________________________________..
76 {
77 
78  // Get Event Header
79  EventHeader *evtheader = findNode::getClass<EventHeader>(topNode, "EventHeader");
80  m_evt = evtheader->get_EvtSequence();
81  if ( m_evt%1 == 0 ) std::cout << "Event " << m_evt << std::endl;
82 
83 
84  //truth particle information
85  PHG4TruthInfoContainer *truthinfo = findNode::getClass<PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
86  if(!truthinfo)
87  {
88  std::cout << PHWHERE << "hijingTruthCheck::process_event Could not find node G4TruthInfo" << std::endl;
90  }
91 
92  PHG4TruthInfoContainer::Range truthRange = truthinfo -> GetPrimaryParticleRange();
94 
95  int ntracks = 0; // stable, charged, and in acceptance
96 
97  // Loop over the monte carlo particles (eg hijing) in the truth container
98  for(truthIter = truthRange.first; truthIter != truthRange.second; truthIter++)
99  {
100  PHG4Particle *truthPar = truthIter->second;
101  double px = truthPar->get_px();
102  double py = truthPar->get_py();
103  double pz = truthPar->get_pz();
104  double e = truthPar->get_e();
105 
106  // return 1 if particle is stable and charged
107  int pid = truthPar->get_pid();
108 
109  if ( isStableCharged( pid ) )
110  {
111  // Stop processing the event since there are already more than two tracks
112  if ( ntracks > 2 ) return Fun4AllReturnCodes::EVENT_OK;
113 
114  float eta = getEta( truthPar );
115  float pt = getpT( truthPar );
116  if ( fabs(eta) < 1.1 && pt > 0.3 ) // in sPHENIX acceptance
117  {
118  m_part[ntracks].SetPdgCode( pid );
119  m_part[ntracks].SetMomentum( px, py, pz, e );
120  ntracks++;
121  }
122 
123  }
124  //std::cout << truthPar->get_pid() << "\t" << px << "\t" << py << "\t" << pz << std::endl;
125 
126 
127  //if(abs(truthPar -> get_pid()) >= 12 && abs(truthPar -> get_pid()) <= 16) continue;
128 
129  /*
130  m_pid.push_back(truthPar -> get_pid());
131 
132  m_p.push_back(getP(truthPar));
133 
134  m_e.push_back(truthPar -> get_e());
135 
136  m_eta.push_back(getEta(truthPar));
137 
138  m_phi.push_back(getPhi(truthPar));
139 
140  m_pt.push_back(getpT(truthPar));
141  */
142 
143  //if(getpT(truthPar) < 0 || getpT(truthPar) > 10)std::cout << "Found particle with pt: " << getpT(truthPar) << std::endl;
144 
145  } // end of loop over truthcontainer
146 
147  //std::cout << "Saw " << npart << " particles" << std::endl;
148  if ( ntracks==2 ) T->Fill();
149 
151 }
152 
153 //____________________________________________________________________________..
155 {
156 
157  m_pid.clear();
158  m_e.clear();
159  m_eta.clear();
160  m_pt.clear();
161  m_phi.clear();
162 
164 }
165 
166 //____________________________________________________________________________..
168 {
169  std::cout << "hijbkg_upc::EndRun(const int runnumber) Ending Run for Run " << runnumber << std::endl;
171 }
172 
173 //____________________________________________________________________________..
175 {
176  out -> cd();
177  T -> Write();
178  out -> Close();
179 
180  std::cout << "hijbkg_upc::End(PHCompositeNode *topNode) This is the End..." << std::endl;
182 }
183 
184 //____________________________________________________________________________..
186 {
187  std::cout << "hijbkg_upc::Reset(PHCompositeNode *topNode) being Reset" << std::endl;
189 }
190 
191 //____________________________________________________________________________..
192 void hijbkg_upc::Print(const std::string &what) const
193 {
194  std::cout << "hijbkg_upc::Print(const std::string &what) const Printing info for " << what << std::endl;
195 }
196 
197 // check if particle is stable and charged
199 {
200  if ( abs(pid) == 211 ) return 1; // pi+/pi-
201  if ( abs(pid) == 211 ) return 1; // pi+/pi-
202  if ( abs(pid) == 321 ) return 1; // K+/K-
203  if ( abs(pid) == 2212 ) return 1; // p+/p-
204  if ( abs(pid) == 11 ) return 1; // e+/e-
205  if ( abs(pid) == 13 ) return 1; // mu+/mu-
206 
207 
208  return 0;
209 }
210 
211 //____________________________________________________________________________..
213 {
214  float px = particle -> get_px();
215  float py = particle -> get_py();
216  float pz = particle -> get_pz();
217  float p = sqrt(pow(px,2) + pow(py,2) + pow(pz,2));
218 
219  return 0.5*log((p+pz)/(p-pz));
220 }
221 
222 //____________________________________________________________________________..
224 {
225  float phi = atan2(particle -> get_py(),particle -> get_px());
226  return phi;
227 }
228 
229 //____________________________________________________________________________..
231 {
232  float px = particle -> get_px();
233  float py = particle -> get_py();
234 
235  float pt = sqrt(pow(px,2) + pow(py,2));
236  return pt;
237 }
238 
239 //____________________________________________________________________________..
241 {
242  float px = particle -> get_px();
243  float py = particle -> get_py();
244  float pz = particle -> get_pz();
245  float p = sqrt(pow(px,2) + pow(py,2) + pow(pz,2));
246 
247  return p;
248 }