Skip to content

Commit

Permalink
Merge pull request #37341 from seungjin-yang/Fix-GEMCSCSegmentProduce…
Browse files Browse the repository at this point in the history
…r-Geometry-Loading__from-CMSSW_12_2_X_2022-03-18-2300

Migrate to EventSetup with ESGetToken in GEMCSCSegmentProducer (backport of #36628, 12_2_X)
  • Loading branch information
cmsbuild authored Mar 28, 2022
2 parents ea11be5 + cc3d2b6 commit aef6b64
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 22 deletions.
40 changes: 27 additions & 13 deletions RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#include <FWCore/Framework/interface/ESHandle.h>
#include <FWCore/MessageLogger/interface/MessageLogger.h>

#include <Geometry/Records/interface/MuonGeometryRecord.h>

#include <DataFormats/GEMRecHit/interface/GEMRecHitCollection.h>
#include <DataFormats/GEMRecHit/interface/GEMCSCSegmentCollection.h>
#include <DataFormats/GEMRecHit/interface/GEMCSCSegment.h>
Expand All @@ -19,9 +17,12 @@
#include <DataFormats/CSCRecHit/interface/CSCSegmentCollection.h>
#include <DataFormats/CSCRecHit/interface/CSCSegment.h>

GEMCSCSegmentProducer::GEMCSCSegmentProducer(const edm::ParameterSet& pas) : iev(0) {
csc_token = consumes<CSCSegmentCollection>(pas.getParameter<edm::InputTag>("inputObjectsCSC"));
gem_token = consumes<GEMRecHitCollection>(pas.getParameter<edm::InputTag>("inputObjectsGEM"));
GEMCSCSegmentProducer::GEMCSCSegmentProducer(const edm::ParameterSet& pas)
: kCSCGeometryToken_(esConsumes<CSCGeometry, MuonGeometryRecord>()),
kGEMGeometryToken_(esConsumes<GEMGeometry, MuonGeometryRecord>()),
kCSCSegmentCollectionToken_(consumes<CSCSegmentCollection>(pas.getParameter<edm::InputTag>("inputObjectsCSC"))),
kGEMRecHitCollectionToken_(consumes<GEMRecHitCollection>(pas.getParameter<edm::InputTag>("inputObjectsGEM"))),
iev(0) {
segmentBuilder_ = new GEMCSCSegmentBuilder(pas); // pass on the parameterset

// register what this produces
Expand All @@ -37,12 +38,18 @@ void GEMCSCSegmentProducer::produce(edm::Event& ev, const edm::EventSetup& setup
LogDebug("GEMCSCSegment") << "start producing segments for " << ++iev << "th event w/ gem and csc data";

// find the geometry (& conditions?) for this event & cache it in the builder
edm::ESHandle<CSCGeometry> cscg;
setup.get<MuonGeometryRecord>().get(cscg);
const auto cscg = setup.getHandle(kCSCGeometryToken_);
if (not cscg.isValid()) {
edm::LogError("GEMCSCSegment") << "invalid CSCGeometry";
return;
}
const CSCGeometry* cgeom = &*cscg;

edm::ESHandle<GEMGeometry> gemg;
setup.get<MuonGeometryRecord>().get(gemg);
const auto gemg = setup.getHandle(kGEMGeometryToken_);
if (not gemg.isValid()) {
edm::LogError("GEMCSCSegment") << "invalid GEMGeometry";
return;
}
const GEMGeometry* ggeom = &*gemg;

// cache the geometry in the builder
Expand All @@ -52,10 +59,17 @@ void GEMCSCSegmentProducer::produce(edm::Event& ev, const edm::EventSetup& setup
segmentBuilder_->LinkGEMRollsToCSCChamberIndex(ggeom, cgeom);

// get the collection of CSCSegment and GEMRecHits
edm::Handle<CSCSegmentCollection> cscSegment;
ev.getByToken(csc_token, cscSegment);
edm::Handle<GEMRecHitCollection> gemRecHits;
ev.getByToken(gem_token, gemRecHits);
const auto cscSegment = ev.getHandle(kCSCSegmentCollectionToken_);
if (not cscSegment.isValid()) {
edm::LogError("GEMCSCSegment") << "invalid CSCSegmentCollection";
return;
}

const auto gemRecHits = ev.getHandle(kGEMRecHitCollectionToken_);
if (not gemRecHits.isValid()) {
edm::LogError("GEMCSCSegment") << "invalid GEMRecHitCollection";
return;
}

// create empty collection of GEMCSC Segments
auto oc = std::make_unique<GEMCSCSegmentCollection>();
Expand Down
12 changes: 10 additions & 2 deletions RecoLocalMuon/GEMCSCSegment/plugins/GEMCSCSegmentProducer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/Utilities/interface/InputTag.h"

#include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
#include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h"

#include <Geometry/Records/interface/MuonGeometryRecord.h>
#include "Geometry/CSCGeometry/interface/CSCGeometry.h"
#include "Geometry/GEMGeometry/interface/GEMGeometry.h"

class GEMCSCSegmentBuilder;

class GEMCSCSegmentProducer : public edm::stream::EDProducer<> {
Expand All @@ -30,10 +35,13 @@ class GEMCSCSegmentProducer : public edm::stream::EDProducer<> {
void produce(edm::Event&, const edm::EventSetup&) override;

private:
const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> kCSCGeometryToken_;
const edm::ESGetToken<GEMGeometry, MuonGeometryRecord> kGEMGeometryToken_;
const edm::EDGetTokenT<CSCSegmentCollection> kCSCSegmentCollectionToken_;
const edm::EDGetTokenT<GEMRecHitCollection> kGEMRecHitCollectionToken_;

int iev; // events through
GEMCSCSegmentBuilder* segmentBuilder_;
edm::EDGetTokenT<CSCSegmentCollection> csc_token;
edm::EDGetTokenT<GEMRecHitCollection> gem_token;
};

#endif
26 changes: 19 additions & 7 deletions RecoLocalMuon/GEMCSCSegment/test/TestGEMCSCSegmentAnalyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

// user include files
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDAnalyzer.h"
#include "FWCore/Framework/interface/one/EDAnalyzer.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down Expand Up @@ -64,7 +64,7 @@
using namespace std;
using namespace edm;

class TestGEMCSCSegmentAnalyzer : public edm::EDAnalyzer {
class TestGEMCSCSegmentAnalyzer : public edm::one::EDAnalyzer<> {
public:
explicit TestGEMCSCSegmentAnalyzer(const edm::ParameterSet&);
~TestGEMCSCSegmentAnalyzer();
Expand All @@ -90,6 +90,8 @@ class TestGEMCSCSegmentAnalyzer : public edm::EDAnalyzer {
bool debug;
std::string rootFileName;

const edm::ESGetToken<CSCGeometry, MuonGeometryRecord> kCSCGeometryToken_;
const edm::ESGetToken<GEMGeometry, MuonGeometryRecord> kGEMGeometryToken_;
edm::EDGetTokenT<edm::SimTrackContainer> SimTrack_Token;
edm::EDGetTokenT<CSCSegmentCollection> CSCSegment_Token;
edm::EDGetTokenT<GEMCSCSegmentCollection> GEMCSCSegment_Token;
Expand Down Expand Up @@ -346,14 +348,15 @@ class TestGEMCSCSegmentAnalyzer : public edm::EDAnalyzer {
// constructors and destructor
//
TestGEMCSCSegmentAnalyzer::TestGEMCSCSegmentAnalyzer(const edm::ParameterSet& iConfig)

{
: kCSCGeometryToken_(esConsumes<CSCGeometry, MuonGeometryRecord>()),
kGEMGeometryToken_(esConsumes<GEMGeometry, MuonGeometryRecord>()) {
//now do what ever initialization is needed
debug = iConfig.getUntrackedParameter<bool>("Debug");
rootFileName = iConfig.getUntrackedParameter<std::string>("RootFileName");

// outputfile = new TFile(rootFileName.c_str(), "RECREATE" );
outputfile.reset(TFile::Open(rootFileName.c_str()));
outputfile.reset(TFile::Open(rootFileName.c_str(), "CREATE"));
outputfile->cd();

SimTrack_Token = consumes<edm::SimTrackContainer>(edm::InputTag("g4SimHits"));
CSCSegment_Token = consumes<CSCSegmentCollection>(edm::InputTag("cscSegments"));
Expand Down Expand Up @@ -973,8 +976,17 @@ TestGEMCSCSegmentAnalyzer::~TestGEMCSCSegmentAnalyzer() {

// ------------ method called for each event ------------
void TestGEMCSCSegmentAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
iSetup.get<MuonGeometryRecord>().get(gemGeom);
iSetup.get<MuonGeometryRecord>().get(cscGeom);
const auto gemGeom = iSetup.getHandle(kGEMGeometryToken_);
if (not gemGeom.isValid()) {
edm::LogError("GEMCSCSegment") << "invalid GEMGeometry";
return;
}

const auto cscGeom = iSetup.getHandle(kCSCGeometryToken_);
if (not cscGeom.isValid()) {
edm::LogError("GEMCSCSegment") << "invalid CSCGeometry";
return;
}
const CSCGeometry* cscGeom_ = &*cscGeom;

// ================
Expand Down

0 comments on commit aef6b64

Please sign in to comment.