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