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
00036
00037
00038
00039
00040
00041 thePropagatorName = pset.getParameter<string>("Propagator");
00042 thePropagator = 0;
00043
00044
00045
00046 theFirstTime = true;
00047
00048
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
00055
00056
00057
00058 GlobalPoint glbPos(position[0],position[1],position[2]);
00059 thePosition = glbPos;
00060
00061
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
00068
00069
00070
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
00081 theChi2Cut = pset.getParameter<double>("MaxChi2");
00082 }
00083
00085 MuonUpdatorAtVertex::~MuonUpdatorAtVertex(){
00086 if (thePropagator) delete thePropagator;
00087 }
00088
00089
00090
00091
00093
00094
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
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
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
00133 return pair<bool,FreeTrajectoryState>(false,result.first);
00134 }
00135 }
00136
00137
00139
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
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
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
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
00230
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
00248
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
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
00283 GlobalPoint p1(0.,0.,-1500);
00284 GlobalPoint p2(0.,0.,1500);
00285
00286 pair<FreeTrajectoryState,double>
00287
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 }