Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-07 04:34:25

0001 //   COCOA class header file

0002 //Id:  Fit.h

0003 //CAT: Model

0004 //

0005 //   Utility class that starts reading the system description file

0006 //              and contains the static data

0007 //

0008 //   History: v1.0

0009 //   Pedro Arce

0010 #ifndef FIT_H
0011 #define FIT_H
0012 
0013 #define MAT_MESCHACH
0014 #ifdef MAT_MESCHACH
0015 #include "Alignment/CocoaFit/interface/MatrixMeschach.h"
0016 #endif
0017 
0018 #include <vector>
0019 
0020 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h"
0021 class Entry;
0022 class OpticalObject;
0023 #include "CLHEP/Vector/Rotation.h"
0024 class FittedEntriesSet;
0025 class ALIFileOut;
0026 #include "Alignment/CocoaModel/interface/Model.h"
0027 
0028 typedef std::pair<ALIstring, ALIstring> pss;
0029 
0030 enum FitQuality { FQsmallDistanceToMinimum, FQbigDistanceToMinimum, FQchiSquareWorsened };
0031 
0032 class Fit {
0033 public:
0034   //----- Constructor / Destructor

0035   Fit() {}
0036   ~Fit() {}
0037 
0038   //----- Gets the only instance of this class

0039   static Fit& getInstance();
0040 
0041   //----- Steering method to make the fit

0042   static void startFit();
0043 
0044   //----- Dump all the entries that have been fitted (those that were 'cal' or 'unk'

0045   //deprecated  static void dumpFittedEntries();

0046 
0047   //----- Dump all the entries of all the objects

0048   static void dumpFittedValues(ALIFileOut& fileout, ALIbool printErrors = true, ALIbool printOrig = true);
0049   static void dumpFittedValuesInAllAncestorFrames(ALIFileOut& fileout,
0050                                                   ALIbool printErrors = true,
0051                                                   ALIbool printOrig = true);
0052   static void dumpEntryAfterFit(
0053       ALIFileOut& fileout, const Entry* entry, double entryvalue, ALIbool printErrors = true, ALIbool printOrig = true);
0054   static void dumpEntryCorrelations(ALIFileOut& file);
0055   static void printCentreInOptOFrame(const OpticalObject* opto,
0056                                      const OpticalObject* optoAncestor,
0057                                      ALIFileOut& fileout,
0058                                      ALIbool printErrors = true,
0059                                      ALIbool printOrig = true);
0060   static void printRotationAnglesInOptOFrame(const OpticalObject* opto,
0061                                              const OpticalObject* optoAncestor,
0062                                              ALIFileOut& fileout,
0063                                              ALIbool printErrors = true,
0064                                              ALIbool printOrig = true);
0065 
0066   //----- Dump matrices used for the fit

0067   static void dumpMatrices();
0068 
0069   //@@@@ Access static data members

0070 
0071   //-----  Search an Entry name in of OpticalObject 'opto_name' and return its fitpos

0072   static ALIint findEntryFitPosition(const ALIstring& opto_name, const ALIstring& entry_name);
0073 
0074   //----- returns propagation matrix

0075   //op  static ALIMatrix& propagationMatrix(){

0076   //op     return *thePropagationMatrix;

0077   //op   }

0078 
0079   //@@@@@ private METHODS

0080 public:
0081   //------ Count how many entries are going to be fitted (have quality >=  theMinimumEntryQuality). Set for this entries the value of theFitPos

0082   static void setFittableEntries();
0083 
0084   static ALIbool fitNextEvent(ALIuint& nEvent);
0085 
0086 private:
0087   static void WriteVisualisationFiles();
0088 
0089   //----- Calculate the parameters (position, angles,...) with the chi square fit

0090   //---- daFactor is the factor by which it is multiplied the matrix Da

0091   static FitQuality fitParameters(const double daFactor);
0092 
0093   static void redoMatrices();
0094 
0095   //----- Propagate the error of every Entry to every Measurement

0096   static void PropagateErrors();
0097 
0098 public:
0099   //----- Calculate the simulated value of each Measurement propagating the LightRay when all the entries have their original values

0100   static void calculateSimulatedMeasurementsWithOriginalValues();
0101 
0102   static ALIint noFitIterations() { return theNoFitIterations; }
0103 
0104 private:
0105   //----- Calculate the NoLines & NoColumns and create matrices

0106   static void CreateMatrices();
0107 
0108   //-----   Loop Measurements:

0109   //---  Fill Matrix A with derivatives respect to affecting entries

0110   //---  Fill Matrix W, y & f with values and sigmas of measurement coordinateFill matrices

0111   static void FillMatricesWithMeasurements();
0112 
0113   //----- Loop Measurements:

0114   //---    Fill Matrix A with derivatives respect to affecting entries

0115   //---    Fill Matrix W, y & f with values and sigmas of measurement coordinate

0116   static void FillMatricesWithCalibratedParameters();
0117 
0118   //----- set Correlations In W Matrix

0119   static void setCorrelationsInWMatrix();
0120 
0121   //---------- set correlation between two entries of two OptOs

0122   static void setCorrelationFromParamFitted(const pss& entry1, const pss& entry2, ALIdouble correl);
0123   static void setCorrelationFromParamFitted(const ALIint fit_pos1, const ALIint fit_pos2, ALIdouble correl);
0124 
0125   //----- multiply matrices needed for fit

0126   static void multiplyMatrices();
0127 
0128   //----- Get Smatrix to calculate chi2

0129   static ALIdouble GetSChi2(ALIbool useDa);
0130 
0131   //----- check if the quality of the fit for this iteration is good enough

0132   static FitQuality getFitQuality(const ALIbool canBeGood = TRUE);
0133   static void evaluateFitQuality(const FitQuality fq, const double daFactor);
0134 
0135   //----- Correct entries with fitted values

0136   static void addDaMatrixToEntries();
0137 
0138   //----- Substract Da of previous iteration (to try with a new Correct entries with fitted values

0139   static void substractLastDisplacementToEntries(const ALIdouble factor);
0140 
0141   static void deleteMatrices();
0142 
0143   static double getEntryValue(const Entry* entry);
0144 
0145 public:
0146   static void PrintChi2(ALIdouble fit_quality, ALIbool isFirst);
0147 
0148   // public static DATA MEMBERS

0149 public:
0150   // maximum deviation in a Measurent when a parameter is  displaced to get derivative

0151 
0152   static ALIMatrix* GetAtWAMatrix() { return AtWAMatrix; }
0153 
0154 private:
0155   static void CheckIfFitPossible();
0156   static int CheckIfMeasIsProportionalToAnother(ALIuint measNo);
0157   static std::string GetMeasurementName(int meas);
0158 
0159   // private DATA MEMBERS

0160 private:
0161   // Only instance of Fit

0162   static Fit* instance;
0163 
0164   static ALIMatrix* AMatrix;
0165   static ALIMatrix* AtMatrix;
0166   static ALIMatrix* WMatrix;
0167   static ALIMatrix* AtWAMatrix;
0168   //op  static ALIMatrix* VaMatrix;

0169   static ALIMatrix* DaMatrix;
0170   //op  static ALIMatrix* PDMatrix;

0171   //-  static ALIMatrix* VyMatrix;

0172   //op  static ALIMatrix* yMatrix;

0173   //op  static ALIMatrix* fMatrix;

0174   static ALIMatrix* yfMatrix;
0175   //op  static ALIMatrix* thePropagationMatrix;

0176   //----- The number of lines and columns of matrix A

0177   static ALIint _NoLinesA;
0178   static ALIint _NoColumnsA;
0179 
0180   //FOR LINK..................

0181 private:
0182   //

0183   //-  void AddSigma( CLHEP::Hep3Vector& vori, CLHEP::Hep3Vector& vadd );

0184   //-  CLHEP::Hep3Vector atanVectorSigma( CLHEP::Hep3Vector& tanvs, const CLHEP::Hep3Vector& tanv );

0185   //-  CLHEP::Hep3Vector atanVector( CLHEP::Hep3Vector& tanv );

0186 
0187   //----- The minimum quality an entry must have to be inhcluded in the fit

0188   static ALIint theMinimumEntryQuality;
0189 
0190   //----- Quality of fit in previous iteration

0191   static ALIdouble thePreviousIterationFitQuality;
0192 
0193   //----- Minimum quality (chi square) the fit has to have to be good

0194   static ALIdouble theFitQualityCut;
0195 
0196   //----- Minimum change in quality (chi square) w.r.t previous iteration the fit has to have to be good

0197   static ALIdouble theRelativeFitQualityCut;
0198 
0199   //----- Number of fit iterations made up to a certain moment

0200   static ALIint theNoFitIterations;
0201   //----- Maximum number of fit iterations for the fit to reach good quality

0202   static ALIint MaxNoFitIterations;
0203 
0204   //----- Minimum value of the factor to multiply Da to test if an smaller chi2 can be obtained (chapter 5.2 of LeastSquareMethods)

0205   static ALIdouble theMinDaFactor;
0206 
0207 public:
0208   static ALIuint nEvent;
0209 };
0210 
0211 #endif