#include <RecoMuon/CosmicMuonProducer/interface/CosmicMuonSmoother.h>
Definition at line 37 of file CosmicMuonSmoother.h.
CosmicMuonSmoother::CosmicMuonSmoother | ( | const edm::ParameterSet & | par, | |
const MuonServiceProxy * | service | |||
) |
Definition at line 34 of file CosmicMuonSmoother.cc.
References category_, Chi2MeasurementEstimatorESProducer_cfi::Chi2MeasurementEstimator, edm::ParameterSet::getParameter(), theErrorRescaling, theEstimator, thePropagatorAlongName, thePropagatorOppositeName, theUpdator, and theUtilities.
Referenced by clone().
00034 : theService(service) { 00035 00036 theUpdator = new KFUpdator; 00037 theUtilities = new CosmicMuonUtilities; 00038 theEstimator = new Chi2MeasurementEstimator(200.0); 00039 thePropagatorAlongName = par.getParameter<string>("PropagatorAlong"); 00040 thePropagatorOppositeName = par.getParameter<string>("PropagatorOpposite"); 00041 theErrorRescaling = par.getParameter<double>("RescalingFactor"); 00042 00043 category_ = "Muon|RecoMuon|CosmicMuon|CosmicMuonSmoother"; 00044 }
CosmicMuonSmoother::~CosmicMuonSmoother | ( | ) | [virtual] |
Definition at line 49 of file CosmicMuonSmoother.cc.
References theEstimator, theUpdator, and theUtilities.
00049 { 00050 00051 if ( theUpdator ) delete theUpdator; 00052 if ( theUtilities ) delete theUtilities; 00053 if ( theEstimator ) delete theEstimator; 00054 00055 }
virtual CosmicMuonSmoother* CosmicMuonSmoother::clone | ( | void | ) | const [inline, virtual] |
Implements TrajectorySmoother.
Definition at line 46 of file CosmicMuonSmoother.h.
References CosmicMuonSmoother().
00046 { 00047 return new CosmicMuonSmoother(*this); 00048 }
Chi2MeasurementEstimator* CosmicMuonSmoother::estimator | ( | void | ) | const [inline] |
Definition at line 64 of file CosmicMuonSmoother.h.
References theEstimator.
00064 {return theEstimator;}
vector< Trajectory > CosmicMuonSmoother::fit | ( | const TrajectorySeed & | seed, | |
const ConstRecHitContainer & | hits, | |||
const TrajectoryStateOnSurface & | firstPredTsos | |||
) | const |
Definition at line 127 of file CosmicMuonSmoother.cc.
References funct::abs(), alongMomentum, category_, Chi2MeasurementEstimator::estimate(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), TrajectoryStateOnSurface::isValid(), LogTrace, Trajectory::measurements(), Propagator::propagate(), propagatorAlong(), Trajectory::push(), edm::second(), CosmicMuonUtilities::stepPropagate(), TrajectoryStateOnSurface::surface(), theEstimator, theService, theUpdator, theUtilities, and KFUpdator::update().
00129 { 00130 00131 LogTrace(category_)<< "fit begin (seed, hit, tsos)."; 00132 00133 if ( hits.empty() ) { 00134 LogTrace(category_)<< "Error: empty hits container."; 00135 return vector<Trajectory>(); 00136 } 00137 00138 Trajectory myTraj(seed, alongMomentum); 00139 00140 TrajectoryStateOnSurface predTsos(firstPredTsos); 00141 LogTrace(category_)<< "first pred TSOS: "<<predTsos; 00142 00143 if ( !predTsos.isValid() ) { 00144 LogTrace(category_)<< "Error: firstTsos invalid."; 00145 return vector<Trajectory>(); 00146 } 00147 TrajectoryStateOnSurface currTsos; 00148 00149 if ( hits.front()->isValid() ) { 00150 00151 TransientTrackingRecHit::RecHitPointer preciseHit = hits.front()->clone(predTsos); 00152 LogTrace(category_)<<"first hit is at det "<< hits.front()->det()->surface().position(); 00153 00154 currTsos = theUpdator->update(predTsos, *preciseHit); 00155 myTraj.push(TrajectoryMeasurement(predTsos, currTsos, hits.front(), 00156 theEstimator->estimate(predTsos, *hits.front()).second)); 00157 if ( currTsos.isValid() ) LogTrace(category_)<< "first curr TSOS: "<<currTsos; 00158 00159 00160 } else { 00161 00162 currTsos = predTsos; 00163 myTraj.push(TrajectoryMeasurement(predTsos, hits.front())); 00164 } 00165 //const TransientTrackingRecHit& firsthit = *hits.front(); 00166 00167 for ( ConstRecHitContainer::const_iterator ihit = hits.begin() + 1; 00168 ihit != hits.end(); ++ihit ) { 00169 00170 if ( !(**ihit).isValid() ) { 00171 LogTrace(category_)<< "Error: invalid hit."; 00172 continue; 00173 } 00174 if (currTsos.isValid()) { 00175 LogTrace(category_)<<"current pos "<<currTsos.globalPosition() 00176 <<"mom "<<currTsos.globalMomentum(); 00177 } else { 00178 LogTrace(category_)<<"current state invalid"; 00179 } 00180 00181 predTsos = propagatorAlong()->propagate(currTsos, (**ihit).det()->surface()); 00182 LogTrace(category_)<<"predicted state propagate directly "<<predTsos.isValid(); 00183 00184 if ( !predTsos.isValid() ) { 00185 LogTrace(category_)<<"step-propagating from "<<currTsos.globalPosition() <<" to position: "<<(*ihit)->globalPosition(); 00186 predTsos = theUtilities->stepPropagate(currTsos, (*ihit), *propagatorAlong()); 00187 } 00188 if ( !predTsos.isValid() && (abs(theService->magneticField()->inTesla(GlobalPoint(0,0,0)).z()) < 0.01) && (theService->propagator("StraightLinePropagator").isValid() ) ) { 00189 LogTrace(category_)<<"straight-line propagating from "<<currTsos.globalPosition() <<" to position: "<<(*ihit)->globalPosition(); 00190 predTsos = theService->propagator("StraightLinePropagator")->propagate(currTsos, (**ihit).det()->surface()); 00191 } 00192 if (predTsos.isValid()) { 00193 LogTrace(category_)<<"predicted pos "<<predTsos.globalPosition() 00194 <<"mom "<<predTsos.globalMomentum(); 00195 } else { 00196 LogTrace(category_)<<"predicted state invalid"; 00197 } 00198 if ( !predTsos.isValid() ) { 00199 LogTrace(category_)<< "Error: predTsos is still invalid forward fit."; 00200 // return vector<Trajectory>(); 00201 continue; 00202 } else if ( (**ihit).isValid() ) { 00203 // update 00204 TransientTrackingRecHit::RecHitPointer preciseHit = (**ihit).clone(predTsos); 00205 00206 if ( !preciseHit->isValid() ) { 00207 currTsos = predTsos; 00208 myTraj.push(TrajectoryMeasurement(predTsos, *ihit)); 00209 } else { 00210 currTsos = theUpdator->update(predTsos, *preciseHit); 00211 myTraj.push(TrajectoryMeasurement(predTsos, currTsos, preciseHit, 00212 theEstimator->estimate(predTsos, *preciseHit).second)); 00213 } 00214 } else { 00215 currTsos = predTsos; 00216 myTraj.push(TrajectoryMeasurement(predTsos, *ihit)); 00217 } 00218 00219 } 00220 00221 std::vector<TrajectoryMeasurement> mytms = myTraj.measurements(); 00222 LogTrace(category_)<<"fit result "<<mytms.size(); 00223 for (std::vector<TrajectoryMeasurement>::const_iterator itm = mytms.begin(); 00224 itm != mytms.end(); ++itm ) { 00225 LogTrace(category_)<<"updated pos "<<itm->updatedState().globalPosition() 00226 <<"mom "<<itm->updatedState().globalMomentum(); 00227 } 00228 00229 00230 return vector<Trajectory>(1, myTraj); 00231 00232 }
vector< Trajectory > CosmicMuonSmoother::fit | ( | const Trajectory & | t | ) | const |
Definition at line 95 of file CosmicMuonSmoother.cc.
References category_, Trajectory::empty(), initialState(), TrajectoryStateOnSurface::isValid(), LogTrace, Trajectory::recHits(), Trajectory::seed(), and sortHitsAlongMom().
Referenced by CosmicMuonTrajectoryBuilder::flipTrajectory(), GlobalCosmicMuonTrajectoryBuilder::trajectories(), and trajectories().
00095 { 00096 00097 if ( t.empty() ) return vector<Trajectory>(); 00098 00099 LogTrace(category_)<< "fit begin (trajectory) "; 00100 00101 TrajectoryStateOnSurface firstTsos = initialState(t); 00102 if ( !firstTsos.isValid() ) { 00103 LogTrace(category_)<< "Error: firstTsos invalid. "; 00104 return vector<Trajectory>(); 00105 } 00106 00107 LogTrace(category_)<< "firstTsos: "<<firstTsos; 00108 00109 ConstRecHitContainer hits = t.recHits(); 00110 LogTrace(category_)<< "hits: "<<hits.size(); 00111 LogTrace(category_)<<"hit front" <<hits.front()->globalPosition()<< " hit back" 00112 <<hits.back()->globalPosition(); 00113 00114 sortHitsAlongMom(hits, firstTsos); 00115 00116 LogTrace(category_)<<"after sorting hit front" <<hits.front()->globalPosition()<< " hit back" 00117 <<hits.back()->globalPosition(); 00118 00119 return fit(t.seed(), hits, firstTsos); 00120 00121 }
TrajectoryStateOnSurface CosmicMuonSmoother::initialState | ( | const Trajectory & | t | ) | const [private] |
Definition at line 403 of file CosmicMuonSmoother.cc.
References Trajectory::empty(), PV3DBase< T, PVType, FrameType >::eta(), Trajectory::firstMeasurement(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), TrajectoryStateOnSurface::isValid(), Trajectory::lastMeasurement(), CosmicMuonUtilities::reverseDirection(), theService, theUtilities, TrajectoryMeasurement::updatedState(), PV3DBase< T, PVType, FrameType >::y(), and PV3DBase< T, PVType, FrameType >::z().
Referenced by fit().
00403 { 00404 if ( t.empty() ) return TrajectoryStateOnSurface(); 00405 00406 if ( !t.firstMeasurement().updatedState().isValid() || !t.lastMeasurement().updatedState().isValid() ) return TrajectoryStateOnSurface(); 00407 00408 TrajectoryStateOnSurface result; 00409 00410 bool beamhaloFlag = ( t.firstMeasurement().updatedState().globalMomentum().eta() > 4.0 || t.lastMeasurement().updatedState().globalMomentum().eta() > 4.0 ); 00411 00412 if ( !beamhaloFlag ) { //initialState is the top one 00413 if (t.firstMeasurement().updatedState().globalPosition().y() > t.lastMeasurement().updatedState().globalPosition().y()) { 00414 result = t.firstMeasurement().updatedState(); 00415 } else { 00416 result = t.lastMeasurement().updatedState(); 00417 } 00418 if (result.globalMomentum().y()> 1.0 ) //top tsos should pointing down 00419 theUtilities->reverseDirection(result,&*theService->magneticField()); 00420 } else { 00421 if ( t.firstMeasurement().updatedState().globalPosition().z() * t.lastMeasurement().updatedState().globalPosition().z() >0 ) { //same side 00422 if ( fabs(t.firstMeasurement().updatedState().globalPosition().z()) > fabs(t.lastMeasurement().updatedState().globalPosition().z()) ) { 00423 result = t.firstMeasurement().updatedState(); 00424 } else { 00425 result = t.lastMeasurement().updatedState(); 00426 } 00427 } else { //different sides 00428 00429 if ( fabs(t.firstMeasurement().updatedState().globalPosition().eta()) > fabs(t.lastMeasurement().updatedState().globalPosition().eta()) ) { 00430 result = t.firstMeasurement().updatedState(); 00431 } else { 00432 result = t.lastMeasurement().updatedState(); 00433 } 00434 } 00435 00436 } 00437 00438 return result; 00439 00440 }
const Propagator* CosmicMuonSmoother::propagatorAlong | ( | ) | const [inline] |
Definition at line 56 of file CosmicMuonSmoother.h.
References thePropagatorAlongName, and theService.
Referenced by fit().
00056 {return &*theService->propagator(thePropagatorAlongName);}
const Propagator* CosmicMuonSmoother::propagatorOpposite | ( | ) | const [inline] |
Definition at line 58 of file CosmicMuonSmoother.h.
References thePropagatorOppositeName, and theService.
Referenced by smooth().
00058 {return &*theService->propagator(thePropagatorOppositeName);}
vector< Trajectory > CosmicMuonSmoother::smooth | ( | const Trajectory & | t | ) | const [private] |
Definition at line 255 of file CosmicMuonSmoother.cc.
References category_, Trajectory::empty(), Chi2MeasurementEstimator::estimate(), TrajectoryStateOnSurface::globalMomentum(), TrajectoryStateOnSurface::globalPosition(), TrajectoryStateOnSurface::isValid(), LogTrace, Trajectory::measurements(), oppositeToMomentum, Propagator::propagate(), propagatorOpposite(), TrajectoryStateOnSurface::rescaleError(), Trajectory::seed(), CosmicMuonUtilities::stepPropagate(), TrajectoryStateOnSurface::surface(), theErrorRescaling, theEstimator, theUpdator, theUtilities, and KFUpdator::update().
00255 { 00256 00257 if ( t.empty() ) { 00258 LogTrace(category_)<< "Error: smooth: empty trajectory."; 00259 return vector<Trajectory>(); 00260 } 00261 00262 Trajectory myTraj(t.seed(), oppositeToMomentum); 00263 00264 vector<TrajectoryMeasurement> avtm = t.measurements(); 00265 00266 if ( avtm.size() < 2 ) { 00267 LogTrace(category_)<< "Error: smooth: too little TM. "; 00268 return vector<Trajectory>(); 00269 } 00270 00271 TrajectoryStateOnSurface predTsos = avtm.back().forwardPredictedState(); 00272 predTsos.rescaleError(theErrorRescaling); 00273 00274 if ( !predTsos.isValid() ) { 00275 LogTrace(category_)<< "Error: smooth: first TSOS from back invalid. "; 00276 return vector<Trajectory>(); 00277 } 00278 00279 TrajectoryStateOnSurface currTsos; 00280 00281 // first smoothed TrajectoryMeasurement is last fitted 00282 if ( avtm.back().recHit()->isValid() ) { 00283 currTsos = theUpdator->update(predTsos, (*avtm.back().recHit())); 00284 myTraj.push(TrajectoryMeasurement(avtm.back().forwardPredictedState(), 00285 predTsos, 00286 avtm.back().updatedState(), 00287 avtm.back().recHit(), 00288 avtm.back().estimate()//, 00289 /*avtm.back().layer()*/), 00290 avtm.back().estimate()); 00291 00292 } else { 00293 currTsos = predTsos; 00294 myTraj.push(TrajectoryMeasurement(avtm.back().forwardPredictedState(), 00295 avtm.back().recHit()//, 00296 /*avtm.back().layer()*/)); 00297 00298 } 00299 00300 TrajectoryStateCombiner combiner; 00301 00302 00303 for ( vector<TrajectoryMeasurement>::reverse_iterator itm = avtm.rbegin() + 1; 00304 itm != avtm.rend() - 1; ++itm ) { 00305 00306 if (currTsos.isValid()) { 00307 LogTrace(category_)<<"current pos "<<currTsos.globalPosition() 00308 <<"mom "<<currTsos.globalMomentum(); 00309 } else { 00310 LogTrace(category_)<<"current state invalid"; 00311 } 00312 00313 predTsos = propagatorOpposite()->propagate(currTsos,(*itm).recHit()->det()->surface()); 00314 00315 if ( !predTsos.isValid() ) { 00316 LogTrace(category_)<<"step-propagating from "<<currTsos.globalPosition() <<" to position: "<<(*itm).recHit()->globalPosition(); 00317 predTsos = theUtilities->stepPropagate(currTsos, (*itm).recHit(), *propagatorOpposite()); 00318 } 00319 if (predTsos.isValid()) { 00320 LogTrace(category_)<<"predicted pos "<<predTsos.globalPosition() 00321 <<"mom "<<predTsos.globalMomentum(); 00322 } else { 00323 LogTrace(category_)<<"predicted state invalid"; 00324 } 00325 00326 if ( !predTsos.isValid() ) { 00327 LogTrace(category_)<< "Error: predTsos is still invalid backward smooth."; 00328 return vector<Trajectory>(); 00329 // continue; 00330 } else if ( (*itm).recHit()->isValid() ) { 00331 //update 00332 currTsos = theUpdator->update(predTsos, (*(*itm).recHit())); 00333 TrajectoryStateOnSurface combTsos = combiner(predTsos, (*itm).forwardPredictedState()); 00334 if ( !combTsos.isValid() ) { 00335 LogTrace(category_)<< "Error: smooth: combining pred TSOS failed. "; 00336 return vector<Trajectory>(); 00337 } 00338 00339 TrajectoryStateOnSurface smooTsos = combiner((*itm).updatedState(), predTsos); 00340 00341 if ( !smooTsos.isValid() ) { 00342 LogTrace(category_)<< "Error: smooth: combining smooth TSOS failed. "; 00343 return vector<Trajectory>(); 00344 } 00345 00346 myTraj.push(TrajectoryMeasurement((*itm).forwardPredictedState(), 00347 predTsos, 00348 smooTsos, 00349 (*itm).recHit(), 00350 theEstimator->estimate(combTsos, (*(*itm).recHit())).second//, 00351 /*(*itm).layer()*/), 00352 (*itm).estimate()); 00353 } else { 00354 currTsos = predTsos; 00355 TrajectoryStateOnSurface combTsos = combiner(predTsos, (*itm).forwardPredictedState()); 00356 00357 if ( !combTsos.isValid() ) { 00358 LogTrace(category_)<< "Error: smooth: combining TSOS failed. "; 00359 return vector<Trajectory>(); 00360 } 00361 00362 myTraj.push(TrajectoryMeasurement((*itm).forwardPredictedState(), 00363 predTsos, 00364 combTsos, 00365 (*itm).recHit()//, 00366 /*(*itm).layer()*/)); 00367 } 00368 } 00369 00370 // last smoothed TrajectoryMeasurement is last filtered 00371 predTsos = propagatorOpposite()->propagate(currTsos, avtm.front().recHit()->det()->surface()); 00372 00373 if ( !predTsos.isValid() ){ 00374 LogTrace(category_)<< "Error: last predict TSOS failed, use original one. "; 00375 // return vector<Trajectory>(); 00376 myTraj.push(TrajectoryMeasurement(avtm.front().forwardPredictedState(), 00377 avtm.front().recHit())); 00378 } else { 00379 if ( avtm.front().recHit()->isValid() ) { 00380 //update 00381 currTsos = theUpdator->update(predTsos, (*avtm.front().recHit())); 00382 if (currTsos.isValid()) 00383 myTraj.push(TrajectoryMeasurement(avtm.front().forwardPredictedState(), 00384 predTsos, 00385 currTsos, 00386 avtm.front().recHit(), 00387 theEstimator->estimate(predTsos, (*avtm.front().recHit())).second//, 00388 /*avtm.front().layer()*/), 00389 avtm.front().estimate()); 00390 } 00391 } 00392 LogTrace(category_)<< "myTraj foundHits. "<<myTraj.foundHits(); 00393 00394 if (myTraj.foundHits() >= 3) 00395 return vector<Trajectory>(1, myTraj); 00396 else { 00397 LogTrace(category_)<< "Error: smooth: No enough hits in trajctory. "; 00398 return vector<Trajectory>(); 00399 } 00400 00401 }
std::vector<Trajectory> CosmicMuonSmoother::smooth | ( | const std::vector< Trajectory > & | ) | const [private] |
Referenced by trajectories().
void CosmicMuonSmoother::sortHitsAlongMom | ( | ConstRecHitContainer & | hits, | |
const TrajectoryStateOnSurface & | tsos | |||
) | const [private] |
Definition at line 442 of file CosmicMuonSmoother.cc.
References TrajectoryStateOnSurface::globalPosition(), and muonGeometry::mag().
Referenced by fit().
00442 { 00443 00444 if (hits.size() < 2) return; 00445 float dis1 = (hits.front()->globalPosition() - tsos.globalPosition()).mag(); 00446 float dis2 = (hits.back()->globalPosition() - tsos.globalPosition()).mag(); 00447 00448 if ( dis1 > dis2 ) 00449 std::reverse(hits.begin(),hits.end()); 00450 00451 return; 00452 }
vector< Trajectory > CosmicMuonSmoother::trajectories | ( | const TrajectorySeed & | seed, | |
const ConstRecHitContainer & | hits, | |||
const TrajectoryStateOnSurface & | firstPredTsos | |||
) | const [virtual] |
refit trajectory
Definition at line 70 of file CosmicMuonSmoother.cc.
References category_, fit(), TrajectoryStateOnSurface::isValid(), LogTrace, TrajectoryStateOnSurface::rescaleError(), smooth(), and theErrorRescaling.
00072 { 00073 00074 if ( hits.empty() ||!firstPredTsos.isValid() ) return vector<Trajectory>(); 00075 00076 LogTrace(category_)<< "trajectory begin (seed hits tsos)"; 00077 00078 TrajectoryStateOnSurface firstTsos = firstPredTsos; 00079 firstTsos.rescaleError(theErrorRescaling); 00080 00081 LogTrace(category_)<< "first TSOS: "<<firstTsos; 00082 00083 vector<Trajectory> fitted = fit(seed, hits, firstTsos); 00084 LogTrace(category_)<< "fitted: "<<fitted.size(); 00085 vector<Trajectory> smoothed = smooth(fitted); 00086 LogTrace(category_)<< "smoothed: "<<smoothed.size(); 00087 00088 return smoothed; 00089 00090 }
vector< Trajectory > CosmicMuonSmoother::trajectories | ( | const Trajectory & | t | ) | const [virtual] |
Implements TrajectorySmoother.
Definition at line 61 of file CosmicMuonSmoother.cc.
References fit(), and smooth().
Referenced by CosmicMuonTrajectoryBuilder::estimateDirection(), GlobalCosmicMuonTrajectoryBuilder::trajectories(), and CosmicMuonTrajectoryBuilder::trajectories().
KFUpdator* CosmicMuonSmoother::updator | ( | ) | const [inline] |
Definition at line 60 of file CosmicMuonSmoother.h.
References theUpdator.
00060 {return theUpdator;}
CosmicMuonUtilities* CosmicMuonSmoother::utilities | ( | ) | const [inline] |
Definition at line 62 of file CosmicMuonSmoother.h.
References theUtilities.
Referenced by CosmicMuonTrajectoryBuilder::utilities(), and GlobalCosmicMuonTrajectoryBuilder::utilities().
00062 {return theUtilities; }
std::string CosmicMuonSmoother::category_ [private] |
Definition at line 88 of file CosmicMuonSmoother.h.
Referenced by CosmicMuonSmoother(), fit(), smooth(), and trajectories().
double CosmicMuonSmoother::theErrorRescaling [private] |
Definition at line 87 of file CosmicMuonSmoother.h.
Referenced by CosmicMuonSmoother(), smooth(), and trajectories().
Definition at line 80 of file CosmicMuonSmoother.h.
Referenced by CosmicMuonSmoother(), estimator(), fit(), smooth(), and ~CosmicMuonSmoother().
std::string CosmicMuonSmoother::thePropagatorAlongName [private] |
Definition at line 85 of file CosmicMuonSmoother.h.
Referenced by CosmicMuonSmoother(), and propagatorAlong().
std::string CosmicMuonSmoother::thePropagatorOppositeName [private] |
Definition at line 86 of file CosmicMuonSmoother.h.
Referenced by CosmicMuonSmoother(), and propagatorOpposite().
const MuonServiceProxy* CosmicMuonSmoother::theService [private] |
Definition at line 83 of file CosmicMuonSmoother.h.
Referenced by fit(), initialState(), propagatorAlong(), and propagatorOpposite().
KFUpdator* CosmicMuonSmoother::theUpdator [private] |
Definition at line 79 of file CosmicMuonSmoother.h.
Referenced by CosmicMuonSmoother(), fit(), smooth(), updator(), and ~CosmicMuonSmoother().
Definition at line 81 of file CosmicMuonSmoother.h.
Referenced by CosmicMuonSmoother(), fit(), initialState(), smooth(), utilities(), and ~CosmicMuonSmoother().