Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DirectPhotonPythia_W.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file DirectPhotonPythia_W.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 {
36 
37  _foutname = filename;
38 
39  _pt_min = 25;
40  _pt_max = 100;
41 
42  _eta_min = -.6;
43  _eta_max = +.6;
44 
45  _rejection_action = Fun4AllReturnCodes::DISCARDEVENT;
46 }
47 
48 int
50 {
51 
52  _verbose = true;
53 
54  _ievent = 0;
55 
56  _total_pass = 0;
57 
58  _f = new TFile(_foutname.c_str(), "RECREATE");
59 
60  _h1 = new TH1D("h1", "", 100, 0, 100.0);
61  _h2 = new TH2D("h2", "", 100, 0, 100.0, 40, -2, +2);
62  _h2_b = new TH2D("h2_b", "", 100, 0, 100.0, 40, -2, +2);
63  _h2_c = new TH2D("h2_c", "", 100, 0, 100.0, 40, -2, +2);
64  _h2all = new TH2D("h2all", "", 100, 0, 100.0, 40, -2, +2);
65 
66  _ntp_gamma = new TNtuple("ntp_gamma","truth shower => best cluster","ev:px:py:pz:pt:eta:phi");
67 
68  return 0;
69 
70 }
71 
72 int
74 {
75  _ievent ++;
76 
77  PHHepMCGenEventMap * geneventmap = findNode::getClass<PHHepMCGenEventMap>(topNode, "PHHepMCGenEventMap");
78  if (!geneventmap)
79  {
80  std::cout <<PHWHERE<<" - Fatal error - missing node PHHepMCGenEventMap"<<std::endl;
82  }
83 
84  PHHepMCGenEvent *genevt = geneventmap->get(_embedding_id);
85  if (!genevt)
86  {
87  std::cout <<PHWHERE<<" - Fatal error - node PHHepMCGenEventMap missing subevent with embedding ID "<<_embedding_id;
88  std::cout <<". Print PHHepMCGenEventMap:";
89  geneventmap->identify();
91  }
92 
93  HepMC::GenEvent* theEvent = genevt->getEvent();
94 
95 
96 for (HepMC::GenEvent::particle_const_iterator p = theEvent->particles_begin();
97  p != theEvent->particles_end(); ++p)
98  {
99  TParticlePDG * pdg_p = TDatabasePDG::Instance()->GetParticle(
100  (*p)->pdg_id());
101  if (pdg_p)
102  {
103  if (TString(pdg_p->GetName()) == "gamma")
104  {
105  // cout <<"Find gamma at eta = "<< (*p)->momentum().pseudoRapidity() <<endl;
106 
107  if((*p)->momentum().perp()>5.) _h2->Fill((*p)->momentum().perp(), (*p)->momentum().pseudoRapidity());
108  if((*p)->momentum().perp()>5.) _h1->Fill((*p)->momentum().perp());
109 
110  if((*p)->momentum().perp()>5.) {
111  const float px = (*p)->momentum().x(),
112  py = (*p)->momentum().y(),
113  pz = (*p)->momentum().z(),
114  pt = (*p)->momentum().perp(),
115  eta = (*p)->momentum().pseudoRapidity(),
116  phi = (*p)->momentum().phi();
117  float shower_data[70] = {(float)_ievent,px,py,pz,pt,eta,phi};
118 
119  _ntp_gamma -> Fill(shower_data);
120  }
121  }
122  }
123  }
124 
125  return 0;;
126 }
127 
128 int
130 {
131 
133  std::cout << __PRETTY_FUNCTION__ << " DVP PASSED " << _total_pass
134  << " events" << std::endl;
135 
136  _f->cd();
137  _f->Write();
138  //_f->Close();
139 
140  return 0;
141 }
142 
143