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 ///////////////////////////////////////////////////////////////////////////////
18 # include <TVectorD.h>
32 class TTreeSRedirector;
37 class AliTRDCalibraMode;
38 class AliTRDCalibraVector;
39 class AliTRDCalibraVdriftLinearFit;
40 class AliTRDCalibraExbAltFit;
45 class AliTRDCalibraFit : public TObject {
50 static AliTRDCalibraFit *Instance();
51 static void Terminate();
52 static void Destroy();
53 void DestroyDebugStreamer();
55 AliTRDCalibraFit(const AliTRDCalibraFit &c);
56 AliTRDCalibraFit &operator=(const AliTRDCalibraFit &) { return *this; }
58 // Function for integration range of the charge
59 void RangeChargeIntegration(Float_t vdrift, Float_t t0, Int_t &begin, Int_t &peak, Int_t &end) const;
62 void SetCalDetVdriftExB(AliTRDCalDet *calDetVdriftUsed,AliTRDCalDet *calDetExBUsed) {fCalDetVdriftUsed = calDetVdriftUsed; fCalDetExBUsed = calDetExBUsed;};
64 // Functions fit for CH
65 Bool_t AnalyseCH(const TH2I *ch);
66 Bool_t AnalyseCH(AliTRDCalibraVector *calvect);
67 Double_t AnalyseCHAllTogether(const TH2I *ch);
69 // Functions fit for PH
70 Bool_t AnalysePH(const TProfile2D *ph);
71 Bool_t AnalysePH(AliTRDCalibraVector *calvect);
72 Double_t AnalysePHAllTogether(const TProfile2D *ph);
74 // Functions fit for PRF
75 Bool_t AnalysePRF(const TProfile2D *prf);
76 Bool_t AnalysePRF(AliTRDCalibraVector *calvect);
78 Bool_t AnalysePRFMarianFit(const TProfile2D *prf);
79 Bool_t AnalysePRFMarianFit(AliTRDCalibraVector *calvect);
81 // Functions fit for vdrift/lorentzangle
82 Bool_t AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli);
83 void AnalyseLinearFittersAllTogether(AliTRDCalibraVdriftLinearFit *calivdli, Double_t &vdriftoverall, Double_t &exboverall);
84 Bool_t AnalyseExbAltFit(AliTRDCalibraExbAltFit *calivdli);
87 Bool_t SetModeCalibration(TString name, Int_t i);
90 void ResetVectorFit();
93 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;
94 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;
95 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;
98 void RemoveOutliers(Int_t type, Bool_t perdetector = kFALSE);
99 void RemoveOutliers2(Bool_t perdetector = kFALSE);
100 void PutMeanValueOtherVectorFit(Int_t ofwhat = 1, Bool_t perdetector = kFALSE);
101 void PutMeanValueOtherVectorFit2(Int_t ofwhat = 1, Bool_t perdetector = kFALSE);
102 AliTRDCalDet *CreateDetObjectVdrift(const TObjArray *vectorFit, Bool_t perdetector = kFALSE);
103 AliTRDCalDet *CreateDetObjectGain(const TObjArray *vectorFit, Bool_t meanOtherBefore=kTRUE, Double_t scaleFitFactor = 0.02431, Bool_t perdetector = kTRUE);
104 AliTRDCalDet *CreateDetObjectT0(const TObjArray *vectorFit, Bool_t perdetector = kFALSE);
105 AliTRDCalDet *CreateDetObjectLorentzAngle(const TObjArray *vectorFit);
106 AliTRDCalDet *CreateDetObjectExbAlt(const TObjArray *vectorFit);
108 TObject *CreatePadObjectGain(const TObjArray *vectorFit = 0, Double_t scaleFitFactor = 1.0, const AliTRDCalDet *detobject = 0);
109 TObject *CreatePadObjectVdrift(const TObjArray *vectorFit = 0, const AliTRDCalDet *detobject = 0);
110 TObject *CreatePadObjectT0(const TObjArray *vectorFit = 0, const AliTRDCalDet *detobject = 0);
111 TObject *CreatePadObjectPRF(const TObjArray *vectorFit);
114 AliTRDCalDet *MakeOutliersStatDet(const TObjArray *vectorFit, const char *name, Double_t &mean);
115 TObject *MakeOutliersStatPad(const TObjArray *vectorFit, const char *name, Double_t &mean);
118 // Set or Get the variables
122 void ChooseMethod(Short_t method) { fMethod = method; }
123 void SetBeginFitCharge(Float_t beginFitCharge);
124 void SetPeriodeFitPH(Int_t periodeFitPH);
125 void SetTakeTheMaxPH() { fTakeTheMaxPH = kTRUE; }
126 void SetT0Shift0(Float_t t0Shift0);
127 void SetT0Shift1(Float_t t0Shift1);
128 void SetRangeFitPRF(Float_t rangeFitPRF);
129 void SetAccCDB() { fAccCDB = kTRUE; }
130 void SetMinEntries(Int_t minEntries);
131 void SetRebin(Short_t rebin);
133 Int_t GetPeriodeFitPH() const { return fFitPHPeriode; }
134 Bool_t GetTakeTheMaxPH() const { return fTakeTheMaxPH; }
135 Float_t GetT0Shift0() const { return fT0Shift0; }
136 Float_t GetT0Shift1() const { return fT0Shift1; }
137 Float_t GetRangeFitPRF() const { return fRangeFitPRF; }
138 Bool_t GetAccCDB() const { return fAccCDB; }
139 Int_t GetMinEntries() const { return fMinEntries; }
140 Short_t GetRebin() const { return fRebin; }
141 Float_t GetScaleFactorGain() const { return fScaleGain; }
144 Int_t GetNumberFit() const { return fNumberFit; }
145 Int_t GetNumberFitSuccess() const { return fNumberFitSuccess; }
146 Int_t GetNumberEnt() const { return fNumberEnt; }
147 Double_t GetStatisticMean() const { return fStatisticMean; }
151 void SetDebugLevel(Short_t level) { fDebugLevel = level; }
152 void SetDet(Int_t iLayer, Int_t iStack, Int_t iSector) { fDet[0] = iLayer;
155 void SetFitVoir(Int_t fitVoir) { fFitVoir = fitVoir; }
157 void SetMagneticField(Float_t magneticfield) { fMagneticField = magneticfield; }
159 // Get the scale factor
160 Double_t GetScaleFitFactor() const { return fScaleFitFactor; }
163 TObjArray GetVectorFit() const { return fVectorFit; }
164 TObjArray GetVectorFit2() const { return fVectorFit2; }
167 AliTRDCalibraMode *GetCalibraMode() const { return fCalibraMode; }
169 class AliTRDFitInfo : public TObject {
177 AliTRDFitInfo(const AliTRDFitInfo &i)
181 AliTRDFitInfo &operator=(const AliTRDFitInfo&) { return *this; }
182 virtual ~AliTRDFitInfo() { if(fCoef) { delete [] fCoef;} }
184 void SetCoef(Float_t *coef) { fCoef = coef; }
185 void SetDetector(Int_t detector) { fDetector = detector; }
187 Float_t *GetCoef() const { return fCoef; }
188 Int_t GetDetector() const { return fDetector; }
192 Float_t *fCoef; // Relative coefficient for each group of the detector
193 Int_t fDetector; // Detector number
198 void FitLagrangePoly(TH1* projPH);
203 AliTRDgeometry *fGeo; //! The TRD geometry
206 Int_t fNumberOfBinsExpected; // Number of bins expected
209 Short_t fMethod; // Method
210 Float_t fBeginFitCharge; // The fit begins at mean/fBeginFitCharge for the gain calibration
211 Int_t fFitPHPeriode; // Periode of the fit PH
212 Bool_t fTakeTheMaxPH; // Take the Max for the T0 determination
213 Float_t fT0Shift0; // T0 Shift with the maximum positive slope
214 Float_t fT0Shift1; // T0 Shift with the maximum of the amplification region
215 Float_t fRangeFitPRF; // The fit range for the PRF is -fRangeFitPRF +fRangeFitPRF
216 Bool_t fAccCDB; // If there is a calibration database to be compared with....
217 Int_t fMinEntries; // Min Entries to fit the histo
218 Short_t fRebin; // If you want to rebin the histo for the gain calibration
219 Float_t fScaleGain; // Scale Factor used to scale the gain
222 Int_t fNumberFit; // To know how many pad groups have been fitted
223 Int_t fNumberFitSuccess; // To know how many pad groups have been fitted successfully
224 Int_t fNumberEnt; // To know how many pad groups have entries in the histo
225 Double_t fStatisticMean; // To know the mean statistic of the histos
229 TTreeSRedirector *fDebugStreamer; //!Debug streamer
230 Short_t fDebugLevel; // Flag for debugging
231 Int_t fDet[3]; // Detector visualised (layer,stack,sector) si debugging == 3 or 4
232 Int_t fFitVoir; // Fit visualised si debugging == 2
234 // Magnetic field lorentz angle
235 Float_t fMagneticField; // Magnetic field lorentz angle
239 AliTRDCalibraMode *fCalibraMode; // The calibration mode
241 // Current values of the coefficients found and ect...
242 Float_t fCurrentCoef[2]; // Current coefs
243 Float_t fCurrentCoefE; // Current coefs error
244 Float_t fCurrentCoef2[2]; // Current coefs
245 Float_t fCurrentCoefE2; // Current coefs error
246 Float_t fPhd[3]; // Begin AR and DR
247 Int_t fDect1; // First calibration group that will be called to be maybe fitted
248 Int_t fDect2; // Last calibration group that will be called to be maybe fitted
249 Double_t fScaleFitFactor; // Scale factor of the fit results for the gain
250 Int_t fEntriesCurrent; // Entries in the current histo
251 Int_t fCountDet; // Current detector (or first in the group)
252 Int_t fCount; // When the next detector comes
253 Int_t fNbDet; // Number of detector in the group
255 // Current calib object
256 AliTRDCalDet *fCalDet; // Current calib object
257 AliTRDCalROC *fCalROC; // Current calib object
258 AliTRDCalDet *fCalDet2; // Current calib object
259 AliTRDCalROC *fCalROC2; // Current calib object
261 AliTRDCalDet *fCalDetVdriftUsed; // ExB calibration
262 AliTRDCalDet *fCalDetExBUsed; // ExB calibration
264 // Current values detector
266 Float_t *fCurrentCoefDetector; // Current values for the detector
267 Float_t *fCurrentCoefDetector2; // Current values for the detector
269 TObjArray fVectorFit; // Vectors to fit
270 TObjArray fVectorFit2; // Vectors to fit
273 // A lot of internal functions......
276 // Init AliTRDCalibraFit
277 Bool_t InitFit(Int_t nbins, Int_t i);
281 Bool_t InitFitLinearFitter();
282 Bool_t InitFitExbAlt();
284 // Not enough Statistics
285 Bool_t NotEnoughStatisticCH(Int_t idect);
286 Bool_t NotEnoughStatisticPH(Int_t idect,Double_t nentries);
287 Bool_t NotEnoughStatisticPRF(Int_t idect);
288 Bool_t NotEnoughStatisticLinearFitter();
289 Bool_t NotEnoughStatisticExbAlt();
292 Bool_t FillInfosFitCH(Int_t idect);
293 Bool_t FillInfosFitPH(Int_t idect,Double_t nentries);
294 Bool_t FillInfosFitPRF(Int_t idect);
295 Bool_t FillInfosFitLinearFitter();
296 Bool_t FillInfosFitExbAlt();
298 void FillFillCH(Int_t idect);
299 void FillFillPH(Int_t idect,Double_t nentries);
300 void FillFillPRF(Int_t idect);
301 void FillFillLinearFitter();
302 void FillFillExbAlt();
304 Bool_t FillVectorFit();
305 Bool_t FillVectorFit2();
308 void InitfCountDetAndfCount(Int_t i);
309 void CalculNumberOfBinsExpected(Int_t i);
310 void CalculDect1Dect2(Int_t i);
311 void UpdatefCountDetAndfCount(Int_t idect, Int_t i);
312 void ReconstructFitRowMinRowMax(Int_t idect, Int_t i);
313 Bool_t CheckFitVoir();
314 void NormierungCharge();
315 Bool_t SetNrphiFromTObject(TString name, Int_t i);
316 Bool_t SetNzFromTObject(TString name, Int_t i);
317 Int_t GetNumberOfGroupsPRF(TString nametitle);
319 // Calculate the mean coefs from the database
320 Bool_t CalculVdriftCoefMean();
321 Bool_t CalculChargeCoefMean(Bool_t vrai);
322 Bool_t CalculPRFCoefMean();
323 Bool_t CalculT0CoefMean();
324 Bool_t CalculVdriftLorentzCoef();
325 Float_t GetPRFDefault(Int_t layer) const;
326 void SetCalROC(Int_t i);
329 void FitBisCH(TH1 *projch, Double_t mean);
330 void FitCH(TH1 *projch, Double_t mean);
331 void FitMeanW(TH1 *projch, Double_t nentries);
332 void FitMeanWSm(TH1 *projch, Float_t sumAll);
333 void FitMean(TH1 *projch, Double_t nentries, Double_t mean);
334 void FitPH(TH1 *projPH, Int_t idect);
335 void FitPRF(TH1 *projPRF);
336 void RmsPRF(TH1 *projPRF);
337 Bool_t FitPRFGausMI(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nBins,Float_t xMin,Float_t xMax);
338 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);
339 void FitPente(TH1 *projPH);
340 void FitTnpRange(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nbg,Int_t nybins);
341 TH1I *ReBin(const TH1I *hist) const;
342 TH1F *ReBin(const TH1F *hist) const;
344 // Some basic geometry function
345 virtual Int_t GetLayer(Int_t d) const;
346 virtual Int_t GetStack(Int_t d) const;
347 virtual Int_t GetSector(Int_t d) const;
349 // Instance of this class and so on
350 static AliTRDCalibraFit *fgInstance; // Instance
351 static Bool_t fgTerminated; // If terminated
356 static Double_t PH(const Double_t *x, const Double_t *par);
357 static Double_t AsymmGauss(const Double_t *x, const Double_t *par);
358 static Double_t FuncLandauGaus(const Double_t *x, const Double_t *par);
359 static Double_t LanGauFun(const Double_t *x, const Double_t *par);
360 TF1 *LanGauFit(TH1 *his, const Double_t *fitrange, const Double_t *startvalues
361 , const Double_t *parlimitslo, const Double_t *parlimitshi, Double_t *fitparams
362 , Double_t *fiterrors, Double_t *chiSqr, Int_t *ndf) const;
363 Int_t LanGauPro(const Double_t *params, Double_t &maxx, Double_t &fwhm);
364 static Double_t GausConstant(const Double_t *x, const Double_t *par);
366 // This is a singleton, contructor is private!
368 virtual ~AliTRDCalibraFit();
371 ClassDef(AliTRDCalibraFit,3) // TRD Calibration class