CMS 3D CMS Logo

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

#include <MuonResidualsAngleFitter.h>

Inheritance diagram for MuonResidualsAngleFitter:
MuonResidualsFitter

Public Types

enum  {
  kAngle = 0, kXControl, kYControl, kSigma,
  kGamma, kNPar
}
 
enum  { kResidual = 0, kXAngle, kYAngle, 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
 
 MuonResidualsAngleFitter (int residualsModel, int minHitsPerRegion, 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:18
Revision
1.10
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 MuonResidualsAngleFitter.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

◆ anonymous enum

anonymous enum

Constructor & Destructor Documentation

◆ MuonResidualsAngleFitter()

MuonResidualsAngleFitter::MuonResidualsAngleFitter ( int  residualsModel,
int  minHitsPerRegion,
int  useResiduals,
bool  weightAlignment = true 
)
inline

Definition at line 18 of file MuonResidualsAngleFitter.h.

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

Member Function Documentation

◆ fit()

bool MuonResidualsAngleFitter::fit ( Alignable ali)
overridevirtual

Implements MuonResidualsFitter.

Definition at line 40 of file MuonResidualsAngleFitter.cc.

References MuonResidualsFitter::dofit(), LaserClient_cfi::high, MuonResidualsFitter::initialize_table(), kAngle, kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPureGaussian, kResidual, kSigma, kXControl, kYControl, LaserClient_cfi::low, MuonResidualsFitter::m_minHits, SiStripPI::mean, MuonResidualsAngleFitter_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().

40  {
41  initialize_table(); // if not already initialized
42 
43  double sum_x = 0.;
44  double sum_xx = 0.;
45  int N = 0;
46 
47  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
48  const double residual = (*resiter)[kResidual];
49  // const double xangle = (*resiter)[kXAngle];
50  // const double yangle = (*resiter)[kYAngle];
51 
52  if (fabs(residual) < 0.1) { // truncate at 100 mrad
53  sum_x += residual;
54  sum_xx += residual * residual;
55  N++;
56  }
57  }
58 
59  if (N < m_minHits)
60  return false;
61 
62  // truncated mean and stdev to seed the fit
63  double mean = sum_x / double(N);
64  double stdev = sqrt(sum_xx / double(N) - pow(sum_x / double(N), 2));
65 
66  // refine the standard deviation calculation
67  sum_x = 0.;
68  sum_xx = 0.;
69  N = 0;
70  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
71  const double residual = (*resiter)[kResidual];
72  if (mean - 1.5 * stdev < residual && residual < mean + 1.5 * stdev) {
73  sum_x += residual;
74  sum_xx += residual * residual;
75  N++;
76  }
77  }
78  mean = sum_x / double(N);
79  stdev = sqrt(sum_xx / double(N) - pow(sum_x / double(N), 2));
80 
81  sum_x = 0.;
82  sum_xx = 0.;
83  N = 0;
84  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
85  const double residual = (*resiter)[kResidual];
86  if (mean - 1.5 * stdev < residual && residual < mean + 1.5 * stdev) {
87  sum_x += residual;
88  sum_xx += residual * residual;
89  N++;
90  }
91  }
92  mean = sum_x / double(N);
93  stdev = sqrt(sum_xx / double(N) - pow(sum_x / double(N), 2));
94 
95  std::vector<int> parNum;
96  std::vector<std::string> parName;
97  std::vector<double> start;
98  std::vector<double> step;
99  std::vector<double> low;
100  std::vector<double> high;
101 
102  parNum.push_back(kAngle);
103  parName.push_back(std::string("angle"));
104  start.push_back(mean);
105  step.push_back(0.1);
106  low.push_back(0.);
107  high.push_back(0.);
108  parNum.push_back(kXControl);
109  parName.push_back(std::string("xcontrol"));
110  start.push_back(0.);
111  step.push_back(0.1);
112  low.push_back(0.);
113  high.push_back(0.);
114  parNum.push_back(kYControl);
115  parName.push_back(std::string("ycontrol"));
116  start.push_back(0.);
117  step.push_back(0.1);
118  low.push_back(0.);
119  high.push_back(0.);
120  parNum.push_back(kSigma);
121  parName.push_back(std::string("sigma"));
122  start.push_back(stdev);
123  step.push_back(0.1 * stdev);
124  low.push_back(0.);
125  high.push_back(0.);
127  parNum.push_back(kGamma);
128  parName.push_back(std::string("gamma"));
129  start.push_back(stdev);
130  step.push_back(0.1 * stdev);
131  low.push_back(0.);
132  high.push_back(0.);
133  }
134 
135  return dofit(&MuonResidualsAngleFitter_FCN, parNum, parName, start, step, low, high);
136 }
Definition: start.py:1
std::vector< double * >::const_iterator residuals_begin() const
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:23
#define N
Definition: blowfish.cc:9
void MuonResidualsAngleFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
def stdev(xlist)
Definition: plotscripts.py:69
step
Definition: StallMonitor.cc:83
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ inform()

void MuonResidualsAngleFitter::inform ( TMinuit *  tMinuit)
overrideprotectedvirtual

Implements MuonResidualsFitter.

Definition at line 5 of file MuonResidualsAngleFitter.cc.

References MuonResidualsAngleFitter_TMinuit.

static TMinuit * MuonResidualsAngleFitter_TMinuit

◆ ndata()

int MuonResidualsAngleFitter::ndata ( )
inlineoverridevirtual

Implements MuonResidualsFitter.

Definition at line 33 of file MuonResidualsAngleFitter.h.

References kNData.

◆ npar()

int MuonResidualsAngleFitter::npar ( )
inlineoverridevirtual

◆ plot()

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

Implements MuonResidualsFitter.

Definition at line 138 of file MuonResidualsAngleFitter.cc.

References DeadROC_duringRun::dir, kAngle, kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, kResidual, MuonResidualsFitter::kROOTVoigt, kSigma, kXAngle, kXControl, kYAngle, kYControl, MuonResidualsFitter_GaussPowerTails_TF1(), MuonResidualsFitter_powerLawTails_TF1(), MuonResidualsFitter_pureGaussian_TF1(), MuonResidualsFitter_ROOTVoigt_TF1(), Skims_PA_cff::name, MuonResidualsFitter::numResiduals(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), AlCaHLTBitMon_QueryRunRegistry::string, MuonResidualsFitter::value(), and profile_base_cff::xangle.

138  {
139  std::stringstream raw_name, narrowed_name, xcontrol_name, ycontrol_name;
140  raw_name << name << "_raw";
141  narrowed_name << name << "_narrowed";
142  xcontrol_name << name << "_xcontrol";
143  ycontrol_name << name << "_ycontrol";
144 
145  TH1F *raw_hist =
146  dir->make<TH1F>(raw_name.str().c_str(), (raw_name.str() + std::string(" (mrad)")).c_str(), 100, -100., 100.);
147  TH1F *narrowed_hist = dir->make<TH1F>(
148  narrowed_name.str().c_str(), (narrowed_name.str() + std::string(" (mrad)")).c_str(), 100, -100., 100.);
149  TProfile *xcontrol_hist = dir->make<TProfile>(
150  xcontrol_name.str().c_str(), (xcontrol_name.str() + std::string(" (mrad)")).c_str(), 100, -1., 1.);
151  TProfile *ycontrol_hist = dir->make<TProfile>(
152  ycontrol_name.str().c_str(), (ycontrol_name.str() + std::string(" (mrad)")).c_str(), 100, -1., 1.);
153 
154  narrowed_name << "fit";
155  xcontrol_name << "fit";
156  ycontrol_name << "fit";
157 
158  double scale_factor = double(numResiduals()) * (100. - -100.) / 100; // (max - min)/nbins
159 
160  TF1 *narrowed_fit = nullptr;
161  if (residualsModel() == kPureGaussian) {
162  narrowed_fit = new TF1(narrowed_name.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, -100., 100., 3);
163  narrowed_fit->SetParameters(scale_factor, value(kAngle) * 1000., value(kSigma) * 1000.);
164  narrowed_fit->Write();
165  } else if (residualsModel() == kPowerLawTails) {
166  narrowed_fit = new TF1(narrowed_name.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, -100., 100., 4);
167  narrowed_fit->SetParameters(scale_factor, value(kAngle) * 1000., value(kSigma) * 1000., value(kGamma) * 1000.);
168  narrowed_fit->Write();
169  } else if (residualsModel() == kROOTVoigt) {
170  narrowed_fit = new TF1(narrowed_name.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, -100., 100., 4);
171  narrowed_fit->SetParameters(scale_factor, value(kAngle) * 1000., value(kSigma) * 1000., value(kGamma) * 1000.);
172  narrowed_fit->Write();
173  } else if (residualsModel() == kGaussPowerTails) {
174  narrowed_fit = new TF1(narrowed_name.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, -100., 100., 3);
175  narrowed_fit->SetParameters(scale_factor, value(kAngle) * 1000., value(kSigma) * 1000.);
176  narrowed_fit->Write();
177  }
178 
179  TF1 *xcontrol_fit = new TF1(xcontrol_name.str().c_str(), "[0]+x*[1]", -1., 1.);
180  xcontrol_fit->SetParameters(value(kAngle) * 1000., value(kXControl) * 1000.);
181  xcontrol_fit->Write();
182 
183  TF1 *ycontrol_fit = new TF1(ycontrol_name.str().c_str(), "[0]+x*[1]", -1., 1.);
184  ycontrol_fit->SetParameters(value(kAngle) * 1000., value(kYControl) * 1000.);
185  ycontrol_fit->Write();
186 
187  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
188  const double raw_residual = (*resiter)[kResidual];
189  const double xangle = (*resiter)[kXAngle];
190  const double yangle = (*resiter)[kYAngle];
191 
192  double xangle_correction = value(kXControl) * xangle;
193  double yangle_correction = value(kYControl) * yangle;
194  double corrected_residual = raw_residual - xangle_correction - yangle_correction;
195 
196  raw_hist->Fill(raw_residual * 1000.);
197  narrowed_hist->Fill(corrected_residual * 1000.);
198 
199  xcontrol_hist->Fill(xangle, (raw_residual - yangle_correction) * 1000.);
200  ycontrol_hist->Fill(yangle, (raw_residual - xangle_correction) * 1000.);
201  }
202 
203  return 0.;
204 }
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
std::vector< double * >::const_iterator residuals_begin() const
double value(int parNum)
std::vector< double * >::const_iterator residuals_end() const
Double_t MuonResidualsFitter_GaussPowerTails_TF1(Double_t *xvec, Double_t *par)
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
Double_t MuonResidualsFitter_ROOTVoigt_TF1(Double_t *xvec, Double_t *par)

◆ sumofweights()

double MuonResidualsAngleFitter::sumofweights ( )
inlineoverridevirtual

Implements MuonResidualsFitter.

Definition at line 36 of file MuonResidualsAngleFitter.h.

References MuonResidualsFitter::numResiduals().

36 { return numResiduals(); }

◆ type()

int MuonResidualsAngleFitter::type ( ) const
inlineoverridevirtual