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