From ab2a29247f95e2c33f9eaa6eef6fb0b3924bc80f Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Fri, 7 Dec 2018 18:07:37 +0100 Subject: [PATCH 01/22] GsfTracks using LowPtGsfElectronSeedProducer moved low pT ele sequence into highlevelreco --- .../python/Reconstruction_cff.py | 6 +- .../python/RecoEgamma_EventContent_cff.py | 6 +- .../EgammaElectronProducers/BuildFile.xml | 11 + .../LowPtGsfElectronSeedHeavyObjectCache.h | 77 +++ .../plugins/BuildFile.xml | 48 +- .../plugins/LowPtGsfElectronSeedProducer.cc | 529 ++++++++++++++++++ .../plugins/LowPtGsfElectronSeedProducer.h | 131 +++++ .../plugins/SealModule.cc | 3 + .../python/lowPtGsfElectronSeeds_cfi.py | 32 ++ .../python/lowPtGsfElectronSequence_cff.py | 48 ++ .../LowPtGsfElectronSeedHeavyObjectCache.cc | 170 ++++++ 11 files changed, 1044 insertions(+), 17 deletions(-) create mode 100644 RecoEgamma/EgammaElectronProducers/BuildFile.xml create mode 100644 RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h create mode 100644 RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc create mode 100644 RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h create mode 100644 RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py create mode 100644 RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py create mode 100644 RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc diff --git a/Configuration/StandardSequences/python/Reconstruction_cff.py b/Configuration/StandardSequences/python/Reconstruction_cff.py index 1440a5910a589..118c92c6d659a 100644 --- a/Configuration/StandardSequences/python/Reconstruction_cff.py +++ b/Configuration/StandardSequences/python/Reconstruction_cff.py @@ -51,6 +51,9 @@ # Cosmic During Collisions from RecoTracker.SpecialSeedGenerators.cosmicDC_cff import * +# Low pT electrons +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSequence_cff import * + localreco = cms.Sequence(bunchSpacingProducer+trackerlocalreco+muonlocalreco+calolocalreco+castorreco) localreco_HcalNZS = cms.Sequence(bunchSpacingProducer+trackerlocalreco+muonlocalreco+calolocalrecoNZS+castorreco) @@ -153,7 +156,8 @@ recoPFMET* PFTau* reducedRecHits* - cosmicDCTracksSeq + cosmicDCTracksSeq* + lowPtGsfElectronSequence ) # AA data with pp reco diff --git a/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py b/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py index 7e151abce88d0..e90dc82b3f7b1 100644 --- a/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py +++ b/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py @@ -96,7 +96,8 @@ 'keep recoRecoEcalCandidates_hfRecoEcalCandidate_*_*', 'keep *_hfEMClusters_*_*', 'keep *_gedGsfElectronCores_*_*', - 'keep *_gedGsfElectrons_*_*' + 'keep *_gedGsfElectrons_*_*', + 'keep *_lowPtGsfEle*_*_*', ) ) @@ -141,7 +142,8 @@ 'keep recoRecoEcalCandidates_hfRecoEcalCandidate_*_*', 'keep *_hfEMClusters_*_*', 'keep *_gedGsfElectronCores_*_*', - 'keep *_gedGsfElectrons_*_*' + 'keep *_gedGsfElectrons_*_*', + 'keep *_lowPtGsfEle*_*_*', ) ) diff --git a/RecoEgamma/EgammaElectronProducers/BuildFile.xml b/RecoEgamma/EgammaElectronProducers/BuildFile.xml new file mode 100644 index 0000000000000..8db45701f959b --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/BuildFile.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h new file mode 100644 index 0000000000000..50ff60bd62562 --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h @@ -0,0 +1,77 @@ +#ifndef RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedHeavyObjectCache_h +#define RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedHeavyObjectCache_h + +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "CondFormats/EgammaObjects/interface/GBRForest.h" +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" +#include +#include + +namespace reco { + class BeamSpot; + class PreId; +} + +namespace lowptgsfeleseed { + + class Features { + public: + float trk_pt_ = -1.; + float trk_eta_ = -1.; + float trk_phi_ = -1.; + float trk_p_ = -1.; + float trk_nhits_ = -1.; + float trk_high_quality_ = -1.; + float trk_chi2red_ = -1.; + float rho_ = -1.; + float ktf_ecal_cluster_e_ = -1.; + float ktf_ecal_cluster_deta_ = -1.; + float ktf_ecal_cluster_dphi_ = -1.; + float ktf_ecal_cluster_e3x3_ = -1.; + float ktf_ecal_cluster_e5x5_ = -1.; + float ktf_ecal_cluster_covEtaEta_ = -1.; + float ktf_ecal_cluster_covEtaPhi_ = -1.; + float ktf_ecal_cluster_covPhiPhi_ = -1.; + float ktf_ecal_cluster_r9_ = -1.; + float ktf_ecal_cluster_circularity_ = -1.; + float ktf_hcal_cluster_e_ = -1.; + float ktf_hcal_cluster_deta_ = -1.; + float ktf_hcal_cluster_dphi_ = -1.; + float preid_gsf_dpt_ = -1.; + float preid_trk_gsf_chiratio_ = -1.; + float preid_gsf_chi2red_ = -1.; + float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model) + public: + std::vector get(); + void set( reco::PreId& ecal, + reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools ); + }; + + class HeavyObjectCache { + + public: + + HeavyObjectCache( const edm::ParameterSet& ); + + std::vector modelNames() const { return names_; } + + bool eval( std::string name, + reco::PreId& ecal, + reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools ) const; + + private: + + std::vector names_; + std::vector< std::unique_ptr > models_; + std::vector thresholds_; + + }; +} + +#endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedHeavyObjectCache_h diff --git a/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml b/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml index c0d6396b69cc4..8c9d03d30859c 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml +++ b/RecoEgamma/EgammaElectronProducers/plugins/BuildFile.xml @@ -1,23 +1,43 @@ - - - - - - - - - - - - + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc new file mode 100644 index 0000000000000..849f662c471cb --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -0,0 +1,529 @@ +// -*- C++ -*- +// +// Package: ElectronProducers +// Class: LowPtGsfElectronSeedProducer +// +/**\class LowPtGsfElectronSeedProducer RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc + Description: EDProducer of ElectronSeed objects + Implementation: + +*/ +// Original Author: Robert Bainbridge + +#include "DataFormats/GeometryVector/interface/GlobalPoint.h" +#include "DataFormats/GeometryVector/interface/GlobalVector.h" +#include "DataFormats/Math/interface/deltaPhi.h" +#include "DataFormats/Math/interface/deltaR.h" +#include "DataFormats/Math/interface/LorentzVector.h" +#include "DataFormats/ParticleFlowReco/interface/PFTrajectoryPoint.h" +#include "DataFormats/TrackReco/interface/TrackBase.h" +#include "FastSimulation/BaseParticlePropagator/interface/BaseParticlePropagator.h" +#include "FastSimulation/Particle/interface/RawParticle.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Utilities/interface/InputTag.h" +#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" +#include "RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h" +#include "RecoTracker/TransientTrackingRecHit/interface/TkClonerImpl.h" +#include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h" +#include "TrackingTools/PatternTools/interface/Trajectory.h" +#include "TrackingTools/PatternTools/interface/TrajectorySmoother.h" +#include "TrackingTools/Records/interface/TransientRecHitRecord.h" +#include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h" +#include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h" +#include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h" +#include "TMath.h" + +////////////////////////////////////////////////////////////////////////////////////////// +// +LowPtGsfElectronSeedProducer::LowPtGsfElectronSeedProducer( const edm::ParameterSet& conf, + const lowptgsfeleseed::HeavyObjectCache* ) : + kfTracks_{consumes(conf.getParameter("tracks"))}, + pfTracks_{consumes(conf.getParameter("pfTracks"))}, + ecalClusters_{consumes(conf.getParameter("ecalClusters"))}, + hcalClusters_{consumes(conf.getParameter("hcalClusters"))}, + ebRecHits_{consumes(conf.getParameter("EBRecHits"))}, + eeRecHits_{consumes(conf.getParameter("EERecHits"))}, + rho_(consumes(conf.getParameter("rho"))), + beamSpot_(consumes(conf.getParameter("BeamSpot"))), + fitter_(conf.getParameter("Fitter")), + smoother_(conf.getParameter("Smoother")), + builder_(conf.getParameter("TTRHBuilder")), + passThrough_(conf.getParameter("PassThrough")), + usePfTracks_(conf.getParameter("UsePfTracks")), + minPtThreshold_(conf.getParameter("MinPtThreshold")), + maxPtThreshold_(conf.getParameter("MaxPtThreshold")) +{ + produces(); + produces(); + produces("HCAL"); +} + +////////////////////////////////////////////////////////////////////////////////////////// +// +LowPtGsfElectronSeedProducer::~LowPtGsfElectronSeedProducer() {} + +////////////////////////////////////////////////////////////////////////////////////////// +// +void LowPtGsfElectronSeedProducer::beginLuminosityBlock( edm::LuminosityBlock const&, + edm::EventSetup const& setup ) +{ + setup.get().get(field_); +} + +////////////////////////////////////////////////////////////////////////////////////////// +// +void LowPtGsfElectronSeedProducer::produce( edm::Event& event, + const edm::EventSetup& setup ) +{ + + // Products + auto seeds = std::make_unique(); + auto ecalPreIds = std::make_unique(); + auto hcalPreIds = std::make_unique(); + + // KF tracks + edm::Handle kfTracks; + event.getByToken(kfTracks_, kfTracks); + + // PF tracks + edm::Handle pfTracks; + event.getByToken(pfTracks_, pfTracks); + + // ECAL clusters + edm::Handle ecalClusters; + event.getByToken(ecalClusters_,ecalClusters); + + // HCAL clusters (only used with PF tracks) + edm::Handle hcalClusters; + event.getByToken(hcalClusters_,hcalClusters); + + if ( usePfTracks_ ) { + loop(pfTracks, // PF tracks + ecalClusters, + hcalClusters, + *seeds, + *ecalPreIds, + *hcalPreIds, + event, + setup); + } else { + loop(kfTracks, // KF tracks + ecalClusters, + hcalClusters, + *seeds, + *ecalPreIds, + *hcalPreIds, + event, + setup); + } + + event.put(std::move(seeds)); + event.put(std::move(ecalPreIds)); + event.put(std::move(hcalPreIds),"HCAL"); + +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Return reco::Track from edm::Ref + +reco::TrackRef LowPtGsfElectronSeedProducer::getBaseRef( edm::Handle< std::vector > handle, int idx ) const +{ + return reco::TrackRef(handle,idx); +} + +reco::TrackRef LowPtGsfElectronSeedProducer::getBaseRef( edm::Handle< std::vector > handle, int idx ) const +{ + return reco::PFRecTrackRef(handle,idx)->trackRef(); +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Template function, instantiated for both reco::Tracks and reco::PFRecTracks +template +void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >& handle, // PF or KF tracks + edm::Handle& ecalClusters, + edm::Handle& hcalClusters, + reco::ElectronSeedCollection& seeds, + reco::PreIdCollection& ecalPreIds, + reco::PreIdCollection& hcalPreIds, + edm::Event& event, + const edm::EventSetup& setup ) +{ + + // Pileup + edm::Handle rho; + event.getByToken(rho_,rho); + + // Beam spot + edm::Handle spot; + event.getByToken(beamSpot_,spot); + + // Utility to access to shower shape vars + noZS::EcalClusterLazyTools ecalTools(event,setup,ebRecHits_,eeRecHits_); + + // Ensure each cluster is only matched once to a track + std::vector matchedEcalClusters; + std::vector matchedHcalClusters; + + // Iterate through (PF or KF) tracks + for ( unsigned int itrk = 0; itrk < handle.product()->size(); itrk++ ) { + + edm::Ref< std::vector > templatedRef(handle,itrk); // TrackRef or PFRecTrackRef + reco::TrackRef trackRef = getBaseRef(handle,itrk); + + if ( !(trackRef->quality(reco::TrackBase::qualityByName("highPurity"))) ) { continue; } + if ( !passThrough_ && ( trackRef->pt() < minPtThreshold_ ) ) { continue; } + + // Create ElectronSeed + reco::ElectronSeed seed( *(trackRef->seedRef()) ); + seed.setCtfTrack(trackRef); + + // Create PreIds + unsigned int nModels = globalCache()->modelNames().size(); + reco::PreId ecalPreId(nModels); + reco::PreId hcalPreId(nModels); + + // Add track ref to PreId + ecalPreId.setTrack(trackRef); + hcalPreId.setTrack(trackRef); + + // Add Track-Calo matching variables to PreIds + propagateTrackToCalo(templatedRef, + ecalClusters, + hcalClusters, + matchedEcalClusters, + matchedHcalClusters, + ecalPreId, + hcalPreId ); + + // Add variables related to GSF tracks to PreId + lightGsfTracking(ecalPreId,trackRef,seed,setup); + + // Decision based on BDT + bool result = decision(templatedRef,ecalPreId,hcalPreId,*rho,*spot,ecalTools); + + // If fails BDT, do not store seed + if ( !result ) { continue; } + + // Store PreId + ecalPreIds.push_back(ecalPreId); + hcalPreIds.push_back(hcalPreId); + + // Store ElectronSeed + seeds.push_back(seed); + + } + +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Template instantiation for reco::Tracks +template +void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >&, + edm::Handle& ecalClusters, + edm::Handle& hcalClusters, + reco::ElectronSeedCollection& seeds, + reco::PreIdCollection& ecalPreIds, + reco::PreIdCollection& hcalPreIds, + edm::Event&, + const edm::EventSetup& ); + +////////////////////////////////////////////////////////////////////////////////////////// +// Template instantiation for reco::PFRecTracks +template +void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >&, + edm::Handle& ecalClusters, + edm::Handle& hcalClusters, + reco::ElectronSeedCollection& seeds, + reco::PreIdCollection& ecalPreIds, + reco::PreIdCollection& hcalPreIds, + edm::Event&, + const edm::EventSetup& ); + +////////////////////////////////////////////////////////////////////////////////////////// +// Loops through both ECAL and HCAL clusters +void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::PFRecTrackRef& pfTrackRef, + const edm::Handle& ecalClusters, + const edm::Handle& hcalClusters, + std::vector& matchedEcalClusters, + std::vector& matchedHcalClusters, + reco::PreId& ecalPreId, + reco::PreId& hcalPreId ) +{ + propagateTrackToCalo( pfTrackRef, ecalClusters, matchedEcalClusters, ecalPreId, true ); + propagateTrackToCalo( pfTrackRef, hcalClusters, matchedHcalClusters, hcalPreId, false ); +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Loops through ECAL or HCAL clusters (called twice) +void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::PFRecTrackRef& pfTrackRef, + const edm::Handle& clusters, + std::vector& matched, + reco::PreId& preId, + bool ecal ) +{ + + // Store info for PreId + struct Info { + reco::PFClusterRef cluRef = reco::PFClusterRef(); + float dr2min = 1.e6; + float deta = 1.e6; + float dphi = 1.e6; + math::XYZPoint showerPos = math::XYZPoint(0.,0.,0.); + } info; + + // Find closest "seed cluster" to KF track extrapolated to ECAL (or HCAL) + reco::PFTrajectoryPoint point; + if ( ecal ) { point = pfTrackRef->extrapolatedPoint(reco::PFTrajectoryPoint::LayerType::ECALShowerMax); } + else { point = pfTrackRef->extrapolatedPoint(reco::PFTrajectoryPoint::LayerType::HCALEntrance); } + + if ( point.isValid() ) { + + Info info; + for ( unsigned int iclu = 0; iclu < clusters.product()->size(); iclu++ ) { + + if ( std::find( matched.begin(), matched.end(), iclu ) == matched.end() ) { + reco::PFClusterRef cluRef(clusters,iclu); + + // Determine deta, dphi, dr + float deta = cluRef->positionREP().eta() - point.positionREP().eta(); + float dphi = reco::deltaPhi( cluRef->positionREP().phi(), point.positionREP().phi() ); + float dr2 = reco::deltaR2( cluRef->positionREP(), point.positionREP() ); + + if ( dr2 < info.dr2min ) { + info.dr2min = dr2; + info.cluRef = cluRef; + info.deta = deta; + info.dphi = dphi; + info.showerPos = point.position(); + } + + } + } + + // Set PreId content if match found + if ( info.dr2min < 1.e5 ) { + float ep = info.cluRef->correctedEnergy() / std::sqrt( pfTrackRef->trackRef()->innerMomentum().mag2() ); + preId.setECALMatchingProperties( info.cluRef, + point.position(), // ECAL or HCAL surface + info.showerPos, // + info.deta, + info.dphi, + 0.f, // chieta + 0.f, // chiphi + pfTrackRef->trackRef()->normalizedChi2(), // chi2 + ep ); + } + + } // clusters + +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Original implementation in GoodSeedProducer, loops over ECAL clusters only +void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::TrackRef& kfTrackRef, + const edm::Handle& ecalClusters, + const edm::Handle& hcalClusters, // not used + std::vector& matchedEcalClusters, + std::vector& matchedHcalClusters, // not used + reco::PreId& ecalPreId, + reco::PreId& hcalPreId /* not used */ ) +{ + + // Store info for PreId + struct Info { + reco::PFClusterRef cluRef = reco::PFClusterRef(); + float dr2min = 1.e6; + float deta = 1.e6; + float dphi = 1.e6; + math::XYZPoint showerPos = math::XYZPoint(0.,0.,0.); + } info; + + // Propagate 'electron' to ECAL surface + float energy = sqrt( pow(0.000511,2.) + kfTrackRef->outerMomentum().Mag2() ); + XYZTLorentzVector mom = XYZTLorentzVector( kfTrackRef->outerMomentum().x(), + kfTrackRef->outerMomentum().y(), + kfTrackRef->outerMomentum().z(), + energy ); + XYZTLorentzVector pos = XYZTLorentzVector( kfTrackRef->outerPosition().x(), + kfTrackRef->outerPosition().y(), + kfTrackRef->outerPosition().z(), + 0. ); + math::XYZVector field(field_->inTesla(GlobalPoint(0,0,0))); + BaseParticlePropagator particle( RawParticle(mom,pos), 0, 0, field.z() ); + particle.setCharge(kfTrackRef->charge()); + particle.propagateToEcalEntrance(false); + if ( particle.getSuccess() == 0 ) { return; } + + // ECAL entry point for track + GlobalPoint ecal_pos(particle.vertex().x(), + particle.vertex().y(), + particle.vertex().z()); + // Preshower limit + bool below_ps = pow(ecal_pos.z(),2.) > pow(2.50746495928f,2.)*ecal_pos.perp2(); + + // Iterate through ECAL clusters + for ( unsigned int iclu = 0; iclu < ecalClusters.product()->size(); iclu++ ) { + reco::PFClusterRef cluRef(ecalClusters,iclu); + + // Correct ecal_pos for shower depth + double shower_depth = reco::PFCluster::getDepthCorrection(cluRef->correctedEnergy(), + below_ps, + false); + GlobalPoint showerPos = ecal_pos + + GlobalVector(particle.momentum().x(), + particle.momentum().y(), + particle.momentum().z()).unit() * shower_depth; + + // Determine deta, dphi, dr + float deta = std::abs( cluRef->positionREP().eta() - showerPos.eta() ); + float dphi = std::abs( reco::deltaPhi( cluRef->positionREP().phi(), showerPos.phi() )); + float dr2 = reco::deltaR2( cluRef->positionREP(), showerPos ); + + // Find nearest ECAL cluster + if ( dr2 < info.dr2min ) { + info.dr2min = dr2; + info.cluRef = cluRef; + info.deta = deta; + info.dphi = dphi; + info.showerPos = showerPos; + } + + } + + // Populate PreId object + math::XYZPoint point( ecal_pos.x(), + ecal_pos.y(), + ecal_pos.z() ); + + // Set PreId content + ecalPreId.setECALMatchingProperties( info.cluRef, + point, + info.showerPos, + info.deta, + info.dphi, + 0.f, // chieta + 0.f, // chiphi + kfTrackRef->normalizedChi2(), // chi2 + info.cluRef->correctedEnergy() / std::sqrt( kfTrackRef->innerMomentum().mag2() ) ); // E/p + +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Original implementation for "lightweight" GSF tracking +bool LowPtGsfElectronSeedProducer::lightGsfTracking( reco::PreId& preId, + const reco::TrackRef& trackRef, + const reco::ElectronSeed& seed, + const edm::EventSetup& setup ) +{ + + edm::ESHandle fitter; + setup.get().get(fitter_,fitter); + std::unique_ptr fitterPtr = fitter->clone(); + + edm::ESHandle smoother; + setup.get().get(smoother_,smoother); + std::unique_ptr smootherPtr; + smootherPtr.reset(smoother->clone()); + + edm::ESHandle builder; + setup.get().get(builder_,builder); + TkClonerImpl hitCloner = static_cast(builder.product())->cloner(); + fitterPtr->setHitCloner(&hitCloner); + smootherPtr->setHitCloner(&hitCloner); + + Trajectory::ConstRecHitContainer hits; + for ( unsigned int ihit = 0; ihit < trackRef->recHitsSize(); ++ihit ) { + hits.push_back( trackRef->recHit(ihit)->cloneSH() ); + } + + GlobalVector gv( trackRef->innerMomentum().x(), + trackRef->innerMomentum().y(), + trackRef->innerMomentum().z() ); + GlobalPoint gp( trackRef->innerPosition().x(), + trackRef->innerPosition().y(), + trackRef->innerPosition().z() ); + + GlobalTrajectoryParameters gtps( gp, + gv, + trackRef->charge(), + &*field_ ); + + TrajectoryStateOnSurface tsos( gtps, + trackRef->innerStateCovariance(), + *hits[0]->surface() ); + + // Track fitted and smoothed under electron hypothesis + Trajectory traj1 = fitterPtr->fitOne( seed, hits, tsos ); + if ( !traj1.isValid() ) { return false; } + Trajectory traj2 = smootherPtr->trajectory(traj1); + if ( !traj2.isValid() ) { return false; } + + // Set PreId content + float chi2Ratio = traj2.chiSquared() / trackRef->chi2(); + float gsfReducedChi2 = chi2Ratio * trackRef->normalizedChi2(); + float ptOut = traj2.firstMeasurement().updatedState().globalMomentum().perp(); + float ptIn = traj2.lastMeasurement().updatedState().globalMomentum().perp(); + float gsfDpt = ( ptIn > 0 ) ? fabs( ptOut - ptIn ) / ptIn : 0.; + preId.setTrackProperties(gsfReducedChi2,chi2Ratio,gsfDpt); + + return true; + +} + +////////////////////////////////////////////////////////////////////////////////////////// +// Decision based on OR of outputs from list of models +bool LowPtGsfElectronSeedProducer::decision( const reco::PFRecTrackRef& pfTrackRef, + reco::PreId& ecalPreId, + reco::PreId& hcalPreId, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools ) +{ + bool result = false; + for ( auto& name: globalCache()->modelNames() ) { + result |= globalCache()->eval(name, + ecalPreId, + hcalPreId, + rho, + spot, + ecalTools); + } + return passThrough_ || ( pfTrackRef->trackRef()->pt() > maxPtThreshold_ ) || result; +} + +////////////////////////////////////////////////////////////////////////////////////////// +// +bool LowPtGsfElectronSeedProducer::decision( const reco::TrackRef& kfTrackRef, + reco::PreId& ecalPreId, + reco::PreId& hcalPreId, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools ) +{ + // No implementation currently + return passThrough_; +} + +////////////////////////////////////////////////////////////////////////////////////////// +// +void LowPtGsfElectronSeedProducer::fillDescription( edm::ParameterSetDescription& desc ) +{ + desc.add("tracks",edm::InputTag("generalTracks")); + desc.add("pfTracks",edm::InputTag("lowPtGsfElePfTracks")); + desc.add("ecalClusters",edm::InputTag("particleFlowClusterECAL")); + desc.add("hcalClusters",edm::InputTag("particleFlowClusterHCAL")); + desc.add("EBRecHits",edm::InputTag("reducedEcalRecHitsEB")); + desc.add("EERecHits",edm::InputTag("reducedEcalRecHitsEE")); + desc.add("rho",edm::InputTag("fixedGridRhoFastjetAllTmp")); + desc.add("BeamSpot",edm::InputTag("offlineBeamSpot")); + desc.add("Fitter","GsfTrajectoryFitter_forPreId"); + desc.add("Smoother","GsfTrajectorySmoother_forPreId"); + desc.add("TTRHBuilder","WithAngleAndTemplate"); + desc.add< std::vector >("ModelNames",std::vector()); + desc.add< std::vector >("ModelWeights",std::vector()); + desc.add< std::vector >("ModelThrsholds",std::vector()); + desc.add("PassThrough",false); + desc.add("UsePfTracks",false); + desc.add("MinPtThreshold",0.5); + desc.add("MaxPtThreshold",15.); +} diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h new file mode 100644 index 0000000000000..54cdae76d3f2a --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h @@ -0,0 +1,131 @@ +#ifndef RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedProducer_h +#define RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedProducer_h + +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/Common/interface/Handle.h" +#include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h" +#include "DataFormats/EgammaReco/interface/ElectronSeed.h" +#include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecTrack.h" +#include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h" +#include "DataFormats/ParticleFlowReco/interface/PreId.h" +#include "DataFormats/ParticleFlowReco/interface/PreIdFwd.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/stream/EDProducer.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "MagneticField/Engine/interface/MagneticField.h" +#include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" +#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h" + +class LowPtGsfElectronSeedProducer final : public edm::stream::EDProducer< edm::GlobalCache > +{ + + public: + + explicit LowPtGsfElectronSeedProducer( const edm::ParameterSet&, + const lowptgsfeleseed::HeavyObjectCache* ); + + ~LowPtGsfElectronSeedProducer() override; + + static std::unique_ptr + initializeGlobalCache( const edm::ParameterSet& conf ) { + return std::make_unique(lowptgsfeleseed::HeavyObjectCache(conf)); + } + + static void globalEndJob( lowptgsfeleseed::HeavyObjectCache const* ) {} + + void beginLuminosityBlock( edm::LuminosityBlock const&, + edm::EventSetup const& ) override; + + void produce( edm::Event&, const edm::EventSetup& ) override; + + static void fillDescription( edm::ParameterSetDescription& ); + + private: // member functions + + template void loop( const edm::Handle< std::vector >& handle, + edm::Handle& ecalClusters, + edm::Handle& hcalClusters, + reco::ElectronSeedCollection& seeds, + reco::PreIdCollection& ecalPreIds, + reco::PreIdCollection& hcalPreIds, + edm::Event&, + const edm::EventSetup& ); + + // Overloaded methods to retrieve reco::TrackRef + + reco::TrackRef getBaseRef( edm::Handle< std::vector > handle, int idx ) const; + reco::TrackRef getBaseRef( edm::Handle< std::vector > handle, int idx ) const; + + // Overloaded methods to populate PreIds (using PF or KF tracks) + + void propagateTrackToCalo( const reco::PFRecTrackRef& pfTrackRef, + const edm::Handle& ecalClusters, + const edm::Handle& hcalClusters, + std::vector& matchedEcalClusters, + std::vector& matchedHcalClusters, + reco::PreId& ecalPreId, + reco::PreId& hcalPreId ); + + void propagateTrackToCalo( const reco::PFRecTrackRef& pfTrackRef, + const edm::Handle& clusters, + std::vector& matchedClusters, + reco::PreId& preId, + bool ecal ); + + void propagateTrackToCalo( const reco::TrackRef& pfTrack, + const edm::Handle& ecalClusters, + const edm::Handle& hcalClusters, + std::vector& matchedEcalClusters, + std::vector& matchedHcalClusters, + reco::PreId& ecalPreId, + reco::PreId& hcalPreId ); + + // Overloaded methods to evaluate BDTs (using PF or KF tracks) + + bool decision( const reco::PFRecTrackRef& pfTrackRef, + reco::PreId& ecal, + reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools ); + + bool decision( const reco::TrackRef& kfTrackRef, + reco::PreId& ecal, + reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools ); + + // Perform lightweight GSF tracking + bool lightGsfTracking( reco::PreId&, + const reco::TrackRef&, + const reco::ElectronSeed&, + const edm::EventSetup& ); + + private: // member data + + edm::ESHandle field_; + const edm::EDGetTokenT kfTracks_; + const edm::EDGetTokenT pfTracks_; + const edm::EDGetTokenT ecalClusters_; + const edm::EDGetTokenT hcalClusters_; + const edm::EDGetTokenT ebRecHits_; + const edm::EDGetTokenT eeRecHits_; + const edm::EDGetTokenT rho_; + const edm::EDGetTokenT beamSpot_; + const std::string fitter_; + const std::string smoother_; + const std::string builder_; + const bool passThrough_; + const bool usePfTracks_; + const double minPtThreshold_; + const double maxPtThreshold_; + +}; + +#endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedProducer_h diff --git a/RecoEgamma/EgammaElectronProducers/plugins/SealModule.cc b/RecoEgamma/EgammaElectronProducers/plugins/SealModule.cc index 7aef7fce2ff62..c691f09e739f7 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/SealModule.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/SealModule.cc @@ -19,6 +19,8 @@ #include "GEDGsfElectronProducer.h" #include "GEDGsfElectronFinalizer.h" +#include "LowPtGsfElectronSeedProducer.h" + DEFINE_FWK_MODULE(SiStripElectronProducer); DEFINE_FWK_MODULE(SiStripElectronAssociator); DEFINE_FWK_MODULE(ElectronSeedProducer); @@ -33,3 +35,4 @@ DEFINE_FWK_MODULE(SiStripElectronSeedProducer); DEFINE_FWK_MODULE(GEDGsfElectronCoreProducer); DEFINE_FWK_MODULE(GEDGsfElectronProducer); DEFINE_FWK_MODULE(GEDGsfElectronFinalizer); +DEFINE_FWK_MODULE(LowPtGsfElectronSeedProducer); diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py new file mode 100644 index 0000000000000..a93b9e9524cd7 --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py @@ -0,0 +1,32 @@ +import FWCore.ParameterSet.Config as cms + +lowPtGsfElectronSeeds = cms.EDProducer( + "LowPtGsfElectronSeedProducer", + tracks = cms.InputTag("generalTracks"), + pfTracks = cms.InputTag("lowPtGsfElePfTracks"), + ecalClusters = cms.InputTag("particleFlowClusterECAL"), + hcalClusters = cms.InputTag("particleFlowClusterHCAL"), + EBRecHits = cms.InputTag('reducedEcalRecHitsEB'), + EERecHits = cms.InputTag('reducedEcalRecHitsEE'), + rho = cms.InputTag('fixedGridRhoFastjetAllTmp'), + BeamSpot = cms.InputTag("offlineBeamSpot"), + Fitter = cms.string('GsfTrajectoryFitter_forPreId'), + Smoother = cms.string('GsfTrajectorySmoother_forPreId'), + TTRHBuilder = cms.string('WithAngleAndTemplate'), + ModelNames = cms.vstring([ + 'unbiased', + 'ptbiased', + ]), + ModelWeights = cms.vstring([ + 'RecoEgamma/ElectronIdentification/data/LowPtElectrons/2018Nov01_improvedfullseeding_formatted.xml.gz', + 'RecoEgamma/ElectronIdentification/data/LowPtElectrons/2018Nov01_displaced_improvedfullseeding_formatted.xml.gz', + ]), + ModelThresholds = cms.vdouble([ + {"L": 1.03,"M":1.75,"T":2.61}["L"], # unbiased + {"L":-0.48,"M":0.76,"T":1.83}["L"], # ptbiased + ]), + PassThrough = cms.bool(False), + UsePfTracks = cms.bool(True), + MinPtThreshold = cms.double(0.5), + MaxPtThreshold = cms.double(15.), + ) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py new file mode 100644 index 0000000000000..5e1abf1d579ba --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py @@ -0,0 +1,48 @@ +import FWCore.ParameterSet.Config as cms + +# PFRecTracks from generalTracks +from RecoParticleFlow.PFTracking.pfTrack_cfi import * +lowPtGsfElePfTracks = pfTrack.clone() +lowPtGsfElePfTracks.TkColList = ['generalTracks'] +lowPtGsfElePfTracks.GsfTracksInEvents = False +lowPtGsfElePfTracks.GsfTrackModuleLabel = '' + +# Low pT ElectronSeeds +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSeeds_cfi import * + +# Electron track candidates +from TrackingTools.GsfTracking.CkfElectronCandidateMaker_cff import * +lowPtGsfEleTrajectoryFilter = TrajectoryFilterForElectrons.clone() +lowPtGsfEleTrajectoryFilter.minPt = 0. +lowPtGsfEleTrajectoryFilter.minimumNumberOfHits = 3 +lowPtGsfEleTrajectoryBuilder = TrajectoryBuilderForElectrons.clone() +lowPtGsfEleTrajectoryBuilder.trajectoryFilter.refToPSet_ = 'lowPtGsfEleTrajectoryFilter' +lowPtGsfEleCkfTrackCandidates = electronCkfTrackCandidates.clone() +lowPtGsfEleCkfTrackCandidates.TrajectoryBuilderPSet.refToPSet_ = 'lowPtGsfEleTrajectoryBuilder' +lowPtGsfEleCkfTrackCandidates.src = 'lowPtGsfElectronSeeds' + +# GsfTracks +from TrackingTools.GsfTracking.GsfElectronGsfFit_cff import * +lowPtGsfEleFittingSmoother = GsfElectronFittingSmoother.clone() +lowPtGsfEleFittingSmoother.ComponentName = 'lowPtGsfEleFittingSmoother' +lowPtGsfEleFittingSmoother.MinNumberOfHits = 2 +from TrackingTools.GsfTracking.GsfElectronGsfFit_cff import * +lowPtGsfEleGsfTracks = electronGsfTracks.clone() +lowPtGsfEleGsfTracks.Fitter = 'lowPtGsfEleFittingSmoother' +lowPtGsfEleGsfTracks.src = 'lowPtGsfEleCkfTrackCandidates' + +# GsfPFRecTracks +from RecoParticleFlow.PFTracking.pfTrackElec_cfi import * +lowPtGsfElePfGsfTracks = pfTrackElec.clone() +lowPtGsfElePfGsfTracks.GsfTrackModuleLabel = 'lowPtGsfEleGsfTracks' +lowPtGsfElePfGsfTracks.PFRecTrackLabel = 'lowPtGsfElePfTracks' +lowPtGsfElePfGsfTracks.applyGsfTrackCleaning = False +lowPtGsfElePfGsfTracks.useFifthStepForTrackerDrivenGsf = True + +# Full sequence +lowPtGsfElectronSequence = cms.Sequence(lowPtGsfElePfTracks + +lowPtGsfElectronSeeds + +lowPtGsfEleCkfTrackCandidates + +lowPtGsfEleGsfTracks + +lowPtGsfElePfGsfTracks + ) diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc new file mode 100644 index 0000000000000..940bc63f8b83e --- /dev/null +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc @@ -0,0 +1,170 @@ +#include "DataFormats/BeamSpot/interface/BeamSpot.h" +#include "DataFormats/ParticleFlowReco/interface/PreId.h" +#include "DataFormats/ParticleFlowReco/interface/PFCluster.h" +#include "DataFormats/ParticleFlowReco/interface/PFClusterFwd.h" +#include "DataFormats/TrackReco/interface/Track.h" +#include "DataFormats/TrackReco/interface/TrackFwd.h" +#include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h" +#include "CommonTools/MVAUtils/interface/GBRForestTools.h" +#include "TMVA/MethodBDT.h" +#include "TMVA/Reader.h" +#include + +namespace lowptgsfeleseed { + + //////////////////////////////////////////////////////////////////////////////// + // + std::vector Features::get() { + std::vector output = { + trk_pt_, + trk_eta_, + trk_phi_, + trk_p_, + trk_nhits_, + trk_high_quality_, + trk_chi2red_, + rho_, + ktf_ecal_cluster_e_, + ktf_ecal_cluster_deta_, + ktf_ecal_cluster_dphi_, + ktf_ecal_cluster_e3x3_, + ktf_ecal_cluster_e5x5_, + ktf_ecal_cluster_covEtaEta_, + ktf_ecal_cluster_covEtaPhi_, + ktf_ecal_cluster_covPhiPhi_, + ktf_ecal_cluster_r9_, + ktf_ecal_cluster_circularity_, + ktf_hcal_cluster_e_, + ktf_hcal_cluster_deta_, + ktf_hcal_cluster_dphi_, + preid_gsf_dpt_, + preid_trk_gsf_chiratio_, + preid_gsf_chi2red_, + trk_dxy_sig_ + }; + return output; + } + + //////////////////////////////////////////////////////////////////////////////// + // + void Features::set( reco::PreId& ecal, + reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& tools ) { + + // Tracks + reco::TrackRef trk = ecal.trackRef(); + if ( trk.isNonnull() ) { + trk_pt_ = float(trk->pt()); + trk_eta_ = float(trk->eta()); + trk_phi_ = float(trk->phi()); + trk_p_ = float(trk->p()); + trk_nhits_ = float(trk->found()); + trk_high_quality_ = float(trk->quality(reco::TrackBase::qualityByName("highPurity"))); + trk_chi2red_ = float(trk->normalizedChi2()); + if ( trk->dxyError() > 0. ) { + trk_dxy_sig_ = float( trk->dxy(spot) / trk->dxyError() ); + } + } + + // Rho + rho_ = float(rho); + + // ECAL clusters + reco::PFClusterRef ecal_clu = ecal.clusterRef(); + if ( ecal_clu.isNonnull() ) { + ktf_ecal_cluster_e_ = float(ecal_clu->energy()); + ktf_ecal_cluster_deta_ = float(ecal.geomMatching()[0]); + ktf_ecal_cluster_dphi_ = float(ecal.geomMatching()[1]); + ktf_ecal_cluster_e3x3_ = float(tools.e3x3(*ecal_clu)); + ktf_ecal_cluster_e5x5_ = float(tools.e5x5(*ecal_clu)); + auto covs = tools.localCovariances(*ecal_clu); + ktf_ecal_cluster_covEtaEta_ = float(covs[0]); + ktf_ecal_cluster_covEtaPhi_ = float(covs[1]); + ktf_ecal_cluster_covPhiPhi_ = float(covs[2]); + if ( ktf_ecal_cluster_e_ > 0. ) { + ktf_ecal_cluster_r9_ = float( ktf_ecal_cluster_e3x3_ / ktf_ecal_cluster_e_ ); + } + if ( ktf_ecal_cluster_e5x5_ > 0. ) { + ktf_ecal_cluster_circularity_ = float( 1. - tools.e1x5(*ecal_clu) / + ktf_ecal_cluster_e5x5_); + } else { + ktf_ecal_cluster_circularity_ = float(-0.1); + } + } + + // HCAL clusters + reco::PFClusterRef hcal_clu = hcal.clusterRef(); + if ( hcal_clu.isNonnull() ) { + ktf_ecal_cluster_e_ = float(hcal_clu->energy()); + ktf_hcal_cluster_deta_ = float(hcal.geomMatching()[0]); + ktf_hcal_cluster_dphi_ = float(hcal.geomMatching()[1]); + } + + // PreId + preid_gsf_dpt_ = float(ecal.dpt()); + preid_trk_gsf_chiratio_ = float(ecal.chi2Ratio()); + preid_gsf_chi2red_ = float(ecal.gsfChi2()); + + }; + + //////////////////////////////////////////////////////////////////////////////// + // + HeavyObjectCache::HeavyObjectCache( const edm::ParameterSet& conf ) { + for ( auto& name : conf.getParameter< std::vector >("ModelNames") ) + { + names_.push_back(name); + } + for ( auto& weights : conf.getParameter< std::vector >("ModelWeights") ) + { + models_.push_back(createGBRForest(edm::FileInPath(weights))); + } + for ( auto& thresh : conf.getParameter< std::vector >("ModelThresholds") ) + { + thresholds_.push_back(thresh); + } + if ( names_.size() != models_.size() ) { + throw cms::Exception("Incorrect configuration") + << "'ModelNames' size (" << names_.size() + << ") != 'ModelWeights' size (" << models_.size() + << ").\n"; + } + if ( models_.size() != thresholds_.size() ) { + throw cms::Exception("Incorrect configuration") + << "'ModelWeights' size (" << models_.size() + << ") != 'ModelThresholds' size (" << thresholds_.size() + << ").\n"; + } + + } + + //////////////////////////////////////////////////////////////////////////////// + // + bool HeavyObjectCache::eval( std::string name, + reco::PreId& ecal, + reco::PreId& hcal, + double rho, + const reco::BeamSpot& spot, + noZS::EcalClusterLazyTools& ecalTools ) const + { + std::vector::const_iterator iter = std::find( names_.begin(), + names_.end(), + name ); + if ( iter != names_.end() ) { + int index = std::distance(names_.begin(),iter); + Features features; + features.set(ecal,hcal,rho,spot,ecalTools); + std::vector inputs = features.get(); + float output = models_.at(index)->GetResponse( inputs.data() ); + bool pass = output > thresholds_.at(index); + ecal.setMVA(pass,output,index); + return pass; + } else { + throw cms::Exception("Unknown model name") + << "'Name given: '" << name + << "'. Check against configuration file.\n"; + } + } + +} // namespace lowptgsfeleseed From 5d6eb579546843c0158f2fa0d127620f2003ccb2 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Mon, 10 Dec 2018 17:10:55 +0100 Subject: [PATCH 02/22] updated model filenames --- .../python/lowPtGsfElectronSeeds_cfi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py index a93b9e9524cd7..ecd3b1bb8df80 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py @@ -18,8 +18,8 @@ 'ptbiased', ]), ModelWeights = cms.vstring([ - 'RecoEgamma/ElectronIdentification/data/LowPtElectrons/2018Nov01_improvedfullseeding_formatted.xml.gz', - 'RecoEgamma/ElectronIdentification/data/LowPtElectrons/2018Nov01_displaced_improvedfullseeding_formatted.xml.gz', + 'RecoEgamma/ElectronIdentification/data/LowPtElectrons/RunII_Fall17_LowPtElectrons_unbiased.xml.gz', + 'RecoEgamma/ElectronIdentification/data/LowPtElectrons/RunII_Fall17_LowPtElectrons_displaced_pt_eta_biased.xml.gz', ]), ModelThresholds = cms.vdouble([ {"L": 1.03,"M":1.75,"T":2.61}["L"], # unbiased From 86ff5eb88b96d374dd245333a56bf802b1fdff9e Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Mon, 10 Dec 2018 17:11:32 +0100 Subject: [PATCH 03/22] only consume PF or KF tracks depending on UsePfTracks configurable --- .../plugins/LowPtGsfElectronSeedProducer.cc | 8 ++++---- .../plugins/LowPtGsfElectronSeedProducer.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc index 849f662c471cb..aa5a8bc681332 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -37,8 +37,6 @@ // LowPtGsfElectronSeedProducer::LowPtGsfElectronSeedProducer( const edm::ParameterSet& conf, const lowptgsfeleseed::HeavyObjectCache* ) : - kfTracks_{consumes(conf.getParameter("tracks"))}, - pfTracks_{consumes(conf.getParameter("pfTracks"))}, ecalClusters_{consumes(conf.getParameter("ecalClusters"))}, hcalClusters_{consumes(conf.getParameter("hcalClusters"))}, ebRecHits_{consumes(conf.getParameter("EBRecHits"))}, @@ -53,6 +51,8 @@ LowPtGsfElectronSeedProducer::LowPtGsfElectronSeedProducer( const edm::Parameter minPtThreshold_(conf.getParameter("MinPtThreshold")), maxPtThreshold_(conf.getParameter("MaxPtThreshold")) { + if ( usePfTracks_ ) { pfTracks_ = consumes(conf.getParameter("pfTracks")); } + else { kfTracks_ = consumes(conf.getParameter("tracks")); } produces(); produces(); produces("HCAL"); @@ -83,11 +83,11 @@ void LowPtGsfElectronSeedProducer::produce( edm::Event& event, // KF tracks edm::Handle kfTracks; - event.getByToken(kfTracks_, kfTracks); + if ( !usePfTracks_ ) { event.getByToken(kfTracks_, kfTracks); } // PF tracks edm::Handle pfTracks; - event.getByToken(pfTracks_, pfTracks); + if ( usePfTracks_ ) { event.getByToken(pfTracks_, pfTracks); } // ECAL clusters edm::Handle ecalClusters; diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h index 54cdae76d3f2a..47f5f91e5f178 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h @@ -110,8 +110,8 @@ class LowPtGsfElectronSeedProducer final : public edm::stream::EDProducer< edm:: private: // member data edm::ESHandle field_; - const edm::EDGetTokenT kfTracks_; - const edm::EDGetTokenT pfTracks_; + edm::EDGetTokenT kfTracks_; + edm::EDGetTokenT pfTracks_; const edm::EDGetTokenT ecalClusters_; const edm::EDGetTokenT hcalClusters_; const edm::EDGetTokenT ebRecHits_; From f0f465818a92371ade2207ca0fa32ed2eb547c40 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Mon, 10 Dec 2018 18:18:50 +0100 Subject: [PATCH 04/22] fillDescriptions --- .../plugins/LowPtGsfElectronSeedProducer.cc | 7 +++++-- .../plugins/LowPtGsfElectronSeedProducer.h | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc index aa5a8bc681332..1cc98e0630aed 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -20,6 +20,7 @@ #include "FastSimulation/BaseParticlePropagator/interface/BaseParticlePropagator.h" #include "FastSimulation/Particle/interface/RawParticle.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" #include "FWCore/Utilities/interface/InputTag.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" #include "RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h" @@ -506,8 +507,9 @@ bool LowPtGsfElectronSeedProducer::decision( const reco::TrackRef& kfTrackRef, ////////////////////////////////////////////////////////////////////////////////////////// // -void LowPtGsfElectronSeedProducer::fillDescription( edm::ParameterSetDescription& desc ) +void LowPtGsfElectronSeedProducer::fillDescriptions( edm::ConfigurationDescriptions& descriptions ) { + edm::ParameterSetDescription desc; desc.add("tracks",edm::InputTag("generalTracks")); desc.add("pfTracks",edm::InputTag("lowPtGsfElePfTracks")); desc.add("ecalClusters",edm::InputTag("particleFlowClusterECAL")); @@ -521,9 +523,10 @@ void LowPtGsfElectronSeedProducer::fillDescription( edm::ParameterSetDescription desc.add("TTRHBuilder","WithAngleAndTemplate"); desc.add< std::vector >("ModelNames",std::vector()); desc.add< std::vector >("ModelWeights",std::vector()); - desc.add< std::vector >("ModelThrsholds",std::vector()); + desc.add< std::vector >("ModelThresholds",std::vector()); desc.add("PassThrough",false); desc.add("UsePfTracks",false); desc.add("MinPtThreshold",0.5); desc.add("MaxPtThreshold",15.); + descriptions.add("produceLowPtGsfElectronSeeds",desc); } diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h index 47f5f91e5f178..e69d33da58bcf 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h @@ -16,7 +16,7 @@ #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/stream/EDProducer.h" -#include "FWCore/ParameterSet/interface/ParameterSetDescription.h" +#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h" #include "MagneticField/Engine/interface/MagneticField.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" #include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h" @@ -43,7 +43,7 @@ class LowPtGsfElectronSeedProducer final : public edm::stream::EDProducer< edm:: void produce( edm::Event&, const edm::EventSetup& ) override; - static void fillDescription( edm::ParameterSetDescription& ); + static void fillDescriptions( edm::ConfigurationDescriptions& ); private: // member functions From 0782b0e9721e5dd056576d36179eae1732dfe8e2 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Tue, 11 Dec 2018 11:32:08 +0100 Subject: [PATCH 05/22] consume collections only when necessary --- .../plugins/LowPtGsfElectronSeedProducer.cc | 46 ++++++++++--------- .../plugins/LowPtGsfElectronSeedProducer.h | 3 +- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc index 1cc98e0630aed..74aeb0b1272b2 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -39,7 +39,6 @@ LowPtGsfElectronSeedProducer::LowPtGsfElectronSeedProducer( const edm::ParameterSet& conf, const lowptgsfeleseed::HeavyObjectCache* ) : ecalClusters_{consumes(conf.getParameter("ecalClusters"))}, - hcalClusters_{consumes(conf.getParameter("hcalClusters"))}, ebRecHits_{consumes(conf.getParameter("EBRecHits"))}, eeRecHits_{consumes(conf.getParameter("EERecHits"))}, rho_(consumes(conf.getParameter("rho"))), @@ -52,8 +51,13 @@ LowPtGsfElectronSeedProducer::LowPtGsfElectronSeedProducer( const edm::Parameter minPtThreshold_(conf.getParameter("MinPtThreshold")), maxPtThreshold_(conf.getParameter("MaxPtThreshold")) { - if ( usePfTracks_ ) { pfTracks_ = consumes(conf.getParameter("pfTracks")); } - else { kfTracks_ = consumes(conf.getParameter("tracks")); } + if ( usePfTracks_ ) { + pfTracks_ = consumes(conf.getParameter("pfTracks")); + hcalClusters_ = consumes(conf.getParameter("hcalClusters")); + } + else { + kfTracks_ = consumes(conf.getParameter("tracks")); + } produces(); produces(); produces("HCAL"); @@ -82,40 +86,37 @@ void LowPtGsfElectronSeedProducer::produce( edm::Event& event, auto ecalPreIds = std::make_unique(); auto hcalPreIds = std::make_unique(); - // KF tracks - edm::Handle kfTracks; - if ( !usePfTracks_ ) { event.getByToken(kfTracks_, kfTracks); } - - // PF tracks - edm::Handle pfTracks; - if ( usePfTracks_ ) { event.getByToken(pfTracks_, pfTracks); } - - // ECAL clusters - edm::Handle ecalClusters; - event.getByToken(ecalClusters_,ecalClusters); - // HCAL clusters (only used with PF tracks) edm::Handle hcalClusters; - event.getByToken(hcalClusters_,hcalClusters); if ( usePfTracks_ ) { + + edm::Handle pfTracks; + event.getByToken(pfTracks_, pfTracks); + + event.getByToken(hcalClusters_,hcalClusters); + loop(pfTracks, // PF tracks - ecalClusters, hcalClusters, *seeds, *ecalPreIds, *hcalPreIds, event, setup); + } else { + + edm::Handle kfTracks; + event.getByToken(kfTracks_, kfTracks); + loop(kfTracks, // KF tracks - ecalClusters, hcalClusters, *seeds, *ecalPreIds, *hcalPreIds, event, setup); + } event.put(std::move(seeds)); @@ -141,7 +142,6 @@ reco::TrackRef LowPtGsfElectronSeedProducer::getBaseRef( edm::Handle< std::vecto // Template function, instantiated for both reco::Tracks and reco::PFRecTracks template void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >& handle, // PF or KF tracks - edm::Handle& ecalClusters, edm::Handle& hcalClusters, reco::ElectronSeedCollection& seeds, reco::PreIdCollection& ecalPreIds, @@ -157,7 +157,11 @@ void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >& ha // Beam spot edm::Handle spot; event.getByToken(beamSpot_,spot); - + + // ECAL clusters + edm::Handle ecalClusters; + event.getByToken(ecalClusters_,ecalClusters); + // Utility to access to shower shape vars noZS::EcalClusterLazyTools ecalTools(event,setup,ebRecHits_,eeRecHits_); @@ -220,7 +224,6 @@ void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >& ha // Template instantiation for reco::Tracks template void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >&, - edm::Handle& ecalClusters, edm::Handle& hcalClusters, reco::ElectronSeedCollection& seeds, reco::PreIdCollection& ecalPreIds, @@ -232,7 +235,6 @@ void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::ve // Template instantiation for reco::PFRecTracks template void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >&, - edm::Handle& ecalClusters, edm::Handle& hcalClusters, reco::ElectronSeedCollection& seeds, reco::PreIdCollection& ecalPreIds, diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h index e69d33da58bcf..83d875fe70a09 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h @@ -48,7 +48,6 @@ class LowPtGsfElectronSeedProducer final : public edm::stream::EDProducer< edm:: private: // member functions template void loop( const edm::Handle< std::vector >& handle, - edm::Handle& ecalClusters, edm::Handle& hcalClusters, reco::ElectronSeedCollection& seeds, reco::PreIdCollection& ecalPreIds, @@ -113,7 +112,7 @@ class LowPtGsfElectronSeedProducer final : public edm::stream::EDProducer< edm:: edm::EDGetTokenT kfTracks_; edm::EDGetTokenT pfTracks_; const edm::EDGetTokenT ecalClusters_; - const edm::EDGetTokenT hcalClusters_; + edm::EDGetTokenT hcalClusters_; const edm::EDGetTokenT ebRecHits_; const edm::EDGetTokenT eeRecHits_; const edm::EDGetTokenT rho_; From 61e635f088075478881bcaa287487a164ae9f01f Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Thu, 13 Dec 2018 22:17:41 +0100 Subject: [PATCH 06/22] removed commented line --- RecoEgamma/EgammaElectronProducers/BuildFile.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/RecoEgamma/EgammaElectronProducers/BuildFile.xml b/RecoEgamma/EgammaElectronProducers/BuildFile.xml index 8db45701f959b..8df2957e47b22 100644 --- a/RecoEgamma/EgammaElectronProducers/BuildFile.xml +++ b/RecoEgamma/EgammaElectronProducers/BuildFile.xml @@ -5,7 +5,6 @@ - From c5c761d475bee12b9c8bc11a3df8fea90732b7cc Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Thu, 13 Dec 2018 22:20:07 +0100 Subject: [PATCH 07/22] comments from perotta --- .../interface/LowPtGsfElectronSeedHeavyObjectCache.h | 2 +- .../plugins/LowPtGsfElectronSeedProducer.cc | 6 ++++-- .../plugins/LowPtGsfElectronSeedProducer.h | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h index 50ff60bd62562..f4b92e9f698a9 100644 --- a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h +++ b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h @@ -33,7 +33,7 @@ namespace lowptgsfeleseed { float ktf_ecal_cluster_covEtaPhi_ = -1.; float ktf_ecal_cluster_covPhiPhi_ = -1.; float ktf_ecal_cluster_r9_ = -1.; - float ktf_ecal_cluster_circularity_ = -1.; + float ktf_ecal_cluster_circularity_ = -0.1; float ktf_hcal_cluster_e_ = -1.; float ktf_hcal_cluster_deta_ = -1.; float ktf_hcal_cluster_dphi_ = -1.; diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc index 74aeb0b1272b2..f7a9a69e0dbce 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -285,6 +285,7 @@ void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::PFRecTrackR for ( unsigned int iclu = 0; iclu < clusters.product()->size(); iclu++ ) { if ( std::find( matched.begin(), matched.end(), iclu ) == matched.end() ) { + reco::PFClusterRef cluRef(clusters,iclu); // Determine deta, dphi, dr @@ -342,7 +343,7 @@ void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::TrackRef& k } info; // Propagate 'electron' to ECAL surface - float energy = sqrt( pow(0.000511,2.) + kfTrackRef->outerMomentum().Mag2() ); + float energy = sqrt( mass_ + kfTrackRef->outerMomentum().Mag2() ); XYZTLorentzVector mom = XYZTLorentzVector( kfTrackRef->outerMomentum().x(), kfTrackRef->outerMomentum().y(), kfTrackRef->outerMomentum().z(), @@ -361,8 +362,9 @@ void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::TrackRef& k GlobalPoint ecal_pos(particle.vertex().x(), particle.vertex().y(), particle.vertex().z()); + // Preshower limit - bool below_ps = pow(ecal_pos.z(),2.) > pow(2.50746495928f,2.)*ecal_pos.perp2(); + bool below_ps = pow(ecal_pos.z(),2.) > boundary_*ecal_pos.perp2(); // Iterate through ECAL clusters for ( unsigned int iclu = 0; iclu < ecalClusters.product()->size(); iclu++ ) { diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h index 83d875fe70a09..a494e13ed4d06 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h @@ -125,6 +125,11 @@ class LowPtGsfElectronSeedProducer final : public edm::stream::EDProducer< edm:: const double minPtThreshold_; const double maxPtThreshold_; + // pow( sinh(1.65), 2. ) + static constexpr double boundary_ = 2.50746495928*2.50746495928; + // pow( ele_mass, 2. ) + static constexpr double mass_ = 0.000511*0.000511; + }; #endif // RecoEgamma_EgammaElectronProducers_LowPtGsfElectronSeedProducer_h From 1b3dd5721b7f74ea4b162b37a04a5ecc5ad68c00 Mon Sep 17 00:00:00 2001 From: Sam Harper Date: Wed, 19 Dec 2018 13:50:26 +0000 Subject: [PATCH 08/22] fixing low pt eles for fastsim --- .../plugins/ElectronSeedTrackRefFix.cc | 129 +++++++++--------- .../plugins/ElectronSeedTrackRefFix.h | 24 ++-- .../python/ElectronSeedTrackRefFix_cfi.py | 4 +- .../python/lowPtGsfElectronSeeds_cfi.py | 12 ++ .../python/lowPtGsfElectronSequence_cff.py | 29 +++- .../python/trackerDrivenElectronSeeds_cfi.py | 2 +- 6 files changed, 118 insertions(+), 82 deletions(-) diff --git a/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc b/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc index 793d3c7f1c6b2..1e9a7c1faf3fa 100644 --- a/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc +++ b/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc @@ -19,31 +19,55 @@ // constructors and destructor // -using namespace std; -using namespace reco; -using namespace edm; + + + + + +namespace{ + template + const edm::OrphanHandle > addVMToEvent(edm::Event& event,const edm::Handle& handle,std::vector values,const std::string& label) + { + auto vMap = std::make_unique >(); + typename edm::ValueMap::Filler mapFiller(*vMap); + mapFiller.insert(handle,values.begin(),values.end()); + mapFiller.fill(); + return event.put(std::move(vMap),label); + } + template edm::Handle getHandle(const edm::Event& event,const edm::EDGetTokenT& token) + { + edm::Handle handle; + event.getByToken(token,handle); + return handle; + } +} ElectronSeedTrackRefFix::ElectronSeedTrackRefFix(const edm::ParameterSet& iConfig) { // read parameters - preidgsfLabel = iConfig.getParameter("PreGsfLabel"); - preidLabel= iConfig.getParameter("PreIdLabel"); - oldTracksTag = iConfig.getParameter("oldTrackCollection"); - newTracksTag = iConfig.getParameter("newTrackCollection"); - seedsTag = iConfig.getParameter("seedCollection"); - idsTag = iConfig.getParameter("idCollection"); + preidgsfLabel_ = iConfig.getParameter("PreGsfLabel"); + preidLabel_ = iConfig.getParameter >("PreIdLabel"); + oldTracksTag_ = iConfig.getParameter("oldTrackCollection"); + newTracksTag_ = iConfig.getParameter("newTrackCollection"); + seedsTag_ = iConfig.getParameter("seedCollection"); + idsTag_ = iConfig.getParameter>("idCollection"); //register your products - produces(preidgsfLabel); - produces(preidLabel); - produces >(preidLabel); + produces(preidgsfLabel_); + for(const auto& idLabel : preidLabel_){ + produces(idLabel); + produces >(idLabel); + } //create tokens - oldTracksToken = consumes(oldTracksTag); - newTracksToken = consumes(newTracksTag); - seedsToken = consumes(seedsTag); - idsToken = consumes(idsTag); - idMapToken = consumes >(idsTag) ; + oldTracksToken_ = consumes(oldTracksTag_); + newTracksToken_ = consumes(newTracksTag_); + seedsToken_ = consumes(seedsTag_); + + for(const auto& idTag: idsTag_){ + idsToken_.emplace_back(consumes(idTag)); + idMapToken_.emplace_back(consumes >(idTag)); + } } @@ -64,58 +88,41 @@ ElectronSeedTrackRefFix::~ElectronSeedTrackRefFix() void ElectronSeedTrackRefFix::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) { - using namespace edm; - - Handle oldTracks; - iEvent.getByToken(oldTracksToken,oldTracks); - - Handle newTracks; - iEvent.getByToken(newTracksToken,newTracks); - - Handle iSeeds; - iEvent.getByToken(seedsToken,iSeeds); - - Handle iIds; - iEvent.getByToken(idsToken,iIds); - - Handle > iIdMap; - iEvent.getByToken(idMapToken,iIdMap); - - unique_ptr oSeeds(new ElectronSeedCollection); - unique_ptr oIds(new PreIdCollection); - unique_ptr > oIdMap(new ValueMap); - ValueMap::Filler mapFiller(*oIdMap); + auto oldTracks = getHandle(iEvent,oldTracksToken_); + auto newTracks = getHandle(iEvent,newTracksToken_); + auto iSeeds = getHandle(iEvent,seedsToken_); + auto oSeeds = std::make_unique(); for(unsigned int s = 0;ssize();++s){ oSeeds->push_back(iSeeds->at(s)); - TrackRef newTrackRef(newTracks,oSeeds->back().ctfTrack().index()); + reco::TrackRef newTrackRef(newTracks,oSeeds->back().ctfTrack().index()); oSeeds->back().setCtfTrack(newTrackRef); } - - for(unsigned int i = 0;isize();++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 preIdProd = iEvent.put(std::move(oIds),preidLabel); - - vector values; - for(unsigned int t = 0;tsize();++t){ - if(t < oldTracks->size()){ - TrackRef oldTrackRef(oldTracks,t); - values.push_back(PreIdRef(preIdProd,(*(iIdMap.product()))[oldTrackRef].index())); + 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(); + for(unsigned int i = 0;isize();++i){ + oIds->push_back(iIds->at(i)); + reco::TrackRef newTrackRef(newTracks,oIds->back().trackRef().index()); + oIds->back().setTrack(newTrackRef); } - else{ - values.push_back(PreIdRef()); + const edm::OrphanHandle preIdProd = iEvent.put(std::move(oIds),preidLabel_[idNr]); + + auto iIdMap = getHandle(iEvent,idMapToken_[idNr]); + std::vector values; + for(size_t trkNr = 0;trkNrsize();++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()); } - } - mapFiller.insert(newTracks,values.begin(),values.end()); - mapFiller.fill(); - - iEvent.put(std::move(oIdMap),preidLabel); + addVMToEvent(iEvent,newTracks,std::move(values),preidLabel_[idNr]); + }//end loop over ids } // ------------ method fills 'descriptions' with the allowed parameters for the module ------------ diff --git a/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h b/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h index 71858002f08de..df8f6a4e0d6e8 100644 --- a/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h +++ b/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h @@ -26,18 +26,18 @@ class ElectronSeedTrackRefFix : public edm::stream::EDProducer<> { void produce(edm::Event&, const edm::EventSetup&) override; // ----------member data --------------------------- - edm::EDGetTokenT newTracksToken; - edm::EDGetTokenT oldTracksToken; - edm::EDGetTokenT seedsToken; - edm::EDGetTokenT idsToken; - edm::EDGetTokenT > idMapToken; - - std::string preidgsfLabel; - std::string preidLabel; - edm::InputTag oldTracksTag; - edm::InputTag newTracksTag; - edm::InputTag seedsTag; - edm::InputTag idsTag; + edm::EDGetTokenT newTracksToken_; + edm::EDGetTokenT oldTracksToken_; + edm::EDGetTokenT seedsToken_; + std::vector > idsToken_; + std::vector > > idMapToken_; + + std::string preidgsfLabel_; + std::vector preidLabel_; + edm::InputTag oldTracksTag_; + edm::InputTag newTracksTag_; + edm::InputTag seedsTag_; + std::vector idsTag_; }; diff --git a/FastSimulation/Tracking/python/ElectronSeedTrackRefFix_cfi.py b/FastSimulation/Tracking/python/ElectronSeedTrackRefFix_cfi.py index 363aa3c8e7785..c031ad55fe118 100644 --- a/FastSimulation/Tracking/python/ElectronSeedTrackRefFix_cfi.py +++ b/FastSimulation/Tracking/python/ElectronSeedTrackRefFix_cfi.py @@ -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",) ) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py index ecd3b1bb8df80..e981d619dfeb8 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py @@ -30,3 +30,15 @@ MinPtThreshold = cms.double(0.5), MaxPtThreshold = cms.double(15.), ) +# copying from RecoParticleFlow/PFTracking/python/trackerDrivenElectronSeeds_cfi.py +# inFastSim jobs, trajectories are only available for the 'before mixing' track collections +# Therefore we let the seeds depend on the 'before mixing' generalTracks collection +from Configuration.Eras.Modifier_fastSim_cff import fastSim +lowPtGsfElectronSeedsTmp = lowPtGsfElectronSeeds.clone(tracks = cms.InputTag("generalTracksBeforeMixing")) +import FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi +_fastSim_lowPtGsfElectronSeeds = FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi.fixedTrackerDrivenElectronSeeds.clone() +_fastSim_lowPtGsfElectronSeeds.seedCollection = cms.InputTag("lowPtGsfElectronSeedsTmp","") +_fastSim_lowPtGsfElectronSeeds.idCollection = cms.VInputTag("lowPtGsfElectronSeedsTmp","lowPtGsfElectronSeedsTmp:HCAL") +_fastSim_lowPtGsfElectronSeeds.PreIdLabel = cms.vstring("","HCAL") +_fastSim_lowPtGsfElectronSeeds.PreGsfLabel = cms.string("") +fastSim.toReplaceWith(lowPtGsfElectronSeeds,_fastSim_lowPtGsfElectronSeeds) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py index 5e1abf1d579ba..33c703bf03346 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py @@ -21,6 +21,11 @@ lowPtGsfEleCkfTrackCandidates.TrajectoryBuilderPSet.refToPSet_ = 'lowPtGsfEleTrajectoryBuilder' lowPtGsfEleCkfTrackCandidates.src = 'lowPtGsfElectronSeeds' +import FastSimulation.Tracking.electronCkfTrackCandidates_cff +fastLowPtGsfTkfTrackCandidates = FastSimulation.Tracking.electronCkfTrackCandidates_cff.electronCkfTrackCandidates.clone(src = cms.InputTag("lowPtGsfElectronSeeds")) + + + # GsfTracks from TrackingTools.GsfTracking.GsfElectronGsfFit_cff import * lowPtGsfEleFittingSmoother = GsfElectronFittingSmoother.clone() @@ -31,6 +36,7 @@ lowPtGsfEleGsfTracks.Fitter = 'lowPtGsfEleFittingSmoother' lowPtGsfEleGsfTracks.src = 'lowPtGsfEleCkfTrackCandidates' + # GsfPFRecTracks from RecoParticleFlow.PFTracking.pfTrackElec_cfi import * lowPtGsfElePfGsfTracks = pfTrackElec.clone() @@ -40,9 +46,20 @@ lowPtGsfElePfGsfTracks.useFifthStepForTrackerDrivenGsf = True # Full sequence -lowPtGsfElectronSequence = cms.Sequence(lowPtGsfElePfTracks - +lowPtGsfElectronSeeds - +lowPtGsfEleCkfTrackCandidates - +lowPtGsfEleGsfTracks - +lowPtGsfElePfGsfTracks - ) +lowPtGsfElectronTask = cms.Task(lowPtGsfElePfTracks, + lowPtGsfElectronSeeds, + lowPtGsfEleCkfTrackCandidates, + lowPtGsfEleGsfTracks, + lowPtGsfElePfGsfTracks) +lowPtGsfElectronSequence = cms.Sequence(lowPtGsfElectronTask) + + +from Configuration.Eras.Modifier_fastSim_cff import fastSim +_fastSim_lowPtGsfElectronTask = lowPtGsfElectronTask.copy() +_fastSim_lowPtGsfElectronTask.replace(lowPtGsfElectronSeeds, cms.Task(lowPtGsfElectronSeedsTmp,lowPtGsfElectronSeeds)) +_fastSim_lowPtGsfElectronTask.replace(lowPtGsfEleCkfTrackCandidates, fastLowPtGsfTkfTrackCandidates) + +fastSim.toReplaceWith(lowPtGsfElectronTask, _fastSim_lowPtGsfElectronTask) +fastSim.toModify(lowPtGsfElePfTracks,TkColList = ['generalTracksBeforeMixing']) +fastSim.toModify(lowPtGsfEleGsfTracks,src = cms.InputTag("fastLowPtGsfTkfTrackCandidates")) + diff --git a/RecoParticleFlow/PFTracking/python/trackerDrivenElectronSeeds_cfi.py b/RecoParticleFlow/PFTracking/python/trackerDrivenElectronSeeds_cfi.py index a30aaa18caa84..9c247e9025be9 100644 --- a/RecoParticleFlow/PFTracking/python/trackerDrivenElectronSeeds_cfi.py +++ b/RecoParticleFlow/PFTracking/python/trackerDrivenElectronSeeds_cfi.py @@ -68,6 +68,6 @@ import FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi _fastSim_trackerDrivenElectronSeeds = FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi.fixedTrackerDrivenElectronSeeds.clone() _fastSim_trackerDrivenElectronSeeds.seedCollection.setModuleLabel("trackerDrivenElectronSeedsTmp"), -_fastSim_trackerDrivenElectronSeeds.idCollection.setModuleLabel("trackerDrivenElectronSeedsTmp") +_fastSim_trackerDrivenElectronSeeds.idCollection = cms.VInputTag("trackerDrivenElectronSeedsTmp:preid",) fastSim.toReplaceWith(trackerDrivenElectronSeeds,_fastSim_trackerDrivenElectronSeeds) From aa2ffc93d2d982e03843b07db5d9fa333cea6327 Mon Sep 17 00:00:00 2001 From: Sam Harper Date: Wed, 19 Dec 2018 16:05:21 +0000 Subject: [PATCH 09/22] fixing low pt ele for phaseII --- .../python/lowPtGsfElectronSeeds_cfi.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py index e981d619dfeb8..21b25b39fedc3 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py @@ -42,3 +42,6 @@ _fastSim_lowPtGsfElectronSeeds.PreIdLabel = cms.vstring("","HCAL") _fastSim_lowPtGsfElectronSeeds.PreGsfLabel = cms.string("") fastSim.toReplaceWith(lowPtGsfElectronSeeds,_fastSim_lowPtGsfElectronSeeds) + +from Configuration.Eras.Modifier_phase2_tracker_cff import phase2_tracker +phase2_tracker.toModify(lowPtGsfElectronSeeds, TTRHBuilder = 'WithTrackAngle') From d1a7fc5e1aeee9c5c48f18da3dbf07892ede1bf8 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Wed, 19 Dec 2018 20:49:00 +0100 Subject: [PATCH 10/22] explicitly specify low pT GsfTracks --- .../Configuration/python/RecoEgamma_EventContent_cff.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py b/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py index e90dc82b3f7b1..a507a2bea8108 100644 --- a/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py +++ b/RecoEgamma/Configuration/python/RecoEgamma_EventContent_cff.py @@ -40,7 +40,8 @@ 'keep *_hfRecoEcalCandidate_*_*', 'keep *_hfEMClusters_*_*', 'keep *_gedGsfElectronCores_*_*', - 'keep *_gedGsfElectrons_*_*' + 'keep *_gedGsfElectrons_*_*', + 'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*' ) ) @@ -97,7 +98,7 @@ 'keep *_hfEMClusters_*_*', 'keep *_gedGsfElectronCores_*_*', 'keep *_gedGsfElectrons_*_*', - 'keep *_lowPtGsfEle*_*_*', + 'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*' ) ) @@ -143,7 +144,7 @@ 'keep *_hfEMClusters_*_*', 'keep *_gedGsfElectronCores_*_*', 'keep *_gedGsfElectrons_*_*', - 'keep *_lowPtGsfEle*_*_*', + 'keep recoGsfTracks_lowPtGsfEleGsfTracks_*_*' ) ) From 82d13fb63a7e6a65b7b61117d8d58e8c6417cb1d Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Wed, 19 Dec 2018 20:49:59 +0100 Subject: [PATCH 11/22] const args, comment from mauro --- .../interface/LowPtGsfElectronSeedHeavyObjectCache.h | 4 ++-- .../src/LowPtGsfElectronSeedHeavyObjectCache.cc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h index f4b92e9f698a9..31f32f180da95 100644 --- a/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h +++ b/RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h @@ -43,8 +43,8 @@ namespace lowptgsfeleseed { float trk_dxy_sig_ = -1.; // must be last (not used by unbiased model) public: std::vector get(); - void set( reco::PreId& ecal, - reco::PreId& hcal, + void set( const reco::PreId& ecal, + const reco::PreId& hcal, double rho, const reco::BeamSpot& spot, noZS::EcalClusterLazyTools& ecalTools ); diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc index 940bc63f8b83e..c3b0b897c1f42 100644 --- a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc @@ -47,8 +47,8 @@ namespace lowptgsfeleseed { //////////////////////////////////////////////////////////////////////////////// // - void Features::set( reco::PreId& ecal, - reco::PreId& hcal, + void Features::set( const reco::PreId& ecal, + const reco::PreId& hcal, double rho, const reco::BeamSpot& spot, noZS::EcalClusterLazyTools& tools ) { From 540945352f1e0225b372f561adf8f851fab2b96f Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Wed, 19 Dec 2018 20:51:17 +0100 Subject: [PATCH 12/22] dPhi(traj,clu) * charge --- .../plugins/LowPtGsfElectronSeedProducer.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc index f7a9a69e0dbce..18afbd1f5013a 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -297,7 +297,7 @@ void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::PFRecTrackR info.dr2min = dr2; info.cluRef = cluRef; info.deta = deta; - info.dphi = dphi; + info.dphi = dphi * pfTrackRef->trackRef()->charge(); info.showerPos = point.position(); } @@ -389,7 +389,7 @@ void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::TrackRef& k info.dr2min = dr2; info.cluRef = cluRef; info.deta = deta; - info.dphi = dphi; + info.dphi = dphi * kfTrackRef->charge(); info.showerPos = showerPos; } From 1503e52839f399f4e09bc6572a5677fb2b2ae245 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Wed, 19 Dec 2018 21:00:39 +0100 Subject: [PATCH 13/22] modifiers for BParking + triv tidy up --- .../Eras/python/Modifier_BParking_cff.py | 3 +++ .../StandardSequences/python/Eras.py | 3 ++- .../python/lowPtGsfElectronSeeds_cfi.py | 19 ++++++++++++------- .../python/lowPtGsfElectronSequence_cff.py | 7 ++----- 4 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 Configuration/Eras/python/Modifier_BParking_cff.py diff --git a/Configuration/Eras/python/Modifier_BParking_cff.py b/Configuration/Eras/python/Modifier_BParking_cff.py new file mode 100644 index 0000000000000..93950a0a34927 --- /dev/null +++ b/Configuration/Eras/python/Modifier_BParking_cff.py @@ -0,0 +1,3 @@ +import FWCore.ParameterSet.Config as cms + +BParking = cms.Modifier() diff --git a/Configuration/StandardSequences/python/Eras.py b/Configuration/StandardSequences/python/Eras.py index 55eb8d8522533..78367504a291b 100644 --- a/Configuration/StandardSequences/python/Eras.py +++ b/Configuration/StandardSequences/python/Eras.py @@ -59,7 +59,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'] diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py index 21b25b39fedc3..c5e393cceff3b 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py @@ -1,5 +1,9 @@ import FWCore.ParameterSet.Config as cms +def thresholds( wp ) : + return cms.vdouble([{"L": 1.03,"M":1.75,"T":2.61}.get(wp,1.e6), # unbiased + {"L":-0.48,"M":0.76,"T":1.83}.get(wp,1.e6)]) # ptbiased + lowPtGsfElectronSeeds = cms.EDProducer( "LowPtGsfElectronSeedProducer", tracks = cms.InputTag("generalTracks"), @@ -21,18 +25,14 @@ 'RecoEgamma/ElectronIdentification/data/LowPtElectrons/RunII_Fall17_LowPtElectrons_unbiased.xml.gz', 'RecoEgamma/ElectronIdentification/data/LowPtElectrons/RunII_Fall17_LowPtElectrons_displaced_pt_eta_biased.xml.gz', ]), - ModelThresholds = cms.vdouble([ - {"L": 1.03,"M":1.75,"T":2.61}["L"], # unbiased - {"L":-0.48,"M":0.76,"T":1.83}["L"], # ptbiased - ]), + ModelThresholds = thresholds("T"), PassThrough = cms.bool(False), UsePfTracks = cms.bool(True), MinPtThreshold = cms.double(0.5), MaxPtThreshold = cms.double(15.), ) -# copying from RecoParticleFlow/PFTracking/python/trackerDrivenElectronSeeds_cfi.py -# inFastSim jobs, trajectories are only available for the 'before mixing' track collections -# Therefore we let the seeds depend on the 'before mixing' generalTracks collection + +# Modifiers for FastSim from Configuration.Eras.Modifier_fastSim_cff import fastSim lowPtGsfElectronSeedsTmp = lowPtGsfElectronSeeds.clone(tracks = cms.InputTag("generalTracksBeforeMixing")) import FastSimulation.Tracking.ElectronSeedTrackRefFix_cfi @@ -43,5 +43,10 @@ _fastSim_lowPtGsfElectronSeeds.PreGsfLabel = cms.string("") fastSim.toReplaceWith(lowPtGsfElectronSeeds,_fastSim_lowPtGsfElectronSeeds) +# Modifiers for Phase2 from Configuration.Eras.Modifier_phase2_tracker_cff import phase2_tracker phase2_tracker.toModify(lowPtGsfElectronSeeds, TTRHBuilder = 'WithTrackAngle') + +# Modifiers for BParking +from Configuration.Eras.Modifier_BParking_cff import BParking +BParking.toModify(lowPtGsfElectronSeeds, ModelThresholds = thresholds("L") ) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py index 33c703bf03346..8db6b75606074 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSequence_cff.py @@ -21,11 +21,10 @@ lowPtGsfEleCkfTrackCandidates.TrajectoryBuilderPSet.refToPSet_ = 'lowPtGsfEleTrajectoryBuilder' lowPtGsfEleCkfTrackCandidates.src = 'lowPtGsfElectronSeeds' +# Modifiers for FastSim import FastSimulation.Tracking.electronCkfTrackCandidates_cff fastLowPtGsfTkfTrackCandidates = FastSimulation.Tracking.electronCkfTrackCandidates_cff.electronCkfTrackCandidates.clone(src = cms.InputTag("lowPtGsfElectronSeeds")) - - # GsfTracks from TrackingTools.GsfTracking.GsfElectronGsfFit_cff import * lowPtGsfEleFittingSmoother = GsfElectronFittingSmoother.clone() @@ -36,7 +35,6 @@ lowPtGsfEleGsfTracks.Fitter = 'lowPtGsfEleFittingSmoother' lowPtGsfEleGsfTracks.src = 'lowPtGsfEleCkfTrackCandidates' - # GsfPFRecTracks from RecoParticleFlow.PFTracking.pfTrackElec_cfi import * lowPtGsfElePfGsfTracks = pfTrackElec.clone() @@ -53,12 +51,11 @@ lowPtGsfElePfGsfTracks) lowPtGsfElectronSequence = cms.Sequence(lowPtGsfElectronTask) - +# Modifiers for FastSim from Configuration.Eras.Modifier_fastSim_cff import fastSim _fastSim_lowPtGsfElectronTask = lowPtGsfElectronTask.copy() _fastSim_lowPtGsfElectronTask.replace(lowPtGsfElectronSeeds, cms.Task(lowPtGsfElectronSeedsTmp,lowPtGsfElectronSeeds)) _fastSim_lowPtGsfElectronTask.replace(lowPtGsfEleCkfTrackCandidates, fastLowPtGsfTkfTrackCandidates) - fastSim.toReplaceWith(lowPtGsfElectronTask, _fastSim_lowPtGsfElectronTask) fastSim.toModify(lowPtGsfElePfTracks,TkColList = ['generalTracksBeforeMixing']) fastSim.toModify(lowPtGsfEleGsfTracks,src = cms.InputTag("fastLowPtGsfTkfTrackCandidates")) From 7a3eedffe79a134d3487b315e18e62a57028a9de Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Thu, 20 Dec 2018 12:53:00 +0100 Subject: [PATCH 14/22] fix white space, tidy up --- .../plugins/ElectronSeedTrackRefFix.cc | 121 ++++++++---------- .../plugins/ElectronSeedTrackRefFix.h | 29 ++--- 2 files changed, 63 insertions(+), 87 deletions(-) diff --git a/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc b/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc index 1e9a7c1faf3fa..acf7cd9201d62 100644 --- a/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc +++ b/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.cc @@ -1,32 +1,17 @@ +#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 -// - - - - -// -// constructors and destructor -// - - - +namespace { - - -namespace{ template - const edm::OrphanHandle > addVMToEvent(edm::Event& event,const edm::Handle& handle,std::vector values,const std::string& label) + const edm::OrphanHandle > addVMToEvent(edm::Event& event,const edm::Handle& handle, + std::vector values,const std::string& label) { auto vMap = std::make_unique >(); typename edm::ValueMap::Filler mapFiller(*vMap); @@ -34,16 +19,20 @@ namespace{ mapFiller.fill(); return event.put(std::move(vMap),label); } - template edm::Handle getHandle(const edm::Event& event,const edm::EDGetTokenT& token) + + template edm::Handle getHandle(const edm::Event& event, + const edm::EDGetTokenT& token) { edm::Handle handle; event.getByToken(token,handle); return handle; } + } ElectronSeedTrackRefFix::ElectronSeedTrackRefFix(const edm::ParameterSet& iConfig) { + // read parameters preidgsfLabel_ = iConfig.getParameter("PreGsfLabel"); preidLabel_ = iConfig.getParameter >("PreIdLabel"); @@ -63,71 +52,61 @@ ElectronSeedTrackRefFix::ElectronSeedTrackRefFix(const edm::ParameterSet& iConfi oldTracksToken_ = consumes(oldTracksTag_); newTracksToken_ = consumes(newTracksTag_); seedsToken_ = consumes(seedsTag_); - for(const auto& idTag: idsTag_){ idsToken_.emplace_back(consumes(idTag)); idMapToken_.emplace_back(consumes >(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) { - - auto oldTracks = getHandle(iEvent,oldTracksToken_); - auto newTracks = getHandle(iEvent,newTracksToken_); - auto iSeeds = getHandle(iEvent,seedsToken_); - - auto oSeeds = std::make_unique(); - for(unsigned int s = 0;ssize();++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 oldTracks = getHandle(iEvent,oldTracksToken_); + auto newTracks = getHandle(iEvent,newTracksToken_); + auto iSeeds = getHandle(iEvent,seedsToken_); + + auto oSeeds = std::make_unique(); + for(unsigned int s = 0;ssize();++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(); + for(unsigned int i = 0;isize();++i){ + oIds->push_back(iIds->at(i)); + reco::TrackRef newTrackRef(newTracks,oIds->back().trackRef().index()); + oIds->back().setTrack(newTrackRef); + } + const edm::OrphanHandle preIdProd = iEvent.put(std::move(oIds),preidLabel_[idNr]); - auto oIds = std::make_unique(); - for(unsigned int i = 0;isize();++i){ - oIds->push_back(iIds->at(i)); - reco::TrackRef newTrackRef(newTracks,oIds->back().trackRef().index()); - oIds->back().setTrack(newTrackRef); - } - const edm::OrphanHandle preIdProd = iEvent.put(std::move(oIds),preidLabel_[idNr]); + auto iIdMap = getHandle(iEvent,idMapToken_[idNr]); + std::vector values; + for(size_t trkNr = 0;trkNrsize();++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 - auto iIdMap = getHandle(iEvent,idMapToken_[idNr]); - std::vector values; - for(size_t trkNr = 0;trkNrsize();++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 } // ------------ 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; diff --git a/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h b/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h index df8f6a4e0d6e8..0db3a5c640991 100644 --- a/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h +++ b/FastSimulation/Tracking/plugins/ElectronSeedTrackRefFix.h @@ -1,37 +1,34 @@ -// system include files #ifndef FastSimulation_Tracking_ElectronSeedTrackRefFix_h #define FastSimulation_Tracking_ElectronSeedTrackRefFix_h - -#include - -// 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 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 --------------------------- + // member data + edm::EDGetTokenT newTracksToken_; edm::EDGetTokenT oldTracksToken_; edm::EDGetTokenT seedsToken_; std::vector > idsToken_; std::vector > > idMapToken_; - std::string preidgsfLabel_; std::vector preidLabel_; edm::InputTag oldTracksTag_; @@ -41,4 +38,4 @@ class ElectronSeedTrackRefFix : public edm::stream::EDProducer<> { }; -#endif +#endif // FastSimulation_Tracking_ElectronSeedTrackRefFix_h From 8c156c847dd87711f2db17ea7424711900121287 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Thu, 20 Dec 2018 12:54:25 +0100 Subject: [PATCH 15/22] move dphi,deta inside if clause; protect against chi2==0. --- .../plugins/LowPtGsfElectronSeedProducer.cc | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc index 18afbd1f5013a..973bf655201e8 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -288,16 +288,16 @@ void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::PFRecTrackR reco::PFClusterRef cluRef(clusters,iclu); - // Determine deta, dphi, dr - float deta = cluRef->positionREP().eta() - point.positionREP().eta(); - float dphi = reco::deltaPhi( cluRef->positionREP().phi(), point.positionREP().phi() ); + // Determine dR squared float dr2 = reco::deltaR2( cluRef->positionREP(), point.positionREP() ); if ( dr2 < info.dr2min ) { info.dr2min = dr2; info.cluRef = cluRef; - info.deta = deta; - info.dphi = dphi * pfTrackRef->trackRef()->charge(); + info.deta = cluRef->positionREP().eta() - point.positionREP().eta(); + info.dphi = + reco::deltaPhi( cluRef->positionREP().phi(), point.positionREP().phi() ) * + pfTrackRef->trackRef()->charge(); info.showerPos = point.position(); } @@ -379,17 +379,17 @@ void LowPtGsfElectronSeedProducer::propagateTrackToCalo( const reco::TrackRef& k particle.momentum().y(), particle.momentum().z()).unit() * shower_depth; - // Determine deta, dphi, dr - float deta = std::abs( cluRef->positionREP().eta() - showerPos.eta() ); - float dphi = std::abs( reco::deltaPhi( cluRef->positionREP().phi(), showerPos.phi() )); + // Determine dR squared float dr2 = reco::deltaR2( cluRef->positionREP(), showerPos ); // Find nearest ECAL cluster if ( dr2 < info.dr2min ) { info.dr2min = dr2; info.cluRef = cluRef; - info.deta = deta; - info.dphi = dphi * kfTrackRef->charge(); + info.deta = std::abs( cluRef->positionREP().eta() - showerPos.eta() ); + info.dphi = + std::abs( reco::deltaPhi( cluRef->positionREP().phi(), showerPos.phi() )) * + kfTrackRef->charge(); info.showerPos = showerPos; } @@ -464,8 +464,8 @@ bool LowPtGsfElectronSeedProducer::lightGsfTracking( reco::PreId& preId, if ( !traj2.isValid() ) { return false; } // Set PreId content - float chi2Ratio = traj2.chiSquared() / trackRef->chi2(); - float gsfReducedChi2 = chi2Ratio * trackRef->normalizedChi2(); + float chi2Ratio = trackRef->chi2() > 0. ? traj2.chiSquared() / trackRef->chi2() : -1.; + float gsfReducedChi2 = chi2Ratio > -1. ? chi2Ratio * trackRef->normalizedChi2() : -1.; float ptOut = traj2.firstMeasurement().updatedState().globalMomentum().perp(); float ptIn = traj2.lastMeasurement().updatedState().globalMomentum().perp(); float gsfDpt = ( ptIn > 0 ) ? fabs( ptOut - ptIn ) / ptIn : 0.; From 7f6c948e253648536fea5a040cb631478c640584 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Wed, 9 Jan 2019 22:30:05 +0100 Subject: [PATCH 16/22] rename to bParking (lower case) --- .../{Modifier_BParking_cff.py => Modifier_bParking_cff.py} | 2 +- Configuration/StandardSequences/python/Eras.py | 2 +- .../python/lowPtGsfElectronSeeds_cfi.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename Configuration/Eras/python/{Modifier_BParking_cff.py => Modifier_bParking_cff.py} (61%) diff --git a/Configuration/Eras/python/Modifier_BParking_cff.py b/Configuration/Eras/python/Modifier_bParking_cff.py similarity index 61% rename from Configuration/Eras/python/Modifier_BParking_cff.py rename to Configuration/Eras/python/Modifier_bParking_cff.py index 93950a0a34927..128f49ffc3737 100644 --- a/Configuration/Eras/python/Modifier_BParking_cff.py +++ b/Configuration/Eras/python/Modifier_bParking_cff.py @@ -1,3 +1,3 @@ import FWCore.ParameterSet.Config as cms -BParking = cms.Modifier() +bParking = cms.Modifier() diff --git a/Configuration/StandardSequences/python/Eras.py b/Configuration/StandardSequences/python/Eras.py index 78367504a291b..d3e1ddaa1b7b5 100644 --- a/Configuration/StandardSequences/python/Eras.py +++ b/Configuration/StandardSequences/python/Eras.py @@ -60,7 +60,7 @@ def __init__(self): 'run2_nanoAOD_94XMiniAODv1', 'run2_nanoAOD_94XMiniAODv2', 'run2_nanoAOD_94X2016', 'run2_miniAOD_devel', 'run2_nanoAOD_102Xv1', 'hcalHardcodeConditions', 'hcalSkipPacker', - 'BParking'] + 'bParking'] internalUseModChains = ['run2_2017_noTrackingModifier'] diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py index c5e393cceff3b..e5542483daa08 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py @@ -48,5 +48,5 @@ def thresholds( wp ) : phase2_tracker.toModify(lowPtGsfElectronSeeds, TTRHBuilder = 'WithTrackAngle') # Modifiers for BParking -from Configuration.Eras.Modifier_BParking_cff import BParking -BParking.toModify(lowPtGsfElectronSeeds, ModelThresholds = thresholds("L") ) +from Configuration.Eras.Modifier_bParking_cff import bParking +bParking.toModify(lowPtGsfElectronSeeds, ModelThresholds = thresholds("L") ) From 4a196ae818a5ab47da1e9ac139fd4becf24e6113 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Wed, 9 Jan 2019 23:11:19 +0100 Subject: [PATCH 17/22] moved unncessary casts, changed others to c++ casts --- .../LowPtGsfElectronSeedHeavyObjectCache.cc | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc index c3b0b897c1f42..26bde5e66d38f 100644 --- a/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc +++ b/RecoEgamma/EgammaElectronProducers/src/LowPtGsfElectronSeedHeavyObjectCache.cc @@ -56,56 +56,55 @@ namespace lowptgsfeleseed { // Tracks reco::TrackRef trk = ecal.trackRef(); if ( trk.isNonnull() ) { - trk_pt_ = float(trk->pt()); - trk_eta_ = float(trk->eta()); - trk_phi_ = float(trk->phi()); - trk_p_ = float(trk->p()); - trk_nhits_ = float(trk->found()); - trk_high_quality_ = float(trk->quality(reco::TrackBase::qualityByName("highPurity"))); - trk_chi2red_ = float(trk->normalizedChi2()); + trk_pt_ = trk->pt(); + trk_eta_ = trk->eta(); + trk_phi_ = trk->phi(); + trk_p_ = trk->p(); + trk_nhits_ = static_cast(trk->found()); + trk_high_quality_ = static_cast(trk->quality(reco::TrackBase::qualityByName("highPurity"))); + trk_chi2red_ = trk->normalizedChi2(); if ( trk->dxyError() > 0. ) { - trk_dxy_sig_ = float( trk->dxy(spot) / trk->dxyError() ); + trk_dxy_sig_ = trk->dxy(spot) / trk->dxyError(); } } // Rho - rho_ = float(rho); + rho_ = static_cast(rho); // ECAL clusters reco::PFClusterRef ecal_clu = ecal.clusterRef(); if ( ecal_clu.isNonnull() ) { - ktf_ecal_cluster_e_ = float(ecal_clu->energy()); - ktf_ecal_cluster_deta_ = float(ecal.geomMatching()[0]); - ktf_ecal_cluster_dphi_ = float(ecal.geomMatching()[1]); - ktf_ecal_cluster_e3x3_ = float(tools.e3x3(*ecal_clu)); - ktf_ecal_cluster_e5x5_ = float(tools.e5x5(*ecal_clu)); + ktf_ecal_cluster_e_ = ecal_clu->energy(); + ktf_ecal_cluster_deta_ = ecal.geomMatching()[0]; + ktf_ecal_cluster_dphi_ = ecal.geomMatching()[1]; + ktf_ecal_cluster_e3x3_ = tools.e3x3(*ecal_clu); + ktf_ecal_cluster_e5x5_ = tools.e5x5(*ecal_clu); auto covs = tools.localCovariances(*ecal_clu); - ktf_ecal_cluster_covEtaEta_ = float(covs[0]); - ktf_ecal_cluster_covEtaPhi_ = float(covs[1]); - ktf_ecal_cluster_covPhiPhi_ = float(covs[2]); + ktf_ecal_cluster_covEtaEta_ = covs[0]; + ktf_ecal_cluster_covEtaPhi_ = covs[1]; + ktf_ecal_cluster_covPhiPhi_ = covs[2]; if ( ktf_ecal_cluster_e_ > 0. ) { - ktf_ecal_cluster_r9_ = float( ktf_ecal_cluster_e3x3_ / ktf_ecal_cluster_e_ ); + ktf_ecal_cluster_r9_ = ktf_ecal_cluster_e3x3_ / ktf_ecal_cluster_e_; } if ( ktf_ecal_cluster_e5x5_ > 0. ) { - ktf_ecal_cluster_circularity_ = float( 1. - tools.e1x5(*ecal_clu) / - ktf_ecal_cluster_e5x5_); + ktf_ecal_cluster_circularity_ = 1. - tools.e1x5(*ecal_clu) / ktf_ecal_cluster_e5x5_; } else { - ktf_ecal_cluster_circularity_ = float(-0.1); + ktf_ecal_cluster_circularity_ = -0.1; } } // HCAL clusters reco::PFClusterRef hcal_clu = hcal.clusterRef(); if ( hcal_clu.isNonnull() ) { - ktf_ecal_cluster_e_ = float(hcal_clu->energy()); - ktf_hcal_cluster_deta_ = float(hcal.geomMatching()[0]); - ktf_hcal_cluster_dphi_ = float(hcal.geomMatching()[1]); + ktf_ecal_cluster_e_ = hcal_clu->energy(); + ktf_hcal_cluster_deta_ = hcal.geomMatching()[0]; + ktf_hcal_cluster_dphi_ = hcal.geomMatching()[1]; } // PreId - preid_gsf_dpt_ = float(ecal.dpt()); - preid_trk_gsf_chiratio_ = float(ecal.chi2Ratio()); - preid_gsf_chi2red_ = float(ecal.gsfChi2()); + preid_gsf_dpt_ = ecal.dpt(); + preid_trk_gsf_chiratio_ = ecal.chi2Ratio(); + preid_gsf_chi2red_ = ecal.gsfChi2(); }; From b912e0e109c1670f5db376269ba688660f081e82 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Wed, 9 Jan 2019 23:51:19 +0100 Subject: [PATCH 18/22] moved track fitter and cloner and builder into loop() method --- .../plugins/LowPtGsfElectronSeedProducer.cc | 44 +++++++++++-------- .../plugins/LowPtGsfElectronSeedProducer.h | 4 ++ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc index 973bf655201e8..1f8c71700ade3 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.cc @@ -27,9 +27,7 @@ #include "RecoTracker/TransientTrackingRecHit/interface/TkClonerImpl.h" #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h" #include "TrackingTools/PatternTools/interface/Trajectory.h" -#include "TrackingTools/PatternTools/interface/TrajectorySmoother.h" #include "TrackingTools/Records/interface/TransientRecHitRecord.h" -#include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h" #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h" #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h" #include "TMath.h" @@ -38,7 +36,13 @@ // LowPtGsfElectronSeedProducer::LowPtGsfElectronSeedProducer( const edm::ParameterSet& conf, const lowptgsfeleseed::HeavyObjectCache* ) : + field_(), + fitterPtr_(), + smootherPtr_(), + kfTracks_(), + pfTracks_(), ecalClusters_{consumes(conf.getParameter("ecalClusters"))}, + hcalClusters_(), ebRecHits_{consumes(conf.getParameter("EBRecHits"))}, eeRecHits_{consumes(conf.getParameter("EERecHits"))}, rho_(consumes(conf.getParameter("rho"))), @@ -158,6 +162,23 @@ void LowPtGsfElectronSeedProducer::loop( const edm::Handle< std::vector >& ha edm::Handle spot; event.getByToken(beamSpot_,spot); + // Track fitter + edm::ESHandle fitter; + setup.get().get(fitter_,fitter); + fitterPtr_ = fitter->clone(); + + // Track smoother + edm::ESHandle smoother; + setup.get().get(smoother_,smoother); + smootherPtr_.reset(smoother->clone()); + + // RecHit cloner + edm::ESHandle builder; + setup.get().get(builder_,builder); + TkClonerImpl hitCloner = static_cast(builder.product())->cloner(); + fitterPtr_->setHitCloner(&hitCloner); + smootherPtr_->setHitCloner(&hitCloner); + // ECAL clusters edm::Handle ecalClusters; event.getByToken(ecalClusters_,ecalClusters); @@ -420,21 +441,6 @@ bool LowPtGsfElectronSeedProducer::lightGsfTracking( reco::PreId& preId, const reco::ElectronSeed& seed, const edm::EventSetup& setup ) { - - edm::ESHandle fitter; - setup.get().get(fitter_,fitter); - std::unique_ptr fitterPtr = fitter->clone(); - - edm::ESHandle smoother; - setup.get().get(smoother_,smoother); - std::unique_ptr smootherPtr; - smootherPtr.reset(smoother->clone()); - - edm::ESHandle builder; - setup.get().get(builder_,builder); - TkClonerImpl hitCloner = static_cast(builder.product())->cloner(); - fitterPtr->setHitCloner(&hitCloner); - smootherPtr->setHitCloner(&hitCloner); Trajectory::ConstRecHitContainer hits; for ( unsigned int ihit = 0; ihit < trackRef->recHitsSize(); ++ihit ) { @@ -458,9 +464,9 @@ bool LowPtGsfElectronSeedProducer::lightGsfTracking( reco::PreId& preId, *hits[0]->surface() ); // Track fitted and smoothed under electron hypothesis - Trajectory traj1 = fitterPtr->fitOne( seed, hits, tsos ); + Trajectory traj1 = fitterPtr_->fitOne( seed, hits, tsos ); if ( !traj1.isValid() ) { return false; } - Trajectory traj2 = smootherPtr->trajectory(traj1); + Trajectory traj2 = smootherPtr_->trajectory(traj1); if ( !traj2.isValid() ) { return false; } // Set PreId content diff --git a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h index a494e13ed4d06..3e97411c3ff1f 100644 --- a/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h +++ b/RecoEgamma/EgammaElectronProducers/plugins/LowPtGsfElectronSeedProducer.h @@ -20,6 +20,8 @@ #include "MagneticField/Engine/interface/MagneticField.h" #include "RecoEcal/EgammaCoreTools/interface/EcalClusterLazyTools.h" #include "RecoEgamma/EgammaElectronProducers/interface/LowPtGsfElectronSeedHeavyObjectCache.h" +#include "TrackingTools/PatternTools/interface/TrajectorySmoother.h" +#include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h" class LowPtGsfElectronSeedProducer final : public edm::stream::EDProducer< edm::GlobalCache > { @@ -109,6 +111,8 @@ class LowPtGsfElectronSeedProducer final : public edm::stream::EDProducer< edm:: private: // member data edm::ESHandle field_; + std::unique_ptr fitterPtr_; + std::unique_ptr smootherPtr_; edm::EDGetTokenT kfTracks_; edm::EDGetTokenT pfTracks_; const edm::EDGetTokenT ecalClusters_; From 82d3b67e244cfbff74d64347c9493ba756f8c65e Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Fri, 11 Jan 2019 14:16:33 +0100 Subject: [PATCH 19/22] standard pT>1.0, bParking pT>0.5 --- .../python/lowPtGsfElectronSeeds_cfi.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py index e5542483daa08..214c5555c2dd9 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py @@ -28,7 +28,7 @@ def thresholds( wp ) : ModelThresholds = thresholds("T"), PassThrough = cms.bool(False), UsePfTracks = cms.bool(True), - MinPtThreshold = cms.double(0.5), + MinPtThreshold = cms.double(1.0), MaxPtThreshold = cms.double(15.), ) @@ -50,3 +50,4 @@ def thresholds( wp ) : # Modifiers for BParking from Configuration.Eras.Modifier_bParking_cff import bParking bParking.toModify(lowPtGsfElectronSeeds, ModelThresholds = thresholds("L") ) +bParking.toModify(lowPtGsfElectronSeeds, MinPtThreshold = 0.5) From 2a1ad40a6cdc091c5660a1a8b353313d42426f89 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Mon, 21 Jan 2019 20:32:54 +0100 Subject: [PATCH 20/22] use full ECAL RecHit collection --- .../python/lowPtGsfElectronSeeds_cfi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py index 214c5555c2dd9..3b9ea16ad0a9d 100644 --- a/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py +++ b/RecoEgamma/EgammaElectronProducers/python/lowPtGsfElectronSeeds_cfi.py @@ -10,8 +10,8 @@ def thresholds( wp ) : pfTracks = cms.InputTag("lowPtGsfElePfTracks"), ecalClusters = cms.InputTag("particleFlowClusterECAL"), hcalClusters = cms.InputTag("particleFlowClusterHCAL"), - EBRecHits = cms.InputTag('reducedEcalRecHitsEB'), - EERecHits = cms.InputTag('reducedEcalRecHitsEE'), + EBRecHits = cms.InputTag("ecalRecHit","EcalRecHitsEB"), + EERecHits = cms.InputTag("ecalRecHit","EcalRecHitsEE"), rho = cms.InputTag('fixedGridRhoFastjetAllTmp'), BeamSpot = cms.InputTag("offlineBeamSpot"), Fitter = cms.string('GsfTrajectoryFitter_forPreId'), From 8bc32f82340655cd5f9a9328cafd4b79bd9e5e41 Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Mon, 21 Jan 2019 20:33:45 +0100 Subject: [PATCH 21/22] move lowPtGsfElectronSequence from highlevelreco to egammaHighLevelRecoPrePF --- RecoEgamma/Configuration/python/RecoEgamma_cff.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/RecoEgamma/Configuration/python/RecoEgamma_cff.py b/RecoEgamma/Configuration/python/RecoEgamma_cff.py index e0a1ad785cb57..2561a6ef56183 100644 --- a/RecoEgamma/Configuration/python/RecoEgamma_cff.py +++ b/RecoEgamma/Configuration/python/RecoEgamma_cff.py @@ -1,6 +1,7 @@ import FWCore.ParameterSet.Config as cms from RecoEgamma.EgammaElectronProducers.electronSequence_cff import * +from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSequence_cff import * from RecoEgamma.EgammaElectronProducers.uncleanedOnlyElectronSequence_cff import * from RecoEgamma.EgammaPhotonProducers.photonSequence_cff import * from RecoEgamma.EgammaPhotonProducers.conversionSequence_cff import * @@ -28,7 +29,7 @@ fastSim.toReplaceWith(egammaGlobalReco, _fastSim_egammaGlobalReco) egammareco = cms.Sequence(electronSequence*conversionSequence*photonSequence) -egammaHighLevelRecoPrePF = cms.Sequence(gsfEcalDrivenElectronSequence*uncleanedOnlyElectronSequence*conversionSequence*photonSequence) +egammaHighLevelRecoPrePF = cms.Sequence(gsfEcalDrivenElectronSequence*uncleanedOnlyElectronSequence*conversionSequence*photonSequence*lowPtGsfElectronSequence) # not commisoned and not relevant in FastSim (?): fastSim.toReplaceWith(egammareco, egammareco.copyAndExclude([conversionSequence])) fastSim.toReplaceWith(egammaHighLevelRecoPrePF,egammaHighLevelRecoPrePF.copyAndExclude([uncleanedOnlyElectronSequence,conversionSequence])) From f6a640bfd94daee5433844090d332e301728bb5e Mon Sep 17 00:00:00 2001 From: Robert Bainbridge Date: Mon, 21 Jan 2019 20:34:05 +0100 Subject: [PATCH 22/22] move lowPtGsfElectronSequence from highlevelreco to egammaHighLevelRecoPrePF --- .../StandardSequences/python/Reconstruction_cff.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Configuration/StandardSequences/python/Reconstruction_cff.py b/Configuration/StandardSequences/python/Reconstruction_cff.py index 118c92c6d659a..1440a5910a589 100644 --- a/Configuration/StandardSequences/python/Reconstruction_cff.py +++ b/Configuration/StandardSequences/python/Reconstruction_cff.py @@ -51,9 +51,6 @@ # Cosmic During Collisions from RecoTracker.SpecialSeedGenerators.cosmicDC_cff import * -# Low pT electrons -from RecoEgamma.EgammaElectronProducers.lowPtGsfElectronSequence_cff import * - localreco = cms.Sequence(bunchSpacingProducer+trackerlocalreco+muonlocalreco+calolocalreco+castorreco) localreco_HcalNZS = cms.Sequence(bunchSpacingProducer+trackerlocalreco+muonlocalreco+calolocalrecoNZS+castorreco) @@ -156,8 +153,7 @@ recoPFMET* PFTau* reducedRecHits* - cosmicDCTracksSeq* - lowPtGsfElectronSequence + cosmicDCTracksSeq ) # AA data with pp reco