CMS 3D CMS Logo

EG9X105XObjectUpdateModifier.cc
Go to the documentation of this file.
15 
16 #include <vdt/vdtMath.h>
17 
18 //this modifier fills variables where not present in CMSSW_92X to CMSSW_105X
19 //use case is when reading older new samples in newer releases, aka legacy
20 //note we suffer from the problem of needing to use the electrons/photons the valuemaps
21 //are keyed to (something that is thankfully going away in 11X!) so we have to take
22 //those collections in and figure out which ele/pho matches to them
24 public:
25  template <typename T>
27  public:
29  : token_(cc.consumes(conf.getParameter<edm::InputTag>(name))) {}
30  void setHandle(const edm::Event& iEvent) { handle_ = iEvent.getHandle(token_); }
31  const edm::Handle<T>& handle() const { return handle_; }
32 
33  private:
36  };
37 
40 
41  void setEvent(const edm::Event&) final;
42 
43  void modifyObject(reco::GsfElectron& ele) const final;
44  void modifyObject(reco::Photon& pho) const final;
45 
46  void modifyObject(pat::Electron& ele) const final { return modifyObject(static_cast<reco::GsfElectron&>(ele)); }
47  void modifyObject(pat::Photon& pho) const final { return modifyObject(static_cast<reco::Photon&>(pho)); }
48 
49 private:
50  template <typename ObjType>
51  static edm::Ptr<ObjType> getPtrForValueMap(const ObjType& obj,
52  const edm::Handle<edm::View<ObjType> >& objsVMIsKeyedTo);
53 
56 
61 
70  //there is a bug which GsfTracks are now allowed to be a match for conversions
71  //due to improper linking of references in the miniAOD since 94X
72  //this allows us to emulate it or not
73  //note: even if this enabled, it will do nothing on miniAOD produced with 94X, 102X
74  //till upto whenever this is fixed (11X?) as the GsfTrack references point to a different
75  //collection to the conversion track references
77  //this allows us to update the charged hadron PF PV isolation
78  //chargedHadPFPVIso is filled in iorules but when running on miniAOD, the value used in IDs
79  //is remade on the miniAOD packedcandidates which differs due to rounding
80  //its still the same variable but can have differences hence inorder to allow IDs calculated on miniAOD
81  //on the same file to be exactly reproduced, this option is set true
83 };
84 
86  : ModifyObjectValueBase(conf),
87  eleCollVMsAreKeyedTo_(conf, "eleCollVMsAreKeyedTo", cc),
88  phoCollVMsAreKeyedTo_(conf, "phoCollVMsAreKeyedTo", cc),
89  conversions_(conf, "conversions", cc),
90  beamspot_(conf, "beamspot", cc),
91  ecalRecHitsEB_(conf, "ecalRecHitsEB", cc),
92  ecalRecHitsEE_(conf, "ecalRecHitsEE", cc),
93  eleTrkIso_(conf, "eleTrkIso", cc),
94  eleTrkIso04_(conf, "eleTrkIso04", cc),
95  phoPhotonIso_(conf, "phoPhotonIso", cc),
96  phoNeutralHadIso_(conf, "phoNeutralHadIso", cc),
97  phoChargedHadIso_(conf, "phoChargedHadIso", cc),
98  phoChargedHadWorstVtxIso_(conf, "phoChargedHadWorstVtxIso", cc),
99  phoChargedHadWorstVtxConeVetoIso_(conf, "phoChargedHadWorstVtxConeVetoIso", cc),
100  phoChargedHadPFPVIso_(conf, "phoChargedHadPFPVIso", cc),
101  allowGsfTrkMatchForConvs_(conf.getParameter<bool>("allowGsfTrackForConvs")),
102  updateChargedHadPFPVIso_(conf.getParameter<bool>("updateChargedHadPFPVIso")) {}
103 
109  ecalRecHitsEB_.setHandle(iEvent);
110  ecalRecHitsEE_.setHandle(iEvent);
120 }
121 
124  if (ptrForVM.isNull()) {
125  throw cms::Exception("LogicError")
126  << " in EG9X105ObjectUpdateModifier, line " << __LINE__ << " electron " << ele.et() << " " << ele.eta() << " "
127  << ele.superCluster()->seed()->seed().rawId()
128  << " failed to match to the electrons the key map was keyed to, check the map collection is correct";
129  }
134  } else {
135  //its rather important to use the core function here to get the org trk ref
137  ele.core()->ctfTrack(), *conversions_.handle(), beamspot_.handle()->position(), 2.0, 1e-6, 0));
138  }
139  ele.setConversionRejectionVariables(convRejVars);
140 
142  isolVars03.tkSumPtHEEP = (*eleTrkIso_.handle())[ptrForVM];
143  ele.setDr03Isolation(isolVars03);
145  isolVars04.tkSumPtHEEP = (*eleTrkIso04_.handle())[ptrForVM];
146  ele.setDr04Isolation(isolVars04);
147 }
148 
151  if (ptrForVM.isNull()) {
152  throw cms::Exception("LogicError")
153  << " in EG9X105ObjectUpdateModifier, line " << __LINE__ << " photon " << pho.et() << " " << pho.eta() << " "
154  << pho.superCluster()->seed()->seed().rawId()
155  << " failed to match to the photons the key map was keyed to, check the map collection is correct";
156  }
157 
159  pfIso.photonIso = (*phoPhotonIso_.handle())[ptrForVM];
160  pfIso.neutralHadronIso = (*phoNeutralHadIso_.handle())[ptrForVM];
161  pfIso.chargedHadronIso = (*phoChargedHadIso_.handle())[ptrForVM];
165  pfIso.chargedHadronPFPVIso = (*phoChargedHadPFPVIso_.handle())[ptrForVM];
166  }
167  pho.setPflowIsolationVariables(pfIso);
168 
171 
172  const reco::CaloClusterPtr seedClus = pho.superCluster()->seed();
173  const bool isEB = seedClus->seed().subdetId() == EcalBarrel;
174  const auto& recHits = isEB ? *ecalRecHitsEB_.handle() : *ecalRecHitsEE_.handle();
175  Cluster2ndMoments clus2ndMomFrac = EcalClusterTools::cluster2ndMoments(*seedClus, recHits);
177  fracSS.smMajor = clus2ndMomFrac.sMaj;
178  fracSS.smMinor = clus2ndMomFrac.sMin;
179  fracSS.smAlpha = clus2ndMomFrac.alpha;
180  fullSS.smMajor = clus2ndMomFull.sMaj;
181  fullSS.smMinor = clus2ndMomFull.sMin;
182  fullSS.smAlpha = clus2ndMomFull.alpha;
183  pho.setShowerShapeVariables(fracSS);
185 }
186 
187 template <typename ObjType>
189  const ObjType& obj, const edm::Handle<edm::View<ObjType> >& objsVMIsKeyedTo) {
190  for (auto& objVMPtr : objsVMIsKeyedTo->ptrs()) {
191  if (obj.superCluster()->seed()->seed() == objVMPtr->superCluster()->seed()->seed())
192  return objVMPtr;
193  }
194  return edm::Ptr<ObjType>(objsVMIsKeyedTo.id()); //return null ptr if not found
195 }
196 
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
reco::Photon::showerShapeVariables
const ShowerShape & showerShapeVariables() const
Definition: Photon.h:201
reco::Photon::superCluster
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
ESHandle.h
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
EG9X105XObjectUpdateModifier::phoChargedHadPFPVIso_
TokenHandlePair< edm::ValueMap< float > > phoChargedHadPFPVIso_
Definition: EG9X105XObjectUpdateModifier.cc:69
EG9X105XObjectUpdateModifier::TokenHandlePair
Definition: EG9X105XObjectUpdateModifier.cc:26
pat::Photon
Analysis-level Photon class.
Definition: Photon.h:46
EG9X105XObjectUpdateModifier::modifyObject
void modifyObject(pat::Electron &ele) const final
Definition: EG9X105XObjectUpdateModifier.cc:46
ConversionTools::getVtxFitProb
static float getVtxFitProb(const reco::Conversion *conv)
Definition: ConversionTools.cc:440
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89287
EG9X105XObjectUpdateModifier::getPtrForValueMap
static edm::Ptr< ObjType > getPtrForValueMap(const ObjType &obj, const edm::Handle< edm::View< ObjType > > &objsVMIsKeyedTo)
Definition: EG9X105XObjectUpdateModifier.cc:188
reco::Photon::PflowIsolationVariables::chargedHadronPFPVIso
float chargedHadronPFPVIso
Definition: Photon.h:463
reco::GsfElectron::dr03IsolationVariables
const IsolationVariables & dr03IsolationVariables() const
Definition: GsfElectron.h:538
EG9X105XObjectUpdateModifier::modifyObject
void modifyObject(pat::Photon &pho) const final
Definition: EG9X105XObjectUpdateModifier.cc:47
EG9X105XObjectUpdateModifier::phoChargedHadIso_
TokenHandlePair< edm::ValueMap< float > > phoChargedHadIso_
Definition: EG9X105XObjectUpdateModifier.cc:66
reco::Photon::PflowIsolationVariables::chargedHadronIso
float chargedHadronIso
Definition: Photon.h:460
EG9X105XObjectUpdateModifier::~EG9X105XObjectUpdateModifier
~EG9X105XObjectUpdateModifier() override
Definition: EG9X105XObjectUpdateModifier.cc:39
edm::Handle
Definition: AssociativeIterator.h:50
EG9X105XObjectUpdateModifier::phoChargedHadWorstVtxIso_
TokenHandlePair< edm::ValueMap< float > > phoChargedHadWorstVtxIso_
Definition: EG9X105XObjectUpdateModifier.cc:67
reco::Photon::PflowIsolationVariables::neutralHadronIso
float neutralHadronIso
Definition: Photon.h:464
EcalBarrel
Definition: EcalSubdetector.h:10
EcalRecHitCollections.h
EG9X105XObjectUpdateModifier::phoNeutralHadIso_
TokenHandlePair< edm::ValueMap< float > > phoNeutralHadIso_
Definition: EG9X105XObjectUpdateModifier.cc:65
reco::GsfElectron::core
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
reco::Photon::PflowIsolationVariables::chargedHadronWorstVtxGeomVetoIso
float chargedHadronWorstVtxGeomVetoIso
Definition: Photon.h:462
reco::GsfElectron::IsolationVariables::tkSumPtHEEP
float tkSumPtHEEP
Definition: GsfElectron.h:512
ModifyObjectValueBase::name
const std::string & name() const
Definition: ModifyObjectValueBase.h:59
EG9X105XObjectUpdateModifier::TokenHandlePair::setHandle
void setHandle(const edm::Event &iEvent)
Definition: EG9X105XObjectUpdateModifier.cc:30
Photon.h
reco::Photon::PflowIsolationVariables
Definition: Photon.h:459
EG9X105XObjectUpdateModifier::eleCollVMsAreKeyedTo_
TokenHandlePair< edm::View< reco::GsfElectron > > eleCollVMsAreKeyedTo_
Definition: EG9X105XObjectUpdateModifier.cc:54
BeamSpot.h
reco::Photon::setPflowIsolationVariables
void setPflowIsolationVariables(const PflowIsolationVariables &pfisol)
Set Particle Flow Isolation variables.
Definition: Photon.h:497
ModifyObjectValueBase.h
reco::GsfElectron::ConversionRejection
Definition: GsfElectron.h:572
reco::Photon::ShowerShape::smAlpha
float smAlpha
Definition: Photon.h:168
EG9X105XObjectUpdateModifier::TokenHandlePair::token_
edm::EDGetTokenT< T > token_
Definition: EG9X105XObjectUpdateModifier.cc:34
EG9X105XObjectUpdateModifier::TokenHandlePair::handle
const edm::Handle< T > & handle() const
Definition: EG9X105XObjectUpdateModifier.cc:31
EG9X105XObjectUpdateModifier::TokenHandlePair::handle_
edm::Handle< T > handle_
Definition: EG9X105XObjectUpdateModifier.cc:35
reco::Photon::ShowerShape::smMajor
float smMajor
Definition: Photon.h:166
reco::GsfElectron
Definition: GsfElectron.h:35
Cluster2ndMoments::alpha
float alpha
Definition: EcalClusterTools.h:68
reco::BeamSpot::position
const Point & position() const
position
Definition: BeamSpot.h:59
GsfElectron.h
reco::GsfElectron::IsolationVariables
Definition: GsfElectron.h:510
DEFINE_EDM_PLUGIN
#define DEFINE_EDM_PLUGIN(factory, type, name)
Definition: PluginFactory.h:124
EDGetToken.h
EcalClusterToolsT::cluster2ndMoments
static Cluster2ndMoments cluster2ndMoments(const reco::BasicCluster &basicCluster, const EcalRecHitCollection &recHits, double phiCorrectionFactor=0.8, double w0=4.7, bool useLogWeights=true)
Definition: EcalClusterTools.h:1446
reco::GsfElectron::setDr04Isolation
void setDr04Isolation(const IsolationVariables &dr04)
Definition: GsfElectron.h:554
getGTfromDQMFile.obj
obj
Definition: getGTfromDQMFile.py:32
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EG9X105XObjectUpdateModifier::beamspot_
TokenHandlePair< reco::BeamSpot > beamspot_
Definition: EG9X105XObjectUpdateModifier.cc:58
FastTrackerRecHitMaskProducer_cfi.recHits
recHits
Definition: FastTrackerRecHitMaskProducer_cfi.py:8
EG9X105XObjectUpdateModifier::eleTrkIso04_
TokenHandlePair< edm::ValueMap< float > > eleTrkIso04_
Definition: EG9X105XObjectUpdateModifier.cc:63
edm::View
Definition: CaloClusterFwd.h:14
reco::Photon::PflowIsolationVariables::chargedHadronWorstVtxIso
float chargedHadronWorstVtxIso
Definition: Photon.h:461
edm::ParameterSet
Definition: ParameterSet.h:47
reco::GsfElectron::conversionRejectionVariables
const ConversionRejection & conversionRejectionVariables() const
Definition: GsfElectron.h:594
Cluster2ndMoments::sMaj
float sMaj
Definition: EcalClusterTools.h:65
reco::Photon::full5x5_setShowerShapeVariables
void full5x5_setShowerShapeVariables(const ShowerShape &a)
Definition: Photon.h:205
reco::Photon::full5x5_showerShapeVariables
const ShowerShape & full5x5_showerShapeVariables() const
Definition: Photon.h:202
ModifyObjectValueBase
Definition: ModifyObjectValueBase.h:18
reco::LeafCandidate::eta
double eta() const final
momentum pseudorapidity
Definition: LeafCandidate.h:152
reco::Photon::getPflowIsolationVariables
const PflowIsolationVariables & getPflowIsolationVariables() const
Get Particle Flow Isolation variables block.
Definition: Photon.h:494
edmplugin::PluginFactory
Definition: PluginFactory.h:34
EcalClusterTools.h
EG9X105XObjectUpdateModifier::phoChargedHadWorstVtxConeVetoIso_
TokenHandlePair< edm::ValueMap< float > > phoChargedHadWorstVtxConeVetoIso_
Definition: EG9X105XObjectUpdateModifier.cc:68
reco::Photon::ShowerShape::smMinor
float smMinor
Definition: Photon.h:167
iEvent
int iEvent
Definition: GenABIO.cc:224
EG9X105XObjectUpdateModifier
Definition: EG9X105XObjectUpdateModifier.cc:23
EG9X105XObjectUpdateModifier::ecalRecHitsEE_
TokenHandlePair< EcalRecHitCollection > ecalRecHitsEE_
Definition: EG9X105XObjectUpdateModifier.cc:60
EG9X105XObjectUpdateModifier::eleTrkIso_
TokenHandlePair< edm::ValueMap< float > > eleTrkIso_
Definition: EG9X105XObjectUpdateModifier.cc:62
EG9X105XObjectUpdateModifier::EG9X105XObjectUpdateModifier
EG9X105XObjectUpdateModifier(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
Definition: EG9X105XObjectUpdateModifier.cc:85
EG9X105XObjectUpdateModifier::allowGsfTrkMatchForConvs_
bool allowGsfTrkMatchForConvs_
Definition: EG9X105XObjectUpdateModifier.cc:76
EG9X105XObjectUpdateModifier::TokenHandlePair::TokenHandlePair
TokenHandlePair(const edm::ParameterSet &conf, const std::string &name, edm::ConsumesCollector &cc)
Definition: EG9X105XObjectUpdateModifier.cc:28
cc
InputTag.h
edm::Ptr
Definition: AssociationVector.h:31
ValueMap.h
EG9X105XObjectUpdateModifier::modifyObject
void modifyObject(reco::GsfElectron &ele) const final
Definition: EG9X105XObjectUpdateModifier.cc:122
EG9X105XObjectUpdateModifier::setEvent
void setEvent(const edm::Event &) final
Definition: EG9X105XObjectUpdateModifier.cc:104
reco::Photon
Definition: Photon.h:21
reco::LeafCandidate::et
double et() const final
transverse energy
Definition: LeafCandidate.h:127
reco::Photon::ShowerShape
Definition: Photon.h:137
reco::GsfElectron::setConversionRejectionVariables
void setConversionRejectionVariables(const ConversionRejection &convRej)
Definition: GsfElectron.h:595
reco::GsfElectron::setDr03Isolation
void setDr03Isolation(const IsolationVariables &dr03)
Definition: GsfElectron.h:553
Exception
Definition: hltDiff.cc:246
EG9X105XObjectUpdateModifier::phoCollVMsAreKeyedTo_
TokenHandlePair< edm::View< reco::Photon > > phoCollVMsAreKeyedTo_
Definition: EG9X105XObjectUpdateModifier.cc:55
ConversionTools::matchedConversion
static const reco::Conversion * matchedConversion(const reco::GsfElectron &ele, const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
Definition: ConversionTools.cc:257
EG9X105XObjectUpdateModifier::conversions_
TokenHandlePair< reco::ConversionCollection > conversions_
Definition: EG9X105XObjectUpdateModifier.cc:57
reco::Photon::PflowIsolationVariables::photonIso
float photonIso
Definition: Photon.h:465
reco::GsfElectron::superCluster
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:163
Cluster2ndMoments::sMin
float sMin
Definition: EcalClusterTools.h:66
pat::Electron
Analysis-level electron class.
Definition: Electron.h:51
ParameterSet.h
EG9X105XObjectUpdateModifier::phoPhotonIso_
TokenHandlePair< edm::ValueMap< float > > phoPhotonIso_
Definition: EG9X105XObjectUpdateModifier.cc:64
edm::Event
Definition: Event.h:73
EG9X105XObjectUpdateModifier::updateChargedHadPFPVIso_
bool updateChargedHadPFPVIso_
Definition: EG9X105XObjectUpdateModifier.cc:82
reco::GsfElectron::dr04IsolationVariables
const IsolationVariables & dr04IsolationVariables() const
Definition: GsfElectron.h:550
Cluster2ndMoments
Definition: EcalClusterTools.h:63
EG9X105XObjectUpdateModifier::ecalRecHitsEB_
TokenHandlePair< EcalRecHitCollection > ecalRecHitsEB_
Definition: EG9X105XObjectUpdateModifier.cc:59
edm::Ptr::isNull
bool isNull() const
Checks for null.
Definition: Ptr.h:142
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
reco::GsfElectron::ConversionRejection::vtxFitProb
float vtxFitProb
Definition: GsfElectron.h:578
reco::Photon::setShowerShapeVariables
void setShowerShapeVariables(const ShowerShape &a)
Definition: Photon.h:204
ConversionTools.h
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
Conversion.h