Skip to content

Commit

Permalink
Merge pull request #25680 from bainbrid/LowPtElectrons_102X
Browse files Browse the repository at this point in the history
Low pT electrons (up to GsfTracks) for 10_2_X
  • Loading branch information
cmsbuild authored Jan 30, 2019
2 parents aef3d73 + 33334aa commit c02236e
Show file tree
Hide file tree
Showing 17 changed files with 1,217 additions and 145 deletions.
3 changes: 3 additions & 0 deletions Configuration/Eras/python/Modifier_bParking_cff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import FWCore.ParameterSet.Config as cms

bParking = cms.Modifier()
3 changes: 2 additions & 1 deletion Configuration/StandardSequences/python/Eras.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def __init__(self):
'tracker_apv_vfp30_2016', 'pf_badHcalMitigation', 'run2_miniAOD_80XLegacy','run2_miniAOD_94XFall17', 'run2_nanoAOD_92X',
'run2_nanoAOD_94XMiniAODv1', 'run2_nanoAOD_94XMiniAODv2', 'run2_nanoAOD_94X2016',
'run2_miniAOD_devel', 'run2_nanoAOD_102Xv1',
'hcalHardcodeConditions', 'hcalSkipPacker']
'hcalHardcodeConditions', 'hcalSkipPacker',
'bParking']
internalUseModChains = ['run2_2017_noTrackingModifier']


Expand Down
7 changes: 7 additions & 0 deletions Configuration/StandardSequences/python/Reconstruction_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@
cosmicDCTracksSeq
)

# Add low pT electrons for bParking era
from Configuration.Eras.Modifier_bParking_cff import bParking
from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSequence_cff import *
_highlevelreco_bParking = highlevelreco.copy()
_highlevelreco_bParking += lowPtGsfElectronSequence
bParking.toReplaceWith(highlevelreco, _highlevelreco_bParking)

# XeXe data with pp reco
from Configuration.Eras.Modifier_pp_on_XeXe_2017_cff import pp_on_XeXe_2017
from RecoHI.HiCentralityAlgos.HiCentrality_cfi import hiCentrality
Expand Down
180 changes: 83 additions & 97 deletions FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc
Original file line number Diff line number Diff line change
@@ -1,126 +1,112 @@
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "DataFormats/ParticleFlowReco/interface/PreId.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h"

#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"

#include "DataFormats/ParticleFlowReco/interface/PreId.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/EgammaReco/interface/ElectronSeed.h"
#include "DataFormats/Common/interface/ValueMap.h"
//
// class declaration
//



namespace {

template<typename VMType,typename HandleType>
const edm::OrphanHandle<edm::ValueMap<VMType> > addVMToEvent(edm::Event& event,const edm::Handle<HandleType>& handle,
std::vector<VMType> values,const std::string& label)
{
auto vMap = std::make_unique<edm::ValueMap<VMType> >();
typename edm::ValueMap<VMType>::Filler mapFiller(*vMap);
mapFiller.insert(handle,values.begin(),values.end());
mapFiller.fill();
return event.put(std::move(vMap),label);
}

template<typename T> edm::Handle<T> getHandle(const edm::Event& event,
const edm::EDGetTokenT<T>& token)
{
edm::Handle<T> handle;
event.getByToken(token,handle);
return handle;
}

//
// constructors and destructor
//

using namespace std;
using namespace reco;
using namespace edm;
}

ElectronSeedTrackRefFix::ElectronSeedTrackRefFix(const edm::ParameterSet& iConfig)
{

// read parameters
preidgsfLabel = iConfig.getParameter<string>("PreGsfLabel");
preidLabel= iConfig.getParameter<string>("PreIdLabel");
oldTracksTag = iConfig.getParameter<InputTag>("oldTrackCollection");
newTracksTag = iConfig.getParameter<InputTag>("newTrackCollection");
seedsTag = iConfig.getParameter<InputTag>("seedCollection");
idsTag = iConfig.getParameter<InputTag>("idCollection");
preidgsfLabel_ = iConfig.getParameter<std::string>("PreGsfLabel");
preidLabel_ = iConfig.getParameter<std::vector<std::string> >("PreIdLabel");
oldTracksTag_ = iConfig.getParameter<edm::InputTag>("oldTrackCollection");
newTracksTag_ = iConfig.getParameter<edm::InputTag>("newTrackCollection");
seedsTag_ = iConfig.getParameter<edm::InputTag>("seedCollection");
idsTag_ = iConfig.getParameter<std::vector<edm::InputTag>>("idCollection");

//register your products
produces<reco::ElectronSeedCollection>(preidgsfLabel);
produces<reco::PreIdCollection>(preidLabel);
produces<ValueMap<reco::PreIdRef> >(preidLabel);
produces<reco::ElectronSeedCollection>(preidgsfLabel_);
for(const auto& idLabel : preidLabel_){
produces<reco::PreIdCollection>(idLabel);
produces<edm::ValueMap<reco::PreIdRef> >(idLabel);
}

//create tokens
oldTracksToken = consumes<reco::TrackCollection>(oldTracksTag);
newTracksToken = consumes<reco::TrackCollection>(newTracksTag);
seedsToken = consumes<reco::ElectronSeedCollection>(seedsTag);
idsToken = consumes<reco::PreIdCollection >(idsTag);
idMapToken = consumes<ValueMap<reco::PreIdRef> >(idsTag) ;
}
oldTracksToken_ = consumes<reco::TrackCollection>(oldTracksTag_);
newTracksToken_ = consumes<reco::TrackCollection>(newTracksTag_);
seedsToken_ = consumes<reco::ElectronSeedCollection>(seedsTag_);
for(const auto& idTag: idsTag_){
idsToken_.emplace_back(consumes<reco::PreIdCollection >(idTag));
idMapToken_.emplace_back(consumes<edm::ValueMap<reco::PreIdRef> >(idTag));
}

}

ElectronSeedTrackRefFix::~ElectronSeedTrackRefFix()
{

// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)

// do anything here that needs to be done at desctruction time
// (e.g. close files, deallocate resources etc.)
}


//
// member functions
//

// ------------ method called to produce the data ------------
void
ElectronSeedTrackRefFix::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
void ElectronSeedTrackRefFix::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
{
using namespace edm;

Handle<TrackCollection> oldTracks;
iEvent.getByToken(oldTracksToken,oldTracks);

Handle<TrackCollection> newTracks;
iEvent.getByToken(newTracksToken,newTracks);

Handle<ElectronSeedCollection> iSeeds;
iEvent.getByToken(seedsToken,iSeeds);

Handle<PreIdCollection > iIds;
iEvent.getByToken(idsToken,iIds);

Handle<ValueMap<PreIdRef> > iIdMap;
iEvent.getByToken(idMapToken,iIdMap);

unique_ptr<ElectronSeedCollection> oSeeds(new ElectronSeedCollection);
unique_ptr<PreIdCollection> oIds(new PreIdCollection);
unique_ptr<ValueMap<PreIdRef> > oIdMap(new ValueMap<PreIdRef>);

ValueMap<PreIdRef>::Filler mapFiller(*oIdMap);

for(unsigned int s = 0;s<iSeeds->size();++s){
oSeeds->push_back(iSeeds->at(s));
TrackRef newTrackRef(newTracks,oSeeds->back().ctfTrack().index());
oSeeds->back().setCtfTrack(newTrackRef);
}

for(unsigned int i = 0;i<iIds->size();++i){
oIds->push_back(iIds->at(i));
TrackRef newTrackRef(newTracks,oIds->back().trackRef().index());
oIds->back().setTrack(newTrackRef);
}

iEvent.put(std::move(oSeeds),preidgsfLabel);
const edm::OrphanHandle<reco::PreIdCollection> preIdProd = iEvent.put(std::move(oIds),preidLabel);

vector<PreIdRef> values;
for(unsigned int t = 0;t<newTracks->size();++t){
if(t < oldTracks->size()){
TrackRef oldTrackRef(oldTracks,t);
values.push_back(PreIdRef(preIdProd,(*(iIdMap.product()))[oldTrackRef].index()));
}
else{
values.push_back(PreIdRef());
}
}
mapFiller.insert(newTracks,values.begin(),values.end());
mapFiller.fill();

auto oldTracks = getHandle(iEvent,oldTracksToken_);
auto newTracks = getHandle(iEvent,newTracksToken_);
auto iSeeds = getHandle(iEvent,seedsToken_);

auto oSeeds = std::make_unique<reco::ElectronSeedCollection>();
for(unsigned int s = 0;s<iSeeds->size();++s){
oSeeds->push_back(iSeeds->at(s));
reco::TrackRef newTrackRef(newTracks,oSeeds->back().ctfTrack().index());
oSeeds->back().setCtfTrack(newTrackRef);
}
iEvent.put(std::move(oSeeds),preidgsfLabel_);

for(size_t idNr = 0; idNr < idsTag_.size(); idNr++){
auto iIds = getHandle(iEvent,idsToken_[idNr]);
auto oIds = std::make_unique<reco::PreIdCollection>();
for(unsigned int i = 0;i<iIds->size();++i){
oIds->push_back(iIds->at(i));
reco::TrackRef newTrackRef(newTracks,oIds->back().trackRef().index());
oIds->back().setTrack(newTrackRef);
}
const edm::OrphanHandle<reco::PreIdCollection> preIdProd = iEvent.put(std::move(oIds),preidLabel_[idNr]);

auto iIdMap = getHandle(iEvent,idMapToken_[idNr]);
std::vector<reco::PreIdRef> values;
for(size_t trkNr = 0;trkNr<newTracks->size();++trkNr){
//low pt electron seeds do not make the idMaps so this is now optional to fill in a useful way
if(trkNr < oldTracks->size() && iIdMap.isValid()){
reco::TrackRef oldTrackRef(oldTracks,trkNr);
values.push_back(reco::PreIdRef(preIdProd,(*(iIdMap.product()))[oldTrackRef].index()));
}else values.push_back(reco::PreIdRef());
}
addVMToEvent(iEvent,newTracks,std::move(values),preidLabel_[idNr]);
}//end loop over ids

iEvent.put(std::move(oIdMap),preidLabel);
}

// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void
ElectronSeedTrackRefFix::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
void ElectronSeedTrackRefFix::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
//The following says we do not know what parameters are allowed so do no validation
// Please change this to state exactly what you do use, even if it is no parameters
edm::ParameterSetDescription desc;
Expand Down
51 changes: 24 additions & 27 deletions FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
// system include files
#ifndef FastSimulation_Tracking_ElectronSeedTrackRefFix_h
#define FastSimulation_Tracking_ElectronSeedTrackRefFix_h


#include <memory>

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
#include "DataFormats/ParticleFlowReco/interface/PreIdFwd.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"

#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "DataFormats/Common/interface/ValueMap.h"

#include <memory>

class ElectronSeedTrackRefFix : public edm::stream::EDProducer<> {
public:

public:

explicit ElectronSeedTrackRefFix(const edm::ParameterSet&);
~ElectronSeedTrackRefFix() override;

static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);

private:
private:

void produce(edm::Event&, const edm::EventSetup&) override;

// ----------member data ---------------------------
edm::EDGetTokenT<reco::TrackCollection > newTracksToken;
edm::EDGetTokenT<reco::TrackCollection > oldTracksToken;
edm::EDGetTokenT<reco::ElectronSeedCollection > seedsToken;
edm::EDGetTokenT<reco::PreIdCollection > idsToken;
edm::EDGetTokenT<edm::ValueMap<reco::PreIdRef> > idMapToken;

std::string preidgsfLabel;
std::string preidLabel;
edm::InputTag oldTracksTag;
edm::InputTag newTracksTag;
edm::InputTag seedsTag;
edm::InputTag idsTag;
// member data

edm::EDGetTokenT<reco::TrackCollection > newTracksToken_;
edm::EDGetTokenT<reco::TrackCollection > oldTracksToken_;
edm::EDGetTokenT<reco::ElectronSeedCollection > seedsToken_;
std::vector<edm::EDGetTokenT<reco::PreIdCollection > > idsToken_;
std::vector<edm::EDGetTokenT<edm::ValueMap<reco::PreIdRef> > > idMapToken_;
std::string preidgsfLabel_;
std::vector<std::string> preidLabel_;
edm::InputTag oldTracksTag_;
edm::InputTag newTracksTag_;
edm::InputTag seedsTag_;
std::vector<edm::InputTag> idsTag_;

};

#endif
#endif // FastSimulation_Tracking_ElectronSeedTrackRefFix_h
4 changes: 2 additions & 2 deletions FastSimulation/Tracking/python/ElectronSeedTrackRefFix_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
fixedTrackerDrivenElectronSeeds = cms.EDProducer(
"ElectronSeedTrackRefFix",
PreGsfLabel = cms.string("SeedsForGsf"),
PreIdLabel = cms.string("preid"),
PreIdLabel = cms.vstring("preid",),
oldTrackCollection = cms.InputTag("generalTracksBeforeMixing"),
newTrackCollection = cms.InputTag("generalTracks"),
seedCollection = cms.InputTag("trackerDrivenElectronSeeds","SeedsForGsf"),
idCollection = cms.InputTag("trackerDrivenElectronSeeds","preid")
idCollection = cms.VInputTag("trackerDrivenElectronSeeds:preid",)
)
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
'keep *_hfRecoEcalCandidate_*_*',
'keep *_hfEMClusters_*_*',
'keep *_gedGsfElectronCores_*_*',
'keep *_gedGsfElectrons_*_*'
'keep *_gedGsfElectrons_*_*',
'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*'
)
)

Expand Down Expand Up @@ -96,7 +97,8 @@
'keep recoRecoEcalCandidates_hfRecoEcalCandidate_*_*',
'keep *_hfEMClusters_*_*',
'keep *_gedGsfElectronCores_*_*',
'keep *_gedGsfElectrons_*_*'
'keep *_gedGsfElectrons_*_*',
'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*'
)
)

Expand Down Expand Up @@ -141,7 +143,8 @@
'keep recoRecoEcalCandidates_hfRecoEcalCandidate_*_*',
'keep *_hfEMClusters_*_*',
'keep *_gedGsfElectronCores_*_*',
'keep *_gedGsfElectrons_*_*'
'keep *_gedGsfElectrons_*_*',
'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*'
)
)

Expand Down
10 changes: 10 additions & 0 deletions RecoEgamma/EgammaElectronProducers/BuildFile.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<use name="CondFormats/EgammaObjects"/>
<use name="DataFormats/BeamSpot"/>
<use name="DataFormats/ParticleFlowReco"/>
<use name="DataFormats/TrackReco"/>
<use name="FWCore/ParameterSet"/>
<use name="RecoEcal/EgammaCoreTools"/>
<use name="RecoEgamma/EgammaTools"/>
<export>
<lib name="RecoEgammaEgammaElectronProducers"/>
</export>
Loading

0 comments on commit c02236e

Please sign in to comment.