CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/TrackingTools/TrackRefitter/src/SeedTransformer.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2011/01/06 17:12:24 $
00005  *  $Revision: 1.8 $
00006  *  \author D. Trocino - University and INFN Torino
00007  */
00008 
00009 #include "TrackingTools/TrackRefitter/interface/SeedTransformer.h"
00010 
00011 // System include files
00012 #include <memory>
00013 #include <Riostream.h>
00014 
00015 // Framework
00016 #include "FWCore/Framework/interface/MakerMacros.h"
00017 #include "FWCore/Framework/interface/Frameworkfwd.h"
00018 #include "FWCore/Framework/interface/Event.h"
00019 #include "FWCore/Framework/interface/EventSetup.h"
00020 #include "FWCore/Framework/interface/ESHandle.h"
00021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 
00024 // Services and Tools
00025 
00026 // Geometry and Magnetic field
00027 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00028 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00029 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00030 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00031 
00032 // Other include files
00033 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00034 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
00035 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00036 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00037 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00038 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
00039 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00040 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00041 
00042 
00043 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHitBreaker.h"
00044 
00045 using namespace std;
00046 using namespace edm;
00047 using namespace reco;
00048 
00049 
00050 SeedTransformer::SeedTransformer(const ParameterSet& iConfig) {
00051 
00052   LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer constructor called." << endl << endl;
00053 
00054   theFitterName = iConfig.getParameter<string>("Fitter");  
00055   theMuonRecHitBuilderName = iConfig.getParameter<string>("MuonRecHitBuilder");
00056   thePropagatorName = iConfig.getParameter<string>("Propagator");
00057 
00058   nMinRecHits = iConfig.getParameter<unsigned int>("NMinRecHits");
00059   errorRescale = iConfig.getParameter<double>("RescaleError");
00060   useSubRecHits = iConfig.getParameter<bool>("UseSubRecHits");
00061 }
00062 
00063 SeedTransformer::~SeedTransformer() {
00064 
00065   LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer destructor called." << endl << endl;
00066 
00067 }
00068 
00069 void SeedTransformer::setServices(const EventSetup& iSetup) {
00070 
00071   iSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry); 
00072   iSetup.get<IdealMagneticFieldRecord>().get(theMagneticField);
00073   iSetup.get<TrajectoryFitter::Record>().get(theFitterName,theFitter);
00074   iSetup.get<TransientRecHitRecord>().get(theMuonRecHitBuilderName,theMuonRecHitBuilder);
00075   iSetup.get<TrackingComponentsRecord>().get(thePropagatorName,thePropagator);
00076 
00077 }
00078 
00079 vector<Trajectory> SeedTransformer::seedTransform(const TrajectorySeed& aSeed) const {
00080 
00081   const string metname = "Reco|TrackingTools|SeedTransformer";
00082 
00083   LogTrace(metname) << " Number of valid RecHits:      " << aSeed.nHits() << endl;
00084 
00085   if( aSeed.nHits() < nMinRecHits ) {
00086     LogTrace(metname) << "    --- Too few RecHits, no refit performed! ---" << endl;
00087     return vector<Trajectory>();
00088   }
00089 
00090   TrajectoryStateOnSurface aTSOS(seedTransientState(aSeed));
00091 
00092   // Rescale errors before refit, not to bias the result
00093   aTSOS.rescaleError(errorRescale);
00094 
00095   vector<TransientTrackingRecHit::ConstRecHitPointer> recHits;
00096   unsigned int countRH = 0;
00097 
00098   for(TrajectorySeed::recHitContainer::const_iterator itRecHits=aSeed.recHits().first; itRecHits!=aSeed.recHits().second; ++itRecHits, ++countRH) {
00099     if((*itRecHits).isValid()) {
00100       TransientTrackingRecHit::ConstRecHitPointer ttrh(theMuonRecHitBuilder->build(&(*itRecHits)));
00101 
00102       if(useSubRecHits){
00103         TransientTrackingRecHit::ConstRecHitContainer subHits =
00104           MuonTransientTrackingRecHitBreaker::breakInSubRecHits(ttrh,2);
00105         copy(subHits.begin(),subHits.end(),back_inserter(recHits));
00106       }
00107       else{
00108         recHits.push_back(ttrh);
00109       }    
00110     }
00111   } // end for(TrajectorySeed::recHitContainer::const_iterator itRecHits=aSeed.recHits().first; itRecHits!=aSeed.recHits().second; ++itRecHits, ++countRH)
00112 
00113   TrajectoryStateOnSurface aInitTSOS = thePropagator->propagate(aTSOS, recHits.front()->det()->surface());
00114 
00115   if(!aInitTSOS.isValid()) {
00116     LogTrace(metname) << "    --- Initial state for refit not valid! ---" << endl;
00117     return vector<Trajectory>();
00118   }
00119 
00120   vector<Trajectory> refittedSeed = theFitter->fit(aSeed, recHits, aInitTSOS);
00121 
00122   if(refittedSeed.empty()) {
00123     LogTrace(metname) << "    --- Seed fit failed! ---" << endl;
00124     return vector<Trajectory>();
00125   }
00126 
00127   else if(!refittedSeed.front().isValid()) {
00128     LogTrace(metname) << "    --- Seed fitted, but trajectory not valid! ---" << endl;
00129     return vector<Trajectory>();
00130   }
00131 
00132   else
00133     LogTrace(metname) << "    +++ Seed fit succeded! +++" << endl;
00134 
00135   return refittedSeed;
00136 
00137 }
00138 
00139 TrajectoryStateOnSurface SeedTransformer::seedTransientState(const TrajectorySeed& tmpSeed) const {
00140 
00141   PTrajectoryStateOnDet tmpTSOD = tmpSeed.startingState();
00142   DetId tmpDetId(tmpTSOD.detId());
00143   const GeomDet* tmpGeomDet = theTrackingGeometry->idToDet(tmpDetId);
00144 
00145   TrajectoryStateTransform tsTransform;
00146   TrajectoryStateOnSurface tmpTSOS = tsTransform.transientState(tmpTSOD, &(tmpGeomDet->surface()), &(*theMagneticField));
00147 
00148   return tmpTSOS;
00149 
00150 }