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