int main(int argc, char **argv) { TROOT root("pythia","run pythia"); // CONSTANT if( argc < 3 ){ std::cout<<Form("usage : ./%s <output> <random_seed>",argv[0])<<std::endl; exit(1); } char *outFile = argv[1]; Int_t random_seed = atoi(argv[2]); TFile *fout = new TFile(outFile,"recreate"); // Generator. Pythia pythia; // Shorthand for some public members of pythia (also static ones). Event& event = pythia.event; //ParticleDataTable& pdt = pythia.particleData; Info& info = pythia.info; // Read in commands from external file. pythia.readFile("main03.cmnd"); // Extract settings to be used in the main program. int nEvent = pythia.mode("Main:numberOfEvents"); int nList = pythia.mode("Main:numberToList"); int nShow = pythia.mode("Main:timesToShow"); bool showCS = pythia.flag("Main:showChangedSettings"); //bool showCPD = pythia.flag("Main:showChangedParticleData"); pythia.readString(Form("Random:seed=%d",random_seed)); // Initialize. Beam parameters set in .cmnd file. pythia.init(); // List changed data. if (showCS) pythia.settings.listChanged(); //if (showCPD) pdt.listChanged(); // Book histograms. TH1D *pThard = new TH1D("pThard","process pT scale", 100, 0., 200.); pThard->Sumw2(); TH1D *mult = new TH1D("mult","charged particle multiplicity", 100, -0.5, 799.5);mult->Sumw2(); TH1D *dndy = new TH1D("dndy","dn/dy for charged particles", 100, -10., 10.);dndy->Sumw2(); TH1D *dndpT_hadron = new TH1D("dndpT_hadron","dn/dpT for charged particles", 500, 0., 50.);dndpT_hadron->Sumw2(); TH1D *dndpT_pion = new TH1D("dndpT_pion","dn/dpT for pions", 500, 0., 50.);dndpT_pion->Sumw2(); TH1D *dndpT_kaon = new TH1D("dndpT_kaon","dn/dpT for kaons", 500, 0., 50.);dndpT_kaon->Sumw2(); TH1D *dndpT_proton = new TH1D("dndpT_proton","dn/dpT for protons", 500, 0., 50.);dndpT_proton->Sumw2(); TH1D *dndpT_antiproton = new TH1D("dndpT_antiproton","dn/dpT for antiprotons", 500, 0., 50.);dndpT_antiproton->Sumw2(); TH1D *dndpT_k0s = new TH1D("dndpT_k0s","dn/dpT for k0s", 500, 0., 50.);dndpT_k0s->Sumw2(); TH1D *dndpT_infly_hadron = new TH1D("dndpT_infly_hadron","dn/dpT for charged particles", 500, 0., 50.);dndpT_infly_hadron->Sumw2(); TH1D *dndpT_infly_pion = new TH1D("dndpT_infly_pion","dn/dpT for pions", 500, 0., 50.);dndpT_infly_pion->Sumw2(); TH1D *dndpT_infly_kaon = new TH1D("dndpT_infly_kaon","dn/dpT for kaons", 500, 0., 50.);dndpT_infly_kaon->Sumw2(); TH1D *dndpT_infly_proton = new TH1D("dndpT_infly_proton","dn/dpT for protons", 500, 0., 50.);dndpT_infly_proton->Sumw2(); TH1D *dndpT_infly_antiproton = new TH1D("dndpT_infly_antiproton","dn/dpT for antiprotons", 500, 0., 50.);dndpT_infly_antiproton->Sumw2(); TH1D *dndpT_hadron_mid = new TH1D("dndpT_hadron_mid","dn/dpT for charged particles |eta|<0.35", 500, 0., 50.);dndpT_hadron_mid->Sumw2(); TH1D *dndpT_pion_mid = new TH1D("dndpT_pion_mid","dn/dpT for pions |eta|<0.35", 500, 0., 50.);dndpT_pion_mid->Sumw2(); TH1D *dndpT_kaon_mid = new TH1D("dndpT_kaon_mid","dn/dpT for kaon |eta|<0.35", 500, 0., 50.);dndpT_kaon_mid->Sumw2(); TH1D *dndpT_proton_mid = new TH1D("dndpT_proton_mid","dn/dpT for proton |eta|<0.35", 500, 0., 50.);dndpT_proton_mid->Sumw2(); TH1D *dndpT_antiproton_mid = new TH1D("dndpT_antiproton_mid","dn/dpT for antiproton |eta|<0.35", 500, 0., 50.);dndpT_antiproton_mid->Sumw2(); TH1D *dndpT_infly_hadron_mid = new TH1D("dndpT_infly_hadron_mid","dn/dpT for charged particles |eta|<0.35", 500, 0., 50.);dndpT_infly_hadron_mid->Sumw2(); TH1D *dndpT_infly_pion_mid = new TH1D("dndpT_infly_pion_mid","dn/dpT for pions |eta|<0.35", 500, 0., 50.);dndpT_infly_pion_mid->Sumw2(); TH1D *dndpT_infly_kaon_mid = new TH1D("dndpT_infly_kaon_mid","dn/dpT for kaon |eta|<0.35", 500, 0., 50.);dndpT_infly_kaon_mid->Sumw2(); TH1D *dndpT_infly_proton_mid = new TH1D("dndpT_infly_proton_mid","dn/dpT for proton |eta|<0.35", 500, 0., 50.);dndpT_infly_proton_mid->Sumw2(); TH1D *dndpT_infly_antiproton_mid = new TH1D("dndpT_infly_antiproton_mid","dn/dpT for antiproton |eta|<0.35", 500, 0., 50.);dndpT_infly_antiproton_mid->Sumw2(); TH1D *dndpT_k0s_mid = new TH1D("dndpT_k0s_mid","dn/dpT for k0s |eta|<0.35", 500, 0., 50.);dndpT_k0s_mid->Sumw2(); TStopwatch timer; timer.Start(); // Begin event loop. int nPace = max(1, nEvent / max(1, nShow) ); for (int iEvent = 0; iEvent < nEvent; ++iEvent) { if (nShow > 0 && iEvent%nPace == 0) cout << " Now begin event " << iEvent << endl; // Generate events. Quit if failure. if (!pythia.next()) { cout << " Event generation aborted prematurely, owing to error!\n"; break; } // List first few events, both info, hard process and complete events. if (iEvent < nList) { info.list(); pythia.process.list(); event.list(); } // Fill hard scale of event. pThard->Fill( info. pTHat() ); // Loop over final charged particles in the event. int nCharged = 0; for (int i = 0; i < event.size(); ++i) { // for k0s if (event[i].id()==310 ) dndpT_k0s->Fill(event[i].pT()); if(event[i].eta()>-0.35&&event[i].eta()<0.35) { if (event[i].id()==310 ) dndpT_k0s_mid->Fill(event[i].pT()); } // Infly decay dndpT_infly_hadron->Fill( event[i].pT() ); if (event[i].id()==211 || event[i].id()==-211 ) dndpT_infly_pion->Fill(event[i].pT()); if (event[i].id()==321 || event[i].id()==-321 ) dndpT_infly_kaon->Fill(event[i].pT()); if (event[i].id()==2212) dndpT_infly_proton->Fill(event[i].pT()); if (event[i].id()==-2212 ) dndpT_infly_antiproton->Fill(event[i].pT()); if(event[i].eta()>-0.35&&event[i].eta()<0.35) { dndpT_infly_hadron_mid->Fill( event[i].pT() ); if (event[i].id()==211 || event[i].id()==-211 ) dndpT_infly_pion_mid->Fill(event[i].pT()); if (event[i].id()==321 || event[i].id()==-321 ) dndpT_infly_kaon_mid->Fill(event[i].pT()); if (event[i].id()==2212) dndpT_infly_proton_mid->Fill(event[i].pT()); if (event[i].id()==-2212) dndpT_infly_antiproton_mid->Fill(event[i].pT()); } // hadron in final state if (event[i].isFinal()&&event[i].isCharged()) { dndpT_hadron->Fill( event[i].pT() ); if (event[i].id()==211 || event[i].id()==-211 ) dndpT_pion->Fill(event[i].pT()); if (event[i].id()==321 || event[i].id()==-321 ) dndpT_kaon->Fill(event[i].pT()); if (event[i].id()==2212) dndpT_proton->Fill(event[i].pT()); if (event[i].id()==-2212 ) dndpT_antiproton->Fill(event[i].pT()); } if(event[i].isFinal()&&event[i].isCharged()&&event[i].eta()>-0.35&&event[i].eta()<0.35) { dndpT_hadron_mid->Fill( event[i].pT() ); if (event[i].id()==211 || event[i].id()==-211 ) dndpT_pion_mid->Fill(event[i].pT()); if (event[i].id()==321 || event[i].id()==-321 ) dndpT_kaon_mid->Fill(event[i].pT()); if (event[i].id()==2212) dndpT_proton_mid->Fill(event[i].pT()); if (event[i].id()==-2212) dndpT_antiproton_mid->Fill(event[i].pT()); } // Analyze charged particles and fill histograms. if(event[i].isFinal()&&event[i].isCharged()) { ++nCharged; dndy->Fill( event[i].y() ); } // End of particle and event loops. Fill charged multiplicity. } mult->Fill( nCharged ); } // Final statistics. Normalize and output histograms. pythia.statistics(); timer.Stop(); timer.Print(); fout->cd(); pThard->Write(); mult->Write(); dndy->Write(); dndpT_hadron->Write(); dndpT_pion->Write(); dndpT_kaon->Write(); dndpT_proton->Write(); dndpT_antiproton->Write(); dndpT_infly_hadron->Write(); dndpT_infly_pion->Write(); dndpT_infly_kaon->Write(); dndpT_infly_proton->Write(); dndpT_infly_antiproton->Write(); dndpT_k0s->Write(); dndpT_hadron_mid->Write(); dndpT_pion_mid->Write(); dndpT_kaon_mid->Write(); dndpT_proton_mid->Write(); dndpT_antiproton_mid->Write(); dndpT_infly_hadron_mid->Write(); dndpT_infly_pion_mid->Write(); dndpT_infly_kaon_mid->Write(); dndpT_infly_proton_mid->Write(); dndpT_infly_antiproton_mid->Write(); dndpT_k0s_mid->Write(); fout->Write(); fout->Close(); // Done. return 0; }
int main(int argc, char* argv[]) { if (argc < 3) { cerr << " Unexpected number of command-line arguments. \n You are" << " expected to provide a number of events and an output file. \n" << "By default, this executable generates events wil 800<m(ff)<100" << " and no Z'." << "To generate a Z', pass a positive value of Z' mass:" << " -massZp=MASSVALUE" << "To extend the mass range:" << " -mMin=MinMass" << " -mMax=MaxMass" << " Program stopped! " << endl; return 1; } int Nevents = 0; sscanf(argv[1],"%i",&Nevents); string hepmcout(string(argv[2])+".hepmc"); float energy = 14000.; float mMin = 80.; float mMax = 100; float massZp = -99.; for (int i=1;i<argc;i++){ if (strncmp(argv[i],"-setEnergy=",11)==0) sscanf(argv[i],"-setEnergy=%f",&energy); if (strncmp(argv[i],"-massZp=",8)==0) { sscanf(argv[i],"-massZp=%f",&massZp); cout << "WARNING: gamma*/Z/Z' (with Z'mass " << massZp << ") will be generated" << endl; } else { cout << "WARNING: gamma*/Z will be generated" << endl; } if (strncmp(argv[i],"-mMin=",5)==0) sscanf(argv[i],"-mMin=%f",&mMin); if (strncmp(argv[i],"-mMax=",5)==0) sscanf(argv[i],"-mMax=%f",&mMax); } // Interface for conversion from Pythia8::Event to HepMC one. HepMC::I_Pythia8 ToHepMC; // Specify file where HepMC events will be stored. HepMC::IO_GenEvent ascii_io(hepmcout.c_str(), std::ios::out); // Generator. Pythia pythia; char command[512]; if(massZp<0.) { pythia.readString("WeakSingleBoson:ffbar2gmZ = on"); sprintf(command, "PhaseSpace:mHatMin = %f", mMin); pythia.readString(command); sprintf(command, "PhaseSpace:mHatMax = %f", mMax); pythia.readString(command); } else { pythia.readString("NewGaugeBoson:ffbar2gmZZprime = on ! full gamma*/Z^0/Z'^0 production"); sprintf(command, "32:m0 = 1000. ! Z' mass", massZp); pythia.readString(command); sprintf(command, "32:mMin = %f ", mMin); pythia.readString(command); sprintf(command, "32:mMax = %f ", mMax); pythia.readString(command); } // setup energy pythia.init(2212, 2212, energy); // List settings. pythia.settings.listChanged(); // List particle data. pythia.particleData.listChanged(); for (int iEvent = 0; iEvent < Nevents; ++iEvent) { if (!pythia.next()) continue; // Construct new empty HepMC event. HepMC::GenEvent* hepmcevt = new HepMC::GenEvent(); // Fill HepMC event, including PDF info. ToHepMC.fill_next_event( pythia, hepmcevt ); // Write the HepMC event to file. Done with it. ascii_io << hepmcevt; delete hepmcevt; // End of event loop. } // Give statistics. pythia.statistics(); // run Delphes string OUTPUT_ATLAS = string(argv[2])+"_DelphesATLAS.root"; string OUTPUT_CMS = string(argv[2])+"_DelphesCMS.root"; system(string(string("echo ")+string(hepmcout)+string(" >> ")+string(hepmcout)+string(".list")).c_str()); system(string(string("cd Delphes; ./Delphes ")+string(hepmcout)+string(".list ")+OUTPUT_ATLAS+string(" data/DetectorCard_ATLAS.dat data/TriggerCard_ATLAS.dat")).c_str()); system(string(string("cd Delphes; ./Delphes ")+string(hepmcout)+string(".list ")+OUTPUT_CMS+string(" data/DetectorCard_CMS.dat data/TriggerCard_CMS.dat")).c_str()); system(string(string("rm ")+string(hepmcout)+string(".list")).c_str()); // Done. return 0; }