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() : theChiSquared(0), theChiSquaredBad(0), theValid(true),
00053 theNumberOfFoundHits(0), theNumberOfLostHits(0),
00054 theDirection(alongMomentum), theDirectionValidity(false),
00055 theSeed(), seedRef_()
00056 {}
00057
00058
00065 Trajectory( const TrajectorySeed& seed) :
00066 theChiSquared(0), theChiSquaredBad(0), theValid(true),
00067 theNumberOfFoundHits(0), theNumberOfLostHits(0),
00068 theDirection(alongMomentum), theDirectionValidity(false),
00069 theSeed( new TrajectorySeed(seed) ), seedRef_()
00070 {}
00071
00076 Trajectory( const TrajectorySeed& seed, PropagationDirection dir) :
00077 theChiSquared(0), theChiSquaredBad(0), theValid(true),
00078 theNumberOfFoundHits(0), theNumberOfLostHits(0),
00079 theDirection(dir), theDirectionValidity(true),
00080 theSeed( new TrajectorySeed(seed) ), seedRef_()
00081 {}
00082
00087 Trajectory( const boost::shared_ptr<const TrajectorySeed> & seed, PropagationDirection dir) :
00088 theChiSquared(0), theChiSquaredBad(0), theValid(true),
00089 theNumberOfFoundHits(0), theNumberOfLostHits(0),
00090 theDirection(dir), theDirectionValidity(true),
00091 theSeed( seed ), seedRef_()
00092 {}
00093
00094
00095 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
00096 Trajectory(Trajectory && rh) :
00097 theData(std::move(rh.theData)),
00098 theChiSquared(rh.theChiSquared), theChiSquaredBad(rh.theChiSquaredBad), theValid(rh.theValid),
00099 theNumberOfFoundHits(rh.theNumberOfFoundHits), theNumberOfLostHits(rh.theNumberOfLostHits),
00100 theDirection(rh.theDirection), theDirectionValidity(rh.theDirectionValidity),
00101 theSeed(std::move(rh.theSeed)), seedRef_(std::move(rh.seedRef_))
00102 {}
00103
00104 Trajectory & operator=(Trajectory && rh) {
00105 using std::swap;
00106 swap(theData,rh.theData);
00107 theChiSquared=rh.theChiSquared;
00108 theChiSquaredBad=rh.theChiSquaredBad;
00109 theValid=rh.theValid;
00110 theNumberOfFoundHits=rh.theNumberOfFoundHits;
00111 theNumberOfLostHits=rh.theNumberOfLostHits;
00112 theDirection=rh.theDirection;
00113 theDirectionValidity=rh.theDirectionValidity;
00114 swap(theSeed,rh.theSeed);
00115 swap(seedRef_,rh.seedRef_);
00116
00117 return *this;
00118
00119 }
00120
00121 #endif
00122
00125 void reserve (unsigned int n) { theData.reserve(n); }
00126
00131 void push( const TrajectoryMeasurement& tm);
00132
00136 void push( const TrajectoryMeasurement& tm, double chi2Increment);
00137
00140 void pop();
00141
00147 TrajectoryMeasurement const & lastMeasurement() const {
00148 check();
00149 if (theData.back().recHit()->hit()!=0) return theData.back();
00150 else if (theData.size()>2) return *(theData.end()-2);
00151 else throw cms::Exception("TrajectoryMeasurement::lastMeasurement - Too few measurements in trajectory");
00152 }
00153
00160 TrajectoryMeasurement const & firstMeasurement() const {
00161 check();
00162 if (theData.front().recHit()->hit()!=0) return theData.front();
00163 else if (theData.size()>2) return *(theData.begin()+1);
00164 else throw cms::Exception("TrajectoryMeasurement::firstMeasurement - Too few measurements in trajectory");
00165 }
00166
00169 DataContainer const & measurements() const { return theData;}
00171 DataContainer const & data() const { return measurements();}
00172
00175 ConstRecHitContainer recHits(bool splitting=false) const;
00176
00177 void recHitsV(ConstRecHitContainer & cont,bool splitting = false) const;
00178
00182 void validRecHits(ConstRecHitContainer & cont) const;
00183
00190 int foundHits() const { return theNumberOfFoundHits;}
00191
00197 int lostHits() const { return theNumberOfLostHits;}
00198
00200 bool empty() const { return theData.empty();}
00201
00208 double chiSquared() const { return (theNumberOfFoundHits ? theChiSquared : theChiSquaredBad);}
00209
00213 int ndof(bool bon = true) const;
00214
00215
00220 PropagationDirection const & direction() const;
00221
00225 bool isValid() const { return theValid;}
00226
00228 void invalidate() { theValid = false;}
00229
00231 TrajectorySeed const & seed() const { return *theSeed;}
00232
00233
00236 static bool inactive(
00237 ){return false;}
00238
00242 static bool lost( const TransientTrackingRecHit& hit);
00243
00247 static bool isBad( const TransientTrackingRecHit& hit);
00248
00250 const DetLayer* lastLayer() const {
00251 check();
00252 if (theData.back().recHit()->hit()!=0) return theData.back().layer();
00253 else if (theData.size()>2) return (theData.end()-2)->layer();
00254 else throw cms::Exception("TrajectoryMeasurement::lastMeasurement - Too few measurements in trajectory");
00255 }
00256
00262 edm::RefToBase<TrajectorySeed> seedRef(void) const { return seedRef_; }
00263
00264 void setSeedRef(const edm::RefToBase<TrajectorySeed> & seedRef) { seedRef_ = seedRef ; }
00265
00266 TrajectoryStateOnSurface geometricalInnermostState() const;
00267
00268 TrajectoryMeasurement const & closestMeasurement(GlobalPoint) const;
00269
00272 void reverse() ;
00273
00274 const boost::shared_ptr<const TrajectorySeed> & sharedSeed() const { return theSeed; }
00275 private:
00276
00277
00278 DataContainer theData;
00279 double theChiSquared;
00280 double theChiSquaredBad;
00281 bool theValid;
00282
00283 int theNumberOfFoundHits;
00284 int theNumberOfLostHits;
00285
00286 PropagationDirection theDirection;
00287 bool theDirectionValidity;
00288
00289 boost::shared_ptr<const TrajectorySeed> theSeed;
00290 edm::RefToBase<TrajectorySeed> seedRef_;
00291
00292 void check() const;
00293 };
00294
00295 #endif