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
MuonResiduals6DOFFitter Class Reference

#include <MuonResiduals6DOFFitter.h>

Inheritance diagram for MuonResiduals6DOFFitter:
MuonResidualsFitter

Public Types

enum  {
  kAlignX = 0, kAlignY, kAlignZ, kAlignPhiX,
  kAlignPhiY, kAlignPhiZ, kResidXSigma, kResidYSigma,
  kResSlopeXSigma, kResSlopeYSigma, kAlphaX, kAlphaY,
  kResidXGamma, kResidYGamma, kResSlopeXGamma, kResSlopeYGamma,
  kNPar
}
 
enum  {
  kResidX = 0, kResidY, kResSlopeX, kResSlopeY,
  kPositionX, kPositionY, kAngleX, kAngleY,
  kRedChi2, kPz, kPt, kCharge,
  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
}
 

Public Member Functions

void correctBField ()
 
bool fit (Alignable *ali)
 
 MuonResiduals6DOFFitter (int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)
 
int ndata ()
 
int npar ()
 
double plot (std::string name, TFileDirectory *dir, Alignable *ali)
 
TTree * readNtuple (std::string fname, unsigned int wheel, unsigned int station, unsigned int sector, unsigned int preselected=1)
 
double sumofweights ()
 
int type () const
 
virtual ~MuonResiduals6DOFFitter ()
 
- 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 fill (double *residual)
 
void fix (int parNum, bool val=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 setPrintLevel (int printLevel)
 
void setStrategy (int strategy)
 
int useRes () const
 
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, 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: Thu Apr 16 14:20:58 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 MuonResiduals6DOFFitter.h.

Member Enumeration Documentation

anonymous enum
Enumerator
kAlignX 
kAlignY 
kAlignZ 
kAlignPhiX 
kAlignPhiY 
kAlignPhiZ 
kResidXSigma 
kResidYSigma 
kResSlopeXSigma 
kResSlopeYSigma 
kAlphaX 
kAlphaY 
kResidXGamma 
kResidYGamma 
kResSlopeXGamma 
kResSlopeYGamma 
kNPar 

Definition at line 21 of file MuonResiduals6DOFFitter.h.

21  {
22  kAlignX = 0,
23  kAlignY,
24  kAlignZ,
25  kAlignPhiX,
26  kAlignPhiY,
27  kAlignPhiZ,
32  kAlphaX,
33  kAlphaY,
38  kNPar
39  };
anonymous enum

Constructor & Destructor Documentation

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

Definition at line 57 of file MuonResiduals6DOFFitter.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
virtual MuonResiduals6DOFFitter::~MuonResiduals6DOFFitter ( )
inlinevirtual

Definition at line 58 of file MuonResiduals6DOFFitter.h.

58 {}

Member Function Documentation

void MuonResiduals6DOFFitter::correctBField ( )
virtual
bool MuonResiduals6DOFFitter::fit ( Alignable ali)
virtual

Implements MuonResidualsFitter.

Definition at line 253 of file MuonResiduals6DOFFitter.cc.

References MuonResidualsFitter::dofit(), MuonResidualsFitter::fix(), i, customizeTrackingMonitorSeedNumber::idx, MuonResidualsFitter::initialize_table(), MuonResidualsFitter::k0010, MuonResidualsFitter::k1010, MuonResidualsFitter::k1100, MuonResidualsFitter::k1110, MuonResidualsFitter::k1111, kAlignPhiX, kAlignPhiY, kAlignPhiZ, kAlignX, kAlignY, kAlignZ, kAlphaX, kAlphaY, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian2D, kResidXGamma, kResidXSigma, kResidYGamma, kResidYSigma, kResSlopeXGamma, kResSlopeXSigma, kResSlopeYGamma, kResSlopeYSigma, MuonResidualsFitter::kROOTVoigt, MuonResiduals6DOFFitter_FCN(), mergeVDriftHistosByStation::name, cscdqm::h::names, pileupDistInMC::num, MuonResidualsFitter::residualsModel(), dqm_diff::start, relval_parameters_module::step, relval_machine::steps, AlCaHLTBitMon_QueryRunRegistry::string, sumofweights(), and MuonResidualsFitter::useRes().

254 {
255  initialize_table(); // if not already initialized
256  sumofweights();
257 
258  double resx_std = 0.5;
259  double resy_std = 3.0;
260  double resslopex_std = 0.002;
261  double resslopey_std = 0.005;
262 
265  std::string names[16] = {"AlignX","AlignY","AlignZ","AlignPhiX","AlignPhiY","AlignPhiZ", "ResidXSigma","ResidYSigma","ResSlopeXSigma","ResSlopeYSigma",
266  "AlphaX","AlphaY", "ResidXGamma","ResidYGamma","ResSlopeXGamma","ResSlopeYGamma"};
267  double starts[16] = {0., 0., 0., 0., 0., 0., resx_std, resy_std, resslopex_std, resslopey_std,
268  0., 0., 0.1*resx_std, 0.1*resy_std, 0.1*resslopex_std, 0.1*resslopey_std};
269  double steps[16] = {0.1, 0.1, 0.1, 0.001, 0.001, 0.001, 0.001*resx_std, 0.001*resy_std, 0.001*resslopex_std, 0.001*resslopey_std,
270  0.001, 0.001, 0.01*resx_std, 0.01*resy_std, 0.01*resslopex_std, 0.01*resslopey_std};
271  double lows[16] = {0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
272  -1., -1., 0., 0., 0., 0.};
273  double highs[16] = {0., 0., 0., 0., 0., 0., 10., 10., 0.1, 0.1,
274  1.,1., 0., 0., 0., 0.};
275 
276  std::vector<int> num(nums, nums+6);
277  std::vector<std::string> name(names, names+6);
278  std::vector<double> start(starts, starts+6);
279  std::vector<double> step(steps, steps+6);
280  std::vector<double> low(lows, lows+6);
281  std::vector<double> high(highs, highs+6);
282 
283  bool add_alpha = ( residualsModel() == kPureGaussian2D );
284  bool add_gamma = ( residualsModel() == kROOTVoigt || residualsModel() == kPowerLawTails );
285 
286  int idx[8], ni = 0;
287  if (useRes() == k1111) {
288  for(ni=0; ni<4; ni++) idx[ni] = ni+6;
289  if (add_alpha) for(; ni<6; ni++) idx[ni] = ni+6;
290  else if (add_gamma) for(; ni<8; ni++) idx[ni] = ni+8;
291  if (!add_alpha) fix(kAlphaX);
292  if (!add_alpha) fix(kAlphaY);
293  }
294  else if (useRes() == k1110) {
295  for(ni=0; ni<3; ni++) idx[ni] = ni+6;
296  if (add_alpha) idx[ni++] = 10;
297  else if (add_gamma) for(; ni<6; ni++) idx[ni] = ni+9;
299  fix(kAlphaY);
300  if (!add_alpha) fix(kAlphaX);
301  }
302  else if (useRes() == k1100) {
303  for(ni=0; ni<2; ni++) idx[ni] = ni+6;
304  if (add_gamma) for(; ni<4; ni++) idx[ni] = ni+10;
307  fix(kAlphaX);
308  fix(kAlphaY);
309  }
310  else if (useRes() == k1010) {
311  idx[ni++] = 6; idx[ni++] = 8;
312  if (add_alpha) idx[ni++] = 10;
313  if (add_gamma) { idx[ni++] = 12; idx[ni++] = 14; }
314  fix(kResidYSigma);
316  fix(kAlphaY);
317  if (!add_alpha) fix(kAlphaX);
318  }
319  else if (useRes() == k0010) {
320  idx[ni++] = 8;
321  if (add_gamma) idx[ni++] = 14;
322  fix(kResidXSigma);
323  fix(kResidYSigma);
325  fix(kAlphaX);
326  fix(kAlphaY);
327  }
328  for (int i=0; i<ni; i++){
329  num.push_back(nums[idx[i]]);
330  name.push_back(names[idx[i]]);
331  start.push_back(starts[idx[i]]);
332  step.push_back(steps[idx[i]]);
333  low.push_back(lows[idx[i]]);
334  high.push_back(highs[idx[i]]);
335  }
336 
337  return dofit(&MuonResiduals6DOFFitter_FCN, num, name, start, step, low, high);
338 }
int i
Definition: DBlmapReader.cc:9
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
void fix(int parNum, bool val=true)
static const HistoName names[]
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)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
void MuonResiduals6DOFFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
void MuonResiduals6DOFFitter::inform ( TMinuit *  tMinuit)
protectedvirtual

Implements MuonResidualsFitter.

Definition at line 219 of file MuonResiduals6DOFFitter.cc.

220 {
221  minuit = tMinuit;
222 }
int MuonResiduals6DOFFitter::ndata ( )
inlinevirtual

Implements MuonResidualsFitter.

Definition at line 68 of file MuonResiduals6DOFFitter.h.

References kNData.

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

Implements MuonResidualsFitter.

Definition at line 341 of file MuonResiduals6DOFFitter.cc.

References MuonResidualsFitter::errorerror(), i, kAlignPhiX, kAlignPhiY, kAlignPhiZ, kAlignX, kAlignY, kAlignZ, kAlphaX, kAlphaY, kAngleX, kAngleY, MuonResidualsFitter::kGaussPowerTails, kPositionX, kPositionY, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, MuonResidualsFitter::kPureGaussian2D, kRedChi2, kResidX, kResidXGamma, kResidXSigma, kResidY, kResidYGamma, kResidYSigma, kResSlopeX, kResSlopeXGamma, kResSlopeXSigma, kResSlopeY, kResSlopeYGamma, kResSlopeYSigma, MuonResidualsFitter::kROOTVoigt, AlignableSurface::length(), MuonResidualsFitter::m_weightAlignment, TFileDirectory::make(), MuonResidualsFitter_GaussPowerTails_TF1(), MuonResidualsFitter_powerLawTails_TF1(), MuonResidualsFitter_pureGaussian_TF1(), MuonResidualsFitter_ROOTVoigt_TF1(), npar(), NULL, funct::pow(), alignCSCRings::r, MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), AlCaHLTBitMon_QueryRunRegistry::string, sumofweights(), Alignable::surface(), MuonResidualsFitter::value(), histoStyle::weight, AlignableSurface::width(), and create_public_lumi_plots::width.

Referenced by cuy.FindIssue::__init__().

342 {
343  sumofweights();
344 
345  double mean_residualx = 0., mean_residualy = 0., mean_resslopex = 0., mean_resslopey = 0.;
346  double mean_trackx = 0., mean_tracky = 0., mean_trackdxdz = 0., mean_trackdydz = 0.;
347  double sum_w = 0.;
348 
349  for (std::vector<double*>::const_iterator rit = residuals_begin(); rit != residuals_end(); ++rit)
350  {
351  const double redchi2 = (*rit)[kRedChi2];
352  double weight = 1./redchi2;
353  if (!m_weightAlignment) weight = 1.;
354 
355  if (!m_weightAlignment || TMath::Prob(redchi2*12, 12) < 0.99) // no spikes allowed
356  {
357  double factor_w = 1./(sum_w + weight);
358  mean_residualx = factor_w * (sum_w * mean_residualx + weight * (*rit)[kResidX]);
359  mean_residualy = factor_w * (sum_w * mean_residualy + weight * (*rit)[kResidY]);
360  mean_resslopex = factor_w * (sum_w * mean_resslopex + weight * (*rit)[kResSlopeX]);
361  mean_resslopey = factor_w * (sum_w * mean_resslopey + weight * (*rit)[kResSlopeY]);
362  mean_trackx = factor_w * (sum_w * mean_trackx + weight * (*rit)[kPositionX]);
363  mean_tracky = factor_w * (sum_w * mean_tracky + weight * (*rit)[kPositionY]);
364  mean_trackdxdz = factor_w * (sum_w * mean_trackdxdz + weight * (*rit)[kAngleX]);
365  mean_trackdydz = factor_w * (sum_w * mean_trackdydz + weight * (*rit)[kAngleY]);
366  sum_w += weight;
367  }
368  }
369 
370  std::string name_x, name_y, name_dxdz, name_dydz, name_x_raw, name_y_raw, name_dxdz_raw, name_dydz_raw, name_x_cut, name_y_cut, name_alphax, name_alphay;
371  std::string name_x_trackx, name_y_trackx, name_dxdz_trackx, name_dydz_trackx;
372  std::string name_x_tracky, name_y_tracky, name_dxdz_tracky, name_dydz_tracky;
373  std::string name_x_trackdxdz, name_y_trackdxdz, name_dxdz_trackdxdz, name_dydz_trackdxdz;
374  std::string name_x_trackdydz, name_y_trackdydz, name_dxdz_trackdydz, name_dydz_trackdydz;
375 
376  name_x = name + "_x";
377  name_y = name + "_y";
378  name_dxdz = name + "_dxdz";
379  name_dydz = name + "_dydz";
380  name_x_raw = name + "_x_raw";
381  name_y_raw = name + "_y_raw";
382  name_dxdz_raw = name + "_dxdz_raw";
383  name_dydz_raw = name + "_dydz_raw";
384  name_x_cut = name + "_x_cut";
385  name_y_cut = name + "_y_cut";
386  name_alphax = name + "_alphax";
387  name_alphay = name + "_alphay";
388  name_x_trackx = name + "_x_trackx";
389  name_y_trackx = name + "_y_trackx";
390  name_dxdz_trackx = name + "_dxdz_trackx";
391  name_dydz_trackx = name + "_dydz_trackx";
392  name_x_tracky = name + "_x_tracky";
393  name_y_tracky = name + "_y_tracky";
394  name_dxdz_tracky = name + "_dxdz_tracky";
395  name_dydz_tracky = name + "_dydz_tracky";
396  name_x_trackdxdz = name + "_x_trackdxdz";
397  name_y_trackdxdz = name + "_y_trackdxdz";
398  name_dxdz_trackdxdz = name + "_dxdz_trackdxdz";
399  name_dydz_trackdxdz = name + "_dydz_trackdxdz";
400  name_x_trackdydz = name + "_x_trackdydz";
401  name_y_trackdydz = name + "_y_trackdydz";
402  name_dxdz_trackdydz = name + "_dxdz_trackdydz";
403  name_dydz_trackdydz = name + "_dydz_trackdydz";
404 
405  double width = ali->surface().width();
406  double length = ali->surface().length();
407  int bins = 200;
408  double min_x = -100., max_x = 100.;
409  double min_y = -100., max_y = 100.;
410  double min_dxdz = -75., max_dxdz = 75.;
411  double min_dydz = -150., max_dydz = 150.;
412  double min_trackx = -width/2., max_trackx = width/2.;
413  double min_tracky = -length/2., max_tracky = length/2.;
414  double min_trackdxdz = -1.5, max_trackdxdz = 1.5;
415  double min_trackdydz = -1.5, max_trackdydz = 1.5;
416 
417  TH1F *hist_x = dir->make<TH1F>(name_x.c_str(), "", bins, min_x, max_x);
418  TH1F *hist_y = dir->make<TH1F>(name_y.c_str(), "", bins, min_y, max_y);
419  TH1F *hist_dxdz = dir->make<TH1F>(name_dxdz.c_str(), "", bins, min_dxdz, max_dxdz);
420  TH1F *hist_dydz = dir->make<TH1F>(name_dydz.c_str(), "", bins, min_dydz, max_dydz);
421  TH1F *hist_x_raw = dir->make<TH1F>(name_x_raw.c_str(), "", bins, min_x, max_x);
422  TH1F *hist_y_raw = dir->make<TH1F>(name_y_raw.c_str(), "", bins, min_y, max_y);
423  TH1F *hist_dxdz_raw = dir->make<TH1F>(name_dxdz_raw.c_str(), "", bins, min_dxdz, max_dxdz);
424  TH1F *hist_dydz_raw = dir->make<TH1F>(name_dydz_raw.c_str(), "", bins, min_dydz, max_dydz);
425  TH1F *hist_x_cut = dir->make<TH1F>(name_x_cut.c_str(), "", bins, min_x, max_x);
426  TH1F *hist_y_cut = dir->make<TH1F>(name_y_cut.c_str(), "", bins, min_y, max_y);
427  TH2F *hist_alphax = dir->make<TH2F>(name_alphax.c_str(), "", 50, 50, 50, 50, -50., 50.);
428  TH2F *hist_alphay = dir->make<TH2F>(name_alphay.c_str(), "", 75, 100, 100, 75, -75., 75.);
429 
430  TProfile *hist_x_trackx = dir->make<TProfile>(name_x_trackx.c_str(), "", 50, min_trackx, max_trackx, min_x, max_x);
431  TProfile *hist_y_trackx = dir->make<TProfile>(name_y_trackx.c_str(), "", 50, min_trackx, max_trackx, min_y, max_y);
432  TProfile *hist_dxdz_trackx = dir->make<TProfile>(name_dxdz_trackx.c_str(), "", 50, min_trackx, max_trackx, min_dxdz, max_dxdz);
433  TProfile *hist_dydz_trackx = dir->make<TProfile>(name_dydz_trackx.c_str(), "", 50, min_trackx, max_trackx, min_dydz, max_dydz);
434  TProfile *hist_x_tracky = dir->make<TProfile>(name_x_tracky.c_str(), "", 50, min_tracky, max_tracky, min_x, max_x);
435  TProfile *hist_y_tracky = dir->make<TProfile>(name_y_tracky.c_str(), "", 50, min_tracky, max_tracky, min_y, max_y);
436  TProfile *hist_dxdz_tracky = dir->make<TProfile>(name_dxdz_tracky.c_str(), "", 50, min_tracky, max_tracky, min_dxdz, max_dxdz);
437  TProfile *hist_dydz_tracky = dir->make<TProfile>(name_dydz_tracky.c_str(), "", 50, min_tracky, max_tracky, min_dydz, max_dydz);
438  TProfile *hist_x_trackdxdz = dir->make<TProfile>(name_x_trackdxdz.c_str(), "", 250, min_trackdxdz, max_trackdxdz, min_x, max_x);
439  TProfile *hist_y_trackdxdz = dir->make<TProfile>(name_y_trackdxdz.c_str(), "", 250, min_trackdxdz, max_trackdxdz, min_y, max_y);
440  TProfile *hist_dxdz_trackdxdz = dir->make<TProfile>(name_dxdz_trackdxdz.c_str(), "", 250, min_trackdxdz, max_trackdxdz, min_dxdz, max_dxdz);
441  TProfile *hist_dydz_trackdxdz = dir->make<TProfile>(name_dydz_trackdxdz.c_str(), "", 250, min_trackdxdz, max_trackdxdz, min_dydz, max_dydz);
442  TProfile *hist_x_trackdydz = dir->make<TProfile>(name_x_trackdydz.c_str(), "", 250, min_trackdydz, max_trackdydz, min_x, max_x);
443  TProfile *hist_y_trackdydz = dir->make<TProfile>(name_y_trackdydz.c_str(), "", 250, min_trackdydz, max_trackdydz, min_y, max_y);
444  TProfile *hist_dxdz_trackdydz = dir->make<TProfile>(name_dxdz_trackdydz.c_str(), "", 250, min_trackdydz, max_trackdydz, min_dxdz, max_dxdz);
445  TProfile *hist_dydz_trackdydz = dir->make<TProfile>(name_dydz_trackdydz.c_str(), "", 250, min_trackdydz, max_trackdydz, min_dydz, max_dydz);
446 
447  hist_x_trackx->SetAxisRange(-10., 10., "Y");
448  hist_y_trackx->SetAxisRange(-20., 20., "Y");
449  hist_dxdz_trackx->SetAxisRange(-10., 10., "Y");
450  hist_dydz_trackx->SetAxisRange(-20., 20., "Y");
451  hist_x_tracky->SetAxisRange(-10., 10., "Y");
452  hist_y_tracky->SetAxisRange(-20., 20., "Y");
453  hist_dxdz_tracky->SetAxisRange(-10., 10., "Y");
454  hist_dydz_tracky->SetAxisRange(-20., 20., "Y");
455  hist_x_trackdxdz->SetAxisRange(-10., 10., "Y");
456  hist_y_trackdxdz->SetAxisRange(-20., 20., "Y");
457  hist_dxdz_trackdxdz->SetAxisRange(-10., 10., "Y");
458  hist_dydz_trackdxdz->SetAxisRange(-20., 20., "Y");
459  hist_x_trackdydz->SetAxisRange(-10., 10., "Y");
460  hist_y_trackdydz->SetAxisRange(-20., 20., "Y");
461  hist_dxdz_trackdydz->SetAxisRange(-10., 10., "Y");
462  hist_dydz_trackdydz->SetAxisRange(-20., 20., "Y");
463 
464  name_x += "_fit";
465  name_y += "_fit";
466  name_dxdz += "_fit";
467  name_dydz += "_fit";
468  name_alphax += "_fit";
469  name_alphay += "_fit";
470  name_x_trackx += "_fit";
471  name_y_trackx += "_fit";
472  name_dxdz_trackx += "_fit";
473  name_dydz_trackx += "_fit";
474  name_x_tracky += "_fit";
475  name_y_tracky += "_fit";
476  name_dxdz_tracky += "_fit";
477  name_dydz_tracky += "_fit";
478  name_x_trackdxdz += "_fit";
479  name_y_trackdxdz += "_fit";
480  name_dxdz_trackdxdz += "_fit";
481  name_dydz_trackdxdz += "_fit";
482  name_x_trackdydz += "_fit";
483  name_y_trackdydz += "_fit";
484  name_dxdz_trackdydz += "_fit";
485  name_dydz_trackdydz += "_fit";
486 
487  TF1 *fit_x = NULL;
488  TF1 *fit_y = NULL;
489  TF1 *fit_dxdz = NULL;
490  TF1 *fit_dydz = NULL;
492  fit_x = new TF1(name_x.c_str(), MuonResidualsFitter_pureGaussian_TF1, min_x, max_x, 3);
493  fit_x->SetParameters(sum_of_weights * (max_x - min_x)/bins, 10.*value(kAlignX), 10.*value(kResidXSigma));
494  const double er_x[3] = {0., 10.*errorerror(kAlignX), 10.*errorerror(kResidXSigma)};
495  fit_x->SetParErrors(er_x);
496  fit_y = new TF1(name_y.c_str(), MuonResidualsFitter_pureGaussian_TF1, min_y, max_y, 3);
497  fit_y->SetParameters(sum_of_weights * (max_y - min_y)/bins, 10.*value(kAlignY), 10.*value(kResidYSigma));
498  const double er_y[3] = {0., 10.*errorerror(kAlignY), 10.*errorerror(kResidYSigma)};
499  fit_y->SetParErrors(er_y);
500  fit_dxdz = new TF1(name_dxdz.c_str(), MuonResidualsFitter_pureGaussian_TF1, min_dxdz, max_dxdz, 3);
501  fit_dxdz->SetParameters(sum_of_weights * (max_dxdz - min_dxdz)/bins, 1000.*value(kAlignPhiY), 1000.*value(kResSlopeXSigma));
502  const double er_dxdz[3] = {0., 1000.*errorerror(kAlignPhiY), 1000.*errorerror(kResSlopeXSigma)};
503  fit_dxdz->SetParErrors(er_dxdz);
504  fit_dydz = new TF1(name_dydz.c_str(), MuonResidualsFitter_pureGaussian_TF1, min_dydz, max_dydz, 3);
505  fit_dydz->SetParameters(sum_of_weights * (max_dydz - min_dydz)/bins, -1000.*value(kAlignPhiX), 1000.*value(kResSlopeYSigma));
506  const double er_dydz[3] = {0., 1000.*errorerror(kAlignPhiX), 1000.*errorerror(kResSlopeYSigma)};
507  fit_dydz->SetParErrors(er_dydz);
508  }
509  else if (residualsModel() == kPowerLawTails) {
510  fit_x = new TF1(name_x.c_str(), MuonResidualsFitter_powerLawTails_TF1, min_x, max_x, 4);
511  fit_x->SetParameters(sum_of_weights * (max_x - min_x)/bins, 10.*value(kAlignX), 10.*value(kResidXSigma), 10.*value(kResidXGamma));
512  fit_y = new TF1(name_y.c_str(), MuonResidualsFitter_powerLawTails_TF1, min_y, max_y, 4);
513  fit_y->SetParameters(sum_of_weights * (max_y - min_y)/bins, 10.*value(kAlignY), 10.*value(kResidYSigma), 10.*value(kResidYGamma));
514  fit_dxdz = new TF1(name_dxdz.c_str(), MuonResidualsFitter_powerLawTails_TF1, min_dxdz, max_dxdz, 4);
515  fit_dxdz->SetParameters(sum_of_weights * (max_dxdz - min_dxdz)/bins, 1000.*value(kAlignPhiY), 1000.*value(kResSlopeXSigma), 1000.*value(kResSlopeXGamma));
516  fit_dydz = new TF1(name_dydz.c_str(), MuonResidualsFitter_powerLawTails_TF1, min_dydz, max_dydz, 4);
517  fit_dydz->SetParameters(sum_of_weights * (max_dydz - min_dydz)/bins, -1000.*value(kAlignPhiX), 1000.*value(kResSlopeYSigma), 1000.*value(kResSlopeYGamma));
518  }
519  else if (residualsModel() == kROOTVoigt) {
520  fit_x = new TF1(name_x.c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_x, max_x, 4);
521  fit_x->SetParameters(sum_of_weights * (max_x - min_x)/bins, 10.*value(kAlignX), 10.*value(kResidXSigma), 10.*value(kResidXGamma));
522  fit_y = new TF1(name_y.c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_y, max_y, 4);
523  fit_y->SetParameters(sum_of_weights * (max_y - min_y)/bins, 10.*value(kAlignY), 10.*value(kResidYSigma), 10.*value(kResidYGamma));
524  fit_dxdz = new TF1(name_dxdz.c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_dxdz, max_dxdz, 4);
525  fit_dxdz->SetParameters(sum_of_weights * (max_dxdz - min_dxdz)/bins, 1000.*value(kAlignPhiY), 1000.*value(kResSlopeXSigma), 1000.*value(kResSlopeXGamma));
526  fit_dydz = new TF1(name_dydz.c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_dydz, max_dydz, 4);
527  fit_dydz->SetParameters(sum_of_weights * (max_dydz - min_dydz)/bins, -1000.*value(kAlignPhiX), 1000.*value(kResSlopeYSigma), 1000.*value(kResSlopeYGamma));
528  }
529  else if (residualsModel() == kGaussPowerTails) {
530  fit_x = new TF1(name_x.c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_x, max_x, 3);
531  fit_x->SetParameters(sum_of_weights * (max_x - min_x)/bins, 10.*value(kAlignX), 10.*value(kResidXSigma));
532  fit_y = new TF1(name_y.c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_y, max_y, 3);
533  fit_y->SetParameters(sum_of_weights * (max_y - min_y)/bins, 10.*value(kAlignY), 10.*value(kResidYSigma));
534  fit_dxdz = new TF1(name_dxdz.c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_dxdz, max_dxdz, 3);
535  fit_dxdz->SetParameters(sum_of_weights * (max_dxdz - min_dxdz)/bins, 1000.*value(kAlignPhiY), 1000.*value(kResSlopeXSigma));
536  fit_dydz = new TF1(name_dydz.c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_dydz, max_dydz, 3);
537  fit_dydz->SetParameters(sum_of_weights * (max_dydz - min_dydz)/bins, -1000.*value(kAlignPhiX), 1000.*value(kResSlopeYSigma));
538  }
539  else { assert(false); }
540 
541  fit_x->SetLineColor(2); fit_x->SetLineWidth(2); fit_x->Write();
542  fit_y->SetLineColor(2); fit_y->SetLineWidth(2); fit_y->Write();
543  fit_dxdz->SetLineColor(2); fit_dxdz->SetLineWidth(2); fit_dxdz->Write();
544  fit_dydz->SetLineColor(2); fit_dydz->SetLineWidth(2); fit_dydz->Write();
545 
546  TF1 *fit_alphax = new TF1(name_alphax.c_str(), "[0] + x*[1]", min_dxdz, max_dxdz);
547  TF1 *fit_alphay = new TF1(name_alphay.c_str(), "[0] + x*[1]", min_dydz, max_dydz);
548  double aX = 10.*value(kAlignX), bX = 10.*value(kAlphaX)/1000.;
549  double aY = 10.*value(kAlignY), bY = 10.*value(kAlphaY)/1000.;
551  {
552  double sx = 10.*value(kResidXSigma), sy = 1000.*value(kResSlopeXSigma), r = value(kAlphaX);
553  aX = mean_residualx;
554  bX = 0.;
555  if ( sx != 0. )
556  {
557  bX = 1./(sy/sx*r);
558  aX = - bX * mean_resslopex;
559  }
560  sx = 10.*value(kResidYSigma); sy = 1000.*value(kResSlopeYSigma); r = value(kAlphaY);
561  aY = mean_residualx;
562  bY = 0.;
563  if ( sx != 0. )
564  {
565  bY = 1./(sy/sx*r);
566  aY = - bY * mean_resslopey;
567  }
568  }
569  fit_alphax->SetParameters(aX, bX);
570  fit_alphay->SetParameters(aY, bY);
571 
572  fit_alphax->SetLineColor(2); fit_alphax->SetLineWidth(2); fit_alphax->Write();
573  fit_alphay->SetLineColor(2); fit_alphay->SetLineWidth(2); fit_alphay->Write();
574 
575  TProfile *fit_x_trackx = dir->make<TProfile>(name_x_trackx.c_str(), "", 100, min_trackx, max_trackx);
576  TProfile *fit_y_trackx = dir->make<TProfile>(name_y_trackx.c_str(), "", 100, min_trackx, max_trackx);
577  TProfile *fit_dxdz_trackx = dir->make<TProfile>(name_dxdz_trackx.c_str(), "", 100, min_trackx, max_trackx);
578  TProfile *fit_dydz_trackx = dir->make<TProfile>(name_dydz_trackx.c_str(), "", 100, min_trackx, max_trackx);
579  TProfile *fit_x_tracky = dir->make<TProfile>(name_x_tracky.c_str(), "", 100, min_tracky, max_tracky);
580  TProfile *fit_y_tracky = dir->make<TProfile>(name_y_tracky.c_str(), "", 100, min_tracky, max_tracky);
581  TProfile *fit_dxdz_tracky = dir->make<TProfile>(name_dxdz_tracky.c_str(), "", 100, min_tracky, max_tracky);
582  TProfile *fit_dydz_tracky = dir->make<TProfile>(name_dydz_tracky.c_str(), "", 100, min_tracky, max_tracky);
583  TProfile *fit_x_trackdxdz = dir->make<TProfile>(name_x_trackdxdz.c_str(), "", 500, min_trackdxdz, max_trackdxdz);
584  TProfile *fit_y_trackdxdz = dir->make<TProfile>(name_y_trackdxdz.c_str(), "", 500, min_trackdxdz, max_trackdxdz);
585  TProfile *fit_dxdz_trackdxdz = dir->make<TProfile>(name_dxdz_trackdxdz.c_str(), "", 500, min_trackdxdz, max_trackdxdz);
586  TProfile *fit_dydz_trackdxdz = dir->make<TProfile>(name_dydz_trackdxdz.c_str(), "", 500, min_trackdxdz, max_trackdxdz);
587  TProfile *fit_x_trackdydz = dir->make<TProfile>(name_x_trackdydz.c_str(), "", 500, min_trackdydz, max_trackdydz);
588  TProfile *fit_y_trackdydz = dir->make<TProfile>(name_y_trackdydz.c_str(), "", 500, min_trackdydz, max_trackdydz);
589  TProfile *fit_dxdz_trackdydz = dir->make<TProfile>(name_dxdz_trackdydz.c_str(), "", 500, min_trackdydz, max_trackdydz);
590  TProfile *fit_dydz_trackdydz = dir->make<TProfile>(name_dydz_trackdydz.c_str(), "", 500, min_trackdydz, max_trackdydz);
591 
592  fit_x_trackx->SetLineColor(2); fit_x_trackx->SetLineWidth(2);
593  fit_y_trackx->SetLineColor(2); fit_y_trackx->SetLineWidth(2);
594  fit_dxdz_trackx->SetLineColor(2); fit_dxdz_trackx->SetLineWidth(2);
595  fit_dydz_trackx->SetLineColor(2); fit_dydz_trackx->SetLineWidth(2);
596  fit_x_tracky->SetLineColor(2); fit_x_tracky->SetLineWidth(2);
597  fit_y_tracky->SetLineColor(2); fit_y_tracky->SetLineWidth(2);
598  fit_dxdz_tracky->SetLineColor(2); fit_dxdz_tracky->SetLineWidth(2);
599  fit_dydz_tracky->SetLineColor(2); fit_dydz_tracky->SetLineWidth(2);
600  fit_x_trackdxdz->SetLineColor(2); fit_x_trackdxdz->SetLineWidth(2);
601  fit_y_trackdxdz->SetLineColor(2); fit_y_trackdxdz->SetLineWidth(2);
602  fit_dxdz_trackdxdz->SetLineColor(2); fit_dxdz_trackdxdz->SetLineWidth(2);
603  fit_dydz_trackdxdz->SetLineColor(2); fit_dydz_trackdxdz->SetLineWidth(2);
604  fit_x_trackdydz->SetLineColor(2); fit_x_trackdydz->SetLineWidth(2);
605  fit_y_trackdydz->SetLineColor(2); fit_y_trackdydz->SetLineWidth(2);
606  fit_dxdz_trackdydz->SetLineColor(2); fit_dxdz_trackdydz->SetLineWidth(2);
607  fit_dydz_trackdydz->SetLineColor(2); fit_dydz_trackdydz->SetLineWidth(2);
608 
609  name_x_trackx += "line";
610  name_y_trackx += "line";
611  name_dxdz_trackx += "line";
612  name_dydz_trackx += "line";
613  name_x_tracky += "line";
614  name_y_tracky += "line";
615  name_dxdz_tracky += "line";
616  name_dydz_tracky += "line";
617  name_x_trackdxdz += "line";
618  name_y_trackdxdz += "line";
619  name_dxdz_trackdxdz += "line";
620  name_dydz_trackdxdz += "line";
621  name_x_trackdydz += "line";
622  name_y_trackdydz += "line";
623  name_dxdz_trackdydz += "line";
624  name_dydz_trackdydz += "line";
625 
626  TF1 *fitline_x_trackx = new TF1(name_x_trackx.c_str(), residual_x_trackx_TF1, min_trackx, max_trackx, 14);
627  TF1 *fitline_y_trackx = new TF1(name_y_trackx.c_str(), residual_y_trackx_TF1, min_trackx, max_trackx, 14);
628  TF1 *fitline_dxdz_trackx = new TF1(name_dxdz_trackx.c_str(), residual_dxdz_trackx_TF1, min_trackx, max_trackx, 14);
629  TF1 *fitline_dydz_trackx = new TF1(name_dydz_trackx.c_str(), residual_dydz_trackx_TF1, min_trackx, max_trackx, 14);
630  TF1 *fitline_x_tracky = new TF1(name_x_tracky.c_str(), residual_x_tracky_TF1, min_tracky, max_tracky, 14);
631  TF1 *fitline_y_tracky = new TF1(name_y_tracky.c_str(), residual_y_tracky_TF1, min_tracky, max_tracky, 14);
632  TF1 *fitline_dxdz_tracky = new TF1(name_dxdz_tracky.c_str(), residual_dxdz_tracky_TF1, min_tracky, max_tracky, 14);
633  TF1 *fitline_dydz_tracky = new TF1(name_dydz_tracky.c_str(), residual_dydz_tracky_TF1, min_tracky, max_tracky, 14);
634  TF1 *fitline_x_trackdxdz = new TF1(name_x_trackdxdz.c_str(), residual_x_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
635  TF1 *fitline_y_trackdxdz = new TF1(name_y_trackdxdz.c_str(), residual_y_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
636  TF1 *fitline_dxdz_trackdxdz = new TF1(name_dxdz_trackdxdz.c_str(), residual_dxdz_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
637  TF1 *fitline_dydz_trackdxdz = new TF1(name_dydz_trackdxdz.c_str(), residual_dydz_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
638  TF1 *fitline_x_trackdydz = new TF1(name_x_trackdydz.c_str(), residual_x_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
639  TF1 *fitline_y_trackdydz = new TF1(name_y_trackdydz.c_str(), residual_y_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
640  TF1 *fitline_dxdz_trackdydz = new TF1(name_dxdz_trackdydz.c_str(), residual_dxdz_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
641  TF1 *fitline_dydz_trackdydz = new TF1(name_dydz_trackdydz.c_str(), residual_dydz_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
642 
643  std::vector<TF1*> fitlines;
644  fitlines.push_back(fitline_x_trackx);
645  fitlines.push_back(fitline_y_trackx);
646  fitlines.push_back(fitline_dxdz_trackx);
647  fitlines.push_back(fitline_dydz_trackx);
648  fitlines.push_back(fitline_x_tracky);
649  fitlines.push_back(fitline_y_tracky);
650  fitlines.push_back(fitline_dxdz_tracky);
651  fitlines.push_back(fitline_dydz_tracky);
652  fitlines.push_back(fitline_x_trackdxdz);
653  fitlines.push_back(fitline_y_trackdxdz);
654  fitlines.push_back(fitline_dxdz_trackdxdz);
655  fitlines.push_back(fitline_dydz_trackdxdz);
656  fitlines.push_back(fitline_x_trackdydz);
657  fitlines.push_back(fitline_y_trackdydz);
658  fitlines.push_back(fitline_dxdz_trackdydz);
659  fitlines.push_back(fitline_dydz_trackdydz);
660 
661  double fitparameters[14] = {value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ),
662  mean_trackx, mean_tracky, mean_trackdxdz, mean_trackdydz,
663  value(kAlphaX), mean_resslopex, value(kAlphaY), mean_resslopey};
664  if (residualsModel() == kPureGaussian2D) fitparameters[10] = fitparameters[12] = 0.;
665 
666  for(std::vector<TF1*>::const_iterator itr = fitlines.begin(); itr != fitlines.end(); itr++)
667  {
668  (*itr)->SetParameters(fitparameters);
669  (*itr)->SetLineColor(2);
670  (*itr)->SetLineWidth(2);
671  (*itr)->Write();
672  }
673 
674  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter)
675  {
676  const double residX = (*resiter)[kResidX];
677  const double residY = (*resiter)[kResidY];
678  const double resslopeX = (*resiter)[kResSlopeX];
679  const double resslopeY = (*resiter)[kResSlopeY];
680  const double positionX = (*resiter)[kPositionX];
681  const double positionY = (*resiter)[kPositionY];
682  const double angleX = (*resiter)[kAngleX];
683  const double angleY = (*resiter)[kAngleY];
684  const double redchi2 = (*resiter)[kRedChi2];
685  double weight = 1./redchi2;
686  if (!m_weightAlignment) weight = 1.;
687 
688  if (!m_weightAlignment || TMath::Prob(redchi2*12, 12) < 0.99) { // no spikes allowed
689 
690  hist_alphax->Fill(1000.*resslopeX, 10.*residX);
691  hist_alphay->Fill(1000.*resslopeY, 10.*residY);
692 
693  double coefX = value(kAlphaX), coefY = value(kAlphaY);
694  if (residualsModel() == kPureGaussian || residualsModel() == kPureGaussian2D) coefX = coefY = 0.;
695  double geom_residX = residual_x(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY, coefX, resslopeX);
696  hist_x->Fill(10.*(residX - geom_residX + value(kAlignX)), weight);
697  hist_x_trackx->Fill(positionX, 10.*residX, weight);
698  hist_x_tracky->Fill(positionY, 10.*residX, weight);
699  hist_x_trackdxdz->Fill(angleX, 10.*residX, weight);
700  hist_x_trackdydz->Fill(angleY, 10.*residX, weight);
701  fit_x_trackx->Fill(positionX, 10.*geom_residX, weight);
702  fit_x_tracky->Fill(positionY, 10.*geom_residX, weight);
703  fit_x_trackdxdz->Fill(angleX, 10.*geom_residX, weight);
704  fit_x_trackdydz->Fill(angleY, 10.*geom_residX, weight);
705 
706  double geom_residY = residual_y(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY, coefY, resslopeY);
707  hist_y->Fill(10.*(residY - geom_residY + value(kAlignY)), weight);
708  hist_y_trackx->Fill(positionX, 10.*residY, weight);
709  hist_y_tracky->Fill(positionY, 10.*residY, weight);
710  hist_y_trackdxdz->Fill(angleX, 10.*residY, weight);
711  hist_y_trackdydz->Fill(angleY, 10.*residY, weight);
712  fit_y_trackx->Fill(positionX, 10.*geom_residY, weight);
713  fit_y_tracky->Fill(positionY, 10.*geom_residY, weight);
714  fit_y_trackdxdz->Fill(angleX, 10.*geom_residY, weight);
715  fit_y_trackdydz->Fill(angleY, 10.*geom_residY, weight);
716 
717  double geom_resslopeX = residual_dxdz(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY);
718  hist_dxdz->Fill(1000.*(resslopeX - geom_resslopeX + value(kAlignPhiY)), weight);
719  hist_dxdz_trackx->Fill(positionX, 1000.*resslopeX, weight);
720  hist_dxdz_tracky->Fill(positionY, 1000.*resslopeX, weight);
721  hist_dxdz_trackdxdz->Fill(angleX, 1000.*resslopeX, weight);
722  hist_dxdz_trackdydz->Fill(angleY, 1000.*resslopeX, weight);
723  fit_dxdz_trackx->Fill(positionX, 1000.*geom_resslopeX, weight);
724  fit_dxdz_tracky->Fill(positionY, 1000.*geom_resslopeX, weight);
725  fit_dxdz_trackdxdz->Fill(angleX, 1000.*geom_resslopeX, weight);
726  fit_dxdz_trackdydz->Fill(angleY, 1000.*geom_resslopeX, weight);
727 
728  double geom_resslopeY = residual_dydz(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY);
729  hist_dydz->Fill(1000.*(resslopeY - geom_resslopeY - value(kAlignPhiX)), weight);
730  hist_dydz_trackx->Fill(positionX, 1000.*resslopeY, weight);
731  hist_dydz_tracky->Fill(positionY, 1000.*resslopeY, weight);
732  hist_dydz_trackdxdz->Fill(angleX, 1000.*resslopeY, weight);
733  hist_dydz_trackdydz->Fill(angleY, 1000.*resslopeY, weight);
734  fit_dydz_trackx->Fill(positionX, 1000.*geom_resslopeY, weight);
735  fit_dydz_tracky->Fill(positionY, 1000.*geom_resslopeY, weight);
736  fit_dydz_trackdxdz->Fill(angleX, 1000.*geom_resslopeY, weight);
737  fit_dydz_trackdydz->Fill(angleY, 1000.*geom_resslopeY, weight);
738  }
739 
740  hist_x_raw->Fill(10.*residX);
741  hist_y_raw->Fill(10.*residY);
742  hist_dxdz_raw->Fill(1000.*resslopeX);
743  hist_dydz_raw->Fill(1000.*resslopeY);
744  if (fabs(resslopeX) < 0.005) hist_x_cut->Fill(10.*residX);
745  if (fabs(resslopeY) < 0.030) hist_y_cut->Fill(10.*residY);
746  }
747 
748  double chi2 = 0.;
749  double ndof = 0.;
750  for (int i = 1; i <= hist_x->GetNbinsX(); i++) {
751  double xi = hist_x->GetBinCenter(i);
752  double yi = hist_x->GetBinContent(i);
753  double yerri = hist_x->GetBinError(i);
754  double yth = fit_x->Eval(xi);
755  if (yerri > 0.) {
756  chi2 += pow((yth - yi)/yerri, 2);
757  ndof += 1.;
758  }
759  }
760  for (int i = 1; i <= hist_y->GetNbinsX(); i++) {
761  double xi = hist_y->GetBinCenter(i);
762  double yi = hist_y->GetBinContent(i);
763  double yerri = hist_y->GetBinError(i);
764  double yth = fit_y->Eval(xi);
765  if (yerri > 0.) {
766  chi2 += pow((yth - yi)/yerri, 2);
767  ndof += 1.;
768  }
769  }
770  for (int i = 1; i <= hist_dxdz->GetNbinsX(); i++) {
771  double xi = hist_dxdz->GetBinCenter(i);
772  double yi = hist_dxdz->GetBinContent(i);
773  double yerri = hist_dxdz->GetBinError(i);
774  double yth = fit_dxdz->Eval(xi);
775  if (yerri > 0.) {
776  chi2 += pow((yth - yi)/yerri, 2);
777  ndof += 1.;
778  }
779  }
780  for (int i = 1; i <= hist_dydz->GetNbinsX(); i++) {
781  double xi = hist_dydz->GetBinCenter(i);
782  double yi = hist_dydz->GetBinContent(i);
783  double yerri = hist_dydz->GetBinError(i);
784  double yth = fit_dydz->Eval(xi);
785  if (yerri > 0.) {
786  chi2 += pow((yth - yi)/yerri, 2);
787  ndof += 1.;
788  }
789  }
790  ndof -= npar();
791 
792  return (ndof > 0. ? chi2 / ndof : -1.);
793 }
align::Scalar width() const
int i
Definition: DBlmapReader.cc:9
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
#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
const AlignableSurface & surface() const
Return the Surface (global position and orientation) of the object.
Definition: Alignable.h:126
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
align::Scalar length() const
double errorerror(int parNum)
std::vector< double * >::const_iterator residuals_end() const
int weight
Definition: histoStyle.py:50
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
TTree * MuonResiduals6DOFFitter::readNtuple ( std::string  fname,
unsigned int  wheel,
unsigned int  station,
unsigned int  sector,
unsigned int  preselected = 1 
)

Definition at line 796 of file MuonResiduals6DOFFitter.cc.

References MuonResidualsFitter::MuonAlignmentTreeRow::angle_x, MuonResidualsFitter::MuonAlignmentTreeRow::angle_y, f, MuonResidualsFitter::fill(), i, kAngleX, kAngleY, kCharge, kNData, kPositionX, kPositionY, kPt, kPz, kRedChi2, kResidX, kResidY, kResSlopeX, kResSlopeY, 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_slope_y, MuonResidualsFitter::MuonAlignmentTreeRow::res_x, MuonResidualsFitter::MuonAlignmentTreeRow::res_y, edmStreamStallGrapher::t, and groupFilesInBlocks::tt.

797 {
798  TFile *f = new TFile(fname.c_str());
799  TTree *t = (TTree*)f->Get("mual_ttree");
800 
801  // Create new temporary file
802  TFile *tmpf = new TFile("small_tree_fit.root","recreate");
803  assert(tmpf!=0);
804 
805  // filter the tree (temporarily lives in the new file)
806  TTree *tt = t->CopyTree(Form("is_dt && ring_wheel==%d && station==%d && sector==%d && select==%d", wheel, station, sector, (bool)preselected));
807 
808  MuonAlignmentTreeRow r;
809  tt->SetBranchAddress("res_x", &r.res_x);
810  tt->SetBranchAddress("res_slope_x", &r.res_slope_x);
811  tt->SetBranchAddress("res_y", &r.res_y);
812  tt->SetBranchAddress("res_slope_y", &r.res_slope_y);
813  tt->SetBranchAddress("pos_x", &r.pos_x);
814  tt->SetBranchAddress("pos_y", &r.pos_y);
815  tt->SetBranchAddress("angle_x", &r.angle_x);
816  tt->SetBranchAddress("angle_y", &r.angle_y);
817  tt->SetBranchAddress("pz", &r.pz);
818  tt->SetBranchAddress("pt", &r.pt);
819  tt->SetBranchAddress("q", &r.q);
820 
821  Long64_t nentries = tt->GetEntries();
822  for (Long64_t i=0;i<nentries; i++)
823  {
824  tt->GetEntry(i);
825  double *rdata = new double[MuonResiduals6DOFFitter::kNData];
826  rdata[kResidX] = r.res_x;
827  rdata[kResidY] = r.res_y;
828  rdata[kResSlopeX] = r.res_slope_x;
829  rdata[kResSlopeY] = r.res_slope_y;
830  rdata[kPositionX] = r.pos_x;
831  rdata[kPositionY] = r.pos_y;
832  rdata[kAngleX] = r.angle_x;
833  rdata[kAngleY] = r.angle_y;
834  rdata[kRedChi2] = 0.1;
835  rdata[kPz] = r.pz;
836  rdata[kPt] = r.pt;
837  rdata[kCharge] = r.q;
838  fill(rdata);
839  }
840  delete f;
841  //delete tmpf;
842  return tt;
843 }
int i
Definition: DBlmapReader.cc:9
void fill(double *residual)
double f[11][100]
string fname
main script
double MuonResiduals6DOFFitter::sumofweights ( )
virtual

Implements MuonResidualsFitter.

Definition at line 231 of file MuonResiduals6DOFFitter.cc.

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

Referenced by fit(), and plot().

232 {
233  sum_of_weights = 0.;
234  number_of_hits = 0.;
235  weight_alignment = m_weightAlignment;
236  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
237  if (m_weightAlignment) {
238  double redchi2 = (*resiter)[kRedChi2];
239  if (TMath::Prob(redchi2*12, 12) < 0.99) { // no spikes allowed
240  sum_of_weights += 1./redchi2;
241  number_of_hits += 1.;
242  }
243  }
244  else {
245  sum_of_weights += 1.;
246  number_of_hits += 1.;
247  }
248  }
249  return sum_of_weights;
250 }
std::vector< double * >::const_iterator residuals_end() const
std::vector< double * >::const_iterator residuals_begin() const
int MuonResiduals6DOFFitter::type ( ) const
inlinevirtual