20 #include <vdt/vdtMath.h> 26 #include <unordered_map> 78 std::unordered_map<unsigned,edm::Ptr<reco::GsfElectron> >
eles_by_oop;
79 std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > >
ele_vmaps;
80 std::unordered_map<unsigned,edm::Handle<edm::ValueMap<int> > >
ele_int_vmaps;
81 std::unordered_map<unsigned,edm::Ptr<reco::Photon> >
phos_by_oop;
82 std::unordered_map<unsigned,edm::Handle<edm::ValueMap<float> > >
pho_vmaps;
83 std::unordered_map<unsigned,edm::Handle<edm::ValueMap<int> > >
pho_int_vmaps;
109 "EGRegressionModifierV1");
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();
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();
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();
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;
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;
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
double GetResponse(const float *vector) const
const ShowerShape & showerShape() const
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::vector< std::string > condnames_sigma_25ns
T getParameter(std::string const &) const
Analysis-level Photon class.
void setEventContent(const edm::EventSetup &) final
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > pho_vmaps
float trackMomentumError() const
bool existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
edm::Handle< reco::VertexCollection > vtxH_
const LorentzVector & p4(P4Kind kind) const
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< int > > > pho_int_vmaps
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::vector< const GBRForestD * > ph_forestH_sigma_
std::vector< std::string > condnames_sigma_50ns
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< int > > > ele_int_vmaps
std::unordered_map< unsigned, edm::Ptr< reco::Photon > > phos_by_oop
edm::InputTag bunchspacingTag_
void correctMomentum(const LorentzVector &p4, float trackMomentumError, float p4Error)
math::XYZVectorF trackMomentumAtVtx() const
std::vector< const GBRForestD * > e_forestH_mean_
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::unordered_map< unsigned, edm::Handle< edm::ValueMap< float > > > ele_vmaps
std::vector< Vertex > VertexCollection
collection of Vertex objects
std::unordered_map< unsigned, edm::Ptr< reco::GsfElectron > > eles_by_oop
std::vector< const GBRForestD * > ph_forestH_mean_
std::string condnames_weight_50ns
bool autoDetectBunchSpacing_
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
std::unordered_map< std::string, ValMapFloatTagTokenPair > tag_float_token_map
double eta() const
pseudorapidity of cluster centroid
void setEvent(const edm::Event &) final
edm::EDGetTokenT< edm::View< pat::Electron > > tok_electron_src
std::vector< std::string > condnames_mean_25ns
U second(std::pair< T, U > const &p)
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
std::unordered_map< std::string, ValMapIntTagTokenPair > tag_int_token_map
bool applyExtraHighEnergyProtection_
void setCorrectedEcalEnergyError(float newEnergyError)
std::pair< edm::InputTag, ValMapFloatToken > ValMapFloatTagTokenPair
const std::string & name() const
std::string condnames_weight_25ns
std::unordered_map< std::string, ValMapFloatTagTokenPair > tag_float_token_map
std::vector< std::string > condnames_mean_25ns
const GBRForest * ep_forestH_weight_
edm::EDGetTokenT< edm::ValueMap< int > > ValMapIntToken
edm::EDGetTokenT< edm::ValueMap< float > > ValMapFloatToken
Abs< T >::type abs(const T &t)
std::pair< edm::InputTag, ValMapIntToken > ValMapIntTagTokenPair
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
double energy() const
cluster energy
edm::EDGetTokenT< double > rhoToken_
const edm::EventSetup * iSetup_
float hadronicOverEm() const
the total hadronic over electromagnetic fraction
std::vector< std::string > getParameterNames() const
const edm::Ptr< reco::Candidate > & originalObjectRef() const
reference to original object. Returns a null reference if not available
void modifyObject(reco::GsfElectron &) const final
EGRegressionModifierV1(const edm::ParameterSet &conf)
std::vector< std::string > condnames_mean_50ns
edm::EDGetTokenT< edm::View< pat::Photon > > tok_photon_src
double deltaPhi(double phi1, double phi2)
DetId seed() const
return DetId of seed
std::vector< const GBRForestD * > e_forestH_sigma_
Classification classification() const
Analysis-level electron class.
void setConsumes(edm::ConsumesCollector &) final
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)
std::vector< std::string > condnames_sigma_50ns
std::vector< std::string > condnames_mean_50ns
SuperClusterRef superCluster() const override
reference to a SuperCluster
bool trackerDrivenSeed() const
std::unordered_map< std::string, ValMapIntTagTokenPair > tag_int_token_map
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
~EGRegressionModifierV1() override
edm::EDGetTokenT< unsigned int > bunchSpacingToken_
const ShowerShape & showerShapeVariables() const
std::vector< std::string > condnames_sigma_25ns
T const * product() const
edm::InputTag electron_src