00001 #ifndef CommonDet_Trajectory_H
00002 #define CommonDet_Trajectory_H
00003
00004 #include "DataFormats/Common/interface/RefToBase.h"
00005 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00006 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
00007 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00008 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010
00011 #include <vector>
00012 #include <algorithm>
00013 #include <boost/shared_ptr.hpp>
00014
00038 class Trajectory
00039 {
00040 public:
00041
00042 typedef std::vector<TrajectoryMeasurement> DataContainer;
00043 typedef TransientTrackingRecHit::ConstRecHitContainer ConstRecHitContainer;
00044 typedef ConstRecHitContainer RecHitContainer;
00045
00046
00052 Trajectory() :
00053 theSeed(), seedRef_(),
00054 theChiSquared(0), theChiSquaredBad(0),
00055 theNumberOfFoundHits(0), theNumberOfLostHits(0),
00056 theDirection(alongMomentum), theDirectionValidity(false), theValid(true)
00057 {}
00058
00059
00066 Trajectory( const TrajectorySeed& seed) :
00067 theSeed( new TrajectorySeed(seed) ), seedRef_(),
00068 theChiSquared(0), theChiSquaredBad(0),
00069 theNumberOfFoundHits(0), theNumberOfLostHits(0),
00070 theDirection(alongMomentum), theDirectionValidity(false), theValid(true)
00071 {}
00072
00077 Trajectory( const TrajectorySeed& seed, PropagationDirection dir) :
00078 theSeed( new TrajectorySeed(seed) ), seedRef_(),
00079 theChiSquared(0), theChiSquaredBad(0),
00080 theNumberOfFoundHits(0), theNumberOfLostHits(0),
00081 theDirection(dir), theDirectionValidity(true), theValid(true)
00082
00083 {}
00084
00089 Trajectory( const boost::shared_ptr<const TrajectorySeed> & seed, PropagationDirection dir) :
00090 theSeed( seed ), seedRef_(),
00091 theChiSquared(0), theChiSquaredBad(0),
00092 theNumberOfFoundHits(0), theNumberOfLostHits(0),
00093 theDirection(dir), theDirectionValidity(true), theValid(true)
00094 {}
00095
00096
00097 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
00098 Trajectory(Trajectory const & rh) :
00099 theSeed(rh.theSeed), seedRef_(rh.seedRef_),
00100 theData(rh.theData),
00101 theChiSquared(rh.theChiSquared), theChiSquaredBad(rh.theChiSquaredBad),
00102 theNumberOfFoundHits(rh.theNumberOfFoundHits), theNumberOfLostHits(rh.theNumberOfLostHits),
00103 theDirection(rh.theDirection), theDirectionValidity(rh.theDirectionValidity), theValid(rh.theValid)
00104 {}
00105
00106
00107 Trajectory(Trajectory && rh) :
00108 theSeed(std::move(rh.theSeed)), seedRef_(std::move(rh.seedRef_)),
00109 theData(std::move(rh.theData)),
00110 theChiSquared(rh.theChiSquared), theChiSquaredBad(rh.theChiSquaredBad),
00111 theNumberOfFoundHits(rh.theNumberOfFoundHits), theNumberOfLostHits(rh.theNumberOfLostHits),
00112 theDirection(rh.theDirection), theDirectionValidity(rh.theDirectionValidity), theValid(rh.theValid)
00113 {}
00114
00115 Trajectory & operator=(Trajectory && rh) {
00116 using std::swap;
00117 swap(theData,rh.theData);
00118 theChiSquared=rh.theChiSquared;
00119 theChiSquaredBad=rh.theChiSquaredBad;
00120 theValid=rh.theValid;
00121 theNumberOfFoundHits=rh.theNumberOfFoundHits;
00122 theNumberOfLostHits=rh.theNumberOfLostHits;
00123 theDirection=rh.theDirection;
00124 theDirectionValidity=rh.theDirectionValidity;
00125 swap(theSeed,rh.theSeed);
00126 swap(seedRef_,rh.seedRef_);
00127
00128 return *this;
00129
00130 }
00131
00132 Trajectory & operator=(Trajectory const & rh) {
00133 theData = rh.theData;
00134 theChiSquared=rh.theChiSquared;
00135 theChiSquaredBad=rh.theChiSquaredBad;
00136 theValid=rh.theValid;
00137 theNumberOfFoundHits=rh.theNumberOfFoundHits;
00138 theNumberOfLostHits=rh.theNumberOfLostHits;
00139 theDirection=rh.theDirection;
00140 theDirectionValidity=rh.theDirectionValidity;
00141 theSeed = rh.theSeed;
00142 seedRef_ = rh.seedRef_;
00143
00144 return *this;
00145
00146 }
00147
00148
00149 #endif
00150
00153 void reserve (unsigned int n) { theData.reserve(n); }
00154
00159 void push( const TrajectoryMeasurement& tm);
00160
00164 void push( const TrajectoryMeasurement& tm, double chi2Increment);
00165
00168 void pop();
00169
00175 TrajectoryMeasurement const & lastMeasurement() const {
00176 check();
00177 if (theData.back().recHit()->hit()!=0) return theData.back();
00178 else if (theData.size()>2) return *(theData.end()-2);
00179 else throw cms::Exception("TrajectoryMeasurement::lastMeasurement - Too few measurements in trajectory");
00180 }
00181
00188 TrajectoryMeasurement const & firstMeasurement() const {
00189 check();
00190 if (theData.front().recHit()->hit()!=0) return theData.front();
00191 else if (theData.size()>2) return *(theData.begin()+1);
00192 else throw cms::Exception("TrajectoryMeasurement::firstMeasurement - Too few measurements in trajectory");
00193 }
00194
00197 DataContainer const & measurements() const { return theData;}
00199 DataContainer const & data() const { return measurements();}
00200
00203 ConstRecHitContainer recHits(bool splitting=false) const;
00204
00205 void recHitsV(ConstRecHitContainer & cont,bool splitting = false) const;
00206
00210 void validRecHits(ConstRecHitContainer & cont) const;
00211
00218 int foundHits() const { return theNumberOfFoundHits;}
00219
00225 int lostHits() const { return theNumberOfLostHits;}
00226
00228 bool empty() const { return theData.empty();}
00229
00236 double chiSquared() const { return (theNumberOfFoundHits ? theChiSquared : theChiSquaredBad);}
00237
00241 int ndof(bool bon = true) const;
00242
00243
00248 PropagationDirection const & direction() const;
00249
00253 bool isValid() const { return theValid;}
00254
00256 void invalidate() { theValid = false;}
00257
00259 TrajectorySeed const & seed() const { return *theSeed;}
00260
00261
00264 static bool inactive(
00265 ){return false;}
00266
00270 static bool lost( const TransientTrackingRecHit& hit);
00271
00275 static bool isBad( const TransientTrackingRecHit& hit);
00276
00278 const DetLayer* lastLayer() const {
00279 check();
00280 if (theData.back().recHit()->hit()!=0) return theData.back().layer();
00281 else if (theData.size()>2) return (theData.end()-2)->layer();
00282 else throw cms::Exception("TrajectoryMeasurement::lastMeasurement - Too few measurements in trajectory");
00283 }
00284
00290 edm::RefToBase<TrajectorySeed> seedRef(void) const { return seedRef_; }
00291
00292 void setSeedRef(const edm::RefToBase<TrajectorySeed> & seedRef) { seedRef_ = seedRef ; }
00293
00294 TrajectoryStateOnSurface geometricalInnermostState() const;
00295
00296 TrajectoryMeasurement const & closestMeasurement(GlobalPoint) const;
00297
00300 void reverse() ;
00301
00302 const boost::shared_ptr<const TrajectorySeed> & sharedSeed() const { return theSeed; }
00303 private:
00304
00305 boost::shared_ptr<const TrajectorySeed> theSeed;
00306 edm::RefToBase<TrajectorySeed> seedRef_;
00307
00308 DataContainer theData;
00309 float theChiSquared;
00310 float theChiSquaredBad;
00311
00312 signed short theNumberOfFoundHits;
00313 signed short theNumberOfLostHits;
00314
00315 PropagationDirection theDirection;
00316 bool theDirectionValidity;
00317 bool theValid;
00318
00319 void check() const;
00320 };
00321
00322 #endif