ZtautauAnalysis.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <sstream>
00003 #include <stdio.h>
00004 
00005 #include "HepMC/GenEvent.h"
00006 #include "HepMC/IO_GenEvent.h"
00007 #include "HepMC/GenParticle.h"
00008 #include "HepMC/GenVertex.h"
00009 #include "HepMC/IO_AsciiParticles.h"
00010 #include "HepMC/SimpleVector.h"
00011 #include "CLHEP/Vector/LorentzVector.h"
00012 
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 //Ztautau analysis header
00022 #include "../include/ZtautauAnalysis.h"
00023 
00024 using namespace std;
00025 
00026 // ---------------------------------------------------------------------- 
00027 ZtautauAnalysis::ZtautauAnalysis()
00028 {}
00029 
00030 // ---------------------------------------------------------------------- 
00031 ZtautauAnalysis::~ZtautauAnalysis()
00032 {}
00033 
00034 // ---------------------------------------------------------------------- 
00035 int ZtautauAnalysis::Init(double tr_max_eta, double tr_min_pt)
00036 {
00037   // specify default eta cut                                                                                                           
00038   m_max_eta=tr_max_eta;
00039 
00040   // specify default pt cut
00041   m_min_pt=tr_min_pt;
00042     
00043   // default Output file name
00044   m_outputFileName="ZtautauAnalysis.root";
00045   m_outputRootDir="Ztautau";
00046 
00047   //declaration of histograms
00048   m_evtnr=initHist(string("evtnr"),string("Event number"),string("Eventnumber"),1000, 0., 1000.);
00049   m_taupt=initHist(string("taupt"),string("transversal momentum of tau+ and tau-"),string("p_{T} [GeV]"),100, 0., 200.);
00050   m_taupt_log=initHist(string("taupt_logscale"),string("transversal momentum of tau+ and tau- - logscale -"),
00051                        string("p_{T} [GeV]"),100, 0., 200.);
00052   m_taueta=initHist(string("taueta"),string("eta of tau+ and tau-"),string("#eta"),60, -6., 6.);
00053   m_tauphi=initHist(string("tauphi"),string("phi of tau+ and tau-"),string("#phi"),48, -3.15, 3.15);
00054   m_ptstable=initHist(string("ptstable"),string("transveral momentum of stable particles (without neutrinos)"),
00055                       string("p_{T} [GeV]"),60, 0., 15.);
00056   m_ptstable_log=initHist(string("ptstable_logscale"),string("transveral momentum of stable particles (without neutrinos) - logscale"),
00057                           string("p_{T} [GeV]"),60, 0., 15.);
00058   m_etastable=initHist(string("etastable"),string("eta of stable particles (without neutrinos)"),string("#eta"),100, -6., 6.);
00059   m_phistable=initHist(string("phistable"),string("phi of stable particles (without neutrinos)"),string("#phi"),100, -3.15, 3.15);
00060   m_E_stable=initHist(string("E_stable"),string("energy of stable particles (without neutrinos)"),string("E [GeV]"),50, 0., 100.);
00061   m_E_stable_log=initHist(string("E_stable_logscale"),string("energy of stable particles (without neutrinos) - logscale -"),
00062                           string("E [GeV]"),50, 0., 100.);
00063   m_ptstable_charged=initHist(string("ptstable_charged"),string("transveral momentum of charged stable particles"),
00064                               string("p_{T} [GeV]"),200, 0., 50.);
00065   m_ptstable_charged_log=initHist(string("ptstable_charged_logscale"),
00066                                   string("transveral momentum of charged stable particles - logscale -"),
00067                                   string("p_{T} [GeV]"),200, 0., 50.);
00068   m_etastable_charged=initHist(string("etastable_charged"),string("eta of charged stable particles"),string("#eta"),100, -6., 6.);
00069   m_phistable_charged=initHist(string("phistable_charged"),string("phi of charged stable particles"),string("#phi"),100, -3.15, 3.15);
00070   m_E_stable_charged=initHist(string("E_stable_without_neutrinos"),string("energy of charged stable particles"),
00071                               string("E [GeV]"),100, 0., 200.);
00072   m_E_stable_charged_log=initHist(string("E_stable_without_neutrinos_logscale"),
00073                                   string("energy of charged stable particles - logscale -"),string("E [GeV]"),100, 0., 200.);
00074   m_cmultpart=initHist(string("cmultpart"),string("number of charged particles in the event"),string("charged particle multiplicity"),
00075                        120, 0., 600.);
00076   m_nTrack_tau=initHist(string("nTrack_tau"),string("number of tracks of tau decay"),string("number of tracks"),16, -0.5, 15.5);
00077   m_pt_hightrack=initHist(string("pt_hightrack"),string("transversal momentum of highest p_{T}-track"),string("p_{T} [GeV]"),
00078                           200, 0., 100.);
00079   m_pt_hightrack_log=initHist(string("pt_hightrack_logscale"),string("transversal momentum of highest p_{T}-track - logscale -"),
00080                               string("p_{T} [GeV]"),200, 0., 100.);
00081   
00082   m_jet_count=baseAnalysis::initHist(string("jet_count"), string("Nr of Jets"), string("Nr Jets"),16, -0.5, 15.5);
00083   m_jet_pt=baseAnalysis::initHist(string("leadingjet_pt_high"),string("Leading Jet Transverse Momentum"),string("Jet p_{T} [GeV]"), 200, 0.,1000.);
00084   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.);
00085 
00086   return true;
00087 }
00088 
00089 // ---------------------------------------------------------------------- 
00090 int ZtautauAnalysis::Process(HepMC::GenEvent* hepmcevt) 
00091 {
00092   int cmult = 0; //charged particle multiplicity
00093   int tau_barcode = 0;
00094   int taubar_barcode = 0;
00095   
00096   //variable for status of particle
00097   int properStatus = 0;
00098   
00099   m_evtnr->Fill(hepmcevt->event_number());
00100 
00101   // loop over the particles and select pdgid and pt
00102   for ( HepMC::GenEvent::particle_const_iterator p = 
00103           hepmcevt->particles_begin(); p != hepmcevt->particles_end(); ++p )
00104     {
00105       // use the pdg id to identify the particles
00106       int pid = (*p)->pdg_id();
00107 
00108       //if (pid == 23 && (*p)->status()%1000==2 && (*p)->end_vertex())
00109       if (pid == 23 && (*p)->end_vertex())
00110         {
00111           // search for decaying particles
00112           // since the particles should decay, they should have a decay vertex
00113           if(!((*p)->end_vertex())) continue;
00114 //          {
00115 //            std::cout<<"CRASH!!!!!"<<std::endl;
00116 //            std::cout<<"event number: "<<hepmcevt->event_number()<<std::endl;
00117 //            std::cout<<"pdgId (of Z): "<<pid<<std::endl;
00118 //            std::cout<<"particle number (Z barcode): "<<(*p)->barcode()<<std::endl;
00119 //            std::cout<<"(*p)->status(): "<<(*p)->status()<<std::endl;
00120 //            std::cout<<"(*p)->end_vertex(): "<<(*p)->end_vertex()<<std::endl;
00121               
00122 //            std::cout<<"skip event"<<std::endl;
00123 //            return false;
00124 //          }
00125       
00126           // find the last taus in the event and 
00127           // store their barcodes  to find them back in the event
00128           for(HepMC::GenVertex::particle_iterator iChild=(*p)->end_vertex()->particles_begin(HepMC::descendants); 
00129               iChild!=(*p)->end_vertex()->particles_end(HepMC::descendants); iChild++)
00130             {
00131               if( (*iChild)->pdg_id() != pid )
00132                 {
00133                   if ((*iChild)->pdg_id() == 15) tau_barcode = (*iChild)->barcode();
00134                   if ((*iChild)->pdg_id() == -15)  taubar_barcode = (*iChild)->barcode();
00135                 }
00136             }
00137         }
00138       
00139       // take all stable particles of this event
00140      if(!IsFinalStateParticle((*p))) continue;
00141       
00142       if(! ( abs(pid)==12 || abs(pid)==14 || abs(pid)==16 ) ) //energy stable particles without neutrinos
00143         {
00144           m_ptstable->Fill( (*p)->momentum().perp() );
00145           m_ptstable_log->Fill( (*p)->momentum().perp() );
00146           m_etastable->Fill( (*p)->momentum().eta() );
00147           m_phistable->Fill( (*p)->momentum().phi() );
00148           m_E_stable->Fill( (*p)->momentum().e() );
00149           m_E_stable_log->Fill( (*p)->momentum().e() );
00150         }
00151       
00152       // cut out the neutral particles  (charge is not stored in HepMC)
00153       // just remove the neutrinos, gammas and neutrons from 
00154       // the final state
00155       if(!chargedParticle(pid)) continue;
00156       
00157       m_ptstable_charged->Fill( (*p)->momentum().perp() );
00158       m_ptstable_charged_log->Fill( (*p)->momentum().perp() );
00159       m_etastable_charged->Fill( (*p)->momentum().eta() );
00160       m_phistable_charged->Fill( (*p)->momentum().phi() );
00161       m_E_stable_charged->Fill( (*p)->momentum().e() );
00162       m_E_stable_charged_log->Fill( (*p)->momentum().e() );
00163       
00164       cmult++;
00165     }  // end of loop over particles
00166   
00167   // storage of input particles for jet
00168   CLHEP::HepLorentzVector lv_leadingJet(0,0,0,0);
00169   
00170   // check if jets were found
00171   //if(!m_inclusive_jets.size()) std::cout<<"ZtautauAnalysis::no jets found"<<std::endl;
00172 
00173   //Fill the histograms
00174   m_jet_count->Fill(m_inclusive_jets.size());
00175 
00176   if(m_inclusive_jets.size()){
00177     m_jet_pt->Fill(m_inclusive_jets[0].perp());
00178     m_jet_pt_log->Fill(m_inclusive_jets[0].perp());
00179   }
00180   
00181   // now we have the taupair - let's histogramm pt, eta and the pt sum
00182   HepMC::GenParticle *tau = hepmcevt->barcode_to_particle(tau_barcode);
00183   HepMC::GenParticle *taubar = hepmcevt->barcode_to_particle(taubar_barcode);
00184   if(tau && taubar) 
00185     {
00186       m_taupt->Fill( tau->momentum().perp() );
00187       m_taupt->Fill( taubar->momentum().perp() );
00188       m_taupt_log->Fill( tau->momentum().perp() );
00189       m_taupt_log->Fill( taubar->momentum().perp() );
00190       m_taueta->Fill( tau->momentum().eta() );
00191       m_taueta->Fill( taubar->momentum().eta() );
00192       m_tauphi->Fill( tau->momentum().phi() );
00193       m_tauphi->Fill( taubar->momentum().phi() );
00194       
00195       m_cmultpart->Fill(cmult);
00196     }
00197   
00198   //checking for children of tau, needed for nTrack and the highest pT track
00199   
00200   //tau-
00201   //properStatus = 2;
00202   
00203   //if (tau && ( tau->status()%1000 == properStatus && tau->end_vertex()) )
00204   if (tau && tau->end_vertex())
00205     {
00206       // search for decaying taus
00207       // since the taus should decay, they should have a decay vertex
00208       if (!tau->end_vertex()) return false;
00209 
00210       int nTrack = 0; //number of tracks in tau decay
00211       double highpT_Track = 0.; //track with hightest pT coming from tau decay
00212       
00213       //important for the tracks (in the following the commented lines apply to the first generation of tau decay:
00214       //if you look only for the first generation as descendant (child), than the child can be stable or not stable,
00215       //only if you look for more than one generation as descendants, you need the proper status on stable;
00216       //this means that the final decay product of the tau has to be stable
00217       
00218       //only first generation
00219       //for(HepMC::GenVertex::particle_iterator iChild=tau->end_vertex()->particles_begin(HepMC::children); 
00220       //  iChild!=tau->end_vertex()->particles_end(HepMC::children); iChild++)
00221       
00222       //all generations as descendants
00223       for(HepMC::GenVertex::particle_iterator iChild=tau->end_vertex()->particles_begin(HepMC::descendants); 
00224           iChild!=tau->end_vertex()->particles_end(HepMC::descendants); iChild++)
00225         {
00226 //        if (!tau->end_vertex())
00227 //          {
00228 //            std::cout<<"CRASH!!!!!"<<std::endl;
00229 //            std::cout<<"event number: "<<hepmcevt->event_number()<<std::endl;
00230 //            std::cout<<"particle number (tau barcode): "<<tau->barcode()<<std::endl;
00231 //            std::cout<<"tau->status(): "<<tau->status()<<std::endl;
00232 //            std::cout<<"tau->end_vertex(): "<<tau->end_vertex()<<std::endl;
00233               
00234 //            std::cout<<"skip event"<<std::endl;
00235 //            return false;
00236 //          }
00237           
00238           if( (*iChild)->pdg_id() != tau->pdg_id() )
00239             {
00240               int iChild_pid = (*iChild)->pdg_id();
00241               properStatus = 1;
00242               
00243               if( chargedParticle(iChild_pid)==true && (*iChild)->status()%1000 == properStatus && !(*iChild)->end_vertex())
00244                 //if(chargedParticle(iChild_pid)==true && !(*iChild)->end_vertex())
00245                 {
00246                   // search for stable decay products of the taus
00247                   // since the children of the taus should not decay, they should not have a decay vertex
00248                   if ((*iChild)->end_vertex()) continue;
00249 
00250                   nTrack = nTrack + 1;
00251                   if ( (*iChild)->momentum().perp() > highpT_Track )
00252                     {
00253                       highpT_Track = (*iChild)->momentum().perp();
00254                     }
00255                 }
00256             }
00257         }
00258 
00259       //only fill nTrack and pt of highest track if a tau decays
00260       //      if (nTrack > 0) 
00261       //{
00262       //std::cout<<"nTrack for tau decay is "<<nTrack<<" for event "<<hepmcevt->event_number()<<std::endl;
00263       
00264           m_nTrack_tau->Fill(nTrack);
00265           m_pt_hightrack->Fill(highpT_Track);
00266           m_pt_hightrack_log->Fill(highpT_Track);
00267           //}
00268     }
00269   
00270   //tau+ (tbar)
00271   //properStatus = 2;
00272   
00273   //if (taubar && taubar->status()%1000 == properStatus && taubar->end_vertex() )
00274   if (taubar && taubar->end_vertex())
00275     {
00276       // search for decaying taubars
00277       // since the antitaus should decay, they should have a decay vertex
00278       if (!taubar->end_vertex()) return false;
00279 
00280       int nTrack = 0; //number of tracks in tau decay
00281       double highpT_Track = 0.; //track with hightest pT coming from tau decay
00282       
00283       //important for the tracks (in the following the commented lines apply to the first generation of tau decay:
00284       //if you look only for the first generation as descendant (child), than the child can be stable or not stable,
00285       //only if you look for more than one generation as descendants, you need the proper status on stable;
00286       //this means that the final decay product of the tau has to be stable
00287       
00288       //only first generation
00289       //for(HepMC::GenVertex::particle_iterator iChild=taubar->end_vertex()->particles_begin(HepMC::children); 
00290       //  iChild!=taubar->end_vertex()->particles_end(HepMC::children); iChild++)
00291       
00292 //       if (!taubar->end_vertex())
00293 //      {
00294 //        std::cout<<"CRASH!!!!!"<<std::endl;
00295 //        std::cout<<"event number: "<<hepmcevt->event_number()<<std::endl;
00296 //        std::cout<<"particle number (tau barcode): "<<taubar->barcode()<<std::endl;
00297 //        std::cout<<"taubar->status(): "<<taubar->status()<<std::endl;
00298 //        std::cout<<"taubar->end_vertex(): "<<taubar->end_vertex()<<std::endl;
00299           
00300 //        std::cout<<"skip event"<<std::endl;
00301 //        return false;
00302 //      }
00303 
00304       //all generations as descendants
00305       for(HepMC::GenVertex::particle_iterator iChild=taubar->end_vertex()->particles_begin(HepMC::descendants); 
00306           iChild!=taubar->end_vertex()->particles_end(HepMC::descendants); iChild++)
00307         {
00308           if( (*iChild)->pdg_id() != taubar->pdg_id() )
00309             {
00310               int iChild_pid = (*iChild)->pdg_id();
00311               properStatus = 1;
00312               
00313               if( (*iChild)->status()%1000 == properStatus && !(*iChild)->end_vertex() && chargedParticle(iChild_pid)==true)
00314                 //if(chargedParticle(iChild_pid)==true && !(*iChild)->end_vertex())
00315                 {
00316                   //search for stable decay products of the taubars
00317                   // since the children of the antitaus should not decay, they should not have a decay vertex
00318                   if ((*iChild)->end_vertex()) continue;
00319 
00320                   nTrack = nTrack + 1;
00321                   if ( (*iChild)->momentum().perp() > highpT_Track )
00322                     {
00323                       highpT_Track = (*iChild)->momentum().perp();
00324                     }
00325                 }
00326             }
00327           
00328         }
00329       //only fill nTrack and pt of highest track if a tau decays
00330       if (nTrack > 0) 
00331         {
00332           m_nTrack_tau->Fill(nTrack);
00333           m_pt_hightrack->Fill(highpT_Track);
00334           m_pt_hightrack_log->Fill(highpT_Track);
00335         }
00336     }
00337   return true;
00338 } //end of Process

Generated on Wed Aug 31 09:44:49 2011 for HepMCAnalysis by  doxygen 1.4.7