CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CombinedMVAJetTagComputer.cc
Go to the documentation of this file.
1 #include <algorithm>
2 #include <iostream>
3 #include <sstream>
4 #include <string>
5 #include <memory>
6 #include <vector>
7 #include <map>
8 
21 
22 using namespace reco;
23 using namespace PhysicsTools;
24 
26  const edm::ParameterSet &params) :
28 {
29  std::vector<edm::ParameterSet> computers =
30  params.getParameter< std::vector<edm::ParameterSet> >(
31  "jetTagComputers");
32 
33  for(std::vector<edm::ParameterSet>::const_iterator iter =
34  computers.begin(); iter != computers.end(); ++iter) {
35 
36  Computer computer;
37  computer.name = iter->getParameter<std::string>("jetTagComputer");
38  computer.discriminator = iter->getParameter<bool>("discriminator");
39  computer.variables = iter->getParameter<bool>("variables");
40  computer.computer = 0;
41 
42  this->computers.push_back(computer);
43  }
44 }
45 
47 {
48 }
49 
51  bool pass) const
52 {
53  std::map<std::string, int> indexMap;
54  int index = 0;
55  int nonameIndex = 0;
56 
57  for(std::vector<Computer>::iterator iter = computers.begin();
58  iter != computers.end(); ++iter) {
59  if (!iter->computer) {
61  es.get<JetTagComputerRecord>().get(
62  iter->name, computer);
63  iter->computer = computer.product();
64 
65  // finalize the JetTagComputer glue setup
66  std::vector<std::string> inputLabels(
67  iter->computer->getInputLabels());
68 
69  // backward compatible case, use default tagInfo
70  if (inputLabels.empty()) {
71  std::ostringstream ss;
72  ss << "tagInfo" << ++nonameIndex;
73  inputLabels.push_back(ss.str());
74  }
75 
76  for(std::vector<std::string>::const_iterator label =
77  inputLabels.begin();
78  label != inputLabels.end(); ++label) {
79  if (indexMap.find(*label) == indexMap.end()) {
80  const_cast<CombinedMVAJetTagComputer*>(
81  this)->uses(index, *label);
82  indexMap[*label] = index;
83  iter->indices.push_back(index++);
84  } else
85  iter->indices.push_back(
86  indexMap[*label]);
87  }
88  }
89 
90  const GenericMVAJetTagComputer *mvaComputer =
91  dynamic_cast<const GenericMVAJetTagComputer*>(
92  iter->computer);
93  if (iter->variables && !mvaComputer)
94  throw cms::Exception("LogicError")
95  << "JetTagComputer \"" << iter->name
96  << "\" is not an MVAJetTagCompputer, "
97  "but tagging variables have been "
98  "requested." << std::endl;
99 
100  if (!pass || iter->discriminator)
101  iter->computer->setEventSetup(es);
102  else if (mvaComputer)
103  mvaComputer->passEventSetup(es);
104  }
105 }
106 
109 {
110  TaggingVariableList vars;
111  std::vector<const BaseTagInfo*> tagInfos;
112 
113  for(std::vector<Computer>::iterator iter = computers.begin();
114  iter != computers.end(); ++iter) {
115  if (!iter->computer)
116  throw cms::Exception("LogicError")
117  << "JetTagComputer \"" << iter->name
118  << "\" is not available in "
119  "CombinedMVAJetTagComputer::"
120  "taggingVariables()" << std::endl;
121 
122  tagInfos.clear();
123  for(std::vector<int>::const_iterator i = iter->indices.begin();
124  i != iter->indices.end(); ++i)
125  tagInfos.push_back(&info.getBase(*i));
126 
127  if (iter->variables) {
128  const GenericMVAJetTagComputer *mvaComputer =
129  dynamic_cast<const GenericMVAJetTagComputer*>(
130  iter->computer);
131  vars.insert(mvaComputer->taggingVariables(info));
132  }
133 
134  if (iter->discriminator)
136  (*iter->computer)(TagInfoHelper(tagInfos)));
137  }
138 
139  return vars;
140 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
CombinedMVAJetTagComputer(const edm::ParameterSet &parameters)
std::vector< Computer > computers
virtual void passEventSetup(const edm::EventSetup &es) const
void uses(unsigned int id, const std::string &label)
const reco::BaseTagInfo & getBase(unsigned int index) const
virtual reco::TaggingVariableList taggingVariables(const TagInfoHelper &info) const
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
virtual void setEventSetup(const edm::EventSetup &es) const
void insert(const TaggingVariable &variable, bool delayed=false)
virtual reco::TaggingVariableList taggingVariables(const reco::BaseTagInfo &tagInfo) const