CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
ElectronMVAVariableHelper< ParticleType > Class Template Reference

#include <ElectronMVAVariableHelper.h>

Inheritance diagram for ElectronMVAVariableHelper< ParticleType >:
edm::stream::EDProducer<>

Public Member Functions

 ElectronMVAVariableHelper (const edm::ParameterSet &iConfig)
 
void produce (edm::Event &iEvent, const edm::EventSetup &iSetup) override
 
 ~ElectronMVAVariableHelper () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Member Functions

template<typename T >
void writeValueMap (edm::Event &iEvent, const edm::Handle< edm::View< ParticleType > > &handle, const std::vector< T > &values, const std::string &label) const
 

Private Attributes

const edm::EDGetTokenT< reco::BeamSpotbeamSpotToken_
 
const edm::EDGetTokenT< reco::BeamSpotbeamSpotTokenMiniAOD_
 
const edm::EDGetTokenT< reco::ConversionCollectionconversionsToken_
 
const edm::EDGetTokenT< reco::ConversionCollectionconversionsTokenMiniAOD_
 
const edm::EDGetTokenT< edm::View< ParticleType > > electronsToken_
 
const edm::EDGetTokenT< edm::View< ParticleType > > electronsTokenMiniAOD_
 
const edm::EDGetTokenT< reco::VertexCollectionvtxToken_
 
const edm::EDGetTokenT< reco::VertexCollectionvtxTokenMiniAOD_
 

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, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

template<class ParticleType>
class ElectronMVAVariableHelper< ParticleType >

Definition at line 34 of file ElectronMVAVariableHelper.h.

Constructor & Destructor Documentation

template<class ParticleType >
ElectronMVAVariableHelper< ParticleType >::ElectronMVAVariableHelper ( const edm::ParameterSet iConfig)
explicit

Definition at line 63 of file ElectronMVAVariableHelper.h.

63  :
65  vtxToken_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexCollection"))),
66  conversionsToken_(consumes<reco::ConversionCollection>(iConfig.getParameter<edm::InputTag>("conversions"))),
67  beamSpotToken_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
69  vtxTokenMiniAOD_(consumes<reco::VertexCollection>(iConfig.getParameter<edm::InputTag>("vertexCollectionMiniAOD"))),
70  conversionsTokenMiniAOD_(consumes<reco::ConversionCollection>(iConfig.getParameter<edm::InputTag>("conversionsMiniAOD"))),
71  beamSpotTokenMiniAOD_(consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpotMiniAOD"))) {
72 
73  produces<edm::ValueMap<float>>("convVtxFitProb");
74  produces<edm::ValueMap<float>>("kfhits");
75  produces<edm::ValueMap<float>>("kfchi2");
76 }
const edm::EDGetTokenT< reco::BeamSpot > beamSpotTokenMiniAOD_
T getParameter(std::string const &) const
const edm::EDGetTokenT< edm::View< ParticleType > > electronsTokenMiniAOD_
const edm::EDGetTokenT< reco::ConversionCollection > conversionsTokenMiniAOD_
const edm::EDGetTokenT< reco::VertexCollection > vtxTokenMiniAOD_
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
const edm::EDGetTokenT< reco::VertexCollection > vtxToken_
const edm::EDGetTokenT< reco::ConversionCollection > conversionsToken_
const edm::EDGetTokenT< edm::View< ParticleType > > electronsToken_
template<class ParticleType >
ElectronMVAVariableHelper< ParticleType >::~ElectronMVAVariableHelper ( )
override

Definition at line 79 of file ElectronMVAVariableHelper.h.

80 {}

Member Function Documentation

template<class ParticleType >
void ElectronMVAVariableHelper< ParticleType >::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
override

Definition at line 83 of file ElectronMVAVariableHelper.h.

References ecalDrivenElectronSeedsParameters_cff::beamSpot, ElectronMVAVariableHelper< ParticleType >::beamSpotToken_, ElectronMVAVariableHelper< ParticleType >::beamSpotTokenMiniAOD_, reco::Vertex::chi2(), conversions_cfi::conversions, ElectronMVAVariableHelper< ParticleType >::conversionsToken_, ElectronMVAVariableHelper< ParticleType >::conversionsTokenMiniAOD_, electrons_cff::electrons, ElectronMVAVariableHelper< ParticleType >::electronsToken_, ElectronMVAVariableHelper< ParticleType >::electronsTokenMiniAOD_, Exception, edm::Ref< C, T, F >::get(), edm::Event::getByToken(), mps_fire::i, edm::Ref< C, T, F >::isAvailable(), edm::Ref< C, T, F >::isNonnull(), edm::Ref< C, T, F >::isNull(), reco::Vertex::isValid(), edm::HandleBase::isValid(), ConversionTools::matchedConversion(), reco::Vertex::ndof(), reco::BeamSpot::position(), edm::Handle< T >::product(), badGlobalMuonTaggersAOD_cff::vtx, ElectronMVAVariableHelper< ParticleType >::vtxToken_, ElectronMVAVariableHelper< ParticleType >::vtxTokenMiniAOD_, and ElectronMVAVariableHelper< ParticleType >::writeValueMap().

83  {
84 
85  // read input
89  edm::Handle<reco::BeamSpot> beamSpotHandle;
90 
91  bool isAOD = true;
92  // Retrieve the collection of particles from the event.
93  // If we fail to retrieve the collection with the standard AOD
94  // name, we next look for the one with the stndard miniAOD name.
95  iEvent.getByToken(electronsToken_, electrons);
96  if( !electrons.isValid() ){
97  isAOD = false;
98  iEvent.getByToken(electronsTokenMiniAOD_,electrons);
99  if( !electrons.isValid() )
100  throw cms::Exception(" Collection not found: ") << " failed to find a standard AOD or miniAOD particle collection " << std::endl;
101  }
102 
103  if (isAOD) {
104  iEvent.getByToken(vtxToken_, vtxH);
105  iEvent.getByToken(conversionsToken_, conversions);
106  iEvent.getByToken(beamSpotToken_, beamSpotHandle);
107  } else {
108  iEvent.getByToken(vtxTokenMiniAOD_, vtxH);
109  iEvent.getByToken(conversionsTokenMiniAOD_, conversions);
110  iEvent.getByToken(beamSpotTokenMiniAOD_, beamSpotHandle);
111  }
112 
113  // Make sure everything is retrieved successfully
114  if(! (beamSpotHandle.isValid() && conversions.isValid() && vtxH.isValid() ) ) {
115  throw cms::Exception("MVA failure: ")
116  << "Failed to retrieve event content needed for this MVA"
117  << std::endl
118  << "Check python MVA configuration file."
119  << std::endl;
120  }
121 
122  const reco::VertexRef vtx(vtxH, 0);
123  const reco::BeamSpot* beamSpot = &*(beamSpotHandle.product());
124 
125  // prepare vector for output
126  std::vector<float> convVtxFitProbVals;
127  std::vector<float> kfhitsVals;
128  std::vector<float> kfchi2Vals;
129 
130  for (size_t i = 0; i < electrons->size(); ++i){
131  auto iCand = electrons->ptrAt(i);
132 
133  // Conversion vertex fit
134  reco::ConversionRef convRef = ConversionTools::matchedConversion(*iCand, conversions, beamSpot->position());
135 
136  float convVtxFitProb = -1.;
137  if(!convRef.isNull()) {
138  const reco::Vertex &vtx = convRef.get()->conversionVertex();
139  if (vtx.isValid()) {
140  convVtxFitProb = TMath::Prob( vtx.chi2(), vtx.ndof());
141  }
142  }
143 
144  convVtxFitProbVals.push_back(convVtxFitProb);
145 
146  // kf track related variables
147  bool validKf=false;
148  reco::TrackRef trackRef = iCand->closestCtfTrackRef();
149  validKf = trackRef.isAvailable();
150  validKf &= trackRef.isNonnull();
151  float kfchi2 = validKf ? trackRef->normalizedChi2() : 0 ; //ielectron->track()->normalizedChi2() : 0 ;
152  float kfhits = validKf ? trackRef->hitPattern().trackerLayersWithMeasurement() : -1. ;
153 
154  kfchi2Vals.push_back(kfchi2);
155  kfhitsVals.push_back(kfhits);
156 
157  }
158 
159 
160  // convert into ValueMap and store
161  writeValueMap(iEvent, electrons, kfchi2Vals, "kfchi2" );
162  writeValueMap(iEvent, electrons, kfhitsVals, "kfhits" );
163  writeValueMap(iEvent, electrons, convVtxFitProbVals, "convVtxFitProb" );
164 }
const edm::EDGetTokenT< reco::BeamSpot > beamSpotTokenMiniAOD_
bool isAvailable() const
Definition: Ref.h:577
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
const edm::EDGetTokenT< edm::View< ParticleType > > electronsTokenMiniAOD_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:68
const edm::EDGetTokenT< reco::ConversionCollection > conversionsTokenMiniAOD_
const edm::EDGetTokenT< reco::VertexCollection > vtxTokenMiniAOD_
double chi2() const
chi-squares
Definition: Vertex.h:98
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:245
bool isValid() const
Definition: HandleBase.h:74
bool isNull() const
Checks for null.
Definition: Ref.h:250
double ndof() const
Definition: Vertex.h:105
const edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
T const * product() const
Definition: Handle.h:81
const edm::EDGetTokenT< reco::VertexCollection > vtxToken_
void writeValueMap(edm::Event &iEvent, const edm::Handle< edm::View< ParticleType > > &handle, const std::vector< T > &values, const std::string &label) const
const edm::EDGetTokenT< reco::ConversionCollection > conversionsToken_
const edm::EDGetTokenT< edm::View< ParticleType > > electronsToken_
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)
template<class ParticleType >
template<typename T >
void ElectronMVAVariableHelper< ParticleType >::writeValueMap ( edm::Event iEvent,
const edm::Handle< edm::View< ParticleType > > &  handle,
const std::vector< T > &  values,
const std::string &  label 
) const
private

Definition at line 167 of file ElectronMVAVariableHelper.h.

References objects.autophobj::filler, cmsBatch::handle, eostools::move(), and edm::Event::put().

Referenced by ElectronMVAVariableHelper< ParticleType >::produce().

171 {
172  auto valMap = std::make_unique<edm::ValueMap<T>>();
173  typename edm::ValueMap<T>::Filler filler(*valMap);
174  filler.insert(handle, values.begin(), values.end());
175  filler.fill();
176  iEvent.put(std::move(valMap), label);
177 }
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
def move(src, dest)
Definition: eostools.py:510

Member Data Documentation

template<class ParticleType >
const edm::EDGetTokenT<reco::BeamSpot> ElectronMVAVariableHelper< ParticleType >::beamSpotToken_
private
template<class ParticleType >
const edm::EDGetTokenT<reco::BeamSpot> ElectronMVAVariableHelper< ParticleType >::beamSpotTokenMiniAOD_
private
template<class ParticleType >
const edm::EDGetTokenT<reco::ConversionCollection> ElectronMVAVariableHelper< ParticleType >::conversionsToken_
private
template<class ParticleType >
const edm::EDGetTokenT<reco::ConversionCollection> ElectronMVAVariableHelper< ParticleType >::conversionsTokenMiniAOD_
private
template<class ParticleType >
const edm::EDGetTokenT<edm::View<ParticleType> > ElectronMVAVariableHelper< ParticleType >::electronsToken_
private
template<class ParticleType >
const edm::EDGetTokenT<edm::View<ParticleType> > ElectronMVAVariableHelper< ParticleType >::electronsTokenMiniAOD_
private
template<class ParticleType >
const edm::EDGetTokenT<reco::VertexCollection> ElectronMVAVariableHelper< ParticleType >::vtxToken_
private
template<class ParticleType >
const edm::EDGetTokenT<reco::VertexCollection> ElectronMVAVariableHelper< ParticleType >::vtxTokenMiniAOD_
private