File indexing completed on 2025-01-18 03:42:23
0001
0002
0003
0004
0005
0006 #include <memory>
0007
0008
0009 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0010 #include "FWCore/Framework/interface/Frameworkfwd.h"
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0013 #include "FWCore/Utilities/interface/InputTag.h"
0014 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0015 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0016 #include "RecoTracker/TrackProducer/interface/GsfTrackProducerBase.h"
0017 #include "RecoTracker/TrackProducer/interface/TrackProducerAlgorithm.h"
0018 #include "TrackingTools/GsfTracking/interface/GsfTrackConstraintAssociation.h"
0019 #include "TrackingTools/GsfTracking/interface/TrajGsfTrackAssociation.h"
0020 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0021 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0022
0023 class GsfTrackRefitter : public GsfTrackProducerBase, public edm::stream::EDProducer<> {
0024 public:
0025
0026 explicit GsfTrackRefitter(const edm::ParameterSet& iConfig);
0027
0028
0029 void produce(edm::Event&, const edm::EventSetup&) override;
0030
0031
0032 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0033
0034 private:
0035 TrackProducerAlgorithm<reco::GsfTrack> theAlgo;
0036 enum Constraint {
0037 none,
0038
0039 vertex
0040 };
0041 Constraint constraint_;
0042 edm::EDGetTokenT<GsfTrackVtxConstraintAssociationCollection> gsfTrackVtxConstraintTag_;
0043 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> ttopoToken_;
0044 };
0045
0046 GsfTrackRefitter::GsfTrackRefitter(const edm::ParameterSet& iConfig)
0047 : GsfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"),
0048 iConfig.getParameter<bool>("useHitsSplitting")),
0049 theAlgo(iConfig) {
0050 initTrackProducerBase(
0051 iConfig, consumesCollector(), consumes<edm::View<reco::GsfTrack>>(iConfig.getParameter<edm::InputTag>("src")));
0052 setAlias(iConfig.getParameter<std::string>("@module_label"));
0053 std::string constraint_str = iConfig.getParameter<std::string>("constraint");
0054
0055 if (constraint_str.empty())
0056 constraint_ = none;
0057
0058 else if (constraint_str == "vertex") {
0059 constraint_ = vertex;
0060 gsfTrackVtxConstraintTag_ = consumes<GsfTrackVtxConstraintAssociationCollection>(
0061 iConfig.getParameter<edm::InputTag>("gsfTrackVtxConstraintTag"));
0062 } else {
0063 edm::LogError("GsfTrackRefitter") << "constraint: " << constraint_str
0064 << " not understood. Set it to 'momentum', 'vertex' or leave it empty";
0065 throw cms::Exception("GsfTrackRefitter")
0066 << "unknown type of contraint! Set it to 'momentum', 'vertex' or leave it empty";
0067 }
0068
0069
0070 produces<reco::GsfTrackCollection>().setBranchAlias(alias_ + "GsfTracks");
0071 produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
0072 produces<reco::GsfTrackExtraCollection>().setBranchAlias(alias_ + "GsfTrackExtras");
0073 produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
0074 produces<std::vector<Trajectory>>();
0075 produces<TrajGsfTrackAssociationCollection>();
0076
0077 ttopoToken_ = esConsumes();
0078 }
0079
0080 void GsfTrackRefitter::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0081 edm::ParameterSetDescription desc;
0082 desc.add<bool>("TrajectoryInEvent", false);
0083 desc.add<bool>("useHitsSplitting", false);
0084 desc.add<edm::InputTag>("src", edm::InputTag(""));
0085 desc.add<std::string>("constraint", "");
0086 desc.add<edm::InputTag>("srcConstr", edm::InputTag(""));
0087 TrackProducerAlgorithm<reco::GsfTrack>::fillPSetDescription(desc);
0088 GsfTrackProducerBase::fillPSetDescription(desc);
0089 descriptions.addWithDefaultLabel(desc);
0090 }
0091
0092 void GsfTrackRefitter::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0093 edm::LogInfo("GsfTrackRefitter") << "Analyzing event number: " << theEvent.id() << "\n";
0094
0095
0096
0097 std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
0098 std::unique_ptr<reco::GsfTrackCollection> outputTColl(new reco::GsfTrackCollection);
0099 std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
0100 std::unique_ptr<reco::GsfTrackExtraCollection> outputGsfTEColl(new reco::GsfTrackExtraCollection);
0101 std::unique_ptr<std::vector<Trajectory>> outputTrajectoryColl(new std::vector<Trajectory>);
0102
0103
0104
0105
0106 edm::ESHandle<TrackerGeometry> theG;
0107 edm::ESHandle<MagneticField> theMF;
0108 edm::ESHandle<TrajectoryFitter> theFitter;
0109 edm::ESHandle<Propagator> thePropagator;
0110 edm::ESHandle<MeasurementTracker> theMeasTk;
0111
0112 edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0113 getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0114
0115 edm::ESHandle<TrackerTopology> httopo = setup.getHandle(ttopoToken_);
0116
0117
0118
0119
0120 AlgoProductCollection algoResults;
0121 reco::BeamSpot bs;
0122 switch (constraint_) {
0123 case none: {
0124 edm::Handle<edm::View<reco::GsfTrack>> theTCollection;
0125 getFromEvt(theEvent, theTCollection, bs);
0126 if (theTCollection.failedToGet()) {
0127 edm::LogError("GsfTrackRefitter") << "could not get the reco::GsfTrackCollection.";
0128 return;
0129 }
0130 LogDebug("GsfTrackRefitter") << "run the algorithm"
0131 << "\n";
0132 try {
0133 theAlgo.runWithTrack(theG.product(),
0134 theMF.product(),
0135 *theTCollection,
0136 theFitter.product(),
0137 thePropagator.product(),
0138 theBuilder.product(),
0139 bs,
0140 algoResults);
0141 } catch (cms::Exception& e) {
0142 edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
0143 << "\n"
0144 << e << "\n";
0145 throw;
0146 }
0147 break;
0148 }
0149 case vertex: {
0150 edm::Handle<GsfTrackVtxConstraintAssociationCollection> theTCollectionWithConstraint;
0151 theEvent.getByToken(gsfTrackVtxConstraintTag_, theTCollectionWithConstraint);
0152 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0153 theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
0154 bs = *recoBeamSpotHandle;
0155 if (theTCollectionWithConstraint.failedToGet()) {
0156 edm::LogError("TrackRefitter") << "could not get TrackVtxConstraintAssociationCollection product.";
0157 break;
0158 }
0159 LogDebug("TrackRefitter") << "run the algorithm"
0160 << "\n";
0161 try {
0162 theAlgo.runWithVertex(theG.product(),
0163 theMF.product(),
0164 *theTCollectionWithConstraint,
0165 theFitter.product(),
0166 thePropagator.product(),
0167 theBuilder.product(),
0168 bs,
0169 algoResults);
0170 } catch (cms::Exception& e) {
0171 edm::LogError("TrackProducer") << "cms::Exception caught during theAlgo.runWithTrack."
0172 << "\n"
0173 << e << "\n";
0174 throw;
0175 }
0176 }
0177
0178 }
0179
0180
0181 putInEvt(theEvent,
0182 thePropagator.product(),
0183 theMeasTk.product(),
0184 outputRHColl,
0185 outputTColl,
0186 outputTEColl,
0187 outputGsfTEColl,
0188 outputTrajectoryColl,
0189 algoResults,
0190 theBuilder.product(),
0191 bs,
0192 httopo.product());
0193 LogDebug("GsfTrackRefitter") << "end"
0194 << "\n";
0195 }
0196
0197 #include "FWCore/Framework/interface/MakerMacros.h"
0198 DEFINE_FWK_MODULE(GsfTrackRefitter);