Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
generator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file generator.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("SoftQCD:nonDiffractive = on");
18  pythiaengine.readString("SoftQCD:singleDiffractive = on");
19  pythiaengine.readString("SoftQCD:doubleDiffractive = on");
20  pythiaengine.readString("PhaseSpace:pTHatMin = 0");
21  pythiaengine.readString("Random::setSeed = on");
22  pythiaengine.readString("Random::seed =0");
23  //pythiaengine.readString("111:onMode = off"); ///pi0 won't decay
24  pythiaengine.init();
25 
26  string tfilename = filename+"_analysis.root";
27  TFile *outFile = new TFile(tfilename.c_str(),"RECREATE");
28  TTree *photonTree = new TTree("photonTree","phat phirn tree");
29  photonTree->SetAutoSave(300);
30  vector<float> photon_pT;
31  photonTree->Branch("photon_pT",&photon_pT);
32  TTree *nophotonTree = new TTree("nophotonTree","phat phirn tree");
33  unsigned noPhotonEvents=0;
34  nophotonTree->Branch("nNoPhoton",&noPhotonEvents);
35 
36  for (int iEvent = 0; iEvent < nEvents; ++iEvent)
37  {
38  if (!pythiaengine.next()){
39  cout<<"pythia.next() failed"<<"\n";
40  iEvent--;
41  continue;
42  }
43  photon_pT.clear();
44  for(unsigned ipart=0; ipart!=pythiaengine.event.size(); ipart++){
45  if(pythiaengine.event[ipart].id()==22&&pythiaengine.event[ipart].isFinal()&&pythiaengine.event[ipart].pT()>5
46  &&TMath::Abs(pythiaengine.event[ipart].eta()))photon_pT.push_back(pythiaengine.event[ipart].pT());
47  }
48  if (photon_pT.size()>0)photonTree->Fill();
49  else{
50  noPhotonEvents++;
51  }
52 /* if(!signalOnly||photon_pT.size()>0){
53  HepMC::GenEvent* hepmcevtfrag = new HepMC::GenEvent(); //create HepMC event
54  ToHepMC.fill_next_event( pythiaengine, hepmcevtfrag ); //convert event from pythia to HepMC
55  ascii_io << hepmcevtfrag;//write event to file
56  delete hepmcevtfrag; //delete event so it can be redeclared next time
57  }*/
58  }
59  nophotonTree->Fill();
60  outFile->Write();
61  outFile->Close();
62  pythiaengine.stat();
63 }
64 
65 int main(int argc, char const *argv[] )
66 {
67  string fileOut = string(argv[1]);
68  bool signalOnly=false;
69  if(argv[2][0]=='1'||argv[2][0]=='t')signalOnly=true;
70  long nEvents =strtol(argv[2],NULL,10); // 5000000;
71  generator(fileOut,nEvents,signalOnly);
72  cout<<"All done"<<endl;
73  return 0;
74 }