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

Generated on Mon Jan 4 15:22:34 2010 for HepMCAnalysis by  doxygen 1.4.7