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