]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibraFit.h
Air with increased transport cuts close to qb28.
[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
29 class AliLog;
30 class AliTRDCalibraMode;
31 class AliTRDCalibraVector;
32 class AliTRDCalDet;
33
34 class AliTRDCalibraFit : public TObject {
35
36  public: 
37
38   // Instance
39   static AliTRDCalibraFit *Instance();
40   static void Terminate();
41   static void Destroy();
42
43   AliTRDCalibraFit(const AliTRDCalibraFit &c);
44   AliTRDCalibraFit &operator=(const AliTRDCalibraFit &) { return *this; }
45
46   // Functions fit online
47           Bool_t   FitCHOnline(TH2I *ch);
48           Bool_t   FitCHOnline();
49           Bool_t   FitCHOnline(TTree *tree);
50           Bool_t   FitPHOnline(TProfile2D *ph);
51           Bool_t   FitPHOnline();
52           Bool_t   FitPHOnline(TTree *tree);
53           Bool_t   FitPRFOnline(TProfile2D *prf);
54           Bool_t   FitPRFOnline();
55           Bool_t   FitPRFOnline(TTree *tree);
56   
57   // Pad Calibration
58           Bool_t   SetModeCalibrationFromTObject(TObject *object, Int_t i);
59
60   // Fill the database
61   TObject         *CreatePadObjectTree(TTree *tree);
62   TObject         *CreatePadObjectTree(TTree *tree, Int_t i, AliTRDCalDet *detobject);
63   AliTRDCalDet    *CreateDetObjectTree(TTree *tree, Int_t i);
64
65   // Correct the error
66   TH1F            *CorrectTheError(TGraphErrors *hist);
67     
68   //
69   // Set or Get the variables
70   //
71
72   // Write
73           void     SetWriteCoef(Int_t i)                                     { fWriteCoef[i]  = kTRUE;         }
74           void     SetWriteNameCoef(TString writeNameCoef)                   { fWriteNameCoef = writeNameCoef; }
75            
76           Bool_t   GetWriteCoef(Int_t i) const                               { return fWriteCoef[i];           }
77           TString  GetWriteNameCoef() const                                  { return fWriteNameCoef;          }
78           
79   // Fit
80           void     SetFitPHOn()                                              { fFitPHOn        = kTRUE;        }
81           void     SetFitPol2On()                                            { fFitPol2On      = kTRUE;        }
82           void     SetFitLagrPolOn()                                         { fFitLagrPolOn   = kTRUE;        }
83           void     SetTakeTheMaxPH()                                         { fTakeTheMaxPH   = kTRUE;        }
84           void     SetPeriodeFitPH(Int_t periodeFitPH); 
85           void     SetFitPHNDB(Int_t fitPHNDB);  
86           void     SetBeginFitCharge(Float_t beginFitCharge);     
87           void     SetT0Shift(Float_t t0Shift); 
88           void     SetRangeFitPRF(Float_t rangeFitPRF);     
89           void     SetFitPRFOn()                                             { fFitPRFOn       = kTRUE;        }
90           void     SetRMSPRFOn()                                             { fRMSPRFOn       = kTRUE;        }
91           void     SetFitPRFNDB(Int_t fitPRFNDB);    
92           void     SetMeanChargeOn()                                         { fMeanChargeOn   = kTRUE;        }
93           void     SetFitChargeBisOn()                                       { fFitChargeBisOn = kTRUE;        }
94           void     SetFitChargeOn()                                          { fFitChargeOn    = kTRUE;        }
95           void     SetFitMeanWOn()                                           { fFitMeanWOn     = kTRUE;        }
96           void     SetFitChargeNDB(Int_t fitChargeNDB);
97           void     SetAccCDB()                                               { fAccCDB         = kTRUE;        }
98           void     SetMinEntries(Int_t minEntries)                           { fMinEntries     = minEntries;   }
99           void     SetRebin(Short_t rebin);
100   
101           Bool_t   GetFitPHOn() const                                        { return fFitPHOn;                }
102           Bool_t   GetFitPol2On() const                                      { return fFitPol2On;              }
103           Bool_t   GetFitLagrPolOn() const                                   { return fFitLagrPolOn;           }
104           Bool_t   GetTakeTheMaxPH() const                                   { return fTakeTheMaxPH;           }
105           Int_t    GetPeriodeFitPH() const                                   { return fFitPHPeriode;           }
106           Int_t    GetFitPHNDB() const                                       { return fFitPHNDB;               }
107           Float_t  GetBeginFitCharge() const                                 { return fBeginFitCharge;         }
108           Float_t  GetT0Shift() const                                        { return fT0Shift;                }
109           Float_t  GetRangeFitPRF() const                                    { return fRangeFitPRF;            }
110           Bool_t   GetFitPRFOn() const                                       { return fFitPRFOn;               }
111           Bool_t   GetRMSPRFOn() const                                       { return fRMSPRFOn;               }
112           Int_t    GetFitPRFNDB() const                                      { return fFitPRFNDB;              }
113           Bool_t   GetMeanChargeOn() const                                   { return fMeanChargeOn;           }
114           Bool_t   GetFitChargeBisOn() const                                 { return fFitChargeBisOn;         }
115           Bool_t   GetFitChargeOn() const                                    { return fFitChargeOn;            }
116           Bool_t   GetFitMeanWOn() const                                     { return fFitMeanWOn;             }
117           Int_t    GetFitChargeNDB() const                                   { return fFitChargeNDB;           }
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     SetDebug(Short_t debug)                                   { fDebug   = debug;               }
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   
136           Short_t  GetDebug() const                                          { return fDebug;                  }
137           Int_t    GetDet(Int_t i) const                                     { return fDet[i];                 }
138           Int_t    GetFitVoir() const                                        { return fFitVoir;                }
139
140   // calibration mode
141           void     SetCalibraMode(AliTRDCalibraMode *calibramode)            { fCalibraMode = calibramode;     }
142 AliTRDCalibraMode  *GetCalibraMode() const                                   { return fCalibraMode;            }
143
144  
145   // Getter for the coefficient trees 
146           TTree   *GetPRF() const                                            { return fPRF;                    }
147           TTree   *GetGain() const                                           { return fGain;                   }
148           TTree   *GetT0() const                                             { return fT0;                     }
149           TTree   *GetVdrift() const                                         { return fVdrift;                 }
150
151   // Vector method
152                void  SetCalibraVector(AliTRDCalibraVector *calibraVector)    { fCalibraVector = calibraVector; }
153 AliTRDCalibraVector *GetCalibraVector() const                                { return fCalibraVector;          }
154           
155
156  private:
157   
158   static  Double_t PH(Double_t *x, Double_t *par);
159   static  Double_t AsymmGauss(Double_t *x, Double_t *par);
160   static  Double_t FuncLandauGaus(Double_t *x, Double_t *par);
161   static  Double_t LanGauFun(Double_t *x, Double_t *par);
162           TF1     *LanGauFit(TH1 *his, Double_t *fitrange, Double_t *startvalues
163                            , Double_t *parlimitslo, Double_t *parlimitshi, Double_t *fitparams
164                            , Double_t *fiterrors, Double_t *chiSqr, Int_t *ndf);
165           Int_t    LanGauPro(Double_t *params, Double_t &maxx, Double_t &fwhm);
166           Double_t *CalculPolynomeLagrange2(Double_t *x, Double_t *y);
167           Double_t *CalculPolynomeLagrange3(Double_t *x, Double_t *y);
168           Double_t *CalculPolynomeLagrange4(Double_t *x, Double_t *y);
169   static  Double_t GausConstant(Double_t *x, Double_t *par); 
170   
171   // This is a singleton, contructor is private!
172   AliTRDCalibraFit();
173   virtual ~AliTRDCalibraFit();
174
175  protected:
176
177   // Write
178           Bool_t   fWriteCoef[3];           // Do you want to write the result in a file?
179           TString  fWriteNameCoef;          // Where the coef Det are written
180          
181   // Fit
182           Bool_t   fFitPHOn;                // The fit PH On (0)
183           Bool_t   fFitPol2On;              // The fit Pol2 On (1)
184           Bool_t   fFitLagrPolOn;           // The fit LagrPol On (3)
185           Bool_t   fTakeTheMaxPH;           // Take the Max for the T0 determination
186           Int_t    fFitPHPeriode;           // Periode of the fit PH
187           Int_t    fFitPHNDB;               // To choose which method will be used to fill the database for the PH 
188           Float_t  fBeginFitCharge;         // The fit begins at mean/fBeginFitCharge for the gain calibration
189           Float_t  fT0Shift;                // T0 Shift with the actual method
190           Float_t  fRangeFitPRF;            // The fit range for the PRF is -fRangeFitPRF +fRangeFitPRF
191           Bool_t   fFitPRFOn;               // The fit PRF Gaussian On (0)
192           Bool_t   fRMSPRFOn;               // The RMS PRF On (2)
193           Int_t    fFitPRFNDB;              // To choose which method will be used to fill the database for the PRF
194           Bool_t   fMeanChargeOn;           // Mean Charge on (1)
195           Bool_t   fFitChargeBisOn;         // For an other fit function (convolution, more time consuming)(2)
196           Bool_t   fFitChargeOn;            // For the first fit function (sum of Gaus and Landau) (0)
197           Bool_t   fFitMeanWOn;             // For the Marian Mean W method (4)
198           Int_t    fFitChargeNDB;           // To choose which method will be used to fill the database for the CH 
199           Bool_t   fAccCDB;                 // If there is a calibration database to be compared with....
200           Int_t    fMinEntries;             // Min Entries to fit the histo
201           Short_t  fRebin;                  // If you want to rebin the histo for the gain calibration
202          
203   // Statistics      
204           Int_t    fNumberFit;              // To know how many pad groups have been fitted
205           Int_t    fNumberFitSuccess;       // To know how many pad groups have been fitted successfully
206           Int_t    fNumberEnt;              // To know how many pad groups have entries in the histo
207           Double_t fStatisticMean;          // To know the mean statistic of the histos
208
209   // Debug Mode
210           Short_t  fDebug;                  // For debugging 0 rien, 1 errors, 2 one fit alone, 3 one detector, 4 one detector with errors
211           Int_t    fDet[3];                 // Detector  visualised (plane,chamb,sect) si debugging == 3 or 4
212           Int_t    fFitVoir;                // Fit visualised si debugging == 2
213   
214   // Calibration mode
215
216           AliTRDCalibraMode *fCalibraMode;  // The calibration mode
217
218   // The coefficients trees
219
220           TTree   *fPRF;                    // Tree of the sigma of PRD
221           TTree   *fGain;                   // Tree of the gain factor
222           TTree   *fT0;                     // Tree of the time0
223           TTree   *fVdrift;                 // Tree of the drift velocity
224
225   // "Pointer" of the branch of the tree
226           Int_t    fVdriftDetector;         // Branch of Vdrift
227           Float_t *fVdriftPad;              // Branch of Vdrift
228           Int_t    fT0Detector;             // Branch of t0
229           Float_t *fT0Pad;                  // Branch of t0
230           Int_t    fPRFDetector;            // Branch of PRF
231           Float_t *fPRFPad;                 // Branch of PRF
232           Float_t *fCoefCH;                 // Branch relative gain
233  
234   //
235   // For debugging 
236   //
237
238   // To build the graph with the errors of the fits
239           Double_t        *fCoefCharge[5];   // Coefs resulting from the fit for the gain
240           Double_t        *fCoefChargeE[4];  // Error of the found coefs for the gain
241           Double_t        *fCoefVdrift[4];   // Coefs resulting from the fit for the drift velocity
242           Double_t        *fCoefVdriftE[3];  // Error of the found coefs for the drift velocity
243           Double_t        *fCoefT0[4];       // Coefs resulting from the fit for the drift velocity
244           Double_t        *fCoefT0E[3];      // Error of the found coefs for the drift velocity
245           Double_t        *fCoefPRF[3];      // Coefs resulting from the fit for the PRF
246           Double_t        *fCoefPRFE[2];     // Error of the found coefs for the PRF
247           TH2F    *fCoefChargeDB[4];         // Visualisation of the coef of the detecteur fDet for the gain
248           TH2F    *fCoefVdriftDB[3];         // Visualisation of the coef of the detecteur fDet for the drift velocity
249           TH2F    *fCoefT0DB[3];             // Visualisation of the coef of the detecteur fDet for time 0
250           TH2F    *fCoefPRFDB[2];            // Visualisation of the coef of the detecteur fDet for the pad response function
251
252   // Variables in the loop for the coef or more general
253           Float_t  fChargeCoef[5];          // 4 Marian Mean W, 3 database value, 0 fit, 1 mean, 2 fit time consuming   
254           Float_t  fVdriftCoef[4];          // 3 lagrangepoly, 2 database value, 1 slope method, 0 fit
255           Float_t  fPRFCoef[3];             // 2 Rms, 1 database, 0 fit 
256           Float_t  fT0Coef[4];              // 3 lagrangepoly, 2 database, 1 slope method, 0 fit
257           Float_t  fPhd[3];                 // Begin AR and DR
258           Int_t    fDect1[3];               // First calibration group that will be called to be maybe fitted
259           Int_t    fDect2[3];               // Last calibration group that will be called to be maybe fitted
260           Double_t fScaleFitFactor;         // Scale factor of the fit results for the gain
261           Int_t    fEntriesCurrent;         // Entries in the current histo
262           Int_t    fCountDet[3];            // Current detector
263           Int_t    fCount[3];               // When the next detector comes
264  
265   // Vector method
266
267           AliTRDCalibraVector *fCalibraVector; // The vector object
268
269           class AliTRDFitCHInfo : public TObject {
270
271           public:
272             
273             AliTRDFitCHInfo()
274               :TObject()
275               ,fCoef(0x0)
276               ,fDetector(-1)                                   { }    
277             AliTRDFitCHInfo(const AliTRDFitCHInfo &i) 
278               :TObject(i)
279               ,fCoef(0x0)
280               ,fDetector(-1)                                   { }
281             AliTRDFitCHInfo &operator=(const AliTRDFitCHInfo&) { return *this;            }
282             virtual ~AliTRDFitCHInfo()                         { }
283             
284             void      SetCoef(Float_t *coef)                   { fCoef     = coef;        }
285             void      SetDetector(Int_t detector)              { fDetector = detector;    }
286             
287             Float_t  *GetCoef() const                          { return fCoef;            }
288             Int_t     GetDetector() const                      { return fDetector;        }
289             
290           protected:
291             
292             Float_t  *fCoef;                        // Relative gain coefficient for each group of the detector
293             Int_t     fDetector;                    // Detector number
294             
295           };
296
297           TObjArray       *fVectorFitCH;            // Vectors to fit
298   
299   //
300   // A lot of internal functions......
301   //
302
303   // Init AliTRDCalibraFit
304           void     Init();
305     
306   //
307   // Fit
308   //  
309
310   // Create histos if fDebug == 1 or fDebug >=3
311           void     CreateFitHistoPHDB(Int_t rowMax, Int_t colMax);
312           void     CreateFitHistoT0DB(Int_t rowMax, Int_t colMax);
313           void     CreateFitHistoCHDB(Int_t rowMax, Int_t colMax);
314           void     CreateFitHistoPRFDB(Int_t rowMax, Int_t colMax);
315           void     InitArrayFitCH();
316           void     InitArrayFitPH();
317           void     InitArrayFitT0();
318           void     InitArrayFitPRF();
319   
320   // CHFit functions
321           Bool_t   FillVectorFitCH(Int_t countdet);
322           Bool_t   InitFit(Int_t nbins, Int_t i);
323           void     InitfCountDetAndfCount(Int_t i);
324           void     UpdatefCountDetAndfCount(Int_t idect, Int_t i);
325           void     ReconstructFitRowMinRowMax(Int_t idect, Int_t i);
326           Bool_t   NotEnoughStatistic(Int_t idect, Int_t i);
327           Bool_t   FillInfosFit(Int_t idect, Int_t i);
328           Bool_t   WriteFitInfos(Int_t i);
329           void     NormierungCharge();
330
331   // Fill histos DB from the Coef histos 
332           void     FillCoefChargeDB();
333           void     FillCoefVdriftDB();
334           void     FillCoefT0DB();
335           void     FillCoefPRFDB();
336
337   // Plot histos CoefPRF Coef....
338           void     PlotWritePH();
339           void     PlotWriteT0();
340           void     PlotWriteCH();
341           void     PlotWritePRF();
342   
343   // Plot histos DB
344           void     PlotPHDB();
345           void     PlotT0DB();
346           void     PlotCHDB();
347           void     PlotPRFDB();
348   
349   // Write the DB histos
350           void     WritePHDB(TFile *fout);
351           void     WriteT0DB(TFile *fout);
352           void     WriteCHDB(TFile *fout);
353           void     WritePRFDB(TFile *fout);
354
355   // Calculate the mean coefs from the database
356           Bool_t   CalculVdriftCoefMean(Int_t fect, Int_t idect);
357           Bool_t   CalculChargeCoefMean(Int_t fect, Int_t idect, Bool_t vrai);
358           Bool_t   CalculPRFCoefMean(Int_t fect, Int_t idect);
359           Bool_t   CalculT0CoefMean(Int_t fect, Int_t idect);
360           Float_t  GetPRFDefault(Int_t plane) const;
361
362  // Fit methods
363           void     FitBisCH(TH1 *projch, Int_t idect);
364           void     FitCH(TH1 *projch, Int_t idect);
365           void     FitMeanW(TH1 *projch, Int_t idect);
366           void     FitMean(TH1 *projch, Int_t idect, Double_t nentries);
367           void     FitPH(TH1 *projPH, Int_t idect);
368           void     FitPRF(TH1 *projPRF, Int_t idect);
369           void     RmsPRF(TH1 *projPRF, Int_t idect);
370           void     FitPente(TH1 *projPH, Int_t idect);
371           void     FitLagrangePoly(TH1* projPH, Int_t idect);
372           TH1I    *ReBin(TH1I *hist) const;
373           TH1F    *ReBin(TH1F *hist) const;
374   
375   // Clear
376           void     ClearTree();
377
378   // Some basic geometry function
379   virtual Int_t    GetPlane(Int_t d) const;
380   virtual Int_t    GetChamber(Int_t d) const;
381   virtual Int_t    GetSector(Int_t d) const;
382   
383   // Init, Fill and Reset the variables to default value tree Gain, PRF, Vdrift and T0
384           void     InitTreePH();
385           void     FillTreeVdrift(Int_t countdet);
386           void     InitTreeT0();
387           void     FillTreeT0(Int_t countdet);
388           void     InitTreePRF();
389           void     FillTreePRF(Int_t countdet);
390           void     ConvertVectorFitCHTree();
391
392   // Instance of this class and so on
393   static  AliTRDCalibraFit *fgInstance;        // Instance
394   static  Bool_t   fgTerminated;               // If terminated
395     
396   ClassDef(AliTRDCalibraFit,1)                 // TRD Calibration class
397
398 };
399   
400 #endif
401
402