Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:26:30

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) {  // it is not consistent with std...
0017       if (TempTrajectory::lost(*(*it).recHit()))
0018         break;
0019       if ((*it).recHit()->isValid())
0020         ++n;
0021     }
0022     return n;
0023   }
0024 }  // namespace
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(it);
0041   }
0042   traj.measurements().clear();
0043 }
0044 
0045 void TempTrajectory::pop() {
0046   if (!empty()) {
0047     if (theData.back().recHit()->isValid()) {
0048       theNumberOfFoundHits--;
0049       if (badForCCC(theData.back()))
0050         theNumberOfCCCBadHits_--;
0051       if (Trajectory::pixel(*(theData.back().recHit())))
0052         theNumberOfFoundPixelHits--;
0053     } else if (lost(*(theData.back().recHit()))) {
0054       theNumberOfLostHits--;
0055     }
0056     theData.pop_back();
0057     theNumberOfTrailingFoundHits = countTrailingValidHits(theData);
0058   }
0059 }
0060 
0061 void TempTrajectory::pushAux(double chi2Increment) {
0062   const TrajectoryMeasurement& tm = theData.back();
0063   if (tm.recHit()->isValid()) {
0064     theNumberOfFoundHits++;
0065     theNumberOfTrailingFoundHits++;
0066     if (badForCCC(tm))
0067       theNumberOfCCCBadHits_++;
0068     if (Trajectory::pixel(*(tm.recHit())))
0069       theNumberOfFoundPixelHits++;
0070   }
0071   //else if (lost( tm.recHit()) && !inactive(tm.recHit().det())) theNumberOfLostHits++;
0072   else if (lost(*(tm.recHit()))) {
0073     theNumberOfLostHits++;
0074     theNumberOfTrailingFoundHits = 0;
0075   }
0076 
0077   theChiSquared += chi2Increment;
0078 }
0079 
0080 void TempTrajectory::push(const TempTrajectory& segment) {
0081   assert(segment.theDirection == theDirection);
0082   assert(segment.theCCCThreshold_ == theCCCThreshold_);
0083 
0084   const int N = segment.measurements().size();
0085   TrajectoryMeasurement const* tmp[N];
0086   int i = 0;
0087   //for (DataContainer::const_iterator it = segment.measurements().rbegin(), ed = segment.measurements().rend(); it != ed; --it)
0088   for (auto const& tm : segment.measurements())
0089     tmp[i++] = &tm;
0090   while (i != 0)
0091     theData.push_back(*tmp[--i]);
0092   theNumberOfFoundHits += segment.theNumberOfFoundHits;
0093   theNumberOfFoundPixelHits += segment.theNumberOfFoundPixelHits;
0094   theNumberOfLostHits += segment.theNumberOfLostHits;
0095   theNumberOfCCCBadHits_ += segment.theNumberOfCCCBadHits_;
0096   theNumberOfTrailingFoundHits = countTrailingValidHits(theData);
0097   theChiSquared += segment.theChiSquared;
0098 }
0099 
0100 void TempTrajectory::join(TempTrajectory& segment) {
0101   assert(segment.theDirection == theDirection);
0102 
0103   if (theCCCThreshold_ != segment.theCCCThreshold_)
0104     segment.updateBadForCCC(theCCCThreshold_);
0105   if (segment.theData.shared()) {
0106     push(segment);
0107     segment.theData.clear();  // obey the contract, and increase the chances it will be not shared one day
0108   } else {
0109     theData.join(segment.theData);
0110     theNumberOfFoundHits += segment.theNumberOfFoundHits;
0111     theNumberOfFoundPixelHits += segment.theNumberOfFoundPixelHits;
0112     theNumberOfLostHits += segment.theNumberOfLostHits;
0113     theNumberOfCCCBadHits_ += segment.theNumberOfCCCBadHits_;
0114     theNumberOfTrailingFoundHits = countTrailingValidHits(theData);
0115     theChiSquared += segment.theChiSquared;
0116   }
0117 }
0118 
0119 PropagationDirection TempTrajectory::direction() const { return PropagationDirection(theDirection); }
0120 
0121 void TempTrajectory::check() const {
0122   if (theData.empty())
0123     throw cms::Exception("TrackingTools/PatternTools",
0124                          "Trajectory::check() - information requested from empty Trajectory");
0125 }
0126 
0127 bool TempTrajectory::lost(const TrackingRecHit& hit) {
0128   if LIKELY (hit.isValid())
0129     return false;
0130 
0131   //     // A DetLayer is always inactive in this logic.
0132   //     // The DetLayer is the Det of an invalid RecHit only if no DetUnit
0133   //     // is compatible with the predicted state, so we don't really expect
0134   //     // a hit in this case.
0135 
0136   if (hit.geographicalId().rawId() == 0) {
0137     return false;
0138   }
0139   return hit.getType() == TrackingRecHit::missing;
0140 }
0141 
0142 bool TempTrajectory::badForCCC(const TrajectoryMeasurement& tm) {
0143   if (!trackerHitRTTI::isFromDet(*tm.recHit()))
0144     return false;
0145   auto const* thit = static_cast<const BaseTrackerRecHit*>(tm.recHit()->hit());
0146   if (!thit)
0147     return false;
0148   if (thit->isPixel() || thit->isPhase2())
0149     return false;
0150   if (!tm.updatedState().isValid())
0151     return false;
0152   return siStripClusterTools::chargePerCM(thit->rawId(),
0153                                           thit->firstClusterRef().stripCluster(),
0154                                           tm.updatedState().localParameters()) < theCCCThreshold_;
0155 }
0156 
0157 void TempTrajectory::updateBadForCCC(float ccc_threshold) {
0158   // If the supplied threshold is the same as the currently cached
0159   // one, then return the current number of bad hits for CCC,
0160   // otherwise do a new full rescan.
0161   if (ccc_threshold == theCCCThreshold_)
0162     return;
0163 
0164   theCCCThreshold_ = ccc_threshold;
0165   theNumberOfCCCBadHits_ = 0;
0166   for (auto const& h : theData) {
0167     if (badForCCC(h))
0168       theNumberOfCCCBadHits_++;
0169   }
0170 }
0171 
0172 int TempTrajectory::numberOfCCCBadHits(float ccc_threshold) {
0173   updateBadForCCC(ccc_threshold);
0174   return theNumberOfCCCBadHits_;
0175 }
0176 
0177 Trajectory TempTrajectory::toTrajectory() const {
0178   PropagationDirection p = PropagationDirection(theDirection);
0179   Trajectory traj(p);
0180   traj.setNLoops(theNLoops);
0181   traj.setStopReason(stopReason_);
0182   traj.numberOfCCCBadHits(theCCCThreshold_);
0183 
0184   traj.reserve(theData.size());
0185   const TrajectoryMeasurement* tmp[theData.size()];
0186   int i = 0;
0187   for (DataContainer::const_iterator it = theData.rbegin(), ed = theData.rend(); it != ed; --it)
0188     tmp[i++] = &(*it);
0189   while (i != 0)
0190     traj.push(*tmp[--i]);
0191   return traj;
0192 }