CMS 3D CMS Logo

LowPtGsfElectronIDProducer.cc
Go to the documentation of this file.
23 #include <string>
24 #include <vector>
25 
27 //
29 public:
31 
32  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
33 
35 
36 private:
37  double eval(
38  const std::string& name, const edm::Ptr<reco::GsfElectron>&, double rho, float unbiased, float field_z) const;
39 
40  const bool usePAT_;
45  const std::vector<std::string> names_;
46  const bool passThrough_;
47  const double minPtThreshold_;
48  const double maxPtThreshold_;
49  std::vector<std::unique_ptr<const GBRForest> > models_;
50  const std::vector<double> thresholds_;
52 };
53 
55 //
57  : usePAT_(conf.getParameter<bool>("usePAT")),
58  electrons_(),
59  patElectrons_(),
60  rho_(consumes<double>(conf.getParameter<edm::InputTag>("rho"))),
61  unbiased_(),
62  names_(conf.getParameter<std::vector<std::string> >("ModelNames")),
63  passThrough_(conf.getParameter<bool>("PassThrough")),
64  minPtThreshold_(conf.getParameter<double>("MinPtThreshold")),
65  maxPtThreshold_(conf.getParameter<double>("MaxPtThreshold")),
66  thresholds_(conf.getParameter<std::vector<double> >("ModelThresholds")),
67  version_(conf.getParameter<std::string>("Version")) {
68  if (usePAT_) {
69  patElectrons_ = consumes<pat::ElectronCollection>(conf.getParameter<edm::InputTag>("electrons"));
70  } else {
71  electrons_ = consumes<reco::GsfElectronCollection>(conf.getParameter<edm::InputTag>("electrons"));
72  unbiased_ = consumes<edm::ValueMap<float> >(conf.getParameter<edm::InputTag>("unbiased"));
73  }
74  for (auto& weights : conf.getParameter<std::vector<std::string> >("ModelWeights")) {
76  }
77  if (names_.size() != models_.size()) {
78  throw cms::Exception("Incorrect configuration")
79  << "'ModelNames' size (" << names_.size() << ") != 'ModelWeights' size (" << models_.size() << ").\n";
80  }
81  if (models_.size() != thresholds_.size()) {
82  throw cms::Exception("Incorrect configuration")
83  << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n";
84  }
85  if (version_ != "V0" && version_ != "V1") {
86  throw cms::Exception("Incorrect configuration") << "Unknown Version: " << version_ << "\n";
87  }
88  for (const auto& name : names_) {
89  produces<edm::ValueMap<float> >(name);
90  }
91 }
92 
94 //
96  // Get z-component of B field
98  setup.get<IdealMagneticFieldRecord>().get(field);
99  math::XYZVector zfield(field->inTesla(GlobalPoint(0, 0, 0)));
100 
101  // Pileup
103  event.getByToken(rho_, rho);
104  if (!rho.isValid()) {
105  std::ostringstream os;
106  os << "Problem accessing rho collection for low-pT electrons" << std::endl;
107  throw cms::Exception("InvalidHandle", os.str());
108  }
109 
110  // Retrieve pat::Electrons or reco::GsfElectrons from Event
113  if (usePAT_) {
114  event.getByToken(patElectrons_, patElectrons);
115  } else {
116  event.getByToken(electrons_, electrons);
117  }
118 
119  // ElectronSeed unbiased BDT
121  if (!unbiased_.isUninitialized()) {
122  event.getByToken(unbiased_, unbiasedH);
123  }
124 
125  // Iterate through Electrons, evaluate BDT, and store result
126  std::vector<std::vector<float> > output;
127  unsigned int nElectrons = usePAT_ ? patElectrons->size() : electrons->size();
128  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
129  output.emplace_back(nElectrons, -999.);
130  }
131 
132  if (usePAT_) {
133  for (unsigned int iele = 0; iele < nElectrons; iele++) {
135  if (!ele->isElectronIDAvailable("unbiased")) {
136  continue;
137  }
138  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
139  output[iname][iele] = eval(names_[iname], ele, *rho, ele->electronID("unbiased"), zfield.z());
140  }
141  }
142  } else {
143  for (unsigned int iele = 0; iele < nElectrons; iele++) {
145  if (ele->core().isNull()) {
146  continue;
147  }
148  const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef
149  if (gsf.isNull()) {
150  continue;
151  }
152  float unbiased = (*unbiasedH)[gsf];
153  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
154  output[iname][iele] = eval(names_[iname], ele, *rho, unbiased, zfield.z());
155  }
156  }
157  }
158 
159  // Create and put ValueMap in Event
160  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
161  auto ptr = std::make_unique<edm::ValueMap<float> >(edm::ValueMap<float>());
163  if (usePAT_) {
164  filler.insert(patElectrons, output[iname].begin(), output[iname].end());
165  } else {
166  filler.insert(electrons, output[iname].begin(), output[iname].end());
167  }
168  filler.fill();
169  event.put(std::move(ptr), names_[iname]);
170  }
171 }
172 
174 //
176  const std::string& name, const edm::Ptr<reco::GsfElectron>& ele, double rho, float unbiased, float field_z) const {
177  auto iter = std::find(names_.begin(), names_.end(), name);
178  if (iter != names_.end()) {
179  int index = std::distance(names_.begin(), iter);
180  std::vector<float> inputs;
181  if (version_ == "V0") {
183  } else if (version_ == "V1") {
184  inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z);
185  }
186  return models_.at(index)->GetResponse(inputs.data());
187  } else {
188  throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n";
189  }
190  return 0.;
191 }
192 
194 //
197  desc.add<bool>("usePAT", false);
198  desc.add<edm::InputTag>("electrons", edm::InputTag("lowPtGsfElectrons"));
199  desc.addOptional<edm::InputTag>("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased"));
200  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoFastjetAll"));
201  desc.add<std::vector<std::string> >("ModelNames", {""});
202  desc.add<std::vector<std::string> >(
203  "ModelWeights", {"RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Nov28.root"});
204  desc.add<std::vector<double> >("ModelThresholds", {-99.});
205  desc.add<bool>("PassThrough", false);
206  desc.add<double>("MinPtThreshold", 0.5);
207  desc.add<double>("MaxPtThreshold", 15.);
208  desc.add<std::string>("Version", "V1");
209  descriptions.add("defaultLowPtGsfElectronID", desc);
210 }
211 
213 //
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer
LowPtGsfElectronIDProducer(const edm::ParameterSet &)
Definition: LowPtGsfElectronIDProducer.cc:56
Handle.h
MagneticField::inTesla
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
electrons_cff.bool
bool
Definition: electrons_cff.py:366
ESHandle.h
LowPtGsfElectronIDProducer::produce
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
Definition: LowPtGsfElectronIDProducer.cc:95
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
lowptgsfeleid::features_V1
std::vector< float > features_V1(reco::GsfElectron const &ele, float rho, float unbiased, float field_z)
Definition: LowPtGsfElectronFeatures.cc:135
custom_jme_cff.nElectrons
nElectrons
Definition: custom_jme_cff.py:149
edm::EDGetTokenT< reco::GsfElectronCollection >
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:89301
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
BaseParticlePropagator.h
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
LowPtGsfElectronIDProducer::usePAT_
const bool usePAT_
Definition: LowPtGsfElectronIDProducer.cc:40
createGBRForest
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)
Definition: GBRForestTools.cc:257
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle< double >
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
reco::GsfElectron::core
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
LowPtGsfElectronIDProducer::models_
std::vector< std::unique_ptr< const GBRForest > > models_
Definition: LowPtGsfElectronIDProducer.cc:49
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
edm::FileInPath
Definition: FileInPath.h:61
MakerMacros.h
LowPtGsfElectronIDProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: LowPtGsfElectronIDProducer.cc:195
pat::Electron::electronID
float electronID(const std::string &name) const
Returns a specific electron ID associated to the pat::Electron given its name.
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
LowPtGsfElectronIDProducer::electrons_
edm::EDGetTokenT< reco::GsfElectronCollection > electrons_
Definition: LowPtGsfElectronIDProducer.cc:41
HLT_FULL_cff.weights
weights
Definition: HLT_FULL_cff.py:99207
LowPtGsfElectronIDProducer::thresholds_
const std::vector< double > thresholds_
Definition: LowPtGsfElectronIDProducer.cc:50
mps_fire.end
end
Definition: mps_fire.py:242
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
LowPtGsfElectronIDProducer::unbiased_
edm::EDGetTokenT< edm::ValueMap< float > > unbiased_
Definition: LowPtGsfElectronIDProducer.cc:44
Point3DBase< float, GlobalTag >
ParameterSetDescription.h
GsfElectron.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
DDAxes::rho
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
trigObjTnPSource_cfi.filler
filler
Definition: trigObjTnPSource_cfi.py:21
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
lowptgsfeleid::features_V0
std::vector< float > features_V0(reco::GsfElectron const &ele, float rho, float unbiased)
Definition: LowPtGsfElectronFeatures.cc:364
LorentzVector.h
Ptr.h
LowPtGsfElectronIDProducer::maxPtThreshold_
const double maxPtThreshold_
Definition: LowPtGsfElectronIDProducer.cc:48
GsfTrack.h
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
ntupleEnum.gsf
gsf
Definition: ntupleEnum.py:48
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:58
lowPtElectrons_cff.unbiased
unbiased
Definition: lowPtElectrons_cff.py:35
get
#define get
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
InputTag.h
edm::Ptr< reco::GsfElectron >
ValueMap.h
LowPtGsfElectronIDProducer::eval
double eval(const std::string &name, const edm::Ptr< reco::GsfElectron > &, double rho, float unbiased, float field_z) const
Definition: LowPtGsfElectronIDProducer.cc:175
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
pwdgSkimBPark_cfi.electrons
electrons
Definition: pwdgSkimBPark_cfi.py:6
edm::ValueMap< float >
SuperCluster.h
Exception
Definition: hltDiff.cc:245
pat::Electron::isElectronIDAvailable
bool isElectronIDAvailable(const std::string &name) const
Returns true if a specific ID is available in this pat::Electron.
LowPtGsfElectronIDProducer::rho_
const edm::EDGetTokenT< double > rho_
Definition: LowPtGsfElectronIDProducer.cc:43
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::minPtThreshold_
const double minPtThreshold_
Definition: LowPtGsfElectronIDProducer.cc:47
Electron.h
LowPtGsfElectronIDProducer::names_
const std::vector< std::string > names_
Definition: LowPtGsfElectronIDProducer.cc:45
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
patElectronEAIsoCorrectionProducer_cfi.patElectrons
patElectrons
Definition: patElectronEAIsoCorrectionProducer_cfi.py:4
LowPtGsfElectronIDProducer
Definition: LowPtGsfElectronIDProducer.cc:28
edm::helper::Filler
Definition: ValueMap.h:22
View.h
ParameterSet.h
EDProducer.h
event
Definition: event.py:1
LowPtGsfElectronIDProducer::version_
const std::string version_
Definition: LowPtGsfElectronIDProducer.cc:51
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7746
LowPtGsfElectronIDProducer::patElectrons_
edm::EDGetTokenT< pat::ElectronCollection > patElectrons_
Definition: LowPtGsfElectronIDProducer.cc:42
LowPtGsfElectronIDProducer::passThrough_
const bool passThrough_
Definition: LowPtGsfElectronIDProducer.cc:46
edm::InputTag
Definition: InputTag.h:15