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