]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSUCalibrationPix.cxx
update in integrated v2 macro
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUCalibrationPix.cxx
CommitLineData
a84c4b15 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"
451f5018 16#include "AliITSUCalibrationPix.h"
a84c4b15 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
451f5018 29ClassImp(AliITSUCalibrationPix)
a84c4b15 30
31//______________________________________________________________________
451f5018 32AliITSUCalibrationPix::AliITSUCalibrationPix()
a84c4b15 33: fNChips(0)
34 ,fNColPerChip(0)
35 ,fNCol(0)
36 ,fNRow(0)
451f5018 37 ,fNrBadSingle(0)
a84c4b15 38 ,fBadChips(0)
39 ,fBadChannels(0)
40{
41 // constructor
42 SetDataType("simulated");
43 ClearBad();
44}
45
46//______________________________________________________________________
451f5018 47AliITSUCalibrationPix::AliITSUCalibrationPix(Short_t nChips,Short_t nColPerChip,Short_t nRow)
a84c4b15 48: fNChips(0)
49 ,fNColPerChip(0)
50 ,fNCol(0)
51 ,fNRow(0)
451f5018 52 ,fNrBadSingle(0)
a84c4b15 53 ,fBadChips(0)
54 ,fBadChannels(0)
55{
56 // constructor
57 SetDataType("simulated");
58 SetColRowData(nChips,nColPerChip,nRow);
59 ClearBad();
60}
61
62//______________________________________________________________________
451f5018 63AliITSUCalibrationPix::AliITSUCalibrationPix(const AliITSUCalibrationPix &src) :
a84c4b15 64 AliITSCalibration(src)
65 ,fNChips(src.fNChips)
66 ,fNColPerChip(src.fNColPerChip)
67 ,fNCol(src.fNCol)
68 ,fNRow(src.fNRow)
451f5018 69 ,fNrBadSingle(src.fNrBadSingle)
a84c4b15 70 ,fBadChips(src.fBadChips)
71 ,fBadChannels(src.fBadChannels)
72{
73}
74
75//____________________________________________________________________________
451f5018 76void AliITSUCalibrationPix::ClearBad()
a84c4b15 77{
78 // clear all bad pixels (single+chips)
79 fBadChannels.Reset();
451f5018 80 fNrBadSingle=0;
a84c4b15 81 fBadChips = 0;
82 //
83}
84
85//____________________________________________________________________________
451f5018 86void AliITSUCalibrationPix::AddBad(Int_t col, Int_t row)
a84c4b15 87{
88 // add single bad pixel
451f5018 89 fBadChannels.Set(fNrBadSingle*2+2);
90 fBadChannels.AddAt(col,fNrBadSingle*2);
91 fBadChannels.AddAt(row,fNrBadSingle*2+1);
92 fNrBadSingle++;
a84c4b15 93}
94
95//____________________________________________________________________________
451f5018 96void AliITSUCalibrationPix::SetChipBad(Int_t chip)
a84c4b15 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//____________________________________________________________________________
451f5018 105void AliITSUCalibrationPix::UnSetChipBad(Int_t chip)
a84c4b15 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//____________________________________________________________________________
451f5018 114Int_t AliITSUCalibrationPix::GetBadColAt(Int_t index) const
a84c4b15 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//____________________________________________________________________________
451f5018 137Int_t AliITSUCalibrationPix::GetBadRowAt(Int_t index) const
a84c4b15 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//____________________________________________________________________________
451f5018 160void AliITSUCalibrationPix::GetBadPixel(Int_t index, Int_t &row, Int_t &col) const
a84c4b15 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
451f5018 192//____________________________________________________________________________
193void 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
a84c4b15 203//___________________________________________________________________________
451f5018 204Int_t AliITSUCalibrationPix::GetNrBad() const
a84c4b15 205{
206 // Total number of bad pixels (including bad chips) in a given module
207 Int_t bad=0;
208 // single pixels:
451f5018 209 bad += fNrBadSingle;
a84c4b15 210 // whole chips:
211 for (int chip=fNChips; chip--;) if (IsChipMarkedBad(chip)) bad += fNColPerChip*fNRow;
212 return bad;
213}
214
215//___________________________________________________________________________
451f5018 216Int_t AliITSUCalibrationPix::GetNrBadInChip(Int_t chip) const
a84c4b15 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;
451f5018 223 for (int i=fNrBadSingle; i--;) {
a84c4b15 224 Int_t col = GetBadColAt(i);
225 if (col!=-1) if (GetChipIndexFromCol(col)==chip) bad++;
226 }
227 return bad;
228 }
229}
230
231//___________________________________________________________________________
451f5018 232Int_t AliITSUCalibrationPix::GetNrBadInColumn(Int_t col) const
a84c4b15 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;
451f5018 239 for (int i=fNrBadSingle; i--;) if (GetBadColAt(i)==col) bad++;
a84c4b15 240 return bad;
241 }
242}
243
244//______________________________________________________________________
451f5018 245Bool_t AliITSUCalibrationPix::IsBad() const
a84c4b15 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//______________________________________________________________________
451f5018 253Bool_t AliITSUCalibrationPix::IsChipBad(Int_t chip) const
a84c4b15 254{
255 // Is the full chip bad?
256 return (GetNrBadInChip(chip)==fNColPerChip*fNRow);
257}
258
259//______________________________________________________________________
451f5018 260Bool_t AliITSUCalibrationPix::IsColumnBad(Int_t col) const
a84c4b15 261{
262 // Is the full column bad?
263 return (GetNrBadInColumn(col)==fNRow);
264}
265
266//____________________________________________________________________________
451f5018 267Bool_t AliITSUCalibrationPix::IsPixelBad(Int_t col, Int_t row) const
a84c4b15 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;
451f5018 273 for (Int_t i=fNrBadSingle; i--;) if (GetBadColAt(i)==col && GetBadRowAt(i)==row) return kTRUE;
a84c4b15 274 return kFALSE;
275}
276
277//______________________________________________________________________
451f5018 278Int_t AliITSUCalibrationPix::GetChipIndexFromCol(Int_t col) const
a84c4b15 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//______________________________________________________________________
451f5018 286void AliITSUCalibrationPix::SetNrBad(Int_t /*nr*/)
a84c4b15 287{
288 // should not be used anymore !!!
289 AliError("This method should not be used anymore. Use SetNrBadSingle instead!!!");
290}
291
292//____________________________________________________________________________
451f5018 293void AliITSUCalibrationPix::SetColRowData(Short_t nchip, Short_t ncolperchip, Short_t nrow)
a84c4b15 294{
295 // set segmentation data
296 fNChips = nchip;
297 fNCol = nchip*ncolperchip;
298 fNRow = nrow;
299 fNColPerChip = ncolperchip;
300}