CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Member Functions

MuonResiduals1DOFFitter Class Reference

#include <MuonResiduals1DOFFitter.h>

Inheritance diagram for MuonResiduals1DOFFitter:
MuonResidualsFitter

List of all members.

Public Types

enum  { kAlign = 0, kSigma, kGamma, kNPar }
enum  { kResid = 0, kRedChi2, kNData }

Public Member Functions

bool fit (Alignable *ali)
 MuonResiduals1DOFFitter (int residualsModel, int minHits, bool weightAlignment=true)
int ndata ()
int npar ()
double plot (std::string name, TFileDirectory *dir, Alignable *ali)
double sumofweights ()
int type () const

Protected Member Functions

void inform (TMinuit *tMinuit)

Detailed Description

$Date: Fri Apr 17 16:09:40 CDT 2009

Revision:
1.4
Author:
J. Pivarski - Texas A&M University <pivarski@physics.tamu.edu>

Definition at line 12 of file MuonResiduals1DOFFitter.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
kAlign 
kSigma 
kGamma 
kNPar 

Definition at line 14 of file MuonResiduals1DOFFitter.h.

       {
    kAlign = 0,
    kSigma,
    kGamma,
    kNPar
  };
anonymous enum
Enumerator:
kResid 
kRedChi2 
kNData 

Definition at line 21 of file MuonResiduals1DOFFitter.h.

       {
    kResid = 0,
    kRedChi2,
    kNData
  };

Constructor & Destructor Documentation

MuonResiduals1DOFFitter::MuonResiduals1DOFFitter ( int  residualsModel,
int  minHits,
bool  weightAlignment = true 
) [inline]

Member Function Documentation

bool MuonResiduals1DOFFitter::fit ( Alignable ali) [virtual]

Implements MuonResidualsFitter.

Definition at line 68 of file MuonResiduals1DOFFitter.cc.

References MuonResidualsFitter::dofit(), MuonResidualsFitter::fixed(), MuonResidualsFitter::initialize_table(), kAlign, kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPureGaussian, kRedChi2, kResid, kSigma, MuonResidualsFitter::m_weightAlignment, MuonResiduals1DOFFitter_FCN(), MultiGaussianStateTransform::N, AlCaRecoCosmics_cfg::name, funct::pow(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), mathSSE::sqrt(), ExpressReco_HICollisions_FallBack::step, sumofweights(), and CommonMethods::weight().

                                                {
  initialize_table();  // if not already initialized
  sumofweights();

  double resid_sum = 0.;
  double resid_sum2 = 0.;
  double resid_N = 0.;
  int N = 0;

  for (std::vector<double*>::const_iterator resiter = residuals_begin();  resiter != residuals_end();  ++resiter) {
    const double residual = (*resiter)[MuonResiduals1DOFFitter::kResid];
    const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
    double weight = 1./redchi2;
    if (!m_weightAlignment) weight = 1.;

    if (!m_weightAlignment  ||  TMath::Prob(redchi2*8, 8) < 0.99) {  // no spikes allowed
      if (fabs(residual) < 10.) {   // 10 cm
        resid_sum += weight * residual;
        resid_sum2 += weight * residual * residual;
        resid_N += weight;
        N++;
      }
    }
  }

  double resid_mean = resid_sum/resid_N;
  double resid_stdev = sqrt(resid_sum2/resid_N - pow(resid_sum/resid_N, 2));

  resid_sum = 0.;
  resid_sum2 = 0.;
  resid_N = 0.;

  for (std::vector<double*>::const_iterator resiter = residuals_begin();  resiter != residuals_end();  ++resiter) {
    const double residual = (*resiter)[MuonResiduals1DOFFitter::kResid];
    const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
    double weight = 1./redchi2;
    if (!m_weightAlignment) weight = 1.;

    if (!m_weightAlignment  ||  TMath::Prob(redchi2*8, 8) < 0.99) {  // no spikes allowed
      if (fabs(residual - resid_mean) < 2.5*resid_stdev) {
        resid_sum += weight * residual;
        resid_sum2 += weight * residual * residual;
        resid_N += weight;
      }
    }
  }

  resid_mean = resid_sum/resid_N;
  resid_stdev = sqrt(resid_sum2/resid_N - pow(resid_sum/resid_N, 2));

  std::vector<int> num;
  std::vector<std::string> name;
  std::vector<double> start;
  std::vector<double> step;
  std::vector<double> low;
  std::vector<double> high;

  if (fixed(kAlign)) {
  num.push_back(kAlign);          name.push_back(std::string("Align"));          start.push_back(0.);              step.push_back(0.01*resid_stdev);    low.push_back(0.);   high.push_back(0.);
  } else {
  num.push_back(kAlign);          name.push_back(std::string("Align"));          start.push_back(resid_mean);      step.push_back(0.01*resid_stdev);    low.push_back(0.);   high.push_back(0.);
  }
  num.push_back(kSigma);          name.push_back(std::string("Sigma"));          start.push_back(resid_stdev);     step.push_back(0.01*resid_stdev);    low.push_back(0.);   high.push_back(0.);
  if (residualsModel() != kPureGaussian && residualsModel() != kGaussPowerTails) {
  num.push_back(kGamma);          name.push_back(std::string("Gamma"));          start.push_back(0.1*resid_stdev); step.push_back(0.01*resid_stdev);    low.push_back(0.);   high.push_back(0.);
  }

  return dofit(&MuonResiduals1DOFFitter_FCN, num, name, start, step, low, high);
}
void MuonResiduals1DOFFitter::inform ( TMinuit *  tMinuit) [protected, virtual]

Implements MuonResidualsFitter.

Definition at line 9 of file MuonResiduals1DOFFitter.cc.

References MuonResiduals1DOFFitter_TMinuit.

int MuonResiduals1DOFFitter::ndata ( ) [inline, virtual]

Implements MuonResidualsFitter.

Definition at line 37 of file MuonResiduals1DOFFitter.h.

References kNData.

{ return kNData; };
int MuonResiduals1DOFFitter::npar ( ) [inline, virtual]
double MuonResiduals1DOFFitter::plot ( std::string  name,
TFileDirectory dir,
Alignable ali 
) [virtual]

Implements MuonResidualsFitter.

Definition at line 138 of file MuonResiduals1DOFFitter.cc.

References ExpressReco_HICollisions_FallBack::chi2, i, kAlign, kGamma, MuonResidualsFitter::kGaussPowerTails, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian, kRedChi2, kResid, MuonResidualsFitter::kROOTVoigt, kSigma, MuonResidualsFitter::m_weightAlignment, TFileDirectory::make(), MuonResiduals1DOFFitter_sum_of_weights, MuonResidualsFitter_GaussPowerTails_TF1(), MuonResidualsFitter_powerLawTails_TF1(), MuonResidualsFitter_pureGaussian_TF1(), MuonResidualsFitter_ROOTVoigt_TF1(), npar(), NULL, funct::pow(), MuonResidualsFitter::residuals_begin(), MuonResidualsFitter::residuals_end(), MuonResidualsFitter::residualsModel(), sumofweights(), MuonResidualsFitter::value(), and CommonMethods::weight().

                                                                                        {
  sumofweights();

  std::stringstream name_residual, name_residual_raw;
  name_residual << name << "_residual";
  name_residual_raw << name << "_residual_raw";

  double min_residual = -100.;     double max_residual = 100.;
  TH1F *hist_residual = dir->make<TH1F>(name_residual.str().c_str(), "", 100, min_residual, max_residual);
  TH1F *hist_residual_raw = dir->make<TH1F>(name_residual_raw.str().c_str(), "", 100, min_residual, max_residual);

  name_residual << "_fit";
  TF1 *fit_residual = NULL;
  if (residualsModel() == kPureGaussian) {
    fit_residual = new TF1(name_residual.str().c_str(), MuonResidualsFitter_pureGaussian_TF1, min_residual, max_residual, 3);
    fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual)/100., 10.*value(kAlign), 10.*value(kSigma));
  }
  else if (residualsModel() == kPowerLawTails) {
    fit_residual = new TF1(name_residual.str().c_str(), MuonResidualsFitter_powerLawTails_TF1, min_residual, max_residual, 4);
    fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual)/100., 10.*value(kAlign), 10.*value(kSigma), 10.*value(kGamma));
  }
  else if (residualsModel() == kROOTVoigt) {
    fit_residual = new TF1(name_residual.str().c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_residual, max_residual, 4);
    fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual)/100., 10.*value(kAlign), 10.*value(kSigma), 10.*value(kGamma));
  }
  else if (residualsModel() == kGaussPowerTails) {
    fit_residual = new TF1(name_residual.str().c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_residual, max_residual, 3);
    fit_residual->SetParameters(MuonResiduals1DOFFitter_sum_of_weights * (max_residual - min_residual)/100., 10.*value(kAlign), 10.*value(kSigma));
  }
  else { assert(false); }

  fit_residual->SetLineColor(2);  fit_residual->SetLineWidth(2);
  fit_residual->Write();

  for (std::vector<double*>::const_iterator resiter = residuals_begin();  resiter != residuals_end();  ++resiter) {
    const double resid = (*resiter)[MuonResiduals1DOFFitter::kResid];
    const double redchi2 = (*resiter)[MuonResiduals1DOFFitter::kRedChi2];
    double weight = 1./redchi2;
    if (!m_weightAlignment) weight = 1.;

    if (!m_weightAlignment  ||  TMath::Prob(redchi2*8, 8) < 0.99) {  // no spikes allowed
      hist_residual->Fill(10.*(resid + value(kAlign)), weight);
    }

    hist_residual_raw->Fill(10.*resid);
  }

  double chi2 = 0.;
  double ndof = 0.;
  for (int i = 1;  i <= hist_residual->GetNbinsX();  i++) {
    double xi = hist_residual->GetBinCenter(i);
    double yi = hist_residual->GetBinContent(i);
    double yerri = hist_residual->GetBinError(i);
    double yth = fit_residual->Eval(xi);
    if (yerri > 0.) {
      chi2 += pow((yth - yi)/yerri, 2);
      ndof += 1.;
    }
  }
  ndof -= npar();

  return (ndof > 0. ? chi2 / ndof : -1.);
}
double MuonResiduals1DOFFitter::sumofweights ( ) [virtual]
int MuonResiduals1DOFFitter::type ( ) const [inline, virtual]

Implements MuonResidualsFitter.

Definition at line 29 of file MuonResiduals1DOFFitter.h.

References MuonResidualsFitter::k1DOF.