17 #include "analysis/OrcaKinFit/JetFitObject.h" 
   18 #include <framework/logging/Logger.h> 
   36   namespace OrcaKinFit {
 
   39     JetFitObject::JetFitObject(
double E, 
double theta, 
double phi,
 
   40                                double DE, 
double Dtheta, 
double Dphi,
 
   42       : ctheta(0), stheta(0), cphi(0), sphi(0),
 
   43         p2(0), p(0), pt(0), px(0), py(0), pz(0), dpdE(0), dptdE(0),
 
   44         dpxdE(0), dpydE(0), dpzdE(0), dpxdtheta(0), dpydtheta(0), chi2(0)
 
   47       assert(
int(NPAR) <= 
int(BaseDefs::MAXPAR));
 
   58       adjustEThetaPhi(m, E, theta, phi);
 
   60       setParam(1, theta, 
true);
 
   61       setParam(2, phi, 
true);
 
   70       paramCycl[2] = 2.*M_PI;
 
   73       B2DEBUG(15, 
"JetFitObject::JetFitObject: E = " << E);
 
   74       B2DEBUG(15, 
"JetFitObject::JetFitObject: getParam(0) = " << getParam(0));
 
   75       B2DEBUG(15, 
"JetFitObject::JetFitObject: " << *
this);
 
   76       B2DEBUG(15, 
"mpar= " << mpar[0] << 
", " << mpar[1] << 
", " << mpar[2]);
 
   80     JetFitObject::~JetFitObject() = 
default;
 
   84         p2(0), p(0), pt(0), px(0), py(0), pz(0), dpdE(0), dptdE(0),
 
   85         dpxdE(0), dpydE(0), dpzdE(0), dpxdtheta(0), dpydtheta(0), chi2(0)
 
  105       if (
const auto* psource = 
dynamic_cast<const JetFitObject*
>(&source)) {
 
  106         if (psource != 
this) {
 
  120         case 1: 
return "theta";
 
  121         case 2: 
return "phi";
 
  132       bool mirrored_e = 
false;
 
  136         assert(iE  >= 0 && iE  < idim);
 
  140           B2INFO(
"JetFitObject::updateParams: mirrored E!\n");
 
  145         double massPlusEpsilon = 
mass * (1.0000001);
 
  146         if (e < massPlusEpsilon) e = massPlusEpsilon;
 
  147         result = result || ((e - 
par[0]) * (e - 
par[0]) > eps2 * 
cov[0][0]);
 
  154         assert(ith >= 0 && ith < idim);
 
  161         result = result || ((th - 
par[1]) * (th - 
par[1]) > eps2 * 
cov[1][1]);
 
  168         assert(iph >= 0 && iph < idim);
 
  175         result = result || ((ph - 
par[2]) * (ph - 
par[2]) > eps2 * 
cov[2][2]);
 
  186       assert(ilocal >= 0 && ilocal < NPAR);
 
  189         case 0: 
return dpxdE;
 
  190         case 1: 
return dpxdtheta;
 
  198       assert(ilocal >= 0 && ilocal < NPAR);
 
  201         case 0: 
return dpydE;
 
  202         case 1: 
return dpydtheta;
 
  210       assert(ilocal >= 0 && ilocal < NPAR);
 
  213         case 0: 
return dpzdE;
 
  222       assert(ilocal >= 0 && ilocal < NPAR);
 
  233       assert(ilocal >= 0 && ilocal < NPAR);
 
  234       B2INFO(
"JetFitObject::getError (ilocal = " << ilocal << 
") = " <<  std::sqrt(
cov[ilocal][ilocal]));
 
  235       return std::sqrt(
cov[ilocal][ilocal]);
 
  240       assert(ilocal >= 0 && ilocal < NPAR);
 
  241       assert(jlocal >= 0 && jlocal < NPAR);
 
  242       return cov[ilocal][jlocal];
 
  272       assert(metaSet == 0);
 
  275           return getDE(ilocal);
 
  294     double JetFitObject::getSecondDerivative_Meta_Local(
int iMeta, 
int ilocal, 
int jlocal, 
int metaSet)
 const 
  296       assert(metaSet == 0);
 
  299       if (jlocal < ilocal) {
 
  305       double d2pdE2 = (
mass != 0) ? -
mass * 
mass / (p * p * p) : 0;
 
  306       double d2ptdE2 = d2pdE2 * stheta;
 
  315           if (ilocal == 0 && jlocal == 0) 
return  d2ptdE2 * cphi;
 
  316           else if (ilocal == 0 && jlocal == 1) 
return  dpzdE * cphi;
 
  317           else if (ilocal == 0 && jlocal == 2) 
return -dpydE;
 
  318           else if (ilocal == 1 && jlocal == 1) 
return -px;
 
  319           else if (ilocal == 1 && jlocal == 2) 
return -dpydtheta;
 
  320           else if (ilocal == 2 && jlocal == 2) 
return -px;
 
  323           if (ilocal == 0 && jlocal == 0) 
return  d2ptdE2 * sphi;
 
  324           else if (ilocal == 0 && jlocal == 1) 
return  dpzdE * sphi;
 
  325           else if (ilocal == 0 && jlocal == 2) 
return  dpxdE;
 
  326           else if (ilocal == 1 && jlocal == 1) 
return -py;
 
  327           else if (ilocal == 1 && jlocal == 2) 
return  dpxdtheta;
 
  328           else if (ilocal == 2 && jlocal == 2) 
return -py;
 
  331           if (ilocal == 0 && jlocal == 0) 
return d2pdE2 * ctheta;
 
  333           else if (ilocal == 0 && jlocal == 1) 
return -dptdE; 
 
  334           else if (ilocal == 0 && jlocal == 2) 
return 0;
 
  335           else if (ilocal == 1 && jlocal == 1) 
return -pz;
 
  336           else if (ilocal == 1 && jlocal == 2) 
return 0;
 
  337           else if (ilocal == 2 && jlocal == 2) 
return 0;
 
  347     void JetFitObject::updateCache()
 const 
  351       double theta = 
par[1];
 
  369       fourMomentum.setValues(e, px, py, pz);
 
  372       dptdE = dpdE * stheta;
 
  373       dpxdE = dptdE * cphi;
 
  374       dpydE = dptdE * sphi;
 
  375       dpzdE = dpdE * ctheta;
 
  377       dpxdtheta = pz * cphi;
 
  378       dpydtheta = pz * sphi;
 
  395         B2INFO(
"JetFitObject::adjustEThetaPhi: mirrored E!\n");
 
  397         theta = M_PI - theta;
 
  405       if (theta < -M_PI || theta > M_PI) {
 
  406         while (theta < -M_PI) theta += 2 * M_PI;
 
  407         while (theta >  M_PI) theta -= 2 * M_PI;
 
  412         B2INFO(
"JetFitObject::adjustEThetaPhi: mirrored theta!\n");
 
  414         phi = phi > 0 ? phi - M_PI : phi + M_PI;
 
  416       } 
else if (theta > M_PI) {
 
  417         B2INFO(
"JetFitObject::adjustEThetaPhi: mirrored theta!\n");
 
  418         theta = 2 * M_PI - theta;
 
  419         phi = phi > 0 ? phi - M_PI : phi + M_PI;
 
  422       if (phi < -M_PI || phi > M_PI) {
 
  423         while (phi < -M_PI) phi += 2 * M_PI;
 
  424         while (phi >  M_PI) phi -= 2 * M_PI;
 
bool cachevalid
flag for valid cache
virtual int getGlobalParNum(int ilocal) const
Get global parameter number of parameter ilocal.
virtual bool isParamFixed(int ilocal) const
Returns whether parameter is fixed.
double par[BaseDefs::MAXPAR]
fit parameters
void invalidateCache() const
invalidate any cached quantities
double cov[BaseDefs::MAXPAR][BaseDefs::MAXPAR]
local covariance matrix
Class for jets with (E, eta, phi) in kinematic fits.
virtual double getDPx(int ilocal) const override
Return d p_x / d par_ilocal (derivative of px w.r.t. local parameter ilocal)
virtual JetFitObject & assign(const BaseFitObject &source) override
Assign from anther object, if of same type.
static bool adjustEThetaPhi(const double &m, double &E, double &theta, double &phi)
Adjust E, theta and phi such that E>=m, 0<=theta<=pi, -pi <= phi < pi; returns true if anything was c...
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)
JetFitObject & operator=(const JetFitObject &rhs)
Assignment.
virtual JetFitObject * copy() const override
Return a new copy of itself.
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 double getFirstDerivative_Meta_Local(int iMeta, int ilocal, int metaSet) const override
add derivatives to vector der of size idim pxfact*dpx/dx_i + pyfact*dpy/dx_i + pzfact*dpz/dx_i + efac...
virtual bool updateParams(double p[], int idim) override
Read values from global vector, readjust vector; return: significant change.
virtual double getCov(int ilocal, int jlocal) const override
Get covariance between parameters ilocal and jlocal.
virtual double getError(int ilocal) const override
Get error of parameter ilocal.
double mass
mass of particle
virtual ParticleFitObject & assign(const BaseFitObject &source) override
Assign from anther object, if of same type.
Abstract base class for different kinds of events.