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