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()) {
429 photonIsoCalculator_ = std::make_unique<PhotonIsolationCalculator>();
436 consumesCollector());
437 photonMIPHaloTagger_ = std::make_unique<PhotonMIPHaloTagger>();
442 if (recoStep_.isFinal() && runMVABasedHaloTagger_) {
444 photonMVABasedHaloTagger_ =
475 produces<reco::PhotonCollection>(photonCollection_);
476 if (not pfEgammaCandidates_.isUninitialized()) {
477 produces<edm::ValueMap<reco::PhotonRef>>(valueMapPFCandPhoton_);
481 dnnPFidEnabled_ = pset_dnn.
getParameter<
bool>(
"enabled");
482 if (dnnPFidEnabled_) {
483 tfSessions_ = gcache->photonDNNEstimator->getSessions();
489 return std::make_unique<CacheData>(
config);
505 auto outputPhotonCollection_p = std::make_unique<reco::PhotonCollection>();
509 bool validPhotonCoreHandle =
false;
511 bool validPhotonHandle =
false;
543 validPhotonHandle =
true;
549 if (photonCoreHandle.
isValid()) {
550 validPhotonCoreHandle =
true;
566 if (!pfEGCandidateHandle.
isValid()) {
567 throw cms::Exception(
"GEDPhotonProducer") <<
"Error! Can't get the pfEgammaCandidates";
578 throw cms::Exception(
"GEDPhotonProducer") <<
"Error! Can't get the pfCandidates";
628 if (validPhotonCoreHandle)
640 *outputPhotonCollection_p,
652 *outputPhotonCollection_p,
654 phoChargedIsolationMap,
655 phoNeutralHadronIsolationMap,
656 phoPhotonIsolationMap,
657 phoChargedWorstVtxIsoMap,
658 phoChargedWorstVtxGeomVetoIsoMap,
659 phoChargedPFPVIsoMap,
660 phoPFECALClusIsolationMap,
661 phoPFHCALClusIsolationMap);
664 edm::LogInfo(
"GEDPhotonProducer") <<
" Put in the event " << iSC <<
" Photon Candidates \n";
668 for (
auto& pho : *outputPhotonCollection_p)
669 pho.hcalToRun2EffDepth();
675 auto pfEGCandToPhotonMap_p = std::make_unique<edm::ValueMap<reco::PhotonRef>>();
677 unsigned nObj = pfEGCandidateHandle->size();
678 std::vector<reco::PhotonRef>
values(nObj);
680 for (
unsigned int lCand = 0; lCand < nObj; lCand++) {
684 for (
unsigned int lSC = 0; lSC < photonOrphHandle->size(); lSC++) {
687 if (pfScRef != scRef)
689 values[lCand] = photonRef;
713 std::vector<double> preselCutValues;
714 std::vector<int> flags_, severitiesexcl_;
716 for (
unsigned int lSC = 0; lSC < photonCoreHandle->size(); lSC++) {
724 DetId::Detector thedet = scRef->seed()->hitsAndFractions()[0].first.det();
725 int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
728 hits = ecalBarrelHits;
733 hits = ecalEndcapHits;
742 edm::LogWarning(
"") <<
"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster: " << thedet
748 ptFast(parentSCRef->energy(), parentSCRef->position(), {0, 0, 0}) <= preselCutValues[0])
756 float e2x5 = (
hits !=
nullptr ? EcalClusterTools::e2x5Max(*(scRef->seed()),
hits,
topology) : 0.f);
757 float e3x3 = (
hits !=
nullptr ? EcalClusterTools::e3x3(*(scRef->seed()),
hits,
topology) : 0.f);
760 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
762 const auto& locCov = (
hits !=
nullptr ? EcalClusterTools::localCovariances(*(scRef->seed()),
hits,
topology)
763 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
775 const auto& full5x5_cov =
777 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
781 const auto& full5x5_locCov =
789 : std::array<float, 3>({{0.f, 0.f, 0.f}}));
791 float full5x5_sigmaEtaEta =
sqrt(full5x5_cov[0]);
793 float full5x5_sigmaIetaIphi = full5x5_locCov[1];
821 newCandidate.setFiducialVolumeFlags(fiducialFlags);
822 newCandidate.setIsolationVariables(isolVarR04, isolVarR03);
828 showerShape.
e3x3 = e3x3;
835 (hcalHelperCone !=
nullptr) ? hcalHelperCone->
hcalESum(*scRef,
id + 1,
hcalCuts_) / scRef->energy() : 0.f;
838 (hcalHelperBc !=
nullptr) ? hcalHelperBc->
hcalESum(*scRef,
id + 1,
hcalCuts_) / scRef->energy() : 0.f;
841 if (hcalHelperBc !=
nullptr)
847 const float sep = locCov[1];
855 showerShape.
e1x3 = (
hits !=
nullptr ? EcalClusterTools::e1x3(*(scRef->seed()),
hits,
topology) : 0.f);
856 showerShape.
e2x2 = (
hits !=
nullptr ? EcalClusterTools::e2x2(*(scRef->seed()),
hits,
topology) : 0.f);
876 const float sigmaRR = toolsforES.eseffsirir(*scRef);
878 newCandidate.setShowerShapeVariables(showerShape);
883 bool isSeedSaturated =
false;
884 if (
hits !=
nullptr) {
885 const auto hitsAndFractions = scRef->hitsAndFractions();
886 for (
auto const& hitFractionPair : hitsAndFractions) {
890 if (
ecalRecHit->checkFlag(EcalRecHit::Flags::kSaturated)) {
893 isSeedSaturated =
true;
900 newCandidate.setSaturationInfo(saturationInfo);
904 full5x5_showerShape.
e1x5 = full5x5_e1x5;
905 full5x5_showerShape.
e2x5 = full5x5_e2x5;
906 full5x5_showerShape.
e3x3 = full5x5_e3x3;
907 full5x5_showerShape.
e5x5 = full5x5_e5x5;
909 full5x5_showerShape.
sigmaEtaEta = full5x5_sigmaEtaEta;
913 const float full5x5_sep = full5x5_sigmaIetaIphi;
918 full5x5_showerShape.
eLeft =
920 full5x5_showerShape.
eRight =
942 full5x5_showerShape.
smMajor = 0.f;
943 full5x5_showerShape.
smMinor = 0.f;
944 full5x5_showerShape.
smAlpha = 0.f;
950 (hcalHelperCone !=
nullptr) ? hcalHelperCone->
hcalESum(*scRef,
id + 1,
hcalCuts_) / full5x5_e5x5 : 0.f;
952 (hcalHelperBc !=
nullptr) ? hcalHelperBc->
hcalESum(*scRef,
id + 1,
hcalCuts_) / full5x5_e5x5 : 0.f;
955 newCandidate.full5x5_setShowerShapeVariables(full5x5_showerShape);
975 newCandidate.setPflowIsolationVariables(pfIso);
987 newCandidate.setMass(0.0);
991 newCandidate.setMass(0.0);
995 newCandidate.setMass(0.0);
999 newCandidate.setMass(0.0);
1004 newCandidate.setP4(p4);
1008 fiducialFlags.
isEE =
true;
1009 newCandidate.setFiducialVolumeFlags(fiducialFlags);
1016 newCandidate.setMIPVariables(mipVar);
1020 bool isLooseEM =
true;
1021 if (newCandidate.pt() <
highEt_) {
1022 if (newCandidate.hadronicOverEm() >= preselCutValues[1])
1024 if (newCandidate.ecalRecHitSumEtConeDR04() > preselCutValues[2] + preselCutValues[3] * newCandidate.pt())
1026 if (newCandidate.hcalTowerSumEtConeDR04() > preselCutValues[4] + preselCutValues[5] * newCandidate.pt())
1028 if (newCandidate.nTrkSolidConeDR04() >
int(preselCutValues[6]))
1030 if (newCandidate.nTrkHollowConeDR04() >
int(preselCutValues[7]))
1032 if (newCandidate.trkSumPtSolidConeDR04() > preselCutValues[8])
1034 if (newCandidate.trkSumPtHollowConeDR04() > preselCutValues[9])
1036 if (newCandidate.sigmaIetaIeta() > preselCutValues[10])
1046 LogDebug(
"GEDPhotonProducer") <<
"Getting DNN PFId for photons";
1050 const auto& [iModel,
values] = dnn_photon_pfid[ipho];
1054 photon.setPflowIDVariables(pfID);
1076 std::vector<double> preselCutValues;
1078 for (
unsigned int lSC = 0; lSC < photonHandle->size(); lSC++) {
1082 DetId::Detector thedet = scRef->seed()->hitsAndFractions()[0].first.det();
1083 int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
1091 edm::LogWarning(
"") <<
"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster" << thedet <<
' ' 1097 ptFast(parentSCRef->energy(), parentSCRef->position(), {0, 0, 0}) <= preselCutValues[0])
1118 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
std::string fullPath() const
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
std::unique_ptr< PhotonMVABasedHaloTagger > photonMVABasedHaloTagger_
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_
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
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< PhotonMIPHaloTagger > photonMIPHaloTagger_
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