CMS 3D CMS Logo

LowPtGsfElectronIDProducer.cc
Go to the documentation of this file.
20 #include <string>
21 #include <vector>
22 
24 //
26 public:
28 
29  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
30 
32 
33 private:
34  double eval(const std::string& name, const edm::Ptr<reco::GsfElectron>&, double rho, float unbiased) const;
35 
39  const std::vector<std::string> names_;
40  const bool passThrough_;
41  const double minPtThreshold_;
42  const double maxPtThreshold_;
43  std::vector<std::unique_ptr<const GBRForest> > models_;
44  const std::vector<double> thresholds_;
45 };
46 
48 //
50  : gsfElectrons_(consumes<edm::View<reco::GsfElectron> >(conf.getParameter<edm::InputTag>("electrons"))),
51  rho_(consumes<double>(conf.getParameter<edm::InputTag>("rho"))),
52  unbiased_(consumes<edm::ValueMap<float> >(conf.getParameter<edm::InputTag>("unbiased"))),
53  names_(conf.getParameter<std::vector<std::string> >("ModelNames")),
54  passThrough_(conf.getParameter<bool>("PassThrough")),
55  minPtThreshold_(conf.getParameter<double>("MinPtThreshold")),
56  maxPtThreshold_(conf.getParameter<double>("MaxPtThreshold")),
57  thresholds_(conf.getParameter<std::vector<double> >("ModelThresholds")) {
58  for (auto& weights : conf.getParameter<std::vector<std::string> >("ModelWeights")) {
60  }
61  if (names_.size() != models_.size()) {
62  throw cms::Exception("Incorrect configuration")
63  << "'ModelNames' size (" << names_.size() << ") != 'ModelWeights' size (" << models_.size() << ").\n";
64  }
65  if (models_.size() != thresholds_.size()) {
66  throw cms::Exception("Incorrect configuration")
67  << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n";
68  }
69  for (const auto& name : names_) {
70  produces<edm::ValueMap<float> >(name);
71  }
72 }
73 
75 //
77  // Pileup
79  event.getByToken(rho_, rho);
80  if (!rho.isValid()) {
81  std::ostringstream os;
82  os << "Problem accessing rho collection for low-pT electrons" << std::endl;
83  edm::LogError("InvalidHandle") << os.str();
84  throw cms::Exception("InvalidHandle", os.str());
85  }
86 
87  // Retrieve GsfElectrons from Event
89  event.getByToken(gsfElectrons_, gsfElectrons);
90  if (!gsfElectrons.isValid()) {
91  std::ostringstream os;
92  os << "Problem accessing low-pT gsfElectrons collection" << std::endl;
93  edm::LogError("InvalidHandle") << os.str();
94  throw cms::Exception("InvalidHandle", os.str());
95  }
96 
97  // ElectronSeed unbiased BDT
99  event.getByToken(unbiased_, unbiasedH);
100  if (!unbiasedH.isValid()) {
101  std::ostringstream os;
102  os << "Problem accessing low-pT 'unbiased' ElectronSeed collection" << std::endl;
103  edm::LogError("InvalidHandle") << os.str();
104  throw cms::Exception("InvalidHandle", os.str());
105  }
106 
107  // Iterate through Electrons, evaluate BDT, and store result
108  std::vector<std::vector<float> > output;
109  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
110  output.emplace_back(gsfElectrons->size(), -999.);
111  }
112  for (unsigned int iele = 0; iele < gsfElectrons->size(); iele++) {
114 
115  if (ele->core().isNull()) {
116  continue;
117  }
118  const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef
119  if (gsf.isNull()) {
120  continue;
121  }
122  float unbiased = (*unbiasedH)[gsf];
123 
124  //if ( !passThrough_ && ( ele->pt() < minPtThreshold_ ) ) { continue; }
125  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
126  output[iname][iele] = eval(names_[iname], ele, *rho, unbiased);
127  }
128  }
129 
130  // Create and put ValueMap in Event
131  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
132  auto ptr = std::make_unique<edm::ValueMap<float> >(edm::ValueMap<float>());
134  filler.insert(gsfElectrons, output[iname].begin(), output[iname].end());
135  filler.fill();
136  event.put(std::move(ptr), names_[iname]);
137  }
138 }
139 
141 //
143  const edm::Ptr<reco::GsfElectron>& ele,
144  double rho,
145  float unbiased) const {
146  auto iter = std::find(names_.begin(), names_.end(), name);
147  if (iter != names_.end()) {
148  int index = std::distance(names_.begin(), iter);
149  std::vector<float> inputs = lowptgsfeleid::features(ele, rho, unbiased);
150  return models_.at(index)->GetResponse(inputs.data());
151  } else {
152  throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n";
153  }
154  return 0.;
155 }
156 
158 //
161  desc.add<edm::InputTag>("electrons", edm::InputTag("lowPtGsfElectrons"));
162  desc.add<edm::InputTag>("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased"));
163  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoFastjetAllTmp"));
164  desc.add<std::vector<std::string> >("ModelNames", {""});
165  desc.add<std::vector<std::string> >(
166  "ModelWeights",
167  {"RecoEgamma/ElectronIdentification/data/LowPtElectrons/RunII_Autumn18_LowPtElectrons_mva_id.xml.gz"});
168  desc.add<std::vector<double> >("ModelThresholds", {-10.});
169  desc.add<bool>("PassThrough", false);
170  desc.add<double>("MinPtThreshold", 0.5);
171  desc.add<double>("MaxPtThreshold", 15.);
172  descriptions.add("lowPtGsfElectronID", desc);
173 }
174 
176 //
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer
LowPtGsfElectronIDProducer(const edm::ParameterSet &)
Definition: LowPtGsfElectronIDProducer.cc:49
Handle.h
lowptgsfeleid::features
std::vector< float > features(edm::Ptr< reco::GsfElectron > const &ele, float rho, float unbiased)
Definition: LowPtGsfElectronFeatures.cc:132
electrons_cff.bool
bool
Definition: electrons_cff.py:393
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
ESHandle.h
LowPtGsfElectronIDProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: LowPtGsfElectronIDProducer.cc:76
sistrip::View
View
Definition: ConstantsForView.h:26
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
GBRForestTools.h
ZElectronSkim_cff.rho
rho
Definition: ZElectronSkim_cff.py:38
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:85964
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
BaseParticlePropagator.h
createGBRForest
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)
Definition: GBRForestTools.cc:244
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
electronIsolatorFromEffectiveArea_cfi.gsfElectrons
gsfElectrons
Definition: electronIsolatorFromEffectiveArea_cfi.py:4
edm::Handle< double >
reco::GsfElectron::core
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
LowPtGsfElectronIDProducer::models_
std::vector< std::unique_ptr< const GBRForest > > models_
Definition: LowPtGsfElectronIDProducer.cc:43
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
LowPtGsfElectronIDProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: LowPtGsfElectronIDProducer.cc:159
Track.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
LowPtGsfElectronFeatures.h
edm::ConfigurationDescriptions::add
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:57
HLT_FULL_cff.weights
weights
Definition: HLT_FULL_cff.py:95855
LowPtGsfElectronIDProducer::thresholds_
const std::vector< double > thresholds_
Definition: LowPtGsfElectronIDProducer.cc:44
mps_fire.end
end
Definition: mps_fire.py:242
LowPtGsfElectronIDProducer::gsfElectrons_
const edm::EDGetTokenT< edm::View< reco::GsfElectron > > gsfElectrons_
Definition: LowPtGsfElectronIDProducer.cc:36
ParameterSetDescription.h
GsfElectron.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
DDAxes::rho
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
LowPtGsfElectronIDProducer::eval
double eval(const std::string &name, const edm::Ptr< reco::GsfElectron > &, double rho, float unbiased) const
Definition: LowPtGsfElectronIDProducer.cc:142
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
LorentzVector.h
Ptr.h
LowPtGsfElectronIDProducer::maxPtThreshold_
const double maxPtThreshold_
Definition: LowPtGsfElectronIDProducer.cc:42
GsfTrack.h
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
ntupleEnum.gsf
gsf
Definition: ntupleEnum.py:48
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
InputTag.h
edm::Ptr< reco::GsfElectron >
ValueMap.h
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ValueMap< float >
SuperCluster.h
Exception
Definition: hltDiff.cc:246
LowPtGsfElectronIDProducer::rho_
const edm::EDGetTokenT< double > rho_
Definition: LowPtGsfElectronIDProducer.cc:37
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
LowPtGsfElectronIDProducer::unbiased_
const edm::EDGetTokenT< edm::ValueMap< float > > unbiased_
Definition: LowPtGsfElectronIDProducer.cc:38
LowPtGsfElectronIDProducer::minPtThreshold_
const double minPtThreshold_
Definition: LowPtGsfElectronIDProducer.cc:41
LowPtGsfElectronIDProducer::names_
const std::vector< std::string > names_
Definition: LowPtGsfElectronIDProducer.cc:39
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
LowPtGsfElectronIDProducer
Definition: LowPtGsfElectronIDProducer.cc:25
edm::helper::Filler
Definition: ValueMap.h:22
View.h
ParameterSet.h
EDProducer.h
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7796
LowPtGsfElectronIDProducer::passThrough_
const bool passThrough_
Definition: LowPtGsfElectronIDProducer.cc:40
edm::InputTag
Definition: InputTag.h:15