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