60 const auto dnnEnabled = pset_dnn.
getParameter<
bool>(
"enabled");
64 config.
modelsFiles = pset_dnn.getParameter<std::vector<std::string>>(
"modelsFiles");
65 config.
scalersFiles = pset_dnn.getParameter<std::vector<std::string>>(
"scalersFiles");
67 const auto useEBModelInGap = pset_dnn.getParameter<
bool>(
"useEBModelInGap");
214 std::unique_ptr<PhotonEcalPFClusterIsolation>
ecalisoAlgo =
nullptr;
232 std::unique_ptr<PhotonHcalPFClusterIsolation>
hcalisoAlgo =
nullptr;
240 const auto v = position - origin;
248 else if (step ==
"oot")
250 else if (step ==
"ootfinal")
252 else if (step ==
"tmp")
256 <<
" reconstructStep " << step <<
" is invalid, the options are: tmp, final,oot or ootfinal" << std::endl;
286 if (config.
exists(
"pfECALClusIsolation")) {
289 if (config.
exists(
"pfHCALClusIsolation")) {
298 if (not pfEg.label().empty()) {
307 if (not hbhetag.label().empty())
327 auto const& flagnamesEB = config.
getParameter<std::vector<std::string>>(
"RecHitFlagToBeExcludedEB");
328 auto const& flagnamesEE = config.
getParameter<std::vector<std::string>>(
"RecHitFlagToBeExcludedEE");
330 flagsexclEB_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
331 flagsexclEE_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
333 auto const& severitynamesEB = config.
getParameter<std::vector<std::string>>(
"RecHitSeverityToBeExcludedEB");
334 auto const& severitynamesEE = config.
getParameter<std::vector<std::string>>(
"RecHitSeverityToBeExcludedEE");
336 severitiesexclEB_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
337 severitiesexclEE_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
352 cfgCone.
maxSeverityHB = config.getParameter<
int>(
"maxHcalRecHitSeverity");
363 cfgBc.
maxSeverityHB = config.getParameter<
int>(
"maxHcalRecHitSeverity");
367 hcalHelperCone_ = std::make_unique<ElectronHcalHelper>(cfgCone, consumesCollector());
368 hcalHelperBc_ = std::make_unique<ElectronHcalHelper>(cfgBc, consumesCollector());
375 config.getParameter<
double>(
"maxHoverEBarrel"),
376 config.getParameter<
double>(
"ecalRecHitSumEtOffsetBarrel"),
377 config.getParameter<
double>(
"ecalRecHitSumEtSlopeBarrel"),
378 config.getParameter<
double>(
"hcalRecHitSumEtOffsetBarrel"),
379 config.getParameter<
double>(
"hcalRecHitSumEtSlopeBarrel"),
380 config.getParameter<
double>(
"nTrackSolidConeBarrel"),
381 config.getParameter<
double>(
"nTrackHollowConeBarrel"),
382 config.getParameter<
double>(
"trackPtSumSolidConeBarrel"),
383 config.getParameter<
double>(
"trackPtSumHollowConeBarrel"),
384 config.getParameter<
double>(
"sigmaIetaIetaCutBarrel")};
387 config.getParameter<
double>(
"maxHoverEEndcap"),
388 config.getParameter<
double>(
"ecalRecHitSumEtOffsetEndcap"),
389 config.getParameter<
double>(
"ecalRecHitSumEtSlopeEndcap"),
390 config.getParameter<
double>(
"hcalRecHitSumEtOffsetEndcap"),
391 config.getParameter<
double>(
"hcalRecHitSumEtSlopeEndcap"),
392 config.getParameter<
double>(
"nTrackSolidConeEndcap"),
393 config.getParameter<
double>(
"nTrackHollowConeEndcap"),
394 config.getParameter<
double>(
"trackPtSumSolidConeEndcap"),
395 config.getParameter<
double>(
"trackPtSumHollowConeEndcap"),
396 config.getParameter<
double>(
"sigmaIetaIetaCutEndcap")};
408 consumesCollector());
430 useHF_ = pfHCALClusIsolCfg.getParameter<
bool>(
"useHF");
431 hcaldrMax_ = pfHCALClusIsolCfg.getParameter<
double>(
"drMax");
438 hcaluseEt_ = pfHCALClusIsolCfg.getParameter<
bool>(
"useEt");
448 if (dnnPFidEnabled_) {
455 return std::make_unique<CacheData>(
config);
467 auto outputPhotonCollection_p = std::make_unique<reco::PhotonCollection>();
471 bool validPhotonCoreHandle =
false;
473 bool validPhotonHandle =
false;
504 if (photonHandle.isValid()) {
505 validPhotonHandle =
true;
511 if (photonCoreHandle.isValid()) {
512 validPhotonCoreHandle =
true;
528 if (!pfEGCandidateHandle.isValid()) {
529 throw cms::Exception(
"GEDPhotonProducer") <<
"Error! Can't get the pfEgammaCandidates";
540 throw cms::Exception(
"GEDPhotonProducer") <<
"Error! Can't get the pfCandidates";
564 photonEnergyCorrector_->init(eventSetup);
565 if (photonEnergyCorrector_->gedRegression()) {
566 photonEnergyCorrector_->gedRegression()->setEvent(theEvent);
567 photonEnergyCorrector_->gedRegression()->setEventContent(eventSetup);
590 if (validPhotonCoreHandle)
602 *outputPhotonCollection_p,
614 *outputPhotonCollection_p,
616 phoChargedIsolationMap,
617 phoNeutralHadronIsolationMap,
618 phoPhotonIsolationMap,
619 phoChargedWorstVtxIsoMap,
620 phoChargedWorstVtxGeomVetoIsoMap,
621 phoChargedPFPVIsoMap,
622 phoPFECALClusIsolationMap,
623 phoPFHCALClusIsolationMap);
626 edm::LogInfo(
"GEDPhotonProducer") <<
" Put in the event " << iSC <<
" Photon Candidates \n";
630 for (
auto& pho : *outputPhotonCollection_p)
631 pho.hcalToRun2EffDepth();
637 auto pfEGCandToPhotonMap_p = std::make_unique<edm::ValueMap<reco::PhotonRef>>();
639 unsigned nObj = pfEGCandidateHandle->size();
640 std::vector<reco::PhotonRef>
values(nObj);
642 for (
unsigned int lCand = 0; lCand < nObj; lCand++) {
646 for (
unsigned int lSC = 0; lSC < photonOrphHandle->size(); lSC++) {
649 if (pfScRef != scRef)
651 values[lCand] = photonRef;
655 filler.insert(pfEGCandidateHandle, values.begin(), values.end());
657 theEvent.
put(
std::move(pfEGCandToPhotonMap_p), valueMapPFCandPhoton_);
675 std::vector<double> preselCutValues;
676 std::vector<int> flags_, severitiesexcl_;
678 for (
unsigned int lSC = 0; lSC < photonCoreHandle->size(); lSC++) {
686 DetId::Detector thedet = scRef->seed()->hitsAndFractions()[0].first.det();
687 int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
690 hits = ecalBarrelHits;
695 hits = ecalEndcapHits;
704 edm::LogWarning(
"") <<
"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster: " << thedet
710 ptFast(parentSCRef->energy(), parentSCRef->position(), {0, 0, 0}) <= preselCutValues[0])
713 float maxXtal = (hits !=
nullptr ? EcalClusterTools::eMax(*(scRef->seed()), hits) : 0.f);
717 float e1x5 = (hits !=
nullptr ? EcalClusterTools::e1x5(*(scRef->seed()), hits, topology) : 0.f);
718 float e2x5 = (hits !=
nullptr ? EcalClusterTools::e2x5Max(*(scRef->seed()), hits, topology) : 0.f);
719 float e3x3 = (hits !=
nullptr ? EcalClusterTools::e3x3(*(scRef->seed()), hits, topology) : 0.f);
720 float e5x5 = (hits !=
nullptr ? EcalClusterTools::e5x5(*(scRef->seed()), hits, topology) : 0.f);
721 const auto& cov = (hits !=
nullptr ? EcalClusterTools::covariances(*(scRef->seed()), hits, topology,
caloGeom_)
722 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
724 const auto& locCov = (hits !=
nullptr ? EcalClusterTools::localCovariances(*(scRef->seed()), hits, topology)
725 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
728 float sigmaIetaIeta =
std::sqrt(locCov[0]);
737 const auto& full5x5_cov =
739 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
743 const auto& full5x5_locCov =
751 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
753 float full5x5_sigmaEtaEta =
sqrt(full5x5_cov[0]);
754 float full5x5_sigmaIetaIeta =
sqrt(full5x5_locCov[0]);
755 float full5x5_sigmaIetaIphi = full5x5_locCov[1];
761 double photonEnergy = 1.;
763 if (!vertexCollection.empty())
764 vtx = vertexCollection.begin()->position();
772 reco::Photon newCandidate(p4, caloPosition, coreRef, vtx);
783 newCandidate.setFiducialVolumeFlags(fiducialFlags);
784 newCandidate.setIsolationVariables(isolVarR04, isolVarR03);
788 showerShape.
e1x5 = e1x5;
789 showerShape.
e2x5 = e2x5;
790 showerShape.
e3x3 = e3x3;
791 showerShape.
e5x5 = e5x5;
797 (hcalHelperCone !=
nullptr) ? hcalHelperCone->
hcalESum(*scRef,
id + 1) / scRef->energy() : 0.f;
800 (hcalHelperBc !=
nullptr) ? hcalHelperBc->
hcalESum(*scRef,
id + 1) / scRef->energy() : 0.f;
803 if (hcalHelperBc !=
nullptr)
809 const float sep = locCov[1];
812 showerShape.
e2nd = (hits !=
nullptr ? EcalClusterTools::e2nd(*(scRef->seed()), hits) : 0.f);
813 showerShape.
eTop = (hits !=
nullptr ? EcalClusterTools::eTop(*(scRef->seed()), hits, topology) : 0.f);
814 showerShape.
eLeft = (hits !=
nullptr ? EcalClusterTools::eLeft(*(scRef->seed()), hits, topology) : 0.f);
815 showerShape.
eRight = (hits !=
nullptr ? EcalClusterTools::eRight(*(scRef->seed()), hits, topology) : 0.f);
816 showerShape.
eBottom = (hits !=
nullptr ? EcalClusterTools::eBottom(*(scRef->seed()), hits, topology) : 0.f);
817 showerShape.
e1x3 = (hits !=
nullptr ? EcalClusterTools::e1x3(*(scRef->seed()), hits, topology) : 0.f);
818 showerShape.
e2x2 = (hits !=
nullptr ? EcalClusterTools::e2x2(*(scRef->seed()), hits, topology) : 0.f);
819 showerShape.
e2x5Max = (hits !=
nullptr ? EcalClusterTools::e2x5Max(*(scRef->seed()), hits, topology) : 0.f);
820 showerShape.
e2x5Left = (hits !=
nullptr ? EcalClusterTools::e2x5Left(*(scRef->seed()), hits, topology) : 0.f);
821 showerShape.
e2x5Right = (hits !=
nullptr ? EcalClusterTools::e2x5Right(*(scRef->seed()), hits, topology) : 0.f);
822 showerShape.
e2x5Top = (hits !=
nullptr ? EcalClusterTools::e2x5Top(*(scRef->seed()), hits, topology) : 0.f);
823 showerShape.
e2x5Bottom = (hits !=
nullptr ? EcalClusterTools::e2x5Bottom(*(scRef->seed()), hits, topology) : 0.f);
825 Cluster2ndMoments clus2ndMoments = EcalClusterTools::cluster2ndMoments(*(scRef->seed()), *hits);
838 const float sigmaRR = toolsforES.eseffsirir(*scRef);
840 newCandidate.setShowerShapeVariables(showerShape);
844 int nSaturatedXtals = 0;
845 bool isSeedSaturated =
false;
846 if (hits !=
nullptr) {
847 const auto hitsAndFractions = scRef->hitsAndFractions();
848 for (
auto const& hitFractionPair : hitsAndFractions) {
852 if (
ecalRecHit->checkFlag(EcalRecHit::Flags::kSaturated)) {
855 isSeedSaturated =
true;
862 newCandidate.setSaturationInfo(saturationInfo);
866 full5x5_showerShape.
e1x5 = full5x5_e1x5;
867 full5x5_showerShape.
e2x5 = full5x5_e2x5;
868 full5x5_showerShape.
e3x3 = full5x5_e3x3;
869 full5x5_showerShape.
e5x5 = full5x5_e5x5;
871 full5x5_showerShape.
sigmaEtaEta = full5x5_sigmaEtaEta;
875 const float full5x5_sep = full5x5_sigmaIetaIphi;
880 full5x5_showerShape.
eLeft =
882 full5x5_showerShape.
eRight =
904 full5x5_showerShape.
smMajor = 0.f;
905 full5x5_showerShape.
smMinor = 0.f;
906 full5x5_showerShape.
smAlpha = 0.f;
912 (hcalHelperCone !=
nullptr) ? hcalHelperCone->
hcalESum(*scRef,
id + 1) / full5x5_e5x5 : 0.f;
914 (hcalHelperBc !=
nullptr) ? hcalHelperBc->
hcalESum(*scRef,
id + 1) / full5x5_e5x5 : 0.f;
917 newCandidate.full5x5_setShowerShapeVariables(full5x5_showerShape);
937 newCandidate.setPflowIsolationVariables(pfIso);
945 photonEnergyCorrector_->calculate(evt, newCandidate, subdet, vertexCollection, es);
946 if (candidateP4type_ ==
"fromEcalEnergy") {
949 }
else if (candidateP4type_ ==
"fromRegression1") {
952 }
else if (candidateP4type_ ==
"fromRegression2") {
955 }
else if (candidateP4type_ ==
"fromRefinedSCRegression") {
962 newCandidate.setP4(p4);
966 fiducialFlags.
isEE =
true;
967 newCandidate.setFiducialVolumeFlags(fiducialFlags);
974 newCandidate.setMIPVariables(mipVar);
978 bool isLooseEM =
true;
979 if (newCandidate.pt() <
highEt_) {
980 if (newCandidate.hadronicOverEm() >= preselCutValues[1])
982 if (newCandidate.ecalRecHitSumEtConeDR04() > preselCutValues[2] + preselCutValues[3] * newCandidate.pt())
984 if (newCandidate.hcalTowerSumEtConeDR04() > preselCutValues[4] + preselCutValues[5] * newCandidate.pt())
986 if (newCandidate.nTrkSolidConeDR04() > int(preselCutValues[6]))
988 if (newCandidate.nTrkHollowConeDR04() > int(preselCutValues[7]))
990 if (newCandidate.trkSumPtSolidConeDR04() > preselCutValues[8])
992 if (newCandidate.trkSumPtHollowConeDR04() > preselCutValues[9])
994 if (newCandidate.sigmaIetaIeta() > preselCutValues[10])
999 outputPhotonCollection.push_back(newCandidate);
1004 LogDebug(
"GEDPhotonProducer") <<
"Getting DNN PFId for photons";
1005 const auto& dnn_photon_pfid = globalCache()->photonDNNEstimator->evaluate(outputPhotonCollection,
tfSessions_);
1007 for (
auto& photon : outputPhotonCollection) {
1008 const auto&
values = dnn_photon_pfid[ipho];
1011 photon.setPflowIDVariables(pfID);
1033 std::vector<double> preselCutValues;
1035 for (
unsigned int lSC = 0; lSC < photonHandle->size(); lSC++) {
1039 DetId::Detector thedet = scRef->seed()->hitsAndFractions()[0].first.det();
1040 int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
1048 edm::LogWarning(
"") <<
"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster" << thedet <<
' '
1054 ptFast(parentSCRef->energy(), parentSCRef->position(), {0, 0, 0}) <= preselCutValues[0])
1070 pfIso.
photonIso = (*photons)[photonPtr];
1083 photonEnergyCorrector_->calculate(evt, newCandidate, subdet, vertexCollection, es);
1084 if (candidateP4type_ ==
"fromEcalEnergy") {
1087 }
else if (candidateP4type_ ==
"fromRegression1") {
1090 }
else if (candidateP4type_ ==
"fromRegression2") {
1093 }
else if (candidateP4type_ ==
"fromRefinedSCRegression") {
1098 outputPhotonCollection.push_back(newCandidate);
void setPflowIsolationVariables(const PflowIsolationVariables &pfisol)
Set Particle Flow Isolation variables.
GEDPhotonProducer(const edm::ParameterSet &ps, const CacheData *gcache)
std::unique_ptr< PhotonHcalPFClusterIsolation > hcalisoAlgo
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool isNonnull() const
Checks for non-null.
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidates_
void fillPhotonCollection(edm::Event &evt, edm::EventSetup const &es, const edm::Handle< reco::PhotonCoreCollection > &photonCoreHandle, const CaloTopology *topology, const EcalRecHitCollection *ecalBarrelHits, const EcalRecHitCollection *ecalEndcapHits, const EcalRecHitCollection *preshowerHits, const ElectronHcalHelper *hcalHelperCone, const ElectronHcalHelper *hcalHelperBc, const reco::VertexCollection &pvVertices, reco::PhotonCollection &outputCollection, int &iSC, EcalPFRecHitThresholds const &thresholds)
double hcalESum(const reco::SuperCluster &, int depth) const
HcalPFClusterIsolation< reco::Photon > PhotonHcalPFClusterIsolation
std::vector< CaloTowerDetId > hcalTowersBehindClusters
ROOT::Math::LorentzVector< ROOT::Math::PxPyPzE4D< double > > XYZTLorentzVectorD
Lorentz vector with cylindrical internal representation using pseudorapidity.
void setCandidateP4type(const P4type type)
static constexpr float kRelEnCut
uint16_t *__restrict__ id
const edm::ESGetToken< EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd > ecalPFRechitThresholdsToken_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
double ecaletaStripEndcap_
#define DEFINE_FWK_MODULE(type)
double ecaletaStripBarrel_
void produce(edm::Event &evt, const edm::EventSetup &es) override
std::unique_ptr< PhotonEnergyCorrector > photonEnergyCorrector_
constexpr bool isUninitialized() const noexcept
CaloGeometry const * caloGeom_
std::unique_ptr< PhotonEcalPFClusterIsolation > ecalisoAlgo
bool exists(std::string const ¶meterName) const
checks if a parameter exists
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducerHFEM_
std::vector< int > flagsexclEB_
float chargedHadronWorstVtxGeomVetoIso
void endStream() override
std::vector< Vertex > VertexCollection
collection of Vertex objects
const edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHits_
float chargedHadronWorstVtxIso
std::array< float, 7 > hcalOverEcalBc
constexpr bool isFinite(T x)
std::vector< int > severitiesexclEE_
edm::EDGetTokenT< HBHERecHitCollection > hbheRecHits
double ptFast(const double energy, const math::XYZPoint &position, const math::XYZPoint &origin)
std::string photonCollection_
RecoStepInfo(const std::string &recoStep)
bool getData(T &iHolder) const
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedPFPVIsoToken_
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHits_
static std::unique_ptr< CacheData > initializeGlobalCache(const edm::ParameterSet &)
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedWorstVtxGeomVetoIsoToken_
std::unique_ptr< ElectronHcalHelper > hcalHelperCone_
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedIsolationToken_
std::unique_ptr< PhotonIsolationCalculator > photonIsoCalculator_
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken
bool closeSession(Session *&session)
std::vector< int > flagsexclEE_
std::unique_ptr< const PhotonDNNEstimator > photonDNNEstimator
auto hcalTowersBehindClusters(const reco::SuperCluster &sc) const
bool get(ProductID const &oid, Handle< PROD > &result) const
edm::EDGetTokenT< reco::PhotonCoreCollection > photonCoreProducerT_
std::vector< tensorflow::Session * > tfSessions_
edm::EDGetTokenT< edm::ValueMap< float > > phoPFHCALClusIsolationToken_
edm::EDGetTokenT< reco::PFCandidateCollection > pfEgammaCandidates_
double hcaletaStripBarrel_
std::vector< int > severitiesexclEB_
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducerHFHAD_
CacheData(const edm::ParameterSet &conf)
const_iterator end() const
Log< level::Info, false > LogInfo
edm::EDGetTokenT< HBHERecHitCollection > hbheRecHits_
edm::EDGetTokenT< edm::ValueMap< float > > phoNeutralHadronIsolationToken_
DetId seed() const
return DetId of seed
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedWorstVtxIsoToken_
bool hasActiveHcal(const reco::SuperCluster &sc) const
std::vector< double > preselCutValuesBarrel_
edm::EDGetTokenT< reco::PhotonCollection > photonProducerT_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
EcalPFClusterIsolation< reco::Photon > PhotonEcalPFClusterIsolation
XYZPointD XYZPoint
point in space with cartesian internal representation
std::array< float, 7 > hcalOverEcal
std::vector< Photon > PhotonCollection
collectin of Photon objects
std::vector< double > preselCutValuesEndcap_
T getParameter(std::string const &) const
const EcalClusterLazyTools::ESGetTokens ecalClusterESGetTokens_
const edm::InputTag photonProducer_
const LorentzVector & p4(P4type type) const
std::unique_ptr< ElectronHcalHelper > hcalHelperBc_
static void globalEndJob(const CacheData *)
std::string candidateP4type_
edm::EDGetTokenT< edm::ValueMap< float > > phoPhotonIsolationToken_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
tuple config
parse the configuration file
float chargedHadronPFPVIso
iterator find(key_type k)
static int position[264][3]
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducer_
edm::EDGetTokenT< edm::ValueMap< float > > phoPFECALClusIsolationToken_
EgammaHcalIsolation::arrayHB eThresHB
EgammaHcalIsolation::arrayHE eThresHE
double hcaletaStripEndcap_
edm::EDGetTokenT< reco::VertexCollection > vertexProducer_
Log< level::Warning, false > LogWarning
std::array< double, 4 > arrayHB
std::unique_ptr< PhotonMIPHaloTagger > photonMIPHaloTagger_
edm::EDGetTokenT< EcalRecHitCollection > preshowerHits_
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducerHCAL_
void setP4(P4type type, const LorentzVector &p4, float p4Error, bool setToRecoCandidate)
std::string valueMapPFCandPhoton_
std::array< double, 7 > arrayHE