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();
374 if( missing_clusters )
return ;
376 std::array<float, 33> eval;
377 const double raw_energy = the_sc->rawEnergy();
382 eval[1] = raw_energy;
383 eval[2] = the_sc->eta();
384 eval[3] = the_sc->phi();
385 eval[4] = the_sc->etaWidth();
386 eval[5] = the_sc->phiWidth();
388 eval[7] = theseed->energy()/raw_energy;
389 eval[8] = ess.eMax/raw_energy;
390 eval[9] = ess.e2nd/raw_energy;
391 eval[10] = (ess.eLeft + ess.eRight != 0.f ? (ess.eLeft-ess.eRight)/(ess.eLeft+ess.eRight) : 0.f);
392 eval[11] = (ess.eTop + ess.eBottom != 0.f ? (ess.eTop-ess.eBottom)/(ess.eTop+ess.eBottom) : 0.f);
393 eval[12] = ess.sigmaIetaIeta;
394 eval[13] = ess.sigmaIetaIphi;
395 eval[14] = ess.sigmaIphiIphi;
396 eval[15] =
std::max(0,numberOfClusters-1);
399 std::vector<float> clusterRawEnergy;
400 clusterRawEnergy.resize(
std::max(3, numberOfClusters), 0);
401 std::vector<float> clusterDEtaToSeed;
402 clusterDEtaToSeed.resize(
std::max(3, numberOfClusters), 0);
403 std::vector<float> clusterDPhiToSeed;
404 clusterDPhiToSeed.resize(
std::max(3, numberOfClusters), 0);
405 float clusterMaxDR = 999.;
406 float clusterMaxDRDPhi = 999.;
407 float clusterMaxDRDEta = 999.;
408 float clusterMaxDRRawEnergy = 0.;
414 auto clusend = the_sc->clustersEnd();
415 for(
auto clus = the_sc->clustersBegin(); clus != clusend; ++clus ) {
418 if(theseed == pclus )
420 clusterRawEnergy[iclus] = pclus->energy();
421 clusterDPhiToSeed[iclus] =
reco::deltaPhi(pclus->phi(),theseed->phi());
422 clusterDEtaToSeed[iclus] = pclus->eta() - theseed->eta();
428 clusterMaxDR = maxDR;
429 clusterMaxDRDPhi = clusterDPhiToSeed[iclus];
430 clusterMaxDRDEta = clusterDEtaToSeed[iclus];
431 clusterMaxDRRawEnergy = clusterRawEnergy[iclus];
436 eval[16] = clusterMaxDR;
437 eval[17] = clusterMaxDRDPhi;
438 eval[18] = clusterMaxDRDEta;
439 eval[19] = clusterMaxDRRawEnergy/raw_energy;
440 eval[20] = clusterRawEnergy[0]/raw_energy;
441 eval[21] = clusterRawEnergy[1]/raw_energy;
442 eval[22] = clusterRawEnergy[2]/raw_energy;
443 eval[23] = clusterDPhiToSeed[0];
444 eval[24] = clusterDPhiToSeed[1];
445 eval[25] = clusterDPhiToSeed[2];
446 eval[26] = clusterDEtaToSeed[0];
447 eval[27] = clusterDEtaToSeed[1];
448 eval[28] = clusterDEtaToSeed[2];
451 const bool iseb = ele.
isEB();
469 eval[29] = the_sc->preshowerEnergy()/the_sc->rawEnergy();
476 constexpr double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
477 constexpr double meanscale = 0.5*(meanlimhigh-meanlimlow);
481 constexpr double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
482 constexpr double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
493 double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
494 double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
498 double ecor = mean*(eval[1]);
500 ecor = mean*(eval[1]+the_sc->preshowerEnergy());
501 const double sigmacor = sigma*ecor;
511 const float tot_energy = the_sc->rawEnergy()+the_sc->preshowerEnergy();
514 const float eOverP = tot_energy*mean/ep;
515 eval_ep[0] = tot_energy*
mean;
516 eval_ep[1] = sigma/
mean;
518 eval_ep[3] = trkMomentumRelError;
519 eval_ep[4] = sigma/mean/trkMomentumRelError;
520 eval_ep[5] = tot_energy*mean/ep;
521 eval_ep[6] = tot_energy*mean/ep*
sqrt(sigma/mean*sigma/mean+trkMomentumRelError*trkMomentumRelError);
535 if ( eOverP > 0.025 &&
536 std::abs(ep-ecor) < 15.*
std::sqrt( momentumError*momentumError + sigmacor*sigmacor ) &&
552 oldMomentum.y()*combinedMomentum/oldMomentum.t(),
553 oldMomentum.z()*combinedMomentum/oldMomentum.t(),
567 std::array<float, 35> eval;
571 const int numberOfClusters = the_sc->clusters().size();
572 const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].
isAvailable();
574 if( missing_clusters )
return ;
576 const double raw_energy = the_sc->rawEnergy();
580 eval[0] = raw_energy;
582 eval[2] = the_sc->etaWidth();
583 eval[3] = the_sc->phiWidth();
584 eval[4] =
std::max(0,numberOfClusters - 1);
588 eval[8] = theseed->eta()-the_sc->position().Eta();
589 eval[9] =
reco::deltaPhi(theseed->phi(),the_sc->position().Phi());
590 eval[10] = theseed->energy()/raw_energy;
591 eval[11] = ess.e3x3/ess.e5x5;
592 eval[12] = ess.sigmaIetaIeta;
593 eval[13] = ess.sigmaIphiIphi;
594 eval[14] = ess.sigmaIetaIphi/(ess.sigmaIphiIphi*ess.sigmaIetaIeta);
595 eval[15] = ess.maxEnergyXtal/ess.e5x5;
596 eval[16] = ess.e2nd/ess.e5x5;
597 eval[17] = ess.eTop/ess.e5x5;
598 eval[18] = ess.eBottom/ess.e5x5;
599 eval[19] = ess.eLeft/ess.e5x5;
600 eval[20] = ess.eRight/ess.e5x5;
601 eval[21] = ess.e2x5Max/ess.e5x5;
602 eval[22] = ess.e2x5Left/ess.e5x5;
603 eval[23] = ess.e2x5Right/ess.e5x5;
604 eval[24] = ess.e2x5Top/ess.e5x5;
605 eval[25] = ess.e2x5Bottom/ess.e5x5;
607 const bool iseb = pho.
isEB();
609 EBDetId ebseedid(theseed->seed());
610 eval[26] = pho.
e5x5()/theseed->energy();
611 int ieta = ebseedid.ieta();
612 int iphi = ebseedid.iphi();
615 int signieta = ieta > 0 ? +1 : -1;
616 eval[29] = (ieta-signieta)%5;
617 eval[30] = (iphi-1)%2;
619 eval[31] = (
abs(ieta)<=25)*((ieta-signieta)) + (
abs(ieta)>25)*((ieta-26*signieta)%20);
620 eval[32] = (iphi-1)%20;
624 EEDetId eeseedid(theseed->seed());
625 eval[26] = the_sc->preshowerEnergy()/raw_energy;
626 eval[27] = the_sc->preshowerEnergyPlane1()/raw_energy;
627 eval[28] = the_sc->preshowerEnergyPlane2()/raw_energy;
628 eval[29] = eeseedid.ix();
629 eval[30] = eeseedid.iy();
634 const double meanlimlow = 0.2;
635 const double meanlimhigh = 2.0;
636 const double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
637 const double meanscale = 0.5*(meanlimhigh-meanlimlow);
639 const double sigmalimlow = 0.0002;
640 const double sigmalimhigh = 0.5;
641 const double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
642 const double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
652 double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
653 double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
657 double ecor = mean*eval[0];
659 ecor = mean*(eval[0]+the_sc->preshowerEnergy());
661 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