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