Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Quarkonia2LeptonsMC.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Quarkonia2LeptonsMC.C
1 #include "Quarkonia2LeptonsMC.h"
2 
3 #include <phool/getClass.h>
6 
8 
9 //#include <g4main/PHG4TruthInfoContainer.h>
10 //#include <g4main/PHG4Particle.h>
11 
12 #include <TLorentzVector.h>
13 #include <TNtuple.h>
14 #include <TFile.h>
15 #include <TString.h>
16 #include <TH2D.h>
17 #include <TDatabasePDG.h>
18 
19 //#include <cmath>
20 //#include <iostream>
21 
24 #include <HepMC/GenEvent.h>
25 #include <HepMC/GenVertex.h>
26 
27 using namespace std;
28 
30  SubsysReco("Quarkonia2LeptonsMC" ),
31  _embedding_id(1)
32 {
34  _tree_quarkonia = NULL;
35 }
36 
37 int
39 {
40  _verbose = false;
41  _ievent = 0;
42 
43  _fout_root = new TFile(_foutname.c_str(), "RECREATE");
44  _tree_quarkonia = new TNtuple("tree_quarkonia","quarkonia info","ev:px:py:pz:e:pt:eta:phi:invmass:ndaughter:d1d2angle");
45 
46  return 0;
47 }
48 
49 
50 int
52 {
53 
54  _ievent ++;
55 
56  // cout << "Process event # " << _ievent << endl;
57 
58  PHHepMCGenEventMap * geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode, "PHHepMCGenEventMap");
59  if (!geneventmap)
60  {
61  std::cout <<PHWHERE<<" - Fatal error - missing node PHHepMCGenEventMap"<<std::endl;
63  }
64 
65  PHHepMCGenEvent *genevt = geneventmap->get(_embedding_id);
66  if (!genevt)
67  {
68  std::cout <<PHWHERE<<" - Fatal error - node PHHepMCGenEventMap missing subevent with embedding ID "<<_embedding_id;
69  std::cout <<". Print PHHepMCGenEventMap:";
70  geneventmap->identify();
72  }
73 
74  HepMC::GenEvent* theEvent = genevt->getEvent();
75 
76  for (HepMC::GenEvent::particle_const_iterator p = theEvent->particles_begin();
77  p != theEvent->particles_end(); ++p)
78  {
79 
80  TParticlePDG * pdg_p = TDatabasePDG::Instance()->GetParticle( (*p)->pdg_id() );
81 
82  // if ( (*p)->pdg_id() == 443 )
83  if (TString(pdg_p->GetName()) == "J/psi" && (*p)->end_vertex() && (*p)->status() == 2 )
84  {
85 
86  /* quarkonia data */
87  float px = (*p)->momentum().px();
88  float py = (*p)->momentum().py();
89  float pz = (*p)->momentum().pz();
90  float pe = (*p)->momentum().e();
91  float pt = sqrt(pow((*p)->momentum().px(),2) + pow((*p)->momentum().py(),2));
92  float eta = (*p)->momentum().eta();
93  float phi = (*p)->momentum().phi();
94  float invmass = (*p)->momentum().m();
95 
96  /* daughter = decay products */
97  float ndaughter = (*p)->end_vertex()->particles_out_size();
98 
99  /* calculate angle between first two daugher particles */
100  float d1d2angle = 0;
101  if ( ndaughter == 2 )
102  {
103  HepMC::GenVertex::particles_out_const_iterator p_d1 = (*p)->end_vertex()->particles_out_const_begin();
104  HepMC::GenVertex::particles_out_const_iterator p_d2 = p_d1 + 1;
105 
106  TLorentzVector v_d1((*p_d1)->momentum().px(),(*p_d1)->momentum().py(),(*p_d1)->momentum().pz(),(*p_d1)->momentum().e());
107  TLorentzVector v_d2((*p_d2)->momentum().px(),(*p_d2)->momentum().py(),(*p_d2)->momentum().pz(),(*p_d2)->momentum().e());
108 
109  d1d2angle = v_d1.Angle(v_d2.Vect()); // get angle between v_d1 and v_d2
110  }
111 
112  float quarkonia_data[70] = {(float)_ievent,px,py,pz,pe,pt,eta,phi,invmass,ndaughter,d1d2angle};
113  _tree_quarkonia -> Fill(quarkonia_data);
114 
115  // cout << "Found a J/Psi in event " << _ievent << " with momentum " << pmom << " and which decays into " << ndecay << " particles:" << endl;
116 
117  //HepMC::IteratorRange irange = HepMC::children;
118 // for ( HepMC::GenVertex::particles_out_const_iterator p2 = (*p)->end_vertex()->particles_out_const_begin();
119 // p2 != (*p)->end_vertex()->particles_out_const_end(); ++p2 ) {
120 // cout << " -> " << (*p2)->pdg_id() << endl;
121 // }
122 
123  }
124 
125 
126 // TParticlePDG * pdg_p = TDatabasePDG::Instance()->GetParticle( (*p)->pdg_id() );
127 //
128 // if (pdg_p)
129 // {
130 // if (TString(pdg_p->GetName()) == "c")
131 // {
132 // cout << "Found a c-quark!" << endl;
133 // }
134 // if (TString(pdg_p->GetName()) == "c_bar")
135 // {
136 // cout << "Found a c-antiquark!" << endl;
137 // }
138 // if (TString(pdg_p->GetName()) == "J/psi" || TString(pdg_p->GetName()) == "J/psi_di")
139 // {
140 // cout << "Found a J/Psi!" << endl;
141 // }
142 // if (TString(pdg_p->GetName()) == "Upsilon")
143 // {
144 // cout << "Found an Upsilon!" << endl;
145 // }
146  // if (TString(pdg_p->GetName()) == "J/psi" && !(*p)->end_vertex() && (*p)->status() == 1 )
147  // {
148  // if((*p)->momentum().perp()>5.) _h2->Fill((*p)->momentum().perp(), (*p)->momentum().pseudoRapidity());
149  // if((*p)->momentum().perp()>5.) _h1->Fill((*p)->momentum().perp());
150  // if((*p)->momentum().perp()>5.) {
151  // const float px = (*p)->momentum().x(),
152  // py = (*p)->momentum().y(),
153  // pz = (*p)->momentum().z(),
154  // pt = (*p)->momentum().perp(),
155  // eta = (*p)->momentum().pseudoRapidity(),
156  // phi = (*p)->momentum().phi();
157  // float shower_data[70] = {(float)_ievent,px,py,pz,pt,eta,phi};
158  //
159  // _ntp_gamma -> Fill(shower_data);
160  //
161  // return 0;
162  // }
163  // }
164  // }
165  }
166 
168 }
169 
170 int
172 {
173  _fout_root->cd();
174  _tree_quarkonia->Write();
175  _fout_root->Close();
176 
177  return 0;
178 }
179 
180