File indexing completed on 2025-01-18 03:42:22
0001
0002
0003
0004
0005
0006
0007
0008 #include <memory>
0009
0010 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0011 #include "FWCore/Framework/interface/Frameworkfwd.h"
0012 #include "FWCore/Framework/interface/stream/EDProducer.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0015 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0016 #include "RecoTracker/Record/interface/MultiRecHitRecord.h"
0017 #include "RecoTracker/SiTrackerMRHTools/interface/MultiRecHitCollector.h"
0018 #include "RecoTracker/SiTrackerMRHTools/interface/SiTrackerMultiRecHitUpdator.h"
0019 #include "RecoTracker/TrackProducer/interface/DAFTrackProducerAlgorithm.h"
0020 #include "RecoTracker/TrackProducer/interface/KfTrackProducerBase.h"
0021 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0022 #include "TrackingTools/PatternTools/interface/TrajAnnealing.h"
0023 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0024 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0025 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0026
0027 class DAFTrackProducer : public KfTrackProducerBase, public edm::stream::EDProducer<> {
0028 public:
0029 typedef std::vector<Trajectory> TrajectoryCollection;
0030
0031 explicit DAFTrackProducer(const edm::ParameterSet& iConfig);
0032
0033
0034 void produce(edm::Event&, const edm::EventSetup&) override;
0035
0036
0037 static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0038
0039 private:
0040 DAFTrackProducerAlgorithm theAlgo;
0041 using TrackProducerBase<reco::Track>::getFromEvt;
0042 void getFromEvt(edm::Event&, edm::Handle<TrajTrackAssociationCollection>&, reco::BeamSpot&);
0043 void putInEvtTrajAnn(edm::Event& theEvent,
0044 TrajAnnealingCollection& trajannResults,
0045 std::unique_ptr<TrajAnnealingCollection>& selTrajAnn);
0046
0047 bool TrajAnnSaving_;
0048 edm::EDGetTokenT<TrajTrackAssociationCollection> srcTT_;
0049 edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> ttopoToken_;
0050 edm::ESGetToken<MultiRecHitCollector, MultiRecHitRecord> measurementCollectorToken_;
0051 edm::ESGetToken<SiTrackerMultiRecHitUpdator, MultiRecHitRecord> updatorToken_;
0052 };
0053
0054 DAFTrackProducer::DAFTrackProducer(const edm::ParameterSet& iConfig)
0055 : KfTrackProducerBase(iConfig.getParameter<bool>("TrajectoryInEvent"), false), theAlgo(iConfig) {
0056 initTrackProducerBase(
0057 iConfig, consumesCollector(), consumes<TrackCandidateCollection>(iConfig.getParameter<edm::InputTag>("src")));
0058 srcTT_ = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("src"));
0059 setAlias(iConfig.getParameter<std::string>("@module_label"));
0060
0061
0062 produces<reco::TrackCollection>().setBranchAlias(alias_ + "Tracks");
0063 produces<reco::TrackExtraCollection>().setBranchAlias(alias_ + "TrackExtras");
0064 produces<TrackingRecHitCollection>().setBranchAlias(alias_ + "RecHits");
0065 produces<std::vector<Trajectory> >();
0066 produces<TrajTrackAssociationCollection>();
0067 produces<TrajAnnealingCollection>().setBranchAlias(alias_ + "TrajectoryAnnealing");
0068 produces<reco::TrackCollection>("beforeDAF").setBranchAlias(alias_ + "TracksBeforeDAF");
0069 produces<reco::TrackExtraCollection>("beforeDAF").setBranchAlias(alias_ + "TrackExtrasBeforeDAF");
0070 produces<reco::TrackCollection>("afterDAF").setBranchAlias(alias_ + "TracksAfterDAF");
0071 produces<reco::TrackExtraCollection>("afterDAF").setBranchAlias(alias_ + "TrackExtrasAfterDAF");
0072
0073 TrajAnnSaving_ = iConfig.getParameter<bool>("TrajAnnealingSaving");
0074 ttopoToken_ = esConsumes();
0075 std::string measurementCollectorName = getConf().getParameter<std::string>("MeasurementCollector");
0076 measurementCollectorToken_ = esConsumes(edm::ESInputTag("", measurementCollectorName));
0077 std::string updatorName = getConf().getParameter<std::string>("UpdatorName");
0078 updatorToken_ = esConsumes(edm::ESInputTag("", updatorName));
0079 }
0080
0081 void DAFTrackProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0082 edm::ParameterSetDescription desc;
0083 desc.add<bool>("TrajectoryInEvent", false);
0084 desc.add<edm::InputTag>("src", edm::InputTag("DAFTrackCandidateMaker"));
0085 desc.add<bool>("TrajAnnealingSaving", false);
0086 desc.add<std::string>("MeasurementCollector", "simpleMultiRecHitCollector");
0087 desc.add<std::string>("UpdatorName", "SiTrackerMultiRecHitUpdator");
0088 KfTrackProducerBase::fillPSetDescription(desc);
0089 DAFTrackProducerAlgorithm::fillPSetDescription(desc);
0090 descriptions.addWithDefaultLabel(desc);
0091 }
0092
0093 void DAFTrackProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0094 edm::LogInfo("DAFTrackProducer") << "Analyzing event number: " << theEvent.id() << "\n";
0095
0096
0097 std::unique_ptr<TrackingRecHitCollection> outputRHColl(new TrackingRecHitCollection);
0098 std::unique_ptr<reco::TrackCollection> outputTColl(new reco::TrackCollection);
0099 std::unique_ptr<reco::TrackExtraCollection> outputTEColl(new reco::TrackExtraCollection);
0100 std::unique_ptr<std::vector<Trajectory> > outputTrajectoryColl(new std::vector<Trajectory>);
0101 std::unique_ptr<TrajAnnealingCollection> outputTrajAnnColl(new TrajAnnealingCollection);
0102 std::unique_ptr<std::vector<int> > outputIndecesInputColl(new std::vector<int>);
0103
0104
0105 std::unique_ptr<TrackingRecHitCollection> outputRHCollBeforeDAF(new TrackingRecHitCollection);
0106 std::unique_ptr<reco::TrackCollection> outputTCollBeforeDAF(new reco::TrackCollection);
0107 std::unique_ptr<reco::TrackExtraCollection> outputTECollBeforeDAF(new reco::TrackExtraCollection);
0108 std::unique_ptr<std::vector<Trajectory> > outputTrajectoryCollBeforeDAF(new std::vector<Trajectory>);
0109 std::unique_ptr<std::vector<int> > outputIndecesInputCollBeforeDAF(new std::vector<int>);
0110
0111 std::unique_ptr<TrackingRecHitCollection> outputRHCollAfterDAF(new TrackingRecHitCollection);
0112 std::unique_ptr<reco::TrackCollection> outputTCollAfterDAF(new reco::TrackCollection);
0113 std::unique_ptr<reco::TrackExtraCollection> outputTECollAfterDAF(new reco::TrackExtraCollection);
0114 std::unique_ptr<std::vector<Trajectory> > outputTrajectoryCollAfterDAF(new std::vector<Trajectory>);
0115 std::unique_ptr<std::vector<int> > outputIndecesInputCollAfterDAF(new std::vector<int>);
0116
0117
0118 edm::ESHandle<TrackerGeometry> theG;
0119 edm::ESHandle<MagneticField> theMF;
0120 edm::ESHandle<TrajectoryFitter> theFitter;
0121 edm::ESHandle<Propagator> thePropagator;
0122 edm::ESHandle<MeasurementTracker> theMeasTk;
0123 edm::ESHandle<TransientTrackingRecHitBuilder> theBuilder;
0124 getFromES(setup, theG, theMF, theFitter, thePropagator, theMeasTk, theBuilder);
0125
0126 edm::ESHandle<TrackerTopology> httopo = setup.getHandle(ttopoToken_);
0127
0128
0129 edm::ESHandle<MultiRecHitCollector> measurementCollectorHandle = setup.getHandle(measurementCollectorToken_);
0130 edm::ESHandle<SiTrackerMultiRecHitUpdator> updatorHandle = setup.getHandle(updatorToken_);
0131
0132
0133 edm::Handle<MeasurementTrackerEvent> mte;
0134 theEvent.getByToken(mteSrc_, mte);
0135
0136
0137 AlgoProductCollection algoResults;
0138 reco::BeamSpot bs;
0139 TrajAnnealingCollection trajannResults;
0140
0141
0142 AlgoProductCollection algoResultsBeforeDAF;
0143 AlgoProductCollection algoResultsAfterDAF;
0144 try {
0145 edm::Handle<TrajTrackAssociationCollection> trajTrackAssociationHandle;
0146 getFromEvt(theEvent, trajTrackAssociationHandle, bs);
0147
0148
0149 LogDebug("DAFTrackProducer") << "run the DAF algorithm"
0150 << "\n";
0151 theAlgo.runWithCandidate(theG.product(),
0152 theMF.product(),
0153 *trajTrackAssociationHandle,
0154 &*mte,
0155 theFitter.product(),
0156 theBuilder.product(),
0157 measurementCollectorHandle.product(),
0158 updatorHandle.product(),
0159 bs,
0160 algoResults,
0161 trajannResults,
0162 TrajAnnSaving_,
0163 algoResultsBeforeDAF,
0164 algoResultsAfterDAF);
0165
0166 } catch (cms::Exception& e) {
0167 edm::LogInfo("DAFTrackProducer") << "cms::Exception caught!!!"
0168 << "\n"
0169 << e << "\n";
0170 throw;
0171 }
0172
0173
0174 putInEvt(theEvent,
0175 thePropagator.product(),
0176 theMeasTk.product(),
0177 outputRHColl,
0178 outputTColl,
0179 outputTEColl,
0180 outputTrajectoryColl,
0181 outputIndecesInputColl,
0182 algoResults,
0183 theBuilder.product(),
0184 httopo.product());
0185 putInEvtTrajAnn(theEvent, trajannResults, outputTrajAnnColl);
0186
0187
0188 putInEvt(theEvent,
0189 thePropagator.product(),
0190 theMeasTk.product(),
0191 outputRHCollBeforeDAF,
0192 outputTCollBeforeDAF,
0193 outputTECollBeforeDAF,
0194 outputTrajectoryCollBeforeDAF,
0195 outputIndecesInputCollBeforeDAF,
0196 algoResultsBeforeDAF,
0197 theBuilder.product(),
0198 httopo.product(),
0199 1);
0200 putInEvt(theEvent,
0201 thePropagator.product(),
0202 theMeasTk.product(),
0203 outputRHCollAfterDAF,
0204 outputTCollAfterDAF,
0205 outputTECollAfterDAF,
0206 outputTrajectoryCollAfterDAF,
0207 outputIndecesInputCollAfterDAF,
0208 algoResultsAfterDAF,
0209 theBuilder.product(),
0210 httopo.product(),
0211 2);
0212
0213 LogDebug("DAFTrackProducer") << "end the DAF algorithm."
0214 << "\n";
0215 }
0216
0217 void DAFTrackProducer::getFromEvt(edm::Event& theEvent,
0218 edm::Handle<TrajTrackAssociationCollection>& trajTrackAssociationHandle,
0219 reco::BeamSpot& bs) {
0220
0221
0222 theEvent.getByToken(srcTT_, trajTrackAssociationHandle);
0223
0224
0225 edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
0226 theEvent.getByToken(bsSrc_, recoBeamSpotHandle);
0227 bs = *recoBeamSpotHandle;
0228 }
0229
0230 void DAFTrackProducer::putInEvtTrajAnn(edm::Event& theEvent,
0231 TrajAnnealingCollection& trajannResults,
0232 std::unique_ptr<TrajAnnealingCollection>& outputTrajAnnColl) {
0233 const int size = trajannResults.size();
0234 outputTrajAnnColl->reserve(size);
0235
0236 for (unsigned int i = 0; i < trajannResults.size(); i++) {
0237 outputTrajAnnColl->push_back(trajannResults[i]);
0238 }
0239
0240 theEvent.put(std::move(outputTrajAnnColl));
0241 }
0242
0243 #include "FWCore/Framework/interface/MakerMacros.h"
0244 DEFINE_FWK_MODULE(DAFTrackProducer);