File indexing completed on 2024-04-06 12:33:22
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/ESHandle.h"
0025 #include "FWCore/Framework/interface/global/EDProducer.h"
0026
0027 #include "FWCore/Framework/interface/Event.h"
0028 #include "FWCore/Framework/interface/MakerMacros.h"
0029
0030 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0031
0032 #include "DataFormats/TrackReco/interface/Track.h"
0033 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0034 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0035 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0036 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
0037 #include "TrackingTools/TrajectoryState/interface/PerigeeConversions.h"
0038 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0039 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0040 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0041 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0042 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0043 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0044 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0045
0046
0047
0048
0049
0050 class TrackFromSeedProducer : public edm::global::EDProducer<> {
0051 public:
0052 explicit TrackFromSeedProducer(const edm::ParameterSet&);
0053 ~TrackFromSeedProducer() override;
0054
0055 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0056
0057 private:
0058 void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
0059
0060
0061 edm::EDGetTokenT<edm::View<TrajectorySeed> > seedsToken;
0062 edm::EDGetTokenT<reco::BeamSpot> beamSpotToken;
0063 const edm::ESGetToken<GlobalTrackingGeometry, GlobalTrackingGeometryRecord> geoToken_;
0064 const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0065 const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> mfToken_;
0066 const edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> ttrhToken_;
0067 };
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 TrackFromSeedProducer::TrackFromSeedProducer(const edm::ParameterSet& iConfig)
0081 : geoToken_(esConsumes()),
0082 tTopoToken_(esConsumes()),
0083 mfToken_(esConsumes()),
0084 ttrhToken_(esConsumes(edm::ESInputTag("", iConfig.getParameter<std::string>("TTRHBuilder")))) {
0085
0086 produces<reco::TrackCollection>();
0087 produces<TrackingRecHitCollection>();
0088 produces<reco::TrackExtraCollection>();
0089
0090
0091 edm::InputTag seedsTag(iConfig.getParameter<edm::InputTag>("src"));
0092 edm::InputTag beamSpotTag(iConfig.getParameter<edm::InputTag>("beamSpot"));
0093
0094
0095 seedsToken = consumes<edm::View<TrajectorySeed> >(seedsTag);
0096 beamSpotToken = consumes<reco::BeamSpot>(beamSpotTag);
0097 }
0098
0099 TrackFromSeedProducer::~TrackFromSeedProducer() {}
0100
0101
0102 void TrackFromSeedProducer::produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const {
0103 using namespace edm;
0104 using namespace reco;
0105 using namespace std;
0106
0107
0108 unique_ptr<TrackCollection> tracks(new TrackCollection);
0109 unique_ptr<TrackingRecHitCollection> rechits(new TrackingRecHitCollection);
0110 unique_ptr<TrackExtraCollection> trackextras(new TrackExtraCollection);
0111
0112
0113 TrackExtraRefProd ref_trackextras = iEvent.getRefBeforePut<TrackExtraCollection>();
0114 TrackingRecHitRefProd ref_rechits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
0115
0116
0117 Handle<edm::View<TrajectorySeed> > hseeds;
0118 iEvent.getByToken(seedsToken, hseeds);
0119 const auto& seeds = *hseeds;
0120
0121
0122 edm::Handle<reco::BeamSpot> beamSpot;
0123 iEvent.getByToken(beamSpotToken, beamSpot);
0124
0125
0126 TSCBLBuilderNoMaterial tscblBuilder;
0127
0128 const auto& tTRHBuilder = &iSetup.getData(ttrhToken_);
0129 const auto& theMF = &iSetup.getData(mfToken_);
0130 const TrackerTopology& ttopo = iSetup.getData(tTopoToken_);
0131 const GlobalTrackingGeometry* const geometry_ = &iSetup.getData(geoToken_);
0132
0133
0134 int nfailed = 0;
0135 for (size_t iSeed = 0; iSeed < seeds.size(); ++iSeed) {
0136 auto const& seed = seeds[iSeed];
0137
0138 TrajectoryStateOnSurface state;
0139 if (seed.nHits() == 0) {
0140 const Surface* deepCore_sruface = &geometry_->idToDet(seed.startingState().detId())->specificSurface();
0141 state = trajectoryStateTransform::transientState(seed.startingState(), deepCore_sruface, theMF);
0142 } else {
0143 TransientTrackingRecHit::RecHitPointer lastRecHit = tTRHBuilder->build(&*(seed.recHits().end() - 1));
0144 state = trajectoryStateTransform::transientState(seed.startingState(), lastRecHit->surface(), theMF);
0145 }
0146 TrajectoryStateClosestToBeamLine tsAtClosestApproachSeed =
0147 tscblBuilder(*state.freeState(), *beamSpot);
0148 if (tsAtClosestApproachSeed.isValid()) {
0149 const reco::TrackBase::Point vSeed1(tsAtClosestApproachSeed.trackStateAtPCA().position().x(),
0150 tsAtClosestApproachSeed.trackStateAtPCA().position().y(),
0151 tsAtClosestApproachSeed.trackStateAtPCA().position().z());
0152 const reco::TrackBase::Vector pSeed(tsAtClosestApproachSeed.trackStateAtPCA().momentum().x(),
0153 tsAtClosestApproachSeed.trackStateAtPCA().momentum().y(),
0154 tsAtClosestApproachSeed.trackStateAtPCA().momentum().z());
0155
0156 PerigeeTrajectoryError seedPerigeeErrors =
0157 PerigeeConversions::ftsToPerigeeError(tsAtClosestApproachSeed.trackStateAtPCA());
0158 tracks->emplace_back(0., 0., vSeed1, pSeed, state.charge(), seedPerigeeErrors.covarianceMatrix());
0159 } else {
0160 edm::LogVerbatim("SeedValidator") << "TrajectoryStateClosestToBeamLine not valid";
0161
0162
0163 tracks->emplace_back(
0164 -1, -1, reco::TrackBase::Point(), reco::TrackBase::Vector(), 0, reco::TrackBase::CovarianceMatrix());
0165 nfailed++;
0166 }
0167
0168 tracks->back().appendHits(seed.recHits().begin(), seed.recHits().end(), ttopo);
0169
0170 size_t firsthitindex = rechits->size();
0171 for (auto const& recHit : seed.recHits()) {
0172 rechits->push_back(recHit);
0173 }
0174
0175
0176 trackextras->push_back(TrackExtra());
0177 trackextras->back().setHits(ref_rechits, firsthitindex, rechits->size() - firsthitindex);
0178 trackextras->back().setSeedRef(edm::RefToBase<TrajectorySeed>(hseeds, iSeed));
0179
0180 tracks->back().setExtra(TrackExtraRef(ref_trackextras, trackextras->size() - 1));
0181 }
0182
0183 if (nfailed > 0) {
0184 edm::LogInfo("SeedValidator") << "failed to create tracks from " << nfailed << " out of " << seeds.size()
0185 << " seeds ";
0186 }
0187 iEvent.put(std::move(tracks));
0188 iEvent.put(std::move(rechits));
0189 iEvent.put(std::move(trackextras));
0190 }
0191
0192
0193 void TrackFromSeedProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0194
0195
0196 edm::ParameterSetDescription desc;
0197 desc.setUnknown();
0198 descriptions.addDefault(desc);
0199 }
0200
0201
0202 DEFINE_FWK_MODULE(TrackFromSeedProducer);