ATLAS Offline Software
GeoRegion.cxx
Go to the documentation of this file.
2 #include <iostream>
3 
4 #define M_PI 3.14159265358979323846
5 #define M_2PI 6.28318530717958647692
6 
7 __HOSTDEV__ double Phi_mpi_pi( double x ) {
8  while ( x >= M_PI ) x -= M_2PI;
9  while ( x < -M_PI ) x += M_2PI;
10  return x;
11 }
12 
13 __HOSTDEV__ bool GeoRegion::index_range_adjust( int& ieta, int& iphi ) const {
14  while ( iphi < 0 ) { iphi += m_cell_grid_phi; };
15  while ( iphi >= m_cell_grid_phi ) { iphi -= m_cell_grid_phi; };
16  if ( ieta < 0 ) {
17  ieta = 0;
18  return false;
19  }
20  if ( ieta >= m_cell_grid_eta ) {
21  ieta = m_cell_grid_eta - 1;
22  return false;
23  }
24  return true;
25 }
26 
27 __HOSTDEV__ float GeoRegion::calculate_distance_eta_phi( const long long DDE, float eta, float phi, float& dist_eta0,
28  float& dist_phi0 ) const {
29 
30  dist_eta0 = ( eta - m_all_cells[DDE].eta() ) / m_deta_double;
31  dist_phi0 = ( Phi_mpi_pi( phi - m_all_cells[DDE].phi() ) ) / m_dphi_double;
32  float abs_dist_eta0 = abs( dist_eta0 );
33  float abs_dist_phi0 = abs( dist_phi0 );
34  return max( abs_dist_eta0, abs_dist_phi0 ) - 0.5;
35 }
36 
37 __HOSTDEV__ long long GeoRegion::getDDE( float eta, float phi, float* distance, int* steps ) {
38 
39  float dist;
40  long long bestDDE = -1;
41  if ( !distance ) distance = &dist;
42  *distance = +10000000;
43  int intsteps = 0;
44  if ( !steps ) steps = &intsteps;
45 
46  float best_eta_corr = m_eta_correction;
47  float best_phi_corr = m_phi_correction;
48 
49  float raw_eta = eta + best_eta_corr;
50  float raw_phi = phi + best_phi_corr;
51 
52  int ieta = raw_eta_position_to_index( raw_eta );
53  int iphi = raw_phi_position_to_index( raw_phi );
54  index_range_adjust( ieta, iphi );
55 
56  long long newDDE = m_cells_g[ieta * m_cell_grid_phi + iphi];
57  float bestdist = +10000000;
58  ++( *steps );
59  int nsearch = 0;
60  while ( ( newDDE >= 0 ) && nsearch < 3 ) {
61  float dist_eta0, dist_phi0;
62 
63  *distance = calculate_distance_eta_phi( newDDE, eta, phi, dist_eta0, dist_phi0 );
64 
65  bestDDE = newDDE;
66  bestdist = *distance;
67 
68  if ( *distance < 0 ) return newDDE;
69 
70  // correct ieta and iphi by the observed difference to the hit cell
71  ieta += round( dist_eta0 );
72  iphi += round( dist_phi0 );
73  index_range_adjust( ieta, iphi );
74  long long oldDDE = newDDE;
75  newDDE = m_cells_g[ieta * m_cell_grid_phi + iphi];
76  ++( *steps );
77  ++nsearch;
78  if ( oldDDE == newDDE ) break;
79  }
80  float minieta = ieta + floor( m_mineta_correction / cell_grid_eta() );
81  float maxieta = ieta + ceil( m_maxeta_correction / cell_grid_eta() );
82  float miniphi = iphi + floor( m_minphi_correction / cell_grid_phi() );
83  float maxiphi = iphi + ceil( m_maxphi_correction / cell_grid_phi() );
84  if ( minieta < 0 ) minieta = 0;
85  if ( maxieta >= m_cell_grid_eta ) maxieta = m_cell_grid_eta - 1;
86  for ( int iieta = minieta; iieta <= maxieta; ++iieta ) {
87  for ( int iiphi = miniphi; iiphi <= maxiphi; ++iiphi ) {
88  ieta = iieta;
89  iphi = iiphi;
90  index_range_adjust( ieta, iphi );
91  newDDE = m_cells_g[ieta * m_cell_grid_phi + iphi];
92  ++( *steps );
93  if ( newDDE >= 0 ) {
94  float dist_eta0, dist_phi0;
95  *distance = calculate_distance_eta_phi( newDDE, eta, phi, dist_eta0, dist_phi0 );
96 
97  if ( *distance < 0 ) return newDDE;
98  if ( *distance < bestdist ) {
99  bestDDE = newDDE;
100  bestdist = *distance;
101  }
102  } else {
103  printf( "GeoRegin::getDDE, windows search ieta=%d iphi=%d is empty\n", ieta, iphi );
104  }
105  }
106  }
107  *distance = bestdist;
108  return bestDDE;
109 }
GeoRegion::m_cell_grid_eta
int m_cell_grid_eta
Definition: GeoRegion.h:109
Phi_mpi_pi
__HOSTDEV__ double Phi_mpi_pi(double x)
Definition: GeoRegion.cxx:7
GeoRegion::calculate_distance_eta_phi
__HOSTDEV__ float calculate_distance_eta_phi(const long long DDE, float eta, float phi, float &dist_eta0, float &dist_phi0) const
Definition: GeoRegion.cxx:27
GeoRegion::m_maxphi_correction
float m_maxphi_correction
Definition: GeoRegion.h:112
max
#define max(a, b)
Definition: cfImp.cxx:41
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
MuonGM::round
float round(const float toRound, const unsigned int decimals)
Definition: Mdt.cxx:27
GeoRegion::m_eta_correction
float m_eta_correction
Definition: GeoRegion.h:113
GeoRegion::index_range_adjust
__HOSTDEV__ bool index_range_adjust(int &ieta, int &iphi) const
Definition: GeoRegion.cxx:13
GeoRegion::m_phi_correction
float m_phi_correction
Definition: GeoRegion.h:113
GeoRegion::m_dphi_double
float m_dphi_double
Definition: GeoRegion.h:114
x
#define x
GeoRegion::cell_grid_phi
__HOSTDEV__ int cell_grid_phi() const
Definition: GeoRegion.h:79
CaloDetDescrElement_Gpu::eta
CUDA_HOSTDEV float eta() const
cell eta
Definition: CaloDetDescrElement_g.h:227
GeoRegion::m_cells_g
long long * m_cells_g
Definition: GeoRegion.h:104
GeoRegion::raw_phi_position_to_index
__HOSTDEV__ int raw_phi_position_to_index(float phi_raw) const
Definition: GeoRegion.h:92
M_PI
#define M_PI
Definition: GeoRegion.cxx:4
beamspotman.steps
int steps
Definition: beamspotman.py:505
GeoRegion::m_minphi_correction
float m_minphi_correction
Definition: GeoRegion.h:112
M_2PI
#define M_2PI
Definition: GeoRegion.cxx:5
__HOSTDEV__
#define __HOSTDEV__
Definition: GeoRegion.h:13
GeoRegion::raw_eta_position_to_index
__HOSTDEV__ int raw_eta_position_to_index(float eta_raw) const
Definition: GeoRegion.h:89
GeoRegion::m_all_cells
CaloDetDescrElement_Gpu * m_all_cells
Definition: GeoRegion.h:105
GeoRegion::cell_grid_eta
__HOSTDEV__ int cell_grid_eta() const
Definition: GeoRegion.h:78
GeoRegion.h
GeoRegion::m_maxeta_correction
float m_maxeta_correction
Definition: GeoRegion.h:112
GeoRegion::getDDE
__HOSTDEV__ long long getDDE(float eta, float phi, float *distance=0, int *steps=0)
Definition: GeoRegion.cxx:37
GeoRegion::m_mineta_correction
float m_mineta_correction
Definition: GeoRegion.h:112
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54
GeoRegion::m_deta_double
float m_deta_double
Definition: GeoRegion.h:114
GeoRegion::m_cell_grid_phi
int m_cell_grid_phi
Definition: GeoRegion.h:109