CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CharmTagger.cc
Go to the documentation of this file.
2 
8 
9 #include <iostream>
10 #include <vector>
11 #include <algorithm>
12 #include <map>
13 #include <iostream>
14 
16  sl_computer_(configuration.getParameter<edm::ParameterSet>("slComputerCfg")),
17  mva_name_( configuration.getParameter<std::string >("mvaName") ),
18  use_condDB_(configuration.getParameter<bool>("useCondDB")),
19  gbrForest_label_(configuration.getParameter<std::string>("gbrForestLabel")),
20  weight_file_(configuration.getParameter<edm::FileInPath>("weightFile")),
21  use_GBRForest_(configuration.getParameter<bool>("useGBRForest")),
22  use_adaBoost_(configuration.getParameter<bool>("useAdaBoost"))
23 {
24  vpset vars_definition = configuration.getParameter<vpset>("variables");
25  for(auto &var : vars_definition) {
26  MVAVar mva_var;
27  mva_var.name = var.getParameter<std::string>("name");
29  var.getParameter<std::string>("taggingVarName")
30  );
31  mva_var.has_index = var.existsAs<int>("idx") ;
32  mva_var.index = mva_var.has_index ? var.getParameter<int>("idx") : 0;
33  mva_var.default_value = var.getParameter<double>("default");
34 
35  variables_.push_back(mva_var);
36  }
37 
38  uses(0, "pfImpactParameterTagInfos");
39  uses(1, "pfInclusiveSecondaryVertexFinderCvsLTagInfos");
40  uses(2, "softPFMuonsTagInfos");
41  uses(3, "softPFElectronsTagInfos");
42 }
43 
45 {
46  mvaID_.reset(new TMVAEvaluator());
47 
48  std::vector<std::string> variable_names;
49  variable_names.reserve(variables_.size());
50 
51  for(auto &var : variables_) {
52  variable_names.push_back(var.name);
53  }
54  std::vector<std::string> spectators;
55 
56  if(use_condDB_) {
57  const GBRWrapperRcd & gbrWrapperRecord = record.getRecord<GBRWrapperRcd>();
58 
59  edm::ESHandle<GBRForest> gbrForestHandle;
60  gbrWrapperRecord.get(gbrForest_label_.c_str(), gbrForestHandle);
61 
62  mvaID_->initializeGBRForest(
63  gbrForestHandle.product(), variable_names,
64  spectators, use_adaBoost_
65  );
66  }
67  else {
68  mvaID_->initialize(
69  "Color:Silent:Error", mva_name_.c_str(),
70  weight_file_.fullPath(), variable_names,
71  spectators, use_GBRForest_, use_adaBoost_
72  );
73  }
74 }
75 
77 {
78 }
79 
82  // default value, used if there are no leptons associated to this jet
83  const reco::CandIPTagInfo & ip_info = tagInfo.get<reco::CandIPTagInfo>(0);
85  const reco::CandSoftLeptonTagInfo& softmu_info = tagInfo.get<reco::CandSoftLeptonTagInfo>(2);
86  const reco::CandSoftLeptonTagInfo& softel_info = tagInfo.get<reco::CandSoftLeptonTagInfo>(3);
87  reco::TaggingVariableList vars = sl_computer_(ip_info, sv_info, softmu_info, softel_info);
88 
89  // Loop over input variables
90  std::map<std::string, float> inputs;
91  for(auto &mva_var : variables_){
92  //vectorial tagging variable
93  if(mva_var.has_index){
94  std::vector<float> vals = vars.getList(mva_var.id, false);
95  inputs[mva_var.name] = (vals.size() > mva_var.index) ? vals[mva_var.index] : mva_var.default_value;
96  }
97  //single value tagging var
98  else {
99  inputs[mva_var.name] = vars.get(mva_var.id, mva_var.default_value);
100  }
101  }
102 
103  //get the MVA output
104  float tag = mvaID_->evaluate(inputs);
105  return tag;
106 }
T getParameter(std::string const &) const
const T & get(unsigned int index=0) const
std::string name
Definition: CharmTagger.h:31
virtual float discriminator(const TagInfoHelper &tagInfo) const override
b-tag a jet based on track-to-jet parameters in the extened info collection
Definition: CharmTagger.cc:81
virtual void initialize(const JetTagComputerRecord &record) override
Definition: CharmTagger.cc:44
JetCorrectorParameters::Record record
Definition: classes.h:7
edm::FileInPath weight_file_
Definition: CharmTagger.h:46
std::vector< MVAVar > variables_
Definition: CharmTagger.h:41
CombinedSVSoftLeptonComputer sl_computer_
Definition: CharmTagger.h:40
void get(HolderT &iHolder) const
void uses(unsigned int id, const std::string &label)
std::string gbrForest_label_
Definition: CharmTagger.h:45
std::string mva_name_
Definition: CharmTagger.h:43
bool use_condDB_
Definition: CharmTagger.h:44
TaggingVariableName getTaggingVariableName(const std::string &name)
reco::btau::TaggingVariableName id
Definition: CharmTagger.h:32
std::vector< edm::ParameterSet > vpset
Definition: CharmTagger.h:28
std::unique_ptr< TMVAEvaluator > mvaID_
Definition: CharmTagger.h:39
bool use_GBRForest_
Definition: CharmTagger.h:47
CharmTagger(const edm::ParameterSet &)
explicit ctor
Definition: CharmTagger.cc:15
std::string fullPath() const
Definition: FileInPath.cc:165
bool use_adaBoost_
Definition: CharmTagger.h:48