Main Page | Namespace List | Class List | Directories | File List | Class Members | File Members

makePyEvts.C

Go to the documentation of this file.
00001 // Program to use Pythia to generate H->ZZ; Z->mu+mu- from within ROOT.
00002 // To make an event sample (of size 100) do 
00003 //
00004 //    shell> root
00005 //    root [0] .L makePyEvts.C
00006 //    root [1] makePyEvts(100)
00007 //
00008 //
00009 #define ECM 14000
00010 
00011 // nEvents is how many events we want. 
00012 int makePyEvts(int nEvents) 
00013 { 
00014 
00015   double P4TOT[4];
00016   // Create an instance of the Pythia event generator ... 
00017  
00018   TPythia6* pythia = new TPythia6; 
00019 
00020   TH1F *h1 = new TH1F("h1","Higgs Mass",50,100.0,200.0);
00021   
00022   // Initialise it to run p+p at ECM GeV in CMS 
00023 
00024   pythia->SetMSEL(0);        //Full user control 
00025   pythia->SetMSUB(102,1);    //Select gg->Higgs
00026   pythia->SetPMAS(25,1,175); //Set Higgs mass
00027   pythia->SetMSTP(61,0);     //Turn off initial-state radiation
00028  
00029  // Turn off all Z decay modes; then turn on correct mode
00030   int KF = 23;               // 
00031   int idcmin = pythia->GetMDCY(KF,2);
00032   int idcmax = idcmin + pythia->GetMDCY(KF,3);
00033   cout<<"MyOutput: Z idcmin="<<idcmin<<" idcmax="<<idcmax<<endl;
00034   for (int idc = idcmin; idc < idcmax; idc++)
00035     {
00036       pythia->SetMDME(idc,1,0);
00037     }   
00038   pythia->SetMDME(184,1,1);
00039  
00040  // Turn off all Higgs (h0) decay modes; then turn on correct mode
00041   int KF = 25;               // 
00042   int idcmin = pythia->GetMDCY(KF,2);
00043   int idcmax = idcmin + pythia->GetMDCY(KF,3);
00044   cout<<"MyOutput: Higgs idcmin="<<idcmin<<" idcmax="<<idcmax<<endl;
00045   for (int idc = idcmin; idc < idcmax; idc++)
00046     {
00047       pythia->SetMDME(idc,1,0);
00048     }   
00049   pythia->SetMDME(225,1,1);
00050   
00051   //Set collision
00052   pythia->Initialize("cms", "p", "p", ECM);
00053   #define FILENAME   "pythia.root"
00054   #define TREENAME   "tree"
00055   #define BRANCHNAME "particles"
00056 
00057  // Open an output file 
00058   TFile* file = TFile::Open(FILENAME, "RECREATE"); 
00059   if (!file || !file->IsOpen()) {
00060     Error("makeEventSample", "Couldn;t open file %s", FILENAME);
00061     return 1;
00062   }  
00063 
00064 
00065   // Make a tree in that file ... 
00066   TTree* tree = new TTree(TREENAME, "Pythia 6 tree"); 
00067    
00068   // Register a the cache of pythia on a branch (It's a 
00069   // TClonesArray of TMCParticle objects. )
00070   TClonesArray* particles = (TClonesArray*)pythia->GetListOfParticles();
00071   tree->Branch(BRANCHNAME, &particles); 
00072   int KF_muon =13;
00073   // Now generate events
00074   for (Int_t ievt = 0; ievt < nEvents; ievt++) {
00075     // Show how far we got every 100'th event. 
00076     if (ievt % 100 == 0) 
00077       cout << "Event # " << ievt << endl;
00078 
00079     // Make one event. 
00080     pythia->GenerateEvent();
00081  // Now we're ready to fill the tree, and the event is over. 
00082     tree->Fill();
00083     //
00084         
00085     for (Int_t i=0; i<4; i++){P4TOT[i]=0.0;}
00086     //P4TOT[0]=0.0;
00087     //P4TOT[1]=0.0;
00088     //P4TOT[2]=0.0;
00089     //P4TOT[3]=0.0;
00090 
00091   //Get some event information!
00092   //Total number of Pythia tracks
00093     Int_t N = pythia->GetN();
00094     //cout << "MyOutput: Number of Pythia tracks ="<<N<<endl;
00095     //Loop over all tracks
00096 
00097     Int_t N_muons =0;     // initialize number muons
00098     for (Int_t itk =1; itk<=N; itk++){
00099       Int_t KS = pythia->GetK(itk,1); //KS code
00100       Int_t KF = pythia->GetK(itk,2); //KF code
00101       if ((abs(KF)== KF_muon)&&(KS!=21)){
00102         N_muons++;
00103         P4TOT[0]=P4TOT[0]+pythia->GetP(itk,1); // get track 4-vector
00104         P4TOT[1]=P4TOT[1]+pythia->GetP(itk,2);  
00105         P4TOT[2]=P4TOT[2]+pythia->GetP(itk,3);
00106         P4TOT[3]=P4TOT[3]+pythia->GetP(itk,4);
00107       }//if             
00108     }//itk
00109     //cout << "MyOutput: Number of muons =" << N_muons<<endl; 
00110     Float_t Hmass2 = pow(P4TOT[3],2)-pow(P4TOT[0],2)-pow(P4TOT[1],2)-pow(P4TOT[2],2); 
00111     Float_t Hmass=0.0;
00112     if (Hmass2 >= 0.0) {Hmass = sqrt(Hmass2);}
00113     else {Hmass = -sqrt(abs(Hmass2));}
00114     //    cout<<"Mass(#mu^+#mu^-#mu^+#mu^-) "<<Hmass<<endl;
00115     h1->Fill(Hmass);
00116  }//ievt
00117 
00118 
00119 
00120    gROOT->Reset();
00121    c1 = new TCanvas("c1","pp -> H-> ZZ",200,10,700,500);
00122    c1->SetFillColor(42);
00123    c1->SetGrid();
00124 
00125   title = new TPaveLabel(0.1,0.94,0.9,0.98,
00126           "Pythia MC: pp -> H -> ZZ");
00127   title->SetFillColor(16);
00128   title->SetTextFont(52);
00129   title->Draw();
00130 
00131   h1->GetXaxis()->SetTitle("CM energy (GeV)");
00132   h1->GetXaxis()->CenterTitle();
00133   h1->GetYaxis()->SetTitle("Number Events/(2 GeV)");
00134   h1->GetYaxis()->CenterTitle();
00135   h1->GetYaxis()->SetRangeUser(0,1400);
00136   h1->GetXaxis()->SetRangeUser(140,200);
00137   h1->SetMarkerStyle(21);
00138   h1->SetMarkerColor(31);
00139   h1->SetMarkerSize(1);
00140   h1->SetLineColor(2);
00141   h1->SetLineWidth(4);
00142   h1->SetTitle("pp #rightarrow H #rightarrow ZZ");
00143   h1->Draw("e1p");
00144 
00145    c1->Update();
00146    c1->GetFrame()->SetFillColor(21);
00147    c1->GetFrame()->SetBorderSize(3);
00148    c1->Modified();  
00149 
00150 
00151    //  h1->SetMarkerStyle(21);
00152    //h1->SetMarkerSize(0.7);
00153    //h1->Draw("e1p");
00154    pythia->Pystat(2);
00155    pythia->Pystat(4);
00156    pythia->Pylist(11);
00157    pythia->Pylist(12);
00158    pythia->Draw();
00159 
00160 }//makePyEvts
00161 
00162 
00163 //____________________________________________________________________ 
00164 //  
00165 // EOF
00166 //
00167 

Generated on Thu Jul 12 14:04:54 2007 for RebassooAnalysis by  doxygen 1.3.9.1