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

TopAnalysis.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include <stdio.h>
00004 #include "HepMC/GenEvent.h"
00005 #include "HepMC/IO_GenEvent.h"
00006 #include "HepMC/GenParticle.h"
00007 #include "HepMC/GenVertex.h"
00008 #include "HepMC/IO_AsciiParticles.h"
00009 #include "HepMC/SimpleVector.h"
00010 #include "CLHEP/Vector/LorentzVector.h"
00011 
00012 using namespace std;
00013 
00014 // ROOT headers
00015 #include "TH1.h"
00016 #include "TH2.h"
00017 #include "TFile.h"
00018 #include "TMath.h"
00019 #include "TLorentzVector.h"
00020 
00021 //top analysis header
00022 #include "../include/TopAnalysis.h"
00023 
00024 //**********************
00025 
00026 // empty default constructor
00027 TopAnalysis::TopAnalysis()
00028 {
00029 }
00030 
00031 /// empty default destructor
00032 TopAnalysis::~TopAnalysis()
00033 {
00034 }
00035 
00036 
00037 int TopAnalysis::Init(double tr_max_eta, double tr_min_pt)
00038 {
00039   // specify default eta cut
00040   m_max_eta=tr_max_eta;
00041   
00042   // specify default pt cut
00043   m_min_pt=tr_min_pt;
00044 
00045   // default Output file name
00046   m_outputFileName="TopAnalysis.root";
00047   m_outputRootDir="Top";
00048   
00049   //declaration of histograms
00050   m_evtnr=initHist(string("evtnr"),string("Event number"),string("Eventnumber"),100, 0., 99.);
00051   m_toppt=initHist(string("toppt"),string("transversal momentum of top and antitop"),string("p_{T} [GeV]"),300, 0., 1500.);
00052   m_toppt_log=initHist(string("toppt_logscale"),string("transversal momentum of top and antitop - logscale -"),string("p_{T} [GeV]"),300, 0., 1500.);
00053   m_topeta=initHist(string("topeta"),string("eta of top and antitop"),string("#eta"),60, -6., 6.);
00054   m_topphi=initHist(string("topphi"),string("phi of top and antitop"),string("#phi"),48, -3.15, 3.15);
00055   m_ptstable=initHist(string("ptstable"),string("transveral momentum of stable particles (without neutrinos)"),
00056                       string("p_{T} [GeV]"),400, 0., 100.);
00057   m_ptstable_log=initHist(string("ptstable_logscale"),
00058                           string("transveral momentum of stable particles (without neutrinos) - logscale -"), 
00059                           string("p_{T} [GeV]"),400, 0., 100.);
00060   m_etastable=initHist(string("etastable"),string("eta of stable particles (without neutrinos)"),string("#eta"),100, -6., 6.);
00061   m_phistable=initHist(string("phistable"),string("phi of stable particles (without neutrinos)"),string("#phi"),100, -3.15, 3.15);
00062   m_ptstable_charged=initHist(string("ptstable_charged"),string("transveral momentum of charged stable particles"),
00063                               string("p_{T} [GeV]"),400, 0., 100.);
00064   m_ptstable_charged_log=initHist(string("ptstable_charged_logscale"),
00065                                   string("transveral momentum of charged stable particles - logscale -"),
00066                                   string("p_{T} [GeV]"),400, 0., 100.);
00067   m_etastable_charged=initHist(string("etastable_charged"),string("eta of charged stable particles"),string("#eta"),100, -6., 6.);
00068   m_phistable_charged=initHist(string("phistable_charged"),string("phi of charged stable particles"),string("#phi"),100, -3.15, 3.15);
00069   m_cmultpart=initHist(string("cmultpart"),string("number of charged particles in the event"),string("charged particle multiplicity"),
00070                        240, 0., 1200.);
00071   m_pttoppair=initHist(string("pttoppair"),string("transveral momentum of top pair"),string("p_{T} [GeV]"),200, 0., 1000.);
00072   m_pttoppair_log=initHist(string("pttoppair_logscale"),string("transveral momentum of top pair - logscale -"),string("p_{T} [GeV]"),200, 0., 1000.);
00073   m_W_W_phi=initHist(string("W_W_phi"),string("phi between W from top and W from tbar"),string("#phi_{W} - #phi_{Wbar}"),
00074                      48, -3.15, 3.15);
00075   m_top_tbar_phi=initHist(string("top_tbar_phi"),string("phi between top and tbar"),string("#phi_{top} - #phi_{tbar}"),48, -3.15, 3.15);
00076   m_W_top_phi=initHist(string("W_top_phi"),string("phi between W (from top) and top (also for tbar)"),
00077                        string("#phi_{top} - #phi_{W}"),48, -3.15, 3.15);
00078   m_Wpt=initHist(string("Wpt"),string("transversal momentum of W"),string("p_{T} [GeV]"),200, 0., 1000.);
00079   m_Wpt_log=initHist(string("Wpt_logscale"),string("transversal momentum of W - logscale -"),string("p_{T} [GeV]"),200, 0., 1000.);
00080   m_Weta=initHist(string("Weta"),string("eta of W"),string("#eta"),60, -6., 6.);
00081   m_Wphi=initHist(string("Wphi"),string("phi of W"),string("#phi"),48, -3.15, 3.15);
00082   
00083   m_jet_count=baseAnalysis::initHist(string("jet_count"), string("Nr of Jets"), string("Nr Jets"),16, -0.5, 15.5);
00084   m_jet_pt=baseAnalysis::initHist(string("leadingjet_pt_high"),string("Leading Jet Transverse Momentum"),string("Jet p_{T} [GeV]"), 200, 0.,1000.);
00085   m_jet_pt_log=baseAnalysis::initHist(string("leadingjet_pt_high_logscale"),string("Leading Jet Transverse Momentum -logscale-"),string("Jet p_{T} [GeV]"), 200, 0.,1000.);
00086   
00087   return true;
00088 }
00089 
00090 int TopAnalysis::Process(HepMC::GenEvent* hepmcevt) 
00091 {
00092 
00093   // Some Variables for storage are needed
00094   int top_barcode=0;
00095   int tbar_barcode=0;
00096   int W_barcode=0;
00097   int Wbar_barcode=0;
00098   
00099   //counter variable
00100   int cmult=0;
00101 
00102   //variable for status of particle
00103   int properStatus = 2;
00104 
00105   // Fill the eventnumber
00106   m_evtnr->Fill(hepmcevt->event_number());
00107 
00108   // loop over the particles and select pdgid and pt
00109   for ( HepMC::GenEvent::particle_const_iterator p = 
00110           hepmcevt->particles_begin(); p != hepmcevt->particles_end(); ++p )
00111     {
00112       // use the pdg id to identify the particles
00113       int pid = (*p)->pdg_id();
00114       
00115       // find the last top quarks in the event and 
00116       // store their barcodes  to find them back in the event
00117       if (pid == 6) top_barcode = (*p)->barcode();
00118       if (pid == -6)  tbar_barcode = (*p)->barcode();
00119       
00120       //the last W-bosons coming from top 
00121       properStatus = 2;
00122       if (abs(pid) == 6 && ( ((*p)->status()) == properStatus))
00123         {
00124           if (!((*p)->end_vertex()))
00125             {
00126               std::cout<<"CRASH!!!!!"<<std::endl;
00127               std::cout<<"event number: "<<hepmcevt->event_number()<<std::endl;
00128               std::cout<<"pdgId (of top): "<<pid<<std::endl;
00129               std::cout<<"particle number (top barcode): "<<(*p)->barcode()<<std::endl;
00130               std::cout<<"(*p)->status(): "<<(*p)->status()<<std::endl;
00131               std::cout<<"(*p)->end_vertex(): "<<(*p)->end_vertex()<<std::endl;
00132               
00133               std::cout<<"skip event"<<std::endl;
00134               return false;
00135             }
00136           
00137           HepMC::GenVertex::particle_iterator firstChild = (*p)->end_vertex()->particles_begin(HepMC::children);
00138           if( ((*firstChild)->pdg_id()) == 24 )
00139             {
00140               W_barcode = (*firstChild)->barcode();
00141             }
00142           
00143           if( ((*firstChild)->pdg_id()) == -24 )
00144             {
00145               Wbar_barcode = (*firstChild)->barcode();
00146             }
00147         }
00148       
00149       // take all stable particles of this event
00150      if(!IsFinalStateParticle((*p))) continue;
00151       
00152       if(! (abs(pid)==12 || abs(pid)==14 || abs(pid)==16) )
00153         {
00154           m_ptstable->Fill( (*p)->momentum().perp() );
00155           m_ptstable_log->Fill( (*p)->momentum().perp() );
00156           m_etastable->Fill( (*p)->momentum().eta() );
00157           m_phistable->Fill( (*p)->momentum().phi() );
00158         }
00159       
00160       // cut out the neutral particles  (charge is not stored in HepMC)
00161       // just remove the neutrinos, gammas and neutrons from 
00162       // the final state
00163       if(!chargedParticle(pid)) continue;
00164       
00165       m_ptstable_charged->Fill( (*p)->momentum().perp() );
00166       m_ptstable_charged_log->Fill( (*p)->momentum().perp() );
00167       m_etastable_charged->Fill( (*p)->momentum().eta() );
00168       m_phistable_charged->Fill( (*p)->momentum().phi() );
00169       
00170       cmult++;
00171       
00172     } // end of loop over particles
00173 
00174   // storage of input particles for jet
00175   CLHEP::HepLorentzVector lv_leadingJet(0,0,0,0);
00176   
00177   // check if jets were found
00178   //if(!m_inclusive_jets.size()) std::cout<<"TopAnalysis::no jets found"<<std::endl;
00179 
00180   //Fill the histograms
00181   m_jet_count->Fill(m_inclusive_jets.size());
00182 
00183   if(m_inclusive_jets.size()){
00184     m_jet_pt->Fill(m_inclusive_jets[0].perp());
00185     m_jet_pt_log->Fill(m_inclusive_jets[0].perp());
00186   }
00187     
00188   // now we have the toppair - let's histogramm pt, eta and the pt sum
00189   HepMC::GenParticle *top = hepmcevt->barcode_to_particle(top_barcode);
00190   HepMC::GenParticle *tbar = hepmcevt->barcode_to_particle(tbar_barcode);
00191   if(top && tbar) 
00192     {
00193       m_toppt->Fill( top->momentum().perp() );
00194       m_toppt->Fill( tbar->momentum().perp() );
00195       m_toppt_log->Fill( top->momentum().perp() );
00196       m_toppt_log->Fill( tbar->momentum().perp() );
00197       m_topeta->Fill( top->momentum().eta() );
00198       m_topeta->Fill( tbar->momentum().eta() );
00199       m_topphi->Fill( top->momentum().phi() );
00200       m_topphi->Fill( tbar->momentum().phi() );
00201       
00202       // calculate the pt of the ttbar system 
00203       double px = top->momentum().px();
00204       px += tbar->momentum().px();
00205       double py = top->momentum().py();
00206       py += tbar->momentum().py();
00207       double perp = px*px + py*py;
00208       perp = TMath::Sqrt(perp);
00209       m_pttoppair->Fill(perp);
00210       m_pttoppair_log->Fill(perp);
00211       m_cmultpart->Fill(cmult);
00212 
00213       //calculate phi angle between top and antitop
00214       double top_phi = 0;
00215       double tbar_phi = 0;
00216       double DeltaPhi_top_tbar = 0;
00217 
00218       top_phi = top->momentum().phi();
00219       tbar_phi = tbar->momentum().phi();
00220       DeltaPhi_top_tbar = top_phi - tbar_phi;
00221 
00222       //if( fabs(DeltaPhi_top_tbar) > TMath::Pi() ||  fabs(DeltaPhi_top_tbar) == TMath::Pi() )
00223       if( DeltaPhi_top_tbar > TMath::Pi() ||  DeltaPhi_top_tbar == TMath::Pi() )
00224         {
00225           DeltaPhi_top_tbar = DeltaPhi_top_tbar - 2 * TMath::Pi() ;
00226         }
00227 
00228       if( DeltaPhi_top_tbar < - TMath::Pi() ||  DeltaPhi_top_tbar == - TMath::Pi() )
00229         {
00230           DeltaPhi_top_tbar = DeltaPhi_top_tbar + 2 * TMath::Pi();
00231         }
00232 
00233       m_top_tbar_phi->Fill(DeltaPhi_top_tbar);
00234     }
00235 
00236    //for W
00237    HepMC::GenParticle *W = hepmcevt->barcode_to_particle(W_barcode);
00238    HepMC::GenParticle *Wbar = hepmcevt->barcode_to_particle(Wbar_barcode);
00239 
00240    if(W && Wbar) 
00241      {
00242        m_Wpt->Fill( W->momentum().perp() );
00243        m_Wpt->Fill( Wbar->momentum().perp() );
00244        m_Wpt_log->Fill( W->momentum().perp() );
00245        m_Wpt_log->Fill( Wbar->momentum().perp() );
00246        m_Weta->Fill( W->momentum().eta() );
00247        m_Weta->Fill( Wbar->momentum().eta() );
00248        m_Wphi->Fill( W->momentum().phi() );
00249        m_Wphi->Fill( Wbar->momentum().phi() );
00250        
00251        //calculate phi angle between W and Wbar
00252        double W_phi = 0;
00253        double Wbar_phi = 0;
00254        double DeltaPhi_W_W = 0;
00255        W_phi = W->momentum().phi();
00256        Wbar_phi = Wbar->momentum().phi();
00257        DeltaPhi_W_W = W_phi - Wbar_phi;
00258        
00259        if( DeltaPhi_W_W > TMath::Pi() ||  DeltaPhi_W_W == TMath::Pi() )
00260          {
00261            DeltaPhi_W_W = DeltaPhi_W_W - 2 * TMath::Pi() ;
00262          }
00263        
00264        if( DeltaPhi_W_W < - TMath::Pi() ||  DeltaPhi_W_W == - TMath::Pi() )
00265          {
00266            DeltaPhi_W_W = DeltaPhi_W_W + 2 * TMath::Pi();
00267          }
00268        m_W_W_phi->Fill(DeltaPhi_W_W);
00269      }
00270 
00271    //calculating the angle between top and W
00272    
00273    if (top && ( top->status() == 2 ) )
00274      {
00275        double top_phi = 0;   
00276        double W_phi = 0;
00277        double DeltaPhi_W_top = 0;
00278        
00279        HepMC::GenVertex::particle_iterator firstChild = top->end_vertex()->particles_begin(HepMC::children);
00280        
00281        if( abs((*firstChild)->pdg_id()) == 24 )
00282          {
00283            top_phi = top->momentum().phi();
00284            W_phi = (*firstChild)->momentum().phi();
00285            DeltaPhi_W_top = top_phi - W_phi;
00286            
00287            if( DeltaPhi_W_top > TMath::Pi() ||  DeltaPhi_W_top == TMath::Pi() )
00288              {
00289                DeltaPhi_W_top = DeltaPhi_W_top - 2 * TMath::Pi() ;
00290              }
00291            
00292            if( DeltaPhi_W_top < - TMath::Pi() ||  DeltaPhi_W_top == - TMath::Pi() )
00293              {
00294                DeltaPhi_W_top = DeltaPhi_W_top + 2 * TMath::Pi();
00295              }
00296            m_W_top_phi->Fill(DeltaPhi_W_top);
00297          }
00298      }
00299 
00300    if (tbar && ( tbar->status() == 2 ) )
00301      {
00302        double top_phi = 0;
00303        double W_phi = 0;
00304        double DeltaPhi_W_top = 0;
00305        
00306        HepMC::GenVertex::particle_iterator firstChild = tbar->end_vertex()->particles_begin(HepMC::children);
00307        
00308        if( abs((*firstChild)->pdg_id()) == 24 )
00309          {
00310            top_phi = tbar->momentum().phi();
00311            W_phi = (*firstChild)->momentum().phi();
00312            DeltaPhi_W_top = top_phi - W_phi;
00313            
00314            if( DeltaPhi_W_top > TMath::Pi() ||  DeltaPhi_W_top == TMath::Pi() )
00315              {
00316                DeltaPhi_W_top = DeltaPhi_W_top - 2 * TMath::Pi() ;
00317              }
00318            
00319            if( DeltaPhi_W_top < - TMath::Pi() ||  DeltaPhi_W_top == - TMath::Pi() )
00320              {
00321                DeltaPhi_W_top = DeltaPhi_W_top + 2 * TMath::Pi();
00322              }
00323            m_W_top_phi->Fill(DeltaPhi_W_top);
00324          }
00325      }
00326    
00327    return true;
00328 } //end Process

Generated on Thu Jul 23 14:57:36 2009 for HepMCAnalysis by  doxygen 1.3.9.1