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) const;
77 Double_t *CalculPolynomeLagrange3(Double_t *x, Double_t *y) const;
78 Double_t *CalculPolynomeLagrange4(Double_t *x, Double_t *y) const;
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() const { return fVectorFit; }
143 TObjArray GetVectorFit2() const { return fVectorFit2; }
146 AliTRDCalibraMode *GetCalibraMode() { return fCalibraMode; }
151 AliTRDgeometry *fGeo; //! The TRD geometry
154 Int_t fNumberOfBinsExpected; // Number of bins expected
157 Short_t fMethod; // Method
158 Float_t fBeginFitCharge; // The fit begins at mean/fBeginFitCharge for the gain calibration
159 Int_t fFitPHPeriode; // Periode of the fit PH
160 Bool_t fTakeTheMaxPH; // Take the Max for the T0 determination
161 Float_t fT0Shift; // T0 Shift with the actual method
162 Float_t fRangeFitPRF; // The fit range for the PRF is -fRangeFitPRF +fRangeFitPRF
163 Bool_t fAccCDB; // If there is a calibration database to be compared with....
164 Int_t fMinEntries; // Min Entries to fit the histo
165 Short_t fRebin; // If you want to rebin the histo for the gain calibration
168 Int_t fNumberFit; // To know how many pad groups have been fitted
169 Int_t fNumberFitSuccess; // To know how many pad groups have been fitted successfully
170 Int_t fNumberEnt; // To know how many pad groups have entries in the histo
171 Double_t fStatisticMean; // To know the mean statistic of the histos
175 TTreeSRedirector *fDebugStreamer; //!Debug streamer
176 Short_t fDebugLevel; // Flag for debugging
177 Int_t fDet[3]; // Detector visualised (plane,chamb,sect) si debugging == 3 or 4
178 Int_t fFitVoir; // Fit visualised si debugging == 2
180 // Magnetic field lorentz angle
181 Float_t fMagneticField; // Magnetic field lorentz angle
185 AliTRDCalibraMode *fCalibraMode; // The calibration mode
187 // Current values of the coefficients found and ect...
188 Float_t fCurrentCoef[2]; // Current coefs
189 Float_t fCurrentCoefE; // Current coefs error
190 Float_t fCurrentCoef2[2]; // Current coefs
191 Float_t fCurrentCoefE2; // Current coefs error
192 Float_t fPhd[3]; // Begin AR and DR
193 Int_t fDect1; // First calibration group that will be called to be maybe fitted
194 Int_t fDect2; // Last calibration group that will be called to be maybe fitted
195 Double_t fScaleFitFactor; // Scale factor of the fit results for the gain
196 Int_t fEntriesCurrent; // Entries in the current histo
197 Int_t fCountDet; // Current detector
198 Int_t fCount; // When the next detector comes
200 // Current calib object
201 AliTRDCalDet *fCalDet; // Current calib object
202 AliTRDCalROC *fCalROC; // Current calib object
203 AliTRDCalDet *fCalDet2; // Current calib object
204 AliTRDCalROC *fCalROC2; // Current calib object
206 // Current values detector
208 Float_t *fCurrentCoefDetector; // Current values for the detector
209 Float_t *fCurrentCoefDetector2; // Current values for the detector
211 class AliTRDFitInfo : public TObject {
219 AliTRDFitInfo(const AliTRDFitInfo &i)
223 AliTRDFitInfo &operator=(const AliTRDFitInfo&) { return *this; }
224 virtual ~AliTRDFitInfo() { }
226 void SetCoef(Float_t *coef) { fCoef = coef; }
227 void SetDetector(Int_t detector) { fDetector = detector; }
229 Float_t *GetCoef() const { return fCoef; }
230 Int_t GetDetector() const { return fDetector; }
234 Float_t *fCoef; // Relative coefficient for each group of the detector
235 Int_t fDetector; // Detector number
239 TObjArray fVectorFit; // Vectors to fit
240 TObjArray fVectorFit2; // Vectors to fit
243 // A lot of internal functions......
246 // Init AliTRDCalibraFit
247 Bool_t InitFit(Int_t nbins, Int_t i);
251 Bool_t InitFitLinearFitter();
253 // Not enough Statistics
254 Bool_t NotEnoughStatisticCH(Int_t idect);
255 Bool_t NotEnoughStatisticPH(Int_t idect);
256 Bool_t NotEnoughStatisticPRF(Int_t idect);
257 Bool_t NotEnoughStatisticLinearFitter();
260 Bool_t FillInfosFitCH(Int_t idect);
261 Bool_t FillInfosFitPH(Int_t idect);
262 Bool_t FillInfosFitPRF(Int_t idect);
263 Bool_t FillInfosFitLinearFitter();
265 void FillFillCH(Int_t idect);
266 void FillFillPH(Int_t idect);
267 void FillFillPRF(Int_t idect);
268 void FillFillLinearFitter();
270 Bool_t FillVectorFit();
271 Bool_t FillVectorFit2();
274 void InitfCountDetAndfCount(Int_t i);
275 void CalculNumberOfBinsExpected(Int_t i);
276 void CalculDect1Dect2(Int_t i);
277 void UpdatefCountDetAndfCount(Int_t idect, Int_t i);
278 void ReconstructFitRowMinRowMax(Int_t idect, Int_t i);
279 Bool_t CheckFitVoir();
280 void NormierungCharge();
281 Bool_t SetNrphiFromTObject(const char *name, Int_t i);
282 Bool_t SetNzFromTObject(const char *name, Int_t i);
283 Int_t GetNumberOfGroupsPRF(const char* nametitle);
285 // Calculate the mean coefs from the database
286 Bool_t CalculVdriftCoefMean();
287 Bool_t CalculChargeCoefMean(Bool_t vrai);
288 Bool_t CalculPRFCoefMean();
289 Bool_t CalculT0CoefMean();
290 Bool_t CalculVdriftLorentzCoef();
291 Float_t GetPRFDefault(Int_t plane) const;
292 void SetCalROC(Int_t i);
295 void FitBisCH(TH1 *projch, Double_t mean);
296 void FitCH(TH1 *projch, Double_t mean);
297 void FitMeanW(TH1 *projch, Double_t nentries);
298 void FitMeanWSm(TH1 *projch, Float_t sumAll);
299 void FitMean(TH1 *projch, Double_t nentries, Double_t mean);
300 void FitPH(TH1 *projPH, Int_t idect);
301 void FitPRF(TH1 *projPRF);
302 void RmsPRF(TH1 *projPRF);
303 Bool_t FitPRFGausMI(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nBins,Float_t xMin,Float_t xMax);
304 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);
305 void FitPente(TH1 *projPH);
306 void FitLagrangePoly(TH1* projPH);
307 void FitTnpRange(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nbg,Int_t nybins);
308 TH1I *ReBin(TH1I *hist) const;
309 TH1F *ReBin(TH1F *hist) const;
311 // Some basic geometry function
312 virtual Int_t GetPlane(Int_t d) const;
313 virtual Int_t GetChamber(Int_t d) const;
314 virtual Int_t GetSector(Int_t d) const;
316 // Instance of this class and so on
317 static AliTRDCalibraFit *fgInstance; // Instance
318 static Bool_t fgTerminated; // If terminated
323 static Double_t PH(Double_t *x, Double_t *par);
324 static Double_t AsymmGauss(Double_t *x, Double_t *par);
325 static Double_t FuncLandauGaus(Double_t *x, Double_t *par);
326 static Double_t LanGauFun(Double_t *x, Double_t *par);
327 TF1 *LanGauFit(TH1 *his, Double_t *fitrange, Double_t *startvalues
328 , Double_t *parlimitslo, Double_t *parlimitshi, Double_t *fitparams
329 , Double_t *fiterrors, Double_t *chiSqr, Int_t *ndf) const;
330 Int_t LanGauPro(Double_t *params, Double_t &maxx, Double_t &fwhm);
331 static Double_t GausConstant(Double_t *x, Double_t *par);
333 // This is a singleton, contructor is private!
335 virtual ~AliTRDCalibraFit();
340 ClassDef(AliTRDCalibraFit,2) // TRD Calibration class