]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TRD/AliTRDCalibraFillHisto.h
QA update by Sylwester
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFillHisto.h
1 #ifndef ALITRDCALIBRAFILLHISTO_H
2 #define ALITRDCALIBRAFILLHISTOs_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_TLinearFitter
18 #  include <TLinearFitter.h> 
19 #endif
20 #ifndef ROOT_TProfile2D
21 #  include <TProfile2D.h> 
22 #endif
23 #ifndef ROOT_TH2I
24 #  include <TH2I.h> 
25 #endif
26
27 class TProfile2D;
28 class TObjArray;
29 class TH1F;
30 class TH2I;
31 class TH2F;
32 class TH2;
33 class TLinearFitter;
34 class TTreeSRedirector;
35
36 class AliLog;
37 class AliRawReader;
38
39 class AliTRDCalibraMode;
40 class AliTRDCalibraVector;
41 class AliTRDCalibraVdriftLinearFit;
42 class AliTRDrawStreamBase;
43 class AliTRDcluster;
44 class AliTRDtrackV1;
45 class AliTRDtrack;
46 class AliTRDseedV1;
47 class AliTRDmcm;
48 class AliTRDmcmTracklet;
49 class AliTRDgeometry;
50 class AliTRDCalDet;
51 class AliTRDCalROC;
52
53
54 struct eventHeaderStruct;
55
56 class AliTRDCalibraFillHisto : public TObject {
57
58  public: 
59
60   // Instance
61   static AliTRDCalibraFillHisto *Instance();
62   static void Terminate();
63   static void Destroy();
64   void DestroyDebugStreamer();
65
66
67   AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c);
68   AliTRDCalibraFillHisto &operator=(const AliTRDCalibraFillHisto &) { return *this; }
69
70   // Functions for initialising and filling with AliTRDtrackV1
71           Bool_t  Init2Dhistos();
72           Bool_t  UpdateHistograms(AliTRDtrack *t);
73           Bool_t  UpdateHistogramsV1(AliTRDtrackV1 *t);
74  
75   // Process events DAQ
76           Int_t   ProcessEventDAQ(AliTRDrawStreamBase *rawStream, Bool_t nocheck = kFALSE);
77           Int_t   ProcessEventDAQ(AliRawReader *rawReader, Bool_t nocheck = kFALSE);
78           Int_t   ProcessEventDAQ(eventHeaderStruct *event, Bool_t nocheck = kFALSE);
79
80           Int_t   ProcessEventDAQV1(AliTRDrawStreamBase *rawStream, Bool_t nocheck = kFALSE);
81           Int_t   ProcessEventDAQV1(AliRawReader *rawReader, Bool_t nocheck = kFALSE);
82           Int_t   ProcessEventDAQV1(eventHeaderStruct *event, Bool_t nocheck = kFALSE);
83
84   // Is Pad on
85           Bool_t   IsPadOn(Int_t detector, Int_t row, Int_t col) const;
86
87   // Functions for write
88           void     Write2d(const Char_t *filename = "TRD.calibration.root", Bool_t append = kFALSE);
89
90   //For the statistics
91           Double_t *StatH(TH2 *ch, Int_t i);
92           Double_t *GetMeanMedianRMSNumberCH();
93           Double_t *GetMeanMedianRMSNumberLinearFitter() const;
94        
95          
96   //
97   // Set of Get the variables
98   //
99
100   // Choice to fill or not the 2D
101           void     SetMcmCorrectAngle(Bool_t mcmcorrectangle = kTRUE)        { fMcmCorrectAngle = mcmcorrectangle;   }
102           void     SetPH2dOn(Bool_t ph2don = kTRUE)                          { fPH2dOn          = ph2don;            }
103           void     SetCH2dOn(Bool_t ch2don = kTRUE)                          { fCH2dOn          = ch2don;            }
104           void     SetPRF2dOn(Bool_t prf2don = kTRUE)                        { fPRF2dOn         = prf2don;           }
105           void     SetHisto2d(Bool_t histo2d = kTRUE)                        { fHisto2d         = histo2d;           }
106           void     SetVector2d(Bool_t vector2d = kTRUE)                      { fVector2d        = vector2d;          }
107           void     SetLinearFitterOn(Bool_t linearfitteron = kTRUE)          { fLinearFitterOn      = linearfitteron;}
108           void     SetLinearFitterDebugOn(Bool_t debug = kTRUE)              { fLinearFitterDebugOn = debug;         }
109                   
110   
111           Bool_t   GetMcmCorrectAngle() const                                { return fMcmCorrectAngle;        }
112           Bool_t   GetPH2dOn() const                                         { return fPH2dOn;                 }
113           Bool_t   GetCH2dOn() const                                         { return fCH2dOn;                 }
114           Bool_t   GetPRF2dOn() const                                        { return fPRF2dOn;                }
115           Bool_t   GetHisto2d() const                                        { return fHisto2d;                }
116           Bool_t   GetVector2d() const                                       { return fVector2d;               }
117           Bool_t   GetLinearFitterOn() const                                 { return fLinearFitterOn;         }
118           Bool_t   GetLinearFitterDebugOn() const                            { return fLinearFitterDebugOn; }
119
120
121   // Get stuff that are filled
122   TH2I            *GetCH2d();
123   TProfile2D      *GetPH2d(Int_t nbtimebin=24, Float_t samplefrequency= 10.0);
124   TProfile2D      *GetPRF2d() const                                          { return fPRF2d;                  } 
125   TObjArray        GetLinearFitterArray() const                              { return fLinearFitterArray;      }
126   TLinearFitter   *GetLinearFitter(Int_t detector, Bool_t force=kFALSE);
127   AliTRDCalibraVdriftLinearFit *GetVdriftLinearFit() const                   { return fLinearVdriftFit;        }
128   
129  
130   // How to fill the 2D
131           void     SetRelativeScale(Float_t relativeScale);                      
132           void     SetThresholdClusterPRF2(Float_t thresholdClusterPRF2)     { fThresholdClusterPRF2 = thresholdClusterPRF2; }
133           void     SetLimitChargeIntegration(Bool_t limitChargeIntegration)  { fLimitChargeIntegration = limitChargeIntegration; }
134           void     SetNz(Int_t i, Short_t nz);
135           void     SetNrphi(Int_t i, Short_t nrphi);
136           void     SetProcent(Float_t procent)                               { fProcent              = procent;              }
137           void     SetDifference(Short_t difference)                         { fDifference           = difference;           }
138           void     SetNumberClusters(Short_t numberClusters)                 { fNumberClusters       = numberClusters;       }
139           void     SetNumberClustersf(Short_t numberClustersf)               { fNumberClustersf      = numberClustersf;      }
140           void     SetNumberBinCharge(Short_t numberBinCharge)               { fNumberBinCharge      = numberBinCharge;      }
141           void     SetNumberBinPRF(Short_t numberBinPRF)                     { fNumberBinPRF         = numberBinPRF;         }
142           void     SetNumberGroupsPRF(Short_t numberGroupsPRF);
143   
144           Float_t  GetRelativeScale() const                                  { return fRelativeScale;          }
145           Float_t  GetThresholdClusterPRF2() const                           { return fThresholdClusterPRF2;   }
146           Bool_t   GetLimitChargeIntegration() const                         { return fLimitChargeIntegration; }
147           Float_t  GetProcent() const                                        { return fProcent;                }
148           Short_t  GetDifference() const                                     { return fDifference;             }
149           Short_t  GetNumberClusters() const                                 { return fNumberClusters;         }
150           Short_t  GetNumberClustersf() const                                { return fNumberClustersf;        }
151           Short_t  GetNumberBinCharge() const                                { return fNumberBinCharge;        }
152           Short_t  GetNumberBinPRF() const                                   { return fNumberBinPRF;           }
153           Short_t  GetNumberGroupsPRF() const                                { return fNgroupprf;              }
154           Int_t    *GetEntriesLinearFitter() const                           { return fEntriesLinearFitter;    }
155
156  // Debug
157           void     SetDebugLevel(Short_t level)                              { fDebugLevel = level;           }
158
159   // Vector method
160 AliTRDCalibraVector *GetCalibraVector() const                                { return fCalibraVector;          }   
161   
162  protected:
163
164   // Geometry
165   AliTRDgeometry  *fGeo;                    //! The TRD geometry
166
167   // Choice to fill or not the 2D
168           Bool_t   fMcmCorrectAngle;        // Apply correction due to the mcmtrackletangle in the z direction (only) assuming  from vertex
169           Bool_t   fCH2dOn;                 // Chose to fill the 2D histos or vectors for the relative gain calibration 
170           Bool_t   fPH2dOn;                 // Chose to fill the 2D histos or vectors for the drift velocity and T0
171           Bool_t   fPRF2dOn;                // Chose to fill the 2D histos or vectors for the pad response function calibration
172           Bool_t   fHisto2d;                // Chose to fill the 2D histos
173           Bool_t   fVector2d;               // Chose to fill vectors
174           Bool_t   fLinearFitterOn;         // Method with linear fit for drift velocity
175           Bool_t   fLinearFitterDebugOn;    // Method with linear fit for drift velocity
176
177   // How to fill the 2D
178           Float_t  fRelativeScale;          // Scale of the deposited charge
179           Float_t  fThresholdClusterPRF2;   // Threshold on cluster pad signals
180           Bool_t   fLimitChargeIntegration; // Integration range for the gain calibration
181   // Calibration mode
182           AliTRDCalibraMode *fCalibraMode;  // Calibration mode
183
184   //For debugging
185           TTreeSRedirector          *fDebugStreamer;                 //!Debug streamer
186           Short_t     fDebugLevel;                                   // Flag for debugging
187   //
188   // Internal variables
189   //
190
191   // Fill the 2D histos in the offline tracking
192           Int_t    fDetectorPreviousTrack;  // Change of detector
193           Int_t    fMCMPrevious;            // Change of MCM
194           Int_t    fROBPrevious;            // Change of ROB
195           Short_t  fNumberClusters;         // Minimum number of clusters in the tracklets
196           Short_t  fNumberClustersf;        // Maximum number of clusters in the tracklets
197           Float_t  fProcent;                // Limit to take the info of the most important calibration group if the track goes through 2 groups (CH)
198           Short_t  fDifference;             // Limit to take the info of the most important calibration group if the track goes through 2 groups (CH)
199           Int_t    fNumberTrack;            // How many tracks could be used (Debug for the moment)
200           Int_t    fNumberUsedCh[2];        // How many tracks have been really used for the gain (0, strict; 1 with fProcent)
201           Int_t    fNumberUsedPh[2];        // How many tracks have been really used for the drift velocity (0, strict; 1 with fDifference)
202           Int_t    fTimeMax;                // Number of time bins
203           Float_t  fSf;                     // Sampling frequence
204           Short_t  fNumberBinCharge;        // Number of bins for the gain factor
205           Short_t  fNumberBinPRF;           // Number of bin for the PRF
206           Short_t  fNgroupprf;              // Number of groups in tnp bins for PRF /2.0
207
208   // Variables per tracklet
209           Float_t       *fAmpTotal;                  // Energy deposited in the calibration group by the track
210           Short_t       *fPHPlace;                   // Calibration group of PH
211           Float_t       *fPHValue;                   // PH
212           Bool_t         fGoodTracklet;              // Good tracklet
213   //Statistics
214           Int_t         *fEntriesCH;                 // Number of entries CH
215           Int_t         *fEntriesLinearFitter;       // Number of entries LinearFitter
216
217
218   //
219   // Vector method
220   //
221           
222           AliTRDCalibraVector *fCalibraVector; // The vector object
223  
224  
225   // Histograms to store the info from the digits, from the tracklets or from the tracks
226           TProfile2D      *fPH2d;                         // 2D average pulse height
227           TProfile2D      *fPRF2d;                        // 2D PRF
228           TH2I            *fCH2d;                         // 2D deposited charge
229           TObjArray       fLinearFitterArray;             // TObjArray of Linear Fitters for the detectors 
230           AliTRDCalibraVdriftLinearFit *fLinearVdriftFit; // Info Linear Fit
231           
232  // Current calib object: to correct for the database used
233           AliTRDCalDet *fCalDetGain;                      // Current calib object gain
234           AliTRDCalROC *fCalROCGain;                      // Current calib object gain
235            
236   //
237   // A lot of internal functions......
238   //
239   // Create the 2D histo to be filled Online
240           void     CreateCH2d(Int_t nn);
241           void     CreatePH2d(Int_t nn);
242           void     CreatePRF2d(Int_t nn);
243   
244   // Calibration with AliTRDtrackV1
245           void     FillTheInfoOfTheTrackPH();
246           void     FillTheInfoOfTheTrackCH(Int_t nbclusters);
247           Bool_t   FindP1TrackPHtracklet(AliTRDtrack *t, Int_t index0, Int_t index1);
248           Bool_t   FindP1TrackPHtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters);
249           Bool_t   HandlePRFtracklet(AliTRDtrack *t, Int_t index0, Int_t index1);
250           Bool_t   HandlePRFtrackletV1(const AliTRDseedV1 *tracklet, Int_t nbclusters);
251           void     ResetfVariablestracklet();
252           void     StoreInfoCHPHtrack(AliTRDcluster *cl, Double_t dqdl, Int_t *group, Int_t row, Int_t col);
253           void     FillCH2d(Int_t x, Float_t y);
254
255   // Calibration on DAQ
256
257           Int_t    FillDAQ(Double_t phvalue[16][144][36]);
258           Int_t    FillDAQ(AliTRDmcm *mcm);
259           Int_t    TestTracklet( Int_t idet, Int_t row, Int_t iSeed, AliTRDmcm *mcm);
260           Bool_t   UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/, Int_t timebin, Float_t signal, Int_t nbtimebins);
261           Int_t    UpdateHistogramcm(AliTRDmcmTracklet *trk);
262
263   // row col calibration groups stuff
264           Bool_t   LocalisationDetectorXbins(Int_t detector);
265           Int_t    CalculateTotalNumberOfBins(Int_t i);
266           void     CheckGoodTrackletV0(Int_t detector, Int_t row, Int_t col);
267           void     CheckGoodTrackletV1(AliTRDcluster *cl);
268           Int_t    CalculateCalibrationGroup(Int_t i, Int_t row, Int_t col) const;
269  
270   // LinearFitter
271           void     AnalyseLinearFitter();
272           
273   // Clear
274           void     ClearHistos();
275       
276   // Some basic geometry function
277   virtual Int_t    GetLayer(Int_t d) const;
278   virtual Int_t    GetStack(Int_t d) const;
279   virtual Int_t    GetSector(Int_t d) const;
280           
281           
282   // Instance of this class and so on
283   static  AliTRDCalibraFillHisto *fgInstance;                // Instance
284   static  Bool_t   fgTerminated;                             // If terminated
285
286  private:
287   
288   // This is a singleton, contructor is private!
289   AliTRDCalibraFillHisto();
290   virtual ~AliTRDCalibraFillHisto(); 
291     
292   ClassDef(AliTRDCalibraFillHisto,4)                         // TRD Calibration class
293
294 };
295   
296 #endif
297
298