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