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
00016 #include "TH1.h"
00017 #include <TH2.h>
00018 #include "TFile.h"
00019 #include "TMath.h"
00020 #include "TLorentzVector.h"
00021
00022
00023 #include "../include/baseAnalysis.h"
00024
00025
00026
00027
00028
00029
00030 baseAnalysis::baseAnalysis()
00031 {
00032 m_Jetfinder_enabled=false;
00033 }
00034
00035
00036
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
00054
00055 int baseAnalysis::InitJetFinder(double coneRadius, double overlapThreshold, double jet_ptmin)
00056 {
00057
00058 if(m_Jetfinder_enabled){
00059
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
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
00088
00089 int baseAnalysis::FindJetableParticles(HepMC::GenEvent* hepmcevt)
00090 {
00091
00092
00093
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
00104 int pid = (*p)->pdg_id();
00105
00106
00107
00108 if (!((*p)->status() == 1)) continue;
00109
00110
00111
00112 if(IsNeutrino(pid) || IsGamma(pid) || IsNeutron(pid)) continue;
00113
00114
00115
00116
00117
00118 if (!(*p)->production_vertex()) continue;
00119
00120 if ((*p)->end_vertex()) continue;
00121
00122
00123 if( trackfromPID(23,(*p)) ) continue;
00124
00125
00126 if( trackfromPID(24,(*p)) ) continue;
00127 if( trackfromPID(-24,(*p)) ) continue;
00128
00129
00130 double eta = (*p)->momentum().eta();
00131 if(abs(eta) > m_max_eta ) continue;
00132
00133
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
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
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
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
00179 m_inclusive_jets= sorted_by_pt(m_clust_seq->inclusive_jets(m_jet_ptmin));
00180
00181 return SUCCESS;
00182 }
00183
00184
00185
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
00198
00199
00200 int baseAnalysis::Finalize()
00201 {
00202
00203 TFile f(m_outputFileName.c_str(),"RECREATE");
00204 Finalize(&f);
00205 f.Close();
00206
00207 return SUCCESS;
00208 }
00209
00210
00211
00212
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
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
00235
00236
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
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
00261
00262
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
00271 if(maxGenerations<0) maxLoops=1000;
00272
00273
00274
00275 HepMC::GenVertex* current_vertex=daughter->production_vertex();
00276 HepMC::GenVertex::particle_iterator current_mother;
00277
00278
00279
00280
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
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
00304 if(maxGenerations<0) maxLoops=1000;
00305
00306
00307
00308 HepMC::GenVertex* current_vertex=track->production_vertex();
00309 HepMC::GenVertex::particle_iterator current_mother;
00310
00311
00312
00313
00314 while((current_vertex) && !(found) && (loop<maxLoops))
00315 {
00316 current_mother = current_vertex->particles_begin(HepMC::parents);
00317
00318
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 }