Skip to content

Commit

Permalink
Merge pull request #37849 from Dr15Jones/deprecatedRecoLocalMuonDTSeg…
Browse files Browse the repository at this point in the history
…ment

Fixed CMS deprecation warnings in RecoLocalMuon/DTSegment
  • Loading branch information
cmsbuild committed May 10, 2022
2 parents 1f74939 + d080fa1 commit 6dde8da
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 55 deletions.
13 changes: 7 additions & 6 deletions RecoLocalMuon/DTSegment/src/DTClusterer.cc
Expand Up @@ -47,6 +47,7 @@ DTClusterer::DTClusterer(const edm::ParameterSet& pset) {
// min number of hits to build a cluster
theMinLayers = pset.getParameter<unsigned int>("minLayers");

dtGeomToken_ = esConsumes();
if (debug)
cout << "[DTClusterer] Constructor called" << endl;

Expand All @@ -57,12 +58,11 @@ DTClusterer::DTClusterer(const edm::ParameterSet& pset) {
DTClusterer::~DTClusterer() {}

/* Operations */
void DTClusterer::produce(edm::Event& event, const edm::EventSetup& setup) {
void DTClusterer::produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const {
if (debug)
cout << "[DTClusterer] produce called" << endl;
// Get the DT Geometry
ESHandle<DTGeometry> dtGeom;
setup.get<MuonGeometryRecord>().get(dtGeom);
ESHandle<DTGeometry> dtGeom = setup.getHandle(dtGeomToken_);

// Get the 1D rechits from the event
Handle<DTRecHitCollection> allHits;
Expand Down Expand Up @@ -103,7 +103,7 @@ void DTClusterer::produce(edm::Event& event, const edm::EventSetup& setup) {
event.put(std::move(clusters));
}

vector<DTSLRecCluster> DTClusterer::buildClusters(const DTSuperLayer* sl, vector<DTRecHit1DPair>& pairs) {
vector<DTSLRecCluster> DTClusterer::buildClusters(const DTSuperLayer* sl, vector<DTRecHit1DPair>& pairs) const {
// create a vector of hits with wire position in SL frame
vector<pair<float, DTRecHit1DPair> > hits = initHits(sl, pairs);

Expand Down Expand Up @@ -157,7 +157,8 @@ vector<DTSLRecCluster> DTClusterer::buildClusters(const DTSuperLayer* sl, vector
return result;
}

vector<pair<float, DTRecHit1DPair> > DTClusterer::initHits(const DTSuperLayer* sl, vector<DTRecHit1DPair>& pairs) {
vector<pair<float, DTRecHit1DPair> > DTClusterer::initHits(const DTSuperLayer* sl,
vector<DTRecHit1DPair>& pairs) const {
vector<pair<float, DTRecHit1DPair> > result;
for (vector<DTRecHit1DPair>::const_iterator pair = pairs.begin(); pair != pairs.end(); ++pair) {
// get wire
Expand All @@ -176,7 +177,7 @@ vector<pair<float, DTRecHit1DPair> > DTClusterer::initHits(const DTSuperLayer* s
return result;
}

unsigned int DTClusterer::differentLayers(vector<DTRecHit1DPair>& hits) {
unsigned int DTClusterer::differentLayers(vector<DTRecHit1DPair>& hits) const {
// Count the number of different layers
int layers = 0;
unsigned int result = 0;
Expand Down
18 changes: 11 additions & 7 deletions RecoLocalMuon/DTSegment/src/DTClusterer.h
Expand Up @@ -14,7 +14,7 @@
*/

/* Base Class Headers */
#include "FWCore/Framework/interface/EDProducer.h"
#include "FWCore/Framework/interface/global/EDProducer.h"

namespace edm {
class ParameterSet;
Expand All @@ -27,6 +27,8 @@ namespace edm {
#include "DataFormats/DTRecHit/interface/DTSLRecCluster.h"
#include "DataFormats/DTRecHit/interface/DTRecHit1DPair.h"
#include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
#include "Geometry/DTGeometry/interface/DTGeometry.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"
class DTSuperLayer;

/* C++ Headers */
Expand All @@ -37,7 +39,7 @@ class DTSuperLayer;

/* Class DTClusterer Interface */

class DTClusterer : public edm::EDProducer {
class DTClusterer : public edm::global::EDProducer<> {
public:
/* Constructor */
DTClusterer(const edm::ParameterSet&);
Expand All @@ -46,20 +48,21 @@ class DTClusterer : public edm::EDProducer {
~DTClusterer() override;

/* Operations */
void produce(edm::Event& event, const edm::EventSetup& setup) override;
void produce(edm::StreamID, edm::Event& event, const edm::EventSetup& setup) const override;

private:
// build clusters from hits
std::vector<DTSLRecCluster> buildClusters(const DTSuperLayer* sl, std::vector<DTRecHit1DPair>& pairs);
std::vector<DTSLRecCluster> buildClusters(const DTSuperLayer* sl, std::vector<DTRecHit1DPair>& pairs) const;

std::vector<std::pair<float, DTRecHit1DPair> > initHits(const DTSuperLayer* sl, std::vector<DTRecHit1DPair>& pairs);
std::vector<std::pair<float, DTRecHit1DPair> > initHits(const DTSuperLayer* sl,
std::vector<DTRecHit1DPair>& pairs) const;

unsigned int differentLayers(std::vector<DTRecHit1DPair>& hits);
unsigned int differentLayers(std::vector<DTRecHit1DPair>& hits) const;

private:
// to sort hits by x
struct sortClusterByX {
bool operator()(const std::pair<float, DTRecHit1DPair>& lhs, const std::pair<float, DTRecHit1DPair>& rhs) {
bool operator()(const std::pair<float, DTRecHit1DPair>& lhs, const std::pair<float, DTRecHit1DPair>& rhs) const {
return lhs.first < rhs.first;
}
};
Expand All @@ -71,6 +74,7 @@ class DTClusterer : public edm::EDProducer {
unsigned int theMinHits; // min number of hits to build a cluster
unsigned int theMinLayers; // min number of layers to build a cluster
edm::EDGetTokenT<DTRecHitCollection> recHits1DToken_;
edm::ESGetToken<DTGeometry, MuonGeometryRecord> dtGeomToken_;

protected:
};
Expand Down
4 changes: 2 additions & 2 deletions RecoLocalMuon/DTSegment/test/DTAnalyzerDetailed.h
Expand Up @@ -14,7 +14,7 @@
*/

/* Base Class Headers */
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
namespace edm {
class ParameterSet;
class Event;
Expand All @@ -41,7 +41,7 @@ class DTGeometry;

/* Class DTAnalyzerDetailed Interface */

class DTAnalyzerDetailed : public edm::EDAnalyzer {
class DTAnalyzerDetailed : public edm::one::EDAnalyzer<> {
public:
/* Constructor */
DTAnalyzerDetailed(const edm::ParameterSet& pset);
Expand Down
16 changes: 8 additions & 8 deletions RecoLocalMuon/DTSegment/test/DTClusAnalyzer.cc
Expand Up @@ -42,18 +42,22 @@ using namespace std;

/* Constructor */
DTClusAnalyzer::DTClusAnalyzer(const ParameterSet& pset) : _ev(0) {
theDtGeomToken = esConsumes();
// Get the debug parameter for verbose output
debug = pset.getUntrackedParameter<bool>("debug");
theRootFileName = pset.getUntrackedParameter<string>("rootFileName");

// the name of the clus rec hits collection
theRecClusLabel = pset.getParameter<string>("recClusLabel");
theRecClusToken = consumes(edm::InputTag(theRecClusLabel));

// the name of the 1D rec hits collection
theRecHits1DLabel = pset.getParameter<string>("recHits1DLabel");
theRecHits1DToken = consumes(edm::InputTag(theRecHits1DLabel));

// the name of the 2D rec hits collection
theRecHits2DLabel = pset.getParameter<string>("recHits2DLabel");
theRecHits2DToken = consumes(edm::InputTag(theRecHits2DLabel));

// Create the root file
theFile = new TFile(theRootFileName.c_str(), "RECREATE");
Expand Down Expand Up @@ -110,20 +114,16 @@ void DTClusAnalyzer::analyze(const Event& event, const EventSetup& eventSetup) {
}

// Get the DT Geometry
ESHandle<DTGeometry> dtGeom;
eventSetup.get<MuonGeometryRecord>().get(dtGeom);
ESHandle<DTGeometry> dtGeom = eventSetup.getHandle(theDtGeomToken);

// Get the 1D clusters from the event --------------
Handle<DTRecClusterCollection> dtClusters;
event.getByLabel(theRecClusLabel, dtClusters);
Handle<DTRecClusterCollection> dtClusters = event.getHandle(theRecClusToken);

// Get the 1D rechits from the event --------------
Handle<DTRecHitCollection> dtRecHits;
event.getByLabel(theRecHits1DLabel, dtRecHits);
Handle<DTRecHitCollection> dtRecHits = event.getHandle(theRecHits1DToken);

// Get the 2D rechit collection from the event -------------------
edm::Handle<DTRecSegment2DCollection> segs2d;
event.getByLabel(theRecHits2DLabel, segs2d);
edm::Handle<DTRecSegment2DCollection> segs2d = event.getHandle(theRecHits2DToken);

// only clusters
int nClus = dtClusters->size();
Expand Down
16 changes: 14 additions & 2 deletions RecoLocalMuon/DTSegment/test/DTClusAnalyzer.h
Expand Up @@ -14,7 +14,7 @@
*/

/* Base Class Headers */
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
namespace edm {
class ParameterSet;
class Event;
Expand All @@ -27,14 +27,20 @@ class TFile;
class TH1F;
class TH2F;

#include "Geometry/DTGeometry/interface/DTGeometry.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"
#include "DataFormats/DTRecHit/interface/DTRecHitCollection.h"
#include "DataFormats/DTRecHit/interface/DTRecSegment2DCollection.h"
#include "DataFormats/DTRecHit/interface/DTRecClusterCollection.h"

/* C++ Headers */
#include <iosfwd>

/* ====================================================================== */

/* Class DTClusAnalyzer Interface */

class DTClusAnalyzer : public edm::EDAnalyzer {
class DTClusAnalyzer : public edm::one::EDAnalyzer<> {
public:
/* Constructor */
DTClusAnalyzer(const edm::ParameterSet& pset);
Expand All @@ -59,6 +65,12 @@ class DTClusAnalyzer : public edm::EDAnalyzer {
std::string theRecHits2DLabel;
std::string theRecHits1DLabel;

edm::ESGetToken<DTGeometry, MuonGeometryRecord> theDtGeomToken;

edm::EDGetTokenT<DTRecClusterCollection> theRecClusToken;
edm::EDGetTokenT<DTRecHitCollection> theRecHits1DToken;
edm::EDGetTokenT<DTRecSegment2DCollection> theRecHits2DToken;

protected:
};
#endif // DTCLUSANALYZER_H
9 changes: 4 additions & 5 deletions RecoLocalMuon/DTSegment/test/DTEffAnalyzer.cc
Expand Up @@ -45,7 +45,7 @@ using namespace std;
/* ====================================================================== */

/* Constructor */
DTEffAnalyzer::DTEffAnalyzer(const ParameterSet& pset) {
DTEffAnalyzer::DTEffAnalyzer(const ParameterSet& pset) : theDtGeomToken(esConsumes()) {
// Get the debug parameter for verbose output
debug = pset.getUntrackedParameter<bool>("debug");
theRootFileName = pset.getUntrackedParameter<string>("rootFileName");
Expand All @@ -62,11 +62,8 @@ DTEffAnalyzer::DTEffAnalyzer(const ParameterSet& pset) {
theMinHitsSegment = static_cast<unsigned int>(pset.getParameter<int>("minHitsSegment"));
theMinChi2NormSegment = pset.getParameter<double>("minChi2NormSegment");
theMinCloseDist = pset.getParameter<double>("minCloseDist");
}

void DTEffAnalyzer::beginRun(const edm::Run& run, const EventSetup& setup) {
// Get the DT Geometry
setup.get<MuonGeometryRecord>().get(dtGeom);
consumes<DTRecSegment4DCollection>(theRecHits4DLabel);
}

void DTEffAnalyzer::beginJob() {
Expand Down Expand Up @@ -137,6 +134,8 @@ DTEffAnalyzer::~DTEffAnalyzer() {

/* Operations */
void DTEffAnalyzer::analyze(const Event& event, const EventSetup& eventSetup) {
dtGeom = eventSetup.getHandle(theDtGeomToken);

if (debug)
cout << endl
<< "--- [DTEffAnalyzer] Event analysed #Run: " << event.id().run() << " #Event: " << event.id().event()
Expand Down
7 changes: 4 additions & 3 deletions RecoLocalMuon/DTSegment/test/DTEffAnalyzer.h
Expand Up @@ -14,7 +14,7 @@
*/

/* Base Class Headers */
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
namespace edm {
class ParameterSet;
class Event;
Expand All @@ -31,6 +31,7 @@ class DTLayerId;
class DTSuperLayerId;
class DTChamberId;
#include "Geometry/DTGeometry/interface/DTGeometry.h"
#include "Geometry/Records/interface/MuonGeometryRecord.h"
#include "DataFormats/DTRecHit/interface/DTRecSegment4DCollection.h"
class DTTTrigBaseSync;

Expand All @@ -41,7 +42,7 @@ class DTTTrigBaseSync;

/* Class DTEffAnalyzer Interface */

class DTEffAnalyzer : public edm::EDAnalyzer {
class DTEffAnalyzer : public edm::one::EDAnalyzer<> {
public:
/* Constructor */
DTEffAnalyzer(const edm::ParameterSet& pset);
Expand All @@ -53,7 +54,6 @@ class DTEffAnalyzer : public edm::EDAnalyzer {

void analyze(const edm::Event& event, const edm::EventSetup& eventSetup);
void beginJob();
void beginRun(const edm::Run& run, const edm::EventSetup& setup);

private:
TH1F* histo(const std::string& name) const;
Expand Down Expand Up @@ -104,6 +104,7 @@ class DTEffAnalyzer : public edm::EDAnalyzer {
double theMinCloseDist;

edm::ESHandle<DTGeometry> dtGeom;
edm::ESGetToken<DTGeometry, MuonGeometryRecord> theDtGeomToken;
edm::Handle<DTRecSegment4DCollection> segs;

protected:
Expand Down
4 changes: 2 additions & 2 deletions RecoLocalMuon/DTSegment/test/DTSegAnalyzer.h
Expand Up @@ -14,7 +14,7 @@
*/

/* Base Class Headers */
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
namespace edm {
class ParameterSet;
class Event;
Expand All @@ -41,7 +41,7 @@ class MuonGeometryRecord;

/* Class DTSegAnalyzer Interface */

class DTSegAnalyzer : public edm::EDAnalyzer {
class DTSegAnalyzer : public edm::one::EDAnalyzer<> {
public:
/* Constructor */
DTSegAnalyzer(const edm::ParameterSet& pset);
Expand Down
27 changes: 13 additions & 14 deletions RecoLocalMuon/DTSegment/test/STAnalyzer.cc
Expand Up @@ -80,6 +80,7 @@ STAnalyzer::STAnalyzer(const ParameterSet& pset) : _ev(0) {

thePropagatorName = pset.getParameter<std::string>("PropagatorName");
thePropagator = 0;
thePropagatorToken = esConsumes(edm::ESInputTag("", thePropagatorName));

doSA = pset.getParameter<bool>("doSA");

Expand Down Expand Up @@ -197,6 +198,11 @@ STAnalyzer::STAnalyzer(const ParameterSet& pset) : _ev(0) {
300.);

TH1::AddDirectory(dirStat);

theDtGeomTokenBR = esConsumes<edm::Transition::BeginRun>();
theDtGeomToken = esConsumes();
theMGFieldToken = esConsumes();
theTrackingGeometryToken = esConsumes();
}

/* Destructor */
Expand All @@ -208,18 +214,15 @@ STAnalyzer::~STAnalyzer() {

void STAnalyzer::beginRun(const edm::Run& run, const EventSetup& setup) {
// Get the DT Geometry
ESHandle<DTGeometry> dtGeom;
setup.get<MuonGeometryRecord>().get(dtGeom);

static bool FirstPass = true;
ESHandle<DTGeometry> dtGeom = setup.getHandle(theDtGeomTokenBR);

if (FirstPass) {
if (firstPass) {
const std::vector<const DTChamber*>& chs = dtGeom->chambers();
for (auto ch = chs.begin(); ch != chs.end(); ++ch)
hitsPerChamber[(*ch)->id()] = 0;
}

FirstPass = false;
firstPass = false;
}

/* Operations */
Expand All @@ -243,8 +246,7 @@ void STAnalyzer::analyzeSATrack(const Event& event, const EventSetup& eventSetup
if (debug)
cout << "STAnalyzer::analyzeSATrack" << endl;
if (!thePropagator) {
ESHandle<Propagator> prop;
eventSetup.get<TrackingComponentsRecord>().get(thePropagatorName, prop);
ESHandle<Propagator> prop = eventSetup.getHandle(thePropagatorToken);
thePropagator = prop->clone();
thePropagator->setPropagationDirection(anyDirection);
}
Expand Down Expand Up @@ -279,11 +281,9 @@ void STAnalyzer::analyzeSATrack(const Event& event, const EventSetup& eventSetup
cout << "ALL Tracks size " << (*i).product()->size() << endl;
}

ESHandle<MagneticField> theMGField;
eventSetup.get<IdealMagneticFieldRecord>().get(theMGField);
ESHandle<MagneticField> theMGField = eventSetup.getHandle(theMGFieldToken);

ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
eventSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
ESHandle<GlobalTrackingGeometry> theTrackingGeometry = eventSetup.getHandle(theTrackingGeometryToken);

reco::TrackCollection::const_iterator staTrack;

Expand Down Expand Up @@ -435,8 +435,7 @@ void STAnalyzer::analyzeSATrack(const Event& event, const EventSetup& eventSetup
}

// Get the DT Geometry
ESHandle<DTGeometry> dtGeom;
eventSetup.get<MuonGeometryRecord>().get(dtGeom);
ESHandle<DTGeometry> dtGeom = eventSetup.getHandle(theDtGeomToken);

// Get the 1D rechits from the event --------------
Handle<DTRecHitCollection> hits1d;
Expand Down

0 comments on commit 6dde8da

Please sign in to comment.