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

makePyEvts_angular.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 // 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   // Create an instance of the Pythia event generator ... 
00036   TPythia6* pythia = new TPythia6; 
00037 
00038  // Initialise it to run p+p at ECM GeV in CMS 
00039 
00040   pythia->SetMSEL(0);        //Full user control 
00041   pythia->SetMSUB(102,1);    //Select gg->Higgs
00042   pythia->SetPMAS(25,1,Higgsmass); //Set Higgs mass
00043   pythia->SetMSTP(61,0);     //Turn off initial-state radiation
00044  
00045 
00046   // Turn off all Z decay modes; then turn on correct mode
00047   int KF = 23;               // 
00048   int idcmin = pythia->GetMDCY(KF,2);
00049   int idcmax = idcmin + pythia->GetMDCY(KF,3);
00050   cout<<"MyOutput: Z idcmin="<<idcmin<<" idcmax="<<idcmax<<endl;
00051   for (int idc = idcmin; idc < idcmax; idc++)
00052     {
00053       pythia->SetMDME(idc,1,0);
00054     }   
00055   pythia->SetMDME(184,1,1);
00056  
00057   // Turn off all Higgs (h0) decay modes; then turn on correct mode
00058   KF = 25;               // 
00059   idcmin = pythia->GetMDCY(KF,2);
00060   idcmax = idcmin + pythia->GetMDCY(KF,3);
00061   cout<<"MyOutput: Higgs idcmin="<<idcmin<<" idcmax="<<idcmax<<endl;
00062   for (Int_t idc = idcmin; idc < idcmax; idc++)
00063     {
00064       pythia->SetMDME(idc,1,0);
00065     }   
00066   pythia->SetMDME(225,1,1);
00067   
00068   //Set collision
00069   pythia->Initialize("cms", "p", "p", ECM);
00070 
00071   float higgswidth = pythia->GetPMAS(25,2);
00072   cout<<"The higgs width from Pythia is "<<higgswidth<<endl;
00073 
00074 
00075   TStopwatch watcher;
00076   watcher.Reset();
00077   watcher.Start();
00078 
00079 
00080   float Higgsmass_max = 3000;
00081 
00082   // if (Higgsmass > Higgsmass_max)
00083   //  {cout<<"I am not happy !"<<endl; return;}
00084     
00085   int NbinIVplot = 100;
00086 
00087 
00088   float Higgsmaxplot = 3000;
00089   float Higgsminplot = 0.0;
00090   int Nbins = 300;
00091  
00092    if (Higgsmass < 191)
00093     {
00094       Nbins = 500;
00095       Higgsminplot = Higgsmass - 5*higgswidth;
00096       Higgsmaxplot = Higgsmass + 5*higgswidth;
00097     }
00098 
00099 
00100 
00101   TH1F *Hmass = new TH1F("Hmass","Higgs Mass",Nbins,Higgsminplot,Higgsmaxplot);
00102 
00103   TH1F *Z1plot = new TH1F("Z1mass","Z1mass",Nbins,0,150);
00104   TH1F *Z2plot = new TH1F("Z2mass","Z2mass",Nbins,0,150);
00105 
00106   TH1F *Cosine1plot = new TH1F("Cosine1graph","Cos(#theta) angle of muon1 in Z1 rest frame",NbinIVplot,-1,1);
00107   TH1F *Cosine2plot = new TH1F("Cosine2graph","Cos(#theta) angle of muon2 in Z2 rest frame",NbinIVplot,-1,1);
00108   TH2F *Correlationplot = new TH2F("Correlationplot","Theta angle muon 1 versus theta angle muon 2",NbinIVplot,-1,1,NbinIVplot,-1,1);
00109 
00110   TH1F *Phiplot1 = new TH1F("Phiplot1","Phi angle of muon 1 in Z1 rest frame",NbinIVplot,0,2*TMath::Pi());
00111   TH1F *Phiplot2 = new TH1F("Phiplot2","Phi angle of muon 2 in Z2 rest frame",NbinIVplot,0,2*TMath::Pi());
00112 
00113  
00114   Int_t KF_muon =13;
00115 
00116   // Now generate events
00117 
00118   TRandom2 R;
00119 
00120   //loop over the events
00121   for (Int_t ievt = 0; ievt < nEvents; ievt++) 
00122     {
00123       // Show how far we got every 100'th event. 
00124       if (ievt % 100 == 0) 
00125         cout << "Event # " << ievt << endl;
00126 
00127       // Make one event. 
00128       pythia->GenerateEvent();
00129       // Now we're ready to fill the tree, and the event is over. 
00130       //      tree->Fill();
00131       //
00132       
00133       TLorentzVector muonsum;
00134       TLorentzVector muon1plus,  muon2plus, muon1minus , muon2minus;
00135 
00136       int Nmuonplus=0;
00137       int Nmuonminus=0;
00138       
00139       int Nz=0;
00140       
00141       //Get some event information!
00142       //Total number of Pythia tracks
00143       Int_t N = pythia->GetN();
00144       //cout << "MyOutput: Number of Pythia tracks ="<<N<<endl;
00145       //Loop over all tracks
00146 
00147 
00148       
00149       Int_t N_muons =0;     // initialize number muons
00150       for (Int_t itk =1; itk<=N; itk++) //loop over the particles in one event
00151         {
00152 
00153           Int_t KS = pythia->GetK(itk,1); //KS code
00154 
00155           if ( KS!=21) continue;
00156 
00157           Int_t KF = pythia->GetK(itk,2); //KF code
00158           
00159 
00160           
00161           if ((abs(KF)== KF_muon))
00162             {
00163               TLorentzVector lvMuon = TLorentzVector(pythia->GetP(itk,1), pythia->GetP(itk,2), pythia->GetP(itk,3), pythia->GetP(itk,4));
00164               
00165              
00166 
00167               if(KS==21)
00168                 {
00169                   N_muons++;
00170                   // hmuonpt_initial->Fill(lvMuon.Pt());
00171                   muonsum+=lvMuon;
00172                   
00173                   
00174                   if (KF<0) //anti-muon
00175                     {
00176                       if (Nmuonplus==1)
00177                         {
00178                           muon2plus = lvMuon;
00179                         }
00180                       if (Nmuonplus==0)
00181                         {
00182                           muon1plus = lvMuon;
00183                           Nmuonplus=1;
00184                         }
00185                     }
00186                   else //muon
00187                     {
00188                       if (Nmuonminus==1)
00189                         {
00190                           muon2minus = lvMuon;
00191                         }
00192                       if (Nmuonminus==0)
00193                         {
00194                           muon1minus = lvMuon;
00195                           Nmuonminus=1;
00196                         }
00197                     }
00198                 }
00199               else
00200                 {
00201                   // hmuonpt_final->Fill(lvMuon.Pt());
00202                 }
00203             }
00204           
00205           
00206         }//itk //end of the loop over particles in one event
00207       //cout << "MyOutput: Number of muons =" << N_muons<<endl; 
00208       
00209 
00210 
00211       
00212       //Want to take the four vector of the muon and anti-muon and add them to get the four vectors of the Z
00213      
00214       TLorentzVector Z1,Z2;
00215       Z1 = muon1plus + muon1minus;
00216       Z2 = muon2plus + muon2minus;
00217       Z1plot->Fill(Z1.M());
00218       Z2plot->Fill(Z2.M());
00219      
00220 
00221       /*
00222       //get the opposite of the 3-vector of the Zs
00223       TVector3 boostZ1,boostZ2;
00224       boostZ1 = - Z1.BoostVector();
00225       boostZ2 = - Z2.BoostVector();
00226 
00227       //      boostZ1.Print();
00228       //      boostZ2.Print();
00229 
00230       //boost muon, anti-muon and Z1 to the Z1 rest frame
00231       TLorentzVector Z1_star,muon1_star,antimuon1_star;
00232       Z1_star = Z1;
00233       muon1_star = muon1minus;
00234       antimuon1_star = muon1plus;
00235 
00236       Z1_star.Boost(boostZ1);
00237       muon1_star.Boost(boostZ1);
00238       antimuon1_star.Boost(boostZ1);
00239       // Z1_star.Vect().Print();
00240 
00241       //boost muon, anti-muon and Z2 to the Z2 rest frame
00242       TLorentzVector Z2_star,muon2_star,antimuon2_star;
00243       Z2_star = Z2;
00244       muon2_star = muon2minus;
00245       antimuon2_star = muon2plus;
00246 
00247       Z2_star.Boost(boostZ2);
00248       muon2_star.Boost(boostZ2);
00249       antimuon2_star.Boost(boostZ2);
00250       // Z2_star.Vect().Print();
00251       */
00252 
00253       //boost Higgs, Z1, and Z2 into Higgs rest frame
00254       TVector3 boostH,boostZ1_hrest,boostZ2_hrest;
00255       TLorentzVector H,H_hrest,Z1_hrest,Z2_hrest,muon1_hrest,muon2_hrest,muon1_star,muon2_star,Z1_star,Z2_star;
00256       H = Z1+Z2;
00257       boostH = -H.BoostVector();
00258       H_hrest = H;
00259       Z1_hrest = Z1;
00260       Z2_hrest = Z2;
00261       muon1_hrest = muon1minus;
00262       muon2_hrest = muon2minus;
00263       H_hrest.Boost(boostH);
00264       Z1_hrest.Boost(boostH);
00265       Z2_hrest.Boost(boostH);
00266       muon1_hrest.Boost(boostH);
00267       muon2_hrest.Boost(boostH);
00268       
00269       boostZ1_hrest = -Z1_hrest.BoostVector();
00270       boostZ2_hrest = -Z2_hrest.BoostVector();
00271       
00272       Z1_star = Z1_hrest;
00273       Z2_star = Z2_hrest;
00274       
00275       muon1_star = muon1_hrest;
00276       muon2_star = muon2_hrest;
00277       
00278       muon1_star.Boost(boostZ1_hrest);
00279       muon2_star.Boost(boostZ2_hrest);
00280 
00281       TVector3 uZ1 = Z1_hrest.Vect().Unit();
00282       TVector3 uZ2 = Z2_hrest.Vect().Unit();
00283 
00284       float cosine1, cosine2;
00285       TVector3 unit_muon1_star = muon1_star.Vect().Unit();
00286       cosine1 = uZ1.Dot(unit_muon1_star);
00287       //      cout <<cosine1<<endl;
00288       //      cout <<" radian or degree "<<uZ1.Angle(unit_muon1_star)<<endl;
00289       //      cout <<cos( uZ1.Angle(unit_muon1_star) )<<endl;
00290 
00291       TVector3 unit_muon2_star = muon2_star.Vect().Unit();
00292       cosine2 = uZ2.Dot(unit_muon2_star);
00293       
00294       Cosine1plot->Fill(cosine1);
00295       Cosine2plot->Fill(cosine2);
00296       Correlationplot->Fill(cosine1,cosine2);
00297 
00298       TVector3 x1(1.0,0.0,0.0),y1(0.0,1.0,0.0);
00299       x1.RotateUz(uZ1);
00300       y1.RotateUz(uZ1);
00301       //(x1,y1,uZ1) is the rest frame of the Z, with z axis along the Z boson.
00302       
00303       TVector2 muon1_star2d(x1.Dot(unit_muon1_star),y1.Dot(unit_muon1_star));
00304       Phiplot1->Fill(muon1_star2d.Phi());
00305       
00306       TVector3 x2(1.0,0.0,0.0),y2(0.0,1.0,0.0);
00307       x2.RotateUz(uZ2);
00308       y2.RotateUz(uZ2);
00309       //(x2,y2,uZ2) is the rest frame of the Z, with z axis along the Z boson.
00310       
00311       TVector2 muon2_star2d(x2.Dot(unit_muon2_star),y2.Dot(unit_muon2_star));
00312       Phiplot2->Fill(muon2_star2d.Phi());
00313       
00314 
00315       bool didImessmuonplus=false;
00316       bool didImessmuonminus=false;
00317 
00318       //randomizing the anti-muons order
00319       if(R.Rndm()>0.5)
00320         {
00321           TLorentzVector temp;
00322           temp=muon1plus;
00323           muon1plus=muon2plus;
00324           muon2plus=temp;
00325           didImessmuonplus=true;
00326         }
00327       //randomizing the muons order
00328       if(R.Rndm()>0.5)
00329         {
00330           TLorentzVector temp;
00331           temp=muon1minus;
00332           muon1minus=muon2minus;
00333           muon2minus=temp;
00334           didImessmuonminus=true;
00335         }
00336          
00337       int MM=didImessmuonminus;
00338       int MP=didImessmuonplus;
00339 
00340       
00341       bool condition=(MM || MP) && (!MP || !MM);
00342       bool auxcond=((MP+MM)&1);
00343       if (auxcond!=condition)
00344         cout <<condition<<" "<<((MP+MM)&1)<<endl;
00345 
00346     
00347 
00348       Hmass->Fill(muonsum.M());
00349      
00350     }//ievt /end of loop over the events
00351   
00352  
00353 
00354  
00355   
00356   
00357  
00358    char name[100];
00359   // sprintf(name,"IVplots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00360   // c1->Print(name);
00361   
00362   TCanvas * c3 = new TCanvas("c3","**",800,800);
00363   c3->Divide(2,2);
00364   c3->SetFillColor(9);
00365   c3->cd(1);
00366   Cosine1plot->Draw();
00367  
00368   Cosine1plot->SetTitle("Cos(#theta) of muon1 in Z1 rest frame");
00369 //Cosine1graph->Rebin(8);
00370   TF1 *f2 = new TF1("f2","[0]*([1]*(3/4)*(1-x**2)+(3/8)*(1-[1])*(1+x**2))",-1,1);
00371   TF1 *f3 = new TF1("f3","[0]*( (1/(1+[1]))*(3/4)*(1-x**2) + (3/8)*([1]/(1+[1]))*(1+x**2) )",-1,1);
00372   //This fit, f4 is incorrect, look at ~/FromJeff/gamma_Z_macros/makePyEvts_angular_incorrect_boost_1.C for the correct fit  
00373 TF1 *f4 = new TF1("f4","[0]*( ((1-[1])/([1]+3)) * (3/4)*(1-x**2) + (3/8)*((2*[1]+2)/([1]+3))*(1+x**2) )",-1,1);
00374 
00375   f2->SetParNames("Normalization","alpha");
00376   f3->SetParNames("Normalization","R");
00377   f4->SetParNames("Normalization","tullyR");
00378 
00379   f2->SetParameter(1,0.9);
00380   f3->SetParameter(1,0.1);
00381   f4->SetParameter(1,0.8);
00382   
00383   f2->FixParameter(0,Cosine1plot->Integral("bin width"));
00384   f3->FixParameter(0,Cosine1plot->Integral("bin width"));
00385   f4->FixParameter(0,Cosine1plot->Integral("bin width"));
00386 
00387   Cosine1plot->Fit("f2","L");
00388   Cosine1plot->Fit("f3","L+");
00389   Cosine1plot->Fit("f4","L+");
00390 
00391 
00392 
00393 
00394   c3->cd(2);
00395   Cosine2plot->Draw();
00396   c3->cd(3);
00397   Correlationplot->Draw();
00398 
00399   // sprintf(name,"AnglePlots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00400   // c3->Print(name);
00401 
00402 
00403   TCanvas *c4 = new TCanvas("c4","**",800,800);
00404   c4->Divide(2,2);
00405   c4->SetFillColor(9);
00406   c4->cd(1);
00407   Phiplot1->Draw();
00408   c4->cd(2);
00409   Phiplot2->Draw();
00410 
00411  
00412   TCanvas * c5 = new TCanvas("c5","**",800,800);
00413   c5->SetFillColor(9);
00414   Hmass->Draw("e");
00415 
00416   TCanvas * c6 = new TCanvas("c6","**",800,800);
00417   c6->cd();
00418   Z1plot->Draw();
00419 
00420   TCanvas * c7 = new TCanvas("c6","**",800,800);
00421   c7->cd();
00422   Z2plot->Draw();
00423 
00424   sprintf(name,"histograms_correct_HtoZZ_angular_Hm%5.2f_Nevt%d.root",Higgsmass,nEvents);
00425   TFile f(name,"recreate");
00426   f.cd();
00427   int N=gROOT->GetList()->GetSize();
00428   for (int key=0; key<N ; key++)
00429     {
00430 
00431       TObject * obj = gROOT->GetList()->At(key);
00432       if (obj->InheritsFrom("TH1F") || obj->InheritsFrom("TH2F"))
00433         {
00434           cout <<"write "<<obj->GetName()<<endl;
00435           obj->Write();
00436 
00437         }
00438     }
00439   f.Close();
00440 
00441   
00442   for (int key=N-1; key>=0 ; key--)
00443     {
00444       
00445       TObject * obj = gROOT->GetList()->At(key);
00446       cout <<"delete "<<obj->GetName()<<endl;
00447       if (obj)  delete obj;
00448       cout <<"deleted "<<gROOT->GetList()->GetSize()<<" objects remaining"<<endl;
00449       }
00450 
00451   watcher.Stop();
00452   cout <<"Time spent for "<<nEvents<<" events :"<< watcher.RealTime()<<" [s]"<<endl;
00453 
00454   return -97534;
00455 
00456 }//makePyEvts
00457 

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