Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
photonJetGenerator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file photonJetGenerator.cc
1 #include "Pythia8/Pythia.h"
2 #include "Pythia8Plugins/HepMC2.h" //added plugin for HepMC, think we will need some new library in pythia for this
3 #include <TTree.h>
4 #include <TFile.h>
5 using namespace Pythia8;
6 using namespace std;
7 
8 void generator(std::string filename, long nEvents, bool signalOnly=false){
9  using namespace HepMC;
10  string hepName = filename+".dat"; //filenames
11  HepMC::Pythia8ToHepMC ToHepMC; // Interface for conversion from Pythia8::Event to HepMC event.
12  HepMC::IO_GenEvent ascii_io(hepName, std::ios::out); //file where HepMC events will be stored.
13 
14  /*pythia set up*/
15  Pythia pythiaengine;
16  pythiaengine.readString("Beams:eCM = 200.");
17  pythiaengine.readString("promptphoton:all = on");
18  pythiaengine.readString("HardQCD:all = on");
19  pythiaengine.readString("PhaseSpace:pTHatMin = 10.");
20  pythiaengine.readString("Random::setSeed = on");
21  pythiaengine.readString("Random::seed =0");
22  //pythiaengine.readString("111:onMode = off"); ///pi0 won't decay
23  pythiaengine.init();
24 
25  string tfilename = filename+"_analysis.root";
26  TFile *outFile = new TFile(tfilename.c_str(),"RECREATE");
27  TTree *photonTree = new TTree("photonTree","phat phirn tree");
28  photonTree->SetAutoSave(300);
29  vector<float> photon_pT;
30  photonTree->Branch("photon_pT",&photon_pT);
31  TTree *nophotonTree = new TTree("nophotonTree","phat phirn tree");
32  unsigned long noPhotonEvents=0;
33  nophotonTree->Branch("n",&noPhotonEvents);
34 
35  for (int iEvent = 0; iEvent < nEvents; ++iEvent)
36  {
37  if (!pythiaengine.next()){
38  cout<<"pythia.next() failed"<<"\n";
39  iEvent--;
40  continue;
41  }
42  photon_pT.clear();
43  for(unsigned ipart=0; ipart!=pythiaengine.event.size(); ipart++){
44  if(pythiaengine.event[ipart].id()==22&&pythiaengine.event[ipart].isFinal()&&pythiaengine.event[ipart].pT()>5
45  &&TMath::Abs(pythiaengine.event[ipart].eta()))photon_pT.push_back(pythiaengine.event[ipart].pT());
46  }
47  if (photon_pT.size()>0)photonTree->Fill();
48  else{
49  noPhotonEvents++;
50  }
51  if(!signalOnly||photon_pT.size()>0){
52  HepMC::GenEvent* hepmcevtfrag = new HepMC::GenEvent(); //create HepMC event
53  ToHepMC.fill_next_event( pythiaengine, hepmcevtfrag ); //convert event from pythia to HepMC
54  ascii_io << hepmcevtfrag;//write event to file
55  delete hepmcevtfrag; //delete event so it can be redeclared next time
56  }
57  }
58  nophotonTree->Fill();
59  outFile->Write();
60  outFile->Close();
61  pythiaengine.stat();
62 }
63 
64 int main(int argc, char const *argv[] )
65 {
66  string fileOut = string(argv[1]);
67  bool signalOnly=false;
68  if(argv[2][0]=='1'||argv[2][0]=='t')signalOnly=true;
69  long nEvents =strtol(argv[2],NULL,10); // 5000000;
70  generator(fileOut,nEvents,signalOnly);
71  cout<<"All done"<<endl;
72  return 0;
73 }