CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EGFull5x5ShowerShapeModifier.cc
Go to the documentation of this file.
2 
6 
9 
10 namespace {
11  const edm::EDGetTokenT<edm::ValueMap<float> > empty_token;
12  const static edm::InputTag empty_tag("");
13 }
14 
15 #include <unordered_map>
16 
18 public:
19  struct electron_config {
44  };
45 
46  struct photon_config {
71  };
72 
74 
75  void setEvent(const edm::Event&) override final;
76  void setEventContent(const edm::EventSetup&) override final;
77  void setConsumes(edm::ConsumesCollector&) override final;
78 
79  void modifyObject(pat::Electron&) const override final;
80  void modifyObject(pat::Photon&) const override final;
81 
82 private:
85  std::unordered_map<unsigned,edm::Ptr<reco::GsfElectron> > eles_by_oop; // indexed by original object ptr
86  std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > > ele_vmaps;
87  std::unordered_map<unsigned,edm::Ptr<reco::Photon> > phos_by_oop;
88  std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > > pho_vmaps;
89  mutable unsigned ele_idx,pho_idx; // hack here until we figure out why some slimmedPhotons don't have original object ptrs
90 };
91 
94  "EGFull5x5ShowerShapeModifierFromValueMaps");
95 
96 EGFull5x5ShowerShapeModifierFromValueMaps::
97 EGFull5x5ShowerShapeModifierFromValueMaps(const edm::ParameterSet& conf) :
99  if( conf.exists("electron_config") ) {
100  const edm::ParameterSet& electrons = conf.getParameter<edm::ParameterSet>("electron_config");
101  if( electrons.exists("electronSrc") ) e_conf.electron_src = electrons.getParameter<edm::InputTag>("electronSrc");
102  if( electrons.exists("sigmaEtaEta") ) e_conf.sigmaEtaEta = electrons.getParameter<edm::InputTag>("sigmaEtaEta");
103  if( electrons.exists("sigmaIetaIeta") ) e_conf.sigmaIetaIeta = electrons.getParameter<edm::InputTag>("sigmaIetaIeta");
104  if( electrons.exists("sigmaIphiIphi") ) e_conf.sigmaIphiIphi = electrons.getParameter<edm::InputTag>("sigmaIphiIphi");
105  if( electrons.exists("e1x5") ) e_conf.e1x5 = electrons.getParameter<edm::InputTag>("e1x5");
106  if( electrons.exists("e2x5Max") ) e_conf.e2x5Max = electrons.getParameter<edm::InputTag>("e2x5Max");
107  if( electrons.exists("e5x5") ) e_conf.e5x5 = electrons.getParameter<edm::InputTag>("e5x5");
108  if( electrons.exists("r9") ) e_conf.r9 = electrons.getParameter<edm::InputTag>("r9");
109  if( electrons.exists("hcalDepth1OverEcal") ) e_conf.hcalDepth1OverEcal = electrons.getParameter<edm::InputTag>("hcalDepth1OverEcal");
110  if( electrons.exists("hcalDepth2OverEcal") ) e_conf.hcalDepth2OverEcal = electrons.getParameter<edm::InputTag>("hcalDepth2OverEcal");
111  if( electrons.exists("hcalDepth1OverEcalBc") ) e_conf.hcalDepth1OverEcalBc = electrons.getParameter<edm::InputTag>("hcalDepth1OverEcalBc");
112  if( electrons.exists("hcalDepth2OverEcalBc") ) e_conf.hcalDepth2OverEcalBc = electrons.getParameter<edm::InputTag>("hcalDepth2OverEcalBc");
113  }
114  if( conf.exists("photon_config") ) {
115  const edm::ParameterSet& photons = conf.getParameter<edm::ParameterSet>("photon_config");
116  if( photons.exists("photonSrc") ) ph_conf.photon_src = photons.getParameter<edm::InputTag>("photonSrc");
117  if( photons.exists("sigmaEtaEta") ) ph_conf.sigmaEtaEta = photons.getParameter<edm::InputTag>("sigmaEtaEta");
118  if( photons.exists("sigmaIetaIeta") ) ph_conf.sigmaIetaIeta = photons.getParameter<edm::InputTag>("sigmaIetaIeta");
119  if( photons.exists("e1x5") ) ph_conf.e1x5 = photons.getParameter<edm::InputTag>("e1x5");
120  if( photons.exists("e2x5") ) ph_conf.e2x5 = photons.getParameter<edm::InputTag>("e2x5");
121  if( photons.exists("e3x3") ) ph_conf.e3x3 = photons.getParameter<edm::InputTag>("e3x3");
122  if( photons.exists("e5x5") ) ph_conf.e5x5 = photons.getParameter<edm::InputTag>("e5x5");
123  if( photons.exists("maxEnergyXtal") ) ph_conf.maxEnergyXtal = photons.getParameter<edm::InputTag>("maxEnergyXtal");
124  if( photons.exists("hcalDepth1OverEcal") ) ph_conf.hcalDepth1OverEcal = photons.getParameter<edm::InputTag>("hcalDepth1OverEcal");
125  if( photons.exists("hcalDepth2OverEcal") ) ph_conf.hcalDepth2OverEcal = photons.getParameter<edm::InputTag>("hcalDepth2OverEcal");
126  if( photons.exists("hcalDepth1OverEcalBc") ) ph_conf.hcalDepth1OverEcalBc = photons.getParameter<edm::InputTag>("hcalDepth1OverEcalBc");
127  if( photons.exists("hcalDepth2OverEcalBc") ) ph_conf.hcalDepth2OverEcalBc = photons.getParameter<edm::InputTag>("hcalDepth2OverEcalBc");
128  }
129 
130  ele_idx = pho_idx = 0;
131 }
132 
133 inline void get_product(const edm::Event& evt,
135  std::unordered_map<unsigned, edm::Handle<edm::ValueMap<float> > >& map) {
136  if( !tok.isUninitialized() ) evt.getByToken(tok,map[tok.index()]);
137 }
138 
140 setEvent(const edm::Event& evt) {
141  eles_by_oop.clear();
142  phos_by_oop.clear();
143  ele_vmaps.clear();
144  pho_vmaps.clear();
145 
146  ele_idx = pho_idx = 0;
147 
151 
152  for( unsigned i = 0; i < eles->size(); ++i ) {
153  edm::Ptr<pat::Electron> ptr = eles->ptrAt(i);
154  eles_by_oop[i] = ptr;
155  }
156  }
157 
169 
173 
174  for( unsigned i = 0; i < phos->size(); ++i ) {
175  edm::Ptr<pat::Photon> ptr = phos->ptrAt(i);
176  phos_by_oop[i] = ptr;
177  }
178  }
179 
191 
192 }
193 
196 }
197 
198 template<typename T, typename U, typename V>
199 inline void make_consumes(T& tag,U& tok,V& sume) { if( !(empty_tag == tag) ) tok = sume.template consumes<edm::ValueMap<float> >(tag); }
200 
203  //setup electrons
216 
217  // setup photons
230 }
231 
232 template<typename T, typename U, typename V>
233 inline void assignValue(const T& ptr, const U& tok, const V& map, float& value) {
234  if( !tok.isUninitialized() ) value = map.find(tok.index())->second->get(ptr.id(),ptr.key());
235 }
236 
239  // we encounter two cases here, either we are running AOD -> MINIAOD
240  // and the value maps are to the reducedEG object, can use original object ptr
241  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
244  auto key = eles_by_oop.find(ele_idx);
245  if( key != eles_by_oop.end() ) {
246  ptr = key->second;
247  } else {
248  throw cms::Exception("BadElectronKey")
249  << "Original object pointer with key = " << ele.originalObjectRef().key() << " not found in cache!";
250  }
251  }
252  //now we go through and modify the objects using the valuemaps we read in
253  auto full5x5 = ele.full5x5_showerShape();
254  assignValue(ptr,e_conf.tok_sigmaEtaEta,ele_vmaps,full5x5.sigmaEtaEta);
255  assignValue(ptr,e_conf.tok_sigmaIetaIeta,ele_vmaps,full5x5.sigmaIetaIeta);
256  assignValue(ptr,e_conf.tok_sigmaIphiIphi,ele_vmaps,full5x5.sigmaIphiIphi);
257  assignValue(ptr,e_conf.tok_e1x5,ele_vmaps,full5x5.e1x5);
258  assignValue(ptr,e_conf.tok_e2x5Max,ele_vmaps,full5x5.e2x5Max);
259  assignValue(ptr,e_conf.tok_e5x5,ele_vmaps,full5x5.e5x5);
260  assignValue(ptr,e_conf.tok_r9,ele_vmaps,full5x5.r9);
261  assignValue(ptr,e_conf.tok_hcalDepth1OverEcal,ele_vmaps,full5x5.hcalDepth1OverEcal);
262  assignValue(ptr,e_conf.tok_hcalDepth2OverEcal,ele_vmaps,full5x5.hcalDepth2OverEcal);
263  assignValue(ptr,e_conf.tok_hcalDepth1OverEcalBc,ele_vmaps,full5x5.hcalDepth1OverEcalBc);
264  assignValue(ptr,e_conf.tok_hcalDepth2OverEcalBc,ele_vmaps,full5x5.hcalDepth2OverEcalBc);
265 
266  ele.full5x5_setShowerShape(full5x5);
267  ++ele_idx;
268 }
269 
270 
273  // we encounter two cases here, either we are running AOD -> MINIAOD
274  // and the value maps are to the reducedEG object, can use original object ptr
275  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
278  auto key = phos_by_oop.find(pho_idx);
279  if( key != phos_by_oop.end() ) {
280  ptr = key->second;
281  } else {
282  throw cms::Exception("BadPhotonKey")
283  << "Original object pointer with key = " << pho.originalObjectRef().key() << " not found in cache!";
284  }
285  }
286  //now we go through and modify the objects using the valuemaps we read in
287  auto full5x5 = pho.full5x5_showerShapeVariables();
288  assignValue(ptr,ph_conf.tok_sigmaEtaEta,pho_vmaps,full5x5.sigmaEtaEta);
289  assignValue(ptr,ph_conf.tok_sigmaIetaIeta,pho_vmaps,full5x5.sigmaIetaIeta);
290  assignValue(ptr,ph_conf.tok_e1x5,pho_vmaps,full5x5.e1x5);
291  assignValue(ptr,ph_conf.tok_e2x5,pho_vmaps,full5x5.e2x5);
292  assignValue(ptr,ph_conf.tok_e3x3,pho_vmaps,full5x5.e3x3);
293  assignValue(ptr,ph_conf.tok_e5x5,pho_vmaps,full5x5.e5x5);
294  assignValue(ptr,ph_conf.tok_maxEnergyXtal,pho_vmaps,full5x5.maxEnergyXtal);
295  assignValue(ptr,ph_conf.tok_hcalDepth1OverEcal,pho_vmaps,full5x5.hcalDepth1OverEcal);
296  assignValue(ptr,ph_conf.tok_hcalDepth2OverEcal,pho_vmaps,full5x5.hcalDepth2OverEcal);
297  assignValue(ptr,ph_conf.tok_hcalDepth1OverEcalBc,pho_vmaps,full5x5.hcalDepth1OverEcalBc);
298  assignValue(ptr,ph_conf.tok_hcalDepth2OverEcalBc,pho_vmaps,full5x5.hcalDepth2OverEcalBc);
299 
300  pho.full5x5_setShowerShapeVariables(full5x5);
301  ++pho_idx;
302 }
edm::EDGetTokenT< edm::View< pat::Photon > > tok_photon_src
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
void setEventContent(const edm::EventSetup &) overridefinal
int i
Definition: DBlmapReader.cc:9
Analysis-level Photon class.
Definition: Photon.h:47
void setConsumes(edm::ConsumesCollector &) overridefinal
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth2OverEcalBc
void setEvent(const edm::Event &) overridefinal
key_type key() const
Definition: Ptr.h:169
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
std::unordered_map< unsigned, edm::Ptr< reco::Photon > > phos_by_oop
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::View< pat::Electron > > tok_electron_src
std::unordered_map< unsigned, edm::Ptr< reco::GsfElectron > > eles_by_oop
void modifyObject(pat::Electron &) const overridefinal
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth2OverEcalBc
U second(std::pair< T, U > const &p)
void assignValue(const T &ptr, const U &tok, const V &map, float &value)
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth2OverEcal
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > ele_vmaps
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth1OverEcal
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:484
tuple conf
Definition: dbtoconf.py:185
void get_product(const edm::Event &evt, const edm::EDGetTokenT< edm::ValueMap< float > > &tok, std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > &map)
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth1OverEcalBc
Analysis-level electron class.
Definition: Electron.h:52
string const
Definition: compareJSON.py:14
EGFull5x5ShowerShapeModifierFromValueMaps(const edm::ParameterSet &conf)
#define private
Definition: FWFileEntry.h:17
void full5x5_setShowerShapeVariables(const ShowerShape &a)
Definition: Photon.h:171
const ShowerShape & full5x5_showerShape() const
Definition: GsfElectron.h:431
const ShowerShape & full5x5_showerShapeVariables() const
Definition: Photon.h:168
bool isUninitialized() const
Definition: EDGetToken.h:71
#define DEFINE_EDM_PLUGIN(factory, type, name)
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth1OverEcalBc
void make_consumes(T &tag, U &tok, V &sume)
long double T
void full5x5_setShowerShape(const ShowerShape &s)
Definition: GsfElectron.h:435
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > pho_vmaps