CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Member Functions | Static Public Attributes | Static Private Member Functions | Static Private Attributes
Fit Class Reference

#include <Fit.h>

Public Member Functions

 Fit ()
 
 ~Fit ()
 

Static Public Member Functions

static void calculateSimulatedMeasurementsWithOriginalValues ()
 
static void dumpEntryAfterFit (ALIFileOut &fileout, const Entry *entry, double entryvalue, ALIbool printErrors=true, ALIbool printOrig=true)
 
static void dumpEntryCorrelations (ALIFileOut &file)
 
static void dumpFittedValues (ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
 
static void dumpFittedValuesInAllAncestorFrames (ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
 
static void dumpMatrices ()
 
static ALIint findEntryFitPosition (const ALIstring &opto_name, const ALIstring &entry_name)
 
static ALIbool fitNextEvent (ALIuint &nEvent)
 
static ALIMatrixGetAtWAMatrix ()
 
static FitgetInstance ()
 
static ALIint noFitIterations ()
 
static void printCentreInOptOFrame (const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
 
static void PrintChi2 (ALIdouble fit_quality, ALIbool isFirst)
 
static void printRotationAnglesInOptOFrame (const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
 
static void setFittableEntries ()
 
static void startFit ()
 

Static Public Attributes

static ALIuint nEvent = 1
 

Static Private Member Functions

static void addDaMatrixToEntries ()
 
static void CheckIfFitPossible ()
 
static int CheckIfMeasIsProportionalToAnother (ALIuint measNo)
 
static void CreateMatrices ()
 
static void deleteMatrices ()
 
static void evaluateFitQuality (const FitQuality fq, const double daFactor)
 
static void FillMatricesWithCalibratedParameters ()
 
static void FillMatricesWithMeasurements ()
 
static FitQuality fitParameters (const double daFactor)
 
static double getEntryValue (const Entry *entry)
 
static FitQuality getFitQuality (const ALIbool canBeGood=TRUE)
 
static std::string GetMeasurementName (int meas)
 
static ALIdouble GetSChi2 (ALIbool useDa)
 
static void multiplyMatrices ()
 
static void PropagateErrors ()
 
static void redoMatrices ()
 
static void setCorrelationFromParamFitted (const pss &entry1, const pss &entry2, ALIdouble correl)
 
static void setCorrelationFromParamFitted (const ALIint fit_pos1, const ALIint fit_pos2, ALIdouble correl)
 
static void setCorrelationsInWMatrix ()
 
static void substractLastDisplacementToEntries (const ALIdouble factor)
 
static void WriteVisualisationFiles ()
 

Static Private Attributes

static ALIint _NoColumnsA
 
static ALIint _NoLinesA
 
static ALIMatrixAMatrix
 
static ALIMatrixAtMatrix
 
static ALIMatrixAtWAMatrix
 
static ALIMatrixDaMatrix
 
static Fitinstance = 0
 
static ALIint MaxNoFitIterations = -1
 
static ALIdouble theFitQualityCut = -1
 
static ALIdouble theMinDaFactor = 1.e-8
 
static ALIint theMinimumEntryQuality
 
static ALIint theNoFitIterations
 
static ALIdouble thePreviousIterationFitQuality = DBL_MAX
 
static ALIdouble theRelativeFitQualityCut = -1
 
static ALIMatrixWMatrix
 
static ALIMatrixyfMatrix
 

Detailed Description

Definition at line 34 of file Fit.h.

Constructor & Destructor Documentation

Fit::Fit ( )
inline

Definition at line 38 of file Fit.h.

Referenced by getInstance().

38 { };
Fit::~Fit ( )
inline

Member Function Documentation

void Fit::addDaMatrixToEntries ( )
staticprivate

Definition at line 1065 of file Fit.cc.

References begin, gather_cfg::cout, DaMatrix, ALIUtils::debug, MatrixMeschach::Dump(), Model::EntryList(), and theMinimumEntryQuality.

Referenced by fitNextEvent(), and noFitIterations().

1066 {
1067 
1068  if(ALIUtils::debug >= 4) {
1069  std::cout << "@@ Adding correction (DaMatrix) to Entries " << std::endl;
1070  DaMatrix->Dump("DaMatrix =");
1071  }
1072 
1073  /*- Now there are other places where entries are changed
1074  if( ALIUtils::report >= 3 ) {
1075  ALIFileOut& fileout = ALIFileOut::getInstance( Model::ReportFName() );
1076  fileout << std::endl << " CHANGE IN ENTRIES" << std::endl
1077  << " Optical Object Parameter xxxxxx " << std::endl;
1078  }*/
1079 
1080  ALIint nEnt = 0;
1081  std::vector<Entry*>::const_iterator vecite;
1082  for ( vecite = Model::EntryList().begin();
1083  vecite != Model::EntryList().end(); ++vecite ) {
1084 //------------------ Number of parameters 'cal'
1085 // (= No parameters to be fitted - No parameters 'unk' )
1086  //- std::cout << "qual" << (*vecite)->quality() << theMinimumEntryQuality << std::endl;
1087  if ( (*vecite)->quality() >= theMinimumEntryQuality ){
1088  if ( ALIUtils::debug >= 5) {
1089  std::cout << std::endl << " @@@ PENTRY change "
1090  << (*vecite)->OptOCurrent()->name() << " " << (*vecite)->name() << " "
1091  << " change= " << (*DaMatrix)(nEnt,0)
1092  << " value= " << (*vecite)->valueDisplacementByFitting()
1093  << std::endl;
1094  }
1095  /* if( ALIUtils::report >=3 ) {
1096  ALIFileOut& fileout = ALIFileOut::getInstance( Model::ReportFName() );
1097  fileout << "dd" << std::setw(30) << (*vecite)->OptOCurrent()->name()
1098  << std::setw(8) << " " << (*vecite)->name() << " "
1099  << std::setw(8) << " " << (*DaMatrix)(nEnt,0) / (*vecite)->OutputValueDimensionFactor()
1100  << " " << (*vecite)->valueDisplacementByFitting() / (*vecite)->OutputValueDimensionFactor() << " fitpos " << (*vecite)->fitPos()
1101  << std::endl;
1102  }*/
1103 
1104  //----- Store this displacement
1105  if(ALIUtils::debug >= 4) std::cout << " old valueDisplacementByFitting " << (*vecite)->name() << " " << (*vecite)->valueDisplacementByFitting() << " original value " << (*vecite)->value() <<std::endl;
1106 
1107  (*vecite)->addFittedDisplacementToValue( (*DaMatrix)(nEnt,0) );
1108 
1109  if(ALIUtils::debug >= 4) std::cout << nEnt << " new valueDisplacementByFitting " << (*vecite)->OptOCurrent()->name() << " " << (*vecite)->name() << " = " << (*vecite)->valueDisplacementByFitting() << " " << (*DaMatrix)(nEnt,0) << std::endl ;
1110  nEnt++;
1111  }
1112  }
1113 
1114 }
static ALIint theMinimumEntryQuality
Definition: Fit.h:184
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
static ALIMatrix * DaMatrix
Definition: Fit.h:165
#define begin
Definition: vmac.h:30
void Dump(const ALIstring &mtext)
void Fit::calculateSimulatedMeasurementsWithOriginalValues ( )
static

Definition at line 515 of file Fit.cc.

References begin, gather_cfg::cout, ALIUtils::debug, Model::MeasurementList(), and DeviationsFromFileSensor2D::setApply().

Referenced by fitNextEvent(), redoMatrices(), WriteVisualisationFiles(), and ~Fit().

516 {
517  // if( ALIUtils::debug >= 4) OpticalObjectMgr::getInstance()->dumpOptOs();
518 
519  //---------- Set DeviationsFromFileSensor2D::apply true
521 
522  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::calculateSimulatedMeasurementsWithOriginalValues" <<std::endl;
523  //---------- Loop Measurements
524  std::vector< Measurement* >::const_iterator vmcite;
525  for ( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite) {
526  //----- Calculate Simulated Value Original
527  (*vmcite)->calculateOriginalSimulatedValue();
528  }
529 
530  //---------- Set DeviationsFromFileSensor2D::apply false
531  // It cannot be applied when calculating derivatives, because after a displacement the laser could hit another square in matrix and then cause a big step in the derivative
533 
534 }
static ALIint debug
Definition: ALIUtils.h:36
static void setApply(ALIbool val)
#define begin
Definition: vmac.h:30
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
void Fit::CheckIfFitPossible ( )
staticprivate

Definition at line 1545 of file Fit.cc.

References funct::abs(), ALI_DBL_MIN, AMatrix, begin, MessageLogger_cfi::cerr, gather_cfg::cout, ALIUtils::debug, Model::EntryList(), Exception, FALSE, cuy::ii, Model::MeasurementList(), MatrixMeschach::NoLines(), and TRUE.

Referenced by GetAtWAMatrix(), and multiplyMatrices().

1546 {
1547  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::CheckIfFitPossible" << std::endl;
1548 
1549  //----- Check if there is an unknown parameter that is not affecting any measurement
1550  ALIint NolinMes = 0;
1551  std::vector<Measurement*>::const_iterator vmcite;
1552  for ( vmcite = Model::MeasurementList().begin();
1553  vmcite != Model::MeasurementList().end(); ++vmcite) {
1554  NolinMes += (*vmcite)->dim();
1555  }
1556 
1557  std::vector< Entry* >::const_iterator vecite;
1558  for ( vecite = Model::EntryList().begin(); vecite != Model::EntryList().end(); ++vecite ) {
1559  if( ALIUtils::debug >= 4 ) std::cout << "Fit::CheckIfFitPossible looping for entry " << (*vecite)->longName() << std::endl;
1560  if ( (*vecite)->quality() == 2 ) {
1561  ALIint nCol = (*vecite)->fitPos();
1562  //--- Check all measurements
1563  ALIbool noDepend = TRUE;
1564  if( ALIUtils::debug >= 4 ) std::cout << "Fit::CheckIfFitPossible looping for entry " << nCol << std::endl;
1565  for( ALIint ii = 0; ii < NolinMes; ii++ ) {
1566  if( ALIUtils::debug >= 5 ) std::cout << " Derivative= (" << ii << "," << nCol << ") = " << (*AMatrix)(ii,nCol) << std::endl;
1567 
1568  if( std::abs((*AMatrix)(ii,nCol)) > ALI_DBL_MIN ) {
1569  if( ALIUtils::debug >= 5 ) std::cout << "Fit::CheckIfFitIsPossible " << nCol << " " << ii << " = " << (*AMatrix)(ii,nCol) << std::endl;
1570  noDepend = FALSE;
1571  break;
1572  }
1573  }
1574  if( noDepend ){
1575  throw cms::Exception("SDFError") << "!!!FATAL ERROR: Fit::CheckIfFitPossible() no measurement depends on unknown entry " << (*vecite)->OptOCurrent()->name() << "/" << (*vecite)->name() << std::endl
1576  << "!!! Fit will not be possible! " << std::endl;
1577  }
1578  }
1579  }
1580 
1581  //------ Check if there are two unknown entries that have the derivatives of all measurements w.r.t. then equal (or 100% proportional). In this case any value of the first entry can be fully compensated by another value in the second entry without change in any measurement ---> the two entries cannot be fitted!
1582 
1583  std::vector< Entry* >::const_iterator vecite1,vecite2;
1584  ALIint nLin = AMatrix->NoLines();
1585  ALIdouble derivPrec = ALI_DBL_MIN;
1586  //---------- Loop entries
1587  for ( vecite1 = Model::EntryList().begin();
1588  vecite1 != Model::EntryList().end(); ++vecite1 ) {
1589  if( (*vecite1)->quality() == 2 ) {
1590  vecite2 = vecite1; ++vecite2;
1591  for ( ;vecite2 != Model::EntryList().end(); ++vecite2 ) {
1592  if( (*vecite2)->quality() == 2 ) {
1593  ALIint fitpos1 = (*vecite1)->fitPos();
1594  ALIint fitpos2 = (*vecite2)->fitPos();
1595  if( ALIUtils::debug >= 5 ) std::cout << "Fit::CheckIfFitIsPossible checking " << (*vecite1)->longName() << " ( " << fitpos1 << " ) & " << (*vecite2)->longName() << " ( " << fitpos2 << " ) "<< std::endl;
1596  ALIdouble prop = DBL_MAX;
1597  ALIbool isProp = TRUE;
1598  for( ALIint ii = 0; ii < nLin; ii++ ) {
1599  if( ALIUtils::debug >= 5 ) std::cout << "Fit::CheckIfFitIsPossible " << ii << " : " << (*AMatrix)(ii,fitpos1) << " ?= " << (*AMatrix)(ii,fitpos2) << std::endl;
1600  if( std::abs((*AMatrix)(ii,fitpos1)) < derivPrec ) {
1601  if( std::abs((*AMatrix)(ii,fitpos2)) > derivPrec ) {
1602  isProp = FALSE;
1603  break;
1604  }
1605  } else {
1606  ALIdouble propn = (*AMatrix)(ii,fitpos2) / (*AMatrix)(ii,fitpos1);
1607  if( prop != DBL_MAX && prop != propn ) {
1608  isProp = FALSE;
1609  break;
1610  }
1611  prop = propn;
1612  }
1613  }
1614  if( isProp ) {
1615  std::cerr << "!!!FATAL ERROR: Fit::CheckIfFitPossible() two entries for which the measurements have the same dependency (or 100% proportional) " << (*vecite1)->longName() << " & " << (*vecite2)->longName() << std::endl
1616  << "!!! Fit will not be possible! " << std::endl;
1617  throw cms::Exception("SDFError");
1618  }
1619  }
1620  }
1621  }
1622  }
1623 }
ALIint NoLines() const
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIMatrix * AMatrix
Definition: Fit.h:160
#define TRUE
Definition: scimark2.h:12
const double ALI_DBL_MIN
Definition: CocoaGlobals.h:25
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
bool ALIbool
Definition: CocoaGlobals.h:19
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ii
Definition: cuy.py:588
#define begin
Definition: vmac.h:30
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of FALSE
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
int Fit::CheckIfMeasIsProportionalToAnother ( ALIuint  measNo)
staticprivate

Definition at line 1626 of file Fit.cc.

References funct::abs(), ALI_DBL_MIN, AMatrix, gather_cfg::cout, ALIUtils::debug, cuy::ii, findQualityFiles::jj, MatrixMeschach::NoColumns(), and MatrixMeschach::NoLines().

Referenced by GetAtWAMatrix().

1627 {
1628  int measProp = -1;
1629 
1630  std::set<ALIuint> columnsEqual;
1631  std::set<ALIuint> columnsEqualSave;
1632  ALIuint biggestColumn = 0;
1633  ALIdouble biggest = 0.;
1634  for (int ii = 0; ii < AMatrix->NoColumns(); ii++ ){
1635  if( std::abs((*AMatrix)(measNo,ii)) > biggest ) {
1636  biggest = std::abs((*AMatrix)(measNo,ii));
1637  biggestColumn = ii;
1638  }
1639  columnsEqualSave.insert(ii);
1640  }
1641 
1642  ALIdouble div;
1643 
1644  for( int jj = 0; jj < AMatrix->NoLines(); jj++ ){
1645  if( jj == int(measNo) ) continue;
1646  columnsEqual = columnsEqualSave;
1647  // check if ratio of each column to 'biggestColumn' is the same as for the N measurement
1648  for (int ii = 0; ii < AMatrix->NoColumns(); ii++ ){
1649  div = (*AMatrix)(measNo,ii)/(*AMatrix)(measNo,biggestColumn);
1650  if( std::abs((*AMatrix)(jj,ii)) > ALI_DBL_MIN && std::abs(div - (*AMatrix)(jj,ii)/(*AMatrix)(jj,biggestColumn) ) > ALI_DBL_MIN ) {
1651  if( ALIUtils::debug >= 3 ) std::cout << "CheckIfMeasIsProportionalToAnother 2 columns = " << ii << " in " << measNo << " & " << jj << std::endl;
1652  } else {
1653  if( ALIUtils::debug >= 3 ) std::cout << "CheckIfMeasIsProportionalToAnother 2 columns != " << ii << " in " << measNo << " & " << jj << std::endl;
1654  // if it is not equal delete this column
1655  std::set<ALIuint>::iterator ite = columnsEqual.find( ii );
1656  if( ite != columnsEqual.end() ){
1657  columnsEqual.erase(ite);
1658  }
1659  }
1660  }
1661  // check if not all columns have been deleted from columnsEqual
1662  if( !columnsEqual.empty() ) {
1663  if( ALIUtils::debug >= 3 ) std::cout << "CheckIfMeasIsProportionalToAnother " << measNo << " = " << jj << std::endl;
1664  measProp = jj;
1665  break;
1666  }
1667  }
1668 
1669  return measProp;
1670 }
ALIint NoLines() const
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIMatrix * AMatrix
Definition: Fit.h:160
const double ALI_DBL_MIN
Definition: CocoaGlobals.h:25
static ALIint debug
Definition: ALIUtils.h:36
ALIint NoColumns() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ii
Definition: cuy.py:588
unsigned int ALIuint
Definition: CocoaGlobals.h:17
void Fit::CreateMatrices ( )
staticprivate

Definition at line 557 of file Fit.cc.

References AMatrix, begin, gather_cfg::cout, ALIUtils::debug, Model::EntryList(), GlobalOptionMgr::getInstance(), GlobalOptionMgr::GlobalOptions(), Model::MeasurementList(), theMinimumEntryQuality, WMatrix, and yfMatrix.

Referenced by noFitIterations(), and PropagateErrors().

558 {
559 
560  //---------- Count number of measurements
561  ALIint NoMeas = 0;
562  std::vector< Measurement* >::const_iterator vmcite;
563  for ( vmcite = Model::MeasurementList().begin();
564  vmcite != Model::MeasurementList().end(); ++vmcite ) {
565  NoMeas += (*vmcite)->dim();
566  }
567  if( ALIUtils::debug >= 9) std::cout << "NOMEAS" << NoMeas << std::endl;
568 
569  //-------- Count number of 'cal'ibrated parameters
570  ALIint nEnt_cal = 0;
571  ALIint noent = 0;
572  //- std::cout << Model::EntryList().size() << std::endl;
574  if ( gomgr->GlobalOptions()[ "calcul_type" ] == 0) { // fit also 'cal' parameters
575  //- if( ALIUtils::debug >= 9) std::cout << "NOENTCALLL " << nEnt_cal << std::endl;
576  if( ALIUtils::debug >= 5 ) std::cout << " Count number of 'cal'ibrated parameters " << std::endl;
577  std::vector< Entry* >::iterator veite;
578  for ( veite = Model::EntryList().begin();
579  veite != Model::EntryList().end(); ++veite ) {
580  if ( (*veite)->quality() == 1 ) nEnt_cal++;
581  noent++;
582  if( ALIUtils::debug >= 6) {
583  std::cout <<(*veite)->quality() << " " << (*veite)->OptOCurrent()->name() << " "
584  << (*veite)->name() << " # ENT CAL " << nEnt_cal << " # ENT " << noent << std::endl;
585  }
586  }
587  }
588 
589  //---------- Count number parameters to be fitted ('cal' + 'unk')
590  ALIint NoParamFit = 0;
591  std::vector<Entry*>::const_iterator vecite;
592  for ( vecite = Model::EntryList().begin();
593  vecite != Model::EntryList().end(); ++vecite) {
594  if ( (*vecite)->quality() >= theMinimumEntryQuality ) {
595  NoParamFit++;
596  if( ALIUtils::debug >= 99) std::cout <<(*vecite)->quality() << (*vecite)->OptOCurrent()->name() << (*vecite)->name() << "NoParamFit" << NoParamFit << std::endl;
597  // break;
598  }
599  }
600 
601  //---------- Create Matrices
602  ALIint NoLinesA = NoMeas + nEnt_cal;
603  ALIint NoColumnsA = NoParamFit;
604  AMatrix = new ALIMatrix( NoLinesA, NoColumnsA );
605 
606  ALIint NoLinesW = NoLinesA;
607  ALIint NoColumnsW = NoLinesA;
608  WMatrix = new ALIMatrix( NoLinesW, NoColumnsW );
609 
610  ALIint NoLinesY = NoLinesA;
611  //op yMatrix = new ALIMatrix( NoLinesY, 1 );
612  yfMatrix = new ALIMatrix( NoLinesY, 1 );
613 
614  //op fMatrix = new ALIMatrix( NoLinesY, 1 );
615 
616  if ( ALIUtils::debug >= 4 ) std::cout << "CreateMatrices: NoLinesA = " << NoLinesA <<
617  " NoColumnsA = " << NoColumnsA << std::endl;
618 }
static ALIMatrix * AMatrix
Definition: Fit.h:160
static ALIint theMinimumEntryQuality
Definition: Fit.h:184
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static GlobalOptionMgr * getInstance()
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
static ALIMatrix * WMatrix
Definition: Fit.h:162
static ALIMatrix * yfMatrix
Definition: Fit.h:170
MatrixMeschach ALIMatrix
#define begin
Definition: vmac.h:30
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
void Fit::deleteMatrices ( )
staticprivate

Definition at line 538 of file Fit.cc.

References AMatrix, AtMatrix, AtWAMatrix, DaMatrix, WMatrix, and yfMatrix.

Referenced by noFitIterations(), and redoMatrices().

539 {
540  //delete matrices created in previous iteration
541  delete DaMatrix;
542  delete AMatrix;
543  delete WMatrix;
544  delete yfMatrix;
545  //op delete fMatrix;
546  delete AtMatrix;
547  delete AtWAMatrix;
548  //op delete VaMatrix;
549  //- delete VyMatrix;
550  //op delete PDMatrix;
551 
552 }
static ALIMatrix * AMatrix
Definition: Fit.h:160
static ALIMatrix * AtMatrix
Definition: Fit.h:161
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
static ALIMatrix * WMatrix
Definition: Fit.h:162
static ALIMatrix * DaMatrix
Definition: Fit.h:165
static ALIMatrix * yfMatrix
Definition: Fit.h:170
void Fit::dumpEntryAfterFit ( ALIFileOut fileout,
const Entry entry,
double  entryvalue,
ALIbool  printErrors = true,
ALIbool  printOrig = true 
)
static

Definition at line 1319 of file Fit.cc.

References funct::abs(), AtWAMatrix, gather_cfg::cout, ALIUtils::debug, Entry::fitPos(), MatrixMeschach::Mat(), Entry::name(), OpticalObject::name(), Entry::OptOCurrent(), Entry::OutputSigmaDimensionFactor(), Entry::OutputValueDimensionFactor(), Entry::quality(), ALIUtils::report, Entry::sigma(), mathSSE::sqrt(), theMinimumEntryQuality, Entry::value(), and Entry::valueDisplacementByFitting().

Referenced by dumpFittedValues(), printCentreInOptOFrame(), printRotationAnglesInOptOFrame(), and ~Fit().

1320 {
1321  //- std::cout << " Fit::dumpEntryAfterFit " << entryvalue << std::endl;
1322  ALIdouble dimv = entry->OutputValueDimensionFactor();
1323  ALIdouble dims = entry->OutputSigmaDimensionFactor();
1324  //----- Dump to std::cout
1325  if(ALIUtils::debug >= 3) {
1326  std::cout << "ENTRY: "
1327  << std::setw(30) << entry->OptOCurrent()->name()
1328  << std::setw(8) << " " << entry->name() << " "
1329  << std::setw(8) << ( entry->value() + entry->valueDisplacementByFitting() )
1330  <<" " << entry->value()
1331  << " Q" << entry->quality() << std::endl;
1332  }
1333 
1334  if ( entry->quality() == 2 ) {
1335  fileout << "UNK: " << entry->fitPos() << " ";
1336  } else if ( entry->quality() == 1 ) {
1337  fileout << "CAL: " << entry->fitPos() << " ";
1338  // fileout << "CAL: -1 ";
1339  } else {
1340  fileout << "FIX: -1 ";
1341  }
1342 
1343  fileout << std::setw(30) << entry->OptOCurrent()->name()
1344  << std::setw(8) << " " << entry->name() << " "
1345  << std::setw(8) << std::setprecision(8) << entryvalue;
1346  if ( entry->quality() >= theMinimumEntryQuality ) {
1347  if( printErrors ) fileout << " +- " << std::setw(8) << sqrt(AtWAMatrix->Mat()->me[entry->fitPos()][entry->fitPos()]) / dims;
1348  } else {
1349  if( printErrors ) fileout << " +- " << std::setw(8) << 0.;
1350  }
1351  if( printOrig ) {
1352  fileout << std::setw(8) << " " << entry->value() / dimv;
1353  if( printErrors ) fileout << " +- " << std::setw(8) << entry->sigma() /dims << " Q" << entry->quality();
1354 
1355  if( ALIUtils::report >= 2) {
1356  float dif = ( entry->value() + entry->valueDisplacementByFitting() ) / dimv - entry->value() / dimv;
1357  if( std::abs(dif) < 1.E-9 ) dif = 0.;
1358  fileout << " DIFF= " << dif;
1359  // << " == " << ( entry->value() + entry->valueDisplacementByFitting() ) / dimv - entryvalue << " @@ " << ( entry->value() + entry->valueDisplacementByFitting() ) / dimv << " @@ " << entryvalue;
1360  } else {
1361  // fileout << std::endl;
1362  }
1363  }
1364 
1365  fileout << std::endl;
1366 
1367 }
long double ALIdouble
Definition: CocoaGlobals.h:11
virtual ALIdouble OutputValueDimensionFactor() const
Definition: Entry.h:39
ALIdouble valueDisplacementByFitting() const
Definition: Entry.h:63
virtual ALIdouble OutputSigmaDimensionFactor() const
Definition: Entry.h:40
static ALIint theMinimumEntryQuality
Definition: Fit.h:184
ALIdouble value() const
Definition: Entry.h:55
static ALIint debug
Definition: ALIUtils.h:36
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const MAT * Mat() const
ALIint fitPos() const
Definition: Entry.h:60
const ALIstring & name() const
Definition: Entry.h:52
static ALIint report
Definition: ALIUtils.h:35
ALIint quality() const
Definition: Entry.h:59
const ALIstring & name() const
Definition: OpticalObject.h:60
OpticalObject * OptOCurrent() const
Definition: Entry.h:61
ALIdouble sigma() const
Definition: Entry.h:57
void Fit::dumpEntryCorrelations ( ALIFileOut file)
static

Definition at line 1370 of file Fit.cc.

References funct::abs(), AtWAMatrix, begin, corr, gather_cfg::cout, ALIUtils::debug, OpticalObjectMgr::dumpOptOs(), Model::EntryList(), OpticalObjectMgr::getInstance(), MatrixMeschach::Mat(), mathSSE::sqrt(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by dumpFittedValues(), and ~Fit().

1371 {
1372  //----- Only dump correlations bigger than a factor
1373  ALIdouble minCorrel = 1.E-6;
1374  //----- Dump correlations
1375  fileout << std::endl << "CORRELATION BETWEEN 'unk' ENTRIES: (>= " << minCorrel<< " )" << std::endl
1376  << "No_1 No_2 correlation " << std::endl;
1377 
1378  ALIuint i1,i2;
1379  std::vector< Entry* >::iterator veite1, veite2;
1380  std::string E1, E2;
1381  for ( veite1 = Model::EntryList().begin();
1382  veite1 != Model::EntryList().end(); ++veite1 ) {
1383  if( (*veite1)->quality() == 0 ) {
1384  continue;
1385  } else if( (*veite1)->quality() == 1 ) {
1386  E1 = "C";
1387  } else if( (*veite1)->quality() == 2 ) {
1388  E1 = "U";
1389  }
1390  i1 = (*veite1)->fitPos();
1391 
1392  for ( veite2 = veite1+1;
1393  veite2 != Model::EntryList().end(); ++veite2 ) {
1394  i2 = (*veite2)->fitPos();
1395  if( (*veite2)->quality() == 0 ) {
1396  continue;
1397  } else if( (*veite2)->quality() == 1 ) {
1398  E2 = "C";
1399  } else if( (*veite2)->quality() == 2 ) {
1400  E2 = "U";
1401  }
1402  ALIdouble corr = AtWAMatrix->Mat()->me[i1][i2];
1403  ALIdouble corrf = corr / sqrt(AtWAMatrix->Mat()->me[i1][i1])
1404  / sqrt(AtWAMatrix->Mat()->me[i2][i2]);
1405  if (std::abs(corrf) >= minCorrel ) {
1406  if(ALIUtils::debug >= 0) {
1407  std::cout << "CORR:" << E1 << "" << E2 << " (" << i1 << ")" << " (" << i2 << ")" << " " << corrf << std::endl;
1408  }
1409  fileout << "CORR:" << E1 << "" << E2 << " (" << i1 << ")" << " (" << i2 << ")" << " " << corrf << std::endl;
1410  }
1411  }
1412  }
1413  //------- Dump optical object list
1415 
1416 }
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIint debug
Definition: ALIUtils.h:36
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
static OpticalObjectMgr * getInstance()
Get the only instance.
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
T sqrt(T t)
Definition: SSEVec.h:18
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const MAT * Mat() const
JetCorrectorParameters corr
Definition: classes.h:5
void dumpOptOs(std::ostream &out=std::cout) const
#define begin
Definition: vmac.h:30
unsigned int ALIuint
Definition: CocoaGlobals.h:17
void Fit::dumpFittedValues ( ALIFileOut fileout,
ALIbool  printErrors = true,
ALIbool  printOrig = true 
)
static

Definition at line 1147 of file Fit.cc.

References begin, MessageLogger_cfi::cerr, gather_cfg::cout, ALIUtils::debug, dumpEntryAfterFit(), dumpEntryCorrelations(), getEntryValue(), cuy::ii, Model::OptOList(), OpticalObject::parent(), printCentreInOptOFrame(), and printRotationAnglesInOptOFrame().

Referenced by fitNextEvent(), and ~Fit().

1148 {
1149  //---------- print
1150  if(ALIUtils::debug >= 0) {
1151  std::cout << "SRPRPOS " << " Optical Object "
1152  << " Parameter" << " Fit.Value " << " Orig.Value" << std::endl;
1153  }
1154  //---------- Dump header
1155  if(ALIUtils::debug >= 0) std::cout << std::endl << "FITTED VALUES " << std::endl;
1156  fileout << std::endl << "FITTED VALUES " << std::endl
1157  << "nEnt_unk"
1158  << " Optical Object"
1159  << " Parameter ";
1160  if( printErrors ) {
1161  fileout << " value (+-error)"
1162  << " orig.val (+-error)";
1163  } else {
1164  fileout << " value "
1165  << " orig.val ";
1166  }
1167  fileout << " quality"
1168  << std::endl;
1169 
1170  //---------- Iterate over OptO list
1171  std::vector< Entry* > entries;
1172  // const Entry* entry;
1173  int ii, siz;
1174  std::vector< OpticalObject* >::const_iterator vocite;
1175  for( vocite = Model::OptOList().begin(); vocite != Model::OptOList().end(); ++vocite ) {
1176  if( (*vocite)->type() == ALIstring("system") ) continue;
1177 
1178  fileout << " %%%% Optical Object: " << (*vocite)->longName() << std::endl;
1179 
1180  entries = (*vocite)->CoordinateEntryList();
1181  siz = entries.size();
1182  if( siz != 6 ) {
1183  std::cerr << "!!! FATAL ERROR: strange number of coordinates = " << siz << std::endl;
1184  abort();
1185  }
1186 
1187  //----- Dump entry centre coordinates (centre in current coordinates of parent frame <> summ of displacements, as each displacement is done with a different rotation of parent frame)
1188  OpticalObject* opto = entries[0]->OptOCurrent();
1189  const OpticalObject* optoParent = opto->parent();
1190  printCentreInOptOFrame( opto, optoParent, fileout, printErrors, printOrig );
1191 
1192  //----- Dump entry angles coordinates
1193  printRotationAnglesInOptOFrame( opto, optoParent, fileout, printErrors, printOrig );
1194 
1195  //----- Dump extra entries
1196  entries = (*vocite)->ExtraEntryList();
1197  siz = entries.size();
1198  for( ii = 0; ii < siz; ii++ ){
1199  double entryvalue = getEntryValue( entries[ii] );
1200  dumpEntryAfterFit( fileout, entries[ii], entryvalue, printErrors, printOrig );
1201  }
1202  }
1203 
1204  dumpEntryCorrelations( fileout );
1205 
1206 }
static void printCentreInOptOFrame(const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1257
static void dumpEntryAfterFit(ALIFileOut &fileout, const Entry *entry, double entryvalue, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1319
static ALIint debug
Definition: ALIUtils.h:36
static double getEntryValue(const Entry *entry)
Definition: Fit.cc:1301
const OpticalObject * parent() const
Definition: OpticalObject.h:62
ii
Definition: cuy.py:588
static std::vector< OpticalObject * > & OptOList()
Definition: Model.h:71
static void dumpEntryCorrelations(ALIFileOut &file)
Definition: Fit.cc:1370
static void printRotationAnglesInOptOFrame(const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1289
#define begin
Definition: vmac.h:30
std::string ALIstring
Definition: CocoaGlobals.h:9
void Fit::dumpFittedValuesInAllAncestorFrames ( ALIFileOut fileout,
ALIbool  printErrors = true,
ALIbool  printOrig = true 
)
static

Definition at line 1210 of file Fit.cc.

References begin, OpticalObject::longName(), Model::OptOList(), OpticalObject::parent(), printCentreInOptOFrame(), and printRotationAnglesInOptOFrame().

Referenced by fitNextEvent(), and ~Fit().

1211 {
1212  //---------- print
1213  fileout << std::endl << "@@@@ FITTED VALUES IN ALL ANCESTORS " << std::endl
1214  << "nEnt_unk"
1215  << " Optical Object"
1216  << " Parameter ";
1217  if( printErrors ) {
1218  fileout << " value (+-error)";
1219  if( printOrig ){
1220  fileout << " orig.val (+-error)";
1221  }
1222  } else {
1223  fileout << " value ";
1224  if( printOrig ){
1225  fileout << " orig.val ";
1226  }
1227  }
1228  fileout << " quality"
1229  << std::endl;
1230 
1231  //---------- Iterate over OptO list
1232  std::vector< Entry* > entries;
1233  std::vector< OpticalObject* >::const_iterator vocite;
1234  for( vocite = Model::OptOList().begin(); vocite != Model::OptOList().end(); ++vocite ) {
1235  if( (*vocite)->type() == ALIstring("system") ) continue;
1236 
1237  fileout << " %%%% Optical Object: " << (*vocite)->longName() << std::endl;
1238 
1239  entries = (*vocite)->CoordinateEntryList();
1240 
1241  //----- Dump entry centre coordinates (centre in current coordinates of parent frame <> summ of displacements, as each displacement is done with a different rotation of parent frame)
1242  OpticalObject* opto = *vocite;
1243  const OpticalObject* optoParent = opto->parent();
1244  do {
1245  fileout << " %% IN FRAME : " << optoParent->longName() << std::endl;
1246  printCentreInOptOFrame( opto, optoParent, fileout, printErrors, printOrig );
1247 
1248  //----- Dump entry angles coordinates
1249  printRotationAnglesInOptOFrame( opto, optoParent, fileout, printErrors, printOrig );
1250  optoParent = optoParent->parent();
1251  }while( optoParent );
1252  }
1253 
1254 }
static void printCentreInOptOFrame(const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1257
const OpticalObject * parent() const
Definition: OpticalObject.h:62
const ALIstring longName() const
static std::vector< OpticalObject * > & OptOList()
Definition: Model.h:71
static void printRotationAnglesInOptOFrame(const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1289
#define begin
Definition: vmac.h:30
std::string ALIstring
Definition: CocoaGlobals.h:9
void Fit::dumpMatrices ( )
static

Definition at line 1422 of file Fit.cc.

References AMatrix, AtMatrix, AtWAMatrix, DaMatrix, ALIFileOut::getInstance(), Model::MatricesFName(), MatrixMeschach::ostrDump(), theNoFitIterations, WMatrix, and yfMatrix.

Referenced by fitNextEvent(), and ~Fit().

1423 {
1424  //----- Dump matrices for this iteration
1426  // ofstream matout("matrices.out");
1427  matout << std::endl << " @@@@@@@@@@@@@@@ Iteration No : " << theNoFitIterations << std::endl;
1428  AMatrix->ostrDump( matout, "Matrix A" );
1429  AtMatrix->ostrDump( matout, "Matrix At" );
1430  WMatrix->ostrDump( matout, "Matrix W" );
1431  AtWAMatrix->ostrDump( matout, "Matrix AtWA" );
1432  //op VaMatrix->ostrDump( matout, "Matrix Va" );
1433  DaMatrix->ostrDump( matout, "Matrix Da" );
1434  yfMatrix->ostrDump( matout, "Matrix y" );
1435  //op fMatrix->ostrDump( matout, "Matrix f" );
1436  //op thePropagationMatrix->ostrDump( matout, "propagation Matrix " );
1437  matout.close();
1438 
1439 }
static ALIMatrix * AMatrix
Definition: Fit.h:160
static ALIMatrix * AtMatrix
Definition: Fit.h:161
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
static ALIMatrix * WMatrix
Definition: Fit.h:162
static ALIMatrix * DaMatrix
Definition: Fit.h:165
static ALIMatrix * yfMatrix
Definition: Fit.h:170
void ostrDump(std::ostream &fout, const ALIstring &mtext)
static ALIstring & MatricesFName()
the name of the File for storing the matrices
Definition: Model.h:101
static ALIFileOut & getInstance(const ALIstring &filename)
Definition: ALIFileOut.cc:19
static ALIint theNoFitIterations
Definition: Fit.h:196
static void Fit::evaluateFitQuality ( const FitQuality  fq,
const double  daFactor 
)
staticprivate

Referenced by noFitIterations().

void Fit::FillMatricesWithCalibratedParameters ( )
staticprivate

Definition at line 709 of file Fit.cc.

References MatrixMeschach::AddData(), AMatrix, begin, gather_cfg::cout, ALIUtils::debug, Model::EntryList(), GlobalOptionMgr::getGlobalOptionValue(), GlobalOptionMgr::getInstance(), Model::MeasurementList(), WMatrix, and yfMatrix.

Referenced by noFitIterations(), and PropagateErrors().

710 {
711  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::FillMatricesWithCalibratedParameters" << std::endl;
712 
713  //---------- Count how many measurements
714  ALIint NolinMes = 0;
715  std::vector<Measurement*>::const_iterator vmcite;
716  for ( vmcite = Model::MeasurementList().begin();
717  vmcite != Model::MeasurementList().end(); ++vmcite) {
718  NolinMes += (*vmcite)->dim();
719  }
720  if(ALIUtils::debug>=4) std::cout << "@@FillMatricesWithCalibratedParameters" << std::endl;
721 
722  std::vector< Entry* >::const_iterator vecite;
723  ALIint nEntcal = 0;
724  //---------- Loop entries
725  for ( vecite = Model::EntryList().begin();
726  vecite != Model::EntryList().end(); ++vecite ) {
727 // (= No parameters to be fitted - No parameters 'unk' )
728  //- std::cout << "entry" << (*veite) << std::endl;
729  //----- Take entries of quality = 'cal'
730  if ( (*vecite)->quality() == 1 ){
731  //--- Matrix A: fill diagonals with 1. (derivatives of entry w.r.t itself)
732  ALIint lineNo = NolinMes + nEntcal;
733  ALIint columnNo = (*vecite)->fitPos(); //=? nEntcal
734  AMatrix->AddData( lineNo, columnNo, 1. );
735  if(ALIUtils::debug >= 4) std::cout << "Fit::FillMatricesWithCalibratedParameters: AMatrix ( " << lineNo << " , " << columnNo << ") = " << 1. << std::endl;
736 
737  //--- Matrix W: sigma*sigma
738  ALIdouble entsig = (*vecite)->sigma();
739  if(ALIUtils::debug >= 4) std::cout << "Fit::FillMatricesWithCalibratedParameters: WMatrix ( " << lineNo << " , " << columnNo << ") = " << entsig*entsig << std::endl;
740  WMatrix->AddData( lineNo, lineNo, entsig*entsig );
741 
742  //--- Matrix y & f: fill it with 0.
743  //op yMatrix->AddData( lineNo, 0, (*vecite)->value());
744  //op yfMatrix->AddData( lineNo, 0, (*vecite)->value());
745  ALIdouble calFit;
747  gomgr->getGlobalOptionValue("calParamInyfMatrix", calFit );
748  if( calFit ) {
749  yfMatrix->AddData( lineNo, 0, -(*vecite)->valueDisplacementByFitting() );
750  //- yfMatrix->AddData( lineNo, 0, (*vecite)->value() );
751  //- yfMatrix->AddData( lineNo, 0, (*vecite)->lastAdditionToValueDisplacementByFitting() );
752  //- ALIFileOut& fileout = ALIFileOut::getInstance( Model::ReportFName() );
753  // fileout << "cal to yf " << (*vecite)->OptOCurrent()->name() << " " << (*vecite)->name() << " " << (*vecite)->valueDisplacementByFitting() << endl;
754  // std::cout << "call to yf " << (*vecite)->OptOCurrent()->name() << " " << (*vecite)->name() << " " << (*vecite)->valueDisplacementByFitting() << std::endl;
755 
756  } else {
757  yfMatrix->AddData( lineNo, 0, 0. );
758  }
759  //t if(ALIUtils::debug >= 5) std::cout << "Fit::FillMatricesWithCalibratedParameters: yfMatrix ( " << lineNo << " , " << columnNo << ") = " << (*yfMatrix)(lineNo)(0) << std::endl;
760  nEntcal++;
761  }
762  }
763 
764 }
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIMatrix * AMatrix
Definition: Fit.h:160
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static GlobalOptionMgr * getInstance()
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
int getGlobalOptionValue(const ALIstring &sstr, ALIdouble &val)
--— Search a string in theGlobalOptions and return 1 if found
static ALIMatrix * WMatrix
Definition: Fit.h:162
static ALIMatrix * yfMatrix
Definition: Fit.h:170
void AddData(ALIuint col, ALIuint lin, ALIdouble data)
#define begin
Definition: vmac.h:30
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
void Fit::FillMatricesWithMeasurements ( )
staticprivate

Definition at line 626 of file Fit.cc.

References MatrixMeschach::AddData(), AMatrix, begin, Measurement::cameraScaleFactor, MessageLogger_cfi::cerr, gather_cfg::cout, ALIUtils::debug, MatrixMeschach::Dump(), findQualityFiles::jj, Model::MeasurementList(), theMinimumEntryQuality, WMatrix, and yfMatrix.

Referenced by noFitIterations(), and PropagateErrors().

627 {
628  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::FillMatricesWithMeasurements" << std::endl;
629 
630  int Aline = 0;
631 
632  //---------- Loop Measurements
633  std::vector<Measurement*>::const_iterator vmcite;
634  std::vector<Entry*>::const_iterator vecite;
635  for ( vmcite = Model::MeasurementList().begin();
636  vmcite != Model::MeasurementList().end(); ++vmcite) {
637  if( ALIUtils::debug >= 5 ) std::cout << "FillMatricesWithMeasurements: measurement " << (*vmcite)->name() << " # entries affecting " <<(*vmcite)->affectingEntryList().size() << std::endl;
638 
639  //-------- Array of derivatives with respect to entries
640  ALIint measdim = (*vmcite)->dim();
641  std::vector<ALIdouble> derivRE;
642  // derivRE = new ALIdouble[measdim];
643 
644  //-------- Fill matrix A:
645  //------ Loop only Entries affecting this Measurement
646  //-std::cout << "number affecting entries: " << (*vmcite)->affectingEntryList().size() << std::endl;
647  for ( vecite = (*vmcite)->affectingEntryList().begin();
648  vecite != (*vmcite)->affectingEntryList().end(); ++vecite) {
649  //-------- If good quality, get derivative of measurement with respect to this Entry
650  if ( (*vecite)->quality() >= theMinimumEntryQuality ) {
651  if ( ALIUtils::debug >= 4) {
652  // std::cout << "FillMatricesWithMeasurements: filling element ( " << Aline << " - " << Aline+measdim-1 << " , " << (*vecite)->fitPos() << std::endl;
653  std::cout <<"entry affecting: " << (*vecite)->OptOCurrent()->name() << " " << (*vecite)->name() <<std::endl;
654  }
655  derivRE = (*vmcite)->DerivativeRespectEntry(*vecite);
656  //---------- Fill matrix A with derivatives
657  for ( ALIuint jj = 0; jj < ALIuint(measdim); jj++) {
658  AMatrix->AddData( Aline+jj, (*vecite)->fitPos(), derivRE[jj] );
659  if( ALIUtils::debug >= 5) std::cout << "FillMatricesWithMeasurements: AMATRIX (" << Aline+jj << "," << (*vecite)->fitPos() << " = " << derivRE[jj] << std::endl;
660  //---------- Reset Measurement simulated_value
661  (*vmcite)->setValueSimulated( jj, (*vmcite)->valueSimulated_orig(jj) );
662  }
663  }
664  }
665  // delete[] derivRE;
666 
667  //---------- Fill matrices W, y and f:
668  //------ Loop Measurement coordinates
669  for ( ALIuint jj=0; jj < ALIuint((*vmcite)->dim()); jj++) {
670  ALIdouble sigma = (*vmcite)->sigma()[jj];
671  if ( sigma == 0. ) {
672  std::cerr << "EXITING: Measurement number " <<
673  vmcite - Model::MeasurementList().begin() <<
674  "has 0 error!!" << std::endl;
675  } else {
676  //----- Fill W Matrix with inverse of sigma squared
677  // multiply error by cameraScaleFactor
678  ALIdouble sigmanew = sigma * Measurement::cameraScaleFactor;
679  // std::cout << Aline+jj << " WMATRIX FILLING " << sigmanew << " * " << Measurement::cameraScaleFactor << std::endl;
680  WMatrix->AddData( Aline+jj, Aline+jj, (sigmanew*sigmanew) );
681  }
682  //op //----- Fill Matrices y with measurement value
683  //op yMatrix->AddData( Aline+jj, 0, (*vmcite)->value()[jj] );
684  //op //----- Fill f Matrix with simulated_value
685  //op fMatrix->AddData( Aline+jj, 0, (*vmcite)->valueSimulated_orig(jj) );
686  //----- Fill Matrix y - f with measurement value - simulated value
687  yfMatrix->AddData( Aline+jj, 0, (*vmcite)->value()[jj] - (*vmcite)->valueSimulated_orig(jj) );
688  // std::cout << " yfMatrix FILLING " << Aline+jj << " + " << (*vmcite)->value()[jj] - (*vmcite)->valueSimulated_orig(jj) << " meas " << (*vmcite)->name() << " val " << (*vmcite)->value()[jj] << " simu val " << (*vmcite)->valueSimulated_orig(jj) << std::endl;
689  }
690  if ( ALIUtils::debug >= 99) std::cout << "change line" << Aline << std::endl;
691  Aline += measdim;
692  if ( ALIUtils::debug >= 99) std::cout << "change line" << Aline << std::endl;
693 
694  }
695 
696  if ( ALIUtils::debug >= 4) AMatrix->Dump("Matrix A with meas");
697  if ( ALIUtils::debug >= 4) WMatrix->Dump("Matrix W with meas");
698  if ( ALIUtils::debug >= 4) yfMatrix->Dump("Matrix y with meas");
699 
700 }
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIMatrix * AMatrix
Definition: Fit.h:160
static ALIint theMinimumEntryQuality
Definition: Fit.h:184
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static ALIMatrix * WMatrix
Definition: Fit.h:162
static ALIMatrix * yfMatrix
Definition: Fit.h:170
void AddData(ALIuint col, ALIuint lin, ALIdouble data)
static ALIdouble cameraScaleFactor
Definition: Measurement.h:209
#define begin
Definition: vmac.h:30
void Dump(const ALIstring &mtext)
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
unsigned int ALIuint
Definition: CocoaGlobals.h:17
ALIint Fit::findEntryFitPosition ( const ALIstring opto_name,
const ALIstring entry_name 
)
static

Definition at line 1445 of file Fit.cc.

References MessageLogger_cfi::cerr, OpticalObject::CoordinateEntryList(), cmsRelvalreport::exit, OpticalObject::ExtraEntryList(), and Model::getOptOByName().

Referenced by ~Fit().

1446 {
1447  ALIint fitposi = -99;
1448 
1449  OpticalObject* opto = Model::getOptOByName( opto_name );
1450  //- std::cout << "OPTO = " << opto->name() << std::endl;
1451  std::vector<Entry*>::const_iterator vecite;
1452  for (vecite = opto->CoordinateEntryList().begin();
1453  vecite < opto->CoordinateEntryList().end(); ++vecite) {
1454  //- std::cout << "ENTRYLIST" << (*vecite)->name() << std::endl;
1455  if ((*vecite)->name() == entry_name ) {
1456  //- std::cout << "FOUND " << std::endl;
1457  fitposi = (*vecite)->fitPos();
1458  }
1459  }
1460  for (vecite = opto->ExtraEntryList().begin();
1461  vecite < opto->ExtraEntryList().end(); ++vecite) {
1462  //- std::cout << "ENTRYLIST" << (*vecite)->name() << std::endl;
1463  if ((*vecite)->name() == entry_name ) {
1464  //- std::cout << "FOUND " << std::endl;
1465  fitposi = (*vecite)->fitPos();
1466  }
1467  }
1468 
1469  if(fitposi == -99) {
1470  std::cerr << "!!EXITING: entry name not found: " << entry_name << std::endl;
1471  exit(2);
1472  } else {
1473  return fitposi;
1474  }
1475 }
const std::vector< Entry * > & ExtraEntryList() const
Definition: OpticalObject.h:69
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:65
int ALIint
Definition: CocoaGlobals.h:15
static OpticalObject * getOptOByName(const ALIstring &opto_name)
--— Find an OptO name in theOptOList and return a pointer to it
Definition: Model.cc:580
ALIbool Fit::fitNextEvent ( ALIuint nEvent)
static

Definition at line 149 of file Fit.cc.

References addDaMatrixToEntries(), FittedEntriesManager::AddFittedEntriesSet(), AtWAMatrix, begin, calculateSimulatedMeasurementsWithOriginalValues(), MessageLogger_cfi::cerr, COCOA_FirstIterationInEvent, COCOA_NextIterationInEvent, gather_cfg::cout, ALIUtils::debug, ALIUtils::dumpDimensions(), dumpFittedValues(), dumpFittedValuesInAllAncestorFrames(), dumpMatrices(), Model::EntryList(), FALSE, NtupleManager::FillChi2(), NtupleManager::FillFitParameters(), NtupleManager::FillMeasurements(), NtupleManager::FillNtupleTree(), NtupleManager::FillOptObjects(), fitParameters(), FQbigDistanceToMinimum, FQchiSquareWorsened, FQsmallDistanceToMinimum, CocoaDaqReader::GetDaqReader(), Model::getFittedEntriesReader(), GlobalOptionMgr::getGlobalOptionValue(), FittedEntriesManager::getInstance(), GlobalOptionMgr::getInstance(), NtupleManager::getInstance(), ALIFileOut::getInstance(), GlobalOptionMgr::GlobalOptions(), NtupleManager::InitNtuple(), MaxNoFitIterations, Measurement::only1, Model::OptOList(), FittedEntriesReader::readFittedEntriesFromFile(), CocoaDaqReader::ReadNextEvent(), ALIUtils::report, Model::ReportFName(), Model::setCocoaStatus(), setFittableEntries(), substractLastDisplacementToEntries(), theMinDaFactor, theNoFitIterations, and TRUE.

Referenced by startFit(), and ~Fit().

150 {
152 
153  //----- Reset coordinates to those read at the start
154  std::vector< OpticalObject* >::iterator voite;
155  for( voite = Model::OptOList().begin(); voite != Model::OptOList().end(); ++voite ) {
156  (*voite)->resetOriginalOriginalCoordinates();
157  }
158 
159  //----- Reset entries displacements to 0.
160  std::vector< Entry* >::iterator veite;
161  for( veite = Model::EntryList().begin(); veite != Model::EntryList().end(); ++veite ) {
162  (*veite)->resetValueDisplacementByFitting();
163  }
164 
165 
166  ALIbool lastEvent = false;
167 
168  //- DeviationsFromFileSensor2D::setApply( 1 );
169 
170  //m ALIbool moreDataSets = Model::readMeasurementsFromFile( Measurement::only1Date, Measurement::only1Time );
171 
172  //----- Check if there are more data sets
173  ALIbool moreDataSets = true;
174  if(CocoaDaqReader::GetDaqReader() != nullptr) moreDataSets = CocoaDaqReader::GetDaqReader()->ReadNextEvent();
175 
176  if(ALIUtils::debug >= 5) std::cout << CocoaDaqReader::GetDaqReader() << "$$$$$$$$$$$$$$$ More Data Sets to be processed: " << moreDataSets << std::endl;
177 
178  if( moreDataSets ) {
179  if( ALIUtils::debug >= 2 ) std::cout << std::endl << "@@@@@@@@@@@@@@@@@@ Starting data set fit : " << nEvent << std::endl;
180 
181  //----- Count entries to be fitted, and set their order in theFitPos
183 
184  //----- Dump dimensions of output in 'report.out' file
186  fileout << std::endl << "@@@@@@@ NEW MEASUREMENT SET " << nEvent << std::endl;
187  if( ALIUtils::report >= 1 ) ALIUtils::dumpDimensions( fileout );
188 
189  //----- reset Number of iterations of non linear fit
190  theNoFitIterations = 0;
191 
193  ALIdouble dumpMat;
194  gomgr->getGlobalOptionValue("save_matrices", dumpMat );
195 
196  //----- Fit parameters
197  double daFactor = 1.;
199  for(;; ){
200  if(ALIUtils::debug >= 2) {
201  std::cout << std::endl << "Fit iteration " << theNoFitIterations << " ..." << std::endl;
202  }
203 
204  //---------- Calculate the original simulated values of each Measurement (when all entries have their read in values)
205  calculateSimulatedMeasurementsWithOriginalValues(); //?? original changed atfer each iteration
206 
207  FitQuality fq = fitParameters( daFactor );
208  if( dumpMat > 1 ) dumpMatrices();
209 
210  //- evaluateFitQuality( fq, daFactor );
211 
212  if(ALIUtils::debug >= 2) {
213  std::cout << std::endl << "@@@@ Check fit quality for iteration " << theNoFitIterations << std::endl;
214  }
215 
216  //----- Check if new iteration must be done
217  if( fq == FQsmallDistanceToMinimum ) {
218  if(ALIUtils::debug >= 2) std::cout << std::endl << "@@@@ Fit quality: distance SMALLER than mininum " << std::endl;
221  //--- Print entries in all ancestor frames
222  ALIdouble go;
223  gomgr->getGlobalOptionValue("dumpInAllFrames", go );
225 
226  break; // No more iterations
227  } else if( fq == FQbigDistanceToMinimum ) {
228  if(ALIUtils::debug >= 2) std::cout << std::endl << "@@@@ Fit quality: distance BIGGER than mininum " << std::endl;
231 
232  //----- Next iteration (if not too many already)
234  daFactor = 1.;
235 
236  //----- Too many iterations: end event here
238  if(ALIUtils::debug >= 1) std::cerr << "!!!! WARNING: Too many iterations " << theNoFitIterations << " and fit DOES NOT CONVERGE " << std::endl;
239 
240  if(ALIUtils::report >= 2) {
242  fileout << "!!!! WARNING: Too many iterations " << theNoFitIterations << " and fit DOES NOT CONVERGE " << std::endl;
243  }
244  // Model::setCocoaStatus( COCOA_FitCannotImprove );
245  break; // No more iterations
246  }
247 
248  } else if( fq == FQchiSquareWorsened ) {
249  if(ALIUtils::debug >= 1) {
250  //----- Recalculate fit quality with decreasing values of Da
251  std::cerr << "!! WARNING: fit quality has worsened, Recalculate fit quality with decreasing values of Da " << std::endl;
252  std::cout << " quality daFactor= " << daFactor << " minimum= " << theMinDaFactor << std::endl;
253  }
254  daFactor *= 0.5;
255  if( daFactor > theMinDaFactor ){
257 
258  if(ALIUtils::report >= 2) {
260  fileout << " Redoing iteration with Da factor " << daFactor << std::endl;
261  }
262  } else {
263  daFactor *= 2.;
264  std::cerr << " !!!ERROR: not possible to get good fit quality even multiplying Da by " << daFactor << std::endl;
265  if(ALIUtils::report >= 2) {
267  fileout << " !!!ERROR: not possible to get good fit quality even multiplying Da by " << daFactor << std::endl;
268  }
269  // Model::setCocoaStatus( COCOA_FitCannotImprove );
270  //- std::cout << "fdsaf FIT STATUS " << Model::printCocoaStatus( Model::getCocoaStatus() ) << std::endl;
271  break; // No more iterations
272  }
273  }
275 
276  }
277 
278  //----- Iteration is finished: dump fitted entries
280  if(gomgr->GlobalOptions()["histograms"] > 0) {
282  }
283 
284  if(GlobalOptionMgr::getInstance()->GlobalOptions()["rootResults"] > 0) {
286  ntupleMgr->InitNtuple();
287  ntupleMgr->FillChi2();
288  ntupleMgr->FillOptObjects(AtWAMatrix);
289  ntupleMgr->FillMeasurements();
290  ntupleMgr->FillFitParameters(AtWAMatrix);
291  ntupleMgr->FillNtupleTree();
292  }
293 
294  //- only if not stopped in worsening quality state if(ALIUtils::report >= 0) dumpFittedValues( ALIFileOut::getInstance( Model::ReportFName() ));
295 
296  /*- std::vector< OpticalObject* >::iterator voite;
297  for( voite = Model::OptOList().begin(); voite != Model::OptOList().end(); voite++ ) {
298  //-?? (*voite)->resetOriginalOriginalCoordinates();
299  }*/
300 
301  //---- If no measurement file, break after looping once
302  //- std::cout << " Measurement::measurementsFileName() " << Measurement::measurementsFileName() << " Measurement::measurementsFileName()" <<std::endl;
303  if( CocoaDaqReader::GetDaqReader() == nullptr ) {
304  //m if( Measurement::measurementsFileName() == "" ) {
305  if( ALIUtils::debug >= 1 ) std::cout << std::endl << "@@@@@@@@@@@@@@@@@@ Fit has ended : only one measurement " << nEvent << std::endl;
306  lastEvent = true;
307  return !lastEvent;
308  }
309 
310  //- std::cout << " Measurement::only1" << Measurement::only1 << std::endl;
311  if( Measurement::only1 ) {
312  if( ALIUtils::debug >= 1 ) std::cout << std::endl << "@@@@@@@@@@@@@@@@@@ Fit has ended : 'Measurement::only1' is set" << std::endl;
313 
314  lastEvent = true;
315  return !lastEvent;
316  }
317 
318  if(GlobalOptionMgr::getInstance()->GlobalOptions()["maxEvents"] <= nEvent ){
319  if( ALIUtils::debug >= 1 ) std::cout << std::endl << "@@@@@@@@@@@@@@@@@@ Fit has ended : 'Number of events exhausted " << nEvent << std::endl;
320 
321  lastEvent = true;
322  return !lastEvent;
323  }
324 
325  } else {
326  lastEvent = true;
327  if( ALIUtils::debug >= 1 ) std::cout << std::endl << "@@@@@@@@@@@@@@@@@@ Fit has ended : ??no more data sets' " << nEvent << std::endl;
328  return !lastEvent;
329  }
330 
331  if( ALIUtils::debug >= 1 ) std::cout << std::endl << "@@@@@@@@@@@@@@@@@@ Fit has ended : " << nEvent << std::endl;
332 
333  return !lastEvent;
334 }
static ALIbool only1
Definition: Measurement.h:267
static ALIdouble theMinDaFactor
Definition: Fit.h:201
long double ALIdouble
Definition: CocoaGlobals.h:11
void AddFittedEntriesSet(FittedEntriesSet *fents)
#define TRUE
Definition: scimark2.h:12
static CocoaDaqReader * GetDaqReader()
static void setCocoaStatus(const cocoaStatus cs)
Definition: Model.h:49
static ALIint debug
Definition: ALIUtils.h:36
static ALIstring & ReportFName()
the name of the report File
Definition: Model.h:96
static GlobalOptionMgr * getInstance()
static void setFittableEntries()
Definition: Fit.cc:364
void FillMeasurements()
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
static FittedEntriesReader * getFittedEntriesReader()
Definition: Model.h:267
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
int getGlobalOptionValue(const ALIstring &sstr, ALIdouble &val)
--— Search a string in theGlobalOptions and return 1 if found
bool ALIbool
Definition: CocoaGlobals.h:19
static void dumpFittedValuesInAllAncestorFrames(ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1210
static void substractLastDisplacementToEntries(const ALIdouble factor)
Definition: Fit.cc:1119
static ALIint MaxNoFitIterations
Definition: Fit.h:198
virtual bool ReadNextEvent()=0
static FittedEntriesManager * getInstance()
static ALIuint nEvent
Definition: Fit.h:204
static std::vector< OpticalObject * > & OptOList()
Definition: Model.h:71
static NtupleManager * getInstance()
static void dumpMatrices()
Definition: Fit.cc:1422
static void dumpFittedValues(ALIFileOut &fileout, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1147
static ALIint report
Definition: ALIUtils.h:35
void FillOptObjects(MatrixMeschach *AtWAMatrix)
#define begin
Definition: vmac.h:30
void FillFitParameters(MatrixMeschach *AtWAMatrix)
static void calculateSimulatedMeasurementsWithOriginalValues()
Definition: Fit.cc:515
static FitQuality fitParameters(const double daFactor)
Definition: Fit.cc:392
FitQuality
Definition: Fit.h:32
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of FALSE
static ALIFileOut & getInstance(const ALIstring &filename)
Definition: ALIFileOut.cc:19
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
static void addDaMatrixToEntries()
Definition: Fit.cc:1065
static ALIint theNoFitIterations
Definition: Fit.h:196
static void dumpDimensions(std::ofstream &fout)
Definition: ALIUtils.cc:337
void FillNtupleTree()
FitQuality Fit::fitParameters ( const double  daFactor)
staticprivate

Definition at line 392 of file Fit.cc.

References COCOA_FirstIterationInEvent, gather_cfg::cout, ALIUtils::debug, cmsRelvalreport::exit, Model::getCocoaStatus(), getFitQuality(), GlobalOptionMgr::getInstance(), GetSChi2(), GlobalOptionMgr::GlobalOptions(), redoMatrices(), theNoFitIterations, and thePreviousIterationFitQuality.

Referenced by fitNextEvent(), and ~Fit().

393 {
394  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::fitParameters: Fit quality daFactor " << daFactor << std::endl;
395 
396  redoMatrices();
397 
398 
399  //---- Get chi2 of first iteration
402 
404  if (gomgr->GlobalOptions()[ ALIstring("stopAfter1stIteration") ] == 1) {
405  std::cout << "@!! STOPPED by user after 1st iteration " << std::endl;
406  exit(1);
407  }
408  }
409 
410  /* //---------- Open output file
411  if( ALIUtils::report >= 1 ) {
412  ALIFileOut& fileout = ALIFileOut::getInstance( Model::ReportFName() );
413  //t fileout << " REPORT.OUT " << std::endl;
414  //t ALIUtils::dumpDimensions( fileout );
415  fileout << std::endl << "Fit iteration " << theNoFitIterations << " ..." << std::endl;
416  }*/
417 
418  //- std::cout << "2 FIT STATUS " << Model::printCocoaStatus( Model::getCocoaStatus() ) << std::endl;
419 
420  if(ALIUtils::debug >= 10) {
421  std::cout << std::endl << " End fitParameters " << theNoFitIterations << " ..." << std::endl;
422  }
423 
424  return getFitQuality();
425 
426 }
static cocoaStatus getCocoaStatus()
Definition: Model.h:48
static ALIint debug
Definition: ALIUtils.h:36
static GlobalOptionMgr * getInstance()
static FitQuality getFitQuality(const ALIbool canBeGood=TRUE)
Definition: Fit.cc:900
static ALIdouble thePreviousIterationFitQuality
Definition: Fit.h:187
static void redoMatrices()
Definition: Fit.cc:429
std::string ALIstring
Definition: CocoaGlobals.h:9
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
static ALIdouble GetSChi2(ALIbool useDa)
Definition: Fit.cc:1000
static ALIint theNoFitIterations
Definition: Fit.h:196
static ALIMatrix* Fit::GetAtWAMatrix ( )
inlinestatic
double Fit::getEntryValue ( const Entry entry)
staticprivate

Definition at line 1301 of file Fit.cc.

References gather_cfg::cout, ALIUtils::debug, Entry::OutputValueDimensionFactor(), Entry::type(), Entry::value(), and Entry::valueDisplacementByFitting().

Referenced by dumpFittedValues(), and noFitIterations().

1302 {
1303  double entryvalue;
1304  if( entry->type() == "angles") {
1305  if(ALIUtils::debug >= 2 ) std::cout << "WARNING valueDisplacementByFitting has no sense for angles " << std::endl;
1306 
1307  // commenting out the following line as it is a dead assignment due to the
1308  // subsequent assignment below
1309  // -> silence static analyzer warnings, but leaving the commented line in
1310  // case someone wants to actively use this code again
1311 
1312  // entryvalue = -999;
1313  }
1314  entryvalue = ( entry->value() + entry->valueDisplacementByFitting() ) / entry->OutputValueDimensionFactor();
1315  return entryvalue;
1316 }
virtual ALIdouble OutputValueDimensionFactor() const
Definition: Entry.h:39
const ALIstring & type() const
Definition: Entry.h:54
ALIdouble valueDisplacementByFitting() const
Definition: Entry.h:63
ALIdouble value() const
Definition: Entry.h:55
static ALIint debug
Definition: ALIUtils.h:36
FitQuality Fit::getFitQuality ( const ALIbool  canBeGood = TRUE)
staticprivate

Definition at line 900 of file Fit.cc.

References funct::abs(), AtMatrix, MessageLogger_cfi::cerr, gather_cfg::cout, DaMatrix, ALIUtils::debug, MatrixMeschach::Dump(), FQbigDistanceToMinimum, FQchiSquareWorsened, FQsmallDistanceToMinimum, ALIFileOut::getInstance(), GetSChi2(), cmsPerfSuiteHarvest::now, ALIUtils::report, Model::ReportFName(), ALIUtils::set_time_now(), theFitQualityCut, theNoFitIterations, thePreviousIterationFitQuality, theRelativeFitQualityCut, ALIUtils::time_now(), MatrixMeschach::transpose(), WMatrix, and yfMatrix.

Referenced by fitParameters(), and noFitIterations().

901 {
902  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::getFitQuality" << std::endl;
903 
904  double fit_quality = GetSChi2(true);
905 
906  //---------- Calculate DS = Variable to recognize convergence (distance to minimum)
907  ALIMatrix* DatMatrix = new ALIMatrix( *DaMatrix );
908  // delete DaMatrix; //op
909  DatMatrix->transpose();
910  if(ALIUtils::debug >= 5) DatMatrix->Dump("DatMatrix");
911  //op ALIMatrix* DSMat = new ALIMatrix(*DatMatrix * *AtMatrix * *WMatrix * *PDMatrix);
912  ALIMatrix* DSMat = new ALIMatrix(*DatMatrix * *AtMatrix * *WMatrix * *yfMatrix);
913  if(ALIUtils::debug >= 5) {
914  ALIMatrix* DSMattemp = new ALIMatrix(*DatMatrix * *AtMatrix * *WMatrix);
915  DSMattemp->Dump("DSMattempMatrix=Dat*At*W");
916  ALIMatrix* DSMattemp2 = new ALIMatrix(*AtMatrix * *WMatrix * *yfMatrix);
917  DSMattemp2->Dump("DSMattempMatrix2=At*W*yf");
918  ALIMatrix* DSMattemp3 = new ALIMatrix(*AtMatrix * *WMatrix);
919  DSMattemp3->Dump("DSMattempMatrix3=At*W");
920  AtMatrix->Dump("AtMatrix");
921  }
922 
923  /* for( int ii = 0; ii < DatMatrix->NoColumns(); ii++ ){
924  std::cout << ii << " DS term " << (*DatMatrix)(0,ii) * (*DSMattemp2)(ii,0) << std::endl;
925  }*/
926  // delete AtMatrix; //op
927  // delete WMatrix; //op
928 
929  //op if(ALIUtils::debug >= 5) (*PDMatrix).Dump("PDMatrix");
930  if(ALIUtils::debug >= 5) (*yfMatrix).Dump("yfMatrix");
931  if(ALIUtils::debug >= 5) DSMat->Dump("DSMatrix final");
932  // delete yfMatrix; //op
933 
934  ALIdouble fit_quality_cut = (*DSMat)(0,0);
935  //- ALIdouble fit_quality_cut =std::abs( (*DSMat)(0,0) );
936  delete DSMat;
937  if(ALIUtils::debug >= 0) std::cout << theNoFitIterations << " Fit quality predicted improvement in distance to minimum is = " << fit_quality_cut << std::endl;
938  if( ALIUtils::report >= 2 ) {
940  fileout << theNoFitIterations << " Fit quality predicted improvement in distance to minimum is = " << fit_quality_cut << std::endl;
941  }
942 
943  //- double fit_quality_cut = thePreviousIterationFitQuality - fit_quality;
944  //- double fit_quality_cut = fit_quality;
945  //- std::cout << " fit_quality_cut " << fit_quality_cut << " fit_quality " << fit_quality << std::endl;
946 
947  //----- Check quality
948  time_t now;
949  now = clock();
950  if(ALIUtils::debug >= 0) std::cout << "TIME:QUALITY_CHECKED: " << now << " " << difftime(now, ALIUtils::time_now())/1.E6 << std::endl;
952 
953  FitQuality fitQuality;
954 
955  //----- Chi2 is bigger, bad
956  // if( theNoFitIterations != 0 && fit_quality_cut > 0. ) {
957  if( fit_quality_cut < 0. ) {
958  fitQuality = FQchiSquareWorsened;
959  if(ALIUtils::debug >= 1) std::cerr << "!!WARNING: Fit quality has worsened: Fit Quality now = " << fit_quality
960  << " before " << thePreviousIterationFitQuality << " diff " << fit_quality - thePreviousIterationFitQuality << std::endl;
961 
962  //----- Chi2 is smaller, check if we make another iteration
963  } else {
964  ALIdouble rel_fit_quality = std::abs(thePreviousIterationFitQuality - fit_quality)/fit_quality;
965  //----- Small chi2 change: end
966  if( (fit_quality_cut < theFitQualityCut || rel_fit_quality < theRelativeFitQualityCut ) && canBeGood ) {
967  if(ALIUtils::debug >= 2) std::cout << "$$ Fit::getFitQuality good " << fit_quality_cut << " <? " << theFitQualityCut
968  << " || " << rel_fit_quality << " <? " << theRelativeFitQualityCut << " GOOD " << canBeGood << std::endl;
969  fitQuality = FQsmallDistanceToMinimum;
970  if(ALIUtils::report >= 1) {
972  fileout << "STOP: SMALL IMPROVEMENT IN ITERATION " << theNoFitIterations << " = " << fit_quality_cut << " < " << theFitQualityCut << " OR (RELATIVE) " << rel_fit_quality << " < " << theRelativeFitQualityCut << std::endl;
973  }
974  if(ALIUtils::debug >= 4) {
975  std::cout << "STOP: SMALL IMPROVEMENT IN ITERATION " << theNoFitIterations << " = " << fit_quality_cut << " < " << theFitQualityCut << " OR (RELATIVE) " << rel_fit_quality << " < " << theRelativeFitQualityCut << std::endl;
976  }
977 
978  //----- Big chi2 change: go to next iteration
979  } else {
980  if(ALIUtils::debug >= 2) std::cout << "$$ Fit::getFitQuality bad " << fit_quality_cut << " <? " << theFitQualityCut << " || " << rel_fit_quality << " <? " << theRelativeFitQualityCut << " GOOD " << canBeGood << std::endl;
981  fitQuality = FQbigDistanceToMinimum;
982  //----- set thePreviousIterationFitQuality for next iteration
983  thePreviousIterationFitQuality = fit_quality;
984 
985  if(ALIUtils::report >= 2) {
987  fileout << "CONTINUE: BIG IMPROVEMENT IN ITERATION " << theNoFitIterations << " = " << fit_quality_cut << " >= " << theFitQualityCut << " AND (RELATIVE) " << rel_fit_quality << " >= " << theRelativeFitQualityCut << std::endl;
988  }
989  if(ALIUtils::debug >= 4) {
990  std::cout << "CONTINUE: BIG IMPROVEMENT IN ITERATION " << theNoFitIterations << " = " << fit_quality_cut << " >= " << theFitQualityCut << " AND (RELATIVE) " << rel_fit_quality << " >= " << theRelativeFitQualityCut << std::endl;
991  }
992  }
993  }
994 
995  return fitQuality;
996 
997 }
static void set_time_now(time_t now)
Definition: ALIUtils.h:48
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIint debug
Definition: ALIUtils.h:36
static ALIMatrix * AtMatrix
Definition: Fit.h:161
static ALIstring & ReportFName()
the name of the report File
Definition: Model.h:96
static ALIdouble theFitQualityCut
Definition: Fit.h:190
static ALIMatrix * WMatrix
Definition: Fit.h:162
static ALIdouble thePreviousIterationFitQuality
Definition: Fit.h:187
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static ALIMatrix * DaMatrix
Definition: Fit.h:165
static ALIMatrix * yfMatrix
Definition: Fit.h:170
MatrixMeschach ALIMatrix
static ALIint report
Definition: ALIUtils.h:35
static ALIdouble theRelativeFitQualityCut
Definition: Fit.h:193
FitQuality
Definition: Fit.h:32
static ALIFileOut & getInstance(const ALIstring &filename)
Definition: ALIFileOut.cc:19
void Dump(const ALIstring &mtext)
static ALIdouble GetSChi2(ALIbool useDa)
Definition: Fit.cc:1000
static ALIint theNoFitIterations
Definition: Fit.h:196
static time_t time_now()
Definition: ALIUtils.h:45
Fit & Fit::getInstance ( )
static

Definition at line 71 of file Fit.cc.

References gather_cfg::cout, ALIUtils::debug, Fit(), GlobalOptionMgr::getGlobalOptionValue(), GlobalOptionMgr::getInstance(), ALIUtils::getMaximumDeviationDerivative(), instance, createfilelist::int, MaxNoFitIterations, ALIUtils::setMaximumDeviationDerivative(), theFitQualityCut, theMinDaFactor, and theRelativeFitQualityCut.

Referenced by CocoaAnalyzer::RunCocoa(), and ~Fit().

72 {
73  if(!instance) {
74  instance = new Fit;
75  ALIdouble go;
77 
78  gomgr->getGlobalOptionValue("maxDeviDerivative", go );
80  if( ALIUtils::debug >= 3 ) std::cout << " Fit::maximum_deviation_derivative " << ALIUtils::getMaximumDeviationDerivative() << std::endl;
81 
82  gomgr->getGlobalOptionValue("maxNoFitIterations", go );
83  MaxNoFitIterations = int(go);
84 
85  gomgr->getGlobalOptionValue("fitQualityCut", go );
86  theFitQualityCut = go;
87  if( ALIUtils::debug >= 3 ) std::cout << " theFitQualityCut " << theFitQualityCut << std::endl;
88 
89  gomgr->getGlobalOptionValue("RelativeFitQualityCut", go );
91  if( ALIUtils::debug >= 3 ) std::cout << " theRelativeFitQualityCut " << theRelativeFitQualityCut << std::endl;
92 
93  gomgr->getGlobalOptionValue("minDaFactor", go );
94  theMinDaFactor = go;
95 
96  }
97 
98  return *instance;
99 }
static ALIdouble theMinDaFactor
Definition: Fit.h:201
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIdouble getMaximumDeviationDerivative()
Definition: ALIUtils.h:107
static ALIint debug
Definition: ALIUtils.h:36
static void setMaximumDeviationDerivative(ALIdouble val)
Definition: ALIUtils.h:109
static GlobalOptionMgr * getInstance()
static ALIdouble theFitQualityCut
Definition: Fit.h:190
int getGlobalOptionValue(const ALIstring &sstr, ALIdouble &val)
--— Search a string in theGlobalOptions and return 1 if found
static ALIint MaxNoFitIterations
Definition: Fit.h:198
static Fit * instance
Definition: Fit.h:158
Fit()
Definition: Fit.h:38
static ALIdouble theRelativeFitQualityCut
Definition: Fit.h:193
std::string Fit::GetMeasurementName ( int  meas)
staticprivate

Definition at line 1674 of file Fit.cc.

References begin, gather_cfg::cout, findQualityFiles::jj, Model::MeasurementList(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by GetAtWAMatrix().

1675 {
1676  std::string measname = " ";
1677 
1678  std::cout << " imeas " << imeas << std::endl;
1679  int Aline = 0;
1680  std::vector< Measurement* >::const_iterator vmcite;
1681  for ( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite) {
1682  for ( ALIuint jj = 0; jj < ALIuint((*vmcite)->dim()); jj++) {
1683  if( Aline == imeas ) {
1684  char ctmp[20];
1685  gcvt( jj, 10, ctmp );
1686  return ((*vmcite)->name()) + ":" + std::string(ctmp);
1687  }
1688  Aline++;
1689  }
1690  }
1691 
1692  std::cout << " return measname " << measname << std::endl;
1693  return measname;
1694 }
#define begin
Definition: vmac.h:30
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
unsigned int ALIuint
Definition: CocoaGlobals.h:17
ALIdouble Fit::GetSChi2 ( ALIbool  useDa)
staticprivate

Definition at line 1000 of file Fit.cc.

References AMatrix, AtMatrix, AtWAMatrix, gather_cfg::cout, DaMatrix, ALIUtils::debug, MatrixMeschach::Dump(), MatrixByMatrix(), PrintChi2(), MatrixMeschach::transpose(), WMatrix, and yfMatrix.

Referenced by fitParameters(), getFitQuality(), and noFitIterations().

1001 {
1002  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::GetSChi2 useDa= " << useDa << std::endl;
1003 
1004  ALIMatrix* SMat = nullptr;
1005  if( useDa ){
1006  //----- Calculate variables to check quality of this set of parameters
1007 
1008  //----- Calculate Da = (At * W * A)-1 * At * W * (y-f)
1009  /*t DaMatrix = new ALIMatrix( *AtWAMatrix );
1010  *DaMatrix *= *AtMatrix * *WMatrix;
1011  if(ALIUtils::debug >= 5) DaMatrix->Dump("DaMatrix before yf ");
1012  *DaMatrix *= *yfMatrix;
1013  if(ALIUtils::debug >= 5) DaMatrix->Dump("DaMatrix");
1014  */
1015 
1016  DaMatrix = new ALIMatrix(0, 0);
1017  // if(ALIUtils::debug >= 5) AtWAMatrix->Dump("AtWAMatrix=0");
1018  *DaMatrix = ( *AtWAMatrix * *AtMatrix * *WMatrix * *yfMatrix);
1019  if(ALIUtils::debug >= 5) DaMatrix->Dump("DaMatrix");
1020 
1021  //----- Calculate S = chi2 = Fit quality = r^T W r (r = residual = f + A*Da - y )
1022  //op ALIMatrix* tmpM = new ALIMatrix( *AMatrix * *DaMatrix + *PDMatrix );
1023  // ALIMatrix* tmpM = new ALIMatrix( *AMatrix * *DaMatrix + *yfMatrix );
1024 
1025  ALIMatrix* tmpM = new ALIMatrix( 0,0 );
1026  *tmpM = *AMatrix * *DaMatrix - *yfMatrix;
1027  if(ALIUtils::debug >= 5) tmpM->Dump("A*Da + f - y Matrix ");
1028 
1029  ALIMatrix* tmptM = new ALIMatrix( *tmpM );
1030  tmptM->transpose();
1031  if(ALIUtils::debug >= 5) tmptM->Dump("tmptM after transpose");
1032  if(ALIUtils::debug >= 5) WMatrix->Dump("WMatrix");
1033 
1034  // std::cout << "smat " << std::endl;
1035  //o ALIMatrix* SMat = new ALIMatrix(*tmptM * *WMatrix * *tmpM);
1036  ALIMatrix* SMat1 = MatrixByMatrix(*tmptM,*WMatrix);
1037  // ALIMatrix* SMat1 = MatrixByMatrix(*AMatrix,*WMatrix);
1038  if(ALIUtils::debug >= 5) SMat1->Dump("(A*Da + f - y)^T * W Matrix");
1039  SMat = MatrixByMatrix(*SMat1,*tmpM);
1040  // std::cout << "smatc " << std::endl;
1041  delete tmpM;
1042  delete tmptM;
1043  if(ALIUtils::debug >= 5) SMat->Dump("SMatrix with Da");
1044  } else {
1045  ALIMatrix* yftMat = new ALIMatrix(*yfMatrix);
1046  yftMat->transpose();
1047  SMat = new ALIMatrix(*yftMat * *WMatrix * *yfMatrix);
1048  delete yftMat;
1049  if(ALIUtils::debug >= 5) SMat->Dump("SMatrix no Da");
1050  }
1051  ALIdouble fit_quality = (*SMat)(0,0);
1052  delete SMat;
1053  if(ALIUtils::debug >= 5) std::cout << " GetSChi2 = " << fit_quality << std::endl;
1054 
1055  PrintChi2( fit_quality, !useDa );
1056 
1057  return fit_quality;
1058 
1059 }
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIMatrix * AMatrix
Definition: Fit.h:160
MatrixMeschach * MatrixByMatrix(const MatrixMeschach &mat1, const MatrixMeschach &mat2)
static ALIint debug
Definition: ALIUtils.h:36
static ALIMatrix * AtMatrix
Definition: Fit.h:161
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
static ALIMatrix * WMatrix
Definition: Fit.h:162
static ALIMatrix * DaMatrix
Definition: Fit.h:165
static ALIMatrix * yfMatrix
Definition: Fit.h:170
MatrixMeschach ALIMatrix
static void PrintChi2(ALIdouble fit_quality, ALIbool isFirst)
Definition: Fit.cc:1479
void Dump(const ALIstring &mtext)
void Fit::multiplyMatrices ( )
staticprivate

Definition at line 821 of file Fit.cc.

References AMatrix, AtMatrix, AtWAMatrix, begin, CheckIfFitPossible(), gather_cfg::cout, ALIUtils::debug, MatrixMeschach::Dump(), Model::EntryList(), MatrixMeschach::inverse(), MatrixMeschach::Mat(), cmsPerfSuiteHarvest::now, ALIUtils::set_time_now(), mathSSE::sqrt(), theMinimumEntryQuality, ALIUtils::time_now(), MatrixMeschach::transpose(), WMatrix, and yfMatrix.

Referenced by noFitIterations(), and PropagateErrors().

822 {
823  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::multiplyMatrices " << std::endl;
824  //---------- Calculate transpose of A
825  AtMatrix = new ALIMatrix( *AMatrix );
826  if(ALIUtils::debug >= 5) AtMatrix->Dump("AtMatrix=A");
827  //- std::cout << "call transpose";
828  AtMatrix->transpose();
829  if(ALIUtils::debug >= 4) AtMatrix->Dump("AtMatrix");
830 
831  //---------- Calculate At * W * A
832  AtWAMatrix = new ALIMatrix(0, 0);
833  // if(ALIUtils::debug >= 5) AtWAMatrix->Dump("AtWAMatrix=0");
834  *AtWAMatrix = *AtMatrix * *WMatrix * *AMatrix;
835  if(ALIUtils::debug >= 5) AtWAMatrix->Dump("AtWAMatrix");
836 
838 
839  //t AtWAMatrix->EliminateLines(0,48);
840  //t AtWAMatrix->EliminateColumns(0,48);
841  time_t now;
842  now = clock();
843  if(ALIUtils::debug >= 0) std::cout << "TIME:BEFORE_INVERSE : " << now << " " << difftime(now, ALIUtils::time_now())/1.E6 << std::endl;
845 
846  /* std::cout << " DETERMINANT W " << m_norm1( AtWAMatrix->MatNonConst() ) << std::endl;
847  if( m_norm1( AtWAMatrix->MatNonConst() ) == 0 ) {
848  std::cout << " DETERMINANT W " << m_norm1( AtWAMatrix->MatNonConst() ) << std::endl;
849  std::exception();
850  } */
851 
852  AtWAMatrix->inverse();
853  if(ALIUtils::debug >= 4) AtWAMatrix->Dump("inverse AtWAmatrix");
854  now = clock();
855  if(ALIUtils::debug >= 0) std::cout << "TIME:AFTER_INVERSE : " << now << " " << difftime(now, ALIUtils::time_now())/1.E6 << std::endl;
857 
858  //op thePropagationMatrix = AtWAMatrix;
859 
860  //op VaMatrix = new ALIMatrix( *AtWAMatrix );
861 
862  //----- Print out propagated errors of parameters (=AtWA diagonal elements)
863  std::vector< Entry* >::const_iterator vecite;
864 
865  if( ALIUtils::debug >= 4 ) {
866  std::cout << "PARAM" << " Optical Object " << " entry name " << " Param.Value "
867  << " Prog.Error" << " Orig.Error" << std::endl;
868  }
869 
870  ALIint nEnt = 0;
871  ALIint nEntUnk = 0;
872  for ( vecite = Model::EntryList().begin();
873  vecite != Model::EntryList().end(); ++vecite ) {
874 //------------------ Number of parameters 'cal'
875 // (= No parameters to be fitted - No parameters 'unk' )
876  if( (*vecite)->quality() >= theMinimumEntryQuality ){
877  if( ALIUtils::debug >= 4) {
878  std::cout << nEnt << "PARAM" << std::setw(26)
879  << (*vecite)->OptOCurrent()->name().c_str()
880  << std::setw(8) << " " << (*vecite)->name().c_str() << " "
881  << std::setw(8) << " " << (*vecite)->value() << " "
882  << std::setw(8) << sqrt(AtWAMatrix->Mat()->me[nEnt][nEnt]) /
883  (*vecite)->OutputSigmaDimensionFactor()
884  << " " << (*vecite)->sigma() / (*vecite)->OutputSigmaDimensionFactor()
885  << " Q" << (*vecite)->quality() << std::endl;
886  }
887  nEnt++;
888  }
889  if ( (*vecite)->quality() == 2 ) nEntUnk++;
890  }
891 
892  if(ALIUtils::debug >= 5) yfMatrix->Dump("PD(y-f)Matrix final");
893 
894 }
static void set_time_now(time_t now)
Definition: ALIUtils.h:48
static ALIMatrix * AMatrix
Definition: Fit.h:160
static ALIint theMinimumEntryQuality
Definition: Fit.h:184
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static ALIMatrix * AtMatrix
Definition: Fit.h:161
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
T sqrt(T t)
Definition: SSEVec.h:18
static ALIMatrix * WMatrix
Definition: Fit.h:162
static ALIMatrix * yfMatrix
Definition: Fit.h:170
const MAT * Mat() const
MatrixMeschach ALIMatrix
static void CheckIfFitPossible()
Definition: Fit.cc:1545
#define begin
Definition: vmac.h:30
void Dump(const ALIstring &mtext)
static time_t time_now()
Definition: ALIUtils.h:45
static ALIint Fit::noFitIterations ( )
inlinestatic
void Fit::printCentreInOptOFrame ( const OpticalObject opto,
const OpticalObject optoAncestor,
ALIFileOut fileout,
ALIbool  printErrors = true,
ALIbool  printOrig = true 
)
static

Definition at line 1257 of file Fit.cc.

References OpticalObject::centreGlob(), OpticalObject::CoordinateEntryList(), gather_cfg::cout, ALIUtils::debug, dumpEntryAfterFit(), ALIUtils::dumprm(), cuy::ii, OpticalObject::name(), OpticalObject::rmGlob(), and OpticalObject::type().

Referenced by dumpFittedValues(), dumpFittedValuesInAllAncestorFrames(), and ~Fit().

1258 {
1259  CLHEP::Hep3Vector centreLocal;
1260  if( optoAncestor->type() == "system" ) {
1261  centreLocal = opto->centreGlob();
1262  } else {
1263  centreLocal = opto->centreGlob() - optoAncestor->centreGlob();
1264  CLHEP::HepRotation parentRmGlobInv = inverseOf( optoAncestor->rmGlob() );
1265  centreLocal = parentRmGlobInv * centreLocal;
1266  }
1267  if(ALIUtils::debug >= 2 ) {
1268  std::cout << "CENTRE LOCAL "<< opto->name() << " " << centreLocal << " GLOBL " << opto->centreGlob() << " parent GLOB " << optoAncestor->centreGlob() << std::endl;
1269  ALIUtils::dumprm( optoAncestor->rmGlob(), " parent rm " );
1270  }
1271  std::vector< Entry* > entries = opto->CoordinateEntryList();
1272  for( ALIuint ii = 0; ii < 3; ii++ ){
1273  /* double entryvalue = getEntryValue( entries[ii] );
1274  ALIdouble entryvalue;
1275  if( ii == 0 ) {
1276  entryvalue = centreLocal.x();
1277  }else if( ii == 1 ) {
1278  entryvalue = centreLocal.y();
1279  }else if( ii == 2 ) {
1280  entryvalue = centreLocal.z();
1281  }*/
1282  dumpEntryAfterFit( fileout, entries[ii], centreLocal[ii] / entries[ii]->OutputValueDimensionFactor(), printErrors, printOrig );
1283  }
1284 
1285 }
static void dumpEntryAfterFit(ALIFileOut &fileout, const Entry *entry, double entryvalue, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1319
static void dumprm(const CLHEP::HepRotation &rm, const std::string &msg, std::ostream &out=std::cout)
Definition: ALIUtils.cc:77
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:65
static ALIint debug
Definition: ALIUtils.h:36
const CLHEP::HepRotation & rmGlob() const
ii
Definition: cuy.py:588
const CLHEP::Hep3Vector & centreGlob() const
Definition: OpticalObject.h:85
const ALIstring & name() const
Definition: OpticalObject.h:60
unsigned int ALIuint
Definition: CocoaGlobals.h:17
const ALIstring & type() const
Definition: OpticalObject.h:61
void Fit::PrintChi2 ( ALIdouble  fit_quality,
ALIbool  isFirst 
)
static

Definition at line 1479 of file Fit.cc.

References begin, gather_cfg::cout, ALIUtils::debug, Model::EntryList(), ALIFileOut::getInstance(), cuy::ii, Model::MeasurementList(), ALIUtils::report, Model::ReportFName(), and theNoFitIterations.

Referenced by GetSChi2(), and noFitIterations().

1480 {
1481  double chi2meas = 0;
1482  double chi2cal = 0;
1483  ALIint nMeas = 0, nUnk = 0;
1484 
1485  //----- Calculate the chi2 of measurements
1486  std::vector< Measurement* >::const_iterator vmcite;
1487  for ( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); ++vmcite) {
1488  //--- Calculate Simulated Value Original
1489  for ( ALIuint ii = 0; ii < ALIuint((*vmcite)->dim()); ii++ ){
1490  nMeas++;
1491  double c2 = ( (*vmcite)->value(ii) - (*vmcite)->valueSimulated(ii) ) / (*vmcite)->sigma(ii);
1492  chi2meas += c2*c2;
1493  if( ALIUtils::debug >= 2) {
1494  std::cout << c2 << " adding chi2meas " << chi2meas << " " << (*vmcite)->name() << ": " << ii << " (mm)R: " << (*vmcite)->value(ii)*1000. << " S: " << (*vmcite)->valueSimulated(ii)*1000. << " Diff= " << ((*vmcite)->value(ii) - (*vmcite)->valueSimulated(ii))*1000. << std::endl;
1495  }
1496  }
1497  }
1498 
1499  //----- Calculate the chi2 of calibrated parameters
1500  std::vector< Entry* >::iterator veite;
1501  for ( veite = Model::EntryList().begin();
1502  veite != Model::EntryList().end(); ++veite ) {
1503  if ( (*veite)->quality() == 2 ) nUnk++;
1504  if ( (*veite)->quality() == 1 ) {
1505  double c2 = (*veite)->valueDisplacementByFitting() / (*veite)->sigma();
1506  //double c2 = (*veite)->value() / (*veite)->sigma();
1507  chi2cal += c2*c2;
1508  if( ALIUtils::debug >= 2) std::cout << c2 << " adding chi2cal " << chi2cal << " " << (*veite)->OptOCurrent()->name() << " " << (*veite)->name() << std::endl;
1509  //- std::cout << " valueDisplacementByFitting " << (*veite)->valueDisplacementByFitting() << " sigma " << (*veite)->sigma() << std::endl;
1510  }
1511  }
1512 
1513  if( ALIUtils::report >= 1) {
1515  fileout << " Chi2= " << chi2meas+chi2cal << " / " << nMeas-nUnk << " dof " << " From measurements= " << chi2meas << " from calibrated parameters= " << chi2cal << std::endl;
1516  }
1517  if( ALIUtils::debug >= 3) std::cout << " quality Chi2 (no correlations) " << chi2meas+chi2cal << " " << chi2meas << " " << chi2cal << std::endl;
1518 
1519 
1520  if( !isFirst ) {
1521  // double fit_quality_change = thePreviousIterationFitQuality - fit_quality;
1522 
1523  if(ALIUtils::debug >= 0) {
1524  std::cout << std::endl << "@@@@ Fit iteration " << theNoFitIterations << " ..." << std::endl;
1525  // std::cout << theNoFitIterations << " Chi2 improvement in this iteration = " << fit_quality_change << std::endl;
1526  }
1527  if( ALIUtils::report >= 1 ) {
1529  fileout << std::endl << "Fit iteration " << theNoFitIterations << " ..." << std::endl;
1530  // fileout << theNoFitIterations << " Chi2 improvement in this iteration = " << fit_quality_change << std::endl;
1531  }
1532  }
1533 
1534  //---- Print chi2
1535  if(ALIUtils::debug >= 0) std::cout << theNoFitIterations << " Chi2 after iteration = " << fit_quality << std::endl;
1536  if( ALIUtils::report >= 1 ) {
1537  //--------- Get report file handler
1539  fileout << theNoFitIterations << " Chi2 after iteration = " << fit_quality << std::endl;
1540  }
1541 
1542 }
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static ALIstring & ReportFName()
the name of the report File
Definition: Model.h:96
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
isFirst
Definition: cuy.py:417
ii
Definition: cuy.py:588
static ALIint report
Definition: ALIUtils.h:35
#define begin
Definition: vmac.h:30
static ALIFileOut & getInstance(const ALIstring &filename)
Definition: ALIFileOut.cc:19
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
static ALIint theNoFitIterations
Definition: Fit.h:196
unsigned int ALIuint
Definition: CocoaGlobals.h:17
void Fit::printRotationAnglesInOptOFrame ( const OpticalObject opto,
const OpticalObject optoAncestor,
ALIFileOut fileout,
ALIbool  printErrors = true,
ALIbool  printOrig = true 
)
static

Definition at line 1289 of file Fit.cc.

References OpticalObject::CoordinateEntryList(), dumpEntryAfterFit(), OpticalObject::getRotationAnglesInOptOFrame(), and cuy::ii.

Referenced by dumpFittedValues(), dumpFittedValuesInAllAncestorFrames(), and ~Fit().

1290 {
1291  std::vector< Entry* > entries = opto->CoordinateEntryList();
1292  std::vector<double> entryvalues = opto->getRotationAnglesInOptOFrame( optoAncestor, entries );
1293  //- std::cout << " after return entryvalues[0] " << entryvalues[0] << " entryvalues[1] " << entryvalues[1] << " entryvalues[2] " << entryvalues[2] << std::endl;
1294  for( ALIuint ii = 3; ii < entries.size(); ii++ ){
1295  dumpEntryAfterFit( fileout, entries[ii], entryvalues[ii-3]/entries[ii]->OutputValueDimensionFactor(), printErrors, printOrig );
1296  }
1297 
1298 }
static void dumpEntryAfterFit(ALIFileOut &fileout, const Entry *entry, double entryvalue, ALIbool printErrors=true, ALIbool printOrig=true)
Definition: Fit.cc:1319
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:65
std::vector< double > getRotationAnglesInOptOFrame(const OpticalObject *optoAncestor, const std::vector< Entry * > &entries) const
ii
Definition: cuy.py:588
unsigned int ALIuint
Definition: CocoaGlobals.h:17
void Fit::PropagateErrors ( )
staticprivate

Definition at line 446 of file Fit.cc.

References AMatrix, gather_cfg::cout, CreateMatrices(), ALIUtils::debug, MatrixMeschach::Dump(), cmsRelvalreport::exit, FillMatricesWithCalibratedParameters(), FillMatricesWithMeasurements(), ALIUtils::getFirstTime(), GlobalOptionMgr::getInstance(), GlobalOptionMgr::GlobalOptions(), MatrixMeschach::inverse(), MatrixMeschach::MatNonConst(), multiplyMatrices(), cmsPerfSuiteHarvest::now, ALIUtils::set_time_now(), setCorrelationsInWMatrix(), ALIUtils::setFirstTime(), ALIUtils::time_now(), WMatrix, and yfMatrix.

Referenced by redoMatrices(), and ~Fit().

447 {
448  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::PropagateErrors" << std::endl;
449 
450  //----- Create empty matrices of appropiate size
451  CreateMatrices();
452 
453  //---- count running time
454  time_t now;
455  now = clock();
456  if(ALIUtils::debug >= 2) std::cout << "TIME:CREATE_MAT : " << now << " " << difftime(now, ALIUtils::time_now())/1.E6 << std::endl;
458 
459  //----- Fill the A, W & y matrices with the measurements
461 
462  //---- count running time
463  now = clock();
464  if(ALIUtils::debug >= 2) std::cout << "TIME:MAT_MEAS_FILLED: " << now << " " << difftime(now, ALIUtils::time_now())/1.E6 << std::endl;
466 
467  //----- Fill the A, W & y matrices with the calibrated parameters
469  if (gomgr->GlobalOptions()[ ALIstring("calcul_type") ] == 0) {
471 
472  //---- count running time
473  now = clock();
474  if(ALIUtils::debug >= 0) std::cout << "TIME:MAT_CAL_FILLED : " << now << " " << difftime(now, ALIUtils::time_now())/1.E6 << std::endl;
476 
477  }
478 
479  //----- Put by hand some correlations if known previously
481 
482  if(ALIUtils::debug >= 3) WMatrix->Dump("WMatrix before inverse");
483 
484  //----- Check first that matrix can be inverted
485  if( m_norm1( WMatrix->MatNonConst() ) == 0 ) {
486  // Model::setCocoaStatus( COCOA_FitMatrixNonInversable );
487  return; // Model::getCocoaStatus();
488  } else {
489  WMatrix->inverse();
490  }
491 
492  if(ALIUtils::debug >= 3) AMatrix->Dump("AMatrix");
493  if(ALIUtils::debug >= 3) WMatrix->Dump("WMatrix");
494  if(ALIUtils::debug >= 3) yfMatrix->Dump("yfMatrix");
495 
496  if(gomgr->GlobalOptions()["onlyDeriv"] >= 1) {
497  std::cout << "ENDING after derivatives are calculated ('onlyDeriv' option set)" << std::endl;
498  exit(1);
499  }
500 
502 
503  now = clock();
504  if(ALIUtils::debug >= 0) std::cout << "TIME:MAT_MULTIPLIED : " << now << " " << difftime(now, ALIUtils::time_now())/1.E6 << std::endl;
506 
507  if( ALIUtils::getFirstTime() == 1) ALIUtils::setFirstTime( false );
508 
509 }
static void set_time_now(time_t now)
Definition: ALIUtils.h:48
static void multiplyMatrices()
Definition: Fit.cc:821
static ALIMatrix * AMatrix
Definition: Fit.h:160
static void setCorrelationsInWMatrix()
Definition: Fit.cc:770
static ALIint debug
Definition: ALIUtils.h:36
static GlobalOptionMgr * getInstance()
static ALIMatrix * WMatrix
Definition: Fit.h:162
static void setFirstTime(ALIbool val)
Definition: ALIUtils.h:104
static ALIMatrix * yfMatrix
Definition: Fit.h:170
MAT * MatNonConst() const
static void FillMatricesWithMeasurements()
Definition: Fit.cc:626
static void CreateMatrices()
Definition: Fit.cc:557
static ALIbool getFirstTime()
Definition: ALIUtils.h:101
std::string ALIstring
Definition: CocoaGlobals.h:9
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
void Dump(const ALIstring &mtext)
static void FillMatricesWithCalibratedParameters()
Definition: Fit.cc:709
static time_t time_now()
Definition: ALIUtils.h:45
void Fit::redoMatrices ( )
staticprivate

Definition at line 429 of file Fit.cc.

References calculateSimulatedMeasurementsWithOriginalValues(), gather_cfg::cout, ALIUtils::debug, deleteMatrices(), and PropagateErrors().

Referenced by fitParameters(), and ~Fit().

430 {
431  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::redoMatrices" << std::endl;
432 
433  deleteMatrices();
434 
436 
437  PropagateErrors();
438 
439 }
static ALIint debug
Definition: ALIUtils.h:36
static void PropagateErrors()
Definition: Fit.cc:446
static void deleteMatrices()
Definition: Fit.cc:538
static void calculateSimulatedMeasurementsWithOriginalValues()
Definition: Fit.cc:515
void Fit::setCorrelationFromParamFitted ( const pss entry1,
const pss entry2,
ALIdouble  correl 
)
staticprivate

Definition at line 793 of file Fit.cc.

References gather_cfg::cout, Entry::fitPos(), Model::getEntryByName(), MatrixMeschach::NoLines(), and WMatrix.

Referenced by noFitIterations(), and setCorrelationsInWMatrix().

795 {
796 
797  ALIint pmsize = WMatrix->NoLines();
798  ALIint fit_pos1 = Model::getEntryByName(entry1.first, entry1.second)->fitPos();
799  ALIint fit_pos2 = Model::getEntryByName(entry2.first, entry2.second)->fitPos();
800  std::cout << "CHECKsetCorrelatiFPF " << fit_pos1 << " " << fit_pos2 << std::endl;
801 
802  if( fit_pos1 >= 0 && fit_pos1 < pmsize && fit_pos2 >= 0 && fit_pos2 < pmsize ) {
803  setCorrelationFromParamFitted( fit_pos1, fit_pos2, correl );
804  }
805 }
ALIint NoLines() const
static void setCorrelationFromParamFitted(const pss &entry1, const pss &entry2, ALIdouble correl)
Definition: Fit.cc:793
int ALIint
Definition: CocoaGlobals.h:15
static Entry * getEntryByName(const ALIstring &opto_name, const ALIstring &entry_name)
--— Search an Entry name in the Entry* list and return a pointer to it
Definition: Model.cc:635
static ALIMatrix * WMatrix
Definition: Fit.h:162
ALIint fitPos() const
Definition: Entry.h:60
void Fit::setCorrelationFromParamFitted ( const ALIint  fit_pos1,
const ALIint  fit_pos2,
ALIdouble  correl 
)
staticprivate

Definition at line 809 of file Fit.cc.

References gather_cfg::cout, MatrixMeschach::SetCorrelation(), and WMatrix.

810 {
811  // ALIdouble error1 = sqrt( (*WMatrix)(fit_pos1, fit_pos1) );
812  // ALIdouble error2 = sqrt( (*WMatrix)(fit_pos2, fit_pos2) );
813  WMatrix->SetCorrelation( fit_pos1, fit_pos2, correl );
814  std::cout << "setCorrelatiFPF " << fit_pos1 << " " << fit_pos2 << " " << correl << std::endl;
815 }
static ALIMatrix * WMatrix
Definition: Fit.h:162
void SetCorrelation(ALIint i1, ALIint i2, ALIdouble corr)
void Fit::setCorrelationsInWMatrix ( )
staticprivate

Definition at line 770 of file Fit.cc.

References corr, gather_cfg::cout, ALIUtils::debug, ErrorCorrelation::getCorrelation(), ErrorCorrelationMgr::getCorrelation(), ErrorCorrelation::getEntry1(), ErrorCorrelation::getEntry2(), ErrorCorrelationMgr::getInstance(), ErrorCorrelationMgr::getNumberOfCorrelations(), cuy::ii, and setCorrelationFromParamFitted().

Referenced by noFitIterations(), and PropagateErrors().

771 {
772  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::setCorrelationsInWMatrix" << std::endl;
773 
774  //----- Check if there are correlations to input
776  ALIint siz = corrMgr->getNumberOfCorrelations();
777  if( siz == 0 ) return;
778 
779  //----- Set correlations
780  ALIuint ii;
781  for( ii = 0; ii < ALIuint(siz); ii++ ){
782  //t if(ALIUtils::debug >= 5) std::cout << "globaloption cmslink fit" << Model::GlobalOptions()["cms_link"] << std::endl;
783  ErrorCorrelation* corr = corrMgr->getCorrelation( ii );
785  }
786 
787 }
static void setCorrelationFromParamFitted(const pss &entry1, const pss &entry2, ALIdouble correl)
Definition: Fit.cc:793
ErrorCorrelation * getCorrelation(ALIint ii)
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:36
static ErrorCorrelationMgr * getInstance()
const pss & getEntry1() const
const ALIdouble getCorrelation() const
JetCorrectorParameters corr
Definition: classes.h:5
ii
Definition: cuy.py:588
const pss & getEntry2() const
unsigned int ALIuint
Definition: CocoaGlobals.h:17
void Fit::setFittableEntries ( )
static

Definition at line 364 of file Fit.cc.

References begin, gather_cfg::cout, ALIUtils::debug, Model::EntryList(), GlobalOptionMgr::getInstance(), GlobalOptionMgr::GlobalOptions(), createfilelist::int, and theMinimumEntryQuality.

Referenced by fitNextEvent(), and ~Fit().

365 {
366 
367  std::vector< Entry* >::const_iterator vecite;
368 
370  theMinimumEntryQuality = int(gomgr->GlobalOptions()[ALIstring("calcul_type")]) + 1;
371  if ( ALIUtils::debug >= 3) std::cout << "@@@ Fit::setFittableEntries: total Entry List size= " << Model::EntryList().size() << std::endl;
372 
373  int No_entry_to_fit = 0;
374  for ( vecite = Model::EntryList().begin();
375  vecite != Model::EntryList().end(); ++vecite ) {
376 
377  // Number the parameters that are going to be fitted
378  if ( (*vecite)->quality() >= theMinimumEntryQuality ) {
379  (*vecite)->setFitPos( No_entry_to_fit );
380  if( ALIUtils::debug >= 4 ) std::cout << " Entry To Fit= " << No_entry_to_fit << " " << (*vecite)->OptOCurrent()->name() << " " << (*vecite)->name() << " with quality= " << (*vecite)->quality() << std::endl;
381  No_entry_to_fit++;
382  }
383  }
384 
385 }
static ALIint theMinimumEntryQuality
Definition: Fit.h:184
static ALIint debug
Definition: ALIUtils.h:36
static GlobalOptionMgr * getInstance()
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
#define begin
Definition: vmac.h:30
std::string ALIstring
Definition: CocoaGlobals.h:9
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
void Fit::startFit ( )
static

Definition at line 105 of file Fit.cc.

References NtupleManager::BookNtuple(), gather_cfg::cout, ALIUtils::debug, CocoaDBMgr::DumpCocoaResults(), fitNextEvent(), FittedEntriesManager::getInstance(), GlobalOptionMgr::getInstance(), NtupleManager::getInstance(), CocoaDBMgr::getInstance(), GlobalOptionMgr::GlobalOptions(), FittedEntriesManager::MakeHistos(), nEvent, ALIUtils::setFirstTime(), NtupleManager::WriteNtuple(), and WriteVisualisationFiles().

Referenced by CocoaAnalyzer::RunCocoa(), and ~Fit().

106 {
107  // Model::setCocoaStatus( COCOA_InitFit );
109  if(GlobalOptionMgr::getInstance()->GlobalOptions()["rootResults"] > 0) {
110  NTmgr->BookNtuple();
111  }
112 
113  ALIUtils::setFirstTime( true );
114 
116 
118  for(;;) {
119 
120  bool bend = fitNextEvent( nEvent );
121  if(gomgr->GlobalOptions()["writeDBOptAlign"] > 0 || gomgr->GlobalOptions()["writeDBAlign"] > 0) {
123  }
124 
125  if( !bend ){
126  if ( ALIUtils::debug >= 1) std::cout << "@@@ Fit::startFit ended n events = " << nEvent << std::endl;
127  break;
128  }
129 
130  //- if ( ALIUtils::debug >= 0) std::cout << " FIT STATUS " << Model::printCocoaStatus( Model::getCocoaStatus() ) << std::endl;
131 
132  nEvent++;
133 
134  }
135 
136  //---------- Program ended, fill histograms of fitted entries
137  if(gomgr->GlobalOptions()["histograms"] > 0) {
139  FEmgr->MakeHistos();
140  }
141 
142  if(GlobalOptionMgr::getInstance()->GlobalOptions()["rootResults"] > 0) {
143  NTmgr->WriteNtuple();
144  }
145 }
bool DumpCocoaResults()
Definition: CocoaDBMgr.cc:51
static ALIint debug
Definition: ALIUtils.h:36
static GlobalOptionMgr * getInstance()
static void setFirstTime(ALIbool val)
Definition: ALIUtils.h:104
static ALIbool fitNextEvent(ALIuint &nEvent)
Definition: Fit.cc:149
static FittedEntriesManager * getInstance()
static ALIuint nEvent
Definition: Fit.h:204
static void WriteVisualisationFiles()
Definition: Fit.cc:338
static NtupleManager * getInstance()
static CocoaDBMgr * getInstance()
Definition: CocoaDBMgr.cc:37
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()
void Fit::substractLastDisplacementToEntries ( const ALIdouble  factor)
staticprivate

Definition at line 1119 of file Fit.cc.

References begin, gather_cfg::cout, ALIUtils::debug, Model::EntryList(), and theMinimumEntryQuality.

Referenced by fitNextEvent(), and noFitIterations().

1120 {
1121 
1122  if(ALIUtils::debug >= 4) {
1123  std::cout << "@@ Fit::substractToHalfDaMatrixToEntries " << std::endl;
1124  }
1125 
1126  std::vector<Entry*>::const_iterator vecite;
1127  for ( vecite = Model::EntryList().begin(); vecite != Model::EntryList().end(); ++vecite ) {
1128  if ( (*vecite)->quality() >= theMinimumEntryQuality ){
1129  //-- (*vecite)->addFittedDisplacementToValue( -(*DaMatrix)(nEnt,0) );!!! it is not substracting the new value of DaMatrix, but substracting the value that was added last iteration, with which the new value of DaMatrix has been calculated for this iteration
1130 
1131  ALIdouble lastadd = (*vecite)->lastAdditionToValueDisplacementByFitting() * factor;
1132  //- if( lastadd < 0 ) lastadd *= -1;
1133  (*vecite)->addFittedDisplacementToValue( -lastadd );
1134  (*vecite)->setLastAdditionToValueDisplacementByFitting( - (*vecite)->lastAdditionToValueDisplacementByFitting() );
1135  // (*vecite)->substractToHalfFittedDisplacementToValue();
1136 
1137  if(ALIUtils::debug >= 4) std::cout << " new valueDisplacementByFitting " << (*vecite)->OptOCurrent()->name() << " " << (*vecite)->name() << " = " << (*vecite)->valueDisplacementByFitting() << " " << std::endl ;
1138  }
1139  }
1140 
1141 }
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIint theMinimumEntryQuality
Definition: Fit.h:184
static ALIint debug
Definition: ALIUtils.h:36
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
#define begin
Definition: vmac.h:30
void Fit::WriteVisualisationFiles ( )
staticprivate

Definition at line 338 of file Fit.cc.

References calculateSimulatedMeasurementsWithOriginalValues(), gather_cfg::cout, ALIUtils::debug, cmsRelvalreport::exit, ALIUtils::getFirstTime(), GlobalOptionMgr::getInstance(), and GlobalOptionMgr::GlobalOptions().

Referenced by startFit(), and ~Fit().

339 {
340 #ifdef COCOA_VIS
341  if(gomgr->GlobalOptions()["VisOnly"] == 1) {
342  calculateSimulatedMeasurementsWithOriginalValues(); //?? original changed atfer each iteration
343  }
344 
346  if(gomgr->GlobalOptions()["VisWriteVRML"] > 0) {
347  if(ALIUtils::getFirstTime()) ALIVRMLMgr::getInstance().writeFile();
348  }
349  if(gomgr->GlobalOptions()["VisWriteIguana"] > 0) {
350  if(ALIUtils::getFirstTime()) IgCocoaFileMgr::getInstance().writeFile();
351  }
352 
353  if(gomgr->GlobalOptions()["VisOnly"] == 1) {
354  if(ALIUtils::debug >= 1 )std::cout << " Visualiation file(s) succesfully written. Ending.... " << std::endl;
355  exit(1);
356  }
357 #endif
358 }
static ALIint debug
Definition: ALIUtils.h:36
static GlobalOptionMgr * getInstance()
static ALIbool getFirstTime()
Definition: ALIUtils.h:101
static void calculateSimulatedMeasurementsWithOriginalValues()
Definition: Fit.cc:515
std::map< ALIstring, ALIdouble, std::less< ALIstring > > & GlobalOptions()

Member Data Documentation

ALIint Fit::_NoColumnsA
staticprivate

Definition at line 174 of file Fit.h.

ALIint Fit::_NoLinesA
staticprivate

Definition at line 173 of file Fit.h.

ALIMatrix * Fit::AMatrix
staticprivate
ALIMatrix * Fit::AtMatrix
staticprivate

Definition at line 161 of file Fit.h.

Referenced by deleteMatrices(), dumpMatrices(), getFitQuality(), GetSChi2(), and multiplyMatrices().

ALIMatrix * Fit::AtWAMatrix
staticprivate
ALIMatrix * Fit::DaMatrix
staticprivate

Definition at line 165 of file Fit.h.

Referenced by addDaMatrixToEntries(), deleteMatrices(), dumpMatrices(), getFitQuality(), and GetSChi2().

Fit * Fit::instance = 0
staticprivate

Definition at line 158 of file Fit.h.

Referenced by getInstance(), and production_tasks.Task::getname().

ALIint Fit::MaxNoFitIterations = -1
staticprivate

Definition at line 198 of file Fit.h.

Referenced by fitNextEvent(), and getInstance().

ALIuint Fit::nEvent = 1
static

Definition at line 204 of file Fit.h.

Referenced by CocoaDBMgr::DumpCocoaResults(), startFit(), and ~Fit().

ALIdouble Fit::theFitQualityCut = -1
staticprivate

Definition at line 190 of file Fit.h.

Referenced by getFitQuality(), and getInstance().

ALIdouble Fit::theMinDaFactor = 1.e-8
staticprivate

Definition at line 201 of file Fit.h.

Referenced by fitNextEvent(), and getInstance().

ALIint Fit::theMinimumEntryQuality
staticprivate
ALIint Fit::theNoFitIterations
staticprivate
ALIdouble Fit::thePreviousIterationFitQuality = DBL_MAX
staticprivate

Definition at line 187 of file Fit.h.

Referenced by fitParameters(), and getFitQuality().

ALIdouble Fit::theRelativeFitQualityCut = -1
staticprivate

Definition at line 193 of file Fit.h.

Referenced by getFitQuality(), and getInstance().

ALIMatrix * Fit::WMatrix
staticprivate
ALIMatrix * Fit::yfMatrix
staticprivate