Skip to content

Commit

Permalink
add consumes interface, and fix memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
wmtan committed Apr 3, 2015
1 parent 7442c40 commit 8c720fe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 48 deletions.
52 changes: 19 additions & 33 deletions FastSimulation/Muons/plugins/FastTSGFromPropagation.cc
Expand Up @@ -44,30 +44,20 @@

using namespace std;


FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet & iConfig,edm::ConsumesCollector& iC) :theTkLayerMeasurements(), theTracker(0), theNavigation(0), theService(0), theEstimator(0), theSigmaZ(0), theConfig (iConfig),
beamSpot_(iConfig.getParameter<edm::InputTag>("beamSpot"))
{
theCategory = "FastSimulation|Muons||FastTSGFromPropagation";
theMeasurementTrackerEventTag = iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent");
FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet& iConfig,edm::ConsumesCollector& iC) : FastTSGFromPropagation(iConfig, nullptr, iC) {
}

FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet & iConfig, const MuonServiceProxy* service,edm::ConsumesCollector& iC) : theTkLayerMeasurements(), theTracker(0), theNavigation(0), theService(service),theUpdator(0), theEstimator(0), theSigmaZ(0), theConfig (iConfig),
beamSpot_(iConfig.getParameter<edm::InputTag>("beamSpot"))
{
theCategory = "FastSimulation|Muons|FastTSGFromPropagation";
theMeasurementTrackerEventTag = iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent");
FastTSGFromPropagation::FastTSGFromPropagation(const edm::ParameterSet& iConfig, const MuonServiceProxy* service, edm::ConsumesCollector& iC) :
theCategory("FastSimulation|Muons|FastTSGFromPropagation"),
theTkLayerMeasurements(), theTracker(), theNavigation(), theService(service), theUpdator(), theEstimator(), theSigmaZ(0.0), theConfig (iConfig),
theSimTrackCollectionToken_(iC.consumes<edm::SimTrackContainer>(theConfig.getParameter<edm::InputTag>("SimTrackCollectionLabel"))),
theHitProducer(iC.consumes<SiTrackerGSMatchedRecHit2DCollection>(theConfig.getParameter<edm::InputTag>("HitProducer"))),
beamSpot_(iC.consumes<reco::BeamSpot>(iConfig.getParameter<edm::InputTag>("beamSpot"))),
theMeasurementTrackerEventToken_(iC.consumes<MeasurementTrackerEvent>(iConfig.getParameter<edm::InputTag>("MeasurementTrackerEvent"))) {
}

FastTSGFromPropagation::~FastTSGFromPropagation()
{

FastTSGFromPropagation::~FastTSGFromPropagation() {
LogTrace(theCategory) << " FastTSGFromPropagation dtor called ";
if ( theNavigation ) delete theNavigation;
if ( theUpdator ) delete theUpdator;
if ( theEstimator ) delete theEstimator;
if ( theErrorMatrixAdjuster ) delete theErrorMatrixAdjuster;

}

void FastTSGFromPropagation::trackerSeeds(const TrackCand& staMuon, const TrackingRegion& region,
Expand Down Expand Up @@ -309,7 +299,7 @@ void FastTSGFromPropagation::init(const MuonServiceProxy* service) {
theResetMethod = "discrete";
}

theEstimator = new Chi2MeasurementEstimator(theMaxChi2);
theEstimator.reset( new Chi2MeasurementEstimator(theMaxChi2));

theCacheId_MT = 0;

Expand All @@ -325,24 +315,21 @@ void FastTSGFromPropagation::init(const MuonServiceProxy* service) {

theSelectStateFlag = theConfig.getParameter<bool>("SelectState");

theSimTrackCollectionLabel = theConfig.getParameter<edm::InputTag>("SimTrackCollectionLabel");
theHitProducer = theConfig.getParameter<edm::InputTag>("HitProducer");

theUpdator = new KFUpdator();
theUpdator.reset(new KFUpdator());

theSigmaZ = theConfig.getParameter<double>("SigmaZ");

edm::ParameterSet errorMatrixPset = theConfig.getParameter<edm::ParameterSet>("errorMatrixPset");
if ( theResetMethod == "matrix" && !errorMatrixPset.empty()){
theAdjustAtIp = errorMatrixPset.getParameter<bool>("atIP");
theErrorMatrixAdjuster = new MuonErrorMatrix(errorMatrixPset);
theErrorMatrixAdjuster.reset(new MuonErrorMatrix(errorMatrixPset));
} else {
theAdjustAtIp =false;
theErrorMatrixAdjuster=0;
theErrorMatrixAdjuster.reset();
}

theService->eventSetup().get<TrackerRecoGeometryRecord>().get(theTracker);
theNavigation = new DirectTrackerNavigation(theTracker);
theNavigation.reset(new DirectTrackerNavigation(theTracker));

edm::ESHandle<TrackerGeometry> geometry;
theService->eventSetup().get<TrackerDigiGeometryRecord>().get(geometry);
Expand All @@ -354,11 +341,11 @@ void FastTSGFromPropagation::init(const MuonServiceProxy* service) {

void FastTSGFromPropagation::setEvent(const edm::Event& iEvent) {

iEvent.getByLabel(beamSpot_, theBeamSpot);
iEvent.getByToken(beamSpot_, theBeamSpot);

// retrieve the MC truth (SimTracks)
iEvent.getByLabel(theSimTrackCollectionLabel, theSimTracks);
iEvent.getByLabel(theHitProducer, theGSRecHits);
iEvent.getByToken(theSimTrackCollectionToken_, theSimTracks);
iEvent.getByToken(theHitProducer, theGSRecHits);


unsigned long long newCacheId_MT = theService->eventSetup().get<CkfComponentsRecord>().cacheIdentifier();
Expand All @@ -370,7 +357,7 @@ void FastTSGFromPropagation::setEvent(const edm::Event& iEvent) {
}

if ( theUpdateStateFlag ) {
iEvent.getByLabel(theMeasurementTrackerEventTag, theMeasTrackerEvent);
iEvent.getByToken(theMeasurementTrackerEventToken_, theMeasTrackerEvent);
theTkLayerMeasurements = LayerMeasurements(*theMeasTracker,*theMeasTrackerEvent);
}

Expand All @@ -386,8 +373,7 @@ void FastTSGFromPropagation::setEvent(const edm::Event& iEvent) {
}

if ( trackerGeomChanged && (&*theTracker) ) {
if ( theNavigation ) delete theNavigation;
theNavigation = new DirectTrackerNavigation(theTracker);
theNavigation.reset(new DirectTrackerNavigation(theTracker));
}
}

Expand Down
29 changes: 14 additions & 15 deletions FastSimulation/Muons/plugins/FastTSGFromPropagation.h
Expand Up @@ -12,7 +12,7 @@

#include "RecoMuon/TrackerSeedGenerator/interface/TrackerSeedGenerator.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
#include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
#include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
Expand All @@ -30,6 +30,7 @@
#include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
#include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include <memory>


class LayerMeasurements;
Expand Down Expand Up @@ -76,9 +77,9 @@ class FastTSGFromPropagation : public TrackerSeedGenerator {

const LayerMeasurements* tkLayerMeasurements() const { return &theTkLayerMeasurements; }

const TrajectoryStateUpdator* updator() const {return theUpdator;}
const TrajectoryStateUpdator* updator() const {return theUpdator.get();}

const Chi2MeasurementEstimator* estimator() const { return theEstimator; }
const Chi2MeasurementEstimator* estimator() const { return theEstimator.get(); }

edm::ESHandle<Propagator> propagator() const {return theService->propagator(thePropagatorName); }

Expand Down Expand Up @@ -136,16 +137,15 @@ class FastTSGFromPropagation : public TrackerSeedGenerator {

edm::ESHandle<MeasurementTracker> theMeasTracker;

const DirectTrackerNavigation* theNavigation;
std::unique_ptr<const DirectTrackerNavigation> theNavigation;

const TrackerGeometry* theGeometry;

const MuonServiceProxy* theService;

const TrajectoryStateUpdator* theUpdator;

const Chi2MeasurementEstimator* theEstimator;
std::unique_ptr<const TrajectoryStateUpdator> theUpdator;

TrajectoryStateTransform* theTSTransformer;
std::unique_ptr<const Chi2MeasurementEstimator> theEstimator;

double theMaxChi2;

Expand All @@ -157,24 +157,23 @@ class FastTSGFromPropagation : public TrackerSeedGenerator {

bool theUpdateStateFlag;

edm::InputTag theSimTrackCollectionLabel;
edm::InputTag theHitProducer;

std::string theResetMethod;

bool theSelectStateFlag;

std::string thePropagatorName;

MuonErrorMatrix * theErrorMatrixAdjuster;
std::unique_ptr<MuonErrorMatrix> theErrorMatrixAdjuster;

bool theAdjustAtIp;

double theSigmaZ;

edm::ParameterSet theConfig;
edm::InputTag beamSpot_;
edm::InputTag theMeasurementTrackerEventTag;
const edm::ParameterSet theConfig;
edm::EDGetTokenT<edm::SimTrackContainer> theSimTrackCollectionToken_;
edm::EDGetTokenT<SiTrackerGSMatchedRecHit2DCollection> theHitProducer;
edm::EDGetTokenT<reco::BeamSpot> beamSpot_;
edm::EDGetTokenT<MeasurementTrackerEvent> theMeasurementTrackerEventToken_;

edm::Handle<reco::BeamSpot> theBeamSpot;
edm::Handle<edm::SimTrackContainer> theSimTracks;
Expand Down

0 comments on commit 8c720fe

Please sign in to comment.