6#include "CLHEP/Vector/TwoVector.h"
16 const std::string& name,
17 const IInterface* parent):
37 if (
m_side < other.m_side)
return (
true);
38 if (
m_side > other.m_side)
return (
false);
39 if (
m_charge < other.m_charge)
return (
true);
40 if (
m_charge > other.m_charge)
return (
false);
41 if (
m_type < other.m_type)
return (
true);
42 if (
m_type > other.m_type)
return (
false);
51 std::ostringstream
ss;
61 std::ifstream ifs(lut_fileName.c_str());
64 return StatusCode::FAILURE;
77 if (line.empty())
continue;
79 if (line.substr(0, 5) ==
"side=") {
80 char side,
charge, ctype[15];
82 if (sscanf(line.c_str(),
"side=%c charge=%c %14s", &side, &
charge, ctype) != 3) {
83 ATH_MSG_ERROR(
"Invalid header line " << line_no <<
" in EndcapLUT file " << lut_fileName);
84 return StatusCode::FAILURE;
89 ATH_MSG_ERROR(
"Invalid header line " << line_no <<
" in EndcapLUT file " << lut_fileName);
90 return StatusCode::FAILURE;
95 m_tables.insert(TableMap::value_type(key, table));
101 ATH_MSG_ERROR(
"Missing header line " << line_no <<
" in EndcapLUT file " << lut_fileName);
102 return StatusCode::FAILURE;
107 if (sscanf(line.c_str(),
"%3d %3d %15lf %15lf", &iEta, &iPhi, &xcept, &slope) != 4) {
108 ATH_MSG_ERROR(
"Invalid data line " << line_no <<
" in EndcapLUT file " << lut_fileName);
109 return StatusCode::FAILURE;
111 table->m_xcepts[iEta-1][iPhi] = xcept;
112 table->m_slopes[iEta-1][iPhi] = slope;
117 return StatusCode::SUCCESS;
125 CLHEP::Hep2Vector mid1(z1, r1);
126 CLHEP::Hep2Vector mid2(z2, r2);
127 CLHEP::Hep2Vector dir = mid2 - mid1;
129 if(std::abs(mid1.unit() * dir.unit()) > 1.)
return 0;
131 double a = std::acos(mid1.unit() * dir.unit());
141 float cr1 = 0.080/400;
145 if (std::abs(x1)>=0.1) {
151 if(!(std::abs(s2+999)<0.1)) {
157 double xm = (x1+x2)/2.;
158 double ym = (y1+y2)/2.;
159 double c1 = (x2-x1)*xm+(y2-y1)*ym;
160 double c2_1 = -x1-A1*y1;
161 double c2_2 = -x2-A2*y2;
162 double yR1 = (-c1-c2_1*(x2-x1))/(A1*(x2-x1)-(y2-y1));
163 double yR2 = (-c1-c2_2*(x2-x1))/(A2*(x2-x1)-(y2-y1));
164 double xR1 = -A1*yR1-c2_1;
165 double xR2 = -A2*yR2-c2_2;
167 double xR = ((1./cr1)*xR1+(1./cr2)*xR2)/((1./cr1)+(1./cr2));
168 double yR = ((1./cr1)*yR1+(1./cr2)*yR2)/((1./cr1)+(1./cr2));
169 double sign = deltar / std::abs(deltar);
170 double radius = 0.5*(std::sqrt((xR-x1)*(xR-x1)+(yR-y1)*(yR-y1))+std::sqrt((xR-x2)*(xR-x2)+(yR-y2)*(yR-y2)));
183 <<
",type=" <<
dt2s(
type) <<
",iEta=" << iEta
184 <<
",iPhi=" << iPhi <<
",value=" << value <<
")");
186 if (iEta == -1) iEta = 0;
187 if (iEta == 30) iEta = 29;
189 if (iEta < 0 || iEta >=
ETAS || iPhi < 0 || iPhi >=
PHISEE) {
191 <<
", " << iEta <<
", " << iPhi <<
") Invalid indices");
199 <<
", " << iEta <<
", " << iPhi <<
") Invalid key");
206 double b = table->m_xcepts[iEta][iPhi];
207 double c = table->m_slopes[iEta][iPhi];
208 const double PT_MAX = 500;
219 double ptinv = value / b;
227 if( ptinv < (1/PT_MAX) ) pt = PT_MAX;
228 else { pt = 1/ptinv; }
235 double judge = b*b + 4*c*value;
239 double ptinv = (-b + pow(judge,0.5)) / c / 2;
247 if( ptinv < (1/PT_MAX) ) {
257 ATH_MSG_DEBUG(
"Pol2: b=" << b <<
" c=" << c <<
" pt=" << pt);
268 std::string stype(
type);
269 if (stype ==
"alphapol2")
return (
ALPHAPOL2);
270 if (stype ==
"betapol2")
return (
BETAPOL2);
273 if (stype ==
"cscpol2")
return (
CSCPOL2);
285 return (
"alphapol2");
break;
288 return (
"betapol2");
break;
291 return (
"tgcalphapol2");
break;
294 return (
"invradiuspol2");
break;
297 return (
"cscpol2");
break;
300 return (
"invalid");
break;
303 return (
"invalid");
break;
316 <<
"Alpha pT=" << ApT
320 if (iEta == -1) iEta = 0;
321 if (iEta == 30) iEta = 29;
323 if (iEta < 0 || iEta >=
ETAS || iPhi < 0 || iPhi >=
PHIS) {
324 ATH_MSG_WARNING(
"pTcombined("<< iEta <<
", " << iPhi <<
") Invalid indices");
329 int iphibin=iPhi < static_cast<int>(
PHIS1) ? iPhi :
PHIS-1 - iPhi;
333 double Ameana =
m_meana[ietabin][iphibin][0];
334 double Ameanb =
m_meanb[ietabin][iphibin][0];
335 double Ameanc =
m_meanc[ietabin][iphibin][0];
336 double Bmeana =
m_meana[ietabin][iphibin][1];
337 double Bmeanb =
m_meanb[ietabin][iphibin][1];
338 double Bmeanc =
m_meanc[ietabin][iphibin][1];
340 double Asigmaa =
m_sigmaa[ietabin][iphibin][0];
341 double Asigmab =
m_sigmab[ietabin][iphibin][0];
342 double Asigmac =
m_sigmac[ietabin][iphibin][0];
343 double Bsigmaa =
m_sigmaa[ietabin][iphibin][1];
344 double Bsigmab =
m_sigmab[ietabin][iphibin][1];
345 double Bsigmac =
m_sigmac[ietabin][iphibin][1];
347 auto notZero =[](
double v){
return (std::abs(v) >
ZERO_LIMIT);};
348 double MeanAP = notZero(ApT) ? (Ameana + Ameanb * std::exp( Ameanc / ApT)) : 1.0;
349 double MeanBP = notZero(BpT) ? (Bmeana + Bmeanb * std::exp( Bmeanc / BpT)) : 1.0;
350 double ApT_tmp = notZero(1-MeanAP) ? (std::abs(ApT) / (1-MeanAP)) : 1.0;
351 ApT_tmp = std::abs(ApT_tmp);
352 if(ApT_tmp >= 500) ApT_tmp = 500;
353 double BpT_tmp = notZero(1-MeanBP) ? (std::abs(BpT) / (1-MeanBP)) : 1.0;
354 BpT_tmp = std::abs(BpT_tmp);
355 if(BpT_tmp >= 500) BpT_tmp = 500;
360 if(ApT == 0. ) CApT = 0.;
361 if(BpT == 0. ) CBpT = 0.;
362 double NSigmaA= Asigmaa * ApT_tmp * ApT_tmp + Asigmab * ApT_tmp + Asigmac;
363 double NSigmaB= Bsigmaa * BpT_tmp * BpT_tmp + Bsigmab * BpT_tmp + Bsigmac;
365 double NVsigpTA = notZero(NSigmaA * ApT_tmp) ? (1./(NSigmaA * ApT_tmp) ): 1.0;
367 double NVsigpTB = notZero(NSigmaB * BpT_tmp) ? (1./(NSigmaB * BpT_tmp) ): 1.0;
368 double NVsigAsq = notZero(NSigmaA * NSigmaA) ? (1./(NSigmaA * NSigmaA)) : 1.0;
369 double NVsigBsq = notZero(NSigmaB * NSigmaB) ? (1./(NSigmaB * NSigmaB)) : 1.0;
371 double NVsigpTAsq = NVsigpTA * NVsigpTA;
372 double NVsigpTBsq = NVsigpTB * NVsigpTB;
373 double pt = notZero(NVsigAsq + NVsigBsq)? (1./std::sqrt((NVsigpTAsq + NVsigpTBsq)/(NVsigAsq + NVsigBsq))) : 0.;
374 if(pt>500) pt = 500.;
382 std::ifstream ifsmean(lut_mean.c_str());
383 std::ifstream ifssigma(lut_sigma.c_str());
384 if (!ifsmean.is_open()) {
385 ATH_MSG_ERROR(
"Cannot open EndcapLUT Mean file " << lut_mean);
386 return StatusCode::FAILURE;
388 if (!ifssigma.is_open()) {
389 ATH_MSG_ERROR(
"Cannot open EndcapLUT Sigma file " << lut_sigma);
390 return StatusCode::FAILURE;
395 for(std::size_t ei=0; ei <
ETAS1; ei++){
397 for(std::size_t pti=0; pti <
PTS1; pti++){
408 while (!ifsmean.eof()) {
409 getline(ifsmean, line);
410 if (line.empty())
continue;
413 double tmp_par1, tmp_par2, tmp_par3;
414 if (sscanf(line.c_str(),
"%d %d %d %lf %lf %lf", &iEta, &iPhi, &iNP, &tmp_par1, &tmp_par2, &tmp_par3) != 6) {
415 ATH_MSG_ERROR(
" Invalid data in mean EndcapLUT file " << lut_mean);
416 return StatusCode::FAILURE;
419 m_meana[iEta][iPhi][iNP] = tmp_par1;
420 m_meanb[iEta][iPhi][iNP] = tmp_par2;
421 m_meanc[iEta][iPhi][iNP] = tmp_par3;
425 while (!ifssigma.eof()) {
426 getline(ifssigma, line2);
427 if (line2.empty())
continue;
430 double tmp_par1, tmp_par2, tmp_par3;
431 if (sscanf(line2.c_str(),
"%d %d %d %lf %lf %lf", &iEta, &iPhi, &iNP, &tmp_par1, &tmp_par2, &tmp_par3) != 6) {
432 ATH_MSG_ERROR(
" Invalid data in mean EndcapLUT file " << lut_mean);
433 return StatusCode::FAILURE;
436 m_sigmaa[iEta][iPhi][iNP] = tmp_par1;
437 m_sigmab[iEta][iPhi][iNP] = tmp_par2;
438 m_sigmac[iEta][iPhi][iNP] = tmp_par3;
442 return StatusCode::SUCCESS;
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
double charge(const T &p)
static constexpr std::size_t ETAS1
static constexpr std::size_t PHIS1
double radius(double z1, double r1, double s1, double z2, double r2, double s2, double deltar) const
double m_sigmaa[ETAS1][PHIS1][PTS1]
double ptcombined(int iEta, int iPhi, double ApT, double BpT, double &CApT, double &CBpT) const
static const char * dt2s(DataType type)
static constexpr std::size_t PTS1
PtEndcapLUT(const std::string &type, const std::string &name, const IInterface *parent)
double m_sigmab[ETAS1][PHIS1][PTS1]
double lookup(int side, int charge, DataType type, int iEta, int iPhi, double value) const
double m_sigmac[ETAS1][PHIS1][PTS1]
double alpha(double z1, double r1, double z2, double r2) const
StatusCode readLUT(const std::string &lut_fileName)
StatusCode readLUTSigmaMean(const std::string &lut_mean, const std::string &lut_sigma)
static DataType s2dt(const char *type)
double m_meanc[ETAS1][PHIS1][PTS1]
double m_meana[ETAS1][PHIS1][PTS1]
double m_meanb[ETAS1][PHIS1][PTS1]
std::string toString() const
KeyType(int side, int charge, DataType type)
bool operator<(const KeyType &other) const