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 
43  const std::vector<std::string> names_;
44  const bool passThrough_;
45  const double minPtThreshold_;
46  const double maxPtThreshold_;
47  std::vector<std::unique_ptr<const GBRForest> > models_;
48  const std::vector<double> thresholds_;
50 };
51 
53 //
55  : electrons_(consumes<edm::View<reco::GsfElectron> >(conf.getParameter<edm::InputTag>("electrons"))),
56  rho_(consumes<double>(conf.getParameter<edm::InputTag>("rho"))),
57  unbiased_(consumes<edm::ValueMap<float> >(conf.getParameter<edm::InputTag>("unbiased"))),
58  names_(conf.getParameter<std::vector<std::string> >("ModelNames")),
59  passThrough_(conf.getParameter<bool>("PassThrough")),
60  minPtThreshold_(conf.getParameter<double>("MinPtThreshold")),
61  maxPtThreshold_(conf.getParameter<double>("MaxPtThreshold")),
62  thresholds_(conf.getParameter<std::vector<double> >("ModelThresholds")),
63  version_(conf.getParameter<std::string>("Version")) {
64  for (auto& weights : conf.getParameter<std::vector<std::string> >("ModelWeights")) {
66  }
67  if (names_.size() != models_.size()) {
68  throw cms::Exception("Incorrect configuration")
69  << "'ModelNames' size (" << names_.size() << ") != 'ModelWeights' size (" << models_.size() << ").\n";
70  }
71  if (models_.size() != thresholds_.size()) {
72  throw cms::Exception("Incorrect configuration")
73  << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n";
74  }
75  if (version_ != "V0" && version_ != "V1") {
76  throw cms::Exception("Incorrect configuration") << "Unknown Version: " << version_ << "\n";
77  }
78  for (const auto& name : names_) {
79  produces<edm::ValueMap<float> >(name);
80  }
81 }
82 
84 //
86  // Get z-component of B field
88  setup.get<IdealMagneticFieldRecord>().get(field);
89  math::XYZVector zfield(field->inTesla(GlobalPoint(0, 0, 0)));
90 
91  // Pileup
93  event.getByToken(rho_, rho);
94  if (!rho.isValid()) {
95  std::ostringstream os;
96  os << "Problem accessing rho collection for low-pT electrons" << std::endl;
97  throw cms::Exception("InvalidHandle", os.str());
98  }
99 
100  // Retrieve GsfElectrons from Event
102  event.getByToken(electrons_, electrons);
103  if (!electrons.isValid()) {
104  std::ostringstream os;
105  os << "Problem accessing low-pT electrons collection" << std::endl;
106  throw cms::Exception("InvalidHandle", os.str());
107  }
108 
109  // ElectronSeed unbiased BDT
111  event.getByToken(unbiased_, unbiasedH);
112 
113  // Iterate through Electrons, evaluate BDT, and store result
114  std::vector<std::vector<float> > output;
115  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
116  output.emplace_back(electrons->size(), -999.);
117  }
118  for (unsigned int iele = 0; iele < electrons->size(); iele++) {
120 
121  if (ele->core().isNull()) {
122  continue;
123  }
124  const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef
125  if (gsf.isNull()) {
126  continue;
127  }
128  float unbiased = (*unbiasedH)[gsf];
129 
130  //if ( !passThrough_ && ( ele->pt() < minPtThreshold_ ) ) { continue; }
131  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
132  output[iname][iele] = eval(names_[iname], ele, *rho, unbiased, zfield.z());
133  }
134  }
135 
136  // Create and put ValueMap in Event
137  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
138  auto ptr = std::make_unique<edm::ValueMap<float> >(edm::ValueMap<float>());
140  filler.insert(electrons, output[iname].begin(), output[iname].end());
141  filler.fill();
142  event.put(std::move(ptr), names_[iname]);
143  }
144 }
145 
147 //
149  const std::string& name, const edm::Ptr<reco::GsfElectron>& ele, double rho, float unbiased, float field_z) const {
150  auto iter = std::find(names_.begin(), names_.end(), name);
151  if (iter != names_.end()) {
152  int index = std::distance(names_.begin(), iter);
153  std::vector<float> inputs;
154  if (version_ == "V0") {
156  } else if (version_ == "V1") {
157  inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z);
158  }
159  return models_.at(index)->GetResponse(inputs.data());
160  } else {
161  throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n";
162  }
163  return 0.;
164 }
165 
167 //
170  desc.add<edm::InputTag>("electrons", edm::InputTag("lowPtGsfElectrons"));
171  desc.add<edm::InputTag>("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased"));
172  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoFastjetAll"));
173  desc.add<std::vector<std::string> >("ModelNames", {""});
174  desc.add<std::vector<std::string> >(
175  "ModelWeights", {"RecoEgamma/ElectronIdentification/data/LowPtElectrons/LowPtElectrons_ID_2020Nov28.root"});
176  desc.add<std::vector<double> >("ModelThresholds", {-99.});
177  desc.add<bool>("PassThrough", false);
178  desc.add<double>("MinPtThreshold", 0.5);
179  desc.add<double>("MaxPtThreshold", 15.);
180  desc.add<std::string>("Version", "V1");
181  descriptions.add("lowPtGsfElectronID", desc);
182 }
183 
185 //
ConfigurationDescriptions.h
edm::StreamID
Definition: StreamID.h:30
LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer
LowPtGsfElectronIDProducer(const edm::ParameterSet &)
Definition: LowPtGsfElectronIDProducer.cc:54
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
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:85
sistrip::View
View
Definition: ConstantsForView.h:26
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:134
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:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
BaseParticlePropagator.h
createGBRForest
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)
Definition: GBRForestTools.cc:257
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
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:47
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
edm::FileInPath
Definition: FileInPath.h:64
MakerMacros.h
LowPtGsfElectronIDProducer::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &)
Definition: LowPtGsfElectronIDProducer.cc:168
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:99166
LowPtGsfElectronIDProducer::thresholds_
const std::vector< double > thresholds_
Definition: LowPtGsfElectronIDProducer.cc:48
mps_fire.end
end
Definition: mps_fire.py:242
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
Point3DBase< float, GlobalTag >
ParameterSetDescription.h
GsfElectron.h
edm::global::EDProducer
Definition: EDProducer.h:32
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
DDAxes::rho
lowPtElectronProducer_cff.unbiased
unbiased
Definition: lowPtElectronProducer_cff.py:24
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
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:363
LorentzVector.h
Ptr.h
LowPtGsfElectronIDProducer::maxPtThreshold_
const double maxPtThreshold_
Definition: LowPtGsfElectronIDProducer.cc:46
GsfTrack.h
PixelMapPlotter.inputs
inputs
Definition: PixelMapPlotter.py:490
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
ntupleEnum.gsf
gsf
Definition: ntupleEnum.py:49
MagneticField.h
edm::EventSetup
Definition: EventSetup.h:58
get
#define get
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:148
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
LowPtGsfElectronIDProducer::electrons_
const edm::EDGetTokenT< edm::View< reco::GsfElectron > > electrons_
Definition: LowPtGsfElectronIDProducer.cc:40
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
LowPtGsfElectronIDProducer::rho_
const edm::EDGetTokenT< double > rho_
Definition: LowPtGsfElectronIDProducer.cc:41
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:42
LowPtGsfElectronIDProducer::minPtThreshold_
const double minPtThreshold_
Definition: LowPtGsfElectronIDProducer.cc:45
Electron.h
LowPtGsfElectronIDProducer::names_
const std::vector< std::string > names_
Definition: LowPtGsfElectronIDProducer.cc:43
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
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:49
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
LowPtGsfElectronIDProducer::passThrough_
const bool passThrough_
Definition: LowPtGsfElectronIDProducer.cc:44
edm::InputTag
Definition: InputTag.h:15