CMS 3D CMS Logo

EG9X105XObjectUpdateModifier.cc
Go to the documentation of this file.
15 
16 
17 #include <vdt/vdtMath.h>
18 
19 //this modifier fills variables where not present in CMSSW_92X to CMSSW_105X
20 //use case is when reading older new samples in newer releases, aka legacy
21 //note we suffer from the problem of needing to use the electrons/photons the valuemaps
22 //are keyed to (something that is thankfully going away in 11X!) so we have to take
23 //those collections in and figure out which ele/pho matches to them
25 public:
26  template<typename T>
28  public:
30  token_(cc.consumes<T>(conf.getParameter<edm::InputTag>(name))){}
31  void setHandle(const edm::Event& iEvent){
32  iEvent.getByToken(token_,handle_);
33  }
34  const edm::Handle<T>& handle()const{return handle_;}
35  private:
38  };
39 
42 
43  void setEvent(const edm::Event&) final;
44  void setEventContent(const edm::EventSetup&) final;
45 
46  void modifyObject(reco::GsfElectron& ele) const final;
47  void modifyObject(reco::Photon& pho) const final;
48 
49  void modifyObject(pat::Electron& ele) const final{return modifyObject(static_cast<reco::GsfElectron&>(ele));}
50  void modifyObject(pat::Photon& pho) const final{return modifyObject(static_cast<reco::Photon&>(pho));}
51 
52 private:
53  template<typename ObjType>
54  static edm::Ptr<ObjType> getPtrForValueMap(const ObjType& obj,
55  const edm::Handle<edm::View<ObjType> >& objsVMIsKeyedTo);
56 
59 
64 
73  //there is a bug which GsfTracks are now allowed to be a match for conversions
74  //due to improper linking of references in the miniAOD since 94X
75  //this allows us to emulate it or not
76  //note: even if this enabled, it will do nothing on miniAOD produced with 94X, 102X
77  //till upto whenever this is fixed (11X?) as the GsfTrack references point to a different
78  //collection to the conversion track references
80  //this allows us to update the charged hadron PF PV isolation
81  //chargedHadPFPVIso is filled in iorules but when running on miniAOD, the value used in IDs
82  //is remade on the miniAOD packedcandidates which differs due to rounding
83  //its still the same variable but can have differences hence inorder to allow IDs calculated on miniAOD
84  //on the same file to be exactly reproduced, this option is set true
86 
87 };
88 
91  eleCollVMsAreKeyedTo_(conf,"eleCollVMsAreKeyedTo",cc),
92  phoCollVMsAreKeyedTo_(conf,"phoCollVMsAreKeyedTo",cc),
93  conversions_(conf,"conversions",cc),
94  beamspot_(conf,"beamspot",cc),
95  ecalRecHitsEB_(conf,"ecalRecHitsEB",cc),
96  ecalRecHitsEE_(conf,"ecalRecHitsEE",cc),
97  eleTrkIso_(conf,"eleTrkIso",cc),
98  eleTrkIso04_(conf,"eleTrkIso04",cc),
99  phoPhotonIso_(conf,"phoPhotonIso",cc),
100  phoNeutralHadIso_(conf,"phoNeutralHadIso",cc),
101  phoChargedHadIso_(conf,"phoChargedHadIso",cc),
102  phoChargedHadWorstVtxIso_(conf,"phoChargedHadWorstVtxIso",cc),
103  phoChargedHadWorstVtxConeVetoIso_(conf,"phoChargedHadWorstVtxConeVetoIso",cc),
104  phoChargedHadPFPVIso_(conf,"phoChargedHadPFPVIso",cc),
105  allowGsfTrkMatchForConvs_(conf.getParameter<bool>("allowGsfTrackForConvs")),
106  updateChargedHadPFPVIso_(conf.getParameter<bool>("updateChargedHadPFPVIso"))
107 {
108 
109 
110 }
111 
113 {
116  conversions_.setHandle(iEvent);
117  beamspot_.setHandle(iEvent);
118  ecalRecHitsEB_.setHandle(iEvent);
119  ecalRecHitsEE_.setHandle(iEvent);
120  eleTrkIso_.setHandle(iEvent);
121  eleTrkIso04_.setHandle(iEvent);
122  phoPhotonIso_.setHandle(iEvent);
128 }
129 
131 {
132 
133 }
134 
136 {
138  if(ptrForVM.isNull()){
139  throw cms::Exception("LogicError") <<" in EG9X105ObjectUpdateModifier, line "<<__LINE__<<" electron "<<ele.et()<<" "<<ele.eta()<<" "<<ele.superCluster()->seed()->seed().rawId()<<" failed to match to the electrons the key map was keyed to, check the map collection is correct";
140  }
144  }else{
145  //its rather important to use the core function here to get the org trk ref
147  }
148  ele.setConversionRejectionVariables(convRejVars);
149 
151  isolVars03.tkSumPtHEEP = (*eleTrkIso_.handle())[ptrForVM];
152  ele.setDr03Isolation(isolVars03);
154  isolVars04.tkSumPtHEEP = (*eleTrkIso04_.handle())[ptrForVM];
155  ele.setDr04Isolation(isolVars04);
156 }
157 
159 {
161  if(ptrForVM.isNull()){
162  throw cms::Exception("LogicError") <<" in EG9X105ObjectUpdateModifier, line "<<__LINE__<<" photon "<<pho.et()<<" "<<pho.eta()<<" "<<pho.superCluster()->seed()->seed().rawId()<<" failed to match to the photons the key map was keyed to, check the map collection is correct";
163  }
164 
166  pfIso.photonIso = (*phoPhotonIso_.handle())[ptrForVM];
167  pfIso.neutralHadronIso = (*phoNeutralHadIso_.handle())[ptrForVM];
168  pfIso.chargedHadronIso = (*phoChargedHadIso_.handle())[ptrForVM];
172  pfIso.chargedHadronPFPVIso = (*phoChargedHadPFPVIso_.handle())[ptrForVM];
173  }
174  pho.setPflowIsolationVariables(pfIso);
175 
178 
179  const reco::CaloClusterPtr seedClus = pho.superCluster()->seed();
180  const bool isEB = seedClus->seed().subdetId()==EcalBarrel;
181  const auto& recHits = isEB ? *ecalRecHitsEB_.handle() : *ecalRecHitsEE_.handle();
182  Cluster2ndMoments clus2ndMomFrac = EcalClusterTools::cluster2ndMoments(*seedClus,recHits);
183  Cluster2ndMoments clus2ndMomFull = noZS::EcalClusterTools::cluster2ndMoments(*seedClus,recHits);
184  fracSS.smMajor = clus2ndMomFrac.sMaj;
185  fracSS.smMinor = clus2ndMomFrac.sMin;
186  fracSS.smAlpha = clus2ndMomFrac.alpha;
187  fullSS.smMajor = clus2ndMomFull.sMaj;
188  fullSS.smMinor = clus2ndMomFull.sMin;
189  fullSS.smAlpha = clus2ndMomFull.alpha;
190  pho.setShowerShapeVariables(fracSS);
192 
193 }
194 
195 template<typename ObjType> edm::Ptr<ObjType> EG9X105XObjectUpdateModifier::
196 getPtrForValueMap(const ObjType& obj,
197  const edm::Handle<edm::View<ObjType> >& objsVMIsKeyedTo)
198 {
199  for(auto& objVMPtr : objsVMIsKeyedTo->ptrs()){
200  if(obj.superCluster()->seed()->seed()==objVMPtr->superCluster()->seed()->seed()) return objVMPtr;
201  }
202  return edm::Ptr<ObjType>(objsVMIsKeyedTo.id()); //return null ptr if not found
203 }
204 
205 
208  "EG9X105XObjectUpdateModifier");
void setDr04Isolation(const IsolationVariables &dr04)
Definition: GsfElectron.h:577
void setPflowIsolationVariables(const PflowIsolationVariables &pfisol)
Set Particle Flow Isolation variables.
Definition: Photon.h:509
Analysis-level Photon class.
Definition: Photon.h:47
void modifyObject(pat::Photon &pho) const final
static reco::Conversion const * 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)
TokenHandlePair< edm::ValueMap< float > > eleTrkIso04_
TokenHandlePair< edm::ValueMap< float > > phoPhotonIso_
double eta() const final
momentum pseudorapidity
TokenHandlePair< edm::ValueMap< float > > phoChargedHadWorstVtxIso_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
TokenHandlePair< edm::View< reco::Photon > > phoCollVMsAreKeyedTo_
void setEvent(const edm::Event &) final
TokenHandlePair< reco::BeamSpot > beamspot_
TokenHandlePair< EcalRecHitCollection > ecalRecHitsEE_
void setConversionRejectionVariables(const ConversionRejection &convRej)
Definition: GsfElectron.h:623
TokenHandlePair< EcalRecHitCollection > ecalRecHitsEB_
reco::SuperClusterRef superCluster() const override
Ref to SuperCluster.
void setDr03Isolation(const IsolationVariables &dr03)
Definition: GsfElectron.h:576
const IsolationVariables & dr04IsolationVariables() const
Definition: GsfElectron.h:573
TokenHandlePair< edm::ValueMap< float > > phoChargedHadWorstVtxConeVetoIso_
void setEventContent(const edm::EventSetup &) final
static edm::Ptr< ObjType > getPtrForValueMap(const ObjType &obj, const edm::Handle< edm::View< ObjType > > &objsVMIsKeyedTo)
TokenHandlePair< edm::ValueMap< float > > eleTrkIso_
int iEvent
Definition: GenABIO.cc:224
static float getVtxFitProb(const reco::Conversion *conv)
const std::string & name() const
double et() const final
transverse energy
bool isNull() const
Checks for null.
Definition: Ptr.h:164
void setShowerShapeVariables(const ShowerShape &a)
Definition: Photon.h:208
static Cluster2ndMoments cluster2ndMoments(const reco::BasicCluster &basicCluster, const EcalRecHitCollection &recHits, double phiCorrectionFactor=0.8, double w0=4.7, bool useLogWeights=true)
void modifyObject(reco::GsfElectron &ele) const final
TokenHandlePair< reco::ConversionCollection > conversions_
Analysis-level electron class.
Definition: Electron.h:52
virtual GsfElectronCoreRef core() const
Definition: GsfElectron.cc:8
void full5x5_setShowerShapeVariables(const ShowerShape &a)
Definition: Photon.h:209
HLT enums.
const ShowerShape & full5x5_showerShapeVariables() const
Definition: Photon.h:206
TokenHandlePair< edm::ValueMap< float > > phoChargedHadPFPVIso_
const IsolationVariables & dr03IsolationVariables() const
Definition: GsfElectron.h:561
SuperClusterRef superCluster() const override
reference to a SuperCluster
Definition: GsfElectron.h:185
TokenHandlePair(const edm::ParameterSet &conf, const std::string &name, edm::ConsumesCollector &cc)
#define DEFINE_EDM_PLUGIN(factory, type, name)
const Point & position() const
position
Definition: BeamSpot.h:62
const ConversionRejection & conversionRejectionVariables() const
Definition: GsfElectron.h:622
const PflowIsolationVariables & getPflowIsolationVariables() const
Get Particle Flow Isolation variables block.
Definition: Photon.h:506
TokenHandlePair< edm::View< reco::GsfElectron > > eleCollVMsAreKeyedTo_
long double T
const ShowerShape & showerShapeVariables() const
Definition: Photon.h:205
EG9X105XObjectUpdateModifier(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
TokenHandlePair< edm::ValueMap< float > > phoNeutralHadIso_
TokenHandlePair< edm::ValueMap< float > > phoChargedHadIso_
void modifyObject(pat::Electron &ele) const final