CMS 3D CMS Logo

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 edm::InputTag empty_tag("");
13  template<typename T, typename U, typename V>
14  inline void make_consumes(const T& tag, edm::EDGetTokenT<U>& tok,V& sume) { if( !(empty_tag == tag) ) tok = sume.template consumes<U>(tag); }
15 }
16 
17 #include <unordered_map>
18 
20 public:
21  struct electron_config {
34  };
35 
36  struct photon_config {
49  };
50 
52 
53  void setEvent(const edm::Event&) final;
54  void setEventContent(const edm::EventSetup&) final;
55 
56  void modifyObject(pat::Electron&) const final;
57  void modifyObject(pat::Photon&) const final;
58 
59 private:
62  std::vector<edm::Ptr<reco::GsfElectron>> eles_by_oop; // indexed by original object ptr
63  std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > > ele_vmaps;
64  std::vector<edm::Ptr<reco::Photon>> phos_by_oop;
65  std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > > pho_vmaps;
66  mutable unsigned ele_idx,pho_idx; // hack here until we figure out why some slimmedPhotons don't have original object ptrs
67 };
68 
71  "EGFull5x5ShowerShapeModifierFromValueMaps");
72 
73 EGFull5x5ShowerShapeModifierFromValueMaps::
74 EGFull5x5ShowerShapeModifierFromValueMaps(const edm::ParameterSet& conf, edm::ConsumesCollector& cc) :
75  ModifyObjectValueBase(conf) {
76  if( conf.exists("electron_config") ) {
77  const edm::ParameterSet& electrons = conf.getParameter<edm::ParameterSet>("electron_config");
78  if( electrons.exists("electronSrc") ) make_consumes(electrons.getParameter<edm::InputTag>("electronSrc"), e_conf.tok_electron_src, cc);
79  if( electrons.exists("sigmaEtaEta") ) make_consumes(electrons.getParameter<edm::InputTag>("sigmaEtaEta"), e_conf.tok_sigmaEtaEta, cc);
80  if( electrons.exists("sigmaIetaIeta") ) make_consumes(electrons.getParameter<edm::InputTag>("sigmaIetaIeta"), e_conf.tok_sigmaIetaIeta, cc);
81  if( electrons.exists("sigmaIphiIphi") ) make_consumes(electrons.getParameter<edm::InputTag>("sigmaIphiIphi"), e_conf.tok_sigmaIphiIphi, cc);
82  if( electrons.exists("e1x5") ) make_consumes(electrons.getParameter<edm::InputTag>("e1x5"), e_conf.tok_e1x5, cc);
83  if( electrons.exists("e2x5Max") ) make_consumes(electrons.getParameter<edm::InputTag>("e2x5Max"), e_conf.tok_e2x5Max, cc);
84  if( electrons.exists("e5x5") ) make_consumes(electrons.getParameter<edm::InputTag>("e5x5"), e_conf.tok_e5x5, cc);
85  if( electrons.exists("r9") ) make_consumes(electrons.getParameter<edm::InputTag>("r9"), e_conf.tok_r9, cc);
86  if( electrons.exists("hcalDepth1OverEcal") ) make_consumes(electrons.getParameter<edm::InputTag>("hcalDepth1OverEcal"), e_conf.tok_hcalDepth1OverEcal, cc);
87  if( electrons.exists("hcalDepth2OverEcal") ) make_consumes(electrons.getParameter<edm::InputTag>("hcalDepth2OverEcal"), e_conf.tok_hcalDepth2OverEcal, cc);
88  if( electrons.exists("hcalDepth1OverEcalBc") ) make_consumes(electrons.getParameter<edm::InputTag>("hcalDepth1OverEcalBc"), e_conf.tok_hcalDepth1OverEcalBc, cc);
89  if( electrons.exists("hcalDepth2OverEcalBc") ) make_consumes(electrons.getParameter<edm::InputTag>("hcalDepth2OverEcalBc"), e_conf.tok_hcalDepth2OverEcalBc, cc);
90  }
91  if( conf.exists("photon_config") ) {
92  const edm::ParameterSet& photons = conf.getParameter<edm::ParameterSet>("photon_config");
93  if( photons.exists("photonSrc") ) make_consumes(photons.getParameter<edm::InputTag>("photonSrc"), ph_conf.tok_photon_src, cc);
94  if( photons.exists("sigmaEtaEta") ) make_consumes(photons.getParameter<edm::InputTag>("sigmaEtaEta"), ph_conf.tok_sigmaEtaEta, cc);
95  if( photons.exists("sigmaIetaIeta") ) make_consumes(photons.getParameter<edm::InputTag>("sigmaIetaIeta"), ph_conf.tok_sigmaIetaIeta, cc);
96  if( photons.exists("e1x5") ) make_consumes(photons.getParameter<edm::InputTag>("e1x5"), ph_conf.tok_e1x5, cc);
97  if( photons.exists("e2x5") ) make_consumes(photons.getParameter<edm::InputTag>("e2x5"), ph_conf.tok_e2x5, cc);
98  if( photons.exists("e3x3") ) make_consumes(photons.getParameter<edm::InputTag>("e3x3"), ph_conf.tok_e3x3, cc);
99  if( photons.exists("e5x5") ) make_consumes(photons.getParameter<edm::InputTag>("e5x5"), ph_conf.tok_e5x5, cc);
100  if( photons.exists("maxEnergyXtal") ) make_consumes(photons.getParameter<edm::InputTag>("maxEnergyXtal"), ph_conf.tok_maxEnergyXtal, cc);
101  if( photons.exists("hcalDepth1OverEcal") ) make_consumes(photons.getParameter<edm::InputTag>("hcalDepth1OverEcal"), ph_conf.tok_hcalDepth1OverEcal, cc);
102  if( photons.exists("hcalDepth2OverEcal") ) make_consumes(photons.getParameter<edm::InputTag>("hcalDepth2OverEcal"), ph_conf.tok_hcalDepth2OverEcal, cc);
103  if( photons.exists("hcalDepth1OverEcalBc") ) make_consumes(photons.getParameter<edm::InputTag>("hcalDepth1OverEcalBc"), ph_conf.tok_hcalDepth1OverEcalBc, cc);
104  if( photons.exists("hcalDepth2OverEcalBc") ) make_consumes(photons.getParameter<edm::InputTag>("hcalDepth2OverEcalBc"), ph_conf.tok_hcalDepth2OverEcalBc, cc);
105  }
106 
107  ele_idx = pho_idx = 0;
108 }
109 
110 namespace {
111  inline void get_product(const edm::Event& evt,
113  std::unordered_map<unsigned, edm::Handle<edm::ValueMap<float> > >& map) {
114  if( !tok.isUninitialized() ) evt.getByToken(tok,map[tok.index()]);
115  }
116 }
117 
119 setEvent(const edm::Event& evt) {
120  eles_by_oop.clear();
121  phos_by_oop.clear();
122  ele_vmaps.clear();
123  pho_vmaps.clear();
124 
125  ele_idx = pho_idx = 0;
126 
130 
131  eles_by_oop.resize(eles->size());
132  std::copy(eles->ptrs().begin(), eles->ptrs().end(), eles_by_oop.begin());
133  }
134 
135  get_product(evt,e_conf.tok_sigmaEtaEta,ele_vmaps);
136  get_product(evt,e_conf.tok_sigmaIetaIeta,ele_vmaps);
137  get_product(evt,e_conf.tok_sigmaIphiIphi,ele_vmaps);
138  get_product(evt,e_conf.tok_e1x5,ele_vmaps);
139  get_product(evt,e_conf.tok_e2x5Max,ele_vmaps);
140  get_product(evt,e_conf.tok_e5x5,ele_vmaps);
141  get_product(evt,e_conf.tok_r9,ele_vmaps);
142  get_product(evt,e_conf.tok_hcalDepth1OverEcal,ele_vmaps);
143  get_product(evt,e_conf.tok_hcalDepth2OverEcal,ele_vmaps);
144  get_product(evt,e_conf.tok_hcalDepth1OverEcalBc,ele_vmaps);
145  get_product(evt,e_conf.tok_hcalDepth2OverEcalBc,ele_vmaps);
146 
150 
151  phos_by_oop.resize(phos->size());
152  std::copy(phos->ptrs().begin(), phos->ptrs().end(), phos_by_oop.begin());
153  }
154 
155  get_product(evt,ph_conf.tok_sigmaEtaEta,pho_vmaps);
156  get_product(evt,ph_conf.tok_sigmaIetaIeta,pho_vmaps);
157  get_product(evt,ph_conf.tok_e1x5,pho_vmaps);
158  get_product(evt,ph_conf.tok_e2x5,pho_vmaps);
159  get_product(evt,ph_conf.tok_e3x3,pho_vmaps);
160  get_product(evt,ph_conf.tok_e5x5,pho_vmaps);
161  get_product(evt,ph_conf.tok_maxEnergyXtal,pho_vmaps);
162  get_product(evt,ph_conf.tok_hcalDepth1OverEcal,pho_vmaps);
163  get_product(evt,ph_conf.tok_hcalDepth2OverEcal,pho_vmaps);
164  get_product(evt,ph_conf.tok_hcalDepth1OverEcalBc,pho_vmaps);
165  get_product(evt,ph_conf.tok_hcalDepth2OverEcalBc,pho_vmaps);
166 
167 }
168 
171 }
172 
173 namespace {
174  template<typename T, typename U, typename V>
175  inline void assignValue(const T& ptr, const U& tok, const V& map, float& value) {
176  if( !tok.isUninitialized() ) value = map.find(tok.index())->second->get(ptr.id(),ptr.key());
177  }
178 }
179 
182  // we encounter two cases here, either we are running AOD -> MINIAOD
183  // and the value maps are to the reducedEG object, can use original object ptr
184  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
186 
187 
188  // The calls to this function should be matched to the order of the electrons
189  // in eles_by_oop. In case it is called too many times, it will throw thanks
190  // to the use of std::vector<T>::at().
192 
193  //now we go through and modify the objects using the valuemaps we read in
194  auto full5x5 = ele.full5x5_showerShape();
195  assignValue(ptr,e_conf.tok_sigmaEtaEta,ele_vmaps,full5x5.sigmaEtaEta);
196  assignValue(ptr,e_conf.tok_sigmaIetaIeta,ele_vmaps,full5x5.sigmaIetaIeta);
197  assignValue(ptr,e_conf.tok_sigmaIphiIphi,ele_vmaps,full5x5.sigmaIphiIphi);
198  assignValue(ptr,e_conf.tok_e1x5,ele_vmaps,full5x5.e1x5);
199  assignValue(ptr,e_conf.tok_e2x5Max,ele_vmaps,full5x5.e2x5Max);
200  assignValue(ptr,e_conf.tok_e5x5,ele_vmaps,full5x5.e5x5);
201  assignValue(ptr,e_conf.tok_r9,ele_vmaps,full5x5.r9);
202  assignValue(ptr,e_conf.tok_hcalDepth1OverEcal,ele_vmaps,full5x5.hcalDepth1OverEcal);
203  assignValue(ptr,e_conf.tok_hcalDepth2OverEcal,ele_vmaps,full5x5.hcalDepth2OverEcal);
204  assignValue(ptr,e_conf.tok_hcalDepth1OverEcalBc,ele_vmaps,full5x5.hcalDepth1OverEcalBc);
205  assignValue(ptr,e_conf.tok_hcalDepth2OverEcalBc,ele_vmaps,full5x5.hcalDepth2OverEcalBc);
206 
207  ele.full5x5_setShowerShape(full5x5);
208  ++ele_idx;
209 }
210 
211 
214  // we encounter two cases here, either we are running AOD -> MINIAOD
215  // and the value maps are to the reducedEG object, can use original object ptr
216  // or we are running MINIAOD->MINIAOD and we need to fetch the pat objects to reference
218 
219  // The calls to this function should be matched to the order of the electrons
220  // in eles_by_oop. In case it is called too many times, it will throw thanks
221  // to the use of std::vector<T>::at().
223 
224  //now we go through and modify the objects using the valuemaps we read in
225  auto full5x5 = pho.full5x5_showerShapeVariables();
226  assignValue(ptr,ph_conf.tok_sigmaEtaEta,pho_vmaps,full5x5.sigmaEtaEta);
227  assignValue(ptr,ph_conf.tok_sigmaIetaIeta,pho_vmaps,full5x5.sigmaIetaIeta);
228  assignValue(ptr,ph_conf.tok_e1x5,pho_vmaps,full5x5.e1x5);
229  assignValue(ptr,ph_conf.tok_e2x5,pho_vmaps,full5x5.e2x5);
230  assignValue(ptr,ph_conf.tok_e3x3,pho_vmaps,full5x5.e3x3);
231  assignValue(ptr,ph_conf.tok_e5x5,pho_vmaps,full5x5.e5x5);
232  assignValue(ptr,ph_conf.tok_maxEnergyXtal,pho_vmaps,full5x5.maxEnergyXtal);
233  assignValue(ptr,ph_conf.tok_hcalDepth1OverEcal,pho_vmaps,full5x5.hcalDepth1OverEcal);
234  assignValue(ptr,ph_conf.tok_hcalDepth2OverEcal,pho_vmaps,full5x5.hcalDepth2OverEcal);
235  assignValue(ptr,ph_conf.tok_hcalDepth1OverEcalBc,pho_vmaps,full5x5.hcalDepth1OverEcalBc);
236  assignValue(ptr,ph_conf.tok_hcalDepth2OverEcalBc,pho_vmaps,full5x5.hcalDepth2OverEcalBc);
237 
238  pho.full5x5_setShowerShapeVariables(full5x5);
239  ++pho_idx;
240 }
edm::EDGetTokenT< edm::View< pat::Photon > > tok_photon_src
T getParameter(std::string const &) const
Analysis-level Photon class.
Definition: Photon.h:47
EGFull5x5ShowerShapeModifierFromValueMaps(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
Definition: Photon.py:1
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth2OverEcalBc
def copy(args, dbName)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
unsigned int index() const
Definition: EDGetToken.h:69
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::EDGetTokenT< edm::View< pat::Electron > > tok_electron_src
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth2OverEcalBc
Definition: HeavyIon.h:7
U second(std::pair< T, U > const &p)
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
Definition: value.py:1
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
Definition: PATObject.h:500
std::vector< edm::Ptr< reco::Photon > > phos_by_oop
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth1OverEcalBc
void setEventContent(const edm::EventSetup &) final
Analysis-level electron class.
Definition: Electron.h:52
void full5x5_setShowerShapeVariables(const ShowerShape &a)
Definition: Photon.h:209
const ShowerShape & full5x5_showerShape() const
Definition: GsfElectron.h:483
fixed size matrix
HLT enums.
const ShowerShape & full5x5_showerShapeVariables() const
Definition: Photon.h:206
std::vector< edm::Ptr< reco::GsfElectron > > eles_by_oop
bool isUninitialized() const
Definition: EDGetToken.h:70
#define DEFINE_EDM_PLUGIN(factory, type, name)
edm::EDGetTokenT< edm::ValueMap< float > > tok_hcalDepth1OverEcalBc
long double T
void full5x5_setShowerShape(const ShowerShape &s)
Definition: GsfElectron.h:487
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > pho_vmaps