CMS 3D CMS Logo

Phase2EndcapLayer.cc
Go to the documentation of this file.
1 #include "Phase2EndcapLayer.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 //hopefully is never called!
20 const std::vector<const GeometricSearchDet*>& Phase2EndcapLayer::components() const {
21  if (not theComponents) {
22  auto temp = std::make_unique<std::vector<const GeometricSearchDet*>>();
23  temp->reserve(15); // This number is just an upper bound
24  for (auto c : theComps)
25  temp->push_back(c);
26  std::vector<const GeometricSearchDet*>* expected = nullptr;
27  if (theComponents.compare_exchange_strong(expected, temp.get())) {
28  //this thread set the value
29  temp.release();
30  }
31  }
32  return *theComponents;
33 }
34 
36  const BoundDisk& ringDisk = static_cast<const BoundDisk&>(theComps[i]->surface());
37  float ringMinZ = std::abs(ringDisk.position().z()) - ringDisk.bounds().thickness() / 2.;
38  float ringMaxZ = std::abs(ringDisk.position().z()) + ringDisk.bounds().thickness() / 2.;
39  RingPar tempPar;
40  tempPar.thetaRingMin = ringDisk.innerRadius() / ringMaxZ;
41  tempPar.thetaRingMax = ringDisk.outerRadius() / ringMinZ;
42  tempPar.theRingR = (ringDisk.innerRadius() + ringDisk.outerRadius()) / 2.;
43  ringPars.push_back(tempPar);
44 }
45 
46 Phase2EndcapLayer::Phase2EndcapLayer(vector<const Phase2EndcapRing*>& rings, const bool isOT)
47  : RingedForwardLayer(true), isOuterTracker(isOT), theComponents{nullptr} {
48  //They should be already R-ordered. TO BE CHECKED!!
49  //sort( theRings.begin(), theRings.end(), DetLessR());
50 
51  theRingSize = rings.size();
52  LogDebug("TkDetLayers") << "Number of rings in Phase2 OT EC layer is " << theRingSize << std::endl;
53  setSurface(computeDisk(rings));
54 
55  for (unsigned int i = 0; i != rings.size(); ++i) {
56  theComps.push_back(rings[i]);
57  fillRingPars(i);
58  theBasicComps.insert(
59  theBasicComps.end(), (*rings[i]).basicComponents().begin(), (*rings[i]).basicComponents().end());
60  }
61 
62  LogDebug("TkDetLayers") << "==== DEBUG Phase2EndcapLayer =====";
63  LogDebug("TkDetLayers") << "r,zed pos , thickness, innerR, outerR: " << this->position().perp() << " , "
64  << this->position().z() << " , " << this->specificSurface().bounds().thickness() << " , "
65  << this->specificSurface().innerRadius() << " , " << this->specificSurface().outerRadius();
66 }
67 
68 BoundDisk* Phase2EndcapLayer::computeDisk(const vector<const Phase2EndcapRing*>& rings) const {
69  float theRmin = rings.front()->specificSurface().innerRadius();
70  float theRmax = rings.front()->specificSurface().outerRadius();
71  float theZmin = rings.front()->position().z() - rings.front()->surface().bounds().thickness() / 2;
72  float theZmax = rings.front()->position().z() + rings.front()->surface().bounds().thickness() / 2;
73 
74  for (vector<const Phase2EndcapRing*>::const_iterator i = rings.begin(); i != rings.end(); i++) {
75  float rmin = (**i).specificSurface().innerRadius();
76  float rmax = (**i).specificSurface().outerRadius();
77  float zmin = (**i).position().z() - (**i).surface().bounds().thickness() / 2.;
78  float zmax = (**i).position().z() + (**i).surface().bounds().thickness() / 2.;
79  theRmin = min(theRmin, rmin);
80  theRmax = max(theRmax, rmax);
81  theZmin = min(theZmin, zmin);
82  theZmax = max(theZmax, zmax);
83  }
84 
85  float zPos = (theZmax + theZmin) / 2.;
86  PositionType pos(0., 0., zPos);
88 
89  return new BoundDisk(pos, rot, new SimpleDiskBounds(theRmin, theRmax, theZmin - zPos, theZmax - zPos));
90 }
91 
93  for (auto c : theComps)
94  delete c;
95 
96  delete theComponents.load();
97 }
98 
100  const Propagator& prop,
101  const MeasurementEstimator& est,
102  std::vector<DetGroup>& result) const {
103  std::array<int, 3> const& ringIndices = ringIndicesByCrossingProximity(startingState, prop);
104  if (ringIndices[0] == -1 || ringIndices[1] == -1 || ringIndices[2] == -1) {
105  edm::LogError("TkDetLayers") << "TkRingedForwardLayer::groupedCompatibleDets : error in CrossingProximity";
106  return;
107  }
108 
109  //order is: rings in front = 0; rings in back = 1
110  //rings should be already ordered in r
111  //if the layer has 1 ring, it does not matter
112  //FIXME: to be optimized once the geometry is stable
113  std::vector<int> ringOrder(theRingSize);
114  std::fill(ringOrder.begin(), ringOrder.end(), 1);
115  if (theRingSize > 1) {
116  if (fabs(theComps[0]->position().z()) < fabs(theComps[1]->position().z())) {
117  for (int i = 0; i < theRingSize; i++) {
118  if (i % 2 == 0)
119  ringOrder[i] = 0;
120  }
121  } else if (fabs(theComps[0]->position().z()) > fabs(theComps[1]->position().z())) {
122  std::fill(ringOrder.begin(), ringOrder.end(), 0);
123  for (int i = 0; i < theRingSize; i++) {
124  if (i % 2 == 0)
125  ringOrder[i] = 1;
126  }
127  } else {
128  throw DetLayerException("Rings in Endcap Layer have same z position, no idea how to order them!");
129  }
130  }
131 
132  auto index = [&ringIndices, &ringOrder](int i) { return ringOrder[ringIndices[i]]; };
133 
134  std::vector<DetGroup> closestResult;
135  theComps[ringIndices[0]]->groupedCompatibleDetsV(startingState, prop, est, closestResult);
136  // if the closest is empty, use the next one and exit: inherited from TID !
137  if (closestResult.empty()) {
138  theComps[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, result);
139  return;
140  }
141 
142  DetGroupElement closestGel(closestResult.front().front());
143  float rWindow = computeWindowSize(closestGel.det(), closestGel.trajectoryState(), est);
144 
145  // check if next ring and next next ring are found and if there is overlap
146 
147  bool ring1ok = ringIndices[1] != -1 && overlapInR(closestGel.trajectoryState(), ringIndices[1], rWindow);
148  bool ring2ok = ringIndices[2] != -1 && overlapInR(closestGel.trajectoryState(), ringIndices[2], rWindow);
149 
150  // look for the two rings in the same plane (are they only two?)
151 
152  // determine if we are propagating from in to out (0) or from out to in (1)
153 
154  int direction = 0;
155  if (startingState.globalPosition().z() * startingState.globalMomentum().z() > 0) {
156  if (prop.propagationDirection() == alongMomentum)
157  direction = 0;
158  else
159  direction = 1;
160  } else {
161  if (prop.propagationDirection() == alongMomentum)
162  direction = 1;
163  else
164  direction = 0;
165  }
166 
167  if ((index(0) == index(1)) && (index(0) == index(2))) {
168  edm::LogInfo("AllRingsInOnePlane") << " All rings: " << ringIndices[0] << " " << ringIndices[1] << " "
169  << ringIndices[2] << " in one plane. Only the first two will be considered";
170  ring2ok = false;
171  }
172 
173  if (index(0) == index(1)) {
174  if (ring1ok) {
175  std::vector<DetGroup> ring1res;
176  theComps[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, ring1res);
177  DetGroupMerger::addSameLevel(std::move(ring1res), closestResult);
178  }
179  if (ring2ok) {
180  std::vector<DetGroup> ring2res;
181  theComps[ringIndices[2]]->groupedCompatibleDetsV(startingState, prop, est, ring2res);
183  std::move(closestResult), std::move(ring2res), result, index(0), direction);
184  return;
185  } else {
186  result.swap(closestResult);
187  return;
188  }
189  } else if (index(0) == index(2)) {
190  if (ring2ok) {
191  std::vector<DetGroup> ring2res;
192  theComps[ringIndices[2]]->groupedCompatibleDetsV(startingState, prop, est, ring2res);
193  DetGroupMerger::addSameLevel(std::move(ring2res), closestResult);
194  }
195  if (ring1ok) {
196  std::vector<DetGroup> ring1res;
197  theComps[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, ring1res);
199  std::move(closestResult), std::move(ring1res), result, index(0), direction);
200  return;
201  } else {
202  result.swap(closestResult);
203  return;
204  }
205  } else {
206  std::vector<DetGroup> ring12res;
207  if (ring1ok) {
208  std::vector<DetGroup> ring1res;
209  theComps[ringIndices[1]]->groupedCompatibleDetsV(startingState, prop, est, ring1res);
210  ring12res.swap(ring1res);
211  }
212  if (ring2ok) {
213  std::vector<DetGroup> ring2res;
214  theComps[ringIndices[2]]->groupedCompatibleDetsV(startingState, prop, est, ring2res);
215  DetGroupMerger::addSameLevel(std::move(ring2res), ring12res);
216  }
217  if (!ring12res.empty()) {
219  std::move(closestResult), std::move(ring12res), result, index(0), direction);
220  return;
221  } else {
222  result.swap(closestResult);
223  return;
224  }
225  }
226 }
227 
229  const Propagator& prop) const {
230  typedef HelixForwardPlaneCrossing Crossing;
232 
233  HelixPlaneCrossing::PositionType startPos(startingState.globalPosition());
234  HelixPlaneCrossing::DirectionType startDir(startingState.globalMomentum());
236  float rho(startingState.transverseCurvature());
237 
238  // calculate the crossings with the ring surfaces
239  // rings are assumed to be sorted in R !
240 
241  Crossing myXing(startPos, startDir, rho, propDir);
242 
243  std::vector<GlobalPoint> ringCrossings;
244  ringCrossings.reserve(theRingSize);
245  // vector<GlobalVector> ringXDirections;
246 
247  for (int i = 0; i < theRingSize; i++) {
248  const BoundDisk& theRing = static_cast<const BoundDisk&>(theComps[i]->surface());
249  pair<bool, double> pathlen = myXing.pathLength(theRing);
250  if (pathlen.first) {
251  ringCrossings.push_back(GlobalPoint(myXing.position(pathlen.second)));
252  // ringXDirections.push_back( GlobalVector( myXing.direction(pathlen.second )));
253  } else {
254  // TO FIX.... perhaps there is something smarter to do
255  //throw DetLayerException("trajectory doesn't cross TID rings");
256  ringCrossings.push_back(GlobalPoint(0., 0., 0.));
257  // ringXDirections.push_back( GlobalVector( 0.,0.,0.));
258  }
259  }
260 
261  //find three closest rings to the crossing
262 
263  std::array<int, 3> closests = findThreeClosest(ringCrossings);
264 
265  return closests;
266 }
267 
269  const TrajectoryStateOnSurface& tsos,
270  const MeasurementEstimator& est) const {
271  const Plane& startPlane = det->surface();
273  return maxDistance.y();
274 }
275 
276 std::array<int, 3> Phase2EndcapLayer::findThreeClosest(std::vector<GlobalPoint> ringCrossing) const {
277  std::array<int, 3> theBins = {{-1, -1, -1}};
278  theBins[0] = 0;
279  float initialR = ringPars[0].theRingR;
280  float rDiff0 = std::abs(ringCrossing[0].perp() - initialR);
281  float rDiff1 = -1.;
282  float rDiff2 = -1.;
283  for (int i = 1; i < theRingSize; i++) {
284  float ringR = ringPars[i].theRingR;
285  float testDiff = std::abs(ringCrossing[i].perp() - ringR);
286  if (testDiff < rDiff0) {
287  rDiff2 = rDiff1;
288  rDiff1 = rDiff0;
289  rDiff0 = testDiff;
290  theBins[2] = theBins[1];
291  theBins[1] = theBins[0];
292  theBins[0] = i;
293  } else if (rDiff1 < 0 || testDiff < rDiff1) {
294  rDiff2 = rDiff1;
295  rDiff1 = testDiff;
296  theBins[2] = theBins[1];
297  theBins[1] = i;
298  } else if (rDiff2 < 0 || testDiff < rDiff2) {
299  rDiff2 = testDiff;
300  theBins[2] = i;
301  }
302  }
303 
304  return theBins;
305 }
306 
307 bool Phase2EndcapLayer::overlapInR(const TrajectoryStateOnSurface& tsos, int index, double ymax) const {
308  // assume "fixed theta window", i.e. margin in local y = r is changing linearly with z
309  float tsRadius = tsos.globalPosition().perp();
310  float thetamin = (max(0., tsRadius - ymax)) / (std::abs(tsos.globalPosition().z()) + 10.f); // add 10 cm contingency
311  float thetamax = (tsRadius + ymax) / (std::abs(tsos.globalPosition().z()) - 10.f);
312 
313  // do the theta regions overlap ?
314 
315  return !(thetamin > ringPars[index].thetaRingMax || ringPars[index].thetaRingMin > thetamax);
316 }
MeasurementEstimator
Definition: MeasurementEstimator.h:19
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
GeomDet
Definition: GeomDet.h:27
align::RotationType
TkRotation< Scalar > RotationType
Definition: Definitions.h:27
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
Phase2EndcapLayer::fillRingPars
void fillRingPars(int i) __attribute__((cold))
Definition: Phase2EndcapLayer.cc:35
min
T min(T a, T b)
Definition: MathUtil.h:58
Phase2EndcapLayer::overlapInR
bool overlapInR(const TrajectoryStateOnSurface &tsos, int i, double ymax) const __attribute__((hot))
Definition: Phase2EndcapLayer.cc:307
TrajectoryStateOnSurface::globalPosition
GlobalPoint globalPosition() const
Definition: TrajectoryStateOnSurface.h:65
Phase2EndcapLayer::computeWindowSize
float computeWindowSize(const GeomDet *det, const TrajectoryStateOnSurface &tsos, const MeasurementEstimator &est) const __attribute__((hot))
Definition: Phase2EndcapLayer.cc:268
pos
Definition: PixelAliasList.h:18
edm::LogInfo
Definition: MessageLogger.h:254
Phase2EndcapLayer::findThreeClosest
std::array< int, 3 > findThreeClosest(std::vector< GlobalPoint >) const __attribute__((hot))
Definition: Phase2EndcapLayer.cc:276
align::PositionType
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:28
particleFlowClusterHGC_cfi.maxDistance
maxDistance
Definition: particleFlowClusterHGC_cfi.py:23
Phase2EndcapLayer::theComps
std::vector< const Phase2EndcapRing * > theComps
Definition: Phase2EndcapLayer.h:67
TrajectoryStateOnSurface::transverseCurvature
double transverseCurvature() const
Definition: TrajectoryStateOnSurface.h:70
Phase2EndcapLayer::groupedCompatibleDetsV
void groupedCompatibleDetsV(const TrajectoryStateOnSurface &tsos, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetGroup > &result) const override __attribute__((hot))
Definition: Phase2EndcapLayer.cc:99
perp
T perp() const
Magnitude of transverse component.
Definition: Basic3DVectorLD.h:133
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
SiStripMonitorCluster_cfi.zmin
zmin
Definition: SiStripMonitorCluster_cfi.py:200
BoundDisk
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
Phase2EndcapLayer::theComponents
std::atomic< std::vector< const GeometricSearchDet * > * > theComponents
Definition: Phase2EndcapLayer.h:66
L1TOccupancyClient_cfi.ymax
ymax
Definition: L1TOccupancyClient_cfi.py:43
SiStripMonitorCluster_cfi.zmax
zmax
Definition: SiStripMonitorCluster_cfi.py:201
Phase2EndcapLayer::~Phase2EndcapLayer
~Phase2EndcapLayer() override __attribute__((cold))
Definition: Phase2EndcapLayer.cc:92
Propagator::propagationDirection
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
DDAxes::z
DetWithState
GeometricSearchDet::DetWithState DetWithState
Definition: Phase2EndcapLayer.cc:17
Vector2DBase
Definition: Vector2DBase.h:8
Phase2EndcapLayer::RingPar::thetaRingMax
float thetaRingMax
Definition: Phase2EndcapLayer.h:69
DetGroupMerger.h
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
DDAxes::rho
DetGroupMerger::orderAndMergeTwoLevels
static void orderAndMergeTwoLevels(std::vector< DetGroup > &&one, std::vector< DetGroup > &&two, std::vector< DetGroup > &result, int firstIndex, int firstCrossed)
Definition: DetGroupMerger.cc:6
Phase2EndcapLayer.h
funct::true
true
Definition: Factorize.h:173
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
Phase2EndcapLayer::theRingSize
int theRingSize
Definition: Phase2EndcapLayer.h:72
edm::LogError
Definition: MessageLogger.h:183
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
Phase2EndcapLayer::RingPar::thetaRingMin
float thetaRingMin
Definition: Phase2EndcapLayer.h:69
GeomDetEnumerators::isOuterTracker
bool isOuterTracker(GeomDetEnumerators::SubDetector m)
Definition: GeomDetEnumerators.cc:78
Phase2EndcapLayer::computeDisk
BoundDisk * computeDisk(const std::vector< const Phase2EndcapRing * > &rings) const __attribute__((cold))
Definition: Phase2EndcapLayer.cc:68
Phase2EndcapLayer::Phase2EndcapLayer
Phase2EndcapLayer(std::vector< const Phase2EndcapRing * > &rings, const bool isOT) __attribute__((cold))
Definition: Phase2EndcapLayer.cc:46
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
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
Phase2EndcapLayer::ringPars
std::vector< RingPar > ringPars
Definition: Phase2EndcapLayer.h:71
Phase2EndcapLayer::RingPar
Definition: Phase2EndcapLayer.h:68
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
PropagationDirection
PropagationDirection
Definition: PropagationDirection.h:4
Plane
Definition: Plane.h:16
makeMuonMisalignmentScenario.rot
rot
Definition: makeMuonMisalignmentScenario.py:322
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
mps_fire.result
result
Definition: mps_fire.py:303
HelixForwardPlaneCrossing
Definition: HelixForwardPlaneCrossing.h:13
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
SimpleDiskBounds.h
Phase2EndcapLayer::RingPar::theRingR
float theRingR
Definition: Phase2EndcapLayer.h:69
DetGroupMerger::addSameLevel
static void addSameLevel(std::vector< DetGroup > &&gvec, std::vector< DetGroup > &result)
Definition: DetGroupMerger.cc:47
BoundDisk
Disk BoundDisk
Definition: BoundDisk.h:54
Phase2EndcapLayer::ringIndicesByCrossingProximity
std::array< int, 3 > ringIndicesByCrossingProximity(const TrajectoryStateOnSurface &startingState, const Propagator &prop) const
Definition: Phase2EndcapLayer.cc:228
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
alongMomentum
Definition: PropagationDirection.h:4
Phase2EndcapLayer::components
const std::vector< const GeometricSearchDet * > & components() const override __attribute__((cold))
Definition: Phase2EndcapLayer.cc:20
Basic3DVector< float >
HelixForwardPlaneCrossing.h
MeasurementEstimator::maximalLocalDisplacement
virtual Local2DVector maximalLocalDisplacement(const TrajectoryStateOnSurface &ts, const Plane &plane) const =0