Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:49

0001 #include "TIDRing.h"
0002 
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
0006 #include "TrackingTools/DetLayers/interface/DetLayerException.h"
0007 #include "TrackingTools/DetLayers/interface/MeasurementEstimator.h"
0008 #include "TrackingTools/GeomPropagators/interface/HelixForwardPlaneCrossing.h"
0009 #include "TrackingTools/DetLayers/interface/rangesIntersect.h"
0010 #include "TrackingTools/DetLayers/interface/ForwardRingDiskBuilderFromDet.h"
0011 
0012 #include "LayerCrossingSide.h"
0013 #include "DetGroupMerger.h"
0014 #include "CompatibleDetToGroupAdder.h"
0015 
0016 #include "TkDetUtil.h"
0017 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
0018 
0019 using namespace std;
0020 
0021 typedef GeometricSearchDet::DetWithState DetWithState;
0022 
0023 TIDRing::TIDRing(std::vector<const GeomDet*>& innerDets, std::vector<const GeomDet*>& outerDets)
0024     : GeometricSearchDet(true),
0025       theFrontDets(innerDets.begin(), innerDets.end()),
0026       theBackDets(outerDets.begin(), outerDets.end()) {
0027   theDets.assign(theFrontDets.begin(), theFrontDets.end());
0028   theDets.insert(theDets.end(), theBackDets.begin(), theBackDets.end());
0029 
0030   // the dets should be already phi-ordered. TO BE CHECKED
0031   //sort( theFrontDets.begin(), theFrontDets.end(), DetLessPhi() );
0032   //sort( theBackDets.begin(), theBackDets.end(), DetLessPhi() );
0033 
0034   theDisk = ForwardRingDiskBuilderFromDet()(theDets);
0035 
0036   theFrontDisk = ForwardRingDiskBuilderFromDet()(theFrontDets);
0037   theBackDisk = ForwardRingDiskBuilderFromDet()(theBackDets);
0038 
0039   theFrontBinFinder = BinFinderType(theFrontDets.front()->surface().position().phi(), theFrontDets.size());
0040   theBackBinFinder = BinFinderType(theBackDets.front()->surface().position().phi(), theBackDets.size());
0041 
0042   LogDebug("TkDetLayers") << "DEBUG INFO for TIDRing";
0043   for (vector<const GeomDet*>::const_iterator it = theFrontDets.begin(); it != theFrontDets.end(); it++) {
0044     LogDebug("TkDetLayers") << "frontDet phi,z,r: " << (*it)->surface().position().phi() << " , "
0045                             << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
0046   }
0047 
0048   for (vector<const GeomDet*>::const_iterator it = theBackDets.begin(); it != theBackDets.end(); it++) {
0049     LogDebug("TkDetLayers") << "backDet phi,z,r: " << (*it)->surface().position().phi() << " , "
0050                             << (*it)->surface().position().z() << " , " << (*it)->surface().position().perp();
0051   }
0052 }
0053 
0054 TIDRing::~TIDRing() {}
0055 
0056 const vector<const GeometricSearchDet*>& TIDRing::components() const {
0057   throw DetLayerException("TIDRing doesn't have GeometricSearchDet components");
0058 }
0059 
0060 pair<bool, TrajectoryStateOnSurface> TIDRing::compatible(const TrajectoryStateOnSurface&,
0061                                                          const Propagator&,
0062                                                          const MeasurementEstimator&) const {
0063   edm::LogError("TkDetLayers") << "temporary dummy implementation of TIDRing::compatible()!!";
0064   return pair<bool, TrajectoryStateOnSurface>();
0065 }
0066 
0067 void TIDRing::groupedCompatibleDetsV(const TrajectoryStateOnSurface& tsos,
0068                                      const Propagator& prop,
0069                                      const MeasurementEstimator& est,
0070                                      std::vector<DetGroup>& result) const {
0071   SubLayerCrossings crossings;
0072   crossings = computeCrossings(tsos, prop.propagationDirection());
0073   if (!crossings.isValid())
0074     return;
0075 
0076   std::vector<DetGroup> closestResult;
0077   addClosest(tsos, prop, est, crossings.closest(), closestResult);
0078   if (closestResult.empty())
0079     return;
0080 
0081   DetGroupElement closestGel(closestResult.front().front());
0082   float phiWindow = tkDetUtil::computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
0083   searchNeighbors(tsos, prop, est, crossings.closest(), phiWindow, closestResult, false);
0084 
0085   vector<DetGroup> nextResult;
0086   searchNeighbors(tsos, prop, est, crossings.other(), phiWindow, nextResult, true);
0087 
0088   int crossingSide = LayerCrossingSide().endcapSide(closestGel.trajectoryState(), prop);
0089   DetGroupMerger::orderAndMergeTwoLevels(
0090       std::move(closestResult), std::move(nextResult), result, crossings.closestIndex(), crossingSide);
0091 }
0092 
0093 // indentical in CompositeTECWedge
0094 SubLayerCrossings TIDRing::computeCrossings(const TrajectoryStateOnSurface& startingState,
0095                                             PropagationDirection propDir) const {
0096   HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
0097   HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
0098 
0099   auto rho = startingState.transverseCurvature();
0100 
0101   HelixForwardPlaneCrossing crossing(startPos, startDir, rho, propDir);
0102 
0103   pair<bool, double> frontPath = crossing.pathLength(*theFrontDisk);
0104   if (!frontPath.first)
0105     return SubLayerCrossings();
0106 
0107   pair<bool, double> backPath = crossing.pathLength(*theBackDisk);
0108   if (!backPath.first)
0109     return SubLayerCrossings();
0110 
0111   GlobalPoint gFrontPoint(crossing.position(frontPath.second));
0112   GlobalPoint gBackPoint(crossing.position(backPath.second));
0113 
0114   int frontIndex = theFrontBinFinder.binIndex(gFrontPoint.barePhi());
0115   SubLayerCrossing frontSLC(0, frontIndex, gFrontPoint);
0116 
0117   int backIndex = theBackBinFinder.binIndex(gBackPoint.barePhi());
0118   SubLayerCrossing backSLC(1, backIndex, gBackPoint);
0119 
0120   // 0ss: frontDisk has index=0, backDisk has index=1
0121   float frontDist = std::abs(Geom::deltaPhi(gFrontPoint.barePhi(), theFrontDets[frontIndex]->surface().phi()));
0122   float backDist = std::abs(Geom::deltaPhi(gBackPoint.barePhi(), theBackDets[backIndex]->surface().phi()));
0123 
0124   if (frontDist < backDist) {
0125     return SubLayerCrossings(frontSLC, backSLC, 0);
0126   } else {
0127     return SubLayerCrossings(backSLC, frontSLC, 1);
0128   }
0129 }
0130 
0131 bool TIDRing::addClosest(const TrajectoryStateOnSurface& tsos,
0132                          const Propagator& prop,
0133                          const MeasurementEstimator& est,
0134                          const SubLayerCrossing& crossing,
0135                          vector<DetGroup>& result) const {
0136   const vector<const GeomDet*>& sub(subLayer(crossing.subLayerIndex()));
0137   const GeomDet* det(sub[crossing.closestDetIndex()]);
0138   return CompatibleDetToGroupAdder::add(*det, tsos, prop, est, result);
0139 }
0140 
0141 void TIDRing::searchNeighbors(const TrajectoryStateOnSurface& tsos,
0142                               const Propagator& prop,
0143                               const MeasurementEstimator& est,
0144                               const SubLayerCrossing& crossing,
0145                               float window,
0146                               vector<DetGroup>& result,
0147                               bool checkClosest) const {
0148   const GlobalPoint& gCrossingPos = crossing.position();
0149 
0150   const vector<const GeomDet*>& sLayer(subLayer(crossing.subLayerIndex()));
0151 
0152   int closestIndex = crossing.closestDetIndex();
0153   int negStartIndex = closestIndex - 1;
0154   int posStartIndex = closestIndex + 1;
0155 
0156   if (checkClosest) {  // must decide if the closest is on the neg or pos side
0157     if (Geom::phiLess(gCrossingPos.barePhi(), sLayer[closestIndex]->surface().phi())) {
0158       posStartIndex = closestIndex;
0159     } else {
0160       negStartIndex = closestIndex;
0161     }
0162   }
0163 
0164   const BinFinderType& binFinder = (crossing.subLayerIndex() == 0 ? theFrontBinFinder : theBackBinFinder);
0165 
0166   typedef CompatibleDetToGroupAdder Adder;
0167   int half = sLayer.size() / 2;  // to check if dets are called twice....
0168   for (int idet = negStartIndex; idet >= negStartIndex - half; idet--) {
0169     const GeomDet& neighborDet = *sLayer[binFinder.binIndex(idet)];
0170     if (!tkDetUtil::overlapInPhi(gCrossingPos, neighborDet, window))
0171       break;
0172     if (!Adder::add(neighborDet, tsos, prop, est, result))
0173       break;
0174     // maybe also add shallow crossing angle test here???
0175   }
0176   for (int idet = posStartIndex; idet < posStartIndex + half; idet++) {
0177     const GeomDet& neighborDet = *sLayer[binFinder.binIndex(idet)];
0178     if (!tkDetUtil::overlapInPhi(gCrossingPos, neighborDet, window))
0179       break;
0180     if (!Adder::add(neighborDet, tsos, prop, est, result))
0181       break;
0182     // maybe also add shallow crossing angle test here???
0183   }
0184 }