Go to the documentation of this file.00001 #include "PixelTrackProducer.h"
00002
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00007
00008 #include "DataFormats/TrackReco/interface/Track.h"
00009 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00010 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00011 #include "DataFormats/Common/interface/OrphanHandle.h"
00012
00013 #include <vector>
00014
00015 using namespace pixeltrackfitting;
00016 using edm::ParameterSet;
00017
00018 PixelTrackProducer::PixelTrackProducer(const ParameterSet& cfg)
00019 : theReconstruction(cfg)
00020 {
00021 edm::LogInfo("PixelTrackProducer")<<" construction...";
00022 produces<reco::TrackCollection>();
00023 produces<TrackingRecHitCollection>();
00024 produces<reco::TrackExtraCollection>();
00025 }
00026
00027 PixelTrackProducer::~PixelTrackProducer() { }
00028
00029 void PixelTrackProducer::endRun(const edm::Run &run, const edm::EventSetup& es)
00030 {
00031 theReconstruction.halt();
00032 }
00033
00034 void PixelTrackProducer::beginRun(const edm::Run &run, const edm::EventSetup& es)
00035 {
00036 theReconstruction.init(es);
00037 }
00038
00039 void PixelTrackProducer::produce(edm::Event& ev, const edm::EventSetup& es)
00040 {
00041 LogDebug("PixelTrackProducer, produce")<<"event# :"<<ev.id();
00042
00043 TracksWithTTRHs tracks;
00044 theReconstruction.run(tracks,ev,es);
00045
00046
00047 store(ev, tracks);
00048 }
00049
00050 void PixelTrackProducer::store(edm::Event& ev, const TracksWithTTRHs& tracksWithHits)
00051 {
00052 std::auto_ptr<reco::TrackCollection> tracks(new reco::TrackCollection());
00053 std::auto_ptr<TrackingRecHitCollection> recHits(new TrackingRecHitCollection());
00054 std::auto_ptr<reco::TrackExtraCollection> trackExtras(new reco::TrackExtraCollection());
00055
00056 int cc = 0, nTracks = tracksWithHits.size();
00057
00058 for (int i = 0; i < nTracks; i++)
00059 {
00060 reco::Track* track = tracksWithHits.at(i).first;
00061 const SeedingHitSet& hits = tracksWithHits.at(i).second;
00062
00063 for (unsigned int k = 0; k < hits.size(); k++)
00064 {
00065 TrackingRecHit *hit = hits[k]->hit()->clone();
00066
00067 track->setHitPattern(*hit, k);
00068 recHits->push_back(hit);
00069 }
00070 tracks->push_back(*track);
00071 delete track;
00072
00073 }
00074
00075 LogDebug("TrackProducer") << "put the collection of TrackingRecHit in the event" << "\n";
00076 edm::OrphanHandle <TrackingRecHitCollection> ohRH = ev.put( recHits );
00077
00078
00079 for (int k = 0; k < nTracks; k++)
00080 {
00081 reco::TrackExtra* theTrackExtra = new reco::TrackExtra();
00082
00083
00084 unsigned int nHits = tracks->at(k).numberOfValidHits();
00085 for(unsigned int i = 0; i < nHits; ++i) {
00086 theTrackExtra->add(TrackingRecHitRef(ohRH,cc));
00087 cc++;
00088 }
00089
00090 trackExtras->push_back(*theTrackExtra);
00091 delete theTrackExtra;
00092 }
00093
00094 LogDebug("TrackProducer") << "put the collection of TrackExtra in the event" << "\n";
00095 edm::OrphanHandle<reco::TrackExtraCollection> ohTE = ev.put(trackExtras);
00096
00097 for (int k = 0; k < nTracks; k++)
00098 {
00099 const reco::TrackExtraRef theTrackExtraRef(ohTE,k);
00100 (tracks->at(k)).setExtra(theTrackExtraRef);
00101 }
00102
00103 ev.put(tracks);
00104
00105 }