]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibra.h
b2579aa8446e66cf6c931c8eb9c2f68f572b1a26
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibra.h
1 #ifndef ALITRDCALIBRA_H
2 #define ALITRDCALIBRA_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 AliTRDcluster;
31 class AliTRDtrack;
32 class AliTRDmcmTracklet;
33 class AliTRDCalDet;
34
35 class AliTRDCalibra : public TObject {
36
37  public: 
38
39   // Instance
40   static AliTRDCalibra *Instance();
41   static void Terminate();
42   static void Destroy();
43
44   AliTRDCalibra(const AliTRDCalibra &c);
45   AliTRDCalibra &operator=(const AliTRDCalibra &) { return *this; }
46
47   // Functions fit online
48           Bool_t   FitCHOnline(TH2I *ch);
49           Bool_t   FitCHOnline();
50           Bool_t   FitCHOnline(TTree *tree);
51           Bool_t   FitPHOnline(TProfile2D *ph);
52           Bool_t   FitPHOnline();
53           Bool_t   FitPHOnline(TTree *tree);
54           Bool_t   FitPRFOnline(TProfile2D *prf);
55           Bool_t   FitPRFOnline();
56           Bool_t   FitPRFOnline(TTree *tree);
57  
58   // Functions for initialising the AliTRDCalibra in the code
59           Bool_t   Init2Dhistos();
60
61   // Functions for filling the histos in the code
62           Bool_t   ResetTrack();
63           Bool_t   UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *t);
64           Bool_t   UpdateHistogramcm(AliTRDmcmTracklet *trk);
65  
66   // Is Pad on
67           Bool_t   IsPadOn(Int_t detector, Int_t col, Int_t row) const;
68
69   // Functions for plotting the 2D
70           void     Plot2d();
71
72   // Functions for writting the 2D
73           Bool_t   Write2d();
74
75   // Function fill 2D for the moment out of the code
76           Bool_t   Create2DDiSimOnline(Int_t iev1, Int_t iev2);
77           Bool_t   Create2DRaDaOnline(Int_t iev1, Int_t iev2);
78
79   // Pad Calibration
80           Bool_t   ModePadFragmentation(Int_t iPlane,Int_t iChamb, Int_t iSect, Int_t i);
81           void     ModePadCalibration(Int_t iChamb, Int_t i);
82           Bool_t   SetModeCalibrationFromTObject(TObject *object, Int_t i);
83
84   // Fill the database
85   TObject         *CreatePadObjectTree(TTree *tree);
86   TObject         *CreatePadObjectTree(TTree *tree, Int_t i, AliTRDCalDet *detobject);
87   AliTRDCalDet    *CreateDetObjectTree(TTree *tree, Int_t i);
88
89   // Correct the error
90   TH1F            *CorrectTheError(TGraphErrors *hist);
91   TGraphErrors    *AddProfiles(TGraphErrors *hist1, TGraphErrors *hist2) const ;
92
93   // Add two trees
94   TTree           *Sum2Trees(const Char_t *filename1, const Char_t *filename2, const Char_t *variablecali);
95   
96   //
97   // Set of Get the variables
98   //
99
100   // Choice to fill or not the 2D
101           void     SetMITracking(Bool_t mitracking = kTRUE)                  { fMITracking      = mitracking;  }
102           void     SetMcmTracking(Bool_t mcmtracking = kTRUE)                { fMcmTracking     = mcmtracking;  }
103           void     SetMcmCorrectAngle()                                      { fMcmCorrectAngle = kTRUE; }
104           void     SetPH2dOn()                                               { fPH2dOn          = kTRUE; }
105           void     SetCH2dOn()                                               { fCH2dOn          = kTRUE; }
106           void     SetPRF2dOn()                                              { fPRF2dOn         = kTRUE; }
107           void     SetHisto2d()                                              { fHisto2d         = kTRUE; }
108           void     SetVector2d()                                             { fVector2d        = kTRUE; }
109   
110           Bool_t   GetMITracking() const                                     { return fMITracking;       }
111           Bool_t   GetMcmTracking() const                                    { return fMcmTracking;      }
112           Bool_t   GetMcmCorrectAngle() const                                { return fMcmCorrectAngle;  }
113           Bool_t   GetPH2dOn() const                                         { return fPH2dOn;           }
114           Bool_t   GetCH2dOn() const                                         { return fCH2dOn;           }
115           Bool_t   GetPRF2dOn() const                                        { return fPRF2dOn;          }
116           Bool_t   GetHisto2d() const                                        { return fHisto2d;          }
117           Bool_t   GetVector2d() const                                       { return fVector2d;         }
118   TH2I            *GetCH2d() const                                           { return fCH2d;             }
119   TProfile2D      *GetPH2d() const                                           { return fPH2d;             }
120   TProfile2D      *GetPRF2d() const                                          { return fPRF2d;            }
121   
122   // How to fill the 2D
123           void     SetRelativeScaleAuto()                                    { fRelativeScaleAuto    = kTRUE;                      }
124           void     SetRelativeScale(Float_t relativeScale);                      
125           void     SetThresholdDigit(Int_t digitthreshold)                   { fThresholdDigit       = digitthreshold;             }
126           void     SetThresholdClusterPRF1(Float_t thresholdClusterPRF1)     { fThresholdClusterPRF1 = thresholdClusterPRF1;       }
127           void     SetThresholdClusterPRF2(Float_t thresholdClusterPRF2)     { fThresholdClusterPRF2 = thresholdClusterPRF2;       }
128           void     SetCenterOfflineCluster()                                 { fCenterOfflineCluster = kTRUE;                      }
129           void     SetTraMaxPad()                                            { fTraMaxPad            = kTRUE;                      }
130           void     SetNz(Int_t i, Short_t nz);
131           void     SetNrphi(Int_t i, Short_t nrphi);
132           void     SetProcent(Float_t procent)                               { fProcent              = procent;                    }
133           void     SetDifference(Short_t difference)                         { fDifference           = difference;                 }
134           void     SetNumberClusters(Short_t numberClusters)                 { fNumberClusters       = numberClusters;             }
135           void     SetNumberBinCharge(Short_t numberBinCharge)               { fNumberBinCharge      = numberBinCharge;            }
136           void     SetNumberBinPRF(Short_t numberBinPRF)                     { fNumberBinPRF         = numberBinPRF;               }
137   
138           Float_t  GetRelativeScale() const                                  { return fRelativeScale;        }
139           Bool_t   GetRelativeScaleAuto() const                              { return fRelativeScaleAuto;    }
140           Int_t    GetThresholdDigit() const                                 { return fThresholdDigit;       }
141           Float_t  GetThresholdClusterPRF1() const                           { return fThresholdClusterPRF1; }
142           Float_t  GetThresholdClusterPRF2() const                           { return fThresholdClusterPRF2; }
143           Bool_t   GetTraMaxPad()const                                       { return fTraMaxPad;            }
144           Short_t  GetNz(Int_t i) const                                      { return fNz[i];                }
145           Short_t  GetNrphi(Int_t i) const                                   { return fNrphi[i];             }
146           Float_t  GetProcent() const                                        { return fProcent;              }
147           Short_t  GetDifference() const                                     { return fDifference;           }
148           Short_t  GetNumberClusters() const                                 { return fNumberClusters;       }
149           Short_t  GetNumberBinCharge() const                                { return fNumberBinCharge;      }
150           Short_t  GetNumberBinPRF() const                                   { return fNumberBinPRF;         }
151   
152   // Write
153           void     SetWriteCoef(Int_t i)                                     { fWriteCoef[i]  = kTRUE;         }
154           void     SetWriteNameCoef(TString writeNameCoef)                   { fWriteNameCoef = writeNameCoef; }
155           void     SetWrite(Int_t i)                                         { fWrite[i]      = kTRUE;         }
156           void     SetWriteName(TString writeName)                           { fWriteName     = writeName;     }
157   
158           Bool_t   GetWriteCoef(Int_t i) const                               { return fWriteCoef[i];           }
159           TString  GetWriteNameCoef() const                                  { return fWriteNameCoef;          }
160           Bool_t   GetWrite(Int_t i) const                                   { return fWrite[i];               }
161           TString  GetWriteName() const                                      { return fWriteName;              }
162   
163   // Fit
164           void     SetFitPHOn()                                              { fFitPHOn        = kTRUE;}
165           void     SetPeriodeFitPH(Int_t periodeFitPH);   
166           void     SetBeginFitCharge(Float_t beginFitCharge);     
167           void     SetT0Shift(Float_t t0Shift); 
168           void     SetRangeFitPRF(Float_t rangeFitPRF);       
169           void     SetMeanChargeOn()                                         { fMeanChargeOn   = kTRUE;      }
170           void     SetAccCDB()                                               { fAccCDB         = kTRUE;      }
171           void     SetFitChargeBisOn()                                       { fFitChargeBisOn = kTRUE;      }
172           void     SetMinEntries(Int_t minEntries)                           { fMinEntries     = minEntries; }
173   
174           Bool_t   GetFitPHOn() const                                        { return fFitPHOn;        }
175           Int_t    GetPeriodeFitPH() const                                   { return fFitPHPeriode;   }
176           Float_t  GetBeginFitCharge() const                                 { return fBeginFitCharge; }
177           Float_t  GetT0Shift() const                                        { return fT0Shift;        }
178           Float_t  GetRangeFitPRF() const                                    { return fRangeFitPRF;    }
179           Bool_t   GetMeanChargeOn() const                                   { return fMeanChargeOn;   }
180           Bool_t   GetAccCDB() const                                         { return fAccCDB;         }
181           Bool_t   GetFitChargeBisOn() const                                 { return fFitChargeBisOn; }
182           Int_t    GetMinEntries() const                                     { return fMinEntries;     }
183           Int_t    GetNumberFit() const                                      { return fNumberFit;      }
184           Double_t GetStatisticMean() const                                  { return fStatisticMean;  }
185   
186   // Debug
187           void     SetDebug(Short_t debug)                                   { fDebug   = debug;   }
188           void     SetDet(Int_t iPlane, Int_t iChamb, Int_t iSect)           { fDet[0]  = iPlane; 
189                                                                                fDet[1]  = iChamb; 
190                                                                                fDet[2]  = iSect;   }
191           void     SetFitVoir(Int_t fitVoir)                                 { fFitVoir = fitVoir; }
192   
193           Short_t  GetDebug() const                                          { return fDebug;      }
194           Int_t    GetDet(Int_t i) const                                     { return fDet[i];     }
195           Int_t    GetFitVoir() const                                        { return fFitVoir;    }
196
197   //
198   // Internal variables to be sure!
199   //
200   
201   // Pad calibration
202           Short_t  GetNnz(Int_t i) const                                     { return fNnZ[i];       }
203           Short_t  GetNnrphi(Int_t i) const                                  { return fNnRphi[i];    }
204           Short_t  GetNfragz(Int_t i) const                                  { return fNfragZ[i];    }
205           Short_t  GetNfragrphi(Int_t i) const                               { return fNfragRphi[i]; }
206           Short_t  GetDetChamb0(Int_t i) const                               { return fDetChamb0[i]; }
207           Short_t  GetDetChamb2(Int_t i) const                               { return fDetChamb2[i]; }
208     
209           void     SetRebin(Short_t rebin);
210           Short_t  GetRebin() const                                          { return fRebin;        }
211
212   // Getter for the coefficient trees 
213           TTree   *GetPRF() const                                            { return fPRF;          }
214           TTree   *GetGain() const                                           { return fGain;         }
215           TTree   *GetT0() const                                             { return fT0;           }
216           TTree   *GetVdrift() const                                         { return fVdrift;       }
217
218  private:
219   
220   static  Double_t PH(Double_t *x, Double_t *par);
221   static  Double_t AsymmGauss(Double_t *x, Double_t *par);
222   static  Double_t FuncLandauGaus(Double_t *x, Double_t *par);
223   static  Double_t LanGauFun(Double_t *x, Double_t *par);
224           TF1     *LanGauFit(TH1 *his, Double_t *fitrange, Double_t *startvalues
225                            , Double_t *parlimitslo, Double_t *parlimitshi, Double_t *fitparams
226                            , Double_t *fiterrors, Double_t *chiSqr, Int_t *ndf);
227           Int_t    LanGauPro(Double_t *params, Double_t &maxx, Double_t &fwhm); 
228   
229   // This is a singleton, contructor is private!
230   AliTRDCalibra();
231   virtual ~AliTRDCalibra();
232
233  protected:
234
235   // Choice to fill or not the 2D
236           Bool_t   fMITracking;             // Chose to fill the 2D histos or vectors during the offline MI tracking
237           Bool_t   fMcmTracking;            // Chose to fill the 2D histos or vectors during the tracking with tracklets
238           Bool_t   fMcmCorrectAngle;        // Apply correction due to the mcmtrackletangle in the z direction (only) assuming  from vertex
239           Bool_t   fCH2dOn;                 // Chose to fill the 2D histos or vectors for the relative gain calibration 
240           Bool_t   fPH2dOn;                 // Chose to fill the 2D histos or vectors for the drift velocity and T0
241           Bool_t   fPRF2dOn;                // Chose to fill the 2D histos or vectors for the pad response function calibration
242           Bool_t   fHisto2d;                // Chose to fill the 2D histos
243           Bool_t   fVector2d;               // Chose to fill vectors
244
245   // How to fill the 2D
246           Float_t  fRelativeScale;          // Scale of the deposited charge
247           Int_t    fCountRelativeScale;     // fCountRelativeScale first data used for the scaling
248           Bool_t   fRelativeScaleAuto;      // Scaling with the first fCountRelativeScale objects
249           Int_t    fThresholdDigit;         // Threshold on RawData
250           Float_t  fThresholdClusterPRF1;   // Threshold on cluster pad signals for PRF peripherique
251           Float_t  fThresholdClusterPRF2;   // Threshold on cluster pad signals for PRF peripherique
252           Bool_t   fCenterOfflineCluster;   // Choose to use the offline determination of the center of the cluster
253           Bool_t   fTraMaxPad;              // Take the Max Pad for the gain calibration and PH
254           Short_t  fNz[3];                  // Mode of calibration 
255           Short_t  fNrphi[3];               // Mode of calibration 
256           Int_t    fNtotal[3];              // Total number of Xbins
257
258   // Write
259           Bool_t   fWriteCoef[3];           // Do you want to write the result in a file?
260           TString  fWriteNameCoef;          // Where the coef Det are written
261           Bool_t   fWrite[3];               // Do you want to write the 2D histo or vectors converted in a tree
262           TString  fWriteName;              // Where the 2D or trees are written
263   
264   // Fit
265           Bool_t   fFitPHOn;                // The fit PH On
266           Int_t    fFitPHPeriode;           // Periode of the fit PH
267           Float_t  fBeginFitCharge;         // The fit begins at mean/fBeginFitCharge for the gain calibration
268           Float_t  fRangeFitPRF;            // The fit range for the PRF is -fRangeFitPRF +fRangeFitPRF
269           Bool_t   fMeanChargeOn;           // Mean Charge on
270           Bool_t   fFitChargeBisOn;         // For an other fit function (convolution and not sum, more time consuming)
271           Float_t  fT0Shift;                // T0 Shift with the actual method
272           Bool_t   fAccCDB;                 // If there is a calibration database to be compared with....
273           Int_t    fNumberFit;              // To know how many pad groups have been fitted
274           Double_t fStatisticMean;          // To know the mean statistic of the histos
275
276   // Debug Mode
277           Short_t  fDebug;                  // For debugging 0 rien, 1 errors, 2 one fit alone, 3 one detector, 4 one detector with errors
278           Int_t    fDet[3];                 // Detector  visualised (plane,chamb,sect) si debugging == 3 or 4
279           Int_t    fFitVoir;                // Fit visualised si debugging == 2
280   
281   //
282   // Internal variables
283   //
284
285   // Storage of coef
286           TTree   *fPRF;                    // Tree of the sigma of PRD
287           TTree   *fGain;                   // Tree of the gain factor
288           TTree   *fT0;                     // Tree of the time0
289           TTree   *fVdrift;                 // Tree of the drift velocity
290
291   // "Pointer" of the branch of the tree
292           Int_t    fVdriftDetector;         // Branch of Vdrift
293           Float_t *fVdriftPad;              // Branch of Vdrift
294           Int_t    fT0Detector;             // Branch of t0
295           Float_t *fT0Pad;                  // Branch of t0
296           Int_t    fPRFDetector;            // Branch of PRF
297           Float_t *fPRFPad;                 // Branch of PRF
298           Float_t *fCoefCH;                 // Branch relative gain
299   
300   // Fill the 2D histos in the offline tracking
301           Bool_t   fDetectorAliTRDtrack;    // Change of track
302           Int_t    fChamberAliTRDtrack;     // Change of chamber
303           Int_t    fDetectorPreviousTrack;  // Change of detector
304           Bool_t   fGoodTrack;              // If goes through a kaputt pad
305           Float_t *fAmpTotal;               // Energy deposited in the calibration group by the track
306           Short_t *fPHPlace;                // Calibration group of PH
307           Float_t *fPHValue;                // PH
308           Short_t  fNumberClusters;         // Minimum number of clusters in the tracklets
309           Float_t  fProcent;                // Limit to take the info of the most important calibration group if the track goes through 2 groups (CH)
310           Short_t  fDifference;             // Limit to take the info of the most important calibration group if the track goes through 2 groups (CH)
311           Int_t    fNumberTrack;            // How many tracks could be used (Debug for the moment)
312           Int_t    fNumberUsedCh[2];        // How many tracks have been really used for the gain (0, strict; 1 with fProcent)
313           Int_t    fNumberUsedPh[2];        // How many tracks have been really used for the drift velocity (0, strict; 1 with fDifference)
314
315   //
316   // For debugging 
317   //
318
319   // Histograms to store the coef
320           TH1F    *fCoefCharge[4];          // Replica des 2D but in coefs resulting from the fit for the gain
321           TH1F    *fCoefVdrift[3];          // Replica des 2D but in coefs resulting from the fit for the drift velocity
322           TH1F    *fCoefPRF[2];             // Replica des 2D but in coefs resulting from the fit for the pad response function
323           TH1F    *fCoefT0[3];              // Replica des 2D but in coefs resulting from the fit for time 0
324           TH1F    *fDeltaCharge[3];         // Replica des 2D but in errors for each detector resulting from the fit for the gain
325           TH1F    *fDeltaVdrift[2];         // Replica des 2D but in errors for each detector resulting from the fit for the drift velocity
326           TH1F    *fDeltaT0[2];             // Replica des 2D but in errors for each detector resulting from the fit for time 0
327           TH1F    *fDeltaPRF;               // Replica des 2D but in errors for each detector resulting from the fit for the pad response function
328           TH1I    *fErrorCharge[3];         // Replica des 2D but in errors resulting from the fit for the gain
329           TH1I    *fErrorVdrift[2];         // Replica des 2D but in errors resulting from the fit for the drift velocity
330           TH1I    *fErrorT0[2];             // Replica des 2D but in errors resulting from the fit for time 0
331           TH1I    *fErrorPRF;               // Replica des 2D but in errors resulting from the fit for the pad response function
332           TH2F    *fCoefChargeDB[3];        // Visualisation of the coef of the detecteur fDet for the gain
333           TH2F    *fCoefVdriftDB[2];        // Visualisation of the coef of the detecteur fDet for the drift velocity
334           TH2F    *fCoefT0DB[2];            // Visualisation of the coef of the detecteur fDet for time 0
335           TH2F    *fCoefPRFDB;              // Visualisation of the coef of the detecteur fDet for the pad response function
336
337   // Variables in the loop for the coef or more general
338           Float_t  fChargeCoef[4];          // 3 database value, 0 fit, 1 mean, 2 fit time consuming   
339           Float_t  fVdriftCoef[3];          // 2 database value, 1 slope method, 0 fit
340           Float_t  fPRFCoef[2];             // 1 database, 0 fit 
341           Float_t  fT0Coef[3];              // 3 database, 1 slope method, 0 fit
342           Float_t  fPhd[3];                 // Begin AR and DR
343           Int_t    fTimeMax;                // Number of time bins
344           Float_t  fSf;                     // Sampling frequence
345           Int_t    fDect1[3];               // First calibration group that will be called to be maybe fitted
346           Int_t    fDect2[3];               // Last calibration group that will be called to be maybe fitted
347           Double_t fScaleFitFactor;         // Scale factor of the fit results for the gain
348           Int_t    fMinEntries;             // Min Entries to fit the histo
349           Int_t    fEntriesCurrent;         // Entries in the current histo
350           Int_t    fCountDet[3];            // Current detector
351           Int_t    fCount[3];               // When the next detector comes
352           Float_t  fL3P0;                   // Parameter to be pass from the default fit of CH histo to the optional one
353           Float_t  fL3P2;                   // Parameter to be pass from the default fit of CH histo to the optional one
354           Float_t  fG3P2;                   // Parameter to be pass from the default fit of CH histo to the optional one
355
356   // Pad Calibration
357           Short_t  fNnZ[3];                 // Number of pad rows in a group
358           Short_t  fNnRphi[3];              // Number of pad cols in a group
359           Short_t  fNfragZ[3];              // Number of  pad row group
360           Short_t  fNfragRphi[3];           // Number of pad col group
361           Short_t  fRowMin[3];              // Limits of the group in pad row
362           Short_t  fRowMax[3];              // Limits of the group in pad row
363           Short_t  fColMin[3];              // Limits of the group in pad col
364           Short_t  fColMax[3];              // Limits of the group in pad col
365           Int_t    fXbins[3];               // First Xbins of the detector
366           Short_t  fDetChamb0[3];           // Number of XBins for chamber != 2
367           Short_t  fDetChamb2[3];           // Number of Xbins fir chamber 2
368   
369   // Methode  Alexandru store info
370   class AliTRDPlace : public TObject {
371
372    public: 
373     
374     AliTRDPlace()
375       :TObject()
376       ,fPlace(0x0)                                     { }
377     AliTRDPlace(const AliTRDPlace &i)
378       :TObject(i)
379       ,fPlace(0x0)                                     { }
380     AliTRDPlace &operator=(const AliTRDPlace&)         { return *this;            } 
381     virtual ~AliTRDPlace()                             { }
382     
383     void      SetPlace(Int_t place)                    { fPlace = place;          }
384     Int_t     GetPlace() const                         { return  fPlace;          }
385     
386   protected:
387     
388     Int_t     fPlace;                       // Place of the calibration group
389
390   };
391   
392   class AliTRDCTInfo : public TObject {
393
394    public: 
395     
396     AliTRDCTInfo()
397       :TObject()
398       ,fEntries(0x0)                                   { }
399     AliTRDCTInfo(const AliTRDCTInfo &i)
400       :TObject(i)
401       ,fEntries(0x0)                                   { }
402     AliTRDCTInfo &operator=(const AliTRDCTInfo&)       { return *this;            } 
403     virtual ~AliTRDCTInfo()                            { }
404     
405     void      SetEntries(UShort_t *entries)            { fEntries = entries;      }
406
407     UShort_t *GetEntries() const                       { return fEntries;         }
408     
409   protected:
410     
411     UShort_t *fEntries;                     // Current number of entries for each bin of CH
412
413   };
414
415   class AliTRDFitCHInfo : public TObject {
416
417    public:
418     
419     AliTRDFitCHInfo()
420       :TObject()
421       ,fCoef(0x0)
422       ,fDetector(-1)                                   { }    
423     AliTRDFitCHInfo(const AliTRDFitCHInfo &i) 
424       :TObject(i)
425       ,fCoef(0x0)
426       ,fDetector(-1)                                   { }
427     AliTRDFitCHInfo &operator=(const AliTRDFitCHInfo&) { return *this;            }
428     virtual ~AliTRDFitCHInfo()                         { }
429     
430     void      SetCoef(Float_t *coef)                   { fCoef     = coef;        }
431     void      SetDetector(Int_t detector)              { fDetector = detector;    }
432
433     Float_t  *GetCoef() const                          { return fCoef;            }
434     Int_t     GetDetector() const                      { return fDetector;        }
435     
436   protected:
437     
438     Float_t  *fCoef;                        // Relative gain coefficient for each group of the detector
439     Int_t     fDetector;                    // Detector number
440
441   };
442   
443   class AliTRDPInfo : public TObject {
444   public:
445     
446     AliTRDPInfo()
447       :TObject()
448       ,fSum(0x0) 
449       ,fSumSquare(0x0)
450       ,fEntries(0x0)                                   { }
451     AliTRDPInfo(const AliTRDPInfo &i)
452       :TObject(i)
453       ,fSum(0x0) 
454       ,fSumSquare(0x0)
455       ,fEntries(0x0)                                   { } 
456     AliTRDPInfo &operator=(const AliTRDPInfo&)         { return *this;            }
457     virtual ~AliTRDPInfo()                             { }
458     
459     void      SetSum(Float_t *sum)                     { fSum       = sum;        }
460     void      SetSumSquare(Float_t *sumSquare)         { fSumSquare = sumSquare;  }
461     void      SetEntries(UShort_t *entries)            { fEntries   = entries;    }
462     
463     Float_t  *GetSum() const                           { return fSum;             }
464     Float_t  *GetSumSquare() const                     { return fSumSquare;       }
465     UShort_t *GetEntries() const                       { return fEntries;         }
466     
467   protected:
468
469     Float_t  *fSum;                         // Current mean for each bin of the average pulse height
470     Float_t  *fSumSquare;                   // Current mean of square values for each bin of the average pulse height
471     UShort_t *fEntries;                     // Current number of entries for each bin of the average pulse height
472
473   }; 
474    
475   // PH
476   // fTimeMax will define the size of fcharge
477   TObjArray       *fVectorPH;               // Vectors to fill
478   TObjArray       *fPlaPH;                  // Vectors to fill
479   // CH
480           Short_t  fNumberBinCharge;        // Number of bins for the gain factor
481   TObjArray       *fVectorCH;               // Vectors to fill
482   TObjArray       *fPlaCH;                  // Vectors to fill
483   // FitCH
484   TObjArray       *fVectorFitCH;            // Vectors to fit
485   // PRF
486   Short_t          fNumberBinPRF;           // Number of bin for the PRF
487   TObjArray       *fVectorPRF;              // Vectors to fill
488   TObjArray       *fPlaPRF;                 // Vectors to fill
489  
490   // Histograms to store the info from the digits, from the tracklets or from the tracks
491   TProfile2D      *fPH2d;                   // 2D average pulse height
492   TProfile2D      *fPRF2d;                  // 2D PRF
493   TH2I            *fCH2d;                   // 2D deposited charge 
494           Short_t  fRebin;                  // If you want to rebin the histo for the gain calibration
495   
496   //
497   // A lot of internal functions......
498   //
499
500   // Init AliTRDCalibra
501           void     Init();
502
503   // Create the 2D histo to be filled Online
504           void     CreateCH2d(Int_t nn);
505           void     CreatePH2d(Int_t nn);
506           void     CreatePRF2d(Int_t nn);  
507   
508   // Fill the 2D
509           void     FillTheInfoOfTheTrackPH();
510           void     FillTheInfoOfTheTrackCH();
511           void     ResetfVariables();
512           Bool_t   LocalisationDetectorXbins(Int_t detector);
513  
514   // Plot the 2D
515           void     PlotCH2d();
516           void     PlotPH2d();
517           void     PlotPRF2d();
518     
519   //
520   // Fit
521   //  
522
523   // Create histos if fDebug == 1 or fDebug >=3
524           void     CreateFitHistoPHDB(Int_t rowMax, Int_t colMax);
525           void     CreateFitHistoT0DB(Int_t rowMax, Int_t colMax);
526           void     CreateFitHistoCHDB(Int_t rowMax, Int_t colMax);
527           void     CreateFitHistoPRFDB(Int_t rowMax, Int_t colMax);
528           void     CreateFitHistoCH(Int_t nbins, Double_t low, Double_t high);
529           void     CreateFitHistoPH(Int_t nbins, Double_t low, Double_t high);
530           void     CreateFitHistoT0(Int_t nbins, Double_t low, Double_t high);
531           void     CreateFitHistoPRF(Int_t nbins, Double_t low, Double_t high);
532   
533   // CHFit functions
534           Bool_t   FillVectorFitCH(Int_t countdet);
535           Bool_t   InitFit(Int_t nbins, Double_t lowedge, Double_t upedge, Int_t i);
536           void     InitfCountDetAndfCount(Int_t i);
537           void     UpdatefCountDetAndfCount(Int_t idect, Int_t i);
538           void     ReconstructFitRowMinRowMax(Int_t idect, Int_t i);
539           Bool_t   NotEnoughStatistic(Int_t idect, Int_t i);
540           Bool_t   FillInfosFit(Int_t idect, Int_t i);
541           Bool_t   WriteFitInfos(Int_t i);
542           void     NormierungCharge();
543
544   // Fill histos Errors from the delta histos
545           void     ErrorPH();
546           void     ErrorT0();
547           void     ErrorCH();
548           void     ErrorPRF();
549
550   // Fill histos DB from the Coef histos 
551           void     FillCoefChargeDB();
552           void     FillCoefVdriftDB();
553           void     FillCoefT0DB();
554           void     FillCoefPRFDB();
555
556   // Plot histos CoefPRF Coef....
557           void     PlotPH();
558           void     PlotT0();
559           void     PlotCH();
560           void     PlotPRF();
561   
562   // Plot histos DB
563           void     PlotPHDB();
564           void     PlotT0DB();
565           void     PlotCHDB();
566           void     PlotPRFDB();
567
568   // Write the Coef, delta and error histos
569           void     WritePH(TFile *fout);
570           void     WriteT0(TFile *fout);
571           void     WriteCH(TFile *fout);
572           void     WritePRF(TFile *fout);
573     
574   // Write the DB histos
575           void     WritePHDB(TFile *fout);
576           void     WriteT0DB(TFile *fout);
577           void     WriteCHDB(TFile *fout);
578           void     WritePRFDB(TFile *fout);
579
580   // Calculate the mean coefs from the database
581           Bool_t   CalculVdriftCoefMean(Int_t fect, Int_t idect);
582           Bool_t   CalculChargeCoefMean(Int_t fect, Int_t idect, Bool_t vrai);
583           Bool_t   CalculPRFCoefMean(Int_t fect, Int_t idect);
584           Bool_t   CalculT0CoefMean(Int_t fect, Int_t idect);
585           Float_t  GetPRFDefault(Int_t plane) const;
586
587   // Pad group calibration mode
588           void     ReconstructionRowPadGroup(Int_t idect, Int_t i);
589           void     CalculXBins(Int_t idect, Int_t i);  
590
591   // Convertion vector, tree, histos....
592           Int_t    SearchInVector(Int_t group, Int_t i) const;
593           Int_t    SearchInTreeVector (TObjArray *vectorplace, Int_t group) const;
594           Int_t    SearchBin (Float_t value, Int_t i) const;
595           Bool_t   UpdateVectorCH(Int_t group, Float_t value);
596           Bool_t   UpdateVectorPRF(Int_t group, Float_t x, Float_t y);
597           Bool_t   UpdateVectorPH(Int_t group, Int_t time, Float_t value);
598           Bool_t   UpdateVectorT0(Int_t group, Int_t time);
599   TGraphErrors    *ConvertVectorPHisto(AliTRDPInfo *pInfo, const Char_t *name) const;
600           TH1F    *ConvertVectorCTHisto(AliTRDCTInfo *cTInfo, const Char_t *name) const;
601           TTree   *ConvertVectorCTTreeHisto(TObjArray *vVectorCT, TObjArray *pPlaCT, const Char_t *name, const Char_t *nametitle) const;
602           TTree   *ConvertVectorPTreeHisto(TObjArray *vVectorP, TObjArray *pPlaP, const Char_t *name, const Char_t *nametitle) const;
603   TObjArray       *ConvertTreeVector(TTree *tree) const ;
604           Bool_t   MergeVectorCT(TObjArray *vVectorCT2, TObjArray *pPlaCT2);
605           Bool_t   MergeVectorP(TObjArray *vVectorP2, TObjArray *pPlaP2, Int_t i);
606
607   // Fit methods
608           void     FitBisCH(TH1 *projch, Int_t idect);
609           void     FitCH(TH1 *projch, Int_t idect);
610           void     FitPH(TH1 *projPH, Int_t idect);
611           void     FitPRF(TH1 *projPRF, Int_t idect);
612           void     FitPente(TH1 *projPH, Int_t idect);
613           TH1I    *ReBin(TH1I *hist) const;
614           TH1F    *ReBin(TH1F *hist) const;
615   
616   // Clear
617           void     ClearHistos();
618           void     ClearTree();
619
620   // Some basic geometry function
621   virtual Int_t    GetPlane(Int_t d) const;
622   virtual Int_t    GetChamber(Int_t d) const;
623   virtual Int_t    GetSector(Int_t d) const;
624   
625   // Init, Fill and Reset the variables to default value tree Gain, PRF, Vdrift and T0
626           void     InitTreePH();
627           void     FillTreeVdrift(Int_t countdet);
628           void     InitTreeT0();
629           void     FillTreeT0(Int_t countdet);
630           void     InitTreePRF();
631           void     FillTreePRF(Int_t countdet);
632           void     ConvertVectorFitCHTree();
633
634   // Instance of this class and so on
635   static  AliTRDCalibra *fgInstance;        // Instance
636   static  Bool_t   fgTerminated;            // If terminated
637     
638   ClassDef(AliTRDCalibra, 1)   // TRD Calibration class
639
640 };
641   
642 #endif
643
644