ATLAS Offline Software
Loading...
Searching...
No Matches
CaloDetDescriptor.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "Identifier/Identifier.h"
7#include <cmath>
8#include <iomanip>
9#include <iostream>
10
11
13 const AtlasDetectorID* helper,
14 const CaloCell_Base_ID* calo_helper,
16 int layer)
17 : m_id (id),
20{
21 m_helper=helper;
22 m_calo_helper=calo_helper;
23
24 // --m_is_xxx
25 m_is_lar_em = m_calo_helper->is_em(id);
26 m_is_lar_em_barrel = m_calo_helper->is_em_barrel(id);
27 m_is_lar_em_endcap = m_calo_helper->is_em_endcap(id);
28 m_is_lar_em_endcap_inner = m_calo_helper->is_em_endcap_inner(id);
29 m_is_lar_em_endcap_outer = m_calo_helper->is_em_endcap_outer(id);
30 m_is_lar_hec = m_calo_helper->is_hec(id);
31 m_is_lar_fcal = m_calo_helper->is_fcal(id);
32 m_is_tile = m_calo_helper->is_tile(id);
33
34 // -- m_calo_sign
35 if (m_is_tile)
36 m_calo_sign = m_calo_helper->side(id);
37 else {
38 int posneg = m_calo_helper->pos_neg(id);
39 if (posneg == 0)
40 m_calo_sign = 0;
41 else
42 m_calo_sign = (int)(posneg/std::abs(posneg));
43 }
44
45 // -- m_layer
47
48 // -- m_calo_sampl
49 if(m_is_tile)
50 {
51 if(sample != CaloCell_ID::Unknown)
52 {
53 m_calo_sampl = sample;
54 }
55 else
56 {
57 const Tile_Base_ID* tileid = static_cast<const Tile_Base_ID*>(m_helper);
58 if(tileid->is_tile_barrel(id))
59 m_calo_sampl = CaloCell_ID::TileBar0;
60 else if(tileid->is_tile_extbarrel(id))
61 m_calo_sampl = CaloCell_ID::TileExt0;
62 else if(tileid->is_tile_gap(id))
63 m_calo_sampl = (CaloCell_ID::CaloSample)
64 ((int)CaloCell_ID::TileGap1 - 1);
65 else
66 m_calo_sampl = CaloCell_ID::Unknown;
67 }
68 }
69 else
70 m_calo_sampl = (CaloCell_ID::CaloSample) m_calo_helper->calo_sample(id);
71
72 // -- m_calo_num
73 m_calo_num = (CaloCell_ID::SUBCALO) m_calo_helper->sub_calo(id);
74
75 // -- m_calocell_min
76 IdentifierHash junk;
77 m_calo_helper->calo_cell_hash_range(id,m_calocell_min,junk);
78
79 // -- m_lar_deta, m_lar_n_eta (phi)
80 m_lar_deta = (double) m_calo_helper->etaGranularity(id);
81 m_lar_dphi = (double) m_calo_helper->phiGranularity(id);
82 m_lar_n_eta = m_calo_helper->eta_max(id) - m_calo_helper->eta_min(id) + 1;
83 m_lar_n_phi = m_calo_helper->phi_max(id) - m_calo_helper->phi_min(id) + 1;
84
85 // To be initialized in the derived classes:
86 m_calo_phi_min = 0.;
87 m_calo_phi_max = 0.;
88 m_calo_r_min = 0.;
89 m_calo_r_max = 0.;
90 m_calo_z_min = 0.;
91 m_calo_z_max = 0.;
92
93 m_lar_reg_min = 999999.;
94 m_lar_reg_max = -999999.;
95 m_lar_phi_min = 999999.;
96 m_lar_eta_min = 0.;
97
98 m_n_calo_depth = 0;
99 m_calo_depth_in.resize(0);
100 m_calo_depth_out.resize(0);
101
102 // Eigen doesn't default-initialize things.
103 m_transform.setIdentity();
104
105 m_etachan_min = m_calo_helper->eta_min(m_id);
106}
107
109= default;
110
112{
113 dump(std::cout);
114}
115
116void CaloDetDescriptor::dump(std::ostream& os) const
117{
118 os << " CaloDetDescriptor print: \n\n";
119
120 os << m_calo_helper->print_to_string(m_id);
121
122 if(m_calo_helper->is_em_endcap(m_id))
123 os << " LAr EM ENDCAP: " << (int) m_calo_sampl << " " << (int) m_calo_num << "\n";
124 else if(m_calo_helper->is_em_barrel(m_id))
125 os << " LAr EM BARREL: " << (int) m_calo_sampl << " " << (int) m_calo_num << "\n";
126 else if(m_calo_helper->is_lar_hec(m_id))
127 os << " LAr HEC: " << (int) m_calo_sampl << " " << (int) m_calo_num << "\n";
128 else if(m_calo_helper->is_lar_fcal(m_id))
129 os << " LAr Fcal: " << (int) m_calo_sampl << " " << (int) m_calo_num << "\n";
130 else
131 {
132 if(!m_is_tile) os << " UNKNOW LAr decriptor !!!! \n";
133 }
134
135 os << "Ideal values before alignment :\n";
136 os << " eta_min eta_max deta n_eta phi_min phi_max dphi n_phi \n";
137 os << std::setw(9) << std::setprecision(4) << calo_eta_min() << " "
138 << std::setw(9) << std::setw(9) << std::setprecision(4) << calo_eta_max() << " "
139 << std::setw(9) << std::setprecision(4) << deta() << " "
140 << std::setw(9) << std::setprecision(4) << n_eta() << " "
141 << std::setw(9) << std::setprecision(4) << calo_phi_min() << " "
142 << std::setw(9) << std::setprecision(4) << calo_phi_max() << " "
143 << std::setw(9) << std::setprecision(4) << dphi() << " "
144 << std::setw(9) << std::setprecision(4) << n_phi() << "\n";
145
146 os << " r_min z_min r_max z_max sign\n";
147
148 os << std::setprecision(4) << calo_r_min() << " "
149 << std::setprecision(4) << calo_r_max() << " "
150 << std::setprecision(4) << calo_z_min() << " "
151 << std::setprecision(4) << calo_z_max() << " "
152 << std::setprecision(1) << calo_sign() << "\n";
153
154 Amg::RotationMatrix3D rot= m_transform.rotation ();
155
156 //calculate euler angles
157 double theta1, psi1, phi1;
158 if (std::abs(std::abs(rot(2,1))-1.0f) > 0.00001)
159 {
160 theta1 = -std::asin(rot(2,0));
161 psi1 = std::atan2(rot(2,1)/std::cos(theta1), rot(2,2)/std::cos(theta1));
162 phi1 = std::atan2(rot(1,0)/std::cos(theta1), rot(0,0)/std::cos(theta1));
163 } else {
164 phi1 = 0;
165 if(rot(2,0) == -1){
166 theta1 = M_PI*0.5;
167 psi1 = std::atan2(rot(0,1),rot(0,2));
168 } else {
169 theta1 = -(M_PI * 0.5);
170 psi1 = std::atan2(-rot(0,1), -rot(0,2));
171 }
172 }
173
174 os << "\nEigenTransform phi,theta,psi,x,y,z: "
175 << phi1 << " " << theta1 << " "
176 << psi1 << " " << m_transform(0,3) << " "
177 << m_transform(1,3) << " " << m_transform(2,3) << "\n\n";
178
179 os << std::setprecision(4) << "in real world (can be <0)"
180 << m_lar_reg_min << " " << m_lar_reg_max << " "
181 << m_lar_phi_min << " " << m_lar_eta_min << "\n\n";
182}
183
186{
188 {
189 const Tile_Base_ID* tileid = reinterpret_cast<const Tile_Base_ID*> (m_helper);
190 Identifier id = tileid->cell_id (onecalo_hash);
191 return (CaloCell_ID::CaloSample) (m_calo_sampl + tileid->sample(id));
192 }
193 else
194 {
195 return m_calo_sampl;
196 }
197}
198
200 double& radius,
201 double& hphi,
202 double& hlength,
203 double& depth) const
204{
205 // For cylinders : htrans is the displacement compared to a cylinder centered along the
206 // z axis
207
208 htrans = m_transform;
209 radius = m_calo_r_min;
210 hlength = m_calo_z_max;
211 hphi = 0.5*m_lar_dphi*m_lar_n_phi;
213
214 if (m_is_tile)
215 {
216 // need to shift tile cylinders (half-barrels, ext.barrels and ITC)
217 hlength = m_calo_z_max-m_calo_z_min;
218 double z = m_calo_sign*(m_calo_z_min + m_calo_z_max)/2.;
220 htrans = (htrans) * vec;
221 }
222
223 return true;
224}
225
227 double& z,
228 double& rmin,
229 double& rmax,
230 double& hphisec,
231 double& depth) const
232{
233 // For disks : htrans is the position of the entrance surface, i.e. the alignment
234 // heptransform + a z shift to put the entrance at the right z.
235
236 htrans = m_transform;
239
240 Amg::Translation3D vec(0.,0.,z);
241 htrans = (htrans) * vec;
242
243 rmin = m_calo_r_min;
244 rmax = m_calo_r_max;
245 hphisec = 0.5*m_lar_dphi*m_lar_n_phi;
246
247 return true;
248}
249
250bool CaloDetDescriptor::is_in(double eta_min,
251 double eta_max,
252 double /*phi_min*/,
253 double /*phi_max*/) const
254{
255 bool result = (eta_min + 0.00001 <= m_lar_reg_max &&
256 eta_max >= m_lar_reg_min + 0.00001);
257 return result;
258}
259
261{
262 int result = -1;
263 // if(m_calo_sign*eta<0) return result;
265
266
267 if(std::abs(eta) + 0.00001 >= m_lar_eta_min)
268 result = (int)((std::abs(eta) - m_lar_eta_min)/m_lar_deta) + m_etachan_min;
269
271
272 return result;
273}
274
276{
277 double phi_fixed = phi ;
278
279 // -M_PI,M_PI convention :
280 if (phi <= m_lar_phi_min)
281 phi_fixed = phi_fixed + 2.0*M_PI;
282
283 int chan = (int)((phi_fixed - m_lar_phi_min)/m_lar_dphi) + m_calo_helper->phi_min(m_id);
284
285 if(chan >= m_lar_n_phi + m_calo_helper->phi_min(m_id)) chan = -1;
286
287 return chan;
288}
289
291{
292 int result = -1;
295
296
297 if(std::abs(eta) + 0.00001 >= m_calo_eta_min)
298 result = (int)((std::abs(eta) - m_calo_eta_min)/m_lar_deta);
299
301
302 return result;
303}
304
306{
307 double phi_fixed = phi ;
308
309 // -M_PI,M_PI convention :
310 if (phi <= m_calo_phi_min)
311 phi_fixed = phi_fixed + 2.0*M_PI;
312
313 int chan = (int)((phi_fixed - m_calo_phi_min)/m_lar_dphi) + m_calo_helper->phi_min(m_id);
314
315 if(chan >= m_lar_n_phi + m_calo_helper->phi_min(m_id)) chan = -1;
316
317 return chan;
318}
319
320
321
324
325void CaloDetDescriptor::get_depth_in(std::vector<double>& calo_depth) const
326{
327 calo_depth.resize(m_n_calo_depth);
328 for (int i=0; i<m_n_calo_depth; i++)
329 calo_depth [i] = m_calo_depth_in[i];
330}
331
332void CaloDetDescriptor::get_depth_out(std::vector<double>& calo_depth) const
333{
334 calo_depth.resize(m_n_calo_depth);
335 for (int i=0; i<m_n_calo_depth; i++)
336 calo_depth [i] = m_calo_depth_out[i];
337}
338
339
346
347void CaloDetDescriptor::set_depth_in(std::vector<double>& calo_depth)
348{
349 for (int i=0; i<m_n_calo_depth; i++)
350 m_calo_depth_in[i] = calo_depth[i];
351}
352
353void CaloDetDescriptor::set_depth_out(std::vector<double>& calo_depth)
354{
355 for (int i=0; i<m_n_calo_depth; i++)
356 m_calo_depth_out[i] = calo_depth[i];
357}
358
360 double deta,
361 int nphi,
362 double dphi)
363{
366 m_lar_n_eta = neta;
367 m_lar_n_phi = nphi;
368}
369
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Definition of CaloDetDescriptor.
std::vector< size_t > vec
#define z
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Helper base class for offline cell identifiers.
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
CaloSampling::CaloSample CaloSample
Definition CaloCell_ID.h:53
CaloDetDescriptor(const Identifier &id, const AtlasDetectorID *helper, const CaloCell_Base_ID *calo_helper, CaloCell_ID::CaloSample sample=CaloCell_ID::Unknown, int layer=CaloCell_ID::NOT_VALID)
Constructor.
double m_calo_eta_max
maximal Eta (to be defined in the derived classes)
double calo_phi_max() const
'ideal' geometry: phi maximal
double m_lar_eta_min
minimal Eta for LAr region
bool m_is_lar_em_endcap_outer
descriptor belongs to the outer wheel of EM end cap
double deta() const
delta eta
void set_depth_out(std::vector< double > &calo_depth)
set vector of out depths
double m_calo_r_max
maximal R (to be defined in the derived classes)
int n_phi() const
phi granularity
std::vector< double > m_calo_depth_in
in depths
double calo_eta_min() const
'ideal' geometry: eta minimal
int m_lar_n_eta
eta granularity (LAr)
int layer() const
get layer
double m_calo_phi_min
minimal Phi (to be defined in the derived classes)
const CaloCell_Base_ID * m_calo_helper
Calo Cell ID helper.
int n_calo_depth() const
number of calo depths
double dphi() const
delta phi
void set_eta_phi_granularity(int neta, double deta, int nphi, double dphi)
Set Phi granularity.
double calo_z_min() const
'ideal' geometry: z minimal
bool is_in(double eta_min, double eta_max, double phi_min, double phi_max) const
check overlap with a given zone in eta and phi (for LAr only)
double calo_z_max() const
'ideal' geometry: z maximal
double m_lar_phi_min
minimal Phi for LAr region
double calo_r_min() const
'ideal' geometry: r minimal
double m_lar_reg_max
maximal Abs Eta for LAr region
std::vector< double > m_calo_depth_out
out depths
int eta_channel(double eta) const
channel number for a given eta/phi (if outside returns -1).
double m_calo_eta_min
minimal Eta (to be defined in the derived classes)
virtual ~CaloDetDescriptor()
virtual detructor
double calo_r_max() const
'ideal' geometry: r maximal
double m_calo_z_max
maximal Z (to be defined in the derived classes)
bool get_disk_surface(Amg::Transform3D &htrans, double &z, double &rmin, double &rmax, double &hphisec, double &depth) const
(for Trk::Surface)
CaloCell_ID::CaloSample m_calo_sampl
Calo Sample.
void set_n_calo_depth(int n_calo_depth)
set number of calo depths
bool get_cylinder_surface(Amg::Transform3D &htrans, double &radius, double &hphi, double &hlength, double &depth) const
this will be the closest radius of this region
CaloCell_ID::SUBCALO m_calo_num
Subcalo.
double calo_eta_max() const
'ideal' geometry: eta maximal
int phi_channel(double phi) const
channel number for a given eta/phi (if outside returns -1) Should not be used for FCAL
int m_n_calo_depth
number of depths
void get_depth_in(std::vector< double > &calo_depth) const
get vector of in depths
CaloCell_ID::CaloSample getSampling() const
get sampling returns the cached CaloSample, if the descriptor contains more than one sampling,...
bool m_is_lar_hec
descriptor belongs to HEC
double m_lar_dphi
delta phi (LAr)
bool m_is_tile
descriptor belongs to Tile
bool m_is_lar_em_barrel
descriptor belongs to EM barrel
double calo_phi_min() const
'ideal' geometry: phi minimal
bool m_is_lar_em_endcap
descriptor belongs to EM end cap
Identifier m_id
Region identifier.
bool m_is_lar_em
descriptor belongs to EM calorimeter
int calo_sign() const
'ideal' geometry: calo sign
void dump(std::ostream &os) const
dump contents to a stream.
double m_lar_deta
delta eta (LAr)
double m_calo_z_min
minimal Z (to be defined in the derived classes)
bool m_is_lar_em_endcap_inner
descriptor belongs to the inner wheel of EM end cap
Amg::Transform3D m_transform
misalignment transformation
void set_depth_in(std::vector< double > &calo_depth)
set vector of in depths
virtual void print() const
print the contents
int phi_channel_raw(double phi) const
channel number for a given eta/phi raw (if outside returns -1) Should not be used for FCAL
int eta_channel_raw(double eta) const
channel number for a given eta/phi raw (if outside returns -1).
const AtlasDetectorID * m_helper
Atlas Detector ID helper.
int m_etachan_min
minimal Eta channel number
int m_lar_n_phi
phi granularity (LAr)
int n_eta() const
eta granularity
double m_lar_reg_min
minimal Abs Eta for LAr region
bool m_is_lar_fcal
descriptor belongs to FCAL
void get_depth_out(std::vector< double > &calo_depth) const
get vector of out depths
double m_calo_r_min
minimal R (to be defined in the derived classes)
This is a "hash" representation of an Identifier.
This class factors out code common between TileID and Tile_SuperCell_ID.
int sample(const Identifier &id) const
Identifier cell_id(const Identifier &any_id) const
std::string depth
tag string for intendation
Definition fastadd.cxx:46
Eigen::Matrix< double, 3, 3 > RotationMatrix3D
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Eigen::Translation< double, 3 > Translation3D
-event-from-file