int main(int argc, char* argv[]) { char tune[25]; char seed[25]; //tune = "5"; //seed = "1370"; strncpy(tune,"5",25); strncpy(seed,"1370",25); //TODO this has gotten big enough to require real command line //options, setup and option parser and do it right. Someone's going //to get headaches over this very soon //TODO add seeds back as an option, required for running on condor! if(argc < 3) { cerr<<"Usage: "<<argv[0]<<" [config file] [out file] [conf lines ...]"<<endl; return 1; } ifstream is(argv[1]); if (!is) { cerr << " Command-line file " << argv[1] << " was not found. \n" << " Program stopped! " << endl; return 1; } cout<<"Configuring PYTHIA from "<<argv[1]<<endl; cout<<"Writing output to "<<argv[2]<<endl; vector<std::string> commandStrings; for(int i=3; i < argc; i++){ commandStrings.push_back(string(argv[i])); cout <<" Got Pythia command: "<<commandStrings.back()<<endl; } cout <<"Warning, command line arguments aren't type-checked, don't be stupid." <<endl; HepMC::Pythia8ToHepMC ToHepMC; HepMC::IO_GenEvent ascii_io(argv[2], std::ios::out); char processline[128]; Pythia pythia; pythia.readFile(argv[1]); int nRequested = 100; nRequested = pythia.mode("Main:numberOfEvents"); int nAbort = pythia.mode("Main:timesAllowErrors"); // Set the seed pythia.readString("Random:setSeed = on"); sprintf(processline,"Random:seed = %s",seed); pythia.readString(processline); // Set the tune sprintf(processline,"Tune:pp = %s",tune); pythia.readString(processline); for(std::vector<std::string>::const_iterator cmd = commandStrings.begin(); cmd != commandStrings.end(); ++cmd){ pythia.readString(*cmd); } pythia.init(); int iAbort = 0; int nGenerated=0; std::vector<int> requestedPdgId;//(3,0); int pid=0; bool keep=false; while(nGenerated < nRequested) { pid=0; keep=false; // requestedPdgId.clear(); if (!pythia.next()) { if (pythia.info.atEndOfFile()) { cout << " Aborted since reached end of Les Houches Event File\n"; break; } if (++iAbort < nAbort) continue; cout << " Event generation aborted prematurely, owing to error!\n"; break; } for(int i=0; i < pythia.event.size(); i++){ pid=abs(pythia.event[i].id()); if(pid == 443 || // J\psi pid == 10441 || //Chi_0 pid == 20443 || //Chi_1 pid == 445 || //Chi_2 pid == 100443 /*pid ==13 */){ keep=true; break; } } if(!keep){ continue; } HepMC::GenEvent* hepmcevt = new HepMC::GenEvent(HepMC::Units::GEV, HepMC::Units::MM); ToHepMC.fill_next_event( pythia, hepmcevt ); ascii_io << hepmcevt ; delete hepmcevt; nGenerated++; } pythia.stat(); return 0; }
int main(int argc, char **argv) { //initial arguments int seed = -1; char seedString[32]; char inputFile[1000]; char outputFile[1000]; sprintf(inputFile, "pythia_inclusive.cmnd"); sprintf(outputFile, "pythiatree.root"); for (int i = 1; i < argc; i=i+2){ if(!strcmp(argv[i], "-t")) strcpy(inputFile, argv[i + 1]); if(!strcmp(argv[i], "-s")) seed = atoi(argv[i+1]); if(!strcmp(argv[i], "-o")) strcpy(outputFile, argv[i + 1]); } // Generator. Pythia pythia; // Shorthand for the event record in pythia. Event& event = pythia.event; // Read in commands from external file. pythia.readString("Random:setSeed = on"); sprintf(seedString, "Random:seed = %d", seed); pythia.readString(seedString); pythia.readFile(inputFile); // Extract settings to be used in the main program. int nEvent = pythia.mode("Main:numberOfEvents"); int nAbort = pythia.mode("Main:timesAllowErrors"); // Initialize. pythia.init(); // Book histograms. TH1F *Hdummy = new TH1F("dummy histo", "dummy histo",10, 0, 1); TVector3 *getMomentum = new TVector3(); TVector3 *getPosition = new TVector3(); int eventID = 0; int nParticles; int particleID[10000]; int parentID[10000]; TClonesArray *fMomentum = new TClonesArray("TVector3"); fMomentum -> BypassStreamer(); TClonesArray& Momentum = *fMomentum; TClonesArray *fPosition = new TClonesArray("TVector3"); fPosition -> BypassStreamer(); TClonesArray& Position = *fPosition; //Make TTree TTree *pythiatree = new TTree("save", "save"); pythiatree -> Branch("eventID", &eventID, "eventID/I"); pythiatree -> Branch("n", &nParticles, "n/I"); pythiatree -> Branch("pdg", particleID, "pdg[n]/I"); pythiatree -> Branch("parent", parentID, "parent[n]/I"); pythiatree -> Branch("pos", &fPosition, 256000, 99); pythiatree -> Branch("mom", &fMomentum, 256000, 99); // Begin event loop. int iAbort = 0; int nMuons = 0; int nPions = 0; int nKaons = 0; for (int iEvent = 0; iEvent < nEvent; ++iEvent) { // Generate events. Quit if many failures. if (!pythia.next()) { if (++iAbort < nAbort) continue; cout << " Event generation aborted prematurely, owing to error!\n"; break; } // Loop over final particles in the event. for (int i = 0; i < event.size(); ++i){ //if (event[i].id() == 2212) { //cout << iEvent << " We got a proton! Energy: " << event[i].e() << " zProd: " << event[i].zDec()/1000 << " Mother1: " << event[event[i].mother1()].id() << endl; //} if(event[i].e() > minEnergy){ if (abs(event[i].id()) == 13) { if(event[i].zProd()/1000 < minZvtxDecay){ nMuons++; //cout << iEvent << " We got a muon! Energy: " << event[i].e() << " zProd: " << event[i].zProd()/1000 << " Mother1: " << event[event[i].mother1()].id() << endl; getMomentum -> SetXYZ(event[i].px(), event[i].py(), event[i].pz()); getPosition -> SetXYZ(event[i].xProd()*cm, event[i].yProd()*cm, event[i].zProd()*cm); nParticles++; particleID[nParticles-1] = event[i].id(); parentID[nParticles-1] = event[event[i].mother1()].id(); new(Momentum[nParticles-1]) TVector3(*getMomentum); new(Position[nParticles-1]) TVector3(*getPosition); //pythiatree -> Fill(); } } /* if (abs(event[i].id()) == 211){ if(event[i].zProd()/1000 < minZvtxDecay && event[i].zDec()/1000 > minZvtxDecay){ //if(event[i].zDec()/1000 > minZvtxDecay){ nPions++; //cout << iEvent << " We got a pion! Energy: " << event[i].e() << " zDec: " << event[i].zDec()/1000 << " zDec: " << event[i].zDec()/1000 << " Mother1: " << event[event[i].mother1()].id() << endl; getMomentum -> SetXYZ(event[i].px(), event[i].py(), event[i].pz()); getPosition -> SetXYZ(event[i].xProd()*cm, event[i].yProd()*cm, event[i].zProd()*cm); nParticles++; particleID[nParticles-1] = event[i].id(); parentID[nParticles-1] = event[event[i].mother1()].id(); new(Momentum[nParticles-1]) TVector3(*getMomentum); new(Position[nParticles-1]) TVector3(*getPosition); //pythiatree -> Fill(); } } if (abs(event[i].id()) == 321){ if(event[i].zProd()/1000 < minZvtxDecay && event[i].zDec()/1000 > minZvtxDecay){ //if(event[i].zDec()/1000 > minZvtxDecay){ nKaons++; //cout << iEvent << " We got a kaon! Energy: " << event[i].e() << " zDec: " << event[i].zDec()/1000 << " Mother1: " << event[event[i].mother1()].id() << endl; getMomentum -> SetXYZ(event[i].px(), event[i].py(), event[i].pz()); getPosition -> SetXYZ(event[i].xProd()*cm, event[i].yProd()*cm, event[i].zProd()*cm); nParticles++; particleID[nParticles-1] = event[i].id(); parentID[nParticles-1] = event[event[i].mother1()].id(); new(Momentum[nParticles-1]) TVector3(*getMomentum); new(Position[nParticles-1]) TVector3(*getPosition); //pythiatree -> Fill(); } } */ } } //fill tree, reset counters if(nParticles>0)pythiatree -> Fill(); eventID++; nParticles = 0.; fMomentum->Clear(); fPosition->Clear(); // End of event loop. } cout << "The total number of muons before dump is " << nMuons << endl; cout << "The total number of pions is " << nPions << endl; cout << "The total number of kaons is " << nKaons << endl; // Final statistics. Normalize and output histograms. pythia.stat(); // Create file on which histogram(s) can be saved. TFile* outFile = new TFile(outputFile, "RECREATE"); // Save histogram on file and close file. pythiatree -> Write(); outFile -> Close(); delete outFile; delete pythiatree; // Done. return 0; }