File indexing completed on 2024-09-07 04:34:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <memory>
0015
0016
0017 #include "AnalysisAlgos/TrackInfoProducer/interface/TrackInfoProducerAlgorithm.h"
0018 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfo.h"
0019 #include "AnalysisDataFormats/TrackInfo/interface/TrackInfoTrackAssociation.h"
0020 #include "DataFormats/Common/interface/Handle.h"
0021 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0022 #include "FWCore/Framework/interface/MakerMacros.h"
0023 #include "FWCore/Framework/interface/Event.h"
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/stream/EDProducer.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0028 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0029 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0030 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0031
0032 class TrackInfoProducer : public edm::stream::EDProducer<> {
0033 public:
0034 explicit TrackInfoProducer(const edm::ParameterSet& iConfig);
0035
0036 ~TrackInfoProducer() override {}
0037
0038 void produce(edm::Event&, const edm::EventSetup&) override;
0039
0040 private:
0041 edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0042 TrackInfoProducerAlgorithm theAlgo_;
0043 edm::EDGetTokenT<std::vector<Trajectory> > TrajectoryToken_;
0044 edm::EDGetTokenT<reco::TrackCollection> trackCollectionToken_;
0045 edm::EDGetTokenT<TrajTrackAssociationCollection> assoMapToken_;
0046 std::string forwardPredictedStateTag_, backwardPredictedStateTag_, updatedStateTag_, combinedStateTag_;
0047 };
0048
0049 TrackInfoProducer::TrackInfoProducer(const edm::ParameterSet& iConfig)
0050 : tkGeomToken_(esConsumes()),
0051 theAlgo_(iConfig),
0052 TrajectoryToken_(consumes<std::vector<Trajectory> >(iConfig.getParameter<edm::InputTag>("cosmicTracks"))),
0053 trackCollectionToken_(consumes<reco::TrackCollection>(iConfig.getParameter<edm::InputTag>("cosmicTracks"))),
0054 assoMapToken_(consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("cosmicTracks"))) {
0055 produces<reco::TrackInfoCollection>();
0056 produces<reco::TrackInfoTrackAssociationCollection>();
0057 }
0058
0059 void TrackInfoProducer::produce(edm::Event& theEvent, const edm::EventSetup& setup) {
0060
0061
0062
0063 std::unique_ptr<reco::TrackInfoCollection> outputColl(new reco::TrackInfoCollection);
0064
0065 const TrackerGeometry* tracker = &setup.getData(tkGeomToken_);
0066
0067 edm::Handle<std::vector<Trajectory> > TrajectoryCollection;
0068 edm::Handle<reco::TrackCollection> trackCollection;
0069 edm::Handle<TrajTrackAssociationCollection> assoMap;
0070
0071 theEvent.getByToken(TrajectoryToken_, TrajectoryCollection);
0072 theEvent.getByToken(trackCollectionToken_, trackCollection);
0073 theEvent.getByToken(assoMapToken_, assoMap);
0074
0075
0076
0077
0078 reco::TrackInfo output;
0079
0080 edm::LogInfo("TrackInfoProducer") << "Loop on trajectories";
0081 std::map<reco::TrackRef, unsigned int> trackid;
0082 int i = 0;
0083
0084 for (TrajTrackAssociationCollection::const_iterator it = assoMap->begin(); it != assoMap->end(); ++it) {
0085 const edm::Ref<std::vector<Trajectory> > traj = it->key;
0086 const reco::TrackRef track = it->val;
0087 trackid.insert(make_pair(track, i));
0088 i++;
0089 theAlgo_.run(traj, track, output, tracker);
0090 outputColl->push_back(output);
0091 }
0092
0093
0094 edm::OrphanHandle<reco::TrackInfoCollection> rTrackInfo;
0095
0096
0097
0098
0099
0100 rTrackInfo = theEvent.put(std::move(outputColl));
0101 std::unique_ptr<reco::TrackInfoTrackAssociationCollection> TIassociationColl(
0102 new reco::TrackInfoTrackAssociationCollection(assoMap->refProd().val, rTrackInfo));
0103
0104 for (std::map<reco::TrackRef, unsigned int>::iterator ref_iter = trackid.begin(); ref_iter != trackid.end();
0105 ++ref_iter) {
0106 TIassociationColl->insert(ref_iter->first, edm::Ref<reco::TrackInfoCollection>(rTrackInfo, ref_iter->second));
0107 }
0108
0109 theEvent.put(std::move(TIassociationColl));
0110 }
0111
0112 DEFINE_FWK_MODULE(TrackInfoProducer);