CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ElectronTagger.cc
Go to the documentation of this file.
1 #include <limits>
2 #include <random>
3 
12 #include <iostream>
13 
15  m_selector(cfg),
16  m_useCondDB(cfg.getParameter<bool>("useCondDB")),
17  m_gbrForestLabel(cfg.existsAs<std::string>("gbrForestLabel") ? cfg.getParameter<std::string>("gbrForestLabel") : ""),
18  m_weightFile(cfg.existsAs<edm::FileInPath>("weightFile") ? cfg.getParameter<edm::FileInPath>("weightFile") : edm::FileInPath()),
19  m_useGBRForest(cfg.existsAs<bool>("useGBRForest") ? cfg.getParameter<bool>("useGBRForest") : false),
20  m_useAdaBoost(cfg.existsAs<bool>("useAdaBoost") ? cfg.getParameter<bool>("useAdaBoost") : false)
21  {
22  uses("seTagInfos");
23  mvaID.reset(new TMVAEvaluator());
24  }
25 
27 {
28  // variable names and order need to be the same as in the training
29  std::vector<std::string> variables({"sip3d", "sip2d", "ptRel", "deltaR", "ratio", "mva_e_pi"});
30  std::vector<std::string> spectators;
31 
32  if (m_useCondDB)
33  {
34  const GBRWrapperRcd & gbrWrapperRecord = record.getRecord<GBRWrapperRcd>();
35 
36  edm::ESHandle<GBRForest> gbrForestHandle;
37  gbrWrapperRecord.get(m_gbrForestLabel.c_str(), gbrForestHandle);
38 
39  mvaID->initializeGBRForest(gbrForestHandle.product(), variables, spectators, m_useAdaBoost);
40  }
41  else
42  mvaID->initialize("Color:Silent:Error", "BDT", m_weightFile.fullPath(), variables, spectators, m_useGBRForest, m_useAdaBoost);
43 }
44 
47  // default value, used if there are no leptons associated to this jet
48  float bestTag = - std::numeric_limits<float>::infinity();
50 
51  std::mt19937_64 random;
52  std::uniform_real_distribution<float> dist(0.f,1.f);
53 
54  // if there are multiple leptons, look for the highest tag result
55  for (unsigned int i = 0; i < info.leptons(); i++) {
56  const reco::SoftLeptonProperties & properties = info.properties(i);
57  if (m_selector(properties)) {
58  int theSeed=1+round(10000.0*std::abs(properties.deltaR));
59  random.seed(theSeed);
60  float rndm = dist(random);
61  //for negative tagger, flip 50% of the negative signs to positive value
62  float sip3dsig = (m_selector.isNegative() && rndm<0.5) ? -properties.sip3dsig : properties.sip3dsig;
63  float sip2dsig = (m_selector.isNegative() && rndm<0.5) ? -properties.sip2dsig : properties.sip2dsig;
64 
65  std::map<std::string,float> inputs;
66  inputs["sip3d"] = sip3dsig;
67  inputs["sip2d"] = sip2dsig;
68  inputs["ptRel"] = properties.ptRel;
69  inputs["deltaR"] = properties.deltaR;
70  inputs["ratio"] = properties.ratio;
71  inputs["mva_e_pi"] = properties.elec_mva;
72 
73  float tag = mvaID->evaluate(inputs);
74  // Transform output between 0 and 1
75  tag = (tag+1.0)/2.0;
76  if (tag > bestTag)
77  bestTag = tag;
78  }
79  }
80  return bestTag;
81 }
int i
Definition: DBlmapReader.cc:9
static const TGPicture * info(bool iBackgroundIsBlack)
const T & get(unsigned int index=0) const
const bool m_useAdaBoost
tuple cfg
Definition: looper.py:293
const bool m_useCondDB
JetCorrectorParameters::Record record
Definition: classes.h:7
TRandom random
Definition: MVATrainer.cc:138
const SoftLeptonProperties & properties(size_t i) const
const btag::LeptonSelector m_selector
const bool m_useGBRForest
const edm::FileInPath m_weightFile
void get(HolderT &iHolder) const
const double infinity
ElectronTagger(const edm::ParameterSet &)
explicit ctor
void uses(unsigned int id, const std::string &label)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
std::unique_ptr< TMVAEvaluator > mvaID
bool isNegative() const
volatile std::atomic< bool > shutdown_flag false
std::string fullPath() const
Definition: FileInPath.cc:165
const std::string m_gbrForestLabel
virtual float discriminator(const TagInfoHelper &tagInfo) const override
b-tag a jet based on track-to-jet parameters in the extened info collection
void initialize(const JetTagComputerRecord &) override