Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-06 23:49:56

0001 #include "CommonTools/CandAlgos/interface/ModifyObjectValueBase.h"
0002 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0003 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "RecoEgamma/EgammaTools/interface/LowPtConversion.h"
0007 
0008 ////////////////////////////////////////////////////////////////////////////////
0009 //
0010 class LowPtElectronModifier : public ModifyObjectValueBase {
0011 public:
0012   LowPtElectronModifier(const edm::ParameterSet& conf, edm::ConsumesCollector&);
0013   ~LowPtElectronModifier() override = default;
0014 
0015   void setEvent(const edm::Event&) final;
0016   void setEventContent(const edm::EventSetup&) final;
0017 
0018   void modifyObject(pat::Electron& ele) const final;
0019 
0020 private:
0021   const edm::EDGetTokenT<reco::ConversionCollection> convT_;
0022   reco::ConversionCollection const* conv_ = nullptr;
0023   const edm::EDGetTokenT<reco::BeamSpot> beamSpotT_;
0024   reco::BeamSpot const* beamSpot_ = nullptr;
0025   const edm::EDGetTokenT<reco::VertexCollection> verticesT_;
0026   reco::VertexCollection const* vertices_ = nullptr;
0027   bool extra_;
0028 };
0029 
0030 ////////////////////////////////////////////////////////////////////////////////
0031 //
0032 LowPtElectronModifier::LowPtElectronModifier(const edm::ParameterSet& conf, edm::ConsumesCollector& cc)
0033     : ModifyObjectValueBase(conf),
0034       convT_(cc.consumes<reco::ConversionCollection>(conf.getParameter<edm::InputTag>("conversions"))),
0035       conv_(),
0036       beamSpotT_(cc.consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("beamSpot"))),
0037       beamSpot_(),
0038       verticesT_(cc.consumes<reco::VertexCollection>(conf.getParameter<edm::InputTag>("vertices"))),
0039       vertices_(),
0040       extra_(conf.getParameter<bool>("addExtraUserVars")) {
0041   ;
0042 }
0043 
0044 ////////////////////////////////////////////////////////////////////////////////
0045 //
0046 void LowPtElectronModifier::setEvent(const edm::Event& iEvent) {
0047   conv_ = &iEvent.get(convT_);
0048   beamSpot_ = &iEvent.get(beamSpotT_);
0049   vertices_ = &iEvent.get(verticesT_);
0050 }
0051 
0052 ////////////////////////////////////////////////////////////////////////////////
0053 //
0054 void LowPtElectronModifier::setEventContent(const edm::EventSetup& iSetup) {}
0055 
0056 ////////////////////////////////////////////////////////////////////////////////
0057 //
0058 void LowPtElectronModifier::modifyObject(pat::Electron& ele) const {
0059   // Embed Conversion info
0060   LowPtConversion conv;
0061   conv.match(*beamSpot_, *conv_, ele);
0062   conv.addUserVars(ele);
0063   if (extra_) {
0064     conv.addExtraUserVars(ele);
0065   }
0066   // Set impact parameters
0067   auto const& gsfTrack = *ele.gsfTrack();
0068   if (!vertices_->empty()) {
0069     const reco::Vertex& pv = vertices_->front();
0070     ele.setDB(gsfTrack.dxy(pv.position()),
0071               gsfTrack.dxyError(pv.position(), pv.covariance()),
0072               pat::Electron::PV2D);  // PV2D
0073     ele.setDB(gsfTrack.dz(pv.position()), std::hypot(gsfTrack.dzError(), pv.zError()),
0074               pat::Electron::PVDZ);  // PVDZ
0075   }
0076   ele.setDB(gsfTrack.dxy(*beamSpot_), gsfTrack.dxyError(*beamSpot_),
0077             pat::Electron::BS2D);  // BS2D
0078 }
0079 
0080 ////////////////////////////////////////////////////////////////////////////////
0081 //
0082 DEFINE_EDM_PLUGIN(ModifyObjectValueFactory, LowPtElectronModifier, "LowPtElectronModifier");