test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 
 MuonResiduals1DOFFitter (int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)
 
int ndata ()
 
int npar ()
 
double plot (std::string name, TFileDirectory *dir, Alignable *ali)
 
double sumofweights ()
 
int type () const
 
- 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)
 
- 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

Constructor & Destructor Documentation

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

Definition at line 27 of file MuonResiduals1DOFFitter.h.

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

Member Function Documentation

bool MuonResiduals1DOFFitter::fit ( Alignable ali)
virtual

Implements MuonResidualsFitter.

Definition at line 68 of file MuonResiduals1DOFFitter.cc.

References MuonResidualsFitter::dofit(), MuonResidualsFitter::fixed(), MuonResidualsFitter::initialize_table(), kAlign, kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPureGaussian, kRedChi2, kResid, kSigma, MuonResidualsFitter::m_weightAlignment, MuonResiduals1DOFFitter_FCN(), N, mergeVDriftHistosByStation::name, pileupDistInMC::num, funct::pow(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), mathSSE::sqrt(), dqm_diff::start, relval_parameters_module::step, AlCaHLTBitMon_QueryRunRegistry::string, sumofweights(), and puppiForMET_cff::weight.

Referenced by trackingPlots.Iteration::modules().

68  {
69  initialize_table(); // if not already initialized
70  sumofweights();
71 
72  double resid_sum = 0.;
73  double resid_sum2 = 0.;
74  double resid_N = 0.;
75  int N = 0;
76 
77  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
78  const double residual = (*resiter)[MuonResiduals1DOFFitter::kResid];
79  const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
80  double weight = 1./redchi2;
81  if (!m_weightAlignment) weight = 1.;
82 
83  if (!m_weightAlignment || TMath::Prob(redchi2*8, 8) < 0.99) { // no spikes allowed
84  if (fabs(residual) < 10.) { // 10 cm
85  resid_sum += weight * residual;
86  resid_sum2 += weight * residual * residual;
87  resid_N += weight;
88  N++;
89  }
90  }
91  }
92 
93  double resid_mean = resid_sum/resid_N;
94  double resid_stdev = sqrt(resid_sum2/resid_N - pow(resid_sum/resid_N, 2));
95 
96  resid_sum = 0.;
97  resid_sum2 = 0.;
98  resid_N = 0.;
99 
100  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
101  const double residual = (*resiter)[MuonResiduals1DOFFitter::kResid];
102  const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
103  double weight = 1./redchi2;
104  if (!m_weightAlignment) weight = 1.;
105 
106  if (!m_weightAlignment || TMath::Prob(redchi2*8, 8) < 0.99) { // no spikes allowed
107  if (fabs(residual - resid_mean) < 2.5*resid_stdev) {
108  resid_sum += weight * residual;
109  resid_sum2 += weight * residual * residual;
110  resid_N += weight;
111  }
112  }
113  }
114 
115  resid_mean = resid_sum/resid_N;
116  resid_stdev = sqrt(resid_sum2/resid_N - pow(resid_sum/resid_N, 2));
117 
118  std::vector<int> num;
119  std::vector<std::string> name;
120  std::vector<double> start;
121  std::vector<double> step;
122  std::vector<double> low;
123  std::vector<double> high;
124 
125  if (fixed(kAlign)) {
126  num.push_back(kAlign); name.push_back(std::string("Align")); start.push_back(0.); step.push_back(0.01*resid_stdev); low.push_back(0.); high.push_back(0.);
127  } else {
128  num.push_back(kAlign); name.push_back(std::string("Align")); start.push_back(resid_mean); step.push_back(0.01*resid_stdev); low.push_back(0.); high.push_back(0.);
129  }
130  num.push_back(kSigma); name.push_back(std::string("Sigma")); start.push_back(resid_stdev); step.push_back(0.01*resid_stdev); low.push_back(0.); high.push_back(0.);
132  num.push_back(kGamma); name.push_back(std::string("Gamma")); start.push_back(0.1*resid_stdev); step.push_back(0.01*resid_stdev); low.push_back(0.); high.push_back(0.);
133  }
134 
135  return dofit(&MuonResiduals1DOFFitter_FCN, num, name, start, step, low, high);
136 }
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
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:18
#define N
Definition: blowfish.cc:9
std::vector< double * >::const_iterator residuals_end() const
std::vector< double * >::const_iterator residuals_begin() const
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:40
void MuonResiduals1DOFFitter::inform ( TMinuit *  tMinuit)
protectedvirtual

Implements MuonResidualsFitter.

Definition at line 9 of file MuonResiduals1DOFFitter.cc.

References MuonResiduals1DOFFitter_TMinuit.

9  {
11 }
static TMinuit * MuonResiduals1DOFFitter_TMinuit
int MuonResiduals1DOFFitter::ndata ( )
inlinevirtual

Implements MuonResidualsFitter.

Definition at line 37 of file MuonResiduals1DOFFitter.h.

References kNData.

int MuonResiduals1DOFFitter::npar ( )
inlinevirtual
double MuonResiduals1DOFFitter::plot ( std::string  name,
TFileDirectory dir,
Alignable ali 
)
virtual

Implements MuonResidualsFitter.

Definition at line 138 of file MuonResiduals1DOFFitter.cc.

References assert(), beam_dqm_sourceclient-live_cfg::chi2, i, kAlign, kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, kRedChi2, kResid, MuonResidualsFitter::kROOTVoigt, kSigma, MuonResidualsFitter::m_weightAlignment, TFileDirectory::make(), MuonResiduals1DOFFitter_sum_of_weights, MuonResidualsFitter_GaussPowerTails_TF1(), MuonResidualsFitter_powerLawTails_TF1(), MuonResidualsFitter_pureGaussian_TF1(), MuonResidualsFitter_ROOTVoigt_TF1(), ndof, npar(), NULL, funct::pow(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), sumofweights(), MuonResidualsFitter::value(), and puppiForMET_cff::weight.

Referenced by cuy.FindIssue::__init__().

138  {
139  sumofweights();
140 
141  std::stringstream name_residual, name_residual_raw;
142  name_residual << name << "_residual";
143  name_residual_raw << name << "_residual_raw";
144 
145  double min_residual = -100.; double max_residual = 100.;
146  TH1F *hist_residual = dir->make<TH1F>(name_residual.str().c_str(), "", 100, min_residual, max_residual);
147  TH1F *hist_residual_raw = dir->make<TH1F>(name_residual_raw.str().c_str(), "", 100, min_residual, max_residual);
148 
149  name_residual << "_fit";
150  TF1 *fit_residual = NULL;
151  if (residualsModel() == kPureGaussian) {
152  fit_residual = new TF1(name_residual.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, min_residual, max_residual, 3);
153  fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual)/100., 10.*value(kAlign), 10.*value(kSigma));
154  }
155  else if (residualsModel() == kPowerLawTails) {
156  fit_residual = new TF1(name_residual.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, min_residual, max_residual, 4);
157  fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual)/100., 10.*value(kAlign), 10.*value(kSigma), 10.*value(kGamma));
158  }
159  else if (residualsModel() == kROOTVoigt) {
160  fit_residual = new TF1(name_residual.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_residual, max_residual, 4);
161  fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual)/100., 10.*value(kAlign), 10.*value(kSigma), 10.*value(kGamma));
162  }
163  else if (residualsModel() == kGaussPowerTails) {
164  fit_residual = new TF1(name_residual.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_residual, max_residual, 3);
165  fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual)/100., 10.*value(kAlign), 10.*value(kSigma));
166  }
167  else { assert(false); }
168 
169  fit_residual->SetLineColor(2); fit_residual->SetLineWidth(2);
170  fit_residual->Write();
171 
172  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
173  const double resid = (*resiter)[MuonResiduals1DOFFitter::kResid];
174  const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
175  double weight = 1./redchi2;
176  if (!m_weightAlignment) weight = 1.;
177 
178  if (!m_weightAlignment || TMath::Prob(redchi2*8, 8) < 0.99) { // no spikes allowed
179  hist_residual->Fill(10.*(resid + value(kAlign)), weight);
180  }
181 
182  hist_residual_raw->Fill(10.*resid);
183  }
184 
185  double chi2 = 0.;
186  double ndof = 0.;
187  for (int i = 1; i <= hist_residual->GetNbinsX(); i++) {
188  double xi = hist_residual->GetBinCenter(i);
189  double yi = hist_residual->GetBinContent(i);
190  double yerri = hist_residual->GetBinError(i);
191  double yth = fit_residual->Eval(xi);
192  if (yerri > 0.) {
193  chi2 += pow((yth - yi)/yerri, 2);
194  ndof += 1.;
195  }
196  }
197  ndof -= npar();
198 
199  return (ndof > 0. ? chi2 / ndof : -1.);
200 }
int i
Definition: DBlmapReader.cc:9
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
assert(m_qm.get())
#define NULL
Definition: scimark2.h:8
double value(int parNum)
Double_t MuonResidualsFitter_GaussPowerTails_TF1(Double_t *xvec, Double_t *par)
T * make(const Args &...args) const
make new ROOT object
static double MuonResiduals1DOFFitter_sum_of_weights
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
std::vector< double * >::const_iterator residuals_end() const
Double_t MuonResidualsFitter_ROOTVoigt_TF1(Double_t *xvec, Double_t *par)
std::vector< double * >::const_iterator residuals_begin() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double MuonResiduals1DOFFitter::sumofweights ( )
virtual

Implements MuonResidualsFitter.

Definition at line 48 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().

48  {
52  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
53  if (m_weightAlignment) {
54  double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
55  if (TMath::Prob(redchi2*8, 8) < 0.99) { // no spikes allowed
58  }
59  }
60  else {
63  }
64  }
66 }
static double MuonResiduals1DOFFitter_number_of_hits
static bool MuonResiduals1DOFFitter_weightAlignment
static double MuonResiduals1DOFFitter_sum_of_weights
std::vector< double * >::const_iterator residuals_end() const
std::vector< double * >::const_iterator residuals_begin() const
int MuonResiduals1DOFFitter::type ( ) const
inlinevirtual