CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/TrackingTools/PatternTools/src/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( traj.sharedSeed() ){
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 TempTrajectory::~TempTrajectory() {
00024 }
00025 
00026 void TempTrajectory::pop() { 
00027   if (!empty()) {
00028     if (theData.back().recHit()->isValid())             theNumberOfFoundHits--;
00029     else if(lost(* (theData.back().recHit()) )) theNumberOfLostHits--;
00030     theData.pop_back();
00031   }
00032 }
00033 
00034 void TempTrajectory::push( const TrajectoryMeasurement& tm) {
00035   push( tm, tm.estimate());
00036 }
00037 
00038 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
00039 void TempTrajectory::push( TrajectoryMeasurement&& tm) {
00040   push( std::forward<TrajectoryMeasurement>(tm), tm.estimate());
00041 }
00042 #endif
00043 
00044 void TempTrajectory::push( const TrajectoryMeasurement& tm, double chi2Increment){
00045   pushAux(tm,chi2Increment);
00046   theData.push_back(tm);
00047 }
00048 
00049 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
00050 void TempTrajectory::push(TrajectoryMeasurement&& tm, double chi2Increment){
00051   pushAux(tm,chi2Increment);
00052   theData.push_back(std::move(tm));
00053 }
00054 #endif
00055 
00056 void TempTrajectory::pushAux( const TrajectoryMeasurement& tm, double chi2Increment)
00057 {
00058   if ( tm.recHit()->isValid()) {
00059     theNumberOfFoundHits++;
00060    }
00061   //else if (lost( tm.recHit()) && !inactive(tm.recHit().det())) theNumberOfLostHits++;
00062   else if (lost( *(tm.recHit()) ) )   theNumberOfLostHits++;
00063   
00064  
00065   theChiSquared += chi2Increment;
00066 
00067   // in case of a Trajectory constructed without direction, 
00068   // determine direction from the radii of the first two measurements
00069 
00070   if ( !theDirectionValidity && theData.size() >= 2) {
00071     if (theData.front().updatedState().globalPosition().perp() <
00072         theData.back().updatedState().globalPosition().perp())
00073       theDirection = alongMomentum;
00074     else theDirection = oppositeToMomentum;
00075     theDirectionValidity = true;
00076   }
00077 }
00078 
00079 void TempTrajectory::push( const TempTrajectory& segment) {
00080   assert (segment.direction() == theDirection) ;
00081     __gnu_cxx::slist<const TrajectoryMeasurement*> list;
00082   for (DataContainer::const_iterator it = segment.measurements().rbegin(), ed = segment.measurements().rend(); it != ed; --it) {
00083         list.push_front(&(*it));
00084   }
00085   for(__gnu_cxx::slist<const TrajectoryMeasurement*>::const_iterator it = list.begin(), ed = list.end(); it != ed; ++it) {
00086         push(**it);
00087   }
00088 }
00089 
00090 void TempTrajectory::join( TempTrajectory& segment) {
00091   assert (segment.direction() == theDirection) ;
00092   if (segment.theData.shared()) {
00093       push(segment);
00094       segment.theData.clear(); // obey the contract, and increase the chances it will be not shared one day
00095   } else {
00096       for (DataContainer::const_iterator it = segment.measurements().rbegin(), ed = segment.measurements().rend(); it != ed; --it) {
00097           if ( it->recHit()->isValid())       theNumberOfFoundHits++;
00098           else if (lost( *(it->recHit()) ) ) theNumberOfLostHits++;
00099           theChiSquared += it->estimate();
00100       }
00101       theData.join(segment.theData);
00102 
00103       if ( !theDirectionValidity && theData.size() >= 2) {
00104         if (theData.front().updatedState().globalPosition().perp() <
00105             theData.back().updatedState().globalPosition().perp())
00106           theDirection = alongMomentum;
00107         else theDirection = oppositeToMomentum;
00108         theDirectionValidity = true;
00109       }
00110   }
00111 }
00112 
00113 
00114 /*
00115 Trajectory::RecHitContainer Trajectory::recHits() const {
00116   RecHitContainer hits;
00117   hits.reserve(theData.size());
00118 
00119   for (Trajectory::DataContainer::const_iterator itm
00120          = theData.begin(); itm != theData.end(); itm++) {
00121     hits.push_back((*itm).recHit());
00122   }
00123   return hits;
00124 }
00125 
00126 */
00127 
00128 PropagationDirection TempTrajectory::direction() const {
00129   if (theDirectionValidity) return theDirection;
00130   else throw cms::Exception("TrackingTools/PatternTools","Trajectory::direction() requested but not set");
00131 }
00132 
00133 void TempTrajectory::check() const {
00134   if ( theData.size() == 0) 
00135     throw cms::Exception("TrackingTools/PatternTools","Trajectory::check() - information requested from empty Trajectory");
00136 }
00137 
00138 bool TempTrajectory::lost( const TransientTrackingRecHit& hit)
00139 {
00140   if ( hit.isValid()) return false;
00141   else {
00142   //     // A DetLayer is always inactive in this logic.
00143   //     // The DetLayer is the Det of an invalid RecHit only if no DetUnit 
00144   //     // is compatible with the predicted state, so we don't really expect
00145   //     // a hit in this case.
00146   
00147     if(hit.geographicalId().rawId() == 0) {return false;}
00148     else{
00149       return hit.getType() == TrackingRecHit::missing;
00150     }
00151   }
00152 }
00153 
00154 Trajectory TempTrajectory::toTrajectory() const {
00155   Trajectory traj(theSeed, theDirection);
00156 
00157   traj.reserve(theData.size());
00158   static std::vector<const TrajectoryMeasurement*> work;
00159   work.resize(theData.size(), 0);
00160   std::vector<const TrajectoryMeasurement*>::iterator workend = work.end(), itwork = workend;
00161   for (TempTrajectory::DataContainer::const_iterator it = theData.rbegin(), ed = theData.rend(); it != ed; --it) {
00162        --itwork;  *itwork = (&(*it));
00163   }
00164   for (; itwork != workend; ++itwork) {
00165         traj.push(**itwork);
00166   }
00167   return traj;
00168 }
00169