Skip to content

Commit

Permalink
store Seed BDT outputs in ValueMaps keyed by GsfTrackRef instead of G…
Browse files Browse the repository at this point in the history
…sfElectronRef
  • Loading branch information
bainbrid committed Feb 12, 2019
1 parent c52e281 commit 36d2189
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronCore.h"
#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrackExtra.h"
#include "DataFormats/ParticleFlowReco/interface/PreId.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/InputTag.h"
Expand All @@ -14,7 +13,7 @@
////////////////////////////////////////////////////////////////////////////////
//
LowPtGsfElectronSeedValueMapsProducer::LowPtGsfElectronSeedValueMapsProducer( const edm::ParameterSet& conf ) :
gsfElectrons_(consumes<reco::GsfElectronCollection>(conf.getParameter<edm::InputTag>("electrons"))),
gsfTracks_(consumes<reco::GsfTrackCollection>(conf.getParameter<edm::InputTag>("gsfTracks"))),
preIdsValueMap_(consumes< edm::ValueMap<reco::PreIdRef> >(conf.getParameter<edm::InputTag>("preIdsValueMap"))),
names_(conf.getParameter< std::vector<std::string> >("ModelNames"))
{
Expand All @@ -29,33 +28,32 @@ LowPtGsfElectronSeedValueMapsProducer::~LowPtGsfElectronSeedValueMapsProducer()
//
void LowPtGsfElectronSeedValueMapsProducer::produce( edm::Event& event, const edm::EventSetup& setup ) {

// Retrieve GsfElectrons from Event
edm::Handle<reco::GsfElectronCollection> gsfElectrons;
event.getByToken(gsfElectrons_,gsfElectrons);
if ( !gsfElectrons.isValid() ) { edm::LogError("Problem with gsfElectrons handle"); }
// Retrieve GsfTracks from Event
edm::Handle<reco::GsfTrackCollection> gsfTracks;
event.getByToken(gsfTracks_,gsfTracks);
if ( !gsfTracks.isValid() ) { edm::LogError("Problem with gsfTracks handle"); }

// Retrieve PreIds from Event
edm::Handle< edm::ValueMap<reco::PreIdRef> > preIdsValueMap;
event.getByToken(preIdsValueMap_,preIdsValueMap);
if ( !preIdsValueMap.isValid() ) { edm::LogError("Problem with preIdsValueMap handle"); }

// Iterate through Electrons, extract BDT output, and store result in ValueMap for each model
// Iterate through GsfTracks, extract BDT output, and store result in ValueMap for each model
std::vector< std::vector<float> > output;
for ( unsigned int iname = 0; iname < names_.size(); ++iname ) {
output.push_back( std::vector<float>(gsfElectrons->size(),-999.) );
output.push_back( std::vector<float>(gsfTracks->size(),-999.) );
}
for ( unsigned int iele = 0; iele < gsfElectrons->size(); iele++ ) {
reco::GsfElectronRef ele(gsfElectrons,iele);
if ( ele->core().isNonnull() &&
ele->core()->gsfTrack().isNonnull() &&
ele->core()->gsfTrack()->extra().isNonnull() &&
ele->core()->gsfTrack()->extra()->seedRef().isNonnull() ) {
reco::ElectronSeedRef seed = ele->core()->gsfTrack()->extra()->seedRef().castTo<reco::ElectronSeedRef>();
for ( unsigned int igsf = 0; igsf < gsfTracks->size(); igsf++ ) {
reco::GsfTrackRef gsf(gsfTracks,igsf);
if ( gsf.isNonnull() &&
gsf->extra().isNonnull() &&
gsf->extra()->seedRef().isNonnull() ) {
reco::ElectronSeedRef seed = gsf->extra()->seedRef().castTo<reco::ElectronSeedRef>();
if ( seed.isNonnull() && seed->ctfTrack().isNonnull() ) {
const reco::PreIdRef preid = (*preIdsValueMap)[seed->ctfTrack()];
if ( preid.isNonnull() ) {
for ( unsigned int iname = 0; iname < names_.size(); ++iname ) {
output[iname][iele] = preid->mva(iname);
output[iname][igsf] = preid->mva(iname);
}
}
}
Expand All @@ -66,7 +64,7 @@ void LowPtGsfElectronSeedValueMapsProducer::produce( edm::Event& event, const ed
for ( unsigned int iname = 0; iname < names_.size(); ++iname ) {
auto ptr = std::make_unique< edm::ValueMap<float> >( edm::ValueMap<float>() );
edm::ValueMap<float>::Filler filler(*ptr);
filler.insert(gsfElectrons, output[iname].begin(), output[iname].end());
filler.insert(gsfTracks, output[iname].begin(), output[iname].end());
filler.fill();
event.put(std::move(ptr),names_[iname]);
}
Expand All @@ -78,9 +76,9 @@ void LowPtGsfElectronSeedValueMapsProducer::produce( edm::Event& event, const ed
void LowPtGsfElectronSeedValueMapsProducer::fillDescriptions( edm::ConfigurationDescriptions& descriptions )
{
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("electrons",edm::InputTag("lowPtGsfElectrons"));
desc.add<edm::InputTag>("gsfTracks",edm::InputTag("lowPtGsfEleGsfTracks"));
desc.add<edm::InputTag>("preIdsValueMap",edm::InputTag("lowPtGsfElectronSeeds"));
desc.add< std::vector<std::string> >("ModelNames",std::vector<std::string>({"default"}));
desc.add< std::vector<std::string> >("ModelNames",std::vector<std::string>());
descriptions.add("defaultLowPtGsfElectronSeedValueMaps",desc);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedValueMapsProducer_h

#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
#include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
#include "DataFormats/ParticleFlowReco/interface/PreIdFwd.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
Expand All @@ -24,11 +24,10 @@ class LowPtGsfElectronSeedValueMapsProducer : public edm::stream::EDProducer<> {

private:

const edm::EDGetTokenT<reco::GsfElectronCollection> gsfElectrons_;
const edm::EDGetTokenT<reco::GsfTrackCollection> gsfTracks_;
const edm::EDGetTokenT< edm::ValueMap<reco::PreIdRef> > preIdsValueMap_;
const std::vector<std::string> names_;

};

#endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedValueMapsProducer_h

0 comments on commit 36d2189

Please sign in to comment.