Skip to content

Commit

Permalink
Merge pull request #37069 from mmusich/modernizeSimTracker
Browse files Browse the repository at this point in the history
get rid of `CMSDEPRECATED_X` warnings in `SimTracker`
  • Loading branch information
cmsbuild authored Feb 27, 2022
2 parents 974fe40 + c574b74 commit faf2a1b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "SimTracker/SiPhase2Digitizer/plugins/PixelBrickedDigitizerAlgorithm.h"
#include "SimTracker/SiPhase2Digitizer/plugins/DigitizerUtility.h"

#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"
Expand Down
36 changes: 16 additions & 20 deletions SimTracker/TrackHistory/plugins/QualityCutsAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@
class QualityCutsAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit QualityCutsAnalyzer(const edm::ParameterSet &);
~QualityCutsAnalyzer() override;
~QualityCutsAnalyzer() override = default;

private:
void beginJob() override;
void analyze(const edm::Event &, const edm::EventSetup &) override;
void endJob() override;

// Member data
const edm::ESGetToken<TransientTrackBuilder, TransientTrackRecord> ttrkToken_;
const edm::EDGetTokenT<edm::View<reco::Track>> trkToken_;
const edm::EDGetTokenT<reco::VertexCollection> vtxToken_;
const edm::EDGetTokenT<reco::JetTracksAssociationCollection> jtaToken_;

typedef std::vector<int> vint;
typedef std::vector<std::string> vstring;

edm::InputTag trackProducer_;
edm::InputTag primaryVertexProducer_;
edm::InputTag jetTracksAssociation_;

std::string rootFile_;

int minimumNumberOfHits_, minimumNumberOfPixelHits_;
Expand Down Expand Up @@ -201,14 +201,13 @@ class QualityCutsAnalyzer : public edm::one::EDAnalyzer<> {
//
// constructors and destructor
//
QualityCutsAnalyzer::QualityCutsAnalyzer(const edm::ParameterSet &config) : classifier_(config, consumesCollector()) {
trackProducer_ = config.getUntrackedParameter<edm::InputTag>("trackProducer");
consumes<edm::View<reco::Track>>(trackProducer_);
primaryVertexProducer_ = config.getUntrackedParameter<edm::InputTag>("primaryVertexProducer");
consumes<reco::VertexCollection>(primaryVertexProducer_);
jetTracksAssociation_ = config.getUntrackedParameter<edm::InputTag>("jetTracksAssociation");
consumes<reco::JetTracksAssociationCollection>(jetTracksAssociation_);

QualityCutsAnalyzer::QualityCutsAnalyzer(const edm::ParameterSet &config)
: ttrkToken_(esConsumes(edm::ESInputTag("", "TransientTrackBuilder"))),
trkToken_(consumes<edm::View<reco::Track>>(config.getUntrackedParameter<edm::InputTag>("trackProducer"))),
vtxToken_(consumes<reco::VertexCollection>(config.getUntrackedParameter<edm::InputTag>("primaryVertexProducer"))),
jtaToken_(consumes<reco::JetTracksAssociationCollection>(
config.getUntrackedParameter<edm::InputTag>("jetTracksAssociation"))),
classifier_(config, consumesCollector()) {
rootFile_ = config.getUntrackedParameter<std::string>("rootFile");

minimumNumberOfHits_ = config.getUntrackedParameter<int>("minimumNumberOfHits");
Expand All @@ -228,8 +227,6 @@ QualityCutsAnalyzer::QualityCutsAnalyzer(const edm::ParameterSet &config) : clas
}
}

QualityCutsAnalyzer::~QualityCutsAnalyzer() {}

//
// member functions
//
Expand All @@ -238,16 +235,15 @@ QualityCutsAnalyzer::~QualityCutsAnalyzer() {}
void QualityCutsAnalyzer::analyze(const edm::Event &event, const edm::EventSetup &setup) {
// Track collection
edm::Handle<edm::View<reco::Track>> trackCollection;
event.getByLabel(trackProducer_, trackCollection);
event.getByToken(trkToken_, trackCollection);
// Primary vertex
edm::Handle<reco::VertexCollection> primaryVertexCollection;
event.getByLabel(primaryVertexProducer_, primaryVertexCollection);
event.getByToken(vtxToken_, primaryVertexCollection);
// Jet to tracks associator
edm::Handle<reco::JetTracksAssociationCollection> jetTracks;
event.getByLabel(jetTracksAssociation_, jetTracks);
event.getByToken(jtaToken_, jetTracks);
// Trasient track builder
edm::ESHandle<TransientTrackBuilder> TTbuilder;
setup.get<TransientTrackRecord>().get("TransientTrackBuilder", TTbuilder);
const edm::ESHandle<TransientTrackBuilder> TTbuilder = setup.getHandle(ttrkToken_);

// Setting up event information for the track categories.
classifier_.newEvent(event, setup);
Expand Down
61 changes: 29 additions & 32 deletions SimTracker/TrackHistory/plugins/TrackHistoryAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@
// class decleration
//

class TrackHistoryAnalyzer : public edm::one::EDAnalyzer<> {
class TrackHistoryAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
explicit TrackHistoryAnalyzer(const edm::ParameterSet &);
~TrackHistoryAnalyzer() override;
~TrackHistoryAnalyzer() override = default;

private:
virtual void beginRun(const edm::Run &, const edm::EventSetup &);
void beginJob() override;
void beginRun(const edm::Run &, const edm::EventSetup &) override;
void analyze(const edm::Event &, const edm::EventSetup &) override;
void endRun(const edm::Run &, const edm::EventSetup &) override{};

// Member data

edm::InputTag trackProducer_;
const edm::ESGetToken<ParticleDataTable, PDTRecord> pdtToken_;
const edm::EDGetTokenT<edm::View<reco::Track>> trkToken_;

std::size_t totalTracks_;

Expand All @@ -62,17 +63,15 @@ class TrackHistoryAnalyzer : public edm::one::EDAnalyzer<> {
HepMC::GenVertex::particles_out_const_iterator) const;
};

TrackHistoryAnalyzer::TrackHistoryAnalyzer(const edm::ParameterSet &config) : classifier_(config, consumesCollector()) {
trackProducer_ = config.getUntrackedParameter<edm::InputTag>("trackProducer");
consumes<edm::View<reco::Track>>(trackProducer_);
}

TrackHistoryAnalyzer::~TrackHistoryAnalyzer() {}
TrackHistoryAnalyzer::TrackHistoryAnalyzer(const edm::ParameterSet &config)
: pdtToken_(esConsumes<edm::Transition::BeginRun>()),
trkToken_(consumes<edm::View<reco::Track>>(config.getUntrackedParameter<edm::InputTag>("trackProducer"))),
classifier_(config, consumesCollector()) {}

void TrackHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSetup &setup) {
// Track collection
edm::Handle<edm::View<reco::Track>> trackCollection;
event.getByLabel(trackProducer_, trackCollection);
event.getByToken(trkToken_, trackCollection);

// Set the classifier for a new event
classifier_.newEvent(event, setup);
Expand All @@ -82,7 +81,7 @@ void TrackHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSetu

// Loop over the track collection.
for (std::size_t index = 0; index < trackCollection->size(); index++) {
std::cout << std::endl << "History for track #" << index << " : " << std::endl;
edm::LogPrint("TrackHistoryAnalyzer") << std::endl << "History for track #" << index << " : ";

// Classify the track and detect for fakes
if (!classifier_.evaluate(reco::TrackBaseRef(trackCollection, index)).is(TrackClassifier::Fake)) {
Expand All @@ -91,8 +90,8 @@ void TrackHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSetu

// Loop over all simParticles
for (std::size_t hindex = 0; hindex < simParticles.size(); hindex++) {
std::cout << " simParticles [" << hindex << "] : " << particleString(simParticles[hindex]->pdgId())
<< std::endl;
edm::LogPrint("TrackHistoryAnalyzer")
<< " simParticles [" << hindex << "] : " << particleString(simParticles[hindex]->pdgId());
}

// Get the list of TrackingVertexes associated to
Expand All @@ -101,20 +100,20 @@ void TrackHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSetu
// Loop over all simVertexes
if (!simVertexes.empty()) {
for (std::size_t hindex = 0; hindex < simVertexes.size(); hindex++) {
std::cout << " simVertex [" << hindex << "] : "
<< vertexString(simVertexes[hindex]->sourceTracks(), simVertexes[hindex]->daughterTracks())
<< std::endl;
edm::LogPrint("TrackHistoryAnalyzer")
<< " simVertex [" << hindex
<< "] : " << vertexString(simVertexes[hindex]->sourceTracks(), simVertexes[hindex]->daughterTracks());
}
} else
std::cout << " simVertex no found" << std::endl;
edm::LogPrint("TrackHistoryAnalyzer") << " simVertex no found";

// Get the list of GenParticles associated to
TrackHistory::GenParticleTrail genParticles(tracer.genParticleTrail());

// Loop over all genParticles
for (std::size_t hindex = 0; hindex < genParticles.size(); hindex++) {
std::cout << " genParticles [" << hindex << "] : " << particleString(genParticles[hindex]->pdg_id())
<< std::endl;
edm::LogPrint("TrackHistoryAnalyzer")
<< " genParticles [" << hindex << "] : " << particleString(genParticles[hindex]->pdg_id());
}

// Get the list of TrackingVertexes associated to
Expand All @@ -123,26 +122,24 @@ void TrackHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSetu
// Loop over all simVertexes
if (!genVertexes.empty()) {
for (std::size_t hindex = 0; hindex < genVertexes.size(); hindex++) {
std::cout << " genVertex [" << hindex << "] : "
<< vertexString(genVertexes[hindex]->particles_in_const_begin(),
genVertexes[hindex]->particles_in_const_end(),
genVertexes[hindex]->particles_out_const_begin(),
genVertexes[hindex]->particles_out_const_end())
<< std::endl;
edm::LogPrint("TrackHistoryAnalyzer") << " genVertex [" << hindex << "] : "
<< vertexString(genVertexes[hindex]->particles_in_const_begin(),
genVertexes[hindex]->particles_in_const_end(),
genVertexes[hindex]->particles_out_const_begin(),
genVertexes[hindex]->particles_out_const_end());
}
} else
std::cout << " genVertex no found" << std::endl;
edm::LogPrint("TrackHistoryAnalyzer") << " genVertex no found";
} else
std::cout << " fake track" << std::endl;
edm::LogPrint("TrackHistoryAnalyzer") << " fake track";

std::cout << " track categories : " << classifier_;
std::cout << std::endl;
edm::LogPrint("TrackHistoryAnalyzer") << " track categories : " << classifier_;
}
}

void TrackHistoryAnalyzer::beginRun(const edm::Run &run, const edm::EventSetup &setup) {
// Get the particles table.
setup.getData(pdt_);
pdt_ = setup.getHandle(pdtToken_);
}

void TrackHistoryAnalyzer::beginJob() { totalTracks_ = 0; }
Expand Down
61 changes: 29 additions & 32 deletions SimTracker/TrackHistory/plugins/VertexHistoryAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Utilities/interface/EDGetToken.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand All @@ -31,21 +32,22 @@
// class decleration
//

class VertexHistoryAnalyzer : public edm::one::EDAnalyzer<> {
class VertexHistoryAnalyzer : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
public:
explicit VertexHistoryAnalyzer(const edm::ParameterSet &);
~VertexHistoryAnalyzer() override = default;

private:
virtual void beginRun(const edm::Run &, const edm::EventSetup &);
void beginJob() override;
void beginRun(const edm::Run &, const edm::EventSetup &) override;
void endRun(const edm::Run &, const edm::EventSetup &) override{};
void analyze(const edm::Event &, const edm::EventSetup &) override;

// Member data
const edm::ESGetToken<ParticleDataTable, PDTRecord> pdtToken_;
const edm::EDGetTokenT<edm::View<reco::Vertex>> vtxToken_;

VertexClassifier classifier_;

edm::InputTag vertexProducer_;

edm::ESHandle<ParticleDataTable> pdt_;

std::string particleString(int) const;
Expand All @@ -59,25 +61,24 @@ class VertexHistoryAnalyzer : public edm::one::EDAnalyzer<> {
};

VertexHistoryAnalyzer::VertexHistoryAnalyzer(const edm::ParameterSet &config)
: classifier_(config, consumesCollector()) {
vertexProducer_ = config.getUntrackedParameter<edm::InputTag>("vertexProducer");
consumes<edm::View<reco::Vertex>>(vertexProducer_);
}
: pdtToken_(esConsumes<edm::Transition::BeginRun>()),
vtxToken_(consumes<edm::View<reco::Vertex>>(config.getUntrackedParameter<edm::InputTag>("vertexProducer"))),
classifier_(config, consumesCollector()) {}

void VertexHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSetup &setup) {
// Set the classifier for a new event
classifier_.newEvent(event, setup);

// Vertex collection
edm::Handle<edm::View<reco::Vertex>> vertexCollection;
event.getByLabel(vertexProducer_, vertexCollection);
event.getByToken(vtxToken_, vertexCollection);

// Get a constant reference to the track history associated to the classifier
VertexHistory const &tracer = classifier_.history();

// Loop over the track collection.
for (std::size_t index = 0; index < vertexCollection->size(); index++) {
std::cout << std::endl << "History for vertex #" << index << " : " << std::endl;
edm::LogPrint("VertexHistoryAnalyzer") << std::endl << "History for vertex #" << index << " : ";

// Classify the track and detect for fakes
if (!classifier_.evaluate(reco::VertexBaseRef(vertexCollection, index)).is(VertexClassifier::Fake)) {
Expand All @@ -86,8 +87,8 @@ void VertexHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSet

// Loop over all simParticles
for (std::size_t hindex = 0; hindex < simParticles.size(); hindex++) {
std::cout << " simParticles [" << hindex << "] : " << particleString(simParticles[hindex]->pdgId())
<< std::endl;
edm::LogPrint("VertexHistoryAnalyzer")
<< " simParticles [" << hindex << "] : " << particleString(simParticles[hindex]->pdgId());
}

// Get the list of TrackingVertexes associated to
Expand All @@ -96,20 +97,20 @@ void VertexHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSet
// Loop over all simVertexes
if (!simVertexes.empty()) {
for (std::size_t hindex = 0; hindex < simVertexes.size(); hindex++) {
std::cout << " simVertex [" << hindex << "] : "
<< vertexString(simVertexes[hindex]->sourceTracks(), simVertexes[hindex]->daughterTracks())
<< std::endl;
edm::LogPrint("VertexHistoryAnalyzer")
<< " simVertex [" << hindex
<< "] : " << vertexString(simVertexes[hindex]->sourceTracks(), simVertexes[hindex]->daughterTracks());
}
} else
std::cout << " simVertex no found" << std::endl;
edm::LogPrint("VertexHistoryAnalyzer") << " simVertex no found";

// Get the list of GenParticles associated to
VertexHistory::GenParticleTrail genParticles(tracer.genParticleTrail());

// Loop over all genParticles
for (std::size_t hindex = 0; hindex < genParticles.size(); hindex++) {
std::cout << " genParticles [" << hindex << "] : " << particleString(genParticles[hindex]->pdg_id())
<< std::endl;
edm::LogPrint("VertexHistoryAnalyzer")
<< " genParticles [" << hindex << "] : " << particleString(genParticles[hindex]->pdg_id());
}

// Get the list of TrackingVertexes associated to
Expand All @@ -118,30 +119,26 @@ void VertexHistoryAnalyzer::analyze(const edm::Event &event, const edm::EventSet
// Loop over all simVertexes
if (!genVertexes.empty()) {
for (std::size_t hindex = 0; hindex < genVertexes.size(); hindex++) {
std::cout << " genVertex [" << hindex << "] : "
<< vertexString(genVertexes[hindex]->particles_in_const_begin(),
genVertexes[hindex]->particles_in_const_end(),
genVertexes[hindex]->particles_out_const_begin(),
genVertexes[hindex]->particles_out_const_end())
<< std::endl;
edm::LogPrint("VertexHistoryAnalyzer") << " genVertex [" << hindex << "] : "
<< vertexString(genVertexes[hindex]->particles_in_const_begin(),
genVertexes[hindex]->particles_in_const_end(),
genVertexes[hindex]->particles_out_const_begin(),
genVertexes[hindex]->particles_out_const_end());
}
} else
std::cout << " genVertex no found" << std::endl;
edm::LogPrint("VertexHistoryAnalyzer") << " genVertex no found";
} else
std::cout << " fake vertex" << std::endl;
edm::LogPrint("VertexHistoryAnalyzer") << " fake vertex";

std::cout << " vertex categories : " << classifier_;
std::cout << std::endl;
edm::LogPrint("VertexHistoryAnalyzer") << " vertex categories : " << classifier_;
}
}

void VertexHistoryAnalyzer::beginRun(const edm::Run &run, const edm::EventSetup &setup) {
// Get the particles table.
setup.getData(pdt_);
pdt_ = setup.getHandle(pdtToken_);
}

void VertexHistoryAnalyzer::beginJob() {}

std::string VertexHistoryAnalyzer::particleString(int pdgId) const {
ParticleData const *pid;

Expand Down

0 comments on commit faf2a1b

Please sign in to comment.