CMS 3D CMS Logo

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