Pandora
Pandora source code navigator
Loading...
Searching...
No Matches
CaloHit.cc
Go to the documentation of this file.
1
9#include "Objects/CaloHit.h"
10
11#include <cmath>
12
13namespace pandora
14{
15
16void CaloHit::GetCellCorners(CartesianPointVector &cartesianPointVector) const
17{
18 if (RECTANGULAR == this->GetCellGeometry())
19 {
20 this->GetRectangularCellCorners(cartesianPointVector);
21 }
22 else if (POINTING == this->GetCellGeometry())
23 {
24 this->GetPointingCellCorners(cartesianPointVector);
25 }
26 else
27 {
28 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
29 }
30}
31
32//------------------------------------------------------------------------------------------------------------------------------------------
33
34bool CaloHit::operator< (const CaloHit &rhs) const
35{
36 const CartesianVector deltaPosition(rhs.GetPositionVector() - this->GetPositionVector());
37
38 if (std::fabs(deltaPosition.GetZ()) > std::numeric_limits<float>::epsilon())
39 return (deltaPosition.GetZ() > std::numeric_limits<float>::epsilon());
40
41 if (std::fabs(deltaPosition.GetX()) > std::numeric_limits<float>::epsilon())
42 return (deltaPosition.GetX() > std::numeric_limits<float>::epsilon());
43
44 if (std::fabs(deltaPosition.GetY()) > std::numeric_limits<float>::epsilon())
45 return (deltaPosition.GetY() > std::numeric_limits<float>::epsilon());
46
47 return (this->GetInputEnergy() > rhs.GetInputEnergy());
48}
49
50//------------------------------------------------------------------------------------------------------------------------------------------
51
53 m_positionVector(parameters.m_positionVector.Get()),
54 m_x0(0.f),
55 m_expectedDirection(parameters.m_expectedDirection.Get().GetUnitVector()),
56 m_cellNormalVector(parameters.m_cellNormalVector.Get().GetUnitVector()),
57 m_cellGeometry(parameters.m_cellGeometry.Get()),
58 m_cellSize0(parameters.m_cellSize0.Get()),
59 m_cellSize1(parameters.m_cellSize1.Get()),
60 m_cellThickness(parameters.m_cellThickness.Get()),
61 m_nCellRadiationLengths(parameters.m_nCellRadiationLengths.Get()),
62 m_nCellInteractionLengths(parameters.m_nCellInteractionLengths.Get()),
63 m_time(parameters.m_time.Get()),
64 m_inputEnergy(parameters.m_inputEnergy.Get()),
65 m_mipEquivalentEnergy(parameters.m_mipEquivalentEnergy.Get()),
66 m_electromagneticEnergy(parameters.m_electromagneticEnergy.Get()),
67 m_hadronicEnergy(parameters.m_hadronicEnergy.Get()),
68 m_isDigital(parameters.m_isDigital.Get()),
69 m_hitType(parameters.m_hitType.Get()),
70 m_hitRegion(parameters.m_hitRegion.Get()),
71 m_layer(parameters.m_layer.Get()),
72 m_isInOuterSamplingLayer(parameters.m_isInOuterSamplingLayer.Get()),
73 m_cellLengthScale(0.f),
74 m_isPossibleMip(false),
75 m_isIsolated(false),
76 m_isAvailable(true),
77 m_weight(1.f),
78 m_pParentAddress(parameters.m_pParentAddress.Get())
79{
81}
82
83//------------------------------------------------------------------------------------------------------------------------------------------
84
86 m_positionVector(parameters.m_pOriginalCaloHit->m_positionVector),
87 m_x0(parameters.m_pOriginalCaloHit->m_x0),
88 m_expectedDirection(parameters.m_pOriginalCaloHit->m_expectedDirection),
89 m_cellNormalVector(parameters.m_pOriginalCaloHit->m_cellNormalVector),
90 m_cellGeometry(parameters.m_pOriginalCaloHit->m_cellGeometry),
91 m_cellSize0(parameters.m_pOriginalCaloHit->m_cellSize0),
92 m_cellSize1(parameters.m_pOriginalCaloHit->m_cellSize1),
93 m_cellThickness(parameters.m_pOriginalCaloHit->m_cellThickness),
94 m_nCellRadiationLengths(parameters.m_pOriginalCaloHit->m_nCellRadiationLengths),
95 m_nCellInteractionLengths(parameters.m_pOriginalCaloHit->m_nCellInteractionLengths),
96 m_time(parameters.m_pOriginalCaloHit->m_time),
97 m_inputEnergy(parameters.m_weight.Get() * parameters.m_pOriginalCaloHit->m_inputEnergy),
98 m_mipEquivalentEnergy(parameters.m_weight.Get() * parameters.m_pOriginalCaloHit->m_mipEquivalentEnergy),
99 m_electromagneticEnergy(parameters.m_weight.Get() * parameters.m_pOriginalCaloHit->m_electromagneticEnergy),
100 m_hadronicEnergy(parameters.m_weight.Get() * parameters.m_pOriginalCaloHit->m_hadronicEnergy),
101 m_isDigital(parameters.m_pOriginalCaloHit->m_isDigital),
102 m_hitType(parameters.m_pOriginalCaloHit->m_hitType),
103 m_hitRegion(parameters.m_pOriginalCaloHit->m_hitRegion),
104 m_layer(parameters.m_pOriginalCaloHit->m_layer),
105 m_pseudoLayer(parameters.m_pOriginalCaloHit->m_pseudoLayer),
106 m_isInOuterSamplingLayer(parameters.m_pOriginalCaloHit->m_isInOuterSamplingLayer),
107 m_cellLengthScale(parameters.m_pOriginalCaloHit->m_cellLengthScale),
108 m_isPossibleMip(parameters.m_pOriginalCaloHit->m_isPossibleMip),
109 m_isIsolated(parameters.m_pOriginalCaloHit->m_isIsolated),
110 m_isAvailable(parameters.m_pOriginalCaloHit->m_isAvailable),
111 m_weight(parameters.m_weight.Get() * parameters.m_pOriginalCaloHit->m_weight),
112 m_mcParticleWeightMap(parameters.m_pOriginalCaloHit->m_mcParticleWeightMap),
113 m_pParentAddress(parameters.m_pOriginalCaloHit->m_pParentAddress)
114{
115 for (MCParticleWeightMap::value_type &mapEntry : m_mcParticleWeightMap)
116 mapEntry.second = mapEntry.second * parameters.m_weight.Get();
117}
118
119//------------------------------------------------------------------------------------------------------------------------------------------
120
124
125//------------------------------------------------------------------------------------------------------------------------------------------
126
128{
129 if (metadata.m_x0.IsInitialized())
130 {
131 const float oldX0(m_x0);
132 m_x0 = metadata.m_x0.Get();
133 m_positionVector += CartesianVector(m_x0 - oldX0, 0.f, 0.f);
134 }
135
136 if (metadata.m_isPossibleMip.IsInitialized())
137 m_isPossibleMip = metadata.m_isPossibleMip.Get();
138
139 if (metadata.m_isIsolated.IsInitialized())
140 m_isIsolated = metadata.m_isIsolated.Get();
141
142 return STATUS_CODE_SUCCESS;
143}
144
145//------------------------------------------------------------------------------------------------------------------------------------------
146
147StatusCode CaloHit::SetPseudoLayer(const unsigned int pseudoLayer)
148{
149 if (!(m_pseudoLayer = pseudoLayer))
150 return STATUS_CODE_NOT_INITIALIZED;
151
152 return STATUS_CODE_SUCCESS;
153}
154
155//------------------------------------------------------------------------------------------------------------------------------------------
156
158{
159 m_mcParticleWeightMap = mcParticleWeightMap;
160}
161
162//------------------------------------------------------------------------------------------------------------------------------------------
163
168
169//------------------------------------------------------------------------------------------------------------------------------------------
170
172{
173 if (RECTANGULAR == this->GetCellGeometry())
174 {
175 return std::sqrt(this->GetCellSize0() * this->GetCellSize1());
176 }
177 else if (POINTING == this->GetCellGeometry())
178 {
179 float radius(0.f), phi(0.f), theta(0.f);
180 this->GetPositionVector().GetSphericalCoordinates(radius, phi, theta);
181 const float centralEta(-1.f * std::log(std::tan(theta / 2.f)));
182
183 const float etaMin(centralEta - this->GetCellSize0() / 2.f), etaMax(centralEta + this->GetCellSize0() / 2.f);
184 const float thetaMin(2.f * std::atan(std::exp(-1.f * etaMin))), thetaMax(2.f * std::atan(std::exp(-1.f * etaMax)));
185
186 return std::sqrt(std::fabs(radius * this->GetCellSize1() * radius * (thetaMax - thetaMin)));
187 }
188 else
189 {
190 throw StatusCodeException(STATUS_CODE_INVALID_PARAMETER);
191 }
192}
193
194//------------------------------------------------------------------------------------------------------------------------------------------
195
197{
198 const CartesianVector &position(this->GetPositionVector());
199
200 CartesianVector normal(this->GetCellNormalVector());
201 CartesianVector dirU((BARREL == this->GetHitRegion()) ? CartesianVector(0.f, 0.f, 1.f) : CartesianVector(0.f, 1.f, 0.f) );
202 CartesianVector dirV(normal.GetCrossProduct(dirU));
203
204 dirU *= (this->GetCellSize0() / 2.f);
205 dirV *= (this->GetCellSize1() / 2.f);
206 normal *= (this->GetCellThickness() / 2.f);
207
208 cartesianPointVector.push_back(CartesianVector(position - dirU - dirV - normal));
209 cartesianPointVector.push_back(CartesianVector(position + dirU - dirV - normal));
210 cartesianPointVector.push_back(CartesianVector(position + dirU + dirV - normal));
211 cartesianPointVector.push_back(CartesianVector(position - dirU + dirV - normal));
212
213 cartesianPointVector.push_back(CartesianVector(position - dirU - dirV + normal));
214 cartesianPointVector.push_back(CartesianVector(position + dirU - dirV + normal));
215 cartesianPointVector.push_back(CartesianVector(position + dirU + dirV + normal));
216 cartesianPointVector.push_back(CartesianVector(position - dirU + dirV + normal));
217}
218
219//------------------------------------------------------------------------------------------------------------------------------------------
220
222{
223 float radius(0.f), phi(0.f), theta(0.f);
224 this->GetPositionVector().GetSphericalCoordinates(radius, phi, theta);
225 const float centralEta(-1.f * std::log(std::tan(theta / 2.f)));
226
227 const float rMin(radius - this->GetCellThickness() / 2.f), rMax(radius + this->GetCellThickness() / 2.f);
228 const float phiMin(phi - this->GetCellSize1() / 2.f), phiMax(phi + this->GetCellSize1() / 2.f);
229 const float etaMin(centralEta - this->GetCellSize0() / 2.f), etaMax(centralEta + this->GetCellSize0() / 2.f);
230 const float thetaMin(2.f * std::atan(std::exp(-1.f * etaMin))), thetaMax(2.f * std::atan(std::exp(-1.f * etaMax)));
231
232 const float sinTheta(std::sin(theta)), cosTheta(std::cos(theta));
233 const float sinThetaMin(std::sin(thetaMin)), cosThetaMin(std::cos(thetaMin)), sinPhiMin(std::sin(phiMin)), cosPhiMin(std::cos(phiMin));
234 const float sinThetaMax(std::sin(thetaMax)), cosThetaMax(std::cos(thetaMax)), sinPhiMax(std::sin(phiMax)), cosPhiMax(std::cos(phiMax));
235
236 float thetaMinRScale(1.f), thetaMaxRScale(1.f);
237
238 if (BARREL == this->GetHitRegion())
239 {
240 if (std::fabs(sinThetaMin) > std::numeric_limits<float>::epsilon())
241 thetaMinRScale = std::fabs(sinTheta / sinThetaMin);
242
243 if (std::fabs(sinThetaMax) > std::numeric_limits<float>::epsilon())
244 thetaMaxRScale = std::fabs(sinTheta / sinThetaMax);
245 }
246 else
247 {
248 if (std::fabs(cosThetaMin) > std::numeric_limits<float>::epsilon())
249 thetaMinRScale = std::fabs(cosTheta / cosThetaMin);
250
251 if (std::fabs(cosThetaMax) > std::numeric_limits<float>::epsilon())
252 thetaMaxRScale = std::fabs(cosTheta / cosThetaMax);
253 }
254
255 const float rMinAtThetaMin(thetaMinRScale * rMin), rMinAtThetaMax(thetaMaxRScale * rMin);
256 const float rMaxAtThetaMin(thetaMinRScale * rMax), rMaxAtThetaMax(thetaMaxRScale * rMax);
257
258 cartesianPointVector.push_back(CartesianVector(rMinAtThetaMin * sinThetaMin * cosPhiMin, rMinAtThetaMin * sinThetaMin * sinPhiMin, rMinAtThetaMin * cosThetaMin));
259 cartesianPointVector.push_back(CartesianVector(rMinAtThetaMax * sinThetaMax * cosPhiMin, rMinAtThetaMax * sinThetaMax * sinPhiMin, rMinAtThetaMax * cosThetaMax));
260 cartesianPointVector.push_back(CartesianVector(rMinAtThetaMax * sinThetaMax * cosPhiMax, rMinAtThetaMax * sinThetaMax * sinPhiMax, rMinAtThetaMax * cosThetaMax));
261 cartesianPointVector.push_back(CartesianVector(rMinAtThetaMin * sinThetaMin * cosPhiMax, rMinAtThetaMin * sinThetaMin * sinPhiMax, rMinAtThetaMin * cosThetaMin));
262
263 cartesianPointVector.push_back(CartesianVector(rMaxAtThetaMin * sinThetaMin * cosPhiMin, rMaxAtThetaMin * sinThetaMin * sinPhiMin, rMaxAtThetaMin * cosThetaMin));
264 cartesianPointVector.push_back(CartesianVector(rMaxAtThetaMax * sinThetaMax * cosPhiMin, rMaxAtThetaMax * sinThetaMax * sinPhiMin, rMaxAtThetaMax * cosThetaMax));
265 cartesianPointVector.push_back(CartesianVector(rMaxAtThetaMax * sinThetaMax * cosPhiMax, rMaxAtThetaMax * sinThetaMax * sinPhiMax, rMaxAtThetaMax * cosThetaMax));
266 cartesianPointVector.push_back(CartesianVector(rMaxAtThetaMin * sinThetaMin * cosPhiMax, rMaxAtThetaMin * sinThetaMin * sinPhiMax, rMaxAtThetaMin * cosThetaMin));
267}
268
269} // namespace pandora
Header file for the calo hit class.
CaloHit class.
Definition CaloHit.h:26
void GetPointingCellCorners(CartesianPointVector &cartesianPointVector) const
Get the list of cartesian coordinates for pointing cell corners.
Definition CaloHit.cc:221
CellGeometry GetCellGeometry() const
Get the cell geometry.
Definition CaloHit.h:378
HitRegion GetHitRegion() const
Get the region of the detector in which the calo hit is located.
Definition CaloHit.h:448
const CartesianVector & GetPositionVector() const
Get the position vector of center of calorimeter cell, units mm.
Definition CaloHit.h:350
bool m_isIsolated
Whether the calo hit is isolated.
Definition CaloHit.h:335
virtual ~CaloHit()
Destructor.
Definition CaloHit.cc:121
float CalculateCellLengthScale() const
Calculate the typical length scale of the cell, units mm.
Definition CaloHit.cc:171
void SetMCParticleWeightMap(const MCParticleWeightMap &mcParticleWeightMap)
Set the mc particles associated with the calo hit.
Definition CaloHit.cc:157
CaloHit(const object_creation::CaloHit::Parameters &parameters)
Constructor.
Definition CaloHit.cc:52
CartesianVector m_positionVector
Position vector of center of calorimeter cell, units mm.
Definition CaloHit.h:312
InputUInt m_pseudoLayer
The pseudo layer to which the calo hit has been assigned.
Definition CaloHit.h:331
void GetCellCorners(CartesianPointVector &cartesianPointVector) const
Get the list of cartesian coordinates for the cell corners.
Definition CaloHit.cc:16
float m_x0
For LArTPC usage, the x-coordinate shift associated with a drift time t0 shift, units mm.
Definition CaloHit.h:313
bool m_isPossibleMip
Whether the calo hit is a possible mip hit.
Definition CaloHit.h:334
float GetCellThickness() const
Get the thickness of cell, units mm.
Definition CaloHit.h:399
float GetCellSize1() const
Get the cell size 1 [pointing: phi, rectangular: perpendicular to size 0 and thickness,...
Definition CaloHit.h:392
void GetRectangularCellCorners(CartesianPointVector &cartesianPointVector) const
Get the list of cartesian coordinates for rectangular cell corners.
Definition CaloHit.cc:196
StatusCode AlterMetadata(const object_creation::CaloHit::Metadata &metadata)
Alter the metadata information stored in a calo hit.
Definition CaloHit.cc:127
float GetCellSize0() const
Get the cell size 0 [pointing: eta, rectangular: up in ENDCAP, along beam in BARREL,...
Definition CaloHit.h:385
bool operator<(const CaloHit &rhs) const
operator< sorting by position, then energy
Definition CaloHit.cc:34
const CartesianVector & GetCellNormalVector() const
Get the unit vector normal to the sampling layer, pointing outwards from the origin.
Definition CaloHit.h:371
float GetInputEnergy() const
Get the corrected energy of the calorimeter cell, units GeV, as supplied by the user.
Definition CaloHit.h:420
float m_cellLengthScale
Typical length scale [pointing: measured at cell mid-point, rectangular: std::sqrt(cellSize0 * cellSi...
Definition CaloHit.h:333
MCParticleWeightMap m_mcParticleWeightMap
The mc particle weight map.
Definition CaloHit.h:338
void RemoveMCParticles()
Remove the mc particles associated with the calo hit.
Definition CaloHit.cc:164
StatusCode SetPseudoLayer(const unsigned int pseudoLayer)
Set the mc pseudo layer for the calo hit.
Definition CaloHit.cc:147
CartesianVector class.
float GetX() const
Get the cartesian x coordinate.
void GetSphericalCoordinates(float &radius, float &phi, float &theta) const
Get the spherical coordinates of the cartesian vector.
float GetZ() const
Get the cartesian z coordinate.
CartesianVector GetCrossProduct(const CartesianVector &rhs) const
Get the cross product of the cartesian vector with a second cartesian vector.
float GetY() const
Get the cartesian y coordinate.
StatusCodeException class.
std::unordered_map< const MCParticle *, float > MCParticleWeightMap
std::vector< CartesianVector > CartesianPointVector
StatusCode
The StatusCode enum.