CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Attributes
EGExtraInfoModifierFromFloatValueMaps Class Reference
Inheritance diagram for EGExtraInfoModifierFromFloatValueMaps:
ModifyObjectValueBase

Classes

struct  electron_config
 
struct  photon_config
 

Public Types

typedef edm::EDGetTokenT
< edm::ValueMap< float > > 
ValMapFloatToken
 
typedef std::unordered_map
< std::string,
ValMapFloatToken
ValueMaps
 
typedef std::unordered_map
< std::string, edm::InputTag
ValueMapsTags
 

Public Member Functions

 EGExtraInfoModifierFromFloatValueMaps (const edm::ParameterSet &conf)
 
void modifyObject (pat::Electron &) const overridefinal
 
void modifyObject (pat::Photon &) const overridefinal
 
void setConsumes (edm::ConsumesCollector &) overridefinal
 
void setEvent (const edm::Event &) overridefinal
 
void setEventContent (const edm::EventSetup &) overridefinal
 
- Public Member Functions inherited from ModifyObjectValueBase
virtual void modifyObject (reco::GsfElectron &) const
 
virtual void modifyObject (reco::Photon &) const
 
virtual void modifyObject (reco::Muon &) const
 
virtual void modifyObject (reco::BaseTau &) const
 
virtual void modifyObject (reco::Jet &) const
 
virtual void modifyObject (pat::Muon &) const
 
virtual void modifyObject (pat::Tau &) const
 
virtual void modifyObject (pat::Jet &) const
 
 ModifyObjectValueBase (const edm::ParameterSet &conf)
 
const std::string & name () const
 
virtual ~ModifyObjectValueBase ()
 

Private Attributes

electron_config e_conf
 
unsigned ele_idx
 
std::unordered_map< unsigned,
edm::Handle< edm::ValueMap
< float > > > 
ele_vmaps
 
std::unordered_map< unsigned,
edm::Ptr< reco::GsfElectron > > 
eles_by_oop
 
photon_config ph_conf
 
unsigned pho_idx
 
std::unordered_map< unsigned,
edm::Handle< edm::ValueMap
< float > > > 
pho_vmaps
 
std::unordered_map< unsigned,
edm::Ptr< reco::Photon > > 
phos_by_oop
 

Detailed Description

Definition at line 17 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Member Typedef Documentation

Definition at line 19 of file EGExtraInfoModifierFromFloatValueMaps.cc.

typedef std::unordered_map<std::string,ValMapFloatToken> EGExtraInfoModifierFromFloatValueMaps::ValueMaps

Definition at line 20 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Definition at line 21 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Constructor & Destructor Documentation

EGExtraInfoModifierFromFloatValueMaps::EGExtraInfoModifierFromFloatValueMaps ( const edm::ParameterSet conf)

Definition at line 60 of file EGExtraInfoModifierFromFloatValueMaps.cc.

References constexpr, EGExtraInfoModifierFromFloatValueMaps::electron_config::electron_src, HI_PhotonSkim_cff::electrons, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), edm::ParameterSet::getParameterNames(), ModifyObjectValueBase::name(), Parameters::parameters, EGExtraInfoModifierFromFloatValueMaps::photon_config::photon_src, interactiveExample::photons, AlCaHLTBitMon_QueryRunRegistry::string, EGExtraInfoModifierFromFloatValueMaps::electron_config::valuemaps, and EGExtraInfoModifierFromFloatValueMaps::photon_config::valuemaps.

60  :
61  ModifyObjectValueBase(conf) {
62  constexpr char electronSrc[] = "electronSrc";
63  constexpr char photonSrc[] = "photonSrc";
64 
65  if( conf.exists("electron_config") ) {
66  const edm::ParameterSet& electrons = conf.getParameter<edm::ParameterSet>("electron_config");
67  if( electrons.exists(electronSrc) ) e_conf.electron_src = electrons.getParameter<edm::InputTag>(electronSrc);
68  const std::vector<std::string> parameters = electrons.getParameterNames();
69  for( const std::string& name : parameters ) {
70  if( std::string(electronSrc) == name ) continue;
71  if( electrons.existsAs<edm::InputTag>(name) ) {
73  }
74  }
75  }
76  if( conf.exists("photon_config") ) {
77  const edm::ParameterSet& photons = conf.getParameter<edm::ParameterSet>("photon_config");
78  if( photons.exists(photonSrc) ) ph_conf.photon_src = photons.getParameter<edm::InputTag>(photonSrc);
79  const std::vector<std::string> parameters = photons.getParameterNames();
80  for( const std::string& name : parameters ) {
81  if( std::string(photonSrc) == name ) continue;
82  if( photons.existsAs<edm::InputTag>(name) ) {
84  }
85  }
86  }
87  ele_idx = pho_idx = 0;
88 }
T getParameter(std::string const &) const
dictionary parameters
Definition: Parameters.py:2
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:186
bool exists(std::string const &parameterName) const
checks if a parameter exists
#define constexpr
const std::string & name() const
std::vector< std::string > getParameterNames() const
ModifyObjectValueBase(const edm::ParameterSet &conf)

Member Function Documentation

void EGExtraInfoModifierFromFloatValueMaps::modifyObject ( pat::Electron ele) const
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 170 of file EGExtraInfoModifierFromFloatValueMaps.cc.

References pat::PATObject< ObjectType >::addUserFloat(), e_conf, ele_idx, ele_vmaps, eles_by_oop, Exception, pat::PATObject< ObjectType >::hasUserFloat(), edm::EDGetTokenT< T >::isUninitialized(), edm::Ptr< T >::key(), relval_steps::key, pat::PATObject< ObjectType >::originalObjectRef(), EGExtraInfoModifierFromFloatValueMaps::electron_config::tok_electron_src, EGExtraInfoModifierFromFloatValueMaps::electron_config::tok_valuemaps, and relativeConstraints::value.

170  {
171  // we encounter two cases here, either we are running AOD -> MINIAOD
172  // and the value maps are to the reducedEG object, can use original object ptr
173  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
176  auto key = eles_by_oop.find(ele_idx);
177  if( key != eles_by_oop.end() ) {
178  ptr = key->second;
179  } else {
180  throw cms::Exception("BadElectronKey")
181  << "Original object pointer with key = " << ele.originalObjectRef().key()
182  << " not found in cache!";
183  }
184  }
185  //now we go through and modify the objects using the valuemaps we read in
186  for( auto itr = e_conf.tok_valuemaps.begin(); itr != e_conf.tok_valuemaps.end(); ++itr ) {
187  float value(0.0);
188  assignValue(ptr,itr->second,ele_vmaps,value);
189  if( !ele.hasUserFloat(itr->first) ) {
190  ele.addUserFloat(itr->first,value);
191  } else {
192  throw cms::Exception("ValueNameAlreadyExists")
193  << "Trying to add new UserFloat = " << itr->first
194  << " failed because it already exists!";
195  }
196  }
197  ++ele_idx;
198 }
key_type key() const
Definition: Ptr.h:186
bool hasUserFloat(const std::string &key) const
Return true if there is a user-defined float with a given name.
Definition: PATObject.h:334
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:793
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:498
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::unordered_map< unsigned, edm::Ptr< reco::GsfElectron > > eles_by_oop
bool isUninitialized() const
Definition: EDGetToken.h:73
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > ele_vmaps
void EGExtraInfoModifierFromFloatValueMaps::modifyObject ( pat::Photon pho) const
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 201 of file EGExtraInfoModifierFromFloatValueMaps.cc.

References pat::PATObject< ObjectType >::addUserFloat(), Exception, pat::PATObject< ObjectType >::hasUserFloat(), edm::EDGetTokenT< T >::isUninitialized(), edm::Ptr< T >::key(), relval_steps::key, pat::PATObject< ObjectType >::originalObjectRef(), ph_conf, pho_idx, pho_vmaps, phos_by_oop, EGExtraInfoModifierFromFloatValueMaps::photon_config::tok_photon_src, EGExtraInfoModifierFromFloatValueMaps::photon_config::tok_valuemaps, and relativeConstraints::value.

201  {
202  // we encounter two cases here, either we are running AOD -> MINIAOD
203  // and the value maps are to the reducedEG object, can use original object ptr
204  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
207  auto key = phos_by_oop.find(pho_idx);
208  if( key != phos_by_oop.end() ) {
209  ptr = key->second;
210  } else {
211  throw cms::Exception("BadPhotonKey")
212  << "Original object pointer with key = " << pho.originalObjectRef().key() << " not found in cache!";
213  }
214  }
215  //now we go through and modify the objects using the valuemaps we read in
216  for( auto itr = ph_conf.tok_valuemaps.begin(); itr != ph_conf.tok_valuemaps.end(); ++itr ) {
217  float value(0.0);
218  assignValue(ptr,itr->second,pho_vmaps,value);
219  if( !pho.hasUserFloat(itr->first) ) {
220  pho.addUserFloat(itr->first,value);
221  } else {
222  throw cms::Exception("ValueNameAlreadyExists")
223  << "Trying to add new UserFloat = " << itr->first
224  << " failed because it already exists!";
225  }
226  }
227  ++pho_idx;
228 }
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > pho_vmaps
key_type key() const
Definition: Ptr.h:186
bool hasUserFloat(const std::string &key) const
Return true if there is a user-defined float with a given name.
Definition: PATObject.h:334
void addUserFloat(const std::string &label, float data, const bool overwrite=false)
Set user-defined float.
Definition: PATObject.h:793
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:498
std::unordered_map< unsigned, edm::Ptr< reco::Photon > > phos_by_oop
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
bool isUninitialized() const
Definition: EDGetToken.h:73
void EGExtraInfoModifierFromFloatValueMaps::setConsumes ( edm::ConsumesCollector sumes)
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 146 of file EGExtraInfoModifierFromFloatValueMaps.cc.

References edm::ConsumesCollector::consumes(), e_conf, EGExtraInfoModifierFromFloatValueMaps::electron_config::electron_src, ph_conf, EGExtraInfoModifierFromFloatValueMaps::photon_config::photon_src, EGExtraInfoModifierFromFloatValueMaps::electron_config::tok_electron_src, EGExtraInfoModifierFromFloatValueMaps::photon_config::tok_photon_src, EGExtraInfoModifierFromFloatValueMaps::electron_config::tok_valuemaps, EGExtraInfoModifierFromFloatValueMaps::photon_config::tok_valuemaps, EGExtraInfoModifierFromFloatValueMaps::electron_config::valuemaps, and EGExtraInfoModifierFromFloatValueMaps::photon_config::valuemaps.

146  {
147  //setup electrons
149 
150  for( auto itr = e_conf.valuemaps.begin(); itr != e_conf.valuemaps.end(); ++itr ) {
151  make_consumes(itr->second,e_conf.tok_valuemaps[itr->first],sumes);
152  }
153 
154  // setup photons
156 
157  for( auto itr = ph_conf.valuemaps.begin(); itr != ph_conf.valuemaps.end(); ++itr ) {
158  make_consumes(itr->second,ph_conf.tok_valuemaps[itr->first],sumes);
159  }
160 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void EGExtraInfoModifierFromFloatValueMaps::setEvent ( const edm::Event evt)
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 99 of file EGExtraInfoModifierFromFloatValueMaps.cc.

References e_conf, ele_idx, ele_vmaps, eles_by_oop, edm::Event::getByToken(), i, edm::EDGetTokenT< T >::isUninitialized(), ph_conf, pho_idx, pho_vmaps, phos_by_oop, EGExtraInfoModifierFromFloatValueMaps::electron_config::tok_electron_src, EGExtraInfoModifierFromFloatValueMaps::photon_config::tok_photon_src, EGExtraInfoModifierFromFloatValueMaps::electron_config::tok_valuemaps, and EGExtraInfoModifierFromFloatValueMaps::photon_config::tok_valuemaps.

99  {
100  eles_by_oop.clear();
101  phos_by_oop.clear();
102  ele_vmaps.clear();
103  pho_vmaps.clear();
104 
105  ele_idx = pho_idx = 0;
106 
110 
111  for( unsigned i = 0; i < eles->size(); ++i ) {
112  edm::Ptr<pat::Electron> ptr = eles->ptrAt(i);
113  eles_by_oop[i] = ptr;
114  }
115  }
116 
117  for( auto itr = e_conf.tok_valuemaps.begin(); itr != e_conf.tok_valuemaps.end(); ++itr ) {
118  get_product(evt,itr->second,ele_vmaps);
119  }
120 
124 
125  for( unsigned i = 0; i < phos->size(); ++i ) {
126  edm::Ptr<pat::Photon> ptr = phos->ptrAt(i);
127  phos_by_oop[i] = ptr;
128  }
129  }
130 
131  for( auto itr = ph_conf.tok_valuemaps.begin(); itr != ph_conf.tok_valuemaps.end(); ++itr ) {
132  get_product(evt,itr->second,pho_vmaps);
133  }
134 }
int i
Definition: DBlmapReader.cc:9
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > pho_vmaps
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
std::unordered_map< unsigned, edm::Ptr< reco::Photon > > phos_by_oop
std::unordered_map< unsigned, edm::Ptr< reco::GsfElectron > > eles_by_oop
bool isUninitialized() const
Definition: EDGetToken.h:73
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > ele_vmaps
void EGExtraInfoModifierFromFloatValueMaps::setEventContent ( const edm::EventSetup evs)
finaloverridevirtual

Reimplemented from ModifyObjectValueBase.

Definition at line 137 of file EGExtraInfoModifierFromFloatValueMaps.cc.

137  {
138 }

Member Data Documentation

electron_config EGExtraInfoModifierFromFloatValueMaps::e_conf
private

Definition at line 46 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), setConsumes(), and setEvent().

unsigned EGExtraInfoModifierFromFloatValueMaps::ele_idx
mutableprivate

Definition at line 52 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > > EGExtraInfoModifierFromFloatValueMaps::ele_vmaps
private

Definition at line 49 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Ptr<reco::GsfElectron> > EGExtraInfoModifierFromFloatValueMaps::eles_by_oop
private

Definition at line 48 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

photon_config EGExtraInfoModifierFromFloatValueMaps::ph_conf
private

Definition at line 47 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), setConsumes(), and setEvent().

unsigned EGExtraInfoModifierFromFloatValueMaps::pho_idx
mutableprivate

Definition at line 52 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > > EGExtraInfoModifierFromFloatValueMaps::pho_vmaps
private

Definition at line 51 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().

std::unordered_map<unsigned,edm::Ptr<reco::Photon> > EGExtraInfoModifierFromFloatValueMaps::phos_by_oop
private

Definition at line 50 of file EGExtraInfoModifierFromFloatValueMaps.cc.

Referenced by modifyObject(), and setEvent().