]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/TRDbase/AliTRDCalibraFillHisto.h
doxy: convert <pre> to Markdown ~~~
[u/mrichter/AliRoot.git] / TRD / TRDbase / AliTRDCalibraFillHisto.h
1 #ifndef ALITRDCALIBRAFILLHISTO_H
2 #define ALITRDCALIBRAFILLHISTO_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_TProfile2D
18 #  include <TProfile2D.h> 
19 #endif
20
21 #include "TObjArray.h"
22
23 class TProfile2D;
24 class TObjArray;
25 class TH1F;
26 class TH2I;
27 class TH2F;
28 class TH2;
29 class TLinearFitter;
30 class TTreeSRedirector;
31
32 class AliLog;
33 class AliRawReader;
34
35 class AliESDtrack;
36
37 class AliTRDCalibraMode;
38 class AliTRDCalibraVector;
39 class AliTRDCalibraVdriftLinearFit;
40 class AliTRDCalibraExbAltFit;
41 class AliTRDcluster;
42 class AliTRDtrackV1;
43 class AliTRDseedV1;
44 class AliTRDgeometry;
45 class AliTRDCalDet;
46 class AliTRDCalROC;
47 class AliTRDcalibDB;
48
49 class AliTRDdigitsManager;
50 class AliTRDSignalIndex;
51
52 struct eventHeaderStruct;
53
54 class AliTRDCalibraFillHisto : public TObject {
55
56  public: 
57
58   // Instance
59   static AliTRDCalibraFillHisto *Instance();
60   static void Terminate();
61   static void Destroy();
62   void DestroyDebugStreamer();
63
64
65   AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c);
66   AliTRDCalibraFillHisto &operator=(const AliTRDCalibraFillHisto &) { return *this; }
67
68   // Functions for initialising and filling with AliTRDtrackV1
69           Bool_t  Init2Dhistos(Int_t nboftimebin = -1);
70           Bool_t  InitCalDet();
71           Bool_t  UpdateHistogramsV1(const AliTRDtrackV1 *t,const AliESDtrack *esdtrack = NULL);
72  
73   // Process events DAQ
74           Int_t   ProcessEventDAQ(AliRawReader *rawReader);
75
76   // Is Pad on
77           Bool_t   IsPadOn(Int_t detector, Int_t row, Int_t col) const;
78
79   // Functions for write
80           void     Write2d(const Char_t *filename = "TRD.calibration.root", Bool_t append = kFALSE);
81
82   //For the statistics
83           Double_t *StatH(TH2 *ch, Int_t i);
84           Double_t *GetMeanMedianRMSNumberCH();
85           Double_t *GetMeanMedianRMSNumberLinearFitter() const;
86  // LinearFitter
87           void     AnalyseLinearFitter();
88        
89          
90   //
91   // Set of Get the variables
92   //
93
94           void     SetIsHLT(Bool_t isHLT = kTRUE)                            { fIsHLT = isHLT;                       }  
95           Bool_t   IsHLT() const                                             { return fIsHLT;                        }  
96
97   // Choice to fill or not the 2D
98           void     SetPH2dOn(Bool_t ph2don = kTRUE)                          { fPH2dOn          = ph2don;            }
99           void     SetCH2dOn(Bool_t ch2don = kTRUE)                          { fCH2dOn          = ch2don;            }
100           void     SetPRF2dOn(Bool_t prf2don = kTRUE)                        { fPRF2dOn         = prf2don;           }
101           void     SetHisto2d(Bool_t histo2d = kTRUE)                        { fHisto2d         = histo2d;           }
102           void     SetVector2d(Bool_t vector2d = kTRUE)                      { fVector2d        = vector2d;          }
103           void     SetLinearFitterOn(Bool_t linearfitteron = kTRUE)          { fLinearFitterOn      = linearfitteron;}
104           void     SetLinearFitterDebugOn(Bool_t debug = kTRUE)              { fLinearFitterDebugOn = debug;         }
105           void     SetExbAltFitOn(Bool_t fiton = kTRUE)                      { fExbAltFitOn      = fiton;}
106           void     SetScaleWithTPCSignal(Bool_t scaleWithTPCSignal = kTRUE)  { fScaleWithTPCSignal = scaleWithTPCSignal;}
107           void     SetTakeSnapshot(Bool_t takesnapshot)                 { fTakeSnapshot = takesnapshot;   }
108           void     SetFirstRunGain(Int_t firstRunGain)                       { fFirstRunGain = firstRunGain;   }
109           void     SetVersionGainUsed(Int_t versionGainUsed)                 { fVersionGainUsed = versionGainUsed;   }
110           void     SetSubVersionGainUsed(Int_t subVersionGainUsed)           { fSubVersionGainUsed = subVersionGainUsed;   }
111           void     SetFirstRunGainLocal(Int_t firstRunGainLocal)             { fFirstRunGainLocal = firstRunGainLocal;   }
112           void     SetVersionGainLocalUsed(Int_t versionGainLocalUsed)       { fVersionGainLocalUsed = versionGainLocalUsed;   }
113           void     SetSubVersionGainLocalUsed(Int_t subVersionGainLocalUsed) { fSubVersionGainLocalUsed = subVersionGainLocalUsed;   }
114           void     SetFirstRunVdrift(Int_t firstRunVdrift)                   { fFirstRunVdrift = firstRunVdrift;   }
115           void     SetVersionVdriftUsed(Int_t versionVdriftUsed)             { fVersionVdriftUsed = versionVdriftUsed;   }
116           void     SetSubVersionVdriftUsed(Int_t subVersionVdriftUsed)       { fSubVersionVdriftUsed = subVersionVdriftUsed;   }
117           void     SetFirstRunExB(Int_t firstRunExB)                         { fFirstRunExB = firstRunExB;   }
118           void     SetVersionExBUsed(Int_t versionExBUsed)                   { fVersionExBUsed = versionExBUsed;   }
119           void     SetSubVersionExBUsed(Int_t subVersionExBUsed)             { fSubVersionExBUsed = subVersionExBUsed;   }
120           
121   
122           Bool_t   GetPH2dOn() const                                         { return fPH2dOn;                 }
123           Bool_t   GetCH2dOn() const                                         { return fCH2dOn;                 }
124           Bool_t   GetPRF2dOn() const                                        { return fPRF2dOn;                }
125           Bool_t   GetHisto2d() const                                        { return fHisto2d;                }
126           Bool_t   GetVector2d() const                                       { return fVector2d;               }
127           Bool_t   GetLinearFitterOn() const                                 { return fLinearFitterOn;         }
128           Bool_t   GetLinearFitterDebugOn() const                            { return fLinearFitterDebugOn;    }
129           Int_t    GetVersionGainUsed() const                                { return fVersionGainUsed;        }
130           Int_t    GetSubVersionGainUsed() const                             { return fSubVersionGainUsed;     }
131           Int_t    GetVersionVdriftUsed() const                              { return fVersionVdriftUsed;      }
132           Int_t    GetSubVersionVdriftUsed() const                           { return fSubVersionVdriftUsed;   }
133
134
135   // Get stuff that are filled
136   TH2I            *GetCH2d();
137   TProfile2D      *GetPH2d(Int_t nbtimebin=24, Float_t samplefrequency= 10.0);
138   TProfile2D      *GetPRF2d() const                                          { return fPRF2d;                  } 
139   TObjArray        GetLinearFitterArray() const                              { return fLinearFitterArray;      }
140   TLinearFitter   *GetLinearFitter(Int_t detector, Bool_t force=kFALSE);
141   AliTRDCalibraVdriftLinearFit *GetVdriftLinearFit() const                   { return fLinearVdriftFit; }
142   AliTRDCalibraExbAltFit *GetExbAltFit() const                               { return fExbAltFit; }
143   
144  
145   // How to fill the 2D
146           void     SetRelativeScale(Float_t relativeScale);                      
147           void     SetThresholdClusterPRF2(Float_t thresholdClusterPRF2)     { fThresholdClusterPRF2 = thresholdClusterPRF2; }
148           void     SetLimitChargeIntegration(Bool_t limitChargeIntegration)  { fLimitChargeIntegration = limitChargeIntegration; }
149           void     SetFillWithZero(Bool_t fillWithZero)                      { fFillWithZero = fillWithZero;   }
150           void     SetNormalizeNbOfCluster(Bool_t normalizeNbOfCluster)      { fNormalizeNbOfCluster = normalizeNbOfCluster; }
151           void     SetMaxCluster(Float_t maxCluster)                         { fMaxCluster = maxCluster; }
152           void     SetNbMaxCluster(Short_t nbMaxCluster)                     { fNbMaxCluster = nbMaxCluster; }
153           void     SetCutWithVdriftCalib(Bool_t cutWithVdriftCalib)          { fCutWithVdriftCalib = cutWithVdriftCalib; }
154           void     SetMinNbTRDtracklets(Int_t minNbTRDtracklets)             { fMinNbTRDtracklets = minNbTRDtracklets; }
155           void     SetMinTRDMomentum(Float_t minTRDMomentum)                 { fMinTRDMomentum = minTRDMomentum; }
156           void     SetNz(Int_t i, Short_t nz);
157           void     SetNrphi(Int_t i, Short_t nrphi);
158           void     SetAllTogether(Int_t i);
159           void     SetPerSuperModule(Int_t i);
160           void     SetProcent(Float_t procent)                               { fProcent              = procent;              }
161           void     SetDifference(Short_t difference)                         { fDifference           = difference;           }
162           void     SetNumberClusters(Short_t numberClusters)                 { if(numberClusters >= 0) fNumberClusters       = numberClusters;       }
163           void     SetNumberClustersf(Short_t numberClustersf)               { fNumberClustersf      = numberClustersf;      }
164           void     SetNumberClustersProcent(Float_t numberClustersProcent)   { fNumberClustersProcent = numberClustersProcent;                       }
165           void     SetThresholdClustersDAQ(Float_t thresholdClustersDAQ)     { fThresholdClustersDAQ = thresholdClustersDAQ;                         }
166           void     SetNumberRowDAQ(Short_t numberRowDAQ)                     { fNumberRowDAQ         = numberRowDAQ;         }
167           void     SetNumberColDAQ(Short_t numberColDAQ)                     { fNumberColDAQ         = numberColDAQ;         }
168           void     SetRangeHistoCharge(Float_t rangeHistoCharge)             { fRangeHistoCharge     = rangeHistoCharge;     }
169           void     SetNumberBinCharge(Short_t numberBinCharge)               { fNumberBinCharge      = numberBinCharge;      }
170           void     SetNumberBinPRF(Short_t numberBinPRF)                     { fNumberBinPRF         = numberBinPRF;         }
171           void     SetNumberGroupsPRF(Short_t numberGroupsPRF);
172   
173           Float_t  GetRelativeScale() const                                  { return fRelativeScale;          }
174           Float_t  GetThresholdClusterPRF2() const                           { return fThresholdClusterPRF2;   }
175           Bool_t   GetLimitChargeIntegration() const                         { return fLimitChargeIntegration; }
176           Bool_t   GetFillWithZero() const                                   { return fFillWithZero;           }
177           Bool_t   GetNormalizeNbOfCluster() const                           { return fNormalizeNbOfCluster;   }
178           Float_t  GetMaxCluster() const                                     { return fMaxCluster;             }
179           Short_t  GetNbMaxCluster() const                                   { return fNbMaxCluster;           }
180           Bool_t   GetCutWithVdriftCalib() const                             { return fCutWithVdriftCalib;     }
181           Float_t  GetProcent() const                                        { return fProcent;                }
182           Short_t  GetDifference() const                                     { return fDifference;             }
183           Short_t  GetNumberClusters() const                                 { return fNumberClusters;         }
184           Short_t  GetNumberClustersf() const                                { return fNumberClustersf;        }
185           Short_t  GetNumberBinCharge() const                                { return fNumberBinCharge;        }
186           Short_t  GetNumberBinPRF() const                                   { return fNumberBinPRF;           }
187           Short_t  GetNumberGroupsPRF() const                                { return fNgroupprf;              }
188           Int_t    *GetEntriesLinearFitter() const                           { return fEntriesLinearFitter;    }
189
190  // Debug
191           void     SetDebugLevel(Short_t level)                              { fDebugLevel = level;           }
192
193   // Vector method
194 AliTRDCalibraVector *GetCalibraVector() const                                { return fCalibraVector;          }   
195   
196  protected:
197
198   // Geometry
199   AliTRDgeometry  *fGeo;                    //! The TRD geometry
200   // calibration DB
201   AliTRDcalibDB   *fCalibDB;                //! The pointer to the TRDcalibDB instance
202
203   // Is HLT
204           Bool_t   fIsHLT;                  // Now if HLT, the per detector
205
206   // Choice to fill or not the 2D
207           Bool_t   fCH2dOn;                 // Chose to fill the 2D histos or vectors for the relative gain calibration 
208           Bool_t   fPH2dOn;                 // Chose to fill the 2D histos or vectors for the drift velocity and T0
209           Bool_t   fPRF2dOn;                // Chose to fill the 2D histos or vectors for the pad response function calibration
210           Bool_t   fHisto2d;                // Chose to fill the 2D histos
211           Bool_t   fVector2d;               // Chose to fill vectors
212           Bool_t   fLinearFitterOn;         // Method with linear fit for drift velocity
213           Bool_t   fLinearFitterDebugOn;    // Method with linear fit for drift velocity
214           Bool_t   fExbAltFitOn;            // Enable parabolic fit for exb
215           Bool_t   fScaleWithTPCSignal;     // Scale the gain with TPC signal (If use then ask at least 70 TPC clusters)
216
217   // How to fill the 2D
218           Float_t  fRelativeScale;          // Scale of the deposited charge
219           Float_t  fThresholdClusterPRF2;   // Threshold on cluster pad signals
220           Bool_t   fLimitChargeIntegration; // Integration range for the gain calibration
221           Bool_t   fFillWithZero;           // Fill with zero or not the average pulse height
222           Bool_t   fNormalizeNbOfCluster;   // Normalize with the number of cluster for the gain
223           Float_t  fMaxCluster;             // Max amplitude of one cluster
224           Short_t  fNbMaxCluster;           // Number of tb at the end
225           Bool_t   fCutWithVdriftCalib;     // CutWithVdriftCalib for the gain and PH
226           Int_t    fMinNbTRDtracklets;      // Min number of TRD tracklets
227           Float_t  fMinTRDMomentum;         // Min TRD momentum
228   // Back correction
229           Bool_t   fTakeSnapshot;           // Take from snapshot
230           Int_t    fFirstRunGain;           // FirstRunGain 
231           Int_t    fVersionGainUsed;        // VersionGainUsed 
232           Int_t    fSubVersionGainUsed;     // SubVersionGainUsed
233           Int_t    fFirstRunGainLocal;      // FirstRunGainLocal 
234           Int_t    fVersionGainLocalUsed;   // VersionGainUsed 
235           Int_t    fSubVersionGainLocalUsed;// SubVersionGainUsed
236           Int_t    fFirstRunVdrift;         // FirstRunVdrift 
237           Int_t    fVersionVdriftUsed;      // VersionVdriftUsed 
238           Int_t    fSubVersionVdriftUsed;   // SubVersionVdriftUsed
239           Int_t    fFirstRunExB;            // FirstRunExB 
240           Int_t    fVersionExBUsed;         // VersionExBUsed 
241           Int_t    fSubVersionExBUsed;      // SubVersionExBUsed
242   // Calibration mode
243           AliTRDCalibraMode *fCalibraMode;  // Calibration mode
244
245   //For debugging
246           TTreeSRedirector          *fDebugStreamer;                 //!Debug streamer
247           Short_t     fDebugLevel;                                   // Flag for debugging
248   //
249   // Internal variables
250   //
251
252   // Fill the 2D histos in the offline tracking
253           Int_t    fDetectorPreviousTrack;  // Change of detector
254           Int_t    fMCMPrevious;            // Change of MCM
255           Int_t    fROBPrevious;            // Change of ROB
256           Short_t  fNumberClusters;         // Minimum number of clusters in the tracklets
257           Short_t  fNumberClustersf;        // Maximum number of clusters in the tracklets
258           Float_t  fNumberClustersProcent;  // Procent of number of time bins for fNumberClusters
259           Float_t  fThresholdClustersDAQ;   // Threshold clusters for DAQ algorithm
260           Short_t  fNumberRowDAQ;           // Size of the spot for DAQ algorithm
261           Short_t  fNumberColDAQ;           // Size of the spot for DAQ algorithm
262           Float_t  fProcent;                // Limit to take the info of the most important calibration group if the track goes through 2 groups (CH)
263           Short_t  fDifference;             // Limit to take the info of the most important calibration group if the track goes through 2 groups (CH)
264           Int_t    fNumberTrack;            // How many tracks could be used (Debug for the moment)
265           Int_t    fNumberUsedCh[2];        // How many tracks have been really used for the gain (0, strict; 1 with fProcent)
266           Int_t    fNumberUsedPh[2];        // How many tracks have been really used for the drift velocity (0, strict; 1 with fDifference)
267           Int_t    fTimeMax;                // Number of time bins
268           Float_t  fSf;                     // Sampling frequence
269           Float_t  fRangeHistoCharge;       // Range of the histo for the charge
270           Short_t  fNumberBinCharge;        // Number of bins for the gain factor
271           Short_t  fNumberBinPRF;           // Number of bin for the PRF
272           Short_t  fNgroupprf;              // Number of groups in tnp bins for PRF /2.0
273
274   // Variables per tracklet
275           Float_t       *fAmpTotal;                  // Energy deposited in the calibration group by the track
276           Short_t       *fPHPlace;                   // Calibration group of PH
277           Float_t       *fPHValue;                   // PH
278           Bool_t         fGoodTracklet;              // Good tracklet
279           TLinearFitter *fLinearFitterTracklet;      // linear fitter tracklet  
280   //Statistics
281           Int_t         *fEntriesCH;                 // Number of entries CH
282           Int_t         *fEntriesLinearFitter;       // Number of entries LinearFitter
283
284
285   //
286   // Vector method
287   //
288           
289           AliTRDCalibraVector *fCalibraVector; // The vector object
290  
291  
292   // Histograms to store the info from the digits, from the tracklets or from the tracks
293           TProfile2D      *fPH2d;                         // 2D average pulse height
294           TProfile2D      *fPRF2d;                        // 2D PRF
295           TH2I            *fCH2d;                         // 2D deposited charge
296           TObjArray       fLinearFitterArray;             // TObjArray of Linear Fitters for the detectors 
297           AliTRDCalibraVdriftLinearFit *fLinearVdriftFit; // Info Linear Fit
298           AliTRDCalibraExbAltFit *fExbAltFit; // ExB parabolic fit (alternative to vdrift linear fit)
299           
300  // Current calib object: to correct for the database used
301           AliTRDCalDet *fCalDetGain;                      // Current calib object gain
302           AliTRDCalROC *fCalROCGain;                      // Current calib object gain
303            
304   //
305   // A lot of internal functions......
306   // Init
307           Bool_t   InitCalPad(Int_t detector);
308   //
309   // Create the 2D histo to be filled Online
310           void     CreateCH2d(Int_t nn);
311           void     CreatePH2d(Int_t nn);
312           void     CreatePRF2d(Int_t nn);
313   
314   // Calibration with AliTRDtrackV1
315           void     FillTheInfoOfTheTrackPH();
316           void     FillTheInfoOfTheTrackCH(Int_t nbclusters);
317           Bool_t   FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters);
318           Bool_t   HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters);
319           void     ResetfVariablestracklet();
320           Float_t  StoreInfoCHPHtrack(const AliTRDcluster *cl,const Double_t dqdl,const Int_t *group,const Int_t row,const Int_t col,const AliTRDcluster *cls=0x0);
321           void     FillCH2d(Int_t x, Float_t y);
322
323   // Calibration on DAQ
324
325           Int_t    FillDAQ(Double_t phvalue[16][144][36]);
326           Bool_t   UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins);
327           
328  // row col calibration groups stuff
329           Bool_t   LocalisationDetectorXbins(Int_t detector);
330           Int_t    CalculateTotalNumberOfBins(Int_t i);
331           void     CheckGoodTrackletV0(const Int_t detector,const Int_t row,const Int_t col);
332           void     CheckGoodTrackletV1(const AliTRDcluster *cl);
333           Int_t    CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const;
334           
335   // Clear
336           void     ClearHistos();
337       
338   // Some basic geometry function
339   virtual Int_t    GetLayer(Int_t d) const;
340   virtual Int_t    GetStack(Int_t d) const;
341   virtual Int_t    GetSector(Int_t d) const;
342           
343           
344   // Instance of this class and so on
345   static  AliTRDCalibraFillHisto *fgInstance;                // Instance
346   static  Bool_t   fgTerminated;                             // If terminated
347
348  private:
349   
350   // This is a singleton, contructor is private!
351   AliTRDCalibraFillHisto();
352   virtual ~AliTRDCalibraFillHisto(); 
353     
354   ClassDef(AliTRDCalibraFillHisto,8)                         // TRD Calibration class
355
356 };
357   
358 #endif
359
360