CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/TrackingTools/TrackRefitter/plugins/TracksToTrajectories.cc

Go to the documentation of this file.
00001 #include "TrackingTools/TrackRefitter/plugins/TracksToTrajectories.h"
00002 
00003 #include "TrackingTools/TrackRefitter/interface/TrackTransformer.h"
00004 #include "TrackingTools/TrackRefitter/interface/TrackTransformerForGlobalCosmicMuons.h"
00005 #include "TrackingTools/TrackRefitter/interface/TrackTransformerForCosmicMuons.h"
00006 
00007 #include "FWCore/Framework/interface/Event.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 
00012 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00013 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
00014 
00015 #include "DataFormats/TrackReco/interface/Track.h"
00016 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00017 #include "DataFormats/Common/interface/Handle.h"
00018 
00019 using namespace std;
00020 using namespace edm;
00021 
00023 TracksToTrajectories::TracksToTrajectories(const ParameterSet& parameterSet):theTrackTransformer(0),
00024                                                                              theNTracks(0),theNFailures(0){
00025 
00026   theTracksLabel = parameterSet.getParameter<InputTag>("Tracks");
00027 
00028   ParameterSet trackTransformerParam = parameterSet.getParameter<ParameterSet>("TrackTransformer");
00029 
00030   string type = parameterSet.getParameter<string>("Type");
00031 
00032   if(type == "Default") theTrackTransformer = new TrackTransformer(trackTransformerParam);
00033   else if(type == "GlobalCosmicMuonsForAlignment") theTrackTransformer = new TrackTransformerForGlobalCosmicMuons(trackTransformerParam);
00034   else if(type == "CosmicMuonsForAlignment") theTrackTransformer = new TrackTransformerForCosmicMuons(trackTransformerParam);
00035   else{
00036     throw cms::Exception("TracksToTrajectories") 
00037       <<"The selected algorithm does not exist"
00038       << "\n"
00039       << "Possible choices are:"
00040       << "\n"
00041       << "Type = [Default, GlobalCosmicMuonsForAlignment, CosmicMuonsForAlignment]";
00042   }
00043 
00044   produces<vector<Trajectory> >("Refitted");
00045   produces<TrajTrackAssociationCollection>("Refitted");
00046 }
00047  
00048 
00050 TracksToTrajectories::~TracksToTrajectories(){
00051   if(theTrackTransformer) delete theTrackTransformer;
00052 }
00053 
00054 void TracksToTrajectories::endJob(){
00055   const string metname = "Reco|TrackingTools|TracksToTrajectories";
00056   
00057   if(theNFailures!=0)
00058     LogWarning(metname) << "During the refit there were " 
00059                         << theNFailures << " out of " << theNTracks << " tracks, i.e. failure rate is: " << double(theNFailures)/theNTracks;
00060   else{
00061     LogTrace(metname) << "Refit of the tracks done without any failure";
00062   }
00063 }
00064 
00065 
00067 void TracksToTrajectories::produce(Event& event, const EventSetup& setup){
00068 
00069   const string metname = "Reco|TrackingTools|TracksToTrajectories";
00070 
00071   theTrackTransformer->setServices(setup);
00072   
00073   // Collection of Trajectory
00074   auto_ptr<vector<Trajectory> > trajectoryCollection(new vector<Trajectory>);
00075   
00076   // Get the reference
00077   RefProd<vector<Trajectory> > trajectoryCollectionRefProd 
00078     = event.getRefBeforePut<vector<Trajectory> >("Refitted");
00079   
00080   // Association map between Trajectory and Track
00081   auto_ptr<TrajTrackAssociationCollection> trajTrackMap(new TrajTrackAssociationCollection);
00082  
00083   // Get the RecTrack collection from the event
00084   Handle<reco::TrackCollection> tracks;
00085   event.getByLabel(theTracksLabel,tracks);
00086   
00087   Ref<vector<Trajectory> >::key_type trajectoryIndex = 0;
00088   reco::TrackRef::key_type trackIndex = 0;
00089 
00090   // Loop over the Rec tracks
00091   for (reco::TrackCollection::const_iterator newTrack = tracks->begin(); 
00092        newTrack != tracks->end(); ++newTrack) {
00093     
00094     ++theNTracks;
00095 
00096     vector<Trajectory> trajectoriesSM = theTrackTransformer->transform(*newTrack);
00097     
00098     if(!trajectoriesSM.empty()){
00099       // Load the trajectory in the Trajectory Container
00100       trajectoryCollection->push_back(trajectoriesSM.front());
00101 
00102       // Make the association between the Trajectory and the original Track
00103       trajTrackMap->insert(Ref<vector<Trajectory> >(trajectoryCollectionRefProd,trajectoryIndex++),
00104                            reco::TrackRef(tracks,trackIndex++));
00105     }
00106     else{
00107       LogTrace(metname) << "Error in the Track refitting. This should not happen";
00108       ++theNFailures;
00109     }
00110   }
00111   LogTrace(metname)<<"Load the Trajectory Collection";
00112   event.put(trajectoryCollection,"Refitted");
00113   event.put(trajTrackMap,"Refitted");
00114 }