18#include "analysis/OrcaKinFit/ISRPhotonFitObject.h"
19#include <framework/logging/Logger.h>
27#include "marlin/Processor.h"
35using namespace marlin;
43 namespace OrcaKinFit {
45 static const double pi_ = M_PI,
46 a = 8. / 3. / pi_ * (pi_ - 3.) / (4. - pi_);
50 double b_,
double PzMaxB_,
double PzMinB_)
52 pt2(0), p2(0), p(0), pz(0),
53 dpx0(0), dpy0(0), dpz0(0), dE0(0), dpx1(0), dpy1(0), dpz1(0), dE1(0),
54 dpx2(0), dpy2(0), dpz2(0), dE2(0), d2pz22(0), d2E22(0),
55 chi2(0), b(0), PzMinB(0), PzMaxB(0), dp2zFact(0)
58 assert(
int(NPAR) <=
int(BaseDefs::MAXPAR));
65 B2INFO(
"ISRPhotonFitObject: b: " << b <<
" PzMinB: " << PzMinB <<
" PzMaxB: " << PzMaxB);
68 if (b <= 0. || b >= 1.) {
69 B2INFO(
"ISRPhotonFitObject: b must be from ]0,1[ ");
71 assert(b > 0. && b < 1.);
72 if (PzMinB < 0. || PzMaxB <= PzMinB) {
73 B2INFO(
"ISRPhotonFitObject: PzMinB and PzMaxB must be chosen such that 0 <= PzMinB < PzMaxB");
76 assert(PzMaxB > PzMinB);
77 dp2zFact = (PzMaxB - PzMinB) / b * sqrt(2. / pi_);
78 double pg = PgFromPz(ppz);
86 B2INFO(
"ISRPhotonFitObject: Initial pg: " << pg);
94 ISRPhotonFitObject::~ISRPhotonFitObject() =
default;
99 pt2(0), p2(0), p(0), pz(0),
100 dpx0(0), dpy0(0), dpz0(0), dE0(0), dpx1(0), dpy1(0), dpz1(0), dE1(0),
101 dpx2(0), dpy2(0), dpz2(0), dE2(0), d2pz22(0), d2E22(0),
102 chi2(0), b(0), PzMinB(0), PzMaxB(0), dp2zFact(0)
123 if (psource !=
this) {
136 case 0:
return "P_x";
137 case 1:
return "P_y";
138 case 2:
return "P_g";
147 assert(i2 >= 0 && i2 < idim);
150 B2INFO(
"ISRPhotonFitObject::updateParams: p2(new) = " << pp[i2] <<
" par[2](old) = " <<
par[2]);
152 bool result = ((pp2 -
par[2]) * (pp2 -
par[2]) > eps2 *
cov[2][2]);
160 assert(ilocal >= 0 && ilocal < NPAR);
161 if (!cachevalid) updateCache();
172 assert(ilocal >= 0 && ilocal < NPAR);
173 if (!cachevalid) updateCache();
184 assert(ilocal >= 0 && ilocal < NPAR);
185 if (!cachevalid) updateCache();
196 assert(ilocal >= 0 && ilocal < NPAR);
197 if (!cachevalid) updateCache();
207 double ISRPhotonFitObject::getFirstDerivative_Meta_Local(
int iMeta,
int ilocal,
int metaSet)
const
209 assert(metaSet == 0);
212 return getDE(ilocal);
229 double ISRPhotonFitObject::getSecondDerivative_Meta_Local(
int iMeta,
int ilocal,
int jlocal,
int metaSet)
const
231 assert(metaSet == 0);
232 if (!cachevalid) updateCache();
234 if (jlocal < ilocal) {
244 if (ilocal == 2 && jlocal == 2)
return d2E22;
252 if (ilocal == 2 && jlocal == 2)
return d2pz22;
263 double ISRPhotonFitObject::PgFromPz(
double ppz)
266 int sign = (ppz > 0.) - (ppz < 0.);
267 double u = (pow(fabs(ppz), b) - PzMinB) / (PzMaxB - PzMinB);
270 B2INFO(
"ISRPhotonFitObject: Initial pz with abs(pz) < pzMin adjusted to zero.");
275 B2INFO(
"ISRPhotonFitObject: Initial pz with abs(pz) >= pzMax adjusted.");
279 double g = std::log(1. - u * u);
280 double g4pa = g + 4. / pi_ / a;
281 return sign * sqrt(-g4pa + sqrt(g4pa * g4pa - 4. / a * g)) ;
285 void ISRPhotonFitObject::updateCache()
const
291 int sign = (pg > 0.) - (pg < 0.);
292 double pg2h = pg * pg / 2.;
293 double exponent = -pg2h * (4. / pi_ + a * pg2h) / (1. + a * pg2h);
294 double u = sqrt((exponent < -1.e-14) ? 1. - exp(exponent) : -exponent);
295 pz = sign * pow((PzMinB + (PzMaxB - PzMinB) * u), (1. / b));
297 pt2 = px * px + py * py;
301 fourMomentum.setValues(p, px, py, pz);
311 dpz2 = dp2zFact * pow(fabs(pz), (1. - b)) * exp(-pg * pg / 2.);
315 d2pz22 = dpz2 * ((1. - b) * dpz2 / pz -
par[2]);
323 d2E22 = pz / p * d2pz22;
325 d2E22 += pt2 / p / p / p * dpz2 * dpz2;
335 B2INFO(
"ISRPhotonFitObject::updateCache: pg: " << pg <<
" pz: " << pz <<
" p: " << p <<
" p^2: " << p2 <<
"\n"
336 <<
" Dpz/Dpg: " << dpz2 <<
" DE/Dpg: " << dE2 <<
" D^2pz/Dpg^2: " << d2pz22
337 <<
" D^2E/Dpg^2: " << d2E22);
virtual bool setParam(int ilocal, double par_, bool measured_, bool fixed_=false)
Set value and measured flag of parameter i; return: significant change.
virtual int getGlobalParNum(int ilocal) const
Get global parameter number of parameter ilocal.
virtual bool setMParam(int ilocal, double mpar_)
Set measured value of parameter ilocal; return: success.
double par[BaseDefs::MAXPAR]
fit parameters
void invalidateCache() const
invalidate any cached quantities
double cov[BaseDefs::MAXPAR][BaseDefs::MAXPAR]
local covariance matrix
virtual bool setError(int ilocal, double err_)
Set error of parameter ilocal; return: success.
virtual double getDPx(int ilocal) const override
Return d p_x / d par_ilocal (derivative of px w.r.t. local parameter ilocal)
virtual double getDPy(int ilocal) const override
Return d p_y / d par_ilocal (derivative of py w.r.t. local parameter ilocal)
virtual double getDE(int ilocal) const override
Return d E / d par_ilocal (derivative of E w.r.t. local parameter ilocal)
ISRPhotonFitObject & operator=(const ISRPhotonFitObject &rhs)
Assignment.
virtual ISRPhotonFitObject & assign(const BaseFitObject &source) override
Assign from anther object, if of same type.
virtual const char * getParamName(int ilocal) const override
Get name of parameter ilocal.
virtual double getDPz(int ilocal) const override
Return d p_z / d par_ilocal (derivative of pz w.r.t. local parameter ilocal)
virtual bool updateParams(double p[], int idim) override
Read values from global vector, readjust vector; return: significant change.
ISRPhotonFitObject(double px, double py, double pz, double b_, double PzMaxB_, double PzMinB_=0.)
virtual ISRPhotonFitObject * copy() const override
Return a new copy of itself.
virtual bool setMass(double mass_)
Set mass of particle; return=success.
virtual ParticleFitObject & assign(const BaseFitObject &source) override
Assign from anther object, if of same type.
Abstract base class for different kinds of events.