Belle II Software development
LocalVertexVariables.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 <analysis/utility/ReferenceFrame.h>
10#include <analysis/VariableManager/Manager.h>
11
12#include <Math/Vector3D.h>
13
14#include <mdst/dataobjects/MCParticle.h>
15
16#include <vxd/geometry/GeoCache.h>
17
18#include <cmath>
19#include <tuple>
20
21namespace Belle2 {
26 class Particle;
27
28 namespace Variable {
29
30
31 // MC Local coordinates and sensor ID from getDecayVertex global coordinates
32
33 std::tuple<ROOT::Math::XYZVector, int, int, int> getmcLocalCoordinates(const Particle* part)
34 {
35 VXD::GeoCache& geo = VXD::GeoCache::getInstance();
36 auto* mcparticle = part->getMCParticle();
37 if (!mcparticle)
38 return std::make_tuple(ROOT::Math::XYZVector(Const::doubleNaN, Const::doubleNaN, Const::doubleNaN), 0, 0, 0);
39
40 const auto& mcglobal = mcparticle->getDecayVertex();
41
42 for (const auto& layer : geo.getLayers()) {
43 for (const auto& ladder : geo.getLadders(layer)) {
44 for (const auto& sensor : geo.getSensors(ladder)) {
45 const auto& sInfo = geo.getSensorInfo(sensor);
46 const auto& mclocal = sInfo.pointToLocal(mcglobal, true);
47 if (sInfo.inside(mclocal))
48 return std::make_tuple(mclocal, sensor.getLayerNumber(), sensor.getLadderNumber(), sensor.getSensorNumber());
49 }
50 }
51 }
52 return std::make_tuple(ROOT::Math::XYZVector(Const::doubleNaN, Const::doubleNaN, Const::doubleNaN), 0, 0, 0);
53 }
54
55 double mcDecayVertexU(const Particle* part)
56 {
57 return std::get<0>(getmcLocalCoordinates(part)).X();
58 }
59
60 double mcDecayVertexV(const Particle* part)
61 {
62 return std::get<0>(getmcLocalCoordinates(part)).Y();
63 }
64
65 double mcDecayVertexW(const Particle* part)
66 {
67 return std::get<0>(getmcLocalCoordinates(part)).Z();
68 }
69 double mcDecayVertexLayer(const Particle* part)
70 {
71 return std::get<1>(getmcLocalCoordinates(part));
72 }
73
74 double mcDecayVertexLadder(const Particle* part)
75 {
76 return std::get<2>(getmcLocalCoordinates(part));
77 }
78
79 double mcDecayVertexSensor(const Particle* part)
80 {
81 return std::get<3>(getmcLocalCoordinates(part));
82 }
83
84 // Local coordinates and sensor ID from getVertex global coordinates
85
86 std::tuple<ROOT::Math::XYZVector, int, int, int> getLocalCoordinates(const Particle* part)
87 {
88 VXD::GeoCache& geo = VXD::GeoCache::getInstance();
89 const auto& frame = ReferenceFrame::GetCurrent();
90 const auto& global = frame.getVertex(part);
91
92 for (const auto& layer : geo.getLayers()) {
93 for (const auto& ladder : geo.getLadders(layer)) {
94 for (const auto& sensor : geo.getSensors(ladder)) {
95
96 const auto& sInfo = geo.getSensorInfo(sensor);
97 const auto& local = sInfo.pointToLocal(global, true);
98 if (sInfo.inside(local.X(), local.Y(), 0.1, 0.1)) {
99 if (std::abs(local.Z()) < 0.1) {
100 return std::make_tuple(local, sensor.getLayerNumber(), sensor.getLadderNumber(), sensor.getSensorNumber());
101 } else {
102 ROOT::Math::XYZVector localz{local.X(), local.Y(), std::abs(local.Z()) - 0.1};
103 if (sInfo.inside(localz))
104 return std::make_tuple(local, sensor.getLayerNumber(), sensor.getLadderNumber(), sensor.getSensorNumber());
105 }
106 }
107
108 }
109 }
110 }
111 return std::make_tuple(ROOT::Math::XYZVector(Const::doubleNaN, Const::doubleNaN, Const::doubleNaN), 0, 0, 0);
112 }
113
114 double particleU(const Particle* part)
115 {
116 return std::get<0>(getLocalCoordinates(part)).X();
117 }
118
119 double particleV(const Particle* part)
120 {
121 return std::get<0>(getLocalCoordinates(part)).Y();
122 }
123
124 double particleW(const Particle* part)
125 {
126 return std::get<0>(getLocalCoordinates(part)).Z();
127 }
128 double particleLayer(const Particle* part)
129 {
130 return std::get<1>(getLocalCoordinates(part));
131 }
132
133 double particleLadder(const Particle* part)
134 {
135 return std::get<2>(getLocalCoordinates(part));
136 }
137
138 double particleSensor(const Particle* part)
139 {
140 return std::get<3>(getLocalCoordinates(part));
141 }
142
143 VARIABLE_GROUP("Local Vertex Information");
144 // Generated vertex information
145 REGISTER_VARIABLE("mcDecayVertexU", mcDecayVertexU,
146 "Returns the U position of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.");
147 REGISTER_VARIABLE("mcDecayVertexV", mcDecayVertexV,
148 "Returns the V position of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.");
149 REGISTER_VARIABLE("mcDecayVertexW", mcDecayVertexW,
150 "Returns the W position of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.");
151 REGISTER_VARIABLE("mcDecayVertexLayer", mcDecayVertexLayer,
152 "Returns the Layer ID of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.");
153 REGISTER_VARIABLE("mcDecayVertexLadder", mcDecayVertexLadder,
154 "Returns the ladder ID of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.");
155 REGISTER_VARIABLE("mcDecayVertexSensor", mcDecayVertexSensor,
156 "Returns the sensor ID of the decay vertex of the matched generated particle. Returns nan if the particle has no matched generated particle.");
157 REGISTER_VARIABLE("u", particleU,
158 "u local sensor coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track");
159 REGISTER_VARIABLE("v", particleV,
160 "V local sensor coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track");
161 REGISTER_VARIABLE("w", particleW,
162 "w local sensor coordinate of vertex in case of composite particle, or point of closest approach (POCA) in case of a track");
163 REGISTER_VARIABLE("layer", particleLayer,
164 "layer identification of vertex in case of composite particle, or point of closest approach (POCA) in case of a track");
165 REGISTER_VARIABLE("ladder", particleLadder,
166 "layer identification of vertex in case of composite particle, or point of closest approach (POCA) in case of a track");
167 REGISTER_VARIABLE("sensor", particleSensor,
168 "sensor identification of vertex in case of composite particle, or point of closest approach (POCA) in case of a track");
169
170 }
172}
static const double doubleNaN
quiet_NaN
Definition Const.h:703
Class to store reconstructed particles.
Definition Particle.h:76
static const ReferenceFrame & GetCurrent()
Get current rest frame.
static GeoCache & getInstance()
Return a reference to the singleton instance.
Definition GeoCache.cc:214
Abstract base class for different kinds of events.