CMS 3D CMS Logo

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 "TrackPropagation/SteppingHelixPropagator/interface/SteppingHelixPropagator.h"
00015 
00016 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00017 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00018 #include "TrackingTools/TransientTrack/interface/TransientTrackFromFTSFactory.h"
00019 #include "TrackingTools/GeomPropagators/interface/TrackerBounds.h"
00020 #include "TrackingTools/PatternTools/interface/TrajectoryStateClosestToBeamLineBuilder.h"
00021 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
00022 
00023 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00024 
00025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027 #include "FWCore/Utilities/interface/Exception.h"
00028 
00029 using namespace std;
00030 
00032 MuonUpdatorAtVertex::MuonUpdatorAtVertex(const edm::ParameterSet& pset,
00033                                          const MuonServiceProxy *service):theService(service){
00034   
00035   // FIXME
00036   // The SteppingHelixPropagator must be used explicitly since the method propagate(TSOS,GlobalPoint)
00037   // is only in its specific interface. Once the interface of the Propagator base class  will be
00038   // updated, then thePropagator will become generic. The string and the MuonServiceProxy are used
00039   // in order to make more simpler and faster the future transition.
00040   
00041   thePropagatorName = pset.getParameter<string>("Propagator");
00042   thePropagator = 0;
00043   
00044   // FIXME
00045   // remove the flag as the Propagator base class will gains the propagate(TSOS,Position) method
00046   theFirstTime = true;
00047   
00048   // Position of the beam spot
00049   vector<double> position = pset.getParameter< vector<double> >("BeamSpotPosition");
00050   if(position.size() != 3) 
00051     edm::LogError("Muon|RecoMuon|MuonUpdatorAtVertex")
00052       <<"MuonUpdatorAtVertex::BeamSpotPosition wrong number of parameters!!";
00053   
00054   // assume:
00055   // position[0] <=> x
00056   // position[1] <=> y
00057   // position[2] <=> z
00058   GlobalPoint glbPos(position[0],position[1],position[2]);
00059   thePosition = glbPos;
00060   
00061   // Errors on the Beam spot position
00062   vector<double> errors = pset.getParameter< vector<double> >("BeamSpotPositionErrors");
00063   if(errors.size() != 3) 
00064     edm::LogError("Muon|RecoMuon|MuonUpdatorAtVertex")
00065       <<"MuonUpdatorAtVertex::BeamSpotPositionErrors wrong number of parameters!!";
00066   
00067   // assume:
00068   // errors[0] = sigma(x) 
00069   // errors[1] = sigma(y) 
00070   // errors[2] = sigma(z)
00071 
00072   AlgebraicSymMatrix33 mat;
00073   mat(0,0) = errors[0]*errors[0];
00074   mat(1,1) = errors[1]*errors[1];
00075   mat(2,2) = errors[2]*errors[2];
00076   GlobalError glbErrPos(mat);
00077 
00078   thePositionErrors = glbErrPos;
00079 
00080   // cut on chi^2
00081   theChi2Cut = pset.getParameter<double>("MaxChi2");
00082 }
00083 
00085 MuonUpdatorAtVertex::~MuonUpdatorAtVertex(){
00086   if (thePropagator) delete thePropagator;
00087 }
00088 
00089 // Operations
00090 
00091 
00093 // FIXME!!! remove this method as the Propagator will gains the propagate(TSOS,Position) method
00094 // remove the flag as well
00095 void MuonUpdatorAtVertex::setPropagator(){
00096   const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
00097   
00098   if(theFirstTime ||
00099      theService->isTrackingComponentsRecordChanged()){
00100     if(thePropagator) delete thePropagator;
00101     Propagator *propagator = &*theService->propagator(thePropagatorName)->clone();
00102     thePropagator = dynamic_cast<SteppingHelixPropagator*>(propagator);  
00103     theFirstTime = false;
00104 
00105     LogTrace(metname) << " MuonUpdatorAtVertex::setPropagator: propagator changed!";
00106   }
00107   
00108 }
00110 
00112 // FIXME it is const. It will be when setPropagator() will be removed
00113 pair<bool,FreeTrajectoryState>
00114 MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos, 
00115                                const GlobalPoint &vtxPosition){
00116 
00117   const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
00118 
00119   setPropagator();
00120   //  return thePropagator->propagate(*tsos.freeState(),vtxPosition);
00121   pair<FreeTrajectoryState,double> 
00122     result = thePropagator->propagateWithPath(*tsos.freeState(),vtxPosition);
00123 
00124   LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: "
00125                     << result.second << " parameters: " << result.first.parameters();
00126 
00127   if( result.first.hasError()) 
00128     return pair<bool,FreeTrajectoryState>(true,result.first);
00129   else{
00130     edm::LogInfo(metname) << "Propagation to the PCA failed!";
00131     
00132     // FIXME: returns FreeTrajectoryState() instead of result.first?
00133     return pair<bool,FreeTrajectoryState>(false,result.first);
00134   }
00135 }
00136 
00137 
00139 // FIXME it is const. It will be when setPropagator() will be removed
00140 pair<bool,FreeTrajectoryState>
00141 MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos, const reco::BeamSpot & beamSpot){
00142 
00143   const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
00144 
00145   setPropagator();
00146   
00147   if(TrackerBounds::isInside(tsos.globalPosition())){
00148     LogTrace(metname) << "Trajectory inside the Tracker";
00149 
00150     TrajectoryStateClosestToBeamLineBuilder tscblBuilder;
00151     TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*(tsos.freeState()),
00152                                                           beamSpot);
00153 
00154     if(tscbl.isValid())
00155       return pair<bool,FreeTrajectoryState>(true,tscbl.trackStateAtPCA());
00156     else
00157       edm::LogWarning(metname) << "Propagation to the PCA using TSCPBuilderNoMaterial failed!"
00158                                << " This can cause a severe bug.";
00159   }
00160   else{
00161     LogTrace(metname) << "Trajectory inside the muon system";
00162 
00163     FreeTrajectoryState
00164       //      result = thePropagator->propagate(*tsos.freeState(),beamSpot);
00165       result =  theService->propagator(thePropagatorName)->propagate(*tsos.freeState(),beamSpot);
00166     
00167     LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: "
00168                       << result << " parameters: " << result.parameters();
00169     
00170     if(result.hasError()) 
00171       return pair<bool,FreeTrajectoryState>(true,result);
00172     else
00173       edm::LogInfo(metname) << "Propagation to the PCA failed!";
00174   }
00175   return pair<bool,FreeTrajectoryState>(false,FreeTrajectoryState());
00176 }
00177 
00178 
00179 // FIXME it is const. It will be when setPropagator() will be removed
00180 pair<bool,FreeTrajectoryState>
00181 MuonUpdatorAtVertex::update(const reco::TransientTrack & track, const reco::BeamSpot & beamSpot){
00182 
00183   const std::string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
00184     
00185   // FIXME
00186   setPropagator();
00187 
00188   pair<bool,FreeTrajectoryState> result(false,FreeTrajectoryState());
00189   
00190   SingleTrackVertexConstraint::TrackFloatPair constrainedTransientTrack;
00191 
00192   try{
00193     GlobalPoint spotPos(beamSpot.x0(),beamSpot.y0(),beamSpot.z0());
00194     constrainedTransientTrack = theConstrictor.constrain(track, spotPos, thePositionErrors);
00195   }
00196   catch ( cms::Exception& e ) {
00197     edm::LogWarning(metname) << "cms::Exception caught in MuonUpdatorAtVertex::update\n"
00198                              << e.explainSelf();
00199     return result;
00200   }
00201 
00202   if(constrainedTransientTrack.second <= theChi2Cut) {
00203     result.first = true;
00204     result.second = *constrainedTransientTrack.first.impactPointState().freeState();
00205   }
00206   else
00207     edm::LogInfo(metname) << "Constraint at vertex failed"; 
00208     
00209   return result;
00210 }
00211 
00212 pair<bool,FreeTrajectoryState>
00213 MuonUpdatorAtVertex::update(const FreeTrajectoryState& ftsAtVtx, const reco::BeamSpot & beamSpot){
00214   
00215   return update(theTransientTrackFactory.build(ftsAtVtx),beamSpot);
00216 }
00217 
00218 
00219 
00220 pair<bool,FreeTrajectoryState>
00221 MuonUpdatorAtVertex::propagateWithUpdate(const TrajectoryStateOnSurface &tsos, 
00222                                          const GlobalPoint &vtxPosition,
00223                                          const reco::BeamSpot & beamSpot){
00224   
00225   pair<bool,FreeTrajectoryState>
00226     propagationResult = propagate(tsos,vtxPosition);
00227 
00228   if(propagationResult.first){
00229     // FIXME!!!
00230     // This is very very temporary! Waiting for the changes in the KalmanVertexFitter interface
00231     return update(propagationResult.second, beamSpot);
00232   }
00233   else{
00234     edm::LogInfo("Muon|RecoMuon|MuonUpdatorAtVertex") << "Constraint at vertex failed";
00235     return pair<bool,FreeTrajectoryState>(false,FreeTrajectoryState());
00236   }
00237 }
00238 
00239 
00240 pair<bool,FreeTrajectoryState>
00241 MuonUpdatorAtVertex::propagateWithUpdate(const TrajectoryStateOnSurface &tsos, const reco::BeamSpot & beamSpot){
00242   
00243   pair<bool,FreeTrajectoryState>
00244     propagationResult = propagate(tsos,beamSpot);
00245 
00246   if(propagationResult.first){
00247     // FIXME!!!
00248     // This is very very temporary! Waiting for the changes in the KalmanVertexFitter interface
00249     return update(propagationResult.second, beamSpot);
00250   }
00251   else{
00252     edm::LogInfo("Muon|RecoMuon|MuonUpdatorAtVertex") << "Constraint at vertex failed";
00253     return pair<bool,FreeTrajectoryState>(false,FreeTrajectoryState());
00254   }
00255 }
00256 
00257 
00258  std::pair<bool,FreeTrajectoryState>
00259  MuonUpdatorAtVertex::propagateToNominalLine(const TrajectoryStateOnSurface &tsos){
00260    
00261    const string metname = "Muon|RecoMuon|MuonUpdatorAtVertex";
00262    
00263    setPropagator();
00264    
00265    if(TrackerBounds::isInside(tsos.globalPosition())){
00266      LogTrace(metname) << "Trajectory inside the Tracker";
00267      
00268      TSCPBuilderNoMaterial tscpBuilder;
00269      TrajectoryStateClosestToPoint tscp = tscpBuilder(*(tsos.freeState()),
00270                                                      GlobalPoint(0.,0.,0.));
00271     
00272     // FIXME: check if the tscp is valid or not!!
00273     if(tscp.hasError())
00274       return pair<bool,FreeTrajectoryState>(true,tscp.theState());
00275     else
00276       edm::LogWarning(metname) << "Propagation to the PCA using TSCPBuilderNoMaterial failed!"
00277                                << " This can cause a severe bug.";
00278   }
00279   else{
00280     LogTrace(metname) << "Trajectory inside the muon system";
00281 
00282     // Define a line using two 3D-points
00283     GlobalPoint p1(0.,0.,-1500);
00284     GlobalPoint p2(0.,0.,1500);
00285     
00286     pair<FreeTrajectoryState,double> 
00287       //      result = thePropagator->propagateWithPath(*tsos.freeState(),p1,p2);
00288       result = theService->propagator(thePropagatorName)->propagateWithPath(*tsos.freeState(),p1,p2);
00289     
00290     LogTrace(metname) << "MuonUpdatorAtVertex::propagate, path: "
00291                       << result.second << " parameters: " << result.first.parameters();
00292     
00293     if(result.first.hasError()) 
00294       return pair<bool,FreeTrajectoryState>(true,result.first);
00295     else
00296       edm::LogInfo(metname) << "Propagation to the PCA failed! Path: "<<result.second;
00297   }
00298   return pair<bool,FreeTrajectoryState>(false,FreeTrajectoryState());
00299 
00300    
00301 }
00302 
00303 std::pair<bool,FreeTrajectoryState>
00304 MuonUpdatorAtVertex::propagate(const TrajectoryStateOnSurface &tsos){
00305   return propagateToNominalLine(tsos);
00306 }

Generated on Tue Jun 9 17:44:37 2009 for CMSSW by  doxygen 1.5.4