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

makePythiagamma.C

Go to the documentation of this file.
00001 // Program to use Pythia to generate H->gamm,gamma from within ROOT.
00002 // To make an event sample (of size 100) do 
00003 //
00004 //    shell> root
00005 //    root [0] .L makePyEvtsgammagamma.C
00006 //    root [1] makePyEvts(100,800)
00007 //
00008 //
00009 #define ECM 14000
00010 // using namespace TMath;
00011 
00012 #include <iostream>
00013 using namespace std;
00014 
00015 #include "TStopwatch.h"
00016 #include "TH1F.h"
00017 #include "TH2F.h"
00018 #include "TF1.h"
00019 #include "TPythia6.h"
00020 #include "TCanvas.h"
00021 #include "TMath.h"
00022 #include "TRandom2.h"
00023 #include "TLorentzVector.h"
00024 #include "TVector3.h"
00025 #include "TVector2.h"
00026 #include "TFile.h"
00027 #include "TROOT.h"
00028 
00029 //double higgswidth;
00030 
00031 // nEvents is how many events we want. 
00032 int makePyEvts(int nEvents,float Higgsmass = 300 ) 
00033 { 
00034 
00035 
00036   // Create an instance of the Pythia event generator ... 
00037   TPythia6* pythia = new TPythia6; 
00038 
00039  
00040   // Initialise it to run p+p at ECM GeV in CMS 
00041 
00042   pythia->SetMSEL(0);        //Full user control 
00043   pythia->SetMSUB(102,1);    //Select gg->Higgs
00044   pythia->SetPMAS(25,1,Higgsmass); //Set Higgs mass
00045   pythia->SetMSTP(61,0);     //Turn off initial-state radiation
00046   //  pythia->SetMSTP(71,0);     //Turn off final-state QCD and QED radiation
00047   //  pythia->SetMSTP(81,0);
00048   //  pythia->SetMSTP(111,0);
00049  
00050  // Turn off all Higgs (h0) decay modes; then turn on correct mode
00051  
00052   int KF = 25;               // 
00053   int idcmin = pythia->GetMDCY(KF,2);
00054   int idcmax = idcmin + pythia->GetMDCY(KF,3);
00055   cout<<"MyOutput: Higgs idcmin="<<idcmin<<" idcmax="<<idcmax<<endl;
00056 
00057   for (int idc = idcmin; idc < idcmax; idc++)
00058     {
00059       pythia->SetMDME(idc,1,0);
00060     }   
00061   pythia->SetMDME(223,1,1);
00062   
00063   //Set collision
00064   pythia->Initialize("cms", "p", "p", ECM);
00065 
00066  
00067 
00068   float higgswidth = pythia->GetPMAS(25,2);
00069   float higgs_generated_mass = 0;
00070   cout<<"The higgs width from Pythia is "<<higgswidth<<endl;
00071 
00072 
00073   TStopwatch watcher;
00074   watcher.Reset();
00075   watcher.Start();
00076 
00077 
00078   float Higgsmass_max = 3000;
00079   float Higgsmaxplot = 3000;
00080   float Higgsminplot = 0.0;
00081 
00082   int Nbins = 500;
00083       if (Higgsmass<191)
00084     {
00085       Nbins = 500;
00086       Higgsmaxplot = Higgsmass + 5 * higgswidth;
00087       Higgsminplot = Higgsmass - 5 * higgswidth;
00088       }
00089 
00090 
00091   TH1F *Hmass = new TH1F("Hmass","Higgs Mass",Nbins,Higgsminplot,Higgsmaxplot);
00092   TH1F *Hpt = new TH1F("Hpt","Higgs Tranverse Momentum",500,0.,500.0);
00093   TH1F *Hgeneratedmass = new TH1F("Hgeneratedmass","Higgs Generated Mass",Nbins,Higgsminplot,Higgsmaxplot);
00094 
00095   // Now generate events
00096 
00097   int Num = 0;
00098   //loop over the events
00099   for (Int_t ievt = 0; ievt < nEvents; ievt++) 
00100     {
00101       // Show how far we got every 100'th event. 
00102       if (ievt % 100 == 0) 
00103         cout << "Event # " << ievt << endl;
00104 
00105 
00106       
00107       // Make one event. 
00108       pythia->GenerateEvent();
00109    
00110       
00111       //displays the particle listing for the first three events
00112       if(Num<1)
00113         {pythia->Pylist(1);
00114       }
00115 
00116       Num++; 
00117         
00118       //Get some event information!
00119       //Total number of Pythia tracks
00120       Int_t N = pythia->GetN();
00121       //cout << "MyOutput: Number of Pythia tracks ="<<N<<endl;
00122       //Loop over all tracks
00123 
00124       TLorentzVector gammasum;
00125 
00126       int N_gammas = 0;
00127   
00128       for (Int_t itk =1; itk<=N; itk++) //loop over the particles in one event
00129         {
00130 
00131           Int_t KS = pythia->GetK(itk,1); //KS code
00132           
00133           if(KS!=21) continue;
00134 
00135           Int_t KF = pythia->GetK(itk,2); //KF code
00136           
00137           if ( KF == 25) //higgs
00138 
00139             {
00140               TLorentzVector higgs = TLorentzVector(pythia->GetP(itk,1), pythia->GetP(itk,2), pythia->GetP(itk,3), pythia->GetP(itk,4)); 
00141               Hgeneratedmass->Fill(higgs.M());  
00142             } 
00143    
00144           if( KF == 22) //photon
00145             {
00146               
00147               TLorentzVector lvGamma = TLorentzVector(pythia->GetP(itk,1), pythia->GetP(itk,2), pythia->GetP(itk,3), pythia->GetP(itk,4));
00148       
00149 
00150               
00151 
00152               if(KS==21)
00153                 {
00154                   N_gammas++;
00155                   gammasum+=lvGamma;
00156                   
00157                   
00158                   
00159                     
00160                 }
00161             }
00162 
00163         }
00164         //itk //end of the loop over particles in one event
00165       //cout << "MyOutput: Number of muons =" << N_muons<<endl; 
00166       // cout<<"Number of photons that decayed from Higgs: "<<N_gammas<<endl;       
00167 
00168 
00169  
00170       
00171       Hmass->Fill(gammasum.M());
00172       Hpt->Fill(gammasum.Pt());
00173     }//ievt /end of loop over the events
00174   
00175  
00176 
00177  
00178 
00179   char name[100];
00180  
00181    // sprintf(name,"IVplots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00182    // c1->Print(name);
00183   
00184  
00185 
00186   // sprintf(name,"AnglePlots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00187   // c3->Print(name);
00188 
00189 
00190    TCanvas * c5 = new TCanvas("c5","**",800,800);
00191    c5->SetFillColor(9);
00192    Hmass->Draw("e");
00193    TF1 *f_fit = new TF1("f_fit","[0]*TMath::BreitWigner(x,[1],[2])",0,500);
00194    TF1 *f_theory = new TF1("f_theory","[0]*TMath::BreitWigner(x,[1],[2])",0,500);
00195    f_fit->SetParNames("Constant","Mass","Width");
00196    f_theory->SetParNames("Constant","Mass","Width");
00197 
00198    if (Higgsmass>180)
00199      {
00200        f_fit->SetParameters(Hmass->GetEntries(),Higgsmass,higgswidth);
00201        f_fit->SetParLimits(2, higgswidth - higgswidth/2, higgswidth + higgswidth/2); 
00202        f_fit->SetParLimits(0,0,100*Hmass->GetEntries());
00203        f_fit->SetParLimits(1,Higgsmass - Higgsmass/2,Higgsmass + Higgsmass/2);
00204      }
00205    else
00206      {
00207        f_fit->SetParameters(Hmass->GetEntries(),Higgsmass,higgswidth);
00208        f_fit->SetParLimits(2, higgswidth - higgswidth/5, higgswidth + higgswidth/5); 
00209        f_fit->SetParLimits(0,0,100*Hmass->GetEntries());
00210        f_fit->SetParLimits(1,Higgsmass - 2*higgswidth,Higgsmass + 2*higgswidth);
00211      }
00212    for(int number = 0;number<3;number++)
00213      { 
00214        Hmass->Fit("f_fit","L","",Higgsminplot,Higgsmaxplot);
00215        
00216      }
00217    float fit_higgswidth = f_fit->GetParameter(2);
00218    float fit_higgsmass = f_fit->GetParameter(1);
00219    
00220    f_theory->SetParameter(0,Hmass->GetEntries());
00221    f_theory->FixParameter(1,Higgsmass);
00222    f_theory->FixParameter(2,higgswidth);
00223    f_theory->SetParLimits(0,0,10000);
00224    
00225    Hmass->Fit("f_theory","L+","",Higgsminplot,Higgsmaxplot);
00226    
00227    cout<<"Fitted Higgs mass: "<<fit_higgsmass<<", Fitted Higgs width: "<<fit_higgswidth<<endl;
00228    cout<<"Theory Higgs mass: "<<Higgsmass<<", Theory Higgs width: "<<higgswidth<<endl;
00229    
00230    sprintf(name,"histograms_Htogammagamma_Hm%5.2f_Nevt%d.root",Higgsmass,nEvents);
00231    TFile f(name,"recreate");
00232    f.cd();
00233    int N=gROOT->GetList()->GetSize();
00234    for (int key=0; key<N ; key++)
00235      {
00236        gROOT->GetList()->At(key)->Write();
00237        //      gROOT->GetList()->At(key)->Delete();
00238      }
00239    f.Close();
00240    
00241    watcher.Stop();
00242    cout <<"Time spent for "<<nEvents<<" events :"<< watcher.RealTime()<<" [s]"<<endl;
00243    
00244    return -97534;
00245    */
00246      }//makePyEvts
00247 

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