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