Skip to content

Commit

Permalink
Merge pull request cms-sw#9201 from makortel/trackingValidationSelect…
Browse files Browse the repository at this point in the history
…ionUpdate

Add more histograms and track selections to MultiTrackValidator, remove standalone mode
  • Loading branch information
cmsbuild committed Jun 5, 2015
2 parents 488e864 + 428b85d commit 8dcc0f3
Show file tree
Hide file tree
Showing 41 changed files with 848 additions and 498 deletions.
110 changes: 110 additions & 0 deletions CommonTools/RecoAlgos/plugins/JetTracksAssociationToTrackRefs.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "DataFormats/Common/interface/EDProductfwd.h"
#include "DataFormats/TrackReco/interface/Track.h"
#include "DataFormats/TrackReco/interface/TrackFwd.h"
#include "DataFormats/JetReco/interface/Jet.h"
#include "DataFormats/JetReco/interface/JetTracksAssociation.h"

#include "JetMETCorrections/JetCorrector/interface/JetCorrector.h"

#include <unordered_set>

/**
* The purpose of this producer is to convert
* AssociationVector<JetRefBaseProd, vector<RefVector<Track> > to a
* RefVector<Track> of the (unique) values.
*/
class JetTracksAssociationToTrackRefs: public edm::global::EDProducer<> {
public:
JetTracksAssociationToTrackRefs(const edm::ParameterSet& iConfig);

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

virtual void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;

private:
edm::EDGetTokenT<reco::JetTracksAssociation::Container> associationToken_;
edm::EDGetTokenT<edm::View<reco::Jet> > jetToken_;
edm::EDGetTokenT<reco::JetCorrector> correctorToken_;
const double ptMin_;
};


JetTracksAssociationToTrackRefs::JetTracksAssociationToTrackRefs(const edm::ParameterSet& iConfig):
associationToken_(consumes<reco::JetTracksAssociation::Container>(iConfig.getParameter<edm::InputTag>("association"))),
jetToken_(consumes<edm::View<reco::Jet>>(iConfig.getParameter<edm::InputTag>("jets"))),
correctorToken_(consumes<reco::JetCorrector>(iConfig.getParameter<edm::InputTag>("corrector"))),
ptMin_(iConfig.getParameter<double>("correctedPtMin"))
{
produces<reco::TrackRefVector> ();
}

void JetTracksAssociationToTrackRefs::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("association", edm::InputTag("ak4JetTracksAssociatorAtVertexPF"));
desc.add<edm::InputTag>("jets", edm::InputTag("ak4PFJetsCHS"));
desc.add<edm::InputTag>("corrector", edm::InputTag("ak4PFL1FastL2L3Corrector"));
desc.add<double>("correctedPtMin", 0);
descriptions.add("jetTracksAssociationToTrackRefs", desc);
}

void JetTracksAssociationToTrackRefs::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
edm::Handle<reco::JetTracksAssociation::Container> h_assoc;
iEvent.getByToken(associationToken_, h_assoc);
const reco::JetTracksAssociation::Container& association = *h_assoc;

edm::Handle<edm::View<reco::Jet>> h_jets;
iEvent.getByToken(jetToken_, h_jets);
const edm::View<reco::Jet>& jets = *h_jets;

edm::Handle<reco::JetCorrector> h_corrector;
iEvent.getByToken(correctorToken_, h_corrector);
const reco::JetCorrector& corrector = *h_corrector;

auto ret = std::make_unique<reco::TrackRefVector>();
std::unordered_set<reco::TrackRefVector::key_type> alreadyAdded;

// Exctract tracks only for jets passing certain pT threshold after
// correction
for(size_t i=0; i<jets.size(); ++i) {
edm::RefToBase<reco::Jet> jetRef = jets.refAt(i);
const reco::Jet& jet = *jetRef;

auto p4 = jet.p4();

// Energy correction in the most general way
if(!corrector.vectorialCorrection()) {
double scale = 1;
if(!corrector.refRequired()) {
scale = corrector.correction(jet);
}
else {
scale = corrector.correction(jet, jetRef);
}
p4 = p4*scale;
}
else {
corrector.correction(jet, jetRef, p4);
}

if(p4.pt() <= ptMin_)
continue;

for(const auto& trackRef: association[jetRef]) {
if(alreadyAdded.find(trackRef.key()) == alreadyAdded.end()) {
ret->push_back(trackRef);
alreadyAdded.insert(trackRef.key());
}
}
}

iEvent.put(std::move(ret));
}

DEFINE_FWK_MODULE(JetTracksAssociationToTrackRefs);
1 change: 0 additions & 1 deletion FastSimulation/Validation/test/MultiTrackValidator_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@

########### configuration MultiTrackValidator ########
process.multiTrackValidator.associators = ['quickTrackAssociatorByHits']
process.multiTrackValidator.skipHistoFit = False
#process.cutsRecoTracks.quality = ['','highPurity']
#process.cutsRecoTracks.quality = ['']
process.multiTrackValidator.label = ['cutsRecoTracks']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
process.edmtome_step = cms.Path(process.EDMtoME)
process.dqmsave_step = cms.Path(process.DQMSaver)
process.load('Validation.RecoTrack.PostProcessorTracker_cfi')
process.mtv_harvesting = cms.Path(process.postProcessorTrack)
process.mtv_harvesting = cms.Path(process.postProcessorTrackSequence)
process.postProcessorTrack.subDirs = cms.untracked.vstring('Tracking/Track/*','Tracking/Seed/*')

# Schedule definition
Expand Down
9 changes: 8 additions & 1 deletion PhysicsTools/RecoAlgos/python/btvTracks_cfi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import FWCore.ParameterSet.Config as cms

btvTracks = cms.EDProducer("RecoTrackSelector",
_content = cms.PSet(
src = cms.InputTag("generalTracks"),
maxChi2 = cms.double(5.0),
tip = cms.double(0.2),
Expand All @@ -17,9 +17,16 @@
beamSpot = cms.InputTag("offlineBeamSpot"),
usePV = cms.bool(True),
vertexTag = cms.InputTag('offlinePrimaryVertices'),
)

btvTracks = cms.EDProducer("RecoTrackSelector",
_content,
copyExtras = cms.untracked.bool(True), ## copies also extras and rechits on RECO
copyTrajectories = cms.untracked.bool(False) # don't set this to true on AOD!
)

btvTrackRefs = cms.EDFilter("RecoTrackRefSelector",
_content
)


Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,13 @@
#process.multiTrackValidator.label = ['cutsRecoTracks']
#process.multiTrackValidator.label_tp_effic = cms.InputTag("cutsTPEffic")
#process.multiTrackValidator.label_tp_fake = cms.InputTag("cutsTPFake")
process.multiTrackValidator.sim = 'famosSimHits'
process.multiTrackValidator.sim = ['famosSimHits']
process.multiTrackValidator.associators = ['trackAssociatorByHits']
process.multiTrackValidator.UseAssociators = True
process.multiTrackValidator.outputFile = "validphase1_muon_50GeV.root"
process.multiTrackValidator.nint = cms.int32(20)
process.multiTrackValidator.nintpT = cms.int32(25)
process.multiTrackValidator.maxpT = cms.double(50.0)
process.multiTrackValidator.skipHistoFit = cms.untracked.bool(False)
process.multiTrackValidator.runStandalone = cms.bool(True)

##### with John's changes ##############################
process.load("SLHCUpgradeSimulations.Geometry.oldTracking_wtriplets")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,13 @@
#process.multiTrackValidator.label = ['cutsRecoTracks']
#process.multiTrackValidator.label_tp_effic = cms.InputTag("cutsTPEffic")
#process.multiTrackValidator.label_tp_fake = cms.InputTag("cutsTPFake")
process.multiTrackValidator.sim = 'famosSimHits'
process.multiTrackValidator.sim = ['famosSimHits']
process.multiTrackValidator.associators = ['trackAssociatorByHits']
process.multiTrackValidator.UseAssociators = True
process.multiTrackValidator.outputFile = "validstdgeom_muon_50GeV.root"
process.multiTrackValidator.nint = cms.int32(20)
process.multiTrackValidator.nintpT = cms.int32(25)
process.multiTrackValidator.maxpT = cms.double(50.0)
process.multiTrackValidator.skipHistoFit = False
##### with John's changes ##############################
process.load("SLHCUpgradeSimulations.Geometry.oldTracking_wtriplets")
#process.PixelLayerTriplets.layerList = cms.vstring('BPix1+BPix2+BPix3',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@
#process.multiTrackValidator.label_tp_fake = cms.InputTag("cutsTPFake")
process.multiTrackValidator.associators = ['trackAssociatorByHits']
process.multiTrackValidator.UseAssociators = True
process.multiTrackValidator.outputFile = "validfullLB_muon_50GeV.root"
process.multiTrackValidator.nint = cms.int32(20)
process.multiTrackValidator.nintpT = cms.int32(25)
process.multiTrackValidator.maxpT = cms.double(50.0)
process.multiTrackValidator.skipHistoFit = False

##### with John's changes ##############################
process.load("SLHCUpgradeSimulations.Geometry.oldTracking_wtriplets")
Expand Down
2 changes: 1 addition & 1 deletion SLHCUpgradeSimulations/Geometry/test/Harvesting_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

# Remove the HLT harvesting from the validation harvesting step
process.validationHarvesting = cms.Path(process.postValidation)
process.trackingOnlyHarvesting = cms.Path(process.postProcessorTrack)
process.trackingOnlyHarvesting = cms.Path(process.postProcessorTrackSequence)
process.seedingOnlyHarvesting = cms.Path(process.postProcessorSeed)
#process.schedule = cms.Schedule(process.edmtome_step,process.validationHarvesting,process.dqmsave_step)
#process.schedule = cms.Schedule(process.edmtome_step,process.trackingOnlyHarvesting,process.seedingOnlyHarvesting,process.dqmsave_step)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,9 @@
#process.multiTrackValidator.label_tp_fake = cms.InputTag("cutsTPFake")
process.multiTrackValidator.associators = ['trackAssociatorByHits']
process.multiTrackValidator.UseAssociators = True
process.multiTrackValidator.outputFile = "validfullph1g_muon_50GeV.root"
process.multiTrackValidator.nint = cms.int32(20)
process.multiTrackValidator.nintpT = cms.int32(25)
process.multiTrackValidator.maxpT = cms.double(50.0)
process.multiTrackValidator.skipHistoFit = False

##### with John's changes ##############################
process.load("SLHCUpgradeSimulations.Geometry.oldTracking_wtriplets")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#ifndef SimGeneral_TrackingAnalysis_TrackingParticleNumberOfLayers_h
#define SimGeneral_TrackingAnalysis_TrackingParticleNumberOfLayers_h

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

#include "DataFormats/Common/interface/ValueMap.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"

/**
* This class calculates the number of tracker layers, pixel layers,
* and strip mono+stereo layers "crossed" by TrackingParticle.
*
* The numbers of pixel and strip mono+stereo layers are not available
* from TrackingParticle itself, so they are calculated here in a
* standalone way in order to not to modify the TP dataformat (for
* now). The number of tracker layers is available in TP, but its
* calculation in TrackingTruthAccumulator gives wrong results (too
* many layers) for loopers, so also it is calculated here on the same
* go.
*
* The PSimHits are needed for the calculation, so, in practice, in
* events with pileup the numbers of layers can be calculated only for
* TPs from the signal event (i.e. not for pileup TPs). Fortunately
* this is exactly what is sufficient for MultiTrackValidator.
*
* Eventually we should move to use HitPattern as in reco::TrackBase
* (more information in a compact format), and consider adding it to
* the TrackingParticle itself.
*
* In principle we could utilize the TP->SimHit map produced in
* SimHitTPAssociationProducer instead of doing the association here
* again, but
* - SimTrack SimHits need to looped over in the order defined by
* SimTrack (to do the same as in TrackingTruthAccumulator). While
* possible, it would be cumbersome to do (more than just doing the
* association via SimTrack id)
* - The main customer of this class, MultiTrackValidator, can in
* principle take a TrackingParticle collection different from the
* one of SimHitTPAssociationProducer (e.g. after a selection, since
* MTV does not support TP Refs because of how
* reco::RecoToSimCollection and reco::SimToRecoCollection are defined
*/
class TrackingParticleNumberOfLayers {
public:
TrackingParticleNumberOfLayers(const edm::Event& iEvent, const std::vector<edm::EDGetTokenT<std::vector<PSimHit> > >& simHitTokens);

enum {
nTrackerLayers = 0,
nPixelLayers = 1,
nStripMonoAndStereoLayers = 2
};
std::tuple<std::unique_ptr<edm::ValueMap<unsigned int>>,
std::unique_ptr<edm::ValueMap<unsigned int>>,
std::unique_ptr<edm::ValueMap<unsigned int>>>
calculate(const edm::Handle<TrackingParticleCollection>& tps, const edm::EventSetup& iSetup) const;

private:
// used as multimap, but faster
std::vector<std::pair<unsigned int, const PSimHit *>> trackIdToHitPtr_;
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"

#include "SimGeneral/TrackingAnalysis/interface/TrackingParticleNumberOfLayers.h"

/**
* The purpose of this producer is to create a ValueMap<pair<unsigned int, unsigned int>>
* for the number of pixel and strip stereo tracker layers the TrackingParticle has hits on.
*/
class TrackingParticleNumberOfLayersProducer: public edm::global::EDProducer<> {
public:
TrackingParticleNumberOfLayersProducer(const edm::ParameterSet& iConfig);

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

virtual void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;

private:
edm::EDGetTokenT<TrackingParticleCollection> tpToken_;
std::vector<edm::EDGetTokenT<std::vector<PSimHit>>> simHitTokens_;
};


TrackingParticleNumberOfLayersProducer::TrackingParticleNumberOfLayersProducer(const edm::ParameterSet& iConfig):
tpToken_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticles")))
{
for(const auto& tag: iConfig.getParameter<std::vector<edm::InputTag>>("simHits")) {
simHitTokens_.push_back(consumes<std::vector<PSimHit>>(tag));
}

produces<edm::ValueMap<unsigned int>>("trackerLayers");
produces<edm::ValueMap<unsigned int>>("pixelLayers");
produces<edm::ValueMap<unsigned int>>("stripStereoLayers");
}

void TrackingParticleNumberOfLayersProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("trackingParticles", edm::InputTag("mix", "MergedTrackTruth"));

desc.add<std::vector<edm::InputTag> >("simHits", {
edm::InputTag("g4SimHits", "TrackerHitsPixelBarrelHighTof"),
edm::InputTag("g4SimHits", "TrackerHitsPixelBarrelLowTof"),
edm::InputTag("g4SimHits", "TrackerHitsPixelEndcapHighTof"),
edm::InputTag("g4SimHits", "TrackerHitsPixelEndcapLowTof"),
edm::InputTag("g4SimHits", "TrackerHitsTECHighTof"),
edm::InputTag("g4SimHits", "TrackerHitsTECLowTof"),
edm::InputTag("g4SimHits", "TrackerHitsTIBHighTof"),
edm::InputTag("g4SimHits", "TrackerHitsTIBLowTof"),
edm::InputTag("g4SimHits", "TrackerHitsTIDHighTof"),
edm::InputTag("g4SimHits", "TrackerHitsTIDLowTof"),
edm::InputTag("g4SimHits", "TrackerHitsTOBHighTof"),
edm::InputTag("g4SimHits", "TrackerHitsTOBLowTof")
});

descriptions.add("trackingParticleNumberOfLayersProducer", desc);
}

void TrackingParticleNumberOfLayersProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
edm::Handle<TrackingParticleCollection> htps;
iEvent.getByToken(tpToken_, htps);

TrackingParticleNumberOfLayers algo(iEvent, simHitTokens_);
auto ret = algo.calculate(htps, iSetup);
iEvent.put(std::move(std::get<TrackingParticleNumberOfLayers::nTrackerLayers>(ret)), "trackerLayers");
iEvent.put(std::move(std::get<TrackingParticleNumberOfLayers::nPixelLayers>(ret)), "pixelLayers");
iEvent.put(std::move(std::get<TrackingParticleNumberOfLayers::nStripMonoAndStereoLayers>(ret)), "stripStereoLayers");
}

DEFINE_FWK_MODULE(TrackingParticleNumberOfLayersProducer);
Loading

0 comments on commit 8dcc0f3

Please sign in to comment.