CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/FastSimulation/TrackingRecHitProducer/src/TrackingRecHitTranslator.cc

Go to the documentation of this file.
00001 
00010 // SiTracker Gaussian Smearing
00011 #include "TrackingRecHitTranslator.h"
00012 
00013 // Geometry
00014 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00015 
00016 // Data Formats
00017 #include "DataFormats/Common/interface/Handle.h"
00018 
00019 // Framework
00020 #include "FWCore/Framework/interface/Event.h"
00021 #include "FWCore/Framework/interface/EventSetup.h"
00022 //#include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Framework/interface/ESHandle.h"
00024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00025 
00026 // Data Formats
00027 #include "DataFormats/DetId/interface/DetId.h"
00028 
00029 // STL
00030 #include <memory>
00031 #include <string>
00032 
00033 TrackingRecHitTranslator::TrackingRecHitTranslator(edm::ParameterSet const& conf) :
00034   hitCollectionInputTag_(conf.getParameter<edm::InputTag>("hitCollectionInputTag"))
00035 {
00036   produces<SiTrackerFullGSRecHit2DCollection>();
00037 }
00038 
00039 // Destructor
00040 TrackingRecHitTranslator::~TrackingRecHitTranslator() {}  
00041 
00042 void 
00043 TrackingRecHitTranslator::beginRun(edm::Run const&, const edm::EventSetup & es) {
00044 
00045   // Initialize the Tracker Geometry
00046   edm::ESHandle<TrackerGeometry> theGeometry;
00047   es.get<TrackerDigiGeometryRecord> ().get (theGeometry);
00048   geometry = &(*theGeometry);
00049 
00050 }
00051 
00052 void TrackingRecHitTranslator::produce(edm::Event& e, const edm::EventSetup& es) 
00053 {
00054   // Step A: Get Inputs (FastGSRecHit's)
00055   edm::Handle<SiTrackerGSRecHit2DCollection> theFastRecHits; 
00056   e.getByLabel(hitCollectionInputTag_, theFastRecHits);
00057 
00058   // Step B: fill a temporary full RecHit collection from the fast RecHit collection
00059   SiTrackerGSRecHit2DCollection::const_iterator aHit = theFastRecHits->begin();
00060   SiTrackerGSRecHit2DCollection::const_iterator theLastHit = theFastRecHits->end();
00061   std::map< DetId, edm::OwnVector<SiTrackerGSRecHit2D> > temporaryRecHits;
00062     
00063   // loop on Fast GS Hits
00064   for ( ; aHit != theLastHit; ++aHit ) {
00065 
00066     DetId det = aHit->geographicalId();
00067 
00068     /* 
00069     const GeomDet* theDet = geometry->idToDet(det);
00070     unsigned trackID = aHit->simtrackId();
00071 
00072     std::cout << "Track/z/r after : "
00073               << trackID << " " 
00074               << theDet->surface().toGlobal(aHit->localPosition()).z() << " " 
00075               << theDet->surface().toGlobal(aHit->localPosition()).perp() << std::endl;
00076     */
00077 
00078     // create RecHit
00079     // Fill the temporary RecHit on the current DetId collection
00080     temporaryRecHits[det].push_back(aHit->clone());
00081 
00082   }
00083 
00084   // Step C: from the temporary RecHit collection, create the real one.
00085   std::auto_ptr<SiTrackerFullGSRecHit2DCollection> 
00086     recHitCollection(new SiTrackerFullGSRecHit2DCollection);
00087   loadRecHits(temporaryRecHits, *recHitCollection);
00088   
00089   // Step D: write output to file
00090   e.put(recHitCollection);
00091 
00092 }
00093 
00094 void 
00095 TrackingRecHitTranslator::loadRecHits(
00096      std::map<DetId,edm::OwnVector<SiTrackerGSRecHit2D> >& theRecHits, 
00097      SiTrackerFullGSRecHit2DCollection& theRecHitCollection) const
00098 {
00099   std::map<DetId,edm::OwnVector<SiTrackerGSRecHit2D> >::const_iterator 
00100     it = theRecHits.begin();
00101   std::map<DetId,edm::OwnVector<SiTrackerGSRecHit2D> >::const_iterator 
00102     lastRecHit = theRecHits.end();
00103 
00104   for( ; it != lastRecHit ; ++it ) { 
00105     theRecHitCollection.put(it->first,it->second.begin(),it->second.end());
00106   }
00107 
00108 }
00109