store also difference in local Y
[u/mrichter/AliRoot.git] / ITS / AliITSCalibrationSPD.cxx
CommitLineData
fcf95fc7 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 **************************************************************************/
cfe39822 15#include "TArrayI.h"
fcf95fc7 16#include "AliITSCalibrationSPD.h"
cfe39822 17
590d15ee 18///////////////////////////////////////////////////////////////////////////
19// Calibration class for set:ITS
20// Specific subdetector implementation for
21// Silicon pixels
22//
23// Modified by D. Elia, G.E. Bruno, H. Tydesjo
590d15ee 24///////////////////////////////////////////////////////////////////////////
b15de2d2 25
478d804c 26ClassImp(AliITSCalibrationSPD)
590d15ee 27
fcf95fc7 28//______________________________________________________________________
29AliITSCalibrationSPD::AliITSCalibrationSPD():
30AliITSCalibration(),
6727e2db 31fNrBad(0),
32fBadChannels(0){
fcf95fc7 33 // constructor
34
fcf95fc7 35 SetDataType("simulated");
478d804c 36 ClearBad();
37}
38//____________________________________________________________________________
39void AliITSCalibrationSPD::ClearBad() {
40 // clear all bad pixels (single+chips)
41 fBadChannels.Reset();
42 fNrBad=0;
43 for (UInt_t chip=0; chip<5; chip++) {
44 fBadChip[chip]=kFALSE;
45 }
fcf95fc7 46}
5bfe44ce 47//____________________________________________________________________________
6727e2db 48void AliITSCalibrationSPD::AddBad(UInt_t col, UInt_t row) {
478d804c 49 // add single bad pixel
6727e2db 50 fBadChannels.Set(fNrBad*2+2);
51 fBadChannels.AddAt(col,fNrBad*2);
52 fBadChannels.AddAt(row,fNrBad*2+1);
53 fNrBad++;
5bfe44ce 54}
590d15ee 55//____________________________________________________________________________
478d804c 56void AliITSCalibrationSPD::SetChipBad(UInt_t chip) {
57 // set full chip bad
c65bdda2 58 if (chip>=5) {AliError("Wrong chip number");
0586b4f5 59 }
60 else {
61 fBadChip[chip]=kTRUE;
62 }
478d804c 63}
64//____________________________________________________________________________
65void AliITSCalibrationSPD::UnSetChipBad(UInt_t chip) {
66 // unset full chip bad
c65bdda2 67 if (chip>=5 ) {AliError("Wrong chip number");
0586b4f5 68 }
69 else {
70 fBadChip[chip]=kFALSE;
71 }
478d804c 72}
73//____________________________________________________________________________
74Int_t AliITSCalibrationSPD::GetBadColAt(UInt_t index) const {
6727e2db 75 // Get column of index-th bad pixel
478d804c 76 if ((Int_t)index<GetNrBadSingle()) {
6727e2db 77 return fBadChannels.At(index*2);
5bfe44ce 78 }
478d804c 79 else {
80 Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
81 Int_t badChipsFound =0;
82 for (UInt_t chip=0; chip<5; chip++) {
83 if (fBadChip[chip]) badChipsFound++;
84 if (badChipIndex==badChipsFound-1) {
85 Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
86 return chip*32 + badPixelIndex/256;
87 }
88 }
89 }
90 AliError(Form("Index %d is out of bounds - returning -1",index));
5bfe44ce 91 return -1;
92}
590d15ee 93//____________________________________________________________________________
478d804c 94Int_t AliITSCalibrationSPD::GetBadRowAt(UInt_t index) const {
6727e2db 95 // Get row of index-th bad pixel
478d804c 96 if ((Int_t)index<GetNrBadSingle()) {
6727e2db 97 return fBadChannels.At(index*2+1);
5bfe44ce 98 }
478d804c 99 else {
100 Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
101 Int_t badChipsFound =0;
102 for (UInt_t chip=0; chip<5; chip++) {
103 if (fBadChip[chip]) badChipsFound++;
104 if (badChipIndex==badChipsFound-1) {
105 Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
106 return badPixelIndex%256;
107 }
5bfe44ce 108 }
109 }
478d804c 110 AliError(Form("Index %d is out of bounds - returning -1",index));
111 return -1;
5bfe44ce 112}
8d37cc87 113//____________________________________________________________________________
478d804c 114void AliITSCalibrationSPD::GetBadPixel(Int_t index, Int_t &row, Int_t &col) const {
115 // i: is the i-th bad pixel in single bad pixel list
8d37cc87 116 // row: is the corresponding row (-1 if i is out of range)
117 // col: is the corresponding column (-1 if i is out of range)
118 row = -1;
119 col = -1;
478d804c 120 if(index>=0 && index<GetNrBadSingle()){
121 col = GetBadColAt(index);
122 row = GetBadRowAt(index);
8d37cc87 123 return;
124 }
478d804c 125 else {
126 if (index>=0) {
127 Int_t badChipIndex=(index-GetNrBadSingle())/(32*256);
128 Int_t badChipsFound =0;
129 for (UInt_t chip=0; chip<5; chip++) {
130 if (fBadChip[chip]) badChipsFound++;
131 if (badChipIndex==badChipsFound-1) {
132 Int_t badPixelIndex=(index-GetNrBadSingle())%(32*256);
133 col = chip*32 + badPixelIndex/256;
134 row = badPixelIndex%256;
135 return;
136 }
137 }
138 }
139 }
140 AliError(Form("Index %d is out of bounds - nothing done",index));
8d37cc87 141}
1bdd39a1 142//___________________________________________________________________________
478d804c 143Int_t AliITSCalibrationSPD::GetNrBad() const {
144 // Total number of bad pixels (including bad chips) in a given module
145 Int_t bad=0;
146 // single pixels:
147 bad+=fNrBad;
148 // whole chips:
149 for (UInt_t chip=0; chip<5; chip++) {
150 bad+=fBadChip[chip]*32*256;
151 }
152 return bad;
1bdd39a1 153}
154//___________________________________________________________________________
155Int_t AliITSCalibrationSPD::GetNrBadInChip(Int_t chip) const {
478d804c 156 // Total number of bad pixels (including bad chips) in a given chip: chip range [0,4]
157 if(chip<0 || chip>4) {AliError("Wrong chip number"); return -1;}
158 if (fBadChip[chip]) return 32*256;
159 else {
160 Int_t bad=0;
161 for (UInt_t i=0; i<fNrBad; i++) {
162 Int_t col = GetBadColAt(i);
163 if (col!=-1) {
164 if (GetChipIndexFromCol(col)==chip) bad++;
165 }
166 }
167 return bad;
168 }
169}
170//___________________________________________________________________________
171Int_t AliITSCalibrationSPD::GetNrBadInColumn(Int_t col) const {
172 // Total number of bad pixels (including bad chips) in a given column: col. range [0,159]
173 if(col<0 || col>159) {AliError("Wrong column number"); return -1;}
174 if (fBadChip[GetChipIndexFromCol(col)]) return 256;
175 else {
176 Int_t bad=0;
177 for (UInt_t i=0; i<fNrBad; i++) {
178 if (GetBadColAt(i)==col) bad++;
179 }
180 return bad;
181 }
182}
183//______________________________________________________________________
184Bool_t AliITSCalibrationSPD::IsBad() const {
185 // Are all chips of this module bad?
186 for (UInt_t chip=0; chip<5; chip++) {
187 if (!fBadChip[chip]) return kFALSE;
188 }
189 return kTRUE;
190}
191//______________________________________________________________________
192Bool_t AliITSCalibrationSPD::IsChipBad(Int_t chip) const {
193 // Is the full chip bad?
194 return (GetNrBadInChip(chip)==32*256);
195}
196//______________________________________________________________________
197Bool_t AliITSCalibrationSPD::IsColumnBad(Int_t col) const {
198 // Is the full column bad?
199 return (GetNrBadInColumn(col)==256);
200}
201//____________________________________________________________________________
202Bool_t AliITSCalibrationSPD::IsPixelBad(Int_t col, Int_t row) const {
203 // Is this pixel bad?
204 if(col<0 || col>159) {AliError("Wrong column number"); return kFALSE;}
205 Int_t chip = GetChipIndexFromCol(col);
206 if (fBadChip[chip]) return kTRUE;
207 for (UInt_t i=0; i<fNrBad; i++) {
208 if (GetBadColAt(i)==col && GetBadRowAt(i)==row) {
209 return kTRUE;
210 }
211 }
212 return kFALSE;
213}
214//______________________________________________________________________
215Int_t AliITSCalibrationSPD::GetChipIndexFromCol(UInt_t col) const {
216 // returns chip index for specific column
217 if(col>=160) {AliWarning("Wrong column number"); return -1;}
218 return col/32;
219}
220//______________________________________________________________________
221void AliITSCalibrationSPD::SetNrBad(UInt_t /*nr*/) {
222 // should not be used anymore !!!
223 AliError("This method should not be used anymore. Use SetNrBadSingle instead!!!");
1bdd39a1 224}
14089bc5 225//______________________________________________________________________
cfe39822 226void AliITSCalibrationSPD::Streamer(TBuffer &ruub) {
14089bc5 227 // Stream an object of class AliITSCalibrationSPD.
cfe39822 228 UInt_t ruus, ruuc;
229 if (ruub.IsReading()) {
230 Version_t ruuv = ruub.ReadVersion(&ruus, &ruuc); if (ruuv) { }
231 AliITSCalibration::Streamer(ruub);
232 if (ruuv >= 8) {
233 ruub >> fNrBad;
234 fBadChannels.Streamer(ruub);
235 ruub.ReadStaticArray((bool*)fBadChip);
14089bc5 236 }
237 else {
bb292d31 238 Double_t dummy;
cfe39822 239 ruub >> dummy;
240 ruub >> dummy;
241 ruub >> dummy;
242 ruub >> dummy;
243 ruub >> dummy;
244 ruub >> dummy;
245 ruub >> dummy;
246 ruub >> fNrBad;
247 if (ruuv == 7) {
248 fBadChannels.Streamer(ruub);
249 ruub.ReadStaticArray((bool*)fBadChip);
478d804c 250 }
251 else {
cfe39822 252 if (ruuv == 6) {
253 fBadChannels.Streamer(ruub);
bb292d31 254 }
255 else {
256 TArrayI fBadChannelsV1;
cfe39822 257 fBadChannelsV1.Streamer(ruub);
bb292d31 258 fBadChannels.Set(fNrBad*2);
259 for (UInt_t i=0; i<fNrBad*2; i++) {
260 fBadChannels[i] = fBadChannelsV1[i];
261 }
262 }
263 for (UInt_t i=0; i<5; i++) {
264 fBadChip[i]=kFALSE;
478d804c 265 }
14089bc5 266 }
267 }
cfe39822 268 ruub.CheckByteCount(ruus, ruuc, AliITSCalibrationSPD::IsA());
14089bc5 269 }
270 else {
cfe39822 271 ruuc = ruub.WriteVersion(AliITSCalibrationSPD::IsA(), kTRUE);
272 AliITSCalibration::Streamer(ruub);
273 ruub << fNrBad;
274 fBadChannels.Streamer(ruub);
275 ruub.WriteArray(fBadChip, 5);
276 ruub.SetByteCount(ruuc, kTRUE);
14089bc5 277 }
278}