From f09f348b6431ab6fe728ed44ff899daa2965ab15 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Mon, 22 Nov 2021 21:20:20 +0100 Subject: [PATCH 1/3] Use ESGetToekn in some of the codes in SimTracker/Track(Vertex)Association --- .../plugins/MCTrackMatcher.cc | 1 - .../plugins/TrackAssociatorEDProducer.cc | 2 - .../plugins/TrackMCQuality.cc | 1 - .../src/ParametersDefinerForTP.cc | 1 - .../test/testTrackAssociator.cc | 34 +++++-- .../test/testTrackAssociator.h | 33 ------- .../test/testVertexAssociator.cc | 90 ++++++++++++++++-- .../test/testVertexAssociator.h | 91 ------------------- 8 files changed, 111 insertions(+), 142 deletions(-) delete mode 100644 SimTracker/TrackAssociation/test/testTrackAssociator.h delete mode 100644 SimTracker/VertexAssociation/test/testVertexAssociator.h diff --git a/SimTracker/TrackAssociation/plugins/MCTrackMatcher.cc b/SimTracker/TrackAssociation/plugins/MCTrackMatcher.cc index d9df9dc3cadc4..4f9be145a6b64 100644 --- a/SimTracker/TrackAssociation/plugins/MCTrackMatcher.cc +++ b/SimTracker/TrackAssociation/plugins/MCTrackMatcher.cc @@ -36,7 +36,6 @@ class MCTrackMatcher : public edm::global::EDProducer<> { }; #include "DataFormats/Common/interface/Handle.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/Framework/interface/Event.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "FWCore/Utilities/interface/EDMException.h" diff --git a/SimTracker/TrackAssociation/plugins/TrackAssociatorEDProducer.cc b/SimTracker/TrackAssociation/plugins/TrackAssociatorEDProducer.cc index 6f0aa9aca6153..950bc2f09b21a 100644 --- a/SimTracker/TrackAssociation/plugins/TrackAssociatorEDProducer.cc +++ b/SimTracker/TrackAssociation/plugins/TrackAssociatorEDProducer.cc @@ -14,8 +14,6 @@ #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/ESHandle.h" - #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h" diff --git a/SimTracker/TrackAssociation/plugins/TrackMCQuality.cc b/SimTracker/TrackAssociation/plugins/TrackMCQuality.cc index 0665c663a4489..61856efc3f7e9 100644 --- a/SimTracker/TrackAssociation/plugins/TrackMCQuality.cc +++ b/SimTracker/TrackAssociation/plugins/TrackMCQuality.cc @@ -27,7 +27,6 @@ #include "FWCore/Framework/interface/Event.h" #include "FWCore/Framework/interface/MakerMacros.h" -#include "FWCore/Framework/interface/ESHandle.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h" diff --git a/SimTracker/TrackAssociation/src/ParametersDefinerForTP.cc b/SimTracker/TrackAssociation/src/ParametersDefinerForTP.cc index 08f87e3dc8b87..56d82188ec06b 100644 --- a/SimTracker/TrackAssociation/src/ParametersDefinerForTP.cc +++ b/SimTracker/TrackAssociation/src/ParametersDefinerForTP.cc @@ -7,7 +7,6 @@ #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h" #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h" #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h" -#include class TrajectoryStateClosestToBeamLineBuilder; ParametersDefinerForTP::ParametersDefinerForTP(const edm::InputTag &beamspot, edm::ConsumesCollector iC) diff --git a/SimTracker/TrackAssociation/test/testTrackAssociator.cc b/SimTracker/TrackAssociation/test/testTrackAssociator.cc index bb1f158d3e0ca..667f79a317e63 100644 --- a/SimTracker/TrackAssociation/test/testTrackAssociator.cc +++ b/SimTracker/TrackAssociation/test/testTrackAssociator.cc @@ -1,22 +1,43 @@ -#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Utilities/interface/InputTag.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "MagneticField/Engine/interface/MagneticField.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" -#include "SimTracker/TrackAssociation/test/testTrackAssociator.h" - #include "DataFormats/TrackReco/interface/TrackFwd.h" #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociator.h" #include +#include #include +#include #include // class TrackAssociator; class TrackAssociatorByHits; class TrackerHitAssociator; +namespace reco { + class TrackToTrackingParticleAssociator; +} + +class testTrackAssociator : public edm::one::EDAnalyzer<> { +public: + testTrackAssociator(const edm::ParameterSet &conf); + ~testTrackAssociator() override = default; + void beginJob() override {} + void analyze(const edm::Event &, const edm::EventSetup &) override; + +private: + reco::TrackToTrackingParticleAssociator const *associatorByChi2; + reco::TrackToTrackingParticleAssociator const *associatorByHits; + edm::InputTag tracksTag, tpTag, simtracksTag, simvtxTag; + edm::ESGetToken tokenMF_; +}; + using namespace reco; using namespace std; using namespace edm; @@ -26,13 +47,12 @@ testTrackAssociator::testTrackAssociator(edm::ParameterSet const &conf) { tpTag = conf.getParameter("tpTag"); simtracksTag = conf.getParameter("simtracksTag"); simvtxTag = conf.getParameter("simvtxTag"); -} + tokenMF_ = esConsumes() ; -testTrackAssociator::~testTrackAssociator() {} +} void testTrackAssociator::analyze(const edm::Event &event, const edm::EventSetup &setup) { - edm::ESHandle theMF; - setup.get().get(theMF); + const auto& theMF = setup.getHandle(tokenMF_); edm::Handle theChiAssociator; event.getByLabel("trackAssociatorByChi2", theChiAssociator); associatorByChi2 = theChiAssociator.product(); diff --git a/SimTracker/TrackAssociation/test/testTrackAssociator.h b/SimTracker/TrackAssociation/test/testTrackAssociator.h deleted file mode 100644 index 427339cde1290..0000000000000 --- a/SimTracker/TrackAssociation/test/testTrackAssociator.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef testTrackAssociator_h -#define testTrackAssociator_h - -#include - -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/Utilities/interface/InputTag.h" - -#include -#include -#include -#include - -namespace reco { - class TrackToTrackingParticleAssociator; -} - -class testTrackAssociator : public edm::EDAnalyzer { -public: - testTrackAssociator(const edm::ParameterSet &conf); - ~testTrackAssociator() override; - void beginJob() override {} - void analyze(const edm::Event &, const edm::EventSetup &) override; - -private: - reco::TrackToTrackingParticleAssociator const *associatorByChi2; - reco::TrackToTrackingParticleAssociator const *associatorByHits; - edm::InputTag tracksTag, tpTag, simtracksTag, simvtxTag; -}; - -#endif diff --git a/SimTracker/VertexAssociation/test/testVertexAssociator.cc b/SimTracker/VertexAssociation/test/testVertexAssociator.cc index d03f73363d944..0231f51e2bbb9 100644 --- a/SimTracker/VertexAssociation/test/testVertexAssociator.cc +++ b/SimTracker/VertexAssociation/test/testVertexAssociator.cc @@ -1,4 +1,8 @@ -#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/one/EDAnalyzer.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + #include "MagneticField/Engine/interface/MagneticField.h" #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h" @@ -9,14 +13,89 @@ #include "SimDataFormats/Associations/interface/VertexToTrackingVertexAssociator.h" #include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h" #include "SimDataFormats/TrackingAnalysis/interface/TrackingVertexContainer.h" -#include "SimTracker/VertexAssociation/test/testVertexAssociator.h" #include "CommonTools/Statistics/interface/ChiSquaredProbability.h" #include "DataFormats/Math/interface/Vector.h" +#include "DataFormats/Math/interface/LorentzVector.h" +#include +#include + +#include "TFile.h" +#include "TH1F.h" +#include "TMath.h" +#include "TROOT.h" +#include "TTree.h" +#include #include +#include #include +#include #include +#include + +namespace reco { + class TrackToTrackingParticleAssociator; + class VertexToTrackingVertexAssociator; +} // namespace reco + +class testVertexAssociator : public edm::one::EDAnalyzer { +public: + testVertexAssociator(const edm::ParameterSet &conf); + ~testVertexAssociator() override = default; + void beginJob() override; + void endJob() override; + void analyze(const edm::Event &, const edm::EventSetup &) override; + +private: + const reco::TrackToTrackingParticleAssociator *associatorByChi2; + const reco::TrackToTrackingParticleAssociator *associatorByHits; + const reco::VertexToTrackingVertexAssociator *associatorByTracks; + + edm::InputTag vertexCollection_; + edm::EDGetTokenT associatorByTracksToken; + edm::ESGetToken tokenMF_; + + int n_event_; + int n_rs_vertices_; + int n_rs_vtxassocs_; + int n_sr_vertices_; + int n_sr_vtxassocs_; + + //--------- RecoToSim Histos ----- + + TH1F *rs_resx; + TH1F *rs_resy; + TH1F *rs_resz; + TH1F *rs_pullx; + TH1F *rs_pully; + TH1F *rs_pullz; + TH1F *rs_dist; + TH1F *rs_simz; + TH1F *rs_recz; + TH1F *rs_nrectrk; + TH1F *rs_nsimtrk; + TH1F *rs_qual; + TH1F *rs_chi2norm; + TH1F *rs_chi2prob; + + //--------- SimToReco Histos ----- + + TH1F *sr_resx; + TH1F *sr_resy; + TH1F *sr_resz; + TH1F *sr_pullx; + TH1F *sr_pully; + TH1F *sr_pullz; + TH1F *sr_dist; + TH1F *sr_simz; + TH1F *sr_recz; + TH1F *sr_nrectrk; + TH1F *sr_nsimtrk; + TH1F *sr_qual; + TH1F *sr_chi2norm; + TH1F *sr_chi2prob; +}; // class TrackAssociator; class TrackAssociatorByHits; @@ -29,7 +108,9 @@ using namespace edm; testVertexAssociator::testVertexAssociator(edm::ParameterSet const &conf) : associatorByTracksToken(consumes( conf.getUntrackedParameter("vertexAssociation"))) { + usesResource(TFileService::kSharedResource); vertexCollection_ = conf.getUntrackedParameter("vertexCollection"); + tokenMF_ = esConsumes(); n_event_ = 0; n_rs_vertices_ = 0; @@ -38,8 +119,6 @@ testVertexAssociator::testVertexAssociator(edm::ParameterSet const &conf) n_sr_vtxassocs_ = 0; } -testVertexAssociator::~testVertexAssociator() {} - void testVertexAssociator::beginJob() { edm::Service fs; @@ -91,8 +170,7 @@ void testVertexAssociator::analyze(const edm::Event &event, const edm::EventSetu using namespace edm; using namespace reco; - edm::ESHandle theMF; - setup.get().get(theMF); + const auto & theMF = setup.getHandle(tokenMF_); edm::Handle theTracksAssociator; event.getByToken(associatorByTracksToken, theTracksAssociator); diff --git a/SimTracker/VertexAssociation/test/testVertexAssociator.h b/SimTracker/VertexAssociation/test/testVertexAssociator.h deleted file mode 100644 index 8191b5f7e82b4..0000000000000 --- a/SimTracker/VertexAssociation/test/testVertexAssociator.h +++ /dev/null @@ -1,91 +0,0 @@ -#ifndef testVertexAssociator_h -#define testVertexAssociator_h - -#include - -#include "FWCore/Framework/interface/EDAnalyzer.h" -#include "FWCore/Framework/interface/Event.h" -#include "FWCore/Framework/interface/EventSetup.h" -#include "FWCore/ParameterSet/interface/ParameterSet.h" - -#include "TFile.h" -#include "TH1F.h" - -#include -#include -#include -#include - -#include "TMath.h" -#include "TROOT.h" -#include "TTree.h" -#include - -#include "DataFormats/Math/interface/LorentzVector.h" -#include -#include -#include - -namespace reco { - class TrackToTrackingParticleAssociator; - class VertexToTrackingVertexAssociator; -} // namespace reco - -class testVertexAssociator : public edm::EDAnalyzer { -public: - testVertexAssociator(const edm::ParameterSet &conf); - ~testVertexAssociator() override; - void beginJob() override; - void endJob() override; - void analyze(const edm::Event &, const edm::EventSetup &) override; - -private: - const reco::TrackToTrackingParticleAssociator *associatorByChi2; - const reco::TrackToTrackingParticleAssociator *associatorByHits; - const reco::VertexToTrackingVertexAssociator *associatorByTracks; - - edm::InputTag vertexCollection_; - edm::EDGetTokenT associatorByTracksToken; - - int n_event_; - int n_rs_vertices_; - int n_rs_vtxassocs_; - int n_sr_vertices_; - int n_sr_vtxassocs_; - - //--------- RecoToSim Histos ----- - - TH1F *rs_resx; - TH1F *rs_resy; - TH1F *rs_resz; - TH1F *rs_pullx; - TH1F *rs_pully; - TH1F *rs_pullz; - TH1F *rs_dist; - TH1F *rs_simz; - TH1F *rs_recz; - TH1F *rs_nrectrk; - TH1F *rs_nsimtrk; - TH1F *rs_qual; - TH1F *rs_chi2norm; - TH1F *rs_chi2prob; - - //--------- SimToReco Histos ----- - - TH1F *sr_resx; - TH1F *sr_resy; - TH1F *sr_resz; - TH1F *sr_pullx; - TH1F *sr_pully; - TH1F *sr_pullz; - TH1F *sr_dist; - TH1F *sr_simz; - TH1F *sr_recz; - TH1F *sr_nrectrk; - TH1F *sr_nsimtrk; - TH1F *sr_qual; - TH1F *sr_chi2norm; - TH1F *sr_chi2prob; -}; - -#endif From 07d5f2cf5da1e897d95c9b23bd515262936ba1f9 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Mon, 22 Nov 2021 21:31:20 +0100 Subject: [PATCH 2/3] Code check --- SimTracker/TrackAssociation/test/testTrackAssociator.cc | 5 ++--- SimTracker/VertexAssociation/test/testVertexAssociator.cc | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/SimTracker/TrackAssociation/test/testTrackAssociator.cc b/SimTracker/TrackAssociation/test/testTrackAssociator.cc index 667f79a317e63..22432a6b393d9 100644 --- a/SimTracker/TrackAssociation/test/testTrackAssociator.cc +++ b/SimTracker/TrackAssociation/test/testTrackAssociator.cc @@ -47,12 +47,11 @@ testTrackAssociator::testTrackAssociator(edm::ParameterSet const &conf) { tpTag = conf.getParameter("tpTag"); simtracksTag = conf.getParameter("simtracksTag"); simvtxTag = conf.getParameter("simvtxTag"); - tokenMF_ = esConsumes() ; - + tokenMF_ = esConsumes(); } void testTrackAssociator::analyze(const edm::Event &event, const edm::EventSetup &setup) { - const auto& theMF = setup.getHandle(tokenMF_); + const auto &theMF = setup.getHandle(tokenMF_); edm::Handle theChiAssociator; event.getByLabel("trackAssociatorByChi2", theChiAssociator); associatorByChi2 = theChiAssociator.product(); diff --git a/SimTracker/VertexAssociation/test/testVertexAssociator.cc b/SimTracker/VertexAssociation/test/testVertexAssociator.cc index 0231f51e2bbb9..6ca8cecd1bd6e 100644 --- a/SimTracker/VertexAssociation/test/testVertexAssociator.cc +++ b/SimTracker/VertexAssociation/test/testVertexAssociator.cc @@ -170,7 +170,7 @@ void testVertexAssociator::analyze(const edm::Event &event, const edm::EventSetu using namespace edm; using namespace reco; - const auto & theMF = setup.getHandle(tokenMF_); + const auto &theMF = setup.getHandle(tokenMF_); edm::Handle theTracksAssociator; event.getByToken(associatorByTracksToken, theTracksAssociator); From aad6e71c29f47deb0a6de5159e88848246845457 Mon Sep 17 00:00:00 2001 From: Sunanda Date: Mon, 22 Nov 2021 22:37:20 +0100 Subject: [PATCH 3/3] Comment out unused variables --- SimTracker/TrackAssociation/test/testTrackAssociator.cc | 2 +- SimTracker/VertexAssociation/test/testVertexAssociator.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SimTracker/TrackAssociation/test/testTrackAssociator.cc b/SimTracker/TrackAssociation/test/testTrackAssociator.cc index 22432a6b393d9..6117fb5a5ae50 100644 --- a/SimTracker/TrackAssociation/test/testTrackAssociator.cc +++ b/SimTracker/TrackAssociation/test/testTrackAssociator.cc @@ -51,7 +51,7 @@ testTrackAssociator::testTrackAssociator(edm::ParameterSet const &conf) { } void testTrackAssociator::analyze(const edm::Event &event, const edm::EventSetup &setup) { - const auto &theMF = setup.getHandle(tokenMF_); + //const auto &theMF = setup.getHandle(tokenMF_); edm::Handle theChiAssociator; event.getByLabel("trackAssociatorByChi2", theChiAssociator); associatorByChi2 = theChiAssociator.product(); diff --git a/SimTracker/VertexAssociation/test/testVertexAssociator.cc b/SimTracker/VertexAssociation/test/testVertexAssociator.cc index 6ca8cecd1bd6e..4bf37568f66de 100644 --- a/SimTracker/VertexAssociation/test/testVertexAssociator.cc +++ b/SimTracker/VertexAssociation/test/testVertexAssociator.cc @@ -170,7 +170,7 @@ void testVertexAssociator::analyze(const edm::Event &event, const edm::EventSetu using namespace edm; using namespace reco; - const auto &theMF = setup.getHandle(tokenMF_); + //const auto &theMF = setup.getHandle(tokenMF_); edm::Handle theTracksAssociator; event.getByToken(associatorByTracksToken, theTracksAssociator);