]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibraFit.h
First fix for the exb calibration.
[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 #ifndef ROOT_TVectorD
18 # include <TVectorD.h>
19 #endif 
20
21 class TString;
22 class TTree;
23 class TProfile2D;
24 class TGraphErrors;
25 class TObjArray;
26 class TH1I;
27 class TH1;
28 class TH1F;
29 class TH2I;
30 class TH2F;
31 class TF1;
32 class TTreeSRedirector;
33
34
35 class AliLog;
36
37 class AliTRDCalibraMode;
38 class AliTRDCalibraVector;
39 class AliTRDCalibraVdriftLinearFit;
40 class AliTRDCalDet;
41 class AliTRDCalROC;
42 class AliTRDgeometry;
43
44 class AliTRDCalibraFit : public TObject {
45
46  public: 
47
48   // Instance
49   static AliTRDCalibraFit *Instance();
50   static void Terminate();
51   static void Destroy();
52   void DestroyDebugStreamer();
53
54   AliTRDCalibraFit(const AliTRDCalibraFit &c);
55   AliTRDCalibraFit &operator=(const AliTRDCalibraFit &) { return *this; }
56
57   // Function for integration range of the charge 
58   void     RangeChargeIntegration(Float_t vdrift, Float_t t0, Int_t &begin, Int_t &peak, Int_t &end) const;
59
60   // ExB calibration
61   void     SetCalDetVdriftExB(AliTRDCalDet *calDetVdriftUsed,AliTRDCalDet *calDetExBUsed) {fCalDetVdriftUsed = calDetVdriftUsed; fCalDetExBUsed = calDetExBUsed;};
62   
63   // Functions fit for CH
64   Bool_t   AnalyseCH(const TH2I *ch);
65   Bool_t   AnalyseCH(AliTRDCalibraVector *calvect);
66   Double_t AnalyseCHAllTogether(const TH2I *ch);
67   
68   // Functions fit for PH       
69   Bool_t   AnalysePH(const TProfile2D *ph);
70   Bool_t   AnalysePH(AliTRDCalibraVector *calvect);
71   Double_t AnalysePHAllTogether(const TProfile2D *ph);
72   
73   // Functions fit for PRF
74   Bool_t   AnalysePRF(const TProfile2D *prf);
75   Bool_t   AnalysePRF(AliTRDCalibraVector *calvect);
76   
77   Bool_t   AnalysePRFMarianFit(const TProfile2D *prf);
78   Bool_t   AnalysePRFMarianFit(AliTRDCalibraVector *calvect);
79   
80   // Functions fit for vdrift/lorentzangle
81   Bool_t   AnalyseLinearFitters(AliTRDCalibraVdriftLinearFit *calivdli);
82   void     AnalyseLinearFittersAllTogether(AliTRDCalibraVdriftLinearFit *calivdli, Double_t &vdriftoverall, Double_t &exboverall);
83   
84   // Pad Calibration
85   Bool_t   SetModeCalibration(TString name, Int_t i);
86   
87   //Reset Function
88   void     ResetVectorFit();
89   
90   // Some functions
91   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;
92   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;
93   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;
94   
95   // Fill the database
96   void         RemoveOutliers(Int_t type, Bool_t perdetector = kFALSE);
97   void         RemoveOutliers2(Bool_t perdetector = kFALSE);
98   void         PutMeanValueOtherVectorFit(Int_t ofwhat = 1, Bool_t perdetector = kFALSE);
99   void         PutMeanValueOtherVectorFit2(Int_t ofwhat = 1, Bool_t perdetector = kFALSE);
100   AliTRDCalDet *CreateDetObjectVdrift(const TObjArray *vectorFit, Bool_t perdetector = kFALSE);
101   AliTRDCalDet *CreateDetObjectGain(const TObjArray *vectorFit, Bool_t meanOtherBefore=kTRUE, Double_t scaleFitFactor = 0.02431, Bool_t perdetector = kTRUE);
102   AliTRDCalDet *CreateDetObjectT0(const TObjArray *vectorFit, Bool_t perdetector = kFALSE);
103   AliTRDCalDet *CreateDetObjectLorentzAngle(const TObjArray *vectorFit);
104   
105   TObject      *CreatePadObjectGain(const TObjArray *vectorFit = 0, Double_t scaleFitFactor = 1.0, const AliTRDCalDet *detobject = 0);
106   TObject      *CreatePadObjectVdrift(const TObjArray *vectorFit = 0, const AliTRDCalDet *detobject = 0);
107   TObject      *CreatePadObjectT0(const TObjArray *vectorFit = 0, const AliTRDCalDet *detobject = 0);
108   TObject      *CreatePadObjectPRF(const TObjArray *vectorFit);
109   
110   // Outliers stats
111   AliTRDCalDet *MakeOutliersStatDet(const TObjArray *vectorFit, const char *name, Double_t &mean);
112   TObject      *MakeOutliersStatPad(const TObjArray *vectorFit, const char *name, Double_t &mean);
113        
114   //
115   // Set or Get the variables
116   //
117   
118   // Fit
119   void     ChooseMethod(Short_t method)                              { fMethod = method;               }
120   void     SetBeginFitCharge(Float_t beginFitCharge);   
121   void     SetPeriodeFitPH(Int_t periodeFitPH);   
122   void     SetTakeTheMaxPH()                                         { fTakeTheMaxPH   = kTRUE;        }
123   void     SetT0Shift0(Float_t t0Shift0); 
124   void     SetT0Shift1(Float_t t0Shift1); 
125   void     SetRangeFitPRF(Float_t rangeFitPRF);     
126   void     SetAccCDB()                                               { fAccCDB         = kTRUE;        }
127   void     SetMinEntries(Int_t minEntries);                    
128   void     SetRebin(Short_t rebin);
129   
130   Int_t    GetPeriodeFitPH() const                                   { return fFitPHPeriode;           }
131   Bool_t   GetTakeTheMaxPH() const                                   { return fTakeTheMaxPH;           }
132   Float_t  GetT0Shift0() const                                       { return fT0Shift0;               }
133   Float_t  GetT0Shift1() const                                       { return fT0Shift1;               }
134   Float_t  GetRangeFitPRF() const                                    { return fRangeFitPRF;            }
135   Bool_t   GetAccCDB() const                                         { return fAccCDB;                 }
136   Int_t    GetMinEntries() const                                     { return fMinEntries;             }
137   Short_t  GetRebin() const                                          { return fRebin;                  }
138   Float_t  GetScaleFactorGain() const                                { return fScaleGain;              }
139   
140   // Statistics
141   Int_t    GetNumberFit() const                                      { return fNumberFit;              }
142   Int_t    GetNumberFitSuccess() const                               { return fNumberFitSuccess;       }
143   Int_t    GetNumberEnt() const                                      { return fNumberEnt;              }
144   Double_t GetStatisticMean() const                                  { return fStatisticMean;          }
145   
146        
147   // Debug
148   void     SetDebugLevel(Short_t level)                              { fDebugLevel = level;            }
149   void     SetDet(Int_t iLayer, Int_t iStack, Int_t iSector)         { fDet[0]  = iLayer; 
150                                                                             fDet[1]  = iStack; 
151                                                                             fDet[2]  = iSector;             }
152        void     SetFitVoir(Int_t fitVoir)                                 { fFitVoir = fitVoir;             }
153        // Magnetic field  
154        void     SetMagneticField(Float_t magneticfield)                   { fMagneticField = magneticfield; }
155        
156        // Get the scale factor
157        Double_t GetScaleFitFactor() const                                 { return fScaleFitFactor;         }
158        
159        // Vector Fit getter
160        TObjArray  GetVectorFit() const                                    { return fVectorFit;              }
161        TObjArray  GetVectorFit2() const                                   { return fVectorFit2;             }
162        
163        // AliTRDCalibraMode
164        AliTRDCalibraMode *GetCalibraMode() const                          { return fCalibraMode;            }
165        
166        class AliTRDFitInfo : public TObject {
167          
168        public:
169          
170          AliTRDFitInfo()
171            :TObject()
172            ,fCoef(0x0)
173            ,fDetector(-1)                                   { }    
174          AliTRDFitInfo(const AliTRDFitInfo &i) 
175            :TObject(i)
176            ,fCoef(0x0)
177            ,fDetector(-1)                                   { }
178          AliTRDFitInfo &operator=(const AliTRDFitInfo&)     { return *this;            }
179          virtual ~AliTRDFitInfo()                           { if(fCoef) { delete [] fCoef;} }
180          
181          void      SetCoef(Float_t *coef)                   { fCoef = coef;            }
182          void      SetDetector(Int_t detector)              { fDetector = detector;    }
183          
184          Float_t  *GetCoef() const                          { return fCoef;            }
185          Int_t     GetDetector() const                      { return fDetector;        }
186          
187        protected:
188          
189          Float_t  *fCoef;                        // Relative coefficient for each group of the detector
190          Int_t     fDetector;                    // Detector number
191          
192        };
193
194        // Fit function
195        void     FitLagrangePoly(TH1* projPH);
196
197  protected:
198        
199        // Geometry
200        AliTRDgeometry  *fGeo;               //! The TRD geometry
201        
202        
203        Int_t        fNumberOfBinsExpected;  // Number of bins expected  
204        
205        // Fit
206        Short_t      fMethod;                // Method
207        Float_t      fBeginFitCharge;        // The fit begins at mean/fBeginFitCharge for the gain calibration
208        Int_t        fFitPHPeriode;          // Periode of the fit PH
209        Bool_t       fTakeTheMaxPH;          // Take the Max for the T0 determination
210        Float_t      fT0Shift0;              // T0 Shift with the maximum positive slope
211        Float_t      fT0Shift1;              // T0 Shift with the maximum of the amplification region
212        Float_t      fRangeFitPRF;           // The fit range for the PRF is -fRangeFitPRF +fRangeFitPRF
213        Bool_t       fAccCDB;                // If there is a calibration database to be compared with....
214        Int_t        fMinEntries;            // Min Entries to fit the histo
215        Short_t      fRebin;                 // If you want to rebin the histo for the gain calibration 
216        Float_t      fScaleGain;            // Scale Factor used to scale the gain
217        
218        // Statistics      
219        Int_t        fNumberFit;             // To know how many pad groups have been fitted
220        Int_t        fNumberFitSuccess;      // To know how many pad groups have been fitted successfully
221        Int_t        fNumberEnt;             // To know how many pad groups have entries in the histo
222        Double_t     fStatisticMean;         // To know the mean statistic of the histos
223        
224        
225        // Debug Modes
226        TTreeSRedirector   *fDebugStreamer;         //!Debug streamer
227        Short_t     fDebugLevel;            // Flag for debugging
228        Int_t       fDet[3];                // Detector  visualised (layer,stack,sector) si debugging == 3 or 4
229        Int_t       fFitVoir;               // Fit visualised si debugging == 2
230        
231        // Magnetic field lorentz angle
232        Float_t     fMagneticField;        // Magnetic field lorentz angle
233        
234        // Calibra objects
235        
236        AliTRDCalibraMode *fCalibraMode;  // The calibration mode
237        
238        // Current values of the coefficients found and ect...
239        Float_t  fCurrentCoef[2];         // Current coefs  
240        Float_t  fCurrentCoefE;           // Current coefs error 
241        Float_t  fCurrentCoef2[2];        // Current coefs  
242        Float_t  fCurrentCoefE2;          // Current coefs error   
243        Float_t  fPhd[3];                 // Begin AR and DR
244        Int_t    fDect1;                  // First calibration group that will be called to be maybe fitted
245        Int_t    fDect2;                  // Last calibration group that will be called to be maybe fitted
246        Double_t fScaleFitFactor;         // Scale factor of the fit results for the gain
247        Int_t    fEntriesCurrent;         // Entries in the current histo
248        Int_t    fCountDet;               // Current detector (or first in the group)
249        Int_t    fCount;                  // When the next detector comes
250        Int_t    fNbDet;                  // Number of detector in the group
251        
252        // Current calib object
253        AliTRDCalDet *fCalDet;            // Current calib object
254        AliTRDCalROC *fCalROC;            // Current calib object
255        AliTRDCalDet *fCalDet2;           // Current calib object
256        AliTRDCalROC *fCalROC2;           // Current calib object
257
258        AliTRDCalDet *fCalDetVdriftUsed;  // ExB calibration
259        AliTRDCalDet *fCalDetExBUsed;     // ExB calibration
260        
261        // Current values detector
262        
263        Float_t *fCurrentCoefDetector;     // Current values for the detector 
264        Float_t *fCurrentCoefDetector2;    // Current values for the detector   
265        
266        TObjArray       fVectorFit;            // Vectors to fit
267        TObjArray       fVectorFit2;           // Vectors to fit
268        
269        //
270        // A lot of internal functions......
271        //
272        
273        // Init AliTRDCalibraFit
274        Bool_t   InitFit(Int_t nbins, Int_t i);
275        Bool_t   InitFitCH();
276        Bool_t   InitFitPH();
277        Bool_t   InitFitPRF();
278        Bool_t   InitFitLinearFitter();
279        
280        // Not enough Statistics
281        Bool_t   NotEnoughStatisticCH(Int_t idect);
282        Bool_t   NotEnoughStatisticPH(Int_t idect,Double_t nentries);
283        Bool_t   NotEnoughStatisticPRF(Int_t idect);
284        Bool_t   NotEnoughStatisticLinearFitter();
285        
286        // Fill Infos Fit
287        Bool_t   FillInfosFitCH(Int_t idect);
288        Bool_t   FillInfosFitPH(Int_t idect,Double_t nentries);
289        Bool_t   FillInfosFitPRF(Int_t idect);
290        Bool_t   FillInfosFitLinearFitter();
291        
292        void     FillFillCH(Int_t idect);
293        void     FillFillPH(Int_t idect,Double_t nentries);
294        void     FillFillPRF(Int_t idect);
295        void     FillFillLinearFitter();
296        
297        Bool_t   FillVectorFit();
298        Bool_t   FillVectorFit2();
299        
300        // Functions... 
301        void     InitfCountDetAndfCount(Int_t i);
302        void     CalculNumberOfBinsExpected(Int_t i);
303        void     CalculDect1Dect2(Int_t i);
304        void     UpdatefCountDetAndfCount(Int_t idect, Int_t i);
305        void     ReconstructFitRowMinRowMax(Int_t idect, Int_t i);
306        Bool_t   CheckFitVoir();
307        void     NormierungCharge();
308        Bool_t   SetNrphiFromTObject(TString name, Int_t i);
309        Bool_t   SetNzFromTObject(TString name, Int_t i);
310        Int_t    GetNumberOfGroupsPRF(TString nametitle);
311        
312        // Calculate the mean coefs from the database
313        Bool_t   CalculVdriftCoefMean();
314        Bool_t   CalculChargeCoefMean(Bool_t vrai);
315        Bool_t   CalculPRFCoefMean();
316        Bool_t   CalculT0CoefMean();
317        Bool_t   CalculVdriftLorentzCoef();
318        Float_t  GetPRFDefault(Int_t layer) const;
319        void     SetCalROC(Int_t i);
320        
321        // Fit methods
322        void     FitBisCH(TH1 *projch, Double_t mean);
323        void     FitCH(TH1 *projch, Double_t mean);
324        void     FitMeanW(TH1 *projch, Double_t nentries);
325        void     FitMeanWSm(TH1 *projch, Float_t sumAll);
326        void     FitMean(TH1 *projch, Double_t nentries, Double_t mean);
327        void     FitPH(TH1 *projPH, Int_t idect);
328        void     FitPRF(TH1 *projPRF);
329        void     RmsPRF(TH1 *projPRF);
330        Bool_t   FitPRFGausMI(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nBins,Float_t xMin,Float_t xMax);
331        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);
332        void     FitPente(TH1 *projPH);
333        void     FitTnpRange(Double_t *arraye,Double_t *arraym,Double_t *arrayme,Int_t nbg,Int_t nybins);
334        TH1I    *ReBin(const TH1I *hist) const;
335        TH1F    *ReBin(const TH1F *hist) const;
336        
337        // Some basic geometry function
338        virtual Int_t    GetLayer(Int_t d) const;
339        virtual Int_t    GetStack(Int_t d) const;
340        virtual Int_t    GetSector(Int_t d) const;
341        
342        // Instance of this class and so on
343        static  AliTRDCalibraFit   *fgInstance;                     // Instance
344        static  Bool_t             fgTerminated;                    // If terminated
345        
346        
347  private:
348        
349        static  Double_t PH(const Double_t *x, const Double_t *par);
350        static  Double_t AsymmGauss(const Double_t *x, const Double_t *par);
351        static  Double_t FuncLandauGaus(const Double_t *x, const Double_t *par);
352        static  Double_t LanGauFun(const Double_t *x, const Double_t *par);
353        TF1     *LanGauFit(TH1 *his, const Double_t *fitrange, const Double_t *startvalues
354                           , const Double_t *parlimitslo, const Double_t *parlimitshi, Double_t *fitparams
355                           , Double_t *fiterrors, Double_t *chiSqr, Int_t *ndf) const;
356        Int_t    LanGauPro(const Double_t *params, Double_t &maxx, Double_t &fwhm);
357        static  Double_t GausConstant(const Double_t *x, const Double_t *par); 
358        
359        // This is a singleton, contructor is private!
360        AliTRDCalibraFit();
361        virtual ~AliTRDCalibraFit();
362        
363        
364   ClassDef(AliTRDCalibraFit,3)                 // TRD Calibration class
365          
366 };
367   
368 #endif
369
370
371