File indexing completed on 2024-05-23 03:13:38
0001 #ifndef CommonDet_Trajectory_H
0002 #define CommonDet_Trajectory_H
0003
0004 #include "DataFormats/Common/interface/RefToBase.h"
0005 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
0006 #include "DataFormats/TrackCandidate/interface/TrajectoryStopReasons.h"
0007 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
0008 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
0009 #include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h"
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011
0012 #include <vector>
0013 #include <algorithm>
0014 #include <limits>
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 class Trajectory {
0039 public:
0040 typedef std::vector<TrajectoryMeasurement> DataContainer;
0041 using ConstRecHitContainer = TrackingRecHit::ConstRecHitContainer;
0042 using RecHitContainer = ConstRecHitContainer;
0043
0044
0045
0046
0047
0048
0049 Trajectory() = default;
0050
0051
0052
0053
0054
0055
0056
0057 explicit Trajectory(const TrajectorySeed& seed) : theSeed(new TrajectorySeed(seed)), theValid(true) {}
0058
0059
0060
0061
0062
0063 Trajectory(const TrajectorySeed& seed, PropagationDirection dir)
0064 : theSeed(new TrajectorySeed(seed)), theDirection(dir), theDirectionValidity(true), theValid(true) {}
0065
0066
0067
0068
0069
0070 Trajectory(const std::shared_ptr<const TrajectorySeed>& seed, PropagationDirection dir)
0071 : theSeed(seed), theDirection(dir), theDirectionValidity(true), theValid(true) {}
0072
0073
0074
0075
0076
0077 explicit Trajectory(PropagationDirection dir) : theDirection(dir), theDirectionValidity(true), theValid(true) {}
0078
0079 Trajectory(Trajectory const& rh) = default;
0080 Trajectory& operator=(Trajectory const& rh) = default;
0081
0082 Trajectory(Trajectory&& rh)
0083 : theSeed(std::move(rh.theSeed)),
0084 seedRef_(std::move(rh.seedRef_)),
0085 theData(std::move(rh.theData)),
0086 theDPhiCache(rh.theDPhiCache),
0087 theCCCThreshold_(rh.theCCCThreshold_),
0088 theChiSquared(rh.theChiSquared),
0089 theChiSquaredBad(rh.theChiSquaredBad),
0090 theDirection(rh.theDirection),
0091 theDirectionValidity(rh.theDirectionValidity),
0092 theValid(rh.theValid),
0093 theNumberOfFoundHits(rh.theNumberOfFoundHits),
0094 theNumberOfFoundPixelHits(rh.theNumberOfFoundPixelHits),
0095 theNumberOfLostHits(rh.theNumberOfLostHits),
0096 theNumberOfTrailingFoundHits(rh.theNumberOfTrailingFoundHits),
0097 theNumberOfCCCBadHits_(rh.theNumberOfCCCBadHits_),
0098 theNLoops(rh.theNLoops),
0099 stopReason_(rh.stopReason_) {}
0100
0101 Trajectory& operator=(Trajectory&& rh) {
0102 using std::swap;
0103 swap(theData, rh.theData);
0104 theDPhiCache = rh.theDPhiCache;
0105 theCCCThreshold_ = rh.theCCCThreshold_;
0106 theChiSquared = rh.theChiSquared;
0107 theChiSquaredBad = rh.theChiSquaredBad;
0108 theValid = rh.theValid;
0109 theNLoops = rh.theNLoops;
0110 theNumberOfFoundHits = rh.theNumberOfFoundHits;
0111 theNumberOfFoundPixelHits = rh.theNumberOfFoundPixelHits;
0112 theNumberOfLostHits = rh.theNumberOfLostHits;
0113 theNumberOfTrailingFoundHits = rh.theNumberOfTrailingFoundHits;
0114 theNumberOfCCCBadHits_ = rh.theNumberOfCCCBadHits_;
0115 theDirection = rh.theDirection;
0116 theDirectionValidity = rh.theDirectionValidity;
0117 stopReason_ = rh.stopReason_;
0118 swap(theSeed, rh.theSeed);
0119 swap(seedRef_, rh.seedRef_);
0120
0121 return *this;
0122 }
0123
0124
0125
0126 void reserve(unsigned int n) { theData.reserve(n); }
0127
0128
0129
0130
0131
0132 void push(const TrajectoryMeasurement& tm);
0133
0134
0135
0136 void push(const TrajectoryMeasurement& tm, double chi2Increment);
0137
0138 void push(TrajectoryMeasurement&& tm);
0139 void push(TrajectoryMeasurement&& tm, double chi2Increment);
0140
0141
0142
0143 void pop();
0144
0145
0146
0147
0148
0149
0150 TrajectoryMeasurement const& lastMeasurement() const {
0151 check();
0152 if (theData.back().recHitR().hit() != nullptr)
0153 return theData.back();
0154 else if (theData.size() > 2)
0155 return *(theData.end() - 2);
0156 else
0157 throw cms::Exception("TrajectoryMeasurement::lastMeasurement - Too few measurements in trajectory");
0158 }
0159
0160
0161
0162
0163
0164
0165
0166 TrajectoryMeasurement const& firstMeasurement() const {
0167 check();
0168 if (theData.front().recHitR().hit() != nullptr)
0169 return theData.front();
0170 else if (theData.size() > 2)
0171 return *(theData.begin() + 1);
0172 else
0173 throw cms::Exception("TrajectoryMeasurement::firstMeasurement - Too few measurements in trajectory");
0174 }
0175
0176
0177
0178 DataContainer const& measurements() const { return theData; }
0179 DataContainer& measurements() { return theData; }
0180
0181
0182 DataContainer const& data() const { return measurements(); }
0183
0184
0185
0186 ConstRecHitContainer recHits() const {
0187 ConstRecHitContainer hits;
0188 hits.reserve(theData.size());
0189 for (Trajectory::DataContainer::const_iterator itm = theData.begin(); itm != theData.end(); itm++) {
0190 hits.push_back((*itm).recHit());
0191 }
0192 return hits;
0193 }
0194
0195
0196
0197
0198 void validRecHits(ConstRecHitContainer& cont) const;
0199
0200
0201
0202
0203
0204
0205
0206 int foundHits() const { return theNumberOfFoundHits; }
0207
0208
0209
0210 int foundPixelHits() const { return theNumberOfFoundPixelHits; }
0211
0212
0213
0214
0215
0216
0217 int lostHits() const { return theNumberOfLostHits; }
0218
0219
0220
0221 int trailingFoundHits() const { return theNumberOfTrailingFoundHits; }
0222
0223
0224
0225
0226
0227 int cccBadHits() const { return theNumberOfCCCBadHits_; }
0228
0229
0230 unsigned int seedNHits() const { return seed().nHits(); }
0231
0232
0233 bool empty() const { return theData.empty(); }
0234
0235
0236
0237
0238
0239
0240
0241 float chiSquared() const { return (theNumberOfFoundHits ? theChiSquared : theChiSquaredBad); }
0242
0243
0244
0245
0246 int ndof(bool bon = true) const;
0247
0248
0249
0250
0251
0252 PropagationDirection const& direction() const;
0253
0254
0255
0256
0257 bool isValid() const { return theValid; }
0258
0259
0260 void invalidate() { theValid = false; }
0261
0262
0263 TrajectorySeed const& seed() const { return *theSeed; }
0264
0265
0266
0267 static bool inactive(
0268 ) {
0269 return false;
0270 }
0271
0272
0273
0274
0275 static bool lost(const TrackingRecHit& hit);
0276
0277
0278
0279
0280 static bool isBad(const TrackingRecHit& hit);
0281
0282
0283
0284
0285 static bool pixel(const TrackingRecHit& hit);
0286
0287
0288 const DetLayer* lastLayer() const {
0289 check();
0290 if (theData.back().recHit()->hit() != nullptr)
0291 return theData.back().layer();
0292 else if (theData.size() > 2)
0293 return (theData.end() - 2)->layer();
0294 else
0295 throw cms::Exception("TrajectoryMeasurement::lastMeasurement - Too few measurements in trajectory");
0296 }
0297
0298
0299
0300
0301
0302
0303 edm::RefToBase<TrajectorySeed> seedRef(void) const { return seedRef_; }
0304
0305 void setSeedRef(const edm::RefToBase<TrajectorySeed>& seedRef) { seedRef_ = seedRef; }
0306
0307 TrajectoryStateOnSurface geometricalInnermostState() const;
0308
0309 TrajectoryMeasurement const& closestMeasurement(GlobalPoint) const;
0310
0311
0312
0313 void reverse();
0314
0315 const std::shared_ptr<const TrajectorySeed>& sharedSeed() const { return theSeed; }
0316 void setSharedSeed(const std::shared_ptr<const TrajectorySeed>& seed) { theSeed = seed; }
0317
0318
0319
0320 float dPhiCacheForLoopersReconstruction() const { return theDPhiCache; }
0321
0322 float cccThreshold() const { return theCCCThreshold_; }
0323
0324
0325
0326 void setDPhiCacheForLoopersReconstruction(float dphi) { theDPhiCache = dphi; }
0327
0328 bool isLooper() const { return (theNLoops > 0); }
0329 int8_t nLoops() const { return theNLoops; }
0330
0331 void setNLoops(int8_t value) { theNLoops = value; }
0332 void incrementLoops() { theNLoops++; }
0333
0334 void setStopReason(StopReason s) { stopReason_ = s; }
0335 StopReason stopReason() const { return stopReason_; }
0336
0337 int numberOfCCCBadHits(float ccc_threshold);
0338
0339 private:
0340 void pushAux(double chi2Increment);
0341 bool badForCCC(const TrajectoryMeasurement& tm);
0342 void updateBadForCCC(float ccc_threshold);
0343
0344 std::shared_ptr<const TrajectorySeed> theSeed;
0345 edm::RefToBase<TrajectorySeed> seedRef_;
0346
0347 DataContainer theData;
0348
0349 float theDPhiCache = 0;
0350 float theCCCThreshold_ = std::numeric_limits<float>::max();
0351
0352 float theChiSquared = 0;
0353 float theChiSquaredBad = 0;
0354
0355 PropagationDirection theDirection = anyDirection;
0356 bool theDirectionValidity = false;
0357 bool theValid = false;
0358
0359 uint8_t theNumberOfFoundHits = 0;
0360 uint8_t theNumberOfFoundPixelHits = 0;
0361 uint8_t theNumberOfLostHits = 0;
0362 uint8_t theNumberOfTrailingFoundHits = 0;
0363 uint8_t theNumberOfCCCBadHits_ = 0;
0364 int8_t theNLoops = 0;
0365 StopReason stopReason_ = StopReason::UNINITIALIZED;
0366
0367 void check() const;
0368 };
0369
0370 #endif