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

baseAnalysis.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 "HepPDT/ParticleData.hh"
00011 #include "CLHEP/Vector/LorentzVector.h"
00012 
00013 using namespace std;
00014 
00015 // ROOT headers
00016 #include "TH1.h"
00017 #include <TH2.h>
00018 #include "TFile.h"
00019 #include "TMath.h"
00020 #include "TLorentzVector.h"
00021 
00022 //top analysis header
00023 #include "../include/baseAnalysis.h"
00024 
00025 //**********************
00026 
00027 /**
00028 Constructor
00029 */
00030 baseAnalysis::baseAnalysis()
00031 { 
00032 m_Jetfinder_enabled=false;
00033 }
00034 
00035 /**
00036 Destructor: delete all the Pointer
00037 */
00038 baseAnalysis::~baseAnalysis()
00039 {
00040   while (!m_histVector.empty()){
00041     delete m_histVector.back();
00042     m_histVector.pop_back();
00043   }
00044 
00045   while (!m_histVectorVariableBin.empty()){
00046     delete m_histVectorVariableBin.back();
00047     m_histVectorVariableBin.pop_back();
00048   }
00049 
00050 }
00051 
00052 /**
00053 InitJetFinder: Initialisation of JetFinder
00054 */
00055 int baseAnalysis::InitJetFinder(double coneRadius, double overlapThreshold, double jet_ptmin)
00056 {
00057 
00058     if(m_Jetfinder_enabled){
00059         // If the Pointer already exist, delete them
00060         if(m_jetDef) {
00061             delete m_jetDef;
00062             m_jetDef=0;
00063         }
00064         
00065         if(m_plugin){
00066             delete m_plugin;
00067             m_plugin=0;
00068         }
00069     }
00070     
00071  // initialise fastjet
00072   m_coneRadius = coneRadius;
00073   m_overlapThreshold = overlapThreshold;
00074   m_jet_ptmin= jet_ptmin;
00075 
00076   m_plugin = new fastjet::SISConePlugin(m_coneRadius, m_overlapThreshold);
00077   m_jetDef = new fastjet::JetDefinition(m_plugin);
00078 
00079   if(!m_jetDef) return FAILURE;
00080 
00081   m_Jetfinder_enabled=true;
00082   return SUCCESS;
00083 
00084 }
00085 
00086 /**
00087 FindJetableParticles
00088 */
00089 int baseAnalysis::FindJetableParticles(HepMC::GenEvent* hepmcevt)
00090 {
00091 
00092   //delete m_clust_seq;
00093   //m_clust_seq=0;
00094   if(!m_Jetfinder_enabled || !m_jetDef){
00095     std::cout << "ERROR: FastJet Algorithm not initialized!" << std::endl;
00096     return FAILURE;
00097   }
00098 
00099   CLHEP::HepLorentzVector lv_leadingJet(0,0,0,0);
00100   for ( HepMC::GenEvent::particle_const_iterator p =
00101           hepmcevt->particles_begin(); p != hepmcevt->particles_end(); ++p ){
00102     
00103     // use the pdg id to identify the particles
00104     int pid = (*p)->pdg_id();
00105     
00106     // now collect the tracks for the Jet algorithm
00107     // first of all we need stable particle
00108     if (!((*p)->status() == 1)) continue;
00109     
00110     // cut out the neutral particles (charge is not stored in HepMC)
00111     // just remove the neutrinos, gammas and Neutron ... from the final state
00112     if(IsNeutrino(pid) || IsGamma(pid) || IsNeutron(pid)) continue;
00113     
00114     // or ... remove all charged particles 
00115     //if(chargedParticle(pid)==NOTCHARGED) continue;
00116     
00117     // They need to have a production Vertex --> we will not select incoming Protons from the Beam
00118     if (!(*p)->production_vertex()) continue;
00119     // And since they are stable they should not have a decay vertex.
00120     if ((*p)->end_vertex()) continue;
00121     
00122     // check wether the track directly comes from a Z-Boson
00123     if( trackfromPID(23,(*p)) ) continue;
00124     
00125     // check wether the track directly comes from a W-Boson
00126     if( trackfromPID(24,(*p)) ) continue;
00127     if( trackfromPID(-24,(*p)) ) continue;
00128     
00129     //set the eta cut for charged particles 
00130     double eta = (*p)->momentum().eta(); 
00131     if(abs(eta) > m_max_eta )  continue;
00132     
00133     //set the pt cut for charged particles 
00134     double pt = (*p)->momentum().perp(); 
00135     if(pt < m_min_pt) continue;
00136     
00137     double px = (*p)->momentum().x();
00138     double py = (*p)->momentum().y();
00139     double pz = (*p)->momentum().z();
00140     double pe = (*p)->momentum().e();
00141     
00142     
00143     // jet finding in stable particles record for charged particles
00144     fastjet::PseudoJet tempVec;
00145     tempVec = fastjet::PseudoJet(px,py,pz,pe);
00146     m_input_particles.push_back(tempVec);
00147   }
00148   return SUCCESS;
00149 }
00150 
00151 /**
00152 FindJet: run JetFinder
00153 */
00154 int baseAnalysis::FindJet(HepMC::GenEvent* hepmcevt) {
00155   
00156   if(!m_Jetfinder_enabled || !m_jetDef){
00157     std::cout << "ERROR: FastJet Algorithm not initialized!" << std::endl;
00158     return FAILURE;
00159   }
00160   
00161   m_input_particles.clear();
00162   m_inclusive_jets.clear();
00163   m_clust_seq=0;
00164   
00165   // run the jet finding
00166   if(!m_input_particles.size()) {
00167     int input = baseAnalysis::FindJetableParticles(hepmcevt); 
00168     if(!input) 
00169       return FAILURE;
00170   }
00171   
00172   if(m_input_particles.size())
00173     m_clust_seq = new fastjet::ClusterSequence(m_input_particles,*m_jetDef);
00174   
00175   if(!m_input_particles.size() || !m_clust_seq) 
00176     return FAILURE;
00177   
00178   // select jets above a threshold, e.g. 0.5 GeV                                                                              
00179   m_inclusive_jets= sorted_by_pt(m_clust_seq->inclusive_jets(m_jet_ptmin));
00180   
00181   return SUCCESS;
00182 }
00183 
00184 /**
00185 DeleteJetObject: delete all the jet objects
00186 */
00187 int baseAnalysis::DeleteJetObject(HepMC::GenEvent* hepmcevt) {
00188   m_input_particles.clear();
00189   m_inclusive_jets.clear();
00190   delete m_clust_seq;
00191   m_clust_seq=0;
00192 
00193   return SUCCESS;
00194 }
00195 
00196 /**
00197 In the final step all the histogramms are stored in a rootfile.
00198 The name of the rootfile can be set with the function setOutpuFileName(const char* filename). 
00199  */
00200 int baseAnalysis::Finalize() 
00201 {
00202   //write the output in a root file
00203   TFile f(m_outputFileName.c_str(),"RECREATE");
00204   Finalize(&f);
00205   f.Close();
00206   
00207   return SUCCESS;
00208 }
00209 
00210 /**
00211 In the final step all the histogramms are stored in a rootfile.
00212 The name of the rootfile can be set with the function setOutpuFileName(const char* filename). 
00213  */
00214 int baseAnalysis::Finalize(TFile* output) 
00215 {
00216   if (! output->cd(m_outputRootDir.c_str())) {
00217     std::cout << "The Directory " << m_outputRootDir.c_str() << " does not exist." << std::endl;
00218     std::cout << "The Directory will be created" << std::endl;
00219     TDirectory* dir = output->mkdir(m_outputRootDir.c_str());
00220     dir->cd();
00221   }
00222 
00223   // loop over the standard vector
00224   for ( vector< TH1D * >::const_iterator iter = m_histVector.begin(); iter!=m_histVector.end(); iter++ ) 
00225     (*iter)->Write(); 
00226   
00227   for ( vector< TH1D * >::const_iterator iter = m_histVectorVariableBin.begin(); iter!=m_histVectorVariableBin.end(); iter++ ) 
00228     (*iter)->Write(); 
00229   
00230   return SUCCESS;
00231 }
00232 
00233 /**
00234 To get a better handling of the several Histogramms. This class initializes the histograms (name, title, binning, x-axis label) 
00235 and collects them in the std::vector m_histVector. By doing this looping over all the 
00236 histograms becomes much more convenient.
00237 */
00238 TH1D * baseAnalysis::initHist(string name, string title, string xlabel, int nrBins, double xmin, double xmax)
00239 {
00240   TH1D * histo=new TH1D(name.c_str(),title.c_str(),nrBins,xmin,xmax);
00241   histo->GetXaxis()->SetTitle(xlabel.c_str());
00242   histo->GetYaxis()->SetTitle("Count");
00243   baseAnalysis::m_histVector.push_back(histo);
00244   return histo;
00245 }
00246 
00247 /**
00248 histograms with variable bin size
00249 */
00250 TH1D * baseAnalysis::initHistVariableBin(string name, string title, string xlabel, int nbin, Double_t nbinRange[])
00251 {
00252   TH1D * histoVariableBin=new TH1D(name.c_str(),title.c_str(),nbin,nbinRange);
00253   histoVariableBin->GetXaxis()->SetTitle(xlabel.c_str());
00254   histoVariableBin->GetYaxis()->SetTitle("Count");
00255   baseAnalysis::m_histVectorVariableBin.push_back(histoVariableBin);
00256   return histoVariableBin;
00257 }
00258 
00259 /**
00260 This function returns true if the particle daughter is the decay product of the particle mother. 
00261 The function scans the mother particle up to a certain level,
00262 which can be specified with maxGenerations (negativ number --> all levels).
00263 */
00264 bool baseAnalysis::checkDaughter(HepMC::GenParticle* mother, HepMC::GenParticle* daughter, int maxGenerations)
00265 {
00266   bool found=false;
00267   int maxLoops=maxGenerations;
00268   int loop=1;
00269   
00270   // initialize the maximal number of mothers (Levels) to be checked
00271   if(maxGenerations<0) maxLoops=1000;
00272   
00273   // initialize current Production Vertex and mother particles
00274   // There should always be only one mother particle for decaying particles
00275   HepMC::GenVertex* current_vertex=daughter->production_vertex();
00276   HepMC::GenVertex::particle_iterator current_mother;
00277   
00278   // iterate through the mother particles and compare with mother
00279   // If found match, than stop the loop, otherwise try until there is no production vertex
00280   // or until you have reached the max number of loops specified
00281   while((current_vertex) && !(found) && (loop<maxLoops))
00282     {
00283       current_mother = current_vertex->particles_begin(HepMC::parents);
00284       
00285       if((*current_mother)==mother) 
00286         found=true;
00287       else
00288         current_vertex=(*current_mother)->production_vertex();
00289       
00290       loop++;
00291     }
00292   return found;
00293 }
00294 
00295 
00296 /** check if the track comes from a specific particle e.g. pid(W-Boson)=23 */
00297 bool baseAnalysis::trackfromPID(int pid, HepMC::GenParticle* track, int maxGenerations) 
00298 {
00299   bool found=false;
00300   int maxLoops=maxGenerations;
00301   int loop=1;
00302   
00303   // initialize the maximal number of mothers (Levels) to be checked
00304   if(maxGenerations<0) maxLoops=1000;
00305   
00306   // initialize current Production Vertex and mother particles
00307   // There should always be only one mother particle for decaying particles
00308   HepMC::GenVertex* current_vertex=track->production_vertex();
00309   HepMC::GenVertex::particle_iterator current_mother;
00310   
00311   // iterate through the mother particles and compare with mother
00312   // If found match, than stop the loop, otherwise try until there is no production vertex
00313   // or until you have reached the max number of loops specified
00314   while((current_vertex) && !(found) && (loop<maxLoops))
00315     {
00316       current_mother = current_vertex->particles_begin(HepMC::parents);
00317       
00318      //if no mother anymore, jump out the loop
00319       if(*current_mother==0)break;     
00320 
00321       if((*current_mother)->pdg_id()==pid) 
00322         found=true;
00323       else
00324         current_vertex=(*current_mother)->production_vertex();
00325       
00326       loop++;
00327     }
00328   return found;
00329 }

Generated on Mon Feb 16 15:58:21 2009 for HepMCAnalysis by  doxygen 1.3.9.1