Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:34

0001 #include <memory>
0002 
0003 #include "RecoBTag/SecondaryVertex/interface/CandidateBoostedDoubleSecondaryVertexComputer.h"
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 
0007 #include "CondFormats/DataRecord/interface/BTauGenericMVAJetTagComputerRcd.h"
0008 #include "DataFormats/BTauReco/interface/BoostedDoubleSVTagInfo.h"
0009 #include "RecoBTau/JetTagComputer/interface/JetTagComputerRecord.h"
0010 
0011 CandidateBoostedDoubleSecondaryVertexComputer::Tokens::Tokens(const edm::ParameterSet& parameters,
0012                                                               edm::ESConsumesCollector&& cc) {
0013   if (parameters.getParameter<bool>("useCondDB")) {
0014     gbrForest_ = cc.consumes(edm::ESInputTag{"",
0015                                              parameters.existsAs<std::string>("gbrForestLabel")
0016                                                  ? parameters.getParameter<std::string>("gbrForestLabel")
0017                                                  : ""});
0018   }
0019 }
0020 
0021 CandidateBoostedDoubleSecondaryVertexComputer::CandidateBoostedDoubleSecondaryVertexComputer(
0022     const edm::ParameterSet& parameters, Tokens tokens)
0023     : weightFile_(parameters.existsAs<edm::FileInPath>("weightFile")
0024                       ? parameters.getParameter<edm::FileInPath>("weightFile")
0025                       : edm::FileInPath()),
0026       useGBRForest_(parameters.existsAs<bool>("useGBRForest") ? parameters.getParameter<bool>("useGBRForest") : false),
0027       useAdaBoost_(parameters.existsAs<bool>("useAdaBoost") ? parameters.getParameter<bool>("useAdaBoost") : false),
0028       tokens_{tokens} {
0029   uses(0, "svTagInfos");
0030 
0031   mvaID = std::make_unique<TMVAEvaluator>();
0032 }
0033 
0034 void CandidateBoostedDoubleSecondaryVertexComputer::initialize(const JetTagComputerRecord& record) {
0035   // variable names and order need to be the same as in the training
0036   std::vector<std::string> variables({"z_ratio",
0037                                       "trackSipdSig_3",
0038                                       "trackSipdSig_2",
0039                                       "trackSipdSig_1",
0040                                       "trackSipdSig_0",
0041                                       "trackSipdSig_1_0",
0042                                       "trackSipdSig_0_0",
0043                                       "trackSipdSig_1_1",
0044                                       "trackSipdSig_0_1",
0045                                       "trackSip2dSigAboveCharm_0",
0046                                       "trackSip2dSigAboveBottom_0",
0047                                       "trackSip2dSigAboveBottom_1",
0048                                       "tau0_trackEtaRel_0",
0049                                       "tau0_trackEtaRel_1",
0050                                       "tau0_trackEtaRel_2",
0051                                       "tau1_trackEtaRel_0",
0052                                       "tau1_trackEtaRel_1",
0053                                       "tau1_trackEtaRel_2",
0054                                       "tau_vertexMass_0",
0055                                       "tau_vertexEnergyRatio_0",
0056                                       "tau_vertexDeltaR_0",
0057                                       "tau_flightDistance2dSig_0",
0058                                       "tau_vertexMass_1",
0059                                       "tau_vertexEnergyRatio_1",
0060                                       "tau_flightDistance2dSig_1",
0061                                       "jetNTracks",
0062                                       "nSV"});
0063   // book TMVA readers
0064   std::vector<std::string> spectators({"massPruned", "flavour", "nbHadrons", "ptPruned", "etaPruned"});
0065 
0066   if (tokens_.gbrForest_.isInitialized()) {
0067     mvaID->initializeGBRForest(&record.get(tokens_.gbrForest_), variables, spectators, useAdaBoost_);
0068   } else
0069     mvaID->initialize(
0070         "Color:Silent:Error", "BDT", weightFile_.fullPath(), variables, spectators, useGBRForest_, useAdaBoost_);
0071 }
0072 
0073 float CandidateBoostedDoubleSecondaryVertexComputer::discriminator(const TagInfoHelper& tagInfo) const {
0074   // get the TagInfo
0075   const reco::BoostedDoubleSVTagInfo& bdsvTagInfo = tagInfo.get<reco::BoostedDoubleSVTagInfo>(0);
0076 
0077   // get the TaggingVariables
0078   const reco::TaggingVariableList vars = bdsvTagInfo.taggingVariables();
0079 
0080   // default discriminator value
0081   float value = -10.;
0082 
0083   std::map<std::string, float> inputs;
0084   inputs["z_ratio"] = vars.get(reco::btau::z_ratio);
0085   inputs["trackSipdSig_3"] = vars.get(reco::btau::trackSip3dSig_3);
0086   inputs["trackSipdSig_2"] = vars.get(reco::btau::trackSip3dSig_2);
0087   inputs["trackSipdSig_1"] = vars.get(reco::btau::trackSip3dSig_1);
0088   inputs["trackSipdSig_0"] = vars.get(reco::btau::trackSip3dSig_0);
0089   inputs["trackSipdSig_1_0"] = vars.get(reco::btau::tau2_trackSip3dSig_0);
0090   inputs["trackSipdSig_0_0"] = vars.get(reco::btau::tau1_trackSip3dSig_0);
0091   inputs["trackSipdSig_1_1"] = vars.get(reco::btau::tau2_trackSip3dSig_1);
0092   inputs["trackSipdSig_0_1"] = vars.get(reco::btau::tau1_trackSip3dSig_1);
0093   inputs["trackSip2dSigAboveCharm_0"] = vars.get(reco::btau::trackSip2dSigAboveCharm);
0094   inputs["trackSip2dSigAboveBottom_0"] = vars.get(reco::btau::trackSip2dSigAboveBottom_0);
0095   inputs["trackSip2dSigAboveBottom_1"] = vars.get(reco::btau::trackSip2dSigAboveBottom_1);
0096   inputs["tau1_trackEtaRel_0"] = vars.get(reco::btau::tau2_trackEtaRel_0);
0097   inputs["tau1_trackEtaRel_1"] = vars.get(reco::btau::tau2_trackEtaRel_1);
0098   inputs["tau1_trackEtaRel_2"] = vars.get(reco::btau::tau2_trackEtaRel_2);
0099   inputs["tau0_trackEtaRel_0"] = vars.get(reco::btau::tau1_trackEtaRel_0);
0100   inputs["tau0_trackEtaRel_1"] = vars.get(reco::btau::tau1_trackEtaRel_1);
0101   inputs["tau0_trackEtaRel_2"] = vars.get(reco::btau::tau1_trackEtaRel_2);
0102   inputs["tau_vertexMass_0"] = vars.get(reco::btau::tau1_vertexMass);
0103   inputs["tau_vertexEnergyRatio_0"] = vars.get(reco::btau::tau1_vertexEnergyRatio);
0104   inputs["tau_vertexDeltaR_0"] = vars.get(reco::btau::tau1_vertexDeltaR);
0105   inputs["tau_flightDistance2dSig_0"] = vars.get(reco::btau::tau1_flightDistance2dSig);
0106   inputs["tau_vertexMass_1"] = vars.get(reco::btau::tau2_vertexMass);
0107   inputs["tau_vertexEnergyRatio_1"] = vars.get(reco::btau::tau2_vertexEnergyRatio);
0108   inputs["tau_flightDistance2dSig_1"] = vars.get(reco::btau::tau2_flightDistance2dSig);
0109   inputs["jetNTracks"] = vars.get(reco::btau::jetNTracks);
0110   inputs["nSV"] = vars.get(reco::btau::jetNSecondaryVertices);
0111 
0112   // evaluate the MVA
0113   value = mvaID->evaluate(inputs);
0114 
0115   // return the final discriminator value
0116   return value;
0117 }