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