test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

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)
 
const reco::TrackgetTrackPointer (const edm::Ptr< reco::Candidate > candidate, bool isAOD)
 
virtual 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
< EcalRecHitCollection
ebReducedRecHitCollection_
 
edm::EDGetTokenT
< EcalRecHitCollection
ebReducedRecHitCollectionMiniAOD_
 
edm::EDGetTokenT
< EcalRecHitCollection
eeReducedRecHitCollection_
 
edm::EDGetTokenT
< EcalRecHitCollection
eeReducedRecHitCollectionMiniAOD_
 
edm::EDGetTokenT
< EcalRecHitCollection
esReducedRecHitCollection_
 
edm::EDGetTokenT
< EcalRecHitCollection
esReducedRecHitCollectionMiniAOD_
 
std::unique_ptr
< noZS::EcalClusterLazyTools
lazyToolnoZS
 
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_
 
edm::EDGetTokenT
< reco::VertexCollection
vtxToken_
 
edm::EDGetTokenT
< reco::VertexCollection
vtxTokenMiniAOD_
 

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"
 

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, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
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 132 of file PhotonIDValueMapProducer.cc.

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

132  {
133 
134  //
135  // Declare consummables, handle both AOD and miniAOD case
136  //
137  ebReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
138  ("ebReducedRecHitCollection"));
139  ebReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
140  ("ebReducedRecHitCollectionMiniAOD"));
141 
142  eeReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
143  ("eeReducedRecHitCollection"));
144  eeReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
145  ("eeReducedRecHitCollectionMiniAOD"));
146 
147  esReducedRecHitCollection_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
148  ("esReducedRecHitCollection"));
149  esReducedRecHitCollectionMiniAOD_ = mayConsume<EcalRecHitCollection>(iConfig.getParameter<edm::InputTag>
150  ("esReducedRecHitCollectionMiniAOD"));
151 
152  vtxToken_ = mayConsume<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertices"));
153  vtxTokenMiniAOD_ = mayConsume<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("verticesMiniAOD"));
154 
155  // reco photons are castable into pat photons, so no need to handle reco/pat seprately
156  src_ = mayConsume<edm::View<reco::Photon> >(iConfig.getParameter<edm::InputTag>("src"));
157  srcMiniAOD_ = mayConsume<edm::View<reco::Photon> >(iConfig.getParameter<edm::InputTag>("srcMiniAOD"));
158 
159  // The particleBasedIsolation object is relevant only for AOD, RECO format
160  particleBasedIsolationToken_ = mayConsume<edm::ValueMap<std::vector<reco::PFCandidateRef > > >
161  (iConfig.getParameter<edm::InputTag>("particleBasedIsolation"));
162 
163  // AOD has reco::PFCandidate vector, and miniAOD has pat::PackedCandidate vector.
164  // Both inherit from reco::Candidate, so we go to the base class. We can cast into
165  // the full type later if needed. Since the collection names are different, we
166  // introduce both collections
167  pfCandidatesToken_ = mayConsume< edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("pfCandidates"));
168  pfCandidatesTokenMiniAOD_ = mayConsume< edm::View<reco::Candidate> >(iConfig.getParameter<edm::InputTag>("pfCandidatesMiniAOD"));
169 
170  //
171  // Declare producibles
172  //
173  // Cluster shapes
174  produces<edm::ValueMap<float> >(phoFull5x5SigmaIEtaIEta_);
175  produces<edm::ValueMap<float> >(phoFull5x5SigmaIEtaIPhi_);
176  produces<edm::ValueMap<float> >(phoFull5x5E1x3_);
177  produces<edm::ValueMap<float> >(phoFull5x5E2x2_);
178  produces<edm::ValueMap<float> >(phoFull5x5E2x5Max_);
179  produces<edm::ValueMap<float> >(phoFull5x5E5x5_);
180  produces<edm::ValueMap<float> >(phoESEffSigmaRR_);
181  // Isolations
182  produces<edm::ValueMap<float> >(phoChargedIsolation_);
183  produces<edm::ValueMap<float> >(phoNeutralHadronIsolation_);
184  produces<edm::ValueMap<float> >(phoPhotonIsolation_);
185  produces<edm::ValueMap<float> >(phoWorstChargedIsolation_);
186 
187 }
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_
PhotonIDValueMapProducer::~PhotonIDValueMapProducer ( )

Definition at line 189 of file PhotonIDValueMapProducer.cc.

189  {
190 }

Member Function Documentation

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

Definition at line 493 of file PhotonIDValueMapProducer.cc.

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

Referenced by computeWorstPFChargedIsolation(), and produce().

494  {
495 
497  if( isAOD )
498  thisCandidateType = ( (const recoCandPtr)candidate)->particleId();
499  else {
500  // the neutral hadrons and charged hadrons can be of pdgId types
501  // only 130 (K0L) and +-211 (pi+-) in packed candidates
502  const int pdgId = ( (const patCandPtr)candidate)->pdgId();
503  if( pdgId == 22 )
504  thisCandidateType = reco::PFCandidate::gamma;
505  else if( abs(pdgId) == 130) // PDG ID for K0L
506  thisCandidateType = reco::PFCandidate::h0;
507  else if( abs(pdgId) == 211) // PDG ID for pi+-
508  thisCandidateType = reco::PFCandidate::h;
509  }
510  return thisCandidateType;
511 }
ParticleType
particle types
Definition: PFCandidate.h:44
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 
)
private

Definition at line 426 of file PhotonIDValueMapProducer.cc.

References candidatePdgId(), reco::deltaR2(), reco::TrackBase::dxy(), reco::TrackBase::dz(), objects.IsoTrackAnalyzer::dzMax, getTrackPointer(), reco::PFCandidate::h, i, and PtMinSelector_cfg::ptMin.

Referenced by produce().

429  {
430 
431  float worstIsolation = 999;
432  std::vector<float> allIsolations;
433 
434  // Constants below: there are no vetos and no min pt requirement,
435  // just like in the original H->gamma gamma code.
436  const float dRvetoBarrel = 0.0;
437  const float dRvetoEndcap = 0.0;
438  const float ptMin = 0.0;
439 
440  float dRveto;
441  if (photon->isEB())
442  dRveto = dRvetoBarrel;
443  else
444  dRveto = dRvetoEndcap;
445 
446  //Calculate isolation sum separately for each vertex
447  for(unsigned int ivtx=0; ivtx<vertices->size(); ++ivtx) {
448 
449  // Shift the photon according to the vertex
450  reco::VertexRef vtx(vertices, ivtx);
451  math::XYZVector photon_directionWrtVtx(photon->superCluster()->x() - vtx->x(),
452  photon->superCluster()->y() - vtx->y(),
453  photon->superCluster()->z() - vtx->z());
454 
455  float sum = 0;
456  // Loop over the PFCandidates
457  for(unsigned i=0; i<pfCandidates->size(); i++) {
458 
459  const auto& iCand = pfCandidates->ptrAt(i);
460 
461  //require that PFCandidate is a charged hadron
462  reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand, isAOD);
463  if (thisCandidateType != reco::PFCandidate::h)
464  continue;
465 
466  if (iCand->pt() < ptMin)
467  continue;
468 
469  const reco::Track *theTrack = getTrackPointer( iCand, isAOD );
470  float dxy = theTrack->dxy(vtx->position());
471  if( fabs(dxy) > dxyMax) continue;
472 
473  float dz = theTrack->dz(vtx->position());
474  if ( fabs(dz) > dzMax) continue;
475 
476  float dR2 = deltaR2(photon_directionWrtVtx.Eta(), photon_directionWrtVtx.Phi(),
477  iCand->eta(), iCand->phi());
478  if(dR2 > dRmax*dRmax || dR2 < dRveto*dRveto) continue;
479 
480  sum += iCand->pt();
481  }
482 
483  allIsolations.push_back(sum);
484  }
485 
486  if( allIsolations.size()>0 )
487  worstIsolation = * std::max_element( allIsolations.begin(), allIsolations.end() );
488 
489  return worstIsolation;
490 }
const reco::Track * getTrackPointer(const edm::Ptr< reco::Candidate > candidate, bool isAOD)
int i
Definition: DBlmapReader.cc:9
ParticleType
particle types
Definition: PFCandidate.h:44
reco::PFCandidate::ParticleType candidatePdgId(const edm::Ptr< reco::Candidate > candidate, bool isAOD)
std::vector< PFCandidatePtr > pfCandidates(const PFJet &jet, int particleId, bool sort=true)
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:604
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
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:586
void PhotonIDValueMapProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 414 of file PhotonIDValueMapProducer.cc.

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

414  {
415  //The following says we do not know what parameters are allowed so do no validation
416  // Please change this to state exactly what you do use, even if it is no parameters
418  desc.setUnknown();
419  descriptions.addDefault(desc);
420 }
void addDefault(ParameterSetDescription const &psetDescription)
const reco::Track * PhotonIDValueMapProducer::getTrackPointer ( const edm::Ptr< reco::Candidate candidate,
bool  isAOD 
)
private

Definition at line 514 of file PhotonIDValueMapProducer.cc.

Referenced by computeWorstPFChargedIsolation(), and produce().

514  {
515 
516  const reco::Track* theTrack = nullptr;
517  if( isAOD )
518  theTrack = &*( ((const recoCandPtr) candidate)->trackRef());
519  else
520  theTrack = &( ((const patCandPtr) candidate)->pseudoTrack());
521 
522  return theTrack;
523 }
edm::Ptr< pat::PackedCandidate > patCandPtr
edm::Ptr< reco::PFCandidate > recoCandPtr
void PhotonIDValueMapProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::stream::EDProducerBase.

Definition at line 192 of file PhotonIDValueMapProducer.cc.

References candidatePdgId(), computeWorstPFChargedIsolation(), reco::deltaR2(), reco::TrackBase::dxy(), reco::TrackBase::dz(), objects.IsoTrackAnalyzer::dzMax, ebReducedRecHitCollection_, ebReducedRecHitCollectionMiniAOD_, eeReducedRecHitCollection_, eeReducedRecHitCollectionMiniAOD_, esReducedRecHitCollection_, esReducedRecHitCollectionMiniAOD_, Exception, reco::PFCandidate::gamma, edm::Event::getByToken(), getTrackPointer(), reco::PFCandidate::h, reco::PFCandidate::h0, isInFootprint(), edm::detail::isnan(), lazyToolnoZS, particleBasedIsolationToken_, pfCandidatesToken_, pfCandidatesTokenMiniAOD_, phoChargedIsolation_, phoESEffSigmaRR_, phoFull5x5E1x3_, phoFull5x5E2x2_, phoFull5x5E2x5Max_, phoFull5x5E5x5_, phoFull5x5SigmaIEtaIEta_, phoFull5x5SigmaIEtaIPhi_, phoNeutralHadronIsolation_, phoPhotonIsolation_, phoWorstChargedIsolation_, MetAnalyzer::pv(), cmsHarvester::sep, mathSSE::sqrt(), alcazmumu_cfi::src, src_, srcMiniAOD_, ctpps_dqm_sourceclient-live_cfg::test, HLT_25ns10e33_v2_cff::vertices, vtxToken_, vtxTokenMiniAOD_, and writeValueMap().

192  {
193 
194  using namespace edm;
195 
196  // Constants
197  const float coneSizeDR = 0.3;
198  const float dxyMax = 0.1;
199  const float dzMax = 0.2;
200 
202 
203  bool isAOD = true;
204  iEvent.getByToken(src_, src);
205  if( !src.isValid() ){
206  isAOD = false;
207  iEvent.getByToken(srcMiniAOD_,src);
208  }
209  if( !src.isValid() ) {
210  throw cms::Exception("IllDefinedDataTier")
211  << "DataFormat does not contain a photon source!";
212  }
213 
214  // Configure Lazy Tools
215  if( isAOD )
216  lazyToolnoZS = std::unique_ptr<noZS::EcalClusterLazyTools>(new noZS::EcalClusterLazyTools(iEvent, iSetup,
220  else
221  lazyToolnoZS = std::unique_ptr<noZS::EcalClusterLazyTools>(new noZS::EcalClusterLazyTools(iEvent, iSetup,
225 
226  // Get PV
228  iEvent.getByToken(vtxToken_, vertices);
229  if( !vertices.isValid() )
231  if (vertices->empty()) return; // skip the event if no PV found
232  const reco::Vertex &pv = vertices->front();
233 
235  if( isAOD ){
236  // this exists only in AOD
237  iEvent.getByToken(particleBasedIsolationToken_, particleBasedIsolationMap);
238  }
239 
240  edm::Handle< edm::View<reco::Candidate> > pfCandidatesHandle;
241 
242  iEvent.getByToken(pfCandidatesToken_, pfCandidatesHandle);
243  if( !pfCandidatesHandle.isValid() )
244  iEvent.getByToken(pfCandidatesTokenMiniAOD_, pfCandidatesHandle);
245 
246  if( !isAOD && src->size() ) {
247  edm::Ptr<pat::Photon> test(src->ptrAt(0));
248  if( test.isNull() || !test.isAvailable() ) {
249  throw cms::Exception("InvalidConfiguration")
250  <<"DataFormat is detected as miniAOD but cannot cast to pat::Photon!";
251  }
252  }
253 
254  // size_t n = src->size();
255  // Cluster shapes
256  std::vector<float> phoFull5x5SigmaIEtaIEta;
257  std::vector<float> phoFull5x5SigmaIEtaIPhi;
258  std::vector<float> phoFull5x5E1x3;
259  std::vector<float> phoFull5x5E2x2;
260  std::vector<float> phoFull5x5E2x5Max;
261  std::vector<float> phoFull5x5E5x5;
262  std::vector<float> phoESEffSigmaRR;
263  // Isolations
264  std::vector<float> phoChargedIsolation;
265  std::vector<float> phoNeutralHadronIsolation;
266  std::vector<float> phoPhotonIsolation;
267  std::vector<float> phoWorstChargedIsolation;
268 
269  // reco::Photon::superCluster() is virtual so we can exploit polymorphism
270  for (unsigned idxpho = 0; idxpho < src->size(); ++idxpho) {
271  const auto& iPho = src->ptrAt(idxpho);
272 
273  //
274  // Compute full 5x5 quantities
275  //
276  const auto& theseed = *(iPho->superCluster()->seed());
277 
278  // For full5x5_sigmaIetaIeta, for 720 we use: lazy tools for AOD,
279  // and userFloats or lazy tools for miniAOD. From some point in 72X and on, one can
280  // retrieve the full5x5 directly from the object with ->full5x5_sigmaIetaIeta()
281  // for both formats.
282  float see = -999;
283  std::vector<float> vCov = lazyToolnoZS->localCovariances( theseed );
284  see = (isnan(vCov[0]) ? 0. : sqrt(vCov[0]));
285  float sep = vCov[1];
286  phoFull5x5SigmaIEtaIEta.push_back(see);
287  phoFull5x5SigmaIEtaIPhi.push_back(sep);
288 
289  phoFull5x5E1x3 .push_back(lazyToolnoZS-> e1x3 (theseed) );
290  phoFull5x5E2x2 .push_back(lazyToolnoZS-> e2x2 (theseed) );
291  phoFull5x5E2x5Max.push_back(lazyToolnoZS-> e2x5Max(theseed) );
292  phoFull5x5E5x5 .push_back(lazyToolnoZS-> e5x5 (theseed) );
293 
294  phoESEffSigmaRR .push_back(lazyToolnoZS->eseffsirir( *(iPho->superCluster()) ) );
295 
296  //
297  // Compute absolute uncorrected isolations with footprint removal
298  //
299 
300  // First, find photon direction with respect to the good PV
301  math::XYZVector photon_directionWrtVtx(iPho->superCluster()->x() - pv.x(),
302  iPho->superCluster()->y() - pv.y(),
303  iPho->superCluster()->z() - pv.z());
304 
305  // Zero the isolation sums
306  float chargedIsoSum = 0;
307  float neutralHadronIsoSum = 0;
308  float photonIsoSum = 0;
309 
310  // Loop over all PF candidates
311  for (unsigned idxcand = 0; idxcand < pfCandidatesHandle->size(); ++idxcand ){
312 
313  // Here, the type will be a simple reco::Candidate. We cast it
314  // for full PFCandidate or PackedCandidate below as necessary
315  const auto& iCand = pfCandidatesHandle->ptrAt(idxcand);
316 
317  // One would think that we should check that this iCand from
318  // the generic PF collection is not identical to the iPho photon
319  // for which we are computing the isolations. However, it turns out
320  // to be unnecessary. Below, in the function isInFootprint(), we drop
321  // this iCand if it is in the footprint, and this always removes
322  // the iCand if it matches the iPho.
323  // The explicit check at this point is not totally trivial because
324  // of non-triviality of implementation of this check for miniAOD (PackedCandidates
325  // of the PF collection do not contain the supercluser link, so can't use that).
326  // if( isAOD ){
327  // if( ((const recoCandPtr)iCand)->superClusterRef() == iPho->superCluster() ) continue;
328  // }
329 
330 
331  // Check if this candidate is within the isolation cone
332  float dR2 = deltaR2(photon_directionWrtVtx.Eta(),photon_directionWrtVtx.Phi(),
333  iCand->eta(), iCand->phi());
334  if( dR2 > coneSizeDR*coneSizeDR ) continue;
335 
336  // Check if this candidate is not in the footprint
337  bool inFootprint = false;
338  if(isAOD) {
339  inFootprint = isInFootprint( (*particleBasedIsolationMap)[iPho], iCand );
340  } else {
341  edm::Ptr<pat::Photon> patPhotonPtr(src->ptrAt(idxpho));
342  inFootprint = isInFootprint(patPhotonPtr->associatedPackedPFCandidates(), iCand);
343  }
344 
345  if( inFootprint ) continue;
346 
347  // Find candidate type
348  reco::PFCandidate::ParticleType thisCandidateType = candidatePdgId(iCand, isAOD);
349 
350  // Increment the appropriate isolation sum
351  if( thisCandidateType == reco::PFCandidate::h ){
352  // for charged hadrons, additionally check consistency
353  // with the PV
354  const reco::Track *theTrack = getTrackPointer( iCand, isAOD );
355 
356  float dxy = theTrack->dxy(pv.position());
357  if(fabs(dxy) > dxyMax) continue;
358 
359  float dz = theTrack->dz(pv.position());
360  if (fabs(dz) > dzMax) continue;
361 
362  // The candidate is eligible, increment the isolaiton
363  chargedIsoSum += iCand->pt();
364  }
365 
366  if( thisCandidateType == reco::PFCandidate::h0 )
367  neutralHadronIsoSum += iCand->pt();
368 
369  if( thisCandidateType == reco::PFCandidate::gamma )
370  photonIsoSum += iCand->pt();
371  }
372 
373  phoChargedIsolation .push_back( chargedIsoSum );
374  phoNeutralHadronIsolation.push_back( neutralHadronIsoSum );
375  phoPhotonIsolation .push_back( photonIsoSum );
376 
377  float worstChargedIso =
378  computeWorstPFChargedIsolation(iPho, pfCandidatesHandle, vertices,
379  isAOD, coneSizeDR, dxyMax, dzMax);
380  phoWorstChargedIsolation .push_back( worstChargedIso );
381 
382 
383  }
384 
385  // Cluster shapes
386  writeValueMap(iEvent, src, phoFull5x5SigmaIEtaIEta, phoFull5x5SigmaIEtaIEta_);
387  writeValueMap(iEvent, src, phoFull5x5SigmaIEtaIPhi, phoFull5x5SigmaIEtaIPhi_);
388  writeValueMap(iEvent, src, phoFull5x5E1x3 , phoFull5x5E1x3_);
389  writeValueMap(iEvent, src, phoFull5x5E2x2 , phoFull5x5E2x2_);
390  writeValueMap(iEvent, src, phoFull5x5E2x5Max, phoFull5x5E2x5Max_);
391  writeValueMap(iEvent, src, phoFull5x5E5x5 , phoFull5x5E5x5_);
392  writeValueMap(iEvent, src, phoESEffSigmaRR , phoESEffSigmaRR_);
393  // Isolations
394  writeValueMap(iEvent, src, phoChargedIsolation, phoChargedIsolation_);
395  writeValueMap(iEvent, src, phoNeutralHadronIsolation, phoNeutralHadronIsolation_);
396  writeValueMap(iEvent, src, phoPhotonIsolation, phoPhotonIsolation_);
397  writeValueMap(iEvent, src, phoWorstChargedIsolation, phoWorstChargedIsolation_);
398 }
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_
const reco::Track * getTrackPointer(const edm::Ptr< reco::Candidate > candidate, bool isAOD)
edm::EDGetTokenT< reco::VertexCollection > vtxToken_
ParticleType
particle types
Definition: PFCandidate.h:44
edm::EDGetTokenT< reco::VertexCollection > vtxTokenMiniAOD_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
std::unique_ptr< noZS::EcalClusterLazyTools > lazyToolnoZS
edm::EDGetTokenT< EcalRecHitCollection > eeReducedRecHitCollectionMiniAOD_
reco::PFCandidate::ParticleType candidatePdgId(const edm::Ptr< reco::Candidate > candidate, bool isAOD)
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollection_
edm::EDGetTokenT< edm::ValueMap< std::vector< reco::PFCandidateRef > > > particleBasedIsolationToken_
EcalClusterLazyToolsT< noZS::EcalClusterTools > EcalClusterLazyTools
edm::EDGetTokenT< EcalRecHitCollection > ebReducedRecHitCollectionMiniAOD_
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)
edm::EDGetTokenT< edm::View< reco::Candidate > > pfCandidatesToken_
float computeWorstPFChargedIsolation(const T &photon, const U &pfCandidates, const edm::Handle< reco::VertexCollection > vertices, bool isAOD, float dRmax, float dxyMax, float dzMax)
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:604
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
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:586
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 400 of file PhotonIDValueMapProducer.cc.

References edm::helper::Filler< Map >::fill(), patZpeak::handle, edm::helper::Filler< Map >::insert(), and edm::Event::put().

Referenced by produce().

404 {
405  using namespace edm;
406  using namespace std;
407  auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
408  edm::ValueMap<float>::Filler filler(*valMap);
409  filler.insert(handle, values.begin(), values.end());
410  filler.fill();
411  iEvent.put(valMap, label);
412 }
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121

Member Data Documentation

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

Definition at line 85 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 94 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 86 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 95 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 87 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 96 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 82 of file PhotonIDValueMapProducer.cc.

Referenced by produce().

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

Definition at line 89 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 98 of file PhotonIDValueMapProducer.cc.

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

Definition at line 90 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 99 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoChargedIsolation_ = "phoChargedIsolation"
staticprivate

Definition at line 111 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoESEffSigmaRR_ = "phoESEffSigmaRR"
staticprivate

Definition at line 109 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5E1x3_ = "phoFull5x5E1x3"
staticprivate

Definition at line 105 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5E2x2_ = "phoFull5x5E2x2"
staticprivate

Definition at line 106 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5E2x5Max_ = "phoFull5x5E2x5Max"
staticprivate

Definition at line 107 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5E5x5_ = "phoFull5x5E5x5"
staticprivate

Definition at line 108 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5SigmaIEtaIEta_ = "phoFull5x5SigmaIEtaIEta"
staticprivate

Definition at line 103 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoFull5x5SigmaIEtaIPhi_ = "phoFull5x5SigmaIEtaIPhi"
staticprivate

Definition at line 104 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoNeutralHadronIsolation_ = "phoNeutralHadronIsolation"
staticprivate

Definition at line 112 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoPhotonIsolation_ = "phoPhotonIsolation"
staticprivate

Definition at line 113 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

char PhotonIDValueMapProducer::phoWorstChargedIsolation_ = "phoWorstChargedIsolation"
staticprivate

Definition at line 114 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetToken PhotonIDValueMapProducer::src_
private

Definition at line 91 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

edm::EDGetToken PhotonIDValueMapProducer::srcMiniAOD_
private

Definition at line 100 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 88 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().

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

Definition at line 97 of file PhotonIDValueMapProducer.cc.

Referenced by PhotonIDValueMapProducer(), and produce().