Skip to content

Commit

Permalink
Merge pull request #34924 from makortel/esconsumesParametersDefinerTP
Browse files Browse the repository at this point in the history
Migrate (Cosmic)ParametersDefinerForTP to esConsumes()
  • Loading branch information
cmsbuild authored Aug 18, 2021
2 parents 294a387 + 1628e94 commit 089e39a
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 311 deletions.
3 changes: 1 addition & 2 deletions SimTracker/TrackAssociation/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<use name="FWCore/Framework"/>
<use name="FWCore/ParameterSet"/>
<use name="SimDataFormats/Track"/>
<use name="DataFormats/BeamSpot"/>
<use name="DataFormats/TrackingRecHit"/>
<use name="DataFormats/TrackReco"/>
<use name="TrackingTools/PatternTools"/>
Expand All @@ -10,8 +11,6 @@
<use name="Geometry/TrackerGeometryBuilder"/>
<use name="MagneticField/Records"/>
<use name="clhep"/>
<use name="boost"/>
<use name="root"/>
<export>
<lib name="1"/>
</export>
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
* \author Boris Mangano (UCSD) 5/7/2009
*/

#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
#include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
#include "SimTracker/TrackAssociation/interface/ParametersDefinerForTP.h"
#include <SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h>

#include <memory>

class CosmicParametersDefinerForTP : public ParametersDefinerForTP {
public:
CosmicParametersDefinerForTP(){};
~CosmicParametersDefinerForTP() override{};
CosmicParametersDefinerForTP(edm::ConsumesCollector iC);
~CosmicParametersDefinerForTP() override;

TrackingParticle::Vector momentum(const edm::Event &iEvent,
const edm::EventSetup &iSetup,
Expand Down Expand Up @@ -54,6 +57,7 @@ class CosmicParametersDefinerForTP : public ParametersDefinerForTP {
}

private:
const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> geometryToken_;
edm::Handle<SimHitTPAssociationProducer::SimHitTPAssociationList> simHitsTPAssoc;
};

Expand Down
14 changes: 9 additions & 5 deletions SimTracker/TrackAssociation/interface/ParametersDefinerForTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@

#include <memory>

#include "DataFormats/BeamSpot/interface/BeamSpot.h"
#include "DataFormats/Candidate/interface/Candidate.h"
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "SimGeneral/TrackingAnalysis/interface/SimHitTPAssociationProducer.h"
#include <SimDataFormats/TrackingAnalysis/interface/TrackingParticle.h>

class ParametersDefinerForTP {
public:
ParametersDefinerForTP(){};
ParametersDefinerForTP(const edm::ParameterSet &iConfig);
virtual ~ParametersDefinerForTP(){};
ParametersDefinerForTP(const edm::InputTag &beamspot, edm::ConsumesCollector iC);
virtual ~ParametersDefinerForTP();

typedef int Charge; ///< electric charge type
typedef math::XYZPointD Point; ///< point in the space
Expand Down Expand Up @@ -79,7 +81,9 @@ class ParametersDefinerForTP {
return std::make_unique<ParametersDefinerForTP>(*this);
}

edm::InputTag beamSpotInputTag_;
protected:
const edm::EDGetTokenT<reco::BeamSpot> bsToken_;
const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> mfToken_;
};

#endif

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

54 changes: 17 additions & 37 deletions SimTracker/TrackAssociation/src/CosmicParametersDefinerForTP.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@
#include "DataFormats/GeometryVector/interface/GlobalVector.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/Utilities/interface/typelookup.h"
#include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
#include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
#include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
#include "MagneticField/Engine/interface/MagneticField.h"
#include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
#include "SimTracker/TrackAssociation/interface/CosmicParametersDefinerForTP.h"
#include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
#include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
#include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
#include <DataFormats/GeometrySurface/interface/GloballyPositioned.h>
#include <DataFormats/GeometrySurface/interface/Surface.h>
#include <FWCore/Framework/interface/ESHandle.h>
#include <Geometry/CommonDetUnit/interface/GeomDet.h>
#include <Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h>

class TrajectoryStateClosestToBeamLineBuilder;

CosmicParametersDefinerForTP::CosmicParametersDefinerForTP(edm::ConsumesCollector iC)
: ParametersDefinerForTP(edm::InputTag("offlineBeamSpot"), iC), geometryToken_(iC.esConsumes()) {}
CosmicParametersDefinerForTP::~CosmicParametersDefinerForTP() = default;

TrackingParticle::Vector CosmicParametersDefinerForTP::momentum(const edm::Event &iEvent,
const edm::EventSetup &iSetup,
const TrackingParticleRef &tpr) const {
Expand All @@ -29,16 +25,9 @@ TrackingParticle::Vector CosmicParametersDefinerForTP::momentum(const edm::Event
using namespace std;
using namespace reco;

ESHandle<TrackerGeometry> tracker;
iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
edm::ESHandle<GlobalTrackingGeometry> theGeometry;
iSetup.get<GlobalTrackingGeometryRecord>().get(theGeometry);

edm::ESHandle<MagneticField> theMF;
iSetup.get<IdealMagneticFieldRecord>().get(theMF);

edm::Handle<reco::BeamSpot> bs;
iEvent.getByLabel(InputTag("offlineBeamSpot"), bs);
auto const &bs = iEvent.get(bsToken_);
auto const &geometry = iSetup.getData(geometryToken_);
auto const &mf = iSetup.getData(mfToken_);

GlobalVector finalGV(0, 0, 0);
GlobalPoint finalGP(0, 0, 0);
Expand All @@ -64,7 +53,7 @@ TrackingParticle::Vector CosmicParametersDefinerForTP::momentum(const edm::Event
SimHitTPAssociationProducer::simHitTPAssociationListGreater);
for (auto ip = range.first; ip != range.second; ++ip) {
TrackPSimHitRef it = ip->second;
const GeomDet *tmpDet = theGeometry->idToDet(DetId(it->detUnitId()));
const GeomDet *tmpDet = geometry.idToDet(DetId(it->detUnitId()));
if (!tmpDet) {
edm::LogVerbatim("CosmicParametersDefinerForTP")
<< "***WARNING in CosmicParametersDefinerForTP::momentum: no GeomDet "
Expand Down Expand Up @@ -98,10 +87,10 @@ TrackingParticle::Vector CosmicParametersDefinerForTP::momentum(const edm::Event
<< "\t \t FINAL State at InnerMost Hit: pt = " << finalGV.perp() << ", pz = " << finalGV.z();

if (found) {
FreeTrajectoryState ftsAtProduction(finalGP, finalGV, TrackCharge(tpr->charge()), theMF.product());
FreeTrajectoryState ftsAtProduction(finalGP, finalGV, TrackCharge(tpr->charge()), &mf);
TSCBLBuilderNoMaterial tscblBuilder;
TrajectoryStateClosestToBeamLine tsAtClosestApproach =
tscblBuilder(ftsAtProduction, *bs); // as in TrackProducerAlgorithm
tscblBuilder(ftsAtProduction, bs); // as in TrackProducerAlgorithm

if (tsAtClosestApproach.isValid()) {
GlobalVector p = tsAtClosestApproach.trackStateAtPCA().momentum();
Expand Down Expand Up @@ -135,16 +124,9 @@ TrackingParticle::Point CosmicParametersDefinerForTP::vertex(const edm::Event &i
using namespace std;
using namespace reco;

ESHandle<TrackerGeometry> tracker;
iSetup.get<TrackerDigiGeometryRecord>().get(tracker);
edm::ESHandle<GlobalTrackingGeometry> theGeometry;
iSetup.get<GlobalTrackingGeometryRecord>().get(theGeometry);

edm::ESHandle<MagneticField> theMF;
iSetup.get<IdealMagneticFieldRecord>().get(theMF);

edm::Handle<reco::BeamSpot> bs;
iEvent.getByLabel(InputTag("offlineBeamSpot"), bs);
auto const &bs = iEvent.get(bsToken_);
auto const &geometry = iSetup.getData(geometryToken_);
auto const &mf = iSetup.getData(mfToken_);

GlobalVector finalGV(0, 0, 0);
GlobalPoint finalGP(0, 0, 0);
Expand Down Expand Up @@ -172,7 +154,7 @@ TrackingParticle::Point CosmicParametersDefinerForTP::vertex(const edm::Event &i
SimHitTPAssociationProducer::simHitTPAssociationListGreater);
for (auto ip = range.first; ip != range.second; ++ip) {
TrackPSimHitRef it = ip->second;
const GeomDet *tmpDet = theGeometry->idToDet(DetId(it->detUnitId()));
const GeomDet *tmpDet = geometry.idToDet(DetId(it->detUnitId()));
if (!tmpDet) {
edm::LogVerbatim("CosmicParametersDefinerForTP")
<< "***WARNING in CosmicParametersDefinerForTP::vertex: no GeomDet "
Expand Down Expand Up @@ -202,18 +184,18 @@ TrackingParticle::Point CosmicParametersDefinerForTP::vertex(const edm::Event &i
<< "\t \t FINAL State at InnerMost Hit: radius = " << finalGP.perp() << ", z = " << finalGP.z();

if (found) {
FreeTrajectoryState ftsAtProduction(finalGP, finalGV, TrackCharge(tpr->charge()), theMF.product());
FreeTrajectoryState ftsAtProduction(finalGP, finalGV, TrackCharge(tpr->charge()), &mf);
TSCBLBuilderNoMaterial tscblBuilder;
TrajectoryStateClosestToBeamLine tsAtClosestApproach =
tscblBuilder(ftsAtProduction, *bs); // as in TrackProducerAlgorithm
tscblBuilder(ftsAtProduction, bs); // as in TrackProducerAlgorithm

if (tsAtClosestApproach.isValid()) {
GlobalPoint v = tsAtClosestApproach.trackStateAtPCA().position();
vertex = TrackingParticle::Point(v.x(), v.y(), v.z());
} else {
// to preserve old behaviour
// would be better to flag this somehow to allow ignoring in downstream
vertex = TrackingParticle::Point(bs->x0(), bs->y0(), bs->z0());
vertex = TrackingParticle::Point(bs.x0(), bs.y0(), bs.z0());
edm::LogVerbatim("CosmicParametersDefinerForTP") << "*** WARNING in CosmicParametersDefinerForTP::vertex: "
"tsAtClosestApproach is not valid."
<< "\n";
Expand All @@ -234,5 +216,3 @@ TrackingParticle::Point CosmicParametersDefinerForTP::vertex(const edm::Event &i

return vertex;
}

TYPELOOKUP_DATA_REG(CosmicParametersDefinerForTP);
Loading

0 comments on commit 089e39a

Please sign in to comment.