Skip to content

Commit

Permalink
Merge pull request #34969 from makortel/esconsumesTrackingParticleNum…
Browse files Browse the repository at this point in the history
…berOfLayersProducer

Migrate TrackingParticleNumberOfLayersProducer to esConsumes()
  • Loading branch information
cmsbuild authored Aug 21, 2021
2 parents cca242c + b0f8547 commit da69ccd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
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

0 comments on commit da69ccd

Please sign in to comment.