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