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 
52  std::map<std::string, int> indexMap;
53  int index = 0;
54  int nonameIndex = 0;
55 
56  for(std::vector<Computer>::iterator iter = computers.begin();
57  iter != computers.end(); ++iter) {
58 
59  edm::ESHandle<JetTagComputer> computerHandle;
60  record.get(iter->name, computerHandle);
61  if (!iter->computer) {
62  iter->computer = computerHandle.product();
63 
64  // finalize the JetTagComputer glue setup
65  std::vector<std::string> inputLabels(iter->computer->getInputLabels());
66 
67  // backward compatible case, use default tagInfo
68  if (inputLabels.empty()) {
69  std::ostringstream ss;
70  ss << "tagInfo" << ++nonameIndex;
71  inputLabels.push_back(ss.str());
72  }
73  for(std::vector<std::string>::const_iterator label =
74  inputLabels.begin();
75  label != inputLabels.end(); ++label) {
76  if (indexMap.find(*label) == indexMap.end()) {
77  uses(index, *label);
78  indexMap[*label] = index;
79  iter->indices.push_back(index++);
80  } else {
81  iter->indices.push_back(indexMap[*label]);
82  }
83  }
84  } else {
85  // A sanity check. This should never fail.
86  if(iter->computer != computerHandle.product()) {
87  throw cms::Exception("LogicError") << "CombinedMVAJetTagComputer::initialize. Pointer to JetTagComputer changed!\n";
88  }
89  }
90 
91  const GenericMVAJetTagComputer *mvaComputer =
92  dynamic_cast<const GenericMVAJetTagComputer*>(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  }
102 }
103 
106 {
107  TaggingVariableList vars;
108  std::vector<const BaseTagInfo*> tagInfos;
109 
110  for(std::vector<Computer>::const_iterator iter = computers.begin();
111  iter != computers.end(); ++iter) {
112  if (!iter->computer)
113  throw cms::Exception("LogicError")
114  << "JetTagComputer \"" << iter->name
115  << "\" is not available in "
116  "CombinedMVAJetTagComputer::"
117  "taggingVariables()" << std::endl;
118 
119  tagInfos.clear();
120  for(std::vector<int>::const_iterator i = iter->indices.begin();
121  i != iter->indices.end(); ++i)
122  tagInfos.push_back(&info.getBase(*i));
123 
124  if (iter->variables) {
125  const GenericMVAJetTagComputer *mvaComputer =
126  dynamic_cast<const GenericMVAJetTagComputer*>(
127  iter->computer);
128  vars.insert(mvaComputer->taggingVariables(info));
129  }
130 
131  if (iter->discriminator)
133  (*iter->computer)(TagInfoHelper(tagInfos)));
134  }
135 
136  return vars;
137 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
static const TGPicture * info(bool iBackgroundIsBlack)
CombinedMVAJetTagComputer(const edm::ParameterSet &parameters)
JetCorrectorParameters::Record record
Definition: classes.h:7
std::vector< Computer > computers
virtual void initialize(const JetTagComputerRecord &)
void get(HolderT &iHolder) 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
virtual void initialize(const JetTagComputerRecord &record)
T const * product() const
Definition: ESHandle.h:86
void insert(const TaggingVariable &variable, bool delayed=false)
virtual reco::TaggingVariableList taggingVariables(const reco::BaseTagInfo &tagInfo) const