CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/TrackingTools/TrackFitters/src/KFTrajectoryFitter.cc

Go to the documentation of this file.
00001 #include "TrackingTools/TrackFitters/interface/KFTrajectoryFitter.h"
00002 #include "TrackingTools/TrackFitters/interface/TrajectoryStateWithArbitraryError.h"
00003 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00007 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00008 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00009 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00010 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00011 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00012 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00013 #include "DataFormats/MuonDetId/interface/DTWireId.h"
00014 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00015 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00016 
00017 
00018 const DetLayerGeometry KFTrajectoryFitter::dummyGeometry;
00019 
00020 std::vector<Trajectory> KFTrajectoryFitter::fit(const Trajectory& aTraj) const {
00021 
00022   if(aTraj.empty()) return std::vector<Trajectory>();
00023  
00024   TM firstTM = aTraj.firstMeasurement();
00025   TSOS firstTsos = TrajectoryStateWithArbitraryError()(firstTM.updatedState());
00026   
00027   return fit(aTraj.seed(), aTraj.recHits(), firstTsos);
00028 }
00029 
00030 std::vector<Trajectory> KFTrajectoryFitter::fit(const TrajectorySeed& aSeed,
00031                                                 const RecHitContainer& hits) const{
00032 
00033   throw cms::Exception("TrackFitters", 
00034                        "KFTrajectoryFitter::fit(TrajectorySeed, <TransientTrackingRecHit>) not implemented"); 
00035 
00036   return std::vector<Trajectory>();
00037 }
00038 
00039 std::vector<Trajectory> KFTrajectoryFitter::fit(const TrajectorySeed& aSeed,
00040                                                 const RecHitContainer& hits,
00041                                                 const TSOS& firstPredTsos) const 
00042 {
00043   if(hits.empty()) return std::vector<Trajectory>();
00044 
00045 
00046   if (aSeed.direction() == anyDirection) 
00047     throw cms::Exception("KFTrajectoryFitter","TrajectorySeed::direction() requested but not set");
00048   
00049   SetPropagationDirection setDir(*thePropagator,aSeed.direction());
00050 
00051 #ifdef EDM_LM_DEBUG
00052   LogDebug("TrackFitters")
00053     <<" +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
00054     <<" KFTrajectoryFitter::fit starting with " << hits.size() <<" HITS";
00055   
00056   for (unsigned int j=0;j<hits.size();j++) { 
00057     if (hits[j]->det()) 
00058       LogTrace("TrackFitters") << "hit #:" << j+1 << " rawId=" << hits[j]->det()->geographicalId().rawId() 
00059                                << " validity=" << hits[j]->isValid();
00060     else
00061       LogTrace("TrackFitters") << "hit #:" << j+1 << " Hit with no Det information";
00062   }
00063   LogTrace("TrackFitters") << " INITIAL STATE "<< firstPredTsos;
00064 #endif
00065 
00066   std::vector<Trajectory> ret(1, Trajectory(aSeed, thePropagator->propagationDirection()));
00067   Trajectory & myTraj = ret.front();
00068   myTraj.reserve(hits.size());
00069 
00070   TSOS predTsos(firstPredTsos);
00071   TSOS currTsos;
00072 
00073   int hitcounter = 1;
00074   for(RecHitContainer::const_iterator ihit = hits.begin(); ihit != hits.end(); ++ihit, ++hitcounter) {
00075 
00076     const TransientTrackingRecHit & hit = (**ihit);
00077 
00078     if (hit.isValid() == false && hit.surface() == 0) {
00079       LogDebug("TrackFitters")<< " Error: invalid hit with no GeomDet attached .... skipping";
00080       continue;
00081     }
00082 
00083 #ifdef EDM_LM_DEBUG
00084     if (hit.isValid()) {
00085       LogTrace("TrackFitters")
00086         << " ----------------- HIT #" << hitcounter << " (VALID)-----------------------\n"
00087         << "  HIT IS AT R   " << hit.globalPosition().perp() << "\n"
00088         << "  HIT IS AT Z   " << hit.globalPosition().z() << "\n"
00089         << "  HIT IS AT Phi " << hit.globalPosition().phi() << "\n"
00090         << "  HIT IS AT Loc " << hit.localPosition() << "\n"
00091         << "  WITH LocError " << hit.localPositionError() << "\n"
00092         << "  HIT IS AT Glo " << hit.globalPosition() << "\n"
00093         << "SURFACE POSITION" << "\n"
00094         << hit.surface()->position()<<"\n"
00095         << "SURFACE ROTATION" << "\n"
00096         << hit.surface()->rotation();
00097       
00098       DetId hitId = hit.geographicalId();
00099 
00100       LogTrace("TrackFitters") << " hit det=" << hitId.rawId();
00101       
00102       if(hitId.det() == DetId::Tracker) {
00103         if (hitId.subdetId() == StripSubdetector::TIB )  
00104           LogTrace("TrackFitters") << " I am TIB " << TIBDetId(hitId).layer();
00105         else if (hitId.subdetId() == StripSubdetector::TOB ) 
00106           LogTrace("TrackFitters") << " I am TOB " << TOBDetId(hitId).layer();
00107         else if (hitId.subdetId() == StripSubdetector::TEC ) 
00108           LogTrace("TrackFitters") << " I am TEC " << TECDetId(hitId).wheel();
00109         else if (hitId.subdetId() == StripSubdetector::TID ) 
00110           LogTrace("TrackFitters") << " I am TID " << TIDDetId(hitId).wheel();
00111         else if (hitId.subdetId() == StripSubdetector::TID ) 
00112           LogTrace("TrackFitters") << " I am TID " << TIDDetId(hitId).wheel();
00113         else if (hitId.subdetId() == (int) PixelSubdetector::PixelBarrel ) 
00114           LogTrace("TrackFitters") << " I am PixBar " << PXBDetId(hitId).layer();
00115         else if (hitId.subdetId() == (int) PixelSubdetector::PixelEndcap )
00116           LogTrace("TrackFitters") << " I am PixFwd " << PXFDetId(hitId).disk();
00117         else 
00118           LogTrace("TrackFitters") << " UNKNOWN TRACKER HIT TYPE ";
00119       }
00120       else if(hitId.det() == DetId::Muon) {
00121         if(hitId.subdetId() == MuonSubdetId::DT)
00122           LogTrace("TrackFitters") << " I am DT " << DTWireId(hitId);
00123         else if (hitId.subdetId() == MuonSubdetId::CSC )
00124           LogTrace("TrackFitters") << " I am CSC " << CSCDetId(hitId);
00125         else if (hitId.subdetId() == MuonSubdetId::RPC )
00126           LogTrace("TrackFitters") << " I am RPC " << RPCDetId(hitId);
00127         else 
00128           LogTrace("TrackFitters") << " UNKNOWN MUON HIT TYPE ";
00129       }
00130       else
00131         LogTrace("TrackFitters") << " UNKNOWN HIT TYPE ";
00132       
00133     } else {
00134       LogTrace("TrackFitters")
00135         << " ----------------- INVALID HIT #" << hitcounter << " -----------------------";      
00136     }
00137 #endif    
00138 
00139     if ( hitcounter != 1) //no propagation needed for the first hit
00140       predTsos = thePropagator->propagate( currTsos, *(hit.surface()) );
00141     
00142 
00143     if(!predTsos.isValid()) {
00144       LogDebug("TrackFitters") 
00145         << "SOMETHING WRONG !" << "\n"
00146         << "KFTrajectoryFitter: predicted tsos not valid!\n" 
00147         << "current TSOS: " << currTsos << "\n";
00148 
00149       if(hit.surface()) LogTrace("TrackFitters") << "next Surface: " << hit.surface()->position() << "\n";
00150 
00151       if( myTraj.foundHits() >= minHits_ ) {
00152         LogDebug("TrackFitters") << " breaking trajectory" << "\n";
00153         break;      
00154       } else {        
00155         LogDebug("TrackFitters") << " killing trajectory" << "\n";       
00156         return std::vector<Trajectory>();
00157       }
00158     }
00159     
00160     if(hit.isValid()) {
00161       //update
00162       LogTrace("TrackFitters") << "THE HIT IS VALID: updating hit with predTsos";
00163       TransientTrackingRecHit::RecHitPointer preciseHit = hit.clone(predTsos);
00164 
00165       if (preciseHit->isValid() == false){
00166         LogTrace("TrackFitters") << "THE Precise HIT IS NOT VALID: using currTsos = predTsos" << "\n";
00167         currTsos = predTsos;
00168         myTraj.push(TM(predTsos, *ihit,0,theGeometry->idToLayer((*ihit)->geographicalId()) ));
00169 
00170       }else{
00171         LogTrace("TrackFitters") << "THE Precise HIT IS VALID: updating currTsos" << "\n";
00172         currTsos = updator()->update(predTsos, *preciseHit);
00173         //check for valid hits with no det (refitter with constraints)
00174         if (!currTsos.isValid()){
00175           edm::LogError("FailedUpdate")<<"updating with the hit failed. Not updating the trajectory with the hit";
00176           myTraj.push(TM(predTsos, *ihit,0,theGeometry->idToLayer((*ihit)->geographicalId())  ));
00177           //There is a no-fail policy here. So, it's time to give up
00178           //Keep the traj with invalid TSOS so that it's clear what happened
00179           if( myTraj.foundHits() >= minHits_ ) {
00180             LogDebug("TrackFitters") << " breaking trajectory" << "\n";
00181             break;      
00182           } else {        
00183             LogDebug("TrackFitters") << " killing trajectory" << "\n";       
00184             return std::vector<Trajectory>();
00185           }
00186         }
00187         else{
00188           if (preciseHit->det()) myTraj.push(TM(predTsos, currTsos, preciseHit,
00189                                                 estimator()->estimate(predTsos, *preciseHit).second,
00190                                                 theGeometry->idToLayer(preciseHit->geographicalId())  ));
00191           else myTraj.push(TM(predTsos, currTsos, preciseHit,
00192                               estimator()->estimate(predTsos, *preciseHit).second));
00193         }
00194       }
00195     } else {
00196       //no update
00197       LogDebug("TrackFitters") << "THE HIT IS NOT VALID: using currTsos" << "\n";
00198       currTsos = predTsos;
00199       myTraj.push(TM(predTsos, *ihit,0,theGeometry->idToLayer((*ihit)->geographicalId())  ));
00200     }
00201 
00202     LogTrace("TrackFitters")
00203       << "predTsos !" << "\n"
00204       << predTsos << "\n"
00205       <<"currTsos !" << "\n"
00206       << currTsos;
00207   }  
00208 
00209   LogDebug("TrackFitters") << "Found 1 trajectory with " << myTraj.foundHits() << " valid hits\n";
00210   
00211   return ret;
00212 }
00213