CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/Alignment/MuonAlignmentAlgorithms/plugins/MuonMillepedeTrackRefitter.cc

Go to the documentation of this file.
00001 
00009 #include "Alignment/MuonAlignmentAlgorithms/plugins/MuonMillepedeTrackRefitter.h"
00010 
00011 // Collaborating Class Header
00012 #include "Alignment/MuonAlignmentAlgorithms/interface/SegmentToTrackAssociator.h"
00013 
00014 #include "FWCore/Framework/interface/MakerMacros.h"
00015 #include "FWCore/Framework/interface/Frameworkfwd.h"
00016 #include "FWCore/Framework/interface/Event.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 
00019 #include "MagneticField/Engine/interface/MagneticField.h"
00020 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00021 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00022 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00023 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00024 
00025 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00026 #include "DataFormats/TrackReco/interface/Track.h"
00027 
00028 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00029 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00030 
00031 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
00032 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00033 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
00034 #include "DataFormats/GeometrySurface/interface/Plane.h"
00035 #include "DataFormats/GeometrySurface/interface/Cone.h"
00036 
00037 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00038 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00039 
00040 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHitBuilder.h"
00041 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00042 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00043 
00044 #include "DataFormats/MuonReco/interface/Muon.h"
00045 #include "DataFormats/MuonReco/interface/MuonFwd.h"
00046 
00047 
00048 #include <vector>
00049 #include "TH2D.h"
00050 
00051 
00053 MuonMillepedeTrackRefitter::MuonMillepedeTrackRefitter( const edm::ParameterSet& pset )
00054 {
00055   
00056   SACollectionTag = pset.getParameter<edm::InputTag>( "SATrackCollectionTag" );
00057   
00058   //Products
00059   produces<std::vector<Trajectory> >();
00060   produces<TrajTrackAssociationCollection>();
00061 
00062 }
00063 
00064 // Destructor
00065 MuonMillepedeTrackRefitter::~MuonMillepedeTrackRefitter()
00066 {
00067 }
00068 
00069 
00070 void MuonMillepedeTrackRefitter::produce( edm::Event & event, const edm::EventSetup& eventSetup )
00071 {
00072  
00073   //Get collections from the event
00074 
00075   edm::Handle<reco::TrackCollection> tracksSA;
00076   event.getByLabel( SACollectionTag, tracksSA );
00077 
00078   edm::ESHandle<MagneticField> theMGField;
00079   eventSetup.get<IdealMagneticFieldRecord>().get( theMGField );
00080 
00081   edm::ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
00082   eventSetup.get<GlobalTrackingGeometryRecord>().get( theTrackingGeometry );
00083 
00084   edm::RefProd<std::vector<Trajectory> > trajectoryCollectionRefProd 
00085     = event.getRefBeforePut<std::vector<Trajectory> >();
00086 
00087   //Allocate collection of tracks
00088   std::auto_ptr<std::vector<Trajectory> > trajectoryCollection( new std::vector<Trajectory> );
00089   // Association map between Trajectory and Track
00090   std::auto_ptr<TrajTrackAssociationCollection> trajTrackMap( new TrajTrackAssociationCollection );
00091  
00092 
00093   //Create the propagator
00094  
00095   std::map<edm::Ref<std::vector<Trajectory> >::key_type, edm::Ref<reco::TrackCollection>::key_type> trajToTrack_map;
00096   
00097   edm::Ref<std::vector<Trajectory> >::key_type trajectoryIndex = 0;
00098      
00099   reco::TrackRef::key_type trackIndex = 0;
00100 
00101   for (reco::TrackCollection::const_iterator trackSA = tracksSA->begin();  trackSA != tracksSA->end();  ++trackSA ) {
00102    
00103     reco::TransientTrack tTrackSA( *trackSA, &*theMGField, theTrackingGeometry );
00104 
00105     //Create an empty trajectory
00106     Trajectory myTraj;
00107 
00108     TrajectoryStateOnSurface innerTSOS = tTrackSA.innermostMeasurementState();
00109     
00110 
00111     for(trackingRecHit_iterator theHit = tTrackSA.recHitsBegin(); theHit != tTrackSA.recHitsEnd(); ++theHit) {
00112   
00113       TrackingRecHit *myClone = (*theHit)->clone(); 
00114       const GeomDet* myDet = theTrackingGeometry->idToDet( (*theHit)->geographicalId() );
00115       TrajectoryMeasurement myMeas(innerTSOS, &* MuonTransientTrackingRecHit::specificBuild(myDet, (TrackingRecHit *) &*myClone));
00116       myTraj.push(myMeas);
00117 
00118     }
00119  
00120     trajectoryCollection->push_back(myTraj);
00121     trajToTrack_map[trajectoryIndex] = trackIndex;          
00122     ++trajectoryIndex;
00123     ++trackIndex;
00124   } 
00125 
00126   edm::OrphanHandle<std::vector<Trajectory> > trajsRef = event.put(trajectoryCollection);
00127   
00128   for( trajectoryIndex = 0; trajectoryIndex < tracksSA->size(); ++trajectoryIndex) 
00129   {      
00130     edm::Ref<reco::TrackCollection>::key_type trackCounter = trajToTrack_map[trajectoryIndex];
00131     trajTrackMap->insert(edm::Ref<std::vector<Trajectory> >(trajsRef, trajectoryIndex), edm::Ref<reco::TrackCollection>(tracksSA, trackCounter));
00132   }
00133   
00134   event.put(trajTrackMap);
00135  
00136 }
00137 
00138 
00139 
00140 DEFINE_FWK_MODULE(MuonMillepedeTrackRefitter);
00141 
00142 
00143