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 ///////////////////////////////////////////////////////////////////////////////
29 class TTreeSRedirector;
33 class AliTRDCalibraMode;
34 class AliTRDCalibraVector;
35 class AliTRDCalibraVdriftLinearFit;
40 class AliTRDCalibraFit : public TObject {
45 static AliTRDCalibraFit *Instance();
46 static void Terminate();
47 static void Destroy();
48 void DestroyDebugStreamer();
50 AliTRDCalibraFit(const AliTRDCalibraFit &c);
51 AliTRDCalibraFit &operator=(const AliTRDCalibraFit &) { return *this; }
53 // Function for integration range of the charge
54 void RangeChargeIntegration(Float_t vdrift, Float_t t0, Int_t &begin, Int_t &peak, Int_t &end) const;
56 // Functions fit for CH
57 Bool_t AnalyseCH(const TH2I *ch);
58 Bool_t AnalyseCH(AliTRDCalibraVector *calvect);
60 // Functions fit for PH
61 Bool_t AnalysePH(const TProfile2D *ph);
62 Bool_t AnalysePH(AliTRDCalibraVector *calvect);
64 // Functions fit for PRF
65 Bool_t AnalysePRF(const TProfile2D *prf);
66 Bool_t AnalysePRF(AliTRDCalibraVector *calvect);
68 Bool_t AnalysePRFMarianFit(const TProfile2D *prf);
69 Bool_t AnalysePRFMarianFit(AliTRDCalibraVector *calvect);
71 // Functions fit for vdrift/lorentzangle
72 Bool_t AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli);
75 Bool_t SetModeCalibration(const char *name, Int_t i);
78 void ResetVectorFit();
81 Double_t *CalculPolynomeLagrange2(const Double_t *x, const Double_t *y) const;
82 Double_t *CalculPolynomeLagrange3(const Double_t *x, const Double_t *y) const;
83 Double_t *CalculPolynomeLagrange4(const Double_t *x, const Double_t *y) const;
86 void PutMeanValueOtherVectorFit(Int_t ofwhat = 1, Bool_t perdetector = kFALSE);
87 void PutMeanValueOtherVectorFit2(Int_t ofwhat = 1, Bool_t perdetector = kFALSE);
88 AliTRDCalDet *CreateDetObjectVdrift(const TObjArray *vectorFit, Bool_t perdetector = kFALSE);
89 AliTRDCalDet *CreateDetObjectGain(const TObjArray *vectorFit, Bool_t meanOtherBefore=kTRUE, Double_t scaleFitFactor = 0.02431, Bool_t perdetector = kTRUE);
90 AliTRDCalDet *CreateDetObjectT0(const TObjArray *vectorFit, Bool_t perdetector = kFALSE);
91 AliTRDCalDet *CreateDetObjectLorentzAngle(const TObjArray *vectorFit);
93 TObject *CreatePadObjectGain(const TObjArray *vectorFit = 0, Double_t scaleFitFactor = 1.0, const AliTRDCalDet *detobject = 0);
94 TObject *CreatePadObjectVdrift(const TObjArray *vectorFit = 0, const AliTRDCalDet *detobject = 0);
95 TObject *CreatePadObjectT0(const TObjArray *vectorFit = 0, const AliTRDCalDet *detobject = 0);
96 TObject *CreatePadObjectPRF(const TObjArray *vectorFit);
99 AliTRDCalDet *MakeOutliersStatDet(const TObjArray *vectorFit, const char *name, Double_t &mean);
100 TObject *MakeOutliersStatPad(const TObjArray *vectorFit, const char *name, Double_t &mean);
103 // Set or Get the variables
107 void ChooseMethod(Short_t method) { fMethod = method; }
108 void SetBeginFitCharge(Float_t beginFitCharge);
109 void SetPeriodeFitPH(Int_t periodeFitPH);
110 void SetTakeTheMaxPH() { fTakeTheMaxPH = kTRUE; }
111 void SetT0Shift0(Float_t t0Shift0);
112 void SetT0Shift1(Float_t t0Shift1);
113 void SetRangeFitPRF(Float_t rangeFitPRF);
114 void SetAccCDB() { fAccCDB = kTRUE; }
115 void SetMinEntries(Int_t minEntries);
116 void SetRebin(Short_t rebin);
118 Int_t GetPeriodeFitPH() const { return fFitPHPeriode; }
119 Bool_t GetTakeTheMaxPH() const { return fTakeTheMaxPH; }
120 Float_t GetT0Shift0() const { return fT0Shift0; }
121 Float_t GetT0Shift1() const { return fT0Shift1; }
122 Float_t GetRangeFitPRF() const { return fRangeFitPRF; }
123 Bool_t GetAccCDB() const { return fAccCDB; }
124 Int_t GetMinEntries() const { return fMinEntries; }
125 Short_t GetRebin() const { return fRebin; }
128 Int_t GetNumberFit() const { return fNumberFit; }
129 Int_t GetNumberFitSuccess() const { return fNumberFitSuccess; }
130 Int_t GetNumberEnt() const { return fNumberEnt; }
131 Double_t GetStatisticMean() const { return fStatisticMean; }
135 void SetDebugLevel(Short_t level) { fDebugLevel = level; }
136 void SetDet(Int_t iLayer, Int_t iStack, Int_t iSector) { fDet[0] = iLayer;
139 void SetFitVoir(Int_t fitVoir) { fFitVoir = fitVoir; }
141 void SetMagneticField(Float_t magneticfield) { fMagneticField = magneticfield; }
143 // Get the scale factor
144 Double_t GetScaleFitFactor() const { return fScaleFitFactor; }
147 TObjArray GetVectorFit() const { return fVectorFit; }
148 TObjArray GetVectorFit2() const { return fVectorFit2; }
151 AliTRDCalibraMode *GetCalibraMode() const { return fCalibraMode; }
153 class AliTRDFitInfo : public TObject {
161 AliTRDFitInfo(const AliTRDFitInfo &i)
165 AliTRDFitInfo &operator=(const AliTRDFitInfo&) { return *this; }
166 virtual ~AliTRDFitInfo() { if(fCoef) { delete [] fCoef;} }
168 void SetCoef(Float_t *coef) { fCoef = coef; }
169 void SetDetector(Int_t detector) { fDetector = detector; }
171 Float_t *GetCoef() const { return fCoef; }
172 Int_t GetDetector() const { return fDetector; }
176 Float_t *fCoef; // Relative coefficient for each group of the detector
177 Int_t fDetector; // Detector number
185 AliTRDgeometry *fGeo; //! The TRD geometry
188 Int_t fNumberOfBinsExpected; // Number of bins expected
191 Short_t fMethod; // Method
192 Float_t fBeginFitCharge; // The fit begins at mean/fBeginFitCharge for the gain calibration
193 Int_t fFitPHPeriode; // Periode of the fit PH
194 Bool_t fTakeTheMaxPH; // Take the Max for the T0 determination
195 Float_t fT0Shift0; // T0 Shift with the maximum positive slope
196 Float_t fT0Shift1; // T0 Shift with the maximum of the amplification region
197 Float_t fRangeFitPRF; // The fit range for the PRF is -fRangeFitPRF +fRangeFitPRF
198 Bool_t fAccCDB; // If there is a calibration database to be compared with....
199 Int_t fMinEntries; // Min Entries to fit the histo
200 Short_t fRebin; // If you want to rebin the histo for the gain calibration
203 Int_t fNumberFit; // To know how many pad groups have been fitted
204 Int_t fNumberFitSuccess; // To know how many pad groups have been fitted successfully
205 Int_t fNumberEnt; // To know how many pad groups have entries in the histo
206 Double_t fStatisticMean; // To know the mean statistic of the histos
210 TTreeSRedirector *fDebugStreamer; //!Debug streamer
211 Short_t fDebugLevel; // Flag for debugging
212 Int_t fDet[3]; // Detector visualised (layer,stack,sector) si debugging == 3 or 4
213 Int_t fFitVoir; // Fit visualised si debugging == 2
215 // Magnetic field lorentz angle
216 Float_t fMagneticField; // Magnetic field lorentz angle
220 AliTRDCalibraMode *fCalibraMode; // The calibration mode
222 // Current values of the coefficients found and ect...
223 Float_t fCurrentCoef[2]; // Current coefs
224 Float_t fCurrentCoefE; // Current coefs error
225 Float_t fCurrentCoef2[2]; // Current coefs
226 Float_t fCurrentCoefE2; // Current coefs error
227 Float_t fPhd[3]; // Begin AR and DR
228 Int_t fDect1; // First calibration group that will be called to be maybe fitted
229 Int_t fDect2; // Last calibration group that will be called to be maybe fitted
230 Double_t fScaleFitFactor; // Scale factor of the fit results for the gain
231 Int_t fEntriesCurrent; // Entries in the current histo
232 Int_t fCountDet; // Current detector (or first in the group)
233 Int_t fCount; // When the next detector comes
234 Int_t fNbDet; // Number of detector in the group
236 // Current calib object
237 AliTRDCalDet *fCalDet; // Current calib object
238 AliTRDCalROC *fCalROC; // Current calib object
239 AliTRDCalDet *fCalDet2; // Current calib object
240 AliTRDCalROC *fCalROC2; // Current calib object
242 // Current values detector
244 Float_t *fCurrentCoefDetector; // Current values for the detector
245 Float_t *fCurrentCoefDetector2; // Current values for the detector
247 TObjArray fVectorFit; // Vectors to fit
248 TObjArray fVectorFit2; // Vectors to fit
251 // A lot of internal functions......
254 // Init AliTRDCalibraFit
255 Bool_t InitFit(Int_t nbins, Int_t i);
259 Bool_t InitFitLinearFitter();
261 // Not enough Statistics
262 Bool_t NotEnoughStatisticCH(Int_t idect);
263 Bool_t NotEnoughStatisticPH(Int_t idect,Double_t nentries);
264 Bool_t NotEnoughStatisticPRF(Int_t idect);
265 Bool_t NotEnoughStatisticLinearFitter();
268 Bool_t FillInfosFitCH(Int_t idect);
269 Bool_t FillInfosFitPH(Int_t idect,Double_t nentries);
270 Bool_t FillInfosFitPRF(Int_t idect);
271 Bool_t FillInfosFitLinearFitter();
273 void FillFillCH(Int_t idect);
274 void FillFillPH(Int_t idect,Double_t nentries);
275 void FillFillPRF(Int_t idect);
276 void FillFillLinearFitter();
278 Bool_t FillVectorFit();
279 Bool_t FillVectorFit2();
282 void InitfCountDetAndfCount(Int_t i);
283 void CalculNumberOfBinsExpected(Int_t i);
284 void CalculDect1Dect2(Int_t i);
285 void UpdatefCountDetAndfCount(Int_t idect, Int_t i);
286 void ReconstructFitRowMinRowMax(Int_t idect, Int_t i);
287 Bool_t CheckFitVoir();
288 void NormierungCharge();
289 Bool_t SetNrphiFromTObject(const char *name, Int_t i);
290 Bool_t SetNzFromTObject(const char *name, Int_t i);
291 Int_t GetNumberOfGroupsPRF(const char* nametitle);
293 // Calculate the mean coefs from the database
294 Bool_t CalculVdriftCoefMean();
295 Bool_t CalculChargeCoefMean(Bool_t vrai);
296 Bool_t CalculPRFCoefMean();
297 Bool_t CalculT0CoefMean();
298 Bool_t CalculVdriftLorentzCoef();
299 Float_t GetPRFDefault(Int_t layer) const;
300 void SetCalROC(Int_t i);
303 void FitBisCH(TH1 *projch, Double_t mean);
304 void FitCH(TH1 *projch, Double_t mean);
305 void FitMeanW(TH1 *projch, Double_t nentries);
306 void FitMeanWSm(TH1 *projch, Float_t sumAll);
307 void FitMean(TH1 *projch, Double_t nentries, Double_t mean);
308 void FitPH(TH1 *projPH, Int_t idect);
309 void FitPRF(TH1 *projPRF);
310 void RmsPRF(TH1 *projPRF);
311 Bool_t FitPRFGausMI(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nBins,Float_t xMin,Float_t xMax);
312 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);
313 void FitPente(TH1 *projPH);
314 void FitLagrangePoly(TH1* projPH);
315 void FitTnpRange(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nbg,Int_t nybins);
316 TH1I *ReBin(const TH1I *hist) const;
317 TH1F *ReBin(const TH1F *hist) const;
319 // Some basic geometry function
320 virtual Int_t GetLayer(Int_t d) const;
321 virtual Int_t GetStack(Int_t d) const;
322 virtual Int_t GetSector(Int_t d) const;
324 // Instance of this class and so on
325 static AliTRDCalibraFit *fgInstance; // Instance
326 static Bool_t fgTerminated; // If terminated
331 static Double_t PH(const Double_t *x, const Double_t *par);
332 static Double_t AsymmGauss(const Double_t *x, const Double_t *par);
333 static Double_t FuncLandauGaus(const Double_t *x, const Double_t *par);
334 static Double_t LanGauFun(const Double_t *x, const Double_t *par);
335 TF1 *LanGauFit(TH1 *his, const Double_t *fitrange, const Double_t *startvalues
336 , const Double_t *parlimitslo, const Double_t *parlimitshi, Double_t *fitparams
337 , Double_t *fiterrors, Double_t *chiSqr, Int_t *ndf) const;
338 Int_t LanGauPro(const Double_t *params, Double_t &maxx, Double_t &fwhm);
339 static Double_t GausConstant(const Double_t *x, const Double_t *par);
341 // This is a singleton, contructor is private!
343 virtual ~AliTRDCalibraFit();
346 ClassDef(AliTRDCalibraFit,2) // TRD Calibration class