#include <memory>
#include <string>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <iostream>
#include "FWCore/FWLite/interface/AutoLibraryLoader.h"
#include "AnalysisDataFormats/TopObjects/interface/TtSemiLeptonicEvent.h"
#include "TopQuarkAnalysis/Examples/bin/NiceStyle.cc"
#include "TopQuarkAnalysis/Examples/interface/RootSystem.h"
#include "TopQuarkAnalysis/Examples/interface/RootHistograms.h"
#include "TopQuarkAnalysis/Examples/interface/RootPostScript.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Definition at line 17 of file TopHypothesisFWLiteAnalyzer.cc.
References TestMuL1L2Filter_cff::cerr, GenMuonPlsPt100GeV_cfg::cout, AutoLibraryLoader::enable(), lat::endl(), TtSemiLeptonicEvent::hadronicTop(), TtSemiLeptonicEvent::hadronicW(), TtEvent::isHypoAvailable(), TtEvent::isHypoValid(), TtEvent::kGenMatch, TtEvent::kGeom, TtEvent::kKinFit, TtEvent::kMaxSumPtWMass, TtEvent::kMVADisc, TtEvent::kWMassMaxSumPt, TtSemiLeptonicEvent::leptonicTop(), TtSemiLeptonicEvent::leptonicW(), reco::Particle::mass(), reco::Particle::pt(), and setNiceStyle().
00018 { 00019 if( argc<4 ){ 00020 // ------------------------------------------------- 00021 std::cerr << "ERROR:: " 00022 << "Wrong number of arguments!" << std::endl 00023 << " Please specify:" << std::endl 00024 << " * filepath" << std::endl 00025 << " * process name" << std::endl 00026 << " * HypoClassKey" << std::endl; 00027 // ------------------------------------------------- 00028 return -1; 00029 } 00030 00031 // parse HypoClassKey 00032 TtSemiLeptonicEvent::HypoClassKey hypoClassKey; 00033 if(!strcmp(argv[3], "kWMassMaxSumPt")) hypoClassKey = TtSemiLeptonicEvent::kWMassMaxSumPt; else if 00034 (!strcmp(argv[3], "kMaxSumPtWMass")) hypoClassKey = TtSemiLeptonicEvent::kMaxSumPtWMass; else if 00035 (!strcmp(argv[3], "kGeom" )) hypoClassKey = TtSemiLeptonicEvent::kGeom; else if 00036 (!strcmp(argv[3], "kKinFit" )) hypoClassKey = TtSemiLeptonicEvent::kKinFit; else if 00037 (!strcmp(argv[3], "kGenMatch" )) hypoClassKey = TtSemiLeptonicEvent::kGenMatch; else if 00038 (!strcmp(argv[3], "kMVADisc" )) hypoClassKey = TtSemiLeptonicEvent::kMVADisc; 00039 else{ 00040 // ------------------------------------------------- 00041 std::cerr << "ERROR:: " 00042 << "Unknown HypoClassKey!" << std::endl 00043 << " Please specify one out of the following keys:" << std::endl 00044 << " * kWMassMaxSumPt" << std::endl 00045 << " * kMaxSumPtWMass" << std::endl 00046 << " * kGeom" << std::endl 00047 << " * kKinFit" << std::endl 00048 << " * kGenMatch" << std::endl 00049 << " * kMVADisc" << std::endl; 00050 // ------------------------------------------------- 00051 return -1; 00052 } 00053 00054 // load framework libraries 00055 gSystem->Load( "libFWCoreFWLite" ); 00056 AutoLibraryLoader::enable(); 00057 00058 // set nice style for histograms 00059 setNiceStyle(); 00060 00061 // define some histograms 00062 TH1F* hadWPt_ = new TH1F("hadWPt", "p_{t} (W_{had}) [GeV]", 100, 0., 500.); 00063 TH1F* hadWMass_ = new TH1F("hadWMass", "M (W_{had}) [GeV]", 50, 0., 150.); 00064 TH1F* hadTopPt_ = new TH1F("hadTopPt", "p_{t} (t_{had}) [GeV]", 100, 0., 500.); 00065 TH1F* hadTopMass_= new TH1F("hadTopMass", "M (t_{had}) [GeV]", 50, 50., 250.); 00066 00067 TH1F* lepWPt_ = new TH1F("lepWPt", "p_{t} (W_{lep}) [GeV]", 100, 0., 500.); 00068 TH1F* lepWMass_ = new TH1F("lepWMass", "M (W_{lep}) [GeV]", 50, 0., 150.); 00069 TH1F* lepTopPt_ = new TH1F("lepTopPt", "p_{t} (t_{lep}) [GeV]", 100, 0., 500.); 00070 TH1F* lepTopMass_= new TH1F("lepTopMass", "M (t_{lep}) [GeV]", 50, 50., 250.); 00071 00072 00073 // ------------------------------------------------- 00074 std::cout << "open file: " << argv[1] << std::endl; 00075 // ------------------------------------------------- 00076 TFile* inFile = TFile::Open(argv[1]); 00077 TTree* events_= 0; 00078 if( inFile ) inFile->GetObject("Events", events_); 00079 if( events_==0 ){ 00080 // ------------------------------------------------- 00081 std::cerr << "ERROR:: " 00082 << "Unable to retrieve TTree Events!" << std::endl 00083 << " Eighter wrong file name or the the tree doesn't exists" << std::endl; 00084 // ------------------------------------------------- 00085 return -1; 00086 } 00087 00088 // acess branch of ttSemiLepEvent 00089 char decayName[50]; 00090 sprintf(decayName, "recoGenParticles_decaySubset__%s.obj", argv[2]); 00091 TBranch* decay_ = events_->GetBranch( decayName ); // referred to from within TtGenEvent class 00092 assert( decay_ != 0 ); 00093 char genEvtName[50]; 00094 sprintf(genEvtName, "TtGenEvent_genEvt__%s.obj", argv[2]); 00095 TBranch* genEvt_ = events_->GetBranch( genEvtName ); // referred to from within TtSemiLeptonicEvent class 00096 assert( genEvt_ != 0 ); 00097 char semiLepEvtName[50]; 00098 sprintf(semiLepEvtName, "TtSemiLeptonicEvent_ttSemiLepEvent__%s.obj", argv[2]); 00099 TBranch* semiLepEvt_ = events_->GetBranch( semiLepEvtName ); 00100 assert( semiLepEvt_ != 0 ); 00101 00102 // loop over events and fill histograms 00103 int nevt = events_->GetEntries(); 00104 TtSemiLeptonicEvent semiLepEvt; 00105 // ------------------------------------------------- 00106 std::cout << "start looping " << nevt << " events..." << std::endl; 00107 // ------------------------------------------------- 00108 for(int evt=0; evt<nevt; ++evt){ 00109 // set branch address 00110 semiLepEvt_-> SetAddress( &semiLepEvt ); 00111 // get event 00112 decay_ ->GetEntry( evt ); 00113 genEvt_ ->GetEntry( evt ); 00114 semiLepEvt_->GetEntry( evt ); 00115 events_ ->GetEntry( evt, 0 ); 00116 00117 // ------------------------------------------------- 00118 if(evt>0 && !(evt%10)) std::cout << " processing event: " << evt << std::endl; 00119 // ------------------------------------------------- 00120 00121 // fill histograms 00122 if( !semiLepEvt.isHypoAvailable(hypoClassKey) ){ 00123 std::cerr << "NonValidHyp:: " << "Hypothesis not available for this event" << std::endl; 00124 continue; 00125 } 00126 if( !semiLepEvt.isHypoValid(hypoClassKey) ){ 00127 std::cerr << "NonValidHyp::" << "Hypothesis not valid for this event" << std::endl; 00128 continue; 00129 } 00130 00131 const reco::Candidate* hadTop = semiLepEvt.hadronicTop(hypoClassKey); 00132 const reco::Candidate* hadW = semiLepEvt.hadronicW (hypoClassKey); 00133 const reco::Candidate* lepTop = semiLepEvt.leptonicTop(hypoClassKey); 00134 const reco::Candidate* lepW = semiLepEvt.leptonicW (hypoClassKey); 00135 00136 if(hadTop && hadW && lepTop && lepW){ 00137 hadWPt_ ->Fill( hadW->pt() ); 00138 hadWMass_ ->Fill( hadW->mass() ); 00139 hadTopPt_ ->Fill( hadTop->pt() ); 00140 hadTopMass_->Fill( hadTop->mass()); 00141 00142 lepWPt_ ->Fill( lepW->pt() ); 00143 lepWMass_ ->Fill( lepW->mass() ); 00144 lepTopPt_ ->Fill( lepTop->pt() ); 00145 lepTopMass_->Fill( lepTop->mass()); 00146 } 00147 } 00148 // ------------------------------------------------- 00149 std::cout << "close file" << std::endl; 00150 // ------------------------------------------------- 00151 inFile->Close(); 00152 00153 // save histograms to file 00154 TFile outFile( "analyzeHypothesis.root", "recreate" ); 00155 switch( hypoClassKey ){ 00156 case TtSemiLeptonicEvent::kGeom : 00157 outFile.mkdir("analyzeGeom"); 00158 outFile.cd("analyzeGeom"); 00159 break; 00160 case TtSemiLeptonicEvent::kWMassMaxSumPt : 00161 outFile.mkdir("analyzeMaxSumPtWMass"); 00162 outFile.cd("analyzeMaxSumPtWMass"); 00163 break; 00164 case TtSemiLeptonicEvent::kMaxSumPtWMass : 00165 outFile.mkdir("analyzeMaxSumPtWMass"); 00166 outFile.cd("analyzeMaxSumPtWMass"); 00167 break; 00168 case TtSemiLeptonicEvent::kKinFit : 00169 outFile.mkdir("analyzeKinFit"); 00170 outFile.cd("analyzeKinFit"); 00171 break; 00172 case TtSemiLeptonicEvent::kGenMatch : 00173 outFile.mkdir("analyzeGenMatch"); 00174 outFile.cd("analyzeGenMatch"); 00175 break; 00176 case TtSemiLeptonicEvent::kMVADisc : 00177 outFile.mkdir("analyzeMVADisc"); 00178 outFile.cd("analyzeMVADisc"); 00179 break; 00180 } 00181 hadWPt_ ->Write( ); 00182 hadWMass_ ->Write( ); 00183 hadTopPt_ ->Write( ); 00184 hadTopMass_->Write( ); 00185 lepWPt_ ->Write( ); 00186 lepWMass_ ->Write( ); 00187 lepTopPt_ ->Write( ); 00188 lepTopMass_->Write( ); 00189 outFile.Close(); 00190 00191 // free allocated space 00192 delete hadWPt_; 00193 delete hadWMass_; 00194 delete hadTopPt_; 00195 delete hadTopMass_; 00196 delete lepWPt_; 00197 delete lepWMass_; 00198 delete lepTopPt_; 00199 delete lepTopMass_; 00200 00201 return 0; 00202 }