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