CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/RecoMuon/TrackingTools/src/MuonSeedFromRecHits.cc

Go to the documentation of this file.
00001 
00011 #include "RecoMuon/TrackingTools/interface/MuonSeedFromRecHits.h"
00012 
00013 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHit.h"
00014 
00015 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00016 
00017 #include "MagneticField/Engine/interface/MagneticField.h"
00018 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00019 
00020 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00021 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00022 
00023 #include "DataFormats/TrajectoryState/interface/PTrajectoryStateOnDet.h"
00024 #include "DataFormats/Common/interface/OwnVector.h"
00025 #include "FWCore/Framework/interface/EventSetup.h"
00026 #include "FWCore/Framework/interface/ESHandle.h"
00027 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00028 
00029 #include "gsl/gsl_statistics.h"
00030 
00031 using namespace std;
00032 
00033 template <class T> T sqr(const T& t) {return t*t;}
00034 
00035 MuonSeedFromRecHits::MuonSeedFromRecHits()
00036 : theField(0)
00037 {
00038 }
00039 
00040 
00041 TrajectorySeed MuonSeedFromRecHits::createSeed(float ptmean,
00042                                                float sptmean,
00043                                                ConstMuonRecHitPointer last) const
00044 {
00045   
00046   const std::string metname = "Muon|RecoMuon|MuonSeedFromRecHits";
00047 
00048   MuonPatternRecoDumper debug;
00049 
00050   // FIXME: put it into a parameter set!
00051   double theMinMomentum = 3.0;
00052  
00053   // Minimal pt
00054   if ( fabs(ptmean) < theMinMomentum ) ptmean = theMinMomentum * ptmean/fabs(ptmean) ;
00055 
00056   AlgebraicVector t(4);
00057   AlgebraicSymMatrix mat(5,0) ;
00058 
00059   // Fill the LocalTrajectoryParameters
00060   LocalPoint segPos=last->localPosition();
00061   GlobalVector mom=last->globalPosition()-GlobalPoint();
00062   GlobalVector polar(GlobalVector::Spherical(mom.theta(),
00063                                              last->globalDirection().phi(),
00064                                              1.));
00065   polar *=fabs(ptmean)/polar.perp();
00066   LocalVector segDirFromPos=last->det()->toLocal(polar);
00067   int charge=(int)(ptmean/fabs(ptmean));
00068 
00069   LocalTrajectoryParameters param(segPos,segDirFromPos, charge);
00070 
00071   // this perform H.T() * parErr * H, which is the projection of the 
00072   // the measurement error (rechit rf) to the state error (TSOS rf)
00073   // Legenda:
00074   // H => is the 4x5 projection matrix
00075   // parError the 4x4 parameter error matrix of the RecHit
00076 
00077   // LogTrace(metname) << "Projection matrix:\n" << last->projectionMatrix();
00078   // LogTrace(metname) << "Error matrix:\n" << last->parametersError();
00079 
00080   mat = last->parametersError().similarityT( last->projectionMatrix() );
00081   
00082 
00083   float p_err = sqr(sptmean/(ptmean*ptmean));
00084   mat[0][0]= p_err;
00085   
00086 
00087   LocalTrajectoryError error(asSMatrix<5>(mat));
00088   
00089   // Create the TrajectoryStateOnSurface
00090   TrajectoryStateOnSurface tsos(param, error, last->det()->surface(), theField);
00091 
00092   // The following LogTraces must be moved somewhere else (StandAloneTrajectoryBuilder)
00093   // Here the TSOS does not have the magnetic field set, so dumpTSOS causes a crash
00094   // (when LogTrace/LogDebug is activated)
00095   //LogTrace(metname) << "Trajectory State on Surface before the extrapolation"<<endl;
00096   //LogTrace(metname) << debug.dumpTSOS(tsos);
00097   
00098   // Take the DetLayer on which relies the rechit
00099   DetId id = last->geographicalId();
00100   // Segment layer
00101   //LogTrace(metname) << "The RecSegment relies on: "<<endl;
00102   //LogTrace(metname) << debug.dumpMuonId(id);
00103   //LogTrace(metname) << debug.dumpTSOS(tsos);
00104 
00105   // Transform it in a TrajectoryStateOnSurface
00106   
00107   
00108   PTrajectoryStateOnDet const & seedTSOS =
00109     trajectoryStateTransform::persistentState( tsos ,id.rawId());
00110   
00111   edm::OwnVector<TrackingRecHit> container;
00112   for (unsigned l=0; l<theRhits.size(); l++) {
00113       container.push_back( theRhits[l]->hit()->clone() );
00114   }
00115 
00116   TrajectorySeed theSeed(seedTSOS,container,alongMomentum);
00117    
00118   return theSeed;
00119 }
00120 
00121 
00122 
00123