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