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
00061 else if (lost( *(tm.recHit()) ) ) theNumberOfLostHits++;
00062
00063
00064 theChiSquared += chi2Increment;
00065
00066
00067
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();
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
00115
00116
00117
00118
00119
00120
00121
00122
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
00142
00143
00144
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