CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CombinedMVAV2JetTagComputer.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 
20 
21 using namespace reco;
22 
24 
25  inputComputerNames( params.getParameter<std::vector<std::string> >("jetTagComputers") ),
26  mvaName( params.getParameter<std::string >("mvaName") ),
27  variables( params.getParameter<std::vector<std::string> >("variables") ),
28  spectators( params.getParameter<std::vector<std::string> >("spectators") ),
29  useCondDB(params.getParameter<bool>("useCondDB")),
30  gbrForestLabel(params.existsAs<std::string>("gbrForestLabel") ? params.getParameter<std::string>("gbrForestLabel") : ""),
31  weightFile(params.existsAs<edm::FileInPath>("weightFile") ? params.getParameter<edm::FileInPath>("weightFile") : edm::FileInPath()),
32  useGBRForest(params.existsAs<bool>("useGBRForest") ? params.getParameter<bool>("useGBRForest") : false),
33  useAdaBoost(params.existsAs<bool>("useAdaBoost") ? params.getParameter<bool>("useAdaBoost") : false)
34 
35 {
36  uses(0, "ipTagInfos");
37  uses(1, "svAVRTagInfos");
38  uses(2, "svIVFTagInfos");
39  uses(3, "smTagInfos");
40  uses(4, "seTagInfos");
41 
42 }
43 
45 {
46 }
47 
49 
50  mvaID.reset(new TMVAEvaluator());
51 
52  if (useCondDB)
53  {
54  const GBRWrapperRcd & gbrWrapperRecord = record.getRecord<GBRWrapperRcd>();
55 
56  edm::ESHandle<GBRForest> gbrForestHandle;
57  gbrWrapperRecord.get(gbrForestLabel.c_str(), gbrForestHandle);
58 
59  mvaID->initializeGBRForest(gbrForestHandle.product(), variables, spectators, useAdaBoost);
60  }
61  else {
62  mvaID->initialize(
63  "Color:Silent:Error", mvaName.c_str(),
65  );
66  }
67  for (auto & name : inputComputerNames) {
68  edm::ESHandle<JetTagComputer> computerHandle;
69  record.get(name, computerHandle);
70  const JetTagComputer* comp = computerHandle.product();
71  computers.push_back(comp);
72  }
73 }
74 
76 {
77  // default discriminator value
78  float value = -10.;
79 
80  // TagInfos for JP taggers
81  std::vector<const BaseTagInfo*> jpTagInfos({ &info.getBase(0) });
82 
83  // TagInfos for the CSVv2AVR tagger
84  std::vector<const BaseTagInfo*> avrTagInfos({ &info.getBase(0), &info.getBase(1) });
85 
86  // TagInfos for the CSVv2IVF tagger
87  std::vector<const BaseTagInfo*> ivfTagInfos({ &info.getBase(0), &info.getBase(2) });
88 
89  // TagInfos for the SoftMuon tagger
90  std::vector<const BaseTagInfo*> smTagInfos({ &info.getBase(3) });
91 
92  // TagInfos for the SoftElectron tagger
93  std::vector<const BaseTagInfo*> seTagInfos({ &info.getBase(4) });
94 
95  std::map<std::string,float> inputs;
96  inputs["Jet_JP"] = (*(computers[0]))( TagInfoHelper(jpTagInfos) );
97  inputs["Jet_JBP"] = (*(computers[1]))( TagInfoHelper(jpTagInfos) );
98  inputs["Jet_CSV"] = (*(computers[2]))( TagInfoHelper(avrTagInfos) );
99  inputs["Jet_CSVIVF"] = (*(computers[2]))( TagInfoHelper(ivfTagInfos) );
100  inputs["Jet_SoftMu"] = (*(computers[3]))( TagInfoHelper(smTagInfos) );
101  inputs["Jet_SoftEl"] = (*(computers[4]))( TagInfoHelper(seTagInfos) );
102  //std::cout << "JP=" << inputs["Jet_JP"]
103  // << " JBP=" << inputs["Jet_JBP"]
104  // << " CSV=" << inputs["Jet_CSV"]
105  // << " CSVIVF=" << inputs["Jet_CSVIVF"]
106  // << " SoftMu=" << inputs["Jet_SoftMu"]
107  // << " SoftEl=" << inputs["Jet_SoftEl"]
108  // << std::endl;
109 // inputs["Jet_pt"] = 0.0;
110 // inputs["Jet_eta"] = 0.0;
111 // inputs["Jet_flavour"] = 0.0;
112 
113  if (inputs["Jet_JP"] <= 0) {
114  inputs["Jet_JP"] = 0;
115  }
116  if (inputs["Jet_JBP"] <= 0) {
117  inputs["Jet_JBP"] = 0;
118  }
119  if (inputs["Jet_CSV"] <= 0) {
120  inputs["Jet_CSV"] = 0;
121  }
122  if (inputs["Jet_CSVIVF"] <= 0) {
123  inputs["Jet_CSVIVF"] = 0;
124  }
125  if (inputs["Jet_SoftMu"] <= 0) {
126  inputs["Jet_SoftMu"] = 0;
127  }
128  if (inputs["Jet_SoftEl"] <= 0) {
129  inputs["Jet_SoftEl"] = 0;
130  }
131 
132  if (inputs["Jet_CSV"] >= 1) {
133  inputs["Jet_CSV"] = 1;
134  }
135  if (inputs["Jet_CSVIVF"] >= 1) {
136  inputs["Jet_CSVIVF"] = 1;
137  }
138  if (inputs["Jet_SoftMu"] >= 1) {
139  inputs["Jet_SoftMu"] = 1;
140  }
141  if (inputs["Jet_SoftEl"] >= 1) {
142  inputs["Jet_SoftEl"] = 1;
143  }
144 
145  // evaluate the MVA
146  value = mvaID->evaluate(inputs);
147 
148  // return the final discriminator value
149  return value;
150 }
static const TGPicture * info(bool iBackgroundIsBlack)
JetCorrectorParameters::Record record
Definition: classes.h:7
const std::vector< std::string > variables
virtual void initialize(const JetTagComputerRecord &record) override
CombinedMVAV2JetTagComputer(const edm::ParameterSet &parameters)
std::unique_ptr< TMVAEvaluator > mvaID
const std::vector< std::string > spectators
std::vector< const JetTagComputer * > computers
void get(HolderT &iHolder) const
void uses(unsigned int id, const std::string &label)
const reco::BaseTagInfo & getBase(unsigned int index) const
const std::vector< std::string > inputComputerNames
float discriminator(const TagInfoHelper &info) const override
T const * product() const
Definition: ESHandle.h:86
volatile std::atomic< bool > shutdown_flag false
std::string fullPath() const
Definition: FileInPath.cc:165