baseAnalysis.cc

Go to the documentation of this file.
00001 // STL
00002 #include <iostream>
00003 #include <sstream>
00004 #include <cmath>
00005 #include <stdio.h>
00006 
00007 #include "HepMC/GenEvent.h"
00008 #include "HepMC/IO_GenEvent.h"
00009 #include "HepMC/GenParticle.h"
00010 #include "HepMC/GenVertex.h"
00011 #include "HepMC/IO_AsciiParticles.h"
00012 #include "HepMC/SimpleVector.h"
00013 #include "HepPDT/ParticleData.hh"
00014 #include "CLHEP/Vector/LorentzVector.h"
00015 #include "fastjet/ClusterSequence.hh"
00016 #include "fastjet/SISConePlugin.hh"
00017 
00018 // ROOT 
00019 #include "TH1.h"
00020 #include "TH2.h"
00021 #include "TFile.h"
00022 #include "TMath.h"
00023 #include "TLorentzVector.h"
00024 
00025 #include "../include/baseAnalysis.h"
00026 
00027 //#define NDEBUG
00028 #include <cassert>
00029 
00030 using namespace std;
00031 
00032 // ---------------------------------------------------------------------- 
00033 /** Default constructor. */
00034 // ---------------------------------------------------------------------- 
00035 baseAnalysis::baseAnalysis()
00036 { 
00037   m_plugin = 0;
00038   m_jetDef = 0;
00039   m_clust_seq = 0;
00040 
00041   // jet finder params
00042   m_coneRadius          = 0.;
00043   m_overlapThreshold    = 0.;
00044   m_jet_ptmin           = 0.;
00045   m_lepton_ptmin        = 0.;
00046   m_DeltaR_lepton_track = 0.;
00047   m_Jetfinder_enabled   = false;
00048   
00049   // specify the maximum eta of tracks
00050   m_max_eta = 0.;
00051   m_min_pt  = 0.;
00052 
00053   // for calculation of the missing energy
00054   exMissTruth     = 0.;
00055   eyMissTruth     = 0.;
00056   etMissTruth     = 0.;
00057   etsumMissTruth  = 0.; 
00058   
00059   m_NanNum = 0;
00060 }
00061 
00062 // ---------------------------------------------------------------------- 
00063 /** Virtual destructor. */
00064 // ---------------------------------------------------------------------- 
00065 baseAnalysis::~baseAnalysis()
00066 {
00067   cout << "baseAnalysis: Total number of particles with NaN (Not a Number) params: " << m_NanNum << endl;
00068   
00069   // clean-up memory assigned to pointers
00070  /* if (m_plugin) {
00071     delete m_plugin;
00072     m_plugin = 0;
00073   }
00074   
00075   if (m_jetDef) {
00076     delete m_jetDef;
00077     m_jetDef = 0;
00078   }
00079   
00080   if ( m_clust_seq ) {
00081     m_clust_seq = 0;
00082     delete m_clust_seq;
00083   }*/
00084   
00085 /*  for (std::vector<TH1D*>::const_iterator i(m_histVector.begin()); i != m_histVector.end(); ++i) {
00086     delete (*i);
00087   }
00088   m_histVector.resize(0);*/
00089 
00090   //probably not needed anymore, due to averagedHistograms function
00091 /*  for (std::vector<TH1D*>::const_iterator i(m_histVectorVariableBin.begin()); i != m_histVectorVariableBin.end(); ++i) {
00092     delete (*i);
00093   }
00094   m_histVectorVariableBin.resize(0);*/
00095 
00096 //   while (!m_histVectorVariableBin.empty()){
00097 //     delete m_histVectorVariableBin.back();
00098 //     m_histVectorVariableBin.pop_back();
00099 //   }
00100 }
00101 
00102 // ---------------------------------------------------------------------- 
00103 int baseAnalysis::Init( double /*maxEta*/, double /*minPt*/ ) 
00104 {
00105   // this method is normally implemented in a derived class
00106   cout << "baseAnalysis: WARNING: You have called the dummy function Init()." << endl; 
00107   return 0;
00108 }
00109 
00110 // ---------------------------------------------------------------------- 
00111 int baseAnalysis::Process( HepMC::GenEvent* /*hepMcEvt*/ ) 
00112 { 
00113   // this method is normally implemented in a derived class(es)
00114   cout << "baseAnalysis: WARNING: You have called the dummy function Process()." << endl; 
00115   return 0;
00116 } 
00117 
00118 // ---------------------------------------------------------------------- 
00119 vector< TH1D* > baseAnalysis::averagedHistograms() 
00120 {
00121   return m_histVector;
00122 }
00123 
00124 // ---------------------------------------------------------------------- 
00125 vector<TH1D*>& baseAnalysis::Histograms()
00126 {
00127   return m_histVector;
00128 }
00129 
00130 // ---------------------------------------------------------------------- 
00131 /** InitJetFinder: Initialisation of JetFinder. */
00132 // ---------------------------------------------------------------------- 
00133 int baseAnalysis::InitJetFinder( double coneRadius, double overlapThreshold, double jet_ptmin, 
00134     double lepton_ptmin, double DeltaR_lepton_track, int jetalgorithm)
00135 {
00136   // jetalgorithm, =1 for siscone, =2 for antikt
00137 
00138     if(m_Jetfinder_enabled){
00139         // If the Pointer already exist, delete them
00140         if(m_jetDef) {
00141             delete m_jetDef;
00142             m_jetDef=0;
00143         }
00144         
00145         if(m_plugin){
00146             delete m_plugin;
00147             m_plugin=0;
00148         }
00149     }
00150     
00151  // initialise fastjet
00152   m_coneRadius = coneRadius;
00153   m_overlapThreshold = overlapThreshold;
00154   m_jet_ptmin = jet_ptmin;
00155   m_lepton_ptmin = lepton_ptmin;
00156   m_DeltaR_lepton_track = DeltaR_lepton_track;
00157   
00158   if( jetalgorithm == 1 ) {
00159       m_plugin = new fastjet::SISConePlugin(m_coneRadius, m_overlapThreshold);
00160       m_jetDef = new fastjet::JetDefinition(m_plugin);
00161   } else if ( jetalgorithm == 2 ) {
00162     m_plugin = 0;
00163     m_jetDef = new fastjet::JetDefinition( fastjet::antikt_algorithm, m_coneRadius );
00164     
00165     cout << "baseAnalysis: jet definition: " << endl;
00166     cout << m_jetDef->description() << endl;
00167   
00168   } else {
00169     m_jetDef = 0;
00170   }
00171 
00172   //   m_plugin = fastjet::antikt_algorithm(m_coneRadius);}
00173 
00174 
00175   if(!m_jetDef) return false;
00176 
00177   m_Jetfinder_enabled=true;
00178   return true;
00179 
00180 }
00181 
00182 // ---------------------------------------------------------------------- 
00183 /** Find Jetable Particles.*/
00184 // ---------------------------------------------------------------------- 
00185 int baseAnalysis::FindJetableParticles( HepMC::GenEvent* hepmcevt )
00186 {
00187   //delete m_clust_seq;
00188   //m_clust_seq=0;
00189   if( !m_Jetfinder_enabled || !m_jetDef ) {
00190     cerr << "baseAnalysis: FastJet Algorithm not initialized!" << endl;
00191     return false;
00192   }
00193 
00194   CLHEP::HepLorentzVector lv_leadingJet(0,0,0,0);
00195   
00196   for ( HepMC::GenEvent::particle_const_iterator p = hepmcevt->particles_begin(); 
00197       p != hepmcevt->particles_end(); ++p ){
00198 
00199      
00200       // use the pdg id to identify the particles
00201     int pid = (*p)->pdg_id();
00202     
00203       // first of all we need stable particle
00204     if ( !( ( (*p)->status() % 1000 ) == 1 ) ) continue;
00205     if ( (*p)->end_vertex() ) continue;
00206     
00207       // cut out the neutral particles (charge is not stored in HepMC)
00208       // just remove the neutrinos and Neutron from the final state
00209     if( IsNeutrino( pid ) || 
00210         IsNeutron( pid ) ) continue;
00211 
00212       // cut out all isolated leptons
00213       // variables for DeltaR calculation
00214     double deltaPhi = 0.0;
00215     double deltaEta = 0.0;
00216     double DeltaR = 9999.0;
00217 
00218     // cut variables
00219     double DeltaRCut = m_DeltaR_lepton_track;
00220     double LeptonpTCut = m_lepton_ptmin;
00221 
00222     if(IsElectron(pid) || IsMuon(pid)) {
00223       int lepton_barcode = (*p)->barcode();
00224       HepMC::GenParticle *lepton = hepmcevt->barcode_to_particle(lepton_barcode);
00225       
00226       // set pt cut for lepton
00227       if(fabs((*lepton).momentum().perp()) > LeptonpTCut) continue;
00228       
00229       // check if it is an isolated lepton
00230       for ( HepMC::GenEvent::particle_const_iterator q = hepmcevt->particles_begin(); 
00231             q != hepmcevt->particles_end(); ++q ){
00232         if(lepton_barcode==(*q)->barcode()) continue;
00233 
00234         // set DeltaR cut
00235         deltaPhi = (*p)->momentum().phi()-(*q)->momentum().phi();
00236 
00237         if( deltaPhi > TMath::Pi() ||  deltaPhi == TMath::Pi() )
00238           {
00239             deltaPhi = deltaPhi - 2 * TMath::Pi() ;
00240           }
00241         
00242         if( deltaPhi < - TMath::Pi() ||  deltaPhi == - TMath::Pi() )
00243           {
00244             deltaPhi = deltaPhi + 2 * TMath::Pi();
00245           }
00246 
00247         deltaEta = (*p)->momentum().eta()-(*q)->momentum().eta();
00248         double DeltaRnew = sqrt( pow(deltaPhi,2) + pow(deltaEta,2));
00249 
00250         if(DeltaRnew < DeltaR) DeltaR = DeltaRnew;
00251       }
00252       if(DeltaR > DeltaRCut) continue;
00253     }
00254 
00255     // or ... remove all charged particles 
00256     //if(chargedParticle(pid)==NOTCHARGED) continue;
00257     
00258     // They need to have a production Vertex --> we will not select incoming Protons from the Beam
00259     if (!(*p)->production_vertex()) continue;
00260     // And since they are stable they should not have a decay vertex.
00261     if ((*p)->end_vertex()) continue;
00262     
00263 //     // check wether the track directly comes from a Z-Boson
00264 //     if( trackfromPID(23,(*p)) ) continue;
00265     
00266 //     // check wether the track directly comes from a W-Boson
00267 //     if( trackfromPID(24,(*p)) ) continue;
00268 //     if( trackfromPID(-24,(*p)) ) continue;
00269     
00270     //set the eta cut for charged particles 
00271     double eta = (*p)->momentum().eta(); 
00272     if(std::abs(eta) > m_max_eta )  continue;
00273     
00274     //set the pt cut for charged particles 
00275     double pt = (*p)->momentum().perp(); 
00276     if(pt < m_min_pt) continue;
00277 
00278     double px = (*p)->momentum().x();
00279     double py = (*p)->momentum().y();
00280     double pz = (*p)->momentum().z();
00281     double pe = (*p)->momentum().e();
00282     
00283       // remove garbage 
00284     if ( isnan( px ) || isnan( py ) || isnan( pz ) || isnan( pe ) || 
00285          isinf( px ) || isinf( py ) || isinf( pz ) || isinf( pe ) ) {
00286       cout << "baseAnalysis: NaN (Not A Number) found in the event record! Particle will be skipped." << endl;
00287       ++m_NanNum;
00288       continue;
00289     }
00290          
00291     // jet finding in stable particles record for charged particles
00292     fastjet::PseudoJet tempVec;
00293     tempVec = fastjet::PseudoJet(px,py,pz,pe);
00294     m_input_particles.push_back(tempVec);
00295   }
00296   return true;
00297 }
00298 
00299 /** Run JetFinder. */
00300 int baseAnalysis::FindJet(HepMC::GenEvent* hepmcevt) 
00301 {
00302   if (!m_Jetfinder_enabled || !m_jetDef) {
00303     cerr << "baseAnalysis: FastJet Algorithm not initialized!" << endl;
00304     return false;
00305   }
00306   
00307   // run the jet finding
00308   if (m_input_particles.empty()) {
00309     if ( !FindJetableParticles(hepmcevt) ) {
00310       return false;
00311     }
00312   }
00313   
00314   if ( !m_input_particles.empty() ) { 
00315     m_clust_seq = new fastjet::ClusterSequence( m_input_particles, *m_jetDef );
00316   } else {
00317     m_clust_seq = 0;
00318   }
00319   
00320   if (m_input_particles.empty() || m_clust_seq==0) { 
00321     return false;
00322   }
00323   
00324   // select jets above a threshold, e.g. 0.5 GeV                                                                              
00325   m_inclusive_jets = sorted_by_pt( m_clust_seq->inclusive_jets( m_jet_ptmin ) );
00326   
00327   return true;
00328 }
00329 
00330 // ---------------------------------------------------------------------- 
00331 vector< fastjet::PseudoJet > baseAnalysis::GetJet( HepMC::GenEvent *hepMcEvt ) 
00332 {
00333   if( m_inclusive_jets.empty() ) {
00334     FindJet( hepMcEvt );
00335   }
00336   
00337   return m_inclusive_jets;
00338 }
00339   
00340 // ---------------------------------------------------------------------- 
00341 void baseAnalysis::SetJet( vector< fastjet::PseudoJet > *inclusive_jets )
00342 {
00343   m_inclusive_jets = *inclusive_jets;
00344 }
00345 
00346 // ---------------------------------------------------------------------- 
00347 /** DeleteJetObject: delete all the jet objects. */
00348 // ---------------------------------------------------------------------- 
00349 int baseAnalysis::DeleteJetObject( HepMC::GenEvent* /*hepmcevt*/ ) 
00350 {
00351   m_input_particles.clear();
00352   m_inclusive_jets.clear();
00353   
00354   delete m_clust_seq;
00355   m_clust_seq = 0;
00356 
00357   return true;
00358 }
00359 
00360 // ---------------------------------------------------------------------- 
00361 /** FindMissingEt: calculate the missing transversal energy of each event. */
00362 // ---------------------------------------------------------------------- 
00363 int baseAnalysis::FindMissingEt(HepMC::GenEvent* hepmcevt) 
00364 {
00365   int properStatus = 1; //stable particles
00366   
00367   exMissTruth     = 0.0;
00368   eyMissTruth     = 0.0;
00369   etMissTruth     = 0.0;
00370   etsumMissTruth  = 0.0;
00371   
00372   // loop over the particles in GenEvent and select pdgid and pt
00373   for ( HepMC::GenEvent::particle_const_iterator p =  hepmcevt->particles_begin(); p != hepmcevt->particles_end(); ++p ) {
00374     int pid = (*p)->pdg_id();
00375 
00376     // skip all not stable particles
00377     if ( (*p)->status()%1000 != properStatus ) continue;
00378     if ( (*p)->end_vertex() ) continue;
00379 
00380     // fiducial range eta cut on 2.5
00381     if(fabs((*p)->momentum().eta()) > 2.5) continue;
00382     // minimum pt for tracks on 0.5 GeV
00383     if((*p)->momentum().perp() < 0.5) continue;
00384 
00385     double px  = (*p)->momentum().px();
00386     double py  = (*p)->momentum().py();
00387     double pt  = (*p)->momentum().perp();
00388 
00389     if ( IsNeutrino(pid) || abs(pid)==1000039 || abs(pid) ==1000022 || abs(pid) ==39 || abs(pid) ==5100022 ) {
00390       exMissTruth     += px;    
00391       eyMissTruth     += py;
00392       etsumMissTruth  += pt;
00393     }
00394   }
00395   
00396   etMissTruth = sqrt(exMissTruth*exMissTruth + eyMissTruth*eyMissTruth); 
00397   
00398   return true;
00399 }
00400 
00401 // ---------------------------------------------------------------------- 
00402 /** ClearMissingEt: setting the variables to calculate missing energy to zero. */
00403 // ---------------------------------------------------------------------- 
00404 int baseAnalysis::ClearMissingEt( HepMC::GenEvent* /*hepmcevt*/ ) 
00405 {
00406   exMissTruth     = 0.0;
00407   eyMissTruth     = 0.0;
00408   etMissTruth     = 0.0;
00409   etsumMissTruth  = 0.0;
00410 
00411   return true;
00412 }
00413 
00414 // ---------------------------------------------------------------------- 
00415 /** Check if final state particle: returns 0 if it is not a final state particle, 1 otherwise. */
00416 // ---------------------------------------------------------------------- 
00417 int baseAnalysis::IsFinalStateParticle(HepMC::GenParticle *p) 
00418 {
00419   // first of all we need stable particle
00420   if ( !( (*p).status()%1000 == 1 ) ) return false;
00421 
00422   // And since they are stable they should not have a decay vertex. 
00423   if ( (*p).end_vertex() ) return false;
00424     
00425   // fiducial range eta cut on 2.5
00426   if( fabs((*p).momentum().eta()) > 2.5 ) return false;
00427   
00428   // minimum pt for tracks on 0.5
00429   if( (*p).momentum().perp() < 0.5 ) return false;
00430 
00431   return true;
00432 }
00433 
00434 // ---------------------------------------------------------------------- 
00435 /** ClearEvent: delete and clear some variables from the event. */
00436 // ---------------------------------------------------------------------- 
00437 int baseAnalysis::ClearEvent( HepMC::GenEvent* hepMcEvt ) 
00438 {
00439   baseAnalysis::DeleteJetObject( hepMcEvt );
00440   baseAnalysis::ClearMissingEt( hepMcEvt );
00441 
00442   return true;
00443 }
00444 
00445 // ---------------------------------------------------------------------- 
00446 int baseAnalysis::setOutputFileName( const string &fileName )
00447 { 
00448   m_outputFileName = fileName; 
00449   return 0;
00450 }
00451   
00452 // ---------------------------------------------------------------------- 
00453 int baseAnalysis::setOutputRootDir( const string &dirName )
00454 { 
00455   m_outputRootDir = dirName; 
00456   return 0;
00457 }
00458 
00459 // ---------------------------------------------------------------------- 
00460 bool baseAnalysis::IsNeutrino( int pid ) 
00461 { 
00462   if( abs( pid ) == 12 || abs( pid ) == 14 || abs( pid ) == 16 ) {
00463     return true; 
00464   } 
00465   return false; 
00466 }
00467 
00468 // ---------------------------------------------------------------------- 
00469 bool baseAnalysis::IsGamma(int pid) 
00470 { 
00471   if( abs( pid ) == 22 ) {
00472     return true; 
00473   }
00474   return false;
00475 }
00476 
00477 // ---------------------------------------------------------------------- 
00478 bool baseAnalysis::IsNeutron(int pid) 
00479 { 
00480   if( abs(pid)==2112 ) return true; 
00481   else return false; 
00482 }
00483 
00484 // ---------------------------------------------------------------------- 
00485 bool baseAnalysis::IsK0(int pid) 
00486 { 
00487   if( abs(pid)==130 || abs(pid)==310 || abs(pid)==311 ) return true; 
00488   else return false; 
00489 }
00490 
00491 // ---------------------------------------------------------------------- 
00492 bool baseAnalysis::IsPi0(int pid) 
00493 { 
00494   if( abs(pid)==111 || abs(pid)==113 || abs(pid)==221 ) return true; 
00495   else return false; 
00496 }
00497 
00498 // ---------------------------------------------------------------------- 
00499 bool baseAnalysis::IsElectron(int pid) 
00500 { 
00501   if( abs(pid)==11 ) return true; 
00502   else return false; 
00503 }
00504 
00505 // ---------------------------------------------------------------------- 
00506 bool baseAnalysis::IsMuon(int pid) 
00507 { 
00508   if( abs(pid)==13 ) return true; 
00509   else return false; 
00510 }
00511 
00512 // ---------------------------------------------------------------------- 
00513 bool baseAnalysis::IsGluon(int pid) 
00514 { 
00515   if( abs(pid)==21 ) return true; 
00516   else return false; 
00517 }
00518 
00519 // ---------------------------------------------------------------------- 
00520 bool baseAnalysis::chargedParticle(int pid) 
00521 { 
00522   if( IsNeutrino(pid) || IsGamma(pid) || IsNeutron(pid) || IsK0(pid) || IsPi0(pid) || IsGluon(pid) || 
00523     abs(pid)== 94 || abs(pid)==1000039 || abs(pid) ==1000022 || abs(pid) ==39 || abs(pid) ==5100022 ) {
00524       //above neutral particles and some "special" neutral particles
00525     return false;
00526   }  
00527   
00528   return true;
00529 }
00530   
00531 // ---------------------------------------------------------------------- 
00532 int baseAnalysis::setMaxEtaCut(double maxeta)
00533 { 
00534   m_max_eta = maxeta; 
00535   return 0;
00536 }
00537 
00538 // ---------------------------------------------------------------------- 
00539 int baseAnalysis::setMinPtCut(double minpt)
00540 { 
00541   m_min_pt = minpt; 
00542   return 0;
00543 }
00544 
00545 // ---------------------------------------------------------------------- 
00546 /** Finalize: In the final step all the histogramms are stored in a rootfile.
00547 The name of the rootfile can be set with the function setOutputFileName(const string& fileName). */
00548 // ---------------------------------------------------------------------- 
00549 int baseAnalysis::Finalize() 
00550 {
00551   //write the output in a root file
00552 //  TFile f(m_outputFileName.c_str(), "RECREATE");
00553 //  Finalize(&f);
00554 //  f.Close();
00555   
00556   return true;
00557 }
00558 
00559 // ---------------------------------------------------------------------- 
00560 /** In the final step all the histogramms are stored in a rootfile.
00561 The name of the rootfile can be set with the function setOutputFileName(const string &fileName). */
00562 // ---------------------------------------------------------------------- 
00563 int baseAnalysis::Finalize(TFile* output) 
00564 {
00565   TDirectory* dir = output->GetDirectory(m_outputRootDir.c_str());
00566   if (dir) {
00567     dir->cd();
00568   } else {
00569     cout << "The directory " << m_outputRootDir << " will be created" << endl;
00570     dir = output->mkdir(m_outputRootDir.c_str());
00571     dir->cd();
00572   }
00573 
00574   // loop over the standard vector
00575   for ( vector< TH1D * >::const_iterator iter = m_histVector.begin(); iter!=m_histVector.end(); iter++ ) 
00576     (*iter)->Write(); 
00577   
00578   // probably not needed anymore, due to averagedHistograms function
00579   //   for ( vector< TH1D * >::const_iterator iter = m_histVectorVariableBin.begin(); iter!=m_histVectorVariableBin.end(); iter++ ) 
00580   //     (*iter)->Write(); 
00581   
00582   return true;
00583 }
00584 
00585 // ---------------------------------------------------------------------- 
00586 /** popHisto: return the last entry  of the histogram vector, needed 
00587 for ATHENA (ATLAS software) implementation. */
00588 // ---------------------------------------------------------------------- 
00589 TH1D* baseAnalysis::popHisto() 
00590 {
00591   // return NULL pointer if no histogram
00592   if ( m_histVector.empty() ) return 0;
00593 
00594   // get last element from vector (don't change vector)
00595   TH1D* temp = m_histVector.back();
00596   
00597   // delete last entry from vector
00598   m_histVector.pop_back();
00599   return temp;
00600 }
00601 
00602 // ---------------------------------------------------------------------- 
00603 /** InitHist: To get a better handling of the several Histogramms. This class 
00604 initializes the histograms (name, title, binning, x-axis label) and collects them 
00605 in the std::vector m_histVector. By doing this looping over all the histograms 
00606 becomes much more convenient. */
00607 // ---------------------------------------------------------------------- 
00608 TH1D* baseAnalysis::initHist(const string &name, const string &title, const string &xlabel, 
00609     int nrBins, double xmin, double xmax)
00610 {
00611   TDirectory* dir = gDirectory->GetDirectory(("/"+m_outputRootDir).c_str());
00612   if (dir) {
00613     dir->cd();
00614   } else {
00615     gDirectory->cd("/");
00616     dir = gDirectory->mkdir(m_outputRootDir.c_str());
00617     dir->cd();
00618   }
00619 
00620     // convert integer into string
00621 //  int histCnt = m_histCounter[ m_outputRootDir ];
00622   int histCnt = 0; ///m_histCounter[ m_outputRootDir ];
00623   //cout << "hist counter': " << m_histCounter[ m_outputRootDir ] << endl;
00624   ostringstream ssHistCnt;
00625   ssHistCnt << histCnt; 
00626 
00627   TH1D* histo = new TH1D((m_outputRootDir + "_" + ssHistCnt.str() + "_" + name).c_str(), title.c_str(), 
00628     nrBins, xmin, xmax);
00629   //TH1D* histo=new TH1D((m_outputRootDir+"_"+intToString(m_histCounter[m_outputRootDir]) + "_" + name).c_str(),
00630   //title.c_str(),nrBins,xmin,xmax);
00631 
00632   histo->GetXaxis()->SetTitle(xlabel.c_str());
00633   histo->GetYaxis()->SetTitle("Count");
00634   m_histVector.push_back(histo);
00635 
00636  // ++m_histCounter[m_outputRootDir];
00637 
00638   return histo;
00639 }
00640 
00641 // ---------------------------------------------------------------------- 
00642 /** InitHistVariableBin: histograms with variable bin size. */
00643 // ---------------------------------------------------------------------- 
00644 TH1D* baseAnalysis::initHistVariableBin(const string &name, const string &title, const string &xlabel, 
00645     int nbin, Double_t nbinRange[])
00646 {
00647   TDirectory* dir = gDirectory->GetDirectory( ("/"+m_outputRootDir).c_str() );
00648   if (dir) {
00649     dir->cd();
00650   } else {
00651     gDirectory->cd("/");
00652     dir = gDirectory->mkdir(m_outputRootDir.c_str());
00653     dir->cd();
00654   }
00655 
00656   TH1D* histoVariableBin = new TH1D(name.c_str(), title.c_str(), nbin, nbinRange);
00657   histoVariableBin->GetXaxis()->SetTitle(xlabel.c_str());
00658   histoVariableBin->GetYaxis()->SetTitle("Count");
00659   m_histVector.push_back(histoVariableBin);
00660 
00661   return histoVariableBin;
00662 }
00663 
00664 // ---------------------------------------------------------------------- 
00665 /** CheckDaughter: This function returns true if the particle daughter is the decay 
00666 product of the particle mother. The function scans the mother particle up to a certain level,
00667 which can be specified with maxGenerations (negativ number --> all levels). */
00668 // ---------------------------------------------------------------------- 
00669 bool baseAnalysis::checkDaughter(HepMC::GenParticle* mother, HepMC::GenParticle* daughter, int maxGenerations)
00670 {
00671   // initialize the maximal number of mothers (Levels) to be checked
00672   const size_t maxLoops = ((maxGenerations < 0) ? 1000 : maxGenerations);
00673   
00674   // initialize current Production Vertex and mother particles
00675   // There should always be only one mother particle for decaying particles
00676   HepMC::GenVertex* current_vertex = daughter->production_vertex();
00677   HepMC::GenVertex::particle_iterator current_mother;
00678   
00679   bool found = false;
00680   size_t loopCnt = 1;
00681 
00682   // iterate through the mother particles and compare with mother
00683   // If found match, than stop the loop, otherwise try until there is no production vertex
00684   // or until you have reached the max number of loops specified
00685   while ((current_vertex) && !(found) && (loopCnt < maxLoops)) {
00686     current_mother = current_vertex->particles_begin(HepMC::parents);
00687       
00688     if ((*current_mother) == mother) {
00689         found = true;
00690     } else {
00691         current_vertex = (*current_mother)->production_vertex();
00692     }
00693     // check next level  
00694     ++loopCnt;
00695   }
00696   return found;
00697 }
00698 
00699 // ---------------------------------------------------------------------- 
00700 /** TrackFromPID: check if the track comes from a specific particle e.g. pid(W-Boson)=23. */
00701 // ---------------------------------------------------------------------- 
00702 bool baseAnalysis::trackfromPID(int pid, HepMC::GenParticle* track, int maxGenerations) 
00703 {
00704   // initialize the maximal number of mothers (Levels) to be checked
00705   const size_t maxLoops = ((maxGenerations < 0) ? 1000 : maxGenerations);
00706    
00707   // initialize current Production Vertex and mother particles
00708   // There should always be only one mother particle for decaying particles
00709   HepMC::GenVertex* current_vertex=track->production_vertex();
00710   HepMC::GenVertex::particle_iterator current_mother;
00711   
00712   bool found = false;
00713   size_t loopCnt = 1;
00714 
00715   // iterate through the mother particles and compare with mother
00716   // If found match, than stop the loop, otherwise try until there is no production vertex
00717   // or until you have reached the max number of loops specified
00718   while ((current_vertex) && !(found) && (loopCnt < maxLoops)) {
00719     current_mother = current_vertex->particles_begin(HepMC::parents);
00720       
00721     //if no mother anymore, jump out the loop
00722     if (*current_mother == 0) break;     
00723 
00724     if ((*current_mother)->pdg_id() == pid) {
00725             found = true;
00726     } else {
00727         current_vertex = (*current_mother)->production_vertex();
00728     }
00729     // check next level  
00730     ++loopCnt;
00731   }
00732 
00733   return found;
00734 }
00735 
00736 // ---------------------------------------------------------------------- 
00737 /** GetRapidity: calculate rapidity of a given particle */
00738 // ---------------------------------------------------------------------- 
00739 double baseAnalysis::getRapidity( const HepMC::GenEvent::particle_const_iterator &p ) 
00740 {
00741   double e  = (*p)->momentum().e();
00742   double pz = (*p)->momentum().pz();
00743   double rapidity = 0.5 * log((e + pz) / (e - pz));
00744   return rapidity;
00745 }
00746 

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