ATLAS Offline Software
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
MuonCalib::BFieldCorFunc Class Reference

#include <BFieldCorFunc.h>

Inheritance diagram for MuonCalib::BFieldCorFunc:
Collaboration diagram for MuonCalib::BFieldCorFunc:

Public Types

typedef std::vector< double > ParVec
 

Public Member Functions

 BFieldCorFunc (const std::string &quality, const CalibFunc::ParVec &parameters, const IRtRelation *rt)
 Constructor: quality = "high", slow but accurate initialization initialization of the correction function, quality = "medium", compromise between speed and accuracy of the initialization of the correction function (default), quality = "low", fast initialization of the correction function at the price of lower quality. More...
 
 BFieldCorFunc (const CalibFunc::ParVec &parameters, const IRtRelation *rt)
 Constructor: parameters[0] = high voltage [V], parameters[1] = \( \epsilon \),. More...
 
double epsilon () const
 < get the \( \epsilon \) parameter of the B-field correction function More...
 
void setRtRelationship (const IRtRelation &rt)
 < set the \( \epsilon \) parameter of the B-field correction function = eps More...
 
std::string name () const
 get the class name More...
 
double correction (double t, double B_wire, double B_mu) const
 get t(r, \( \vec{B} \)!=0)-t(r, \( \vec{B} \)=0); t = drift time t [ns] for B=0; B_wire = magnetic field parallel to the anode wire of the given tube, B_mu = magnetic field orthogonal to the wire and parallel to the muon trajectory in the given tube [B] = Tesla More...
 
double correction_to_B (double t, double B_wire, double B_mu, double B_factor=-1.0) const
 
virtual std::string typeName () const
 
unsigned int nPar () const
 
const ParVecparameters () const
 
double par (unsigned int index) const
 

Private Member Functions

void init (const std::string &quality, const CalibFunc::ParVec &params, const IRtRelation *rt)
 
double t_from_r (const double &r, const IRtRelation *rt) const
 
double integral (const double &r_min, const double &r_max, const IRtRelation *rt) const
 

Private Attributes

std::vector< double > m_param
 
std::string m_quality
 
double m_step_size
 
Amg::VectorX m_alpha
 
const Legendre_polynomialm_Legendre
 
double m_t_min
 
double m_t_max
 
double m_r_min
 
double m_r_max
 
ParVec m_parameters
 

Detailed Description

This class allows the user to get the difference between the drift time measured by a tube operated in a magnetic field \( \vec{B} \) and the drift time which would be measured by this tube if \( \vec{B} \) vanished.

Correction:

\[ t(r,\vec{B}) = t(r,\vec{B}=0) + B_\perp^{2-\epsilon}\cdot \int\limits_{25\ \mu m}^{r} \frac{v_{B=0}^{1-\epsilon}(r')} {E^{2-\epsilon}(r')}\,dr' \]

.

\( B_\perp = |\vec{B}_\perp| \); \( \vec{B}_\perp = \vec{B}_{wire}+\vec{B}_\mu \);

\( \vec{B}_{wire} \): magnetic field parallel to the anode wire of the given tube;

\( \vec{B}_\mu \): magnetic field magnetic field perpendicular to wire and parallel to the muon trajectory in the given tube.

Definition at line 61 of file BFieldCorFunc.h.

Member Typedef Documentation

◆ ParVec

typedef std::vector<double> MuonCalib::CalibFunc::ParVec
inherited

Definition at line 36 of file CalibFunc.h.

Constructor & Destructor Documentation

◆ BFieldCorFunc() [1/2]

MuonCalib::BFieldCorFunc::BFieldCorFunc ( const std::string &  quality,
const CalibFunc::ParVec parameters,
const IRtRelation rt 
)
inlineexplicit

Constructor: quality = "high", slow but accurate initialization initialization of the correction function, quality = "medium", compromise between speed and accuracy of the initialization of the correction function (default), quality = "low", fast initialization of the correction function at the price of lower quality.

parameters[0] = high voltage [V], parameters[1] = \( \epsilon \),

Definition at line 64 of file BFieldCorFunc.h.

◆ BFieldCorFunc() [2/2]

MuonCalib::BFieldCorFunc::BFieldCorFunc ( const CalibFunc::ParVec parameters,
const IRtRelation rt 
)
inlineexplicit

Constructor: parameters[0] = high voltage [V], parameters[1] = \( \epsilon \),.

Definition at line 77 of file BFieldCorFunc.h.

Member Function Documentation

◆ correction()

double BFieldCorFunc::correction ( double  t,
double  B_wire,
double  B_mu 
) const
virtual

get t(r, \( \vec{B} \)!=0)-t(r, \( \vec{B} \)=0); t = drift time t [ns] for B=0; B_wire = magnetic field parallel to the anode wire of the given tube, B_mu = magnetic field orthogonal to the wire and parallel to the muon trajectory in the given tube [B] = Tesla

Implements MuonCalib::IMdtBFieldCorFunc.

Definition at line 237 of file BFieldCorFunc.cxx.

237  {
238  if (m_Legendre == nullptr) { return 0.0; }
239 
241  // VARIABLES //
243  double B_perp(std::hypot(B_wire, B_mu)); // B orthogonal to the
244  // electron drift path
245  double B_factor(std::pow(B_perp, 2.0 - m_param[1]));
246  double precision(0.1); // precision of the correction in ns
247  double t_max(t); // upper time search limit
248  double t_min(t - 2 * correction_to_B(t, B_wire, B_mu, B_factor)); // lower time search limit
249  if (t_min < m_t_min) t_min = m_t_min;
250  double time(t); // auxiliary time variable
251  double integ(0.0); // integral
252  double tmean(0.5 * (m_t_min + m_t_max)); // mean time
253  double tlength(m_t_max - m_t_min); // length of drift-time interval
254 
256  // DRIFT TIME CHECK //
258  if (t <= m_t_min) { return 0.0; }
259  if (t > m_t_max) {
260  t_max = m_t_max;
261  time = m_t_max;
262  }
263 
265  // SEARCH FOR THE CORRECTED DRIFT TIME //
267  while (t_max - t_min > precision) {
268  integ = 0.0;
269  for (int k = 0; k < m_alpha.rows(); k++) {
270  integ = integ + m_alpha[k] * m_Legendre->value(k, 2 * (0.5 * (t_min + t_max) - tmean) / tlength);
271  }
272  if (0.5 * (t_min + t_max) + B_factor * integ > time) {
273  t_max = 0.5 * (t_min + t_max);
274  } else {
275  t_min = 0.5 * (t_min + t_max);
276  }
277  }
278 
279  return B_factor * integ;
280 } // end BFieldCorFunc::correction

◆ correction_to_B()

double BFieldCorFunc::correction_to_B ( double  t,
double  B_wire,
double  B_mu,
double  B_factor = -1.0 
) const

Definition at line 287 of file BFieldCorFunc.cxx.

287  {
288  if (m_Legendre == nullptr) { return 0.0; }
290  // VARIABLES //
292  if (B_factor < 0) {
293  double B_perp(std::hypot(B_wire, B_mu));
294  // B orthogonal to the electron drift path
295  B_factor = std::pow(B_perp, 2.0 - m_param[1]);
296  }
297  double time(t);
298  double integ(0.0); // integral
299  double tmean(0.5 * (m_t_min + m_t_max)); // mean time
300  double tlength(m_t_max - m_t_min); // length of drift-time interval
301 
303  // DRIFT TIME CHECK //
305  if (t <= m_t_min) { return 0.0; }
306  if (t > m_t_max) { time = m_t_max; }
307 
309  // CALCULATE THE CORRECTION //
311  integ = 0.0;
312  for (int k = 0; k < m_alpha.rows(); k++) { integ = integ + m_alpha[k] * m_Legendre->value(k, 2 * (time - tmean) / tlength); }
313 
314  return B_factor * integ;
315 } // end BFieldCorFunc::correction_to_B

◆ epsilon()

double BFieldCorFunc::epsilon ( ) const

< get the \( \epsilon \) parameter of the B-field correction function

Definition at line 202 of file BFieldCorFunc.cxx.

202 { return m_param[1]; }

◆ init()

void BFieldCorFunc::init ( const std::string &  quality,
const CalibFunc::ParVec params,
const IRtRelation rt 
)
private

Definition at line 28 of file BFieldCorFunc.cxx.

28  {
30  // PARAMETERS //
32  m_quality = quality;
33  m_param = params;
34 
36  // CONSISTENCY CHECK //
38  if (m_param.size() != 2) {
39  MsgStream log(Athena::getMessageSvc(), "BFieldCorFunc");
40  log << MSG::ERROR << "Wrong number of parameters!" << endmsg;
41  m_Legendre = nullptr;
42  return;
43  }
44 
46  // VARIABLES //
48  unsigned int nb_points(31); // number of sample points for the integral
49  // in the correction function
50  double step; // r step size
51  double time; // auxiliary time variable
52  BaseFunctionFitter fitter(6); // 6 fit parameters for the integral by
53  // default ("medium quality")
54  LegendrePolynomial legendre;
55 
57  // QUALITY SETTING //
59  if (m_quality == "high") {
60  fitter.set_number_of_coefficients(8);
61  nb_points = 31;
62  m_step_size = 0.02;
63  }
64  if (m_quality == "medium") {
65  fitter.set_number_of_coefficients(8);
66  nb_points = 31;
67  m_step_size = 0.06;
68  }
69  if (m_quality == "low") {
70  fitter.set_number_of_coefficients(8);
71  nb_points = 31;
72  m_step_size = 0.12;
73  }
74  // sample points for the integral factor in the correction function
75  std::vector<SamplePoint> sample_points(nb_points);
76 
78  // CALCULATE THE INTEGRAL PART OF THE CORRECTION FUNCTION //
80  m_t_min = (rt)->tLower();
81  m_t_max = (rt)->tUpper();
82 
83  // minimum and maximum radius //
84  m_r_min = 0.025 * CLHEP::mm; // minimum radius
85  m_r_max = rt->radius(m_t_max); // maximum radius
86  if (m_r_max > 17.0 || m_r_max < m_r_min) {
87  MsgStream log(Athena::getMessageSvc(), "BFieldCorFunc");
88  log << MSG::INFO << "UNPHYSICAL MAXIMUM DRIFT RADIUS OF " << m_r_max << ", WILL BE SET TO 17.0!" << endmsg;
89  m_r_max = 17.0;
90  }
91  step = ((m_r_max - m_r_min) / static_cast<double>(nb_points - 1));
92 
93  // set the sample points //
94  double prev_r = 0;
95  double prev_integral = 0;
96  for (unsigned int k = 0; k < nb_points; k++) {
97  time = t_from_r(m_r_min + k * step, rt);
98  sample_points[k].set_x1(2 * (time - 0.5 * (m_t_min + m_t_max)) / (m_t_max - m_t_min));
99  double new_r = rt->radius(time);
100  double new_integral = 1.0e9 * integral(prev_r, new_r, rt) + prev_integral;
101  sample_points[k].set_x2(new_integral);
102  sample_points[k].set_error(1.0);
103  prev_r = new_r;
104  prev_integral = new_integral;
105  }
106 
107  // perform the fit //
108  if (fitter.fit_parameters(sample_points, 1, nb_points, &legendre)) {
109  MsgStream log(Athena::getMessageSvc(), "BFieldCorFunc");
110  log << MSG::WARNING << "Unable to fit the integral in the correction!" << endmsg;
111  m_Legendre = nullptr;
112  return;
113  }
114  m_alpha = fitter.coefficients();
115 
117  // SET A POINTER TO THE LEGENDRE POLYNOMIAL //
120 
121  return;
122 } // end BFieldCorFunc::init

◆ integral()

double BFieldCorFunc::integral ( const double &  r_min,
const double &  r_max,
const IRtRelation rt 
) const
private

Definition at line 162 of file BFieldCorFunc.cxx.

162  {
163  // catch fp exceptions//
164  if (m_r_min < 1e-10 || r_min < m_r_min) return 0.0;
165 
167  // VARIABLES //
169  double E0(m_param[0] / std::log(m_r_max / m_r_min)); // E(r)=E0/r
170  double radius(r_max), rp(r_min); // auxiliary radius variables
171  double integ(0.0); // current value of the integral
172  // double step(0.010); // integration step size [mm]
173  double step(m_step_size); // integration step size [mm]
174  double time; // drift time
175 
177  // r IN [m_r_min, m_r_max]? //
179  if (r_max < r_min) { return 0.0; }
180  if (r_max > m_r_max) { radius = m_r_max; }
181 
183  // INTEGRATION //
185  double delta = step;
186  while (rp < radius) {
187  time = t_from_r(rp, rt);
188  if (rp + step > radius) delta = radius - rp;
189  integ = integ + 1.0e-3 * delta * std::pow(std::abs(rt->driftvelocity(time)) * 1.0e6, 1.0 - m_param[1]) /
190  std::pow(E0 / (rp * 1.0e-3), 2.0 - m_param[1]);
191  rp = rp + step;
192  }
193 
194  return integ;
195 } // end BFieldCorFunc::integral

◆ name()

std::string BFieldCorFunc::name ( ) const
virtual

get the class name

get t(r, \( \vec{B} \) !=0)-t(r, \( \vec{B} \) =0); t = measured drift time t [ns]; B_wire = magnetic field parallel to the anode wire of the given tube, B_mu = magnetic field orthogonal to the wire and parallel to the muon trajectory in the given tube [B] = Tesla

Implements MuonCalib::CalibFunc.

Definition at line 230 of file BFieldCorFunc.cxx.

230 { return std::string("BFieldCorFunc"); }

◆ nPar()

unsigned int MuonCalib::CalibFunc::nPar ( ) const
inlineinherited

Definition at line 39 of file CalibFunc.h.

39 { return m_parameters.size(); }

◆ par()

double MuonCalib::CalibFunc::par ( unsigned int  index) const
inlineinherited

Definition at line 41 of file CalibFunc.h.

41  {
42  if (index < nPar())
43  return m_parameters[index];
44  else
45  return 0.;
46  }

◆ parameters()

const ParVec& MuonCalib::CalibFunc::parameters ( ) const
inlineinherited

Definition at line 40 of file CalibFunc.h.

40 { return m_parameters; }

◆ setRtRelationship()

void BFieldCorFunc::setRtRelationship ( const IRtRelation rt)

< set the \( \epsilon \) parameter of the B-field correction function = eps

< set the r-t relationship used to calculate the B field correction to the measured drift time = rt

Definition at line 220 of file BFieldCorFunc.cxx.

220  {
221  init(m_quality, m_param, &rt);
222  return;
223 }

◆ t_from_r()

double BFieldCorFunc::t_from_r ( const double &  r,
const IRtRelation rt 
) const
private

Definition at line 129 of file BFieldCorFunc.cxx.

129  {
131  // VARIABLES //
133  double precision(0.010); // spatial precision of the inversion
134  double t_max(m_t_max); // upper time search limit
135  double t_min(m_t_min); // lower time search limit
136  double r_max(m_r_max); // upper radius search limit
137  double r_min(m_r_min); // lower radius search limit
139  // SEARCH FOR THE CORRESPONDING DRIFT TIME //
141  double t_guess, r_guess;
142 
143  do {
144  t_guess = t_min + (t_max - t_min) / (r_max - r_min) * (r - r_min);
145  r_guess = rt->radius(t_guess);
146  if (r_guess > r) {
147  r_max = r_guess;
148  t_max = t_guess;
149  } else {
150  r_min = r_guess;
151  t_min = t_guess;
152  }
153  } while (t_max - t_min > 0.1 && std::abs(r_guess - r) > precision);
154  return t_guess;
155 } // end BFieldCorFunc::t_from_r

◆ typeName()

virtual std::string MuonCalib::IMdtBFieldCorFunc::typeName ( ) const
inlinevirtualinherited

Implements MuonCalib::CalibFunc.

Definition at line 18 of file IMdtBFieldCorFunc.h.

18 { return "IMdtBFieldCorFunc"; }

Member Data Documentation

◆ m_alpha

Amg::VectorX MuonCalib::BFieldCorFunc::m_alpha
private

Definition at line 128 of file BFieldCorFunc.h.

◆ m_Legendre

const Legendre_polynomial* MuonCalib::BFieldCorFunc::m_Legendre
private

Definition at line 132 of file BFieldCorFunc.h.

◆ m_param

std::vector<double> MuonCalib::BFieldCorFunc::m_param
private

Definition at line 121 of file BFieldCorFunc.h.

◆ m_parameters

ParVec MuonCalib::CalibFunc::m_parameters
privateinherited

Definition at line 51 of file CalibFunc.h.

◆ m_quality

std::string MuonCalib::BFieldCorFunc::m_quality
private

Definition at line 124 of file BFieldCorFunc.h.

◆ m_r_max

double MuonCalib::BFieldCorFunc::m_r_max
private

Definition at line 139 of file BFieldCorFunc.h.

◆ m_r_min

double MuonCalib::BFieldCorFunc::m_r_min
private

Definition at line 139 of file BFieldCorFunc.h.

◆ m_step_size

double MuonCalib::BFieldCorFunc::m_step_size
private

Definition at line 125 of file BFieldCorFunc.h.

◆ m_t_max

double MuonCalib::BFieldCorFunc::m_t_max
private

Definition at line 137 of file BFieldCorFunc.h.

◆ m_t_min

double MuonCalib::BFieldCorFunc::m_t_min
private

Definition at line 137 of file BFieldCorFunc.h.


The documentation for this class was generated from the following files:
MuonCalib::BFieldCorFunc::m_r_max
double m_r_max
Definition: BFieldCorFunc.h:139
beamspotman.r
def r
Definition: beamspotman.py:676
LArSamples::FitterData::fitter
const ShapeFitter * fitter
Definition: ShapeFitter.cxx:23
MuonCalib::BFieldCorFunc::m_t_max
double m_t_max
Definition: BFieldCorFunc.h:137
MuonCalib::BFieldCorFunc::m_t_min
double m_t_min
Definition: BFieldCorFunc.h:137
index
Definition: index.py:1
MuonCalib::BFieldCorFunc::init
void init(const std::string &quality, const CalibFunc::ParVec &params, const IRtRelation *rt)
Definition: BFieldCorFunc.cxx:28
conifer::pow
constexpr int pow(int x)
Definition: conifer.h:20
MuonCalib::Legendre_polynomial::get_Legendre_polynomial
static const Legendre_polynomial * get_Legendre_polynomial(void)
get a pointer to the Legendre polynomial
Definition: Legendre_polynomial.cxx:31
MuonCalib::BFieldCorFunc::correction_to_B
double correction_to_B(double t, double B_wire, double B_mu, double B_factor=-1.0) const
Definition: BFieldCorFunc.cxx:287
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
MuonCalib::BFieldCorFunc::integral
double integral(const double &r_min, const double &r_max, const IRtRelation *rt) const
Definition: BFieldCorFunc.cxx:162
MuonCalib::BaseFunctionFitter
Definition: BaseFunctionFitter.h:47
MuonCalib::IRtRelation::driftvelocity
virtual double driftvelocity(double t) const =0
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib::Legendre_polynomial::value
double value(const int &order, const double &x) const
get the value of the Legendre polynomial of order m_order at x
MuonCalib::LegendrePolynomial
Definition: LegendrePolynomial.h:39
MuonCalib::BFieldCorFunc::t_from_r
double t_from_r(const double &r, const IRtRelation *rt) const
Definition: BFieldCorFunc.cxx:129
MuonCalib::BFieldCorFunc::m_alpha
Amg::VectorX m_alpha
Definition: BFieldCorFunc.h:128
MuonCalib::IRtRelation::radius
virtual double radius(double t) const =0
returns drift radius for a given time
MuonCalib::BFieldCorFunc::m_step_size
double m_step_size
Definition: BFieldCorFunc.h:125
ParticleGun_SamplingFraction.radius
radius
Definition: ParticleGun_SamplingFraction.py:96
python.SystemOfUnits.mm
int mm
Definition: SystemOfUnits.py:83
DeMoScan.index
string index
Definition: DeMoScan.py:362
MuonCalib::BFieldCorFunc::m_r_min
double m_r_min
Definition: BFieldCorFunc.h:139
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
MuonCalib::BFieldCorFunc::m_Legendre
const Legendre_polynomial * m_Legendre
Definition: BFieldCorFunc.h:132
MuonCalib::CalibFunc::m_parameters
ParVec m_parameters
Definition: CalibFunc.h:51
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
LArCellBinning.step
step
Definition: LArCellBinning.py:158
MuonCalib::CalibFunc::nPar
unsigned int nPar() const
Definition: CalibFunc.h:39
MuonCalib::BFieldCorFunc::m_param
std::vector< double > m_param
Definition: BFieldCorFunc.h:121
MuonCalib::BFieldCorFunc::m_quality
std::string m_quality
Definition: BFieldCorFunc.h:124
PowhegControl_ttFCNC_NLO.params
params
Definition: PowhegControl_ttFCNC_NLO.py:226
rp
ReadCards * rp
Definition: IReadCards.cxx:26
fitman.k
k
Definition: fitman.py:528