16 #include <vdt/vdtMath.h> 22 #include <unordered_map> 101 "EGRegressionModifierV2");
106 lowEnergy_ECALonlyThr_ = conf.getParameter<
double>(
"lowEnergy_ECALonlyThr");
107 lowEnergy_ECALTRKThr_ = conf.getParameter<
double>(
"lowEnergy_ECALTRKThr");
108 highEnergy_ECALTRKThr_ = conf.getParameter<
double>(
"highEnergy_ECALTRKThr");
109 eOverP_ECALTRKThr_ = conf.getParameter<
double>(
"eOverP_ECALTRKThr");
110 epDiffSig_ECALTRKThr_ = conf.getParameter<
double>(
"epDiffSig_ECALTRKThr");
111 epSig_ECALTRKThr_ = conf.getParameter<
double>(
"epSig_ECALTRKThr");
112 forceHighEnergyEcalTrainingIfSaturated_ = conf.getParameter<
bool>(
"forceHighEnergyEcalTrainingIfSaturated");
118 if(conf.exists(
"electron_config")) {
120 if( electrons.
exists(electronSrc) )
123 std::vector<std::string> intValueMaps;
124 if ( electrons.
existsAs<std::vector<std::string> >(
"intValueMaps"))
125 intValueMaps = electrons.
getParameter<std::vector<std::string> >(
"intValueMaps");
132 for (
auto vmp : intValueMaps) {
148 e_forestH_mean_.reserve(2*encor);
149 e_forestH_sigma_.reserve(2*encor);
153 if( conf.exists(
"photon_config") ) {
156 if( photons.
exists(photonSrc) )
159 std::vector<std::string> intValueMaps;
160 if ( photons.
existsAs<std::vector<std::string> >(
"intValueMaps"))
161 intValueMaps = photons.
getParameter<std::vector<std::string> >(
"intValueMaps");
168 for (
auto vmp : intValueMaps) {
182 ph_forestH_mean_.reserve(ncor);
183 ph_forestH_sigma_.reserve(ncor);
192 inline void get_product(
const edm::Event& evt,
214 for(
unsigned i = 0;
i < eles->size(); ++
i ) {
223 get_product(evt, imap->second.second,
ele_vmaps);
236 for(
unsigned i = 0;
i < phos->size(); ++
i ) {
246 get_product(evt, imap->second.second,
pho_vmaps);
270 unsigned int ncor = ph_condnames_ecalonly_mean.size();
271 for (
unsigned int icor=0; icor<ncor; ++icor) {
283 unsigned int encor = e_condnames_ecalonly_mean.size();
284 for (
unsigned int icor=0; icor<encor; ++icor) {
290 for (
unsigned int icor=0; icor<encor; ++icor) {
300 template<
typename T,
typename U,
typename V>
301 inline void make_consumes(
T&
tag,
U& tok,V& sume) {
302 if(!(empty_tag == tag))
303 tok = sume.template consumes<edm::ValueMap<float> >(
tag);
306 template<
typename T,
typename U,
typename V>
307 inline void make_int_consumes(
T& tag,
U& tok,V& sume) {
308 if(!(empty_tag == tag))
309 tok = sume.template consumes<edm::ValueMap<int> >(
tag);
324 make_consumes(imap->second.first, imap->second.second, sumes);
327 for ( std::unordered_map<std::string, ValMapIntTagTokenPair>::iterator imap =
e_conf.
tag_int_token_map.begin();
330 make_int_consumes(imap->second.first, imap->second.second, sumes);
340 make_consumes(imap->second.first, imap->second.second, sumes);
346 make_int_consumes(imap->second.first, imap->second.second, sumes);
351 template<
typename T,
typename U,
typename V,
typename Z>
352 inline void assignValue(
const T& ptr,
const U& tok,
const V&
map,
Z&
value) {
353 if( !tok.isUninitialized() ) value = map.find(tok.index())->
second->get(ptr.id(),ptr.key());
367 const int numberOfClusters = the_sc->clusters().size();
368 const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].
isAvailable();
369 if( missing_clusters )
return ;
375 const bool iseb = ele.
isEB();
377 std::array<float, 32> eval;
378 const double raw_energy = the_sc->rawEnergy();
379 const double raw_es_energy = the_sc->preshowerEnergy();
382 float e5x5Inverse = full5x5_ess.
e5x5 != 0. ? vdt::fast_inv(full5x5_ess.e5x5) : 0.;
384 eval[0] = raw_energy;
385 eval[1] = the_sc->etaWidth();
386 eval[2] = the_sc->phiWidth();
387 eval[3] = the_sc->seed()->energy()/raw_energy;
388 eval[4] = full5x5_ess.e5x5/raw_energy;
391 eval[7] = theseed->
eta() - the_sc->position().Eta();
393 eval[9] = full5x5_ess.r9;
394 eval[10] = full5x5_ess.sigmaIetaIeta;
395 eval[11] = full5x5_ess.sigmaIetaIphi;
396 eval[12] = full5x5_ess.sigmaIphiIphi;
397 eval[13] = full5x5_ess.eMax*e5x5Inverse;
398 eval[14] = full5x5_ess.e2nd*e5x5Inverse;
399 eval[15] = full5x5_ess.eTop*e5x5Inverse;
400 eval[16] = full5x5_ess.eBottom*e5x5Inverse;
401 eval[17] = full5x5_ess.eLeft*e5x5Inverse;
402 eval[18] = full5x5_ess.eRight*e5x5Inverse;
403 eval[19] = full5x5_ess.e2x5Max*e5x5Inverse;
404 eval[20] = full5x5_ess.e2x5Left*e5x5Inverse;
405 eval[21] = full5x5_ess.e2x5Right*e5x5Inverse;
406 eval[22] = full5x5_ess.e2x5Top*e5x5Inverse;
407 eval[23] = full5x5_ess.e2x5Bottom*e5x5Inverse;
409 eval[25] =
std::max(0,numberOfClusters);
421 int signieta = ieta > 0 ? +1 : -1;
422 eval[28] = (ieta-signieta)%5;
423 eval[29] = (iphi-1)%2;
424 eval[30] = (
abs(ieta)<=25)*((ieta-signieta)) + (
abs(ieta)>25)*((ieta-26*signieta)%20);
425 eval[31] = (iphi-1)%20;
435 eval[28] = raw_es_energy/raw_energy;
443 constexpr double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
444 constexpr double meanscale = 0.5*(meanlimhigh-meanlimlow);
448 constexpr double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
449 constexpr double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
453 float raw_pt = raw_energy*the_sc->position().rho()/the_sc->position().r();
471 double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
472 double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
477 if (mean < 0.) mean = 1.0;
479 const double ecor = mean*(raw_energy + raw_es_energy);
480 const double sigmacor = sigma*ecor;
485 double combinedEnergy = ecor;
486 double combinedEnergyError = sigmacor;
489 const float trkMomentum = el_track->pMode();
490 const float trkEta = el_track->etaMode();
491 const float trkPhi = el_track->phiMode();
492 const float trkMomentumError =
std::abs(el_track->qoverpModeError())*trkMomentum*trkMomentum;
494 const float eOverP = (raw_energy+raw_es_energy)*mean/trkMomentum;
495 const float fbrem = ele.
fbrem();
503 raw_pt = ecor/cosh(trkEta);
514 eval[1] = sigma/
mean;
515 eval[2] = trkMomentumError/trkMomentum;
518 eval[5] = full5x5_ess.r9;
523 float ecalEnergyVar = (raw_energy + raw_es_energy)*sigma;
524 float rawcombNormalization = (trkMomentumError*trkMomentumError + ecalEnergyVar*ecalEnergyVar);
525 float rawcomb = ( ecor*trkMomentumError*trkMomentumError + trkMomentum*ecalEnergyVar*ecalEnergyVar ) / rawcombNormalization;
528 double rawmean_trk =
e_forestH_mean_[coridx]->GetResponse(eval.data());
532 double mean_trk = meanoffset + meanscale*vdt::fast_sin(rawmean_trk);
533 double sigma_trk = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma_trk);
539 if (mean_trk < 0.) mean_trk = 1.0;
541 combinedEnergy = mean_trk*rawcomb;
542 combinedEnergyError = sigma_trk*rawcomb;
547 oldFourMomentum.y()*combinedEnergy/oldFourMomentum.t(),
548 oldFourMomentum.z()*combinedEnergy/oldFourMomentum.t(),
567 const int numberOfClusters = the_sc->clusters().size();
568 const bool missing_clusters = !the_sc->clusters()[numberOfClusters-1].
isAvailable();
569 if( missing_clusters )
return ;
571 const bool iseb = pho.
isEB();
573 std::array<float, 32> eval;
574 const double raw_energy = the_sc->rawEnergy();
575 const double raw_es_energy = the_sc->preshowerEnergy();
578 float e5x5Inverse = full5x5_pss.
e5x5 != 0. ? vdt::fast_inv(full5x5_pss.e5x5) : 0.;
580 eval[0] = raw_energy;
581 eval[1] = the_sc->etaWidth();
582 eval[2] = the_sc->phiWidth();
583 eval[3] = the_sc->seed()->energy()/raw_energy;
584 eval[4] = full5x5_pss.e5x5/raw_energy;
587 eval[7] = theseed->
eta() - the_sc->position().Eta();
590 eval[10] = full5x5_pss.sigmaIetaIeta;
591 eval[11] = full5x5_pss.sigmaIetaIphi;
592 eval[12] = full5x5_pss.sigmaIphiIphi;
593 eval[13] = full5x5_pss.maxEnergyXtal*e5x5Inverse;
594 eval[14] = full5x5_pss.e2nd*e5x5Inverse;
595 eval[15] = full5x5_pss.eTop*e5x5Inverse;
596 eval[16] = full5x5_pss.eBottom*e5x5Inverse;
597 eval[17] = full5x5_pss.eLeft*e5x5Inverse;
598 eval[18] = full5x5_pss.eRight*e5x5Inverse;
599 eval[19] = full5x5_pss.e2x5Max*e5x5Inverse;
600 eval[20] = full5x5_pss.e2x5Left*e5x5Inverse;
601 eval[21] = full5x5_pss.e2x5Right*e5x5Inverse;
602 eval[22] = full5x5_pss.e2x5Top*e5x5Inverse;
603 eval[23] = full5x5_pss.e2x5Bottom*e5x5Inverse;
605 eval[25] =
std::max(0,numberOfClusters);
618 int signieta = ieta > 0 ? +1 : -1;
619 eval[28] = (ieta-signieta)%5;
620 eval[29] = (iphi-1)%2;
621 eval[30] = (
abs(ieta)<=25)*((ieta-signieta)) + (
abs(ieta)>25)*((ieta-26*signieta)%20);
622 eval[31] = (iphi-1)%20;
632 eval[28] = raw_es_energy/raw_energy;
640 constexpr double meanoffset = meanlimlow + 0.5*(meanlimhigh-meanlimlow);
641 constexpr double meanscale = 0.5*(meanlimhigh-meanlimlow);
645 constexpr double sigmaoffset = sigmalimlow + 0.5*(sigmalimhigh-sigmalimlow);
646 constexpr double sigmascale = 0.5*(sigmalimhigh-sigmalimlow);
649 float raw_pt = raw_energy*the_sc->position().rho()/the_sc->position().r();
666 double mean = meanoffset + meanscale*vdt::fast_sin(rawmean);
667 double sigma = sigmaoffset + sigmascale*vdt::fast_sin(rawsigma);
672 if (mean < 0.) mean = 1.0;
674 const double ecor = mean*(raw_energy + raw_es_energy);
675 const double sigmacor = sigma*ecor;
constexpr double deltaPhi(double phi1, double phi2)
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
GsfTrackRef gsfTrack() const override
reference to a GsfTrack
Analysis-level Photon class.
std::unordered_map< std::string, ValMapIntTagTokenPair > tag_int_token_map
float nSaturatedXtals() const
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > ele_vmaps
float trackMomentumError() const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
void setEventContent(const edm::EventSetup &) final
const LorentzVector & p4(P4Kind kind) const
EGRegressionModifierV2(const edm::ParameterSet &conf)
edm::EDGetTokenT< edm::View< pat::Electron > > tok_electron_src
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
const edm::EventSetup * iSetup_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double lowEnergy_ECALonlyThr_
double epDiffSig_ECALTRKThr_
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
std::vector< std::string > condnames_ecalonly_sigma
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::pair< edm::InputTag, ValMapIntToken > ValMapIntTagTokenPair
std::vector< std::string > condnames_ecalonly_mean
std::vector< std::string > condnames_ecalonly_mean
void setEvent(const edm::Event &) final
std::vector< std::string > condnames_ecalonly_sigma
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
double eta() const
pseudorapidity of cluster centroid
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< int > > > ele_int_vmaps
U second(std::pair< T, U > const &p)
double highEnergy_ECALTRKThr_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
std::unordered_map< std::string, ValMapFloatTagTokenPair > tag_float_token_map
std::unordered_map< unsigned, edm::Ptr< reco::Photon > > phos_by_oop
void setCorrectedEcalEnergyError(float newEnergyError)
const std::string & name() const
std::pair< edm::InputTag, ValMapFloatToken > ValMapFloatTagTokenPair
bool forceHighEnergyEcalTrainingIfSaturated_
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > pho_vmaps
void modifyObject(reco::GsfElectron &) const final
std::vector< const GBRForestD * > ph_forestH_sigma_
std::unordered_map< unsigned, edm::Ptr< reco::GsfElectron > > eles_by_oop
Abs< T >::type abs(const T &t)
void setConsumes(edm::ConsumesCollector &) final
float hadronicOverEm() const
the total hadronic over electromagnetic fraction
std::vector< std::string > getParameterNames() const
edm::InputTag electron_src
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
float hcalOverEcalBc() const
edm::EDGetTokenT< edm::ValueMap< int > > ValMapIntToken
std::vector< std::string > condnames_ecaltrk_mean
DetId seed() const
return DetId of seed
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< int > > > pho_int_vmaps
std::vector< std::string > condnames_ecaltrk_sigma
Analysis-level electron class.
double eOverP_ECALTRKThr_
void localCoordsEB(const reco::CaloCluster &bclus, const edm::EventSetup &es, float &etacry, float &phicry, int &ieta, int &iphi, float &thetatilt, float &phitilt) const
std::unordered_map< std::string, ValMapFloatTagTokenPair > tag_float_token_map
~EGRegressionModifierV2() override
std::unordered_map< std::string, ValMapIntTagTokenPair > tag_int_token_map
void setCorrectedEcalEnergy(float newEnergy)
edm::EDGetTokenT< double > rhoToken_
bool isSaturated(const Digi &digi, const int &maxADCvalue, int ifirst, int n)
const ShowerShape & full5x5_showerShape() const
const ShowerShape & full5x5_showerShapeVariables() const
edm::EDGetTokenT< edm::View< pat::Photon > > tok_photon_src
std::vector< const GBRForestD * > e_forestH_sigma_
SuperClusterRef superCluster() const override
reference to a SuperCluster
bool isUninitialized() const
#define DEFINE_EDM_PLUGIN(factory, type, name)
double phi() const
azimuthal angle of cluster centroid
void localCoordsEE(const reco::CaloCluster &bclus, const edm::EventSetup &es, float &xcry, float &ycry, int &ix, int &iy, float &thetatilt, float &phitilt) const
double lowEnergy_ECALTRKThr_
T const * product() const
edm::EDGetTokenT< edm::ValueMap< float > > ValMapFloatToken
std::vector< const GBRForestD * > ph_forestH_mean_
std::vector< const GBRForestD * > e_forestH_mean_
float nSaturatedXtals() const
bool ecalDrivenSeed() const
constexpr Detector det() const
get the detector field from this detid