Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DirectPhotonPythia.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DirectPhotonPythia.C
1 #include "DirectPhotonPythia.h"
2 
3 #include <phool/getClass.h>
6 
8 
10 #include <g4main/PHG4Particle.h>
11 #include <g4main/PHG4Hit.h>
12 
13 #include <TLorentzVector.h>
14 #include <TTree.h>
15 #include <TFile.h>
16 #include <TString.h>
17 #include <TH2D.h>
18 #include <TDatabasePDG.h>
19 
20 #include <cmath>
21 #include <iostream>
22 
23 #include <g4jets/JetMap.h>
24 #include <g4jets/Jet.h>
25 
28 #include <HepMC/GenEvent.h>
29 #include <HepMC/GenVertex.h>
30 using namespace std;
31 
33  SubsysReco("DirectPhoton" ),
34  _embedding_id(1)
35 {
37 
38  _pt_min = 25;
39  _pt_max = 100;
40 
41  _eta_min = -.6;
42  _eta_max = +.6;
43 
45 }
46 
47 int
49 {
50 
51  _verbose = true;
52 
53  _ievent = 0;
54 
55  _total_pass = 0;
56 
57  _f = new TFile(_foutname.c_str(), "RECREATE");
58 
59  _h1 = new TH1D("h1", "", 100, 0, 100.0);
60  _h2 = new TH2D("h2", "", 100, 0, 100.0, 40, -2, +2);
61  _h2_b = new TH2D("h2_b", "", 100, 0, 100.0, 40, -2, +2);
62  _h2_c = new TH2D("h2_c", "", 100, 0, 100.0, 40, -2, +2);
63  _h2all = new TH2D("h2all", "", 100, 0, 100.0, 40, -2, +2);
64 
65  _ntp_gamma = new TNtuple("ntp_gamma","truth shower => best cluster","ev:px:py:pz:pt:eta:phi");
66 
67  return 0;
68 
69 }
70 
71 int
73 {
74  _ievent ++;
75 
76  PHHepMCGenEventMap * geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode, "PHHepMCGenEventMap");
77  if (!geneventmap)
78  {
79  std::cout <<PHWHERE<<" - Fatal error - missing node PHHepMCGenEventMap"<<std::endl;
81  }
82 
83  PHHepMCGenEvent *genevt = geneventmap->get(_embedding_id);
84  if (!genevt)
85  {
86  std::cout <<PHWHERE<<" - Fatal error - node PHHepMCGenEventMap missing subevent with embedding ID "<<_embedding_id;
87  std::cout <<". Print PHHepMCGenEventMap:";
88  geneventmap->identify();
90  }
91 
92  HepMC::GenEvent* theEvent = genevt->getEvent();
93 
94 
95 for (HepMC::GenEvent::particle_const_iterator p = theEvent->particles_begin();
96  p != theEvent->particles_end(); ++p)
97  {
98  TParticlePDG * pdg_p = TDatabasePDG::Instance()->GetParticle(
99  (*p)->pdg_id());
100  if (pdg_p)
101  {
102  if (TString(pdg_p->GetName()) == "gamma" && !(*p)->end_vertex() && (*p)->status() == 1 )
103  {
104  if((*p)->momentum().perp()>5.) _h2->Fill((*p)->momentum().perp(), (*p)->momentum().pseudoRapidity());
105  if((*p)->momentum().perp()>5.) _h1->Fill((*p)->momentum().perp());
106 
107  if((*p)->momentum().perp()>5.) {
108  const float px = (*p)->momentum().x(),
109  py = (*p)->momentum().y(),
110  pz = (*p)->momentum().z(),
111  pt = (*p)->momentum().perp(),
112  eta = (*p)->momentum().pseudoRapidity(),
113  phi = (*p)->momentum().phi();
114  float shower_data[70] = {(float)_ievent,px,py,pz,pt,eta,phi};
115 
116  _ntp_gamma -> Fill(shower_data);
117 
118  return 0;
119  }
120  }
121  }
122  }
123 
125 }
126 
127 int
129 {
130 
132  std::cout << __PRETTY_FUNCTION__ << " DVP PASSED " << _total_pass
133  << " events" << std::endl;
134 
135  _f->cd();
136  _f->Write();
137  //_f->Close();
138 
139  return 0;
140 }
141 
142