CMS 3D CMS Logo

TIDLayer.cc
Go to the documentation of this file.
1 #include "TIDLayer.h"
2 
4 
6 
9 
10 #include <array>
11 #include "DetGroupMerger.h"
12 
13 //#include "CommonDet/DetLayout/src/DetLessR.h"
14 
15 using namespace std;
16 
18 
19 namespace {
20 
21  // 2 0 1
22  /*
23 class TIDringLess {
24  // z-position ordering of TID rings indices
25 public:
26  bool operator()( const pair<vector<DetGroup> const *,int> & a,const pair<vector<DetGroup>const *,int> & b) const {
27  if(a.second==2) {return true;}
28  else if(a.second==0) {
29  if(b.second==2) return false;
30  if(b.second==1) return true;
31  }
32  return false;
33  };
34 };
35 */
36 
37  // groups in correct order: one may be empty
38  inline void mergeOutward(std::array<vector<DetGroup>, 3>& groups, std::vector<DetGroup>& result) {
39  typedef DetGroupMerger Merger;
40  Merger::orderAndMergeTwoLevels(std::move(groups[0]), std::move(groups[1]), result, 1, 1);
41  if (!groups[2].empty()) {
42  std::vector<DetGroup> tmp;
43  tmp.swap(result);
44  Merger::orderAndMergeTwoLevels(std::move(tmp), std::move(groups[2]), result, 1, 1);
45  }
46  }
47 
48  inline void mergeInward(std::array<vector<DetGroup>, 3>& groups, std::vector<DetGroup>& result) {
49  typedef DetGroupMerger Merger;
50  Merger::orderAndMergeTwoLevels(std::move(groups[2]), std::move(groups[1]), result, 1, 1);
51  if (!groups[0].empty()) {
52  std::vector<DetGroup> tmp;
53  tmp.swap(result);
54  Merger::orderAndMergeTwoLevels(std::move(tmp), std::move(groups[0]), result, 1, 1);
55  }
56  }
57 
58  void orderAndMergeLevels(const TrajectoryStateOnSurface& tsos,
59  const Propagator& prop,
60  std::array<vector<DetGroup>, 3>& groups,
61  std::vector<DetGroup>& result) {
62  float zpos = tsos.globalPosition().z();
63  if (tsos.globalMomentum().z() * zpos > 0) { // momentum points outwards
64  if (prop.propagationDirection() == alongMomentum)
65  mergeOutward(groups, result);
66  else
67  mergeInward(groups, result);
68  } else { // momentum points inwards
70  mergeOutward(groups, result);
71  else
72  mergeInward(groups, result);
73  }
74  }
75 
76 } // namespace
77 
78 //hopefully is never called!
79 const std::vector<const GeometricSearchDet*>& TIDLayer::components() const {
80  if (not theComponents) {
81  auto temp = std::make_unique<std::vector<const GeometricSearchDet*>>();
82  temp->reserve(3);
83  for (auto c : theComps)
84  temp->push_back(c);
85  std::vector<const GeometricSearchDet*>* expected = nullptr;
86  if (theComponents.compare_exchange_strong(expected, temp.get())) {
87  //this thread set the value
88  temp.release();
89  }
90  }
91 
92  return *theComponents;
93 }
94 
96  const BoundDisk& ringDisk = static_cast<const BoundDisk&>(theComps[i]->surface());
97  float ringMinZ = std::abs(ringDisk.position().z()) - ringDisk.bounds().thickness() / 2.;
98  float ringMaxZ = std::abs(ringDisk.position().z()) + ringDisk.bounds().thickness() / 2.;
99  ringPars[i].thetaRingMin = ringDisk.innerRadius() / ringMaxZ;
100  ringPars[i].thetaRingMax = ringDisk.outerRadius() / ringMinZ;
101  ringPars[i].theRingR = (ringDisk.innerRadius() + ringDisk.outerRadius()) / 2.;
102 }
103 
104 TIDLayer::TIDLayer(vector<const TIDRing*>& rings) : RingedForwardLayer(true), theComponents{nullptr} {
105  //They should be already R-ordered. TO BE CHECKED!!
106  //sort( theRings.begin(), theRings.end(), DetLessR());
107 
108  if (rings.size() != 3)
109  throw DetLayerException("Number of rings in TID layer is not equal to 3 !!");
110  setSurface(computeDisk(rings));
111 
112  for (int i = 0; i != 3; ++i) {
113  theComps[i] = rings[i];
114  fillRingPars(i);
115  theBasicComps.insert(
116  theBasicComps.end(), (*rings[i]).basicComponents().begin(), (*rings[i]).basicComponents().end());
117  }
118 
119  LogDebug("TkDetLayers") << "==== DEBUG TIDLayer =====";
120  LogDebug("TkDetLayers") << "r,zed pos , thickness, innerR, outerR: " << this->position().perp() << " , "
121  << this->position().z() << " , " << this->specificSurface().bounds().thickness() << " , "
122  << this->specificSurface().innerRadius() << " , " << this->specificSurface().outerRadius();
123 }
124 
125 BoundDisk* TIDLayer::computeDisk(const vector<const TIDRing*>& rings) const {
126  float theRmin = rings.front()->specificSurface().innerRadius();
127  float theRmax = rings.front()->specificSurface().outerRadius();
128  float theZmin = rings.front()->position().z() - rings.front()->surface().bounds().thickness() / 2;
129  float theZmax = rings.front()->position().z() + rings.front()->surface().bounds().thickness() / 2;
130 
131  for (vector<const TIDRing*>::const_iterator i = rings.begin(); i != rings.end(); i++) {
132  float rmin = (**i).specificSurface().innerRadius();
133  float rmax = (**i).specificSurface().outerRadius();
134  float zmin = (**i).position().z() - (**i).surface().bounds().thickness() / 2.;
135  float zmax = (**i).position().z() + (**i).surface().bounds().thickness() / 2.;
136  theRmin = min(theRmin, rmin);
137  theRmax = max(theRmax, rmax);
138  theZmin = min(theZmin, zmin);
139  theZmax = max(theZmax, zmax);
140  }
141 
142  float zPos = (theZmax + theZmin) / 2.;
143  PositionType pos(0., 0., zPos);
145 
146  return new BoundDisk(pos, rot, new SimpleDiskBounds(theRmin, theRmax, theZmin - zPos, theZmax - zPos));
147 }
148 
150  for (auto c : theComps)
151  delete c;
152 
153  delete theComponents.load();
154 }
155 
157  const Propagator& prop,
158  const MeasurementEstimator& est,
159  std::vector<DetGroup>& result) const {
160  std::array<int, 3> const& ringIndices = ringIndicesByCrossingProximity(startingState, prop);
161  if (ringIndices[0] == -1) {
162  edm::LogError("TkDetLayers") << "TkRingedForwardLayer::groupedCompatibleDets : error in CrossingProximity";
163  return;
164  }
165 
166  std::array<vector<DetGroup>, 3> groupsAtRingLevel;
167  //order is ring3,ring1,ring2 i.e. 2 0 1
168  // 0 1 2
169  static constexpr int ringOrder[3]{1, 2, 0};
170  auto index = [&ringIndices](int i) { return ringOrder[ringIndices[i]]; };
171 
172  auto& closestResult = groupsAtRingLevel[index(0)];
173  theComps[ringIndices[0]]->groupedCompatibleDetsV(startingState, prop, est, closestResult);
174  if (closestResult.empty()) {
175  theComps[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, result);
176  return;
177  }
178 
179  DetGroupElement closestGel(closestResult.front().front());
180  float rWindow = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
181 
182  if (!overlapInR(closestGel.trajectoryState(), ringIndices[1], rWindow)) {
183  result.swap(closestResult);
184  return;
185  }
186 
187  auto& nextResult = groupsAtRingLevel[index(1)];
188  theComps[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, nextResult);
189  if (nextResult.empty()) {
190  result.swap(closestResult);
191  return;
192  }
193 
194  if (!overlapInR(closestGel.trajectoryState(), ringIndices[2], rWindow)) {
195  //then merge 2 levels & return
196  orderAndMergeLevels(closestGel.trajectoryState(), prop, groupsAtRingLevel, result);
197  return;
198  }
199 
200  auto& nextNextResult = groupsAtRingLevel[index(2)];
201  theComps[ringIndices[2]]->groupedCompatibleDetsV(startingState, prop, est, nextNextResult);
202  if (nextNextResult.empty()) {
203  // then merge 2 levels and return
204  orderAndMergeLevels(closestGel.trajectoryState(), prop, groupsAtRingLevel, result); //
205  return;
206  }
207 
208  // merge 3 level and return merged
209  orderAndMergeLevels(closestGel.trajectoryState(), prop, groupsAtRingLevel, result);
210 }
211 
213  const Propagator& prop) const {
214  typedef HelixForwardPlaneCrossing Crossing;
216 
217  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
218  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
220  float rho(startingState.transverseCurvature());
221 
222  // calculate the crossings with the ring surfaces
223  // rings are assumed to be sorted in R !
224 
225  Crossing myXing(startPos, startDir, rho, propDir);
226 
227  GlobalPoint ringCrossings[3];
228  // vector<GlobalVector> ringXDirections;
229 
230  for (int i = 0; i < 3; i++) {
231  const BoundDisk& theRing = static_cast<const BoundDisk&>(theComps[i]->surface());
232  pair<bool, double> pathlen = myXing.pathLength(theRing);
233  if (pathlen.first) {
234  ringCrossings[i] = GlobalPoint(myXing.position(pathlen.second));
235  // ringXDirections.push_back( GlobalVector( myXing.direction(pathlen.second )));
236  } else {
237  // TO FIX.... perhaps there is something smarter to do
238  //throw DetLayerException("trajectory doesn't cross TID rings");
239  ringCrossings[i] = GlobalPoint(0., 0., 0.);
240  // ringXDirections.push_back( GlobalVector( 0.,0.,0.));
241  }
242  }
243 
244  int closestIndex = findClosest(ringCrossings);
245  int nextIndex = findNextIndex(ringCrossings, closestIndex);
246  if (closestIndex < 0 || nextIndex < 0)
247  return std::array<int, 3>{{-1, -1, -1}};
248  int nextNextIndex = -1;
249  for (int i = 0; i < 3; i++) {
250  if (i != closestIndex && i != nextIndex) {
251  nextNextIndex = i;
252  break;
253  }
254  }
255 
256  std::array<int, 3> indices{{closestIndex, nextIndex, nextNextIndex}};
257  return indices;
258 }
259 
261  const TrajectoryStateOnSurface& tsos,
262  const MeasurementEstimator& est) const {
263  const Plane& startPlane = det->surface();
265  return maxDistance.y();
266 }
267 
268 int TIDLayer::findClosest(const GlobalPoint ringCrossing[3]) const {
269  int theBin = 0;
270  float initialR = ringPars[0].theRingR;
271  float rDiff = std::abs(ringCrossing[0].perp() - initialR);
272  for (int i = 1; i < 3; i++) {
273  float ringR = ringPars[i].theRingR;
274  float testDiff = std::abs(ringCrossing[i].perp() - ringR);
275  if (testDiff < rDiff) {
276  rDiff = testDiff;
277  theBin = i;
278  }
279  }
280  return theBin;
281 }
282 
283 int TIDLayer::findNextIndex(const GlobalPoint ringCrossing[3], int closest) const {
284  int firstIndexToCheck = (closest != 0) ? 0 : 1;
285  float initialR = ringPars[firstIndexToCheck].theRingR;
286  float rDiff = std::abs(ringCrossing[firstIndexToCheck].perp() - initialR);
287  int theBin = firstIndexToCheck;
288  for (int i = firstIndexToCheck + 1; i < 3; i++) {
289  if (i != closest) {
290  float ringR = ringPars[i].theRingR;
291  float testDiff = std::abs(ringCrossing[i].perp() - ringR);
292  if (testDiff < rDiff) {
293  rDiff = testDiff;
294  theBin = i;
295  }
296  }
297  }
298  return theBin;
299 }
300 
301 bool TIDLayer::overlapInR(const TrajectoryStateOnSurface& tsos, int index, double ymax) const {
302  // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
303  float tsRadius = tsos.globalPosition().perp();
304  float thetamin = (max(0., tsRadius - ymax)) / (std::abs(tsos.globalPosition().z()) + 10.f); // add 10 cm contingency
305  float thetamax = (tsRadius + ymax) / (std::abs(tsos.globalPosition().z()) - 10.f);
306 
307  // do the theta regions overlap ?
308 
309  return !(thetamin > ringPars[index].thetaRingMax || ringPars[index].thetaRingMin > thetamax);
310 }
TIDLayer::theComps
const TIDRing * theComps[3]
Definition: TIDLayer.h:62
bTagCombinedSVVariables_cff.indices
indices
Definition: bTagCombinedSVVariables_cff.py:67
MeasurementEstimator
Definition: MeasurementEstimator.h:19
mps_fire.i
i
Definition: mps_fire.py:428
TIDLayer::~TIDLayer
~TIDLayer() override __attribute__((cold))
Definition: TIDLayer.cc:149
TIDLayer::fillRingPars
void fillRingPars(int i) __attribute__((cold))
Definition: TIDLayer.cc:95
MessageLogger.h
GeomDet
Definition: GeomDet.h:27
align::RotationType
TkRotation< Scalar > RotationType
Definition: Definitions.h:27
TIDLayer::ringIndicesByCrossingProximity
std::array< int, 3 > ringIndicesByCrossingProximity(const TrajectoryStateOnSurface &startingState, const Propagator &prop) const
Definition: TIDLayer.cc:212
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
TIDLayer::computeDisk
BoundDisk * computeDisk(const std::vector< const TIDRing * > &rings) const __attribute__((cold))
Definition: TIDLayer.cc:125
TIDLayer::RingPar::thetaRingMin
float thetaRingMin
Definition: TIDLayer.h:64
min
T min(T a, T b)
Definition: MathUtil.h:58
TIDLayer::groupedCompatibleDetsV
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
Definition: TIDLayer.cc:156
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
pos
Definition: PixelAliasList.h:18
TIDLayer::RingPar::thetaRingMax
float thetaRingMax
Definition: TIDLayer.h:64
align::PositionType
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:28
TIDLayer::RingPar::theRingR
float theRingR
Definition: TIDLayer.h:64
oppositeToMomentum
Definition: PropagationDirection.h:4
particleFlowClusterHGC_cfi.maxDistance
maxDistance
Definition: particleFlowClusterHGC_cfi.py:23
TIDLayer::computeWindowSize
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
Definition: TIDLayer.cc:260
mps_check.array
array
Definition: mps_check.py:216
TrajectoryStateOnSurface::transverseCurvature
double transverseCurvature() const
Definition: TrajectoryStateOnSurface.h:70
perp
T perp() const
Magnitude of transverse component.
Definition: Basic3DVectorLD.h:133
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
SiStripMonitorCluster_cfi.zmin
zmin
Definition: SiStripMonitorCluster_cfi.py:200
BoundDisk
DetWithState
GeometricSearchDet::DetWithState DetWithState
Definition: TIDLayer.cc:17
TIDRing::groupedCompatibleDetsV
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
Definition: TIDRing.cc:67
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
SimpleDiskBounds
Definition: SimpleDiskBounds.h:11
Propagator
Definition: Propagator.h:44
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
DetLayerException.h
L1TOccupancyClient_cfi.ymax
ymax
Definition: L1TOccupancyClient_cfi.py:43
SiStripMonitorCluster_cfi.zmax
zmax
Definition: SiStripMonitorCluster_cfi.py:201
Propagator::propagationDirection
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
TIDLayer::ringPars
RingPar ringPars[3]
Definition: TIDLayer.h:66
Vector2DBase
Definition: Vector2DBase.h:8
DetGroupMerger.h
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
DDAxes::rho
funct::true
true
Definition: Factorize.h:173
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:223
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
Local2DVector
Vector2DBase< float, LocalTag > Local2DVector
Definition: FourPointPlaneBounds.h:8
DetGroupElement
Definition: DetGroup.h:10
RingedForwardLayer
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
GeometricSearchDet::DetWithState
std::pair< const GeomDet *, TrajectoryStateOnSurface > DetWithState
Definition: GeometricSearchDet.h:19
DetLayerException
Common base class.
Definition: DetLayerException.h:15
TrajectoryStateOnSurface::globalMomentum
GlobalVector globalMomentum() const
Definition: TrajectoryStateOnSurface.h:66
DetGroupMerger
Definition: DetGroupMerger.h:7
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TIDLayer::theComponents
std::atomic< std::vector< const GeometricSearchDet * > * > theComponents
Definition: TIDLayer.h:61
TIDLayer::overlapInR
bool overlapInR(const TrajectoryStateOnSurface &tsos, int i, double ymax) const __attribute__((hot))
Definition: TIDLayer.cc:301
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
Plane
Definition: Plane.h:16
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
TIDLayer::components
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Definition: TIDLayer.cc:79
TIDLayer::TIDLayer
TIDLayer(std::vector< const TIDRing * > &rings) __attribute__((cold))
Definition: TIDLayer.cc:104
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
TIDLayer.h
mps_fire.result
result
Definition: mps_fire.py:311
HelixForwardPlaneCrossing
Definition: HelixForwardPlaneCrossing.h:13
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
TIDLayer::findClosest
int findClosest(const GlobalPoint[3]) const __attribute__((hot))
Definition: TIDLayer.cc:268
SimpleDiskBounds.h
TIDLayer::findNextIndex
int findNextIndex(const GlobalPoint[3], int) const __attribute__((hot))
Definition: TIDLayer.cc:283
BoundDisk
Disk BoundDisk
Definition: BoundDisk.h:54
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
alongMomentum
Definition: PropagationDirection.h:4
Basic3DVector< float >
HelixForwardPlaneCrossing.h
HLT_FULL_cff.Merger
Merger
Definition: HLT_FULL_cff.py:7261
MeasurementEstimator::maximalLocalDisplacement
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0