CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
MuonResidualsFitter Class Referenceabstract

#include <MuonResidualsFitter.h>

Inheritance diagram for MuonResidualsFitter:
MuonResiduals1DOFFitter MuonResiduals5DOFFitter MuonResiduals6DOFFitter MuonResiduals6DOFrphiFitter MuonResidualsAngleFitter MuonResidualsBfieldAngleFitter MuonResidualsPositionFitter

Classes

struct  MuonAlignmentTreeRow
 

Public Types

enum  {
  kPureGaussian, kPowerLawTails, kROOTVoigt, kGaussPowerTails,
  kPureGaussian2D
}
 
enum  {
  k1DOF, k5DOF, k6DOF, k6DOFrphi,
  kPositionFitter, kAngleFitter, kAngleBfieldFitter
}
 
enum  {
  k1111, k1110, k1100, k1010,
  k0010, k1000, k0100
}
 

Public Member Functions

void computeHistogramRangeAndBinning (int which, int &nbins, double &a, double &b)
 
virtual void correctBField ()=0
 
virtual void correctBField (int idx_momentum, int idx_q)
 
TMatrixDSym correlationMatrix ()
 
double covarianceElement (int parNum1, int parNum2)
 
TMatrixDSym covarianceMatrix ()
 
void eraseNotSelectedResiduals ()
 
double errorerror (int parNum)
 
void fiducialCuts (double xMin=-80.0, double xMax=80.0, double yMin=-80.0, double yMax=80.0, bool fidcut1=false)
 
void fill (double *residual)
 
virtual bool fit (Alignable *ali)=0
 
void fix (int parNum, bool dofix=true)
 
bool fixed (int parNum)
 
void histogramChi2GaussianFit (int which, double &fit_mean, double &fit_sigma)
 
double loglikelihood ()
 
 MuonResidualsFitter (int residualsModel, int minHits, int useResiduals, bool weightAlignment=true)
 
virtual int ndata ()=0
 
int nfixed ()
 
virtual int npar ()=0
 
long numResiduals () const
 
long numsegments ()
 
int parNum2parIdx (int parNum)
 
virtual double plot (std::string name, TFileDirectory *dir, Alignable *ali)=0
 
void plotsimple (std::string name, TFileDirectory *dir, int which, double multiplier)
 
void plotweighted (std::string name, TFileDirectory *dir, int which, int whichredchi2, double multiplier)
 
void read (FILE *file, int which=0)
 
std::vector< double * >::const_iterator residuals_begin () const
 
std::vector< double * >::const_iterator residuals_end () const
 
int residualsModel () const
 
std::vector< bool > & selectedResidualsFlags ()
 
void selectPeakResiduals (double nsigma, int nvar, int *vars)
 
void selectPeakResiduals_simple (double nsigma, int nvar, int *vars)
 
void setInitialValue (int parNum, double value)
 
void setPrintLevel (int printLevel)
 
void setStrategy (int strategy)
 
virtual double sumofweights ()=0
 
virtual int type () const =0
 
int useRes (int pattern=-1)
 
double value (int parNum)
 
void write (FILE *file, int which=0)
 
virtual ~MuonResidualsFitter ()
 

Protected Member Functions

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)
 
virtual void inform (TMinuit *tMinuit)=0
 
void initialize_table ()
 

Protected Attributes

double m_center [20]
 
TMatrixDSym m_cov
 
std::vector< double > m_error
 
std::vector< bool > m_fixed
 
double m_loglikelihood
 
int m_minHits
 
std::map< int, double > m_parNum2InitValue
 
std::map< int, int > m_parNum2parIdx
 
int m_printLevel
 
double m_radii [20]
 
std::vector< double * > m_residuals
 
std::vector< bool > m_residuals_ok
 
int m_residualsModel
 
int m_strategy
 
int m_useResiduals
 
std::vector< double > m_value
 
bool m_weightAlignment
 

Detailed Description

Date
2011/04/15 21:51:13
Revision
1.16
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
Id
MuonResidualsFitter.h,v 1.16 2011/04/15 21:51:13 khotilov Exp

Definition at line 84 of file MuonResidualsFitter.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

◆ anonymous enum

anonymous enum

◆ anonymous enum

anonymous enum

Constructor & Destructor Documentation

◆ MuonResidualsFitter()

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

Definition at line 151 of file MuonResidualsFitter.cc.

References Exception, kGaussPowerTails, kPowerLawTails, kPureGaussian, kPureGaussian2D, kROOTVoigt, and m_residualsModel.

156  m_printLevel(0),
157  m_strategy(1),
158  m_cov(1),
159  m_loglikelihood(0.) {
162  throw cms::Exception("MuonResidualsFitter") << "unrecognized residualsModel";
163 }
tuple weightAlignment
Definition: align_cfg.py:30

◆ ~MuonResidualsFitter()

MuonResidualsFitter::~MuonResidualsFitter ( )
virtual

Definition at line 165 of file MuonResidualsFitter.cc.

References residuals_begin(), and residuals_end().

165  {
166  for (std::vector<double *>::const_iterator residual = residuals_begin(); residual != residuals_end(); ++residual) {
167  delete[](*residual);
168  }
169 }
std::vector< double * >::const_iterator residuals_begin() const
std::vector< double * >::const_iterator residuals_end() const

Member Function Documentation

◆ computeHistogramRangeAndBinning()

void MuonResidualsFitter::computeHistogramRangeAndBinning ( int  which,
int &  nbins,
double &  a,
double &  b 
)

Definition at line 510 of file MuonResidualsFitter.cc.

References a, b, gather_cfg::cout, data, mps_fire::i, createfilelist::int, m_residuals, dqmiodumpmetadata::n, LaserClient_cfi::nbins, numResiduals(), funct::pow(), alignCSCRings::r, jetUpdater_cfi::sort, and eostools::which().

Referenced by histogramChi2GaussianFit().

510  {
511  // first, make a numeric array while discarding some crazy outliers
512  double *data = new double[numResiduals()];
513  int n = 0;
514  for (std::vector<double *>::const_iterator r = m_residuals.begin(); r != m_residuals.end(); r++)
515  if (fabs((*r)[which]) < 50.) {
516  data[n] = (*r)[which];
517  n++;
518  }
519 
520  // compute "3 normal sigma" and regular interquantile ranges
521  const int n_quantiles = 7;
522  double probabilities[n_quantiles] = {0.00135, 0.02275, 0.25, 0.5, 0.75, 0.97725, 0.99865}; // "3 normal sigma"
523  //double probabilities[n_quantiles] = {0.02275, 0.25, 0.75, 0.97725}; // "2 normal sigma"
524  double quantiles[n_quantiles];
525  std::sort(data, data + n);
526  TMath::Quantiles(n, n_quantiles, data, quantiles, probabilities, true, nullptr, 7);
527  delete[] data;
528  double iqr = quantiles[4] - quantiles[2];
529 
530  // estimate optimal bin size according to Freedman-Diaconis rule
531  double hbin = 2 * iqr / pow(n, 1. / 3);
532 
533  a = quantiles[1];
534  b = quantiles[5];
535  nbins = (int)((b - a) / hbin + 3.); // add extra safety margin of 3
536 
537  std::cout << " quantiles: ";
538  for (int i = 0; i < n_quantiles; i++)
539  std::cout << quantiles[i] << " ";
540  std::cout << std::endl;
541  //cout<<"n="<<select_count<<" quantiles ["<<quantiles[1]<<", "<<quantiles[2]<<"] IQR="<<iqr
542  // <<" full range=["<<minx<<","<<maxx<<"]"<<" 2 normal sigma quantile range = ["<<quantiles[0]<<", "<<quantiles[3]<<"]"<<endl;
543  std::cout << " optimal h=" << hbin << " nbins=" << nbins << std::endl;
544 }
std::vector< double * > m_residuals
double b
Definition: hdecay.h:118
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
double a
Definition: hdecay.h:119
def which(cmd)
Definition: eostools.py:336
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ correctBField() [1/2]

virtual void MuonResidualsFitter::correctBField ( )
pure virtual

◆ correctBField() [2/2]

void MuonResidualsFitter::correctBField ( int  idx_momentum,
int  idx_q 
)
virtual

Definition at line 822 of file MuonResidualsFitter.cc.

References newFWLiteAna::bin, submitPVResolutionJobs::count, gather_cfg::cout, MillePedeFileConverter_cfg::e, mps_fire::i, createfilelist::int, dqmiolumiharvest::j, m_residuals, m_residuals_ok, cosmictrackSelector_cfi::min_pt, DiDispStaMuonMonitor_cfi::pt, alignCSCRings::r, residuals_begin(), residuals_end(), findQualityFiles::size, and jetUpdater_cfi::sort.

822  {
823  const int Nbin = 17;
824  // find max 1/pt and bin width
825  double min_pt = 9999.;
826  for (std::vector<double *>::const_iterator r = residuals_begin(); r != residuals_end(); ++r) {
827  double pt = fabs((*r)[idx_momentum]);
828  if (pt < min_pt)
829  min_pt = pt;
830  }
831  min_pt -= 0.01; // to prevent bin # overflow
832  const double bin_width = 1. / min_pt / Nbin;
833 
834  // fill indices of positive and negative charge residuals in each bin
835  std::vector<size_t> pos[Nbin], neg[Nbin], to_erase;
836  for (size_t i = 0; i < m_residuals.size(); i++) {
837  if (!m_residuals_ok[i])
838  continue;
839  int bin = (int)floor(1. / fabs(m_residuals[i][idx_momentum]) / bin_width);
840  if (m_residuals[i][idx_q] > 0)
841  pos[bin].push_back(i);
842  else
843  neg[bin].push_back(i);
844  }
845 
846  // equalize pos and neg in each bin
847  for (int j = 0; j < Nbin; j++) {
848  size_t psize = pos[j].size();
849  size_t nsize = neg[j].size();
850  if (psize == nsize)
851  continue;
852 
853  std::set<int> idx_set; // use a set to collect certain number of unique random indices to erase
854  if (psize > nsize) {
855  while (idx_set.size() < psize - nsize)
856  idx_set.insert(gRandom->Integer(psize));
857  for (std::set<int>::iterator it = idx_set.begin(); it != idx_set.end(); it++)
858  to_erase.push_back(pos[j][*it]);
859  } else {
860  while (idx_set.size() < nsize - psize)
861  idx_set.insert(gRandom->Integer(nsize));
862  for (std::set<int>::iterator it = idx_set.begin(); it != idx_set.end(); it++)
863  to_erase.push_back(neg[j][*it]);
864  }
865  }
866  // sort in descending order, so we safely go from higher to lower indices:
867  std::sort(to_erase.begin(), to_erase.end(), std::greater<int>());
868  for (std::vector<size_t>::const_iterator e = to_erase.begin(); e != to_erase.end(); ++e) {
869  m_residuals_ok[*e] = false;
870  //delete[] *(m_residuals.begin() + *e);
871  //m_residuals.erase(m_residuals.begin() + *e);
872  }
873 
874  std::vector<size_t> apos[Nbin], aneg[Nbin];
875  for (size_t i = 0; i < m_residuals.size(); i++) {
876  if (!m_residuals_ok[i])
877  continue;
878  int bin = (int)floor(1. / fabs(m_residuals[i][idx_momentum]) / bin_width);
879  if (m_residuals[i][idx_q] > 0)
880  apos[bin].push_back(i);
881  else
882  aneg[bin].push_back(i);
883  }
884  for (int j = 0; j < Nbin; j++)
885  std::cout << "bin " << j << ": [pos,neg] sizes before & after: [" << pos[j].size() << "," << neg[j].size()
886  << "] -> [" << apos[j].size() << "," << aneg[j].size() << "]" << std::endl;
887  std::cout << " N residuals " << m_residuals.size() << " -> "
888  << (size_t)std::count(m_residuals_ok.begin(), m_residuals_ok.end(), true) << std::endl;
889 }
size
Write out results.
std::vector< double * > m_residuals
std::vector< double * >::const_iterator residuals_begin() const
std::vector< double * >::const_iterator residuals_end() const
std::vector< bool > m_residuals_ok

◆ correlationMatrix()

TMatrixDSym MuonResidualsFitter::correlationMatrix ( )

◆ covarianceElement()

double MuonResidualsFitter::covarianceElement ( int  parNum1,
int  parNum2 
)

Definition at line 191 of file MuonResidualsFitter.cc.

References cms::cuda::assert(), m_cov, npar(), and parNum2parIdx().

191  {
192  assert(0 <= parNum1 && parNum1 < npar());
193  assert(0 <= parNum2 && parNum2 < npar());
194  assert(m_cov.GetNcols() == npar()); // m_cov might have not yet been resized to account for proper #parameters
195  return m_cov(parNum2parIdx(parNum1), parNum2parIdx(parNum2));
196 }
int parNum2parIdx(int parNum)
virtual int npar()=0
assert(be >=bs)

◆ covarianceMatrix()

TMatrixDSym MuonResidualsFitter::covarianceMatrix ( )
inline

Definition at line 158 of file MuonResidualsFitter.h.

References m_cov.

158 { return m_cov; }

◆ dofit()

bool MuonResidualsFitter::dofit ( void(*)(int &, double *, double &, double *, int)  fcn,
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 
)
protected

Definition at line 272 of file MuonResidualsFitter.cc.

References MillePedeFileConverter_cfg::e, fcn(), fixed(), LaserClient_cfi::high, mps_fire::i, inform(), LaserClient_cfi::low, m_cov, m_error, m_loglikelihood, m_strategy, m_value, MuonResidualsFitter_TMinuit, npar(), and findQualityFiles::v.

Referenced by MuonResidualsAngleFitter::fit(), MuonResidualsPositionFitter::fit(), MuonResidualsBfieldAngleFitter::fit(), MuonResiduals1DOFFitter::fit(), MuonResiduals6DOFrphiFitter::fit(), MuonResiduals5DOFFitter::fit(), and MuonResiduals6DOFFitter::fit().

278  {
280 
281  MuonResidualsFitter_TMinuit = new TMinuit(npar());
282  // MuonResidualsFitter_TMinuit->SetPrintLevel(m_printLevel);
283  MuonResidualsFitter_TMinuit->SetPrintLevel();
284  MuonResidualsFitter_TMinuit->SetObjectFit(fitinfo);
287 
288  std::vector<int>::const_iterator iNum = parNum.begin();
289  std::vector<std::string>::const_iterator iName = parName.begin();
290  std::vector<double>::const_iterator istart = start.begin();
291  std::vector<double>::const_iterator istep = step.begin();
292  std::vector<double>::const_iterator ilow = low.begin();
293  std::vector<double>::const_iterator ihigh = high.begin();
294 
295  //MuonResidualsFitter_TMinuit->SetPrintLevel(-1);
296 
297  for (; iNum != parNum.end(); ++iNum, ++iName, ++istart, ++istep, ++ilow, ++ihigh) {
298  MuonResidualsFitter_TMinuit->DefineParameter(*iNum, iName->c_str(), *istart, *istep, *ilow, *ihigh);
299  if (fixed(*iNum))
300  MuonResidualsFitter_TMinuit->FixParameter(*iNum);
301  }
302 
303  double arglist[10];
304  int ierflg;
305  int smierflg; //second MIGRAD ierflg
306 
307  // chi^2 errors should be 1.0, log-likelihood should be 0.5
308  for (int i = 0; i < 10; i++)
309  arglist[i] = 0.;
310  arglist[0] = 0.5;
311  ierflg = 0;
312  smierflg = 0;
313  MuonResidualsFitter_TMinuit->mnexcm("SET ERR", arglist, 1, ierflg);
314  if (ierflg != 0) {
316  delete fitinfo;
317  return false;
318  }
319 
320  // set strategy = 2 (more refined fits)
321  for (int i = 0; i < 10; i++)
322  arglist[i] = 0.;
323  arglist[0] = m_strategy;
324  ierflg = 0;
325  MuonResidualsFitter_TMinuit->mnexcm("SET STR", arglist, 1, ierflg);
326  if (ierflg != 0) {
328  delete fitinfo;
329  return false;
330  }
331 
332  bool try_again = false;
333 
334  // minimize
335  for (int i = 0; i < 10; i++)
336  arglist[i] = 0.;
337  arglist[0] = 50000;
338  ierflg = 0;
339  MuonResidualsFitter_TMinuit->mnexcm("MIGRAD", arglist, 1, ierflg);
340  if (ierflg != 0)
341  try_again = true;
342 
343  // just once more, if needed (using the final Minuit parameters from the failed fit; often works)
344  if (try_again) {
345  for (int i = 0; i < 10; i++)
346  arglist[i] = 0.;
347  arglist[0] = 50000;
348  MuonResidualsFitter_TMinuit->mnexcm("MIGRAD", arglist, 1, smierflg);
349  }
350 
351  Double_t fmin, fedm, errdef;
352  Int_t npari, nparx, istat;
353  MuonResidualsFitter_TMinuit->mnstat(fmin, fedm, errdef, npari, nparx, istat);
354 
355  if (istat != 3) {
356  for (int i = 0; i < 10; i++)
357  arglist[i] = 0.;
358  ierflg = 0;
359  MuonResidualsFitter_TMinuit->mnexcm("HESSE", arglist, 0, ierflg);
360  }
361 
362  // read-out the results
363  m_loglikelihood = -fmin;
364 
365  m_value.clear();
366  m_error.clear();
367  for (int i = 0; i < npar(); i++) {
368  double v, e;
369  MuonResidualsFitter_TMinuit->GetParameter(i, v, e);
370  m_value.push_back(v);
371  m_error.push_back(e);
372  }
373  m_cov.ResizeTo(npar(), npar());
374  MuonResidualsFitter_TMinuit->mnemat(m_cov.GetMatrixArray(), npar());
375 
377  delete fitinfo;
378  if (smierflg != 0)
379  return false;
380  return true;
381 }
Definition: start.py:1
virtual void inform(TMinuit *tMinuit)=0
virtual int npar()=0
std::vector< double > m_error
std::vector< double > m_value
static TMinuit * MuonResidualsFitter_TMinuit
void fcn(int &, double *, double &, double *, int)
step
Definition: StallMonitor.cc:98

◆ eraseNotSelectedResiduals()

void MuonResidualsFitter::eraseNotSelectedResiduals ( )

Definition at line 891 of file MuonResidualsFitter.cc.

References submitPVResolutionJobs::count, gather_cfg::cout, mps_fire::i, m_residuals, m_residuals_ok, and createJobs::tmp.

Referenced by MuonResidualsTwoBin::eraseNotSelectedResiduals().

891  {
892  // it should probably be faster then doing erase
893  size_t n_ok = (size_t)std::count(m_residuals_ok.begin(), m_residuals_ok.end(), true);
894  std::vector<double *> tmp(n_ok, nullptr);
895  std::cout << "residuals sizes: all=" << m_residuals.size() << " good=" << n_ok << std::endl;
896  int iok = 0;
897  for (size_t i = 0; i < m_residuals.size(); i++) {
898  if (!m_residuals_ok[i])
899  continue;
900  tmp[iok++] = m_residuals[i];
901  }
902  m_residuals.swap(tmp);
903 
904  std::vector<bool> tmp_ok(n_ok, true);
905  m_residuals_ok.swap(tmp_ok);
906 
907  std::cout << "residuals size after eraseNotSelectedResiduals =" << m_residuals.size()
908  << " ok size=" << m_residuals_ok.size() << std::endl;
909 }
std::vector< double * > m_residuals
std::vector< bool > m_residuals_ok
tmp
align.sh
Definition: createJobs.py:716

◆ errorerror()

double MuonResidualsFitter::errorerror ( int  parNum)
inline

Definition at line 149 of file MuonResidualsFitter.h.

References cms::cuda::assert(), m_error, and npar().

Referenced by MuonResidualsTwoBin::errorerror(), MuonResiduals6DOFrphiFitter::plot(), MuonResiduals5DOFFitter::plot(), and MuonResiduals6DOFFitter::plot().

149  {
150  assert(0 <= parNum && parNum < npar());
151  return m_error[parNum];
152  }
virtual int npar()=0
std::vector< double > m_error
assert(be >=bs)

◆ fiducialCuts()

void MuonResidualsFitter::fiducialCuts ( double  xMin = -80.0,
double  xMax = 80.0,
double  yMin = -80.0,
double  yMax = 80.0,
bool  fidcut1 = false 
)

Definition at line 719 of file MuonResidualsFitter.cc.

References m_residuals_ok, alignCSCRings::r, residuals_begin(), residuals_end(), multiplicitycorr_cfi::xMax, photonAnalyzer_cfi::xMin, multiplicitycorr_cfi::yMax, and photonAnalyzer_cfi::yMin.

Referenced by MuonResidualsTwoBin::fiducialCuts().

719  {
720  int iResidual = -1;
721 
722  int n_station = 9999;
723  int n_wheel = 9999;
724  int n_sector = 9999;
725 
726  double positionX = 9999.;
727  double positionY = 9999.;
728 
729  double chambw = 9999.;
730  double chambl = 9999.;
731 
732  for (std::vector<double *>::const_iterator r = residuals_begin(); r != residuals_end(); ++r) {
733  iResidual++;
734  if (!m_residuals_ok[iResidual])
735  continue;
736 
737  if ((*r)[15] >
738  0.0001) { // this value is greater than zero (chamber width) for 6DOFs stations 1,2,3 better to change for type()!!!
739  n_station = (*r)[12];
740  n_wheel = (*r)[13];
741  n_sector = (*r)[14];
742  positionX = (*r)[4];
743  positionY = (*r)[5];
744  chambw = (*r)[15];
745  chambl = (*r)[16];
746  } else { // in case of 5DOF residual the residual object index is different
747  n_station = (*r)[10];
748  n_wheel = (*r)[11];
749  n_sector = (*r)[12];
750  positionX = (*r)[2];
751  positionY = (*r)[3];
752  chambw = (*r)[13];
753  chambl = (*r)[14];
754  }
755 
756  if (fidcut1) { // this is the standard fiducial cut used so far 80x80 cm in x,y
757  if (positionX >= xMax || positionX <= xMin)
758  m_residuals_ok[iResidual] = false;
759  if (positionY >= yMax || positionY <= yMin)
760  m_residuals_ok[iResidual] = false;
761  }
762 
763  // Implementation of new fiducial cut
764 
765  double dtrkchamx = (chambw / 2.) - positionX; // variables to cut tracks on the edge of the chambers
766  double dtrkchamy = (chambl / 2.) - positionY;
767 
768  if (!fidcut1) {
769  if (n_station == 4) {
770  if ((n_wheel == -1 && n_sector == 3) ||
771  (n_wheel == 1 &&
772  n_sector == 4)) { // FOR SHORT CHAMBER LENGTH IN: WHEEL 1 SECTOR 4 AND WHEEL -1 SECTOR 3
773  if ((n_sector == 1 || n_sector == 2 || n_sector == 3 || n_sector == 5 || n_sector == 6 || n_sector == 7 ||
774  n_sector == 8 || n_sector == 12) &&
775  ((dtrkchamx < 40 || dtrkchamx > 380) || (dtrkchamy < 40.0 || dtrkchamy > 170.0)))
776  m_residuals_ok[iResidual] = false;
777  if ((n_sector == 4 || n_sector == 13) &&
778  ((dtrkchamx < 40 || dtrkchamx > 280) || (dtrkchamy < 40.0 || dtrkchamy > 170.0)))
779  m_residuals_ok[iResidual] = false;
780  if ((n_sector == 9 || n_sector == 11) &&
781  ((dtrkchamx < 40 || dtrkchamx > 180) || (dtrkchamy < 40.0 || dtrkchamy > 170.0)))
782  m_residuals_ok[iResidual] = false;
783  if ((n_sector == 10 || n_sector == 14) &&
784  ((dtrkchamx < 40 || dtrkchamx > 220) || (dtrkchamy < 40.0 || dtrkchamy > 170.0)))
785  m_residuals_ok[iResidual] = false;
786  } else {
787  if ((n_sector == 1 || n_sector == 2 || n_sector == 3 || n_sector == 5 || n_sector == 6 || n_sector == 7 ||
788  n_sector == 8 || n_sector == 12) &&
789  ((dtrkchamx < 40 || dtrkchamx > 380) || (dtrkchamy < 40.0 || dtrkchamy > 210.0)))
790  m_residuals_ok[iResidual] = false;
791  if ((n_sector == 4 || n_sector == 13) &&
792  ((dtrkchamx < 40 || dtrkchamx > 280) || (dtrkchamy < 40.0 || dtrkchamy > 210.0)))
793  m_residuals_ok[iResidual] = false;
794  if ((n_sector == 9 || n_sector == 11) &&
795  ((dtrkchamx < 40 || dtrkchamx > 180) || (dtrkchamy < 40.0 || dtrkchamy > 210.0)))
796  m_residuals_ok[iResidual] = false;
797  if ((n_sector == 10 || n_sector == 14) &&
798  ((dtrkchamx < 40 || dtrkchamx > 220) || (dtrkchamy < 40.0 || dtrkchamy > 210.0)))
799  m_residuals_ok[iResidual] = false;
800  }
801  } else {
802  if ((n_wheel == -1 && n_sector == 3) || (n_wheel == 1 && n_sector == 4)) {
803  if (n_station == 1 && ((dtrkchamx < 30.0 || dtrkchamx > 190.0) || (dtrkchamy < 40.0 || dtrkchamy > 170.0)))
804  m_residuals_ok[iResidual] = false;
805  if (n_station == 2 && ((dtrkchamx < 30.0 || dtrkchamx > 240.0) || (dtrkchamy < 40.0 || dtrkchamy > 170.0)))
806  m_residuals_ok[iResidual] = false;
807  if (n_station == 3 && ((dtrkchamx < 30.0 || dtrkchamx > 280.0) || (dtrkchamy < 40.0 || dtrkchamy > 170.0)))
808  m_residuals_ok[iResidual] = false;
809  } else {
810  if (n_station == 1 && ((dtrkchamx < 30.0 || dtrkchamx > 190.0) || (dtrkchamy < 40.0 || dtrkchamy > 210.0)))
811  m_residuals_ok[iResidual] = false;
812  if (n_station == 2 && ((dtrkchamx < 30.0 || dtrkchamx > 240.0) || (dtrkchamy < 40.0 || dtrkchamy > 210.0)))
813  m_residuals_ok[iResidual] = false;
814  if (n_station == 3 && ((dtrkchamx < 30.0 || dtrkchamx > 280.0) || (dtrkchamy < 40.0 || dtrkchamy > 210.0)))
815  m_residuals_ok[iResidual] = false;
816  }
817  }
818  }
819  }
820 }
std::vector< double * >::const_iterator residuals_begin() const
std::vector< double * >::const_iterator residuals_end() const
std::vector< bool > m_residuals_ok

◆ fill()

void MuonResidualsFitter::fill ( double *  residual)

Definition at line 186 of file MuonResidualsFitter.cc.

References m_residuals, and m_residuals_ok.

Referenced by MuonResidualsTwoBin::fill(), read(), MuonResiduals6DOFrphiFitter::readNtuple(), MuonResiduals5DOFFitter::readNtuple(), and MuonResiduals6DOFFitter::readNtuple().

186  {
187  m_residuals.push_back(residual);
188  m_residuals_ok.push_back(true);
189 }
std::vector< double * > m_residuals
std::vector< bool > m_residuals_ok

◆ fit()

virtual bool MuonResidualsFitter::fit ( Alignable ali)
pure virtual

◆ fix()

void MuonResidualsFitter::fix ( int  parNum,
bool  dofix = true 
)

Definition at line 171 of file MuonResidualsFitter.cc.

References cms::cuda::assert(), m_fixed, and npar().

Referenced by MuonResiduals6DOFrphiFitter::fit(), MuonResiduals5DOFFitter::fit(), MuonResiduals6DOFFitter::fit(), and MuonResidualsTwoBin::fix().

171  {
172  assert(0 <= parNum && parNum < npar());
173  if (m_fixed.empty())
174  m_fixed.resize(npar(), false);
175  m_fixed[parNum] = dofix;
176 }
virtual int npar()=0
assert(be >=bs)
std::vector< bool > m_fixed

◆ fixed()

bool MuonResidualsFitter::fixed ( int  parNum)

Definition at line 178 of file MuonResidualsFitter.cc.

References cms::cuda::assert(), m_fixed, and npar().

Referenced by dofit(), MuonResiduals1DOFFitter::fit(), and MuonResidualsTwoBin::fixed().

178  {
179  assert(0 <= parNum && parNum < npar());
180  if (m_fixed.empty())
181  return false;
182  else
183  return m_fixed[parNum];
184 }
virtual int npar()=0
assert(be >=bs)
std::vector< bool > m_fixed

◆ histogramChi2GaussianFit()

void MuonResidualsFitter::histogramChi2GaussianFit ( int  which,
double &  fit_mean,
double &  fit_sigma 
)

Definition at line 546 of file MuonResidualsFitter.cc.

References a, b, computeHistogramRangeAndBinning(), gather_cfg::cout, DeadROC_duringRun::f1, compareTotals::hist, m_residuals, LaserClient_cfi::nbins, alignCSCRings::r, and eostools::which().

Referenced by selectPeakResiduals().

546  {
547  int nbins;
548  double a, b;
550  if (a == b || a > b) {
551  fit_mean = a;
552  fit_sigma = 0;
553  return;
554  }
555 
556  TH1D *hist = new TH1D("htmp", "", nbins, a, b);
557  for (std::vector<double *>::const_iterator r = m_residuals.begin(); r != m_residuals.end(); ++r)
558  hist->Fill((*r)[which]);
559 
560  // do simple chi2 gaussian fit
561  TF1 *f1 = new TF1("f1", "gaus", a, b);
562  f1->SetParameter(0, hist->GetEntries());
563  f1->SetParameter(1, 0);
564  f1->SetParameter(2, hist->GetRMS());
565  hist->Fit("f1", "RQ");
566  // hist->Fit(f1,"RQ");
567 
568  fit_mean = f1->GetParameter(1);
569  fit_sigma = f1->GetParameter(2);
570  std::cout << " h(" << nbins << "," << a << "," << b << ") mu=" << fit_mean << " sig=" << fit_sigma << std::endl;
571 
572  delete f1;
573  delete hist;
574 }
std::vector< double * > m_residuals
void computeHistogramRangeAndBinning(int which, int &nbins, double &a, double &b)
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
def which(cmd)
Definition: eostools.py:336

◆ inform()

virtual void MuonResidualsFitter::inform ( TMinuit *  tMinuit)
protectedpure virtual

◆ initialize_table()

void MuonResidualsFitter::initialize_table ( )
protected

Definition at line 205 of file MuonResidualsFitter.cc.

References gather_cfg::cout, Exception, kPowerLawTails, MuonResidualsFitter_compute_log_convolution(), MuonResidualsFitter_gsbinsize, MuonResidualsFitter_lookup_table, MuonResidualsFitter_numgsbins, MuonResidualsFitter_numtsbins, MuonResidualsFitter_table_initialized, MuonResidualsFitter_tsbinsize, residualsModel(), and heppy_batch::val.

Referenced by MuonResidualsAngleFitter::fit(), MuonResidualsPositionFitter::fit(), MuonResidualsBfieldAngleFitter::fit(), MuonResiduals1DOFFitter::fit(), MuonResiduals6DOFrphiFitter::fit(), MuonResiduals5DOFFitter::fit(), and MuonResiduals6DOFFitter::fit().

205  {
207  return;
209 
210  std::ifstream convolution_table("convolution_table.txt");
211  if (convolution_table.is_open()) {
212  int numgsbins = 0;
213  int numtsbins = 0;
214  double tsbinsize = 0.;
215  double gsbinsize = 0.;
216 
217  convolution_table >> numgsbins >> numtsbins >> tsbinsize >> gsbinsize;
218  if (numgsbins != MuonResidualsFitter_numgsbins || numtsbins != MuonResidualsFitter_numtsbins ||
219  tsbinsize != MuonResidualsFitter_tsbinsize || gsbinsize != MuonResidualsFitter_gsbinsize) {
220  throw cms::Exception("MuonResidualsFitter") << "convolution_table.txt has the wrong bin width/bin size. Throw "
221  "it away and let the fitter re-create the file.\n";
222  }
223 
224  for (int gsbin = 0; gsbin < MuonResidualsFitter_numgsbins; gsbin++) {
225  for (int tsbin = 0; tsbin < MuonResidualsFitter_numtsbins; tsbin++) {
226  int read_gsbin = 0;
227  int read_tsbin = 0;
228  double val = 0.;
229 
230  convolution_table >> read_gsbin >> read_tsbin >> val;
231  if (read_gsbin != gsbin || read_tsbin != tsbin) {
232  throw cms::Exception("MuonResidualsFitter")
233  << "convolution_table.txt is out of order. Throw it away and let the fitter re-create the file.\n";
234  }
235  MuonResidualsFitter_lookup_table[gsbin][tsbin] = val;
236  }
237  }
238  convolution_table.close();
239  } else {
240  std::ofstream convolution_table2("convolution_table.txt");
241 
242  if (!convolution_table2.is_open())
243  throw cms::Exception("MuonResidualsFitter") << "Couldn't write to file convolution_table.txt\n";
244 
245  convolution_table2 << MuonResidualsFitter_numgsbins << " " << MuonResidualsFitter_numtsbins << " "
247 
248  std::cout << "Initializing convolution look-up table (takes a few minutes)..." << std::endl;
249 
250  for (int gsbin = 0; gsbin < MuonResidualsFitter_numgsbins; gsbin++) {
251  double gammaoversigma = double(gsbin) * MuonResidualsFitter_gsbinsize;
252  std::cout << " gsbin " << gsbin << "/" << MuonResidualsFitter_numgsbins << std::endl;
253  for (int tsbin = 0; tsbin < MuonResidualsFitter_numtsbins; tsbin++) {
254  double toversigma = double(tsbin) * MuonResidualsFitter_tsbinsize;
255 
256  // 1e-6 errors (out of a value of ~0.01) with max=100, step=0.001, power=4 (max=1000 does a little better with the tails)
257  MuonResidualsFitter_lookup_table[gsbin][tsbin] =
258  MuonResidualsFitter_compute_log_convolution(toversigma, gammaoversigma);
259 
260  // <10% errors with max=20, step=0.005, power=4 (faster computation for testing)
261  // MuonResidualsFitter_lookup_table[gsbin][tsbin] = MuonResidualsFitter_compute_log_convolution(toversigma, gammaoversigma, 100., 0.005, 4.);
262 
263  convolution_table2 << gsbin << " " << tsbin << " " << MuonResidualsFitter_lookup_table[gsbin][tsbin]
264  << std::endl;
265  }
266  }
267  convolution_table2.close();
268  std::cout << "Initialization done!" << std::endl;
269  }
270 }
const int MuonResidualsFitter_numgsbins
const int MuonResidualsFitter_numtsbins
const double MuonResidualsFitter_gsbinsize
const double MuonResidualsFitter_tsbinsize
double MuonResidualsFitter_compute_log_convolution(double toversigma, double gammaoversigma, double max, double step, double power)
bool MuonResidualsFitter_table_initialized
double MuonResidualsFitter_lookup_table[MuonResidualsFitter_numgsbins][MuonResidualsFitter_numtsbins]

◆ loglikelihood()

double MuonResidualsFitter::loglikelihood ( )
inline

Definition at line 162 of file MuonResidualsFitter.h.

References m_loglikelihood.

Referenced by MuonResidualsTwoBin::loglikelihood().

162 { return m_loglikelihood; }

◆ ndata()

virtual int MuonResidualsFitter::ndata ( )
pure virtual

◆ nfixed()

int MuonResidualsFitter::nfixed ( )
inline

Definition at line 130 of file MuonResidualsFitter.h.

References submitPVResolutionJobs::count, and m_fixed.

130 { return std::count(m_fixed.begin(), m_fixed.end(), true); }
std::vector< bool > m_fixed

◆ npar()

virtual int MuonResidualsFitter::npar ( )
pure virtual

◆ numResiduals()

long MuonResidualsFitter::numResiduals ( ) const
inline

◆ numsegments()

long MuonResidualsFitter::numsegments ( )

Definition at line 198 of file MuonResidualsFitter.cc.

References EgammaValidation_cff::num, residuals_begin(), and residuals_end().

Referenced by MuonResidualsTwoBin::numsegments().

198  {
199  long num = 0;
200  for (std::vector<double *>::const_iterator resiter = residuals_begin(); resiter != residuals_end(); ++resiter)
201  num++;
202  return num;
203 }
std::vector< double * >::const_iterator residuals_begin() const
std::vector< double * >::const_iterator residuals_end() const

◆ parNum2parIdx()

int MuonResidualsFitter::parNum2parIdx ( int  parNum)
inline

Definition at line 156 of file MuonResidualsFitter.h.

References m_parNum2parIdx.

Referenced by covarianceElement().

156 { return m_parNum2parIdx[parNum]; }
std::map< int, int > m_parNum2parIdx

◆ plot()

virtual double MuonResidualsFitter::plot ( std::string  name,
TFileDirectory dir,
Alignable ali 
)
pure virtual

◆ plotsimple()

void MuonResidualsFitter::plotsimple ( std::string  name,
TFileDirectory dir,
int  which,
double  multiplier 
)

Definition at line 474 of file MuonResidualsFitter.cc.

References DeadROC_duringRun::dir, compareTotals::hist, Skims_PA_cff::name, alignCSCRings::r, residuals_begin(), residuals_end(), eostools::which(), and svgfig::window().

Referenced by MuonResidualsTwoBin::plotsimple().

474  {
475  double window = 100.;
476  if (which == 0)
477  window = 2. * 30.;
478  else if (which == 1)
479  window = 2. * 30.;
480  else if (which == 2)
481  window = 2. * 20.;
482  else if (which == 3)
483  window = 2. * 50.;
484 
485  TH1F *hist = dir->make<TH1F>(name.c_str(), "", 200, -window, window);
486  for (std::vector<double *>::const_iterator r = residuals_begin(); r != residuals_end(); ++r)
487  hist->Fill(multiplier * (*r)[which]);
488 }
std::vector< double * >::const_iterator residuals_begin() const
std::vector< double * >::const_iterator residuals_end() const
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:643
def which(cmd)
Definition: eostools.py:336

◆ plotweighted()

void MuonResidualsFitter::plotweighted ( std::string  name,
TFileDirectory dir,
int  which,
int  whichredchi2,
double  multiplier 
)

Definition at line 490 of file MuonResidualsFitter.cc.

References DeadROC_duringRun::dir, compareTotals::hist, Skims_PA_cff::name, alignCSCRings::r, residuals_begin(), residuals_end(), eostools::which(), and svgfig::window().

Referenced by MuonResidualsTwoBin::plotweighted().

491  {
492  double window = 100.;
493  if (which == 0)
494  window = 2. * 30.;
495  else if (which == 1)
496  window = 2. * 30.;
497  else if (which == 2)
498  window = 2. * 20.;
499  else if (which == 3)
500  window = 2. * 50.;
501 
502  TH1F *hist = dir->make<TH1F>(name.c_str(), "", 200, -window, window);
503  for (std::vector<double *>::const_iterator r = residuals_begin(); r != residuals_end(); ++r) {
504  double weight = 1. / (*r)[whichredchi2];
505  if (TMath::Prob(1. / weight * 12, 12) < 0.99)
506  hist->Fill(multiplier * (*r)[which], weight);
507  }
508 }
std::vector< double * >::const_iterator residuals_begin() const
Definition: weight.py:1
std::vector< double * >::const_iterator residuals_end() const
def window(xmin, xmax, ymin, ymax, x=0, y=0, width=100, height=100, xlogbase=None, ylogbase=None, minusInfinity=-1000, flipx=False, flipy=True)
Definition: svgfig.py:643
def which(cmd)
Definition: eostools.py:336

◆ read()

void MuonResidualsFitter::read ( FILE *  file,
int  which = 0 
)

Definition at line 418 of file MuonResidualsFitter.cc.

References MillePedeFileConverter_cfg::e, Exception, geometryDiff::file, fill(), mps_fire::i, m_residuals, m_residuals_ok, ndata(), numResiduals(), mysort::rows, and eostools::which().

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), and MuonResidualsTwoBin::read().

418  {
419  long rows = -100;
420  int cols = -100;
421  int readwhich = -100;
422 
423  fread(&rows, sizeof(long), 1, file);
424  fread(&cols, sizeof(int), 1, file);
425  fread(&readwhich, sizeof(int), 1, file);
426 
427  if (cols != ndata() || rows < 0 || readwhich != which) {
428  throw cms::Exception("MuonResidualsFitter")
429  << "temporary file is corrupted (which = " << which << " readwhich = " << readwhich << " rows = " << rows
430  << " cols = " << cols << ")\n";
431  }
432 
433  double *likeAChecksum = new double[cols];
434  double *likeAChecksum2 = new double[cols];
435  for (int i = 0; i < cols; i++) {
436  likeAChecksum[i] = 0.;
437  likeAChecksum2[i] = 0.;
438  }
439 
440  m_residuals.reserve(rows);
441  for (long row = 0; row < rows; row++) {
442  double *residual = new double[cols];
443  fread(residual, sizeof(double), cols, file);
444  fill(residual);
445  for (int i = 0; i < cols; i++) {
446  if (fabs(residual[i]) > likeAChecksum[i])
447  likeAChecksum[i] = fabs(residual[i]);
448  if (fabs(residual[i]) < likeAChecksum2[i])
449  likeAChecksum2[i] = fabs(residual[i]);
450  }
451  } // end loop over records in file
452 
453  double *readChecksum = new double[cols];
454  double *readChecksum2 = new double[cols];
455  fread(readChecksum, sizeof(double), cols, file);
456  fread(readChecksum2, sizeof(double), cols, file);
457 
458  for (int i = 0; i < cols; i++) {
459  if (fabs(likeAChecksum[i] - readChecksum[i]) > 1e-10 ||
460  fabs(1. / likeAChecksum2[i] - 1. / readChecksum2[i]) > 1e10) {
461  throw cms::Exception("MuonResidualsFitter")
462  << "temporary file is corrupted (which = " << which << " rows = " << rows << " likeAChecksum "
463  << likeAChecksum[i] << " != readChecksum " << readChecksum[i] << " "
464  << " likeAChecksum2 " << likeAChecksum2[i] << " != readChecksum2 " << readChecksum2[i] << ")\n";
465  }
466  }
467 
468  m_residuals_ok.resize(numResiduals(), true);
469 
470  delete[] likeAChecksum;
471  delete[] likeAChecksum2;
472 }
std::vector< double * > m_residuals
void fill(double *residual)
std::vector< bool > m_residuals_ok
virtual int ndata()=0
def which(cmd)
Definition: eostools.py:336
rows
Definition: mysort.py:12

◆ residuals_begin()

std::vector<double *>::const_iterator MuonResidualsFitter::residuals_begin ( ) const
inline

◆ residuals_end()

std::vector<double *>::const_iterator MuonResidualsFitter::residuals_end ( ) const
inline

◆ residualsModel()

int MuonResidualsFitter::residualsModel ( ) const
inline

◆ selectedResidualsFlags()

std::vector<bool>& MuonResidualsFitter::selectedResidualsFlags ( )
inline

◆ selectPeakResiduals()

void MuonResidualsFitter::selectPeakResiduals ( double  nsigma,
int  nvar,
int *  vars 
)

Definition at line 579 of file MuonResidualsFitter.cc.

References cms::cuda::assert(), gather_cfg::cout, histogramChi2GaussianFit(), m_center, m_radii, m_residuals, m_residuals_ok, numResiduals(), funct::pow(), alignCSCRings::r, findQualityFiles::v, and eostools::which().

Referenced by MuonResidualsTwoBin::selectPeakResiduals().

579  {
580  // does not make sense for small statistics
581  if (numResiduals() < 25)
582  return;
583 
584  int nbefore = numResiduals();
585 
586  //just to be sure (can't see why it might ever be more then 10)
587  assert(nvar <= 10);
588 
589  // estimate nvar-D ellipsoid center & axes
590  for (int v = 0; v < nvar; v++) {
591  int which = vars[v];
593  m_radii[which] = nsigma * m_radii[which];
594  }
595 
596  // filter out residuals that don't fit into the ellipsoid
597  std::vector<double *>::iterator r = m_residuals.begin();
598  while (r != m_residuals.end()) {
599  double ellipsoid_sum = 0;
600  for (int v = 0; v < nvar; v++) {
601  int which = vars[v];
602  if (m_radii[which] == 0.)
603  continue;
604  ellipsoid_sum += pow(((*r)[which] - m_center[which]) / m_radii[which], 2);
605  }
606  if (ellipsoid_sum <= 1.)
607  ++r;
608  else {
609  m_residuals_ok[r - m_residuals.begin()] = false;
610  ++r;
611  // delete [] (*r);
612  // r = m_residuals.erase(r);
613  }
614  }
615  std::cout << " N residuals " << nbefore << " -> " << numResiduals() << std::endl;
616 }
void histogramChi2GaussianFit(int which, double &fit_mean, double &fit_sigma)
std::vector< double * > m_residuals
assert(be >=bs)
std::vector< bool > m_residuals_ok
def which(cmd)
Definition: eostools.py:336
vars
Definition: DeepTauId.cc:30
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29

◆ selectPeakResiduals_simple()

void MuonResidualsFitter::selectPeakResiduals_simple ( double  nsigma,
int  nvar,
int *  vars 
)

Definition at line 620 of file MuonResidualsFitter.cc.

References cms::cuda::assert(), submitPVResolutionJobs::count, gather_cfg::cout, data, HLT_2023v12_cff::distance, mps_fire::i, m_residuals, m_residuals_ok, numResiduals(), alignCSCRings::r, mathSSE::sqrt(), and findQualityFiles::v.

620  {
621  //std::cout<<"doing selectpeakresiduals: nsig="<<nsigma<<" nvar="<<nvar<<" vars=";
622  for (int i = 0; i < nvar; ++i)
623  std::cout << vars[i] << " ";
624  std::cout << std::endl;
625 
626  // does not make sense for small statistics set to 50
627  // YP changed it to 10 for test
628  if (numResiduals() < 10)
629  return;
630  // if (numResiduals()<50) return;
631 
632  size_t nbefore = numResiduals();
633  std::cout << " N residuals " << nbefore << " ~ "
634  << (size_t)std::count(m_residuals_ok.begin(), m_residuals_ok.end(), true) << std::endl;
635  //just to be sure (can't see why it might ever be more then 10)
636  assert(nvar <= 10 && nvar > 0);
637 
638  std::vector<double *>::iterator r = m_residuals.begin();
639 
640  // it's awkward, but the 1D case has to be handled separately
641  if (nvar == 1) {
642  std::cout << "1D case" << std::endl;
643  // get robust estimates for the peak and sigma
644  double *data = new double[nbefore];
645  for (size_t i = 0; i < nbefore; i++)
646  data[i] = m_residuals[i][vars[0]];
647  double peak, sigma;
648  TRobustEstimator re;
649  re.EvaluateUni(nbefore, data, peak, sigma);
650 
651  // filter out residuals that are more then nsigma away from the peak
652  while (r != m_residuals.end()) {
653  double distance = fabs(((*r)[vars[0]] - peak) / sigma);
654  if (distance <= nsigma)
655  ++r;
656  else {
657  m_residuals_ok[r - m_residuals.begin()] = false;
658  ++r;
659  //delete [] (*r);
660  //r = m_residuals.erase(r);
661  }
662  }
663  std::cout << " N residuals " << nbefore << " -> " << numResiduals() << std::endl;
664  return;
665  } // end 1D case
666 
667  // initialize and run the robust estimator for D>1
668  std::cout << "D>1 case" << std::endl;
669  TRobustEstimator re(nbefore + 1, nvar);
670  std::cout << "nbefore " << nbefore << " nvar " << nvar << std::endl;
671  r = m_residuals.begin();
672  std::cout << "+++++ JUST before loop while (r != m_residuals.end())" << std::endl;
673  int counter1 = 0;
674  while (r != m_residuals.end()) {
675  double *row = new double[nvar];
676  for (int v = 0; v < nvar; v++)
677  row[v] = (*r)[vars[v]];
678  re.AddRow(row);
679  // delete[] row;
680  ++r;
681  counter1++;
682  }
683  std::cout << "counter1 " << counter1 << std::endl;
684  std::cout << "+++++ JUST after loop while (r != m_residuals.end())" << std::endl;
685  re.Evaluate();
686  std::cout << "+++++ JUST after re.Evaluate()" << std::endl;
687 
688  // get nvar-dimensional ellipsoid center & covariance
689  TVectorD M(nvar);
690  re.GetMean(M);
691  TMatrixDSym Cov(nvar);
692  re.GetCovariance(Cov);
693  Cov.Invert();
694 
695  // calculate the normalized radius for this nvar-dimensional ellipsoid from a 1D-Gaussian nsigma equivalent distance
696  double conf_1d = TMath::Erf(nsigma / sqrt(2));
697  double surf_radius = sqrt(TMath::ChisquareQuantile(conf_1d, nvar));
698 
699  // filter out residuals that are outside of the covariance ellipsoid with the above normalized radius
700  r = m_residuals.begin();
701  while (r != m_residuals.end()) {
702  TVectorD res(nvar);
703  for (int v = 0; v < nvar; v++)
704  res[v] = (*r)[vars[v]];
705  double distance = sqrt(Cov.Similarity(res - M));
706  if (distance <= surf_radius)
707  ++r;
708  else {
709  m_residuals_ok[r - m_residuals.begin()] = false;
710  ++r;
711  //delete [] (*r);
712  //r = m_residuals.erase(r);
713  }
714  }
715  std::cout << " N residuals " << nbefore << " -> "
716  << (size_t)std::count(m_residuals_ok.begin(), m_residuals_ok.end(), true) << std::endl;
717 }
std::vector< double * > m_residuals
assert(be >=bs)
Definition: Electron.h:6
T sqrt(T t)
Definition: SSEVec.h:19
std::vector< bool > m_residuals_ok
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
vars
Definition: DeepTauId.cc:30

◆ setInitialValue()

void MuonResidualsFitter::setInitialValue ( int  parNum,
double  value 
)
inline

Definition at line 135 of file MuonResidualsFitter.h.

References m_parNum2InitValue, and value().

135 { m_parNum2InitValue[parNum] = value; }
double value(int parNum)
std::map< int, double > m_parNum2InitValue

◆ setPrintLevel()

void MuonResidualsFitter::setPrintLevel ( int  printLevel)
inline

Definition at line 132 of file MuonResidualsFitter.h.

References m_printLevel.

Referenced by MuonResidualsTwoBin::setPrintLevel().

132 { m_printLevel = printLevel; }

◆ setStrategy()

void MuonResidualsFitter::setStrategy ( int  strategy)
inline

Definition at line 133 of file MuonResidualsFitter.h.

References m_strategy.

Referenced by MuonResidualsTwoBin::setStrategy().

133 { m_strategy = strategy; }

◆ sumofweights()

virtual double MuonResidualsFitter::sumofweights ( )
pure virtual

◆ type()

virtual int MuonResidualsFitter::type ( ) const
pure virtual

◆ useRes()

int MuonResidualsFitter::useRes ( int  pattern = -1)
inline

◆ value()

double MuonResidualsFitter::value ( int  parNum)
inline

◆ write()

void MuonResidualsFitter::write ( FILE *  file,
int  which = 0 
)

Definition at line 383 of file MuonResidualsFitter.cc.

References geometryDiff::file, mps_fire::i, ndata(), numResiduals(), residuals_begin(), residuals_end(), mysort::rows, and eostools::which().

Referenced by pkg.AbstractPkg::generate(), MuonResidualsTwoBin::write(), and querying.connection::write_and_commit().

383  {
384  long rows = numResiduals();
385  int cols = ndata();
386  int whichcopy = which;
387 
388  fwrite(&rows, sizeof(long), 1, file);
389  fwrite(&cols, sizeof(int), 1, file);
390  fwrite(&whichcopy, sizeof(int), 1, file);
391 
392  double *likeAChecksum = new double[cols];
393  double *likeAChecksum2 = new double[cols];
394  for (int i = 0; i < cols; i++) {
395  likeAChecksum[i] = 0.;
396  likeAChecksum2[i] = 0.;
397  }
398 
399  for (std::vector<double *>::const_iterator residual = residuals_begin(); residual != residuals_end(); ++residual) {
400  fwrite((*residual), sizeof(double), cols, file);
401  for (int i = 0; i < cols; i++) {
402  if (fabs((*residual)[i]) > likeAChecksum[i])
403  likeAChecksum[i] = fabs((*residual)[i]);
404  if (fabs((*residual)[i]) < likeAChecksum2[i])
405  likeAChecksum2[i] = fabs((*residual)[i]);
406  }
407  } // end loop over residuals
408 
409  // the idea is that mal-formed doubles are likely to be huge values (or tiny values)
410  // because the exponent gets screwed up; we want to check for that
411  fwrite(likeAChecksum, sizeof(double), cols, file);
412  fwrite(likeAChecksum2, sizeof(double), cols, file);
413 
414  delete[] likeAChecksum;
415  delete[] likeAChecksum2;
416 }
std::vector< double * >::const_iterator residuals_begin() const
std::vector< double * >::const_iterator residuals_end() const
virtual int ndata()=0
def which(cmd)
Definition: eostools.py:336
rows
Definition: mysort.py:12

Member Data Documentation

◆ m_center

double MuonResidualsFitter::m_center[20]
protected

Definition at line 245 of file MuonResidualsFitter.h.

Referenced by selectPeakResiduals().

◆ m_cov

TMatrixDSym MuonResidualsFitter::m_cov
protected

Definition at line 237 of file MuonResidualsFitter.h.

Referenced by covarianceElement(), covarianceMatrix(), and dofit().

◆ m_error

std::vector<double> MuonResidualsFitter::m_error
protected

Definition at line 236 of file MuonResidualsFitter.h.

Referenced by dofit(), and errorerror().

◆ m_fixed

std::vector<bool> MuonResidualsFitter::m_fixed
protected

Definition at line 228 of file MuonResidualsFitter.h.

Referenced by fix(), fixed(), and nfixed().

◆ m_loglikelihood

double MuonResidualsFitter::m_loglikelihood
protected

Definition at line 238 of file MuonResidualsFitter.h.

Referenced by dofit(), and loglikelihood().

◆ m_minHits

int MuonResidualsFitter::m_minHits
protected

◆ m_parNum2InitValue

std::map<int, double> MuonResidualsFitter::m_parNum2InitValue
protected

Definition at line 229 of file MuonResidualsFitter.h.

Referenced by setInitialValue().

◆ m_parNum2parIdx

std::map<int, int> MuonResidualsFitter::m_parNum2parIdx
protected

Definition at line 240 of file MuonResidualsFitter.h.

Referenced by parNum2parIdx().

◆ m_printLevel

int MuonResidualsFitter::m_printLevel
protected

Definition at line 230 of file MuonResidualsFitter.h.

Referenced by setPrintLevel().

◆ m_radii

double MuonResidualsFitter::m_radii[20]
protected

Definition at line 246 of file MuonResidualsFitter.h.

Referenced by selectPeakResiduals().

◆ m_residuals

std::vector<double *> MuonResidualsFitter::m_residuals
protected

◆ m_residuals_ok

std::vector<bool> MuonResidualsFitter::m_residuals_ok
protected

◆ m_residualsModel

int MuonResidualsFitter::m_residualsModel
protected

Definition at line 224 of file MuonResidualsFitter.h.

Referenced by MuonResidualsFitter(), and residualsModel().

◆ m_strategy

int MuonResidualsFitter::m_strategy
protected

Definition at line 230 of file MuonResidualsFitter.h.

Referenced by dofit(), and setStrategy().

◆ m_useResiduals

int MuonResidualsFitter::m_useResiduals
protected

Definition at line 226 of file MuonResidualsFitter.h.

Referenced by useRes().

◆ m_value

std::vector<double> MuonResidualsFitter::m_value
protected

Definition at line 235 of file MuonResidualsFitter.h.

Referenced by dofit(), and value().

◆ m_weightAlignment

bool MuonResidualsFitter::m_weightAlignment
protected