00001
00002
00003
00004
00005
00006
00007
00008
00009
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
00038 Fit(){ };
00039 ~Fit(){ };
00040
00041
00042 static Fit& getInstance();
00043
00044
00045 static void startFit();
00046
00047
00048
00049
00050
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
00059 static void dumpMatrices();
00060
00061
00062
00063
00064
00065 static ALIint findEntryFitPosition( const ALIstring& opto_name, const ALIstring& entry_name );
00066
00067
00068
00069
00070
00071
00072
00073
00074 public:
00075
00076 static void setFittableEntries();
00077
00078 static ALIbool fitNextEvent( ALIuint& nEvent );
00079
00080 private:
00081 static void WriteVisualisationFiles();
00082
00083
00084
00085 static FitQuality fitParameters( const double daFactor );
00086
00087 static void redoMatrices();
00088
00089
00090 static void PropagateErrors();
00091
00092 public:
00093
00094 static void calculateSimulatedMeasurementsWithOriginalValues();
00095
00096 static ALIint noFitIterations(){ return theNoFitIterations; }
00097
00098 private:
00099
00100 static void CreateMatrices();
00101
00102
00103
00104
00105 static void FillMatricesWithMeasurements();
00106
00107
00108
00109
00110 static void FillMatricesWithCalibratedParameters();
00111
00112
00113 static void setCorrelationsInWMatrix();
00114
00115
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
00120 static void multiplyMatrices();
00121
00122
00123 static ALIdouble GetSChi2( ALIbool useDa );
00124
00125
00126 static FitQuality getFitQuality( const ALIbool canBeGood = TRUE );
00127 static void evaluateFitQuality( const FitQuality fq, const double daFactor );
00128
00129
00130 static void addDaMatrixToEntries();
00131
00132
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
00143 public:
00144
00145
00146 static ALIMatrix* GetAtWAMatrix(){
00147 return AtWAMatrix; }
00148
00149 private:
00150
00151 static void CheckIfFitPossible();
00152 static int CheckIfMeasIsProportionalToAnother( uint measNo );
00153 static std::string GetMeasurementName( int meas );
00154
00155
00156 private:
00157
00158 static Fit* instance;
00159
00160 static ALIMatrix* AMatrix;
00161 static ALIMatrix* AtMatrix;
00162 static ALIMatrix* WMatrix;
00163 static ALIMatrix* AtWAMatrix;
00164
00165 static ALIMatrix* DaMatrix;
00166
00167
00168
00169
00170 static ALIMatrix* yfMatrix;
00171
00172
00173 static ALIint _NoLinesA;
00174 static ALIint _NoColumnsA;
00175
00176
00177 private:
00178
00179
00180
00181
00182
00183
00184 static ALIint theMinimumEntryQuality;
00185
00186
00187 static ALIdouble thePreviousIterationFitQuality;
00188
00189
00190 static ALIdouble theFitQualityCut;
00191
00192
00193 static ALIdouble theRelativeFitQualityCut;
00194
00195
00196 static ALIint theNoFitIterations;
00197
00198 static ALIint MaxNoFitIterations;
00199
00200
00201 static ALIdouble theMinDaFactor;
00202 };
00203
00204
00205 #endif
00206
00207