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