Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate TrackingParticleNumberOfLayersProducer to esConsumes() #34969

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h"
#include "SimDataFormats/TrackingHit/interface/PSimHit.h"

class TrackerTopology;

/**
* This class calculates the number of tracker layers, pixel layers,
* and strip mono+stereo layers "crossed" by TrackingParticle.
Expand Down Expand Up @@ -50,7 +52,7 @@ class TrackingParticleNumberOfLayers {
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;
calculate(const edm::Handle<TrackingParticleCollection> &tps, const TrackerTopology &tTopo) const;

private:
// used as multimap, but faster
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/global/EDProducer.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "Geometry/Records/interface/TrackerTopologyRcd.h"

#include "SimGeneral/TrackingAnalysis/interface/TrackingParticleNumberOfLayers.h"

Expand All @@ -23,10 +25,12 @@ class TrackingParticleNumberOfLayersProducer : public edm::global::EDProducer<>
private:
edm::EDGetTokenT<TrackingParticleCollection> tpToken_;
std::vector<edm::EDGetTokenT<std::vector<PSimHit>>> simHitTokens_;
edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
};

TrackingParticleNumberOfLayersProducer::TrackingParticleNumberOfLayersProducer(const edm::ParameterSet &iConfig)
: tpToken_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticles"))) {
: tpToken_(consumes<TrackingParticleCollection>(iConfig.getParameter<edm::InputTag>("trackingParticles"))),
tTopoToken_(esConsumes()) {
for (const auto &tag : iConfig.getParameter<std::vector<edm::InputTag>>("simHits")) {
simHitTokens_.push_back(consumes<std::vector<PSimHit>>(tag));
}
Expand Down Expand Up @@ -64,7 +68,7 @@ void TrackingParticleNumberOfLayersProducer::produce(edm::StreamID,
iEvent.getByToken(tpToken_, htps);

TrackingParticleNumberOfLayers algo(iEvent, simHitTokens_);
auto ret = algo.calculate(htps, iSetup);
auto ret = algo.calculate(htps, iSetup.getData(tTopoToken_));
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");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#include "SimGeneral/TrackingAnalysis/interface/TrackingParticleNumberOfLayers.h"

#include "FWCore/Framework/interface/ESHandle.h"

#include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
#include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
#include "FWCore/Utilities/interface/isFinite.h"
#include "Geometry/Records/interface/TrackerTopologyRcd.h"

namespace {
bool trackIdHitPairLess(const std::pair<unsigned int, const PSimHit *> &a,
Expand Down Expand Up @@ -47,12 +44,7 @@ std::tuple<std::unique_ptr<edm::ValueMap<unsigned int>>,
std::unique_ptr<edm::ValueMap<unsigned int>>,
std::unique_ptr<edm::ValueMap<unsigned int>>>
TrackingParticleNumberOfLayers::calculate(const edm::Handle<TrackingParticleCollection> &htps,
const edm::EventSetup &iSetup) const {
// Retrieve tracker topology from geometry
edm::ESHandle<TrackerTopology> tTopoHandle;
iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
const TrackerTopology &tTopo = *tTopoHandle;

const TrackerTopology &tTopo) const {
const TrackingParticleCollection &tps = *htps;
std::vector<unsigned int> valuesLayers(tps.size(), 0);
std::vector<unsigned int> valuesPixelLayers(tps.size(), 0);
Expand Down