Belle II Software development
AlignableEKLMRecoHit.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <alignment/reconstruction/AlignableEKLMRecoHit.h>
10
11#include <alignment/GlobalDerivatives.h>
12#include <alignment/GlobalLabel.h>
13#include <klm/dataobjects/eklm/EKLMElementNumbers.h>
14#include <klm/dataobjects/KLMDigit.h>
15#include <klm/dataobjects/KLMElementNumbers.h>
16#include <klm/dataobjects/KLMHit2d.h>
17#include <klm/dbobjects/eklm/EKLMAlignment.h>
18#include <klm/eklm/geometry/GeometryData.h>
19#include <klm/eklm/geometry/TransformDataGlobalAligned.h>
20
21using namespace Belle2;
22using namespace alignment;
23
27
29 const EKLMAlignmentHit* hit, const genfit::TrackCandHit* trackCandHit) :
30 genfit::PlanarMeasurement(1)
31{
32 (void)trackCandHit;
33 int digit, plane, segment, strip;
34 const HepGeom::Transform3D* t;
35 CLHEP::HepRotation r;
36 CLHEP::Hep3Vector origin;
37 CLHEP::Hep3Vector u(1, 0, 0);
38 CLHEP::Hep3Vector v(0, 1, 0);
39 B2Vector3D origin2, u2, v2;
41 const KLMElementNumbers* elementNumbers = &(KLMElementNumbers::Instance());
42 const EKLMElementNumbers* eklmElementNumbers =
44 const EKLM::TransformDataGlobalAligned* transformData =
46 RelationVector<KLMHit2d> hit2ds = hit->getRelationsTo<KLMHit2d>();
47 if (hit2ds.size() != 1)
48 B2FATAL("Incorrect number of related KLMHit2ds.");
49 RelationVector<KLMDigit> eklmDigits = hit2ds[0]->getRelationsTo<KLMDigit>();
50 if (eklmDigits.size() != 2)
51 B2FATAL("Incorrect number of related KLMDigits.");
52 digit = hit->getDigitIdentifier();
53 m_Section = eklmDigits[digit]->getSection();
54 m_Layer = eklmDigits[digit]->getLayer();
55 m_Sector = eklmDigits[digit]->getSector();
56 plane = eklmDigits[digit]->getPlane();
57 segment = (eklmDigits[digit]->getStrip() - 1) /
58 eklmElementNumbers->getNStripsSegment() + 1;
59 strip = (segment - 1) * eklmElementNumbers->getNStripsSegment() + 1;
61 m_Segment = eklmElementNumbers->segmentNumber(
62 m_Section, m_Layer, m_Sector, plane, segment);
63 t = transformData->getStripTransform(
64 m_Section, m_Layer, m_Sector, plane, strip);
65 origin = t->getTranslation();
66 origin2.SetX(origin.x() / CLHEP::cm * Unit::cm);
67 origin2.SetY(origin.y() / CLHEP::cm * Unit::cm);
68 origin2.SetZ(origin.z() / CLHEP::cm * Unit::cm);
69 r = t->getRotation();
70 u = r * u;
71 v = r * v;
72 u2.SetX(u.x());
73 u2.SetY(u.y());
74 u2.SetZ(u.z());
75 v2.SetX(v.x());
76 v2.SetY(v.y());
77 v2.SetZ(v.z());
78 t = transformData->getSectorTransform(m_Section, m_Layer, m_Sector);
79 r = t->getRotation().inverse();
80 v = r * v;
81 m_StripV.SetX(v.unit().x());
82 m_StripV.SetY(v.unit().y());
83 genfit::SharedPlanePtr detPlane(new genfit::DetPlane(origin2, u2, v2, 0));
84 setPlane(detPlane, m_Segment);
85 rawHitCoords_[0] = geoDat->getStripGeometry()->getWidth() *
86 ((eklmDigits[digit]->getStrip() - 1) %
87 eklmElementNumbers->getNStripsSegment()) / CLHEP::cm * Unit::cm;
88 rawHitCov_[0][0] = pow(geoDat->getStripGeometry()->getWidth() /
89 CLHEP::cm * Unit::cm, 2) / 12;
90 setStripV();
91}
92
96
97std::pair<std::vector<int>, TMatrixD> AlignableEKLMRecoHit::globalDerivatives(const genfit::StateOnPlane* sop)
98{
99 std::vector<int> labGlobal;
103
104 /* Local parameters. */
105 const double dalpha = 0;
106 const double dxs = 0;
107 const double dys = 0;
108 const double sinda = sin(dalpha);
109 const double cosda = cos(dalpha);
110 /* Local position in sector coordinates. */
111 HepGeom::Point3D<double> globalPos;
112 HepGeom::Transform3D t;
113 const EKLM::TransformDataGlobalAligned* transformData =
115 t = (*transformData->getSectorTransform(m_Section, m_Layer, m_Sector)).inverse();
116 globalPos.setX(sop->getPos().X() / Unit::cm * CLHEP::cm);
117 globalPos.setY(sop->getPos().Y() / Unit::cm * CLHEP::cm);
118 globalPos.setZ(sop->getPos().Z() / Unit::cm * CLHEP::cm);
119 globalPos = t * globalPos;
120 double x = globalPos.x() / CLHEP::cm * Unit::cm;
121 double y = globalPos.y() / CLHEP::cm * Unit::cm;
122 /*
123 * Matrix of global derivatives of local coordinate (second dimension is
124 * added because of resizing in GblFitterInfo::constructGblPoint()) by
125 * variations of the detector element position.
126 * The sign is inverted to match the convention for other detectors.
127 */
128 TMatrixD derGlobal(2, 3);
129 derGlobal(0, 0) = 0;
130 derGlobal(0, 1) = 0;
131 derGlobal(0, 2) = 0;
132 derGlobal(1, 0) = cosda * m_StripV.X() - sinda * m_StripV.Y();
133 derGlobal(1, 1) = sinda * m_StripV.X() + cosda * m_StripV.Y();
134 derGlobal(1, 2) =
135 -((x - dxs) * (-sinda * m_StripV.X() - cosda * m_StripV.Y()) +
136 (y - dys) * (cosda * m_StripV.X() - sinda * m_StripV.Y()));
137 return alignment::GlobalDerivatives(labGlobal, derGlobal);
138
139}
140
141genfit::AbsMeasurement* AlignableEKLMRecoHit::clone() const
142{
143 return new AlignableEKLMRecoHit(*this);
144}
145
uint16_t m_Segment
Segment number.
virtual std::pair< std::vector< int >, TMatrixD > globalDerivatives(const genfit::StateOnPlane *sop) override
Labels and derivatives of residuals (local measurement coordinates) w.r.t.
genfit::AbsMeasurement * clone() const override
Clone.
uint16_t m_KLMModule
KLM module number.
void SetX(DataType x)
set X/1st-coordinate
Definition B2Vector3.h:457
void SetZ(DataType z)
set Z/3rd-coordinate
Definition B2Vector3.h:461
void SetY(DataType y)
set Y/2nd-coordinate
Definition B2Vector3.h:459
This dataobject is used only for EKLM alignment.
static const EKLMElementNumbers & Instance()
Instantiation.
static constexpr int getNStripsSegment()
Get number of strips in a segment.
int segmentNumber(int section, int layer, int sector, int plane, int segment) const
Get segment number.
double getWidth() const
Get width.
const StripGeometry * getStripGeometry() const
Get strip geometry data.
EKLM geometry data.
static const GeometryData & Instance(enum DataSource dataSource=c_Database, const GearDir *gearDir=nullptr)
Instantiation.
Transformation data (global, aligned): singleton version.
static const TransformDataGlobalAligned & Instance()
Instantiation.
const HepGeom::Transform3D * getStripTransform(int section, int layer, int sector, int plane, int strip) const
Get strip transformation.
const HepGeom::Transform3D * getSectorTransform(int section, int layer, int sector) const
Get sector transformation.
static GlobalLabel construct(gidTYPE element, gidTYPE param)
Construct label for given DB object (template argument) and its element and parameter.
Definition GlobalLabel.h:81
@ c_DeltaU
Shift in U (EKLM: local X).
@ c_DeltaGamma
Rotation in gamma (EKLM: rotation in local plane).
@ c_DeltaV
Shift in V (EKLM: local Y).
KLM digit (class representing a digitized hit in RPCs or scintillators).
Definition KLMDigit.h:29
static const KLMElementNumbers & Instance()
Instantiation.
KLMModuleNumber moduleNumberEKLM(int section, int sector, int layer) const
Get module number for EKLM.
KLM 2d hit.
Definition KLMHit2d.h:33
Class for type safe access to objects that are referred to in relations.
size_t size() const
Get number of relations.
static const double cm
Standard units with the value = 1.
Definition Unit.h:47
Class for easier manipulation with global derivatives (and their labels)
B2Vector3< double > B2Vector3D
typedef for common usage with double
Definition B2Vector3.h:516
Abstract base class for different kinds of events.