CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SegmentUtils.cc
Go to the documentation of this file.
3 
5 
6 #include <cmath>
7 
8 namespace fireworks {
9  void createSegment(int detector,
10  bool matchedSegment,
11  float segmentLength,
12  float segmentLimit,
13  float* segmentPosition,
14  float* segmentDirection,
15  float* segmentInnerPoint,
16  float* segmentOuterPoint) {
17  if (detector == MuonSubdetId::CSC || detector == MuonSubdetId::GEM || detector == MuonSubdetId::ME0) {
18  if (matchedSegment) {
19  segmentOuterPoint[0] = segmentPosition[0] + segmentLength * segmentDirection[0];
20  segmentOuterPoint[1] = segmentPosition[1] + segmentLength * segmentDirection[1];
21  segmentOuterPoint[2] = segmentLength;
22 
23  if (fabs(segmentOuterPoint[1]) > segmentLimit)
24  segmentOuterPoint[1] = segmentLimit * (segmentOuterPoint[1] / fabs(segmentOuterPoint[1]));
25 
26  segmentInnerPoint[0] = segmentPosition[0] - segmentLength * segmentDirection[0];
27  segmentInnerPoint[1] = segmentPosition[1] - segmentLength * segmentDirection[1];
28  segmentInnerPoint[2] = -segmentLength;
29 
30  if (fabs(segmentInnerPoint[1]) > segmentLimit)
31  segmentInnerPoint[1] = segmentLimit * (segmentInnerPoint[1] / fabs(segmentInnerPoint[1]));
32 
33  return;
34  } else {
35  segmentOuterPoint[0] = segmentPosition[0] + segmentDirection[0] * (segmentPosition[2] / segmentDirection[2]);
36  segmentOuterPoint[1] = segmentPosition[1] + segmentDirection[1] * (segmentPosition[2] / segmentDirection[2]);
37  segmentOuterPoint[2] = segmentPosition[2];
38 
39  if (fabs(segmentOuterPoint[1]) > segmentLength)
40  segmentOuterPoint[1] = segmentLength * (segmentOuterPoint[1] / fabs(segmentOuterPoint[1]));
41 
42  segmentInnerPoint[0] = segmentPosition[0] - segmentDirection[0] * (segmentPosition[2] / segmentDirection[2]);
43  segmentInnerPoint[1] = segmentPosition[1] - segmentDirection[1] * (segmentPosition[2] / segmentDirection[2]);
44  segmentInnerPoint[2] = -segmentPosition[2];
45 
46  if (fabs(segmentInnerPoint[1]) > segmentLength)
47  segmentInnerPoint[1] = segmentLength * (segmentInnerPoint[1] / fabs(segmentInnerPoint[1]));
48 
49  return;
50  }
51  }
52 
53  if (detector == MuonSubdetId::DT) {
54  if (matchedSegment) {
55  segmentOuterPoint[0] = segmentPosition[0] + segmentLength * segmentDirection[0];
56  segmentOuterPoint[1] = segmentPosition[1] + segmentLength * segmentDirection[1];
57  segmentOuterPoint[2] = segmentLength;
58 
59  segmentInnerPoint[0] = segmentPosition[0] - segmentLength * segmentDirection[0];
60  segmentInnerPoint[1] = segmentPosition[1] - segmentLength * segmentDirection[1];
61  segmentInnerPoint[2] = -segmentLength;
62 
63  return;
64  } else {
65  double mag = sqrt(segmentDirection[0] * segmentDirection[0] + segmentDirection[1] * segmentDirection[1] +
66  segmentDirection[2] * segmentDirection[2]);
67 
68  double theta =
69  atan2(sqrt(segmentDirection[0] * segmentDirection[0] + segmentDirection[1] * segmentDirection[1]),
70  segmentDirection[2]);
71 
72  double newSegmentLength = segmentLength / cos(theta);
73 
74  segmentInnerPoint[0] = segmentPosition[0] + (segmentDirection[0] / mag) * newSegmentLength;
75  segmentInnerPoint[1] = segmentPosition[1] + (segmentDirection[1] / mag) * newSegmentLength;
76  segmentInnerPoint[2] = segmentPosition[2] + (segmentDirection[2] / mag) * newSegmentLength;
77 
78  segmentOuterPoint[0] = segmentPosition[0] - (segmentDirection[0] / mag) * newSegmentLength;
79  segmentOuterPoint[1] = segmentPosition[1] - (segmentDirection[1] / mag) * newSegmentLength;
80  segmentOuterPoint[2] = segmentPosition[2] - (segmentDirection[2] / mag) * newSegmentLength;
81 
82  if (fabs(segmentOuterPoint[0]) > segmentLimit) {
83  segmentOuterPoint[0] = segmentLimit * (segmentOuterPoint[0] / fabs(segmentOuterPoint[0]));
84  segmentOuterPoint[1] = (segmentOuterPoint[1] / fabs(segmentOuterPoint[1])) * tan(theta);
85  }
86 
87  return;
88  }
89  }
90 
91  fwLog(fwlog::kWarning) << "MuonSubdetId: " << detector << std::endl;
92  return;
93  }
94 
95 } // namespace fireworks
static constexpr int GEM
Definition: MuonSubdetId.h:14
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Theta< T > theta() const
void createSegment(int detector, bool matchedSegment, float segmentLength, float segmentLimit, float *segmentPosition, float *segmentDirection, float *segmentInnerPoint, float *segmentOuterPoint)
Definition: SegmentUtils.cc:9
T sqrt(T t)
Definition: SSEVec.h:19
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
static constexpr int ME0
Definition: MuonSubdetId.h:15
#define fwLog(_level_)
Definition: fwLog.h:45
static constexpr int DT
Definition: MuonSubdetId.h:11
static constexpr int CSC
Definition: MuonSubdetId.h:12