]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSCalibrationPixUpg.cxx
Decoupled ITS/UPGRADE cmake stuff from ITS
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSCalibrationPixUpg.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"
16#include "AliITSCalibrationPixUpg.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
29ClassImp(AliITSCalibrationPixUpg)
30
31//______________________________________________________________________
32AliITSCalibrationPixUpg::AliITSCalibrationPixUpg()
33: fNChips(0)
34 ,fNColPerChip(0)
35 ,fNCol(0)
36 ,fNRow(0)
37 ,fNrBad(0)
38 ,fBadChips(0)
39 ,fBadChannels(0)
40{
41 // constructor
42 SetDataType("simulated");
43 ClearBad();
44}
45
46//______________________________________________________________________
47AliITSCalibrationPixUpg::AliITSCalibrationPixUpg(Short_t nChips,Short_t nColPerChip,Short_t nRow)
48: fNChips(0)
49 ,fNColPerChip(0)
50 ,fNCol(0)
51 ,fNRow(0)
52 ,fNrBad(0)
53 ,fBadChips(0)
54 ,fBadChannels(0)
55{
56 // constructor
57 SetDataType("simulated");
58 SetColRowData(nChips,nColPerChip,nRow);
59 ClearBad();
60}
61
62//______________________________________________________________________
63AliITSCalibrationPixUpg::AliITSCalibrationPixUpg(const AliITSCalibrationPixUpg &src) :
64 AliITSCalibration(src)
65 ,fNChips(src.fNChips)
66 ,fNColPerChip(src.fNColPerChip)
67 ,fNCol(src.fNCol)
68 ,fNRow(src.fNRow)
69 ,fNrBad(src.fNrBad)
70 ,fBadChips(src.fBadChips)
71 ,fBadChannels(src.fBadChannels)
72{
73}
74
75//____________________________________________________________________________
76void AliITSCalibrationPixUpg::ClearBad()
77{
78 // clear all bad pixels (single+chips)
79 fBadChannels.Reset();
80 fNrBad=0;
81 fBadChips = 0;
82 //
83}
84
85//____________________________________________________________________________
86void AliITSCalibrationPixUpg::AddBad(Int_t col, Int_t row)
87{
88 // add single bad pixel
89 fBadChannels.Set(fNrBad*2+2);
90 fBadChannels.AddAt(col,fNrBad*2);
91 fBadChannels.AddAt(row,fNrBad*2+1);
92 fNrBad++;
93}
94
95//____________________________________________________________________________
96void AliITSCalibrationPixUpg::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//____________________________________________________________________________
105void AliITSCalibrationPixUpg::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//____________________________________________________________________________
114Int_t AliITSCalibrationPixUpg::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//____________________________________________________________________________
137Int_t AliITSCalibrationPixUpg::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//____________________________________________________________________________
160void AliITSCalibrationPixUpg::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//___________________________________________________________________________
193Int_t AliITSCalibrationPixUpg::GetNrBad() const
194{
195 // Total number of bad pixels (including bad chips) in a given module
196 Int_t bad=0;
197 // single pixels:
198 bad += fNrBad;
199 // whole chips:
200 for (int chip=fNChips; chip--;) if (IsChipMarkedBad(chip)) bad += fNColPerChip*fNRow;
201 return bad;
202}
203
204//___________________________________________________________________________
205Int_t AliITSCalibrationPixUpg::GetNrBadInChip(Int_t chip) const
206{
207 // Total number of bad pixels (including bad chips) in a given chip
208 if(chip<0 || chip>=fNChips) {AliError("Wrong chip number"); return -1;}
209 if (IsChipMarkedBad(chip)) return fNColPerChip*fNRow;
210 else {
211 Int_t bad=0;
212 for (int i=fNrBad; i--;) {
213 Int_t col = GetBadColAt(i);
214 if (col!=-1) if (GetChipIndexFromCol(col)==chip) bad++;
215 }
216 return bad;
217 }
218}
219
220//___________________________________________________________________________
221Int_t AliITSCalibrationPixUpg::GetNrBadInColumn(Int_t col) const
222{
223 // Total number of bad pixels (including bad chips) in a given column: col. range
224 if(col<0 || col>=fNCol) {AliError("Wrong column number"); return -1;}
225 if (IsChipMarkedBad(GetChipIndexFromCol(col))) return fNRow;
226 else {
227 Int_t bad=0;
228 for (int i=fNrBad; i--;) if (GetBadColAt(i)==col) bad++;
229 return bad;
230 }
231}
232
233//______________________________________________________________________
234Bool_t AliITSCalibrationPixUpg::IsBad() const
235{
236 // Are all chips of this module bad?
237 for (Int_t chip=fNChips; chip--;) if (!IsChipMarkedBad(chip)) return kFALSE;
238 return kTRUE;
239}
240
241//______________________________________________________________________
242Bool_t AliITSCalibrationPixUpg::IsChipBad(Int_t chip) const
243{
244 // Is the full chip bad?
245 return (GetNrBadInChip(chip)==fNColPerChip*fNRow);
246}
247
248//______________________________________________________________________
249Bool_t AliITSCalibrationPixUpg::IsColumnBad(Int_t col) const
250{
251 // Is the full column bad?
252 return (GetNrBadInColumn(col)==fNRow);
253}
254
255//____________________________________________________________________________
256Bool_t AliITSCalibrationPixUpg::IsPixelBad(Int_t col, Int_t row) const
257{
258 // Is this pixel bad?
259 if(col<0 || col>=fNCol) {AliError("Wrong column number"); return kFALSE;}
260 Int_t chip = GetChipIndexFromCol(col);
261 if (IsChipMarkedBad(chip)) return kTRUE;
262 for (Int_t i=fNrBad; i--;) if (GetBadColAt(i)==col && GetBadRowAt(i)==row) return kTRUE;
263 return kFALSE;
264}
265
266//______________________________________________________________________
267Int_t AliITSCalibrationPixUpg::GetChipIndexFromCol(Int_t col) const
268{
269 // returns chip index for specific column
270 if(col>=fNCol) {AliWarning("Wrong column number"); return -1;}
271 return col/fNColPerChip;
272}
273
274//______________________________________________________________________
275void AliITSCalibrationPixUpg::SetNrBad(Int_t /*nr*/)
276{
277 // should not be used anymore !!!
278 AliError("This method should not be used anymore. Use SetNrBadSingle instead!!!");
279}
280
281//____________________________________________________________________________
282void AliITSCalibrationPixUpg::SetColRowData(Short_t nchip, Short_t ncolperchip, Short_t nrow)
283{
284 // set segmentation data
285 fNChips = nchip;
286 fNCol = nchip*ncolperchip;
287 fNRow = nrow;
288 fNColPerChip = ncolperchip;
289}