From 45f58b683d4be12860a3381bb75e941a57a076c9 Mon Sep 17 00:00:00 2001 From: "tfarooque@ifae.es" <tfarooque@at305.pic.es> Date: Mon, 22 Jan 2018 16:42:25 +0100 Subject: [PATCH] Fixing discriminant computation in TRF mode --- Root/VLQ_AnalysisTools.cxx | 76 ++++++++++++++++++++++++++++++++- Root/VLQ_Analysis_Data2015.cxx | 55 +----------------------- VLQAnalysis/VLQ_AnalysisTools.h | 7 ++- 3 files changed, 81 insertions(+), 57 deletions(-) diff --git a/Root/VLQ_AnalysisTools.cxx b/Root/VLQ_AnalysisTools.cxx index 14229d5..5b79b92 100644 --- a/Root/VLQ_AnalysisTools.cxx +++ b/Root/VLQ_AnalysisTools.cxx @@ -12,6 +12,10 @@ #include "VLQAnalysis/VLQ_VariableComputer.h" #include "VLQAnalysis/VLQ_WeightManager.h" #include "VLQAnalysis/VLQ_Enums.h" +#include "TTHAnalysis/TTH_Discriminant.h" +#include "TTHAnalysis/TTH_VariableComputer.h" +#include "TTHAnalysis/TruthMatchingOutput.h" +#include "TTHAnalysis/TlvTruth.h" #include <iostream> #include <utility> // pair @@ -24,14 +28,15 @@ using std::pair; // VLQ_AnalysisTools::VLQ_AnalysisTools( VLQ_Options* opt, OutputHistManager* outMngr, const VLQ_NtupleData *m_ntupData, VLQ_OutputData* outData, VLQ_WeightManager *weightManager, - VLQ_TRFManager* trfMngr, VLQ_VariableComputer *varCptr ): + VLQ_TRFManager* trfMngr, VLQ_VariableComputer *varCptr, TTH_Discriminant * discriminant ): m_opt(opt), m_outputMngr(outMngr), m_ntupData(m_ntupData), m_outData(outData), m_weightMngr(weightManager), m_trfMngr(trfMngr), -m_varComputer(varCptr){ +m_varComputer(varCptr), +m_discriminant(discriminant){ } //_________________________________________________________________________ @@ -43,6 +48,7 @@ VLQ_AnalysisTools::VLQ_AnalysisTools( const VLQ_AnalysisTools &q ) m_ntupData = q.m_ntupData; m_outData = q.m_outData; m_trfMngr = q.m_trfMngr; + m_discriminant = q.m_discriminant; } //_________________________________________________________________________ @@ -573,6 +579,8 @@ bool VLQ_AnalysisTools::PassBTagRequirement( const int btag_req, const bool isIn // variables needed by the user that depend on b-tagged jets, to make sure // the proper permutation is indeed used when calling PassBTagRequirement. this -> ComputeBTagVariables(); + this -> ComputeFCNCDiscriminant(); + // Updating the OutputData to contain the latest loaded b-tagging configuration m_outData -> o_TRF_bjets_n = btag_req; m_outData -> o_TRF_isIncl = isIncl; @@ -633,6 +641,7 @@ bool VLQ_AnalysisTools::ComputeAllVariables(){ if(m_opt -> MsgLevel() == Debug::DEBUG) std::cout << " -> After m_outData -> o_dRaverage_jetjet (" << m_outData -> o_dRaverage_jetjet << ")" << std::endl; this -> ComputeBTagVariables(); + this -> ComputeFCNCDiscriminant(); if(m_opt -> MsgLevel() == Debug::DEBUG) std::cout << "Leaving VLQ_AnalysisTools::ComputeAllVariables()" << std::endl; @@ -699,5 +708,68 @@ bool VLQ_AnalysisTools::ComputeBTagVariables() { + return true; +} + +//____________________________________________________________________________________ +// +bool VLQ_AnalysisTools::ComputeFCNCDiscriminant() { + + if(m_opt -> MsgLevel() == Debug::DEBUG) std::cout << "Entering in VLQ_AnalysisTools::ComputeFCNCDiscriminant()" << std::endl; + + // FCNC discriminant + struct TlvSetter { + TLorentzVector &m_tlv; + TlvSetter(TLorentzVector &tlv) : m_tlv(tlv) {}; + void set(const AnalysisObject* ao) { + m_tlv.SetPtEtaPhiE(ao->Pt(), ao->Eta(), ao->Phi(), ao->E()); + } + }; + const bool has_el = m_outData->o_channel_type == VLQ_Enums::ELECTRON; + const bool has_mu = m_outData->o_channel_type == VLQ_Enums::MUON; + const int nj = m_outData->o_jets_n; + const int nb = m_outData->o_bjets_n; + const bool derive_templates = true; // false DG 'false' causing a crash...todo fix this 2017-12-15 + if((has_el or has_mu) and + (nj>=4 and nb>=2)) { + const bool print_debug = false; // true + TLorentzVector lep4mom, met4mom; + TlvSetter(lep4mom).set(has_el ? m_outData->o_el->at(0) : m_outData->o_mu->at(0)); + TlvSetter(met4mom).set(m_outData->o_AO_met); + std::vector<TLorentzVector> NuSolutions = TTH_VariableComputer::NuSolution(lep4mom, met4mom); + m_discriminant->m_recoJets = m_discriminant->fillRecoJets(*m_outData->o_jets); + if(derive_templates){ + // requires IFAETopFramework 06d767b and TTHAnalysis c7af431 + tth::TlvTruth tlvt = m_discriminant->fillTruthTlvs(m_ntupData->d_mc_pt, + m_ntupData->d_mc_eta, + m_ntupData->d_mc_phi, + m_ntupData->d_mc_m, + m_ntupData->d_mc_pdgId, + m_ntupData->d_mc_children_index); + m_discriminant->m_truthMatch = m_discriminant->matchToTruth(lep4mom, + NuSolutions, + tlvt); + if(print_debug) cout<<m_discriminant->m_truthMatch.str()<<endl; + } + m_discriminant->GetDiscriminant(nj, nb, + m_discriminant->m_recoJets, + NuSolutions, + lep4mom); + if(print_debug) { + const TTH_Discriminant::Result &discriminant_result = m_discriminant->m_result; + cout<<(string("")+ + (nj==4 ? "4jex" : nj==5 ? "5jex" : "6jin")+ + (nb==2 ? "2bex" : nb==3 ? "3bex" : "4bin")) + <<" "<<m_discriminant->m_recoJets.size()<<" reco jets " + <<" probSig "<<discriminant_result.ProbSig + <<" ("<<discriminant_result.ProbSigNum + <<" / "<<discriminant_result.ProbSigDen<<")" + <<endl; + } + } else { + m_discriminant->m_result.setDefaults(); + } + + return true; } diff --git a/Root/VLQ_Analysis_Data2015.cxx b/Root/VLQ_Analysis_Data2015.cxx index 136cffa..01e1267 100644 --- a/Root/VLQ_Analysis_Data2015.cxx +++ b/Root/VLQ_Analysis_Data2015.cxx @@ -202,7 +202,7 @@ bool VLQ_Analysis_Data2015::Begin(){ // //############################################################################ if(m_opt -> MsgLevel() == Debug::DEBUG) std::cout << "Declaring VLQ_AnalysisTools" << std::endl; - m_anaTools = new VLQ_AnalysisTools( m_opt, m_outMngrHist, m_ntupData, m_outData, m_weightMngr, m_TRFMngr, m_varComputer ); + m_anaTools = new VLQ_AnalysisTools( m_opt, m_outMngrHist, m_ntupData, m_outData, m_weightMngr, m_TRFMngr, m_varComputer, m_discriminant ); //############################################################################ // @@ -1098,59 +1098,6 @@ bool VLQ_Analysis_Data2015::Process(Long64_t entry) } if(m_opt -> MsgLevel() == Debug::DEBUG) std::cout << "==> After truth handling" << std::endl; - // FCNC discriminant - struct TlvSetter { - TLorentzVector &m_tlv; - TlvSetter(TLorentzVector &tlv) : m_tlv(tlv) {}; - void set(const AnalysisObject* ao) { - m_tlv.SetPtEtaPhiE(ao->Pt(), ao->Eta(), ao->Phi(), ao->E()); - } - }; - const bool has_el = m_outData->o_channel_type == VLQ_Enums::ELECTRON; - const bool has_mu = m_outData->o_channel_type == VLQ_Enums::MUON; - const int nj = m_outData->o_jets_n; - const int nb = m_outData->o_bjets_n; - const bool derive_templates = true; // false DG 'false' causing a crash...todo fix this 2017-12-15 - if((has_el or has_mu) and - (nj>=4 and nb>=2)) { - const bool print_debug = false; // true - TLorentzVector lep4mom, met4mom; - TlvSetter(lep4mom).set(has_el ? m_outData->o_el->at(0) : m_outData->o_mu->at(0)); - TlvSetter(met4mom).set(m_outData->o_AO_met); - std::vector<TLorentzVector> NuSolutions = TTH_VariableComputer::NuSolution(lep4mom, met4mom); - m_discriminant->m_recoJets = m_discriminant->fillRecoJets(*m_outData->o_jets); - if(derive_templates){ - // requires IFAETopFramework 06d767b and TTHAnalysis c7af431 - tth::TlvTruth tlvt = m_discriminant->fillTruthTlvs(m_ntupData->d_mc_pt, - m_ntupData->d_mc_eta, - m_ntupData->d_mc_phi, - m_ntupData->d_mc_m, - m_ntupData->d_mc_pdgId, - m_ntupData->d_mc_children_index); - m_discriminant->m_truthMatch = m_discriminant->matchToTruth(lep4mom, - NuSolutions, - tlvt); - if(print_debug) cout<<m_discriminant->m_truthMatch.str()<<endl; - } - m_discriminant->GetDiscriminant(nj, nb, - m_discriminant->m_recoJets, - NuSolutions, - lep4mom); - if(print_debug) { - const TTH_Discriminant::Result &discriminant_result = m_discriminant->m_result; - cout<<(string("")+ - (nj==4 ? "4jex" : nj==5 ? "5jex" : "6jin")+ - (nb==2 ? "2bex" : nb==3 ? "3bex" : "4bin")) - <<" "<<m_discriminant->m_recoJets.size()<<" reco jets " - <<" probSig "<<discriminant_result.ProbSig - <<" ("<<discriminant_result.ProbSigNum - <<" / "<<discriminant_result.ProbSigDen<<")" - <<endl; - } - } else { - m_discriminant->m_result.setDefaults(); - } - //########################################################### // # diff --git a/VLQAnalysis/VLQ_AnalysisTools.h b/VLQAnalysis/VLQ_AnalysisTools.h index d05f7c1..7f1aeee 100644 --- a/VLQAnalysis/VLQ_AnalysisTools.h +++ b/VLQAnalysis/VLQ_AnalysisTools.h @@ -16,6 +16,8 @@ class VLQ_TRFManager; class VLQ_VariableComputer; class VLQ_WeightManager; +class TTH_Discriminant; + class VLQ_AnalysisTools { public: @@ -23,7 +25,7 @@ public: // // Standard C++ functions // - VLQ_AnalysisTools( VLQ_Options*, OutputHistManager*, const VLQ_NtupleData *, VLQ_OutputData *, VLQ_WeightManager *, VLQ_TRFManager *, VLQ_VariableComputer * ); + VLQ_AnalysisTools( VLQ_Options*, OutputHistManager*, const VLQ_NtupleData *, VLQ_OutputData *, VLQ_WeightManager *, VLQ_TRFManager *, VLQ_VariableComputer *, TTH_Discriminant * ); VLQ_AnalysisTools( const VLQ_AnalysisTools & ); ~VLQ_AnalysisTools(); @@ -65,6 +67,7 @@ public: // bool ComputeAllVariables(); bool ComputeBTagVariables(); + bool ComputeFCNCDiscriminant(); protected: // @@ -83,6 +86,8 @@ private: VLQ_WeightManager* m_weightMngr; VLQ_TRFManager* m_trfMngr; VLQ_VariableComputer* m_varComputer; + TTH_Discriminant* m_discriminant; + }; #endif //VLQ_ANALYSIS_TOOLS_H -- GitLab