CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
PhotonIDValueMapProducer Class Reference
Inheritance diagram for PhotonIDValueMapProducer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 PhotonIDValueMapProducer (const edm::ParameterSet &)
 
 ~PhotonIDValueMapProducer () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
virtual ~ProducerBase () noexcept(false)
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
virtual ~EDConsumerBase () noexcept(false)
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

reco::PFCandidate::ParticleType candidatePdgId (const edm::Ptr< reco::Candidate > candidate, bool isAOD)
 
template<class T , class U >
float computeWorstPFChargedIsolation (const T &photon, const U &pfCandidates, const edm::Handle< reco::VertexCollection > vertices, bool isAOD, float dRmax, float dxyMax, float dzMax, float dRvetoBarrel, float dRvetoEndcap, float ptMin)
 
std::pair< float, float > getTrackDxyDz (const edm::Ptr< reco::Candidate > &candidate, const reco::Particle::Point &vtxpos, bool isAOD)
 
void produce (edm::Event &, const edm::EventSetup &) override
 
void writeValueMap (edm::Event &iEvent, const edm::Handle< edm::View< reco::Photon > > &handle, const std::vector< float > &values, const std::string &label) const
 

Private Attributes

edm::EDGetTokenT< EcalRecHitCollectionebReducedRecHitCollection_
 
edm::EDGetTokenT< EcalRecHitCollectionebReducedRecHitCollectionMiniAOD_
 
edm::EDGetTokenT< EcalRecHitCollectioneeReducedRecHitCollection_
 
edm::EDGetTokenT< EcalRecHitCollectioneeReducedRecHitCollectionMiniAOD_
 
edm::EDGetTokenT< EcalRecHitCollectionesReducedRecHitCollection_
 
edm::EDGetTokenT< EcalRecHitCollectionesReducedRecHitCollectionMiniAOD_
 
std::unique_ptr< noZS::EcalClusterLazyToolslazyToolnoZS
 
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
 
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationTokenMiniAOD_
 
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandidatesToken_
 
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandidatesTokenMiniAOD_
 
edm::EDGetToken src_
 
edm::EDGetToken srcMiniAOD_
 
bool usesES_
 
edm::EDGetTokenT< reco::VertexCollectionvtxToken_
 
edm::EDGetTokenT< reco::VertexCollectionvtxTokenMiniAOD_
 

Static Private Attributes

static char phoChargedIsolation_ [] = "phoChargedIsolation"
 
static char phoESEffSigmaRR_ [] = "phoESEffSigmaRR"
 
static char phoFull5x5E1x3_ [] = "phoFull5x5E1x3"
 
static char phoFull5x5E2x2_ [] = "phoFull5x5E2x2"
 
static char phoFull5x5E2x5Max_ [] = "phoFull5x5E2x5Max"
 
static char phoFull5x5E5x5_ [] = "phoFull5x5E5x5"
 
static char phoFull5x5SigmaIEtaIEta_ [] = "phoFull5x5SigmaIEtaIEta"
 
static char phoFull5x5SigmaIEtaIPhi_ [] = "phoFull5x5SigmaIEtaIPhi"
 
static char phoNeutralHadronIsolation_ [] = "phoNeutralHadronIsolation"
 
static char phoPhotonIsolation_ [] = "phoPhotonIsolation"
 
static char phoWorstChargedIsolation_ [] = "phoWorstChargedIsolation"
 
static char phoWorstChargedIsolationWithConeVeto_ [] = "phoWorstChargedIsolationWithConeVeto"
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex >>
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 40 of file PhotonIDValueMapProducer.cc.

Constructor & Destructor Documentation

PhotonIDValueMapProducer::PhotonIDValueMapProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 138 of file PhotonIDValueMapProducer.cc.

References ebReducedRecHitCollection_, ebReducedRecHitCollectionMiniAOD_, eeReducedRecHitCollection_, eeReducedRecHitCollectionMiniAOD_, esReducedRecHitCollection_, esReducedRecHitCollectionMiniAOD_, edm::ParameterSet::getParameter(), edm::InputTag::label(), diffTwoXMLs::label, particleBasedIsolationToken_, pfCandidatesToken_, pfCandidatesTokenMiniAOD_, phoChargedIsolation_, phoESEffSigmaRR_, phoFull5x5E1x3_, phoFull5x5E2x2_, phoFull5x5E2x5Max_, phoFull5x5E5x5_, phoFull5x5SigmaIEtaIEta_, phoFull5x5SigmaIEtaIPhi_, phoNeutralHadronIsolation_, phoPhotonIsolation_, phoWorstChargedIsolation_, phoWorstChargedIsolationWithConeVeto_, src_, srcMiniAOD_, usesES_, vtxToken_, and vtxTokenMiniAOD_.

138  {
139 
140  //
141  // Declare consummables, handle both AOD and miniAOD case
142  //
143  ebReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
144  ("ebReducedRecHitCollection"));
145  ebReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
146  ("ebReducedRecHitCollectionMiniAOD"));
147 
148  eeReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
149  ("eeReducedRecHitCollection"));
150  eeReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
151  ("eeReducedRecHitCollectionMiniAOD"));
152 
153  if (!iConfig.getParameter<edm::InputTag>("esReducedRecHitCollection").label().empty() ||
154  !iConfig.getParameter<edm::InputTag>("esReducedRecHitCollectionMiniAOD").label().empty()) {
155  usesES_ = true;
156  esReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
157  ("esReducedRecHitCollection"));
158  esReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
159  ("esReducedRecHitCollectionMiniAOD"));
160 
161  } else {
162  usesES_ = false;
163  }
164 
165  vtxToken_ = mayConsume<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"));
166  vtxTokenMiniAOD_ = mayConsume<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("verticesMiniAOD"));
167 
168  // reco photons are castable into pat photons, so no need to handle reco/pat seprately
169  src_ = mayConsume<edm::View<reco::Photon> >(iConfig.getParameter<edm::InputTag>("src"));
170  srcMiniAOD_ = mayConsume<edm::View<reco::Photon> >(iConfig.getParameter<edm::InputTag>("srcMiniAOD"));
171 
172  // The particleBasedIsolation object is relevant only for AOD, RECO format
173  particleBasedIsolationToken_ = mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef > > >
174  (iConfig.getParameter<edm::InputTag>("particleBasedIsolation"));
175 
176  // AOD has reco::PFCandidate vector, and miniAOD has pat::PackedCandidate vector.
177  // Both inherit from reco::Candidate, so we go to the base class. We can cast into
178  // the full type later if needed. Since the collection names are different, we
179  // introduce both collections
180  pfCandidatesToken_ = mayConsume< edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("pfCandidates"));
181  pfCandidatesTokenMiniAOD_ = mayConsume< edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("pfCandidatesMiniAOD"));
182 
183  //
184  // Declare producibles
185  //
186  // Cluster shapes
187  produces<edm::ValueMap<float> >(phoFull5x5SigmaIEtaIEta_);
188  produces<edm::ValueMap<float> >(phoFull5x5SigmaIEtaIPhi_);
189  produces<edm::ValueMap<float> >(phoFull5x5E1x3_);
190  produces<edm::ValueMap<float> >(phoFull5x5E2x2_);
191  produces<edm::ValueMap<float> >(phoFull5x5E2x5Max_);
192  produces<edm::ValueMap<float> >(phoFull5x5E5x5_);
193  produces<edm::ValueMap<float> >(phoESEffSigmaRR_);
194  // Isolations
195  produces<edm::ValueMap<float> >(phoChargedIsolation_);
196  produces<edm::ValueMap<float> >(phoNeutralHadronIsolation_);
197  produces<edm::ValueMap<float> >(phoPhotonIsolation_);
198  produces<edm::ValueMap<float> >(phoWorstChargedIsolation_);
199  produces<edm::ValueMap<float> >(phoWorstChargedIsolationWithConeVeto_);
200 
201 }
T getParameter(std::string const &) const
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollectionMiniAOD_
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
edm::EDGetTokenT< reco::VertexCollection > vtxTokenMiniAOD_
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollectionMiniAOD_
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollection_
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollectionMiniAOD_
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandidatesTokenMiniAOD_
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollection_
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandidatesToken_
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollection_
std::string const & label() const
Definition: InputTag.h:36
static char phoWorstChargedIsolationWithConeVeto_[]
PhotonIDValueMapProducer::~PhotonIDValueMapProducer ( )
override

Definition at line 203 of file PhotonIDValueMapProducer.cc.

203  {
204 }

Member Function Documentation

reco::PFCandidate::ParticleType PhotonIDValueMapProducer::candidatePdgId ( const edm::Ptr< reco::Candidate candidate,
bool  isAOD 
)
private

Definition at line 529 of file PhotonIDValueMapProducer.cc.

References funct::abs(), reco::PFCandidate::gamma, reco::PFCandidate::h, reco::PFCandidate::h0, common_cff::pdgId, and reco::PFCandidate::X.

Referenced by computeWorstPFChargedIsolation(), and produce().

530  {
531 
533  if( isAOD )
534  thisCandidateType = ( (const recoCandPtr)candidate)->particleId();
535  else {
536  // the neutral hadrons and charged hadrons can be of pdgId types
537  // only 130 (K0L) and +-211 (pi+-) in packed candidates
538  const int pdgId = ( (const patCandPtr)candidate)->pdgId();
539  if( pdgId == 22 )
540  thisCandidateType = reco::PFCandidate::gamma;
541  else if( abs(pdgId) == 130) // PDG ID for K0L
542  thisCandidateType = reco::PFCandidate::h0;
543  else if( abs(pdgId) == 211) // PDG ID for pi+-
544  thisCandidateType = reco::PFCandidate::h;
545  }
546  return thisCandidateType;
547 }
ParticleType
particle types
Definition: PFCandidate.h:45
edm::Ptr< pat::PackedCandidate > patCandPtr
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::Ptr< reco::PFCandidate > recoCandPtr
template<class T , class U >
float PhotonIDValueMapProducer::computeWorstPFChargedIsolation ( const T photon,
const U &  pfCandidates,
const edm::Handle< reco::VertexCollection vertices,
bool  isAOD,
float  dRmax,
float  dxyMax,
float  dzMax,
float  dRvetoBarrel,
float  dRvetoEndcap,
float  ptMin 
)
private

Definition at line 469 of file PhotonIDValueMapProducer.cc.

References candidatePdgId(), reco::deltaR2(), AlignmentTrackSelector_cfi::dzMax, getTrackDxyDz(), reco::PFCandidate::h, mps_fire::i, ALCARECOTkAlBeamHalo_cff::ptMin, and badGlobalMuonTaggersAOD_cff::vtx.

Referenced by fillDescriptions(), and produce().

473  {
474 
475 
476  float worstIsolation = 999;
477  std::vector<float> allIsolations;
478 
479  float dRveto;
480  if (photon->isEB())
481  dRveto = dRvetoBarrel;
482  else
483  dRveto = dRvetoEndcap;
484 
485  //Calculate isolation sum separately for each vertex
486  for(unsigned int ivtx=0; ivtx<vertices->size(); ++ivtx) {
487 
488  // Shift the photon according to the vertex
489  reco::VertexRef vtx(vertices, ivtx);
490  math::XYZVector photon_directionWrtVtx(photon->superCluster()->x() - vtx->x(),
491  photon->superCluster()->y() - vtx->y(),
492  photon->superCluster()->z() - vtx->z());
493 
494  float sum = 0;
495  // Loop over the PFCandidates
496  for(unsigned i=0; i<pfCandidates->size(); i++) {
497 
498  const auto& iCand = pfCandidates->ptrAt(i);
499 
500  //require that PFCandidate is a charged hadron
501  reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand, isAOD);
502  if (thisCandidateType != reco::PFCandidate::h)
503  continue;
504 
505  if (iCand->pt() < ptMin)
506  continue;
507 
508  auto dxydz = getTrackDxyDz(iCand, vtx->position(), isAOD);
509  if ( fabs(dxydz.first) > dxyMax) continue;
510  if ( fabs(dxydz.second) > dzMax) continue;
511 
512  float dR2 = deltaR2(photon_directionWrtVtx.Eta(), photon_directionWrtVtx.Phi(),
513  iCand->eta(), iCand->phi());
514  if(dR2 > dRmax*dRmax || dR2 < dRveto*dRveto) continue;
515 
516  sum += iCand->pt();
517  }
518 
519  allIsolations.push_back(sum);
520  }
521 
522  if( !allIsolations.empty() )
523  worstIsolation = * std::max_element( allIsolations.begin(), allIsolations.end() );
524 
525  return worstIsolation;
526 }
ParticleType
particle types
Definition: PFCandidate.h:45
reco::PFCandidate::ParticleType candidatePdgId(const edm::Ptr< reco::Candidate > candidate, bool isAOD)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
std::pair< float, float > getTrackDxyDz(const edm::Ptr< reco::Candidate > &candidate, const reco::Particle::Point &vtxpos, bool isAOD)
void PhotonIDValueMapProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 457 of file PhotonIDValueMapProducer.cc.

References edm::ConfigurationDescriptions::addDefault(), computeWorstPFChargedIsolation(), and edm::ParameterSetDescription::setUnknown().

457  {
458  //The following says we do not know what parameters are allowed so do no validation
459  // Please change this to state exactly what you do use, even if it is no parameters
461  desc.setUnknown();
462  descriptions.addDefault(desc);
463 }
void addDefault(ParameterSetDescription const &psetDescription)
std::pair< float, float > PhotonIDValueMapProducer::getTrackDxyDz ( const edm::Ptr< reco::Candidate > &  candidate,
const reco::Particle::Point vtxpos,
bool  isAOD 
)
private

Definition at line 550 of file PhotonIDValueMapProducer.cc.

References DEFINE_FWK_MODULE, reco::TrackBase::dxy(), pat::PackedCandidate::dxy(), reco::TrackBase::dz(), and pat::PackedCandidate::dz().

Referenced by computeWorstPFChargedIsolation(), and produce().

550  {
551 
552  if( isAOD ) {
553  const reco::Track & theTrack = *recoCandPtr(candidate)->trackRef();
554  return std::make_pair(theTrack.dxy(vtxpos),theTrack.dz(vtxpos));
555  } else {
556  const pat::PackedCandidate & theCand = *(patCandPtr(candidate));
557  return std::make_pair(theCand.dxy(vtxpos),theCand.dz(vtxpos));
558  }
559 
560 }
virtual float dz(size_t ipv=0) const
dz with respect to the PV[ipv]
edm::Ptr< pat::PackedCandidate > patCandPtr
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:609
virtual float dxy() const
dxy with respect to the PV ref
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:591
edm::Ptr< reco::PFCandidate > recoCandPtr
void PhotonIDValueMapProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivate

Definition at line 206 of file PhotonIDValueMapProducer.cc.

References candidatePdgId(), computeWorstPFChargedIsolation(), reco::deltaR2(), AlignmentTrackSelector_cfi::dzMax, heepElectronID_HEEPV50_CSA14_25ns_cff::e5x5, ebReducedRecHitCollection_, ebReducedRecHitCollectionMiniAOD_, eeReducedRecHitCollection_, eeReducedRecHitCollectionMiniAOD_, esReducedRecHitCollection_, esReducedRecHitCollectionMiniAOD_, Exception, reco::PFCandidate::gamma, edm::Event::getByToken(), getTrackDxyDz(), reco::PFCandidate::h, reco::PFCandidate::h0, iEvent, isInFootprint(), edm::detail::isnan(), edm::HandleBase::isValid(), lazyToolnoZS, particleBasedIsolationToken_, pfCandidatesToken_, pfCandidatesTokenMiniAOD_, egammaObjectModificationsInMiniAOD_cff::phoChargedIsolation, phoChargedIsolation_, phoESEffSigmaRR_, phoFull5x5E1x3_, phoFull5x5E2x2_, phoFull5x5E2x5Max_, phoFull5x5E5x5_, phoFull5x5SigmaIEtaIEta_, phoFull5x5SigmaIEtaIPhi_, egammaObjectModificationsInMiniAOD_cff::phoNeutralHadronIsolation, phoNeutralHadronIsolation_, egammaObjectModificationsInMiniAOD_cff::phoPhotonIsolation, phoPhotonIsolation_, egammaObjectModificationsInMiniAOD_cff::phoWorstChargedIsolation, phoWorstChargedIsolation_, phoWorstChargedIsolationWithConeVeto_, reco::Vertex::position(), ALCARECOTkAlBeamHalo_cff::ptMin, MetAnalyzer::pv(), mathSSE::sqrt(), TrackRefitter_38T_cff::src, src_, srcMiniAOD_, PFTauMVAInputDiscriminatorTranslator_cfi::test, usesES_, electrons_cff::vertices, vtxToken_, vtxTokenMiniAOD_, writeValueMap(), reco::Vertex::x(), reco::Vertex::y(), and reco::Vertex::z().

206  {
207 
208  using namespace edm;
209 
210  // Constants
211  const float coneSizeDR = 0.3;
212  const float dxyMax = 0.1;
213  const float dzMax = 0.2;
214 
216 
217  bool isAOD = true;
218  iEvent.getByToken(src_, src);
219  if( !src.isValid() ){
220  isAOD = false;
221  iEvent.getByToken(srcMiniAOD_,src);
222  }
223  if( !src.isValid() ) {
224  throw cms::Exception("IllDefinedDataTier")
225  << "DataFormat does not contain a photon source!";
226  }
227 
228  // Configure Lazy Tools
229  if (usesES_) {
230  if( isAOD )
231  lazyToolnoZS = std::make_unique<noZS::EcalClusterLazyTools>(iEvent, iSetup,
235  else
236  lazyToolnoZS = std::make_unique<noZS::EcalClusterLazyTools>(iEvent, iSetup,
240  } else {
241  if( isAOD )
242  lazyToolnoZS = std::make_unique<noZS::EcalClusterLazyTools>(iEvent, iSetup,
245  else
246  lazyToolnoZS = std::make_unique<noZS::EcalClusterLazyTools>(iEvent, iSetup,
249 
250  }
251 
252  // Get PV
254  iEvent.getByToken(vtxToken_, vertices);
255  if( !vertices.isValid() )
256  iEvent.getByToken(vtxTokenMiniAOD_, vertices);
257  if (vertices->empty()) return; // skip the event if no PV found
258  const reco::Vertex &pv = vertices->front();
259 
261  if( isAOD ){
262  // this exists only in AOD
263  iEvent.getByToken(particleBasedIsolationToken_, particleBasedIsolationMap);
264  }
265 
266  edm::Handle< edm::View<reco::Candidate> > pfCandidatesHandle;
267 
268  iEvent.getByToken(pfCandidatesToken_, pfCandidatesHandle);
269  if( !pfCandidatesHandle.isValid() )
270  iEvent.getByToken(pfCandidatesTokenMiniAOD_, pfCandidatesHandle);
271 
272  if( !isAOD && !src->empty() ) {
273  edm::Ptr<pat::Photon> test(src->ptrAt(0));
274  if( test.isNull() || !test.isAvailable() ) {
275  throw cms::Exception("InvalidConfiguration")
276  <<"DataFormat is detected as miniAOD but cannot cast to pat::Photon!";
277  }
278  }
279 
280  // size_t n = src->size();
281  // Cluster shapes
282  std::vector<float> phoFull5x5SigmaIEtaIEta;
283  std::vector<float> phoFull5x5SigmaIEtaIPhi;
284  std::vector<float> phoFull5x5E1x3;
285  std::vector<float> phoFull5x5E2x2;
286  std::vector<float> phoFull5x5E2x5Max;
287  std::vector<float> phoFull5x5E5x5;
288  std::vector<float> phoESEffSigmaRR;
289  // Isolations
290  std::vector<float> phoChargedIsolation;
291  std::vector<float> phoNeutralHadronIsolation;
292  std::vector<float> phoPhotonIsolation;
293  std::vector<float> phoWorstChargedIsolation;
294  std::vector<float> phoWorstChargedIsolationWithConeVeto;
295 
296  // reco::Photon::superCluster() is virtual so we can exploit polymorphism
297  for (unsigned idxpho = 0; idxpho < src->size(); ++idxpho) {
298  const auto& iPho = src->ptrAt(idxpho);
299 
300  //
301  // Compute full 5x5 quantities
302  //
303  const auto& theseed = *(iPho->superCluster()->seed());
304 
305  // For full5x5_sigmaIetaIeta, for 720 we use: lazy tools for AOD,
306  // and userFloats or lazy tools for miniAOD. From some point in 72X and on, one can
307  // retrieve the full5x5 directly from the object with ->full5x5_sigmaIetaIeta()
308  // for both formats.
309  float see = -999;
310  std::vector<float> vCov = lazyToolnoZS->localCovariances( theseed );
311  see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0]));
312  float sep = vCov[1];
313  phoFull5x5SigmaIEtaIEta.push_back(see);
314  phoFull5x5SigmaIEtaIPhi.push_back(sep);
315 
316  phoFull5x5E1x3 .push_back(lazyToolnoZS-> e1x3 (theseed) );
317  phoFull5x5E2x2 .push_back(lazyToolnoZS-> e2x2 (theseed) );
318  phoFull5x5E2x5Max.push_back(lazyToolnoZS-> e2x5Max(theseed) );
319  phoFull5x5E5x5 .push_back(lazyToolnoZS-> e5x5 (theseed) );
320 
321  phoESEffSigmaRR .push_back(lazyToolnoZS->eseffsirir( *(iPho->superCluster()) ) );
322 
323  //
324  // Compute absolute uncorrected isolations with footprint removal
325  //
326 
327  // First, find photon direction with respect to the good PV
328  math::XYZVector photon_directionWrtVtx(iPho->superCluster()->x() - pv.x(),
329  iPho->superCluster()->y() - pv.y(),
330  iPho->superCluster()->z() - pv.z());
331 
332  // Zero the isolation sums
333  float chargedIsoSum = 0;
334  float neutralHadronIsoSum = 0;
335  float photonIsoSum = 0;
336 
337  // Loop over all PF candidates
338  for (unsigned idxcand = 0; idxcand < pfCandidatesHandle->size(); ++idxcand ){
339 
340  // Here, the type will be a simple reco::Candidate. We cast it
341  // for full PFCandidate or PackedCandidate below as necessary
342  const auto& iCand = pfCandidatesHandle->ptrAt(idxcand);
343 
344  // One would think that we should check that this iCand from
345  // the generic PF collection is not identical to the iPho photon
346  // for which we are computing the isolations. However, it turns out
347  // to be unnecessary. Below, in the function isInFootprint(), we drop
348  // this iCand if it is in the footprint, and this always removes
349  // the iCand if it matches the iPho.
350  // The explicit check at this point is not totally trivial because
351  // of non-triviality of implementation of this check for miniAOD (PackedCandidates
352  // of the PF collection do not contain the supercluser link, so can't use that).
353  // if( isAOD ){
354  // if( ((const recoCandPtr)iCand)->superClusterRef() == iPho->superCluster() ) continue;
355  // }
356 
357 
358  // Check if this candidate is within the isolation cone
359  float dR2 = deltaR2(photon_directionWrtVtx.Eta(),photon_directionWrtVtx.Phi(),
360  iCand->eta(), iCand->phi());
361  if( dR2 > coneSizeDR*coneSizeDR ) continue;
362 
363  // Check if this candidate is not in the footprint
364  bool inFootprint = false;
365  if(isAOD) {
366  inFootprint = isInFootprint( (*particleBasedIsolationMap)[iPho], iCand );
367  } else {
368  edm::Ptr<pat::Photon> patPhotonPtr(src->ptrAt(idxpho));
369  inFootprint = isInFootprint(patPhotonPtr->associatedPackedPFCandidates(), iCand);
370  }
371 
372  if( inFootprint ) continue;
373 
374  // Find candidate type
375  reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand, isAOD);
376 
377  // Increment the appropriate isolation sum
378  if( thisCandidateType == reco::PFCandidate::h ){
379  // for charged hadrons, additionally check consistency
380  // with the PV
381 
382  auto dxydz = getTrackDxyDz(iCand, pv.position(), isAOD);
383  if ( fabs(dxydz.first) > dxyMax) continue;
384  if ( fabs(dxydz.second) > dzMax) continue;
385 
386  // The candidate is eligible, increment the isolaiton
387  chargedIsoSum += iCand->pt();
388  }
389 
390  if( thisCandidateType == reco::PFCandidate::h0 )
391  neutralHadronIsoSum += iCand->pt();
392 
393  if( thisCandidateType == reco::PFCandidate::gamma )
394  photonIsoSum += iCand->pt();
395  }
396 
397  phoChargedIsolation .push_back( chargedIsoSum );
398  phoNeutralHadronIsolation.push_back( neutralHadronIsoSum );
399  phoPhotonIsolation .push_back( photonIsoSum );
400 
401  // Worst isolation computed with no vetos or ptMin cut, as in
402  // Run 1 Hgg code.
403  float dRvetoBarrel = 0.0;
404  float dRvetoEndcap = 0.0;
405  float ptMin = 0.0;
406  float worstChargedIso =
407  computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices,
408  isAOD, coneSizeDR, dxyMax, dzMax,
409  dRvetoBarrel, dRvetoEndcap, ptMin);
410  phoWorstChargedIsolation .push_back( worstChargedIso );
411 
412  // Worst isolation computed with cone vetos and a ptMin cut, as in
413  // Run 2 Hgg code.
414  dRvetoBarrel = 0.02;
415  dRvetoEndcap = 0.02;
416  ptMin = 0.1;
417  float worstChargedIsoWithConeVeto =
418  computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices,
419  isAOD, coneSizeDR, dxyMax, dzMax,
420  dRvetoBarrel, dRvetoEndcap, ptMin);
421  phoWorstChargedIsolationWithConeVeto .push_back( worstChargedIsoWithConeVeto );
422 
423 
424 
425  }
426 
427  // Cluster shapes
428  writeValueMap(iEvent, src, phoFull5x5SigmaIEtaIEta, phoFull5x5SigmaIEtaIEta_);
429  writeValueMap(iEvent, src, phoFull5x5SigmaIEtaIPhi, phoFull5x5SigmaIEtaIPhi_);
430  writeValueMap(iEvent, src, phoFull5x5E1x3 , phoFull5x5E1x3_);
431  writeValueMap(iEvent, src, phoFull5x5E2x2 , phoFull5x5E2x2_);
432  writeValueMap(iEvent, src, phoFull5x5E2x5Max, phoFull5x5E2x5Max_);
433  writeValueMap(iEvent, src, phoFull5x5E5x5 , phoFull5x5E5x5_);
434  writeValueMap(iEvent, src, phoESEffSigmaRR , phoESEffSigmaRR_);
435  // IsolationsOB
436  writeValueMap(iEvent, src, phoChargedIsolation, phoChargedIsolation_);
437  writeValueMap(iEvent, src, phoNeutralHadronIsolation, phoNeutralHadronIsolation_);
438  writeValueMap(iEvent, src, phoPhotonIsolation, phoPhotonIsolation_);
439  writeValueMap(iEvent, src, phoWorstChargedIsolation, phoWorstChargedIsolation_);
440  writeValueMap(iEvent, src, phoWorstChargedIsolationWithConeVeto, phoWorstChargedIsolationWithConeVeto_);
441 }
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< reco::Photon > > &handle, const std::vector< float > &values, const std::string &label) const
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollectionMiniAOD_
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
ParticleType
particle types
Definition: PFCandidate.h:45
edm::EDGetTokenT< reco::VertexCollection > vtxTokenMiniAOD_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:519
std::unique_ptr< noZS::EcalClusterLazyTools > lazyToolnoZS
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollectionMiniAOD_
double y() const
y coordinate
Definition: Vertex.h:113
reco::PFCandidate::ParticleType candidatePdgId(const edm::Ptr< reco::Candidate > candidate, bool isAOD)
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollection_
float computeWorstPFChargedIsolation(const T &photon, const U &pfCandidates, const edm::Handle< reco::VertexCollection > vertices, bool isAOD, float dRmax, float dxyMax, float dzMax, float dRvetoBarrel, float dRvetoEndcap, float ptMin)
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollectionMiniAOD_
const Point & position() const
position
Definition: Vertex.h:109
int iEvent
Definition: GenABIO.cc:230
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandidatesTokenMiniAOD_
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollection_
bool isnan(float x)
Definition: math.h:13
T sqrt(T t)
Definition: SSEVec.h:18
bool isInFootprint(const T &thefootprint, const U &theCandidate)
def pv(vc)
Definition: MetAnalyzer.py:6
double z() const
z coordinate
Definition: Vertex.h:115
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandidatesToken_
bool isValid() const
Definition: HandleBase.h:74
double x() const
x coordinate
Definition: Vertex.h:111
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
edm::EDGetTokenT< EcalRecHitCollection > esReducedRecHitCollection_
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
edm::Ptr< pat::Photon > patPhotonPtr
HLT enums.
std::pair< float, float > getTrackDxyDz(const edm::Ptr< reco::Candidate > &candidate, const reco::Particle::Point &vtxpos, bool isAOD)
static char phoWorstChargedIsolationWithConeVeto_[]
void PhotonIDValueMapProducer::writeValueMap ( edm::Event iEvent,
const edm::Handle< edm::View< reco::Photon > > &  handle,
const std::vector< float > &  values,
const std::string &  label 
) const
private

Definition at line 443 of file PhotonIDValueMapProducer.cc.

References objects.autophobj::filler, cmsBatch::handle, eostools::move(), and edm::Event::put().

Referenced by produce().

447 {
448  using namespace edm;
449  using namespace std;
450  auto valMap = std::make_unique<ValueMap<float>>();
452  filler.insert(handle, values.begin(), values.end());
453  filler.fill();
454  iEvent.put(std::move(valMap), label);
455 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:136
HLT enums.
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

edm::EDGetTokenT<EcalRecHitCollection> PhotonIDValueMapProducer::ebReducedRecHitCollection_
private

Definition at line 86 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<EcalRecHitCollection> PhotonIDValueMapProducer::ebReducedRecHitCollectionMiniAOD_
private

Definition at line 95 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<EcalRecHitCollection> PhotonIDValueMapProducer::eeReducedRecHitCollection_
private

Definition at line 87 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<EcalRecHitCollection> PhotonIDValueMapProducer::eeReducedRecHitCollectionMiniAOD_
private

Definition at line 96 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<EcalRecHitCollection> PhotonIDValueMapProducer::esReducedRecHitCollection_
private

Definition at line 88 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<EcalRecHitCollection> PhotonIDValueMapProducer::esReducedRecHitCollectionMiniAOD_
private

Definition at line 97 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

std::unique_ptr<noZS::EcalClusterLazyTools> PhotonIDValueMapProducer::lazyToolnoZS
private

Definition at line 83 of file PhotonIDValueMapProducer.cc.

Referenced by produce().

edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef > > > PhotonIDValueMapProducer::particleBasedIsolationToken_
private

Definition at line 90 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<edm::ValueMap<std::vector<reco::PFCandidateRef > > > PhotonIDValueMapProducer::particleBasedIsolationTokenMiniAOD_
private

Definition at line 99 of file PhotonIDValueMapProducer.cc.

edm::EDGetTokenT<edm::View<reco::Candidate> > PhotonIDValueMapProducer::pfCandidatesToken_
private

Definition at line 91 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<edm::View<reco::Candidate> > PhotonIDValueMapProducer::pfCandidatesTokenMiniAOD_
private

Definition at line 100 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoChargedIsolation_ = "phoChargedIsolation"
staticprivate

Definition at line 115 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoESEffSigmaRR_ = "phoESEffSigmaRR"
staticprivate

Definition at line 113 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5E1x3_ = "phoFull5x5E1x3"
staticprivate

Definition at line 109 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5E2x2_ = "phoFull5x5E2x2"
staticprivate

Definition at line 110 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5E2x5Max_ = "phoFull5x5E2x5Max"
staticprivate

Definition at line 111 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5E5x5_ = "phoFull5x5E5x5"
staticprivate

Definition at line 112 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5SigmaIEtaIEta_ = "phoFull5x5SigmaIEtaIEta"
staticprivate

Definition at line 107 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5SigmaIEtaIPhi_ = "phoFull5x5SigmaIEtaIPhi"
staticprivate

Definition at line 108 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoNeutralHadronIsolation_ = "phoNeutralHadronIsolation"
staticprivate

Definition at line 116 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoPhotonIsolation_ = "phoPhotonIsolation"
staticprivate

Definition at line 117 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoWorstChargedIsolation_ = "phoWorstChargedIsolation"
staticprivate

Definition at line 118 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoWorstChargedIsolationWithConeVeto_ = "phoWorstChargedIsolationWithConeVeto"
staticprivate

Definition at line 119 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetToken PhotonIDValueMapProducer::src_
private

Definition at line 92 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetToken PhotonIDValueMapProducer::srcMiniAOD_
private

Definition at line 101 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

bool PhotonIDValueMapProducer::usesES_
private

Definition at line 104 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<reco::VertexCollection> PhotonIDValueMapProducer::vtxToken_
private

Definition at line 89 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetTokenT<reco::VertexCollection> PhotonIDValueMapProducer::vtxTokenMiniAOD_
private

Definition at line 98 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().