]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSOnlineCalibrationSPDhandler.h
bugfix in calculation of tracklet <theta> for resolution scaling
[u/mrichter/AliRoot.git] / ITS / AliITSOnlineCalibrationSPDhandler.h
1 #ifndef ALIITSONLINECALIBRATIONSPDHANDLER_H
2 #define ALIITSONLINECALIBRATIONSPDHANDLER_H
3
4 //////////////////////////////////////////////////////////////////////////////
5 // Author: Henrik Tydesjo                                                   //
6 // Class that  simplifies the managing of dead, noisy, and inactive pixels. //
7 // Has interface to the AliITSOnlineCalibrationSPD container objects        //
8 // through reading and writing to TFile.                                    //
9 //////////////////////////////////////////////////////////////////////////////
10
11 /* $Id$  */
12
13 #include "AliITSRawStreamSPD.h"
14 #include <TString.h>
15
16 class TArrayI;
17 class TArrayS;
18 class AliITSIntMap;
19 class AliITSTriggerConditions;
20 class AliITSCalibrationSPD;
21
22 class AliITSOnlineCalibrationSPDhandler {
23
24  public:
25   AliITSOnlineCalibrationSPDhandler();
26   AliITSOnlineCalibrationSPDhandler(const AliITSOnlineCalibrationSPDhandler& handle);
27   virtual ~AliITSOnlineCalibrationSPDhandler();
28   AliITSOnlineCalibrationSPDhandler& operator=(const AliITSOnlineCalibrationSPDhandler& handle);
29
30   void    SetFileLocation(const Char_t* loc) {fFileLocation = loc;}
31   TString GetFileLocation() const {return fFileLocation;}
32
33   void    ClearMaps();
34   void    ResetDead();
35   void    ResetNoisy();
36   void    ResetDeadForChip(UInt_t eq, UInt_t hs, UInt_t chip);
37   void    ResetNoisyForChip(UInt_t eq, UInt_t hs, UInt_t chip);
38   void    ResetDeadForEq(UInt_t eq);
39   void    ResetNoisyForEq(UInt_t eq);
40
41   Bool_t  ReadFromFiles();
42   Bool_t  ReadSilentFromFiles();
43   Bool_t  ReadDeadFromFiles();
44   Bool_t  ReadNoisyFromFiles();
45   Bool_t  ReadSilentFromFile(UInt_t eq);
46   Bool_t  ReadDeadFromFile(UInt_t eq);
47   Bool_t  ReadNoisyFromFile(UInt_t eq);
48   Bool_t  ReadSilentFromFileName(const char *fileName);
49   Bool_t  ReadDeadFromFileName(const char *fileName, Bool_t inactive=kFALSE);
50   Bool_t  ReadNoisyFromFileName(const char *fileName);
51
52   UInt_t  ReadDeadFromText(const char *fileName, UInt_t module);
53   UInt_t  ReadNoisyFromText(const char *fileName, UInt_t module);
54   void    ReadPITConditionsFromText(const char *fileName);
55
56   void    WriteToFilesAlways();
57   UInt_t  WriteToFiles();
58   void    WriteSilentToFilesAlways();
59   void    WriteDeadToFilesAlways();
60   void    WriteNoisyToFilesAlways();
61   UInt_t  WriteSilentToFiles();
62   UInt_t  WriteDeadToFiles();
63   UInt_t  WriteNoisyToFiles();
64   void    WriteSilentToFile(UInt_t eq);
65   void    WriteDeadToFile(UInt_t eq, Bool_t inactive=kFALSE);
66   void    WriteNoisyToFile(UInt_t eq);
67
68   Bool_t  ReadPITConditionsFromDB(Int_t runNr, const Char_t *storage="default");
69 #ifndef SPD_DA_OFF
70   Bool_t  ReadDeadModuleFromDB(UInt_t module, Int_t runNr, const Char_t *storage="default", Bool_t treeSerial=kFALSE);
71   Bool_t  ReadNoisyModuleFromDB(UInt_t module, Int_t runNr, const Char_t *storage="default", Bool_t treeSerial=kFALSE);
72   Bool_t  ReadFromDB(Int_t runNr, const Char_t *storage="default", Bool_t treeSerial=kFALSE);
73   Bool_t  ReadDeadFromDB(Int_t runNr, const Char_t *storage="default", Bool_t treeSerial=kFALSE);
74   Bool_t  ReadSparseDeadFromDB(Int_t runNr, const Char_t *storage="default", Bool_t treeSerial=kFALSE);
75   Bool_t  ReadNoisyFromDB(Int_t runNr, const Char_t *storage="default", Bool_t treeSerial=kFALSE);
76   Bool_t  ReadDeadFromDBasNoisy(Int_t runNr, const Char_t *storage="default", Bool_t treeSerial=kFALSE);
77   Bool_t  ReadDeadFromCalibObj(const TObjArray* calObj);
78   Bool_t  ReadNoisyFromCalibObj(const TObjArray* calObj);
79   Bool_t  WriteToDB(Int_t runNrStart, Int_t runNrEnd, const Char_t *storage="default");
80   Bool_t  WriteDeadToDB(Int_t runNrStart, Int_t runNrEnd, const Char_t *storage="default");
81   Bool_t  WriteSparseDeadToDB(Int_t runNrStart, Int_t runNrEnd, const Char_t *storage="default");
82   Bool_t  WriteDeadToDBasNoisy(Int_t runNrStart, Int_t runNrEnd, const Char_t *storage="default");
83   Bool_t  WriteNoisyToDB(Int_t runNrStart, Int_t runNrEnd, const Char_t *storage="default");
84   Bool_t  WritePITConditionsToDB(Int_t runNrStart, Int_t runNrEnd, const Char_t *storage="default");
85 #endif
86
87   void    GenerateDCSConfigFile(const Char_t* fileName);
88
89   TArrayS GetSilentArray(UInt_t module, Bool_t treeSerial=kFALSE); // temporarily needed
90   TArrayS GetDeadArray(UInt_t module, Bool_t treeSerial=kFALSE);
91   TArrayS GetSparseDeadArray(UInt_t module, Bool_t treeSerial=kFALSE);
92   TArrayS GetNoisyArray(UInt_t module, Bool_t treeSerial=kFALSE);
93
94   TArrayI GetDeadArrayOnline(UInt_t eq);
95   TArrayI GetNoisyArrayOnline(UInt_t eq);
96
97   void    PrintEqSummary();
98   void    PrintSilent() const; // silent = dead or inactive
99   void    PrintDead() const;
100   void    PrintSparseDead() const;
101   void    PrintNoisy() const;
102
103   Bool_t  SetDeadPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row);
104   Bool_t  SetSparseDeadPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row);
105   Bool_t  SetNoisyPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row);
106   Bool_t  SetDeadPixelM(UInt_t module, UInt_t colM, UInt_t row);
107   Bool_t  SetSparseDeadPixelM(UInt_t module, UInt_t colM, UInt_t row);
108   Bool_t  SetNoisyPixelM(UInt_t module, UInt_t colM, UInt_t row);
109   Bool_t  UnSetDeadPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row);
110   Bool_t  UnSetSparseDeadPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row);
111   Bool_t  UnSetNoisyPixel(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row);
112   Bool_t  UnSetDeadPixelM(UInt_t module, UInt_t colM, UInt_t row);
113   Bool_t  UnSetSparseDeadPixelM(UInt_t module, UInt_t colM, UInt_t row);
114   Bool_t  UnSetNoisyPixelM(UInt_t module, UInt_t colM, UInt_t row);
115
116   Bool_t SetInactiveChipInPITmask(UInt_t eq, UInt_t hs, UInt_t chip);
117   Bool_t UnSetInactiveChipInPITmask(UInt_t eq, UInt_t hs, UInt_t chip);
118
119   Bool_t  IsPixelBad(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const;
120   Bool_t  IsPixelSilent(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const; // silent = dead or inactive
121   Bool_t  IsPixelDead(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const;
122   Bool_t  IsPixelNoisy(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const;
123   Bool_t  IsPixelBadM(UInt_t module, UInt_t colM, UInt_t row) const;
124   Bool_t  IsPixelSilentM(UInt_t module, UInt_t colM, UInt_t row) const;
125   Bool_t  IsPixelDeadM(UInt_t module, UInt_t colM, UInt_t row) const;
126   Bool_t  IsPixelNoisyM(UInt_t module, UInt_t colM, UInt_t row) const;
127   Bool_t  IsPixelBadKey(Int_t key) const;
128   Bool_t  IsPixelSilentKey(Int_t key) const;
129   Bool_t  IsPixelDeadKey(Int_t key) const;
130   Bool_t  IsPixelNoisyKey(Int_t key) const;
131
132   UInt_t  GetNrBad() const; // bad = silent or noisy
133   UInt_t  GetNrSilent() const; // silent = dead or inactive
134   UInt_t  GetNrDead() const;
135   UInt_t  GetNrSparseDead() const;
136   UInt_t  GetDeadEqIdAt(UInt_t index) const;
137   UInt_t  GetDeadHSAt(UInt_t index) const;
138   UInt_t  GetDeadChipAt(UInt_t index) const;
139   UInt_t  GetDeadColAt(UInt_t index) const;
140   UInt_t  GetDeadRowAt(UInt_t index) const;
141   UInt_t  GetNrNoisy() const;
142   UInt_t  GetNoisyEqIdAt(UInt_t index) const;
143   UInt_t  GetNoisyHSAt(UInt_t index) const;
144   UInt_t  GetNoisyChipAt(UInt_t index) const;
145   UInt_t  GetNoisyColAt(UInt_t index) const;
146   UInt_t  GetNoisyRowAt(UInt_t index) const;
147
148
149   UInt_t  GetNrBad(UInt_t module) const; // bad = silent or noisy
150   UInt_t  GetNrSilent(UInt_t module) const; // silent = dead or inactive
151   UInt_t  GetNrDead(UInt_t module) const;
152   UInt_t  GetNrSparseDead(UInt_t module) const;
153   UInt_t  GetNrDeadSingle(UInt_t module) const;
154   UInt_t  GetDeadEqIdAt(UInt_t module,UInt_t index) const;
155   UInt_t  GetDeadHSAt(UInt_t module,UInt_t index) const;
156   UInt_t  GetDeadChipAt(UInt_t module,UInt_t index) const;
157   UInt_t  GetDeadColAt(UInt_t module,UInt_t index) const;
158   UInt_t  GetDeadRowAt(UInt_t module,UInt_t index) const;
159   UInt_t  GetNrNoisy(UInt_t module) const;
160   UInt_t  GetNrNoisySingle(UInt_t module) const;
161   UInt_t  GetNoisyEqIdAt(UInt_t module, UInt_t index) const;
162   UInt_t  GetNoisyHSAt(UInt_t module, UInt_t index) const;
163   UInt_t  GetNoisyChipAt(UInt_t module, UInt_t index) const;
164   UInt_t  GetNoisyColAt(UInt_t module, UInt_t index) const;
165   UInt_t  GetNoisyRowAt(UInt_t module, UInt_t index) const;
166
167   UInt_t  GetNrBadEq(UInt_t eq) const; // bad = silent or noisy
168   UInt_t  GetNrSilentEq(UInt_t eq) const; // silent = dead or inactive
169   UInt_t  GetNrDeadEq(UInt_t eq) const;
170   UInt_t  GetNrSparseDeadEq(UInt_t eq) const;
171   UInt_t  GetDeadEqIdAtEq(UInt_t eq, UInt_t index) const;
172   UInt_t  GetDeadHSAtEq(UInt_t eq, UInt_t index) const;
173   UInt_t  GetDeadChipAtEq(UInt_t eq, UInt_t index) const;
174   UInt_t  GetDeadColAtEq(UInt_t eq, UInt_t index) const;
175   UInt_t  GetDeadRowAtEq(UInt_t eq, UInt_t index) const;
176   UInt_t  GetNrNoisyEq(UInt_t eq) const;
177   UInt_t  GetNoisyEqIdAtEq(UInt_t eq, UInt_t index) const;
178   UInt_t  GetNoisyHSAtEq(UInt_t eq, UInt_t index) const;
179   UInt_t  GetNoisyChipAtEq(UInt_t eq, UInt_t index) const;
180   UInt_t  GetNoisyColAtEq(UInt_t eq, UInt_t index) const;
181   UInt_t  GetNoisyRowAtEq(UInt_t eq, UInt_t index) const;
182
183   UInt_t  GetNrBadC(UInt_t eq, UInt_t hs, UInt_t chip) const; // bad = silent or noisy
184   UInt_t  GetNrSilentC(UInt_t eq, UInt_t hs, UInt_t chip) const; // silent = dead or inactive
185   UInt_t  GetNrDeadC(UInt_t eq, UInt_t hs, UInt_t chip) const;
186   UInt_t  GetNrSparseDeadC(UInt_t eq, UInt_t hs, UInt_t chip) const;
187   UInt_t  GetDeadEqIdAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
188   UInt_t  GetDeadHSAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
189   UInt_t  GetDeadChipAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
190   UInt_t  GetDeadColAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
191   UInt_t  GetDeadRowAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
192   UInt_t  GetNrNoisyC(UInt_t eq, UInt_t hs, UInt_t chip) const;
193   UInt_t  GetNoisyEqIdAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
194   UInt_t  GetNoisyHSAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
195   UInt_t  GetNoisyChipAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
196   UInt_t  GetNoisyColAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
197   UInt_t  GetNoisyRowAtC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
198
199   const Char_t* GetDeadPixelAsTextC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
200   const Char_t* GetNoisyPixelAsTextC(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t index) const;
201
202   void    ActivateALL();
203   void    ActivateEq(UInt_t eq, Bool_t setval = kTRUE);
204   void    ActivateHS(UInt_t eq, UInt_t hs, Bool_t setval = kTRUE);
205   void    ActivateChip(UInt_t eq, UInt_t hs, UInt_t chip, Bool_t setval = kTRUE);
206
207   void    UnSetDeadALL();
208   void    SetDeadEq(UInt_t eq, Bool_t setval = kTRUE);
209   void    SetDeadHS(UInt_t eq, UInt_t hs, Bool_t setval = kTRUE);
210   void    SetDeadChip(UInt_t eq, UInt_t hs, UInt_t chip, Bool_t setval = kTRUE);
211
212   Bool_t  IsActiveEq(UInt_t eq) const;
213   Bool_t  IsActiveHS(UInt_t eq, UInt_t hs) const;
214   Bool_t  IsActiveChip(UInt_t eq, UInt_t hs, UInt_t chip) const;
215
216   Bool_t  IsDeadEq(UInt_t eq) const;
217   Bool_t  IsDeadHS(UInt_t eq, UInt_t hs) const;
218   Bool_t  IsDeadChip(UInt_t eq, UInt_t hs, UInt_t chip) const;
219
220   Bool_t  IsSilentEq(UInt_t eq) const;
221   Bool_t  IsSilentHS(UInt_t eq, UInt_t hs) const;
222   Bool_t  IsSilentChip(UInt_t eq, UInt_t hs, UInt_t chip) const;
223
224   Bool_t  IsNoisyChip(UInt_t eq, UInt_t hs, UInt_t chip) const; 
225
226   UInt_t  AddSilentFrom(AliITSOnlineCalibrationSPDhandler* other);
227   UInt_t  AddDeadFrom(const AliITSOnlineCalibrationSPDhandler* other);
228   UInt_t  AddNoisyFrom(const AliITSOnlineCalibrationSPDhandler* other);
229
230   UInt_t  GetNrDiff(AliITSOnlineCalibrationSPDhandler* other) const;
231   UInt_t  GetNrSilentDiff(AliITSOnlineCalibrationSPDhandler* other) const;
232   UInt_t  GetNrDeadDiff(const AliITSOnlineCalibrationSPDhandler* other) const;
233   UInt_t  GetNrNoisyDiff(const AliITSOnlineCalibrationSPDhandler* other) const;
234   AliITSOnlineCalibrationSPDhandler* GetDiff(const AliITSOnlineCalibrationSPDhandler* other) const;
235   AliITSOnlineCalibrationSPDhandler* GetSilentDiff(const AliITSOnlineCalibrationSPDhandler* other) const;
236   AliITSOnlineCalibrationSPDhandler* GetDeadDiff(const AliITSOnlineCalibrationSPDhandler* other) const;
237   AliITSOnlineCalibrationSPDhandler* GetNoisyDiff(const AliITSOnlineCalibrationSPDhandler* other) const;
238   AliITSTriggerConditions * GetTriggerConditions() const {return fTriggerConditions;}
239
240   void PrintDiffInDead(AliITSOnlineCalibrationSPDhandler *other) const;
241   void PrintDiffInPITmask(AliITSOnlineCalibrationSPDhandler *other) const;
242
243  private:
244   TString fFileLocation;              // location (dir) of files to read and write from
245   AliITSIntMap* fDeadPixelMap[1200];  // lists of dead pixels for each chip
246   AliITSIntMap* fSparseDeadPixelMap[1200];  // lists of dead pixels for each chip (used to define sparse dead pixel on LHC period basis)
247   AliITSIntMap* fNoisyPixelMap[1200]; // lists of noisy pixels for each chip
248   UInt_t fNrDead[1200];               // nr of dead pixels for each chip
249   UInt_t fNrSparseDead[1200];         // nr of sparse dead pixels for each chip
250   UInt_t fNrNoisy[1200];              // nr of noisy pixels for each chip
251   Bool_t fActiveEq[20];               // active bit for each equipment
252   Bool_t fActiveHS[20][6];            // active bit for each half-stave
253   Bool_t fActiveChip[20][6][10];      // active bit for each chip
254   Bool_t fDeadEq[20];                 // dead bit for each equipment
255   Bool_t fDeadHS[20][6];              // dead bit for each half-stave
256   Bool_t fDeadChip[20][6][10];        // dead bit for each chip
257   AliITSTriggerConditions *fTriggerConditions; // PIT conditions (mask, parameters name, parameters values)
258
259
260   Int_t    GetKey(UInt_t eq, UInt_t hs, UInt_t chip, UInt_t col, UInt_t row) const 
261     {return eq*6*10*32*256 + hs*10*32*256 + chip*32*256 + col*256 + row;}
262   UInt_t   GetEqIdFromKey(Int_t key) const 
263     {return key/(6*10*32*256);}
264   UInt_t   GetHSFromKey(Int_t key) const 
265     {return (key%(6*10*32*256))/(10*32*256);}
266   UInt_t   GetChipFromKey(Int_t key) const 
267     {return ((key%(6*10*32*256))%(10*32*256))/(32*256);}
268   UInt_t   GetColFromKey(Int_t key) const 
269     {return (((key%(6*10*32*256))%(10*32*256))%(32*256))/256;}
270   UInt_t   GetRowFromKey(Int_t key) const 
271     {return (((key%(6*10*32*256))%(10*32*256))%(32*256))%256;}
272   UInt_t   GetModuleFromKey(Int_t key) const
273     {return AliITSRawStreamSPD::GetOfflineModuleFromOnline(GetEqIdFromKey(key),GetHSFromKey(key),GetChipFromKey(key));}
274   UInt_t   GetColMFromKey(Int_t key) const 
275     {return AliITSRawStreamSPD::GetOfflineColFromOnline(GetEqIdFromKey(key),GetHSFromKey(key),GetChipFromKey(key),GetColFromKey(key));}
276   UInt_t   GetRowMFromKey(Int_t key) const 
277     {return AliITSRawStreamSPD::GetOfflineRowFromOnline(GetEqIdFromKey(key),GetHSFromKey(key),GetChipFromKey(key),GetRowFromKey(key));}
278   
279   UInt_t   GetGloChip(UInt_t eq, UInt_t hs, UInt_t chip) const {return eq*60 + hs*10 + chip;}
280   UInt_t   GetEqGlo(UInt_t gloChip) const {return gloChip/60;}
281   UInt_t   GetHSGlo(UInt_t gloChip) const {return (gloChip%60)/10;}
282   UInt_t   GetChipGlo(UInt_t gloChip) const {return (gloChip%60)%10;}
283
284   void     GetChipAndIndexDead(UInt_t module, UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const;
285   void     GetChipAndIndexNoisy(UInt_t module, UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const;
286   void     GetChipAndIndexEqDead(UInt_t eq, UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const;
287   void     GetChipAndIndexEqNoisy(UInt_t eq, UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const;
288   void     GetChipAndIndexTotDead(UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const;
289   void     GetChipAndIndexTotNoisy(UInt_t index, UInt_t& gloChip, UInt_t& chipIndex) const;
290
291   UInt_t   GetEqIdFromOffline(UInt_t module) const;
292   UInt_t   GetHSFromOffline(UInt_t module) const;
293   UInt_t   GetChipFromOffline(UInt_t module, UInt_t colM) const;
294   UInt_t   GetColFromOffline(UInt_t module, UInt_t colM) const;
295   UInt_t   GetRowFromOffline(UInt_t module, UInt_t rowM) const;
296
297   void     RecursiveInsertDead(AliITSCalibrationSPD* calibSPD, UInt_t module, Int_t lowInd, Int_t highInd);
298   void     RecursiveInsertSparseDead(AliITSCalibrationSPD* calibSPD, UInt_t module, Int_t lowInd, Int_t highInd);
299   void     RecursiveInsertNoisy(AliITSCalibrationSPD* calibSPD, UInt_t module, Int_t lowInd, Int_t highInd);
300
301   UInt_t   GetNrDeadC2(UInt_t gloChip) const;
302   UInt_t   GetNrSparseDeadC2(UInt_t gloChip) const;
303   UInt_t   GetDeadEqIdAtC2(UInt_t gloChip, UInt_t index) const;
304   UInt_t   GetDeadHSAtC2(UInt_t gloChip, UInt_t index) const;
305   UInt_t   GetDeadChipAtC2(UInt_t gloChip, UInt_t index) const;
306   UInt_t   GetDeadColAtC2(UInt_t gloChip, UInt_t index) const;
307   UInt_t   GetDeadRowAtC2(UInt_t gloChip, UInt_t index) const;    
308   UInt_t   GetNrNoisyC2(UInt_t gloChip) const;
309   UInt_t   GetNoisyEqIdAtC2(UInt_t gloChip, UInt_t index) const;
310   UInt_t   GetNoisyHSAtC2(UInt_t gloChip, UInt_t index) const;
311   UInt_t   GetNoisyChipAtC2(UInt_t gloChip, UInt_t index) const;
312   UInt_t   GetNoisyColAtC2(UInt_t gloChip, UInt_t index) const;
313   UInt_t   GetNoisyRowAtC2(UInt_t gloChip, UInt_t index) const;
314
315 };
316
317 #endif