CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/TopQuarkAnalysis/Examples/plugins/HypothesisAnalyzer.cc

Go to the documentation of this file.
00001 #include "FWCore/Framework/interface/Event.h"
00002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00003 #include "FWCore/ServiceRegistry/interface/Service.h"
00004 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 
00007 #include "AnalysisDataFormats/TopObjects/interface/TtSemiLeptonicEvent.h"
00008 
00009 #include "TopQuarkAnalysis/Examples/plugins/HypothesisAnalyzer.h"
00010 
00011 HypothesisAnalyzer::HypothesisAnalyzer(const edm::ParameterSet& cfg):
00012   semiLepEvt_  (cfg.getParameter<edm::InputTag>("semiLepEvent")),
00013   hypoClassKey_(cfg.getParameter<std::string>("hypoClassKey"))
00014 {
00015 }
00016 
00017 void
00018 HypothesisAnalyzer::analyze(const edm::Event& event, const edm::EventSetup& setup)
00019 {
00021   // get a handle for the TtSemiLeptonicEvent and a key to the hypothesis
00023   
00024   edm::Handle<TtSemiLeptonicEvent> semiLepEvt;
00025   event.getByLabel(semiLepEvt_, semiLepEvt);
00026 
00028   // check if hypothesis is available and valid in this event
00030 
00031   if( !semiLepEvt->isHypoValid(hypoClassKey_) ){
00032     edm::LogInfo("HypothesisAnalyzer") << "Hypothesis " << hypoClassKey_ << " not valid for this event";
00033     return;
00034   }
00035 
00037   // get reconstructed top quarks, W bosons, the top pair and the neutrino from the hypothesis
00039 
00040   const reco::Candidate* topPair  = semiLepEvt->topPair(hypoClassKey_);
00041   const reco::Candidate* lepTop   = semiLepEvt->leptonicDecayTop(hypoClassKey_);
00042   const reco::Candidate* lepW     = semiLepEvt->leptonicDecayW(hypoClassKey_);
00043   const reco::Candidate* hadTop   = semiLepEvt->hadronicDecayTop(hypoClassKey_);
00044   const reco::Candidate* hadW     = semiLepEvt->hadronicDecayW(hypoClassKey_);
00045   const reco::Candidate* neutrino = semiLepEvt->singleNeutrino(hypoClassKey_);
00046 
00048   // fill simple histograms with kinematic variables of the reconstructed particles
00050 
00051   if(topPair)
00052     topPairMass_->Fill( topPair->mass() );
00053   if(hadW) {
00054     hadWPt_  ->Fill( hadW->pt()   );
00055     hadWEta_ ->Fill( hadW->eta()  );
00056     hadWMass_->Fill( hadW->mass() );
00057   }
00058   if(hadTop) {
00059     hadTopPt_  ->Fill( hadTop->pt()   );
00060     hadTopEta_ ->Fill( hadTop->eta()  );
00061     hadTopMass_->Fill( hadTop->mass() );
00062   }
00063   if(lepW) {
00064     lepWPt_  ->Fill( lepW->pt()   );
00065     lepWEta_ ->Fill( lepW->eta()  );
00066     lepWMass_->Fill( lepW->mass() );
00067   }
00068   if(lepTop) {
00069     lepTopPt_  ->Fill( lepTop->pt()   );
00070     lepTopEta_ ->Fill( lepTop->eta()  );
00071     lepTopMass_->Fill( lepTop->mass() );
00072   }
00073   if(neutrino)
00074     neutrinoEta_->Fill( neutrino->eta() );
00075 
00077   // get corresponding genParticles
00079 
00080   const math::XYZTLorentzVector* genTopPair = semiLepEvt->topPair();
00081   const reco::Candidate* genHadTop   = semiLepEvt->hadronicDecayTop();
00082   const reco::Candidate* genHadW     = semiLepEvt->hadronicDecayW();
00083   const reco::Candidate* genLepTop   = semiLepEvt->leptonicDecayTop();
00084   const reco::Candidate* genLepW     = semiLepEvt->leptonicDecayW();
00085   const reco::Candidate* genNeutrino = semiLepEvt->singleNeutrino();
00086 
00088   // fill pull histograms of kinematic variables with respect to the generated particles
00090 
00091   if(topPair && genTopPair)
00092     topPairPullMass_->Fill( (topPair->mass()-genTopPair->mass())/ genTopPair->mass() );
00093   if(hadW && genHadW) {
00094     hadWPullPt_  ->Fill( (hadW->pt() - genHadW->pt()) / genHadW->pt()   );
00095     hadWPullEta_ ->Fill( (hadW->eta() - genHadW->eta()) / genHadW->eta()  );
00096     hadWPullMass_->Fill( (hadW->mass() - genHadW->mass()) / genHadW->mass() );
00097   }
00098 
00099   if(hadTop && genHadTop) {
00100     hadTopPullPt_  ->Fill( (hadTop->pt() - genHadTop->pt()) / genHadTop->pt()   );
00101     hadTopPullEta_ ->Fill( (hadTop->eta() - genHadTop->eta()) / genHadTop->eta()  );
00102     hadTopPullMass_->Fill( (hadTop->mass() - genHadTop->mass()) / genHadTop->mass() );
00103   }
00104   if(lepW && genLepW) {
00105     lepWPullPt_  ->Fill( (lepW->pt() - genLepW->pt()) / genLepW->pt()   );
00106     lepWPullEta_ ->Fill( (lepW->eta() - genLepW->eta()) / genLepW->eta()  );
00107     lepWPullMass_->Fill( (lepW->mass() - genLepW->mass()) / genLepW->mass() );
00108   }
00109 
00110   if(lepTop && genLepTop) {
00111     lepTopPullPt_  ->Fill( (lepTop->pt() - genLepTop->pt()) / genLepTop->pt()   );
00112     lepTopPullEta_ ->Fill( (lepTop->eta() - genLepTop->eta()) / genLepTop->eta()  );
00113     lepTopPullMass_->Fill( (lepTop->mass() - genLepTop->mass()) / genLepTop->mass() );
00114   }
00115   if(neutrino && genNeutrino)
00116     neutrinoPullEta_->Fill( (neutrino->eta()-genNeutrino->eta()) / genNeutrino->eta() );
00117 
00119   // fill histograms with variables describing the quality of the hypotheses
00121 
00122   genMatchDr_->Fill(semiLepEvt->genMatchSumDR());
00123   kinFitProb_->Fill(semiLepEvt->fitProb());
00124 
00125   if(hadTop && genHadTop) {
00126     genMatchDrVsHadTopPullMass_->Fill((hadTop->mass() - genHadTop->mass()) / genHadTop->mass(), semiLepEvt->genMatchSumDR());
00127     kinFitProbVsHadTopPullMass_->Fill((hadTop->mass() - genHadTop->mass()) / genHadTop->mass(), semiLepEvt->fitProb());
00128   }
00129 
00130 }
00131 
00132 void 
00133 HypothesisAnalyzer::beginJob()
00134 {
00135   edm::Service<TFileService> fs;
00136   if( !fs ) throw edm::Exception( edm::errors::Configuration, "TFile Service is not registered in cfg file" );
00137 
00139   // book histograms
00141 
00142   neutrinoEta_ = fs->make<TH1F>("neutrinoEta", "#eta (neutrino)", 21, -4., 4.);
00143   neutrinoPullEta_ = fs->make<TH1F>("neutrinoPullEta", "(#eta_{rec}-#eta_{gen})/#eta_{gen} (neutrino)", 40,  -1., 1.);
00144 
00145   hadWPt_   = fs->make<TH1F>("hadWPt"  , "p_{T} (W_{had}) [GeV]", 25,  0., 500.);
00146   hadWEta_  = fs->make<TH1F>("hadWEta" , "#eta (W_{had})"       , 21, -4.,   4.);
00147   hadWMass_ = fs->make<TH1F>("hadWMass", "M (W_{had}) [GeV]"    , 25,  0., 200.);
00148 
00149   hadTopPt_   = fs->make<TH1F>("hadTopPt"  , "p_{T} (t_{had}) [GeV]", 25, 0. , 500.);
00150   hadTopEta_  = fs->make<TH1F>("hadTopEta" , "#eta (t_{had})"       , 21, -4.,   4.);
00151   hadTopMass_ = fs->make<TH1F>("hadTopMass", "M (t_{had}) [GeV]"    , 40, 0. , 400.);
00152 
00153   lepWPt_   = fs->make<TH1F>("lepWPt"  , "p_{t} (W_{lep}) [GeV]", 25,  0., 500.);
00154   lepWEta_  = fs->make<TH1F>("lepWEta" , "#eta (W_{lep})"       , 21, -4.,   4.);
00155   lepWMass_ = fs->make<TH1F>("lepWMass", "M (W_{lep}) [GeV]"    , 25,  0., 200.);
00156 
00157   lepTopPt_   = fs->make<TH1F>("lepTopPt"  , "p_{T} (t_{lep}) [GeV]", 25, 0. , 500.);
00158   lepTopEta_  = fs->make<TH1F>("lepTopEta" , "#eta (t_{lep})"       , 21, -4.,   4.);
00159   lepTopMass_ = fs->make<TH1F>("lepTopMass", "M (t_{lep}) [GeV]"    , 40, 0. , 400.);
00160 
00161   hadWPullPt_   = fs->make<TH1F>("hadWPullPt"  , "(p_{T,rec}-p_{T,gen})/p_{T,gen} (W_{had})"   , 40, -1., 1.);
00162   hadWPullEta_  = fs->make<TH1F>("hadWPullEta" , "(#eta_{rec}-#eta_{gen})/#eta_{gen} (W_{had})", 40, -1., 1.);
00163   hadWPullMass_ = fs->make<TH1F>("hadWPullMass", "(M_{rec}-M_{gen})/M_{gen} (W_{had})"         , 40, -1., 1.);
00164 
00165   hadTopPullPt_   = fs->make<TH1F>("hadTopPullPt"  , "(p_{T,rec}-p_{T,gen})/p_{T,gen} (t_{had})"   , 40, -1., 1.);
00166   hadTopPullEta_  = fs->make<TH1F>("hadTopPullEta" , "(#eta_{rec}-#eta_{gen})/#eta_{gen} (t_{had})", 40, -1., 1.);
00167   hadTopPullMass_ = fs->make<TH1F>("hadTopPullMass", "(M_{rec}-M_{gen})/M_{gen} (t_{had})"         , 40, -1., 1.);
00168 
00169   lepWPullPt_   = fs->make<TH1F>("lepWPullPt"  , "(p_{T,rec}-p_{T,gen})/p_{T,gen} (W_{lep})"   , 40, -1., 1.);
00170   lepWPullEta_  = fs->make<TH1F>("lepWPullEta" , "(#eta_{rec}-#eta_{gen})/#eta_{gen} (W_{lep})", 40, -1., 1.);
00171   lepWPullMass_ = fs->make<TH1F>("lepWPullMass", "(M_{rec}-M_{gen})/M_{gen} (W_{lep})"         , 40, -1., 1.);
00172 
00173   lepTopPullPt_   = fs->make<TH1F>("lepTopPullPt"  , "(p_{T,rec}-p_{T,gen})/p_{T,gen} (t_{lep})"   , 40, -1., 1.);
00174   lepTopPullEta_  = fs->make<TH1F>("lepTopPullEta" , "(#eta_{rec}-#eta_{gen})/#eta_{gen} (t_{lep})", 40, -1., 1.);
00175   lepTopPullMass_ = fs->make<TH1F>("lepTopPullMass", "(M_{rec}-M_{gen})/M_{gen} (t_{lep})"         , 40, -1., 1.);
00176 
00177   topPairMass_ = fs->make<TH1F>("topPairMass", "M (t#bar{t})", 36, 340., 940.);
00178   topPairPullMass_ = fs->make<TH1F>("topPairPullMass", "(M_{rec}-M_{gen})/M_{gen} (t#bar{t})", 40,  -1., 1.);
00179 
00180   genMatchDr_ = fs->make<TH1F>("genMatchDr", "GenMatch #Sigma#DeltaR", 40, 0., 4.);
00181   kinFitProb_ = fs->make<TH1F>("kinFitProb", "KinFit probability"      , 50, 0., 1.);
00182 
00183   genMatchDrVsHadTopPullMass_ = fs->make<TH2F>("genMatchDrVsHadTopPullMass",
00184                                                "GenMatch #Sigma #Delta R vs. (M_{rec}-M_{gen})/M_{gen} (t_{had}))",
00185                                                40, -1., 1., 40, 0., 4.);
00186   kinFitProbVsHadTopPullMass_ = fs->make<TH2F>("kinFitProbVsHadTopPullMass",
00187                                                "KinFit probability vs. (M_{rec}-M_{gen})/M_{gen} (t_{had}))",
00188                                                40, -1., 1., 20, 0., 1.);
00189 }
00190 
00191 void
00192 HypothesisAnalyzer::endJob() 
00193 {
00194 }