]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibraFit.h
Provide a special IO ctor for the parameter singleton classes
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFit.h
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
18 class TTree;
19 class TProfile2D;
20 class TGraphErrors;
21 class TObjArray;
22 class TH1I;
23 class TH1;
24 class TH1F;
25 class TH2I;
26 class TH2F;
27 class TF1;
28 class TTreeSRedirector;
29
30 class AliLog;
31
32 class AliTRDCalibraMode;
33 class AliTRDCalibraVector;
34 class AliTRDCalibraVdriftLinearFit;
35 class AliTRDCalDet;
36 class AliTRDCalROC;
37 class AliTRDgeometry;
38
39 class AliTRDCalibraFit : public TObject {
40
41  public: 
42
43   // Instance
44   static AliTRDCalibraFit *Instance();
45   static void Terminate();
46   static void Destroy();
47
48   AliTRDCalibraFit(const AliTRDCalibraFit &c);
49   AliTRDCalibraFit &operator=(const AliTRDCalibraFit &) { return *this; }
50
51   // Functions fit for CH
52           Bool_t   AnalyseCH(TH2I *ch);
53           Bool_t   AnalyseCH(AliTRDCalibraVector *calvect);
54                   
55   // Functions fit for PH       
56           Bool_t   AnalysePH(TProfile2D *ph);
57           Bool_t   AnalysePH(AliTRDCalibraVector *calvect);
58          
59  // Functions fit for PRF
60           Bool_t   AnalysePRF(TProfile2D *prf);
61           Bool_t   AnalysePRF(AliTRDCalibraVector *calvect);
62       
63           Bool_t   AnalysePRFMarianFit(TProfile2D *prf);
64           Bool_t   AnalysePRFMarianFit(AliTRDCalibraVector *calvect);
65           
66  // Functions fit for vdrift/lorentzangle
67           Bool_t   AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli);
68           
69   // Pad Calibration
70           Bool_t   SetModeCalibration(const char *name, Int_t i);
71
72   //Reset Function
73           void     ResetVectorFit();
74
75   // Some functions
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);
79
80   // Fill the database
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);
85           
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);
90
91   // Outliers stats
92           AliTRDCalDet *MakeOutliersStatDet(TObjArray *vectorFit, const char *name, Double_t &mean);
93           TObject      *MakeOutliersStatPad(TObjArray *vectorFit, const char *name, Double_t &mean);
94
95
96   // Correct the error
97   TH1F            *CorrectTheError(TGraphErrors *hist);
98     
99   //
100   // Set or Get the variables
101   //
102  
103   // Fit
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);
113   
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;                  }
121
122   // Statistics
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;          }
127         
128   
129   // Debug
130           void     SetDebugLevel(Short_t level)                              { fDebugLevel = level;           }
131           void     SetDet(Int_t iPlane, Int_t iChamb, Int_t iSect)           { fDet[0]  = iPlane; 
132                                                                                fDet[1]  = iChamb; 
133                                                                                fDet[2]  = iSect;               }
134           void     SetFitVoir(Int_t fitVoir)                                 { fFitVoir = fitVoir;             }
135  // Magnetic field  
136           void     SetMagneticField(Float_t magneticfield)                   { fMagneticField = magneticfield; }
137
138  // Get the scale factor
139            Double_t GetScaleFitFactor() const                                { return fScaleFitFactor;         }
140
141   // Vector Fit getter
142           TObjArray  GetVectorFit()                                          { return fVectorFit;              }
143           TObjArray  GetVectorFit2()                                         { return fVectorFit2;             }
144
145           // AliTRDCalibraMode
146           AliTRDCalibraMode *GetCalibraMode()                                { return fCalibraMode;            }
147
148  private:
149   
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); 
159   
160   // This is a singleton, contructor is private!
161   AliTRDCalibraFit();
162   virtual ~AliTRDCalibraFit();
163
164  protected:
165
166   // Geometry
167   AliTRDgeometry  *fGeo;                    //! The TRD geometry
168
169
170           Int_t        fNumberOfBinsExpected;  // Number of bins expected  
171   
172  // Fit
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 
182          
183   // Statistics      
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
188
189
190   // Debug Modes
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
195
196   // Magnetic field lorentz angle
197           Float_t     fMagneticField;        // Magnetic field lorentz angle
198
199   // Calibra objects
200
201           AliTRDCalibraMode *fCalibraMode;  // The calibration mode
202           
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
215   
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
221          
222   // Current values detector
223
224           Float_t *fCurrentCoefDetector;     // Current values for the detector 
225           Float_t *fCurrentCoefDetector2;    // Current values for the detector   
226
227           class AliTRDFitInfo : public TObject {
228
229           public:
230             
231             AliTRDFitInfo()
232               :TObject()
233               ,fCoef(0x0)
234               ,fDetector(-1)                                   { }    
235             AliTRDFitInfo(const AliTRDFitInfo &i) 
236               :TObject(i)
237               ,fCoef(0x0)
238               ,fDetector(-1)                                   { }
239             AliTRDFitInfo &operator=(const AliTRDFitInfo&)     { return *this;            }
240             virtual ~AliTRDFitInfo()                           { }
241             
242             void      SetCoef(Float_t *coef)                   { fCoef     = coef;        }
243             void      SetDetector(Int_t detector)              { fDetector = detector;    }
244             
245             Float_t  *GetCoef() const                          { return fCoef;            }
246             Int_t     GetDetector() const                      { return fDetector;        }
247             
248           protected:
249             
250             Float_t  *fCoef;                        // Relative coefficient for each group of the detector
251             Int_t     fDetector;                    // Detector number
252             
253           };
254
255           TObjArray       fVectorFit;            // Vectors to fit
256           TObjArray       fVectorFit2;           // Vectors to fit
257    
258   //
259   // A lot of internal functions......
260   //
261
262   // Init AliTRDCalibraFit
263           Bool_t   InitFit(Int_t nbins, Int_t i);
264           Bool_t   InitFitCH();
265           Bool_t   InitFitPH();
266           Bool_t   InitFitPRF();
267           Bool_t   InitFitLinearFitter();
268           
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();
274
275  // Fill Infos Fit
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();
280
281           void     FillFillCH(Int_t idect);
282           void     FillFillPH(Int_t idect);
283           void     FillFillPRF(Int_t idect);
284           void     FillFillLinearFitter();
285
286           Bool_t   FillVectorFit();
287           Bool_t   FillVectorFit2();
288                   
289  // Functions... 
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);
300         
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);
309
310  // Fit methods
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;
326
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;
331   
332  // Instance of this class and so on
333   static  AliTRDCalibraFit   *fgInstance;                     // Instance
334   static  Bool_t             fgTerminated;                    // If terminated
335
336     
337   ClassDef(AliTRDCalibraFit,2)                 // TRD Calibration class
338
339 };
340   
341 #endif
342
343