CMS 3D CMS Logo

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  defaultValueNoTracks_(configuration.getParameter<bool>("defaultValueNoTracks"))
24 {
25  vpset vars_definition = configuration.getParameter<vpset>("variables");
26  for(auto &var : vars_definition) {
27  MVAVar mva_var;
28  mva_var.name = var.getParameter<std::string>("name");
30  var.getParameter<std::string>("taggingVarName")
31  );
32  mva_var.has_index = var.existsAs<int>("idx") ;
33  mva_var.index = mva_var.has_index ? var.getParameter<int>("idx") : 0;
34  mva_var.default_value = var.getParameter<double>("default");
35 
36  variables_.push_back(mva_var);
37  }
38 
39  uses(0, "pfImpactParameterTagInfos");
40  uses(1, "pfInclusiveSecondaryVertexFinderCvsLTagInfos");
41  uses(2, "softPFMuonsTagInfos");
42  uses(3, "softPFElectronsTagInfos");
43 }
44 
46 {
47  mvaID_.reset(new TMVAEvaluator());
48 
49  std::vector<std::string> variable_names;
50  variable_names.reserve(variables_.size());
51 
52  for(auto &var : variables_) {
53  variable_names.push_back(var.name);
54  }
55  std::vector<std::string> spectators;
56 
57  if(use_condDB_) {
58  const GBRWrapperRcd & gbrWrapperRecord = record.getRecord<GBRWrapperRcd>();
59 
60  edm::ESHandle<GBRForest> gbrForestHandle;
61  gbrWrapperRecord.get(gbrForest_label_.c_str(), gbrForestHandle);
62 
63  mvaID_->initializeGBRForest(
64  gbrForestHandle.product(), variable_names,
66  );
67  }
68  else {
69  mvaID_->initialize(
70  "Color:Silent:Error", mva_name_,
71  weight_file_.fullPath(), variable_names,
73  );
74  }
75 }
76 
78 {
79 }
80 
82 float CharmTagger::discriminator(const TagInfoHelper & tagInfo) const {
83  // default value, used if there are no leptons associated to this jet
84  const reco::CandIPTagInfo & ip_info = tagInfo.get<reco::CandIPTagInfo>(0);
86  const reco::CandSoftLeptonTagInfo& softmu_info = tagInfo.get<reco::CandSoftLeptonTagInfo>(2);
87  const reco::CandSoftLeptonTagInfo& softel_info = tagInfo.get<reco::CandSoftLeptonTagInfo>(3);
88  reco::TaggingVariableList vars = sl_computer_(ip_info, sv_info, softmu_info, softel_info);
89 
90  // Loop over input variables
91  std::map<std::string, float> inputs;
92  for(auto &mva_var : variables_){
93  //vectorial tagging variable
94  if(mva_var.has_index){
95  std::vector<float> vals = vars.getList(mva_var.id, false);
96  inputs[mva_var.name] = (vals.size() > mva_var.index) ? vals[mva_var.index] : mva_var.default_value;
97  }
98  //single value tagging var
99  else {
100  inputs[mva_var.name] = vars.get(mva_var.id, mva_var.default_value);
101  }
102  }
103 
104  //get the MVA output
105  bool notracks = (vars.get(reco::btau::jetNTracks,0) == 0);
106  float tag = mvaID_->evaluate(inputs);
107  if (defaultValueNoTracks_ && notracks){tag = -2;} // if no tracks available, put value at -2 (only for Phase I)
108  return tag;
109 }
T getParameter(std::string const &) const
const T & get(unsigned int index=0) const
std::string name
Definition: CharmTagger.h:31
void initialize(const JetTagComputerRecord &record) override
Definition: CharmTagger.cc:45
JetCorrectorParameters::Record record
Definition: classes.h:7
edm::FileInPath weight_file_
Definition: CharmTagger.h:46
std::vector< MVAVar > variables_
Definition: CharmTagger.h:41
PRODUCT const & get(ESGetToken< PRODUCT, T > const &iToken) const
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:82
~CharmTagger() override
Definition: CharmTagger.cc:77
CombinedSVSoftLeptonComputer sl_computer_
Definition: CharmTagger.h:40
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 defaultValueNoTracks_
Definition: CharmTagger.h:49
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
HLT enums.
bool use_GBRForest_
Definition: CharmTagger.h:47
CharmTagger(const edm::ParameterSet &)
explicit ctor
Definition: CharmTagger.cc:15
std::string fullPath() const
Definition: FileInPath.cc:163
vars
Definition: DeepTauId.cc:77
bool use_adaBoost_
Definition: CharmTagger.h:48