CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Alignment/CocoaFit/interface/Fit.h

Go to the documentation of this file.
00001 //   COCOA class header file
00002 //Id:  Fit.h
00003 //CAT: Model
00004 //
00005 //   Utility class that starts reading the system description file
00006 //              and contains the static data 
00007 // 
00008 //   History: v1.0 
00009 //   Pedro Arce
00010 #ifndef FIT_H
00011 #define FIT_H
00012 
00013 #define MAT_MESCHACH
00014 #ifdef MAT_MESCHACH
00015 #include "Alignment/CocoaFit/interface/MatrixMeschach.h"
00016 #endif
00017 
00018 
00019 #include <vector>
00020 
00021 
00022 #include "Alignment/CocoaUtilities/interface/CocoaGlobals.h" 
00023 class Entry;
00024 class OpticalObject;
00025 #include "CLHEP/Vector/Rotation.h"
00026 class FittedEntriesSet;
00027 class ALIFileOut;
00028 #include "Alignment/CocoaModel/interface/Model.h"
00029 
00030 typedef std::pair<ALIstring, ALIstring> pss;
00031 
00032 enum FitQuality{FQsmallDistanceToMinimum,FQbigDistanceToMinimum,FQchiSquareWorsened};
00033 
00034 class Fit
00035 {
00036 public:
00037   //----- Constructor / Destructor
00038   Fit(){ };
00039   ~Fit(){ };
00040 
00041   //----- Gets the only instance of this class
00042   static Fit& getInstance();  
00043 
00044   //----- Steering method to make the fit
00045   static void startFit();
00046 
00047   //----- Dump all the entries that have been fitted (those that were 'cal' or 'unk'
00048   //deprecated  static void dumpFittedEntries();
00049 
00050   //----- Dump all the entries of all the objects 
00051   static void dumpFittedValues( ALIFileOut& fileout, ALIbool printErrors = 1, ALIbool printOrig = 1 );
00052   static void dumpFittedValuesInAllAncestorFrames( ALIFileOut& fileout, ALIbool printErrors = 1, ALIbool printOrig = 1 );
00053   static void dumpEntryAfterFit( ALIFileOut& fileout, const Entry* entry, double entryvalue, ALIbool printErrors = 1, ALIbool printOrig = 1 );
00054   static void dumpEntryCorrelations( ALIFileOut& file );
00055   static void printCentreInOptOFrame( const OpticalObject* opto, const OpticalObject* optoAncestor, ALIFileOut& fileout, ALIbool printErrors = 1, ALIbool printOrig = 1 );
00056   static void printRotationAnglesInOptOFrame( const OpticalObject* opto, const OpticalObject* optoAncestor, ALIFileOut& fileout, ALIbool printErrors = 1, ALIbool printOrig = 1 );
00057 
00058   //----- Dump matrices used for the fit
00059   static void dumpMatrices();
00060 
00061 
00062  //@@@@ Access static data members
00063 
00064   //-----  Search an Entry name in of OpticalObject 'opto_name' and return its fitpos
00065   static ALIint findEntryFitPosition( const ALIstring& opto_name, const ALIstring& entry_name ); 
00066 
00067   //----- returns propagation matrix
00068   //op  static ALIMatrix& propagationMatrix(){
00069  //op     return *thePropagationMatrix;
00070  //op   }
00071 
00072 
00073 //@@@@@ private METHODS
00074  public:
00075   //------ Count how many entries are going to be fitted (have quality >=  theMinimumEntryQuality). Set for this entries the value of theFitPos
00076   static void setFittableEntries();
00077   
00078   static ALIbool fitNextEvent( ALIuint& nEvent );
00079 
00080  private:
00081   static void WriteVisualisationFiles();
00082 
00083   //----- Calculate the parameters (position, angles,...) with the chi square fit 
00084   //---- daFactor is the factor by which it is multiplied the matrix Da
00085   static FitQuality fitParameters( const double daFactor ); 
00086 
00087   static void redoMatrices();
00088 
00089   //----- Propagate the error of every Entry to every Measurement
00090   static void PropagateErrors();
00091 
00092  public:
00093   //----- Calculate the simulated value of each Measurement propagating the LightRay when all the entries have their original values
00094   static void calculateSimulatedMeasurementsWithOriginalValues();
00095 
00096   static ALIint noFitIterations(){ return theNoFitIterations; }
00097 
00098  private:
00099   //----- Calculate the NoLines & NoColumns and create matrices 
00100   static void CreateMatrices();
00101 
00102   //-----   Loop Measurements:
00103   //---  Fill Matrix A with derivatives respect to affecting entries 
00104   //---  Fill Matrix W, y & f with values and sigmas of measurement coordinateFill matrices  
00105   static void FillMatricesWithMeasurements();
00106 
00107   //----- Loop Measurements:
00108   //---    Fill Matrix A with derivatives respect to affecting entries 
00109   //---    Fill Matrix W, y & f with values and sigmas of measurement coordinate
00110   static void FillMatricesWithCalibratedParameters();
00111 
00112   //----- set Correlations In W Matrix
00113   static void setCorrelationsInWMatrix();
00114 
00115   //---------- set correlation between two entries of two OptOs
00116   static void setCorrelationFromParamFitted( const pss& entry1, const pss& entry2, ALIdouble correl );
00117   static void setCorrelationFromParamFitted( const ALIint fit_pos1, const ALIint fit_pos2, ALIdouble correl );
00118 
00119   //----- multiply matrices needed for fit
00120   static void multiplyMatrices();
00121 
00122   //----- Get Smatrix to calculate chi2
00123   static ALIdouble GetSChi2( ALIbool useDa );
00124 
00125   //----- check if the quality of the fit for this iteration is good enough
00126   static FitQuality getFitQuality( const ALIbool canBeGood = TRUE );
00127   static void evaluateFitQuality( const FitQuality fq, const double daFactor );
00128 
00129   //----- Correct entries with fitted values  
00130   static void addDaMatrixToEntries();
00131 
00132   //----- Substract Da of previous iteration (to try with a new Correct entries with fitted values  
00133   static void substractLastDisplacementToEntries( const ALIdouble factor );
00134 
00135   static void deleteMatrices();
00136 
00137   static double getEntryValue( const Entry* entry );
00138 
00139  public:
00140   static void PrintChi2( ALIdouble fit_quality, ALIbool isFirst );
00141 
00142  // public static DATA MEMBERS 
00143 public:
00144   // maximum deviation in a Measurent when a parameter is  displaced to get derivative
00145 
00146   static ALIMatrix* GetAtWAMatrix(){ 
00147     return AtWAMatrix; }
00148 
00149  private:
00150 
00151   static void CheckIfFitPossible();
00152   static int CheckIfMeasIsProportionalToAnother( ALIuint measNo );
00153   static std::string GetMeasurementName( int meas );
00154 
00155 // private DATA MEMBERS 
00156 private:
00157   // Only instance of Fit
00158   static Fit* instance;
00159 
00160   static ALIMatrix* AMatrix;
00161   static ALIMatrix* AtMatrix;
00162   static ALIMatrix* WMatrix;
00163   static ALIMatrix* AtWAMatrix;
00164   //op  static ALIMatrix* VaMatrix;
00165   static ALIMatrix* DaMatrix;
00166   //op  static ALIMatrix* PDMatrix;
00167   //-  static ALIMatrix* VyMatrix;
00168   //op  static ALIMatrix* yMatrix;
00169   //op  static ALIMatrix* fMatrix;
00170   static ALIMatrix* yfMatrix;
00171   //op  static ALIMatrix* thePropagationMatrix;
00172   //----- The number of lines and columns of matrix A
00173   static ALIint _NoLinesA;
00174   static ALIint _NoColumnsA;
00175 
00176   //FOR LINK..................
00177 private:
00178     //
00179   //-  void AddSigma( CLHEP::Hep3Vector& vori, CLHEP::Hep3Vector& vadd );
00180   //-  CLHEP::Hep3Vector atanVectorSigma( CLHEP::Hep3Vector& tanvs, const CLHEP::Hep3Vector& tanv );
00181   //-  CLHEP::Hep3Vector atanVector( CLHEP::Hep3Vector& tanv );
00182 
00183   //----- The minimum quality an entry must have to be inhcluded in the fit
00184   static ALIint theMinimumEntryQuality; 
00185 
00186   //----- Quality of fit in previous iteration 
00187   static ALIdouble thePreviousIterationFitQuality;
00188 
00189   //----- Minimum quality (chi square) the fit has to have to be good
00190   static ALIdouble theFitQualityCut;
00191 
00192   //----- Minimum change in quality (chi square) w.r.t previous iteration the fit has to have to be good
00193   static ALIdouble theRelativeFitQualityCut;
00194 
00195   //----- Number of fit iterations made up to a certain moment
00196   static ALIint theNoFitIterations;
00197   //----- Maximum number of fit iterations for the fit to reach good quality
00198   static ALIint MaxNoFitIterations;
00199 
00200   //----- Minimum value of the factor to multiply Da to test if an smaller chi2 can be obtained (chapter 5.2 of LeastSquareMethods)
00201   static ALIdouble theMinDaFactor;
00202 
00203  public:
00204   static ALIuint nEvent; 
00205 };
00206 
00207 
00208 #endif 
00209 
00210