CMS 3D CMS Logo

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

#include <MuonResidualsPositionFitter.h>

Inheritance diagram for MuonResidualsPositionFitter:
MuonResidualsFitter

Public Types

enum  {
  kPosition = 0, kZpos, kPhiz, kScattering,
  kSigma, kGamma, kNPar
}
 
enum  {
  kResidual = 0, kAngleError, kTrackAngle, kTrackPosition,
  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
 
 MuonResidualsPositionFitter (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
2010/03/12 22:23:34
Revision
1.8
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 MuonResidualsPositionFitter.h.

Member Enumeration Documentation

anonymous enum
anonymous enum

Constructor & Destructor Documentation

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

Definition at line 32 of file MuonResidualsPositionFitter.h.

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

Member Function Documentation

bool MuonResidualsPositionFitter::fit ( Alignable ali)
overridevirtual

Implements MuonResidualsFitter.

Definition at line 42 of file MuonResidualsPositionFitter.cc.

References MuonResidualsFitter::dofit(), MuonResidualsFitter::initialize_table(), kGamma, MuonResidualsFitter::kGaussPowerTails, kPhiz, kPosition, MuonResidualsFitter::kPureGaussian, kResidual, kScattering, kSigma, kZpos, MuonResidualsFitter::m_minHits, SiStripPI::mean, MuonResidualsPositionFitter_FCN(), N, funct::pow(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), mathSSE::sqrt(), command_line::start, plotscripts::stdev(), AlCaHLTBitMon_QueryRunRegistry::string, makeMuonMisalignmentScenario::sum_x, and makeMuonMisalignmentScenario::sum_xx.

Referenced by trackingPlots.Iteration::modules(), and ndata().

42  {
43  initialize_table(); // if not already initialized
44 
45  double sum_x = 0.;
46  double sum_xx = 0.;
47  int N = 0;
48 
49  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
50  const double residual = (*resiter)[kResidual];
51  // const double angleerror = (*resiter)[kAngleError];
52  // const double trackangle = (*resiter)[kTrackAngle];
53  // const double trackposition = (*resiter)[kTrackPosition];
54 
55  if (fabs(residual) < 10.) { // truncate at 100 mm
56  sum_x += residual;
57  sum_xx += residual*residual;
58  N++;
59  }
60  }
61 
62  if (N < m_minHits) return false;
63 
64  // truncated mean and stdev to seed the fit
65  double mean = sum_x/double(N);
66  double stdev = sqrt(sum_xx/double(N) - pow(sum_x/double(N), 2));
67 
68  // refine the standard deviation calculation
69  sum_x = 0.;
70  sum_xx = 0.;
71  N = 0;
72  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
73  const double residual = (*resiter)[kResidual];
74  if (mean - 1.5*stdev < residual && residual < mean + 1.5*stdev) {
75  sum_x += residual;
76  sum_xx += residual*residual;
77  N++;
78  }
79  }
80  mean = sum_x/double(N);
81  stdev = sqrt(sum_xx/double(N) - pow(sum_x/double(N), 2));
82 
83  sum_x = 0.;
84  sum_xx = 0.;
85  N = 0;
86  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
87  const double residual = (*resiter)[kResidual];
88  if (mean - 1.5*stdev < residual && residual < mean + 1.5*stdev) {
89  sum_x += residual;
90  sum_xx += residual*residual;
91  N++;
92  }
93  }
94  mean = sum_x/double(N);
95  stdev = sqrt(sum_xx/double(N) - pow(sum_x/double(N), 2));
96 
97  std::vector<int> parNum;
98  std::vector<std::string> parName;
99  std::vector<double> start;
100  std::vector<double> step;
101  std::vector<double> low;
102  std::vector<double> high;
103 
104  parNum.push_back(kPosition); parName.push_back(std::string("position")); start.push_back(mean); step.push_back(0.1); low.push_back(0.); high.push_back(0.);
105  parNum.push_back(kZpos); parName.push_back(std::string("zpos")); start.push_back(0.); step.push_back(0.1); low.push_back(0.); high.push_back(0.);
106  parNum.push_back(kPhiz); parName.push_back(std::string("phiz")); start.push_back(0.); step.push_back(0.1); low.push_back(0.); high.push_back(0.);
107  parNum.push_back(kScattering); parName.push_back(std::string("scattering")); start.push_back(0.); step.push_back(0.1*1000.); low.push_back(0.); high.push_back(0.);
108  parNum.push_back(kSigma); parName.push_back(std::string("sigma")); start.push_back(stdev); step.push_back(0.1*stdev); low.push_back(0.); high.push_back(0.);
110  parNum.push_back(kGamma); parName.push_back(std::string("gamma")); start.push_back(stdev); step.push_back(0.1*stdev); low.push_back(0.); high.push_back(0.);
111  }
112 
113  return dofit(&MuonResidualsPositionFitter_FCN, parNum, parName, start, step, low, high);
114 }
void MuonResidualsPositionFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
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
def stdev(xlist)
Definition: plotscripts.py:67
step
std::vector< double * >::const_iterator residuals_begin() const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void MuonResidualsPositionFitter::inform ( TMinuit *  tMinuit)
overrideprotectedvirtual

Implements MuonResidualsFitter.

Definition at line 5 of file MuonResidualsPositionFitter.cc.

References MuonResidualsPositionFitter_TMinuit.

Referenced by sumofweights().

5  {
7 }
static TMinuit * MuonResidualsPositionFitter_TMinuit
int MuonResidualsPositionFitter::ndata ( )
inlineoverridevirtual

Implements MuonResidualsFitter.

Definition at line 42 of file MuonResidualsPositionFitter.h.

References fit(), and kNData.

int MuonResidualsPositionFitter::npar ( )
inlineoverridevirtual
double MuonResidualsPositionFitter::plot ( std::string  name,
TFileDirectory dir,
Alignable ali 
)
overridevirtual

Implements MuonResidualsFitter.

Definition at line 116 of file MuonResidualsPositionFitter.cc.

References kAngleError, kGamma, MuonResidualsFitter::kGaussPowerTails, kPhiz, kPosition, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, kResidual, MuonResidualsFitter::kROOTVoigt, kScattering, kSigma, kTrackAngle, kTrackPosition, kZpos, TFileDirectory::make(), MuonResidualsFitter_GaussPowerTails_TF1(), MuonResidualsFitter_powerLawTails_TF1(), MuonResidualsFitter_pureGaussian_TF1(), MuonResidualsFitter_ROOTVoigt_TF1(), MuonResidualsFitter::numResiduals(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), AlCaHLTBitMon_QueryRunRegistry::string, and MuonResidualsFitter::value().

Referenced by sumofweights().

116  {
117  std::stringstream raw_name, narrowed_name, angleerror_name, trackangle_name, trackposition_name;
118  raw_name << name << "_raw";
119  narrowed_name << name << "_narrowed";
120  angleerror_name << name << "_angleerror";
121  trackangle_name << name << "_trackangle";
122  trackposition_name << name << "_trackposition";
123 
124  TH1F *raw_hist = dir->make<TH1F>(raw_name.str().c_str(), (raw_name.str() + std::string(" (mm)")).c_str(), 100, -100., 100.);
125  TH1F *narrowed_hist = dir->make<TH1F>(narrowed_name.str().c_str(), (narrowed_name.str() + std::string(" (mm)")).c_str(), 100, -100., 100.);
126  TProfile *angleerror_hist = dir->make<TProfile>(angleerror_name.str().c_str(), (angleerror_name.str() + std::string(" (mm)")).c_str(), 100, -30., 30.);
127  TProfile *trackangle_hist = dir->make<TProfile>(trackangle_name.str().c_str(), (trackangle_name.str() + std::string(" (mm)")).c_str(), 100, -0.5, 0.5);
128  TProfile *trackposition_hist = dir->make<TProfile>(trackposition_name.str().c_str(), (trackposition_name.str() + std::string(" (mm)")).c_str(), 100, -300., 300.);
129 
130  angleerror_hist->SetAxisRange(-100., 100., "Y");
131  trackangle_hist->SetAxisRange(-10., 10., "Y");
132  trackposition_hist->SetAxisRange(-10., 10., "Y");
133 
134  narrowed_name << "fit";
135  angleerror_name << "fit";
136  trackangle_name << "fit";
137  trackposition_name << "fit";
138 
139  double scale_factor = double(numResiduals()) * (100. - -100.)/100; // (max - min)/nbins
140 
141  TF1 *narrowed_fit = nullptr;
142  if (residualsModel() == kPureGaussian) {
143  narrowed_fit = new TF1(narrowed_name.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, -100., 100., 3);
144  narrowed_fit->SetParameters(scale_factor, value(kPosition) * 10., value(kSigma) * 10.);
145  narrowed_fit->Write();
146  }
147  else if (residualsModel() == kPowerLawTails) {
148  narrowed_fit = new TF1(narrowed_name.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, -100., 100., 4);
149  narrowed_fit->SetParameters(scale_factor, value(kPosition) * 10., value(kSigma) * 10., value(kGamma) * 10.);
150  narrowed_fit->Write();
151  }
152  else if (residualsModel() == kROOTVoigt) {
153  narrowed_fit = new TF1(narrowed_name.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, -100., 100., 4);
154  narrowed_fit->SetParameters(scale_factor, value(kPosition) * 10., value(kSigma) * 10., value(kGamma) * 10.);
155  narrowed_fit->Write();
156  }
157  else if (residualsModel() == kGaussPowerTails) {
158  narrowed_fit = new TF1(narrowed_name.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, -100., 100., 3);
159  narrowed_fit->SetParameters(scale_factor, value(kPosition) * 10., value(kSigma) * 10.);
160  narrowed_fit->Write();
161  }
162 
163  TF1 *angleerror_fit = new TF1(angleerror_name.str().c_str(), "[0]+x*[1]", -30., 30.);
164  angleerror_fit->SetParameters(value(kPosition) * 10., value(kScattering) * 10./1000.);
165  angleerror_fit->Write();
166 
167  TF1 *trackangle_fit = new TF1(trackangle_name.str().c_str(), "[0]+x*[1]", -0.5, 0.5);
168  trackangle_fit->SetParameters(value(kPosition) * 10., value(kZpos) * 10.);
169  trackangle_fit->Write();
170 
171  TF1 *trackposition_fit = new TF1(trackposition_name.str().c_str(), "[0]+x*[1]", -300., 300.);
172  trackposition_fit->SetParameters(value(kPosition) * 10., value(kPhiz) * 10.);
173  trackposition_fit->Write();
174 
175  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
176  const double raw_residual = (*resiter)[kResidual];
177  const double angleerror = (*resiter)[kAngleError];
178  const double trackangle = (*resiter)[kTrackAngle];
179  const double trackposition = (*resiter)[kTrackPosition];
180 
181  double angleerror_correction = value(kScattering) * angleerror;
182  double trackangle_correction = value(kZpos) * trackangle;
183  double trackposition_correction = value(kPhiz) * trackposition;
184 
185  double corrected_residual = raw_residual - angleerror_correction - trackangle_correction - trackposition_correction;
186 
187  raw_hist->Fill(raw_residual * 10.);
188  narrowed_hist->Fill(corrected_residual * 10.);
189 
190  angleerror_hist->Fill(angleerror*1000., (raw_residual - trackangle_correction - trackposition_correction) * 10.);
191  trackangle_hist->Fill(trackangle, (raw_residual - angleerror_correction - trackposition_correction) * 10.);
192  trackposition_hist->Fill(trackposition, (raw_residual - angleerror_correction - trackangle_correction) * 10.);
193  }
194 
195  return 0.;
196 }
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
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
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
double MuonResidualsPositionFitter::sumofweights ( )
inlineoverridevirtual
int MuonResidualsPositionFitter::type ( ) const
inlineoverridevirtual