ATLAS Offline Software
CaloCellHelpers.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef REC_CALOCELLHELPERS_H
6 #define REC_CALOCELLHELPERS_H
7 
8 #include <cmath>
9 
10 #include "CaloEvent/CaloCell.h"
12 
13 inline double phiMean(double a, double b) { return 0.5 * (a + b) + (a * b < 0) * M_PI; }
14 
16 inline bool crossedPhi(const CaloCell& cell, double phi_entrance, double phi_exit) {
17  double mean_phi = phiMean(phi_entrance, phi_exit);
18  double dphi = fabs(CaloPhiRange::diff(phi_entrance, phi_exit));
19  double phi_min = mean_phi - dphi, phi_max = mean_phi + dphi;
20 
21  return (CaloPhiRange::diff(cell.phi() + cell.caloDDE()->dphi() / 2., phi_min) > 0 &&
22  CaloPhiRange::diff(phi_max, cell.phi() - cell.caloDDE()->dphi() / 2.) > 0);
23 }
24 
26 inline double getPathLengthInEta(const CaloCell& cell, double eta_entrance, double eta_exit) {
27  double etaMin = cell.eta() - 0.5 * cell.caloDDE()->deta();
28  double etaMax = cell.eta() + 0.5 * cell.caloDDE()->deta();
29  if (fabs(eta_entrance - eta_exit) < 1e-6) // to avoid FPE
30  return eta_entrance > etaMin && eta_entrance < etaMax;
31 
32  double etaMinTrack = std::min(eta_entrance, eta_exit);
33  double etaMaxTrack = std::max(eta_entrance, eta_exit);
34  return (std::min(etaMax, etaMaxTrack) - std::max(etaMin, etaMinTrack)) / (etaMaxTrack - etaMinTrack);
35 }
36 
38 inline double getPathLengthInZ(double zMin, double zMax, double z_entrance, double z_exit) {
39  if (fabs(z_entrance - z_exit) < 1e-6) // to avoid FPE
40  return z_entrance > zMin && z_entrance < zMax;
41 
42  double zMinTrack = std::min(z_entrance, z_exit);
43  double zMaxTrack = std::max(z_entrance, z_exit);
44  return (std::min(zMax, zMaxTrack) - std::max(zMin, zMinTrack)) / (zMaxTrack - zMinTrack);
45 }
46 
48 inline double getPathLengthInZ(const CaloCell& cell, double z_entrance, double z_exit) {
49  return getPathLengthInZ(cell.z() - 0.5 * cell.caloDDE()->dz(), cell.z() + 0.5 * cell.caloDDE()->dz(), z_entrance, z_exit);
50 }
51 
52 // /** Return the % of path length crossed by the track inside a cell in Z for a ladder shaped cell **/
53 // inline double getPathLengthInZTileBar1(const CaloCell& cell, double z_entrance, double z_exit) {
54 // // Divide the problem in 2 rectangles: the cell contains 6 tile rows, 3 in the bottom part, 3 in the top
55 // // Calculate the point where the track crossed the boundary between the bottom and top parts
56 // // and determine the path lenght inside each part
57 // TileCellDim *cell_dim = m_tileDDM->get_cell_dim(cell.caloDDE()->identify());
58 // if (!cell_dim || cell_dim->getNRows() != 6) // should always be the case for this sampling
59 // return 0;
60 
61 // // Get the percentage in depth covered by the bottom part of the cell
62 // double R = (cell_dim->getRMax(2) - cell_dim->getRMin(0))/(cell_dim->getRMax(5) - cell_dim->getRMin(0));
63 
64 // // The point where the track crossed the boundary
65 // double z_middle = z_entrance + R*(z_exit - z_entrance);
66 
67 // // Get the boundaries of the 2 half-cells
68 // double zBottom_min = cell_dim->getZMin(0), zBottom_max = cell_dim->getZMax(0);
69 // double zTop_min = cell_dim->getZMin(3), zTop_max = cell_dim->getZMax(3);
70 // double pathBottom = getPathLengthInZ(zBottom_min, zBottom_max, z_entrance, z_middle);
71 
72 // // Calculate the path traversed in the bottom and top parts
73 // if (zTop_min == zTop_max) { // top part of B9 cell has 0 width. Don't take the mean in this case
74 // if ( fabs(z_middle) > fabs(zBottom_max) && pathBottom > 0)
75 // pathBottom = 1;
76 // return pathBottom;
77 // }
78 // double pathTop = getPathLengthInZ(zTop_min, zTop_max, z_middle, z_exit);
79 // // Take the weighted mean using the depth ratio since the method gives the %
80 // return R*pathBottom + (1.-R)*pathTop;
81 // }
82 
84 inline double pathInsideCell(const CaloCell& cell, const Amg::Vector3D& entry, const Amg::Vector3D& exit) {
85  if (!crossedPhi(cell, entry.phi(), exit.phi())) return 0;
86  double pathCrossed = 0;
87  if (cell.caloDDE()->getSubCalo() != CaloCell_ID::TILE)
88  pathCrossed = getPathLengthInEta(cell, entry.eta(), exit.eta());
89  else if (cell.caloDDE()->getSampling() == CaloCell_ID::TileBar1) // ladder shape cells, divide the problem in 2
90  pathCrossed = 0; // getPathLengthInZTileBar1(cell, entry.z(), exit.z());
91  else
92  pathCrossed = getPathLengthInZ(cell, entry.z(), exit.z());
93  if (pathCrossed <= 0) return 0;
94  return pathCrossed;
95 }
96 
97 #endif
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
crossedPhi
bool crossedPhi(const CaloCell &cell, double phi_entrance, double phi_exit)
Return true if the cell crossed was crossed by the track in phi.
Definition: CaloCellHelpers.h:16
ReadCellNoiseFromCool.cell
cell
Definition: ReadCellNoiseFromCool.py:53
max
#define max(a, b)
Definition: cfImp.cxx:41
CaloCell_ID_FCS::TileBar1
@ TileBar1
Definition: FastCaloSim_CaloCell_ID.h:32
getPathLengthInEta
double getPathLengthInEta(const CaloCell &cell, double eta_entrance, double eta_exit)
Return the % of path length crossed by the track inside a cell in eta.
Definition: CaloCellHelpers.h:26
M_PI
#define M_PI
Definition: ActiveFraction.h:11
xAOD::etaMax
etaMax
Definition: HIEventShape_v2.cxx:46
CaloCell.h
phiMean
double phiMean(double a, double b)
Definition: CaloCellHelpers.h:13
pathInsideCell
double pathInsideCell(const CaloCell &cell, const Amg::Vector3D &entry, const Amg::Vector3D &exit)
Return the % of the path crossed inside the cell, given the parameters for the extrapolation at entra...
Definition: CaloCellHelpers.h:84
CaloPhiRange.h
CaloPhiRange class declaration.
CaloCell_Base_ID::TILE
@ TILE
Definition: CaloCell_Base_ID.h:46
getPathLengthInZ
double getPathLengthInZ(double zMin, double zMax, double z_entrance, double z_exit)
Return the % of path length crossed by the track inside a cell in Z.
Definition: CaloCellHelpers.h:38
calibdata.exit
exit
Definition: calibdata.py:236
min
#define min(a, b)
Definition: cfImp.cxx:40
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
a
TList * a
Definition: liststreamerinfos.cxx:10
LArCellBinning.etaMin
etaMin
Definition: LArCellBinning.py:84
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloPhiRange::diff
static double diff(double phi1, double phi2)
simple phi1 - phi2 calculation, but result is fixed to respect range.
Definition: CaloPhiRange.cxx:22