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

makePyEvts_angular_wphi_tae.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   TH2F *Correlationplot_theta1_phi = new TH2F("Correlationplot_theta1_phi","Phi angle versus theta angle muon 1",NbinIVplot,-1,1,NbinIVplot,0,2*TMath::Pi());
00114   TH2F *Correlationplot_theta2_phi = new TH2F("Correlationplot_theta2_phi","Phi angle versus theta angle muon 2",NbinIVplot,-1,1,NbinIVplot,0,2*TMath::Pi());
00115  
00116   Int_t KF_muon =13;
00117 
00118   // Now generate events
00119 
00120   TRandom2 R;
00121 
00122   //loop over the events
00123   for (Int_t ievt = 0; ievt < nEvents; ievt++) 
00124     {
00125       // Show how far we got every 100'th event. 
00126       if (ievt % 100 == 0) 
00127         cout << "Event # " << ievt << endl;
00128 
00129       // Make one event. 
00130       pythia->GenerateEvent();
00131       // Now we're ready to fill the tree, and the event is over. 
00132       //      tree->Fill();
00133       //
00134       
00135       TLorentzVector muonsum;
00136       TLorentzVector muon1plus,  muon2plus, muon1minus , muon2minus;
00137 
00138       int Nmuonplus=0;
00139       int Nmuonminus=0;
00140       
00141       int Nz=0;
00142       
00143       //Get some event information!
00144       //Total number of Pythia tracks
00145       Int_t N = pythia->GetN();
00146       //cout << "MyOutput: Number of Pythia tracks ="<<N<<endl;
00147       //Loop over all tracks
00148 
00149 
00150       
00151       Int_t N_muons =0;     // initialize number muons
00152       for (Int_t itk =1; itk<=N; itk++) //loop over the particles in one event
00153         {
00154 
00155           Int_t KS = pythia->GetK(itk,1); //KS code
00156 
00157           if ( KS!=21) continue;
00158 
00159           Int_t KF = pythia->GetK(itk,2); //KF code
00160           
00161 
00162           
00163           if ((abs(KF)== KF_muon))
00164             {
00165               TLorentzVector lvMuon = TLorentzVector(pythia->GetP(itk,1), pythia->GetP(itk,2), pythia->GetP(itk,3), pythia->GetP(itk,4));
00166               
00167              
00168 
00169               if(KS==21)
00170                 {
00171                   N_muons++;
00172                   // hmuonpt_initial->Fill(lvMuon.Pt());
00173                   muonsum+=lvMuon;
00174                   
00175                   
00176                   if (KF<0) //anti-muon
00177                     {
00178                       if (Nmuonplus==1)
00179                         {
00180                           muon2plus = lvMuon;
00181                         }
00182                       if (Nmuonplus==0)
00183                         {
00184                           muon1plus = lvMuon;
00185                           Nmuonplus=1;
00186                         }
00187                     }
00188                   else //muon
00189                     {
00190                       if (Nmuonminus==1)
00191                         {
00192                           muon2minus = lvMuon;
00193                         }
00194                       if (Nmuonminus==0)
00195                         {
00196                           muon1minus = lvMuon;
00197                           Nmuonminus=1;
00198                         }
00199                     }
00200                 }
00201               else
00202                 {
00203                   // hmuonpt_final->Fill(lvMuon.Pt());
00204                 }
00205             }
00206           
00207           
00208         }//itk //end of the loop over particles in one event
00209       //cout << "MyOutput: Number of muons =" << N_muons<<endl; 
00210       
00211 
00212 
00213       
00214       //Want to take the four vector of the muon and anti-muon and add them to get the four vectors of the Z
00215 
00216       cout<<"The 3-vector of muon1plus is: "<<endl;
00217       muon1plus.Vect().Print();
00218       cout<<"The Energy component is: "<<muon1plus.T()<<endl;
00219       cout<<"The P_X component is: "<<muon1plus.X()<<endl;
00220       cout<<"The P_Y component is: "<<muon1plus.Y()<<endl;
00221       cout<<"The P_z component is: "<<muon1plus.Z()<<endl;
00222 
00223       cout<<"The 3-vector of muon1minus is: "<<endl;
00224       muon1minus.Vect().Print();
00225       cout<<"The Energy component is: "<<muon1minus.T()<<endl;
00226       cout<<"The P_X component is: "<<muon1minus.X()<<endl;
00227       cout<<"The P_Y component is: "<<muon1minus.Y()<<endl;
00228       cout<<"The P_z component is: "<<muon1minus.Z()<<endl;
00229 
00230       cout<<"The 3-vector of muon2plus is: "<<endl;
00231       muon2plus.Vect().Print();
00232       cout<<"The Energy component is: "<<muon2plus.T()<<endl;
00233       cout<<"The P_X component is: "<<muon2plus.X()<<endl;
00234       cout<<"The P_Y component is: "<<muon2plus.Y()<<endl;
00235       cout<<"The P_z component is: "<<muon2plus.Z()<<endl;
00236 
00237       cout<<"The 3-vector of muon2minus is: "<<endl;
00238       muon2minus.Vect().Print();
00239       cout<<"The Energy component is: "<<muon2minus.T()<<endl;
00240       cout<<"The P_X component is: "<<muon2minus.X()<<endl;
00241       cout<<"The P_Y component is: "<<muon2minus.Y()<<endl;
00242       cout<<"The P_z component is: "<<muon2minus.Z()<<endl;
00243 
00244       TLorentzVector Z1,Z2;
00245       Z1 = muon1plus + muon1minus;
00246       Z2 = muon2plus + muon2minus;
00247       Z1plot->Fill(Z1.M());
00248       Z2plot->Fill(Z2.M());
00249      
00250 
00251       //boost Higgs, Z1, and Z2 into Higgs rest frame
00252       TVector3 boostH,boostZ1_hrest,boostZ2_hrest;
00253       TLorentzVector H,H_hrest,Z1_hrest,Z2_hrest,muon1_hrest,muon2_hrest,muon1_star,muon2_star,Z1_star,Z2_star;
00254       H = Z1+Z2;
00255       boostH = -H.BoostVector();
00256       H_hrest = H;
00257       Z1_hrest = Z1;
00258       Z2_hrest = Z2;
00259       muon1_hrest = muon1minus;
00260       muon2_hrest = muon2minus;
00261       H_hrest.Boost(boostH);
00262       Z1_hrest.Boost(boostH);
00263       Z2_hrest.Boost(boostH);
00264       muon1_hrest.Boost(boostH);
00265       muon2_hrest.Boost(boostH);
00266       
00267       boostZ1_hrest = -Z1_hrest.BoostVector();
00268       boostZ2_hrest = -Z2_hrest.BoostVector();
00269       
00270       Z1_star = Z1_hrest;
00271       Z2_star = Z2_hrest;
00272       
00273       muon1_star = muon1_hrest;
00274       muon2_star = muon2_hrest;
00275       
00276       muon1_star.Boost(boostZ1_hrest);
00277       muon2_star.Boost(boostZ2_hrest);
00278 
00279       TVector3 uZ1 = Z1_hrest.Vect().Unit();
00280       TVector3 uZ2 = Z2_hrest.Vect().Unit();
00281 
00282       float cosine1, cosine2;
00283       TVector3 unit_muon1_star = muon1_star.Vect().Unit();
00284       cosine1 = uZ1.Dot(unit_muon1_star);
00285       cout<<"The angle cosine1 is: "<<cosine1<<endl;
00286 
00287       TVector3 unit_muon2_star = muon2_star.Vect().Unit();
00288       cosine2 = uZ2.Dot(unit_muon2_star);
00289       cout<<"The angle cosine2 is "<<cosine2<<endl;
00290 
00291       Cosine1plot->Fill(cosine1);
00292       Cosine2plot->Fill(cosine2);
00293       Correlationplot->Fill(cosine1,cosine2);
00294 
00295 
00296       //tae's method
00297       TVector3 boostZ1_tae;
00298       TLorentzVector muon1_Z1_rest_tae, higgs_Z1_rest_tae;
00299       
00300       boostZ1_tae = -Z1.BoostVector();
00301       muon1_Z1_rest_tae = muon1minus;
00302       muon1_Z1_rest_tae.Boost(boostZ1_tae);
00303       
00304       higgs_Z1_rest_tae = H;
00305       higgs_Z1_rest_tae.Boost(boostZ1_tae);
00306       
00307 
00308       TVector3 unit_muon1_Z1_rest_tae = muon1_Z1_rest_tae.Vect().Unit();
00309       TVector3 unit_higgs_Z1_rest_tae = higgs_Z1_rest_tae.Vect().Unit();
00310 
00311       float cosine1_tae;
00312       cosine1_tae = unit_higgs_Z1_rest_tae.Dot(unit_muon1_Z1_rest_tae);
00313       cout<<"Tae's angle for cosine 1 is :"<<cosine1_tae<<endl;
00314 
00315 
00316       
00317       double projection_z_1, projection_z_2;
00318       TVector3 muon1_hrest_vector3, muon1_x1;
00319       TVector3 muon2_hrest_vector3, muon2_T;      
00320 
00321       muon1_hrest_vector3 = muon1_hrest.Vect();
00322       projection_z_1 = -uZ1.Dot(muon1_hrest_vector3);
00323       muon1_x1 = muon1_hrest_vector3 + projection_z_1*uZ1;
00324       double check_1 = muon1_x1.Dot(uZ1);
00325       //cout<<"The dot product between the x-axis and z-axis for muon 1 is:"<<check_1<<endl;
00326       
00327       muon2_hrest_vector3 = muon2_hrest.Vect();
00328       projection_z_2 = uZ1.Dot(muon2_hrest_vector3);
00329       muon2_T = muon2_hrest_vector3 - projection_z_2*uZ1;
00330       double check_2 = muon2_T.Dot(uZ2);
00331       //cout<<"The dot product between the x-axis and z-axis for muon 2 is:"<<check_2<<endl;      
00332 
00333       double phi, phi_0_2pi;
00334 
00335       TVector3 y_axis_1, muon1_x1_unit;
00336       muon1_x1_unit = muon1_x1.Unit();
00337       y_axis_1 = muon1_x1.Dot(uZ1);
00338       
00339 
00340       double dot_y_mu2;
00341       double sign;
00342       dot_y_mu2 = y_axis_1.Dot(muon2_T);
00343       if(dot_y_mu2 > 0)
00344         {sign = +1;
00345         }
00346       else
00347         {sign = -1;}
00348         
00349       phi = sign*(muon2_T.Angle(muon1_x1));
00350       if(phi<0)
00351         {phi_0_2pi = 2*TMath::Pi()+phi;
00352         }
00353       else
00354         {phi_0_2pi = phi;
00355         }
00356       Phiplot1->Fill(phi_0_2pi);
00357       Correlationplot_theta1_phi->Fill(cosine1,phi_0_2pi);
00358       Correlationplot_theta2_phi->Fill(cosine2,phi_0_2pi);
00359 
00360       bool didImessmuonplus=false;
00361       bool didImessmuonminus=false;
00362 
00363       //randomizing the anti-muons order
00364       if(R.Rndm()>0.5)
00365         {
00366           TLorentzVector temp;
00367           temp=muon1plus;
00368           muon1plus=muon2plus;
00369           muon2plus=temp;
00370           didImessmuonplus=true;
00371         }
00372       //randomizing the muons order
00373       if(R.Rndm()>0.5)
00374         {
00375           TLorentzVector temp;
00376           temp=muon1minus;
00377           muon1minus=muon2minus;
00378           muon2minus=temp;
00379           didImessmuonminus=true;
00380         }
00381          
00382       int MM=didImessmuonminus;
00383       int MP=didImessmuonplus;
00384 
00385       
00386       bool condition=(MM || MP) && (!MP || !MM);
00387       bool auxcond=((MP+MM)&1);
00388       if (auxcond!=condition)
00389         cout <<condition<<" "<<((MP+MM)&1)<<endl;
00390 
00391     
00392 
00393       Hmass->Fill(muonsum.M());
00394      
00395     }//ievt /end of loop over the events
00396   
00397  
00398 
00399  
00400   
00401   
00402  
00403    char name[100];
00404   // sprintf(name,"IVplots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00405   // c1->Print(name);
00406   
00407   TCanvas * c3 = new TCanvas("c3","**",800,800);
00408   c3->Divide(3,2);
00409   c3->SetFillColor(9);
00410   c3->cd(1);
00411   Cosine1plot->Draw();
00412  
00413   Cosine1plot->SetTitle("Cos(#theta) of muon1 in Z1 rest frame");
00414 //Cosine1graph->Rebin(8);
00415   TF1 *f2 = new TF1("f2","[0]*([1]*(3/4)*(1-x**2)+(3/8)*(1-[1])*(1+x**2))",-1,1);
00416   TF1 *f3 = new TF1("f3","[0]*( (1/(1+[1]))*(3/4)*(1-x**2) + (3/8)*([1]/(1+[1]))*(1+x**2) )",-1,1);
00417   //This fit, f4 is incorrect, look at ~/FromJeff/gamma_Z_macros/makePyEvts_angular_incorrect_boost_1.C for the correct fit  
00418 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);
00419 
00420   f2->SetParNames("Normalization","alpha");
00421   f3->SetParNames("Normalization","R");
00422   f4->SetParNames("Normalization","tullyR");
00423 
00424   f2->SetParameter(1,0.9);
00425   f3->SetParameter(1,0.1);
00426   f4->SetParameter(1,0.8);
00427   
00428   f2->FixParameter(0,Cosine1plot->Integral("bin width"));
00429   f3->FixParameter(0,Cosine1plot->Integral("bin width"));
00430   f4->FixParameter(0,Cosine1plot->Integral("bin width"));
00431 
00432   Cosine1plot->Fit("f2","L");
00433   Cosine1plot->Fit("f3","L+");
00434   Cosine1plot->Fit("f4","L+");
00435 
00436 
00437 
00438 
00439   c3->cd(2);
00440   Cosine2plot->Draw();
00441   Cosine2plot->SetTitle("Cos(#theta) of muon2 in Z2 rest frame");
00442   c3->cd(3);
00443   Correlationplot->Draw();
00444   Correlationplot->SetTitle("Cos(#theta) of muon2 in Z2 rest frame vs. muon1 in Z1 rest frame");
00445   c3->cd(4);
00446   Correlationplot_theta1_phi->Draw();
00447   Correlationplot_theta1_phi->SetTitle("Phi vs. muon1 in Z1 rest frame");
00448   c3->cd(5);
00449   Correlationplot_theta2_phi->Draw();
00450   Correlationplot_theta2_phi->SetTitle("Phi vs. muon2 in Z2 rest frame");
00451   // sprintf(name,"AnglePlots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00452   // c3->Print(name);
00453 
00454 
00455   TCanvas *c4 = new TCanvas("c4","**",800,800);
00456   c4->Divide(2,2);
00457   c4->SetFillColor(9);
00458   c4->cd(1);
00459   Phiplot1->Draw();
00460 
00461   //c4->cd(2);
00462   //  Phiplot2->Draw();
00463 
00464  
00465   TCanvas * c5 = new TCanvas("c5","**",800,800);
00466   c5->SetFillColor(9);
00467   Hmass->Draw("e");
00468 
00469   TCanvas * c6 = new TCanvas("c6","**",800,800);
00470   c6->cd();
00471   Z1plot->Draw();
00472 
00473   TCanvas * c7 = new TCanvas("c7","**",800,800);
00474   c7->cd();
00475   Z2plot->Draw();
00476 
00477   TCanvas * c8 = new TCanvas("c8","**",800,800);
00478   c8->cd();
00479   Phiplot1->Draw();
00480 
00481   TF1 *f7 = new TF1("f7","[0]*(1+[1]*[2]*cos(x)+[2]*cos(2*x))",0,2*TMath::Pi());
00482   
00483   f7->SetParNames("Normalization","a1","a2");
00484  
00485   //f7->SetParameter(1,0.9);
00486   
00487   
00488   
00489   f7->FixParameter(0,(Phiplot1->Integral("bin width"))/(2*TMath::Pi()));
00490   
00491   Phiplot1->Fit("f7","L");
00492   
00493   
00494 
00495 
00496   sprintf(name,"histograms_correct_HtoZZ_angular_wphi_Hm%5.2f_Nevt%d.root",Higgsmass,nEvents);
00497   TFile f(name,"recreate");
00498   f.cd();
00499   int N=gROOT->GetList()->GetSize();
00500   for (int key=0; key<N ; key++)
00501     {
00502 
00503       TObject * obj = gROOT->GetList()->At(key);
00504       if (obj->InheritsFrom("TH1F") || obj->InheritsFrom("TH2F"))
00505         {
00506           cout <<"write "<<obj->GetName()<<endl;
00507           obj->Write();
00508 
00509         }
00510     }
00511   f.Close();
00512 
00513   
00514   for (int key=N-1; key>=0 ; key--)
00515     {
00516       
00517       TObject * obj = gROOT->GetList()->At(key);
00518       cout <<"delete "<<obj->GetName()<<endl;
00519       if (obj)  delete obj;
00520       cout <<"deleted "<<gROOT->GetList()->GetSize()<<" objects remaining"<<endl;
00521       }
00522 
00523   watcher.Stop();
00524   cout <<"Time spent for "<<nEvents<<" events :"<< watcher.RealTime()<<" [s]"<<endl;
00525 
00526   return -97534;
00527 
00528 }//makePyEvts
00529 

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