CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MuonResidualsFitter.h
Go to the documentation of this file.
1 #ifndef Alignment_MuonAlignmentAlgorithms_MuonResidualsFitter_H
2 #define Alignment_MuonAlignmentAlgorithms_MuonResidualsFitter_H
3 
11 
15 
16 #include "TMinuit.h"
17 #include "TH1F.h"
18 #include "TProfile.h"
19 #include "TF1.h"
20 #include "TMath.h"
21 
22 #include <cstdio>
23 #include <iostream>
24 #include <string>
25 #include <sstream>
26 
28 public:
29  enum {
34  };
35 
36  enum {
44  };
45 
48  if (m_residualsModel != kPureGaussian && m_residualsModel != kPowerLawTails && m_residualsModel != kROOTVoigt && m_residualsModel != kGaussPowerTails) throw cms::Exception("MuonResidualsFitter") << "unrecognized residualsModel";
49  };
50 
52  for (std::vector<double*>::const_iterator residual = residuals_begin(); residual != residuals_end(); ++residual) {
53  delete [] (*residual);
54  }
55  };
56 
57  virtual int type() const = 0;
58 
59  int residualsModel() const { return m_residualsModel; };
60  long numResiduals() const { return m_residuals.size(); };
61  virtual int npar() = 0;
62  virtual int ndata() = 0;
63 
64  void fix(int parNum, bool value=true) {
65  assert(0 <= parNum && parNum < npar());
66  if (m_fixed.size() == 0) {
67  for (int i = 0; i < npar(); i++) {
68  m_fixed.push_back(false);
69  }
70  }
71  m_fixed[parNum] = value;
72  };
73 
74  bool fixed(int parNum) {
75  assert(0 <= parNum && parNum < npar());
76  if (m_fixed.size() == 0) return false;
77  else return m_fixed[parNum];
78  };
79 
80  void setPrintLevel(int printLevel) { m_printLevel = printLevel; };
81  void setStrategy(int strategy) { m_strategy = strategy; };
82 
83  // an array of the actual residual and associated baggage (qoverpt, trackangle, trackposition)
84  // arrays passed to fill() are "owned" by MuonResidualsFitter: MuonResidualsFitter will delete them, don't do it yourself!
85  void fill(double *residual) {
86  m_residuals.push_back(residual);
87  };
88 
89  // this block of results is only valid if fit() returns true
90  // also gamma is only valid if the model is kPowerLawTails or kROOTVoigt
91  virtual bool fit(Alignable *ali) = 0;
92  double value(int parNum) { assert(0 <= parNum && parNum < npar()); return m_value[parNum]; };
93  double errorerror(int parNum) { assert(0 <= parNum && parNum < npar()); return m_error[parNum]; };
94  double loglikelihood() { return m_loglikelihood; };
95  long numsegments() {
96  long num = 0;
97  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
98  num++;
99  }
100  return num;
101  };
102  virtual double sumofweights() = 0;
103 
104  // demonstration plots; return reduced chi**2
105  virtual double plot(std::string name, TFileDirectory *dir, Alignable *ali) = 0;
106 
107  // I/O of temporary files for collect mode
108  void write(FILE *file, int which=0);
109  void read(FILE *file, int which=0);
110 
111  // these are for the FCN to access what it needs to
112  std::vector<double*>::const_iterator residuals_begin() const { return m_residuals.begin(); };
113  std::vector<double*>::const_iterator residuals_end() const { return m_residuals.end(); };
114 
115  void plotsimple(std::string name, TFileDirectory *dir, int which, double multiplier);
116  void plotweighted(std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier);
117 
118 protected:
119  void initialize_table();
120  bool dofit(void (*fcn)(int&,double*,double&,double*,int), std::vector<int> &parNum, std::vector<std::string> &parName, std::vector<double> &start, std::vector<double> &step, std::vector<double> &low, std::vector<double> &high);
121  virtual void inform(TMinuit *tMinuit) = 0;
122 
126  std::vector<bool> m_fixed;
128 
129  std::vector<double*> m_residuals;
130 
131  std::vector<double> m_value;
132  std::vector<double> m_error;
134 };
135 
136 // A ROOT-sponsored hack to get information into the fit function
137 class MuonResidualsFitterFitInfo: public TObject {
138 public:
140  : m_fitter(fitter) {};
142 private:
144 };
145 
146 // fit functions (these can't be put in the class; "MuonResidualsFitter_" prefix avoids namespace clashes)
147 double MuonResidualsFitter_integrate_pureGaussian(double low, double high, double center, double sigma);
148 double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma);
149 Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par);
150 double MuonResidualsFitter_compute_log_convolution(double toversigma, double gammaoversigma, double max=1000., double step=0.001, double power=4.);
151 double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma);
152 Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par);
153 double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma);
154 Double_t MuonResidualsFitter_ROOTVoigt_TF1(Double_t *xvec, Double_t *par);
155 double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma);
156 Double_t MuonResidualsFitter_GaussPowerTails_TF1(Double_t *xvec, Double_t *par);
157 void MuonResidualsPositionFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag);
158 void MuonResidualsAngleFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag);
159 
160 #endif // Alignment_MuonAlignmentAlgorithms_MuonResidualsFitter_H
tuple weightAlignment
Definition: align_cfg.py:24
double MuonResidualsFitter_logGaussPowerTails(double residual, double center, double sigma)
int i
Definition: DBlmapReader.cc:9
double MuonResidualsFitter_integrate_pureGaussian(double low, double high, double center, double sigma)
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
virtual void inform(TMinuit *tMinuit)=0
void write(FILE *file, int which=0)
long numResiduals() const
void fix(int parNum, bool value=true)
virtual int npar()=0
list file
Definition: dbtoweb.py:253
std::vector< double > m_error
void read(FILE *file, int which=0)
void MuonResidualsPositionFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
virtual bool fit(Alignable *ali)=0
void fill(double *residual)
MuonResidualsFitter * fitter()
double value(int parNum)
bool dofit(void(*fcn)(int &, double *, double &, double *, int), std::vector< int > &parNum, std::vector< std::string > &parName, std::vector< double > &start, std::vector< double > &step, std::vector< double > &low, std::vector< double > &high)
double MuonResidualsFitter_logROOTVoigt(double residual, double center, double sigma, double gamma)
double MuonResidualsFitter_compute_log_convolution(double toversigma, double gammaoversigma, double max=1000., double step=0.001, double power=4.)
std::vector< double > m_value
std::vector< double * > m_residuals
const T & max(const T &a, const T &b)
bool fixed(int parNum)
double MuonResidualsFitter_logPowerLawTails(double residual, double center, double sigma, double gamma)
Double_t MuonResidualsFitter_GaussPowerTails_TF1(Double_t *xvec, Double_t *par)
virtual double plot(std::string name, TFileDirectory *dir, Alignable *ali)=0
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
void plotsimple(std::string name, TFileDirectory *dir, int which, double multiplier)
virtual int ndata()=0
void setStrategy(int strategy)
virtual double sumofweights()=0
MuonResidualsFitter * m_fitter
double errorerror(int parNum)
void fcn(int &, double *, double &, double *, int)
long long int num
Definition: procUtils.cc:71
std::vector< double * >::const_iterator residuals_end() const
void plotweighted(std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier)
void MuonResidualsAngleFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
std::vector< bool > m_fixed
dbl *** dir
Definition: mlp_gen.cc:35
void setPrintLevel(int printLevel)
Double_t MuonResidualsFitter_ROOTVoigt_TF1(Double_t *xvec, Double_t *par)
std::vector< double * >::const_iterator residuals_begin() const
MuonResidualsFitter(int residualsModel, int minHits, bool weightAlignment=true)
virtual int type() const =0
MuonResidualsFitterFitInfo(MuonResidualsFitter *fitter)
double MuonResidualsFitter_logPureGaussian(double residual, double center, double sigma)
const double par[8 *NPar][4]