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
Enumerator
kAlign 
kSigma 
kGamma 
kNPar 

Definition at line 14 of file MuonResiduals1DOFFitter.h.

14 { kAlign = 0, kSigma, kGamma, kNPar };

◆ anonymous enum

anonymous enum
Enumerator
kResid 
kRedChi2 
kNData 

Definition at line 16 of file MuonResiduals1DOFFitter.h.

16 { kResid = 0, kRedChi2, kNData };

Constructor & Destructor Documentation

◆ MuonResiduals1DOFFitter()

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

Member Function Documentation

◆ fit()

bool MuonResiduals1DOFFitter::fit ( Alignable ali)
overridevirtual

Implements MuonResidualsFitter.

Definition at line 64 of file MuonResiduals1DOFFitter.cc.

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  int N = 0;
72 
73  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
74  const double residual = (*resiter)[MuonResiduals1DOFFitter::kResid];
75  const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
76  double weight = 1. / redchi2;
77  if (!m_weightAlignment)
78  weight = 1.;
79 
80  if (!m_weightAlignment || TMath::Prob(redchi2 * 8, 8) < 0.99) { // no spikes allowed
81  if (fabs(residual) < 10.) { // 10 cm
82  resid_sum += weight * residual;
83  resid_sum2 += weight * residual * residual;
84  resid_N += weight;
85  N++;
86  }
87  }
88  }
89 
90  double resid_mean = resid_sum / resid_N;
91  double resid_stdev = sqrt(resid_sum2 / resid_N - pow(resid_sum / resid_N, 2));
92 
93  resid_sum = 0.;
94  resid_sum2 = 0.;
95  resid_N = 0.;
96 
97  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
98  const double residual = (*resiter)[MuonResiduals1DOFFitter::kResid];
99  const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
100  double weight = 1. / redchi2;
101  if (!m_weightAlignment)
102  weight = 1.;
103 
104  if (!m_weightAlignment || TMath::Prob(redchi2 * 8, 8) < 0.99) { // no spikes allowed
105  if (fabs(residual - resid_mean) < 2.5 * resid_stdev) {
106  resid_sum += weight * residual;
107  resid_sum2 += weight * residual * residual;
108  resid_N += weight;
109  }
110  }
111  }
112 
113  resid_mean = resid_sum / resid_N;
114  resid_stdev = sqrt(resid_sum2 / resid_N - pow(resid_sum / resid_N, 2));
115 
116  std::vector<int> num;
117  std::vector<std::string> name;
118  std::vector<double> start;
119  std::vector<double> step;
120  std::vector<double> low;
121  std::vector<double> high;
122 
123  if (fixed(kAlign)) {
124  num.push_back(kAlign);
125  name.push_back(std::string("Align"));
126  start.push_back(0.);
127  step.push_back(0.01 * resid_stdev);
128  low.push_back(0.);
129  high.push_back(0.);
130  } else {
131  num.push_back(kAlign);
132  name.push_back(std::string("Align"));
133  start.push_back(resid_mean);
134  step.push_back(0.01 * resid_stdev);
135  low.push_back(0.);
136  high.push_back(0.);
137  }
138  num.push_back(kSigma);
139  name.push_back(std::string("Sigma"));
140  start.push_back(resid_stdev);
141  step.push_back(0.01 * resid_stdev);
142  low.push_back(0.);
143  high.push_back(0.);
145  num.push_back(kGamma);
146  name.push_back(std::string("Gamma"));
147  start.push_back(0.1 * resid_stdev);
148  step.push_back(0.01 * resid_stdev);
149  low.push_back(0.);
150  high.push_back(0.);
151  }
152 
154 }

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(), N, 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().

◆ inform()

void MuonResiduals1DOFFitter::inform ( TMinuit *  tMinuit)
overrideprotectedvirtual

Implements MuonResidualsFitter.

Definition at line 9 of file MuonResiduals1DOFFitter.cc.

References MuonResiduals1DOFFitter_TMinuit.

◆ ndata()

int MuonResiduals1DOFFitter::ndata ( )
inlineoverridevirtual

Implements MuonResidualsFitter.

Definition at line 33 of file MuonResiduals1DOFFitter.h.

33 { return kNData; }

References kNData.

◆ npar()

int MuonResiduals1DOFFitter::npar ( )
inlineoverridevirtual

◆ plot()

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

Implements MuonResidualsFitter.

Definition at line 156 of file MuonResiduals1DOFFitter.cc.

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

References cms::cuda::assert(), hltPixelTracks_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(), tools::TF1, MuonResidualsFitter::value(), and hybridSuperClusters_cfi::xi.

◆ sumofweights()

double MuonResiduals1DOFFitter::sumofweights ( )
overridevirtual

◆ type()

int MuonResiduals1DOFFitter::type ( ) const
inlineoverridevirtual

Implements MuonResidualsFitter.

Definition at line 21 of file MuonResiduals1DOFFitter.h.

References MuonResidualsFitter::k1DOF.

MuonResidualsFitter_pureGaussian_TF1
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
Definition: MuonResidualsFitter.cc:38
mps_fire.i
i
Definition: mps_fire.py:428
start
Definition: start.py:1
MuonResiduals1DOFFitter_weightAlignment
static bool MuonResiduals1DOFFitter_weightAlignment
Definition: MuonResiduals1DOFFitter.cc:7
MuonResidualsFitter::MuonResidualsFitter
MuonResidualsFitter(int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)
Definition: MuonResidualsFitter.cc:151
MuonResidualsFitter::value
double value(int parNum)
Definition: MuonResidualsFitter.h:145
align_cfg.useResiduals
useResiduals
Definition: align_cfg.py:36
step
step
Definition: StallMonitor.cc:94
mps_merge.weight
weight
Definition: mps_merge.py:88
MuonResidualsFitter::dofit
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)
Definition: MuonResidualsFitter.cc:272
hybridSuperClusters_cfi.xi
xi
Definition: hybridSuperClusters_cfi.py:10
MuonResiduals1DOFFitter_FCN
void MuonResiduals1DOFFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
Definition: MuonResiduals1DOFFitter.cc:11
MuonResiduals1DOFFitter::npar
int npar() override
Definition: MuonResiduals1DOFFitter.h:23
cms::cuda::assert
assert(be >=bs)
MuonResidualsFitter::kGaussPowerTails
Definition: MuonResidualsFitter.h:86
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
tools.TF1
TF1
Definition: tools.py:23
MuonResiduals1DOFFitter::kRedChi2
Definition: MuonResiduals1DOFFitter.h:16
MuonResiduals1DOFFitter::kSigma
Definition: MuonResiduals1DOFFitter.h:14
MuonResiduals1DOFFitter::kAlign
Definition: MuonResiduals1DOFFitter.h:14
ndof
Definition: HIMultiTrackSelector.h:49
MuonResiduals1DOFFitter::kGamma
Definition: MuonResiduals1DOFFitter.h:14
MuonResiduals1DOFFitter::kNData
Definition: MuonResiduals1DOFFitter.h:16
MuonResiduals1DOFFitter::kResid
Definition: MuonResiduals1DOFFitter.h:16
MuonResiduals1DOFFitter_number_of_hits
static double MuonResiduals1DOFFitter_number_of_hits
Definition: MuonResiduals1DOFFitter.cc:6
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
MuonResidualsFitter::kPowerLawTails
Definition: MuonResidualsFitter.h:86
MuonResidualsFitter_powerLawTails_TF1
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
Definition: MuonResidualsFitter.cc:116
N
#define N
Definition: blowfish.cc:9
MuonResiduals1DOFFitter::kNPar
Definition: MuonResiduals1DOFFitter.h:14
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MuonResidualsFitter::k1DOF
Definition: MuonResidualsFitter.h:88
MuonResidualsFitter_ROOTVoigt_TF1
Double_t MuonResidualsFitter_ROOTVoigt_TF1(Double_t *xvec, Double_t *par)
Definition: MuonResidualsFitter.cc:124
MuonResidualsFitter::kPureGaussian
Definition: MuonResidualsFitter.h:86
MuonResidualsFitter::residuals_end
std::vector< double * >::const_iterator residuals_end() const
Definition: MuonResidualsFitter.h:191
MuonResiduals1DOFFitter_sum_of_weights
static double MuonResiduals1DOFFitter_sum_of_weights
Definition: MuonResiduals1DOFFitter.cc:5
MuonResidualsFitter::kROOTVoigt
Definition: MuonResidualsFitter.h:86
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:34
MuonResidualsFitter::m_weightAlignment
bool m_weightAlignment
Definition: MuonResidualsFitter.h:227
LaserClient_cfi.high
high
Definition: LaserClient_cfi.py:50
align_cfg.weightAlignment
tuple weightAlignment
Definition: align_cfg.py:30
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
MuonResidualsFitter::initialize_table
void initialize_table()
Definition: MuonResidualsFitter.cc:205
MuonResidualsFitter_GaussPowerTails_TF1
Double_t MuonResidualsFitter_GaussPowerTails_TF1(Double_t *xvec, Double_t *par)
Definition: MuonResidualsFitter.cc:142
funct::pow
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
command_line.start
start
Definition: command_line.py:167
MuonResidualsFitter::residualsModel
int residualsModel() const
Definition: MuonResidualsFitter.h:124
MuonResidualsFitter::fixed
bool fixed(int parNum)
Definition: MuonResidualsFitter.cc:178
MuonResidualsFitter::residuals_begin
std::vector< double * >::const_iterator residuals_begin() const
Definition: MuonResidualsFitter.h:190
LaserClient_cfi.low
low
Definition: LaserClient_cfi.py:52
weight
Definition: weight.py:1
reco_skim_cfg_mod.minHits
minHits
Definition: reco_skim_cfg_mod.py:177
MuonResiduals1DOFFitter_TMinuit
static TMinuit * MuonResiduals1DOFFitter_TMinuit
Definition: MuonResiduals1DOFFitter.cc:4
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23
MuonResiduals1DOFFitter::sumofweights
double sumofweights() override
Definition: MuonResiduals1DOFFitter.cc:45