File indexing completed on 2024-04-06 12:11:50
0001 #include "Fireworks/Muons/interface/SegmentUtils.h"
0002 #include "Fireworks/Core/interface/fwLog.h"
0003
0004 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
0005
0006 #include <cmath>
0007
0008 namespace fireworks {
0009 void createSegment(int detector,
0010 bool matchedSegment,
0011 float segmentLength,
0012 float segmentLimit,
0013 float* segmentPosition,
0014 float* segmentDirection,
0015 float* segmentInnerPoint,
0016 float* segmentOuterPoint) {
0017 if (detector == MuonSubdetId::CSC || detector == MuonSubdetId::GEM || detector == MuonSubdetId::ME0) {
0018 if (matchedSegment) {
0019 segmentOuterPoint[0] = segmentPosition[0] + segmentLength * segmentDirection[0];
0020 segmentOuterPoint[1] = segmentPosition[1] + segmentLength * segmentDirection[1];
0021 segmentOuterPoint[2] = segmentLength;
0022
0023 if (fabs(segmentOuterPoint[1]) > segmentLimit)
0024 segmentOuterPoint[1] = segmentLimit * (segmentOuterPoint[1] / fabs(segmentOuterPoint[1]));
0025
0026 segmentInnerPoint[0] = segmentPosition[0] - segmentLength * segmentDirection[0];
0027 segmentInnerPoint[1] = segmentPosition[1] - segmentLength * segmentDirection[1];
0028 segmentInnerPoint[2] = -segmentLength;
0029
0030 if (fabs(segmentInnerPoint[1]) > segmentLimit)
0031 segmentInnerPoint[1] = segmentLimit * (segmentInnerPoint[1] / fabs(segmentInnerPoint[1]));
0032
0033 return;
0034 } else {
0035 segmentOuterPoint[0] = segmentPosition[0] + segmentDirection[0] * (segmentPosition[2] / segmentDirection[2]);
0036 segmentOuterPoint[1] = segmentPosition[1] + segmentDirection[1] * (segmentPosition[2] / segmentDirection[2]);
0037 segmentOuterPoint[2] = segmentPosition[2];
0038
0039 if (fabs(segmentOuterPoint[1]) > segmentLength)
0040 segmentOuterPoint[1] = segmentLength * (segmentOuterPoint[1] / fabs(segmentOuterPoint[1]));
0041
0042 segmentInnerPoint[0] = segmentPosition[0] - segmentDirection[0] * (segmentPosition[2] / segmentDirection[2]);
0043 segmentInnerPoint[1] = segmentPosition[1] - segmentDirection[1] * (segmentPosition[2] / segmentDirection[2]);
0044 segmentInnerPoint[2] = -segmentPosition[2];
0045
0046 if (fabs(segmentInnerPoint[1]) > segmentLength)
0047 segmentInnerPoint[1] = segmentLength * (segmentInnerPoint[1] / fabs(segmentInnerPoint[1]));
0048
0049 return;
0050 }
0051 }
0052
0053 if (detector == MuonSubdetId::DT) {
0054 if (matchedSegment) {
0055 segmentOuterPoint[0] = segmentPosition[0] + segmentLength * segmentDirection[0];
0056 segmentOuterPoint[1] = segmentPosition[1] + segmentLength * segmentDirection[1];
0057 segmentOuterPoint[2] = segmentLength;
0058
0059 segmentInnerPoint[0] = segmentPosition[0] - segmentLength * segmentDirection[0];
0060 segmentInnerPoint[1] = segmentPosition[1] - segmentLength * segmentDirection[1];
0061 segmentInnerPoint[2] = -segmentLength;
0062
0063 return;
0064 } else {
0065 double mag = sqrt(segmentDirection[0] * segmentDirection[0] + segmentDirection[1] * segmentDirection[1] +
0066 segmentDirection[2] * segmentDirection[2]);
0067
0068 double theta =
0069 atan2(sqrt(segmentDirection[0] * segmentDirection[0] + segmentDirection[1] * segmentDirection[1]),
0070 segmentDirection[2]);
0071
0072 double newSegmentLength = segmentLength / cos(theta);
0073
0074 segmentInnerPoint[0] = segmentPosition[0] + (segmentDirection[0] / mag) * newSegmentLength;
0075 segmentInnerPoint[1] = segmentPosition[1] + (segmentDirection[1] / mag) * newSegmentLength;
0076 segmentInnerPoint[2] = segmentPosition[2] + (segmentDirection[2] / mag) * newSegmentLength;
0077
0078 segmentOuterPoint[0] = segmentPosition[0] - (segmentDirection[0] / mag) * newSegmentLength;
0079 segmentOuterPoint[1] = segmentPosition[1] - (segmentDirection[1] / mag) * newSegmentLength;
0080 segmentOuterPoint[2] = segmentPosition[2] - (segmentDirection[2] / mag) * newSegmentLength;
0081
0082 if (fabs(segmentOuterPoint[0]) > segmentLimit) {
0083 segmentOuterPoint[0] = segmentLimit * (segmentOuterPoint[0] / fabs(segmentOuterPoint[0]));
0084 segmentOuterPoint[1] = (segmentOuterPoint[1] / fabs(segmentOuterPoint[1])) * tan(theta);
0085 }
0086
0087 return;
0088 }
0089 }
0090
0091 fwLog(fwlog::kWarning) << "MuonSubdetId: " << detector << std::endl;
0092 return;
0093 }
0094
0095 }