CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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

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

Definition at line 9 of file MuonResidualsAngleFitter.cc.

References 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(), and MuonResidualsFitter::residualsModel().

Referenced by MuonResidualsAngleFitter::fit().

9  {
11  MuonResidualsFitter *fitter = fitinfo->fitter();
12 
13  fval = 0.;
14  for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end(); ++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];
21  center += par[MuonResidualsAngleFitter::kXControl] * xangle;
22  center += par[MuonResidualsAngleFitter::kYControl] * yangle;
23 
26  }
29  }
30  else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
32  }
35  }
36  else { assert(false); }
37  }
38 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
assert(m_qm.get())
MuonResidualsFitter * fitter()
double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma)
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
std::vector< double * >::const_iterator residuals_end() const
std::vector< double * >::const_iterator residuals_begin() const
static TMinuit * MuonResidualsAngleFitter_TMinuit
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)
double MuonResidualsFitter_compute_log_convolution ( double  toversigma,
double  gammaoversigma,
double  max = 1000.,
double  step = 0.001,
double  power = 4. 
)

Definition at line 57 of file MuonResidualsFitter.cc.

References create_public_lumi_plots::exp, create_public_lumi_plots::log, M_PI, bookConverter::max, funct::pow(), mathSSE::sqrt(), and relval_parameters_module::step.

Referenced by MuonResidualsFitter::initialize_table().

58 {
59  if (gammaoversigma == 0.) return (-toversigma*toversigma/2.) - log(sqrt(2*M_PI));
60 
61  double sum = 0.;
62  double uplus = 0.;
63  double integrandplus_last = 0.;
64  double integrandminus_last = 0.;
65  for (double inc = 0.; uplus < max; inc += step)
66  {
67  double uplus_last = uplus;
68  uplus = pow(inc, power);
69 
70  double integrandplus = exp(-pow(uplus - toversigma, 2)/2.) / (uplus*uplus/gammaoversigma + gammaoversigma) / M_PI / sqrt(2.*M_PI);
71  double integrandminus = exp(-pow(-uplus - toversigma, 2)/2.) / (uplus*uplus/gammaoversigma + gammaoversigma) / M_PI / sqrt(2.*M_PI);
72 
73  sum += integrandplus * (uplus - uplus_last);
74  sum += 0.5 * fabs(integrandplus_last - integrandplus) * (uplus - uplus_last);
75 
76  sum += integrandminus * (uplus - uplus_last);
77  sum += 0.5 * fabs(integrandminus_last - integrandminus) * (uplus - uplus_last);
78 
79  integrandplus_last = integrandplus;
80  integrandminus_last = integrandminus;
81  }
82  return log(sum);
83 }
T sqrt(T t)
Definition: SSEVec.h:48
#define M_PI
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
Double_t MuonResidualsFitter_GaussPowerTails_TF1 ( Double_t *  xvec,
Double_t *  par 
)
double MuonResidualsFitter_integrate_pureGaussian ( double  low,
double  high,
double  center,
double  sigma 
)

Definition at line 159 of file MuonResidualsFitter.cc.

References create_public_lumi_plots::exp, and mathSSE::sqrt().

160 {
161  static const double isqr2 = 1./sqrt(2.);
162  return (erf((high + center) * isqr2 / sigma) - erf((low + center) * isqr2 / sigma)) * exp(0.5/sigma/sigma) * 0.5;
163 }
T sqrt(T t)
Definition: SSEVec.h:48
double MuonResidualsFitter_logGaussPowerTails ( double  residual,
double  center,
double  sigma 
)

Definition at line 140 of file MuonResidualsFitter.cc.

References a, create_public_lumi_plots::exp, create_public_lumi_plots::log, contentValuesFiles::m, M_PI, gen::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().

140  {
141  double x = residual-center;
142  double s = fabs(sigma);
143  double m = 2.*s;
144  static const double e2 = exp(-2.), sqerf = sqrt(2.*M_PI)*erf(sqrt(2.));
145  double a = pow(m,4)*e2;
146  double n = sqerf*s + 2.*a*pow(m,-3)/3.;
147 
148  if (fabs(x)<m) return -x*x/(2.*s*s) - log(n);
149  else return log(a) -4.*log(fabs(x)) - log(n);
150 }
T sqrt(T t)
Definition: SSEVec.h:48
#define M_PI
double a
Definition: hdecay.h:121
Definition: DDAxes.h:10
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double MuonResidualsFitter_logPowerLawTails ( double  residual,
double  center,
double  sigma,
double  gamma 
)

Definition at line 86 of file MuonResidualsFitter.cc.

References create_public_lumi_plots::log, M_PI, MuonResidualsFitter_gsbinsize, MuonResidualsFitter_lookup_table, MuonResidualsFitter_numgsbins, MuonResidualsFitter_numtsbins, MuonResidualsFitter_tsbinsize, and value::val1.

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

87 {
88  sigma = fabs(sigma);
89  double gammaoversigma = fabs(gamma / sigma);
90  double toversigma = fabs((residual - center) / sigma);
91 
92  int gsbin0 = int(floor(gammaoversigma / MuonResidualsFitter_gsbinsize));
93  int gsbin1 = int(ceil(gammaoversigma / MuonResidualsFitter_gsbinsize));
94  int tsbin0 = int(floor(toversigma / MuonResidualsFitter_tsbinsize));
95  int tsbin1 = int(ceil(toversigma / MuonResidualsFitter_tsbinsize));
96 
97  bool gsisbad = (gsbin0 >= MuonResidualsFitter_numgsbins || gsbin1 >= MuonResidualsFitter_numgsbins);
98  bool tsisbad = (tsbin0 >= MuonResidualsFitter_numtsbins || tsbin1 >= MuonResidualsFitter_numtsbins);
99 
100  if (gsisbad || tsisbad)
101  {
102  return log(gammaoversigma/M_PI) - log(toversigma*toversigma + gammaoversigma*gammaoversigma) - log(sigma);
103  }
104  else
105  {
106  double val00 = MuonResidualsFitter_lookup_table[gsbin0][tsbin0];
107  double val01 = MuonResidualsFitter_lookup_table[gsbin0][tsbin1];
108  double val10 = MuonResidualsFitter_lookup_table[gsbin1][tsbin0];
109  double val11 = MuonResidualsFitter_lookup_table[gsbin1][tsbin1];
110 
111  double val0 = val00 + ((toversigma / MuonResidualsFitter_tsbinsize) - tsbin0) * (val01 - val00);
112  double val1 = val10 + ((toversigma / MuonResidualsFitter_tsbinsize) - tsbin0) * (val11 - val10);
113 
114  double val = val0 + ((gammaoversigma / MuonResidualsFitter_gsbinsize) - gsbin0) * (val1 - val0);
115 
116  return val - log(sigma);
117  }
118 }
const int MuonResidualsFitter_numgsbins
tuple val1
Definition: value.py:53
const int MuonResidualsFitter_numtsbins
const double MuonResidualsFitter_gsbinsize
const double MuonResidualsFitter_tsbinsize
#define M_PI
double MuonResidualsFitter_lookup_table[MuonResidualsFitter_numgsbins][MuonResidualsFitter_numtsbins]
double MuonResidualsFitter_logPureGaussian ( double  residual,
double  center,
double  sigma 
)

Definition at line 31 of file MuonResidualsFitter.cc.

References create_public_lumi_plots::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().

32 {
33  sigma = fabs(sigma);
34  static const double cgaus = 0.5 * log( 2.*M_PI );
35  return (-pow(residual - center, 2) *0.5 / sigma / sigma) - cgaus - log(sigma);
36 }
#define M_PI
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double MuonResidualsFitter_logPureGaussian2D ( double  x,
double  y,
double  x0,
double  y0,
double  sx,
double  sy,
double  r 
)

Definition at line 46 of file MuonResidualsFitter.cc.

References create_public_lumi_plots::log, M_PI, funct::pow(), alignCSCRings::r, and mathSSE::sqrt().

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

47 {
48  sx = fabs(sx); sy = fabs(sy);
49  static const double c2gaus = log( 2.*M_PI );
50  double one_r2 = 1. - r*r;
51  double dx = x - x0;
52  double dy = y - y0;
53  return -0.5/one_r2 * ( pow(dx/sx, 2) + pow(dy/sy, 2) - 2.*r*dx/sx*dy/sy ) - c2gaus - log(sx*sy*sqrt(one_r2));
54 }
T sqrt(T t)
Definition: SSEVec.h:48
#define M_PI
Definition: DDAxes.h:10
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
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 
)

Definition at line 9 of file MuonResidualsPositionFitter.cc.

References 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().

9  {
11  MuonResidualsFitter *fitter = fitinfo->fitter();
12 
13  fval = 0.;
14  for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin(); resiter != fitter->residuals_end(); ++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  }
31  }
32  else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
34  }
37  }
38  else { assert(false); }
39  }
40 }
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
assert(m_qm.get())
MuonResidualsFitter * fitter()
static TMinuit * MuonResidualsPositionFitter_TMinuit
double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma)
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
std::vector< double * >::const_iterator residuals_end() const
std::vector< double * >::const_iterator residuals_begin() const
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)