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