CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoBTau/JetTagComputer/src/GenericMVAJetTagComputer.cc

Go to the documentation of this file.
00001 #include <algorithm>
00002 #include <iostream>
00003 #include <string>
00004 #include <memory>
00005 
00006 #include "FWCore/Utilities/interface/Exception.h"
00007 #include "FWCore/Framework/interface/ESHandle.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "CondFormats/PhysicsToolsObjects/interface/MVAComputer.h"
00010 #include "CondFormats/DataRecord/interface/BTauGenericMVAJetTagComputerRcd.h"
00011 #include "DataFormats/Common/interface/RefToBase.h"
00012 #include "DataFormats/JetReco/interface/Jet.h"
00013 #include "DataFormats/BTauReco/interface/TaggingVariable.h"
00014 #include "RecoBTau/JetTagComputer/interface/GenericMVAComputer.h"
00015 #include "RecoBTau/JetTagComputer/interface/GenericMVAJetTagComputer.h"
00016 
00017 using namespace reco;
00018 using namespace PhysicsTools;
00019 
00020 static std::vector<std::string>
00021 getCalibrationLabels(const edm::ParameterSet &params,
00022                      std::auto_ptr<TagInfoMVACategorySelector> &selector)
00023 {
00024         if (params.getParameter<bool>("useCategories")) {
00025                 selector = std::auto_ptr<TagInfoMVACategorySelector>(
00026                                 new TagInfoMVACategorySelector(params));
00027 
00028                 return selector->getCategoryLabels();
00029         } else {
00030                 std::string calibrationRecord =
00031                         params.getParameter<std::string>("calibrationRecord");
00032 
00033                 std::vector<std::string> calibrationLabels;
00034                 calibrationLabels.push_back(calibrationRecord);
00035                 return calibrationLabels;
00036         }
00037 }
00038 
00039 GenericMVAJetTagComputer::GenericMVAJetTagComputer(
00040                                         const edm::ParameterSet &params) :
00041         computerCache(getCalibrationLabels(params, categorySelector))
00042 {
00043 }
00044 
00045 GenericMVAJetTagComputer::~GenericMVAJetTagComputer()
00046 {
00047 }
00048 
00049 void GenericMVAJetTagComputer::setEventSetup(const edm::EventSetup &es) const
00050 {
00051         // retrieve MVAComputer calibration container
00052         edm::ESHandle<Calibration::MVAComputerContainer> calibHandle;
00053         es.get<BTauGenericMVAJetTagComputerRcd>().get(calibHandle);
00054         const Calibration::MVAComputerContainer *calib = calibHandle.product();
00055 
00056         // check for updates
00057         computerCache.update(calib);
00058 }
00059 
00060 float GenericMVAJetTagComputer::discriminator(const TagInfoHelper &info) const
00061 {
00062         TaggingVariableList variables = taggingVariables(info);
00063 
00064         // retrieve index of computer in case categories are used
00065         int index = 0;
00066         if (categorySelector.get()) {
00067                 index = categorySelector->findCategory(variables);
00068                 if (index < 0)
00069                         return -10.0;
00070         }
00071 
00072         GenericMVAComputer *computer = computerCache.getComputer(index);
00073 
00074         if (!computer)
00075                 return -10.0;
00076 
00077         return computer->eval(variables);
00078 }
00079 
00080 TaggingVariableList
00081 GenericMVAJetTagComputer::taggingVariables(const BaseTagInfo &baseTag) const
00082 {
00083         TaggingVariableList variables = baseTag.taggingVariables();
00084 
00085         // add jet pt and jet eta variables (ordering irrelevant)
00086         edm::RefToBase<Jet> jet = baseTag.jet();
00087         variables.push_back(TaggingVariable(btau::jetPt, jet->pt()));
00088         variables.push_back(TaggingVariable(btau::jetEta, jet->eta()));
00089 
00090         return variables;
00091 }
00092 
00093 TaggingVariableList
00094 GenericMVAJetTagComputer::taggingVariables(const TagInfoHelper &info) const
00095 {
00096         return taggingVariables(info.getBase(0));
00097 }