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