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