66 const auto dnnEnabled = pset_dnn.
getParameter<
bool>(
"enabled");
70 config.modelsFiles = pset_dnn.getParameter<std::vector<std::string>>(
"modelsFiles");
71 config.scalersFiles = pset_dnn.getParameter<std::vector<std::string>>(
"scalersFiles");
72 config.outputDim = pset_dnn.getParameter<std::vector<unsigned int>>(
"outputDim");
73 const auto useEBModelInGap = pset_dnn.getParameter<
bool>(
"useEBModelInGap");
235 std::unique_ptr<PhotonEcalPFClusterIsolation>
ecalisoAlgo =
nullptr;
253 std::unique_ptr<PhotonHcalPFClusterIsolation>
hcalisoAlgo =
nullptr;
269 else if (
step ==
"oot")
271 else if (
step ==
"ootfinal")
273 else if (
step ==
"tmp")
277 <<
" reconstructStep " <<
step <<
" is invalid, the options are: tmp, final,oot or ootfinal" << std::endl;
283 ecalClusterESGetTokens_{consumesCollector()},
288 hcalHelperCone_(
nullptr),
289 hcalHelperBc_(
nullptr) {
291 cutsFromDB_ =
config.getParameter<
bool>(
"usePFThresholdsFromDB");
293 hcalCutsToken_ = esConsumes<HcalPFCuts, HcalPFCutsRcd>(
edm::ESInputTag(
"",
"withTopo"));
296 if (recoStep_.isFinal()) {
297 photonProducerT_ = consumes(photonProducer_);
304 phoChargedIsolationToken_ = getVMToken(
"chargedHadronIso");
305 phoNeutralHadronIsolationToken_ = getVMToken(
"neutralHadronIso");
306 phoPhotonIsolationToken_ = getVMToken(
"photonIso");
307 phoChargedWorstVtxIsoToken_ = getVMToken(
"chargedHadronWorstVtxIso");
308 phoChargedWorstVtxGeomVetoIsoToken_ = getVMToken(
"chargedHadronWorstVtxGeomVetoIso");
309 phoChargedPFPVIsoToken_ = getVMToken(
"chargedHadronPFPVIso");
313 if (
config.exists(
"pfECALClusIsolation")) {
314 phoPFECALClusIsolationToken_ = consumes(
config.getParameter<
edm::InputTag>(
"pfECALClusIsolation"));
316 if (
config.exists(
"pfHCALClusIsolation")) {
317 phoPFHCALClusIsolationToken_ = consumes(
config.getParameter<
edm::InputTag>(
"pfHCALClusIsolation"));
321 photonCoreProducerT_ = consumes(photonProducer_);
325 if (not pfEg.label().empty()) {
326 pfEgammaCandidates_ = consumes(pfEg);
334 if (not hbhetag.label().empty())
335 hbheRecHits_ = consumes<HBHERecHitCollection>(hbhetag);
339 multThresEB_ =
config.getParameter<
double>(
"multThresEB");
340 multThresEE_ =
config.getParameter<
double>(
"multThresEE");
341 hOverEConeSize_ =
config.getParameter<
double>(
"hOverEConeSize");
342 highEt_ =
config.getParameter<
double>(
"highEt");
344 minR9Barrel_ =
config.getParameter<
double>(
"minR9Barrel");
345 minR9Endcap_ =
config.getParameter<
double>(
"minR9Endcap");
346 usePrimaryVertex_ =
config.getParameter<
bool>(
"usePrimaryVertex");
347 runMIPTagger_ =
config.getParameter<
bool>(
"runMIPTagger");
348 runMVABasedHaloTagger_ =
config.getParameter<
bool>(
"runMVABasedHaloTagger");
355 auto const& flagnamesEB =
config.getParameter<std::vector<std::string>>(
"RecHitFlagToBeExcludedEB");
356 auto const& flagnamesEE =
config.getParameter<std::vector<std::string>>(
"RecHitFlagToBeExcludedEE");
358 flagsexclEB_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
359 flagsexclEE_ = StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
361 auto const& severitynamesEB =
config.getParameter<std::vector<std::string>>(
"RecHitSeverityToBeExcludedEB");
362 auto const& severitynamesEE =
config.getParameter<std::vector<std::string>>(
"RecHitSeverityToBeExcludedEE");
364 severitiesexclEB_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
365 severitiesexclEE_ = StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
367 photonEnergyCorrector_ = std::make_unique<PhotonEnergyCorrector>(
config, consumesCollector());
369 checkHcalStatus_ =
config.getParameter<
bool>(
"checkHcalStatus");
370 if (not hbheRecHits_.isUninitialized()) {
395 hcalHelperCone_ = std::make_unique<ElectronHcalHelper>(cfgCone, consumesCollector());
396 hcalHelperBc_ = std::make_unique<ElectronHcalHelper>(cfgBc, consumesCollector());
399 hcalRun2EffDepth_ =
config.getParameter<
bool>(
"hcalRun2EffDepth");
402 preselCutValuesBarrel_ = {
config.getParameter<
double>(
"minSCEtBarrel"),
403 config.getParameter<
double>(
"maxHoverEBarrel"),
404 config.getParameter<
double>(
"ecalRecHitSumEtOffsetBarrel"),
405 config.getParameter<
double>(
"ecalRecHitSumEtSlopeBarrel"),
406 config.getParameter<
double>(
"hcalRecHitSumEtOffsetBarrel"),
407 config.getParameter<
double>(
"hcalRecHitSumEtSlopeBarrel"),
408 config.getParameter<
double>(
"nTrackSolidConeBarrel"),
409 config.getParameter<
double>(
"nTrackHollowConeBarrel"),
410 config.getParameter<
double>(
"trackPtSumSolidConeBarrel"),
411 config.getParameter<
double>(
"trackPtSumHollowConeBarrel"),
412 config.getParameter<
double>(
"sigmaIetaIetaCutBarrel")};
414 preselCutValuesEndcap_ = {
config.getParameter<
double>(
"minSCEtEndcap"),
415 config.getParameter<
double>(
"maxHoverEEndcap"),
416 config.getParameter<
double>(
"ecalRecHitSumEtOffsetEndcap"),
417 config.getParameter<
double>(
"ecalRecHitSumEtSlopeEndcap"),
418 config.getParameter<
double>(
"hcalRecHitSumEtOffsetEndcap"),
419 config.getParameter<
double>(
"hcalRecHitSumEtSlopeEndcap"),
420 config.getParameter<
double>(
"nTrackSolidConeEndcap"),
421 config.getParameter<
double>(
"nTrackHollowConeEndcap"),
422 config.getParameter<
double>(
"trackPtSumSolidConeEndcap"),
423 config.getParameter<
double>(
"trackPtSumHollowConeEndcap"),
424 config.getParameter<
double>(
"sigmaIetaIetaCutEndcap")};
428 if (!recoStep_.isFinal()) {
435 consumesCollector());
437 photonMIPHaloTagger_ = std::make_unique<PhotonMIPHaloTagger>(
mipVariableSet, consumesCollector());
440 if (recoStep_.isFinal() && runMVABasedHaloTagger_) {
442 photonMVABasedHaloTagger_ =
473 produces<reco::PhotonCollection>(photonCollection_);
474 if (not pfEgammaCandidates_.isUninitialized()) {
475 produces<edm::ValueMap<reco::PhotonRef>>(valueMapPFCandPhoton_);
479 dnnPFidEnabled_ = pset_dnn.
getParameter<
bool>(
"enabled");
480 if (dnnPFidEnabled_) {
481 tfSessions_ = gcache->photonDNNEstimator->getSessions();
487 return std::make_unique<CacheData>(
config);
503 auto outputPhotonCollection_p = std::make_unique<reco::PhotonCollection>();
507 bool validPhotonCoreHandle =
false;
509 bool validPhotonHandle =
false;
541 validPhotonHandle =
true;
547 if (photonCoreHandle.
isValid()) {
548 validPhotonCoreHandle =
true;
564 if (!pfEGCandidateHandle.
isValid()) {
565 throw cms::Exception(
"GEDPhotonProducer") <<
"Error! Can't get the pfEgammaCandidates";
576 throw cms::Exception(
"GEDPhotonProducer") <<
"Error! Can't get the pfCandidates";
626 if (validPhotonCoreHandle)
638 *outputPhotonCollection_p,
650 *outputPhotonCollection_p,
652 phoChargedIsolationMap,
653 phoNeutralHadronIsolationMap,
654 phoPhotonIsolationMap,
655 phoChargedWorstVtxIsoMap,
656 phoChargedWorstVtxGeomVetoIsoMap,
657 phoChargedPFPVIsoMap,
658 phoPFECALClusIsolationMap,
659 phoPFHCALClusIsolationMap);
662 edm::LogInfo(
"GEDPhotonProducer") <<
" Put in the event " << iSC <<
" Photon Candidates \n";
666 for (
auto& pho : *outputPhotonCollection_p)
667 pho.hcalToRun2EffDepth();
673 auto pfEGCandToPhotonMap_p = std::make_unique<edm::ValueMap<reco::PhotonRef>>();
675 unsigned nObj = pfEGCandidateHandle->size();
676 std::vector<reco::PhotonRef>
values(nObj);
678 for (
unsigned int lCand = 0; lCand < nObj; lCand++) {
682 for (
unsigned int lSC = 0; lSC < photonOrphHandle->size(); lSC++) {
685 if (pfScRef != scRef)
687 values[lCand] = photonRef;
711 std::vector<double> preselCutValues;
712 std::vector<int> flags_, severitiesexcl_;
714 for (
unsigned int lSC = 0; lSC < photonCoreHandle->size(); lSC++) {
722 DetId::Detector thedet = scRef->seed()->hitsAndFractions()[0].first.det();
723 int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
726 hits = ecalBarrelHits;
731 hits = ecalEndcapHits;
740 edm::LogWarning(
"") <<
"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster: " << thedet
746 ptFast(parentSCRef->energy(), parentSCRef->position(), {0, 0, 0}) <= preselCutValues[0])
754 float e2x5 = (
hits !=
nullptr ? EcalClusterTools::e2x5Max(*(scRef->seed()),
hits,
topology) : 0.f);
755 float e3x3 = (
hits !=
nullptr ? EcalClusterTools::e3x3(*(scRef->seed()),
hits,
topology) : 0.f);
758 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
760 const auto& locCov = (
hits !=
nullptr ? EcalClusterTools::localCovariances(*(scRef->seed()),
hits,
topology)
761 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
773 const auto& full5x5_cov =
775 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
779 const auto& full5x5_locCov =
787 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
789 float full5x5_sigmaEtaEta =
sqrt(full5x5_cov[0]);
791 float full5x5_sigmaIetaIphi = full5x5_locCov[1];
819 newCandidate.setFiducialVolumeFlags(fiducialFlags);
820 newCandidate.setIsolationVariables(isolVarR04, isolVarR03);
826 showerShape.
e3x3 = e3x3;
833 (hcalHelperCone !=
nullptr) ? hcalHelperCone->
hcalESum(*scRef,
id + 1,
hcalCuts_) / scRef->energy() : 0.f;
836 (hcalHelperBc !=
nullptr) ? hcalHelperBc->
hcalESum(*scRef,
id + 1,
hcalCuts_) / scRef->energy() : 0.f;
839 if (hcalHelperBc !=
nullptr)
845 const float sep = locCov[1];
853 showerShape.
e1x3 = (
hits !=
nullptr ? EcalClusterTools::e1x3(*(scRef->seed()),
hits,
topology) : 0.f);
854 showerShape.
e2x2 = (
hits !=
nullptr ? EcalClusterTools::e2x2(*(scRef->seed()),
hits,
topology) : 0.f);
874 const float sigmaRR = toolsforES.eseffsirir(*scRef);
876 newCandidate.setShowerShapeVariables(showerShape);
881 bool isSeedSaturated =
false;
882 if (
hits !=
nullptr) {
883 const auto hitsAndFractions = scRef->hitsAndFractions();
884 for (
auto const& hitFractionPair : hitsAndFractions) {
888 if (
ecalRecHit->checkFlag(EcalRecHit::Flags::kSaturated)) {
891 isSeedSaturated =
true;
898 newCandidate.setSaturationInfo(saturationInfo);
902 full5x5_showerShape.
e1x5 = full5x5_e1x5;
903 full5x5_showerShape.
e2x5 = full5x5_e2x5;
904 full5x5_showerShape.
e3x3 = full5x5_e3x3;
905 full5x5_showerShape.
e5x5 = full5x5_e5x5;
907 full5x5_showerShape.
sigmaEtaEta = full5x5_sigmaEtaEta;
911 const float full5x5_sep = full5x5_sigmaIetaIphi;
916 full5x5_showerShape.
eLeft =
918 full5x5_showerShape.
eRight =
940 full5x5_showerShape.
smMajor = 0.f;
941 full5x5_showerShape.
smMinor = 0.f;
942 full5x5_showerShape.
smAlpha = 0.f;
948 (hcalHelperCone !=
nullptr) ? hcalHelperCone->
hcalESum(*scRef,
id + 1,
hcalCuts_) / full5x5_e5x5 : 0.f;
950 (hcalHelperBc !=
nullptr) ? hcalHelperBc->
hcalESum(*scRef,
id + 1,
hcalCuts_) / full5x5_e5x5 : 0.f;
953 newCandidate.full5x5_setShowerShapeVariables(full5x5_showerShape);
973 newCandidate.setPflowIsolationVariables(pfIso);
985 newCandidate.setMass(0.0);
989 newCandidate.setMass(0.0);
993 newCandidate.setMass(0.0);
997 newCandidate.setMass(0.0);
1002 newCandidate.setP4(p4);
1006 fiducialFlags.
isEE =
true;
1007 newCandidate.setFiducialVolumeFlags(fiducialFlags);
1013 newCandidate.setMIPVariables(mipVar);
1017 bool isLooseEM =
true;
1018 if (newCandidate.pt() <
highEt_) {
1019 if (newCandidate.hadronicOverEm() >= preselCutValues[1])
1021 if (newCandidate.ecalRecHitSumEtConeDR04() > preselCutValues[2] + preselCutValues[3] * newCandidate.pt())
1023 if (newCandidate.hcalTowerSumEtConeDR04() > preselCutValues[4] + preselCutValues[5] * newCandidate.pt())
1025 if (newCandidate.nTrkSolidConeDR04() >
int(preselCutValues[6]))
1027 if (newCandidate.nTrkHollowConeDR04() >
int(preselCutValues[7]))
1029 if (newCandidate.trkSumPtSolidConeDR04() > preselCutValues[8])
1031 if (newCandidate.trkSumPtHollowConeDR04() > preselCutValues[9])
1033 if (newCandidate.sigmaIetaIeta() > preselCutValues[10])
1043 LogDebug(
"GEDPhotonProducer") <<
"Getting DNN PFId for photons";
1047 const auto& [iModel,
values] = dnn_photon_pfid[ipho];
1051 photon.setPflowIDVariables(pfID);
1073 std::vector<double> preselCutValues;
1075 for (
unsigned int lSC = 0; lSC < photonHandle->size(); lSC++) {
1079 DetId::Detector thedet = scRef->seed()->hitsAndFractions()[0].first.det();
1080 int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
1088 edm::LogWarning(
"") <<
"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster" << thedet <<
' ' 1094 ptFast(parentSCRef->energy(), parentSCRef->position(), {0, 0, 0}) <= preselCutValues[0])
1115 pfIso.
photonIso = (*photons)[photonPtr];
void setPflowIsolationVariables(const PflowIsolationVariables &pfisol)
Set Particle Flow Isolation variables.
GEDPhotonProducer(const edm::ParameterSet &ps, const CacheData *gcache)
std::unique_ptr< PhotonHcalPFClusterIsolation > hcalisoAlgo
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
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)
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
bool get(ProductID const &oid, Handle< PROD > &result) const
isolationSumsCalculatorSet
void setMass(double m) final
set particle mass
bool hasActiveHcal(const reco::SuperCluster &sc) const
const edm::ESGetToken< EcalPFRecHitThresholds, EcalPFRecHitThresholdsRcd > ecalPFRechitThresholdsToken_
double ecaletaStripEndcap_
double ecaletaStripBarrel_
void produce(edm::Event &evt, const edm::EventSetup &es) override
DetId seed() const
return DetId of seed
std::unique_ptr< PhotonEnergyCorrector > photonEnergyCorrector_
constexpr bool isUninitialized() const noexcept
CaloGeometry const * caloGeom_
std::unique_ptr< PhotonEcalPFClusterIsolation > ecalisoAlgo
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducerHFEM_
std::vector< int > flagsexclEB_
bool isNonnull() const
Checks for non-null.
float chargedHadronWorstVtxGeomVetoIso
void endStream() override
std::vector< Vertex > VertexCollection
collection of Vertex objects
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const edm::ESGetToken< CaloTopology, CaloTopologyRecord > caloTopologyToken_
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHits_
float chargedHadronWorstVtxIso
std::array< float, 7 > hcalOverEcalBc
void setHaloTaggerMVAVal(float x)
set the haloTaggerMVAVal here
constexpr bool isFinite(T x)
T get() const
get a component
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)
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
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_
std::unique_ptr< const PhotonMIPHaloTagger > photonMIPHaloTagger_
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken
bool closeSession(Session *&session)
std::vector< int > flagsexclEE_
std::unique_ptr< const PhotonDNNEstimator > photonDNNEstimator
edm::EDGetTokenT< reco::PhotonCoreCollection > photonCoreProducerT_
#define DEFINE_FWK_MODULE(type)
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)
Log< level::Info, false > LogInfo
edm::EDGetTokenT< HBHERecHitCollection > hbheRecHits_
edm::EDGetTokenT< edm::ValueMap< float > > phoNeutralHadronIsolationToken_
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedWorstVtxIsoToken_
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_
const EcalClusterLazyTools::ESGetTokens ecalClusterESGetTokens_
const edm::InputTag photonProducer_
std::unique_ptr< ElectronHcalHelper > hcalHelperBc_
auto hcalTowersBehindClusters(const reco::SuperCluster &sc) const
static void globalEndJob(const CacheData *)
std::string candidateP4type_
edm::EDGetTokenT< edm::ValueMap< float > > phoPhotonIsolationToken_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
float chargedHadronPFPVIso
Handle< PROD > getHandle(EDGetTokenT< PROD > token) const
static int position[264][3]
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducer_
edm::EDGetTokenT< edm::ValueMap< float > > phoPFECALClusIsolationToken_
dictionary config
Read in AllInOne config in JSON format.
bool runMVABasedHaloTagger_
const LorentzVector & p4(P4type type) const
EgammaHcalIsolation::arrayHB eThresHB
const std::string & fullPath() const
HcalPFCuts const * hcalCuts_
EgammaHcalIsolation::arrayHE eThresHE
edm::ESGetToken< HcalPFCuts, HcalPFCutsRcd > hcalCutsToken_
double hcaletaStripEndcap_
edm::EDGetTokenT< reco::VertexCollection > vertexProducer_
Log< level::Warning, false > LogWarning
double hcalESum(const reco::SuperCluster &, int depth, const HcalPFCuts *hcalCuts) const
std::array< double, 4 > arrayHB
std::unique_ptr< const PhotonMVABasedHaloTagger > photonMVABasedHaloTagger_
edm::EDGetTokenT< EcalRecHitCollection > preshowerHits_
edm::EDGetTokenT< reco::PFClusterCollection > pfClusterProducerHCAL_
void setP4(P4type type, const LorentzVector &p4, float p4Error, bool setToRecoCandidate)
std::unique_ptr< const GBRForest > haloTaggerGBR
std::string valueMapPFCandPhoton_
std::array< double, 7 > arrayHE