CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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=1, ALIbool printOrig=1)
 
static void dumpEntryCorrelations (ALIFileOut &file)
 
static void dumpFittedValues (ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
 
static void dumpFittedValuesInAllAncestorFrames (ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
 
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=1, ALIbool printOrig=1)
 
static void PrintChi2 (ALIdouble fit_quality, ALIbool isFirst)
 
static void printRotationAnglesInOptOFrame (const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
 
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

Definition at line 39 of file Fit.h.

39 { };

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().

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:35
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
static ALIMatrix * DaMatrix
Definition: Fit.h:165
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
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(), and WriteVisualisationFiles().

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:35
static void setApply(ALIbool val)
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
static std::vector< Measurement * > & MeasurementList()
Definition: Model.h:79
void Fit::CheckIfFitPossible ( )
staticprivate

Definition at line 1539 of file Fit.cc.

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

Referenced by multiplyMatrices().

1540 {
1541  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::CheckIfFitPossible" << std::endl;
1542 
1543  //----- Check if there is an unknown parameter that is not affecting any measurement
1544  ALIint NolinMes = 0;
1545  std::vector<Measurement*>::const_iterator vmcite;
1546  for ( vmcite = Model::MeasurementList().begin();
1547  vmcite != Model::MeasurementList().end(); vmcite++) {
1548  NolinMes += (*vmcite)->dim();
1549  }
1550 
1551  std::vector< Entry* >::const_iterator vecite;
1552  for ( vecite = Model::EntryList().begin(); vecite != Model::EntryList().end(); vecite++ ) {
1553  if( ALIUtils::debug >= 4 ) std::cout << "Fit::CheckIfFitPossible looping for entry " << (*vecite)->longName() << std::endl;
1554  if ( (*vecite)->quality() == 2 ) {
1555  ALIint nCol = (*vecite)->fitPos();
1556  //--- Check all measurements
1557  ALIbool noDepend = TRUE;
1558  if( ALIUtils::debug >= 4 ) std::cout << "Fit::CheckIfFitPossible looping for entry " << nCol << std::endl;
1559  for( ALIint ii = 0; ii < NolinMes; ii++ ) {
1560  if( ALIUtils::debug >= 5 ) std::cout << " Derivative= (" << ii << "," << nCol << ") = " << (*AMatrix)(ii,nCol) << std::endl;
1561 
1562  if( fabs((*AMatrix)(ii,nCol)) > ALI_DBL_MIN ) {
1563  if( ALIUtils::debug >= 5 ) std::cout << "Fit::CheckIfFitIsPossible " << nCol << " " << ii << " = " << (*AMatrix)(ii,nCol) << std::endl;
1564  noDepend = FALSE;
1565  break;
1566  }
1567  }
1568  if( noDepend ){
1569  throw cms::Exception("SDFError") << "!!!FATAL ERROR: Fit::CheckIfFitPossible() no measurement depends on unknown entry " << (*vecite)->OptOCurrent()->name() << "/" << (*vecite)->name() << std::endl
1570  << "!!! Fit will not be possible! " << std::endl;
1571  }
1572  }
1573  }
1574 
1575  //------ 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!
1576 
1577  std::vector< Entry* >::const_iterator vecite1,vecite2;
1578  ALIint nLin = AMatrix->NoLines();
1579  ALIdouble derivPrec = ALI_DBL_MIN;
1580  //---------- Loop entries
1581  for ( vecite1 = Model::EntryList().begin();
1582  vecite1 != Model::EntryList().end(); vecite1++ ) {
1583  if( (*vecite1)->quality() == 2 ) {
1584  vecite2 = vecite1; vecite2++;
1585  for ( ;vecite2 != Model::EntryList().end(); vecite2++ ) {
1586  if( (*vecite2)->quality() == 2 ) {
1587  ALIint fitpos1 = (*vecite1)->fitPos();
1588  ALIint fitpos2 = (*vecite2)->fitPos();
1589  if( ALIUtils::debug >= 5 ) std::cout << "Fit::CheckIfFitIsPossible checking " << (*vecite1)->longName() << " ( " << fitpos1 << " ) & " << (*vecite2)->longName() << " ( " << fitpos2 << " ) "<< std::endl;
1590  ALIdouble prop = DBL_MAX;
1591  ALIbool isProp = TRUE;
1592  for( ALIint ii = 0; ii < nLin; ii++ ) {
1593  if( ALIUtils::debug >= 5 ) std::cout << "Fit::CheckIfFitIsPossible " << ii << " : " << (*AMatrix)(ii,fitpos1) << " ?= " << (*AMatrix)(ii,fitpos2) << std::endl;
1594  if( fabs((*AMatrix)(ii,fitpos1)) < derivPrec ) {
1595  if( fabs((*AMatrix)(ii,fitpos2)) > derivPrec ) {
1596  isProp = FALSE;
1597  break;
1598  }
1599  } else {
1600  ALIdouble propn = (*AMatrix)(ii,fitpos2) / (*AMatrix)(ii,fitpos1);
1601  if( prop != DBL_MAX && prop != propn ) {
1602  isProp = FALSE;
1603  break;
1604  }
1605  prop = propn;
1606  }
1607  }
1608  if( isProp ) {
1609  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
1610  << "!!! Fit will not be possible! " << std::endl;
1611  throw cms::Exception("SDFError");
1612  }
1613  }
1614  }
1615  }
1616  }
1617 }
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:35
int ii
Definition: cuy.py:588
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
bool ALIbool
Definition: CocoaGlobals.h:19
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
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 1620 of file Fit.cc.

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

1621 {
1622  int measProp = -1;
1623 
1624  std::set<ALIuint> columnsEqual;
1625  std::set<ALIuint> columnsEqualSave;
1626  ALIuint biggestColumn = 0;
1627  ALIdouble biggest = 0.;
1628  for (int ii = 0; ii < AMatrix->NoColumns(); ii++ ){
1629  if( fabs((*AMatrix)(measNo,ii)) > biggest ) {
1630  biggest = fabs((*AMatrix)(measNo,ii));
1631  biggestColumn = ii;
1632  }
1633  columnsEqualSave.insert(ii);
1634  }
1635 
1636  ALIdouble div;
1637 
1638  for( int jj = 0; jj < AMatrix->NoLines(); jj++ ){
1639  if( jj == int(measNo) ) continue;
1640  columnsEqual = columnsEqualSave;
1641  // check if ratio of each column to 'biggestColumn' is the same as for the N measurement
1642  for (int ii = 0; ii < AMatrix->NoColumns(); ii++ ){
1643  div = (*AMatrix)(measNo,ii)/(*AMatrix)(measNo,biggestColumn);
1644  if( fabs((*AMatrix)(jj,ii)) > ALI_DBL_MIN && fabs(div - (*AMatrix)(jj,ii)/(*AMatrix)(jj,biggestColumn) ) > ALI_DBL_MIN ) {
1645  if( ALIUtils::debug >= 3 ) std::cout << "CheckIfMeasIsProportionalToAnother 2 columns = " << ii << " in " << measNo << " & " << jj << std::endl;
1646  } else {
1647  if( ALIUtils::debug >= 3 ) std::cout << "CheckIfMeasIsProportionalToAnother 2 columns != " << ii << " in " << measNo << " & " << jj << std::endl;
1648  // if it is not equal delete this column
1649  std::set<ALIuint>::iterator ite = columnsEqual.find( ii );
1650  if( ite != columnsEqual.end() ){
1651  columnsEqual.erase(ite);
1652  }
1653  }
1654  }
1655  // check if not all columns have been deleted from columnsEqual
1656  if( columnsEqual.size() != 0 ) {
1657  if( ALIUtils::debug >= 3 ) std::cout << "CheckIfMeasIsProportionalToAnother " << measNo << " = " << jj << std::endl;
1658  measProp = jj;
1659  break;
1660  }
1661  }
1662 
1663  return measProp;
1664 }
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:35
int ii
Definition: cuy.py:588
ALIint NoColumns() const
tuple cout
Definition: gather_cfg.py:121
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 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:35
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
tuple cout
Definition: gather_cfg.py:121
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 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 = 1,
ALIbool  printOrig = 1 
)
static

Definition at line 1313 of file Fit.cc.

References 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(), and printRotationAnglesInOptOFrame().

1314 {
1315  //- std::cout << " Fit::dumpEntryAfterFit " << entryvalue << std::endl;
1316  ALIdouble dimv = entry->OutputValueDimensionFactor();
1317  ALIdouble dims = entry->OutputSigmaDimensionFactor();
1318  //----- Dump to std::cout
1319  if(ALIUtils::debug >= 3) {
1320  std::cout << "ENTRY: "
1321  << std::setw(30) << entry->OptOCurrent()->name()
1322  << std::setw(8) << " " << entry->name() << " "
1323  << std::setw(8) << ( entry->value() + entry->valueDisplacementByFitting() )
1324  <<" " << entry->value()
1325  << " Q" << entry->quality() << std::endl;
1326  }
1327 
1328  if ( entry->quality() == 2 ) {
1329  fileout << "UNK: " << entry->fitPos() << " ";
1330  } else if ( entry->quality() == 1 ) {
1331  fileout << "CAL: " << entry->fitPos() << " ";
1332  // fileout << "CAL: -1 ";
1333  } else {
1334  fileout << "FIX: -1 ";
1335  }
1336 
1337  fileout << std::setw(30) << entry->OptOCurrent()->name()
1338  << std::setw(8) << " " << entry->name() << " "
1339  << std::setw(8) << std::setprecision(8) << entryvalue;
1340  if ( entry->quality() >= theMinimumEntryQuality ) {
1341  if( printErrors ) fileout << " +- " << std::setw(8) << sqrt(AtWAMatrix->Mat()->me[entry->fitPos()][entry->fitPos()]) / dims;
1342  } else {
1343  if( printErrors ) fileout << " +- " << std::setw(8) << 0.;
1344  }
1345  if( printOrig ) {
1346  fileout << std::setw(8) << " " << entry->value() / dimv;
1347  if( printErrors ) fileout << " +- " << std::setw(8) << entry->sigma() /dims << " Q" << entry->quality();
1348 
1349  if( ALIUtils::report >= 2) {
1350  float dif = ( entry->value() + entry->valueDisplacementByFitting() ) / dimv - entry->value() / dimv;
1351  if( fabs(dif) < 1.E-9 ) dif = 0.;
1352  fileout << " DIFF= " << dif;
1353  // << " == " << ( entry->value() + entry->valueDisplacementByFitting() ) / dimv - entryvalue << " @@ " << ( entry->value() + entry->valueDisplacementByFitting() ) / dimv << " @@ " << entryvalue;
1354  } else {
1355  // fileout << std::endl;
1356  }
1357  }
1358 
1359  fileout << std::endl;
1360 
1361 }
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:35
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
T sqrt(T t)
Definition: SSEVec.h:48
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:34
ALIint quality() const
Definition: Entry.h:59
tuple cout
Definition: gather_cfg.py:121
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 1364 of file Fit.cc.

References 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().

1365 {
1366  //----- Only dump correlations bigger than a factor
1367  ALIdouble minCorrel = 1.E-6;
1368  //----- Dump correlations
1369  fileout << std::endl << "CORRELATION BETWEEN 'unk' ENTRIES: (>= " << minCorrel<< " )" << std::endl
1370  << "No_1 No_2 correlation " << std::endl;
1371 
1372  ALIuint i1,i2;
1373  std::vector< Entry* >::iterator veite1, veite2;
1374  std::string E1, E2;
1375  for ( veite1 = Model::EntryList().begin();
1376  veite1 != Model::EntryList().end(); veite1++ ) {
1377  if( (*veite1)->quality() == 0 ) {
1378  continue;
1379  } else if( (*veite1)->quality() == 1 ) {
1380  E1 = "C";
1381  } else if( (*veite1)->quality() == 2 ) {
1382  E1 = "U";
1383  }
1384  i1 = (*veite1)->fitPos();
1385 
1386  for ( veite2 = veite1+1;
1387  veite2 != Model::EntryList().end(); veite2++ ) {
1388  i2 = (*veite2)->fitPos();
1389  if( (*veite2)->quality() == 0 ) {
1390  continue;
1391  } else if( (*veite2)->quality() == 1 ) {
1392  E2 = "C";
1393  } else if( (*veite2)->quality() == 2 ) {
1394  E2 = "U";
1395  }
1396  ALIdouble corr = AtWAMatrix->Mat()->me[i1][i2];
1397  ALIdouble corrf = corr / sqrt(AtWAMatrix->Mat()->me[i1][i1])
1398  / sqrt(AtWAMatrix->Mat()->me[i2][i2]);
1399  if (fabs(corrf) >= minCorrel ) {
1400  if(ALIUtils::debug >= 0) {
1401  std::cout << "CORR:" << E1 << "" << E2 << " (" << i1 << ")" << " (" << i2 << ")" << " " << corrf << std::endl;
1402  }
1403  fileout << "CORR:" << E1 << "" << E2 << " (" << i1 << ")" << " (" << i2 << ")" << " " << corrf << std::endl;
1404  }
1405  }
1406  }
1407  //------- Dump optical object list
1409 
1410 }
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIint debug
Definition: ALIUtils.h:35
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:48
const MAT * Mat() const
JetCorrectorParameters corr
Definition: classes.h:5
void dumpOptOs(std::ostream &out=std::cout) const
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
unsigned int ALIuint
Definition: CocoaGlobals.h:17
void Fit::dumpFittedValues ( ALIFileOut fileout,
ALIbool  printErrors = 1,
ALIbool  printOrig = 1 
)
static

Definition at line 1147 of file Fit.cc.

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

Referenced by fitNextEvent().

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=1, ALIbool printOrig=1)
Definition: Fit.cc:1257
static ALIint debug
Definition: ALIUtils.h:35
int ii
Definition: cuy.py:588
static double getEntryValue(const Entry *entry)
Definition: Fit.cc:1301
static void dumpEntryAfterFit(ALIFileOut &fileout, const Entry *entry, double entryvalue, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1313
const OpticalObject * parent() const
Definition: OpticalObject.h:62
static std::vector< OpticalObject * > & OptOList()
Definition: Model.h:71
static void dumpEntryCorrelations(ALIFileOut &file)
Definition: Fit.cc:1364
#define begin
Definition: vmac.h:30
std::string ALIstring
Definition: CocoaGlobals.h:9
tuple cout
Definition: gather_cfg.py:121
static void printRotationAnglesInOptOFrame(const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1289
void Fit::dumpFittedValuesInAllAncestorFrames ( ALIFileOut fileout,
ALIbool  printErrors = 1,
ALIbool  printOrig = 1 
)
static

Definition at line 1210 of file Fit.cc.

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

Referenced by fitNextEvent().

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=1, ALIbool printOrig=1)
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
#define begin
Definition: vmac.h:30
std::string ALIstring
Definition: CocoaGlobals.h:9
static void printRotationAnglesInOptOFrame(const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1289
void Fit::dumpMatrices ( )
static

Definition at line 1416 of file Fit.cc.

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

Referenced by fitNextEvent().

1417 {
1418  //----- Dump matrices for this iteration
1420  // ofstream matout("matrices.out");
1421  matout << std::endl << " @@@@@@@@@@@@@@@ Iteration No : " << theNoFitIterations << std::endl;
1422  AMatrix->ostrDump( matout, "Matrix A" );
1423  AtMatrix->ostrDump( matout, "Matrix At" );
1424  WMatrix->ostrDump( matout, "Matrix W" );
1425  AtWAMatrix->ostrDump( matout, "Matrix AtWA" );
1426  //op VaMatrix->ostrDump( matout, "Matrix Va" );
1427  DaMatrix->ostrDump( matout, "Matrix Da" );
1428  yfMatrix->ostrDump( matout, "Matrix y" );
1429  //op fMatrix->ostrDump( matout, "Matrix f" );
1430  //op thePropagationMatrix->ostrDump( matout, "propagation Matrix " );
1431  matout.close();
1432 
1433 }
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
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 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:35
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
tuple cout
Definition: gather_cfg.py:121
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, dtNoiseDBValidation_cfg::cerr, gather_cfg::cout, ALIUtils::debug, MatrixMeschach::Dump(), findQualityFiles::jj, Model::MeasurementList(), theMinimumEntryQuality, WMatrix, and yfMatrix.

Referenced by 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:35
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
tuple cout
Definition: gather_cfg.py:121
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 1439 of file Fit.cc.

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

1440 {
1441  ALIint fitposi = -99;
1442 
1443  OpticalObject* opto = Model::getOptOByName( opto_name );
1444  //- std::cout << "OPTO = " << opto->name() << std::endl;
1445  std::vector<Entry*>::const_iterator vecite;
1446  for (vecite = opto->CoordinateEntryList().begin();
1447  vecite < opto->CoordinateEntryList().end(); vecite++) {
1448  //- std::cout << "ENTRYLIST" << (*vecite)->name() << std::endl;
1449  if ((*vecite)->name() == entry_name ) {
1450  //- std::cout << "FOUND " << std::endl;
1451  fitposi = (*vecite)->fitPos();
1452  }
1453  }
1454  for (vecite = opto->ExtraEntryList().begin();
1455  vecite < opto->ExtraEntryList().end(); vecite++) {
1456  //- std::cout << "ENTRYLIST" << (*vecite)->name() << std::endl;
1457  if ((*vecite)->name() == entry_name ) {
1458  //- std::cout << "FOUND " << std::endl;
1459  fitposi = (*vecite)->fitPos();
1460  }
1461  }
1462 
1463  if(fitposi == -99) {
1464  std::cerr << "!!EXITING: entry name not found: " << entry_name << std::endl;
1465  exit(2);
1466  } else {
1467  return fitposi;
1468  }
1469 }
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:578
ALIbool Fit::fitNextEvent ( ALIuint nEvent)
static

Definition at line 149 of file Fit.cc.

References addDaMatrixToEntries(), FittedEntriesManager::AddFittedEntriesSet(), AtWAMatrix, begin, calculateSimulatedMeasurementsWithOriginalValues(), dtNoiseDBValidation_cfg::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().

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 = 0;
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 = 1;
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() == 0 ) {
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 = 1;
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 = 1;
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 = 1;
322  return !lastEvent;
323  }
324 
325  } else {
326  lastEvent = 1;
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 dumpFittedValuesInAllAncestorFrames(ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1210
static void setCocoaStatus(const cocoaStatus cs)
Definition: Model.h:49
static ALIint debug
Definition: ALIUtils.h:35
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 substractLastDisplacementToEntries(const ALIdouble factor)
Definition: Fit.cc:1119
static ALIint MaxNoFitIterations
Definition: Fit.h:198
static void dumpFittedValues(ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1147
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:1416
static ALIint report
Definition: ALIUtils.h:34
void FillOptObjects(MatrixMeschach *AtWAMatrix)
#define begin
Definition: vmac.h:30
void FillFitParameters(MatrixMeschach *AtWAMatrix)
static void calculateSimulatedMeasurementsWithOriginalValues()
Definition: Fit.cc:515
tuple cout
Definition: gather_cfg.py:121
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().

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:35
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
tuple cout
Definition: gather_cfg.py:121
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

Definition at line 146 of file Fit.h.

References AtWAMatrix.

Referenced by CocoaDBMgr::GetEntryError(), and CocoaDBMgr::GetOptAlignInfoFromOptO().

146  {
147  return AtWAMatrix; }
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
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().

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  entryvalue = -999;
1307  }
1308  entryvalue = ( entry->value() + entry->valueDisplacementByFitting() ) / entry->OutputValueDimensionFactor();
1309  return entryvalue;
1310 }
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:35
tuple cout
Definition: gather_cfg.py:121
FitQuality Fit::getFitQuality ( const ALIbool  canBeGood = TRUE)
staticprivate

Definition at line 900 of file Fit.cc.

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

Referenced by fitParameters().

901 {
902  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::getFitQuality" << std::endl;
903 
904  double fit_quality = GetSChi2(1);
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 =fabs( (*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 = fabs(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:47
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIint debug
Definition: ALIUtils.h:35
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
static ALIMatrix * DaMatrix
Definition: Fit.h:165
static ALIMatrix * yfMatrix
Definition: Fit.h:170
MatrixMeschach ALIMatrix
static ALIint report
Definition: ALIUtils.h:34
static ALIdouble theRelativeFitQualityCut
Definition: Fit.h:193
tuple cout
Definition: gather_cfg.py:121
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:44
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, MaxNoFitIterations, ALIUtils::setMaximumDeviationDerivative(), theFitQualityCut, theMinDaFactor, and theRelativeFitQualityCut.

Referenced by CocoaAnalyzer::RunCocoa().

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:106
static ALIint debug
Definition: ALIUtils.h:35
static void setMaximumDeviationDerivative(ALIdouble val)
Definition: ALIUtils.h:108
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
tuple cout
Definition: gather_cfg.py:121
std::string Fit::GetMeasurementName ( int  meas)
staticprivate

Definition at line 1668 of file Fit.cc.

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

1669 {
1670  std::string measname = " ";
1671 
1672  std::cout << " imeas " << imeas << std::endl;
1673  int Aline = 0;
1674  std::vector< Measurement* >::const_iterator vmcite;
1675  for ( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); vmcite++) {
1676  for ( ALIuint jj = 0; jj < ALIuint((*vmcite)->dim()); jj++) {
1677  if( Aline == imeas ) {
1678  char ctmp[20];
1679  gcvt( jj, 10, ctmp );
1680  return ((*vmcite)->name()) + ":" + std::string(ctmp);
1681  }
1682  Aline++;
1683  }
1684  }
1685 
1686  std::cout << " return measname " << measname << std::endl;
1687  return measname;
1688 }
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
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(), and getFitQuality().

1001 {
1002  if(ALIUtils::debug >= 3) std::cout << "@@@ Fit::GetSChi2 useDa= " << useDa << std::endl;
1003 
1004  ALIMatrix* SMat = 0;
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:35
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
tuple cout
Definition: gather_cfg.py:121
static void PrintChi2(ALIdouble fit_quality, ALIbool isFirst)
Definition: Fit.cc:1473
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(), fileCollector::now, ALIUtils::set_time_now(), mathSSE::sqrt(), theMinimumEntryQuality, ALIUtils::time_now(), MatrixMeschach::transpose(), WMatrix, and yfMatrix.

Referenced by 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:47
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:35
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:48
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:1539
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
void Dump(const ALIstring &mtext)
static time_t time_now()
Definition: ALIUtils.h:44
static ALIint Fit::noFitIterations ( )
inlinestatic

Definition at line 96 of file Fit.h.

References theNoFitIterations.

96 { return theNoFitIterations; }
static ALIint theNoFitIterations
Definition: Fit.h:196
void Fit::printCentreInOptOFrame ( const OpticalObject opto,
const OpticalObject optoAncestor,
ALIFileOut fileout,
ALIbool  printErrors = 1,
ALIbool  printOrig = 1 
)
static

Definition at line 1257 of file Fit.cc.

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

Referenced by dumpFittedValues(), and dumpFittedValuesInAllAncestorFrames().

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 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:35
int ii
Definition: cuy.py:588
static void dumpEntryAfterFit(ALIFileOut &fileout, const Entry *entry, double entryvalue, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1313
const CLHEP::HepRotation & rmGlob() const
const CLHEP::Hep3Vector & centreGlob() const
Definition: OpticalObject.h:85
tuple cout
Definition: gather_cfg.py:121
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 1473 of file Fit.cc.

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

Referenced by GetSChi2().

1474 {
1475  double chi2meas = 0;
1476  double chi2cal = 0;
1477  ALIint nMeas = 0, nUnk = 0;
1478 
1479  //----- Calculate the chi2 of measurements
1480  std::vector< Measurement* >::const_iterator vmcite;
1481  for ( vmcite = Model::MeasurementList().begin(); vmcite != Model::MeasurementList().end(); vmcite++) {
1482  //--- Calculate Simulated Value Original
1483  for ( ALIuint ii = 0; ii < ALIuint((*vmcite)->dim()); ii++ ){
1484  nMeas++;
1485  double c2 = ( (*vmcite)->value(ii) - (*vmcite)->valueSimulated(ii) ) / (*vmcite)->sigma(ii);
1486  chi2meas += c2*c2;
1487  if( ALIUtils::debug >= 2) {
1488  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;
1489  }
1490  }
1491  }
1492 
1493  //----- Calculate the chi2 of calibrated parameters
1494  std::vector< Entry* >::iterator veite;
1495  for ( veite = Model::EntryList().begin();
1496  veite != Model::EntryList().end(); veite++ ) {
1497  if ( (*veite)->quality() == 2 ) nUnk++;
1498  if ( (*veite)->quality() == 1 ) {
1499  double c2 = (*veite)->valueDisplacementByFitting() / (*veite)->sigma();
1500  //double c2 = (*veite)->value() / (*veite)->sigma();
1501  chi2cal += c2*c2;
1502  if( ALIUtils::debug >= 2) std::cout << c2 << " adding chi2cal " << chi2cal << " " << (*veite)->OptOCurrent()->name() << " " << (*veite)->name() << std::endl;
1503  //- std::cout << " valueDisplacementByFitting " << (*veite)->valueDisplacementByFitting() << " sigma " << (*veite)->sigma() << std::endl;
1504  }
1505  }
1506 
1507  if( ALIUtils::report >= 1) {
1509  fileout << " Chi2= " << chi2meas+chi2cal << " / " << nMeas-nUnk << " dof " << " From measurements= " << chi2meas << " from calibrated parameters= " << chi2cal << std::endl;
1510  }
1511  if( ALIUtils::debug >= 3) std::cout << " quality Chi2 (no correlations) " << chi2meas+chi2cal << " " << chi2meas << " " << chi2cal << std::endl;
1512 
1513 
1514  if( !isFirst ) {
1515  // double fit_quality_change = thePreviousIterationFitQuality - fit_quality;
1516 
1517  if(ALIUtils::debug >= 0) {
1518  std::cout << std::endl << "@@@@ Fit iteration " << theNoFitIterations << " ..." << std::endl;
1519  // std::cout << theNoFitIterations << " Chi2 improvement in this iteration = " << fit_quality_change << std::endl;
1520  }
1521  if( ALIUtils::report >= 1 ) {
1523  fileout << std::endl << "Fit iteration " << theNoFitIterations << " ..." << std::endl;
1524  // fileout << theNoFitIterations << " Chi2 improvement in this iteration = " << fit_quality_change << std::endl;
1525  }
1526  }
1527 
1528  //---- Print chi2
1529  if(ALIUtils::debug >= 0) std::cout << theNoFitIterations << " Chi2 after iteration = " << fit_quality << std::endl;
1530  if( ALIUtils::report >= 1 ) {
1531  //--------- Get report file handler
1533  fileout << theNoFitIterations << " Chi2 after iteration = " << fit_quality << std::endl;
1534  }
1535 
1536 }
isFirst
Definition: cuy.py:417
int ALIint
Definition: CocoaGlobals.h:15
static ALIint debug
Definition: ALIUtils.h:35
static ALIstring & ReportFName()
the name of the report File
Definition: Model.h:96
int ii
Definition: cuy.py:588
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
tuple c2
Definition: counter.py:145
static ALIint report
Definition: ALIUtils.h:34
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
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 = 1,
ALIbool  printOrig = 1 
)
static

Definition at line 1289 of file Fit.cc.

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

Referenced by dumpFittedValues(), and dumpFittedValuesInAllAncestorFrames().

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 }
const std::vector< Entry * > & CoordinateEntryList() const
Definition: OpticalObject.h:65
int ii
Definition: cuy.py:588
std::vector< double > getRotationAnglesInOptOFrame(const OpticalObject *optoAncestor, const std::vector< Entry * > &entries) const
static void dumpEntryAfterFit(ALIFileOut &fileout, const Entry *entry, double entryvalue, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1313
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(), fileCollector::now, ALIUtils::set_time_now(), setCorrelationsInWMatrix(), ALIUtils::setFirstTime(), ALIUtils::time_now(), WMatrix, and yfMatrix.

Referenced by redoMatrices().

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 
508 
509 }
static void set_time_now(time_t now)
Definition: ALIUtils.h:47
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:35
static GlobalOptionMgr * getInstance()
static ALIMatrix * WMatrix
Definition: Fit.h:162
static void setFirstTime(ALIbool val)
Definition: ALIUtils.h:103
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:100
std::string ALIstring
Definition: CocoaGlobals.h:9
tuple cout
Definition: gather_cfg.py:121
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:44
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().

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:35
static void PropagateErrors()
Definition: Fit.cc:446
static void deleteMatrices()
Definition: Fit.cc:538
static void calculateSimulatedMeasurementsWithOriginalValues()
Definition: Fit.cc:515
tuple cout
Definition: gather_cfg.py:121
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 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:633
static ALIMatrix * WMatrix
Definition: Fit.h:162
ALIint fitPos() const
Definition: Entry.h:60
tuple cout
Definition: gather_cfg.py:121
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)
tuple cout
Definition: gather_cfg.py:121
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 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:35
static ErrorCorrelationMgr * getInstance()
int ii
Definition: cuy.py:588
const pss & getEntry1() const
const ALIdouble getCorrelation() const
JetCorrectorParameters corr
Definition: classes.h:5
const pss & getEntry2() const
tuple cout
Definition: gather_cfg.py:121
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(), and theMinimumEntryQuality.

Referenced by fitNextEvent().

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:35
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
tuple cout
Definition: gather_cfg.py:121
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().

106 {
107  // Model::setCocoaStatus( COCOA_InitFit );
109  if(GlobalOptionMgr::getInstance()->GlobalOptions()["rootResults"] > 0) {
110  NTmgr->BookNtuple();
111  }
112 
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:54
static ALIint debug
Definition: ALIUtils.h:35
static GlobalOptionMgr * getInstance()
static void setFirstTime(ALIbool val)
Definition: ALIUtils.h:103
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:40
tuple cout
Definition: gather_cfg.py:121
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().

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:35
static std::vector< Entry * > & EntryList()
Definition: Model.h:75
#define begin
Definition: vmac.h:30
tuple cout
Definition: gather_cfg.py:121
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().

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:35
static GlobalOptionMgr * getInstance()
static ALIbool getFirstTime()
Definition: ALIUtils.h:100
static void calculateSimulatedMeasurementsWithOriginalValues()
Definition: Fit.cc:515
tuple cout
Definition: gather_cfg.py:121
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().

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(), and startFit().

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