CMS 3D CMS Logo

ElectronMVAVariableHelper.cc
Go to the documentation of this file.
14 
15 #include <TMath.h>
16 
18  public:
19 
20  explicit ElectronMVAVariableHelper(const edm::ParameterSet & iConfig);
21  ~ElectronMVAVariableHelper() override ;
22 
23  void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
26 
27 private:
28 
29  // for AOD and MiniAOD case
34 };
35 
37  : electronsToken_ ( consumesCollector(), iConfig, "src" , "srcMiniAOD")
38  , vtxToken_ (electronsToken_, consumesCollector(), iConfig, "vertexCollection", "vertexCollectionMiniAOD")
39  , conversionsToken_(electronsToken_, consumesCollector(), iConfig, "conversions" , "conversionsMiniAOD")
40  , beamSpotToken_ (consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot")))
41 {
42  produces<edm::ValueMap<float>>("convVtxFitProb");
43  produces<edm::ValueMap<float>>("kfhits");
44  produces<edm::ValueMap<float>>("kfchi2");
45 }
46 
48 {}
49 
51 
52  // get Handles
54  auto vtxH = vtxToken_.getValidHandle(iEvent);
56 
57  edm::Handle<reco::BeamSpot> beamSpotHandle;
58  iEvent.getByToken(beamSpotToken_, beamSpotHandle);
59 
60  const reco::VertexRef vtx(vtxH, 0);
61  const reco::BeamSpot* beamSpot = &*(beamSpotHandle.product());
62 
63  // prepare vector for output
64  std::vector<float> convVtxFitProbVals;
65  std::vector<float> kfhitsVals;
66  std::vector<float> kfchi2Vals;
67 
68  for (auto const& ele : *electrons) {
69 
70  // Conversion vertex fit
72 
73  float convVtxFitProb = -1.;
74  if(!convRef.isNull()) {
75  const reco::Vertex &vtx = convRef.get()->conversionVertex();
76  if (vtx.isValid()) {
77  convVtxFitProb = TMath::Prob( vtx.chi2(), vtx.ndof());
78  }
79  }
80 
81  convVtxFitProbVals.push_back(convVtxFitProb);
82 
83  // kf track related variables
84  bool validKf=false;
85  reco::TrackRef trackRef = ele.closestCtfTrackRef();
86  validKf = trackRef.isAvailable();
87  validKf &= trackRef.isNonnull();
88  float kfchi2 = validKf ? trackRef->normalizedChi2() : 0 ; //ielectron->track()->normalizedChi2() : 0 ;
89  float kfhits = validKf ? trackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
90 
91  kfchi2Vals.push_back(kfchi2);
92  kfhitsVals.push_back(kfhits);
93 
94  }
95 
96  // convert into ValueMap and store
97  writeValueMap(iEvent, electrons, kfchi2Vals, "kfchi2" );
98  writeValueMap(iEvent, electrons, kfhitsVals, "kfhits" );
99  writeValueMap(iEvent, electrons, convVtxFitProbVals, "convVtxFitProb" );
100 }
101 
103  // electronMVAVariableHelper
105  desc.add<edm::InputTag>("conversions", edm::InputTag("allConversions"));
106  desc.add<edm::InputTag>("src", edm::InputTag("gedGsfElectrons"));
107  desc.add<edm::InputTag>("srcMiniAOD", edm::InputTag("slimmedElectrons","","@skipCurrentProcess"));
108  desc.add<edm::InputTag>("beamSpot", edm::InputTag("offlineBeamSpot"));
109  desc.add<edm::InputTag>("conversionsMiniAOD", edm::InputTag("reducedEgamma","reducedConversions"));
110  desc.add<edm::InputTag>("vertexCollection", edm::InputTag("offlinePrimaryVertices"));
111  desc.add<edm::InputTag>("vertexCollectionMiniAOD", edm::InputTag("offlineSlimmedPrimaryVertices"));
112  descriptions.add("electronMVAVariableHelper", desc);
113 }
114 
bool isAvailable() const
Definition: Ref.h:577
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:68
void writeValueMap(edm::Event &iEvent, const edm::Handle< HandleType > &handle, const std::vector< ValueType > &values, const std::string &label)
Definition: Utils.h:13
ElectronMVAVariableHelper(const edm::ParameterSet &iConfig)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
int iEvent
Definition: GenABIO.cc:230
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
double chi2() const
chi-squares
Definition: Vertex.h:98
MultiTokenT< reco::VertexCollection > vtxToken_
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
ParameterDescriptionBase * add(U const &iLabel, T const &value)
MultiTokenT< reco::ConversionCollection > conversionsToken_
bool isNull() const
Checks for null.
Definition: Ref.h:250
double ndof() const
Definition: Vertex.h:105
edm::Handle< T > getValidHandle(const edm::Event &iEvent)
Definition: MultiToken.h:83
T const * product() const
Definition: Handle.h:81
void add(std::string const &label, ParameterSetDescription const &psetDescription)
MultiTokenT< edm::View< reco::GsfElectron > > electronsToken_
fixed size matrix
HLT enums.
const Point & position() const
position
Definition: BeamSpot.h:62
static reco::ConversionRef matchedConversion(const reco::GsfElectron &ele, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_