CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/FastSimulation/TrackingRecHitProducer/src/TrackingRecHitTranslator.cc

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