CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions
MuonResiduals5DOFFitter Class Reference

#include <MuonResiduals5DOFFitter.h>

Inheritance diagram for MuonResiduals5DOFFitter:
MuonResidualsFitter

Public Types

enum  {
  kAlignX = 0, kAlignZ, kAlignPhiX, kAlignPhiY,
  kAlignPhiZ, kResidSigma, kResSlopeSigma, kAlpha,
  kResidGamma, kResSlopeGamma, kNPar
}
 
enum  {
  kResid = 0, kResSlope, kPositionX, kPositionY,
  kAngleX, kAngleY, kRedChi2, kPz,
  kPt, kCharge, kStation, kWheel,
  kSector, kChambW, kChambl, 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

void correctBField () override
 
bool fit (Alignable *ali) override
 
 MuonResiduals5DOFFitter (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
 
TTree * readNtuple (std::string fname, unsigned int wheel, unsigned int station, unsigned int sector, unsigned int preselected=1)
 
double sumofweights () override
 
int type () const override
 
 ~MuonResiduals5DOFFitter () override
 
- Public Member Functions inherited from MuonResidualsFitter
void computeHistogramRangeAndBinning (int which, int &nbins, double &a, double &b)
 
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 15:29:54 CDT 2009

Revision:
1.5
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 18 of file MuonResiduals5DOFFitter.h.

Member Enumeration Documentation

anonymous enum
anonymous enum
Enumerator
kResid 
kResSlope 
kPositionX 
kPositionY 
kAngleX 
kAngleY 
kRedChi2 
kPz 
kPt 
kCharge 
kStation 
kWheel 
kSector 
kChambW 
kChambl 
kNData 

Definition at line 34 of file MuonResiduals5DOFFitter.h.

Constructor & Destructor Documentation

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

Definition at line 53 of file MuonResiduals5DOFFitter.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
MuonResiduals5DOFFitter::~MuonResiduals5DOFFitter ( )
inlineoverride

Definition at line 55 of file MuonResiduals5DOFFitter.h.

55 {}

Member Function Documentation

void MuonResiduals5DOFFitter::correctBField ( )
overridevirtual
bool MuonResiduals5DOFFitter::fit ( Alignable ali)
overridevirtual

Implements MuonResidualsFitter.

Definition at line 176 of file MuonResiduals5DOFFitter.cc.

References MuonResidualsFitter::dofit(), MuonResidualsFitter::fix(), mps_fire::i, MuonResidualsFitter::initialize_table(), MuonResidualsFitter::k0010, MuonResidualsFitter::k1010, MuonResidualsFitter::k1100, MuonResidualsFitter::k1110, MuonResidualsFitter::k1111, kAlignPhiX, kAlignPhiY, kAlignPhiZ, kAlignX, kAlignZ, kAlpha, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian2D, kResidGamma, kResidSigma, kResSlopeGamma, kResSlopeSigma, MuonResidualsFitter::kROOTVoigt, MuonResiduals5DOFFitter_FCN(), mergeVDriftHistosByStation::name, names, pileupDistInMC::num, MuonResidualsFitter::residualsModel(), command_line::start, relval_machine::steps, AlCaHLTBitMon_QueryRunRegistry::string, sumofweights(), and MuonResidualsFitter::useRes().

Referenced by trackingPlots.Iteration::modules().

176  {
177  initialize_table(); // if not already initialized
178  sumofweights();
179 
180  double res_std = 0.5;
181  double resslope_std = 0.005;
182 
183  int nums[10] = {kAlignX,
184  kAlignZ,
185  kAlignPhiX,
186  kAlignPhiY,
187  kAlignPhiZ,
188  kResidSigma,
190  kAlpha,
191  kResidGamma,
193  std::string names[10] = {"AlignX",
194  "AlignZ",
195  "AlignPhiX",
196  "AlignPhiY",
197  "AlignPhiZ",
198  "ResidSigma",
199  "ResSlopeSigma",
200  "Alpha",
201  "ResidGamma",
202  "ResSlopeGamma"};
203  double starts[10] = {0., 0., 0., 0., 0., res_std, resslope_std, 0., 0.1 * res_std, 0.1 * resslope_std};
204  double steps[10] = {
205  0.1, 0.1, 0.001, 0.001, 0.001, 0.001 * res_std, 0.001 * resslope_std, 0.001, 0.01 * res_std, 0.01 * resslope_std};
206  double lows[10] = {0., 0., 0., 0., 0., 0., 0., -1., 0., 0.};
207  double highs[10] = {0., 0., 0., 0., 0., 10., 0.1, 1., 0., 0.};
208 
209  std::vector<int> num(nums, nums + 5);
210  std::vector<std::string> name(names, names + 5);
211  std::vector<double> start(starts, starts + 5);
212  std::vector<double> step(steps, steps + 5);
213  std::vector<double> low(lows, lows + 5);
214  std::vector<double> high(highs, highs + 5);
215 
216  bool add_alpha = (residualsModel() == kPureGaussian2D);
217  bool add_gamma = (residualsModel() == kROOTVoigt || residualsModel() == kPowerLawTails);
218 
219  int idx[4], ni = 0;
220  if (useRes() == k1111 || useRes() == k1110 || useRes() == k1010) {
221  for (ni = 0; ni < 2; ni++)
222  idx[ni] = ni + 5;
223  if (add_alpha)
224  idx[ni++] = 7;
225  else if (add_gamma)
226  for (; ni < 4; ni++)
227  idx[ni] = ni + 6;
228  if (!add_alpha)
229  fix(kAlpha);
230  } else if (useRes() == k1100) {
231  idx[ni++] = 5;
232  if (add_gamma)
233  idx[ni++] = 8;
235  fix(kAlpha);
236  } else if (useRes() == k0010) {
237  idx[ni++] = 6;
238  if (add_gamma)
239  idx[ni++] = 9;
240  fix(kResidSigma);
241  fix(kAlpha);
242  }
243  for (int i = 0; i < ni; i++) {
244  num.push_back(nums[idx[i]]);
245  name.push_back(names[idx[i]]);
246  start.push_back(starts[idx[i]]);
247  step.push_back(steps[idx[i]]);
248  low.push_back(lows[idx[i]]);
249  high.push_back(highs[idx[i]]);
250  }
251 
252  return dofit(&MuonResiduals5DOFFitter_FCN, num, name, start, step, low, high);
253 }
const std::string names[nVars_]
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 MuonResiduals5DOFFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
void fix(int parNum, bool dofix=true)
int useRes(int pattern=-1)
step
Definition: StallMonitor.cc:98
void MuonResiduals5DOFFitter::inform ( TMinuit *  tMinuit)
overrideprotectedvirtual

Implements MuonResidualsFitter.

Definition at line 155 of file MuonResiduals5DOFFitter.cc.

155 { minuit = tMinuit; }
int MuonResiduals5DOFFitter::ndata ( )
inlineoverridevirtual

Implements MuonResidualsFitter.

Definition at line 70 of file MuonResiduals5DOFFitter.h.

References kNData.

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

Implements MuonResidualsFitter.

Definition at line 255 of file MuonResiduals5DOFFitter.cc.

References a, cms::cuda::assert(), b, HLT_FULL_cff::chi2, MuonResidualsFitter::errorerror(), mps_fire::i, kAlignPhiX, kAlignPhiY, kAlignPhiZ, kAlignX, kAlignZ, kAlpha, kAngleX, kAngleY, MuonResidualsFitter::kGaussPowerTails, kPositionX, kPositionY, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsFitter::kPureGaussian2D, kRedChi2, kResid, kResidGamma, kResidSigma, kResSlope, kResSlopeGamma, kResSlopeSigma, MuonResidualsFitter::kROOTVoigt, AlignableSurface::length(), MuonResidualsFitter::m_weightAlignment, TFileDirectory::make(), MuonResidualsFitter_GaussPowerTails_TF1(), MuonResidualsFitter_powerLawTails_TF1(), MuonResidualsFitter_pureGaussian_TF1(), MuonResidualsFitter_ROOTVoigt_TF1(), ndof, npar(), funct::pow(), alignCSCRings::r, MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), AlCaHLTBitMon_QueryRunRegistry::string, sumofweights(), Alignable::surface(), MuonResidualsFitter::value(), histoStyle::weight, and AlignableSurface::width().

255  {
256  sumofweights();
257 
258  double mean_residual = 0., mean_resslope = 0.;
259  double mean_trackx = 0., mean_tracky = 0., mean_trackdxdz = 0., mean_trackdydz = 0.;
260  double sum_w = 0.;
261 
262  for (std::vector<double *>::const_iterator rit = residuals_begin(); rit != residuals_end(); ++rit) {
263  const double redchi2 = (*rit)[kRedChi2];
264  double weight = 1. / redchi2;
265  if (!m_weightAlignment)
266  weight = 1.;
267 
268  if (!m_weightAlignment || TMath::Prob(redchi2 * 6, 6) < 0.99) // no spikes allowed
269  {
270  double factor_w = 1. / (sum_w + weight);
271  mean_residual = factor_w * (sum_w * mean_residual + weight * (*rit)[kResid]);
272  mean_resslope = factor_w * (sum_w * mean_resslope + weight * (*rit)[kResSlope]);
273  mean_trackx = factor_w * (sum_w * mean_trackx + weight * (*rit)[kPositionX]);
274  mean_tracky = factor_w * (sum_w * mean_tracky + weight * (*rit)[kPositionY]);
275  mean_trackdxdz = factor_w * (sum_w * mean_trackdxdz + weight * (*rit)[kAngleX]);
276  mean_trackdydz = factor_w * (sum_w * mean_trackdydz + weight * (*rit)[kAngleY]);
277  sum_w += weight;
278  }
279  }
280 
281  std::string name_residual, name_resslope, name_residual_raw, name_resslope_raw, name_residual_cut, name_alpha;
282  std::string name_residual_trackx, name_resslope_trackx;
283  std::string name_residual_tracky, name_resslope_tracky;
284  std::string name_residual_trackdxdz, name_resslope_trackdxdz;
285  std::string name_residual_trackdydz, name_resslope_trackdydz;
286 
287  name_residual = name + "_residual";
288  name_resslope = name + "_resslope";
289  name_residual_raw = name + "_residual_raw";
290  name_resslope_raw = name + "_resslope_raw";
291  name_residual_cut = name + "_residual_cut";
292  name_alpha = name + "_alpha";
293  name_residual_trackx = name + "_residual_trackx";
294  name_resslope_trackx = name + "_resslope_trackx";
295  name_residual_tracky = name + "_residual_tracky";
296  name_resslope_tracky = name + "_resslope_tracky";
297  name_residual_trackdxdz = name + "_residual_trackdxdz";
298  name_resslope_trackdxdz = name + "_resslope_trackdxdz";
299  name_residual_trackdydz = name + "_residual_trackdydz";
300  name_resslope_trackdydz = name + "_resslope_trackdydz";
301 
302  double width = ali->surface().width();
303  double length = ali->surface().length();
304  int bins_residual = 150, bins_resslope = 100;
305  double min_residual = -75., max_residual = 75.;
306  double min_resslope = -50., max_resslope = 50.;
307  double min_trackx = -width / 2., max_trackx = width / 2.;
308  double min_tracky = -length / 2., max_tracky = length / 2.;
309  double min_trackdxdz = -1.5, max_trackdxdz = 1.5;
310  double min_trackdydz = -1.5, max_trackdydz = 1.5;
311 
312  TH1F *hist_residual = dir->make<TH1F>(name_residual.c_str(), "", bins_residual, min_residual, max_residual);
313  TH1F *hist_resslope = dir->make<TH1F>(name_resslope.c_str(), "", bins_resslope, min_resslope, max_resslope);
314  TH1F *hist_residual_raw = dir->make<TH1F>(name_residual_raw.c_str(), "", bins_residual, min_residual, max_residual);
315  TH1F *hist_resslope_raw = dir->make<TH1F>(name_resslope_raw.c_str(), "", bins_resslope, min_resslope, max_resslope);
316  TH1F *hist_residual_cut = dir->make<TH1F>(name_residual_cut.c_str(), "", bins_residual, min_residual, max_residual);
317  TH2F *hist_alpha = dir->make<TH2F>(name_alpha.c_str(), "", 50, min_resslope, max_resslope, 50, -50., 50.);
318 
319  TProfile *hist_residual_trackx =
320  dir->make<TProfile>(name_residual_trackx.c_str(), "", 50, min_trackx, max_trackx, min_residual, max_residual);
321  TProfile *hist_resslope_trackx =
322  dir->make<TProfile>(name_resslope_trackx.c_str(), "", 50, min_trackx, max_trackx, min_resslope, max_resslope);
323  TProfile *hist_residual_tracky =
324  dir->make<TProfile>(name_residual_tracky.c_str(), "", 50, min_tracky, max_tracky, min_residual, max_residual);
325  TProfile *hist_resslope_tracky =
326  dir->make<TProfile>(name_resslope_tracky.c_str(), "", 50, min_tracky, max_tracky, min_resslope, max_resslope);
327  TProfile *hist_residual_trackdxdz = dir->make<TProfile>(
328  name_residual_trackdxdz.c_str(), "", 250, min_trackdxdz, max_trackdxdz, min_residual, max_residual);
329  TProfile *hist_resslope_trackdxdz = dir->make<TProfile>(
330  name_resslope_trackdxdz.c_str(), "", 250, min_trackdxdz, max_trackdxdz, min_resslope, max_resslope);
331  TProfile *hist_residual_trackdydz = dir->make<TProfile>(
332  name_residual_trackdydz.c_str(), "", 250, min_trackdydz, max_trackdydz, min_residual, max_residual);
333  TProfile *hist_resslope_trackdydz = dir->make<TProfile>(
334  name_resslope_trackdydz.c_str(), "", 250, min_trackdydz, max_trackdydz, min_resslope, max_resslope);
335 
336  hist_residual_trackx->SetAxisRange(-10., 10., "Y");
337  hist_resslope_trackx->SetAxisRange(-10., 10., "Y");
338  hist_residual_tracky->SetAxisRange(-10., 10., "Y");
339  hist_resslope_tracky->SetAxisRange(-10., 10., "Y");
340  hist_residual_trackdxdz->SetAxisRange(-10., 10., "Y");
341  hist_resslope_trackdxdz->SetAxisRange(-10., 10., "Y");
342  hist_residual_trackdydz->SetAxisRange(-10., 10., "Y");
343  hist_resslope_trackdydz->SetAxisRange(-10., 10., "Y");
344 
345  name_residual += "_fit";
346  name_resslope += "_fit";
347  name_alpha += "_fit";
348  name_residual_trackx += "_fit";
349  name_resslope_trackx += "_fit";
350  name_residual_tracky += "_fit";
351  name_resslope_tracky += "_fit";
352  name_residual_trackdxdz += "_fit";
353  name_resslope_trackdxdz += "_fit";
354  name_residual_trackdydz += "_fit";
355  name_resslope_trackdydz += "_fit";
356 
357  TF1 *fit_residual = nullptr;
358  TF1 *fit_resslope = nullptr;
360  fit_residual = new TF1(name_residual.c_str(), MuonResidualsFitter_pureGaussian_TF1, min_residual, max_residual, 3);
361  fit_residual->SetParameters(
362  sum_of_weights * (max_residual - min_residual) / bins_residual, 10. * value(kAlignX), 10. * value(kResidSigma));
363  const double er_res[3] = {0., 10. * errorerror(kAlignX), 10. * errorerror(kResidSigma)};
364  fit_residual->SetParErrors(er_res);
365  fit_resslope = new TF1(name_resslope.c_str(), MuonResidualsFitter_pureGaussian_TF1, min_resslope, max_resslope, 3);
366  fit_resslope->SetParameters(sum_of_weights * (max_resslope - min_resslope) / bins_resslope,
367  1000. * value(kAlignPhiY),
368  1000. * value(kResSlopeSigma));
369  const double er_resslope[3] = {0., 1000. * errorerror(kAlignPhiY), 1000. * errorerror(kResSlopeSigma)};
370  fit_resslope->SetParErrors(er_resslope);
371  } else if (residualsModel() == kPowerLawTails) {
372  fit_residual = new TF1(name_residual.c_str(), MuonResidualsFitter_powerLawTails_TF1, min_residual, max_residual, 4);
373  fit_residual->SetParameters(sum_of_weights * (max_residual - min_residual) / bins_residual,
374  10. * value(kAlignX),
375  10. * value(kResidSigma),
376  10. * value(kResidGamma));
377  fit_resslope = new TF1(name_resslope.c_str(), MuonResidualsFitter_powerLawTails_TF1, min_resslope, max_resslope, 4);
378  fit_resslope->SetParameters(sum_of_weights * (max_resslope - min_resslope) / bins_resslope,
379  1000. * value(kAlignPhiY),
380  1000. * value(kResSlopeSigma),
381  1000. * value(kResSlopeGamma));
382  } else if (residualsModel() == kROOTVoigt) {
383  fit_residual = new TF1(name_residual.c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_residual, max_residual, 4);
384  fit_residual->SetParameters(sum_of_weights * (max_residual - min_residual) / bins_residual,
385  10. * value(kAlignX),
386  10. * value(kResidSigma),
387  10. * value(kResidGamma));
388  fit_resslope = new TF1(name_resslope.c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_resslope, max_resslope, 4);
389  fit_resslope->SetParameters(sum_of_weights * (max_resslope - min_resslope) / bins_resslope,
390  1000. * value(kAlignPhiY),
391  1000. * value(kResSlopeSigma),
392  1000. * value(kResSlopeGamma));
393  } else if (residualsModel() == kGaussPowerTails) {
394  fit_residual =
395  new TF1(name_residual.c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_residual, max_residual, 3);
396  fit_residual->SetParameters(
397  sum_of_weights * (max_residual - min_residual) / bins_residual, 10. * value(kAlignX), 10. * value(kResidSigma));
398  fit_resslope =
399  new TF1(name_resslope.c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_resslope, max_resslope, 3);
400  fit_resslope->SetParameters(sum_of_weights * (max_resslope - min_resslope) / bins_resslope,
401  1000. * value(kAlignPhiY),
402  1000. * value(kResSlopeSigma));
403  } else {
404  assert(false);
405  }
406 
407  fit_residual->SetLineColor(2);
408  fit_residual->SetLineWidth(2);
409  fit_residual->Write();
410  fit_resslope->SetLineColor(2);
411  fit_resslope->SetLineWidth(2);
412  fit_resslope->Write();
413 
414  TF1 *fit_alpha = new TF1(name_alpha.c_str(), "[0] + x*[1]", min_resslope, max_resslope);
415  double a = 10. * value(kAlignX), b = 10. * value(kAlpha) / 1000.;
416  if (residualsModel() == kPureGaussian2D) {
417  double sx = 10. * value(kResidSigma), sy = 1000. * value(kResSlopeSigma), r = value(kAlpha);
418  a = mean_residual;
419  b = 0.;
420  if (sx != 0.) {
421  b = 1. / (sy / sx * r);
422  a = -b * mean_resslope;
423  }
424  }
425  fit_alpha->SetParameters(a, b);
426  fit_alpha->SetLineColor(2);
427  fit_alpha->SetLineWidth(2);
428  fit_alpha->Write();
429 
430  TProfile *fit_residual_trackx = dir->make<TProfile>(name_residual_trackx.c_str(), "", 50, min_trackx, max_trackx);
431  TProfile *fit_resslope_trackx = dir->make<TProfile>(name_resslope_trackx.c_str(), "", 50, min_trackx, max_trackx);
432  TProfile *fit_residual_tracky = dir->make<TProfile>(name_residual_tracky.c_str(), "", 50, min_tracky, max_tracky);
433  TProfile *fit_resslope_tracky = dir->make<TProfile>(name_resslope_tracky.c_str(), "", 50, min_tracky, max_tracky);
434  TProfile *fit_residual_trackdxdz =
435  dir->make<TProfile>(name_residual_trackdxdz.c_str(), "", 250, min_trackdxdz, max_trackdxdz);
436  TProfile *fit_resslope_trackdxdz =
437  dir->make<TProfile>(name_resslope_trackdxdz.c_str(), "", 250, min_trackdxdz, max_trackdxdz);
438  TProfile *fit_residual_trackdydz =
439  dir->make<TProfile>(name_residual_trackdydz.c_str(), "", 250, min_trackdydz, max_trackdydz);
440  TProfile *fit_resslope_trackdydz =
441  dir->make<TProfile>(name_resslope_trackdydz.c_str(), "", 250, min_trackdydz, max_trackdydz);
442 
443  fit_residual_trackx->SetLineColor(2);
444  fit_residual_trackx->SetLineWidth(2);
445  fit_resslope_trackx->SetLineColor(2);
446  fit_resslope_trackx->SetLineWidth(2);
447  fit_residual_tracky->SetLineColor(2);
448  fit_residual_tracky->SetLineWidth(2);
449  fit_resslope_tracky->SetLineColor(2);
450  fit_resslope_tracky->SetLineWidth(2);
451  fit_residual_trackdxdz->SetLineColor(2);
452  fit_residual_trackdxdz->SetLineWidth(2);
453  fit_resslope_trackdxdz->SetLineColor(2);
454  fit_resslope_trackdxdz->SetLineWidth(2);
455  fit_residual_trackdydz->SetLineColor(2);
456  fit_residual_trackdydz->SetLineWidth(2);
457  fit_resslope_trackdydz->SetLineColor(2);
458  fit_resslope_trackdydz->SetLineWidth(2);
459 
460  name_residual_trackx += "line";
461  name_resslope_trackx += "line";
462  name_residual_tracky += "line";
463  name_resslope_tracky += "line";
464  name_residual_trackdxdz += "line";
465  name_resslope_trackdxdz += "line";
466  name_residual_trackdydz += "line";
467  name_resslope_trackdydz += "line";
468 
469  TF1 *fitline_residual_trackx =
470  new TF1(name_residual_trackx.c_str(), residual_x_trackx_TF1, min_trackx, max_trackx, 12);
471  TF1 *fitline_resslope_trackx =
472  new TF1(name_resslope_trackx.c_str(), residual_dxdz_trackx_TF1, min_trackx, max_trackx, 12);
473  TF1 *fitline_residual_tracky =
474  new TF1(name_residual_tracky.c_str(), residual_x_tracky_TF1, min_tracky, max_tracky, 12);
475  TF1 *fitline_resslope_tracky =
476  new TF1(name_resslope_tracky.c_str(), residual_dxdz_tracky_TF1, min_tracky, max_tracky, 12);
477  TF1 *fitline_residual_trackdxdz =
478  new TF1(name_residual_trackdxdz.c_str(), residual_x_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 12);
479  TF1 *fitline_resslope_trackdxdz =
480  new TF1(name_resslope_trackdxdz.c_str(), residual_dxdz_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 12);
481  TF1 *fitline_residual_trackdydz =
482  new TF1(name_residual_trackdydz.c_str(), residual_x_trackdydz_TF1, min_trackdydz, max_trackdydz, 12);
483  TF1 *fitline_resslope_trackdydz =
484  new TF1(name_resslope_trackdydz.c_str(), residual_dxdz_trackdydz_TF1, min_trackdydz, max_trackdydz, 12);
485 
486  std::vector<TF1 *> fitlines;
487  fitlines.push_back(fitline_residual_trackx);
488  fitlines.push_back(fitline_resslope_trackx);
489  fitlines.push_back(fitline_residual_tracky);
490  fitlines.push_back(fitline_resslope_tracky);
491  fitlines.push_back(fitline_residual_trackdxdz);
492  fitlines.push_back(fitline_resslope_trackdxdz);
493  fitlines.push_back(fitline_residual_trackdydz);
494  fitlines.push_back(fitline_resslope_trackdydz);
495 
496  double fitparameters[12] = {value(kAlignX),
497  0.,
498  value(kAlignZ),
499  value(kAlignPhiX),
500  value(kAlignPhiY),
501  value(kAlignPhiZ),
502  mean_trackx,
503  mean_tracky,
504  mean_trackdxdz,
505  mean_trackdydz,
506  value(kAlpha),
507  mean_resslope};
509  fitparameters[10] = 0.;
510 
511  for (std::vector<TF1 *>::const_iterator itr = fitlines.begin(); itr != fitlines.end(); itr++) {
512  (*itr)->SetParameters(fitparameters);
513  (*itr)->SetLineColor(2);
514  (*itr)->SetLineWidth(2);
515  (*itr)->Write();
516  }
517 
518  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
519  const double resid = (*resiter)[kResid];
520  const double resslope = (*resiter)[kResSlope];
521  const double positionX = (*resiter)[kPositionX];
522  const double positionY = (*resiter)[kPositionY];
523  const double angleX = (*resiter)[kAngleX];
524  const double angleY = (*resiter)[kAngleY];
525  const double redchi2 = (*resiter)[kRedChi2];
526  double weight = 1. / redchi2;
527  if (!m_weightAlignment)
528  weight = 1.;
529 
530  if (!m_weightAlignment || TMath::Prob(redchi2 * 8, 8) < 0.99) { // no spikes allowed
531  hist_alpha->Fill(1000. * resslope, 10. * resid);
532 
533  double coeff = value(kAlpha);
535  coeff = 0.;
536  double geom_resid = residual_x(value(kAlignX),
537  value(kAlignZ),
538  value(kAlignPhiX),
539  value(kAlignPhiY),
540  value(kAlignPhiZ),
541  positionX,
542  positionY,
543  angleX,
544  angleY,
545  coeff,
546  resslope);
547  hist_residual->Fill(10. * (resid - geom_resid + value(kAlignX)), weight);
548  hist_residual_trackx->Fill(positionX, 10. * resid, weight);
549  hist_residual_tracky->Fill(positionY, 10. * resid, weight);
550  hist_residual_trackdxdz->Fill(angleX, 10. * resid, weight);
551  hist_residual_trackdydz->Fill(angleY, 10. * resid, weight);
552  fit_residual_trackx->Fill(positionX, 10. * geom_resid, weight);
553  fit_residual_tracky->Fill(positionY, 10. * geom_resid, weight);
554  fit_residual_trackdxdz->Fill(angleX, 10. * geom_resid, weight);
555  fit_residual_trackdydz->Fill(angleY, 10. * geom_resid, weight);
556 
557  double geom_resslope = residual_dxdz(value(kAlignX),
558  value(kAlignZ),
559  value(kAlignPhiX),
560  value(kAlignPhiY),
561  value(kAlignPhiZ),
562  positionX,
563  positionY,
564  angleX,
565  angleY);
566  hist_resslope->Fill(1000. * (resslope - geom_resslope + value(kAlignPhiY)), weight);
567  hist_resslope_trackx->Fill(positionX, 1000. * resslope, weight);
568  hist_resslope_tracky->Fill(positionY, 1000. * resslope, weight);
569  hist_resslope_trackdxdz->Fill(angleX, 1000. * resslope, weight);
570  hist_resslope_trackdydz->Fill(angleY, 1000. * resslope, weight);
571  fit_resslope_trackx->Fill(positionX, 1000. * geom_resslope, weight);
572  fit_resslope_tracky->Fill(positionY, 1000. * geom_resslope, weight);
573  fit_resslope_trackdxdz->Fill(angleX, 1000. * geom_resslope, weight);
574  fit_resslope_trackdydz->Fill(angleY, 1000. * geom_resslope, weight);
575  }
576 
577  hist_residual_raw->Fill(10. * resid);
578  hist_resslope_raw->Fill(1000. * resslope);
579  if (fabs(resslope) < 0.005)
580  hist_residual_cut->Fill(10. * resid);
581  }
582 
583  double chi2 = 0.;
584  double ndof = 0.;
585  for (int i = 1; i <= hist_residual->GetNbinsX(); i++) {
586  double xi = hist_residual->GetBinCenter(i);
587  double yi = hist_residual->GetBinContent(i);
588  double yerri = hist_residual->GetBinError(i);
589  double yth = fit_residual->Eval(xi);
590  if (yerri > 0.) {
591  chi2 += pow((yth - yi) / yerri, 2);
592  ndof += 1.;
593  }
594  }
595  for (int i = 1; i <= hist_resslope->GetNbinsX(); i++) {
596  double xi = hist_resslope->GetBinCenter(i);
597  double yi = hist_resslope->GetBinContent(i);
598  double yerri = hist_resslope->GetBinError(i);
599  double yth = fit_resslope->Eval(xi);
600  if (yerri > 0.) {
601  chi2 += pow((yth - yi) / yerri, 2);
602  ndof += 1.;
603  }
604  }
605  ndof -= npar();
606 
607  return (ndof > 0. ? chi2 / ndof : -1.);
608 }
align::Scalar width() const
std::vector< double * >::const_iterator residuals_begin() const
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
double value(int parNum)
assert(be >=bs)
Double_t MuonResidualsFitter_GaussPowerTails_TF1(Double_t *xvec, Double_t *par)
T * make(const Args &...args) const
make new ROOT object
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:132
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
align::Scalar length() const
double errorerror(int parNum)
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
std::vector< double * >::const_iterator residuals_end() const
int weight
Definition: histoStyle.py:51
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
TTree * MuonResiduals5DOFFitter::readNtuple ( std::string  fname,
unsigned int  wheel,
unsigned int  station,
unsigned int  sector,
unsigned int  preselected = 1 
)

Definition at line 610 of file MuonResiduals5DOFFitter.cc.

References MuonResidualsFitter::MuonAlignmentTreeRow::angle_x, MuonResidualsFitter::MuonAlignmentTreeRow::angle_y, cms::cuda::assert(), validate-o2o-wbm::f, MuonResidualsFitter::fill(), mps_fire::i, kAngleX, kAngleY, kCharge, kNData, kPositionX, kPositionY, kPt, kPz, kRedChi2, kResid, kResSlope, MuonResidualsFitter::MuonAlignmentTreeRow::pos_x, MuonResidualsFitter::MuonAlignmentTreeRow::pos_y, MuonResidualsFitter::MuonAlignmentTreeRow::pt, MuonResidualsFitter::MuonAlignmentTreeRow::pz, MuonResidualsFitter::MuonAlignmentTreeRow::q, alignCSCRings::r, MuonResidualsFitter::MuonAlignmentTreeRow::res_slope_x, MuonResidualsFitter::MuonAlignmentTreeRow::res_x, submitPVValidationJobs::t, and groupFilesInBlocks::tt.

611  {
612  TFile *f = new TFile(fname.c_str());
613  TTree *t = (TTree *)f->Get("mual_ttree");
614 
615  // Create new temporary file
616  TFile *tmpf = new TFile("small_tree_fit.root", "recreate");
617  assert(tmpf != nullptr);
618 
619  // filter the tree (temporarily lives in the new file)
620  TTree *tt = t->CopyTree(Form(
621  "is_dt && ring_wheel==%d && station==%d && sector==%d && select==%d", wheel, station, sector, (bool)preselected));
622 
623  MuonAlignmentTreeRow r;
624  tt->SetBranchAddress("res_x", &r.res_x);
625  tt->SetBranchAddress("res_slope_x", &r.res_slope_x);
626  tt->SetBranchAddress("pos_x", &r.pos_x);
627  tt->SetBranchAddress("pos_y", &r.pos_y);
628  tt->SetBranchAddress("angle_x", &r.angle_x);
629  tt->SetBranchAddress("angle_y", &r.angle_y);
630  tt->SetBranchAddress("pz", &r.pz);
631  tt->SetBranchAddress("pt", &r.pt);
632  tt->SetBranchAddress("q", &r.q);
633 
634  Long64_t nentries = tt->GetEntries();
635  for (Long64_t i = 0; i < nentries; i++) {
636  tt->GetEntry(i);
637  double *rdata = new double[MuonResiduals5DOFFitter::kNData];
638  rdata[kResid] = r.res_x;
639  rdata[kResSlope] = r.res_slope_x;
640  rdata[kPositionX] = r.pos_x;
641  rdata[kPositionY] = r.pos_y;
642  rdata[kAngleX] = r.angle_x;
643  rdata[kAngleY] = r.angle_y;
644  rdata[kRedChi2] = 0.1;
645  rdata[kPz] = r.pz;
646  rdata[kPt] = r.pt;
647  rdata[kCharge] = r.q;
648  fill(rdata);
649  }
650  delete f;
651  //delete tmpf;
652  return tt;
653 }
void fill(double *residual)
assert(be >=bs)
string fname
main script
double MuonResiduals5DOFFitter::sumofweights ( )
overridevirtual

Implements MuonResidualsFitter.

Definition at line 157 of file MuonResiduals5DOFFitter.cc.

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

Referenced by fit(), and plot().

157  {
158  sum_of_weights = 0.;
159  number_of_hits = 0.;
160  weight_alignment = m_weightAlignment;
161  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
162  if (m_weightAlignment) {
163  double redchi2 = (*resiter)[MuonResiduals5DOFFitter::kRedChi2];
164  if (TMath::Prob(redchi2 * 8, 8) < 0.99) {
165  sum_of_weights += 1. / redchi2;
166  number_of_hits += 1.;
167  }
168  } else {
169  sum_of_weights += 1.;
170  number_of_hits += 1.;
171  }
172  }
173  return sum_of_weights;
174 }
std::vector< double * >::const_iterator residuals_begin() const
std::vector< double * >::const_iterator residuals_end() const
int MuonResiduals5DOFFitter::type ( ) const
inlineoverridevirtual