CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Protected Member Functions
MuonResiduals1DOFFitter Class Reference

#include <MuonResiduals1DOFFitter.h>

Inheritance diagram for MuonResiduals1DOFFitter:
MuonResidualsFitter

Public Types

enum  { kAlign = 0, kSigma, kGamma, kNPar }
 
enum  { kResid = 0, kRedChi2, kNData }
 
- Public Types inherited from MuonResidualsFitter
enum  {
  kPureGaussian, kPowerLawTails, kROOTVoigt, kGaussPowerTails,
  kPureGaussian2D
}
 
enum  {
  k1DOF, k5DOF, k6DOF, k6DOFrphi,
  kPositionFitter, kAngleFitter, kAngleBfieldFitter
}
 
enum  {
  k1111, k1110, k1100, k1010,
  k0010, k1000, k0100
}
 

Public Member Functions

bool fit (Alignable *ali) override
 
 MuonResiduals1DOFFitter (int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)
 
int ndata () override
 
int npar () override
 
double plot (std::string name, TFileDirectory *dir, Alignable *ali) override
 
double sumofweights () override
 
int type () const override
 
- Public Member Functions inherited from MuonResidualsFitter
void computeHistogramRangeAndBinning (int which, int &nbins, double &a, double &b)
 
virtual void correctBField ()=0
 
virtual void correctBField (int idx_momentum, int idx_q)
 
TMatrixDSym correlationMatrix ()
 
double covarianceElement (int parNum1, int parNum2)
 
TMatrixDSym covarianceMatrix ()
 
void eraseNotSelectedResiduals ()
 
double errorerror (int parNum)
 
void fiducialCuts (double xMin=-80.0, double xMax=80.0, double yMin=-80.0, double yMax=80.0, bool fidcut1=false)
 
void fill (double *residual)
 
void fix (int parNum, bool dofix=true)
 
bool fixed (int parNum)
 
void histogramChi2GaussianFit (int which, double &fit_mean, double &fit_sigma)
 
double loglikelihood ()
 
 MuonResidualsFitter (int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)
 
int nfixed ()
 
long numResiduals () const
 
long numsegments ()
 
int parNum2parIdx (int parNum)
 
void plotsimple (std::string name, TFileDirectory *dir, int which, double multiplier)
 
void plotweighted (std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier)
 
void read (FILE *file, int which=0)
 
std::vector< double * >::const_iterator residuals_begin () const
 
std::vector< double * >::const_iterator residuals_end () const
 
int residualsModel () const
 
std::vector< bool > & selectedResidualsFlags ()
 
void selectPeakResiduals (double nsigma, int nvar, int *vars)
 
void selectPeakResiduals_simple (double nsigma, int nvar, int *vars)
 
void setInitialValue (int parNum, double value)
 
void setPrintLevel (int printLevel)
 
void setStrategy (int strategy)
 
int useRes (int pattern=-1)
 
double value (int parNum)
 
void write (FILE *file, int which=0)
 
virtual ~MuonResidualsFitter ()
 

Protected Member Functions

void inform (TMinuit *tMinuit) override
 
- Protected Member Functions inherited from MuonResidualsFitter
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)
 
void initialize_table ()
 

Additional Inherited Members

- Protected Attributes inherited from MuonResidualsFitter
double m_center [20]
 
TMatrixDSym m_cov
 
std::vector< double > m_error
 
std::vector< bool > m_fixed
 
double m_loglikelihood
 
int m_minHits
 
std::map< int, double > m_parNum2InitValue
 
std::map< int, int > m_parNum2parIdx
 
int m_printLevel
 
double m_radii [20]
 
std::vector< double * > m_residuals
 
std::vector< bool > m_residuals_ok
 
int m_residualsModel
 
int m_strategy
 
int m_useResiduals
 
std::vector< double > m_value
 
bool m_weightAlignment
 

Detailed Description

$Date: Fri Apr 17 16:09:40 CDT 2009

Revision
1.4
Author
J. Pivarski - Texas A&M University pivar.nosp@m.ski@.nosp@m.physi.nosp@m.cs.t.nosp@m.amu.e.nosp@m.du

Definition at line 12 of file MuonResiduals1DOFFitter.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

◆ anonymous enum

anonymous enum

Constructor & Destructor Documentation

◆ MuonResiduals1DOFFitter()

MuonResiduals1DOFFitter::MuonResiduals1DOFFitter ( int  residualsModel,
int  minHits,
int  useResiduals,
bool  weightAlignment = true 
)
inline

Definition at line 18 of file MuonResiduals1DOFFitter.h.

tuple weightAlignment
Definition: align_cfg.py:30
MuonResidualsFitter(int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)

Member Function Documentation

◆ fit()

bool MuonResiduals1DOFFitter::fit ( Alignable ali)
overridevirtual

Implements MuonResidualsFitter.

Definition at line 64 of file MuonResiduals1DOFFitter.cc.

References MuonResidualsFitter::dofit(), MuonResidualsFitter::fixed(), LaserClient_cfi::high, MuonResidualsFitter::initialize_table(), kAlign, kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPureGaussian, kRedChi2, kResid, kSigma, LaserClient_cfi::low, MuonResidualsFitter::m_weightAlignment, MuonResiduals1DOFFitter_FCN(), Skims_PA_cff::name, EgammaValidation_cff::num, funct::pow(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), mathSSE::sqrt(), command_line::start, AlCaHLTBitMon_QueryRunRegistry::string, sumofweights(), and mps_merge::weight.

Referenced by trackingPlots.Iteration::modules().

64  {
65  initialize_table(); // if not already initialized
66  sumofweights();
67 
68  double resid_sum = 0.;
69  double resid_sum2 = 0.;
70  double resid_N = 0.;
71 
72  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
73  const double residual = (*resiter)[MuonResiduals1DOFFitter::kResid];
74  const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
75  double weight = 1. / redchi2;
76  if (!m_weightAlignment)
77  weight = 1.;
78 
79  if (!m_weightAlignment || TMath::Prob(redchi2 * 8, 8) < 0.99) { // no spikes allowed
80  if (fabs(residual) < 10.) { // 10 cm
81  resid_sum += weight * residual;
82  resid_sum2 += weight * residual * residual;
83  resid_N += weight;
84  }
85  }
86  }
87 
88  double resid_mean = resid_sum / resid_N;
89  double resid_stdev = sqrt(resid_sum2 / resid_N - pow(resid_sum / resid_N, 2));
90 
91  resid_sum = 0.;
92  resid_sum2 = 0.;
93  resid_N = 0.;
94 
95  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
96  const double residual = (*resiter)[MuonResiduals1DOFFitter::kResid];
97  const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
98  double weight = 1. / redchi2;
99  if (!m_weightAlignment)
100  weight = 1.;
101 
102  if (!m_weightAlignment || TMath::Prob(redchi2 * 8, 8) < 0.99) { // no spikes allowed
103  if (fabs(residual - resid_mean) < 2.5 * resid_stdev) {
104  resid_sum += weight * residual;
105  resid_sum2 += weight * residual * residual;
106  resid_N += weight;
107  }
108  }
109  }
110 
111  resid_mean = resid_sum / resid_N;
112  resid_stdev = sqrt(resid_sum2 / resid_N - pow(resid_sum / resid_N, 2));
113 
114  std::vector<int> num;
115  std::vector<std::string> name;
116  std::vector<double> start;
117  std::vector<double> step;
118  std::vector<double> low;
119  std::vector<double> high;
120 
121  if (fixed(kAlign)) {
122  num.push_back(kAlign);
123  name.push_back(std::string("Align"));
124  start.push_back(0.);
125  step.push_back(0.01 * resid_stdev);
126  low.push_back(0.);
127  high.push_back(0.);
128  } else {
129  num.push_back(kAlign);
130  name.push_back(std::string("Align"));
131  start.push_back(resid_mean);
132  step.push_back(0.01 * resid_stdev);
133  low.push_back(0.);
134  high.push_back(0.);
135  }
136  num.push_back(kSigma);
137  name.push_back(std::string("Sigma"));
138  start.push_back(resid_stdev);
139  step.push_back(0.01 * resid_stdev);
140  low.push_back(0.);
141  high.push_back(0.);
143  num.push_back(kGamma);
144  name.push_back(std::string("Gamma"));
145  start.push_back(0.1 * resid_stdev);
146  step.push_back(0.01 * resid_stdev);
147  low.push_back(0.);
148  high.push_back(0.);
149  }
150 
152 }
Definition: start.py:1
std::vector< double * >::const_iterator residuals_begin() const
Definition: weight.py:1
std::vector< double * >::const_iterator residuals_end() const
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)
T sqrt(T t)
Definition: SSEVec.h:19
step
Definition: StallMonitor.cc:83
void MuonResiduals1DOFFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ inform()

void MuonResiduals1DOFFitter::inform ( TMinuit *  tMinuit)
overrideprotectedvirtual

Implements MuonResidualsFitter.

Definition at line 9 of file MuonResiduals1DOFFitter.cc.

References MuonResiduals1DOFFitter_TMinuit.

static TMinuit * MuonResiduals1DOFFitter_TMinuit

◆ ndata()

int MuonResiduals1DOFFitter::ndata ( )
inlineoverridevirtual

Implements MuonResidualsFitter.

Definition at line 33 of file MuonResiduals1DOFFitter.h.

References kNData.

◆ npar()

int MuonResiduals1DOFFitter::npar ( )
inlineoverridevirtual

◆ plot()

double MuonResiduals1DOFFitter::plot ( std::string  name,
TFileDirectory dir,
Alignable ali 
)
overridevirtual

Implements MuonResidualsFitter.

Definition at line 154 of file MuonResiduals1DOFFitter.cc.

References cms::cuda::assert(), nano_mu_local_reco_cff::chi2, DeadROC_duringRun::dir, mps_fire::i, kAlign, kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, kRedChi2, kResid, MuonResidualsFitter::kROOTVoigt, kSigma, MuonResidualsFitter::m_weightAlignment, MuonResiduals1DOFFitter_sum_of_weights, MuonResidualsFitter_GaussPowerTails_TF1(), MuonResidualsFitter_powerLawTails_TF1(), MuonResidualsFitter_pureGaussian_TF1(), MuonResidualsFitter_ROOTVoigt_TF1(), Skims_PA_cff::name, ndof, npar(), funct::pow(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), sumofweights(), MuonResidualsFitter::value(), and protons_cff::xi.

154  {
155  sumofweights();
156 
157  std::stringstream name_residual, name_residual_raw;
158  name_residual << name << "_residual";
159  name_residual_raw << name << "_residual_raw";
160 
161  double min_residual = -100.;
162  double max_residual = 100.;
163  TH1F *hist_residual = dir->make<TH1F>(name_residual.str().c_str(), "", 100, min_residual, max_residual);
164  TH1F *hist_residual_raw = dir->make<TH1F>(name_residual_raw.str().c_str(), "", 100, min_residual, max_residual);
165 
166  name_residual << "_fit";
167  TF1 *fit_residual = nullptr;
168  if (residualsModel() == kPureGaussian) {
169  fit_residual =
170  new TF1(name_residual.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, min_residual, max_residual, 3);
171  fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual) / 100.,
172  10. * value(kAlign),
173  10. * value(kSigma));
174  } else if (residualsModel() == kPowerLawTails) {
175  fit_residual =
176  new TF1(name_residual.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, min_residual, max_residual, 4);
177  fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual) / 100.,
178  10. * value(kAlign),
179  10. * value(kSigma),
180  10. * value(kGamma));
181  } else if (residualsModel() == kROOTVoigt) {
182  fit_residual =
183  new TF1(name_residual.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_residual, max_residual, 4);
184  fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual) / 100.,
185  10. * value(kAlign),
186  10. * value(kSigma),
187  10. * value(kGamma));
188  } else if (residualsModel() == kGaussPowerTails) {
189  fit_residual =
190  new TF1(name_residual.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_residual, max_residual, 3);
191  fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual) / 100.,
192  10. * value(kAlign),
193  10. * value(kSigma));
194  } else {
195  assert(false);
196  }
197 
198  fit_residual->SetLineColor(2);
199  fit_residual->SetLineWidth(2);
200  fit_residual->Write();
201 
202  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
203  const double resid = (*resiter)[MuonResiduals1DOFFitter::kResid];
204  const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
205  double weight = 1. / redchi2;
206  if (!m_weightAlignment)
207  weight = 1.;
208 
209  if (!m_weightAlignment || TMath::Prob(redchi2 * 8, 8) < 0.99) { // no spikes allowed
210  hist_residual->Fill(10. * (resid + value(kAlign)), weight);
211  }
212 
213  hist_residual_raw->Fill(10. * resid);
214  }
215 
216  double chi2 = 0.;
217  double ndof = 0.;
218  for (int i = 1; i <= hist_residual->GetNbinsX(); i++) {
219  double xi = hist_residual->GetBinCenter(i);
220  double yi = hist_residual->GetBinContent(i);
221  double yerri = hist_residual->GetBinError(i);
222  double yth = fit_residual->Eval(xi);
223  if (yerri > 0.) {
224  chi2 += pow((yth - yi) / yerri, 2);
225  ndof += 1.;
226  }
227  }
228  ndof -= npar();
229 
230  return (ndof > 0. ? chi2 / ndof : -1.);
231 }
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
std::vector< double * >::const_iterator residuals_begin() const
Definition: weight.py:1
double value(int parNum)
std::vector< double * >::const_iterator residuals_end() const
assert(be >=bs)
Double_t MuonResidualsFitter_GaussPowerTails_TF1(Double_t *xvec, Double_t *par)
static double MuonResiduals1DOFFitter_sum_of_weights
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
Double_t MuonResidualsFitter_ROOTVoigt_TF1(Double_t *xvec, Double_t *par)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ sumofweights()

double MuonResiduals1DOFFitter::sumofweights ( )
overridevirtual

Implements MuonResidualsFitter.

Definition at line 45 of file MuonResiduals1DOFFitter.cc.

References kRedChi2, MuonResidualsFitter::m_weightAlignment, MuonResiduals1DOFFitter_number_of_hits, MuonResiduals1DOFFitter_sum_of_weights, MuonResiduals1DOFFitter_weightAlignment, MuonResidualsFitter::residuals_begin(), and MuonResidualsFitter::residuals_end().

Referenced by fit(), and plot().

45  {
49  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
50  if (m_weightAlignment) {
51  double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
52  if (TMath::Prob(redchi2 * 8, 8) < 0.99) { // no spikes allowed
55  }
56  } else {
59  }
60  }
62 }
std::vector< double * >::const_iterator residuals_begin() const
static double MuonResiduals1DOFFitter_number_of_hits
std::vector< double * >::const_iterator residuals_end() const
static bool MuonResiduals1DOFFitter_weightAlignment
static double MuonResiduals1DOFFitter_sum_of_weights

◆ type()

int MuonResiduals1DOFFitter::type ( ) const
inlineoverridevirtual