12 #include <klm/eklm/geometry/TransformData.h>
15 #include <klm/dbobjects/eklm/EKLMAlignment.h>
16 #include <klm/dbobjects/eklm/EKLMSegmentAlignment.h>
17 #include <klm/eklm/geometry/AlignmentChecker.h>
18 #include <klm/eklm/geometry/GeometryData.h>
21 #include <framework/database/DBObjPtr.h>
22 #include <framework/logging/Logger.h>
23 #include <framework/gearbox/Unit.h>
30 int iSection, iLayer, iSector, iPlane, iSegment, iStrip, sector, segment;
31 int nSections, nLayers, nSectors, nPlanes, nStrips, nSegments, nStripsSegment;
43 m_Section =
new HepGeom::Transform3D[nSections];
44 m_Layer =
new HepGeom::Transform3D*[nSections];
45 m_Sector =
new HepGeom::Transform3D** [nSections];
46 m_Plane =
new HepGeom::Transform3D** *[nSections];
48 m_Segment =
new HepGeom::Transform3D**** [nSections];
49 m_Strip =
new HepGeom::Transform3D**** [nSections];
51 for (iSection = 0; iSection < nSections; iSection++) {
54 m_Layer[iSection] =
new HepGeom::Transform3D[nLayers];
55 m_Sector[iSection] =
new HepGeom::Transform3D*[nLayers];
56 m_Plane[iSection] =
new HepGeom::Transform3D** [nLayers];
58 m_Segment[iSection] =
new HepGeom::Transform3D** *[nLayers];
59 m_Strip[iSection] =
new HepGeom::Transform3D** *[nLayers];
61 for (iLayer = 0; iLayer < nLayers; iLayer++) {
63 m_Sector[iSection][iLayer] =
new HepGeom::Transform3D[nSectors];
64 if (iLayer < nDetectorLayers) {
65 m_Plane[iSection][iLayer] =
new HepGeom::Transform3D*[nSectors];
67 new HepGeom::Transform3D*[nSectors];
68 m_Segment[iSection][iLayer] =
new HepGeom::Transform3D** [nSectors];
69 m_Strip[iSection][iLayer] =
new HepGeom::Transform3D** [nSectors];
70 m_StripInverse[iSection][iLayer] =
new HepGeom::Transform3D** [nSectors];
72 for (iSector = 0; iSector < nSectors; iSector++) {
75 if (iLayer >= nDetectorLayers)
77 m_Plane[iSection][iLayer][iSector] =
new HepGeom::Transform3D[nPlanes];
79 new HepGeom::Transform3D[nPlanes];
81 new HepGeom::Transform3D*[nPlanes];
82 m_Strip[iSection][iLayer][iSector] =
new HepGeom::Transform3D*[nPlanes];
84 new HepGeom::Transform3D*[nPlanes];
85 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
87 &
m_Plane[iSection][iLayer][iSector][iPlane], iPlane);
89 HepGeom::Translate3D(0, 0, 0);
90 m_Segment[iSection][iLayer][iSector][iPlane] =
91 new HepGeom::Transform3D[nSegments];
92 for (iSegment = 0; iSegment < nSegments; iSegment++) {
93 m_Segment[iSection][iLayer][iSector][iPlane][iSegment] =
94 HepGeom::Translate3D(0, 0, 0);
96 m_Strip[iSection][iLayer][iSector][iPlane] =
97 new HepGeom::Transform3D[nStrips];
99 new HepGeom::Transform3D[nStrips];
100 for (iStrip = 0; iStrip < nStrips; iStrip++) {
102 &
m_Strip[iSection][iLayer][iSector][iPlane][iStrip], iStrip);
109 if (displacementType !=
c_None) {
110 std::string payload, segmentPayload;
112 payload =
"EKLMDisplacement";
113 segmentPayload =
"EKLMSegmentDisplacement";
115 payload =
"EKLMAlignment";
116 segmentPayload =
"EKLMSegmentAlignment";
120 if (!alignment.isValid())
121 B2FATAL(
"No EKLM displacement (alignment) data.");
123 if (!alignmentChecker.
checkAlignment(&(*alignment), &(*segmentAlignment)))
124 B2FATAL(
"EKLM displacement data are incorrect, overlaps exist.");
126 for (iSection = 1; iSection <= nSections; iSection++) {
128 for (iLayer = 1; iLayer <= nDetectorLayers; iLayer++) {
129 for (iSector = 1; iSector <= nSectors; iSector++) {
132 alignment->getModuleAlignment(sector);
133 if (sectorAlignment ==
nullptr)
134 B2FATAL(
"Incomplete EKLM displacement (alignment) data.");
135 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();
196 nLayers = m_GeoDat->getNLayers();
197 nSectors = m_GeoDat->getNSectors();
198 nPlanes = m_GeoDat->getNPlanes();
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];
209 delete[] m_StripInverse[iSection][iLayer][iSector][iPlane];
211 delete[] m_Plane[iSection][iLayer][iSector];
212 delete[] m_PlaneDisplacement[iSection][iLayer][iSector];
213 delete[] m_Segment[iSection][iLayer][iSector];
214 delete[] m_Strip[iSection][iLayer][iSector];
215 delete[] m_StripInverse[iSection][iLayer][iSector];
217 delete[] m_Plane[iSection][iLayer];
218 delete[] m_PlaneDisplacement[iSection][iLayer];
219 delete[] m_Segment[iSection][iLayer];
220 delete[] m_Strip[iSection][iLayer];
221 delete[] m_StripInverse[iSection][iLayer];
223 delete[] m_Layer[iSection];
224 delete[] m_Sector[iSection];
225 delete[] m_PlaneDisplacement[iSection];
226 delete[] m_Plane[iSection];
227 delete[] m_Segment[iSection];
228 delete[] m_Strip[iSection];
229 delete[] m_StripInverse[iSection];
234 delete[] m_PlaneDisplacement;
238 delete[] m_StripInverse;
243 int iSection, iLayer, iSector, iPlane, iSegment, iStrip;
245 int nSections, nLayers, nDetectorLayers, nSectors, nPlanes, nSegments, nStrips;
246 nSections = m_GeoDat->getNSections();
247 nLayers = m_GeoDat->getNLayers();
248 nSectors = m_GeoDat->getNSectors();
249 nPlanes = m_GeoDat->getNPlanes();
250 nSegments = m_GeoDat->getNSegments();
251 nStrips = m_GeoDat->getNStrips();
252 for (iSection = 0; iSection < nSections; iSection++) {
253 nDetectorLayers = m_GeoDat->getNDetectorLayers(iSection + 1);
254 for (iLayer = 0; iLayer < nLayers; iLayer++) {
255 m_Layer[iSection][iLayer] = m_Section[iSection] * m_Layer[iSection][iLayer];
256 for (iSector = 0; iSector < nSectors; iSector++) {
257 m_Sector[iSection][iLayer][iSector] =
258 m_Layer[iSection][iLayer] * m_Sector[iSection][iLayer][iSector];
259 if (iLayer >= nDetectorLayers)
261 for (iPlane = 0; iPlane < nPlanes; iPlane++) {
262 m_Plane[iSection][iLayer][iSector][iPlane] =
263 m_Sector[iSection][iLayer][iSector] *
264 m_Plane[iSection][iLayer][iSector][iPlane];
265 for (iSegment = 0; iSegment < nSegments; iSegment++) {
266 m_Segment[iSection][iLayer][iSector][iPlane][iSegment] =
267 m_Plane[iSection][iLayer][iSector][iPlane] *
268 m_PlaneDisplacement[iSection][iLayer][iSector][iPlane] *
269 m_Segment[iSection][iLayer][iSector][iPlane][iSegment];
271 for (iStrip = 0; iStrip < nStrips; iStrip++) {
272 m_Strip[iSection][iLayer][iSector][iPlane][iStrip] =
273 m_Plane[iSection][iLayer][iSector][iPlane] *
274 m_PlaneDisplacement[iSection][iLayer][iSector][iPlane] *
275 m_Strip[iSection][iLayer][iSector][iPlane][iStrip];
276 m_StripInverse[iSection][iLayer][iSector][iPlane][iStrip] =
277 m_Strip[iSection][iLayer][iSector][iPlane][iStrip].inverse();
285 const HepGeom::Transform3D*
288 return &m_Section[section - 1];
291 const HepGeom::Transform3D*
294 return &m_Layer[section - 1][layer - 1];
300 return &m_Sector[section - 1][layer - 1][sector - 1];
306 return &m_Plane[section - 1][layer - 1][sector - 1][plane - 1];
312 return &m_PlaneDisplacement[section - 1][layer - 1][sector - 1][plane - 1];
319 return &m_Segment[section - 1][layer - 1][sector - 1][plane - 1][segment - 1];
325 return &m_Strip[section - 1][layer - 1][sector - 1][plane - 1][strip - 1];
328 const HepGeom::Transform3D*
331 return &(m_Strip[hit->getSection() - 1][hit->getLayer() - 1]
332 [hit->getSector() - 1][hit->getPlane() - 1][hit->getStrip() - 1]);
335 const HepGeom::Transform3D*
338 return &(m_StripInverse[hit->getSection() - 1][hit->getLayer() - 1]
339 [hit->getSector() - 1][hit->getPlane() - 1][hit->getStrip() - 1]);
342 const HepGeom::Transform3D*
344 int plane,
int strip)
const
346 return &(m_StripInverse[section - 1][layer - 1][sector - 1][plane - 1]
352 double* d1,
double* d2,
double* sd,
366 double l1 = m_GeoDat->getStripLength(hit1->
getStrip());
369 const HepGeom::Transform3D* tr1 = getStripLocalToGlobal(hit1);
373 double l2 = m_GeoDat->getStripLength(hit2->
getStrip());
376 const HepGeom::Transform3D* tr2 = getStripLocalToGlobal(hit2);
388 HepGeom::Vector3D<double> v1 = s1_2g - s1_1g;
389 HepGeom::Vector3D<double> v2 = s2_2g - s2_1g;
390 HepGeom::Vector3D<double> d = s1_1g - s2_1g;
391 double v1sq = v1.mag2();
392 double v2sq = v2.mag2();
393 double v1dv2 = v1.dot(v2);
394 double ddv1 = d.dot(v1);
395 double ddv2 = d.dot(v2);
396 double den = v1sq * v2sq - v1dv2 * v1dv2;
397 double t1 = (v1dv2 * ddv2 - v2sq * ddv1) / den;
398 double t2 = (- v1dv2 * ddv1 + v1sq * ddv2) / den;
401 if (t1 < 0.0 || t1 > 1.0)
403 if (t2 < 0.0 || t2 > 1.0)
409 *d1 = s1_2g.distance(s1_cg) / CLHEP::mm *
Unit::mm;
410 *d2 = s2_2g.distance(s2_cg) / CLHEP::mm *
Unit::mm;
411 *cross = 0.5 * (s1_cg + s2_cg) / CLHEP::mm *
Unit::mm;
412 *sd = s1_cg.distance(s2_cg) / CLHEP::mm *
Unit::mm;
413 if (s2_cg.mag2() < s1_cg.mag2())
428 if (position.y() > 0) {
446 int section, layer, sector, plane, segment, strip, stripSegment, stripGlobal;
448 int nLayers, nPlanes, nSegments, nStripsSegment, minDistanceSegment;
449 double solenoidCenter, firstLayerCenter, layerShift;
451 double x, y, z, l, minY, maxY;
452 double minDistance = 0, minDistanceNew, stripWidth;
454 intersectionClhep = intersection * CLHEP::cm /
Unit::cm;
455 solenoidCenter = m_GeoDat->getSolenoidZ() / CLHEP::cm *
Unit::cm;
456 if (intersection.z() < solenoidCenter)
461 (m_GeoDat->getSectionPosition()->getZ()
462 - 0.5 * m_GeoDat->getSectionPosition()->getLength()
463 + m_GeoDat->getLayerShiftZ()
464 - 0.5 * m_GeoDat->getLayerPosition()->getLength()) /
466 layerShift = m_GeoDat->getLayerShiftZ() / CLHEP::cm *
Unit::cm;
467 z = fabs(intersection.z() - solenoidCenter);
468 layer = round((z - firstLayerCenter) / layerShift) + 1;
471 nLayers = m_GeoDat->getNDetectorLayers(section);
474 sector = getSectorByPosition(section, intersection);
475 nPlanes = m_GeoDat->getNPlanes();
476 nSegments = m_GeoDat->getNSegments();
477 nStripsSegment = m_ElementNumbers->getNStripsSegment();
478 stripWidth = m_GeoDat->getStripGeometry()->getWidth() / CLHEP::cm *
Unit::cm;
479 minY = -stripWidth / 2;
480 maxY = (double(nStripsSegment) - 0.5) * stripWidth;
481 for (plane = 1; plane <= nPlanes; plane++) {
482 minDistanceSegment = 1;
483 for (segment = 1; segment <= nSegments; segment++) {
484 strip = (segment - 1) * nStripsSegment;
485 intersectionLocal = m_StripInverse[section - 1][layer - 1]
486 [sector - 1][plane - 1][strip] * intersectionClhep;
487 y = intersectionLocal.y() / CLHEP::cm *
Unit::cm;
489 minDistanceNew = minY - y;
490 }
else if (y > maxY) {
491 minDistanceNew = y - maxY;
494 minDistanceSegment = segment;
498 minDistance = minDistanceNew;
499 }
else if (minDistanceNew < minDistance) {
500 minDistance = minDistanceNew;
501 minDistanceSegment = segment;
510 strip = (minDistanceSegment - 1) * nStripsSegment;
511 intersectionLocal = m_StripInverse[section - 1][layer - 1]
512 [sector - 1][plane - 1][strip] * intersectionClhep;
513 y = intersectionLocal.y() / CLHEP::cm *
Unit::cm;
514 stripSegment = ceil((y - 0.5 * stripWidth) / stripWidth);
515 if (stripSegment <= 0)
517 else if (stripSegment > nStripsSegment)
518 stripSegment = nStripsSegment;
519 strip = stripSegment + (minDistanceSegment - 1) * nStripsSegment;
520 intersectionLocal = m_StripInverse[section - 1][layer - 1]
521 [sector - 1][plane - 1][strip - 1] * intersectionClhep;
522 x = intersectionLocal.x();
523 l = m_GeoDat->getStripLength(strip);
528 if (fabs(x) > 0.5 * l)
530 stripGlobal = m_ElementNumbers->stripNumber(
531 section, layer, sector, plane, strip);
533 *strip1 = stripGlobal;
535 *strip2 = stripGlobal;