CMS 3D CMS Logo

Classes | Functions
MuonResidualsFitter.h File Reference
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "CommonTools/UtilAlgos/interface/TFileService.h"
#include "Alignment/CommonAlignment/interface/Alignable.h"
#include "TMinuit.h"
#include "TH1F.h"
#include "TProfile.h"
#include "TF1.h"
#include "TMath.h"
#include "TRandom3.h"
#include "TMatrixDSym.h"
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <map>

Go to the source code of this file.

Classes

struct  MuonResidualsFitter::MuonAlignmentTreeRow
 
class  MuonResidualsFitter
 
class  MuonResidualsFitterFitInfo
 

Functions

void MuonResidualsAngleFitter_FCN (int &npar, double *gin, double &fval, double *par, int iflag)
 
double MuonResidualsFitter_compute_log_convolution (double toversigma, double gammaoversigma, double max=1000., double step=0.001, double power=4.)
 
Double_t MuonResidualsFitter_GaussPowerTails_TF1 (Double_t *xvec, Double_t *par)
 
double MuonResidualsFitter_integrate_pureGaussian (double low, double high, double center, double sigma)
 
double MuonResidualsFitter_logGaussPowerTails (double residual, double center, double sigma)
 
double MuonResidualsFitter_logPowerLawTails (double residual, double center, double sigma, double gamma)
 
double MuonResidualsFitter_logPureGaussian (double residual, double center, double sigma)
 
double MuonResidualsFitter_logPureGaussian2D (double x, double y, double x0, double y0, double sx, double sy, double r)
 
double MuonResidualsFitter_logROOTVoigt (double residual, double center, double sigma, double gamma)
 
Double_t MuonResidualsFitter_powerLawTails_TF1 (Double_t *xvec, Double_t *par)
 
Double_t MuonResidualsFitter_pureGaussian_TF1 (Double_t *xvec, Double_t *par)
 
Double_t MuonResidualsFitter_ROOTVoigt_TF1 (Double_t *xvec, Double_t *par)
 
void MuonResidualsPositionFitter_FCN (int &npar, double *gin, double &fval, double *par, int iflag)
 

Function Documentation

◆ MuonResidualsAngleFitter_FCN()

void MuonResidualsAngleFitter_FCN ( int &  npar,
double *  gin,
double &  fval,
double *  par,
int  iflag 
)

Definition at line 7 of file MuonResidualsAngleFitter.cc.

References cms::cuda::assert(), MuonResidualsFitterFitInfo::fitter(), MuonResidualsAngleFitter::kAngle, MuonResidualsAngleFitter::kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsAngleFitter::kResidual, MuonResidualsFitter::kROOTVoigt, MuonResidualsAngleFitter::kSigma, MuonResidualsAngleFitter::kXAngle, MuonResidualsAngleFitter::kXControl, MuonResidualsAngleFitter::kYAngle, MuonResidualsAngleFitter::kYControl, MuonResidualsAngleFitter_TMinuit, MuonResidualsFitter_logGaussPowerTails(), MuonResidualsFitter_logPowerLawTails(), MuonResidualsFitter_logPureGaussian(), MuonResidualsFitter_logROOTVoigt(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), and ctppsOpticalFunctions_non_DB_cff::xangle.

Referenced by MuonResidualsAngleFitter::fit().

7  {
10  MuonResidualsFitter *fitter = fitinfo->fitter();
11 
12  fval = 0.;
13  for (std::vector<double *>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end();
14  ++resiter) {
15  const double residual = (*resiter)[MuonResidualsAngleFitter::kResidual];
16  const double xangle = (*resiter)[MuonResidualsAngleFitter::kXAngle];
17  const double yangle = (*resiter)[MuonResidualsAngleFitter::kYAngle];
18 
19  double center = 0.;
20  center += par[MuonResidualsAngleFitter::kAngle];
22  center += par[MuonResidualsAngleFitter::kYControl] * yangle;
23 
26  } else if (fitter->residualsModel() == MuonResidualsFitter::kPowerLawTails) {
29  } else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
32  } else if (fitter->residualsModel() == MuonResidualsFitter::kGaussPowerTails) {
34  } else {
35  assert(false);
36  }
37  }
38 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
std::vector< double * >::const_iterator residuals_begin() const
MuonResidualsFitter * fitter()
std::vector< double * >::const_iterator residuals_end() const
assert(be >=bs)
double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma)
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
static TMinuit * MuonResidualsAngleFitter_TMinuit
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)

◆ MuonResidualsFitter_compute_log_convolution()

double MuonResidualsFitter_compute_log_convolution ( double  toversigma,
double  gammaoversigma,
double  max = 1000.,
double  step = 0.001,
double  power = 4. 
)

Definition at line 54 of file MuonResidualsFitter.cc.

References JetChargeProducer_cfi::exp, CrabHelper::log, M_PI, WZElectronSkims53X_cff::max, funct::pow(), cms::alpakatools::detail::power(), and mathSSE::sqrt().

Referenced by MuonResidualsFitter::initialize_table().

55  {
56  if (gammaoversigma == 0.)
57  return (-toversigma * toversigma / 2.) - log(sqrt(2 * M_PI));
58 
59  double sum = 0.;
60  double uplus = 0.;
61  double integrandplus_last = 0.;
62  double integrandminus_last = 0.;
63  for (double inc = 0.; uplus < max; inc += step) {
64  double uplus_last = uplus;
65  uplus = pow(inc, power);
66 
67  double integrandplus = exp(-pow(uplus - toversigma, 2) / 2.) / (uplus * uplus / gammaoversigma + gammaoversigma) /
68  M_PI / sqrt(2. * M_PI);
69  double integrandminus = exp(-pow(-uplus - toversigma, 2) / 2.) / (uplus * uplus / gammaoversigma + gammaoversigma) /
70  M_PI / sqrt(2. * M_PI);
71 
72  sum += integrandplus * (uplus - uplus_last);
73  sum += 0.5 * fabs(integrandplus_last - integrandplus) * (uplus - uplus_last);
74 
75  sum += integrandminus * (uplus - uplus_last);
76  sum += 0.5 * fabs(integrandminus_last - integrandminus) * (uplus - uplus_last);
77 
78  integrandplus_last = integrandplus;
79  integrandminus_last = integrandminus;
80  }
81  return log(sum);
82 }
T sqrt(T t)
Definition: SSEVec.h:23
#define M_PI
constexpr unsigned int power(unsigned int base, unsigned int exponent)
step
Definition: StallMonitor.cc:83
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ MuonResidualsFitter_GaussPowerTails_TF1()

Double_t MuonResidualsFitter_GaussPowerTails_TF1 ( Double_t *  xvec,
Double_t *  par 
)

◆ MuonResidualsFitter_integrate_pureGaussian()

double MuonResidualsFitter_integrate_pureGaussian ( double  low,
double  high,
double  center,
double  sigma 
)

Definition at line 146 of file MuonResidualsFitter.cc.

References JetChargeProducer_cfi::exp, LaserClient_cfi::high, LaserClient_cfi::low, and mathSSE::sqrt().

146  {
147  static const double isqr2 = 1. / sqrt(2.);
148  return (erf((high + center) * isqr2 / sigma) - erf((low + center) * isqr2 / sigma)) * exp(0.5 / sigma / sigma) * 0.5;
149 }
T sqrt(T t)
Definition: SSEVec.h:23

◆ MuonResidualsFitter_logGaussPowerTails()

double MuonResidualsFitter_logGaussPowerTails ( double  residual,
double  center,
double  sigma 
)

Definition at line 128 of file MuonResidualsFitter.cc.

References a, JetChargeProducer_cfi::exp, CrabHelper::log, visualization-live-secondInstance_cfg::m, M_PI, create_idmaps::n, funct::pow(), alignCSCRings::s, mathSSE::sqrt(), and x.

Referenced by MuonResiduals1DOFFitter_FCN(), MuonResiduals5DOFFitter_FCN(), MuonResiduals6DOFFitter_FCN(), MuonResiduals6DOFrphiFitter_FCN(), MuonResidualsAngleFitter_FCN(), MuonResidualsBfieldAngleFitter_FCN(), MuonResidualsFitter_GaussPowerTails_TF1(), and MuonResidualsPositionFitter_FCN().

128  {
129  double x = residual - center;
130  double s = fabs(sigma);
131  double m = 2. * s;
132  static const double e2 = exp(-2.), sqerf = sqrt(2. * M_PI) * erf(sqrt(2.));
133  double a = pow(m, 4) * e2;
134  double n = sqerf * s + 2. * a * pow(m, -3) / 3.;
135 
136  if (fabs(x) < m)
137  return -x * x / (2. * s * s) - log(n);
138  else
139  return log(a) - 4. * log(fabs(x)) - log(n);
140 }
T sqrt(T t)
Definition: SSEVec.h:23
#define M_PI
double a
Definition: hdecay.h:121
float x
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ MuonResidualsFitter_logPowerLawTails()

double MuonResidualsFitter_logPowerLawTails ( double  residual,
double  center,
double  sigma,
double  gamma 
)

Definition at line 85 of file MuonResidualsFitter.cc.

References reco::ceil(), CustomPhysics_cfi::gamma, createfilelist::int, CrabHelper::log, M_PI, MuonResidualsFitter_gsbinsize, MuonResidualsFitter_lookup_table, MuonResidualsFitter_numgsbins, MuonResidualsFitter_numtsbins, MuonResidualsFitter_tsbinsize, and heppy_batch::val.

Referenced by MuonResiduals1DOFFitter_FCN(), MuonResiduals5DOFFitter_FCN(), MuonResiduals6DOFFitter_FCN(), MuonResiduals6DOFrphiFitter_FCN(), MuonResidualsAngleFitter_FCN(), MuonResidualsBfieldAngleFitter_FCN(), MuonResidualsFitter_powerLawTails_TF1(), and MuonResidualsPositionFitter_FCN().

85  {
86  sigma = fabs(sigma);
87  double gammaoversigma = fabs(gamma / sigma);
88  double toversigma = fabs((residual - center) / sigma);
89 
90  int gsbin0 = int(floor(gammaoversigma / MuonResidualsFitter_gsbinsize));
91  int gsbin1 = int(ceil(gammaoversigma / MuonResidualsFitter_gsbinsize));
92  int tsbin0 = int(floor(toversigma / MuonResidualsFitter_tsbinsize));
93  int tsbin1 = int(ceil(toversigma / MuonResidualsFitter_tsbinsize));
94 
95  bool gsisbad = (gsbin0 >= MuonResidualsFitter_numgsbins || gsbin1 >= MuonResidualsFitter_numgsbins);
96  bool tsisbad = (tsbin0 >= MuonResidualsFitter_numtsbins || tsbin1 >= MuonResidualsFitter_numtsbins);
97 
98  if (gsisbad || tsisbad) {
99  return log(gammaoversigma / M_PI) - log(toversigma * toversigma + gammaoversigma * gammaoversigma) - log(sigma);
100  } else {
101  double val00 = MuonResidualsFitter_lookup_table[gsbin0][tsbin0];
102  double val01 = MuonResidualsFitter_lookup_table[gsbin0][tsbin1];
103  double val10 = MuonResidualsFitter_lookup_table[gsbin1][tsbin0];
104  double val11 = MuonResidualsFitter_lookup_table[gsbin1][tsbin1];
105 
106  double val0 = val00 + ((toversigma / MuonResidualsFitter_tsbinsize) - tsbin0) * (val01 - val00);
107  double val1 = val10 + ((toversigma / MuonResidualsFitter_tsbinsize) - tsbin0) * (val11 - val10);
108 
109  double val = val0 + ((gammaoversigma / MuonResidualsFitter_gsbinsize) - gsbin0) * (val1 - val0);
110 
111  return val - log(sigma);
112  }
113 }
constexpr int32_t ceil(float num)
const int MuonResidualsFitter_numgsbins
const int MuonResidualsFitter_numtsbins
const double MuonResidualsFitter_gsbinsize
const double MuonResidualsFitter_tsbinsize
#define M_PI
double MuonResidualsFitter_lookup_table[MuonResidualsFitter_numgsbins][MuonResidualsFitter_numtsbins]

◆ MuonResidualsFitter_logPureGaussian()

double MuonResidualsFitter_logPureGaussian ( double  residual,
double  center,
double  sigma 
)

Definition at line 31 of file MuonResidualsFitter.cc.

References CrabHelper::log, M_PI, and funct::pow().

Referenced by MuonResiduals1DOFFitter_FCN(), MuonResiduals5DOFFitter_FCN(), MuonResiduals6DOFFitter_FCN(), MuonResiduals6DOFrphiFitter_FCN(), MuonResidualsAngleFitter_FCN(), MuonResidualsBfieldAngleFitter_FCN(), MuonResidualsFitter_pureGaussian_TF1(), and MuonResidualsPositionFitter_FCN().

31  {
32  sigma = fabs(sigma);
33  static const double cgaus = 0.5 * log(2. * M_PI);
34  return (-pow(residual - center, 2) * 0.5 / sigma / sigma) - cgaus - log(sigma);
35 }
#define M_PI
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ MuonResidualsFitter_logPureGaussian2D()

double MuonResidualsFitter_logPureGaussian2D ( double  x,
double  y,
double  x0,
double  y0,
double  sx,
double  sy,
double  r 
)

Definition at line 43 of file MuonResidualsFitter.cc.

References PVValHelper::dx, PVValHelper::dy, CrabHelper::log, M_PI, funct::pow(), alignCSCRings::r, mathSSE::sqrt(), fftjetcommon_cfi::sx, fftjetcommon_cfi::sy, x, and relval_data_highstats::y.

Referenced by MuonResiduals5DOFFitter_FCN(), MuonResiduals6DOFFitter_FCN(), and MuonResiduals6DOFrphiFitter_FCN().

43  {
44  sx = fabs(sx);
45  sy = fabs(sy);
46  static const double c2gaus = log(2. * M_PI);
47  double one_r2 = 1. - r * r;
48  double dx = x - x0;
49  double dy = y - y0;
50  return -0.5 / one_r2 * (pow(dx / sx, 2) + pow(dy / sy, 2) - 2. * r * dx / sx * dy / sy) - c2gaus -
51  log(sx * sy * sqrt(one_r2));
52 }
T sqrt(T t)
Definition: SSEVec.h:23
#define M_PI
float x
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ MuonResidualsFitter_logROOTVoigt()

double MuonResidualsFitter_logROOTVoigt ( double  residual,
double  center,
double  sigma,
double  gamma 
)

◆ MuonResidualsFitter_powerLawTails_TF1()

Double_t MuonResidualsFitter_powerLawTails_TF1 ( Double_t *  xvec,
Double_t *  par 
)

◆ MuonResidualsFitter_pureGaussian_TF1()

Double_t MuonResidualsFitter_pureGaussian_TF1 ( Double_t *  xvec,
Double_t *  par 
)

◆ MuonResidualsFitter_ROOTVoigt_TF1()

Double_t MuonResidualsFitter_ROOTVoigt_TF1 ( Double_t *  xvec,
Double_t *  par 
)

◆ MuonResidualsPositionFitter_FCN()

void MuonResidualsPositionFitter_FCN ( int &  npar,
double *  gin,
double &  fval,
double *  par,
int  iflag 
)

Definition at line 7 of file MuonResidualsPositionFitter.cc.

References cms::cuda::assert(), MuonResidualsFitterFitInfo::fitter(), MuonResidualsPositionFitter::kAngleError, MuonResidualsPositionFitter::kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsPositionFitter::kPhiz, MuonResidualsPositionFitter::kPosition, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsPositionFitter::kResidual, MuonResidualsFitter::kROOTVoigt, MuonResidualsPositionFitter::kScattering, MuonResidualsPositionFitter::kSigma, MuonResidualsPositionFitter::kTrackAngle, MuonResidualsPositionFitter::kTrackPosition, MuonResidualsPositionFitter::kZpos, MuonResidualsFitter_logGaussPowerTails(), MuonResidualsFitter_logPowerLawTails(), MuonResidualsFitter_logPureGaussian(), MuonResidualsFitter_logROOTVoigt(), MuonResidualsPositionFitter_TMinuit, MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), and MuonResidualsFitter::residualsModel().

Referenced by MuonResidualsPositionFitter::fit().

7  {
10  MuonResidualsFitter *fitter = fitinfo->fitter();
11 
12  fval = 0.;
13  for (std::vector<double *>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end();
14  ++resiter) {
15  const double residual = (*resiter)[MuonResidualsPositionFitter::kResidual];
16  const double angleerror = (*resiter)[MuonResidualsPositionFitter::kAngleError];
17  const double trackangle = (*resiter)[MuonResidualsPositionFitter::kTrackAngle];
18  const double trackposition = (*resiter)[MuonResidualsPositionFitter::kTrackPosition];
19 
20  double center = 0.;
22  center += par[MuonResidualsPositionFitter::kZpos] * trackangle;
23  center += par[MuonResidualsPositionFitter::kPhiz] * trackposition;
24  center += par[MuonResidualsPositionFitter::kScattering] * angleerror;
25 
28  } else if (fitter->residualsModel() == MuonResidualsFitter::kPowerLawTails) {
31  } else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
34  } else if (fitter->residualsModel() == MuonResidualsFitter::kGaussPowerTails) {
36  } else {
37  assert(false);
38  }
39  }
40 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
std::vector< double * >::const_iterator residuals_begin() const
MuonResidualsFitter * fitter()
static TMinuit * MuonResidualsPositionFitter_TMinuit
std::vector< double * >::const_iterator residuals_end() const
assert(be >=bs)
double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma)
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)