Go to the documentation of this file.00001 #include <algorithm>
00002 #include <iostream>
00003 #include <sstream>
00004 #include <string>
00005 #include <memory>
00006 #include <vector>
00007 #include <map>
00008
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 #include "FWCore/Framework/interface/ESHandle.h"
00011 #include "FWCore/Framework/interface/EventSetup.h"
00012 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00013 #include "CondFormats/PhysicsToolsObjects/interface/MVAComputer.h"
00014 #include "DataFormats/Common/interface/RefToBase.h"
00015 #include "DataFormats/JetReco/interface/Jet.h"
00016 #include "DataFormats/BTauReco/interface/TaggingVariable.h"
00017 #include "RecoBTau/JetTagComputer/interface/JetTagComputer.h"
00018 #include "RecoBTau/JetTagComputer/interface/JetTagComputerRecord.h"
00019 #include "RecoBTau/JetTagComputer/interface/GenericMVAJetTagComputer.h"
00020 #include "RecoBTau/JetTagComputer/interface/CombinedMVAJetTagComputer.h"
00021
00022 using namespace reco;
00023 using namespace PhysicsTools;
00024
00025 CombinedMVAJetTagComputer::CombinedMVAJetTagComputer(
00026 const edm::ParameterSet ¶ms) :
00027 GenericMVAJetTagComputer(params)
00028 {
00029 std::vector<edm::ParameterSet> computers =
00030 params.getParameter< std::vector<edm::ParameterSet> >(
00031 "jetTagComputers");
00032
00033 for(std::vector<edm::ParameterSet>::const_iterator iter =
00034 computers.begin(); iter != computers.end(); ++iter) {
00035
00036 Computer computer;
00037 computer.name = iter->getParameter<std::string>("jetTagComputer");
00038 computer.discriminator = iter->getParameter<bool>("discriminator");
00039 computer.variables = iter->getParameter<bool>("variables");
00040 computer.computer = 0;
00041
00042 this->computers.push_back(computer);
00043 }
00044 }
00045
00046 CombinedMVAJetTagComputer::~CombinedMVAJetTagComputer()
00047 {
00048 }
00049
00050 void CombinedMVAJetTagComputer::setEventSetup(const edm::EventSetup &es,
00051 bool pass) const
00052 {
00053 std::map<std::string, int> indexMap;
00054 int index = 0;
00055 int nonameIndex = 0;
00056
00057 for(std::vector<Computer>::iterator iter = computers.begin();
00058 iter != computers.end(); ++iter) {
00059 if (!iter->computer) {
00060 edm::ESHandle<JetTagComputer> computer;
00061 es.get<JetTagComputerRecord>().get(
00062 iter->name, computer);
00063 iter->computer = computer.product();
00064
00065
00066 std::vector<std::string> inputLabels(
00067 iter->computer->getInputLabels());
00068
00069
00070 if (inputLabels.empty()) {
00071 std::ostringstream ss;
00072 ss << "tagInfo" << ++nonameIndex;
00073 inputLabels.push_back(ss.str());
00074 }
00075
00076 for(std::vector<std::string>::const_iterator label =
00077 inputLabels.begin();
00078 label != inputLabels.end(); ++label) {
00079 if (indexMap.find(*label) == indexMap.end()) {
00080 const_cast<CombinedMVAJetTagComputer*>(
00081 this)->uses(index, *label);
00082 indexMap[*label] = index;
00083 iter->indices.push_back(index++);
00084 } else
00085 iter->indices.push_back(
00086 indexMap[*label]);
00087 }
00088 }
00089
00090 const GenericMVAJetTagComputer *mvaComputer =
00091 dynamic_cast<const GenericMVAJetTagComputer*>(
00092 iter->computer);
00093 if (iter->variables && !mvaComputer)
00094 throw cms::Exception("LogicError")
00095 << "JetTagComputer \"" << iter->name
00096 << "\" is not an MVAJetTagCompputer, "
00097 "but tagging variables have been "
00098 "requested." << std::endl;
00099
00100 if (!pass || iter->discriminator)
00101 iter->computer->setEventSetup(es);
00102 else if (mvaComputer)
00103 mvaComputer->passEventSetup(es);
00104 }
00105 }
00106
00107 TaggingVariableList
00108 CombinedMVAJetTagComputer::taggingVariables(const TagInfoHelper &info) const
00109 {
00110 TaggingVariableList vars;
00111 std::vector<const BaseTagInfo*> tagInfos;
00112
00113 for(std::vector<Computer>::iterator iter = computers.begin();
00114 iter != computers.end(); ++iter) {
00115 if (!iter->computer)
00116 throw cms::Exception("LogicError")
00117 << "JetTagComputer \"" << iter->name
00118 << "\" is not available in "
00119 "CombinedMVAJetTagComputer::"
00120 "taggingVariables()" << std::endl;
00121
00122 tagInfos.clear();
00123 for(std::vector<int>::const_iterator i = iter->indices.begin();
00124 i != iter->indices.end(); ++i)
00125 tagInfos.push_back(&info.getBase(*i));
00126
00127 if (iter->variables) {
00128 const GenericMVAJetTagComputer *mvaComputer =
00129 dynamic_cast<const GenericMVAJetTagComputer*>(
00130 iter->computer);
00131 vars.insert(mvaComputer->taggingVariables(info));
00132 }
00133
00134 if (iter->discriminator)
00135 vars.insert(btau::algoDiscriminator,
00136 (*iter->computer)(TagInfoHelper(tagInfos)));
00137 }
00138
00139 return vars;
00140 }