]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUCalibrationPix.cxx
adding contamination correct for trigger particles
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUCalibrationPix.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15 #include "TArrayI.h"
16 #include "AliITSUCalibrationPix.h"
17
18 ///////////////////////////////////////////////////////////////////////////
19 //
20 //  Calibration class for set:ITS                   
21 //  Specific subdetector implementation for         
22 //  Silicon pixels                                  
23 //
24 //  Modified by D. Elia, G.E. Bruno, H. Tydesjo
25 //  Adapted for upgrade ruben.shahoyan@cern.ch
26 //
27 ///////////////////////////////////////////////////////////////////////////
28
29 ClassImp(AliITSUCalibrationPix)
30
31 //______________________________________________________________________
32 AliITSUCalibrationPix::AliITSUCalibrationPix() 
33 : fNChips(0)
34   ,fNColPerChip(0)
35   ,fNCol(0)
36   ,fNRow(0)
37   ,fNrBadSingle(0)
38   ,fBadChips(0)
39   ,fBadChannels(0)
40 {
41   // constructor
42    SetDataType("simulated");
43    ClearBad();
44 }
45
46 //______________________________________________________________________
47 AliITSUCalibrationPix::AliITSUCalibrationPix(Short_t nChips,Short_t nColPerChip,Short_t nRow) 
48 : fNChips(0)
49   ,fNColPerChip(0)
50   ,fNCol(0)
51   ,fNRow(0)
52   ,fNrBadSingle(0)
53   ,fBadChips(0)
54   ,fBadChannels(0)
55 {
56   // constructor
57    SetDataType("simulated");
58    SetColRowData(nChips,nColPerChip,nRow);
59    ClearBad();
60 }
61
62 //______________________________________________________________________
63 AliITSUCalibrationPix::AliITSUCalibrationPix(const AliITSUCalibrationPix &src) : 
64   AliITSCalibration(src)
65   ,fNChips(src.fNChips)
66   ,fNColPerChip(src.fNColPerChip)
67   ,fNCol(src.fNCol)
68   ,fNRow(src.fNRow)
69   ,fNrBadSingle(src.fNrBadSingle)
70   ,fBadChips(src.fBadChips)
71   ,fBadChannels(src.fBadChannels)
72 {
73 }
74
75 //____________________________________________________________________________
76 void AliITSUCalibrationPix::ClearBad() 
77 {
78   // clear all bad pixels (single+chips)
79   fBadChannels.Reset();
80   fNrBadSingle=0;
81   fBadChips = 0;
82   //
83 }
84
85 //____________________________________________________________________________
86 void AliITSUCalibrationPix::AddBad(Int_t col, Int_t row) 
87 {
88   // add single bad pixel 
89   fBadChannels.Set(fNrBadSingle*2+2);
90   fBadChannels.AddAt(col,fNrBadSingle*2);
91   fBadChannels.AddAt(row,fNrBadSingle*2+1);
92   fNrBadSingle++;
93 }
94
95 //____________________________________________________________________________
96 void AliITSUCalibrationPix::SetChipBad(Int_t chip) 
97 {
98   // set full chip bad
99   if ((int)chip>=fNChips) {AliError(Form("chip number %d exceeds allowed limit %d",chip,fNChips)); return;}
100   fBadChips |= 0x1<<chip;
101   //
102 }
103
104 //____________________________________________________________________________
105 void AliITSUCalibrationPix::UnSetChipBad(Int_t chip) 
106 {
107   // unset full chip bad
108   if (chip>=fNChips) {AliError(Form("chip number %d exceeds allowed limit %d",chip,fNChips)); return;}
109   fBadChips &= ~(0x1<<chip);
110   //
111 }
112
113 //____________________________________________________________________________
114 Int_t AliITSUCalibrationPix::GetBadColAt(Int_t index) const 
115 {
116   // Get column of index-th bad pixel
117   int nrc = fNColPerChip*fNRow;
118   if (nrc<1) AliFatal("Number of colums and rows is not set");
119   //
120   if ((Int_t)index<GetNrBadSingle()) return fBadChannels.At(index*2);
121   else {
122     Int_t badChipIndex=(index-GetNrBadSingle())/nrc;
123     Int_t badChipsFound =0;
124     for (int chip=fNChips; chip--;) {
125       if (IsChipMarkedBad(chip)) badChipsFound++;
126       if (badChipIndex==badChipsFound-1) {
127         Int_t badPixelIndex=(index-GetNrBadSingle())%(nrc);
128         return chip*fNColPerChip + badPixelIndex/fNRow;
129       }
130     }
131   }
132   AliError(Form("Index %d is out of bounds - returning -1",index));
133   return -1;
134 }
135
136 //____________________________________________________________________________
137 Int_t AliITSUCalibrationPix::GetBadRowAt(Int_t index) const 
138 {
139   // Get row of index-th bad pixel
140   int nrc = fNColPerChip*fNRow;
141   if (nrc<1) AliFatal("Number of colums and rows is not set");
142   //
143   if ((Int_t)index<GetNrBadSingle()) return fBadChannels.At(index*2+1);
144   else {
145     Int_t badChipIndex=(index-GetNrBadSingle())/nrc;
146     Int_t badChipsFound =0;
147     for (int chip=fNChips; chip--;) {
148       if (IsChipMarkedBad(chip)) badChipsFound++;
149       if (badChipIndex==badChipsFound-1) {
150         Int_t badPixelIndex=(index-GetNrBadSingle())%nrc;
151         return badPixelIndex%fNRow;
152       }
153     }
154   }
155   AliError(Form("Index %d is out of bounds - returning -1",index));
156   return -1;
157 }
158
159 //____________________________________________________________________________
160 void AliITSUCalibrationPix::GetBadPixel(Int_t index, Int_t &row, Int_t &col) const 
161 {
162   // i: is the i-th bad pixel in single bad pixel list
163   // row: is the corresponding row (-1 if i is out of range)
164   // col: is the corresponding column (-1 if i is out of range)
165   row = -1;
166   col = -1;
167   if(index>=0 && index<GetNrBadSingle()){
168     col = GetBadColAt(index);
169     row = GetBadRowAt(index);
170     return;
171   }
172   else {
173     if (index>=0) {
174       int nrc = fNColPerChip*fNRow;
175       if (nrc<1) AliFatal("Number of colums and rows is not set");
176       Int_t badChipIndex=(index-GetNrBadSingle())/nrc;
177       Int_t badChipsFound =0;
178       for (int chip=fNChips; chip--;) {
179         if (IsChipMarkedBad(chip)) badChipsFound++;
180         if (badChipIndex==badChipsFound-1) {
181           Int_t badPixelIndex=(index-GetNrBadSingle())%nrc;
182           col = chip*fNColPerChip + badPixelIndex/fNRow;
183           row = badPixelIndex%fNRow;
184           return;
185         }
186       }
187     }
188   }
189   AliError(Form("Index %d is out of bounds - nothing done",index));
190 }
191
192 //____________________________________________________________________________
193 void AliITSUCalibrationPix::GetBadPixelSingle(Int_t index, UInt_t &row, UInt_t &col) const 
194 {
195   // i: is the i-th bad pixel in single bad pixel list
196   // row: is the corresponding row (-1 if i is out of range)
197   // col: is the corresponding column (-1 if i is out of range)
198   if(index<0 && index>=GetNrBadSingle())  AliFatal(Form("Index %d >= NrBadSingle=%d",index,fNrBadSingle));
199   col = fBadChannels.At(index*2);
200   row = fBadChannels.At(index*2+1);
201 }
202
203 //___________________________________________________________________________
204 Int_t  AliITSUCalibrationPix::GetNrBad() const 
205 {
206   // Total number of bad pixels (including bad chips) in a given module
207   Int_t bad=0;
208   // single pixels:
209   bad += fNrBadSingle;
210   // whole chips:
211   for (int chip=fNChips; chip--;) if (IsChipMarkedBad(chip)) bad += fNColPerChip*fNRow;
212   return bad;
213 }
214
215 //___________________________________________________________________________
216 Int_t  AliITSUCalibrationPix::GetNrBadInChip(Int_t chip) const 
217 {
218   // Total number of bad pixels (including bad chips) in a given chip
219   if(chip<0 || chip>=fNChips) {AliError("Wrong chip number"); return -1;}
220   if (IsChipMarkedBad(chip)) return fNColPerChip*fNRow;
221   else {
222     Int_t bad=0;
223     for (int i=fNrBadSingle; i--;) {
224       Int_t col = GetBadColAt(i);
225       if (col!=-1) if (GetChipIndexFromCol(col)==chip) bad++;
226     }
227     return bad;
228   }
229 }
230
231 //___________________________________________________________________________
232 Int_t  AliITSUCalibrationPix::GetNrBadInColumn(Int_t col) const 
233 {
234   // Total number of bad pixels (including bad chips) in a given column: col. range
235   if(col<0 || col>=fNCol) {AliError("Wrong column number"); return -1;}
236   if (IsChipMarkedBad(GetChipIndexFromCol(col))) return fNRow;
237   else {
238     Int_t bad=0;
239     for (int i=fNrBadSingle; i--;) if (GetBadColAt(i)==col) bad++;
240     return bad;
241   }
242 }
243
244 //______________________________________________________________________
245 Bool_t AliITSUCalibrationPix::IsBad() const 
246 {
247   // Are all chips of this module bad?
248   for (Int_t chip=fNChips; chip--;) if (!IsChipMarkedBad(chip)) return kFALSE;
249   return kTRUE;
250 }
251
252 //______________________________________________________________________
253 Bool_t AliITSUCalibrationPix::IsChipBad(Int_t chip) const 
254 {
255   // Is the full chip bad?
256   return (GetNrBadInChip(chip)==fNColPerChip*fNRow);
257 }
258
259 //______________________________________________________________________
260 Bool_t AliITSUCalibrationPix::IsColumnBad(Int_t col) const 
261 {
262   // Is the full column bad?
263   return (GetNrBadInColumn(col)==fNRow);
264 }
265
266 //____________________________________________________________________________
267 Bool_t AliITSUCalibrationPix::IsPixelBad(Int_t col, Int_t row) const 
268 {
269   // Is this pixel bad?
270   if(col<0 || col>=fNCol) {AliError("Wrong column number"); return kFALSE;}
271   Int_t chip = GetChipIndexFromCol(col);
272   if (IsChipMarkedBad(chip)) return kTRUE;
273   for (Int_t i=fNrBadSingle; i--;) if (GetBadColAt(i)==col && GetBadRowAt(i)==row) return kTRUE;
274   return kFALSE;
275 }
276
277 //______________________________________________________________________
278 Int_t AliITSUCalibrationPix::GetChipIndexFromCol(Int_t col) const 
279 {
280   // returns chip index for specific column
281   if(col>=fNCol) {AliWarning("Wrong column number"); return -1;}
282   return col/fNColPerChip;
283 }
284
285 //______________________________________________________________________
286 void AliITSUCalibrationPix::SetNrBad(Int_t /*nr*/) 
287 {
288   // should not be used anymore !!!
289   AliError("This method should not be used anymore. Use SetNrBadSingle instead!!!");
290 }
291
292 //____________________________________________________________________________
293 void  AliITSUCalibrationPix::SetColRowData(Short_t nchip, Short_t ncolperchip, Short_t nrow) 
294 {
295   // set segmentation data
296   fNChips = nchip; 
297   fNCol   = nchip*ncolperchip; 
298   fNRow   = nrow; 
299   fNColPerChip = ncolperchip;
300 }