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