48 inline double ptFast(
const double energy,
51 const auto v = position - origin;
62 else if(step==
"tmp")
flags_ = 0;
64 throw cms::Exception(
"InvalidConfig") <<
" reconstructStep "<<step<<
" is invalid, the options are: tmp, final,oot or ootfinal"<<std::endl;
112 if (not pfEg.label().empty())
114 consumes<reco::PFCandidateCollection>(pfEg);
125 if (not hcTow.label().empty())
127 consumes<CaloTowerCollection>(hcTow);
149 const std::vector<std::string> flagnamesEB =
150 config.
getParameter<std::vector<std::string> >(
"RecHitFlagToBeExcludedEB");
152 const std::vector<std::string> flagnamesEE =
153 config.
getParameter<std::vector<std::string> >(
"RecHitFlagToBeExcludedEE");
156 StringToEnumValue<EcalRecHit::Flags>(flagnamesEB);
159 StringToEnumValue<EcalRecHit::Flags>(flagnamesEE);
161 const std::vector<std::string> severitynamesEB =
162 config.
getParameter<std::vector<std::string> >(
"RecHitSeverityToBeExcludedEB");
165 StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEB);
167 const std::vector<std::string> severitynamesEE =
168 config.
getParameter<std::vector<std::string> >(
"RecHitSeverityToBeExcludedEE");
171 StringToEnumValue<EcalSeverityLevel::SeverityLevel>(severitynamesEE);
267 auto outputPhotonCollection_p = std::make_unique<reco::PhotonCollection>();
272 bool validPhotonCoreHandle=
false;
274 bool validPhotonHandle=
false;
306 validPhotonHandle=
true;
313 if (photonCoreHandle.
isValid()) {
314 validPhotonCoreHandle=
true;
322 bool validEcalRecHits=
true;
326 if (!barrelHitHandle.
isValid()) {
328 <<
"Error! Can't get the barrelEcalHits";
335 if (!endcapHitHandle.
isValid()) {
337 <<
"Error! Can't get the endcapEcalHits";
341 bool validPreshowerRecHits=
true;
345 if (!preshowerHitHandle.
isValid()) {
347 <<
"Error! Can't get the preshowerEcalHits";
349 if( validPreshowerRecHits ) preshowerRecHits = *(preshowerHitHandle.
product());
357 if (!pfEGCandidateHandle.
isValid()) {
359 <<
"Error! Can't get the pfEgammaCandidates";
371 <<
"Error! Can't get the pfCandidates";
402 bool validVertex=
true;
407 <<
"Error! Can't get the product primary Vertex Collection";
425 if ( validPhotonCoreHandle)
436 outputPhotonCollection,
448 outputPhotonCollection,
450 phoChargedIsolationMap,
451 phoNeutralHadronIsolationMap,
452 phoPhotonIsolationMap,
453 phoChargedWorstVtxIsoMap,
454 phoChargedWorstVtxGeomVetoIsoMap,
455 phoChargedPFPVIsoMap,
456 phoPFECALClusIsolationMap,
457 phoPFHCALClusIsolationMap);
462 edm::LogInfo(
"GEDPhotonProducer") <<
" Put in the event " << iSC <<
" Photon Candidates \n";
463 outputPhotonCollection_p->assign(outputPhotonCollection.begin(),outputPhotonCollection.end());
469 auto pfEGCandToPhotonMap_p = std::make_unique<edm::ValueMap<reco::PhotonRef>>();
471 unsigned nObj = pfEGCandidateHandle->size();
472 std::vector<reco::PhotonRef>
values(nObj);
474 for(
unsigned int lCand=0; lCand < nObj; lCand++) {
478 for(
unsigned int lSC=0; lSC < photonOrphHandle->size(); lSC++) {
481 if ( pfScRef != scRef )
continue;
482 values[lCand] = photonRef;
487 filler.insert(pfEGCandidateHandle,values.begin(),values.end());
515 std::vector<double> preselCutValues;
516 std::vector<int> flags_, severitiesexcl_;
518 for(
unsigned int lSC=0; lSC < photonCoreHandle->size(); lSC++) {
529 DetId::Detector thedet = scRef->seed()->hitsAndFractions()[0].first.det();
530 int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
533 hits = ecalBarrelHits;
538 hits = ecalEndcapHits;
547 edm::LogWarning(
"")<<
"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster: " << thedet <<
' ' << subdet;
555 ptFast(parentSCRef->energy(),parentSCRef->position(),
math::XYZPoint(0,0,0)) <= preselCutValues[0] )
continue;
561 std::vector<CaloTowerDetId> TowersBehindClus;
562 float hcalDepth1OverEcalBc,hcalDepth2OverEcalBc;
563 hcalDepth1OverEcalBc=hcalDepth2OverEcalBc=0.f;
564 bool invalidHcal =
false;
575 TowersBehindClus = towerIsoBehindClus.
towersOf(*scRef);
576 hcalDepth1OverEcalBc = towerIsoBehindClus.
getDepth1HcalESum(TowersBehindClus)/scRef->energy();
577 hcalDepth2OverEcalBc = towerIsoBehindClus.
getDepth2HcalESum(TowersBehindClus)/scRef->energy();
579 if (
checkHcalStatus_ && hcalDepth1OverEcalBc == 0 && hcalDepth2OverEcalBc == 0) {
580 invalidHcal = !towerIsoBehindClus.
hasActiveHcal(TowersBehindClus);
590 float e1x5 = ( hits !=
nullptr ? EcalClusterTools::e1x5( *(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
591 float e2x5 = ( hits !=
nullptr ? EcalClusterTools::e2x5Max( *(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
592 float e3x3 = ( hits !=
nullptr ? EcalClusterTools::e3x3( *(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
593 float e5x5 = ( hits !=
nullptr ? EcalClusterTools::e5x5( *(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
594 std::vector<float> cov = ( hits !=
nullptr ? EcalClusterTools::covariances( *(scRef->seed()), &(*hits), &(*topology),
geometry) : std::vector<float>( {0.f,0.f,0.f} ) );
595 std::vector<float> locCov = ( hits !=
nullptr ? EcalClusterTools::localCovariances( *(scRef->seed()), &(*hits), &(*topology)) : std::vector<float>( {0.f,0.f,0.f} ) );
598 float sigmaIetaIeta =
sqrt(locCov[0]);
610 float full5x5_sigmaEtaEta =
sqrt(full5x5_cov[0]);
618 double photonEnergy=1.;
620 if (!vertexCollection.empty()) vtx = vertexCollection.begin()->position();
639 newCandidate.setFiducialVolumeFlags( fiducialFlags );
640 newCandidate.setIsolationVariables(isolVarR04, isolVarR03 );
645 showerShape.
e1x5= e1x5;
646 showerShape.
e2x5= e2x5;
647 showerShape.
e3x3= e3x3;
648 showerShape.
e5x5= e5x5;
660 const float sep = locCov[1];
663 showerShape.
e2nd = ( hits !=
nullptr ? EcalClusterTools::e2nd(*(scRef->seed()),&(*hits)) : 0.
f );
664 showerShape.
eTop = ( hits !=
nullptr ? EcalClusterTools::eTop(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
665 showerShape.
eLeft = ( hits !=
nullptr ? EcalClusterTools::eLeft(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
666 showerShape.
eRight = ( hits !=
nullptr ? EcalClusterTools::eRight(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
667 showerShape.
eBottom = ( hits !=
nullptr ? EcalClusterTools::eBottom(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
668 showerShape.
e1x3 = ( hits !=
nullptr ? EcalClusterTools::e1x3(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
669 showerShape.
e2x2 = ( hits !=
nullptr ? EcalClusterTools::e2x2(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
670 showerShape.
e2x5Max = ( hits !=
nullptr ? EcalClusterTools::e2x5Max(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
671 showerShape.
e2x5Left = ( hits !=
nullptr ? EcalClusterTools::e2x5Left(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
672 showerShape.
e2x5Right = ( hits !=
nullptr ? EcalClusterTools::e2x5Right(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
673 showerShape.
e2x5Top = ( hits !=
nullptr ? EcalClusterTools::e2x5Top(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
674 showerShape.
e2x5Bottom = ( hits !=
nullptr ? EcalClusterTools::e2x5Bottom(*(scRef->seed()), &(*hits), &(*topology)) : 0.
f );
676 Cluster2ndMoments clus2ndMoments = EcalClusterTools::cluster2ndMoments(*(scRef->seed()),*hits);
689 const float sigmaRR = toolsforES.eseffsirir( *scRef );
691 newCandidate.setShowerShapeVariables ( showerShape );
696 int nSaturatedXtals = 0;
697 bool isSeedSaturated =
false;
698 if (hits !=
nullptr) {
699 const auto hitsAndFractions = scRef->hitsAndFractions();
700 for (
auto&& hitFractionPair : hitsAndFractions) {
703 if (
ecalRecHit->checkFlag(EcalRecHit::Flags::kSaturated)) {
706 isSeedSaturated =
true;
712 newCandidate.setSaturationInfo(saturationInfo);
716 full5x5_showerShape.
e1x5= full5x5_e1x5;
717 full5x5_showerShape.
e2x5= full5x5_e2x5;
718 full5x5_showerShape.
e3x3= full5x5_e3x3;
719 full5x5_showerShape.
e5x5= full5x5_e5x5;
721 full5x5_showerShape.
sigmaEtaEta = full5x5_sigmaEtaEta;
724 const float full5x5_spp = (!
edm::isFinite(full5x5_locCov[2]) ? 0. :
sqrt(full5x5_locCov[2]));
725 const float full5x5_sep = full5x5_locCov[1];
746 full5x5_showerShape.
smMajor = 0.f;
747 full5x5_showerShape.
smMinor = 0.f;
748 full5x5_showerShape.
smAlpha = 0.f;
752 newCandidate.full5x5_setShowerShapeVariables ( full5x5_showerShape );
781 newCandidate.setP4(
p4);
785 fiducialFlags.
isEE =
true;
786 newCandidate.setFiducialVolumeFlags(fiducialFlags);
802 newCandidate.setMIPVariables(mipVar);
809 if ( newCandidate.pt() <
highEt_) {
810 if ( newCandidate.hadronicOverEm() >= preselCutValues[1] ) isLooseEM=
false;
811 if ( newCandidate.ecalRecHitSumEtConeDR04() > preselCutValues[2]+ preselCutValues[3]*newCandidate.pt() ) isLooseEM=
false;
812 if ( newCandidate.hcalTowerSumEtConeDR04() > preselCutValues[4]+ preselCutValues[5]*newCandidate.pt() ) isLooseEM=
false;
813 if ( newCandidate.nTrkSolidConeDR04() >
int(preselCutValues[6]) ) isLooseEM=
false;
814 if ( newCandidate.nTrkHollowConeDR04() >
int(preselCutValues[7]) ) isLooseEM=
false;
815 if ( newCandidate.trkSumPtSolidConeDR04() > preselCutValues[8] ) isLooseEM=
false;
816 if ( newCandidate.trkSumPtHollowConeDR04() > preselCutValues[9] ) isLooseEM=
false;
817 if ( newCandidate.sigmaIetaIeta() > preselCutValues[10] ) isLooseEM=
false;
823 outputPhotonCollection.push_back(newCandidate);
851 std::vector<double> preselCutValues;
854 for(
unsigned int lSC=0; lSC < photonHandle->size(); lSC++) {
858 DetId::Detector thedet = scRef->seed()->hitsAndFractions()[0].first.det();
859 int subdet = scRef->seed()->hitsAndFractions()[0].first.subdetId();
867 edm::LogWarning(
"")<<
"GEDPhotonProducer: do not know if it is a barrel or endcap SuperCluster" << thedet <<
' ' << subdet;
874 ptFast(parentSCRef->energy(),parentSCRef->position(),
math::XYZPoint(0,0,0)) <= preselCutValues[0] )
continue;
930 outputPhotonCollection.push_back(newCandidate);
edm::InputTag photonProducer_
void setPflowIsolationVariables(const PflowIsolationVariables &pfisol)
Set Particle Flow Isolation variables.
T getParameter(std::string const &) const
PhotonEnergyCorrector * thePhotonEnergyCorrector_
PhotonMIPHaloTagger * thePhotonMIPHaloTagger_
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void calculate(const reco::Photon *, const edm::Event &, const edm::EventSetup &es, reco::Photon::FiducialFlags &phofid, reco::Photon::IsolationVariables &phoisolR03, reco::Photon::IsolationVariables &phoisolR04) const
bool isNonnull() const
Checks for non-null.
edm::EDGetTokenT< reco::PFCandidateCollection > pfCandidates_
edm::ESHandle< CaloGeometry > theCaloGeom_
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)
void beginRun(edm::Run const &r, edm::EventSetup const &es) final
edm::EDGetTokenT< CaloTowerCollection > hcalTowers_
isolationSumsCalculatorSet
CaloTopology const * topology(0)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
void produce(edm::Event &evt, const edm::EventSetup &es) override
float hcalDepth2OverEcalBc
~GEDPhotonProducer() override
bool exists(std::string const ¶meterName) const
checks if a parameter exists
std::vector< int > flagsexclEB_
float chargedHadronWorstVtxGeomVetoIso
std::vector< Vertex > VertexCollection
collection of Vertex objects
edm::EDGetTokenT< EcalRecHitCollection > endcapEcalHits_
float chargedHadronWorstVtxIso
constexpr bool isFinite(T x)
PhotonIsolationCalculator * thePhotonIsolationCalculator_
std::vector< int > severitiesexclEE_
std::unique_ptr< ModifyObjectValueBase > & gedRegression()
double ptFast(const double energy, const math::XYZPoint &position, const math::XYZPoint &origin)
std::string photonCollection_
bool hasActiveHcal(const reco::SuperCluster &sc) const
RecoStepInfo(const std::string &recoStep)
edm::ESHandle< CaloTopology > theCaloTopo_
void setTowerCollection(const CaloTowerCollection *towercollection)
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedPFPVIsoToken_
edm::EDGetTokenT< EcalRecHitCollection > barrelEcalHits_
PositionCalc posCalculator_
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedWorstVtxGeomVetoIsoToken_
double getDepth1HcalESum(const reco::SuperCluster &sc) const
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedIsolationToken_
void setup(const edm::ParameterSet &conf, std::vector< int > const &flagsEB_, std::vector< int > const &flagsEE_, std::vector< int > const &severitiesEB_, std::vector< int > const &severitiesEE_, edm::ConsumesCollector &&iC)
void setPflowIDVariables(const PflowIDVariables &pfid)
std::vector< int > flagsexclEE_
edm::EDGetTokenT< reco::PhotonCoreCollection > photonCoreProducerT_
edm::EDGetTokenT< edm::ValueMap< float > > phoPFHCALClusIsolationToken_
void init(const edm::EventSetup &theEventSetup)
void setup(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
double getTowerESum(const reco::Candidate *cand, const std::vector< CaloTowerDetId > *detIdToExclude=0) const
edm::EDGetTokenT< reco::PFCandidateCollection > pfEgammaCandidates_
std::vector< int > severitiesexclEB_
const_iterator end() const
void calculate(edm::Event &evt, reco::Photon &, int subdet, const reco::VertexCollection &vtxcol, const edm::EventSetup &iSetup)
edm::EDGetTokenT< edm::ValueMap< float > > phoNeutralHadronIsolationToken_
DetId seed() const
return DetId of seed
GEDPhotonProducer(const edm::ParameterSet &ps)
float hcalDepth1OverEcalBc
edm::EDGetTokenT< edm::ValueMap< float > > phoChargedWorstVtxIsoToken_
T const * product() const
std::vector< double > preselCutValuesBarrel_
edm::EDGetTokenT< reco::PhotonCollection > photonProducerT_
XYZVectorD XYZVector
spatial vector with cartesian internal representation
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< Photon > PhotonCollection
collectin of Photon objects
std::vector< double > preselCutValuesEndcap_
const LorentzVector & p4(P4type type) const
std::string candidateP4type_
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 edm::Handle< CaloTowerCollection > &hcalTowersHandle, const reco::VertexCollection &pvVertices, reco::PhotonCollection &outputCollection, int &iSC)
edm::EDGetTokenT< edm::ValueMap< float > > phoPhotonIsolationToken_
void endRun(edm::Run const &, edm::EventSetup const &) final
std::vector< CaloTowerDetId > towersOf(const reco::SuperCluster &sc) const
float chargedHadronPFPVIso
double getDepth2HcalESum(const reco::SuperCluster &sc) const
ESHandle< TrackerGeometry > geometry
iterator find(key_type k)
static int position[264][3]
edm::EDGetTokenT< edm::ValueMap< float > > phoPFECALClusIsolationToken_
bool isUninitialized() const
edm::EDGetTokenT< reco::VertexCollection > vertexProducer_
T const * product() const
edm::EDGetTokenT< EcalRecHitCollection > preshowerHits_
void setP4(P4type type, const LorentzVector &p4, float p4Error, bool setToRecoCandidate)
std::string valueMapPFCandPhoton_