CMS 3D CMS Logo

Fit.h
Go to the documentation of this file.
1 // COCOA class header file
2 //Id: Fit.h
3 //CAT: Model
4 //
5 // Utility class that starts reading the system description file
6 // and contains the static data
7 //
8 // History: v1.0
9 // Pedro Arce
10 #ifndef FIT_H
11 #define FIT_H
12 
13 #define MAT_MESCHACH
14 #ifdef MAT_MESCHACH
16 #endif
17 
18 
19 #include <vector>
20 
21 
23 class Entry;
24 class OpticalObject;
25 #include "CLHEP/Vector/Rotation.h"
26 class FittedEntriesSet;
27 class ALIFileOut;
29 
30 typedef std::pair<ALIstring, ALIstring> pss;
31 
33 
34 class Fit
35 {
36 public:
37  //----- Constructor / Destructor
38  Fit(){ };
39  ~Fit(){ };
40 
41  //----- Gets the only instance of this class
42  static Fit& getInstance();
43 
44  //----- Steering method to make the fit
45  static void startFit();
46 
47  //----- Dump all the entries that have been fitted (those that were 'cal' or 'unk'
48  //deprecated static void dumpFittedEntries();
49 
50  //----- Dump all the entries of all the objects
51  static void dumpFittedValues( ALIFileOut& fileout, ALIbool printErrors = 1, ALIbool printOrig = 1 );
52  static void dumpFittedValuesInAllAncestorFrames( ALIFileOut& fileout, ALIbool printErrors = 1, ALIbool printOrig = 1 );
53  static void dumpEntryAfterFit( ALIFileOut& fileout, const Entry* entry, double entryvalue, ALIbool printErrors = 1, ALIbool printOrig = 1 );
54  static void dumpEntryCorrelations( ALIFileOut& file );
55  static void printCentreInOptOFrame( const OpticalObject* opto, const OpticalObject* optoAncestor, ALIFileOut& fileout, ALIbool printErrors = 1, ALIbool printOrig = 1 );
56  static void printRotationAnglesInOptOFrame( const OpticalObject* opto, const OpticalObject* optoAncestor, ALIFileOut& fileout, ALIbool printErrors = 1, ALIbool printOrig = 1 );
57 
58  //----- Dump matrices used for the fit
59  static void dumpMatrices();
60 
61 
62  //@@@@ Access static data members
63 
64  //----- Search an Entry name in of OpticalObject 'opto_name' and return its fitpos
65  static ALIint findEntryFitPosition( const ALIstring& opto_name, const ALIstring& entry_name );
66 
67  //----- returns propagation matrix
68  //op static ALIMatrix& propagationMatrix(){
69  //op return *thePropagationMatrix;
70  //op }
71 
72 
73 //@@@@@ private METHODS
74  public:
75  //------ Count how many entries are going to be fitted (have quality >= theMinimumEntryQuality). Set for this entries the value of theFitPos
76  static void setFittableEntries();
77 
79 
80  private:
81  static void WriteVisualisationFiles();
82 
83  //----- Calculate the parameters (position, angles,...) with the chi square fit
84  //---- daFactor is the factor by which it is multiplied the matrix Da
85  static FitQuality fitParameters( const double daFactor );
86 
87  static void redoMatrices();
88 
89  //----- Propagate the error of every Entry to every Measurement
90  static void PropagateErrors();
91 
92  public:
93  //----- Calculate the simulated value of each Measurement propagating the LightRay when all the entries have their original values
95 
97 
98  private:
99  //----- Calculate the NoLines & NoColumns and create matrices
100  static void CreateMatrices();
101 
102  //----- Loop Measurements:
103  //--- Fill Matrix A with derivatives respect to affecting entries
104  //--- Fill Matrix W, y & f with values and sigmas of measurement coordinateFill matrices
105  static void FillMatricesWithMeasurements();
106 
107  //----- Loop Measurements:
108  //--- Fill Matrix A with derivatives respect to affecting entries
109  //--- Fill Matrix W, y & f with values and sigmas of measurement coordinate
111 
112  //----- set Correlations In W Matrix
113  static void setCorrelationsInWMatrix();
114 
115  //---------- set correlation between two entries of two OptOs
116  static void setCorrelationFromParamFitted( const pss& entry1, const pss& entry2, ALIdouble correl );
117  static void setCorrelationFromParamFitted( const ALIint fit_pos1, const ALIint fit_pos2, ALIdouble correl );
118 
119  //----- multiply matrices needed for fit
120  static void multiplyMatrices();
121 
122  //----- Get Smatrix to calculate chi2
123  static ALIdouble GetSChi2( ALIbool useDa );
124 
125  //----- check if the quality of the fit for this iteration is good enough
126  static FitQuality getFitQuality( const ALIbool canBeGood = TRUE );
127  static void evaluateFitQuality( const FitQuality fq, const double daFactor );
128 
129  //----- Correct entries with fitted values
130  static void addDaMatrixToEntries();
131 
132  //----- Substract Da of previous iteration (to try with a new Correct entries with fitted values
133  static void substractLastDisplacementToEntries( const ALIdouble factor );
134 
135  static void deleteMatrices();
136 
137  static double getEntryValue( const Entry* entry );
138 
139  public:
140  static void PrintChi2( ALIdouble fit_quality, ALIbool isFirst );
141 
142  // public static DATA MEMBERS
143 public:
144  // maximum deviation in a Measurent when a parameter is displaced to get derivative
145 
147  return AtWAMatrix; }
148 
149  private:
150 
151  static void CheckIfFitPossible();
152  static int CheckIfMeasIsProportionalToAnother( ALIuint measNo );
153  static std::string GetMeasurementName( int meas );
154 
155 // private DATA MEMBERS
156 private:
157  // Only instance of Fit
158  static Fit* instance;
159 
164  //op static ALIMatrix* VaMatrix;
166  //op static ALIMatrix* PDMatrix;
167  //- static ALIMatrix* VyMatrix;
168  //op static ALIMatrix* yMatrix;
169  //op static ALIMatrix* fMatrix;
171  //op static ALIMatrix* thePropagationMatrix;
172  //----- The number of lines and columns of matrix A
175 
176  //FOR LINK..................
177 private:
178  //
179  //- void AddSigma( CLHEP::Hep3Vector& vori, CLHEP::Hep3Vector& vadd );
180  //- CLHEP::Hep3Vector atanVectorSigma( CLHEP::Hep3Vector& tanvs, const CLHEP::Hep3Vector& tanv );
181  //- CLHEP::Hep3Vector atanVector( CLHEP::Hep3Vector& tanv );
182 
183  //----- The minimum quality an entry must have to be inhcluded in the fit
185 
186  //----- Quality of fit in previous iteration
188 
189  //----- Minimum quality (chi square) the fit has to have to be good
191 
192  //----- Minimum change in quality (chi square) w.r.t previous iteration the fit has to have to be good
194 
195  //----- Number of fit iterations made up to a certain moment
197  //----- Maximum number of fit iterations for the fit to reach good quality
199 
200  //----- Minimum value of the factor to multiply Da to test if an smaller chi2 can be obtained (chapter 5.2 of LeastSquareMethods)
202 
203  public:
204  static ALIuint nEvent;
205 };
206 
207 
208 #endif
209 
210 
static void multiplyMatrices()
Definition: Fit.cc:821
static ALIdouble theMinDaFactor
Definition: Fit.h:201
~Fit()
Definition: Fit.h:39
long double ALIdouble
Definition: CocoaGlobals.h:11
static ALIMatrix * AMatrix
Definition: Fit.h:160
#define TRUE
Definition: scimark2.h:12
static void setCorrelationFromParamFitted(const pss &entry1, const pss &entry2, ALIdouble correl)
Definition: Fit.cc:793
static void dumpFittedValuesInAllAncestorFrames(ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1210
static void setCorrelationsInWMatrix()
Definition: Fit.cc:770
std::pair< ALIstring, ALIstring > pss
Definition: Fit.h:27
Definition: Entry.h:18
static ALIMatrix * GetAtWAMatrix()
Definition: Fit.h:146
static ALIint theMinimumEntryQuality
Definition: Fit.h:184
static void printCentreInOptOFrame(const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1257
int ALIint
Definition: CocoaGlobals.h:15
static ALIMatrix * AtMatrix
Definition: Fit.h:161
static Fit & getInstance()
Definition: Fit.cc:71
static void setFittableEntries()
Definition: Fit.cc:364
static double getEntryValue(const Entry *entry)
Definition: Fit.cc:1301
static ALIint _NoLinesA
Definition: Fit.h:173
static void dumpEntryAfterFit(ALIFileOut &fileout, const Entry *entry, double entryvalue, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1313
static ALIMatrix * AtWAMatrix
Definition: Fit.h:163
static ALIdouble theFitQualityCut
Definition: Fit.h:190
bool ALIbool
Definition: CocoaGlobals.h:19
static FitQuality getFitQuality(const ALIbool canBeGood=TRUE)
Definition: Fit.cc:900
static void substractLastDisplacementToEntries(const ALIdouble factor)
Definition: Fit.cc:1119
Definition: Fit.h:34
static ALIint MaxNoFitIterations
Definition: Fit.h:198
static void dumpFittedValues(ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1147
static ALIint findEntryFitPosition(const ALIstring &opto_name, const ALIstring &entry_name)
Definition: Fit.cc:1439
static ALIMatrix * WMatrix
Definition: Fit.h:162
static std::string GetMeasurementName(int meas)
Definition: Fit.cc:1668
static ALIdouble thePreviousIterationFitQuality
Definition: Fit.h:187
static ALIMatrix * DaMatrix
Definition: Fit.h:165
static void PropagateErrors()
Definition: Fit.cc:446
static ALIbool fitNextEvent(ALIuint &nEvent)
Definition: Fit.cc:149
static ALIMatrix * yfMatrix
Definition: Fit.h:170
static Fit * instance
Definition: Fit.h:158
static void evaluateFitQuality(const FitQuality fq, const double daFactor)
static ALIuint nEvent
Definition: Fit.h:204
isFirst
Definition: cuy.py:417
static void WriteVisualisationFiles()
Definition: Fit.cc:338
static ALIint _NoColumnsA
Definition: Fit.h:174
static void FillMatricesWithMeasurements()
Definition: Fit.cc:626
static void CreateMatrices()
Definition: Fit.cc:557
static void redoMatrices()
Definition: Fit.cc:429
static void dumpMatrices()
Definition: Fit.cc:1416
static void dumpEntryCorrelations(ALIFileOut &file)
Definition: Fit.cc:1364
static void startFit()
Definition: Fit.cc:105
static void deleteMatrices()
Definition: Fit.cc:538
static void CheckIfFitPossible()
Definition: Fit.cc:1539
static ALIint noFitIterations()
Definition: Fit.h:96
static int CheckIfMeasIsProportionalToAnother(ALIuint measNo)
Definition: Fit.cc:1620
Fit()
Definition: Fit.h:38
std::string ALIstring
Definition: CocoaGlobals.h:9
static ALIdouble theRelativeFitQualityCut
Definition: Fit.h:193
static void calculateSimulatedMeasurementsWithOriginalValues()
Definition: Fit.cc:515
static void PrintChi2(ALIdouble fit_quality, ALIbool isFirst)
Definition: Fit.cc:1473
static FitQuality fitParameters(const double daFactor)
Definition: Fit.cc:392
FitQuality
Definition: Fit.h:32
static void addDaMatrixToEntries()
Definition: Fit.cc:1065
static ALIdouble GetSChi2(ALIbool useDa)
Definition: Fit.cc:1000
static ALIint theNoFitIterations
Definition: Fit.h:196
static void printRotationAnglesInOptOFrame(const OpticalObject *opto, const OpticalObject *optoAncestor, ALIFileOut &fileout, ALIbool printErrors=1, ALIbool printOrig=1)
Definition: Fit.cc:1289
unsigned int ALIuint
Definition: CocoaGlobals.h:17
static void FillMatricesWithCalibratedParameters()
Definition: Fit.cc:709