Beispiel #1
0
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[]) {
  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;
}
Beispiel #3
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;
}