CMS 3D CMS Logo

TempTrajectory.cc

Go to the documentation of this file.
00001 #include "TrackingTools/PatternTools/interface/TempTrajectory.h"
00002 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 
00005 #include <ext/slist>
00006 
00007 TempTrajectory::TempTrajectory( const Trajectory& traj):
00008   theChiSquared(0), theValid(traj.isValid()),
00009   theNumberOfFoundHits(0), theNumberOfLostHits(0),
00010   theDirection(traj.direction()), theDirectionValidity(true),
00011   theSeed( new TrajectorySeed(traj.seed()) ){
00012 
00013   Trajectory::DataContainer::const_iterator begin=traj.measurements().begin();
00014   Trajectory::DataContainer::const_iterator end=traj.measurements().end();
00015 
00016   for(Trajectory::DataContainer::const_iterator it=begin; it!=end; ++it){
00017     push(*it);
00018   }
00019 
00020 
00021 }
00022 
00023 void TempTrajectory::pop() { 
00024   if (!empty()) {
00025     if (theData.back().recHit()->isValid())             theNumberOfFoundHits--;
00026     else if(lost(* (theData.back().recHit()) )) theNumberOfLostHits--;
00027     theData.pop_back();
00028   }
00029 }
00030 
00031 // bool Trajectory::inactive( const Det& det) 
00032 // {
00033 //   typedef Det::DetUnitContainer DUC;
00034 
00035 //   // DetUnit case -- straightforward
00036 //   const DetUnit* detu = dynamic_cast<const DetUnit*>(&det);
00037 //   if (detu != 0) return detu->inactive();
00038 //   else {
00039 //     const DetLayer* detl = dynamic_cast<const DetLayer*>(&det);
00040 //     if (detl != 0) return false; // DetLayer should have inactive() too,
00041 //                               // but for the moment we skip it (see below)
00042 //     else { // composite case
00043 //       DUC duc = det.detUnits();
00044 //       for (DUC::const_iterator i=duc.begin(); i!=duc.end(); i++) {
00045 //      if ( !(**i).inactive()) return false;
00046 //       }
00047 //       return true;
00048 //     }
00049 //   }
00050 //   // the loop over DetUnits works for all 
00051 //   // Dets, but it would be too slow for a big DetLayer; it would
00052 //   // require creatind and copying the vector of all DetUnit* each time
00053 //   // an invalid RecHit is produced by the layer, so it is penalizing
00054 //   // even for active layers.
00055 //   // Therefore the layer is not handled yet, and should eventually have
00056 //   // it's own inactive() method.
00057 // }
00058   
00059 void TempTrajectory::push( const TrajectoryMeasurement& tm) {
00060   push( tm, tm.estimate());
00061 }
00062 
00063 void TempTrajectory::push( const TrajectoryMeasurement& tm, double chi2Increment)
00064 {
00065   theData.push_back(tm);
00066   if ( tm.recHit()->isValid()) {
00067     theNumberOfFoundHits++;
00068    }
00069   //else if (lost( tm.recHit()) && !inactive(tm.recHit().det())) theNumberOfLostHits++;
00070   else if (lost( *(tm.recHit()) ) )   theNumberOfLostHits++;
00071   
00072  
00073   theChiSquared += chi2Increment;
00074 
00075   // in case of a Trajectory constructed without direction, 
00076   // determine direction from the radii of the first two measurements
00077 
00078   if ( !theDirectionValidity && theData.size() >= 2) {
00079     if (theData.front().updatedState().globalPosition().perp() <
00080         theData.back().updatedState().globalPosition().perp())
00081       theDirection = alongMomentum;
00082     else theDirection = oppositeToMomentum;
00083     theDirectionValidity = true;
00084   }
00085 }
00086 
00087 void TempTrajectory::push( const TempTrajectory& segment) {
00088   assert (segment.direction() == theDirection) ;
00089     __gnu_cxx::slist<const TrajectoryMeasurement*> list;
00090   for (DataContainer::const_iterator it = segment.measurements().rbegin(), ed = segment.measurements().rend(); it != ed; --it) {
00091         list.push_front(&(*it));
00092   }
00093   for(__gnu_cxx::slist<const TrajectoryMeasurement*>::const_iterator it = list.begin(), ed = list.end(); it != ed; ++it) {
00094         push(**it);
00095   }
00096 }
00097 
00098 
00099 /*
00100 Trajectory::RecHitContainer Trajectory::recHits() const {
00101   RecHitContainer hits;
00102   hits.reserve(theData.size());
00103 
00104   for (Trajectory::DataContainer::const_iterator itm
00105          = theData.begin(); itm != theData.end(); itm++) {
00106     hits.push_back((*itm).recHit());
00107   }
00108   return hits;
00109 }
00110 
00111 */
00112 
00113 PropagationDirection TempTrajectory::direction() const {
00114   if (theDirectionValidity) return theDirection;
00115   else throw cms::Exception("TrackingTools/PatternTools","Trajectory::direction() requested but not set");
00116 }
00117 
00118 void TempTrajectory::check() const {
00119   if ( theData.size() == 0) 
00120     throw cms::Exception("TrackingTools/PatternTools","Trajectory::check() - information requested from empty Trajectory");
00121 }
00122 
00123 bool TempTrajectory::lost( const TransientTrackingRecHit& hit)
00124 {
00125   if ( hit.isValid()) return false;
00126   else {
00127   //     // A DetLayer is always inactive in this logic.
00128   //     // The DetLayer is the Det of an invalid RecHit only if no DetUnit 
00129   //     // is compatible with the predicted state, so we don't really expect
00130   //     // a hit in this case.
00131   
00132     if(hit.geographicalId().rawId() == 0) {return false;}
00133     else{
00134       return hit.getType() == TrackingRecHit::missing;
00135     }
00136   }
00137 }
00138 
00139 Trajectory TempTrajectory::toTrajectory() const {
00140   Trajectory traj(*theSeed, theDirection);
00141 
00142   traj.reserve(theData.size());
00143   __gnu_cxx::slist<const TrajectoryMeasurement*> list;
00144   for (TempTrajectory::DataContainer::const_iterator it = theData.rbegin(), ed = theData.rend(); it != ed; --it) {
00145         list.push_front(&(*it));
00146   }
00147   for(__gnu_cxx::slist<const TrajectoryMeasurement*>::const_iterator it = list.begin(), ed = list.end(); it != ed; ++it) {
00148         traj.push(**it);
00149   }
00150   return traj;
00151 }
00152 

Generated on Tue Jun 9 17:48:25 2009 for CMSSW by  doxygen 1.5.4