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

#include <MuonResiduals6DOFrphiFitter.h>

Inheritance diagram for MuonResiduals6DOFrphiFitter:
MuonResidualsFitter

Public Types

enum  {
  kAlignX = 0, kAlignY, kAlignZ, kAlignPhiX,
  kAlignPhiY, kAlignPhiZ, kResidSigma, kResSlopeSigma,
  kAlpha, kResidGamma, kResSlopeGamma, kNPar
}
 
enum  {
  kResid = 0, kResSlope, 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)
 
 MuonResiduals6DOFrphiFitter (int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)
 
 MuonResiduals6DOFrphiFitter (int residualsModel, int minHits, int useResiduals, const CSCGeometry *cscGeometry, bool weightAlignment=true)
 
int ndata ()
 
int npar ()
 
double plot (std::string name, TFileDirectory *dir, Alignable *ali)
 
TTree * readNtuple (std::string fname, unsigned int endcap, unsigned int station, unsigned int ring, unsigned int chamber, unsigned int preselected=1)
 
double sumofweights ()
 
int type () const
 
virtual ~MuonResiduals6DOFrphiFitter ()
 
- 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 21:29:15 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 19 of file MuonResiduals6DOFrphiFitter.h.

Member Enumeration Documentation

anonymous enum
anonymous enum

Constructor & Destructor Documentation

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

Definition at line 51 of file MuonResiduals6DOFrphiFitter.h.

51  :
tuple weightAlignment
Definition: align_cfg.py:30
MuonResidualsFitter(int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)
list useResiduals
Definition: align_cfg.py:36
MuonResiduals6DOFrphiFitter::MuonResiduals6DOFrphiFitter ( int  residualsModel,
int  minHits,
int  useResiduals,
const CSCGeometry cscGeometry,
bool  weightAlignment = true 
)
inline

Definition at line 55 of file MuonResiduals6DOFrphiFitter.h.

55  :
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 MuonResiduals6DOFrphiFitter::~MuonResiduals6DOFrphiFitter ( )
inlinevirtual

Definition at line 59 of file MuonResiduals6DOFrphiFitter.h.

59 {}

Member Function Documentation

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

Implements MuonResidualsFitter.

Definition at line 195 of file MuonResiduals6DOFrphiFitter.cc.

References MuonResidualsFitter::dofit(), MuonResidualsFitter::fix(), Alignable::globalPosition(), i, customizeTrackingMonitorSeedNumber::idx, MuonResidualsFitter::initialize_table(), MuonResidualsFitter::k0010, MuonResidualsFitter::k1010, MuonResidualsFitter::k1100, MuonResidualsFitter::k1110, MuonResidualsFitter::k1111, kAlignPhiX, kAlignPhiY, kAlignPhiZ, kAlignX, kAlignZ, kAlpha, MuonResidualsFitter::kPowerLawTails, MuonResidualsFitter::kPureGaussian2D, kResidGamma, kResidSigma, kResSlopeGamma, kResSlopeSigma, MuonResidualsFitter::kROOTVoigt, MuonResiduals6DOFrphiFitter_FCN(), mergeVDriftHistosByStation::name, cscdqm::h::names, pileupDistInMC::num, funct::pow(), MuonResidualsFitter::residualsModel(), mathSSE::sqrt(), dqm_diff::start, relval_parameters_module::step, relval_machine::steps, AlCaHLTBitMon_QueryRunRegistry::string, sumofweights(), MuonResidualsFitter::useRes(), PV3DBase< T, PVType, FrameType >::x(), and PV3DBase< T, PVType, FrameType >::y().

196 {
197  //cscGeometry = m_cscGeometry;
198  //cscDetId = CSCDetId(ali->geomDetId().rawId());
199 
200 #ifndef STANDALONE_FITTER
201  csc_R = sqrt(pow(ali->globalPosition().x(), 2) + pow(ali->globalPosition().y(), 2));
202 #else
203  csc_R = 200; // not important what number it is, as we usually not use the DOF where it matters
204 #endif
205 
206  initialize_table(); // if not already initialized
207  sumofweights();
208 
209  double res_std = 0.5;
210  double resslope_std = 0.002;
211 
213  std::string names[10] = {"AlignX","AlignZ","AlignPhiX","AlignPhiY","AlignPhiZ", "ResidSigma","ResSlopeSigma", "Alpha", "ResidGamma","ResSlopeGamma"};
214  double starts[10] = {0., 0., 0., 0., 0., res_std, resslope_std, 0., 0.1*res_std, 0.1*resslope_std};
215  double steps[10] = {0.1, 0.1, 0.001, 0.001, 0.001, 0.001*res_std, 0.001*resslope_std, 0.001, 0.01*res_std, 0.01*resslope_std};
216  double lows[10] = {0., 0., 0., 0., 0., 0., 0., -1., 0., 0.};
217  double highs[10] = {0., 0., 0., 0., 0., 10., 0.1, 1., 0., 0.};
218 
219  std::vector<int> num(nums, nums+5);
220  std::vector<std::string> name(names, names+5);
221  std::vector<double> start(starts, starts+5);
222  std::vector<double> step(steps, steps+5);
223  std::vector<double> low(lows, lows+5);
224  std::vector<double> high(highs, highs+5);
225 
226  bool add_alpha = ( residualsModel() == kPureGaussian2D);
227  bool add_gamma = ( residualsModel() == kROOTVoigt || residualsModel() == kPowerLawTails);
228 
229  int idx[4], ni = 0;
230  if (useRes() == k1111 || useRes() == k1110 || useRes() == k1010) {
231  for(ni=0; ni<2; ni++) idx[ni] = ni+5;
232  if (add_alpha) idx[ni++] = 7;
233  else if (add_gamma) for(; ni<4; ni++) idx[ni] = ni+6;
234  if (!add_alpha) fix(kAlpha);
235  }
236  else if (useRes() == k1100) {
237  idx[ni++] = 5;
238  if (add_gamma) idx[ni++] = 8;
240  fix(kAlpha);
241  }
242  else if (useRes() == k0010) {
243  idx[ni++] = 6;
244  if (add_gamma) idx[ni++] = 9;
245  fix(kResidSigma);
246  fix(kAlpha);
247  }
248  for (int i=0; i<ni; i++){
249  num.push_back(nums[idx[i]]);
250  name.push_back(names[idx[i]]);
251  start.push_back(starts[idx[i]]);
252  step.push_back(steps[idx[i]]);
253  low.push_back(lows[idx[i]]);
254  high.push_back(highs[idx[i]]);
255  }
256 
257  return dofit(&MuonResiduals6DOFrphiFitter_FCN, num, name, start, step, low, high);
258 }
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[]
T y() const
Definition: PV3DBase.h:63
bool dofit(void(*fcn)(int &, double *, double &, double *, int), std::vector< int > &parNum, std::vector< std::string > &parName, std::vector< double > &start, std::vector< double > &step, std::vector< double > &low, std::vector< double > &high)
T sqrt(T t)
Definition: SSEVec.h:48
void MuonResiduals6DOFrphiFitter_FCN(int &npar, double *gin, double &fval, double *par, int iflag)
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
const PositionType & globalPosition() const
Return the global position of the object.
Definition: Alignable.h:134
T x() const
Definition: PV3DBase.h:62
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
void MuonResiduals6DOFrphiFitter::inform ( TMinuit *  tMinuit)
protectedvirtual

Implements MuonResidualsFitter.

Definition at line 167 of file MuonResiduals6DOFrphiFitter.cc.

168 {
169  minuit = tMinuit;
170 }
int MuonResiduals6DOFrphiFitter::ndata ( )
inlinevirtual

Implements MuonResidualsFitter.

Definition at line 70 of file MuonResiduals6DOFrphiFitter.h.

References kNData.

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

Implements MuonResidualsFitter.

Definition at line 261 of file MuonResiduals6DOFrphiFitter.cc.

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

Referenced by cuy.FindIssue::__init__().

262 {
263  sumofweights();
264 
265  double mean_residual = 0., mean_resslope = 0.;
266  double mean_trackx = 0., mean_tracky = 0., mean_trackdxdz = 0., mean_trackdydz = 0.;
267  double sum_w = 0.;
268 
269  for (std::vector<double*>::const_iterator rit = residuals_begin(); rit != residuals_end(); ++rit)
270  {
271  const double redchi2 = (*rit)[kRedChi2];
272  double weight = 1./redchi2;
273  if (!m_weightAlignment) weight = 1.;
274 
275  if (!m_weightAlignment || TMath::Prob(redchi2*6, 6) < 0.99) // no spikes allowed
276  {
277  double factor_w = 1./(sum_w + weight);
278  mean_residual = factor_w * (sum_w * mean_residual + weight * (*rit)[kResid]);
279  mean_resslope = factor_w * (sum_w * mean_resslope + weight * (*rit)[kResSlope]);
280  mean_trackx = factor_w * (sum_w * mean_trackx + weight * (*rit)[kPositionX]);
281  mean_tracky = factor_w * (sum_w * mean_tracky + weight * (*rit)[kPositionY]);
282  mean_trackdxdz = factor_w * (sum_w * mean_trackdxdz + weight * (*rit)[kAngleX]);
283  mean_trackdydz = factor_w * (sum_w * mean_trackdydz + weight * (*rit)[kAngleY]);
284  sum_w += weight;
285  }
286  }
287 
288  std::string name_residual, name_resslope, name_residual_raw, name_resslope_raw, name_residual_cut, name_alpha;
289  std::string name_residual_trackx, name_resslope_trackx;
290  std::string name_residual_tracky, name_resslope_tracky;
291  std::string name_residual_trackdxdz, name_resslope_trackdxdz;
292  std::string name_residual_trackdydz, name_resslope_trackdydz;
293 
294  name_residual = name + "_residual";
295  name_resslope = name + "_resslope";
296  name_residual_raw = name + "_residual_raw";
297  name_resslope_raw = name + "_resslope_raw";
298  name_residual_cut = name + "_residual_cut";
299  name_alpha = name + "_alpha";
300  name_residual_trackx = name + "_residual_trackx";
301  name_resslope_trackx = name + "_resslope_trackx";
302  name_residual_tracky = name + "_residual_tracky";
303  name_resslope_tracky = name + "_resslope_tracky";
304  name_residual_trackdxdz = name + "_residual_trackdxdz";
305  name_resslope_trackdxdz = name + "_resslope_trackdxdz";
306  name_residual_trackdydz = name + "_residual_trackdydz";
307  name_resslope_trackdydz = name + "_resslope_trackdydz";
308 
309  double width = ali->surface().width();
310  double length = ali->surface().length();
311  int bins_residual = 100, bins_resslope = 100;
312  double min_residual = -50., max_residual = 50.;
313  double min_resslope = -50., max_resslope = 50.;
314  double min_trackx = -width/2., max_trackx = width/2.;
315  double min_tracky = -length/2., max_tracky = length/2.;
316  double min_trackdxdz = -1.5, max_trackdxdz = 1.5;
317  double min_trackdydz = -1.5, max_trackdydz = 1.5;
318 
319  TH1F *hist_residual = dir->make<TH1F>(name_residual.c_str(), "", bins_residual, min_residual, max_residual);
320  TH1F *hist_resslope = dir->make<TH1F>(name_resslope.c_str(), "", bins_resslope, min_resslope, max_resslope);
321  TH1F *hist_residual_raw = dir->make<TH1F>(name_residual_raw.c_str(), "", bins_residual, min_residual, max_residual);
322  TH1F *hist_resslope_raw = dir->make<TH1F>(name_resslope_raw.c_str(), "", bins_resslope, min_resslope, max_resslope);
323  TH1F *hist_residual_cut = dir->make<TH1F>(name_residual_cut.c_str(), "", bins_residual, min_residual, max_residual);
324  TH2F *hist_alpha = dir->make<TH2F>(name_alpha.c_str(),"", 50, min_resslope, max_resslope, 50, -50., 50.);
325 
326  TProfile *hist_residual_trackx = dir->make<TProfile>(name_residual_trackx.c_str(), "", 50, min_trackx, max_trackx, min_residual, max_residual);
327  TProfile *hist_resslope_trackx = dir->make<TProfile>(name_resslope_trackx.c_str(), "", 50, min_trackx, max_trackx, min_resslope, max_resslope);
328  TProfile *hist_residual_tracky = dir->make<TProfile>(name_residual_tracky.c_str(), "", 50, min_tracky, max_tracky, min_residual, max_residual);
329  TProfile *hist_resslope_tracky = dir->make<TProfile>(name_resslope_tracky.c_str(), "", 50, min_tracky, max_tracky, min_resslope, max_resslope);
330  TProfile *hist_residual_trackdxdz = dir->make<TProfile>(name_residual_trackdxdz.c_str(), "", 500, min_trackdxdz, max_trackdxdz, min_residual, max_residual);
331  TProfile *hist_resslope_trackdxdz = dir->make<TProfile>(name_resslope_trackdxdz.c_str(), "", 500, min_trackdxdz, max_trackdxdz, min_resslope, max_resslope);
332  TProfile *hist_residual_trackdydz = dir->make<TProfile>(name_residual_trackdydz.c_str(), "", 500, min_trackdydz, max_trackdydz, min_residual, max_residual);
333  TProfile *hist_resslope_trackdydz = dir->make<TProfile>(name_resslope_trackdydz.c_str(), "", 500, min_trackdydz, max_trackdydz, min_resslope, max_resslope);
334 
335  hist_residual_trackx->SetAxisRange(-10., 10., "Y");
336  hist_resslope_trackx->SetAxisRange(-10., 10., "Y");
337  hist_residual_tracky->SetAxisRange(-10., 10., "Y");
338  hist_resslope_tracky->SetAxisRange(-10., 10., "Y");
339  hist_residual_trackdxdz->SetAxisRange(-10., 10., "Y");
340  hist_resslope_trackdxdz->SetAxisRange(-10., 10., "Y");
341  hist_residual_trackdydz->SetAxisRange(-10., 10., "Y");
342  hist_resslope_trackdydz->SetAxisRange(-10., 10., "Y");
343 
344  name_residual += "_fit";
345  name_resslope += "_fit";
346  name_alpha += "_fit";
347  name_residual_trackx += "_fit";
348  name_resslope_trackx += "_fit";
349  name_residual_tracky += "_fit";
350  name_resslope_tracky += "_fit";
351  name_residual_trackdxdz += "_fit";
352  name_resslope_trackdxdz += "_fit";
353  name_residual_trackdydz += "_fit";
354  name_resslope_trackdydz += "_fit";
355 
356  TF1 *fit_residual = NULL;
357  TF1 *fit_resslope = NULL;
359  fit_residual = new TF1(name_residual.c_str(), MuonResidualsFitter_pureGaussian_TF1, min_residual, max_residual, 3);
360  fit_residual->SetParameters(sum_of_weights * (max_residual - min_residual)/bins_residual, 10.*value(kAlignX), 10.*value(kResidSigma));
361  const double er_res[3] = {0., 10.*errorerror(kAlignX), 10.*errorerror(kResidSigma)};
362  fit_residual->SetParErrors(er_res);
363  fit_resslope = new TF1(name_resslope.c_str(), MuonResidualsFitter_pureGaussian_TF1, min_resslope, max_resslope, 3);
364  fit_resslope->SetParameters(sum_of_weights * (max_resslope - min_resslope)/bins_resslope, 1000.*value(kAlignPhiY), 1000.*value(kResSlopeSigma));
365  const double er_resslope[3] = {0., 1000.*errorerror(kAlignPhiY), 1000.*errorerror(kResSlopeSigma)};
366  fit_resslope->SetParErrors(er_resslope);
367  }
368  else if (residualsModel() == kPowerLawTails) {
369  fit_residual = new TF1(name_residual.c_str(), MuonResidualsFitter_powerLawTails_TF1, min_residual, max_residual, 4);
370  fit_residual->SetParameters(sum_of_weights * (max_residual - min_residual)/bins_residual, 10.*value(kAlignX), 10.*value(kResidSigma), 10.*value(kResidGamma));
371  fit_resslope = new TF1(name_resslope.c_str(), MuonResidualsFitter_powerLawTails_TF1, min_resslope, max_resslope, 4);
372  fit_resslope->SetParameters(sum_of_weights * (max_resslope - min_resslope)/bins_resslope, 1000.*value(kAlignPhiY), 1000.*value(kResSlopeSigma), 1000.*value(kResSlopeGamma));
373  }
374  else if (residualsModel() == kROOTVoigt) {
375  fit_residual = new TF1(name_residual.c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_residual, max_residual, 4);
376  fit_residual->SetParameters(sum_of_weights * (max_residual - min_residual)/bins_residual, 10.*value(kAlignX), 10.*value(kResidSigma), 10.*value(kResidGamma));
377  fit_resslope = new TF1(name_resslope.c_str(), MuonResidualsFitter_ROOTVoigt_TF1, min_resslope, max_resslope, 4);
378  fit_resslope->SetParameters(sum_of_weights * (max_resslope - min_resslope)/bins_resslope, 1000.*value(kAlignPhiY), 1000.*value(kResSlopeSigma), 1000.*value(kResSlopeGamma));
379  }
380  else if (residualsModel() == kGaussPowerTails) {
381  fit_residual = new TF1(name_residual.c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_residual, max_residual, 3);
382  fit_residual->SetParameters(sum_of_weights * (max_residual - min_residual)/bins_residual, 10.*value(kAlignX), 10.*value(kResidSigma));
383  fit_resslope = new TF1(name_resslope.c_str(), MuonResidualsFitter_GaussPowerTails_TF1, min_resslope, max_resslope, 3);
384  fit_resslope->SetParameters(sum_of_weights * (max_resslope - min_resslope)/bins_resslope, 1000.*value(kAlignPhiY), 1000.*value(kResSlopeSigma));
385  }
386  else { assert(false); }
387 
388  fit_residual->SetLineColor(2); fit_residual->SetLineWidth(2); fit_residual->Write();
389  fit_resslope->SetLineColor(2); fit_resslope->SetLineWidth(2); fit_resslope->Write();
390 
391  TF1 *fit_alpha = new TF1(name_alpha.c_str(), "[0] + x*[1]", min_resslope, max_resslope);
392  double a = 10.*value(kAlignX), b = 10.*value(kAlpha)/1000.;
394  {
395  double sx = 10.*value(kResidSigma), sy = 1000.*value(kResSlopeSigma), r = value(kAlpha);
396  a = mean_residual;
397  b = 0.;
398  if ( sx != 0. )
399  {
400  b = 1./(sy/sx*r);
401  a = - b * mean_resslope;
402  }
403  }
404  fit_alpha->SetParameters(a, b);
405  fit_alpha->SetLineColor(2); fit_alpha->SetLineWidth(2); fit_alpha->Write();
406 
407  TProfile *fit_residual_trackx = dir->make<TProfile>(name_residual_trackx.c_str(), "", 100, min_trackx, max_trackx);
408  TProfile *fit_resslope_trackx = dir->make<TProfile>(name_resslope_trackx.c_str(), "", 100, min_trackx, max_trackx);
409  TProfile *fit_residual_tracky = dir->make<TProfile>(name_residual_tracky.c_str(), "", 100, min_tracky, max_tracky);
410  TProfile *fit_resslope_tracky = dir->make<TProfile>(name_resslope_tracky.c_str(), "", 100, min_tracky, max_tracky);
411  TProfile *fit_residual_trackdxdz = dir->make<TProfile>(name_residual_trackdxdz.c_str(), "", 500, min_trackdxdz, max_trackdxdz);
412  TProfile *fit_resslope_trackdxdz = dir->make<TProfile>(name_resslope_trackdxdz.c_str(), "", 500, min_trackdxdz, max_trackdxdz);
413  TProfile *fit_residual_trackdydz = dir->make<TProfile>(name_residual_trackdydz.c_str(), "", 500, min_trackdydz, max_trackdydz);
414  TProfile *fit_resslope_trackdydz = dir->make<TProfile>(name_resslope_trackdydz.c_str(), "", 500, min_trackdydz, max_trackdydz);
415 
416  fit_residual_trackx->SetLineColor(2); fit_residual_trackx->SetLineWidth(2);
417  fit_resslope_trackx->SetLineColor(2); fit_resslope_trackx->SetLineWidth(2);
418  fit_residual_tracky->SetLineColor(2); fit_residual_tracky->SetLineWidth(2);
419  fit_resslope_tracky->SetLineColor(2); fit_resslope_tracky->SetLineWidth(2);
420  fit_residual_trackdxdz->SetLineColor(2); fit_residual_trackdxdz->SetLineWidth(2);
421  fit_resslope_trackdxdz->SetLineColor(2); fit_resslope_trackdxdz->SetLineWidth(2);
422  fit_residual_trackdydz->SetLineColor(2); fit_residual_trackdydz->SetLineWidth(2);
423  fit_resslope_trackdydz->SetLineColor(2); fit_resslope_trackdydz->SetLineWidth(2);
424 
425  name_residual_trackx += "line";
426  name_resslope_trackx += "line";
427  name_residual_tracky += "line";
428  name_resslope_tracky += "line";
429  name_residual_trackdxdz += "line";
430  name_resslope_trackdxdz += "line";
431  name_residual_trackdydz += "line";
432  name_resslope_trackdydz += "line";
433 
434  TF1 *fitline_residual_trackx = new TF1(name_residual_trackx.c_str(), residual_trackx_TF1, min_trackx, max_trackx, 12);
435  TF1 *fitline_resslope_trackx = new TF1(name_resslope_trackx.c_str(), resslope_trackx_TF1, min_trackx, max_trackx, 12);
436  TF1 *fitline_residual_tracky = new TF1(name_residual_tracky.c_str(), residual_tracky_TF1, min_tracky, max_tracky, 12);
437  TF1 *fitline_resslope_tracky = new TF1(name_resslope_tracky.c_str(), resslope_tracky_TF1, min_tracky, max_tracky, 12);
438  TF1 *fitline_residual_trackdxdz = new TF1(name_residual_trackdxdz.c_str(), residual_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 12);
439  TF1 *fitline_resslope_trackdxdz = new TF1(name_resslope_trackdxdz.c_str(), resslope_trackdxdz_TF1, min_trackdxdz, max_trackdxdz, 12);
440  TF1 *fitline_residual_trackdydz = new TF1(name_residual_trackdydz.c_str(), residual_trackdydz_TF1, min_trackdydz, max_trackdydz, 12);
441  TF1 *fitline_resslope_trackdydz = new TF1(name_resslope_trackdydz.c_str(), resslope_trackdydz_TF1, min_trackdydz, max_trackdydz, 12);
442 
443  std::vector< TF1* > fitlines;
444  fitlines.push_back(fitline_residual_trackx);
445  fitlines.push_back(fitline_resslope_trackx);
446  fitlines.push_back(fitline_residual_tracky);
447  fitlines.push_back(fitline_resslope_tracky);
448  fitlines.push_back(fitline_residual_trackdxdz);
449  fitlines.push_back(fitline_resslope_trackdxdz);
450  fitlines.push_back(fitline_residual_trackdydz);
451  fitlines.push_back(fitline_resslope_trackdydz);
452 
453  double fitparameters[12] = {value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ),
454  mean_trackx, mean_tracky, mean_trackdxdz, mean_trackdydz, value(kAlpha), mean_resslope};
455  if (residualsModel() == kPureGaussian2D) fitparameters[10] = 0.;
456 
457  for(std::vector<TF1*>::const_iterator itr = fitlines.begin(); itr != fitlines.end(); itr++)
458  {
459  (*itr)->SetParameters(fitparameters);
460  (*itr)->SetLineColor(2);
461  (*itr)->SetLineWidth(2);
462  (*itr)->Write();
463  }
464 
465  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
466  const double resid = (*resiter)[kResid];
467  const double resslope = (*resiter)[kResSlope];
468  const double positionX = (*resiter)[kPositionX];
469  const double positionY = (*resiter)[kPositionY];
470  const double angleX = (*resiter)[kAngleX];
471  const double angleY = (*resiter)[kAngleY];
472  const double redchi2 = (*resiter)[kRedChi2];
473  double weight = 1./redchi2;
474  if (!m_weightAlignment) weight = 1.;
475 
476  if (!m_weightAlignment || TMath::Prob(redchi2*6, 6) < 0.99) { // no spikes allowed
477  hist_alpha->Fill(1000.*resslope, 10.*resid);
478 
479  double coeff = value(kAlpha);
480  if (residualsModel() == kPureGaussian || residualsModel() == kPureGaussian2D) coeff = 0.;
481  double geom_resid = getResidual(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY, effectiveR(positionX, positionY), coeff, resslope);
482  hist_residual->Fill(10.*(resid - geom_resid + value(kAlignX)), weight);
483  hist_residual_trackx->Fill(positionX, 10.*resid, weight);
484  hist_residual_tracky->Fill(positionY, 10.*resid, weight);
485  hist_residual_trackdxdz->Fill(angleX, 10.*resid, weight);
486  hist_residual_trackdydz->Fill(angleY, 10.*resid, weight);
487  fit_residual_trackx->Fill(positionX, 10.*geom_resid, weight);
488  fit_residual_tracky->Fill(positionY, 10.*geom_resid, weight);
489  fit_residual_trackdxdz->Fill(angleX, 10.*geom_resid, weight);
490  fit_residual_trackdydz->Fill(angleY, 10.*geom_resid, weight);
491 
492  double geom_resslope = getResSlope(value(kAlignX), value(kAlignY), value(kAlignZ), value(kAlignPhiX), value(kAlignPhiY), value(kAlignPhiZ), positionX, positionY, angleX, angleY, effectiveR(positionX, positionY));
493  hist_resslope->Fill(1000.*(resslope - geom_resslope + value(kAlignPhiY)), weight);
494  hist_resslope_trackx->Fill(positionX, 1000.*resslope, weight);
495  hist_resslope_tracky->Fill(positionY, 1000.*resslope, weight);
496  hist_resslope_trackdxdz->Fill(angleX, 1000.*resslope, weight);
497  hist_resslope_trackdydz->Fill(angleY, 1000.*resslope, weight);
498  fit_resslope_trackx->Fill(positionX, 1000.*geom_resslope, weight);
499  fit_resslope_tracky->Fill(positionY, 1000.*geom_resslope, weight);
500  fit_resslope_trackdxdz->Fill(angleX, 1000.*geom_resslope, weight);
501  fit_resslope_trackdydz->Fill(angleY, 1000.*geom_resslope, weight);
502  }
503 
504  hist_residual_raw->Fill(10.*resid);
505  hist_resslope_raw->Fill(1000.*resslope);
506  if (fabs(resslope) < 0.005) hist_residual_cut->Fill(10.*resid);
507  }
508 
509  double chi2 = 0.;
510  double ndof = 0.;
511  for (int i = 1; i <= hist_residual->GetNbinsX(); i++) {
512  double xi = hist_residual->GetBinCenter(i);
513  double yi = hist_residual->GetBinContent(i);
514  double yerri = hist_residual->GetBinError(i);
515  double yth = fit_residual->Eval(xi);
516  if (yerri > 0.) {
517  chi2 += pow((yth - yi)/yerri, 2);
518  ndof += 1.;
519  }
520  }
521  for (int i = 1; i <= hist_resslope->GetNbinsX(); i++) {
522  double xi = hist_resslope->GetBinCenter(i);
523  double yi = hist_resslope->GetBinContent(i);
524  double yerri = hist_resslope->GetBinError(i);
525  double yth = fit_resslope->Eval(xi);
526  if (yerri > 0.) {
527  chi2 += pow((yth - yi)/yerri, 2);
528  ndof += 1.;
529  }
530  }
531  ndof -= npar();
532 
533  return (ndof > 0. ? chi2 / ndof : -1.);
534 }
align::Scalar width() const
int i
Definition: DBlmapReader.cc:9
Double_t MuonResidualsFitter_powerLawTails_TF1(Double_t *xvec, Double_t *par)
assert(m_qm.get())
#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:131
Double_t MuonResidualsFitter_pureGaussian_TF1(Double_t *xvec, Double_t *par)
align::Scalar length() const
double errorerror(int parNum)
double b
Definition: hdecay.h:120
std::vector< double * >::const_iterator residuals_end() const
double a
Definition: hdecay.h:121
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 * MuonResiduals6DOFrphiFitter::readNtuple ( std::string  fname,
unsigned int  endcap,
unsigned int  station,
unsigned int  ring,
unsigned int  chamber,
unsigned int  preselected = 1 
)

Definition at line 537 of file MuonResiduals6DOFrphiFitter.cc.

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

538 {
539  TFile *f = new TFile(fname.c_str());
540  TTree *t = (TTree*)f->Get("mual_ttree");
541 
542  // Create new temporary file
543  TFile *tmpf = new TFile("small_tree_fit.root","recreate");
544  assert(tmpf!=0);
545 
546  // filter the tree (temporarily lives in the new file)
547  TTree *tt = t->CopyTree(Form("!is_dt && is_plus==%d && ring_wheel==%d && station==%d && sector==%d && select==%d", 2-endcap, station, ring, chamber, (bool)preselected));
548 
549  MuonAlignmentTreeRow r;
550  tt->SetBranchAddress("res_x", &r.res_x);
551  tt->SetBranchAddress("res_slope_x", &r.res_slope_x);
552  tt->SetBranchAddress("pos_x", &r.pos_x);
553  tt->SetBranchAddress("pos_y", &r.pos_y);
554  tt->SetBranchAddress("angle_x", &r.angle_x);
555  tt->SetBranchAddress("angle_y", &r.angle_y);
556  tt->SetBranchAddress("pz", &r.pz);
557  tt->SetBranchAddress("pt", &r.pt);
558  tt->SetBranchAddress("q", &r.q);
559 
560  Long64_t nentries = tt->GetEntries();
561  for (Long64_t i=0;i<nentries; i++)
562  {
563  tt->GetEntry(i);
564  double *rdata = new double[MuonResiduals6DOFrphiFitter::kNData];
565  rdata[kResid] = r.res_x;
566  rdata[kResSlope] = r.res_slope_x;
567  rdata[kPositionX] = r.pos_x;
568  rdata[kPositionY] = r.pos_y;
569  rdata[kAngleX] = r.angle_x;
570  rdata[kAngleY] = r.angle_y;
571  rdata[kRedChi2] = 0.1;
572  rdata[kPz] = r.pz;
573  rdata[kPt] = r.pt;
574  rdata[kCharge] = r.q;
575  fill(rdata);
576  }
577  delete f;
578  //delete tmpf;
579  return tt;
580 }
int i
Definition: DBlmapReader.cc:9
assert(m_qm.get())
void fill(double *residual)
double f[11][100]
string fname
main script
double MuonResiduals6DOFrphiFitter::sumofweights ( )
virtual

Implements MuonResidualsFitter.

Definition at line 173 of file MuonResiduals6DOFrphiFitter.cc.

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

Referenced by fit(), and plot().

174 {
175  sum_of_weights = 0.;
176  number_of_hits = 0.;
177  weight_alignment = m_weightAlignment;
178  for (std::vector<double*>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter) {
179  if (m_weightAlignment) {
180  double redchi2 = (*resiter)[kRedChi2];
181  if (TMath::Prob(redchi2*6, 6) < 0.99) { // no spikes allowed
182  sum_of_weights += 1./redchi2;
183  number_of_hits += 1.;
184  }
185  }
186  else {
187  sum_of_weights += 1.;
188  number_of_hits += 1.;
189  }
190  }
191  return sum_of_weights;
192 }
std::vector< double * >::const_iterator residuals_end() const
std::vector< double * >::const_iterator residuals_begin() const
int MuonResiduals6DOFrphiFitter::type ( ) const
inlinevirtual