20 #include <vdt/vdtMath.h>
26 #include <unordered_map>
66 void setConsumes(edm::ConsumesCollector&) override final;
109 "EGExtraInfoModifierFromDB");
115 autoDetectBunchSpacing_ = conf.getParameter<
bool>(
"autoDetectBunchSpacing");
116 applyExtraHighEnergyProtection_ = conf.getParameter<
bool>(
"applyExtraHighEnergyProtection");
119 vtxTag_ = conf.getParameter<
edm::InputTag>(
"vertexCollection");
121 if (autoDetectBunchSpacing_) {
122 bunchspacingTag_ = conf.getParameter<
edm::InputTag>(
"bunchSpacingTag");
124 bunchspacing_ = conf.getParameter<
int>(
"manualBunchSpacing");
127 constexpr char electronSrc[] =
"electronSrc";
128 constexpr char photonSrc[] =
"photonSrc";
130 if(conf.exists(
"electron_config")) {
132 if( electrons.
exists(electronSrc) )
135 std::vector<std::string> intValueMaps;
136 if ( electrons.
existsAs<std::vector<std::string> >(
"intValueMaps"))
137 intValueMaps = electrons.
getParameter<std::vector<std::string> >(
"intValueMaps");
144 for (
auto vmp : intValueMaps) {
162 if( conf.exists(
"photon_config") ) {
165 if( photons.
exists(photonSrc) )
168 std::vector<std::string> intValueMaps;
169 if ( photons.
existsAs<std::vector<std::string> >(
"intValueMaps"))
170 intValueMaps = photons.
getParameter<std::vector<std::string> >(
"intValueMaps");
177 for (
auto vmp : intValueMaps) {
196 inline void get_product(
const edm::Event& evt,
215 for(
unsigned i = 0;
i < eles->size(); ++
i ) {
224 get_product(evt, imap->second.second,
ele_vmaps);
237 for(
unsigned i = 0;
i < phos->size(); ++
i ) {
247 get_product(evt, imap->second.second,
pho_vmaps);
280 unsigned int ncor = ph_condnames_mean.size();
281 for (
unsigned int icor=0; icor<ncor; ++icor) {
292 unsigned int encor = e_condnames_mean.size();
296 for (
unsigned int icor=0; icor<encor; ++icor) {
305 template<
typename T,
typename U,
typename V>
306 inline void make_consumes(
T&
tag,U& tok,V& sume) {
307 if(!(empty_tag == tag))
308 tok = sume.template consumes<edm::ValueMap<float> >(
tag);
311 template<
typename T,
typename U,
typename V>
312 inline void make_int_consumes(
T& tag,U& tok,V& sume) {
313 if(!(empty_tag == tag))
314 tok = sume.template consumes<edm::ValueMap<int> >(
tag);
333 make_consumes(imap->second.first, imap->second.second, sumes);
336 for ( std::unordered_map<std::string, ValMapIntTagTokenPair>::iterator imap =
e_conf.
tag_int_token_map.begin();
339 make_int_consumes(imap->second.first, imap->second.second, sumes);
349 make_consumes(imap->second.first, imap->second.second, sumes);
355 make_int_consumes(imap->second.first, imap->second.second, sumes);
360 template<
typename T,
typename U,
typename V,
typename Z>
361 inline void assignValue(
const T& ptr,
const U& tok,
const V& map,
Z&
value) {
362 if( !tok.isUninitialized() ) value = map.find(tok.index())->
second->get(ptr.id(),ptr.key());
371 const int numberOfClusters = the_sc->clusters().size();
372 const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].
isAvailable();
377 if( missing_clusters )
return ;
379 std::array<float, 33> eval;
380 const double raw_energy = the_sc->rawEnergy();
385 eval[1] = raw_energy;
386 eval[2] = the_sc->eta();
387 eval[3] = the_sc->phi();
388 eval[4] = the_sc->etaWidth();
389 eval[5] = the_sc->phiWidth();
391 eval[7] = theseed->energy()/raw_energy;
392 eval[8] = ess.eMax/raw_energy;
393 eval[9] = ess.e2nd/raw_energy;
394 eval[10] = (ess.eLeft + ess.eRight != 0.f ? (ess.eLeft-ess.eRight)/(ess.eLeft+ess.eRight) : 0.f);
395 eval[11] = (ess.eTop + ess.eBottom != 0.f ? (ess.eTop-ess.eBottom)/(ess.eTop+ess.eBottom) : 0.f);
396 eval[12] = ess.sigmaIetaIeta;
397 eval[13] = ess.sigmaIetaIphi;
398 eval[14] = ess.sigmaIphiIphi;
399 eval[15] =
std::max(0,numberOfClusters-1);
402 std::vector<float> clusterRawEnergy;
403 clusterRawEnergy.resize(
std::max(3, numberOfClusters), 0);
404 std::vector<float> clusterDEtaToSeed;
405 clusterDEtaToSeed.resize(
std::max(3, numberOfClusters), 0);
406 std::vector<float> clusterDPhiToSeed;
407 clusterDPhiToSeed.resize(
std::max(3, numberOfClusters), 0);
408 float clusterMaxDR = 999.;
409 float clusterMaxDRDPhi = 999.;
410 float clusterMaxDRDEta = 999.;
411 float clusterMaxDRRawEnergy = 0.;
417 auto clusend = the_sc->clustersEnd();
418 for(
auto clus = the_sc->clustersBegin(); clus != clusend; ++clus ) {
421 if(theseed == pclus )
423 clusterRawEnergy[iclus] = pclus->energy();
424 clusterDPhiToSeed[iclus] =
reco::deltaPhi(pclus->phi(),theseed->phi());
425 clusterDEtaToSeed[iclus] = pclus->eta() - theseed->eta();
431 clusterMaxDR = maxDR;
432 clusterMaxDRDPhi = clusterDPhiToSeed[iclus];
433 clusterMaxDRDEta = clusterDEtaToSeed[iclus];
434 clusterMaxDRRawEnergy = clusterRawEnergy[iclus];
439 eval[16] = clusterMaxDR;
440 eval[17] = clusterMaxDRDPhi;
441 eval[18] = clusterMaxDRDEta;
442 eval[19] = clusterMaxDRRawEnergy/raw_energy;
443 eval[20] = clusterRawEnergy[0]/raw_energy;
444 eval[21] = clusterRawEnergy[1]/raw_energy;
445 eval[22] = clusterRawEnergy[2]/raw_energy;
446 eval[23] = clusterDPhiToSeed[0];
447 eval[24] = clusterDPhiToSeed[1];
448 eval[25] = clusterDPhiToSeed[2];
449 eval[26] = clusterDEtaToSeed[0];
450 eval[27] = clusterDEtaToSeed[1];
451 eval[28] = clusterDEtaToSeed[2];
454 const bool iseb = ele.
isEB();
472 eval[29] = the_sc->preshowerEnergy()/the_sc->rawEnergy();
479 constexpr double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
480 constexpr double meanscale = 0.5*(meanlimhigh-meanlimlow);
484 constexpr double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
485 constexpr double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
496 double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
497 double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
501 double ecor = mean*(eval[1]);
503 ecor = mean*(eval[1]+the_sc->preshowerEnergy());
504 const double sigmacor = sigma*ecor;
514 const float tot_energy = the_sc->rawEnergy()+the_sc->preshowerEnergy();
517 const float eOverP = tot_energy*mean/ep;
518 eval_ep[0] = tot_energy*
mean;
519 eval_ep[1] = sigma/
mean;
521 eval_ep[3] = trkMomentumRelError;
522 eval_ep[4] = sigma/mean/trkMomentumRelError;
523 eval_ep[5] = tot_energy*mean/ep;
524 eval_ep[6] = tot_energy*mean/ep*
sqrt(sigma/mean*sigma/mean+trkMomentumRelError*trkMomentumRelError);
538 if ( eOverP > 0.025 &&
539 std::abs(ep-ecor) < 15.*
std::sqrt( momentumError*momentumError + sigmacor*sigmacor ) &&
555 oldMomentum.y()*combinedMomentum/oldMomentum.t(),
556 oldMomentum.z()*combinedMomentum/oldMomentum.t(),
570 std::array<float, 35> eval;
574 const int numberOfClusters = the_sc->clusters().size();
575 const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].
isAvailable();
579 if( missing_clusters )
return ;
581 const double raw_energy = the_sc->rawEnergy();
585 eval[0] = raw_energy;
587 eval[2] = the_sc->etaWidth();
588 eval[3] = the_sc->phiWidth();
589 eval[4] =
std::max(0,numberOfClusters - 1);
593 eval[8] = theseed->eta()-the_sc->position().Eta();
594 eval[9] =
reco::deltaPhi(theseed->phi(),the_sc->position().Phi());
595 eval[10] = theseed->energy()/raw_energy;
596 eval[11] = ess.e3x3/ess.e5x5;
597 eval[12] = ess.sigmaIetaIeta;
598 eval[13] = ess.sigmaIphiIphi;
599 eval[14] = ess.sigmaIetaIphi/(ess.sigmaIphiIphi*ess.sigmaIetaIeta);
600 eval[15] = ess.maxEnergyXtal/ess.e5x5;
601 eval[16] = ess.e2nd/ess.e5x5;
602 eval[17] = ess.eTop/ess.e5x5;
603 eval[18] = ess.eBottom/ess.e5x5;
604 eval[19] = ess.eLeft/ess.e5x5;
605 eval[20] = ess.eRight/ess.e5x5;
606 eval[21] = ess.e2x5Max/ess.e5x5;
607 eval[22] = ess.e2x5Left/ess.e5x5;
608 eval[23] = ess.e2x5Right/ess.e5x5;
609 eval[24] = ess.e2x5Top/ess.e5x5;
610 eval[25] = ess.e2x5Bottom/ess.e5x5;
612 const bool iseb = pho.
isEB();
614 EBDetId ebseedid(theseed->seed());
615 eval[26] = pho.
e5x5()/theseed->energy();
616 int ieta = ebseedid.ieta();
617 int iphi = ebseedid.iphi();
620 int signieta = ieta > 0 ? +1 : -1;
621 eval[29] = (ieta-signieta)%5;
622 eval[30] = (iphi-1)%2;
624 eval[31] = (
abs(ieta)<=25)*((ieta-signieta)) + (
abs(ieta)>25)*((ieta-26*signieta)%20);
625 eval[32] = (iphi-1)%20;
629 EEDetId eeseedid(theseed->seed());
630 eval[26] = the_sc->preshowerEnergy()/raw_energy;
631 eval[27] = the_sc->preshowerEnergyPlane1()/raw_energy;
632 eval[28] = the_sc->preshowerEnergyPlane2()/raw_energy;
633 eval[29] = eeseedid.ix();
634 eval[30] = eeseedid.iy();
639 const double meanlimlow = 0.2;
640 const double meanlimhigh = 2.0;
641 const double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
642 const double meanscale = 0.5*(meanlimhigh-meanlimlow);
644 const double sigmalimlow = 0.0002;
645 const double sigmalimhigh = 0.5;
646 const double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
647 const double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
657 double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
658 double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
662 double ecor = mean*eval[0];
664 ecor = mean*(eval[0]+the_sc->preshowerEnergy());
666 double sigmacor = sigma*ecor;
const double Z[kNumberCalorimeter]
double GetResponse(const float *vector) const
const ShowerShape & showerShape() const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Analysis-level Photon class.
float trackMomentumError() const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
const LorentzVector & p4(P4Kind kind) const
reco::SuperClusterRef superCluster() const
Ref to SuperCluster.
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
math::XYZVectorF trackMomentumAtVtx() const
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::vector< Vertex > VertexCollection
collection of Vertex objects
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
void setCorrectedEcalEnergyError(float newEnergyError)
const std::string & name() const
virtual SuperClusterRef superCluster() const
reference to a SuperCluster
Abs< T >::type abs(const T &t)
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
float hadronicOverEm() const
the total hadronic over electromagnetic fraction
std::vector< std::string > getParameterNames() const
double deltaPhi(double phi1, double phi2)
Classification classification() const
T const * product() const
Analysis-level electron class.
void localCoordsEB(const reco::CaloCluster &bclus, const edm::EventSetup &es, float &etacry, float &phicry, int &ieta, int &iphi, float &thetatilt, float &phitilt) const
return(e1-e2)*(e1-e2)+dp *dp
void setCorrectedEcalEnergy(float newEnergy)
bool trackerDrivenSeed() const
bool isUninitialized() const
#define DEFINE_EDM_PLUGIN(factory, type, name)
void localCoordsEE(const reco::CaloCluster &bclus, const edm::EventSetup &es, float &xcry, float &ycry, int &ix, int &iy, float &thetatilt, float &phitilt) const
const ShowerShape & showerShapeVariables() const