CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Alignment/MuonAlignmentAlgorithms/src/MuonResiduals6DOFFitter.cc

Go to the documentation of this file.
00001 #include "Alignment/MuonAlignmentAlgorithms/interface/MuonResiduals6DOFFitter.h"
00002 #include "TH2F.h"
00003 // #include "TTree.h"
00004 #include "TMath.h"
00005 
00006 static TMinuit *MuonResiduals6DOFFitter_TMinuit;
00007 static double MuonResiduals6DOFFitter_sum_of_weights;
00008 static double MuonResiduals6DOFFitter_number_of_hits;
00009 static bool MuonResiduals6DOFFitter_weightAlignment;
00010 
00011 void MuonResiduals6DOFFitter::inform(TMinuit *tMinuit) {
00012   MuonResiduals6DOFFitter_TMinuit = tMinuit;
00013 }
00014 
00015 double MuonResiduals6DOFFitter_x(double delta_x, double delta_y, double delta_z, double delta_phix, double delta_phiy, double delta_phiz, double track_x, double track_y, double track_dxdz, double track_dydz, double alphax, double residual_dxdz) {
00016   return delta_x - track_dxdz * delta_z - track_y * track_dxdz * delta_phix + track_x * track_dxdz * delta_phiy - track_y * delta_phiz + residual_dxdz * alphax;
00017 }
00018 
00019 double MuonResiduals6DOFFitter_y(double delta_x, double delta_y, double delta_z, double delta_phix, double delta_phiy, double delta_phiz, double track_x, double track_y, double track_dxdz, double track_dydz, double alphay, double residual_dydz) {
00020   return delta_y - track_dydz * delta_z - track_y * track_dydz * delta_phix + track_x * track_dydz * delta_phiy + track_x * delta_phiz + residual_dydz * alphay;
00021 }
00022 
00023 double MuonResiduals6DOFFitter_dxdz(double delta_x, double delta_y, double delta_z, double delta_phix, double delta_phiy, double delta_phiz, double track_x, double track_y, double track_dxdz, double track_dydz) {
00024   return -track_dxdz * track_dydz * delta_phix + (1. + track_dxdz * track_dxdz) * delta_phiy - track_dydz * delta_phiz;
00025 }
00026 
00027 double MuonResiduals6DOFFitter_dydz(double delta_x, double delta_y, double delta_z, double delta_phix, double delta_phiy, double delta_phiz, double track_x, double track_y, double track_dxdz, double track_dydz) {
00028   return -(1. + track_dydz * track_dydz) * delta_phix + track_dxdz * track_dydz * delta_phiy + track_dxdz * delta_phiz;
00029 }
00030 
00031 Double_t MuonResiduals6DOFFitter_x_trackx_TF1(Double_t *xvec, Double_t *par) { return 10.*MuonResiduals6DOFFitter_x(par[0], par[1], par[2], par[3], par[4], par[5], xvec[0], par[7], par[8], par[9], par[10], par[11]); }
00032 Double_t MuonResiduals6DOFFitter_x_tracky_TF1(Double_t *xvec, Double_t *par) { return 10.*MuonResiduals6DOFFitter_x(par[0], par[1], par[2], par[3], par[4], par[5], par[6], xvec[0], par[8], par[9], par[10], par[11]); }
00033 Double_t MuonResiduals6DOFFitter_x_trackdxdz_TF1(Double_t *xvec, Double_t *par) { return 10.*MuonResiduals6DOFFitter_x(par[0], par[1], par[2], par[3], par[4], par[5], par[6], par[7], xvec[0], par[9], par[10], par[11]); }
00034 Double_t MuonResiduals6DOFFitter_x_trackdydz_TF1(Double_t *xvec, Double_t *par) { return 10.*MuonResiduals6DOFFitter_x(par[0], par[1], par[2], par[3], par[4], par[5], par[6], par[7], par[8], xvec[0], par[10], par[11]); }
00035 
00036 Double_t MuonResiduals6DOFFitter_y_trackx_TF1(Double_t *xvec, Double_t *par) { return 10.*MuonResiduals6DOFFitter_y(par[0], par[1], par[2], par[3], par[4], par[5], xvec[0], par[7], par[8], par[9], par[12], par[13]); }
00037 Double_t MuonResiduals6DOFFitter_y_tracky_TF1(Double_t *xvec, Double_t *par) { return 10.*MuonResiduals6DOFFitter_y(par[0], par[1], par[2], par[3], par[4], par[5], par[6], xvec[0], par[8], par[9], par[12], par[13]); }
00038 Double_t MuonResiduals6DOFFitter_y_trackdxdz_TF1(Double_t *xvec, Double_t *par) { return 10.*MuonResiduals6DOFFitter_y(par[0], par[1], par[2], par[3], par[4], par[5], par[6], par[7], xvec[0], par[9], par[12], par[13]); }
00039 Double_t MuonResiduals6DOFFitter_y_trackdydz_TF1(Double_t *xvec, Double_t *par) { return 10.*MuonResiduals6DOFFitter_y(par[0], par[1], par[2], par[3], par[4], par[5], par[6], par[7], par[8], xvec[0], par[12], par[13]); }
00040 
00041 Double_t MuonResiduals6DOFFitter_dxdz_trackx_TF1(Double_t *xvec, Double_t *par) { return 1000.*MuonResiduals6DOFFitter_dxdz(par[0], par[1], par[2], par[3], par[4], par[5], xvec[0], par[7], par[8], par[9]); }
00042 Double_t MuonResiduals6DOFFitter_dxdz_tracky_TF1(Double_t *xvec, Double_t *par) { return 1000.*MuonResiduals6DOFFitter_dxdz(par[0], par[1], par[2], par[3], par[4], par[5], par[6], xvec[0], par[8], par[9]); }
00043 Double_t MuonResiduals6DOFFitter_dxdz_trackdxdz_TF1(Double_t *xvec, Double_t *par) { return 1000.*MuonResiduals6DOFFitter_dxdz(par[0], par[1], par[2], par[3], par[4], par[5], par[6], par[7], xvec[0], par[9]); }
00044 Double_t MuonResiduals6DOFFitter_dxdz_trackdydz_TF1(Double_t *xvec, Double_t *par) { return 1000.*MuonResiduals6DOFFitter_dxdz(par[0], par[1], par[2], par[3], par[4], par[5], par[6], par[7], par[8], xvec[0]); }
00045 
00046 Double_t MuonResiduals6DOFFitter_dydz_trackx_TF1(Double_t *xvec, Double_t *par) { return 1000.*MuonResiduals6DOFFitter_dydz(par[0], par[1], par[2], par[3], par[4], par[5], xvec[0], par[7], par[8], par[9]); }
00047 Double_t MuonResiduals6DOFFitter_dydz_tracky_TF1(Double_t *xvec, Double_t *par) { return 1000.*MuonResiduals6DOFFitter_dydz(par[0], par[1], par[2], par[3], par[4], par[5], par[6], xvec[0], par[8], par[9]); }
00048 Double_t MuonResiduals6DOFFitter_dydz_trackdxdz_TF1(Double_t *xvec, Double_t *par) { return 1000.*MuonResiduals6DOFFitter_dydz(par[0], par[1], par[2], par[3], par[4], par[5], par[6], par[7], xvec[0], par[9]); }
00049 Double_t MuonResiduals6DOFFitter_dydz_trackdydz_TF1(Double_t *xvec, Double_t *par) { return 1000.*MuonResiduals6DOFFitter_dydz(par[0], par[1], par[2], par[3], par[4], par[5], par[6], par[7], par[8], xvec[0]); }
00050 
00051 void MuonResiduals6DOFFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag) {
00052   MuonResidualsFitterFitInfo *fitinfo = (MuonResidualsFitterFitInfo*)(MuonResiduals6DOFFitter_TMinuit->GetObjectFit());
00053   MuonResidualsFitter *fitter = fitinfo->fitter();
00054 
00055   fval = 0.;
00056   for (std::vector<double*>::const_iterator resiter = fitter->residuals_begin();  resiter != fitter->residuals_end();  ++resiter) {
00057     const double residX = (*resiter)[MuonResiduals6DOFFitter::kResidX];
00058     const double residY = (*resiter)[MuonResiduals6DOFFitter::kResidY];
00059     const double resslopeX = (*resiter)[MuonResiduals6DOFFitter::kResSlopeX];
00060     const double resslopeY = (*resiter)[MuonResiduals6DOFFitter::kResSlopeY];
00061     const double positionX = (*resiter)[MuonResiduals6DOFFitter::kPositionX];
00062     const double positionY = (*resiter)[MuonResiduals6DOFFitter::kPositionY];
00063     const double angleX = (*resiter)[MuonResiduals6DOFFitter::kAngleX];
00064     const double angleY = (*resiter)[MuonResiduals6DOFFitter::kAngleY];
00065     const double redchi2 = (*resiter)[MuonResiduals6DOFFitter::kRedChi2];
00066 
00067     const double alignx = par[MuonResiduals6DOFFitter::kAlignX];
00068     const double aligny = par[MuonResiduals6DOFFitter::kAlignY];
00069     const double alignz = par[MuonResiduals6DOFFitter::kAlignZ];
00070     const double alignphix = par[MuonResiduals6DOFFitter::kAlignPhiX];
00071     const double alignphiy = par[MuonResiduals6DOFFitter::kAlignPhiY];
00072     const double alignphiz = par[MuonResiduals6DOFFitter::kAlignPhiZ];
00073     const double resXsigma = par[MuonResiduals6DOFFitter::kResidXSigma];
00074     const double resYsigma = par[MuonResiduals6DOFFitter::kResidYSigma];
00075     const double slopeXsigma = par[MuonResiduals6DOFFitter::kResSlopeXSigma];
00076     const double slopeYsigma = par[MuonResiduals6DOFFitter::kResSlopeYSigma];
00077     const double alphax = par[MuonResiduals6DOFFitter::kAlphaX];
00078     const double alphay = par[MuonResiduals6DOFFitter::kAlphaY];
00079     const double resXgamma = par[MuonResiduals6DOFFitter::kResidXGamma];
00080     const double resYgamma = par[MuonResiduals6DOFFitter::kResidYGamma];
00081     const double slopeXgamma = par[MuonResiduals6DOFFitter::kResSlopeXGamma];
00082     const double slopeYgamma = par[MuonResiduals6DOFFitter::kResSlopeYGamma];
00083 
00084     double residXpeak = MuonResiduals6DOFFitter_x(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, alphax, resslopeX);
00085     double residYpeak = MuonResiduals6DOFFitter_y(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY, alphay, resslopeY);
00086     double slopeXpeak = MuonResiduals6DOFFitter_dxdz(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY);
00087     double slopeYpeak = MuonResiduals6DOFFitter_dydz(alignx, aligny, alignz, alignphix, alignphiy, alignphiz, positionX, positionY, angleX, angleY);
00088 
00089     double weight = (1./redchi2) * MuonResiduals6DOFFitter_number_of_hits / MuonResiduals6DOFFitter_sum_of_weights;
00090     if (!MuonResiduals6DOFFitter_weightAlignment) weight = 1.;
00091 
00092     if (!MuonResiduals6DOFFitter_weightAlignment  ||  TMath::Prob(redchi2*12, 12) < 0.99) {  // no spikes allowed
00093 
00094       if (fitter->residualsModel() == MuonResidualsFitter::kPureGaussian) {
00095         fval += -weight * MuonResidualsFitter_logPureGaussian(residX, residXpeak, resXsigma);
00096         fval += -weight * MuonResidualsFitter_logPureGaussian(residY, residYpeak, resYsigma);
00097         fval += -weight * MuonResidualsFitter_logPureGaussian(resslopeX, slopeXpeak, slopeXsigma);
00098         fval += -weight * MuonResidualsFitter_logPureGaussian(resslopeY, slopeYpeak, slopeYsigma);
00099       }
00100       else if (fitter->residualsModel() == MuonResidualsFitter::kPowerLawTails) {
00101         fval += -weight * MuonResidualsFitter_logPowerLawTails(residX, residXpeak, resXsigma, resXgamma);
00102         fval += -weight * MuonResidualsFitter_logPowerLawTails(residY, residYpeak, resYsigma, resYgamma);
00103         fval += -weight * MuonResidualsFitter_logPowerLawTails(resslopeX, slopeXpeak, slopeXsigma, slopeXgamma);
00104         fval += -weight * MuonResidualsFitter_logPowerLawTails(resslopeY, slopeYpeak, slopeYsigma, slopeYgamma);
00105       }
00106       else if (fitter->residualsModel() == MuonResidualsFitter::kROOTVoigt) {
00107         fval += -weight * MuonResidualsFitter_logROOTVoigt(residX, residXpeak, resXsigma, resXgamma);
00108         fval += -weight * MuonResidualsFitter_logROOTVoigt(residY, residYpeak, resYsigma, resYgamma);
00109         fval += -weight * MuonResidualsFitter_logROOTVoigt(resslopeX, slopeXpeak, slopeXsigma, slopeXgamma);
00110         fval += -weight * MuonResidualsFitter_logROOTVoigt(resslopeY, slopeYpeak, slopeYsigma, slopeYgamma);
00111       }
00112       else if (fitter->residualsModel() == MuonResidualsFitter::kGaussPowerTails) {
00113         fval += -weight * MuonResidualsFitter_logGaussPowerTails(residX, residXpeak, resXsigma);
00114         fval += -weight * MuonResidualsFitter_logGaussPowerTails(residY, residYpeak, resYsigma);
00115         fval += -weight * MuonResidualsFitter_logGaussPowerTails(resslopeX, slopeXpeak, slopeXsigma);
00116         fval += -weight * MuonResidualsFitter_logGaussPowerTails(resslopeY, slopeYpeak, slopeYsigma);
00117       }
00118       else { assert(false); }
00119 
00120     }
00121   }
00122 }
00123 
00124 double MuonResiduals6DOFFitter::sumofweights() {
00125   MuonResiduals6DOFFitter_sum_of_weights = 0.;
00126   MuonResiduals6DOFFitter_number_of_hits = 0.;
00127   MuonResiduals6DOFFitter_weightAlignment = m_weightAlignment;
00128   for (std::vector<double*>::const_iterator resiter = residuals_begin();  resiter != residuals_end();  ++resiter) {
00129     if (m_weightAlignment) {
00130        double redchi2 = (*resiter)[MuonResiduals6DOFFitter::kRedChi2];
00131        if (TMath::Prob(redchi2*12, 12) < 0.99) {  // no spikes allowed
00132           MuonResiduals6DOFFitter_sum_of_weights += 1./redchi2;
00133           MuonResiduals6DOFFitter_number_of_hits += 1.;
00134        }
00135     }
00136     else {
00137        MuonResiduals6DOFFitter_sum_of_weights += 1.;
00138        MuonResiduals6DOFFitter_number_of_hits += 1.;
00139     }
00140   }
00141   return MuonResiduals6DOFFitter_sum_of_weights;
00142 }
00143 
00144 bool MuonResiduals6DOFFitter::fit(Alignable *ali) {
00145   initialize_table();  // if not already initialized
00146   sumofweights();
00147 
00148   double residx_mean = 0;
00149   double residy_mean = 0;
00150   double resslopex_mean = 0;
00151   double resslopey_mean = 0;
00152   double residx_stdev = 0.5;
00153   double residy_stdev = 3.0;
00154   double resslopex_stdev = 0.005;
00155   double resslopey_stdev = 0.03;
00156   double alphax_estimate = 0;
00157   double alphay_estimate = 0;
00158 
00159   std::vector<int> num;
00160   std::vector<std::string> name;
00161   std::vector<double> start;
00162   std::vector<double> step;
00163   std::vector<double> low;
00164   std::vector<double> high;
00165 
00166   if (fixed(kAlignX)) {
00167   num.push_back(kAlignX);         name.push_back(std::string("AlignX"));         start.push_back(0.);              step.push_back(0.1);                      low.push_back(0.);   high.push_back(0.);
00168   } else {
00169   num.push_back(kAlignX);         name.push_back(std::string("AlignX"));         start.push_back(residx_mean);     step.push_back(0.1);                      low.push_back(0.);   high.push_back(0.);
00170   }
00171   if (fixed(kAlignY)) {
00172   num.push_back(kAlignY);         name.push_back(std::string("AlignY"));         start.push_back(0.);              step.push_back(0.1);                      low.push_back(0.);   high.push_back(0.);
00173   } else {
00174   num.push_back(kAlignY);         name.push_back(std::string("AlignY"));         start.push_back(residy_mean);     step.push_back(0.1);                      low.push_back(0.);   high.push_back(0.);
00175   }
00176   num.push_back(kAlignZ);         name.push_back(std::string("AlignZ"));         start.push_back(0.);              step.push_back(0.1);                      low.push_back(0.);   high.push_back(0.);
00177   if (fixed(kAlignPhiX)) {
00178   num.push_back(kAlignPhiX);      name.push_back(std::string("AlignPhiX"));      start.push_back(0.);              step.push_back(0.001);                    low.push_back(0.);   high.push_back(0.);
00179   } else {
00180   num.push_back(kAlignPhiX);      name.push_back(std::string("AlignPhiX"));      start.push_back(-resslopey_mean); step.push_back(0.001);                    low.push_back(0.);   high.push_back(0.);
00181   }
00182   if (fixed(kAlignPhiY)) {
00183   num.push_back(kAlignPhiY);      name.push_back(std::string("AlignPhiY"));      start.push_back(0.);              step.push_back(0.001);                    low.push_back(0.);   high.push_back(0.);
00184   } else {
00185   num.push_back(kAlignPhiY);      name.push_back(std::string("AlignPhiY"));      start.push_back(resslopex_mean);  step.push_back(0.001);                    low.push_back(0.);   high.push_back(0.);
00186   }
00187   num.push_back(kAlignPhiZ);      name.push_back(std::string("AlignPhiZ"));      start.push_back(0.);              step.push_back(0.001);                    low.push_back(0.);   high.push_back(0.);
00188   num.push_back(kResidXSigma);    name.push_back(std::string("ResidXSigma"));    start.push_back(residx_stdev);    step.push_back(0.01*residx_stdev);        low.push_back(0.);   high.push_back(0.);
00189   num.push_back(kResidYSigma);    name.push_back(std::string("ResidYSigma"));    start.push_back(residy_stdev);    step.push_back(0.01*residy_stdev);        low.push_back(0.);   high.push_back(0.);
00190   num.push_back(kResSlopeXSigma); name.push_back(std::string("ResSlopeXSigma")); start.push_back(resslopex_stdev); step.push_back(0.01*resslopex_stdev);     low.push_back(0.);   high.push_back(0.);
00191   num.push_back(kResSlopeYSigma); name.push_back(std::string("ResSlopeYSigma")); start.push_back(resslopey_stdev); step.push_back(0.01*resslopey_stdev);     low.push_back(0.);   high.push_back(0.);
00192   num.push_back(kAlphaX);         name.push_back(std::string("AlphaX"));         start.push_back(alphax_estimate); step.push_back(0.01*resslopex_stdev);     low.push_back(0.);   high.push_back(0.);
00193   num.push_back(kAlphaY);         name.push_back(std::string("AlphaY"));         start.push_back(alphay_estimate); step.push_back(0.01*resslopey_stdev);     low.push_back(0.);   high.push_back(0.);
00194   if (residualsModel() != kPureGaussian && residualsModel() != kGaussPowerTails) {
00195   num.push_back(kResidXGamma);    name.push_back(std::string("ResidXGamma"));    start.push_back(0.1*residx_stdev);    step.push_back(0.01*residx_stdev);    low.push_back(0.);   high.push_back(0.);
00196   num.push_back(kResidYGamma);    name.push_back(std::string("ResidYGamma"));    start.push_back(0.1*residy_stdev);    step.push_back(0.01*residy_stdev);    low.push_back(0.);   high.push_back(0.);
00197   num.push_back(kResSlopeXGamma); name.push_back(std::string("ResSlopeXGamma")); start.push_back(0.1*resslopex_stdev); step.push_back(0.01*resslopex_stdev); low.push_back(0.);   high.push_back(0.);
00198   num.push_back(kResSlopeYGamma); name.push_back(std::string("ResSlopeYGamma")); start.push_back(0.1*resslopey_stdev); step.push_back(0.01*resslopey_stdev); low.push_back(0.);   high.push_back(0.);
00199   }
00200 
00201   return dofit(&MuonResiduals6DOFFitter_FCN, num, name, start, step, low, high);
00202 }
00203 
00204 double MuonResiduals6DOFFitter::plot(std::string name, TFileDirectory *dir, Alignable *ali) {
00205   sumofweights();
00206 
00207 //   std::stringstream name_ntuple;
00208 //   name_ntuple << name << "_ntuple";
00209 //   TTree *ntuple = dir->make<TTree>(name_ntuple.str().c_str(), "");
00210 //   Float_t ntuple_residX;
00211 //   Float_t ntuple_residY;
00212 //   Float_t ntuple_resslopeX;
00213 //   Float_t ntuple_resslopeY;
00214 //   Float_t ntuple_positionX;
00215 //   Float_t ntuple_positionY;
00216 //   Float_t ntuple_angleX;
00217 //   Float_t ntuple_angleY;
00218 //   Float_t ntuple_redchi2;
00219 //   Float_t ntuple_prob;
00220 
00221 //   ntuple->Branch("residX", &ntuple_residX, "residX/F");
00222 //   ntuple->Branch("residY", &ntuple_residY, "residY/F");
00223 //   ntuple->Branch("resslopeX", &ntuple_resslopeX, "resslopeX/F");
00224 //   ntuple->Branch("resslopeY", &ntuple_resslopeY, "resslopeY/F");
00225 //   ntuple->Branch("positionX", &ntuple_positionX, "positionX/F");
00226 //   ntuple->Branch("positionY", &ntuple_positionY, "positionY/F");
00227 //   ntuple->Branch("angleX", &ntuple_angleX, "angleX/F");
00228 //   ntuple->Branch("angleY", &ntuple_angleY, "angleY/F");
00229 //   ntuple->Branch("redchi2", &ntuple_redchi2, "redchi2/F");
00230 //   ntuple->Branch("prob", &ntuple_prob, "prob/F");
00231   
00232 //   for (std::vector<double*>::const_iterator resiter = residuals_begin();  resiter != residuals_end();  ++resiter) {
00233 //     ntuple_residX = (*resiter)[MuonResiduals6DOFFitter::kResidX];
00234 //     ntuple_residY = (*resiter)[MuonResiduals6DOFFitter::kResidY];
00235 //     ntuple_resslopeX = (*resiter)[MuonResiduals6DOFFitter::kResSlopeX];
00236 //     ntuple_resslopeY = (*resiter)[MuonResiduals6DOFFitter::kResSlopeY];
00237 //     ntuple_positionX = (*resiter)[MuonResiduals6DOFFitter::kPositionX];
00238 //     ntuple_positionY = (*resiter)[MuonResiduals6DOFFitter::kPositionY];
00239 //     ntuple_angleX = (*resiter)[MuonResiduals6DOFFitter::kAngleX];
00240 //     ntuple_angleY = (*resiter)[MuonResiduals6DOFFitter::kAngleY];
00241 //     ntuple_redchi2 = (*resiter)[MuonResiduals6DOFFitter::kRedChi2];
00242 //     ntuple_prob = TMath::Prob((*resiter)[MuonResiduals6DOFFitter::kRedChi2]);
00243 
00244 //     ntuple->Fill();
00245 //   }
00246 
00247   std::stringstream 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;
00248   std::stringstream name_x_trackx, name_y_trackx, name_dxdz_trackx, name_dydz_trackx;
00249   std::stringstream name_x_tracky, name_y_tracky, name_dxdz_tracky, name_dydz_tracky;
00250   std::stringstream name_x_trackdxdz, name_y_trackdxdz, name_dxdz_trackdxdz, name_dydz_trackdxdz;
00251   std::stringstream name_x_trackdydz, name_y_trackdydz, name_dxdz_trackdydz, name_dydz_trackdydz;
00252 
00253   name_x << name << "_x";
00254   name_y << name << "_y";
00255   name_dxdz << name << "_dxdz";
00256   name_dydz << name << "_dydz";
00257   name_x_raw << name << "_x_raw";
00258   name_y_raw << name << "_y_raw";
00259   name_dxdz_raw << name << "_dxdz_raw";
00260   name_dydz_raw << name << "_dydz_raw";
00261   name_x_cut << name << "_x_cut";
00262   name_y_cut << name << "_y_cut";
00263   name_alphax << name << "_alphax";
00264   name_alphay << name << "_alphay";
00265   name_x_trackx << name << "_x_trackx";
00266   name_y_trackx << name << "_y_trackx";
00267   name_dxdz_trackx << name << "_dxdz_trackx";
00268   name_dydz_trackx << name << "_dydz_trackx";
00269   name_x_tracky << name << "_x_tracky";
00270   name_y_tracky << name << "_y_tracky";
00271   name_dxdz_tracky << name << "_dxdz_tracky";
00272   name_dydz_tracky << name << "_dydz_tracky";
00273   name_x_trackdxdz << name << "_x_trackdxdz";
00274   name_y_trackdxdz << name << "_y_trackdxdz";
00275   name_dxdz_trackdxdz << name << "_dxdz_trackdxdz";
00276   name_dydz_trackdxdz << name << "_dydz_trackdxdz";
00277   name_x_trackdydz << name << "_x_trackdydz";
00278   name_y_trackdydz << name << "_y_trackdydz";
00279   name_dxdz_trackdydz << name << "_dxdz_trackdydz";
00280   name_dydz_trackdydz << name << "_dydz_trackdydz";
00281 
00282   double width = ali->surface().width();
00283   double length = ali->surface().length();
00284   double min_x = -100.;            double max_x = 100.;
00285   double min_y = -200.;            double max_y = 200.;
00286   double min_dxdz = -100.;         double max_dxdz = 100.;
00287   double min_dydz = -200.;         double max_dydz = 200.;
00288   double min_trackx = -width/2.;   double max_trackx = width/2.;
00289   double min_tracky = -length/2.;  double max_tracky = length/2.;
00290   double min_trackdxdz = -1.5;     double max_trackdxdz = 1.5;
00291   double min_trackdydz = -1.5;     double max_trackdydz = 1.5;
00292 
00293   TH1F *hist_x = dir->make<TH1F>(name_x.str().c_str(), "", 100, min_x, max_x);
00294   TH1F *hist_y = dir->make<TH1F>(name_y.str().c_str(), "", 100, min_y, max_y);
00295   TH1F *hist_dxdz = dir->make<TH1F>(name_dxdz.str().c_str(), "", 100, min_dxdz, max_dxdz);
00296   TH1F *hist_dydz = dir->make<TH1F>(name_dydz.str().c_str(), "", 100, min_dydz, max_dydz);
00297   TH1F *hist_x_raw = dir->make<TH1F>(name_x_raw.str().c_str(), "", 100, min_x, max_x);
00298   TH1F *hist_y_raw = dir->make<TH1F>(name_y_raw.str().c_str(), "", 100, min_y, max_y);
00299   TH1F *hist_dxdz_raw = dir->make<TH1F>(name_dxdz_raw.str().c_str(), "", 100, min_dxdz, max_dxdz);
00300   TH1F *hist_dydz_raw = dir->make<TH1F>(name_dydz_raw.str().c_str(), "", 100, min_dydz, max_dydz);
00301   TH1F *hist_x_cut = dir->make<TH1F>(name_x_cut.str().c_str(), "", 100, min_x, max_x);
00302   TH1F *hist_y_cut = dir->make<TH1F>(name_y_cut.str().c_str(), "", 100, min_y, max_y);
00303   TH2F *hist_alphax = dir->make<TH2F>(name_alphax.str().c_str(), "", 40, min_dxdz, max_dxdz, 40, -20., 20.);
00304   TH2F *hist_alphay = dir->make<TH2F>(name_alphay.str().c_str(), "", 40, min_dydz, max_dydz, 40, -100., 100.);
00305   TProfile *hist_x_trackx = dir->make<TProfile>(name_x_trackx.str().c_str(), "", 100, min_trackx, max_trackx, min_x, max_x);
00306   TProfile *hist_y_trackx = dir->make<TProfile>(name_y_trackx.str().c_str(), "", 100, min_trackx, max_trackx, min_y, max_y);
00307   TProfile *hist_dxdz_trackx = dir->make<TProfile>(name_dxdz_trackx.str().c_str(), "", 100, min_trackx, max_trackx, min_dxdz, max_dxdz);
00308   TProfile *hist_dydz_trackx = dir->make<TProfile>(name_dydz_trackx.str().c_str(), "", 100, min_trackx, max_trackx, min_dydz, max_dydz);
00309   TProfile *hist_x_tracky = dir->make<TProfile>(name_x_tracky.str().c_str(), "", 100, min_tracky, max_tracky, min_x, max_x);
00310   TProfile *hist_y_tracky = dir->make<TProfile>(name_y_tracky.str().c_str(), "", 100, min_tracky, max_tracky, min_y, max_y);
00311   TProfile *hist_dxdz_tracky = dir->make<TProfile>(name_dxdz_tracky.str().c_str(), "", 100, min_tracky, max_tracky, min_dxdz, max_dxdz);
00312   TProfile *hist_dydz_tracky = dir->make<TProfile>(name_dydz_tracky.str().c_str(), "", 100, min_tracky, max_tracky, min_dydz, max_dydz);
00313   TProfile *hist_x_trackdxdz = dir->make<TProfile>(name_x_trackdxdz.str().c_str(), "", 500, min_trackdxdz, max_trackdxdz, min_x, max_x);
00314   TProfile *hist_y_trackdxdz = dir->make<TProfile>(name_y_trackdxdz.str().c_str(), "", 500, min_trackdxdz, max_trackdxdz, min_y, max_y);
00315   TProfile *hist_dxdz_trackdxdz = dir->make<TProfile>(name_dxdz_trackdxdz.str().c_str(), "", 500, min_trackdxdz, max_trackdxdz, min_dxdz, max_dxdz);
00316   TProfile *hist_dydz_trackdxdz = dir->make<TProfile>(name_dydz_trackdxdz.str().c_str(), "", 500, min_trackdxdz, max_trackdxdz, min_dydz, max_dydz);
00317   TProfile *hist_x_trackdydz = dir->make<TProfile>(name_x_trackdydz.str().c_str(), "", 500, min_trackdydz, max_trackdydz, min_x, max_x);
00318   TProfile *hist_y_trackdydz = dir->make<TProfile>(name_y_trackdydz.str().c_str(), "", 500, min_trackdydz, max_trackdydz, min_y, max_y);
00319   TProfile *hist_dxdz_trackdydz = dir->make<TProfile>(name_dxdz_trackdydz.str().c_str(), "", 500, min_trackdydz, max_trackdydz, min_dxdz, max_dxdz);
00320   TProfile *hist_dydz_trackdydz = dir->make<TProfile>(name_dydz_trackdydz.str().c_str(), "", 500, min_trackdydz, max_trackdydz, min_dydz, max_dydz);
00321 
00322   hist_x_trackx->SetAxisRange(-10., 10., "Y");
00323   hist_y_trackx->SetAxisRange(-20., 20., "Y");
00324   hist_dxdz_trackx->SetAxisRange(-10., 10., "Y");
00325   hist_dydz_trackx->SetAxisRange(-20., 20., "Y");
00326   hist_x_tracky->SetAxisRange(-10., 10., "Y");
00327   hist_y_tracky->SetAxisRange(-20., 20., "Y");
00328   hist_dxdz_tracky->SetAxisRange(-10., 10., "Y");
00329   hist_dydz_tracky->SetAxisRange(-20., 20., "Y");
00330   hist_x_trackdxdz->SetAxisRange(-10., 10., "Y");
00331   hist_y_trackdxdz->SetAxisRange(-20., 20., "Y");
00332   hist_dxdz_trackdxdz->SetAxisRange(-10., 10., "Y");
00333   hist_dydz_trackdxdz->SetAxisRange(-20., 20., "Y");
00334   hist_x_trackdydz->SetAxisRange(-10., 10., "Y");
00335   hist_y_trackdydz->SetAxisRange(-20., 20., "Y");
00336   hist_dxdz_trackdydz->SetAxisRange(-10., 10., "Y");
00337   hist_dydz_trackdydz->SetAxisRange(-20., 20., "Y");
00338 
00339   name_x << "_fit";
00340   name_y << "_fit";
00341   name_dxdz << "_fit";
00342   name_dydz << "_fit";
00343   name_alphax << "_fit";
00344   name_alphay << "_fit";
00345   name_x_trackx << "_fit";
00346   name_y_trackx << "_fit";
00347   name_dxdz_trackx << "_fit";
00348   name_dydz_trackx << "_fit";
00349   name_x_tracky << "_fit";
00350   name_y_tracky << "_fit";
00351   name_dxdz_tracky << "_fit";
00352   name_dydz_tracky << "_fit";
00353   name_x_trackdxdz << "_fit";
00354   name_y_trackdxdz << "_fit";
00355   name_dxdz_trackdxdz << "_fit";
00356   name_dydz_trackdxdz << "_fit";
00357   name_x_trackdydz << "_fit";
00358   name_y_trackdydz << "_fit";
00359   name_dxdz_trackdydz << "_fit";
00360   name_dydz_trackdydz << "_fit";
00361 
00362   TF1 *fit_x = NULL;
00363   TF1 *fit_y = NULL;
00364   TF1 *fit_dxdz = NULL;
00365   TF1 *fit_dydz = NULL;
00366   if (residualsModel() == kPureGaussian) {
00367     fit_x = new TF1(name_x.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, min_x, max_x, 3);
00368     fit_x->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_x - min_x)/100., 10.*value(kAlignX), 10.*value(kResidXSigma));
00369     fit_y = new TF1(name_y.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, min_y, max_y, 3);
00370     fit_y->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_y - min_y)/100., 10.*value(kAlignY), 10.*value(kResidYSigma));
00371     fit_dxdz = new TF1(name_dxdz.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, min_dxdz, max_dxdz, 3);
00372     fit_dxdz->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_dxdz - min_dxdz)/100., 1000.*value(kAlignPhiY), 1000.*value(kResSlopeXSigma));
00373     fit_dydz = new TF1(name_dydz.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, min_dydz, max_dydz, 3);
00374     fit_dydz->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_dydz - min_dydz)/100., -1000.*value(kAlignPhiX), 1000.*value(kResSlopeYSigma));
00375   }
00376   else if (residualsModel() == kPowerLawTails) {
00377     fit_x = new TF1(name_x.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, min_x, max_x, 4);
00378     fit_x->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_x - min_x)/100., 10.*value(kAlignX), 10.*value(kResidXSigma), 10.*value(kResidXGamma));
00379     fit_y = new TF1(name_y.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, min_y, max_y, 4);
00380     fit_y->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_y - min_y)/100., 10.*value(kAlignY), 10.*value(kResidYSigma), 10.*value(kResidYGamma));
00381     fit_dxdz = new TF1(name_dxdz.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, min_dxdz, max_dxdz, 4);
00382     fit_dxdz->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_dxdz - min_dxdz)/100., 1000.*value(kAlignPhiY), 1000.*value(kResSlopeXSigma), 1000.*value(kResSlopeXGamma));
00383     fit_dydz = new TF1(name_dydz.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, min_dydz, max_dydz, 4);
00384     fit_dydz->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_dydz - min_dydz)/100., -1000.*value(kAlignPhiX), 1000.*value(kResSlopeYSigma), 1000.*value(kResSlopeYGamma));
00385   }
00386   else if (residualsModel() == kROOTVoigt) {
00387     fit_x = new TF1(name_x.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_x, max_x, 4);
00388     fit_x->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_x - min_x)/100., 10.*value(kAlignX), 10.*value(kResidXSigma), 10.*value(kResidXGamma));
00389     fit_y = new TF1(name_y.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_y, max_y, 4);
00390     fit_y->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_y - min_y)/100., 10.*value(kAlignY), 10.*value(kResidYSigma), 10.*value(kResidYGamma));
00391     fit_dxdz = new TF1(name_dxdz.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_dxdz, max_dxdz, 4);
00392     fit_dxdz->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_dxdz - min_dxdz)/100., 1000.*value(kAlignPhiY), 1000.*value(kResSlopeXSigma), 1000.*value(kResSlopeXGamma));
00393     fit_dydz = new TF1(name_dydz.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_dydz, max_dydz, 4);
00394     fit_dydz->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_dydz - min_dydz)/100., -1000.*value(kAlignPhiX), 1000.*value(kResSlopeYSigma), 1000.*value(kResSlopeYGamma));
00395   }
00396   else if (residualsModel() == kGaussPowerTails) {
00397     fit_x = new TF1(name_x.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_x, max_x, 3);
00398     fit_x->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_x - min_x)/100., 10.*value(kAlignX), 10.*value(kResidXSigma));
00399     fit_y = new TF1(name_y.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_y, max_y, 3);
00400     fit_y->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_y - min_y)/100., 10.*value(kAlignY), 10.*value(kResidYSigma));
00401     fit_dxdz = new TF1(name_dxdz.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_dxdz, max_dxdz, 3);
00402     fit_dxdz->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_dxdz - min_dxdz)/100., 1000.*value(kAlignPhiY), 1000.*value(kResSlopeXSigma));
00403     fit_dydz = new TF1(name_dydz.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_dydz, max_dydz, 3);
00404     fit_dydz->SetParameters(MuonResiduals6DOFFitter_sum_of_weights * (max_dydz - min_dydz)/100., -1000.*value(kAlignPhiX), 1000.*value(kResSlopeYSigma));
00405   }
00406   else { assert(false); }
00407 
00408   fit_x->SetLineColor(2);     fit_x->SetLineWidth(2);
00409   fit_y->SetLineColor(2);     fit_y->SetLineWidth(2);
00410   fit_dxdz->SetLineColor(2);  fit_dxdz->SetLineWidth(2);
00411   fit_dydz->SetLineColor(2);  fit_dydz->SetLineWidth(2);
00412   fit_x->Write();
00413   fit_y->Write();
00414   fit_dxdz->Write();
00415   fit_dydz->Write();
00416 
00417   TF1 *fit_alphax = new TF1(name_alphax.str().c_str(), "[0] + x*[1]", min_dxdz, max_dxdz);
00418   fit_alphax->SetParameters(10.*value(kAlignX), 10.*value(kAlphaX)/1000.);
00419   TF1 *fit_alphay = new TF1(name_alphay.str().c_str(), "[0] + x*[1]", min_dydz, max_dydz);
00420   fit_alphay->SetParameters(10.*value(kAlignY), 10.*value(kAlphaY)/1000.);
00421 
00422   fit_alphax->SetLineColor(2);  fit_alphax->SetLineWidth(2);
00423   fit_alphay->SetLineColor(2);  fit_alphay->SetLineWidth(2);
00424   fit_alphax->Write();
00425   fit_alphay->Write();
00426 
00427   TProfile *fit_x_trackx = dir->make<TProfile>(name_x_trackx.str().c_str(), "", 100, min_trackx, max_trackx);
00428   TProfile *fit_y_trackx = dir->make<TProfile>(name_y_trackx.str().c_str(), "", 100, min_trackx, max_trackx);
00429   TProfile *fit_dxdz_trackx = dir->make<TProfile>(name_dxdz_trackx.str().c_str(), "", 100, min_trackx, max_trackx);
00430   TProfile *fit_dydz_trackx = dir->make<TProfile>(name_dydz_trackx.str().c_str(), "", 100, min_trackx, max_trackx);
00431   TProfile *fit_x_tracky = dir->make<TProfile>(name_x_tracky.str().c_str(), "", 100, min_tracky, max_tracky);
00432   TProfile *fit_y_tracky = dir->make<TProfile>(name_y_tracky.str().c_str(), "", 100, min_tracky, max_tracky);
00433   TProfile *fit_dxdz_tracky = dir->make<TProfile>(name_dxdz_tracky.str().c_str(), "", 100, min_tracky, max_tracky);
00434   TProfile *fit_dydz_tracky = dir->make<TProfile>(name_dydz_tracky.str().c_str(), "", 100, min_tracky, max_tracky);
00435   TProfile *fit_x_trackdxdz = dir->make<TProfile>(name_x_trackdxdz.str().c_str(), "", 500, min_trackdxdz, max_trackdxdz);
00436   TProfile *fit_y_trackdxdz = dir->make<TProfile>(name_y_trackdxdz.str().c_str(), "", 500, min_trackdxdz, max_trackdxdz);
00437   TProfile *fit_dxdz_trackdxdz = dir->make<TProfile>(name_dxdz_trackdxdz.str().c_str(), "", 500, min_trackdxdz, max_trackdxdz);
00438   TProfile *fit_dydz_trackdxdz = dir->make<TProfile>(name_dydz_trackdxdz.str().c_str(), "", 500, min_trackdxdz, max_trackdxdz);
00439   TProfile *fit_x_trackdydz = dir->make<TProfile>(name_x_trackdydz.str().c_str(), "", 500, min_trackdydz, max_trackdydz);
00440   TProfile *fit_y_trackdydz = dir->make<TProfile>(name_y_trackdydz.str().c_str(), "", 500, min_trackdydz, max_trackdydz);
00441   TProfile *fit_dxdz_trackdydz = dir->make<TProfile>(name_dxdz_trackdydz.str().c_str(), "", 500, min_trackdydz, max_trackdydz);
00442   TProfile *fit_dydz_trackdydz = dir->make<TProfile>(name_dydz_trackdydz.str().c_str(), "", 500, min_trackdydz, max_trackdydz);
00443 
00444   fit_x_trackx->SetLineColor(2);        fit_x_trackx->SetLineWidth(2);
00445   fit_y_trackx->SetLineColor(2);        fit_y_trackx->SetLineWidth(2);
00446   fit_dxdz_trackx->SetLineColor(2);     fit_dxdz_trackx->SetLineWidth(2);
00447   fit_dydz_trackx->SetLineColor(2);     fit_dydz_trackx->SetLineWidth(2);
00448   fit_x_tracky->SetLineColor(2);        fit_x_tracky->SetLineWidth(2);
00449   fit_y_tracky->SetLineColor(2);        fit_y_tracky->SetLineWidth(2);
00450   fit_dxdz_tracky->SetLineColor(2);     fit_dxdz_tracky->SetLineWidth(2);
00451   fit_dydz_tracky->SetLineColor(2);     fit_dydz_tracky->SetLineWidth(2);
00452   fit_x_trackdxdz->SetLineColor(2);     fit_x_trackdxdz->SetLineWidth(2);
00453   fit_y_trackdxdz->SetLineColor(2);     fit_y_trackdxdz->SetLineWidth(2);
00454   fit_dxdz_trackdxdz->SetLineColor(2);  fit_dxdz_trackdxdz->SetLineWidth(2);
00455   fit_dydz_trackdxdz->SetLineColor(2);  fit_dydz_trackdxdz->SetLineWidth(2);
00456   fit_x_trackdydz->SetLineColor(2);     fit_x_trackdydz->SetLineWidth(2);
00457   fit_y_trackdydz->SetLineColor(2);     fit_y_trackdydz->SetLineWidth(2);
00458   fit_dxdz_trackdydz->SetLineColor(2);  fit_dxdz_trackdydz->SetLineWidth(2);
00459   fit_dydz_trackdydz->SetLineColor(2);  fit_dydz_trackdydz->SetLineWidth(2);
00460 
00461   name_x_trackx << "line";
00462   name_y_trackx << "line";
00463   name_dxdz_trackx << "line";
00464   name_dydz_trackx << "line";
00465   name_x_tracky << "line";
00466   name_y_tracky << "line";
00467   name_dxdz_tracky << "line";
00468   name_dydz_tracky << "line";
00469   name_x_trackdxdz << "line";
00470   name_y_trackdxdz << "line";
00471   name_dxdz_trackdxdz << "line";
00472   name_dydz_trackdxdz << "line";
00473   name_x_trackdydz << "line";
00474   name_y_trackdydz << "line";
00475   name_dxdz_trackdydz << "line";
00476   name_dydz_trackdydz << "line";
00477 
00478   TF1 *fitline_x_trackx = new TF1(name_x_trackx.str().c_str(), MuonResiduals6DOFFitter_x_trackx_TF1, min_trackx, max_trackx, 14);
00479   TF1 *fitline_y_trackx = new TF1(name_y_trackx.str().c_str(), MuonResiduals6DOFFitter_y_trackx_TF1, min_trackx, max_trackx, 14);
00480   TF1 *fitline_dxdz_trackx = new TF1(name_dxdz_trackx.str().c_str(), MuonResiduals6DOFFitter_dxdz_trackx_TF1, min_trackx, max_trackx, 14);
00481   TF1 *fitline_dydz_trackx = new TF1(name_dydz_trackx.str().c_str(), MuonResiduals6DOFFitter_dydz_trackx_TF1, min_trackx, max_trackx, 14);
00482   TF1 *fitline_x_tracky = new TF1(name_x_tracky.str().c_str(), MuonResiduals6DOFFitter_x_tracky_TF1, min_tracky, max_tracky, 14);
00483   TF1 *fitline_y_tracky = new TF1(name_y_tracky.str().c_str(), MuonResiduals6DOFFitter_y_tracky_TF1, min_tracky, max_tracky, 14);
00484   TF1 *fitline_dxdz_tracky = new TF1(name_dxdz_tracky.str().c_str(), MuonResiduals6DOFFitter_dxdz_tracky_TF1, min_tracky, max_tracky, 14);
00485   TF1 *fitline_dydz_tracky = new TF1(name_dydz_tracky.str().c_str(), MuonResiduals6DOFFitter_dydz_tracky_TF1, min_tracky, max_tracky, 14);
00486   TF1 *fitline_x_trackdxdz = new TF1(name_x_trackdxdz.str().c_str(), MuonResiduals6DOFFitter_x_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
00487   TF1 *fitline_y_trackdxdz = new TF1(name_y_trackdxdz.str().c_str(), MuonResiduals6DOFFitter_y_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
00488   TF1 *fitline_dxdz_trackdxdz = new TF1(name_dxdz_trackdxdz.str().c_str(), MuonResiduals6DOFFitter_dxdz_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
00489   TF1 *fitline_dydz_trackdxdz = new TF1(name_dydz_trackdxdz.str().c_str(), MuonResiduals6DOFFitter_dydz_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 14);
00490   TF1 *fitline_x_trackdydz = new TF1(name_x_trackdydz.str().c_str(), MuonResiduals6DOFFitter_x_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
00491   TF1 *fitline_y_trackdydz = new TF1(name_y_trackdydz.str().c_str(), MuonResiduals6DOFFitter_y_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
00492   TF1 *fitline_dxdz_trackdydz = new TF1(name_dxdz_trackdydz.str().c_str(), MuonResiduals6DOFFitter_dxdz_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
00493   TF1 *fitline_dydz_trackdydz = new TF1(name_dydz_trackdydz.str().c_str(), MuonResiduals6DOFFitter_dydz_trackdydz_TF1, min_trackdydz, max_trackdydz, 14);
00494 
00495   double sum_resslopex = 0.;
00496   double sum_resslopey = 0.;
00497   double sum_trackx = 0.;
00498   double sum_tracky = 0.;
00499   double sum_trackdxdz = 0.;
00500   double sum_trackdydz = 0.;
00501   for (std::vector<double*>::const_iterator resiter = residuals_begin();  resiter != residuals_end();  ++resiter) {
00502     const double resslopeX = (*resiter)[MuonResiduals6DOFFitter::kResSlopeX];
00503     const double resslopeY = (*resiter)[MuonResiduals6DOFFitter::kResSlopeY];
00504     const double positionX = (*resiter)[MuonResiduals6DOFFitter::kPositionX];
00505     const double positionY = (*resiter)[MuonResiduals6DOFFitter::kPositionY];
00506     const double angleX = (*resiter)[MuonResiduals6DOFFitter::kAngleX];
00507     const double angleY = (*resiter)[MuonResiduals6DOFFitter::kAngleY];
00508     const double redchi2 = (*resiter)[MuonResiduals6DOFFitter::kRedChi2];
00509     double weight = 1./redchi2;
00510     if (!m_weightAlignment) weight = 1.;
00511 
00512     if (!m_weightAlignment  ||  TMath::Prob(redchi2*12, 12) < 0.99) {  // no spikes allowed
00513       sum_resslopex += weight * resslopeX;
00514       sum_resslopey += weight * resslopeY;
00515       sum_trackx += weight * positionX;
00516       sum_tracky += weight * positionY;
00517       sum_trackdxdz += weight * angleX;
00518       sum_trackdydz += weight * angleY;
00519     }
00520   }
00521   double mean_resslopex = sum_resslopex / MuonResiduals6DOFFitter_sum_of_weights;
00522   double mean_resslopey = sum_resslopey / MuonResiduals6DOFFitter_sum_of_weights;
00523   double mean_trackx = sum_trackx / MuonResiduals6DOFFitter_sum_of_weights;
00524   double mean_tracky = sum_tracky / MuonResiduals6DOFFitter_sum_of_weights;
00525   double mean_trackdxdz = sum_trackdxdz / MuonResiduals6DOFFitter_sum_of_weights;
00526   double mean_trackdydz = sum_trackdydz / MuonResiduals6DOFFitter_sum_of_weights;
00527 
00528   double fitparameters[14];
00529   fitparameters[0] = value(kAlignX);
00530   fitparameters[1] = value(kAlignY);
00531   fitparameters[2] = value(kAlignZ);
00532   fitparameters[3] = value(kAlignPhiX);
00533   fitparameters[4] = value(kAlignPhiY);
00534   fitparameters[5] = value(kAlignPhiZ);
00535   fitparameters[6] = mean_trackx;
00536   fitparameters[7] = mean_tracky;
00537   fitparameters[8] = mean_trackdxdz;
00538   fitparameters[9] = mean_trackdydz;
00539   fitparameters[10] = value(kAlphaX);
00540   fitparameters[11] = mean_resslopex;
00541   fitparameters[12] = value(kAlphaY);
00542   fitparameters[13] = mean_resslopey;
00543 
00544   fitline_x_trackx->SetParameters(fitparameters);
00545   fitline_y_trackx->SetParameters(fitparameters);
00546   fitline_dxdz_trackx->SetParameters(fitparameters);
00547   fitline_dydz_trackx->SetParameters(fitparameters);
00548   fitline_x_tracky->SetParameters(fitparameters);
00549   fitline_y_tracky->SetParameters(fitparameters);
00550   fitline_dxdz_tracky->SetParameters(fitparameters);
00551   fitline_dydz_tracky->SetParameters(fitparameters);
00552   fitline_x_trackdxdz->SetParameters(fitparameters);
00553   fitline_y_trackdxdz->SetParameters(fitparameters);
00554   fitline_dxdz_trackdxdz->SetParameters(fitparameters);
00555   fitline_dydz_trackdxdz->SetParameters(fitparameters);
00556   fitline_x_trackdydz->SetParameters(fitparameters);
00557   fitline_y_trackdydz->SetParameters(fitparameters);
00558   fitline_dxdz_trackdydz->SetParameters(fitparameters);
00559   fitline_dydz_trackdydz->SetParameters(fitparameters);
00560 
00561   fitline_x_trackx->SetLineColor(2);        fitline_x_trackx->SetLineWidth(2);
00562   fitline_y_trackx->SetLineColor(2);        fitline_y_trackx->SetLineWidth(2);
00563   fitline_dxdz_trackx->SetLineColor(2);     fitline_dxdz_trackx->SetLineWidth(2);
00564   fitline_dydz_trackx->SetLineColor(2);     fitline_dydz_trackx->SetLineWidth(2);
00565   fitline_x_tracky->SetLineColor(2);        fitline_x_tracky->SetLineWidth(2);
00566   fitline_y_tracky->SetLineColor(2);        fitline_y_tracky->SetLineWidth(2);
00567   fitline_dxdz_tracky->SetLineColor(2);     fitline_dxdz_tracky->SetLineWidth(2);
00568   fitline_dydz_tracky->SetLineColor(2);     fitline_dydz_tracky->SetLineWidth(2);
00569   fitline_x_trackdxdz->SetLineColor(2);     fitline_x_trackdxdz->SetLineWidth(2);
00570   fitline_y_trackdxdz->SetLineColor(2);     fitline_y_trackdxdz->SetLineWidth(2);
00571   fitline_dxdz_trackdxdz->SetLineColor(2);  fitline_dxdz_trackdxdz->SetLineWidth(2);
00572   fitline_dydz_trackdxdz->SetLineColor(2);  fitline_dydz_trackdxdz->SetLineWidth(2);
00573   fitline_x_trackdydz->SetLineColor(2);     fitline_x_trackdydz->SetLineWidth(2);
00574   fitline_y_trackdydz->SetLineColor(2);     fitline_y_trackdydz->SetLineWidth(2);
00575   fitline_dxdz_trackdydz->SetLineColor(2);  fitline_dxdz_trackdydz->SetLineWidth(2);
00576   fitline_dydz_trackdydz->SetLineColor(2);  fitline_dydz_trackdydz->SetLineWidth(2);
00577 
00578   fitline_x_trackx->Write();
00579   fitline_y_trackx->Write();
00580   fitline_dxdz_trackx->Write();
00581   fitline_dydz_trackx->Write();
00582   fitline_x_tracky->Write();
00583   fitline_y_tracky->Write();
00584   fitline_dxdz_tracky->Write();
00585   fitline_dydz_tracky->Write();
00586   fitline_x_trackdxdz->Write();
00587   fitline_y_trackdxdz->Write();
00588   fitline_dxdz_trackdxdz->Write();
00589   fitline_dydz_trackdxdz->Write();
00590   fitline_x_trackdydz->Write();
00591   fitline_y_trackdydz->Write();
00592   fitline_dxdz_trackdydz->Write();
00593   fitline_dydz_trackdydz->Write();
00594 
00595   for (std::vector<double*>::const_iterator resiter = residuals_begin();  resiter != residuals_end();  ++resiter) {
00596     const double residX = (*resiter)[MuonResiduals6DOFFitter::kResidX];
00597     const double residY = (*resiter)[MuonResiduals6DOFFitter::kResidY];
00598     const double resslopeX = (*resiter)[MuonResiduals6DOFFitter::kResSlopeX];
00599     const double resslopeY = (*resiter)[MuonResiduals6DOFFitter::kResSlopeY];
00600     const double positionX = (*resiter)[MuonResiduals6DOFFitter::kPositionX];
00601     const double positionY = (*resiter)[MuonResiduals6DOFFitter::kPositionY];
00602     const double angleX = (*resiter)[MuonResiduals6DOFFitter::kAngleX];
00603     const double angleY = (*resiter)[MuonResiduals6DOFFitter::kAngleY];
00604     const double redchi2 = (*resiter)[MuonResiduals6DOFFitter::kRedChi2];
00605     double weight = 1./redchi2;
00606     if (!m_weightAlignment) weight = 1.;
00607 
00608     if (!m_weightAlignment  ||  TMath::Prob(redchi2*12, 12) < 0.99) {  // no spikes allowed
00609 
00610       hist_alphax->Fill(1000.*resslopeX, 10.*residX);
00611       hist_alphay->Fill(1000.*resslopeY, 10.*residY);
00612 
00613       double geom_residX = MuonResiduals6DOFFitter_x(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY, value(kAlphaX), resslopeX);
00614       hist_x->Fill(10.*(residX - geom_residX + value(kAlignX)), weight);
00615       hist_x_trackx->Fill(positionX, 10.*residX, weight);
00616       hist_x_tracky->Fill(positionY, 10.*residX, weight);
00617       hist_x_trackdxdz->Fill(angleX, 10.*residX, weight);
00618       hist_x_trackdydz->Fill(angleY, 10.*residX, weight);
00619       fit_x_trackx->Fill(positionX, 10.*geom_residX, weight);
00620       fit_x_tracky->Fill(positionY, 10.*geom_residX, weight);
00621       fit_x_trackdxdz->Fill(angleX, 10.*geom_residX, weight);
00622       fit_x_trackdydz->Fill(angleY, 10.*geom_residX, weight);
00623 
00624       double geom_residY = MuonResiduals6DOFFitter_y(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY, value(kAlphaY), resslopeY);
00625       hist_y->Fill(10.*(residY - geom_residY + value(kAlignY)), weight);
00626       hist_y_trackx->Fill(positionX, 10.*residY, weight);
00627       hist_y_tracky->Fill(positionY, 10.*residY, weight);
00628       hist_y_trackdxdz->Fill(angleX, 10.*residY, weight);
00629       hist_y_trackdydz->Fill(angleY, 10.*residY, weight);
00630       fit_y_trackx->Fill(positionX, 10.*geom_residY, weight);
00631       fit_y_tracky->Fill(positionY, 10.*geom_residY, weight);
00632       fit_y_trackdxdz->Fill(angleX, 10.*geom_residY, weight);
00633       fit_y_trackdydz->Fill(angleY, 10.*geom_residY, weight);
00634 
00635       double geom_resslopeX = MuonResiduals6DOFFitter_dxdz(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY);
00636       hist_dxdz->Fill(1000.*(resslopeX - geom_resslopeX + value(kAlignPhiY)), weight);
00637       hist_dxdz_trackx->Fill(positionX, 1000.*resslopeX, weight);
00638       hist_dxdz_tracky->Fill(positionY, 1000.*resslopeX, weight);
00639       hist_dxdz_trackdxdz->Fill(angleX, 1000.*resslopeX, weight);
00640       hist_dxdz_trackdydz->Fill(angleY, 1000.*resslopeX, weight);
00641       fit_dxdz_trackx->Fill(positionX, 1000.*geom_resslopeX, weight);
00642       fit_dxdz_tracky->Fill(positionY, 1000.*geom_resslopeX, weight);
00643       fit_dxdz_trackdxdz->Fill(angleX, 1000.*geom_resslopeX, weight);
00644       fit_dxdz_trackdydz->Fill(angleY, 1000.*geom_resslopeX, weight);
00645 
00646       double geom_resslopeY = MuonResiduals6DOFFitter_dydz(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY);
00647       hist_dydz->Fill(1000.*(resslopeY - geom_resslopeY - value(kAlignPhiX)), weight);
00648       hist_dydz_trackx->Fill(positionX, 1000.*resslopeY, weight);
00649       hist_dydz_tracky->Fill(positionY, 1000.*resslopeY, weight);
00650       hist_dydz_trackdxdz->Fill(angleX, 1000.*resslopeY, weight);
00651       hist_dydz_trackdydz->Fill(angleY, 1000.*resslopeY, weight);
00652       fit_dydz_trackx->Fill(positionX, 1000.*geom_resslopeY, weight);
00653       fit_dydz_tracky->Fill(positionY, 1000.*geom_resslopeY, weight);
00654       fit_dydz_trackdxdz->Fill(angleX, 1000.*geom_resslopeY, weight);
00655       fit_dydz_trackdydz->Fill(angleY, 1000.*geom_resslopeY, weight);
00656     }
00657 
00658     hist_x_raw->Fill(10.*residX);
00659     hist_y_raw->Fill(10.*residY);
00660     hist_dxdz_raw->Fill(1000.*resslopeX);
00661     hist_dydz_raw->Fill(1000.*resslopeY);
00662     if (fabs(resslopeX) < 0.005) hist_x_cut->Fill(10.*residX);
00663     if (fabs(resslopeY) < 0.030) hist_y_cut->Fill(10.*residY);
00664   }
00665 
00666   double chi2 = 0.;
00667   double ndof = 0.;
00668   for (int i = 1;  i <= hist_x->GetNbinsX();  i++) {
00669     double xi = hist_x->GetBinCenter(i);
00670     double yi = hist_x->GetBinContent(i);
00671     double yerri = hist_x->GetBinError(i);
00672     double yth = fit_x->Eval(xi);
00673     if (yerri > 0.) {
00674       chi2 += pow((yth - yi)/yerri, 2);
00675       ndof += 1.;
00676     }
00677   }
00678   for (int i = 1;  i <= hist_y->GetNbinsX();  i++) {
00679     double xi = hist_y->GetBinCenter(i);
00680     double yi = hist_y->GetBinContent(i);
00681     double yerri = hist_y->GetBinError(i);
00682     double yth = fit_y->Eval(xi);
00683     if (yerri > 0.) {
00684       chi2 += pow((yth - yi)/yerri, 2);
00685       ndof += 1.;
00686     }
00687   }
00688   for (int i = 1;  i <= hist_dxdz->GetNbinsX();  i++) {
00689     double xi = hist_dxdz->GetBinCenter(i);
00690     double yi = hist_dxdz->GetBinContent(i);
00691     double yerri = hist_dxdz->GetBinError(i);
00692     double yth = fit_dxdz->Eval(xi);
00693     if (yerri > 0.) {
00694       chi2 += pow((yth - yi)/yerri, 2);
00695       ndof += 1.;
00696     }
00697   }
00698   for (int i = 1;  i <= hist_dydz->GetNbinsX();  i++) {
00699     double xi = hist_dydz->GetBinCenter(i);
00700     double yi = hist_dydz->GetBinContent(i);
00701     double yerri = hist_dydz->GetBinError(i);
00702     double yth = fit_dydz->Eval(xi);
00703     if (yerri > 0.) {
00704       chi2 += pow((yth - yi)/yerri, 2);
00705       ndof += 1.;
00706     }
00707   }
00708   ndof -= npar();
00709 
00710   return (ndof > 0. ? chi2 / ndof : -1.);
00711 }