25 #include <vdt/vdtMath.h>
31 #include <unordered_map>
67 void setConsumes(edm::ConsumesCollector&) override final;
119 "EGExtraInfoModifierFromDBUser");
124 lowEnergy_ECALonlyThr_ = conf.getParameter<
double>(
"lowEnergy_ECALonlyThr");
125 lowEnergy_ECALTRKThr_ = conf.getParameter<
double>(
"lowEnergy_ECALTRKThr");
126 highEnergy_ECALTRKThr_ = conf.getParameter<
double>(
"highEnergy_ECALTRKThr");
127 eOverP_ECALTRKThr_ = conf.getParameter<
double>(
"eOverP_ECALTRKThr");
128 epDiffSig_ECALTRKThr_ = conf.getParameter<
double>(
"epDiffSig_ECALTRKThr");
129 epSig_ECALTRKThr_ = conf.getParameter<
double>(
"epSig_ECALTRKThr");
133 ecalRecHitEBTag_ = conf.getParameter<
edm::InputTag>(
"ecalrechitsEB");
134 ecalRecHitEETag_ = conf.getParameter<
edm::InputTag>(
"ecalrechitsEE");
136 constexpr char electronSrc[] =
"electronSrc";
137 constexpr char photonSrc[] =
"photonSrc";
139 if(conf.exists(
"electron_config")) {
141 if( electrons.
exists(electronSrc) )
144 std::vector<std::string> intValueMaps;
145 if ( electrons.
existsAs<std::vector<std::string> >(
"intValueMaps"))
146 intValueMaps = electrons.
getParameter<std::vector<std::string> >(
"intValueMaps");
153 for (
auto vmp : intValueMaps) {
169 e_forestH_mean_.reserve(2*encor);
170 e_forestH_sigma_.reserve(2*encor);
174 if( conf.exists(
"photon_config") ) {
177 if( photons.
exists(photonSrc) )
180 std::vector<std::string> intValueMaps;
181 if ( photons.
existsAs<std::vector<std::string> >(
"intValueMaps"))
182 intValueMaps = photons.
getParameter<std::vector<std::string> >(
"intValueMaps");
189 for (
auto vmp : intValueMaps) {
203 ph_forestH_mean_.reserve(ncor);
204 ph_forestH_sigma_.reserve(ncor);
213 inline void get_product(
const edm::Event& evt,
237 for(
unsigned i = 0;
i < eles->size(); ++
i ) {
246 get_product(evt, imap->second.second,
ele_vmaps);
259 for(
unsigned i = 0;
i < phos->size(); ++
i ) {
269 get_product(evt, imap->second.second,
pho_vmaps);
296 unsigned int ncor = ph_condnames_ecalonly_mean.size();
297 for (
unsigned int icor=0; icor<ncor; ++icor) {
309 unsigned int encor = e_condnames_ecalonly_mean.size();
310 for (
unsigned int icor=0; icor<encor; ++icor) {
316 for (
unsigned int icor=0; icor<encor; ++icor) {
330 template<
typename T,
typename U,
typename V>
331 inline void make_consumes(
T&
tag,U& tok,V& sume) {
332 if(!(empty_tag == tag))
333 tok = sume.template consumes<edm::ValueMap<float> >(
tag);
336 template<
typename T,
typename U,
typename V>
337 inline void make_int_consumes(
T& tag,U& tok,V& sume) {
338 if(!(empty_tag == tag))
339 tok = sume.template consumes<edm::ValueMap<int> >(
tag);
356 make_consumes(imap->second.first, imap->second.second, sumes);
359 for ( std::unordered_map<std::string, ValMapIntTagTokenPair>::iterator imap =
e_conf.
tag_int_token_map.begin();
362 make_int_consumes(imap->second.first, imap->second.second, sumes);
372 make_consumes(imap->second.first, imap->second.second, sumes);
378 make_int_consumes(imap->second.first, imap->second.second, sumes);
383 template<
typename T,
typename U,
typename V,
typename Z>
384 inline void assignValue(
const T& ptr,
const U& tok,
const V& map,
Z&
value) {
385 if( !tok.isUninitialized() ) value = map.find(tok.index())->
second->get(ptr.id(),ptr.key());
395 const int numberOfClusters = the_sc->clusters().size();
396 const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].
isAvailable();
398 if( missing_clusters )
return ;
400 const bool iseb = ele.
isEB();
404 if ( !ecalRecHits.
isValid() )
return;
406 int nSaturatedXtals = 0;
407 std::vector< std::pair<DetId, float> > hitsAndFractions = theseed->hitsAndFractions();
408 for (
auto hitFractionPair : hitsAndFractions) {
409 auto ecalRecHit = ecalRecHits->find(hitFractionPair.first);
410 if (
ecalRecHit == ecalRecHits->end())
continue;
411 if (
ecalRecHit->checkFlag(EcalRecHit::Flags::kSaturated)) nSaturatedXtals++;
414 std::array<float, 32> eval;
415 const double raw_energy = the_sc->rawEnergy();
416 const double raw_es_energy = the_sc->preshowerEnergy();
419 float e5x5Inverse = full5x5_ess.
e5x5 != 0. ? 1./full5x5_ess.e5x5 : 0.;
421 eval[0] = raw_energy;
422 eval[1] = the_sc->etaWidth();
423 eval[2] = the_sc->phiWidth();
424 eval[3] = the_sc->seed()->energy()/raw_energy;
425 eval[4] = full5x5_ess.e5x5/raw_energy;
428 eval[7] = theseed->eta() - the_sc->position().Eta();
429 eval[8] =
reco::deltaPhi( theseed->phi(),the_sc->position().Phi());
430 eval[9] = full5x5_ess.r9;
431 eval[10] = full5x5_ess.sigmaIetaIeta;
432 eval[11] = full5x5_ess.sigmaIetaIphi;
433 eval[12] = full5x5_ess.sigmaIphiIphi;
434 eval[13] = full5x5_ess.eMax*e5x5Inverse;
435 eval[14] = full5x5_ess.e2nd*e5x5Inverse;
436 eval[15] = full5x5_ess.eTop*e5x5Inverse;
437 eval[16] = full5x5_ess.eBottom*e5x5Inverse;
438 eval[17] = full5x5_ess.eLeft*e5x5Inverse;
439 eval[18] = full5x5_ess.eRight*e5x5Inverse;
445 eval[24] = nSaturatedXtals;
446 eval[25] =
std::max(0,numberOfClusters);
458 int signieta = ieta > 0 ? +1 : -1;
459 eval[28] = (ieta-signieta)%5;
460 eval[29] = (iphi-1)%2;
461 eval[30] = (
abs(ieta)<=25)*((ieta-signieta)) + (
abs(ieta)>25)*((ieta-26*signieta)%20);
462 eval[31] = (iphi-1)%20;
472 eval[28] = raw_es_energy/raw_energy;
480 constexpr double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
481 constexpr double meanscale = 0.5*(meanlimhigh-meanlimlow);
485 constexpr double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
486 constexpr double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
490 float raw_pt = raw_energy/cosh(the_sc->eta());
506 double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
507 double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
520 if (mean < 0.) mean = 1.0;
522 const double ecor = mean*(raw_energy + raw_es_energy);
523 const double sigmacor = sigma*ecor;
528 double combinedEnergy = ecor;
529 double combinedEnergyError = sigmacor;
533 const float trkMomentum = el_track->pMode();
534 const float trkEta = el_track->etaMode();
535 const float trkPhi = el_track->phiMode();
537 float ptMode = el_track->ptMode();
538 float ptModeErrror = el_track->ptModeError();
539 float etaModeError = el_track->etaModeError();
540 float pModeError =
sqrt(ptModeErrror*ptModeErrror*cosh(trkEta)*cosh(trkEta) + ptMode*ptMode*sinh(trkEta)*sinh(trkEta)*etaModeError*etaModeError);
542 const float trkMomentumError = pModeError;
543 const float eOverP = (raw_energy+raw_es_energy)*mean/trkMomentum;
544 const float fbrem = ele.
fbrem();
552 raw_pt = ecor/cosh(trkEta);
563 eval[1] = sigma/
mean;
564 eval[2] = trkMomentumError/trkMomentum;
567 eval[5] = full5x5_ess.r9;
572 float rawcomb = ( ecor*trkMomentumError*trkMomentumError + trkMomentum*(raw_energy+raw_es_energy)*(raw_energy+raw_es_energy)*sigma*sigma ) / ( trkMomentumError*trkMomentumError + (raw_energy + raw_es_energy)*(raw_energy + raw_es_energy)*sigma*sigma );
575 double rawmean_trk =
e_forestH_mean_[coridx]->GetResponse(eval.data());
579 double mean_trk = meanoffset + meanscale*vdt::fast_sin(rawmean_trk);
580 double sigma_trk = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma_trk);
592 if (mean_trk < 0.) mean_trk = 1.0;
594 combinedEnergy = mean_trk*rawcomb;
595 combinedEnergyError = sigma_trk*rawcomb;
600 oldFourMomentum.y()*combinedEnergy/oldFourMomentum.t(),
601 oldFourMomentum.z()*combinedEnergy/oldFourMomentum.t(),
617 const int numberOfClusters = the_sc->clusters().size();
618 const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].
isAvailable();
620 if( missing_clusters )
return ;
622 const bool iseb = pho.
isEB();
627 int nSaturatedXtals = 0;
628 std::vector< std::pair<DetId, float> > hitsAndFractions = theseed->hitsAndFractions();
629 for (
auto hitFractionPair : hitsAndFractions) {
630 auto ecalRecHit = ecalRecHits->find(hitFractionPair.first);
631 if (
ecalRecHit == ecalRecHits->end())
continue;
632 if (
ecalRecHit->checkFlag(EcalRecHit::Flags::kSaturated)) nSaturatedXtals++;
635 std::array<float, 32> eval;
636 const double raw_energy = the_sc->rawEnergy();
637 const double raw_es_energy = the_sc->preshowerEnergy();
640 float e5x5Inverse = full5x5_pss.
e5x5 != 0. ? 1./full5x5_pss.e5x5 : 0.;
642 eval[0] = raw_energy;
643 eval[1] = the_sc->etaWidth();
644 eval[2] = the_sc->phiWidth();
645 eval[3] = the_sc->seed()->energy()/raw_energy;
646 eval[4] = full5x5_pss.e5x5/raw_energy;
649 eval[7] = theseed->eta() - the_sc->position().Eta();
650 eval[8] =
reco::deltaPhi( theseed->phi(),the_sc->position().Phi());
652 eval[10] = full5x5_pss.sigmaIetaIeta;
653 eval[11] = full5x5_pss.sigmaIetaIphi;
654 eval[12] = full5x5_pss.sigmaIphiIphi;
655 eval[13] = full5x5_pss.maxEnergyXtal*e5x5Inverse;
656 eval[14] = full5x5_pss.e2nd*e5x5Inverse;
657 eval[15] = full5x5_pss.eTop*e5x5Inverse;
658 eval[16] = full5x5_pss.eBottom*e5x5Inverse;
659 eval[17] = full5x5_pss.eLeft*e5x5Inverse;
660 eval[18] = full5x5_pss.eRight*e5x5Inverse;
661 eval[19] = full5x5_pss.e2x5Max/full5x5_pss.e5x5;
662 eval[20] = full5x5_pss.e2x5Left/full5x5_pss.e5x5;
663 eval[21] = full5x5_pss.e2x5Right/full5x5_pss.e5x5;
664 eval[22] = full5x5_pss.e2x5Top/full5x5_pss.e5x5;
665 eval[23] = full5x5_pss.e2x5Bottom/full5x5_pss.e5x5;
666 eval[24] = nSaturatedXtals;
667 eval[25] =
std::max(0,numberOfClusters);
680 int signieta = ieta > 0 ? +1 : -1;
681 eval[28] = (ieta-signieta)%5;
682 eval[29] = (iphi-1)%2;
683 eval[30] = (
abs(ieta)<=25)*((ieta-signieta)) + (
abs(ieta)>25)*((ieta-26*signieta)%20);
684 eval[31] = (iphi-1)%20;
694 eval[28] = raw_es_energy/raw_energy;
702 constexpr double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
703 constexpr double meanscale = 0.5*(meanlimhigh-meanlimlow);
707 constexpr double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
708 constexpr double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
711 float raw_pt = raw_energy/cosh(the_sc->eta());
727 double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
728 double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
742 if (mean < 0.) mean = 1.0;
744 const double ecor = mean*(raw_energy + raw_es_energy);
745 const double sigmacor = sigma*ecor;
const double Z[kNumberCalorimeter]
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)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
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)
float hadronicOverEm() const
the total hadronic over electromagnetic fraction
std::vector< std::string > getParameterNames() const
float hcalOverEcalBc() const
double deltaPhi(double phi1, double phi2)
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)
const ShowerShape & full5x5_showerShape() const
const ShowerShape & full5x5_showerShapeVariables() 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
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
bool ecalDrivenSeed() const