28 int iSection, iLayer, iSector, iPlane, iSegment, iStrip, sector, segment;
29 int nSections, nLayers, nSectors, nPlanes, nStrips, nSegments, nStripsSegment;
34 nSections =
m_GeoDat->getNSections();
39 nSegments =
m_GeoDat->getNSegments();
41 m_Section =
new HepGeom::Transform3D[nSections];
42 m_Layer =
new HepGeom::Transform3D*[nSections];
43 m_Sector =
new HepGeom::Transform3D** [nSections];
44 m_Plane =
new HepGeom::Transform3D** *[nSections];
46 m_Segment =
new HepGeom::Transform3D**** [nSections];
47 m_Strip =
new HepGeom::Transform3D**** [nSections];
49 for (iSection = 0; iSection < nSections; iSection++) {
51 nDetectorLayers =
m_GeoDat->getNDetectorLayers(iSection + 1);
52 m_Layer[iSection] =
new HepGeom::Transform3D[nLayers];
53 m_Sector[iSection] =
new HepGeom::Transform3D*[nLayers];
54 m_Plane[iSection] =
new HepGeom::Transform3D** [nLayers];
56 m_Segment[iSection] =
new HepGeom::Transform3D** *[nLayers];
57 m_Strip[iSection] =
new HepGeom::Transform3D** *[nLayers];
59 for (iLayer = 0; iLayer < nLayers; iLayer++) {
61 m_Sector[iSection][iLayer] =
new HepGeom::Transform3D[nSectors];
62 if (iLayer < nDetectorLayers) {
63 m_Plane[iSection][iLayer] =
new HepGeom::Transform3D*[nSectors];
65 new HepGeom::Transform3D*[nSectors];
66 m_Segment[iSection][iLayer] =
new HepGeom::Transform3D** [nSectors];
67 m_Strip[iSection][iLayer] =
new HepGeom::Transform3D** [nSectors];
68 m_StripInverse[iSection][iLayer] =
new HepGeom::Transform3D** [nSectors];
70 for (iSector = 0; iSector < nSectors; iSector++) {
73 if (iLayer >= nDetectorLayers)
75 m_Plane[iSection][iLayer][iSector] =
new HepGeom::Transform3D[nPlanes];
77 new HepGeom::Transform3D[nPlanes];
79 new HepGeom::Transform3D*[nPlanes];
80 m_Strip[iSection][iLayer][iSector] =
new HepGeom::Transform3D*[nPlanes];
82 new HepGeom::Transform3D*[nPlanes];
83 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
85 &
m_Plane[iSection][iLayer][iSector][iPlane], iPlane);
87 HepGeom::Translate3D(0, 0, 0);
88 m_Segment[iSection][iLayer][iSector][iPlane] =
89 new HepGeom::Transform3D[nSegments];
90 for (iSegment = 0; iSegment < nSegments; iSegment++) {
91 m_Segment[iSection][iLayer][iSector][iPlane][iSegment] =
92 HepGeom::Translate3D(0, 0, 0);
94 m_Strip[iSection][iLayer][iSector][iPlane] =
95 new HepGeom::Transform3D[nStrips];
97 new HepGeom::Transform3D[nStrips];
98 for (iStrip = 0; iStrip < nStrips; iStrip++) {
100 &
m_Strip[iSection][iLayer][iSector][iPlane][iStrip], iStrip);
107 if (displacementType !=
c_None) {
108 std::string payload, segmentPayload;
110 payload =
"EKLMDisplacement";
111 segmentPayload =
"EKLMSegmentDisplacement";
113 payload =
"EKLMAlignment";
114 segmentPayload =
"EKLMSegmentAlignment";
118 if (!alignment.isValid())
119 B2FATAL(
"No EKLM displacement (alignment) data.");
121 if (!alignmentChecker.
checkAlignment(&(*alignment), &(*segmentAlignment)))
122 B2FATAL(
"EKLM displacement data are incorrect, overlaps exist.");
124 for (iSection = 1; iSection <= nSections; iSection++) {
125 nDetectorLayers =
m_GeoDat->getNDetectorLayers(iSection);
126 assert(nDetectorLayers <= nLayers);
127 for (iLayer = 1; iLayer <= nDetectorLayers; iLayer++) {
128 for (iSector = 1; iSector <= nSectors; iSector++) {
131 alignment->getModuleAlignment(sector);
132 if (sectorAlignment ==
nullptr)
133 B2FATAL(
"Incomplete EKLM displacement (alignment) data.");
134 for (iPlane = 1; iPlane <= nPlanes; iPlane++) {
139 HepGeom::Translate3D(
146 HepGeom::Translate3D(
152 for (iSegment = 1; iSegment <= nSegments; iSegment++) {
154 iSection, iLayer, iSector, iPlane, iSegment);
156 segmentAlignment->getSegmentAlignment(segment);
157 if (segmentAlignmentData ==
nullptr)
158 B2FATAL(
"Incomplete EKLM displacement (alignment) data.");
159 m_Segment[iSection - 1][iLayer - 1][iSector - 1][iPlane - 1]
161 HepGeom::Translate3D(
164 m_Segment[iSection - 1][iLayer - 1][iSector - 1][iPlane - 1]
168 for (iStrip = 1; iStrip <= nStripsSegment; iStrip++) {
169 m_Strip[iSection - 1][iLayer - 1][iSector - 1][iPlane - 1]
170 [nStripsSegment * (iSegment - 1) + iStrip - 1] =
171 HepGeom::Translate3D(
175 m_Strip[iSection - 1][iLayer - 1][iSector - 1][iPlane - 1]
176 [nStripsSegment * (iSegment - 1) + iStrip - 1] *
192 int iSection, iLayer, iSector, iPlane;
194 int nSections, nLayers, nDetectorLayers, nSectors, nPlanes;
195 nSections =
m_GeoDat->getNSections();
199 for (iSection = 0; iSection < nSections; iSection++) {
200 nDetectorLayers =
m_GeoDat->getNDetectorLayers(iSection + 1);
201 for (iLayer = 0; iLayer < nLayers; iLayer++) {
202 delete[]
m_Sector[iSection][iLayer];
203 if (iLayer >= nDetectorLayers)
205 for (iSector = 0; iSector < nSectors; iSector++) {
206 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
207 delete[]
m_Segment[iSection][iLayer][iSector][iPlane];
208 delete[]
m_Strip[iSection][iLayer][iSector][iPlane];
211 delete[]
m_Plane[iSection][iLayer][iSector];
213 delete[]
m_Segment[iSection][iLayer][iSector];
214 delete[]
m_Strip[iSection][iLayer][iSector];
217 delete[]
m_Plane[iSection][iLayer];
220 delete[]
m_Strip[iSection][iLayer];
243 int iSection, iLayer, iSector, iPlane, iSegment, iStrip;
245 int nSections, nLayers, nDetectorLayers, nSectors, nPlanes, nSegments, nStrips;
246 nSections =
m_GeoDat->getNSections();
250 nSegments =
m_GeoDat->getNSegments();
252 for (iSection = 0; iSection < nSections; iSection++) {
253 nDetectorLayers =
m_GeoDat->getNDetectorLayers(iSection + 1);
254 for (iLayer = 0; iLayer < nLayers; iLayer++) {
256 for (iSector = 0; iSector < nSectors; iSector++) {
257 m_Sector[iSection][iLayer][iSector] =
259 if (iLayer >= nDetectorLayers)
261 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
263 m_Plane[iSection][iLayer][iSector][iPlane] =
264 m_Sector[iSection][iLayer][iSector] *
265 m_Plane[iSection][iLayer][iSector][iPlane];
266 for (iSegment = 0; iSegment < nSegments; iSegment++) {
267 m_Segment[iSection][iLayer][iSector][iPlane][iSegment] =
268 m_Plane[iSection][iLayer][iSector][iPlane] *
270 m_Segment[iSection][iLayer][iSector][iPlane][iSegment];
272 for (iStrip = 0; iStrip < nStrips; iStrip++) {
273 m_Strip[iSection][iLayer][iSector][iPlane][iStrip] =
274 m_Plane[iSection][iLayer][iSector][iPlane] *
276 m_Strip[iSection][iLayer][iSector][iPlane][iStrip];
278 m_Strip[iSection][iLayer][iSector][iPlane][iStrip].inverse();
353 double* d1,
double* d2,
double* sd,
389 HepGeom::Vector3D<double> v1 = s1_2g - s1_1g;
390 HepGeom::Vector3D<double> v2 = s2_2g - s2_1g;
391 HepGeom::Vector3D<double> d = s1_1g - s2_1g;
392 double v1sq = v1.mag2();
393 double v2sq = v2.mag2();
394 double v1dv2 = v1.dot(v2);
395 double ddv1 = d.dot(v1);
396 double ddv2 = d.dot(v2);
397 double den = v1sq * v2sq - v1dv2 * v1dv2;
398 double t1 = (v1dv2 * ddv2 - v2sq * ddv1) / den;
399 double t2 = (- v1dv2 * ddv1 + v1sq * ddv2) / den;
402 if (t1 < 0.0 || t1 > 1.0)
404 if (t2 < 0.0 || t2 > 1.0)
410 *d1 = s1_2g.distance(s1_cg) / CLHEP::mm *
Unit::mm;
411 *d2 = s2_2g.distance(s2_cg) / CLHEP::mm *
Unit::mm;
412 *cross = 0.5 * (s1_cg + s2_cg) / CLHEP::mm *
Unit::mm;
413 *sd = s1_cg.distance(s2_cg) / CLHEP::mm *
Unit::mm;
414 if (s2_cg.mag2() < s1_cg.mag2())
447 int section, layer, sector, plane, segment, strip, stripSegment, stripGlobal;
449 int nLayers, nPlanes, nSegments, nStripsSegment, minDistanceSegment;
450 double solenoidCenter, firstLayerCenter, layerShift;
452 double x, y, z, l, minY, maxY;
453 double minDistance = 0, minDistanceNew, stripWidth;
462 (
m_GeoDat->getSectionPosition()->getZ()
463 - 0.5 *
m_GeoDat->getSectionPosition()->getLength()
465 - 0.5 *
m_GeoDat->getLayerPosition()->getLength()) /
469 layer = round((z - firstLayerCenter) / layerShift) + 1;
472 nLayers =
m_GeoDat->getNDetectorLayers(section);
477 nSegments =
m_GeoDat->getNSegments();
479 stripWidth =
m_GeoDat->getStripGeometry()->getWidth() / CLHEP::cm *
Unit::cm;
480 minY = -stripWidth / 2;
481 maxY = (double(nStripsSegment) - 0.5) * stripWidth;
482 for (plane = 1; plane <= nPlanes; plane++) {
483 minDistanceSegment = 1;
484 for (segment = 1; segment <= nSegments; segment++) {
485 strip = (segment - 1) * nStripsSegment;
487 [sector - 1][plane - 1][strip] * intersectionClhep;
488 y = intersectionLocal.y() / CLHEP::cm *
Unit::cm;
490 minDistanceNew = minY - y;
491 }
else if (y > maxY) {
492 minDistanceNew = y - maxY;
495 minDistanceSegment = segment;
499 minDistance = minDistanceNew;
500 }
else if (minDistanceNew < minDistance) {
501 minDistance = minDistanceNew;
502 minDistanceSegment = segment;
511 strip = (minDistanceSegment - 1) * nStripsSegment;
513 [sector - 1][plane - 1][strip] * intersectionClhep;
514 y = intersectionLocal.y() / CLHEP::cm *
Unit::cm;
515 stripSegment = ceil((y - 0.5 * stripWidth) / stripWidth);
516 if (stripSegment <= 0)
518 else if (stripSegment > nStripsSegment)
519 stripSegment = nStripsSegment;
520 strip = stripSegment + (minDistanceSegment - 1) * nStripsSegment;
522 [sector - 1][plane - 1][strip - 1] * intersectionClhep;
523 x = intersectionLocal.x();
524 l =
m_GeoDat->getStripLength(strip);
529 if (fabs(x) > 0.5 * l)
532 section, layer, sector, plane, strip);
534 *strip1 = stripGlobal;
536 *strip2 = stripGlobal;