Skip to content

Commit

Permalink
Use reco::MuonToTrackingParticleAssociator instead of MuonToSimAssoci…
Browse files Browse the repository at this point in the history
…atorBase

MuonToSimAssociatorBase is an EventSetup object which uses the edm::Event
to get data. This is a problem for consumes. So instead    we nw use the
reco::MuonToTrackingParticleAssociator which does the same work but  is an
edm::Event product which already contains the data it needs from the event.
  • Loading branch information
Dr15Jones committed Jan 14, 2015
1 parent d2b278d commit c7ef28a
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 98 deletions.
41 changes: 20 additions & 21 deletions MuonAnalysis/MuonAssociators/plugins/MuonMCClassifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#include "DataFormats/PatCandidates/interface/Muon.h"
#include "DataFormats/HepMCCandidate/interface/GenParticle.h"

#include "SimMuon/MCTruth/interface/MuonToSimAssociatorBase.h"
#include "SimDataFormats/Associations/interface/MuonToTrackingParticleAssociator.h"
#include "SimTracker/Records/interface/TrackAssociatorRecord.h"
#include <SimDataFormats/TrackingAnalysis/interface/TrackingVertex.h>

Expand All @@ -82,7 +82,7 @@ class MuonMCClassifier : public edm::EDProducer {
StringCutObjectSelector<pat::Muon> muonCut_;

/// Track to use
MuonToSimAssociatorBase::MuonTrackType trackType_;
reco::MuonTrackType trackType_;

/// The TrackingParticle objects
edm::EDGetTokenT<TrackingParticleCollection> trackingParticlesToken_;
Expand Down Expand Up @@ -137,10 +137,10 @@ MuonMCClassifier::MuonMCClassifier(const edm::ParameterSet &iConfig) :
genParticles_(linkToGenParticles_ ? iConfig.getParameter<edm::InputTag>("genParticles") : edm::InputTag("NONE"))
{
std::string trackType = iConfig.getParameter< std::string >("trackType");
if (trackType == "inner") trackType_ = MuonToSimAssociatorBase::InnerTk;
else if (trackType == "outer") trackType_ = MuonToSimAssociatorBase::OuterTk;
else if (trackType == "global") trackType_ = MuonToSimAssociatorBase::GlobalTk;
else if (trackType == "segments") trackType_ = MuonToSimAssociatorBase::Segments;
if (trackType == "inner") trackType_ = reco::InnerTk;
else if (trackType == "outer") trackType_ = reco::OuterTk;
else if (trackType == "global") trackType_ = reco::GlobalTk;
else if (trackType == "segments") trackType_ = reco::Segments;
else throw cms::Exception("Configuration") << "Track type '" << trackType << "' not supported.\n";
if (linkToGenParticles_) {
genParticlesToken_ = consumes<reco::GenParticleCollection>(genParticles_);
Expand Down Expand Up @@ -189,13 +189,12 @@ MuonMCClassifier::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
iEvent.getByToken(genParticlesToken_, genParticles);
}

edm::ESHandle<MuonToSimAssociatorBase> associatorBase;
iSetup.get<TrackAssociatorRecord>().get(associatorLabel_, associatorBase);
const MuonToSimAssociatorBase * assoByHits = associatorBase.product();
if (assoByHits == 0) throw cms::Exception("Configuration") << "The Track Associator with label '" << associatorLabel_ << "' is not a MuonToSimAssociatorBase.\n";
edm::Handle<reco::MuonToTrackingParticleAssociator> associatorBase;
iEvent.getByLabel(associatorLabel_, associatorBase);
const reco::MuonToTrackingParticleAssociator * assoByHits = associatorBase.product();

MuonToSimAssociatorBase::MuonToSimCollection recSimColl;
MuonToSimAssociatorBase::SimToMuonCollection simRecColl;
reco::MuonToSimCollection recSimColl;
reco::SimToMuonCollection simRecColl;
edm::LogVerbatim("MuonMCClassifier") <<"\n ***************************************************************** ";
edm::LogVerbatim("MuonMCClassifier") << " RECO MUON association, type: "<< trackType_;
edm::LogVerbatim("MuonMCClassifier") << " ***************************************************************** \n";
Expand All @@ -221,21 +220,21 @@ MuonMCClassifier::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
allTPs.push_back(TrackingParticleRef(trackingParticles,i));
}

assoByHits->associateMuons(recSimColl, simRecColl, selMuons, trackType_, allTPs, &iEvent, &iSetup);
assoByHits->associateMuons(recSimColl, simRecColl, selMuons, trackType_, allTPs);

// for global muons without hits on muon detectors, look at the linked standalone muon
MuonToSimAssociatorBase::MuonToSimCollection UpdSTA_recSimColl;
MuonToSimAssociatorBase::SimToMuonCollection UpdSTA_simRecColl;
if (trackType_ == MuonToSimAssociatorBase::GlobalTk) {
reco::MuonToSimCollection UpdSTA_recSimColl;
reco::SimToMuonCollection UpdSTA_simRecColl;
if (trackType_ == reco::GlobalTk) {
edm::LogVerbatim("MuonMCClassifier") <<"\n ***************************************************************** ";
edm::LogVerbatim("MuonMCClassifier") << " STANDALONE (UpdAtVtx) MUON association ";
edm::LogVerbatim("MuonMCClassifier") << " ***************************************************************** \n";
assoByHits->associateMuons(UpdSTA_recSimColl, UpdSTA_simRecColl, selMuons, MuonToSimAssociatorBase::OuterTk,
allTPs, &iEvent, &iSetup);
assoByHits->associateMuons(UpdSTA_recSimColl, UpdSTA_simRecColl, selMuons, reco::OuterTk,
allTPs);
}

typedef MuonToSimAssociatorBase::MuonToSimCollection::const_iterator r2s_it;
typedef MuonToSimAssociatorBase::SimToMuonCollection::const_iterator s2r_it;
typedef reco::MuonToSimCollection::const_iterator r2s_it;
typedef reco::SimToMuonCollection::const_iterator s2r_it;

size_t nmu = muons->size();
edm::LogVerbatim("MuonMCClassifier") <<"\n There are "<<nmu<<" reco::Muons.";
Expand Down Expand Up @@ -276,7 +275,7 @@ MuonMCClassifier::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
} else {
edm::LogWarning("MuonMCClassifier") << "\n***WARNING: This I do NOT understand: why no match back? *** \n";
}
} else if ((trackType_ == MuonToSimAssociatorBase::GlobalTk) &&
} else if ((trackType_ == reco::GlobalTk) &&
mu->isGlobalMuon()) {
// perform a second attempt, matching with the standalone muon
r2s_it matchSta = UpdSTA_recSimColl.find(mu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
mixTracks = mix.mixObjects.mixTracks.clone(),
),
)
from SimMuon.MCTruth.MuonAssociatorByHitsESProducer_NoSimHits_cfi import *
from SimMuon.MCTruth.muonAssociatorByHitsNoSimHitsHelper_cfi import *

classByHitsTM = cms.EDProducer("MuonMCClassifier",
muons = cms.InputTag("muons"),
muonPreselection = cms.string("isTrackerMuon"), #
#muonPreselection = cms.string("muonID('TrackerMuonArbitrated')"), # You might want this
trackType = cms.string("segments"), # or 'inner','outer','global'
trackingParticles = cms.InputTag("trackingParticlesNoSimHits","MergedTrackTruth"),
associatorLabel = cms.string("muonAssociatorByHits_NoSimHits"),
associatorLabel = cms.string("muonAssociatorByHitsNoSimHitsHelper"),
decayRho = cms.double(200), # to classifiy differently decay muons included in ppMuX
decayAbsZ = cms.double(400), # and decay muons that could not be in ppMuX
linkToGenParticles = cms.bool(True), # produce also a collection of GenParticles for secondary muons
Expand All @@ -51,6 +51,7 @@
muonClassificationByHits = cms.Sequence(
#mix +
trackingParticlesNoSimHits +
muonAssociatorByHitsNoSimHitsHelper +
( classByHitsTM +
classByHitsTMLSAT +
classByHitsGlb +
Expand Down
6 changes: 6 additions & 0 deletions SimMuon/MCTruth/python/muonAssociatorByHitsHelper_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import FWCore.ParameterSet.Config as cms

from SimMuon.MCTruth.MuonAssociatorByHits_cfi import muonAssociatorByHitsCommonParameters
muonAssociatorByHitsHelper = cms.EDProducer("MuonToTrackingParticleAssociatorEDProducer",
muonAssociatorByHitsCommonParameters
)
20 changes: 20 additions & 0 deletions SimMuon/MCTruth/python/muonAssociatorByHitsNoSimHitsHelper_cfi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import FWCore.ParameterSet.Config as cms

## muonAssociatorByHits using only digiSimLinks (and TrackingParticles),
## not accessing the PSimHits directly. Useful if you run on RECOSIM without RAWSIM

from SimMuon.MCTruth.MuonAssociatorByHits_cfi import muonAssociatorByHitsCommonParameters
muonAssociatorByHitsNoSimHitsHelper = cms.EDProducer("MuonToTrackingParticleAssociatorEDProducer",
muonAssociatorByHitsCommonParameters
)
# don't read simhits, they're not there
muonAssociatorByHitsNoSimHitsHelper.CSCsimHitsTag = ""
muonAssociatorByHitsNoSimHitsHelper.RPCsimhitsTag = ""
muonAssociatorByHitsNoSimHitsHelper.DTsimhitsTag = ""

### The following is useful when running only on RECO
# don't normalize on the total number of hits (which is unknown, if I don't have simHits)
muonAssociatorByHitsNoSimHitsHelper.AbsoluteNumberOfHits_muon = True
muonAssociatorByHitsNoSimHitsHelper.AbsoluteNumberOfHits_track = True
# use only muon system
muonAssociatorByHitsNoSimHitsHelper.UseTracker = False
8 changes: 4 additions & 4 deletions SimMuon/MCTruth/test/testAssociatorRecoMuon_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# MessageLogger
process.load("FWCore.MessageService.MessageLogger_cfi")

process.MessageLogger.categories = cms.untracked.vstring('testAssociatorRecoMuon', 'MuonAssociatorByHits')
process.MessageLogger.categories = cms.untracked.vstring('testAssociatorRecoMuon', 'muonAssociatorByHitsHelper')
process.MessageLogger.cout = cms.untracked.PSet(
noTimeStamps = cms.untracked.bool(True),
threshold = cms.untracked.string('INFO'),
Expand All @@ -41,7 +41,7 @@
#process.load("SimGeneral.TrackingAnalysis.trackingParticles_cfi") # On RAW+RECO
#process.load("SimMuon.MCTruth.MuonAssociatorByHitsESProducer_cfi") # On RAW+RECO
process.load("SimGeneral.TrackingAnalysis.trackingParticlesNoSimHits_cfi") # On RECO
process.load("SimMuon.MCTruth.MuonAssociatorByHitsESProducer_NoSimHits_cfi") # On RECO
process.load("SimMuon.MCTruth.muonAssociatorByHitsNoSimHitsHelper_cfi") # On RECO

process.GlobalTag.globaltag = cms.string('START37_V3::All')
process.options = cms.untracked.PSet(wantSummary = cms.untracked.bool(True))
Expand All @@ -53,10 +53,10 @@
#tpTag = cms.InputTag("mix"), # RAW+RECO
#associatorLabel = cms.string("muonAssociatorByHits"), # RAW+RECO
tpTag = cms.InputTag("mergedtruthNoSimHits"), # RECO Only
associatorLabel = cms.string("muonAssociatorByHits_NoSimHits"), # RECO Only
associatorLabel = cms.string("muonAssociatorByHitsNoSimHitsHelper"), # RECO Only
)

process.skim = cms.EDFilter("CandViewCountFilter", src = cms.InputTag("muons"), minNumber = cms.uint32(1))
process.test = cms.Path(process.skim+process.mix * process.trackingParticlesNoSimHits * process.testanalyzer) # RECO
process.test = cms.Path(process.skim+process.mix * process.trackingParticlesNoSimHits * process.muonAssociatorByHitsNoSimHitsHelper * process.testanalyzer) # RECO
#process.test = cms.Path(process.skim+process.mix * process.trackingParticles * process.testanalyzer) # RAW+RECO

10 changes: 5 additions & 5 deletions SimTracker/TrackHistory/python/MuonHistory_cff.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import FWCore.ParameterSet.Config as cms

# Muon Associator
from SimMuon.MCTruth.MuonAssociatorByHitsESProducer_cfi import *
from SimMuon.MCTruth.muonAssociatorByHitsHelper_cfi import *

# Setting for StandAloneMuons
muonAssociatorByHitsESProducer.tracksTag = cms.InputTag("standAloneMuons")
muonAssociatorByHitsESProducer.UseTracker = cms.bool(False)
muonAssociatorByHitsESProducer.UseMuon = cms.bool(True)
muonAssociatorByHitsHelper.tracksTag = cms.InputTag("standAloneMuons")
muonAssociatorByHitsHelper.UseTracker = cms.bool(False)
muonAssociatorByHitsHelper.UseMuon = cms.bool(True)

# Track history parameters
muonHistory = cms.PSet(
bestMatchByMaxValue = cms.untracked.bool(True),
trackingTruth = cms.untracked.InputTag("mix","MergedTrackTruth"),
trackAssociator = cms.untracked.string("muonAssociatorByHits"),
trackAssociator = cms.untracked.string("muonAssociatorByHitsHelper"),
trackProducer = cms.untracked.InputTag("standAloneMuons"),
enableRecoToSim = cms.untracked.bool(True),
enableSimToReco = cms.untracked.bool(False)
Expand Down
2 changes: 1 addition & 1 deletion Validation/RecoMuon/python/RecoMuonValidator_cfi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
simLabel = cms.InputTag("mix","MergedTrackTruth"),
muonLabel = cms.InputTag("muons"),

muAssocLabel = cms.InputTag("MuonAssociatorByHits"),
muAssocLabel = cms.InputTag("muonAssociatorByHitsHelper"),

doAssoc = cms.untracked.bool(True),

Expand Down
2 changes: 2 additions & 0 deletions Validation/RecoMuon/python/muonValidationFastSim_cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
+staMuonTrackVMuonAssocFS+staUpdMuonTrackVMuonAssocFS+glbMuonTrackVMuonAssocFS
+staRefitMuonTrackVMuonAssocFS+staRefitUpdMuonTrackVMuonAssocFS
+tevMuonFirstTrackVMuonAssocFS+tevMuonPickyTrackVMuonAssocFS+tevMuonDytTrackVMuonAssocFS
+muonAssociatorByHitsNoSimHitsHelperTrk+muonAssociatorByHitsNoSimHitsHelperStandalone+muonAssociatorByHitsNoSimHitsHelperGlobal+muonAssociatorByHitsNoSimHitsHelperTight
+recoMuonVMuAssoc_trk+recoMuonVMuAssoc_sta+recoMuonVMuAssoc_glb+recoMuonVMuAssoc_tgt
+muonAssociatorByHitsNoSimHitsHelperTrkPF+muonAssociatorByHitsNoSimHitsHelperStandalonePF+muonAssociatorByHitsNoSimHitsHelperGlobalPF
+recoMuonVMuAssoc_trkPF+recoMuonVMuAssoc_staPF+recoMuonVMuAssoc_glbPF)

# The muon association and validation sequence
Expand Down

0 comments on commit c7ef28a

Please sign in to comment.