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 */
8 ///////////////////////////////////////////////////////////////////////////////
10 // TRD calibration class for the HLT parameters //
12 ///////////////////////////////////////////////////////////////////////////////
28 class TTreeSRedirector;
32 class AliTRDCalibraMode;
33 class AliTRDCalibraVector;
34 class AliTRDCalibraVdriftLinearFit;
39 class AliTRDCalibraFit : public TObject {
44 static AliTRDCalibraFit *Instance();
45 static void Terminate();
46 static void Destroy();
48 AliTRDCalibraFit(const AliTRDCalibraFit &c);
49 AliTRDCalibraFit &operator=(const AliTRDCalibraFit &) { return *this; }
51 // Functions fit for CH
52 Bool_t AnalyseCH(TH2I *ch);
53 Bool_t AnalyseCH(AliTRDCalibraVector *calvect);
55 // Functions fit for PH
56 Bool_t AnalysePH(TProfile2D *ph);
57 Bool_t AnalysePH(AliTRDCalibraVector *calvect);
59 // Functions fit for PRF
60 Bool_t AnalysePRF(TProfile2D *prf);
61 Bool_t AnalysePRF(AliTRDCalibraVector *calvect);
63 Bool_t AnalysePRFMarianFit(TProfile2D *prf);
64 Bool_t AnalysePRFMarianFit(AliTRDCalibraVector *calvect);
66 // Functions fit for vdrift/lorentzangle
67 Bool_t AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli);
70 Bool_t SetModeCalibration(const char *name, Int_t i);
73 void ResetVectorFit();
76 Double_t *CalculPolynomeLagrange2(Double_t *x, Double_t *y);
77 Double_t *CalculPolynomeLagrange3(Double_t *x, Double_t *y);
78 Double_t *CalculPolynomeLagrange4(Double_t *x, Double_t *y);
81 AliTRDCalDet *CreateDetObjectVdrift(TObjArray *vectorFit, Bool_t perdetector = kFALSE);
82 AliTRDCalDet *CreateDetObjectGain(TObjArray *vectorFit, Double_t scaleFitFactor, Bool_t perdetector = kFALSE);
83 AliTRDCalDet *CreateDetObjectT0(TObjArray *vectorFit, Bool_t perdetector = kFALSE);
84 AliTRDCalDet *CreateDetObjectLorentzAngle(TObjArray *vectorFit);
86 TObject *CreatePadObjectGain(TObjArray *vectorFit = 0, Double_t scaleFitFactor = 1.0, AliTRDCalDet *detobject = 0);
87 TObject *CreatePadObjectVdrift(TObjArray *vectorFit = 0, AliTRDCalDet *detobject = 0);
88 TObject *CreatePadObjectT0(TObjArray *vectorFit = 0, AliTRDCalDet *detobject = 0);
89 TObject *CreatePadObjectPRF(TObjArray *vectorFit);
92 AliTRDCalDet *MakeOutliersStatDet(TObjArray *vectorFit, const char *name, Double_t &mean);
93 TObject *MakeOutliersStatPad(TObjArray *vectorFit, const char *name, Double_t &mean);
97 TH1F *CorrectTheError(TGraphErrors *hist);
100 // Set or Get the variables
104 void ChooseMethod(Short_t method) { fMethod = method; }
105 void SetBeginFitCharge(Float_t beginFitCharge);
106 void SetPeriodeFitPH(Int_t periodeFitPH);
107 void SetTakeTheMaxPH() { fTakeTheMaxPH = kTRUE; }
108 void SetT0Shift(Float_t t0Shift);
109 void SetRangeFitPRF(Float_t rangeFitPRF);
110 void SetAccCDB() { fAccCDB = kTRUE; }
111 void SetMinEntries(Int_t minEntries);
112 void SetRebin(Short_t rebin);
114 Int_t GetPeriodeFitPH() const { return fFitPHPeriode; }
115 Bool_t GetTakeTheMaxPH() const { return fTakeTheMaxPH; }
116 Float_t GetT0Shift() const { return fT0Shift; }
117 Float_t GetRangeFitPRF() const { return fRangeFitPRF; }
118 Bool_t GetAccCDB() const { return fAccCDB; }
119 Int_t GetMinEntries() const { return fMinEntries; }
120 Short_t GetRebin() const { return fRebin; }
123 Int_t GetNumberFit() const { return fNumberFit; }
124 Int_t GetNumberFitSuccess() const { return fNumberFitSuccess; }
125 Int_t GetNumberEnt() const { return fNumberEnt; }
126 Double_t GetStatisticMean() const { return fStatisticMean; }
130 void SetDebugLevel(Short_t level) { fDebugLevel = level; }
131 void SetDet(Int_t iPlane, Int_t iChamb, Int_t iSect) { fDet[0] = iPlane;
134 void SetFitVoir(Int_t fitVoir) { fFitVoir = fitVoir; }
136 void SetMagneticField(Float_t magneticfield) { fMagneticField = magneticfield; }
138 // Get the scale factor
139 Double_t GetScaleFitFactor() const { return fScaleFitFactor; }
142 TObjArray GetVectorFit() { return fVectorFit; }
143 TObjArray GetVectorFit2() { return fVectorFit2; }
146 AliTRDCalibraMode *GetCalibraMode() { return fCalibraMode; }
150 static Double_t PH(Double_t *x, Double_t *par);
151 static Double_t AsymmGauss(Double_t *x, Double_t *par);
152 static Double_t FuncLandauGaus(Double_t *x, Double_t *par);
153 static Double_t LanGauFun(Double_t *x, Double_t *par);
154 TF1 *LanGauFit(TH1 *his, Double_t *fitrange, Double_t *startvalues
155 , Double_t *parlimitslo, Double_t *parlimitshi, Double_t *fitparams
156 , Double_t *fiterrors, Double_t *chiSqr, Int_t *ndf);
157 Int_t LanGauPro(Double_t *params, Double_t &maxx, Double_t &fwhm);
158 static Double_t GausConstant(Double_t *x, Double_t *par);
160 // This is a singleton, contructor is private!
162 virtual ~AliTRDCalibraFit();
167 AliTRDgeometry *fGeo; //! The TRD geometry
170 Int_t fNumberOfBinsExpected; // Number of bins expected
173 Short_t fMethod; // Method
174 Float_t fBeginFitCharge; // The fit begins at mean/fBeginFitCharge for the gain calibration
175 Int_t fFitPHPeriode; // Periode of the fit PH
176 Bool_t fTakeTheMaxPH; // Take the Max for the T0 determination
177 Float_t fT0Shift; // T0 Shift with the actual method
178 Float_t fRangeFitPRF; // The fit range for the PRF is -fRangeFitPRF +fRangeFitPRF
179 Bool_t fAccCDB; // If there is a calibration database to be compared with....
180 Int_t fMinEntries; // Min Entries to fit the histo
181 Short_t fRebin; // If you want to rebin the histo for the gain calibration
184 Int_t fNumberFit; // To know how many pad groups have been fitted
185 Int_t fNumberFitSuccess; // To know how many pad groups have been fitted successfully
186 Int_t fNumberEnt; // To know how many pad groups have entries in the histo
187 Double_t fStatisticMean; // To know the mean statistic of the histos
191 TTreeSRedirector *fDebugStreamer; //!Debug streamer
192 Short_t fDebugLevel; // Flag for debugging
193 Int_t fDet[3]; // Detector visualised (plane,chamb,sect) si debugging == 3 or 4
194 Int_t fFitVoir; // Fit visualised si debugging == 2
196 // Magnetic field lorentz angle
197 Float_t fMagneticField; // Magnetic field lorentz angle
201 AliTRDCalibraMode *fCalibraMode; // The calibration mode
203 // Current values of the coefficients found and ect...
204 Float_t fCurrentCoef[2]; // Current coefs
205 Float_t fCurrentCoefE; // Current coefs error
206 Float_t fCurrentCoef2[2]; // Current coefs
207 Float_t fCurrentCoefE2; // Current coefs error
208 Float_t fPhd[3]; // Begin AR and DR
209 Int_t fDect1; // First calibration group that will be called to be maybe fitted
210 Int_t fDect2; // Last calibration group that will be called to be maybe fitted
211 Double_t fScaleFitFactor; // Scale factor of the fit results for the gain
212 Int_t fEntriesCurrent; // Entries in the current histo
213 Int_t fCountDet; // Current detector
214 Int_t fCount; // When the next detector comes
216 // Current calib object
217 AliTRDCalDet *fCalDet; // Current calib object
218 AliTRDCalROC *fCalROC; // Current calib object
219 AliTRDCalDet *fCalDet2; // Current calib object
220 AliTRDCalROC *fCalROC2; // Current calib object
222 // Current values detector
224 Float_t *fCurrentCoefDetector; // Current values for the detector
225 Float_t *fCurrentCoefDetector2; // Current values for the detector
227 class AliTRDFitInfo : public TObject {
235 AliTRDFitInfo(const AliTRDFitInfo &i)
239 AliTRDFitInfo &operator=(const AliTRDFitInfo&) { return *this; }
240 virtual ~AliTRDFitInfo() { }
242 void SetCoef(Float_t *coef) { fCoef = coef; }
243 void SetDetector(Int_t detector) { fDetector = detector; }
245 Float_t *GetCoef() const { return fCoef; }
246 Int_t GetDetector() const { return fDetector; }
250 Float_t *fCoef; // Relative coefficient for each group of the detector
251 Int_t fDetector; // Detector number
255 TObjArray fVectorFit; // Vectors to fit
256 TObjArray fVectorFit2; // Vectors to fit
259 // A lot of internal functions......
262 // Init AliTRDCalibraFit
263 Bool_t InitFit(Int_t nbins, Int_t i);
267 Bool_t InitFitLinearFitter();
269 // Not enough Statistics
270 Bool_t NotEnoughStatisticCH(Int_t idect);
271 Bool_t NotEnoughStatisticPH(Int_t idect);
272 Bool_t NotEnoughStatisticPRF(Int_t idect);
273 Bool_t NotEnoughStatisticLinearFitter();
276 Bool_t FillInfosFitCH(Int_t idect);
277 Bool_t FillInfosFitPH(Int_t idect);
278 Bool_t FillInfosFitPRF(Int_t idect);
279 Bool_t FillInfosFitLinearFitter();
281 void FillFillCH(Int_t idect);
282 void FillFillPH(Int_t idect);
283 void FillFillPRF(Int_t idect);
284 void FillFillLinearFitter();
286 Bool_t FillVectorFit();
287 Bool_t FillVectorFit2();
290 void InitfCountDetAndfCount(Int_t i);
291 void CalculNumberOfBinsExpected(Int_t i);
292 void CalculDect1Dect2(Int_t i);
293 void UpdatefCountDetAndfCount(Int_t idect, Int_t i);
294 void ReconstructFitRowMinRowMax(Int_t idect, Int_t i);
295 Bool_t CheckFitVoir();
296 void NormierungCharge();
297 Bool_t SetNrphiFromTObject(const char *name, Int_t i);
298 Bool_t SetNzFromTObject(const char *name, Int_t i);
299 Int_t GetNumberOfGroupsPRF(const char* nametitle);
301 // Calculate the mean coefs from the database
302 Bool_t CalculVdriftCoefMean();
303 Bool_t CalculChargeCoefMean(Bool_t vrai);
304 Bool_t CalculPRFCoefMean();
305 Bool_t CalculT0CoefMean();
306 Bool_t CalculVdriftLorentzCoef();
307 Float_t GetPRFDefault(Int_t plane) const;
308 void SetCalROC(Int_t i);
311 void FitBisCH(TH1 *projch, Double_t mean);
312 void FitCH(TH1 *projch, Double_t mean);
313 void FitMeanW(TH1 *projch, Double_t nentries);
314 void FitMeanWSm(TH1 *projch, Float_t sumAll);
315 void FitMean(TH1 *projch, Double_t nentries, Double_t mean);
316 void FitPH(TH1 *projPH, Int_t idect);
317 void FitPRF(TH1 *projPRF);
318 void RmsPRF(TH1 *projPRF);
319 Bool_t FitPRFGausMI(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nBins,Float_t xMin,Float_t xMax);
320 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);
321 void FitPente(TH1 *projPH);
322 void FitLagrangePoly(TH1* projPH);
323 void FitTnpRange(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nbg,Int_t nybins);
324 TH1I *ReBin(TH1I *hist) const;
325 TH1F *ReBin(TH1F *hist) const;
327 // Some basic geometry function
328 virtual Int_t GetPlane(Int_t d) const;
329 virtual Int_t GetChamber(Int_t d) const;
330 virtual Int_t GetSector(Int_t d) const;
332 // Instance of this class and so on
333 static AliTRDCalibraFit *fgInstance; // Instance
334 static Bool_t fgTerminated; // If terminated
337 ClassDef(AliTRDCalibraFit,2) // TRD Calibration class