10#include <framework/logging/Logger.h>
31 typedef unsigned short XtID;
59 B2FATAL(
"The no. of alpha bins > limit !");
72 B2FATAL(
"The no. of theta bins > limit !");
81 return lhs[0] < rhs[0];
97 unsigned short nXtParams = params.size();
101 m_xts.insert(std::pair<
XtID, std::vector<float>>(xtID, params));
104 B2FATAL(
"The no. of xt params. > limit !");
111 void setXtParams(
unsigned short iCLayer,
unsigned short iLR,
unsigned short iAlpha,
unsigned short iTheta,
112 const std::vector<float>& params)
114 const XtID xtID =
getXtID(iCLayer, iLR, iAlpha, iTheta);
123 std::map<XtID, std::vector<float>>::iterator it =
m_xts.find(xtID);
125 if (it !=
m_xts.end()) {
127 (it->second)[i] += delta[i];
130 B2FATAL(
"Specified xt params not found in addXTParams !");
137 void addXTParams(
unsigned short iCLayer,
unsigned short iLR,
unsigned short iAlpha,
unsigned short iTheta,
138 const std::vector<float>& delta)
140 const XtID xtID =
getXtID(iCLayer, iLR, iAlpha, iTheta);
149 std::map<XtID, std::vector<float>>::iterator it =
m_xts.find(xtID);
151 if (it !=
m_xts.end()) {
153 (it->second)[i] = param[i];
156 B2FATAL(
"Specified xt params not found in replaceXTParams !");
163 void replaceXTParams(
unsigned short iCLayer,
unsigned short iLR,
unsigned short iAlpha,
unsigned short iTheta,
164 const std::vector<float>& param)
166 const XtID xtID =
getXtID(iCLayer, iLR, iAlpha, iTheta);
234 XtID getXtID(
unsigned short iCLayer,
unsigned short iLR,
unsigned short iAlpha,
unsigned short iTheta)
const
236 XtID id = iCLayer + 64 * iLR + 128 * iAlpha + 4096 * iTheta;
243 XtID getXtID(
unsigned short iCLayer,
unsigned short iLR,
float alpha,
float theta)
const
256 unsigned short iTheta = 999;
257 unsigned short ibin = 0;
259 if (it[0] <= theta && theta <= it[1]) {
265 if (iTheta == 999) B2FATAL(
"Theta bin not found !");
278 unsigned short iAlpha = 999;
281 if (it[0] <= alpha && alpha <= it[1]) {
287 if (iAlpha == 999) B2FATAL(
"Alpha bin not found ! " << alpha);
289 return getXtID(iCLayer, iLR, iAlpha, iTheta);
297 std::map<XtID, std::vector<float>>::const_iterator it =
m_xts.find(xtID);
298 if (it !=
m_xts.end()) {
301 B2FATAL(
"Specified xt params. not found in getXtParams !");
308 const std::vector<float>&
getXtParams(
unsigned short iCLayer,
unsigned short iLR,
unsigned short iAlpha,
309 unsigned short iTheta)
const
311 const XtID xtID =
getXtID(iCLayer, iLR, iAlpha, iTheta);
321 std::cout <<
" " << std::endl;
322 std::cout <<
"Contents of xt db" << std::endl;
323 std::cout <<
"alpha bins" << std::endl;
325 const double deg = 180. / M_PI;
328 for (
unsigned short i = 0; i < nAlphaBins; ++i) {
332 std::cout <<
" " << std::endl;
333 std::cout <<
"theta bins" << std::endl;
336 for (
unsigned short i = 0; i < nThetaBins; ++i) {
340 std::cout <<
" " << std::endl;
341 std::cout <<
"coefficients for xt" << std::endl;
343 for (
unsigned short iT = 0; iT < nThetaBins; ++iT) {
344 for (
unsigned short iA = 0; iA < nAlphaBins; ++iA) {
345 for (
unsigned short iCL = 0; iCL <
c_nSLayers; ++iCL) {
346 for (
unsigned short iLR = 0; iLR < 2; ++iLR) {
347 unsigned short iLRp = abs(iLR - 1);
349 const std::vector<float> params =
getXtParams(iCL, iLRp, iA, iT);
351 std::cout <<
" " << params[i];
353 std::cout <<
" " << std::endl;
365 std::ofstream fout(fileName);
368 B2ERROR(
"Specified output file could not be opened!");
370 const double deg = 180. / M_PI;
373 fout << nAlphaBins << std::endl;
375 for (
unsigned short i = 0; i < nAlphaBins; ++i) {
380 fout << nThetaBins << std::endl;
382 for (
unsigned short i = 0; i < nThetaBins; ++i) {
388 signed short phiAngle = 0.;
389 for (
unsigned short iT = 0; iT < nThetaBins; ++iT) {
390 for (
unsigned short iA = 0; iA < nAlphaBins; ++iA) {
391 for (
unsigned short iCL = 0; iCL <
c_nSLayers; ++iCL) {
392 for (
unsigned short iLR = 0; iLR < 2; ++iLR) {
393 unsigned short iLRp = abs(iLR - 1);
394 fout << std::setw(2) << std::right << std::fixed << iCL <<
" " << std::setw(5) << std::setprecision(
395 1) << deg*
m_thetaBins[iT][2] <<
" " << std::setw(5) << std::right << deg*
m_alphaBins[iA][2] <<
" " << std::setw(
396 1) << std::setprecision(1) << phiAngle <<
" " << std::setw(1) << iLRp;
397 const std::vector<float> params =
getXtParams(iCL, iLRp, iA, iT);
399 fout <<
" " << std::setw(15) << std::scientific << std::setprecision(8) << params[i];
422 std::map<XtID, std::vector<float>>::const_iterator it =
m_xts.find(xtId);
423 if (it !=
m_xts.end()) {
424 std::vector<float> allParams = it->second;
425 allParams.at(i) = value;
428 B2INFO(
"Specified xt params. not found in getXtParams.");
429 std::vector<float> allParams {0., 0., 0., 0., 0., 0., 0., 0.};
430 allParams.at(i) = value;
437 std::vector<std::pair<unsigned short, unsigned short>> result;
438 for (
auto ixt :
m_xts) {
439 for (
int i = 0; i < 8; ++i) {
440 result.push_back({ixt.first, i});
450 std::map<XtID, std::vector<float>>
Database object for xt-relations.
static bool comp(const array3 &lhs, const array3 &rhs)
Static function for sorting.
ClassDef(CDCXtRelations, 2)
ClassDef.
void replaceXTParams(unsigned short iCLayer, unsigned short iLR, unsigned short iAlpha, unsigned short iTheta, const std::vector< float > ¶m)
Replace xt parameters for the specified id.
const std::vector< float > & getXtParams(unsigned short iCLayer, unsigned short iLR, unsigned short iAlpha, unsigned short iTheta) const
Get xt parameters for the specified id.
void setThetaBin(const array3 &theta)
Set theta-angle bin (rad)
static unsigned short getGlobalUniqueID()
Get global unique id.
void outputToFile(std::string fileName) const
Output the contents in test file format.
XtID getXtID(unsigned short iCLayer, unsigned short iLR, unsigned short iAlpha, unsigned short iTheta) const
Get xt id.
CDCXtRelations()
Default constructor.
const array3 & getThetaBin(unsigned short i) const
Get i-th theta-angle bin info.
void setGlobalParam(double value, unsigned short xtId, unsigned short i)
Set global parameter for i-th component of the specified xtId.
const array3 & getAlphaBin(unsigned short i) const
Get i-th alpha-angle bin info.
unsigned short getNoOfAlphaBins() const
Get no.
unsigned short m_xtParamMode
Mode for xt parameterization.
unsigned short m_nXtParams
no.
std::map< XtID, std::vector< float > > m_xts
XT-relation coefficients for each layer, Left/Right, entrance angle and polar angle.
XtID getXtID(unsigned short iCLayer, unsigned short iLR, float alpha, float theta) const
Get xt id.
void setXtParams(unsigned short iCLayer, unsigned short iLR, unsigned short iAlpha, unsigned short iTheta, const std::vector< float > ¶ms)
Set xt parameters for the specified id.
const std::vector< float > & getXtParams(const XtID xtID) const
Get xt parameters for the specified id.
void replaceXTParams(const XtID xtID, const std::vector< float > ¶m)
Replace xt parameters for the specified id.
float getAlphaPoint(unsigned short i) const
Get i-th alpha-angle point (rad)
unsigned short getNoOfThetaBins() const
Get no.
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams() const
list stored global parameters TODO FIXME CDC not ready
void addXTParams(unsigned short iCLayer, unsigned short iLR, unsigned short iAlpha, unsigned short iTheta, const std::vector< float > &delta)
Update xt parameters for the specified id.
unsigned short getXtParamMode() const
Get xt parameterization mode.
void setXtParamMode(unsigned short mode)
Set xt parameterization mode.
void setXtParams(const XtID xtID, const std::vector< float > ¶ms)
Set xt parameters for the specified id.
std::vector< array3 > m_alphaBins
alpha bins for xt (rad)
std::vector< array3 > m_thetaBins
theta bins for xt (rad)
void addXTParams(const XtID xtID, const std::vector< float > &delta)
Update xt parameters for the specified id.
float getThetaPoint(unsigned short i) const
Get i-th theta-angle point (rad)
void setAlphaBin(const array3 &alpha)
Set alpha-angle bin (rad)
double getGlobalParam(unsigned short xtId, unsigned short i) const
Get global parameter for i-th component of the specified xtId.
std::array< float, 3 > array3
angle bin info.
void dump() const
Print all contents.
Abstract base class for different kinds of events.