CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoMuon/TrackingTools/src/MuonUpdatorAtVertex.cc

Go to the documentation of this file.
00001 
00011 #include "RecoMuon/TrackingTools/interface/MuonUpdatorAtVertex.h"
00012 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
00013 
00014 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00015 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00016 #include "TrackingTools/TransientTrack/interface/TransientTrackFromFTSFactory.h"
00017 #include "TrackingTools/GeomPropagators/interface/TrackerBounds.h"
00018 #include "TrackingTools/PatternTools/interface/TSCBLBuilderNoMaterial.h"
00019 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00020 
00021 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00022 
00023 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00025 #include "FWCore/Utilities/interface/Exception.h"
00026 
00027 using namespace std;
00028 
00030 MuonUpdatorAtVertex::MuonUpdatorAtVertex(const edm::ParameterSet& pset,
00031                                          const MuonServiceProxy *service):theService(service){
00032    
00033   thePropagatorName = pset.getParameter<string>("Propagator");
00034     
00035 
00036   // Errors on the Beam spot position
00037   vector<double> errors = pset.getParameter< vector<double> >("BeamSpotPositionErrors");
00038   if(errors.size() != 3) 
00039     edm::LogError("Muon|RecoMuon|MuonUpdatorAtVertex")
00040       <<"MuonUpdatorAtVertex::BeamSpotPositionErrors wrong number of parameters!!";
00041   
00042   // assume:
00043   // errors[0] = sigma(x) 
00044   // errors[1] = sigma(y) 
00045   // errors[2] = sigma(z)
00046 
00047   AlgebraicSymMatrix33 mat;
00048   mat(0,0) = errors[0]*errors[0];
00049   mat(1,1) = errors[1]*errors[1];
00050   mat(2,2) = errors[2]*errors[2];
00051   GlobalError glbErrPos(mat);
00052 
00053   thePositionErrors = glbErrPos;
00054 
00055   // cut on chi^2
00056   theChi2Cut = pset.getParameter<double>("MaxChi2");
00057 }
00058 
00060 MuonUpdatorAtVertex::~MuonUpdatorAtVertex(){}
00061 
00062 // Operations
00063 
00065 pair<bool,FreeTrajectoryState>
00066 MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos, const reco::BeamSpot & beamSpot) const{
00067 
00068   const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
00069  
00070   if(TrackerBounds::isInside(tsos.globalPosition())){
00071     LogTrace(metname) << "Trajectory inside the Tracker";
00072 
00073     TSCBLBuilderNoMaterial tscblBuilder;
00074     TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*(tsos.freeState()),
00075                                                           beamSpot);
00076 
00077     if(tscbl.isValid())
00078       return pair<bool,FreeTrajectoryState>(true,tscbl.trackStateAtPCA());
00079     else
00080       edm::LogWarning(metname) << "Propagation to the PCA using TSCPBuilderNoMaterial failed!"
00081                                << " This can cause a severe bug.";
00082   }
00083   else{
00084     LogTrace(metname) << "Trajectory inside the muon system";
00085 
00086     FreeTrajectoryState
00087       result =  theService->propagator(thePropagatorName)->propagate(*tsos.freeState(),beamSpot);
00088     
00089     LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: "
00090                       << result << " parameters: " << result.parameters();
00091     
00092     if(result.hasError()) 
00093       return pair<bool,FreeTrajectoryState>(true,result);
00094     else
00095       edm::LogInfo(metname) << "Propagation to the PCA failed!";
00096   }
00097   return pair<bool,FreeTrajectoryState>(false,FreeTrajectoryState());
00098 }
00099 
00100 
00101 pair<bool,FreeTrajectoryState>
00102 MuonUpdatorAtVertex::update(const reco::TransientTrack & track, const reco::BeamSpot & beamSpot) const{
00103 
00104   const std::string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
00105     
00106   
00107   pair<bool,FreeTrajectoryState> result(false,FreeTrajectoryState());
00108 
00109   GlobalPoint spotPos(beamSpot.x0(),beamSpot.y0(),beamSpot.z0());
00110 
00111   SingleTrackVertexConstraint::BTFtuple constrainedTransientTrack;
00112 
00113   // Temporary hack here. A fix in the SingleTrackVertexConstraint code
00114   // is needed. Once available try&catch will be removed 
00115   try{
00116     constrainedTransientTrack = theConstrictor.constrain(track, 
00117                                                          spotPos, 
00118                                                          thePositionErrors);
00119   }
00120   catch(cms::Exception& e) {
00121     edm::LogWarning(metname) << "cms::Exception caught in MuonUpdatorAtVertex::update\n"
00122                              << "Exception from SingleTrackVertexConstraint\n"
00123                              << e.explainSelf();
00124     return result;
00125   }
00126 
00127 
00128   if(constrainedTransientTrack.get<0>())
00129     if(constrainedTransientTrack.get<2>() <= theChi2Cut) {
00130       result.first = true;
00131       result.second = *constrainedTransientTrack.get<1>().impactPointState().freeState();
00132     }
00133     else
00134       LogTrace(metname) << "Constraint at vertex failed: too large chi2"; 
00135   else
00136     LogTrace(metname) << "Constraint at vertex failed"; 
00137   
00138   return result;
00139 }
00140 
00141 pair<bool,FreeTrajectoryState>
00142 MuonUpdatorAtVertex::update(const FreeTrajectoryState& ftsAtVtx, const reco::BeamSpot & beamSpot) const{
00143   
00144   return update(theTransientTrackFactory.build(ftsAtVtx),beamSpot);
00145 }
00146 
00147 
00148 pair<bool,FreeTrajectoryState>
00149 MuonUpdatorAtVertex::propagateWithUpdate(const TrajectoryStateOnSurface &tsos, const reco::BeamSpot & beamSpot) const{
00150   
00151   pair<bool,FreeTrajectoryState>
00152     propagationResult = propagate(tsos,beamSpot);
00153 
00154   if(propagationResult.first){
00155     return update(propagationResult.second, beamSpot);
00156   }
00157   else{
00158     edm::LogInfo("Muon|RecoMuon|MuonUpdatorAtVertex") << "Constraint at vertex failed";
00159     return pair<bool,FreeTrajectoryState>(false,FreeTrajectoryState());
00160   }
00161 }
00162 
00163 
00164  std::pair<bool,FreeTrajectoryState>
00165  MuonUpdatorAtVertex::propagateToNominalLine(const TrajectoryStateOnSurface &tsos) const{
00166    
00167    const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
00168    
00169    if(TrackerBounds::isInside(tsos.globalPosition())){
00170      LogTrace(metname) << "Trajectory inside the Tracker";
00171      
00172      TSCPBuilderNoMaterial tscpBuilder;
00173      TrajectoryStateClosestToPoint tscp = tscpBuilder(*(tsos.freeState()),
00174                                                      GlobalPoint(0.,0.,0.));
00175     
00176     if(tscp.isValid())
00177       return pair<bool,FreeTrajectoryState>(true,tscp.theState());
00178     else
00179       edm::LogWarning(metname) << "Propagation to the PCA using TSCPBuilderNoMaterial failed!"
00180                                << " This can cause a severe bug.";
00181   }
00182   else{
00183     LogTrace(metname) << "Trajectory inside the muon system";
00184 
00185     // Define a line using two 3D-points
00186     GlobalPoint p1(0.,0.,-1500);
00187     GlobalPoint p2(0.,0.,1500);
00188     
00189     pair<FreeTrajectoryState,double> 
00190       result = theService->propagator(thePropagatorName)->propagateWithPath(*tsos.freeState(),p1,p2);
00191     
00192     LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: "
00193                       << result.second << " parameters: " << result.first.parameters();
00194     
00195     if(result.first.hasError()) 
00196       return pair<bool,FreeTrajectoryState>(true,result.first);
00197     else
00198       edm::LogInfo(metname) << "Propagation to the PCA failed! Path: "<<result.second;
00199   }
00200   return pair<bool,FreeTrajectoryState>(false,FreeTrajectoryState());  
00201 }
00202 
00203 std::pair<bool,FreeTrajectoryState>
00204 MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos) const{
00205   return propagateToNominalLine(tsos);
00206 }