Coding rule violations (Raphaelle)
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFit.h
CommitLineData
55a288e5 1#ifndef ALITRDCALIBRAFIT_H
2#define ALITRDCALIBRAFIT_H
3/* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
5
6/* $Id$ */
7
8///////////////////////////////////////////////////////////////////////////////
9// //
10// TRD calibration class for the HLT parameters //
11// //
12///////////////////////////////////////////////////////////////////////////////
13
14#ifndef ROOT_TObject
36dc3337 15# include <TObject.h>
6bbdc11a 16#endif
17#ifndef ROOT_TVectorD
18# include <TVectorD.h>
36dc3337 19#endif
55a288e5 20
21class TTree;
22class TProfile2D;
23class TGraphErrors;
24class TObjArray;
25class TH1I;
26class TH1;
27class TH1F;
28class TH2I;
29class TH2F;
30class TF1;
3a0f6479 31class TTreeSRedirector;
55a288e5 32
daa7dc79 33
55a288e5 34class AliLog;
f162af62 35
55a288e5 36class AliTRDCalibraMode;
37class AliTRDCalibraVector;
3a0f6479 38class AliTRDCalibraVdriftLinearFit;
55a288e5 39class AliTRDCalDet;
3a0f6479 40class AliTRDCalROC;
f162af62 41class AliTRDgeometry;
55a288e5 42
43class AliTRDCalibraFit : public TObject {
44
45 public:
46
47 // Instance
48 static AliTRDCalibraFit *Instance();
49 static void Terminate();
50 static void Destroy();
64942b85 51 void DestroyDebugStreamer();
55a288e5 52
53 AliTRDCalibraFit(const AliTRDCalibraFit &c);
54 AliTRDCalibraFit &operator=(const AliTRDCalibraFit &) { return *this; }
55
6aafa7ea 56 // Function for integration range of the charge
57 void RangeChargeIntegration(Float_t vdrift, Float_t t0, Int_t &begin, Int_t &peak, Int_t &end) const;
55a288e5 58
6aafa7ea 59 // Functions fit for CH
60 Bool_t AnalyseCH(const TH2I *ch);
61 Bool_t AnalyseCH(AliTRDCalibraVector *calvect);
62
63 // Functions fit for PH
64 Bool_t AnalysePH(const TProfile2D *ph);
65 Bool_t AnalysePH(AliTRDCalibraVector *calvect);
66
67 // Functions fit for PRF
68 Bool_t AnalysePRF(const TProfile2D *prf);
69 Bool_t AnalysePRF(AliTRDCalibraVector *calvect);
70
71 Bool_t AnalysePRFMarianFit(const TProfile2D *prf);
72 Bool_t AnalysePRFMarianFit(AliTRDCalibraVector *calvect);
73
74 // Functions fit for vdrift/lorentzangle
75 Bool_t AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli);
76
77 // Pad Calibration
78 Bool_t SetModeCalibration(const char *name, Int_t i);
79
80 //Reset Function
81 void ResetVectorFit();
82
83 // Some functions
84 Double_t *CalculPolynomeLagrange2(const Double_t *x, const Double_t *y) const;
85 Double_t *CalculPolynomeLagrange3(const Double_t *x, const Double_t *y) const;
86 Double_t *CalculPolynomeLagrange4(const Double_t *x, const Double_t *y) const;
87
88 // Fill the database
89 void RemoveOutliers(Int_t type, Bool_t perdetector = kFALSE);
90 void RemoveOutliers2(Bool_t perdetector = kFALSE);
91 void PutMeanValueOtherVectorFit(Int_t ofwhat = 1, Bool_t perdetector = kFALSE);
92 void PutMeanValueOtherVectorFit2(Int_t ofwhat = 1, Bool_t perdetector = kFALSE);
93 AliTRDCalDet *CreateDetObjectVdrift(const TObjArray *vectorFit, Bool_t perdetector = kFALSE);
94 AliTRDCalDet *CreateDetObjectGain(const TObjArray *vectorFit, Bool_t meanOtherBefore=kTRUE, Double_t scaleFitFactor = 0.02431, Bool_t perdetector = kTRUE);
95 AliTRDCalDet *CreateDetObjectT0(const TObjArray *vectorFit, Bool_t perdetector = kFALSE);
96 AliTRDCalDet *CreateDetObjectLorentzAngle(const TObjArray *vectorFit);
97
98 TObject *CreatePadObjectGain(const TObjArray *vectorFit = 0, Double_t scaleFitFactor = 1.0, const AliTRDCalDet *detobject = 0);
99 TObject *CreatePadObjectVdrift(const TObjArray *vectorFit = 0, const AliTRDCalDet *detobject = 0);
100 TObject *CreatePadObjectT0(const TObjArray *vectorFit = 0, const AliTRDCalDet *detobject = 0);
101 TObject *CreatePadObjectPRF(const TObjArray *vectorFit);
102
103 // Outliers stats
104 AliTRDCalDet *MakeOutliersStatDet(const TObjArray *vectorFit, const char *name, Double_t &mean);
105 TObject *MakeOutliersStatPad(const TObjArray *vectorFit, const char *name, Double_t &mean);
413153cb 106
6aafa7ea 107 //
108 // Set or Get the variables
109 //
110
111 // Fit
112 void ChooseMethod(Short_t method) { fMethod = method; }
113 void SetBeginFitCharge(Float_t beginFitCharge);
114 void SetPeriodeFitPH(Int_t periodeFitPH);
115 void SetTakeTheMaxPH() { fTakeTheMaxPH = kTRUE; }
116 void SetT0Shift0(Float_t t0Shift0);
117 void SetT0Shift1(Float_t t0Shift1);
118 void SetRangeFitPRF(Float_t rangeFitPRF);
119 void SetAccCDB() { fAccCDB = kTRUE; }
120 void SetMinEntries(Int_t minEntries);
121 void SetRebin(Short_t rebin);
122
123 Int_t GetPeriodeFitPH() const { return fFitPHPeriode; }
124 Bool_t GetTakeTheMaxPH() const { return fTakeTheMaxPH; }
125 Float_t GetT0Shift0() const { return fT0Shift0; }
126 Float_t GetT0Shift1() const { return fT0Shift1; }
127 Float_t GetRangeFitPRF() const { return fRangeFitPRF; }
128 Bool_t GetAccCDB() const { return fAccCDB; }
129 Int_t GetMinEntries() const { return fMinEntries; }
130 Short_t GetRebin() const { return fRebin; }
131
132 // Statistics
133 Int_t GetNumberFit() const { return fNumberFit; }
134 Int_t GetNumberFitSuccess() const { return fNumberFitSuccess; }
135 Int_t GetNumberEnt() const { return fNumberEnt; }
136 Double_t GetStatisticMean() const { return fStatisticMean; }
137
413153cb 138
6aafa7ea 139 // Debug
140 void SetDebugLevel(Short_t level) { fDebugLevel = level; }
141 void SetDet(Int_t iLayer, Int_t iStack, Int_t iSector) { fDet[0] = iLayer;
053767a4 142 fDet[1] = iStack;
143 fDet[2] = iSector; }
413153cb 144 void SetFitVoir(Int_t fitVoir) { fFitVoir = fitVoir; }
145 // Magnetic field
146 void SetMagneticField(Float_t magneticfield) { fMagneticField = magneticfield; }
147
148 // Get the scale factor
053767a4 149 Double_t GetScaleFitFactor() const { return fScaleFitFactor; }
413153cb 150
151 // Vector Fit getter
152 TObjArray GetVectorFit() const { return fVectorFit; }
153 TObjArray GetVectorFit2() const { return fVectorFit2; }
154
155 // AliTRDCalibraMode
979b168f 156 AliTRDCalibraMode *GetCalibraMode() const { return fCalibraMode; }
413153cb 157
e526983e 158 class AliTRDFitInfo : public TObject {
159
160 public:
161
162 AliTRDFitInfo()
163 :TObject()
164 ,fCoef(0x0)
165 ,fDetector(-1) { }
166 AliTRDFitInfo(const AliTRDFitInfo &i)
167 :TObject(i)
168 ,fCoef(0x0)
169 ,fDetector(-1) { }
170 AliTRDFitInfo &operator=(const AliTRDFitInfo&) { return *this; }
171 virtual ~AliTRDFitInfo() { if(fCoef) { delete [] fCoef;} }
172
daa7dc79 173 void SetCoef(Float_t *coef) { fCoef = coef; }
e526983e 174 void SetDetector(Int_t detector) { fDetector = detector; }
175
176 Float_t *GetCoef() const { return fCoef; }
177 Int_t GetDetector() const { return fDetector; }
178
179 protected:
180
181 Float_t *fCoef; // Relative coefficient for each group of the detector
182 Int_t fDetector; // Detector number
183
184 };
185
6aafa7ea 186 // Fit function
187 void FitLagrangePoly(TH1* projPH);
e526983e 188
55a288e5 189 protected:
413153cb 190
191 // Geometry
64942b85 192 AliTRDgeometry *fGeo; //! The TRD geometry
413153cb 193
194
195 Int_t fNumberOfBinsExpected; // Number of bins expected
196
197 // Fit
198 Short_t fMethod; // Method
199 Float_t fBeginFitCharge; // The fit begins at mean/fBeginFitCharge for the gain calibration
200 Int_t fFitPHPeriode; // Periode of the fit PH
201 Bool_t fTakeTheMaxPH; // Take the Max for the T0 determination
202 Float_t fT0Shift0; // T0 Shift with the maximum positive slope
203 Float_t fT0Shift1; // T0 Shift with the maximum of the amplification region
204 Float_t fRangeFitPRF; // The fit range for the PRF is -fRangeFitPRF +fRangeFitPRF
205 Bool_t fAccCDB; // If there is a calibration database to be compared with....
206 Int_t fMinEntries; // Min Entries to fit the histo
207 Short_t fRebin; // If you want to rebin the histo for the gain calibration
208
209 // Statistics
210 Int_t fNumberFit; // To know how many pad groups have been fitted
211 Int_t fNumberFitSuccess; // To know how many pad groups have been fitted successfully
212 Int_t fNumberEnt; // To know how many pad groups have entries in the histo
213 Double_t fStatisticMean; // To know the mean statistic of the histos
214
215
216 // Debug Modes
217 TTreeSRedirector *fDebugStreamer; //!Debug streamer
218 Short_t fDebugLevel; // Flag for debugging
053767a4 219 Int_t fDet[3]; // Detector visualised (layer,stack,sector) si debugging == 3 or 4
413153cb 220 Int_t fFitVoir; // Fit visualised si debugging == 2
221
222 // Magnetic field lorentz angle
223 Float_t fMagneticField; // Magnetic field lorentz angle
224
225 // Calibra objects
226
227 AliTRDCalibraMode *fCalibraMode; // The calibration mode
228
229 // Current values of the coefficients found and ect...
230 Float_t fCurrentCoef[2]; // Current coefs
231 Float_t fCurrentCoefE; // Current coefs error
232 Float_t fCurrentCoef2[2]; // Current coefs
233 Float_t fCurrentCoefE2; // Current coefs error
234 Float_t fPhd[3]; // Begin AR and DR
235 Int_t fDect1; // First calibration group that will be called to be maybe fitted
236 Int_t fDect2; // Last calibration group that will be called to be maybe fitted
237 Double_t fScaleFitFactor; // Scale factor of the fit results for the gain
238 Int_t fEntriesCurrent; // Entries in the current histo
64942b85 239 Int_t fCountDet; // Current detector (or first in the group)
413153cb 240 Int_t fCount; // When the next detector comes
64942b85 241 Int_t fNbDet; // Number of detector in the group
413153cb 242
243 // Current calib object
244 AliTRDCalDet *fCalDet; // Current calib object
245 AliTRDCalROC *fCalROC; // Current calib object
246 AliTRDCalDet *fCalDet2; // Current calib object
247 AliTRDCalROC *fCalROC2; // Current calib object
248
249 // Current values detector
250
251 Float_t *fCurrentCoefDetector; // Current values for the detector
252 Float_t *fCurrentCoefDetector2; // Current values for the detector
253
413153cb 254 TObjArray fVectorFit; // Vectors to fit
255 TObjArray fVectorFit2; // Vectors to fit
256
257 //
258 // A lot of internal functions......
259 //
260
261 // Init AliTRDCalibraFit
262 Bool_t InitFit(Int_t nbins, Int_t i);
263 Bool_t InitFitCH();
264 Bool_t InitFitPH();
265 Bool_t InitFitPRF();
266 Bool_t InitFitLinearFitter();
267
268 // Not enough Statistics
269 Bool_t NotEnoughStatisticCH(Int_t idect);
64942b85 270 Bool_t NotEnoughStatisticPH(Int_t idect,Double_t nentries);
413153cb 271 Bool_t NotEnoughStatisticPRF(Int_t idect);
272 Bool_t NotEnoughStatisticLinearFitter();
273
274 // Fill Infos Fit
275 Bool_t FillInfosFitCH(Int_t idect);
64942b85 276 Bool_t FillInfosFitPH(Int_t idect,Double_t nentries);
413153cb 277 Bool_t FillInfosFitPRF(Int_t idect);
278 Bool_t FillInfosFitLinearFitter();
279
280 void FillFillCH(Int_t idect);
64942b85 281 void FillFillPH(Int_t idect,Double_t nentries);
413153cb 282 void FillFillPRF(Int_t idect);
283 void FillFillLinearFitter();
284
285 Bool_t FillVectorFit();
286 Bool_t FillVectorFit2();
287
288 // Functions...
289 void InitfCountDetAndfCount(Int_t i);
290 void CalculNumberOfBinsExpected(Int_t i);
291 void CalculDect1Dect2(Int_t i);
292 void UpdatefCountDetAndfCount(Int_t idect, Int_t i);
293 void ReconstructFitRowMinRowMax(Int_t idect, Int_t i);
294 Bool_t CheckFitVoir();
295 void NormierungCharge();
296 Bool_t SetNrphiFromTObject(const char *name, Int_t i);
297 Bool_t SetNzFromTObject(const char *name, Int_t i);
298 Int_t GetNumberOfGroupsPRF(const char* nametitle);
299
300 // Calculate the mean coefs from the database
301 Bool_t CalculVdriftCoefMean();
302 Bool_t CalculChargeCoefMean(Bool_t vrai);
303 Bool_t CalculPRFCoefMean();
304 Bool_t CalculT0CoefMean();
305 Bool_t CalculVdriftLorentzCoef();
053767a4 306 Float_t GetPRFDefault(Int_t layer) const;
413153cb 307 void SetCalROC(Int_t i);
308
309 // Fit methods
310 void FitBisCH(TH1 *projch, Double_t mean);
311 void FitCH(TH1 *projch, Double_t mean);
312 void FitMeanW(TH1 *projch, Double_t nentries);
313 void FitMeanWSm(TH1 *projch, Float_t sumAll);
314 void FitMean(TH1 *projch, Double_t nentries, Double_t mean);
315 void FitPH(TH1 *projPH, Int_t idect);
316 void FitPRF(TH1 *projPRF);
317 void RmsPRF(TH1 *projPRF);
318 Bool_t FitPRFGausMI(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nBins,Float_t xMin,Float_t xMax);
319 Double_t FitGausMI(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nBins, Float_t xMin,Float_t xMax,TVectorD *param, Bool_t kError= kTRUE);
320 void FitPente(TH1 *projPH);
413153cb 321 void FitTnpRange(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nbg,Int_t nybins);
979b168f 322 TH1I *ReBin(const TH1I *hist) const;
323 TH1F *ReBin(const TH1F *hist) const;
413153cb 324
325 // Some basic geometry function
053767a4 326 virtual Int_t GetLayer(Int_t d) const;
327 virtual Int_t GetStack(Int_t d) const;
413153cb 328 virtual Int_t GetSector(Int_t d) const;
329
330 // Instance of this class and so on
331 static AliTRDCalibraFit *fgInstance; // Instance
332 static Bool_t fgTerminated; // If terminated
333
334
335 private:
336
979b168f 337 static Double_t PH(const Double_t *x, const Double_t *par);
338 static Double_t AsymmGauss(const Double_t *x, const Double_t *par);
339 static Double_t FuncLandauGaus(const Double_t *x, const Double_t *par);
340 static Double_t LanGauFun(const Double_t *x, const Double_t *par);
341 TF1 *LanGauFit(TH1 *his, const Double_t *fitrange, const Double_t *startvalues
342 , const Double_t *parlimitslo, const Double_t *parlimitshi, Double_t *fitparams
413153cb 343 , Double_t *fiterrors, Double_t *chiSqr, Int_t *ndf) const;
979b168f 344 Int_t LanGauPro(const Double_t *params, Double_t &maxx, Double_t &fwhm);
345 static Double_t GausConstant(const Double_t *x, const Double_t *par);
413153cb 346
347 // This is a singleton, contructor is private!
348 AliTRDCalibraFit();
349 virtual ~AliTRDCalibraFit();
350
351
f162af62 352 ClassDef(AliTRDCalibraFit,2) // TRD Calibration class
413153cb 353
55a288e5 354};
355
356#endif