]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSCalibrationSPD.cxx
A skeleton of a comparison macro for pileup studies
[u/mrichter/AliRoot.git] / ITS / AliITSCalibrationSPD.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 "AliITSCalibrationSPD.h"
17
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
24 ///////////////////////////////////////////////////////////////////////////
25
26 ClassImp(AliITSCalibrationSPD)
27
28 //______________________________________________________________________
29 AliITSCalibrationSPD::AliITSCalibrationSPD():
30 AliITSCalibration(),
31 fNrBad(0),
32 fBadChannels(0){
33   // constructor
34
35    SetDataType("simulated");
36    ClearBad();
37 }
38 //____________________________________________________________________________
39 void 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   }
46 }
47 //____________________________________________________________________________
48 void AliITSCalibrationSPD::AddBad(UInt_t col, UInt_t row) {
49   // add single bad pixel 
50   fBadChannels.Set(fNrBad*2+2);
51   fBadChannels.AddAt(col,fNrBad*2);
52   fBadChannels.AddAt(row,fNrBad*2+1);
53   fNrBad++;
54 }
55 //____________________________________________________________________________
56 void AliITSCalibrationSPD::SetChipBad(UInt_t chip) {
57   // set full chip bad
58   if (chip>=5) {AliError("Wrong chip number");
59   }
60   else {
61     fBadChip[chip]=kTRUE;
62   }
63 }
64 //____________________________________________________________________________
65 void AliITSCalibrationSPD::UnSetChipBad(UInt_t chip) {
66   // unset full chip bad
67   if (chip>=5 ) {AliError("Wrong chip number");
68   }
69   else {
70     fBadChip[chip]=kFALSE;
71   }
72 }
73 //____________________________________________________________________________
74 Int_t AliITSCalibrationSPD::GetBadColAt(UInt_t index) const {
75   // Get column of index-th bad pixel
76   if ((Int_t)index<GetNrBadSingle()) {
77     return fBadChannels.At(index*2);
78   }
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));
91   return -1;
92 }
93 //____________________________________________________________________________
94 Int_t AliITSCalibrationSPD::GetBadRowAt(UInt_t index) const {
95   // Get row of index-th bad pixel
96   if ((Int_t)index<GetNrBadSingle()) {
97     return fBadChannels.At(index*2+1);
98   }
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       }
108     }
109   }
110   AliError(Form("Index %d is out of bounds - returning -1",index));
111   return -1;
112 }
113 //____________________________________________________________________________
114 void 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
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;
120   if(index>=0 && index<GetNrBadSingle()){
121     col = GetBadColAt(index);
122     row = GetBadRowAt(index);
123     return;
124   }
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));
141 }
142 //___________________________________________________________________________
143 Int_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;
153 }
154 //___________________________________________________________________________
155 Int_t  AliITSCalibrationSPD::GetNrBadInChip(Int_t chip) const {
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 //___________________________________________________________________________
171 Int_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 //______________________________________________________________________
184 Bool_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 //______________________________________________________________________
192 Bool_t AliITSCalibrationSPD::IsChipBad(Int_t chip) const {
193   // Is the full chip bad?
194   return (GetNrBadInChip(chip)==32*256);
195 }
196 //______________________________________________________________________
197 Bool_t AliITSCalibrationSPD::IsColumnBad(Int_t col) const {
198   // Is the full column bad?
199   return (GetNrBadInColumn(col)==256);
200 }
201 //____________________________________________________________________________
202 Bool_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 //______________________________________________________________________
215 Int_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 //______________________________________________________________________
221 void AliITSCalibrationSPD::SetNrBad(UInt_t /*nr*/) {
222   // should not be used anymore !!!
223   AliError("This method should not be used anymore. Use SetNrBadSingle instead!!!");
224 }
225 //______________________________________________________________________
226 void AliITSCalibrationSPD::Streamer(TBuffer &ruub) {
227   // Stream an object of class AliITSCalibrationSPD.
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);
236     }
237     else {
238       Double_t dummy;
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);
250       }
251       else {
252         if (ruuv == 6) {
253           fBadChannels.Streamer(ruub);
254         }
255         else {
256           TArrayI fBadChannelsV1;
257           fBadChannelsV1.Streamer(ruub);
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;
265         }
266       }
267     }
268     ruub.CheckByteCount(ruus, ruuc, AliITSCalibrationSPD::IsA());
269   }
270   else {
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);
277   }
278 }