]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibraFit.h
Coverity
[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 AliTRDCalibraExbAltFit;
41 class AliTRDCalDet;
42 class AliTRDCalROC;
43 class AliTRDgeometry;
44
45 class AliTRDCalibraFit : public TObject {
46
47  public: 
48
49   // Instance
50   static AliTRDCalibraFit *Instance();
51   static void Terminate();
52   static void Destroy();
53   void DestroyDebugStreamer();
54
55   AliTRDCalibraFit(const AliTRDCalibraFit &c);
56   AliTRDCalibraFit &operator=(const AliTRDCalibraFit &) { return *this; }
57
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;
60
61   // ExB calibration
62   void     SetCalDetVdriftExB(AliTRDCalDet *calDetVdriftUsed,AliTRDCalDet *calDetExBUsed) {fCalDetVdriftUsed = calDetVdriftUsed; fCalDetExBUsed = calDetExBUsed;};
63   
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);
68   
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);
73   
74   // Functions fit for PRF
75   Bool_t   AnalysePRF(const TProfile2D *prf);
76   Bool_t   AnalysePRF(AliTRDCalibraVector *calvect);
77   
78   Bool_t   AnalysePRFMarianFit(const TProfile2D *prf);
79   Bool_t   AnalysePRFMarianFit(AliTRDCalibraVector *calvect);
80   
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);
85   
86   // Pad Calibration
87   Bool_t   SetModeCalibration(TString name, Int_t i);
88   
89   //Reset Function
90   void     ResetVectorFit();
91   
92   // Some functions
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;
96   
97   // Fill the database
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);
107   
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);
112   
113   // Outliers stats
114   AliTRDCalDet *MakeOutliersStatDet(const TObjArray *vectorFit, const char *name, Double_t &mean);
115   TObject      *MakeOutliersStatPad(const TObjArray *vectorFit, const char *name, Double_t &mean);
116        
117   //
118   // Set or Get the variables
119   //
120   
121   // Fit
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);
132   
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;              }
142   
143   // Statistics
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;          }
148   
149        
150   // Debug
151   void     SetDebugLevel(Short_t level)                              { fDebugLevel = level;            }
152   void     SetDet(Int_t iLayer, Int_t iStack, Int_t iSector)         { fDet[0]  = iLayer; 
153                                                                             fDet[1]  = iStack; 
154                                                                             fDet[2]  = iSector;             }
155        void     SetFitVoir(Int_t fitVoir)                                 { fFitVoir = fitVoir;             }
156        // Magnetic field  
157        void     SetMagneticField(Float_t magneticfield)                   { fMagneticField = magneticfield; }
158        
159        // Get the scale factor
160        Double_t GetScaleFitFactor() const                                 { return fScaleFitFactor;         }
161        
162        // Vector Fit getter
163        TObjArray  GetVectorFit() const                                    { return fVectorFit;              }
164        TObjArray  GetVectorFit2() const                                   { return fVectorFit2;             }
165        
166        // AliTRDCalibraMode
167        AliTRDCalibraMode *GetCalibraMode() const                          { return fCalibraMode;            }
168        
169        class AliTRDFitInfo : public TObject {
170          
171        public:
172          
173          AliTRDFitInfo()
174            :TObject()
175            ,fCoef(0x0)
176            ,fDetector(-1)                                   { }    
177          AliTRDFitInfo(const AliTRDFitInfo &i) 
178            :TObject(i)
179            ,fCoef(0x0)
180            ,fDetector(-1)                                   { }
181          AliTRDFitInfo &operator=(const AliTRDFitInfo&)     { return *this;            }
182          virtual ~AliTRDFitInfo()                           { if(fCoef) { delete [] fCoef;} }
183          
184          void      SetCoef(Float_t *coef)                   { fCoef = coef;            }
185          void      SetDetector(Int_t detector)              { fDetector = detector;    }
186          
187          Float_t  *GetCoef() const                          { return fCoef;            }
188          Int_t     GetDetector() const                      { return fDetector;        }
189          
190        protected:
191          
192          Float_t  *fCoef;                        // Relative coefficient for each group of the detector
193          Int_t     fDetector;                    // Detector number
194          
195        };
196
197        // Fit function
198        void     FitLagrangePoly(TH1* projPH);
199
200  protected:
201        
202        // Geometry
203        AliTRDgeometry  *fGeo;               //! The TRD geometry
204        
205        
206        Int_t        fNumberOfBinsExpected;  // Number of bins expected  
207        
208        // Fit
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
220        
221        // Statistics      
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
226        
227        
228        // Debug Modes
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
233        
234        // Magnetic field lorentz angle
235        Float_t     fMagneticField;        // Magnetic field lorentz angle
236        
237        // Calibra objects
238        
239        AliTRDCalibraMode *fCalibraMode;  // The calibration mode
240        
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
254        
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
260
261        AliTRDCalDet *fCalDetVdriftUsed;  // ExB calibration
262        AliTRDCalDet *fCalDetExBUsed;     // ExB calibration
263        
264        // Current values detector
265        
266        Float_t *fCurrentCoefDetector;     // Current values for the detector 
267        Float_t *fCurrentCoefDetector2;    // Current values for the detector   
268        
269        TObjArray       fVectorFit;            // Vectors to fit
270        TObjArray       fVectorFit2;           // Vectors to fit
271        
272        //
273        // A lot of internal functions......
274        //
275        
276        // Init AliTRDCalibraFit
277        Bool_t   InitFit(Int_t nbins, Int_t i);
278        Bool_t   InitFitCH();
279        Bool_t   InitFitPH();
280        Bool_t   InitFitPRF();
281        Bool_t   InitFitLinearFitter();
282        Bool_t   InitFitExbAlt();
283        
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();
290        
291        // Fill Infos Fit
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();
297        
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();
303        
304        Bool_t   FillVectorFit();
305        Bool_t   FillVectorFit2();
306        
307        // Functions... 
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);
318        
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);
327        
328        // Fit methods
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;
343        
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;
348        
349        // Instance of this class and so on
350        static  AliTRDCalibraFit   *fgInstance;                     // Instance
351        static  Bool_t             fgTerminated;                    // If terminated
352        
353        
354  private:
355        
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); 
365        
366        // This is a singleton, contructor is private!
367        AliTRDCalibraFit();
368        virtual ~AliTRDCalibraFit();
369        
370        
371   ClassDef(AliTRDCalibraFit,3)                 // TRD Calibration class
372          
373 };
374   
375 #endif
376
377
378