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