Belle II Software development
AlignableBKLMRecoHit.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/AlignableBKLMRecoHit.h>
10
11#include <alignment/GlobalDerivatives.h>
12#include <alignment/GlobalLabel.h>
13#include <alignment/Hierarchy.h>
14#include <framework/geometry/B2Vector3.h>
15#include <klm/bklm/geometry/GeometryPar.h>
16#include <klm/dataobjects/KLMElementNumbers.h>
17#include <klm/dataobjects/KLMHit2d.h>
18#include <klm/dbobjects/bklm/BKLMAlignment.h>
19
20#include <genfit/DetPlane.h>
21
22using namespace std;
23using namespace Belle2;
24
25AlignableBKLMRecoHit::AlignableBKLMRecoHit(const KLMHit2d* hit, const genfit::TrackCandHit*):
26 genfit::PlanarMeasurement(HIT_DIMENSIONS)
27{
28 int section = hit->getSection();
29 int sector = hit->getSector();
30 m_Layer = hit->getLayer();
31 const KLMElementNumbers* elementNumbers = &(KLMElementNumbers::Instance());
32 m_KLMModule = elementNumbers->moduleNumberBKLM(section, sector, m_Layer);
33
35 m_Module = m_GeoPar->findModule(section, sector, m_Layer);
36
37 //+++ global coordinates of the hit
38 global[0] = hit->getPositionX();
39 global[1] = hit->getPositionY();
40 global[2] = hit->getPositionZ();
41
42 //+++ local coordinates of the hit
43 CLHEP::Hep3Vector local = m_Module->globalToLocal(global);
44
45 //+++ local coordinates in KLM m_Layer of the hit
46 double localU = local[1]; //phi
47 double localV = local[2]; //z
48 double errorU = m_Module->getPhiStripWidth() / sqrt(12);
49 double errorV = m_Module->getZStripWidth() / sqrt(12);
50
51 if (hit->inRPC()) {
52 //+++ scale localU and localV based on measured-in-Belle resolution
53 int nStrips = hit->getPhiStripMax() - hit->getPhiStripMin() + 1;
54 double dn = nStrips - 1.5;
55 double factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.60;//measured-in-Belle resolution
56 errorU = errorU * sqrt(factor);
57
58 nStrips = hit->getZStripMax() - hit->getZStripMin() + 1;
59 dn = nStrips - 1.5;
60 factor = std::pow((0.9 + 0.4 * dn * dn), 1.5) * 0.55;//measured-in-Belle resolution
61 errorV = errorV * sqrt(factor);
62 }
63
64 //Set positions
65 rawHitCoords_(0) = localU;
66 rawHitCoords_(1) = localV;
67 //Set the error covariance matrix
68 rawHitCov_(0, 0) = errorU * errorU; // error in U, squared
69 rawHitCov_(0, 1) = 0.;
70 rawHitCov_(1, 0) = 0.;
71 rawHitCov_(1, 1) = errorV * errorV; // error in V, squared
72
73 //+++ Construct vectors o, u, v of m_Layer in global coords.
74 CLHEP::Hep3Vector gOrigin = m_Module->getGlobalOrigin();
75 CLHEP::Hep3Vector lOrigin = m_Module->globalToLocal(gOrigin) + m_Module->getLocalReconstructionShift();
76 CLHEP::Hep3Vector gOrigin_midway = m_Module->localToGlobal(lOrigin);
77 CLHEP::Hep3Vector uAxis(0, 1, 0);
78 CLHEP::Hep3Vector vAxis(0, 0, 1);
79 CLHEP::Hep3Vector gUaxis = m_Module->localToGlobal(uAxis) - gOrigin;
80 CLHEP::Hep3Vector gVaxis = m_Module->localToGlobal(vAxis) - gOrigin;
81
83 B2Vector3D origin_mid(gOrigin_midway[0], gOrigin_midway[1], gOrigin_midway[2]);
84
86 B2Vector3D uGlobal(gUaxis[0], gUaxis[1], gUaxis[2]);
88 B2Vector3D vGlobal(gVaxis[0], gVaxis[1], gVaxis[2]);
89
90 genfit::SharedPlanePtr detPlane(new genfit::DetPlane(origin_mid, uGlobal, vGlobal, 0));
91 setPlane(detPlane, m_KLMModule);
92}
93
94genfit::AbsMeasurement* AlignableBKLMRecoHit::clone() const
95{
96 return new AlignableBKLMRecoHit(*this);
97}
98
99std::vector<genfit::MeasurementOnPlane*> AlignableBKLMRecoHit::constructMeasurementsOnPlane(const genfit::StateOnPlane& state) const
100{
101 TVectorD predFglo = state.get6DState();
102 TVectorD correctedLocal(2);
103 CLHEP::Hep3Vector localmom(predFglo[3], predFglo[4], predFglo[5]);
104 localmom = m_Module->RotateToLocal(localmom);
105
106 //do correction for scintillators
107 if (m_Layer == 1 || m_Layer == 2) {
108 CLHEP::Hep3Vector global_shift_z(0, 0, predFglo[5]*halfheight_sci / sqrt(predFglo[3]*predFglo[3] + predFglo[4]*predFglo[4]));
109 CLHEP::Hep3Vector local_corrected_z = m_Module->globalToLocal(global - global_shift_z);
110 double local_shift_u = localmom[1] / localmom[0] * halfheight_sci;
111 correctedLocal[0] = local_corrected_z[1] + local_shift_u;
112 //correctedLocal[0] = local_corrected_z[1];
113 correctedLocal[1] = local_corrected_z[2];
114 } else {
115 correctedLocal[0] = rawHitCoords_[0];
116 correctedLocal[1] = rawHitCoords_[1];
117 }
118
119 // return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(rawHitCoords_, rawHitCov_, state.getPlane(),
120 return std::vector<genfit::MeasurementOnPlane*>(1, new genfit::MeasurementOnPlane(correctedLocal, rawHitCov_, state.getPlane(),
121 state.getRep(), this->constructHMatrix(state.getRep())));
122}
123
124std::pair<std::vector<int>, TMatrixD> AlignableBKLMRecoHit::globalDerivatives(const genfit::StateOnPlane* sop)
125{
126 std::vector<int> labGlobal;
127
128 labGlobal.push_back(GlobalLabel::construct<BKLMAlignment>(m_KLMModule, KLMAlignmentData::c_DeltaU));
129 labGlobal.push_back(GlobalLabel::construct<BKLMAlignment>(m_KLMModule, KLMAlignmentData::c_DeltaV));
130 labGlobal.push_back(GlobalLabel::construct<BKLMAlignment>(m_KLMModule, KLMAlignmentData::c_DeltaW));
131 labGlobal.push_back(GlobalLabel::construct<BKLMAlignment>(m_KLMModule, KLMAlignmentData::c_DeltaAlpha));
132 labGlobal.push_back(GlobalLabel::construct<BKLMAlignment>(m_KLMModule, KLMAlignmentData::c_DeltaBeta));
133 labGlobal.push_back(GlobalLabel::construct<BKLMAlignment>(m_KLMModule, KLMAlignmentData::c_DeltaGamma));
134
135 // Matrix of global derivatives
136 TMatrixD derGlobal(2, 6);
137 derGlobal.Zero();
138
139 // track u-slope in local sensor system
140 double uSlope = sop->getState()[1];
141 // track v-slope in local sensor system
142 double vSlope = sop->getState()[2];
143 // Predicted track u-position in local sensor system
144 double uPos = sop->getState()[3];
145 // Predicted track v-position in local sensor system
146 double vPos = sop->getState()[4];
147
148 // Global derivatives for alignment in module local coordinates
149 derGlobal(0, 0) = 1.0;
150 derGlobal(0, 1) = 0.0;
151 derGlobal(0, 2) = - uSlope;
152 derGlobal(0, 3) = vPos * uSlope;
153 derGlobal(0, 4) = -uPos * uSlope;
154 derGlobal(0, 5) = vPos;
155
156 derGlobal(1, 0) = 0.0;
157 derGlobal(1, 1) = 1.0;
158 derGlobal(1, 2) = - vSlope;
159 derGlobal(1, 3) = vPos * vSlope;
160 derGlobal(1, 4) = -uPos * vSlope;
161 derGlobal(1, 5) = -uPos;
162
163 return alignment::GlobalDerivatives(labGlobal, derGlobal);
164
165}
166
167
168
169
virtual std::vector< genfit::MeasurementOnPlane * > constructMeasurementsOnPlane(const genfit::StateOnPlane &state) const override
Measurement construction.
CLHEP::Hep3Vector global
not streamed
const bklm::Module * m_Module
Module used to get geometry information.
const double halfheight_sci
not streamed
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
Creating a deep copy of this hit.
uint16_t m_KLMModule
KLM module number.
@ c_DeltaAlpha
Rotation in alpha.
@ c_DeltaBeta
Rotation in beta.
@ 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 element numbers.
static const KLMElementNumbers & Instance()
Instantiation.
KLMModuleNumber moduleNumberBKLM(int section, int sector, int layer) const
Get module number for BKLM.
KLM 2d hit.
Definition: KLMHit2d.h:33
Class for easier manipulation with global derivatives (and their labels)
Provides BKLM geometry parameters for simulation, reconstruction etc (from Gearbox or DataBase)
Definition: GeometryPar.h:37
const Module * findModule(int section, int sector, int layer) const
Get the pointer to the definition of a module.
Definition: GeometryPar.cc:721
static GeometryPar * instance(void)
Static method to get a reference to the singleton GeometryPar instance.
Definition: GeometryPar.cc:27
const CLHEP::Hep3Vector globalToLocal(const CLHEP::Hep3Vector &v, bool reco=false) const
Transform space-point within this module from global to local coordinates.
Definition: Module.cc:339
double getPhiStripWidth() const
Get phi-strip width.
Definition: Module.h:137
const CLHEP::Hep3Vector getLocalReconstructionShift() const
Return the local-coordinate real-vs-ideal translation of this module's sensitive volume; nominally (0...
Definition: Module.h:279
const CLHEP::Hep3Vector getGlobalOrigin() const
Return the position (in global coordinates) of this module's sensitive-volume origin.
Definition: Module.h:285
const CLHEP::Hep3Vector localToGlobal(const CLHEP::Hep3Vector &v, bool reco=false) const
Transform space-point within this module from local to global coordinates.
Definition: Module.cc:326
const CLHEP::Hep3Vector RotateToLocal(const CLHEP::Hep3Vector &v) const
Rotate a vector from global to local system.
Definition: Module.h:262
double getZStripWidth() const
Get z-strip width.
Definition: Module.h:155
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.
STL namespace.