ddbe16d5 |
1 | ////////////////////////////////////////////////////////////////////////// |
2 | // // |
3 | // Example of usage: // |
4 | // 1. Fix the seed // |
5 | // 2. Randomly store 1% dead pixels all over the SPD // |
6 | // 3. Print the number of dead pixels temporarily generated // |
7 | // 4. Store the dead pixels in calibration objects for runNrs 1 to 10 // |
8 | // // |
9 | // root [0] .L AliITSStoreDeadSPD.C // |
10 | // root [1] SetSeed(11) // |
11 | // root [2] RandomizeDeadPixelsFrac(0.01) // |
12 | // root [3] PrintNrDead() // |
13 | // root [4] StoreCalib(1,10) // |
14 | // // |
15 | ////////////////////////////////////////////////////////////////////////// |
16 | |
17 | AliITSOnlineCalibrationSPDhandler* handler = NULL; |
18 | TRandom* rnd = new TRandom(); |
19 | |
20 | void StoreCalib(Int_t RunNrStart=0, Int_t RunNrEnd=9999999) { |
21 | if (handler!=NULL) { |
22 | handler->WriteToDB(RunNrStart,RunNrEnd); |
23 | } |
24 | } |
25 | |
26 | void ReadCalib(UInt_t runNr) { |
27 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
28 | else ClearDead(); |
29 | handler->ReadFromDB(runNr); |
30 | } |
31 | |
32 | void SetSeed(UInt_t seed) { |
33 | rnd->SetSeed(seed); |
34 | } |
35 | |
36 | void PrintNrDead() { |
37 | if (handler!=NULL) { |
38 | printf("Nr of dead pixels: %d\n",handler->GetNrDead()); |
39 | } |
40 | } |
41 | |
42 | void PrintDead() { |
43 | if (handler!=NULL) { |
44 | handler->PrintDead(); |
45 | } |
46 | } |
47 | |
48 | void ClearDead() { |
49 | if (handler!=NULL) { |
50 | handler->ResetDead(); |
51 | } |
52 | } |
53 | |
54 | void RandomizeDeadPixelsFrac(Double_t fraction) { |
55 | if (fraction>0 && fraction<=1) { |
56 | UInt_t nrdeadpixels = static_cast<UInt_t>(fraction*256*160*240 + 0.5); |
57 | RandomizeDeadPixels(nrdeadpixels); |
58 | } |
59 | } |
60 | void RandomizeDeadPixels(UInt_t nrDead) { |
61 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
62 | UInt_t nrDeadInserted = 0; |
63 | while (nrDeadInserted<nrDead) { |
64 | UInt_t mod = (UInt_t)(rnd->Rndm()*240); |
65 | UInt_t col = (UInt_t)(rnd->Rndm()*160); |
66 | UInt_t row = (UInt_t)(rnd->Rndm()*256); |
67 | if (handler->SetDeadPixelM(mod,col,row)) nrDeadInserted++; |
68 | } |
69 | } |
70 | |
71 | void RandomizeDeadPixelsFrac(Double_t fraction, UInt_t layer) { |
72 | if (fraction>0 && fraction<=1) { |
73 | UInt_t nr_pixels; |
74 | UInt_t nrdeadpixels; |
75 | switch(layer) { |
76 | case 0: |
77 | nr_pixels = 256*160*80; |
78 | nrdeadpixels = static_cast<UInt_t>(fraction*nr_pixels + 0.5); |
79 | RandomizeDeadPixels(nrdeadpixels,layer); |
80 | break; |
81 | case 1: |
82 | nr_pixels = 256*160*160; |
83 | nrdeadpixels = static_cast<Int_t>(fraction*nr_pixels + 0.5); |
84 | RandomizeDeadPixels(nrdeadpixels,layer); |
85 | break; |
86 | default: |
87 | return; |
88 | } |
89 | } |
90 | } |
91 | void RandomizeDeadPixels(UInt_t nrDead, UInt_t layer) { |
92 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
93 | UInt_t nr_modules; |
94 | UInt_t mod_offset; |
95 | switch(layer) { |
96 | case 0: |
97 | nr_modules=80; |
98 | mod_offset=0; |
99 | break; |
100 | case 1: |
101 | nr_modules=160; |
102 | mod_offset=80; |
103 | break; |
104 | default: |
105 | return; |
106 | } |
107 | UInt_t nrDeadInserted = 0; |
108 | while (nrDeadInserted<nrDead) { |
109 | UInt_t mod = (UInt_t)(rnd->Rndm()*nr_modules) + mod_offset; |
110 | UInt_t col = (UInt_t)(rnd->Rndm()*160); |
111 | UInt_t row = (UInt_t)(rnd->Rndm()*256); |
112 | if (handler->SetDeadPixelM(mod,col,row)) nrDeadInserted++; |
113 | } |
114 | } |
115 | |
116 | void RandomizeDeadChipsFrac(Double_t fraction) { |
117 | if (fraction>0 && fraction<=1) { |
118 | UInt_t nrdeadchips = static_cast<UInt_t>(fraction*240*5 + 0.5); |
119 | RandomizeDeadChips(nrdeadchips); |
120 | } |
121 | } |
122 | void RandomizeDeadChips(UInt_t nrDeadChips) { |
123 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
124 | UInt_t nrDeadChipsInserted = 0; |
125 | AliITSIntMap* chipMap = new AliITSIntMap(); |
126 | while (nrDeadChipsInserted<nrDeadChips) { |
127 | UInt_t eq = (UInt_t)(rnd->Rndm()*20); |
128 | UInt_t hs = (UInt_t)(rnd->Rndm()*6); |
129 | UInt_t chip = (UInt_t)(rnd->Rndm()*10); |
130 | if (!chipMap->Find(20*6*chip + 20*hs + eq)) { |
131 | for (UInt_t col=0; col<32; col++) { |
132 | for (UInt_t row=0; row<256; row++) { |
133 | handler->SetDeadPixel(eq,hs,chip,col,row); |
134 | } |
135 | } |
136 | chipMap->Insert(20*6*chip + 20*hs + eq, chip); |
137 | nrDeadChipsInserted++; |
138 | } |
139 | } |
140 | delete chipMap; |
141 | } |
142 | |
143 | void RandomizeDeadChipsFrac(Double_t fraction, UInt_t layer) { |
144 | if (fraction>0 && fraction<=1) { |
145 | UInt_t nr_chips; |
146 | UInt_t nrdeadchips; |
147 | switch(layer) { |
148 | case 0: |
149 | nr_chips = 400; |
150 | nrdeadchips = static_cast<UInt_t>(fraction*nr_chips + 0.5); |
151 | RandomizeDeadChips(nrdeadchips,layer); |
152 | break; |
153 | case 1: |
154 | nr_chips = 800; |
155 | nrdeadchips = static_cast<UInt_t>(fraction*nr_chips + 0.5); |
156 | RandomizeDeadChips(nrdeadchips,layer); |
157 | break; |
158 | default: |
159 | return; |
160 | } |
161 | } |
162 | } |
163 | void RandomizeDeadChips(UInt_t nrDeadChips, UInt_t layer) { |
164 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
165 | UInt_t hs_nr; |
166 | UInt_t hs_offset; |
167 | switch(layer) { |
168 | case 0: |
169 | hs_nr=2; |
170 | hs_offset=0; |
171 | break; |
172 | case 1: |
173 | hs_nr=4; |
174 | hs_offset=2; |
175 | break; |
176 | default: |
177 | return; |
178 | } |
179 | UInt_t nrDeadChipsInserted = 0; |
180 | AliITSIntMap* chipMap = new AliITSIntMap(); |
181 | while (nrDeadChipsInserted<nrDeadChips) { |
182 | UInt_t eq = (UInt_t)(rnd->Rndm()*20); |
183 | UInt_t hs = (UInt_t)(rnd->Rndm()*hs_nr+hs_offset); |
184 | UInt_t chip = (UInt_t)(rnd->Rndm()*10); |
185 | if (!chipMap->Find(20*6*chip + 20*hs + eq)) { |
186 | for (UInt_t col=0; col<32; col++) { |
187 | for (UInt_t row=0; row<256; row++) { |
188 | handler->SetDeadPixel(eq,hs,chip,col,row); |
189 | } |
190 | } |
191 | chipMap->Insert(20*6*chip + 20*hs + eq, chip); |
192 | nrDeadChipsInserted++; |
193 | } |
194 | } |
195 | delete chipMap; |
196 | } |
197 | |
198 | void RandomizeDeadHalfStavesFrac(Double_t fraction) { |
199 | if (fraction>0 && fraction<=1) { |
200 | UInt_t nrdeadhstaves = static_cast<UInt_t>(fraction*120 + 0.5); |
201 | RandomizeDeadHalfStaves(nrdeadhstaves); |
202 | } |
203 | } |
204 | void RandomizeDeadHalfStaves(UInt_t nrDeadHS) { |
205 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
206 | UInt_t nrDeadHSInserted = 0; |
207 | AliITSIntMap* hsMap = new AliITSIntMap(); |
208 | while (nrDeadHSInserted<nrDeadHS) { |
209 | UInt_t eq = (UInt_t)(rnd->Rndm()*20); |
210 | UInt_t hs = (UInt_t)(rnd->Rndm()*6); |
211 | if (!hsMap->Find(20*hs + eq)) { |
212 | for (UInt_t chip=0; chip<10; chip++) { |
213 | for (UInt_t col=0; col<32; col++) { |
214 | for (UInt_t row=0; row<256; row++) { |
215 | handler->SetDeadPixel(eq,hs,chip,col,row); |
216 | } |
217 | } |
218 | } |
219 | hsMap->Insert(20*hs + eq, hs); |
220 | nrDeadHSInserted++; |
221 | } |
222 | } |
223 | delete hsMap; |
224 | } |
225 | |
226 | void RandomizeDeadHalfStavesFrac(Double_t fraction, UInt_t layer) { |
227 | if (fraction>0 && fraction<=1) { |
228 | UInt_t nr_hstaves; |
229 | switch(layer) { |
230 | case 0: |
231 | nr_hstaves=static_cast<UInt_t>(fraction*40 + 0.5); |
232 | RandomizeDeadHalfStaves(nr_hstaves,layer); |
233 | break; |
234 | case 1: |
235 | nr_hstaves=static_cast<UInt_t>(fraction*80 + 0.5); |
236 | RandomizeDeadHalfStaves(nr_hstaves,layer); |
237 | break; |
238 | default: |
239 | return; |
240 | } |
241 | } |
242 | } |
243 | void RandomizeDeadHalfStaves(UInt_t nrDeadHS, UInt_t layer) { |
244 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
245 | UInt_t hs_nr; |
246 | UInt_t hs_offset; |
247 | switch(layer) { |
248 | case 0: |
249 | hs_nr=2; |
250 | hs_offset=0; |
251 | break; |
252 | case 1: |
253 | hs_nr=4; |
254 | hs_offset=2; |
255 | break; |
256 | default: |
257 | return; |
258 | } |
259 | UInt_t nrDeadHSInserted = 0; |
260 | AliITSIntMap* hsMap = new AliITSIntMap(); |
261 | while (nrDeadHSInserted<nrDeadHS) { |
262 | UInt_t eq = (UInt_t)(rnd->Rndm()*20); |
263 | UInt_t hs = (UInt_t)(rnd->Rndm()*hs_nr+hs_offset); |
264 | if (!hsMap->Find(20*hs + eq)) { |
265 | for (UInt_t chip=0; chip<10; chip++) { |
266 | for (UInt_t col=0; col<32; col++) { |
267 | for (UInt_t row=0; row<256; row++) { |
268 | handler->SetDeadPixel(eq,hs,chip,col,row); |
269 | } |
270 | } |
271 | } |
272 | hsMap->Insert(20*hs + eq, hs); |
273 | nrDeadHSInserted++; |
274 | } |
275 | } |
276 | delete hsMap; |
277 | } |
278 | |
279 | void RandomizeDeadColumnChipsFrac(Double_t chipfraction, Double_t columnfraction) { |
280 | if (chipfraction>0 && chipfraction<=1 && columnfraction>0 && columnfraction<=1) { |
281 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
282 | UInt_t nrColChips = static_cast<UInt_t>(chipfraction*240*5 + 0.5); |
283 | UInt_t nrColChipsUsed = 0; |
284 | AliITSIntMap* colChipMap = new AliITSIntMap(); |
285 | while (nrColChipsUsed<nrColChips) { |
286 | UInt_t eq = (UInt_t)(rnd->Rndm()*20); |
287 | UInt_t hs = (UInt_t)(rnd->Rndm()*6); |
288 | UInt_t chip = (UInt_t)(rnd->Rndm()*10); |
289 | if (!colChipMap->Find(20*6*chip + 20*hs + eq)) { |
290 | UInt_t nrCols = static_cast<UInt_t>(columnfraction*32 + 0.5); |
291 | UInt_t nrColsInserted = 0; |
292 | AliITSIntMap* colMap = new AliITSIntMap(); |
293 | while (nrColsInserted<nrCols) { |
294 | UInt_t col = (UInt_t)(rnd->Rndm()*32); |
295 | if (!colMap->Find(col)) { |
296 | for (UInt_t row=0; row<256; row++) { |
297 | handler->SetDeadPixel(eq,hs,chip,col,row); |
298 | } |
299 | colMap->Insert(col,col); |
300 | nrColsInserted++; |
301 | } |
302 | } |
303 | delete colMap; |
304 | colChipMap->Insert(20*6*chip + 20*hs + eq, chip); |
305 | nrColChipsUsed++; |
306 | } |
307 | } |
308 | delete colChipMap; |
309 | } |
310 | } |
311 | void RandomizeDeadColumnChipsFrac(Double_t chipfraction, Double_t columnfraction, Int_t layer) { |
312 | if (chipfraction>0 && chipfraction<=1 && columnfraction>0 && columnfraction<=1) { |
313 | if (handler==NULL) handler = new AliITSOnlineCalibrationSPDhandler(); |
314 | UInt_t hs_nr; |
315 | UInt_t hs_offset; |
316 | switch(layer) { |
317 | case 0: |
318 | hs_nr=2; |
319 | hs_offset=0; |
320 | break; |
321 | case 1: |
322 | hs_nr=4; |
323 | hs_offset=2; |
324 | break; |
325 | default: |
326 | return; |
327 | } |
328 | UInt_t nrColChips = static_cast<UInt_t>(chipfraction*240*5 + 0.5); |
329 | UInt_t nrColChipsUsed = 0; |
330 | AliITSIntMap* colChipMap = new AliITSIntMap(); |
331 | while (nrColChipsUsed<nrColChips) { |
332 | UInt_t eq = (UInt_t)(rnd->Rndm()*20); |
333 | UInt_t hs = (UInt_t)(rnd->Rndm()*hs_nr+hs_offset); |
334 | UInt_t chip = (UInt_t)(rnd->Rndm()*10); |
335 | if (!colChipMap->Find(20*6*chip + 20*hs + eq)) { |
336 | UInt_t nrCols = static_cast<UInt_t>(columnfraction*32 + 0.5); |
337 | UInt_t nrColsInserted = 0; |
338 | AliITSIntMap* colMap = new AliITSIntMap(); |
339 | while (nrColsInserted<nrCols) { |
340 | UInt_t col = (UInt_t)(rnd->Rndm()*32); |
341 | if (!colMap->Find(col)) { |
342 | for (UInt_t row=0; row<256; row++) { |
343 | handler->SetDeadPixel(eq,hs,chip,col,row); |
344 | } |
345 | colMap->Insert(col,col); |
346 | nrColsInserted++; |
347 | } |
348 | } |
349 | delete colMap; |
350 | colChipMap->Insert(20*6*chip + 20*hs + eq, chip); |
351 | nrColChipsUsed++; |
352 | } |
353 | } |
354 | delete colChipMap; |
355 | } |
356 | } |
357 | |