Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-20 02:47:06

0001 #ifndef RecoPixelVertexingPixelTrackFittingStoreTracks_H
0002 #define RecoPixelVertexingPixelTrackFittingStoreTracks_H
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0007 
0008 #include "DataFormats/TrajectoryState/interface/LocalTrajectoryParameters.h"
0009 #include "DataFormats/TrackReco/interface/Track.h"
0010 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0011 #include "DataFormats/TrackReco/interface/TrackExtra.h"
0012 #include "DataFormats/Common/interface/OrphanHandle.h"
0013 #include "RecoPixelVertexing/PixelTrackFitting/interface/TracksWithHits.h"
0014 
0015 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0016 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0017 
0018 template <typename Ev, typename TWH>
0019 void storeTracks(Ev& ev, const TWH& tracksWithHits, const TrackerTopology& ttopo) {
0020   auto tracks = std::make_unique<reco::TrackCollection>();
0021   auto recHits = std::make_unique<TrackingRecHitCollection>();
0022   auto trackExtras = std::make_unique<reco::TrackExtraCollection>();
0023 
0024   int cc = 0, nTracks = tracksWithHits.size();
0025 
0026   trackExtras->resize(nTracks);
0027   tracks->reserve(nTracks);
0028   recHits->reserve(4 * nTracks);
0029 
0030   for (int i = 0; i < nTracks; i++) {
0031     reco::Track* track = tracksWithHits[i].first;
0032     const auto& hits = tracksWithHits[i].second;
0033 
0034     for (unsigned int k = 0; k < hits.size(); k++) {
0035       auto* hit = hits[k]->clone();  // need to clone (at least if from SoA)
0036       track->appendHitPattern(*hit, ttopo);
0037       recHits->push_back(hit);
0038     }
0039     tracks->push_back(*track);
0040     delete track;
0041   }
0042 
0043   LogDebug("TrackProducer") << "put the collection of TrackingRecHit in the event"
0044                             << "\n";
0045   edm::OrphanHandle<TrackingRecHitCollection> ohRH = ev.put(std::move(recHits));
0046 
0047   edm::RefProd<TrackingRecHitCollection> hitCollProd(ohRH);
0048   for (int k = 0; k < nTracks; k++) {
0049     auto& aTrackExtra = (*trackExtras)[k];
0050 
0051     //fill the TrackExtra with TrackingRecHitRef
0052     unsigned int nHits = (*tracks)[k].numberOfValidHits();
0053     aTrackExtra.setHits(hitCollProd, cc, nHits);
0054     cc += nHits;
0055     AlgebraicVector5 v = AlgebraicVector5(0, 0, 0, 0, 0);
0056     reco::TrackExtra::TrajParams trajParams(nHits, LocalTrajectoryParameters(v, 1.));
0057     reco::TrackExtra::Chi2sFive chi2s(nHits, 0);
0058     aTrackExtra.setTrajParams(std::move(trajParams), std::move(chi2s));
0059   }
0060 
0061   LogDebug("TrackProducer") << "put the collection of TrackExtra in the event"
0062                             << "\n";
0063   edm::OrphanHandle<reco::TrackExtraCollection> ohTE = ev.put(std::move(trackExtras));
0064 
0065   for (int k = 0; k < nTracks; k++) {
0066     const reco::TrackExtraRef theTrackExtraRef(ohTE, k);
0067     (*tracks)[k].setExtra(theTrackExtraRef);
0068   }
0069 
0070   ev.put(std::move(tracks));
0071 }
0072 
0073 #endif