ATLAS Offline Software
CscRegUtils.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 #include "CscRegUtils.h"
7 
9 
10 #include <cmath>
11 
12 
13 namespace TrigL2MuonSA{
14 
15 
16 CscRegDict :: CscRegDict(const std::string &type, const std::string &name, const IInterface *parent)
18  m_util()
19 {
20 }
21 
22 
24 
25  int i=0;
26 
27  //small sector
28  const double SPwid = 0.32369;
29  const double Setamin = 1.97667;
30  const double Setamax = 2.76781;
31  const double SDisplace = (7441.+7518.)/2.;//7428.3;
32  const double SAtanNormal = 0.20223129856437;
33 
34  //Cside Small
35  for (int phi=0; phi<8; ++phi) {
36  m_reg_dict[i].etaMin=(-1)*Setamax;
37  m_reg_dict[i].etaMax=(-1)*Setamin;
38  m_reg_dict[i].phiMin=PhiConv( 0.125*M_PI+ phi*0.25*M_PI - 0.5*SPwid );
39  m_reg_dict[i].phiMax=PhiConv( 0.125*M_PI+ phi*0.25*M_PI + 0.5*SPwid );
40  m_reg_dict[i].phiCen= m_reg_dict[i].phiMod =PhiConv( 0.125*M_PI+ phi*0.25*M_PI );
41  m_reg_dict[i].Displacement=SDisplace;
45  ATH_MSG_DEBUG( "CscRegDict: hash= " << i << " StationName=" << stationName(i) << " StationEta=" << stationEta(i) << " StationPhi=" << stationPhi(i)
46  << " eta:[" << m_reg_dict[i].etaMin << "," << m_reg_dict[i].etaMax << "]"
47  << " phi:[" << m_reg_dict[i].phiMin << "," << m_reg_dict[i].phiMax << "]"
48  << " theta:[" << m_util.calc_theta(m_reg_dict[i].etaMin) << "," << m_util.calc_theta(m_reg_dict[i].etaMax) << "]");
49  ++i;
50  }
51  //Aside Small
52  for (int phi=0; phi<8; ++phi) {
53  m_reg_dict[i].etaMin=Setamin;
54  m_reg_dict[i].etaMax=Setamax;
55  m_reg_dict[i].phiMin=PhiConv( 0.125*M_PI+ phi*0.25*M_PI - 0.5*SPwid );
56  m_reg_dict[i].phiMax=PhiConv( 0.125*M_PI+ phi*0.25*M_PI + 0.5*SPwid );
57  m_reg_dict[i].phiCen= m_reg_dict[i].phiMod =PhiConv( 0.125*M_PI+ phi*0.25*M_PI );
58  m_reg_dict[i].Displacement=SDisplace;
62  ATH_MSG_DEBUG( "CscRegDict: hash= " << i << " StationName=" << stationName(i) << " StationEta=" << stationEta(i) << " StationPhi=" << stationPhi(i)
63  << " eta:[" << m_reg_dict[i].etaMin << "," << m_reg_dict[i].etaMax << "]"
64  << " phi:[" << m_reg_dict[i].phiMin << "," << m_reg_dict[i].phiMax << "]"
65  << " theta:[" << m_util.calc_theta(m_reg_dict[i].etaMin) << "," << m_util.calc_theta(m_reg_dict[i].etaMax) << "]");
66  ++i;
67  }
68 
69 
70  //large sector
71  const double LPwid = 0.514507;
72  const double Letamin = 2.01471;
73  const double Letamax = 2.75914;
74  const double LDisplace = (7800.+7880.)/2.;//7789.6;
75  const double LAtanNormal = 0.20223129856437;
76 
77  //Cside Large
78  for (int phi=0; phi<8; ++phi) {
79  m_reg_dict[i].etaMin=(-1)*Letamax;
80  m_reg_dict[i].etaMax=(-1)*Letamin;
81  m_reg_dict[i].phiMin=PhiConv( phi*0.25*M_PI - 0.5*LPwid );
82  m_reg_dict[i].phiMax=PhiConv( phi*0.25*M_PI + 0.5*LPwid );
83  m_reg_dict[i].phiCen= m_reg_dict[i].phiMod =PhiConv( phi*0.25*M_PI );
84  m_reg_dict[i].Displacement=LDisplace;
88  ATH_MSG_DEBUG( "CscRegDict: hash= " << i << " StationName=" << stationName(i) << " StationEta=" << stationEta(i) << " StationPhi=" << stationPhi(i)
89  << " eta:[" << m_reg_dict[i].etaMin << "," << m_reg_dict[i].etaMax << "]"
90  << " phi:[" << m_reg_dict[i].phiMin << "," << m_reg_dict[i].phiMax << "]"
91  << " theta:[" << m_util.calc_theta(m_reg_dict[i].etaMin) << "," << m_util.calc_theta(m_reg_dict[i].etaMax) << "]");
92  ++i;
93  }
94  //Aside Large
95  for (int phi=0; phi<8; ++phi) {
96  m_reg_dict[i].etaMin=Letamin;
97  m_reg_dict[i].etaMax=Letamax;
98  m_reg_dict[i].phiMin=PhiConv( phi*0.25*M_PI - 0.5*LPwid );
99  m_reg_dict[i].phiMax=PhiConv( phi*0.25*M_PI + 0.5*LPwid );
100  m_reg_dict[i].phiCen= m_reg_dict[i].phiMod =PhiConv( phi*0.25*M_PI );
101  m_reg_dict[i].Displacement=LDisplace;
105  ATH_MSG_DEBUG( "CscRegDict: hash= " << i << " StationName=" << stationName(i) << " StationEta=" << stationEta(i) << " StationPhi=" << stationPhi(i)
106  << " eta:[" << m_reg_dict[i].etaMin << "," << m_reg_dict[i].etaMax << "]"
107  << " phi:[" << m_reg_dict[i].phiMin << "," << m_reg_dict[i].phiMax << "]"
108  << " theta:[" << m_util.calc_theta(m_reg_dict[i].etaMin) << "," << m_util.calc_theta(m_reg_dict[i].etaMax) << "]");
109  ++i;
110  }
111  /*
112  ATH_MSG_DEBUG( "m_isMC=" << m_isMC );
113  if (!m_isMC){
114  initializePosCorrectionParameters();
115  initializeDictionaryForData();
116  }
117  */
119 
120 
121  return StatusCode::SUCCESS;
122 }
123 
124 
125 int CscRegDict :: get_hash(int stationname, int stationeta, int stationphi) const{
126 
127  int sname, seta, sphi;
128  if (stationname == 50 || stationname == 51) sname = stationname-50;
129  else { ATH_MSG_DEBUG( "stationname is out of [50,51]");
130  return 999;
131  }
132  if (stationeta == 1 || stationeta ==-1) seta = ((stationeta == 1)? 1:0);
133  else { ATH_MSG_DEBUG( "stationeta is not 1 nor -1" );
134  return 999;
135  }
136  if (stationphi >=1 || stationeta <=8) sphi = stationphi-1;
137  else { ATH_MSG_DEBUG( "stationeta is out of [1,8]" );
138  return 999;
139  }
140 
141  return m_module_hashes[sname][seta][sphi];
142 }
143 
144 
145 
146 
147 double CscRegDict :: PhiConv(double phi){
148 
149  if (phi>M_PI) {
150  phi -= 2*M_PI;
151  }
152 
153  return phi;
154 }
155 
156 
158 
159  int hash = 0;
160  for (int sname=0; sname<2; ++sname) {
161  for (int seta=0; seta<2; ++seta) {
162  for (int sphi=0; sphi<8; ++sphi) {
163  m_module_hashes[sname][seta][sphi] = hash;
164  ATH_MSG_DEBUG( "module_hash:" << hash << " StationName:" << sname+50 << " StationEta:" << (seta ? 1 : -1) << " StationPhi:" << sphi+1 );
165  ++hash;
166  }
167  }
168  }
169  return 0;
170 }
171 
172 
173 
175 
176  double phi=m_reg_dict[module].phiCen;
177  double theta=m_reg_dict[module].idealAtanNormal;
178  Amg::Vector3D nomvec( std::sin(theta)*std::cos(phi), std::sin(theta)*std::sin(phi), std::cos(theta));
179 
180  return nomvec;
181 
182 }
183 
184 
185 double CscRegDict :: posCorrectionR(int module, int charge/*0 or 1*/){
186 
188  if (1==charge) return m_reg_dict[module].posCorrectionPlusR;
189 
190  return 0.0;
191 }
192 
193 
194 double CscRegDict :: posCorrectionZ(int module, int charge/*0 or 1*/){
195 
196  double tan = this->idealAtanNormal(module);
197 
198  if (0==charge) return (-1)*tan*( m_reg_dict[module].posCorrectionMinusR );
199  if (1==charge) return (-1)*tan*( m_reg_dict[module].posCorrectionPlusR );
200 
201  return 0.0;
202 }
203 
204 
205 
206 
207 double UtilTools :: calc_phi(double x, double y) const{
208 
209  double /*abs_x=std::abs(x),*/ abs_y=std::abs(y);
210  double abs_sine=abs_y/std::sqrt(x*x+y*y);
211  //std::cout << "convert " << ASin(abssin) << std::endl;
212 
213  if (x>0 && y>=0) {
214  return std::asin(abs_sine);
215  }else if(x<=0 && y>0){
216  return M_PI-std::asin(abs_sine);
217  }else if(x<0 && y<=0){
218  return M_PI+std::asin(abs_sine)-2*M_PI;
219  }else if(x>=0 && y<0){
220  return 2*M_PI-std::asin(abs_sine)-2*M_PI;
221  }else{
222  //std::cout<< "UtilTools::calc_phi, sin=cos=0" << std::endl;
223  return 0.;
224  }
225 
226 }
227 
228 
229 double UtilTools :: calc_dphi(double phi1, double phi2) const
230 {
231  double dphi=phi1-phi2;
232 
233  if (dphi > M_PI) {
234  dphi -= 2*M_PI;
235  }else if(dphi < (-1)*M_PI){
236  dphi += 2*M_PI;
237  }
238 
239  return dphi;
240 }
241 
242 
243 double UtilTools :: average_phi(double phi1, double phi2) const
244 {
245  double phi = 0.;
246 
247  if (phi1*phi2<0. && std::abs(phi1)>M_PI/2.){
248 
249  double tmp1 = (phi1>0.) ? phi1 - M_PI : phi1 + M_PI;
250  double tmp2 = (phi2>0.) ? phi2 - M_PI : phi2 + M_PI;
251 
252  double tmp = (tmp1+tmp2)/2.;
253 
254  phi = (tmp>0.) ? tmp - M_PI : tmp + M_PI;
255 
256  } else {
257 
258  phi = (phi1+phi2)/2.;
259 
260  }
261 
262  return phi;
263 }
264 
265 
266 
268 
269  return ReturnCode::SUCCESS;
270 }
271 
272 
273 
275 
276 
277  return ReturnCode::SUCCESS;
278 }
279 
280 
281 }//namespace TrigL2MuonSA
TrigL2MuonSA::CscRegDict::m_module_hashes
int m_module_hashes[2][2][8]
Definition: CscRegUtils.h:85
TrigL2MuonSA::CscRegDict::PhiConv
double PhiConv(double phi)
Definition: CscRegUtils.cxx:147
DeMoUpdate.tmp2
string tmp2
Definition: DeMoUpdate.py:1168
TrigL2MuonSA::CscRegDict::idealAtanNormal
double idealAtanNormal(int module) const
Definition: CscRegUtils.h:76
TrigL2MuonSA::CscRegDict::posCorrectionZ
double posCorrectionZ(int module, int charge)
Definition: CscRegUtils.cxx:194
AthMsgStreamMacros.h
M_PI
#define M_PI
Definition: ActiveFraction.h:11
xAOD::etaMax
etaMax
Definition: HIEventShape_v2.cxx:46
TrigL2MuonSA::CscRegDict::initializePosCorrectionParameters
ReturnCode initializePosCorrectionParameters()
Definition: CscRegUtils.cxx:274
TrigL2MuonSA::CscRegDict::CscRegion::posCorrectionPlusR
double posCorrectionPlusR
Definition: CscRegUtils.h:60
TrigL2MuonSA::CscRegDict::CscRegion::phiCen
double phiCen
Definition: CscRegUtils.h:55
CscRegUtils.h
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
TrigL2MuonSA::CscRegDict::initializeDictionaryForData
ReturnCode initializeDictionaryForData()
Definition: CscRegUtils.cxx:267
TrigL2MuonSA::CscRegDict::initializeHashDictionary
ReturnCode initializeHashDictionary()
Definition: CscRegUtils.cxx:157
x
#define x
TrigL2MuonSA::CscRegDict::CscRegion::etaMin
double etaMin
Definition: CscRegUtils.h:51
TrigL2MuonSA::CscRegDict::CscRegion::actualAtanNormal
double actualAtanNormal
Definition: CscRegUtils.h:59
TrigL2MuonSA::CscRegDict::stationName
int stationName(int hash) const
Definition: CscRegUtils.h:104
TrigL2MuonSA::CscRegDict::initialize
virtual StatusCode initialize() override
Definition: CscRegUtils.cxx:23
TrigL2MuonSA::CscRegDict::CscRegion::Displacement
double Displacement
Definition: CscRegUtils.h:57
python.PyAthena.module
module
Definition: PyAthena.py:131
TrigL2MuonSA::UtilTools::calc_dphi
double calc_dphi(double phi1, double phi2) const
Definition: CscRegUtils.cxx:229
TrigL2MuonSA::UtilTools::calc_theta
double calc_theta(double eta) const
Definition: CscRegUtils.h:30
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigL2MuonSA::CscRegDict::CscRegDict
CscRegDict(const std::string &type, const std::string &name, const IInterface *parent)
Definition: CscRegUtils.cxx:16
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
drawFromPickle.tan
tan
Definition: drawFromPickle.py:36
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
TrigL2MuonSA::CscRegDict::CscRegion::phiMod
double phiMod
Definition: CscRegUtils.h:56
TrigL2MuonSA::UtilTools::calc_phi
double calc_phi(double x, double y) const
Definition: CscRegUtils.cxx:207
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
charge
double charge(const T &p)
Definition: AtlasPID.h:756
TrigL2MuonSA::CscRegDict::get_hash
int get_hash(int stationname, int stationeta, int stationphi) const
Definition: CscRegUtils.cxx:125
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TrigL2MuonSA::CscRegDict::CscRegion::phiMin
double phiMin
Definition: CscRegUtils.h:53
TrigL2MuonSA::UtilTools::average_phi
double average_phi(double phi1, double phi2) const
Definition: CscRegUtils.cxx:243
TrigL2MuonSA::CscRegDict::CscRegion::phiMax
double phiMax
Definition: CscRegUtils.h:54
TrigL2MuonSA::ReturnCode
Definition: CscRegUtils.h:126
LArCellBinning.etaMin
etaMin
Definition: LArCellBinning.py:84
y
#define y
TrigL2MuonSA::CscRegDict::stationPhi
int stationPhi(int hash) const
Definition: CscRegUtils.h:119
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
TrigL2MuonSA::CscRegDict::CscRegion::etaMax
double etaMax
Definition: CscRegUtils.h:52
TrigL2MuonSA::CscRegDict::stationEta
int stationEta(int hash) const
Definition: CscRegUtils.h:110
drawFromPickle.sin
sin
Definition: drawFromPickle.py:36
AthAlgTool
Definition: AthAlgTool.h:26
TrigL2MuonSA::CscRegDict::m_util
TrigL2MuonSA::UtilTools m_util
Definition: CscRegUtils.h:94
TrigL2MuonSA::CscRegDict::m_reg_dict
CscRegion m_reg_dict[32]
Definition: CscRegUtils.h:84
TrigL2MuonSA::ReturnCode::SUCCESS
@ SUCCESS
Definition: CscRegUtils.h:134
TrigL2MuonSA::CscRegDict::posCorrectionR
double posCorrectionR(int module, int charge)
Definition: CscRegUtils.cxx:185
TrigL2MuonSA::CscRegDict::nomalVector
Amg::Vector3D nomalVector(int module) const
Definition: CscRegUtils.cxx:174
TrigL2MuonSA::CscRegDict::CscRegion::idealAtanNormal
double idealAtanNormal
Definition: CscRegUtils.h:58
TrigL2MuonSA
Definition: AlignmentBarrelLUT.h:13
TrigL2MuonSA::CscRegDict::CscRegion::posCorrectionMinusR
double posCorrectionMinusR
Definition: CscRegUtils.h:61