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