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
 

Private Attributes

edm::EDGetTokenT< reco::GsfElectronCollectionelectrons_
 
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 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 29 of file LowPtGsfElectronIDProducer.cc.

Constructor & Destructor Documentation

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

Definition at line 56 of file LowPtGsfElectronIDProducer.cc.

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

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" && !version_.empty()) {
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 }
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_
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
private

Definition at line 175 of file LowPtGsfElectronIDProducer.cc.

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

Referenced by produce().

176  {
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_.empty()) { // Original XML model
183  features.set(*ele, rho);
184  inputs = features.get();
185  } else if (version_ == "V0") {
186  inputs = lowptgsfeleid::features_V0(*ele, rho, unbiased);
187  } else if (version_ == "V1") {
188  inputs = lowptgsfeleid::features_V1(*ele, rho, unbiased, field_z);
189  }
190  return models_.at(index)->GetResponse(inputs.data());
191  } else {
192  throw cms::Exception("Unknown model name") << "'Name given: '" << name << "'. Check against configuration file.\n";
193  }
194  return 0.;
195 }
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_V0(reco::GsfElectron const &ele, float rho, float unbiased)
void set(const reco::GsfElectronRef &ele, double rho)
std::vector< float > features_V1(reco::GsfElectron const &ele, float rho, float unbiased, float field_z)
void LowPtGsfElectronIDProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 199 of file LowPtGsfElectronIDProducer.cc.

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

199  {
201  desc.add<bool>("usePAT", false);
202  desc.add<edm::InputTag>("electrons", edm::InputTag("lowPtGsfElectrons"));
203  desc.addOptional<edm::InputTag>("unbiased", edm::InputTag("lowPtGsfElectronSeedValueMaps:unbiased"));
204  desc.add<edm::InputTag>("rho", edm::InputTag("fixedGridRhoFastjetAllTmp"));
205  desc.add<std::vector<std::string> >("ModelNames", std::vector<std::string>());
206  desc.add<std::vector<std::string> >("ModelWeights", std::vector<std::string>());
207  desc.add<std::vector<double> >("ModelThresholds", std::vector<double>());
208  desc.add<bool>("PassThrough", false);
209  desc.add<double>("MinPtThreshold", 0.5);
210  desc.add<double>("MaxPtThreshold", 15.);
211  desc.add<std::string>("Version", "");
212  descriptions.add("defaultLowPtGsfElectronID", desc);
213 }
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 95 of file LowPtGsfElectronIDProducer.cc.

References begin, reco::GsfElectron::core(), pat::Electron::electronID(), lowPtElectrons_cff::electrons, electrons_, end, eval(), Exception, edm::helper::Filler< Map >::fill(), objects.autophobj::filler, edm::EventSetup::get(), ntupleEnum::gsf, edm::helper::Filler< Map >::insert(), MagneticField::inTesla(), pat::Electron::isElectronIDAvailable(), 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_, and usePAT_.

95  {
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++) {
134  edm::Ptr<pat::Electron> ele(patElectrons, 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++) {
144  edm::Ptr<reco::GsfElectron> ele(electrons, 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 }
edm::EDGetTokenT< reco::GsfElectronCollection > electrons_
const std::vector< std::string > names_
edm::EDGetTokenT< pat::ElectronCollection > patElectrons_
#define end
Definition: vmac.h:39
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
double eval(const std::string &name, const edm::Ptr< reco::GsfElectron > &, double rho, float unbiased, float field_z) const
const edm::EDGetTokenT< double > rho_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
edm::EDGetTokenT< edm::ValueMap< float > > unbiased_
#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 41 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

const double LowPtGsfElectronIDProducer::maxPtThreshold_
private

Definition at line 48 of file LowPtGsfElectronIDProducer.cc.

const double LowPtGsfElectronIDProducer::minPtThreshold_
private

Definition at line 47 of file LowPtGsfElectronIDProducer.cc.

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

Definition at line 49 of file LowPtGsfElectronIDProducer.cc.

Referenced by eval(), and LowPtGsfElectronIDProducer().

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

Definition at line 45 of file LowPtGsfElectronIDProducer.cc.

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

const bool LowPtGsfElectronIDProducer::passThrough_
private

Definition at line 46 of file LowPtGsfElectronIDProducer.cc.

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

Definition at line 42 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

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

Definition at line 43 of file LowPtGsfElectronIDProducer.cc.

Referenced by produce().

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

Definition at line 50 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer().

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

Definition at line 44 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

const bool LowPtGsfElectronIDProducer::usePAT_
private

Definition at line 40 of file LowPtGsfElectronIDProducer.cc.

Referenced by LowPtGsfElectronIDProducer(), and produce().

const std::string LowPtGsfElectronIDProducer::version_
private

Definition at line 51 of file LowPtGsfElectronIDProducer.cc.

Referenced by eval(), and LowPtGsfElectronIDProducer().