23 #include <unordered_map>
36 k_clusterMaxDRRawEnergy,
54 static const std::vector<std::string> float_var_names( {
"sigmaIEtaIPhi",
64 "clusterMaxDRRawEnergy",
77 static const std::vector<std::string> integer_var_names( {
"iPhi",
"iEta" } );
80 std::unordered_map<std::string,float>&
map) {
84 std::unordered_map<std::string,int>&
map) {
89 inline void check_map(
const std::unordered_map<std::string,T>&
map,
unsigned exp_size) {
90 if( map.size() != exp_size ) {
92 <<
"variable map size: " << map.size()
93 <<
" not equal to expected size: " << exp_size <<
" !"
94 <<
" The regression variable calculation code definitely has a bug, fix it!";
98 template<
typename LazyTools>
102 std::unordered_map<std::string,float>& float_vars,
103 std::unordered_map<std::string,int>& int_vars ) {
104 LazyTools* tools =
static_cast<LazyTools*
>(tools_tocast);
106 const auto& the_sc = iEle->superCluster();
107 const auto& theseed = the_sc->seed();
109 const int numberOfClusters = the_sc->clusters().size();
110 const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].
isAvailable();
112 std::vector<float> vCov = tools->localCovariances( *theseed );
114 const float eMax = tools->eMax( *theseed );
115 const float e2nd = tools->e2nd( *theseed );
116 const float eTop = tools->eTop( *theseed );
117 const float eLeft = tools->eLeft( *theseed );
118 const float eRight = tools->eRight( *theseed );
119 const float eBottom = tools->eBottom( *theseed );
128 _ecalLocal.
localCoordsEB(*theseed, iSetup, cryEta, cryPhi, iEta, iPhi, dummy, dummy);
130 _ecalLocal.
localCoordsEE(*theseed, iSetup, cryEta, cryPhi, iEta, iPhi, dummy, dummy);
132 double see = (
isnan(vCov[0]) ? 0. :
sqrt(vCov[0]));
133 double spp = (
isnan(vCov[2]) ? 0. :
sqrt(vCov[2]));
136 sep = vCov[1] / (see * spp);
137 else if (vCov[1] > 0)
142 set_map_val(k_sigmaIEtaIPhi,sep,float_vars);
143 set_map_val(k_eMax,eMax,float_vars);
144 set_map_val(k_e2nd,e2nd,float_vars);
145 set_map_val(k_eTop,eTop,float_vars);
146 set_map_val(k_eBottom,eBottom,float_vars);
147 set_map_val(k_eLeft,eLeft,float_vars);
148 set_map_val(k_eRight,eRight,float_vars);
149 set_map_val(k_cryPhi,cryPhi,float_vars);
150 set_map_val(k_cryEta,cryEta,float_vars);
152 set_map_val(k_iPhi,iPhi,int_vars);
153 set_map_val(k_iEta,iEta,int_vars);
155 std::vector<float> _clusterRawEnergy;
156 _clusterRawEnergy.resize(
std::max(3, numberOfClusters), 0);
157 std::vector<float> _clusterDEtaToSeed;
158 _clusterDEtaToSeed.resize(
std::max(3, numberOfClusters), 0);
159 std::vector<float> _clusterDPhiToSeed;
160 _clusterDPhiToSeed.resize(
std::max(3, numberOfClusters), 0);
161 float _clusterMaxDR = 999.;
162 float _clusterMaxDRDPhi = 999.;
163 float _clusterMaxDRDEta = 999.;
164 float _clusterMaxDRRawEnergy = 0.;
169 if( !missing_clusters ) {
171 auto clusend = the_sc->clustersEnd();
172 for(
auto clus = the_sc->clustersBegin(); clus != clusend; ++clus ) {
175 if(theseed == pclus )
177 _clusterRawEnergy[iclus] = pclus->energy();
178 _clusterDPhiToSeed[iclus] =
reco::deltaPhi(pclus->phi(),theseed->phi());
179 _clusterDEtaToSeed[iclus] = pclus->eta() - theseed->eta();
184 _clusterMaxDR = maxDR;
185 _clusterMaxDRDPhi = _clusterDPhiToSeed[iclus];
186 _clusterMaxDRDEta = _clusterDEtaToSeed[iclus];
187 _clusterMaxDRRawEnergy = _clusterRawEnergy[iclus];
193 set_map_val(k_clusterMaxDR,_clusterMaxDR,float_vars);
194 set_map_val(k_clusterMaxDRDPhi,_clusterMaxDRDPhi,float_vars);
195 set_map_val(k_clusterMaxDRDEta,_clusterMaxDRDEta,float_vars);
196 set_map_val(k_clusterMaxDRRawEnergy,_clusterMaxDRRawEnergy,float_vars);
197 set_map_val(k_clusterRawEnergy0,_clusterRawEnergy[0],float_vars);
198 set_map_val(k_clusterRawEnergy1,_clusterRawEnergy[1],float_vars);
199 set_map_val(k_clusterRawEnergy2,_clusterRawEnergy[2],float_vars);
200 set_map_val(k_clusterDPhiToSeed0,_clusterDPhiToSeed[0],float_vars);
201 set_map_val(k_clusterDPhiToSeed1,_clusterDPhiToSeed[1],float_vars);
202 set_map_val(k_clusterDPhiToSeed2,_clusterDPhiToSeed[2],float_vars);
203 set_map_val(k_clusterDEtaToSeed0,_clusterDEtaToSeed[0],float_vars);
204 set_map_val(k_clusterDEtaToSeed1,_clusterDEtaToSeed[1],float_vars);
205 set_map_val(k_clusterDEtaToSeed2,_clusterDEtaToSeed[2],float_vars);
225 const std::vector<T> &
values,
246 use_full5x5_(iConfig.getParameter<bool>(
"useFull5x5")) {
252 (
"ebReducedRecHitCollection"));
254 (
"ebReducedRecHitCollectionMiniAOD"));
257 (
"eeReducedRecHitCollection"));
259 (
"eeReducedRecHitCollectionMiniAOD"));
262 (
"esReducedRecHitCollection"));
264 (
"esReducedRecHitCollectionMiniAOD"));
270 produces<edm::ValueMap<float> >(
name);
274 produces<edm::ValueMap<int> >(
name);
293 if( !
src.isValid() ) {
313 ebrh, eerh, esrh ) );
316 ebrh, eerh, esrh ) );
319 std::vector<std::vector<float> > float_vars(k_NFloatVars);
320 std::vector<std::vector<int> > int_vars(k_NIntVars);
322 std::unordered_map<std::string,float> float_vars_map;
323 std::unordered_map<std::string,int> int_vars_map;
326 for (
size_t i = 0;
i <
src->size(); ++
i){
327 auto iEle =
src->ptrAt(
i);
330 calculateValues<noZS::EcalClusterLazyTools>(
lazyTools.get(),
336 calculateValues<EcalClusterLazyTools>(
lazyTools.get(),
343 check_map(float_vars_map, k_NFloatVars);
344 check_map(int_vars_map, k_NIntVars);
346 for(
unsigned i = 0;
i < float_vars.size(); ++
i ) {
347 float_vars[
i].emplace_back(float_vars_map.at(float_var_names[
i]));
350 for(
unsigned i = 0;
i < int_vars.size(); ++
i ) {
351 int_vars[
i].emplace_back(int_vars_map.at(integer_var_names[
i]));
355 for(
unsigned i = 0;
i < float_vars.size(); ++
i ) {
359 for(
unsigned i = 0;
i < int_vars.size(); ++
i ) {
369 const std::vector<T> &
values,
376 auto_ptr<TValueMap> valMap(
new TValueMap());
377 typename TValueMap::Filler filler(*valMap);
378 filler.insert(
handle, values.begin(), values.end());
380 iEvent.
put(valMap, label);
T getParameter(std::string const &) const
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollection_
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::GsfElectron > > &handle, const std::vector< T > &values, const std::string &label) const
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollection_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
~ElectronRegressionValueMapProducer()
#define DEFINE_FWK_MODULE(type)
double deltaR(const T1 &t1, const T2 &t2)
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollectionMiniAOD_
void addDefault(ParameterSetDescription const &psetDescription)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollection_
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollectionMiniAOD_
std::unique_ptr< EcalClusterLazyToolsBase > lazyTools
edm::EDGetToken srcMiniAOD_
double deltaPhi(double phi1, double phi2)
ElectronRegressionValueMapProducer(const edm::ParameterSet &)
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollectionMiniAOD_
virtual void produce(edm::Event &, const edm::EventSetup &) override
void localCoordsEB(const reco::CaloCluster &bclus, const edm::EventSetup &es, float &etacry, float &phicry, int &ieta, int &iphi, float &thetatilt, float &phitilt) const
void localCoordsEE(const reco::CaloCluster &bclus, const edm::EventSetup &es, float &xcry, float &ycry, int &ix, int &iy, float &thetatilt, float &phitilt) const