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

makePyEvts_angular_wphi_axial.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   pythia->SetMSTP(25,2);
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       //boost Higgs, Z1, and Z2 into Higgs rest frame
00222       TVector3 boostH,boostZ1_hrest,boostZ2_hrest;
00223       TLorentzVector H,H_hrest,Z1_hrest,Z2_hrest,muon1_hrest,muon2_hrest,muon1_star,muon2_star,Z1_star,Z2_star;
00224       H = Z1+Z2;
00225       boostH = -H.BoostVector();
00226       H_hrest = H;
00227       Z1_hrest = Z1;
00228       Z2_hrest = Z2;
00229       muon1_hrest = muon1minus;
00230       muon2_hrest = muon2minus;
00231       H_hrest.Boost(boostH);
00232       Z1_hrest.Boost(boostH);
00233       Z2_hrest.Boost(boostH);
00234       muon1_hrest.Boost(boostH);
00235       muon2_hrest.Boost(boostH);
00236       
00237       boostZ1_hrest = -Z1_hrest.BoostVector();
00238       boostZ2_hrest = -Z2_hrest.BoostVector();
00239       
00240       Z1_star = Z1_hrest;
00241       Z2_star = Z2_hrest;
00242       
00243       muon1_star = muon1_hrest;
00244       muon2_star = muon2_hrest;
00245       
00246       muon1_star.Boost(boostZ1_hrest);
00247       muon2_star.Boost(boostZ2_hrest);
00248 
00249       TVector3 uZ1 = Z1_hrest.Vect().Unit();
00250       TVector3 uZ2 = Z2_hrest.Vect().Unit();
00251 
00252       float cosine1, cosine2;
00253       TVector3 unit_muon1_star = muon1_star.Vect().Unit();
00254       cosine1 = uZ1.Dot(unit_muon1_star);
00255 
00256       TVector3 unit_muon2_star = muon2_star.Vect().Unit();
00257       cosine2 = uZ2.Dot(unit_muon2_star);
00258       
00259       Cosine1plot->Fill(cosine1);
00260       Cosine2plot->Fill(cosine2);
00261       Correlationplot->Fill(cosine1,cosine2);
00262 
00263 
00264       
00265       double projection_z_1, projection_z_2;
00266       TVector3 muon1_hrest_vector3, muon1_x1;
00267       TVector3 muon2_hrest_vector3, muon2_T;      
00268 
00269       muon1_hrest_vector3 = muon1_hrest.Vect();
00270       projection_z_1 = -uZ1.Dot(muon1_hrest_vector3);
00271       muon1_x1 = muon1_hrest_vector3 + projection_z_1*uZ1;
00272       double check_1 = muon1_x1.Dot(uZ1);
00273       //cout<<"The dot product between the x-axis and z-axis for muon 1 is:"<<check_1<<endl;
00274       
00275       muon2_hrest_vector3 = muon2_hrest.Vect();
00276       projection_z_2 = uZ1.Dot(muon2_hrest_vector3);
00277       muon2_T = muon2_hrest_vector3 - projection_z_2*uZ1;
00278       double check_2 = muon2_T.Dot(uZ2);
00279       //cout<<"The dot product between the x-axis and z-axis for muon 2 is:"<<check_2<<endl;      
00280 
00281       double phi, phi_0_2pi;
00282 
00283       TVector3 y_axis_1, muon1_x1_unit;
00284       muon1_x1_unit = muon1_x1.Unit();
00285       y_axis_1 = muon1_x1.Dot(uZ1);
00286       
00287 
00288       double dot_y_mu2;
00289       double sign;
00290       dot_y_mu2 = y_axis_1.Dot(muon2_T);
00291       if(dot_y_mu2 > 0)
00292         {sign = +1;
00293         }
00294       else
00295         {sign = -1;}
00296         
00297       phi = sign*(muon2_T.Angle(muon1_x1));
00298       if(phi<0)
00299         {phi_0_2pi = 2*TMath::Pi()+phi;
00300         }
00301       else
00302         {phi_0_2pi = phi;
00303         }
00304       Phiplot1->Fill(phi_0_2pi);
00305           
00306       
00307 
00308       bool didImessmuonplus=false;
00309       bool didImessmuonminus=false;
00310 
00311       //randomizing the anti-muons order
00312       if(R.Rndm()>0.5)
00313         {
00314           TLorentzVector temp;
00315           temp=muon1plus;
00316           muon1plus=muon2plus;
00317           muon2plus=temp;
00318           didImessmuonplus=true;
00319         }
00320       //randomizing the muons order
00321       if(R.Rndm()>0.5)
00322         {
00323           TLorentzVector temp;
00324           temp=muon1minus;
00325           muon1minus=muon2minus;
00326           muon2minus=temp;
00327           didImessmuonminus=true;
00328         }
00329          
00330       int MM=didImessmuonminus;
00331       int MP=didImessmuonplus;
00332 
00333       
00334       bool condition=(MM || MP) && (!MP || !MM);
00335       bool auxcond=((MP+MM)&1);
00336       if (auxcond!=condition)
00337         cout <<condition<<" "<<((MP+MM)&1)<<endl;
00338 
00339     
00340 
00341       Hmass->Fill(muonsum.M());
00342      
00343     }//ievt /end of loop over the events
00344   
00345  
00346 
00347  
00348   
00349   
00350  
00351    char name[100];
00352   // sprintf(name,"IVplots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00353   // c1->Print(name);
00354   
00355   TCanvas * c3 = new TCanvas("c3","**",800,800);
00356   c3->Divide(2,2);
00357   c3->SetFillColor(9);
00358   c3->cd(1);
00359   Cosine1plot->Draw();
00360  
00361   Cosine1plot->SetTitle("Cos(#theta) of muon1 in Z1 rest frame");
00362 //Cosine1graph->Rebin(8);
00363   TF1 *f2 = new TF1("f2","[0]*([1]*(3/4)*(1-x**2)+(3/8)*(1-[1])*(1+x**2))",-1,1);
00364   TF1 *f3 = new TF1("f3","[0]*( (1/(1+[1]))*(3/4)*(1-x**2) + (3/8)*([1]/(1+[1]))*(1+x**2) )",-1,1);
00365   //This fit, f4 is incorrect, look at ~/FromJeff/gamma_Z_macros/makePyEvts_angular_incorrect_boost_1.C for the correct fit  
00366 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);
00367 
00368   f2->SetParNames("Normalization","alpha");
00369   f3->SetParNames("Normalization","R");
00370   f4->SetParNames("Normalization","tullyR");
00371 
00372   f2->SetParameter(1,0.9);
00373   f3->SetParameter(1,0.1);
00374   f4->SetParameter(1,0.8);
00375   
00376   f2->FixParameter(0,Cosine1plot->Integral("bin width"));
00377   f3->FixParameter(0,Cosine1plot->Integral("bin width"));
00378   f4->FixParameter(0,Cosine1plot->Integral("bin width"));
00379 
00380   Cosine1plot->Fit("f2","L");
00381   Cosine1plot->Fit("f3","L+");
00382   Cosine1plot->Fit("f4","L+");
00383 
00384 
00385 
00386 
00387   c3->cd(2);
00388   Cosine2plot->Draw();
00389   c3->cd(3);
00390   Correlationplot->Draw();
00391 
00392   // sprintf(name,"AnglePlots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00393   // c3->Print(name);
00394 
00395 
00396   TCanvas *c4 = new TCanvas("c4","**",800,800);
00397   c4->Divide(2,2);
00398   c4->SetFillColor(9);
00399   c4->cd(1);
00400   Phiplot1->Draw();
00401 
00402   //c4->cd(2);
00403   //  Phiplot2->Draw();
00404 
00405  
00406   TCanvas * c5 = new TCanvas("c5","**",800,800);
00407   c5->SetFillColor(9);
00408   Hmass->Draw("e");
00409 
00410   TCanvas * c6 = new TCanvas("c6","**",800,800);
00411   c6->cd();
00412   Z1plot->Draw();
00413 
00414   TCanvas * c7 = new TCanvas("c7","**",800,800);
00415   c7->cd();
00416   Z2plot->Draw();
00417 
00418   TCanvas * c8 = new TCanvas("c8","**",800,800);
00419   c8->cd();
00420   Phiplot1->Draw();
00421 
00422   TF1 *f7 = new TF1("f7","[0]*(1+[1]*[2]*cos(x)+[2]*cos(2*x))",0,2*TMath::Pi());
00423   
00424   f7->SetParNames("Normalization","a1","a2");
00425  
00426   //f7->SetParameter(1,0.9);
00427   
00428   
00429   
00430   f7->FixParameter(0,(Phiplot1->Integral("bin width"))/(2*TMath::Pi()));
00431   
00432   Phiplot1->Fit("f7","L");
00433   
00434   
00435 
00436 
00437   sprintf(name,"histograms_correct_HtoZZ_angular_wphi_Hm%5.2f_Nevt%d.root",Higgsmass,nEvents);
00438   TFile f(name,"recreate");
00439   f.cd();
00440   int N=gROOT->GetList()->GetSize();
00441   for (int key=0; key<N ; key++)
00442     {
00443 
00444       TObject * obj = gROOT->GetList()->At(key);
00445       if (obj->InheritsFrom("TH1F") || obj->InheritsFrom("TH2F"))
00446         {
00447           cout <<"write "<<obj->GetName()<<endl;
00448           obj->Write();
00449 
00450         }
00451     }
00452   f.Close();
00453 
00454   
00455   for (int key=N-1; key>=0 ; key--)
00456     {
00457       
00458       TObject * obj = gROOT->GetList()->At(key);
00459       cout <<"delete "<<obj->GetName()<<endl;
00460       if (obj)  delete obj;
00461       cout <<"deleted "<<gROOT->GetList()->GetSize()<<" objects remaining"<<endl;
00462       }
00463 
00464   watcher.Stop();
00465   cout <<"Time spent for "<<nEvents<<" events :"<< watcher.RealTime()<<" [s]"<<endl;
00466 
00467   return -97534;
00468 
00469 }//makePyEvts
00470 

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