forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cms-sw#9201 from makortel/trackingValidationSelect…
…ionUpdate Add more histograms and track selections to MultiTrackValidator, remove standalone mode
- Loading branch information
Showing
41 changed files
with
848 additions
and
498 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
CommonTools/RecoAlgos/plugins/JetTracksAssociationToTrackRefs.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
SimGeneral/TrackingAnalysis/interface/TrackingParticleNumberOfLayers.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
73 changes: 73 additions & 0 deletions
73
SimGeneral/TrackingAnalysis/plugins/TrackingParticleNumberOfLayersProducer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.