12#include "CLHEP/Vector/Sqr.h"
13#include "trg/cdc/Lpav.h"
30 static double err_dis_inv(
double x,
double y,
double w,
double a,
double b)
32 if (a == 0 && b == 0) {
35 double f = x * b - y * a;
36 double rsq = x * x + y * y;
110 double rri(xi * xi + yi * yi);
111 double wrri(wi * rri);
116 double xxav((
m_xxsum + wi * xi * xi) * wsum_inv);
117 double yyav((
m_yysum + wi * yi * yi) * wsum_inv);
118 double xyav((
m_xysum + wi * xi * yi) * wsum_inv);
119 double xrrav((
m_xrrsum + xi * wrri) * wsum_inv);
120 double yrrav((
m_yrrsum + yi * wrri) * wsum_inv);
121 double rrrrav((
m_rrrrsum + wrri * rri) * wsum_inv);
135 double xxav(
m_xxsum * wsum_inv);
136 double yyav(
m_yysum * wsum_inv);
137 double xyav(
m_xysum * wsum_inv);
146 double xrrav,
double yrrav,
double rrrrav)
151 double rrav_p = xxav_p + yyav_p;
153 double a = std::fabs(xxav_p - yyav_p);
154 double b = 4 * xyav_p * xyav_p;
155 double asqpb = a * a + b;
156 double rasqpb = std::sqrt(asqpb);
157 double splus = 1 + a / rasqpb;
158 double sminus = b / (asqpb * splus);
159 splus = std::sqrt(0.5 * splus);
160 sminus = std::sqrt(0.5 * sminus);
164 if (xxav_p <= yyav_p) {
192 double rrav_p_inv(1 / rrav_p);
193 m_xxavp = (cos2 * xxav_p + cs2 * xyav_p + sin2 * yyav_p) * rrav_p_inv;
194 m_yyavp = (cos2 * yyav_p - cs2 * xyav_p + sin2 * xxav_p) * rrav_p_inv;
198 double xrrav_p = (xrrav - 2 * xxav *
m_xav + xav2 *
m_xav -
200 double yrrav_p = (yrrav - 2 * yyav *
m_yav + yav2 *
m_yav -
205 double rrav = xxav + yyav;
206 double rrrrav_p = rrrrav
208 + rrav * (xav2 + yav2)
209 - 2 *
m_xav * xrrav_p - xav2 * rrav_p
210 - 2 *
m_yav * yrrav_p - yav2 * rrav_p;
211 m_rrrravp = rrrrav_p * rrav_p_inv * rrav_p_inv;
220 double rri(xi * xi + yi * yi);
230 double wrri(wi * rri);
278 o <<
" nc=" << a.m_nc <<
" chisq=" << a.m_chisq <<
" " << (
TRGCDCLpar&) a;
291 double c1 = - rrrrm1 + xrrxrr + yrryrr - 4 * xxyy;
292 double c2 = 4 + rrrrm1 - 4 * xxyy;
303 double dlamax = 0.001 / chiscl;
306 double dlambda = dlamax;
307 while (itry < ntry && std::fabs(dlambda) >= dlamax) {
308 double cpoly = c0 + lambda * (c1 + lambda *
309 (c2 + lambda * lambda * c4));
310 double dcpoly = c1 + lambda * (c2d + lambda * lambda * c4d);
311 dlambda = - cpoly / dcpoly;
315 lambda = lambda < 0 ? 0 : lambda;
332 if (c >= 0 && b <= 0) {
333 return (-b - std::sqrt(b * b - 4 * a * c)) / 2 / a;
334 }
else if (c >= 0 && b > 0) {
335 std::cout <<
" returning " << -1 << std::endl;
338 return (-b + std::sqrt(b * b - 4 * a * c)) / 2 / a;
348 if (lambda < 0)
return -1;
351 if (h11 == 0.0)
return -1;
354 double h34 = 1 + 2 * lambda;
355 double rootsq = (h14 * h14 / h11 / h11) + 4 * h34;
356 if (std::fabs(h22) > std::fabs(h24)) {
357 if (h22 == 0.0)
return -1;
358 double ratio = h24 / h22;
359 rootsq += ratio * ratio ;
360 m_kappa = 1 / std::sqrt(rootsq);
363 if (h24 == 0.0)
return -1;
364 double ratio = h22 / h24;
365 rootsq = 1 + ratio * ratio * rootsq;
366 m_beta = 1 / std::sqrt(rootsq);
402 if (lambda < 0)
return -1;
409 double det = h11 * h22 - h12 * h12;
411 double r1 = (h14 * h22 - h24 * h12) / (det);
412 double r2 = (h24 * h11 - h14 * h12) / (det);
413 double kinvsq = r1 * r1 + r2 * r2;
414 m_kappa = std::sqrt(1 / kinvsq);
421 if (h11 != 0 && h22 != 0) {
422 m_beta = 1 / std::sqrt(1 + h12 * h12 / h11 / h11);
424 }
else if (h11 != 0) {
443 if (
m_nc <= 3)
return -1;
459 if (
m_nc <= 3)
return -1;
475#ifdef BELLE_OPTIMIZED_RETURN
480 CLHEP::HepSymMatrix vret(4);
482 vret(1, 1) = m_xxsum;
483 vret(2, 1) = m_xysum;
484 vret(2, 2) = m_yysum;
488 vret(4, 1) = m_xrrsum;
489 vret(4, 2) = m_yrrsum;
490 vret(4, 3) = m_xxsum + m_yysum;
491 vret(4, 4) = m_rrrrsum;
498 std::cout <<
"TRGCDCLpav::cov:could not invert nc=" << m_nc << vret;
508#ifdef BELLE_OPTIMIZED_RETURN
513 CLHEP::HepSymMatrix vret(3);
519 vret = cov(1).similarity(dldc());
523 throw new Singular_c();
532 std::cout <<
"TRGCDCLpav::cov_c:could not invert " << vret;
534 throw new Singular_c();
545 if (
xy(r,
x,
y) != 0)
return -1;
546 phi = std::atan2(
y,
x);
547 if (
phi < 0)
phi += (2 * M_PI);
548 CLHEP::HepVector v(4);
560 double l =
cov().similarity(v);
562 double ls = std::sqrt(l);
577 if (
m_nc <= 3)
return -1;
578 CLHEP::HepVector v(4);
582 v(4) =
x *
x +
y *
y;
587 l =
cov().similarity(v);
613 double rri = (xi * xi + yi * yi);
614 double wrri = wi * rri;
633 double rri = (xi * xi + yi * yi);
634 double wrri = wi * rri;
653 double rri = (xi * xi + yi * yi);
654 double wrri = wi * rri;
677#ifdef BELLE_OPTIMIZED_RETURN
699 if (
m_nc <= 3)
return 0;
711 if (
m_nc <= 3)
return -1;
718 if (sim < 0)
return -1;
720 double delta = sqr(
d) * w / (1 + sim * w);
double m_beta
data members
double m_kappa
data members
double m_gamma
data members
void scale(double s)
private member functions
double m_alpha
data members
exception class, no covarience matrix.
double m_xsum
data members
double m_xyavp
data members
double m_rrrravp
data members
double m_xrravp
data members
double m_rrrrsum
data members
double m_chisq
data members
double m_wsum
data members
double m_sinrot
data members
double m_cosrot
data members
double m_xxsum
data members
double m_ysum
data members
double m_xrrsum
data members
double m_rscale
data members
double m_yysum
data members
double m_yrravp
data members
double m_xxavp
data members
double m_xysum
data members
double m_wsum_temp
data members
double m_yrrsum
data members
double m_yyavp
data members
std::ostream & operator<<(std::ostream &output, const IntervalOfValidity &iov)
B2Vector3< DataType > operator+(const TVector3 &a, const B2Vector3< DataType > &b)
non-memberfunction for adding a TVector3 to a B2Vector3
static double err_dis_inv(double x, double y, double w, double a, double b)
distance error
void add_point(double x, double y, double w=1)
member functions to add point
int extrapolate(double, double &, double &) const
const member function for extrapolation
void neg()
member functions
double d0(double x, double y) const
private const member functions
void calculate_average(void)
member functions for calculation
void calculate_average_n(double xxav, double yyav, double xyav, double xrrav, double yrrav, double rrrrav)
private member function calculate_average_n
CLHEP::HepSymMatrix cov(int=0) const
const member function cov
double solve_lambda(void)
private member function solve_lambda
bool xy(double, double &, double &, int dir=0) const
private const member functions
void calculate_average3(void)
member functions for calculation
double x(double r) const
private const member functions
double fit()
member functions for fit
double delta_chisq(double x, double y, double w=1) const
const member function for delta chisq
double solve_lambda3(void)
private member function solve_lambda3
void rotate(double c, double s)
private member functions
void sub(double x, double y, double w=1, double a=0, double b=0)
private member functions
CLHEP::HepSymMatrix cov_c(int=0) const
const member function cov_c
double calculate_lpar(void)
member functions for calculation
double d(double x, double y) const
const member functions
double calculate_lpar3(void)
member functions for calculation
virtual ~TRGCDCLpav()
Destructor.
double chi_deg() const
const member function chi_deg
double prob() const
const member function prob
void clear()
member functions for clear
double y(double r) const
private const member functions
float prob_(float *, int *)
prob function
const TRGCDCLpav & operator+=(const TRGCDCLpav &)
assignment operator(s)
double similarity(double, double) const
const member function similarity
double phi(double r, int dir=0) const
const member functions
void move(double x, double y)
private member functions
void add_point_frac(double x, double y, double w, double f)
member functions to add point
Abstract base class for different kinds of events.