File indexing completed on 2021-06-12 03:09:55
0001 #include "TrackingTools/PatternTools/interface/TempTrajectory.h"
0002 #include "DataFormats/SiStripCluster/interface/SiStripClusterTools.h"
0003 #include "DataFormats/SiStripCluster/interface/SiStripCluster.h"
0004 #include "DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h"
0005 #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h"
0006 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0007 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0010 #include "FWCore/Utilities/interface/Likely.h"
0011
0012 namespace {
0013 template <typename DataContainer>
0014 unsigned short countTrailingValidHits(DataContainer const& meas) {
0015 unsigned short n = 0;
0016 for (auto it = meas.rbegin(); it != meas.rend(); --it) {
0017 if (TempTrajectory::lost(*(*it).recHit()))
0018 break;
0019 if ((*it).recHit()->isValid())
0020 ++n;
0021 }
0022 return n;
0023 }
0024 }
0025
0026 TempTrajectory::TempTrajectory(Trajectory&& traj)
0027 : theChiSquared(0),
0028 theNumberOfFoundHits(0),
0029 theNumberOfFoundPixelHits(0),
0030 theNumberOfLostHits(0),
0031 theNumberOfCCCBadHits_(0),
0032 theDirection(traj.direction()),
0033 theValid(traj.isValid()),
0034 theNHseed(traj.seedNHits()),
0035 theNLoops(traj.nLoops()),
0036 theDPhiCache(traj.dPhiCacheForLoopersReconstruction()),
0037 theCCCThreshold_(traj.cccThreshold()),
0038 stopReason_(traj.stopReason()) {
0039 for (auto& it : traj.measurements()) {
0040 push(std::move(it));
0041 }
0042 }
0043
0044 void TempTrajectory::pop() {
0045 if (!empty()) {
0046 if (theData.back().recHit()->isValid()) {
0047 theNumberOfFoundHits--;
0048 if (badForCCC(theData.back()))
0049 theNumberOfCCCBadHits_--;
0050 if (Trajectory::pixel(*(theData.back().recHit())))
0051 theNumberOfFoundPixelHits--;
0052 } else if (lost(*(theData.back().recHit()))) {
0053 theNumberOfLostHits--;
0054 }
0055 theData.pop_back();
0056 theNumberOfTrailingFoundHits = countTrailingValidHits(theData);
0057 }
0058 }
0059
0060 void TempTrajectory::pushAux(double chi2Increment) {
0061 const TrajectoryMeasurement& tm = theData.back();
0062 if (tm.recHit()->isValid()) {
0063 theNumberOfFoundHits++;
0064 theNumberOfTrailingFoundHits++;
0065 if (badForCCC(tm))
0066 theNumberOfCCCBadHits_++;
0067 if (Trajectory::pixel(*(tm.recHit())))
0068 theNumberOfFoundPixelHits++;
0069 }
0070
0071 else if (lost(*(tm.recHit()))) {
0072 theNumberOfLostHits++;
0073 theNumberOfTrailingFoundHits = 0;
0074 }
0075
0076 theChiSquared += chi2Increment;
0077 }
0078
0079 void TempTrajectory::push(const TempTrajectory& segment) {
0080 assert(segment.theDirection == theDirection);
0081 assert(segment.theCCCThreshold_ == theCCCThreshold_);
0082
0083 const int N = segment.measurements().size();
0084 TrajectoryMeasurement const* tmp[N];
0085 int i = 0;
0086
0087 for (auto const& tm : segment.measurements())
0088 tmp[i++] = &tm;
0089 while (i != 0)
0090 theData.push_back(*tmp[--i]);
0091 theNumberOfFoundHits += segment.theNumberOfFoundHits;
0092 theNumberOfFoundPixelHits += segment.theNumberOfFoundPixelHits;
0093 theNumberOfLostHits += segment.theNumberOfLostHits;
0094 theNumberOfCCCBadHits_ += segment.theNumberOfCCCBadHits_;
0095 theNumberOfTrailingFoundHits = countTrailingValidHits(theData);
0096 theChiSquared += segment.theChiSquared;
0097 }
0098
0099 void TempTrajectory::join(TempTrajectory& segment) {
0100 assert(segment.theDirection == theDirection);
0101
0102 if (theCCCThreshold_ != segment.theCCCThreshold_)
0103 segment.updateBadForCCC(theCCCThreshold_);
0104 if (segment.theData.shared()) {
0105 push(segment);
0106 segment.theData.clear();
0107 } else {
0108 theData.join(segment.theData);
0109 theNumberOfFoundHits += segment.theNumberOfFoundHits;
0110 theNumberOfFoundPixelHits += segment.theNumberOfFoundPixelHits;
0111 theNumberOfLostHits += segment.theNumberOfLostHits;
0112 theNumberOfCCCBadHits_ += segment.theNumberOfCCCBadHits_;
0113 theNumberOfTrailingFoundHits = countTrailingValidHits(theData);
0114 theChiSquared += segment.theChiSquared;
0115 }
0116 }
0117
0118 PropagationDirection TempTrajectory::direction() const { return PropagationDirection(theDirection); }
0119
0120 void TempTrajectory::check() const {
0121 if (theData.size() == 0)
0122 throw cms::Exception("TrackingTools/PatternTools",
0123 "Trajectory::check() - information requested from empty Trajectory");
0124 }
0125
0126 bool TempTrajectory::lost(const TrackingRecHit& hit) {
0127 if LIKELY (hit.isValid())
0128 return false;
0129
0130
0131
0132
0133
0134
0135 if (hit.geographicalId().rawId() == 0) {
0136 return false;
0137 }
0138 return hit.getType() == TrackingRecHit::missing;
0139 }
0140
0141 bool TempTrajectory::badForCCC(const TrajectoryMeasurement& tm) {
0142 if (!trackerHitRTTI::isFromDet(*tm.recHit()))
0143 return false;
0144 auto const* thit = static_cast<const BaseTrackerRecHit*>(tm.recHit()->hit());
0145 if (!thit)
0146 return false;
0147 if (thit->isPixel() || thit->isPhase2())
0148 return false;
0149 if (!tm.updatedState().isValid())
0150 return false;
0151 return siStripClusterTools::chargePerCM(thit->rawId(),
0152 thit->firstClusterRef().stripCluster(),
0153 tm.updatedState().localParameters()) < theCCCThreshold_;
0154 }
0155
0156 void TempTrajectory::updateBadForCCC(float ccc_threshold) {
0157
0158
0159
0160 if (ccc_threshold == theCCCThreshold_)
0161 return;
0162
0163 theCCCThreshold_ = ccc_threshold;
0164 theNumberOfCCCBadHits_ = 0;
0165 for (auto const& h : theData) {
0166 if (badForCCC(h))
0167 theNumberOfCCCBadHits_++;
0168 }
0169 }
0170
0171 int TempTrajectory::numberOfCCCBadHits(float ccc_threshold) {
0172 updateBadForCCC(ccc_threshold);
0173 return theNumberOfCCCBadHits_;
0174 }
0175
0176 Trajectory TempTrajectory::toTrajectory() const {
0177 PropagationDirection p = PropagationDirection(theDirection);
0178 Trajectory traj(p);
0179 traj.setNLoops(theNLoops);
0180 traj.setStopReason(stopReason_);
0181 traj.numberOfCCCBadHits(theCCCThreshold_);
0182
0183 traj.reserve(theData.size());
0184 const TrajectoryMeasurement* tmp[theData.size()];
0185 int i = 0;
0186 for (DataContainer::const_iterator it = theData.rbegin(), ed = theData.rend(); it != ed; --it)
0187 tmp[i++] = &(*it);
0188 while (i != 0)
0189 traj.push(*tmp[--i]);
0190 return traj;
0191 }