CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
LowPtGsfElectronIDProducer Class Referencefinal
Inheritance diagram for LowPtGsfElectronIDProducer:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 LowPtGsfElectronIDProducer (const edm::ParameterSet &)
 
void produce (edm::StreamID, edm::Event &, const edm::EventSetup &) const override
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsStreamLuminosityBlocks () const final
 
bool wantsStreamRuns () const final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &)
 
- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

double eval (const std::string &name, const edm::Ptr< reco::GsfElectron > &, double rho, float unbiased, float field_z, const reco::Track *trk=0) const
 

Private Attributes

edm::EDGetTokenT< reco::GsfElectronCollectionelectrons_
 
edm::EDGetTokenT< edm::Association< reco::TrackCollection > > gsf2trk_
 
const double maxPtThreshold_
 
const double minPtThreshold_
 
std::vector< std::unique_ptr< const GBRForest > > models_
 
const std::vector< std::string > names_
 
const bool passThrough_
 
edm::EDGetTokenT< pat::ElectronCollectionpatElectrons_
 
const edm::EDGetTokenT< double > rho_
 
const std::vector< double > thresholds_
 
edm::EDGetTokenT< edm::ValueMap< float > > unbiased_
 
const bool useGsfToTrack_
 
const bool usePAT_
 
const std::string version_
 

Additional Inherited Members

- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 30 of file LowPtGsfElectronIDProducer.cc.

Constructor & Destructor Documentation

LowPtGsfElectronIDProducer::LowPtGsfElectronIDProducer ( const edm::ParameterSet conf)
explicit

Definition at line 64 of file LowPtGsfElectronIDProducer.cc.

References createGBRForest(), electrons_, Exception, edm::ParameterSet::getParameter(), gsf2trk_, models_, dataset::name, names_, patElectrons_, thresholds_, unbiased_, useGsfToTrack_, usePAT_, version_, and HGCalRecHit_cfi::weights.

65  : useGsfToTrack_(conf.getParameter<bool>("useGsfToTrack")),
66  usePAT_(conf.getParameter<bool>("usePAT")),
67  electrons_(),
68  patElectrons_(),
69  rho_(consumes<double>(conf.getParameter<edm::InputTag>("rho"))),
70  gsf2trk_(),
71  unbiased_(),
72  names_(conf.getParameter<std::vector<std::string> >("ModelNames")),
73  passThrough_(conf.getParameter<bool>("PassThrough")),
74  minPtThreshold_(conf.getParameter<double>("MinPtThreshold")),
75  maxPtThreshold_(conf.getParameter<double>("MaxPtThreshold")),
76  thresholds_(conf.getParameter<std::vector<double> >("ModelThresholds")),
77  version_(conf.getParameter<std::string>("Version")) {
78  if (useGsfToTrack_) {
79  gsf2trk_ = consumes<edm::Association<reco::TrackCollection> >(conf.getParameter<edm::InputTag>("gsfToTrack"));
80  }
81  if (usePAT_) {
82  patElectrons_ = consumes<pat::ElectronCollection>(conf.getParameter<edm::InputTag>("electrons"));
83  } else {
84  electrons_ = consumes<reco::GsfElectronCollection>(conf.getParameter<edm::InputTag>("electrons"));
85  unbiased_ = consumes<edm::ValueMap<float> >(conf.getParameter<edm::InputTag>("unbiased"));
86  }
87  for (auto& weights : conf.getParameter<std::vector<std::string> >("ModelWeights")) {
89  }
90  if (names_.size() != models_.size()) {
91  throw cms::Exception("Incorrect configuration")
92  << "'ModelNames' size (" << names_.size() << ") != 'ModelWeights' size (" << models_.size() << ").\n";
93  }
94  if (models_.size() != thresholds_.size()) {
95  throw cms::Exception("Incorrect configuration")
96  << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size() << ").\n";
97  }
98  if (version_ != "V0" && version_ != "V1" && !version_.empty()) {
99  throw cms::Exception("Incorrect configuration") << "Unknown Version: " << version_ << "\n";
100  }
101  for (const auto& name : names_) {
102  produces<edm::ValueMap<float> >(name);
103  }
104 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::GsfElectronCollection > electrons_
const std::vector< double > thresholds_
const std::vector< std::string > names_
std::vector< std::unique_ptr< const GBRForest > > models_
edm::EDGetTokenT< pat::ElectronCollection > patElectrons_
const edm::EDGetTokenT< double > rho_
edm::EDGetTokenT< edm::ValueMap< float > > unbiased_
edm::EDGetTokenT< edm::Association< reco::TrackCollection > > gsf2trk_
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)

Member Function Documentation

double LowPtGsfElectronIDProducer::eval ( const std::string &  name,
const edm::Ptr< reco::GsfElectron > &  ele,
double  rho,
float  unbiased,
float  field_z,
const reco::Track trk = 0 
) const
private

Definition at line 234 of file LowPtGsfElectronIDProducer.cc.

References SoftLeptonByDistance_cfi::distance, Exception, postprocess-scan-build::features, lowptgsfeleid::features_V0(), lowptgsfeleid::features_V1(), spr::find(), lowptgsfeleid::Features::get(), haddnano::inputs, models_, dataset::name, names_, lowptgsfeleid::Features::set(), and version_.

Referenced by produce().

239  {
240  auto iter = std::find(names_.begin(), names_.end(), name);
241  if (iter != names_.end()) {
242  int index = std::distance(names_.begin(), iter);
243  std::vector<float> inputs;
244  if (version_.empty()) { // Original XML model
246  features.set(*ele, rho);
247  inputs = features.get();
248  } else if (version_ == "V0") {
249  inputs = lowptgsfeleid::features_V0(*ele, rho, unbiased);
250  } else if (version_ == "V1") {
251  inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z, trk);
252  }
253  return models_.at(index)->GetResponse(inputs.data());
254  } else {
255  throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n";
256  }
257  return 0.;
258 }
const std::vector< std::string > names_
std::vector< std::unique_ptr< const GBRForest > > models_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< float > features_V1(reco::GsfElectron const &ele, float rho, float unbiased, float field_z, const reco::Track *trk=0)
std::vector< float > features_V0(reco::GsfElectron const &ele, float rho, float unbiased)
void set(const reco::GsfElectronRef &ele, double rho)
void LowPtGsfElectronIDProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 262 of file LowPtGsfElectronIDProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addOptional(), DEFINE_FWK_MODULE, and AlCaHLTBitMon_QueryRunRegistry::string.

262  {
264  desc.add<bool>("useGsfToTrack", false);
265  desc.add<bool>("usePAT", false);
266  desc.add<edm::InputTag>("electrons", edm::InputTag("lowPtGsfElectrons"));
267  desc.addOptional<edm::InputTag>("gsfToTrack", edm::InputTag("lowPtGsfToTrackLinks"));
268  desc.addOptional<edm::InputTag>("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased"));
269  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoFastjetAllTmp"));
270  desc.add<std::vector<std::string> >("ModelNames", std::vector<std::string>());
271  desc.add<std::vector<std::string> >("ModelWeights", std::vector<std::string>());
272  desc.add<std::vector<double> >("ModelThresholds", std::vector<double>());
273  desc.add<bool>("PassThrough", false);
274  desc.add<double>("MinPtThreshold", 0.5);
275  desc.add<double>("MaxPtThreshold", 15.);
276  desc.add<std::string>("Version", "");
277  descriptions.add("defaultLowPtGsfElectronID", desc);
278 }
ParameterDescriptionBase * addOptional(U const &iLabel, T const &value)
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void LowPtGsfElectronIDProducer::produce ( edm::StreamID  ,
edm::Event event,
const edm::EventSetup setup 
) const
override

Definition at line 108 of file LowPtGsfElectronIDProducer.cc.

References begin, pat::Electron::closestCtfTrackRef(), reco::GsfElectron::closestCtfTrackRef(), reco::GsfElectron::core(), pat::Electron::electronID(), lowPtElectrons_cff::electrons, electrons_, end, eval(), Exception, edm::helper::Filler< Map >::fill(), objects.autophobj::filler, edm::EventSetup::get(), edm::Ref< C, T, F >::get(), ntupleEnum::gsf, gsf2trk_, edm::helper::Filler< Map >::insert(), MagneticField::inTesla(), edm::Ref< C, T, F >::isAvailable(), pat::Electron::isElectronIDAvailable(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::isNull(), edm::EDGetTokenT< T >::isUninitialized(), eostools::move(), names_, custom_jme_cff::nElectrons, convertSQLitetoXML_cfg::output, electronProducer_cfi::patElectrons, patElectrons_, rho, rho_, lowPtElectrons_cff::unbiased, unbiased_, useGsfToTrack_, usePAT_, and pat::PATObject< ObjectType >::userData().

108  {
109  // Get z-component of B field
111  setup.get<IdealMagneticFieldRecord>().get(field);
112  math::XYZVector zfield(field->inTesla(GlobalPoint(0, 0, 0)));
113 
114  // Pileup
116  event.getByToken(rho_, rho);
117  if (!rho.isValid()) {
118  std::ostringstream os;
119  os << "Problem accessing rho collection for low-pT electrons" << std::endl;
120  throw cms::Exception("InvalidHandle", os.str());
121  }
122 
123  // Retrieve GsfToTrack Association from Event
125  if (useGsfToTrack_) {
126  event.getByToken(gsf2trk_, gsf2trk);
127  }
128 
129  // Retrieve pat::Electrons or reco::GsfElectrons from Event
132  if (usePAT_) {
133  event.getByToken(patElectrons_, patElectrons);
134  } else {
135  event.getByToken(electrons_, electrons);
136  }
137 
138  // ElectronSeed unbiased BDT
140  if (!unbiased_.isUninitialized()) {
141  event.getByToken(unbiased_, unbiasedH);
142  }
143 
144  // Iterate through Electrons, evaluate BDT, and store result
145  std::vector<std::vector<float> > output;
146  unsigned int nElectrons = usePAT_ ? patElectrons->size() : electrons->size();
147  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
148  output.emplace_back(nElectrons, -999.);
149  }
150 
151  if (usePAT_) {
152  for (unsigned int iele = 0; iele < nElectrons; iele++) {
153  edm::Ptr<pat::Electron> ele(patElectrons, iele);
154  if (!ele->isElectronIDAvailable("unbiased")) {
155  continue;
156  }
157 
158  // Extract Track
159  const reco::Track* trk = nullptr;
160  if (useGsfToTrack_) {
161  using PackedPtr = edm::Ptr<pat::PackedCandidate>;
162  const PackedPtr* ptr1 = ele->userData<PackedPtr>("ele2packed");
163  const PackedPtr* ptr2 = ele->userData<PackedPtr>("ele2lost");
164  auto hasBestTrack = [](const PackedPtr* ptr) {
165  return ptr != nullptr && ptr->isNonnull() && ptr->isAvailable() && ptr->get() != nullptr &&
166  ptr->get()->bestTrack() != nullptr;
167  };
168  if (hasBestTrack(ptr1)) {
169  trk = ptr1->get()->bestTrack();
170  } else if (hasBestTrack(ptr2)) {
171  trk = ptr2->get()->bestTrack();
172  }
173  } else {
174  reco::TrackRef ref = ele->closestCtfTrackRef();
175  if (ref.isNonnull() && ref.isAvailable()) {
176  trk = ref.get();
177  }
178  }
179 
180  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
181  output[iname][iele] = eval(names_[iname], ele, *rho, ele->electronID("unbiased"), zfield.z(), trk);
182  }
183  }
184  } else {
185  for (unsigned int iele = 0; iele < nElectrons; iele++) {
186  edm::Ptr<reco::GsfElectron> ele(electrons, iele);
187  if (ele->core().isNull()) {
188  continue;
189  }
190  const auto& gsf = ele->core()->gsfTrack(); // reco::GsfTrackRef
191  if (gsf.isNull()) {
192  continue;
193  }
194 
195  // Extract Track
196  const reco::Track* trk = nullptr;
197  if (useGsfToTrack_) {
198  if (gsf.isAvailable()) {
199  auto const& ref = (*gsf2trk)[gsf];
200  if (ref.isNonnull() && ref.isAvailable()) {
201  trk = ref.get();
202  }
203  }
204  } else {
205  reco::TrackRef ref = ele->closestCtfTrackRef();
206  if (ref.isNonnull() && ref.isAvailable()) {
207  trk = ref.get();
208  }
209  }
210 
211  float unbiased = (*unbiasedH)[gsf];
212  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
213  output[iname][iele] = eval(names_[iname], ele, *rho, unbiased, zfield.z(), trk);
214  }
215  }
216  }
217 
218  // Create and put ValueMap in Event
219  for (unsigned int iname = 0; iname < names_.size(); ++iname) {
220  auto ptr = std::make_unique<edm::ValueMap<float> >(edm::ValueMap<float>());
222  if (usePAT_) {
223  filler.insert(patElectrons, output[iname].begin(), output[iname].end());
224  } else {
225  filler.insert(electrons, output[iname].begin(), output[iname].end());
226  }
227  filler.fill();
228  event.put(std::move(ptr), names_[iname]);
229  }
230 }
bool isAvailable() const
Definition: Ref.h:575
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
edm::EDGetTokenT< reco::GsfElectronCollection > electrons_
const std::vector< std::string > names_
double eval(const std::string &name, const edm::Ptr< reco::GsfElectron > &, double rho, float unbiased, float field_z, const reco::Track *trk=0) const
edm::EDGetTokenT< pat::ElectronCollection > patElectrons_
#define end
Definition: vmac.h:39
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:243
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
const edm::EDGetTokenT< double > rho_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
edm::EDGetTokenT< edm::ValueMap< float > > unbiased_
edm::EDGetTokenT< edm::Association< reco::TrackCollection > > gsf2trk_
#define begin
Definition: vmac.h:32
T get() const
Definition: EventSetup.h:71
bool isUninitialized() const
Definition: EDGetToken.h:70
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

edm::EDGetTokenT<reco::GsfElectronCollection> LowPtGsfElectronIDProducer::electrons_
private

Definition at line 48 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

edm::EDGetTokenT<edm::Association<reco::TrackCollection> > LowPtGsfElectronIDProducer::gsf2trk_
private

Definition at line 51 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

const double LowPtGsfElectronIDProducer::maxPtThreshold_
private

Definition at line 56 of file LowPtGsfElectronIDProducer.cc.

const double LowPtGsfElectronIDProducer::minPtThreshold_
private

Definition at line 55 of file LowPtGsfElectronIDProducer.cc.

std::vector<std::unique_ptr<const GBRForest> > LowPtGsfElectronIDProducer::models_
private

Definition at line 57 of file LowPtGsfElectronIDProducer.cc.

Referenced by eval(), and LowPtGsfElectronIDProducer().

const std::vector<std::string> LowPtGsfElectronIDProducer::names_
private

Definition at line 53 of file LowPtGsfElectronIDProducer.cc.

Referenced by eval(), LowPtGsfElectronIDProducer(), and produce().

const bool LowPtGsfElectronIDProducer::passThrough_
private

Definition at line 54 of file LowPtGsfElectronIDProducer.cc.

edm::EDGetTokenT<pat::ElectronCollection> LowPtGsfElectronIDProducer::patElectrons_
private

Definition at line 49 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

const edm::EDGetTokenT<double> LowPtGsfElectronIDProducer::rho_
private

Definition at line 50 of file LowPtGsfElectronIDProducer.cc.

Referenced by produce().

const std::vector<double> LowPtGsfElectronIDProducer::thresholds_
private

Definition at line 58 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer().

edm::EDGetTokenT<edm::ValueMap<float> > LowPtGsfElectronIDProducer::unbiased_
private

Definition at line 52 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

const bool LowPtGsfElectronIDProducer::useGsfToTrack_
private

Definition at line 46 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

const bool LowPtGsfElectronIDProducer::usePAT_
private

Definition at line 47 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

const std::string LowPtGsfElectronIDProducer::version_
private

Definition at line 59 of file LowPtGsfElectronIDProducer.cc.

Referenced by eval(), and LowPtGsfElectronIDProducer().