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

makePyEvts_angular_comparison.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 = 100;
00091  
00092    if (Higgsmass < 131)
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",800,Higgsminplot,400);
00102 
00103   TH1F *Z1mass = new TH1F("Z1mass","Z1mass",800,0,400);
00104   TH1F *Z2mass = new TH1F("Z2mass","Z2mass",800,0,400);
00105   TH1F *Z_Pt = new TH1F("Z_Pt","Z_Pt",Nbins,0,150);
00106   TH1F *Z_phi = new TH1F("Z_phi","Z_phi",NbinIVplot,0,2*TMath::Pi());
00107   TH1F *Z_rapidity = new TH1F("Z_rapidity","Z_rapidity",NbinIVplot,-2.5,2.5);
00108 
00109   TH1F *Higgs_Pt = new TH1F("Higgs_Pt","Higgs_Pt",Nbins,0,150);
00110   TH1F *Higgs_phi = new TH1F("Higgs_phi","Higgs_phi",NbinIVplot,0,2*TMath::Pi());
00111   TH1F *Higgs_rapidity = new TH1F("Higgs_rapidity","Higgs_rapidity",NbinIVplot,-2.5,2.5);
00112 
00113   TH1F *Cosine1plot = new TH1F("Cosine1graph","Cos(#theta) angle of muon1 in Z1 rest frame",NbinIVplot,-1,1);
00114   TH1F *Cosine2plot = new TH1F("Cosine2graph","Cos(#theta) angle of muon2 in Z2 rest frame",NbinIVplot,-1,1);
00115   TH2F *Correlationplot = new TH2F("Correlationplot","Cos(#Theta) angle muon 1 versus Cos(#theta) angle muon 2",NbinIVplot,-1,1,NbinIVplot,-1,1);
00116 
00117   TH1F *Muon1_phi = new TH1F("Muon1_phi","Muon1_phi",NbinIVplot,0,2*TMath::Pi());
00118   TH1F *Muon1_Pt = new TH1F("Muon1_Pt","Muon1_Pt",Nbins,0,150);
00119   TH1F *Muon1_rapidity = new TH1F("Muon1_rapidity","Muon2_rapidity",NbinIVplot,-2.5,2.5);
00120 
00121   TH1F *Muons_Pt = new TH1F("Muons_Pt","Muons_Pt",Nbins,0,150);
00122   TH1F *Muons_rapidity = new TH1F("Muons_rapidity","Muons_rapidity",NbinIVplot,-2.5,2.5);
00123   TH1F *Muons_phi = new TH1F("Muons_phi","Muons_phi",NbinIVplot,0,2*TMath::Pi());
00124 
00125   TH1F *Phiplot1 = new TH1F("Phiplot1","Phi angle of muon 1 in Z1 rest frame",NbinIVplot,0,2*TMath::Pi());
00126   TH1F *Phiplot2 = new TH1F("Phiplot2","Phi angle of muon 2 in Z2 rest frame",NbinIVplot,0,2*TMath::Pi());
00127 
00128  
00129   Int_t KF_muon =13;
00130 
00131   // Now generate events
00132 
00133   TRandom2 R;
00134 
00135   //loop over the events
00136   for (Int_t ievt = 0; ievt < nEvents; ievt++) 
00137     {
00138       // Show how far we got every 100'th event. 
00139       if (ievt % 100 == 0) 
00140         cout << "Event # " << ievt << endl;
00141 
00142       // Make one event. 
00143       pythia->GenerateEvent();
00144       // Now we're ready to fill the tree, and the event is over. 
00145       //      tree->Fill();
00146       //
00147       
00148       TLorentzVector muonsum;
00149       TLorentzVector muon1plus,  muon2plus, muon1minus , muon2minus;
00150 
00151       int Nmuonplus=0;
00152       int Nmuonminus=0;
00153       
00154       int Nz=0;
00155       
00156       //Get some event information!
00157       //Total number of Pythia tracks
00158       Int_t N = pythia->GetN();
00159       //cout << "MyOutput: Number of Pythia tracks ="<<N<<endl;
00160       //Loop over all tracks
00161 
00162 
00163       
00164       Int_t N_muons =0;     // initialize number muons
00165       for (Int_t itk =1; itk<=N; itk++) //loop over the particles in one event
00166         {
00167 
00168           Int_t KS = pythia->GetK(itk,1); //KS code
00169 
00170           if ( KS!=21) continue;
00171 
00172           Int_t KF = pythia->GetK(itk,2); //KF code
00173           
00174 
00175           
00176           if ((abs(KF)== KF_muon))
00177             {
00178               TLorentzVector lvMuon = TLorentzVector(pythia->GetP(itk,1), pythia->GetP(itk,2), pythia->GetP(itk,3), pythia->GetP(itk,4));
00179               
00180              
00181 
00182               if(KS==21)
00183                 { Muons_Pt->Fill(lvMuon.Pt());
00184                 Muons_phi->Fill(lvMuon.Phi());
00185                 Muons_rapidity->Fill(lvMuon.Rapidity());
00186                 N_muons++;
00187                 // hmuonpt_initial->Fill(lvMuon.Pt());
00188                 muonsum+=lvMuon;
00189                 
00190                 
00191                 if (KF<0) //anti-muon
00192                   {
00193                     if (Nmuonplus==1)
00194                       {
00195                         muon2plus = lvMuon;
00196                       }
00197                     if (Nmuonplus==0)
00198                       {
00199                         muon1plus = lvMuon;
00200                         Nmuonplus=1;
00201                       }
00202                   }
00203                 else //muon
00204                   {
00205                     if (Nmuonminus==1)
00206                       {
00207                         muon2minus = lvMuon;
00208                       }
00209                     if (Nmuonminus==0)
00210                       {
00211                         muon1minus = lvMuon;
00212                         Nmuonminus=1;
00213                         Muon1_Pt->Fill(lvMuon.Pt());
00214                         Muon1_rapidity->Fill(lvMuon.Rapidity());
00215                         Muon1_phi->Fill(lvMuon.Phi());
00216                       }
00217                   }
00218                 }
00219               else
00220                 {
00221                   // hmuonpt_final->Fill(lvMuon.Pt());
00222                 }
00223             }
00224           
00225           
00226         }//itk //end of the loop over particles in one event
00227       //cout << "MyOutput: Number of muons =" << N_muons<<endl; 
00228       
00229       
00230       
00231       
00232       //Want to take the four vector of the muon and anti-muon and add them to get the four vectors of the Z
00233       
00234       TLorentzVector Z1,Z2;
00235       Z1 = muon1plus + muon1minus;
00236       Z_Pt->Fill(Z1.Pt());
00237       Z_rapidity->Fill(Z1.Rapidity());
00238       Z_phi->Fill(Z1.Phi());
00239 
00240       Z2 = muon2plus + muon2minus;
00241       Z_Pt->Fill(Z2.Pt());
00242       Z_rapidity->Fill(Z2.Rapidity());
00243       Z_phi->Fill(Z2.Phi());
00244       
00245       Z1mass->Fill(Z1.M());
00246       Z2mass->Fill(Z2.M());
00247      
00248 
00249       /*
00250       //get the opposite of the 3-vector of the Zs
00251       TVector3 boostZ1,boostZ2;
00252       boostZ1 = - Z1.BoostVector();
00253       boostZ2 = - Z2.BoostVector();
00254 
00255       //      boostZ1.Print();
00256       //      boostZ2.Print();
00257 
00258       //boost muon, anti-muon and Z1 to the Z1 rest frame
00259       TLorentzVector Z1_star,muon1_star,antimuon1_star;
00260       Z1_star = Z1;
00261       muon1_star = muon1minus;
00262       antimuon1_star = muon1plus;
00263 
00264       Z1_star.Boost(boostZ1);
00265       muon1_star.Boost(boostZ1);
00266       antimuon1_star.Boost(boostZ1);
00267       // Z1_star.Vect().Print();
00268 
00269       //boost muon, anti-muon and Z2 to the Z2 rest frame
00270       TLorentzVector Z2_star,muon2_star,antimuon2_star;
00271       Z2_star = Z2;
00272       muon2_star = muon2minus;
00273       antimuon2_star = muon2plus;
00274 
00275       Z2_star.Boost(boostZ2);
00276       muon2_star.Boost(boostZ2);
00277       antimuon2_star.Boost(boostZ2);
00278       // Z2_star.Vect().Print();
00279       */
00280 
00281       //boost Higgs, Z1, and Z2 into Higgs rest frame
00282       TVector3 boostH,boostZ1_hrest,boostZ2_hrest;
00283       TLorentzVector H,H_hrest,Z1_hrest,Z2_hrest,muon1_hrest,muon2_hrest,muon1_star,muon2_star,Z1_star,Z2_star,antimuon1_hrest,antimuon1_star;
00284       H = Z1+Z2;
00285       boostH = -H.BoostVector();
00286       H_hrest = H;
00287       Z1_hrest = Z1;
00288       Z2_hrest = Z2;
00289       muon1_hrest = muon1minus;
00290       muon2_hrest = muon2minus;
00291       antimuon1_hrest = muon1plus;
00292       //      H_hrest.Vect().Print();
00293       H_hrest.Boost(boostH);//zero ?
00294       // H_hrest.Vect().Print();
00295       //Z1_hrest.Vect().Print();
00296       //Z2_hrest.Vect().Print();
00297       Z1_hrest.Boost(boostH);
00298       Z2_hrest.Boost(boostH);
00299       //Z1_hrest.Vect().Print();
00300       //Z2_hrest.Vect().Print();
00301       muon1_hrest.Boost(boostH);
00302       muon2_hrest.Boost(boostH);
00303       antimuon1_hrest.Boost(boostH);
00304 
00305       boostZ1_hrest = -Z1_hrest.BoostVector();
00306       boostZ2_hrest = -Z2_hrest.BoostVector();
00307       
00308       Z1_star = Z1_hrest;
00309       Z2_star = Z2_hrest;
00310       
00311       muon1_star = muon1_hrest;
00312       muon2_star = muon2_hrest;
00313       antimuon1_star = antimuon1_hrest;
00314       
00315       Z1_star.Boost(boostZ1_hrest);
00316       Z2_star.Boost(boostZ2_hrest);
00317       //Z1_star.Vect().Print();
00318       //Z2_star.Vect().Print();
00319       
00320       muon1_star.Boost(boostZ1_hrest);
00321       muon2_star.Boost(boostZ2_hrest);
00322       antimuon1_star.Boost(boostZ1_hrest);
00323 
00324       TVector3 uZ1 = Z1_hrest.Vect().Unit();
00325       TVector3 uZ2 = Z2_hrest.Vect().Unit();
00326 
00327       float cosine1, cosine2, antimuon_cosine1;
00328       TVector3 unit_muon1_star = muon1_star.Vect().Unit();
00329       cosine1 = uZ1.Dot(unit_muon1_star);
00330       //      cout <<cosine1<<endl;
00331       //      cout <<" radian or degree "<<uZ1.Angle(unit_muon1_star)<<endl;
00332       //      cout <<cos( uZ1.Angle(unit_muon1_star) )<<endl;
00333       //cout<<"The cosine(theta) of muon 1 is :"<<cosine1<<endl;
00334 
00335       TVector3 unit_antimuon2_star = antimuon1_star.Vect().Unit();
00336       antimuon_cosine1 = uZ1.Dot(unit_antimuon2_star);
00337        
00338       //cout<<"The cosine(theta) of anti-muon 1 is: "<<antimuon_cosine1<<endl;
00339       
00340       TVector3 unit_muon2_star = muon2_star.Vect().Unit();
00341       cosine2 = uZ2.Dot(unit_muon2_star);     
00342       //cout<<"The cosine(theta) of muon 2 is: "<<cosine2<<endl;
00343 
00344       Cosine1plot->Fill(cosine1);
00345       Cosine2plot->Fill(cosine2);
00346       Correlationplot->Fill(cosine1,cosine2);
00347 
00348       TVector3 x1(1.0,0.0,0.0),y1(0.0,1.0,0.0);
00349       x1.RotateUz(uZ1);
00350       y1.RotateUz(uZ1);
00351       //(x1,y1,uZ1) is the rest frame of the Z, with z axis along the Z boson.
00352       
00353       TVector2 muon1_star2d(x1.Dot(unit_muon1_star),y1.Dot(unit_muon1_star));
00354       Phiplot1->Fill(muon1_star2d.Phi());
00355       
00356       TVector3 x2(1.0,0.0,0.0),y2(0.0,1.0,0.0);
00357       x2.RotateUz(uZ2);
00358       y2.RotateUz(uZ2);
00359       //(x2,y2,uZ2) is the rest frame of the Z, with z axis along the Z boson.
00360       
00361       TVector2 muon2_star2d(x2.Dot(unit_muon2_star),y2.Dot(unit_muon2_star));
00362       Phiplot2->Fill(muon2_star2d.Phi());
00363       
00364 
00365       bool didImessmuonplus=false;
00366       bool didImessmuonminus=false;
00367 
00368       //randomizing the anti-muons order
00369       if(R.Rndm()>0.5)
00370         {
00371           TLorentzVector temp;
00372           temp=muon1plus;
00373           muon1plus=muon2plus;
00374           muon2plus=temp;
00375           didImessmuonplus=true;
00376         }
00377       //randomizing the muons order
00378       if(R.Rndm()>0.5)
00379         {
00380           TLorentzVector temp;
00381           temp=muon1minus;
00382           muon1minus=muon2minus;
00383           muon2minus=temp;
00384           didImessmuonminus=true;
00385         }
00386          
00387       int MM=didImessmuonminus;
00388       int MP=didImessmuonplus;
00389 
00390       
00391       bool condition=(MM || MP) && (!MP || !MM);
00392       bool auxcond=((MP+MM)&1);
00393       if (auxcond!=condition)
00394         cout <<condition<<" "<<((MP+MM)&1)<<endl;
00395 
00396     
00397 
00398       Hmass->Fill(muonsum.M());
00399       Higgs_Pt->Fill(muonsum.Pt());
00400       Higgs_phi->Fill(muonsum.Phi());
00401       Higgs_rapidity->Fill(muonsum.Rapidity());
00402      
00403     }//ievt /end of loop over the events
00404   
00405  
00406 
00407  
00408   
00409   
00410  
00411    char name[100];
00412   // sprintf(name,"IVplots_Hm%5.2f_Nevt%d.eps",Higgsmass,nEvents);
00413   // c1->Print(name);
00414   
00415   TCanvas * c3 = new TCanvas("c3","**",800,800);
00416   c3->Divide(2,2);
00417   c3->SetFillColor(9);
00418   c3->cd(1);
00419   Cosine1plot->Draw();
00420  
00421   Cosine1plot->SetTitle("Cos(#theta) of muon1 in Z1 rest frame");
00422 //Cosine1graph->Rebin(8);
00423   TF1 *f2 = new TF1("f2","[0]*([1]*(3/4)*(1-x**2)+(3/8)*(1-[1])*(1+x**2))",-1,1);
00424   TF1 *f3 = new TF1("f3","[0]*( (1/(1+[1]))*(3/4)*(1-x**2) + (3/8)*([1]/(1+[1]))*(1+x**2) )",-1,1);
00425   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);
00426 
00427   f2->SetParNames("Normalization","alpha");
00428   f3->SetParNames("Normalization","R");
00429   f4->SetParNames("Normalization","tullyR");
00430 
00431   f2->SetParameter(1,0.9);
00432   f3->SetParameter(1,0.1);
00433   f4->SetParameter(1,0.8);
00434   
00435   f2->FixParameter(0,Cosine1plot->Integral("bin width"));
00436   f3->FixParameter(0,Cosine1plot->Integral("bin width"));
00437   f4->FixParameter(0,Cosine1plot->Integral("bin width"));
00438 
00439   Cosine1plot->Fit("f2","L");
00440   Cosine1plot->Fit("f3","L+");
00441   Cosine1plot->Fit("f4","L+");
00442 
00443 
00444 
00445 
00446   c3->cd(2);
00447   Cosine2plot->Draw();
00448   c3->cd(3);
00449   Correlationplot->Draw();
00450 
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   c4->cd(2);
00461   Phiplot2->Draw();
00462 
00463  
00464   TCanvas * c5 = new TCanvas("c5","**",800,800);
00465   c5->SetFillColor(9);
00466   Hmass->Draw("e");
00467 
00468   TCanvas * c6 = new TCanvas("c6","**",800,800);
00469   c6->cd();
00470   Z1mass->Draw();
00471 
00472   TCanvas * c7 = new TCanvas("c7","**",800,800);
00473   c7->cd();
00474   Z2mass->Draw();
00475 
00476   TCanvas * c8 = new TCanvas("c8","**",800,800);
00477   c8->cd();
00478   Higgs_Pt->Draw();
00479 
00480 
00481   TCanvas * c9 = new TCanvas("c9","**",800,800);
00482   c9->cd();
00483   Z_Pt->Draw();
00484 
00485   TCanvas * c10 = new TCanvas("c10","**",800,800);
00486   c10->cd();
00487   Higgs_phi->Draw();
00488   
00489   TCanvas * c11 = new TCanvas("c11","**",800,800);
00490   c11->cd();
00491   Higgs_rapidity->Draw();
00492 
00493   TCanvas * c12 = new TCanvas("c12","**",800,800);
00494   c12->cd();
00495   Z_rapidity->Draw();
00496   
00497   TCanvas * c13 = new TCanvas("c13","**",800,800);
00498   c13->cd();
00499   Z_phi->Draw();
00500 
00501   TCanvas * c14 = new TCanvas("c14","**",800,800);
00502   c14->cd();
00503   Muon1_phi->Draw();
00504 
00505   TCanvas * c15 = new TCanvas("c15","**",800,800);
00506   c15->cd();
00507   Muon1_Pt->Draw();
00508 
00509   TCanvas * c16 = new TCanvas("c16","**",800,800);
00510   c16->cd();
00511   Muon1_rapidity->Draw();
00512 
00513   TCanvas * c17 = new TCanvas("c17","**",800,800);
00514   c17->cd();
00515   Muons_Pt->Draw();
00516 
00517   TCanvas * c18 = new TCanvas("c18","**",800,800);
00518   c18->cd();
00519   Muons_rapidity->Draw();
00520   
00521   TCanvas * c19 = new TCanvas("c19","**",800,800);
00522   c19->cd();
00523   Muons_phi->Draw();
00524 
00525   
00526   sprintf(name,"histograms_correct_HtoZZ_angular_Hm%5.2f_Nevt%d.root",Higgsmass,nEvents);
00527   TFile f(name,"recreate");
00528   f.cd();
00529   int N=gROOT->GetList()->GetSize();
00530   for (int key=0; key<N ; key++)
00531     {
00532 
00533       TObject * obj = gROOT->GetList()->At(key);
00534       if (obj->InheritsFrom("TH1F") || obj->InheritsFrom("TH2F"))
00535         {
00536           cout <<"write "<<obj->GetName()<<endl;
00537           obj->Write();
00538 
00539         }
00540     }
00541   f.Close();
00542 
00543   
00544   for (int key=N-1; key>=0 ; key--)
00545     {
00546       
00547       TObject * obj = gROOT->GetList()->At(key);
00548       cout <<"delete "<<obj->GetName()<<endl;
00549       if (obj)  delete obj;
00550       cout <<"deleted "<<gROOT->GetList()->GetSize()<<" objects remaining"<<endl;
00551       }
00552   
00553   watcher.Stop();
00554   cout <<"Time spent for "<<nEvents<<" events :"<< watcher.RealTime()<<" [s]"<<endl;
00555 
00556   return -97534;
00557 
00558 }//makePyEvts
00559 

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