Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use esConsumes in TSGFromL2Muon #35327

Merged
merged 7 commits into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions FastSimulation/Muons/plugins/FastTSGFromL2Muon.cc
Expand Up @@ -17,7 +17,7 @@

#include <set>

FastTSGFromL2Muon::FastTSGFromL2Muon(const edm::ParameterSet& cfg) : theConfig(cfg) {
FastTSGFromL2Muon::FastTSGFromL2Muon(const edm::ParameterSet& cfg) {
produces<L3MuonTrajectorySeedCollection>();

edm::ParameterSet serviceParameters = cfg.getParameter<edm::ParameterSet>("ServiceParameters");
Expand All @@ -28,15 +28,14 @@ FastTSGFromL2Muon::FastTSGFromL2Muon(const edm::ParameterSet& cfg) : theConfig(c
theSeedCollectionLabels = cfg.getParameter<std::vector<edm::InputTag> >("SeedCollectionLabels");
theSimTrackCollectionLabel = cfg.getParameter<edm::InputTag>("SimTrackCollectionLabel");
// useTFileService_ = cfg.getUntrackedParameter<bool>("UseTFileService",false);
edm::ParameterSet regionBuilderPSet = cfg.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
theRegionBuilder = std::make_unique<MuonTrackingRegionBuilder>(regionBuilderPSet, consumesCollector());
}

FastTSGFromL2Muon::~FastTSGFromL2Muon() {}

void FastTSGFromL2Muon::beginRun(edm::Run const& run, edm::EventSetup const& es) {
//region builder
edm::ParameterSet regionBuilderPSet = theConfig.getParameter<edm::ParameterSet>("MuonTrackingRegionBuilder");
edm::ConsumesCollector iC = consumesCollector();
theRegionBuilder = new MuonTrackingRegionBuilder(regionBuilderPSet, iC);

/*
if(useTFileService_) {
Expand Down
3 changes: 1 addition & 2 deletions FastSimulation/Muons/plugins/FastTSGFromL2Muon.h
Expand Up @@ -37,7 +37,6 @@ class FastTSGFromL2Muon : public edm::stream::EDProducer<> {
const SimTrack& theSimTrack);

private:
edm::ParameterSet theConfig;
edm::InputTag theSimTrackCollectionLabel;
edm::InputTag theL2CollectionLabel;
std::vector<edm::InputTag> theSeedCollectionLabels;
Expand All @@ -46,7 +45,7 @@ class FastTSGFromL2Muon : public edm::stream::EDProducer<> {

MuonServiceProxy* theService;
double thePtCut;
MuonTrackingRegionBuilder* theRegionBuilder;
std::unique_ptr<MuonTrackingRegionBuilder> theRegionBuilder;

// TH1F* h_nSeedPerTrack;
// TH1F* h_nGoodSeedPerTrack;
Expand Down
33 changes: 7 additions & 26 deletions FastSimulation/Muons/plugins/FastTSGFromPropagation.cc
Expand Up @@ -52,7 +52,6 @@ FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet& iConfig,
const MuonServiceProxy* service,
edm::ConsumesCollector& iC)
: theCategory("FastSimulation|Muons|FastTSGFromPropagation"),
theTracker(),
theNavigation(),
theService(service),
theUpdator(),
Expand All @@ -65,7 +64,10 @@ FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet& iConfig,
iC.consumes<FastTrackerRecHitCombinationCollection>(theConfig.getParameter<edm::InputTag>("HitProducer"))),
beamSpot_(iC.consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
theMeasurementTrackerEventToken_(
iC.consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent"))) {}
iC.consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
theGeometryToken(iC.esConsumes<edm::Transition::BeginRun>()),
theTTRHBuilderToken(iC.esConsumes<edm::Transition::BeginRun>(edm::ESInputTag("", "WithTrackAngle"))),
theTrackerToken(iC.esConsumes()) {}

FastTSGFromPropagation::~FastTSGFromPropagation() { LogTrace(theCategory) << " FastTSGFromPropagation dtor called "; }

Expand Down Expand Up @@ -320,8 +322,6 @@ void FastTSGFromPropagation::init(const MuonServiceProxy* service) {

theEstimator = std::make_unique<Chi2MeasurementEstimator>(theMaxChi2);

theCacheId_MT = 0;

theCacheId_TG = 0;

thePropagatorName = theConfig.getParameter<std::string>("Propagator");
Expand All @@ -347,14 +347,9 @@ void FastTSGFromPropagation::init(const MuonServiceProxy* service) {
theErrorMatrixAdjuster.reset();
}

theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
theNavigation = std::make_unique<DirectTrackerNavigation>(theTracker);

edm::ESHandle<TrackerGeometry> geometry;
theService->eventSetup().get<TrackerDigiGeometryRecord>().get(geometry);
theGeometry = &(*geometry);
theGeometry = &theService->eventSetup().getData(theGeometryToken);

theService->eventSetup().get<TransientRecHitRecord>().get("WithTrackAngle", theTTRHBuilder);
theTTRHBuilder = theService->eventSetup().getHandle(theTTRHBuilderToken);
}

void FastTSGFromPropagation::setEvent(const edm::Event& iEvent) {
Expand All @@ -364,30 +359,16 @@ void FastTSGFromPropagation::setEvent(const edm::Event& iEvent) {
iEvent.getByToken(theSimTrackCollectionToken_, theSimTracks);
iEvent.getByToken(recHitCombinationsToken_, recHitCombinations);

unsigned long long newCacheId_MT = theService->eventSetup().get<CkfComponentsRecord>().cacheIdentifier();

if (theUpdateStateFlag && newCacheId_MT != theCacheId_MT) {
LogTrace(theCategory) << "Measurment Tracker Geometry changed!";
theCacheId_MT = newCacheId_MT;
theService->eventSetup().get<CkfComponentsRecord>().get(theMeasTracker);
}

if (theUpdateStateFlag) {
iEvent.getByToken(theMeasurementTrackerEventToken_, theMeasTrackerEvent);
}

bool trackerGeomChanged = false;

unsigned long long newCacheId_TG = theService->eventSetup().get<TrackerRecoGeometryRecord>().cacheIdentifier();

if (newCacheId_TG != theCacheId_TG) {
LogTrace(theCategory) << "Tracker Reco Geometry changed!";
theCacheId_TG = newCacheId_TG;
theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
trackerGeomChanged = true;
}

if (trackerGeomChanged && theTracker.product()) {
auto theTracker = theService->eventSetup().getHandle(theTrackerToken);
theNavigation = std::make_unique<DirectTrackerNavigation>(theTracker);
}
}
Expand Down
15 changes: 10 additions & 5 deletions FastSimulation/Muons/plugins/FastTSGFromPropagation.h
Expand Up @@ -44,6 +44,9 @@ struct TrajectoryStateTransform;
class SimTrack;
class TrackerGeometry;
class TrackerTopology;
class TransientRecHitRecord;
class CkfComponentsRecord;
class TrackerRecoGeometryRecord;

class FastTSGFromPropagation : public TrackerSeedGenerator {
public:
Expand Down Expand Up @@ -123,15 +126,10 @@ class FastTSGFromPropagation : public TrackerSeedGenerator {
}
};

unsigned long long theCacheId_MT;
unsigned long long theCacheId_TG;

std::string theCategory;

edm::ESHandle<GeometricSearchTracker> theTracker;

edm::ESHandle<MeasurementTracker> theMeasTracker;

std::unique_ptr<const DirectTrackerNavigation> theNavigation;

const TrackerGeometry* theGeometry;
Expand Down Expand Up @@ -175,6 +173,13 @@ class FastTSGFromPropagation : public TrackerSeedGenerator {
edm::Handle<FastTrackerRecHitCombinationCollection> recHitCombinations;
edm::Handle<MeasurementTrackerEvent> theMeasTrackerEvent;
edm::ESHandle<TransientTrackingRecHitBuilder> theTTRHBuilder;

//from init
edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> theGeometryToken;
edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> theTTRHBuilderToken;

//from setEvent
edm::ESGetToken<GeometricSearchTracker, TrackerRecoGeometryRecord> theTrackerToken;
};

#endif
3 changes: 3 additions & 0 deletions RecoMuon/TrackerSeedGenerator/interface/TrackerSeedCleaner.h
Expand Up @@ -16,6 +16,7 @@
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
#include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
#include "TrackingTools/Records/interface/TransientRecHitRecord.h"
#include "RecoTracker/TkTrackingRegions/interface/RectangularEtaPhiTrackingRegion.h"
#include "RecoMuon/TrackerSeedGenerator/interface/RedundantSeedCleaner.h"
#include "DataFormats/BeamSpot/interface/BeamSpot.h"
Expand Down Expand Up @@ -47,6 +48,7 @@ class TrackerSeedCleaner {
usePt_Cleaner = pset.getParameter<bool>("ptCleaner");
cleanBySharedHits = pset.getParameter<bool>("cleanerFromSharedHits");
beamspotToken_ = iC.consumes<reco::BeamSpot>(theBeamSpotTag);
theTTRHBuilderToken = iC.esConsumes(edm::ESInputTag("", builderName_));
}

///intizialization
Expand All @@ -70,6 +72,7 @@ class TrackerSeedCleaner {

std::string builderName_;
edm::ESHandle<TransientTrackingRecHitBuilder> theTTRHBuilder;
edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> theTTRHBuilderToken;
bool useDirection_Cleaner, usePt_Cleaner, cleanBySharedHits;
};

Expand Down
11 changes: 3 additions & 8 deletions RecoMuon/TrackerSeedGenerator/plugins/TSGForRoadSearch.cc
Expand Up @@ -23,7 +23,8 @@
#include <TrackingTools/KalmanUpdators/interface/KFUpdator.h>
#include "TrackingTools/GeomPropagators/interface/StateOnTrackerBound.h"

TSGForRoadSearch::TSGForRoadSearch(const edm::ParameterSet &par, edm::ConsumesCollector &iC) {
TSGForRoadSearch::TSGForRoadSearch(const edm::ParameterSet &par, edm::ConsumesCollector &iC)
: theGeometricSearchTrackerToken(iC.esConsumes()) {
theOption = par.getParameter<unsigned int>("option");
theCopyMuonRecHit = par.getParameter<bool>("copyMuonRecHit");

Expand Down Expand Up @@ -69,13 +70,7 @@ void TSGForRoadSearch::init(const MuonServiceProxy *service) { theProxyService =

void TSGForRoadSearch::setEvent(const edm::Event &event) {
//get the measurementtracker
if (theManySeeds) {
theProxyService->eventSetup().get<CkfComponentsRecord>().get(theMeasurementTracker);
if (!theMeasurementTracker.isValid()) /*abort*/ {
edm::LogError(theCategory) << "measurement tracker geometry not found ";
}
}
theProxyService->eventSetup().get<TrackerRecoGeometryRecord>().get(theGeometricSearchTracker);
theGeometricSearchTracker = theProxyService->eventSetup().getHandle(theGeometricSearchTrackerToken);

edm::Handle<MeasurementTrackerEvent> data;
event.getByToken(theMeasurementTrackerEventToken, data);
Expand Down
5 changes: 2 additions & 3 deletions RecoMuon/TrackerSeedGenerator/plugins/TSGForRoadSearch.h
Expand Up @@ -41,6 +41,7 @@ class TrackingRegion;
class MuonServiceProxy;
class TrajectoryStateUpdator;
class TrackerTopology;
class TrackerRecoGeometryRecord;

class TSGForRoadSearch : public TrackerSeedGenerator {
public:
Expand Down Expand Up @@ -88,8 +89,8 @@ class TSGForRoadSearch : public TrackerSeedGenerator {
std::vector<TrajectorySeed> &result) const;
edm::ParameterSet theConfig;

edm::ESHandle<MeasurementTracker> theMeasurementTracker;
edm::ESHandle<GeometricSearchTracker> theGeometricSearchTracker;
edm::ESGetToken<GeometricSearchTracker, TrackerRecoGeometryRecord> theGeometricSearchTrackerToken;

edm::InputTag theMeasurementTrackerEventTag;
edm::EDGetTokenT<MeasurementTrackerEvent> theMeasurementTrackerEventToken;
Expand All @@ -102,9 +103,7 @@ class TSGForRoadSearch : public TrackerSeedGenerator {
bool theCopyMuonRecHit;
bool theManySeeds;
std::string thePropagatorName;
edm::ESHandle<Propagator> theProp;
std::string thePropagatorCompatibleName;
edm::ESHandle<Propagator> thePropCompatible;
Chi2MeasurementEstimator *theChi2Estimator;
std::string theCategory;

Expand Down
6 changes: 3 additions & 3 deletions RecoMuon/TrackerSeedGenerator/plugins/TSGFromL2Muon.cc
Expand Up @@ -42,6 +42,8 @@ TSGFromL2Muon::TSGFromL2Muon(const edm::ParameterSet& cfg) {
//L2 collection
theL2CollectionLabel = cfg.getParameter<edm::InputTag>("MuonCollectionLabel");
l2muonToken = consumes<reco::TrackCollection>(theL2CollectionLabel);

theTTopoToken = esConsumes();
}

TSGFromL2Muon::~TSGFromL2Muon() = default;
Expand All @@ -59,9 +61,7 @@ void TSGFromL2Muon::produce(edm::Event& ev, const edm::EventSetup& es) {
auto result = std::make_unique<L3MuonTrajectorySeedCollection>();

//Retrieve tracker topology from geometry
edm::ESHandle<TrackerTopology> tTopoHand;
es.get<TrackerTopologyRcd>().get(tTopoHand);
const TrackerTopology* tTopo = tTopoHand.product();
const TrackerTopology* tTopo = &es.getData(theTTopoToken);

//intialize tools
theService->update(es);
Expand Down
2 changes: 2 additions & 0 deletions RecoMuon/TrackerSeedGenerator/plugins/TSGFromL2Muon.h
Expand Up @@ -17,6 +17,7 @@ class MuonServiceProxy;
class TrackerSeedGenerator;
class MuonTrackingRegionBuilder;
class TrackerSeedCleaner;
class TrackerTopologyRcd;

//
// Generate tracker seeds from L2 muons
Expand All @@ -37,5 +38,6 @@ class TSGFromL2Muon : public edm::stream::EDProducer<> {
std::unique_ptr<TrackerSeedGenerator> theTkSeedGenerator;
std::unique_ptr<TrackerSeedCleaner> theSeedCleaner;
edm::EDGetTokenT<reco::TrackCollection> l2muonToken;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> theTTopoToken;
};
#endif
25 changes: 3 additions & 22 deletions RecoMuon/TrackerSeedGenerator/plugins/TSGFromPropagation.cc
Expand Up @@ -33,7 +33,6 @@ TSGFromPropagation::TSGFromPropagation(const edm::ParameterSet& iConfig,
edm::ConsumesCollector& iC,
const MuonServiceProxy* service)
: theCategory("Muon|RecoMuon|TSGFromPropagation"),
theMeasTrackerName(iConfig.getParameter<std::string>("MeasurementTrackerName")),
theService(service),
theMaxChi2(iConfig.getParameter<double>("MaxChi2")),
theFixedErrorRescaling(iConfig.getParameter<double>("ErrorRescaling")),
Expand Down Expand Up @@ -61,7 +60,8 @@ TSGFromPropagation::TSGFromPropagation(const edm::ParameterSet& iConfig,
theErrorMatrixPset(iConfig.getParameter<edm::ParameterSet>("errorMatrixPset")),
theBeamSpotToken(iC.consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
theMeasurementTrackerEventToken(
iC.consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent"))) {}
iC.consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
theTrackerToken(iC.esConsumes()) {}

TSGFromPropagation::~TSGFromPropagation() { LogTrace(theCategory) << " TSGFromPropagation dtor called "; }

Expand Down Expand Up @@ -157,8 +157,6 @@ void TSGFromPropagation::init(const MuonServiceProxy* service) {

theEstimator = std::make_unique<Chi2MeasurementEstimator>(theMaxChi2);

theCacheId_MT = 0;

theCacheId_TG = 0;

theService = service;
Expand All @@ -168,38 +166,21 @@ void TSGFromPropagation::init(const MuonServiceProxy* service) {
if (theResetMethod == ResetMethod::matrix && !theErrorMatrixPset.empty()) {
theErrorMatrixAdjuster = std::make_unique<MuonErrorMatrix>(theErrorMatrixPset);
}

theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
theNavigation = std::make_unique<DirectTrackerNavigation>(theTracker);
}

void TSGFromPropagation::setEvent(const edm::Event& iEvent) {
iEvent.getByToken(theBeamSpotToken, beamSpot);

unsigned long long newCacheId_MT = theService->eventSetup().get<CkfComponentsRecord>().cacheIdentifier();

if (theUpdateStateFlag && newCacheId_MT != theCacheId_MT) {
LogTrace(theCategory) << "Measurment Tracker Geometry changed!";
theCacheId_MT = newCacheId_MT;
theService->eventSetup().get<CkfComponentsRecord>().get(theMeasTrackerName, theMeasTracker);
}

if (theUpdateStateFlag) {
iEvent.getByToken(theMeasurementTrackerEventToken, theMeasTrackerEvent);
}

bool trackerGeomChanged = false;

unsigned long long newCacheId_TG = theService->eventSetup().get<TrackerRecoGeometryRecord>().cacheIdentifier();

if (newCacheId_TG != theCacheId_TG) {
LogTrace(theCategory) << "Tracker Reco Geometry changed!";
theCacheId_TG = newCacheId_TG;
theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
trackerGeomChanged = true;
}

if (trackerGeomChanged && (theTracker.product() != nullptr)) {
edm::ESHandle<GeometricSearchTracker> theTracker = theService->eventSetup().getHandle(theTrackerToken);
theNavigation = std::make_unique<DirectTrackerNavigation>(theTracker);
}
}
Expand Down
7 changes: 2 additions & 5 deletions RecoMuon/TrackerSeedGenerator/plugins/TSGFromPropagation.h
Expand Up @@ -29,6 +29,7 @@ class GeometricSearchTracker;
class DirectTrackerNavigation;
struct TrajectoryStateTransform;
class TrackerTopology;
class TrackerRecoGeometryRecord;

class TSGFromPropagation : public TrackerSeedGenerator {
public:
Expand Down Expand Up @@ -105,15 +106,10 @@ class TSGFromPropagation : public TrackerSeedGenerator {
}
};

unsigned long long theCacheId_MT;
unsigned long long theCacheId_TG;

const std::string theCategory;

edm::ESHandle<GeometricSearchTracker> theTracker;

const std::string theMeasTrackerName;
edm::ESHandle<MeasurementTracker> theMeasTracker;
edm::Handle<MeasurementTrackerEvent> theMeasTrackerEvent;

std::unique_ptr<const DirectTrackerNavigation> theNavigation;
Expand Down Expand Up @@ -150,6 +146,7 @@ class TSGFromPropagation : public TrackerSeedGenerator {
edm::Handle<reco::BeamSpot> beamSpot;
const edm::EDGetTokenT<reco::BeamSpot> theBeamSpotToken;
const edm::EDGetTokenT<MeasurementTrackerEvent> theMeasurementTrackerEventToken;
const edm::ESGetToken<GeometricSearchTracker, TrackerRecoGeometryRecord> theTrackerToken;
};

#endif
5 changes: 1 addition & 4 deletions RecoMuon/TrackerSeedGenerator/src/TrackerSeedCleaner.cc
Expand Up @@ -24,15 +24,12 @@

#include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
#include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
#include "TrackingTools/Records/interface/TransientRecHitRecord.h"
#include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
#include "RecoTracker/TkTrackingRegions/interface/RectangularEtaPhiTrackingRegion.h"
#include "RecoTracker/TkTrackingRegions/interface/TkTrackingRegionsMargin.h"
#include "RecoTracker/TkMSParametrization/interface/PixelRecoRange.h"

#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
#include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedGenerator.h"
#include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedGeneratorFactory.h"

using namespace std;
using namespace edm;
Expand Down Expand Up @@ -61,7 +58,7 @@ void TrackerSeedCleaner::clean(const reco::TrackRef& muR,
if (cleanBySharedHits)
theRedundantCleaner->define(seeds);

theProxyService->eventSetup().get<TransientRecHitRecord>().get(builderName_, theTTRHBuilder);
theTTRHBuilder = theProxyService->eventSetup().getHandle(theTTRHBuilderToken);

LogDebug("TrackerSeedCleaner") << seeds.size() << " trajectory seeds to the events before cleaning" << endl;

Expand Down