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