b3c7c475 |
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 | |
16 | /* $Id$ */ |
17 | |
18 | /// By Laurent Aphecetche |
19 | |
20 | #if !defined(__CINT__) || defined(__MAKECINT__) |
d29760d6 |
21 | |
b3c7c475 |
22 | #include "MUONCDB.h" |
d29760d6 |
23 | |
b3c7c475 |
24 | #include "AliCDBEntry.h" |
25 | #include "AliCDBManager.h" |
d29760d6 |
26 | #include "AliMUON1DArray.h" |
8f7d7575 |
27 | #include "AliMUON2DMap.h" |
8f7d7575 |
28 | #include "AliMUONCalibParam1I.h" |
29 | #include "AliMUONCalibParam2F.h" |
d29760d6 |
30 | #include "AliMUONConstants.h" |
5322694c |
31 | #include "AliMUONObjectPair.h" |
32 | #include "AliMUONTriggerEfficiencyCells.h" |
d29760d6 |
33 | #include "AliMUONTriggerLut.h" |
34 | #include "AliMUONV2DStore.h" |
35 | #include "AliMUONVCalibParam.h" |
5322694c |
36 | #include "AliMUONVDataIterator.h" |
b3c7c475 |
37 | #include "AliMpDEIterator.h" |
38 | #include "AliMpDEManager.h" |
5322694c |
39 | #include "AliMpManuList.h" |
3e8e7033 |
40 | #include "AliMpSegmentation.h" |
b3c7c475 |
41 | #include "AliMpVSegmentation.h" |
3e8e7033 |
42 | #include "AliMpStationType.h" |
b3c7c475 |
43 | #include "Riostream.h" |
44 | #include "TH1F.h" |
45 | #include "TList.h" |
46 | #include "TRandom.h" |
47 | #include "TStopwatch.h" |
48 | #include "TSystem.h" |
49 | #endif |
50 | |
d29760d6 |
51 | //_____________________________________________________________________________ |
3e8e7033 |
52 | Int_t countChannels(const AliMpVSegmentation& seg) |
d29760d6 |
53 | { |
54 | Int_t n(0); |
55 | |
56 | for ( Int_t ix = 0; ix < seg.MaxPadIndexX(); ++ix ) |
57 | { |
58 | for ( Int_t iy = 0; iy < seg.MaxPadIndexY(); ++iy ) |
59 | { |
60 | if ( seg.HasPad(AliMpIntPair(ix,iy)) ) ++n; |
61 | } |
62 | } |
63 | return n; |
64 | } |
b3c7c475 |
65 | |
b3c7c475 |
66 | //_____________________________________________________________________________ |
d29760d6 |
67 | void countChannels() |
68 | { |
69 | AliMpDEIterator it; |
70 | Int_t ntotal(0); |
71 | Int_t ntracker(0); |
72 | Int_t ntrigger(0); |
73 | |
74 | for ( Int_t station = 0; station < AliMUONConstants::NCh(); ++station ) |
75 | { |
76 | Int_t n(0); |
77 | it.First(station); |
78 | while (!it.IsDone()) |
79 | { |
80 | Int_t de = it.CurrentDE(); |
81 | for ( Int_t cathode = 0; cathode < 2; ++cathode ) |
82 | { |
3e8e7033 |
83 | const AliMpVSegmentation* seg |
84 | = AliMpSegmentation::Instance()->GetMpSegmentation(de,cathode); |
d29760d6 |
85 | n += countChannels(*seg); |
86 | } |
87 | it.Next(); |
88 | } |
89 | cout << "Station " << station << " has " << n << " channels" << endl; |
90 | if ( station < AliMUONConstants::NTrackingCh() ) |
91 | { |
92 | ntracker += n; |
93 | } |
94 | else |
95 | { |
96 | ntrigger += n; |
97 | } |
98 | ntotal += n; |
99 | } |
100 | cout << "Tracker channels = " << ntracker << endl; |
101 | cout << "Trigger channels = " << ntrigger << endl; |
102 | cout << "Total channels =" << ntotal << endl; |
103 | } |
104 | |
105 | //_____________________________________________________________________________ |
5322694c |
106 | AliMUONV2DStore* read2D(const char* calibType, Int_t runNumber) |
b3c7c475 |
107 | { |
108 | AliCDBManager* man = AliCDBManager::Instance(); |
109 | man->SetDefaultStorage(CDBPath); |
110 | |
5322694c |
111 | AliCDBEntry* entry = man->Get(calibType,runNumber); |
b3c7c475 |
112 | |
113 | if (entry) |
114 | { |
8f7d7575 |
115 | return (AliMUONV2DStore*)entry->GetObject(); |
b3c7c475 |
116 | } |
117 | return 0; |
118 | } |
119 | |
d29760d6 |
120 | //_____________________________________________________________________________ |
5322694c |
121 | AliMUONV1DStore* read1D(const char* calibType, Int_t runNumber) |
d29760d6 |
122 | { |
123 | AliCDBManager* man = AliCDBManager::Instance(); |
124 | man->SetDefaultStorage(CDBPath); |
125 | |
5322694c |
126 | AliCDBEntry* entry = man->Get(calibType,runNumber); |
d29760d6 |
127 | |
128 | if (entry) |
129 | { |
130 | return (AliMUONV1DStore*)entry->GetObject(); |
131 | } |
132 | return 0; |
133 | } |
134 | |
b3c7c475 |
135 | //_____________________________________________________________________________ |
8f7d7575 |
136 | void checkCDB(const char* calibType) |
137 | { |
138 | TString c(calibType); |
139 | Float_t refValue(0); |
140 | |
141 | if ( c == "MUON/Calib/DeadChannels" ) |
142 | { |
143 | refValue=5; |
144 | } |
145 | |
d29760d6 |
146 | AliMUONV2DStore* store = read2D(calibType); |
8f7d7575 |
147 | if (!store) return; |
148 | |
5322694c |
149 | TList* list = AliMpManuList::ManuList(); |
150 | TIter next(list); |
8f7d7575 |
151 | AliMpIntPair* p; |
152 | |
153 | while ( ( p = (AliMpIntPair*)next() ) ) |
154 | { |
155 | Int_t detElemId = p->GetFirst(); |
156 | Int_t manuId = p->GetSecond(); |
157 | |
158 | AliMUONVCalibParam* value = |
159 | dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId)); |
160 | |
161 | if (value) |
162 | { |
163 | for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel ) |
164 | { |
165 | Float_t testValue = value->ValueAsFloat(manuChannel,0); |
166 | if ( testValue && testValue != refValue ) |
167 | { |
168 | cout << "Got a strange value for DE=" << detElemId << " manuId=" |
169 | << manuId << " manuChannel=" << manuChannel << " was expecting " |
170 | << refValue << " and I got " << testValue << endl; |
171 | } |
172 | } |
173 | } |
174 | else |
175 | { |
176 | cout << "Got a null value for DE=" << detElemId << " manuId=" |
177 | << manuId << endl; |
178 | } |
179 | } |
180 | |
5322694c |
181 | delete list; |
8f7d7575 |
182 | delete store; |
183 | } |
184 | |
5322694c |
185 | //_____________________________________________________________________________ |
186 | //void testDump(AliMUONV2DStore& store, int n) |
187 | //{ |
188 | // AliMUONObjectPair* p; |
189 | // |
190 | // Int_t c(0); |
191 | // |
192 | // for ( Int_t i = 0; i < n; ++i ) |
193 | // { |
194 | // AliMUONVDataIterator* it = store.Iterator(); |
195 | // |
196 | // while ( ( p = dynamic_cast<AliMUONObjectPair*>(it->Next() ) ) ) |
197 | // { |
198 | // AliMpIntPair* dm = dynamic_cast<AliMpIntPair*>(p->Key()); |
199 | // if (dm) |
200 | // { |
201 | // Int_t a(dm->GetFirst()+dm->GetSecond()); |
202 | // a=2; |
203 | // ++c; |
204 | // AliMUONVCalibParam* param = dynamic_cast<AliMUONVCalibParam*>(p->Value()); |
205 | // } |
206 | // delete p; |
207 | // } |
208 | // delete it; |
209 | // } |
210 | // |
211 | // cout << c << endl; |
212 | //} |
8f7d7575 |
213 | |
214 | //_____________________________________________________________________________ |
5322694c |
215 | AliMUONV2DStore* diff(AliMUONV2DStore& store1, AliMUONV2DStore& store2, |
216 | const char* /* opt */) |
b3c7c475 |
217 | { |
5322694c |
218 | // creates a store which contains store1-store2 |
219 | // if opt="abs" the difference is absolute one, |
220 | // if opt="rel" then what is stored is (store1-store2)/store1 |
b3c7c475 |
221 | |
5322694c |
222 | AliMUONV2DStore* d = static_cast<AliMUONV2DStore*>(store1.Clone()); |
223 | |
224 | AliMUONVDataIterator* it = d->Iterator(); |
225 | |
226 | AliMUONObjectPair* p; |
b3c7c475 |
227 | |
5322694c |
228 | while ( ( p = dynamic_cast<AliMUONObjectPair*>(it->Next() ) ) ) |
b3c7c475 |
229 | { |
5322694c |
230 | AliMpIntPair* dm = dynamic_cast<AliMpIntPair*>(p->Key()); |
231 | //FIXME: this might happen (if a full manu is missing, for instance) |
232 | //handle it. |
233 | assert(dm!=0); |
234 | AliMUONVCalibParam* param = dynamic_cast<AliMUONVCalibParam*>(p->Value()); |
235 | //FIXMENOT: this should *not* happen |
236 | assert(param!=0); |
237 | |
238 | AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.Get(dm->GetFirst(),dm->GetSecond())); |
239 | //FIXME: this might happen. Handle it. |
240 | assert(param2!=0); |
241 | |
242 | for ( Int_t i = 0; i < param->Size(); ++i ) |
243 | { |
244 | for ( Int_t j = 0; j < param->Dimension(); ++j ) |
245 | { |
246 | param->SetValueAsFloat(i,j,param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j)); |
247 | } |
248 | } |
b3c7c475 |
249 | } |
5322694c |
250 | return d; |
251 | } |
252 | |
253 | //_____________________________________________________________________________ |
254 | void getBoundaries(const AliMUONV2DStore& store, |
255 | Float_t& x0min, Float_t& x0max, |
256 | Float_t& x1min, Float_t& x1max) |
257 | { |
258 | x0min=1E30; |
259 | x0max=-1E30; |
260 | x1min=1E30; |
261 | x1max=-1E30; |
262 | |
263 | TList* list = AliMpManuList::ManuList(); |
264 | TIter next(list); |
265 | AliMpIntPair* p; |
266 | |
267 | while ( ( p = (AliMpIntPair*)next() ) ) |
b3c7c475 |
268 | { |
5322694c |
269 | Int_t detElemId = p->GetFirst(); |
270 | Int_t manuId = p->GetSecond(); |
271 | |
3e8e7033 |
272 | const AliMpVSegmentation* seg = |
273 | AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId); |
5322694c |
274 | |
275 | AliMUONVCalibParam* value = |
276 | dynamic_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId)); |
277 | |
278 | if (!value) continue; |
279 | |
280 | for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel ) |
281 | { |
282 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE); |
283 | if (!pad.IsValid()) continue; |
284 | |
285 | Float_t x0 = value->ValueAsFloat(manuChannel,0); |
286 | |
287 | x0min = TMath::Min(x0min,x0); |
288 | x0max = TMath::Max(x0max,x0); |
289 | if ( value->Dimension()>1 ) |
290 | { |
291 | Float_t x1 = value->ValueAsFloat(manuChannel,1); |
292 | x1min = TMath::Min(x1min,x1); |
293 | x1max = TMath::Max(x1max,x1); |
294 | } |
295 | } |
296 | } |
297 | delete list; |
298 | } |
299 | |
300 | //_____________________________________________________________________________ |
301 | void plot(const AliMUONV2DStore& store, const char* name, Int_t nbins) |
302 | { |
303 | Float_t x0min, x0max, x1min, x1max; |
304 | |
305 | getBoundaries(store,x0min,x0max,x1min,x1max); |
306 | |
307 | if ( x0min > x0max ) |
308 | { |
309 | cerr << Form("Something is wrong with boundaries : x0(min,max)=%e,%e", |
310 | x0min,x0max) << endl; |
311 | return; |
8f7d7575 |
312 | } |
5322694c |
313 | |
314 | if ( TMath::Abs(x0min-x0max) < 1E-3 ) |
8f7d7575 |
315 | { |
5322694c |
316 | x0min -= 1; |
317 | x0max += 1; |
b3c7c475 |
318 | } |
5322694c |
319 | |
320 | TH1* h0 = new TH1F(Form("%s_0",name),Form("%s_0",name), |
321 | nbins,x0min,x0max); |
322 | |
323 | TH1* h1(0); |
324 | |
325 | if ( x1max > x1min ) |
b3c7c475 |
326 | { |
5322694c |
327 | h1 = new TH1F(Form("%s_1",name),Form("%s_1",name), |
328 | nbins,x1min,x1max); |
b3c7c475 |
329 | } |
330 | |
5322694c |
331 | TList* list = AliMpManuList::ManuList(); |
332 | TIter next(list); |
8f7d7575 |
333 | AliMpIntPair* p; |
334 | Int_t n(0); |
8f7d7575 |
335 | Int_t nPerStation[7]; |
336 | |
337 | for ( Int_t i = 0; i < 7; ++i ) nPerStation[i]=0; |
b3c7c475 |
338 | |
8f7d7575 |
339 | while ( ( p = (AliMpIntPair*)next() ) ) |
b3c7c475 |
340 | { |
8f7d7575 |
341 | Int_t detElemId = p->GetFirst(); |
342 | Int_t manuId = p->GetSecond(); |
aaf6e802 |
343 | Int_t station = AliMpDEManager::GetChamberId(detElemId); |
8f7d7575 |
344 | |
3e8e7033 |
345 | const AliMpVSegmentation* seg = |
346 | AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId); |
5322694c |
347 | |
8f7d7575 |
348 | AliMUONVCalibParam* value = |
5322694c |
349 | dynamic_cast<AliMUONVCalibParam*>(store.Get(detElemId,manuId)); |
b3c7c475 |
350 | |
b3c7c475 |
351 | if (value) |
352 | { |
8f7d7575 |
353 | for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel ) |
354 | { |
5322694c |
355 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE); |
356 | if (!pad.IsValid()) continue; |
357 | |
8f7d7575 |
358 | ++n; |
359 | ++nPerStation[station]; |
5322694c |
360 | Float_t x = value->ValueAsFloat(manuChannel,0); |
361 | h0->Fill(x); |
362 | if (h1) |
8f7d7575 |
363 | { |
5322694c |
364 | h1->Fill(value->ValueAsFloat(manuChannel,1)); |
8f7d7575 |
365 | } |
366 | } |
b3c7c475 |
367 | } |
368 | else |
369 | { |
370 | cout << "Got a null value for DE=" << detElemId << " manuId=" |
5322694c |
371 | << manuId << endl; |
b3c7c475 |
372 | } |
373 | } |
374 | |
8f7d7575 |
375 | cout << "Number of channels = " << n << endl; |
376 | for ( Int_t i = 0; i < 7; ++i ) |
377 | { |
378 | cout << "Station " << (i+1) << " " << nPerStation[i] << endl; |
379 | } |
380 | |
5322694c |
381 | delete list; |
382 | } |
383 | |
384 | //_____________________________________________________________________________ |
385 | void plotCDB(const char* calibType, Int_t runNumber) |
386 | { |
387 | AliMUONV2DStore* store = read2D(calibType,runNumber); |
388 | if (!store) return; |
389 | |
390 | TString c(calibType); |
391 | c.ReplaceAll("/","_"); |
392 | |
393 | plot(*store,c.Data()); |
394 | |
b3c7c475 |
395 | delete store; |
396 | } |
397 | |
398 | //_____________________________________________________________________________ |
8f7d7575 |
399 | void testReadStore(const AliMUONV2DStore& store, Int_t n) |
b3c7c475 |
400 | { |
5322694c |
401 | TList* list = AliMpManuList::ManuList(); |
402 | TIter next(list); |
8f7d7575 |
403 | AliMpIntPair* p; |
b3c7c475 |
404 | |
8f7d7575 |
405 | while ( ( p = (AliMpIntPair*)next() ) ) |
b3c7c475 |
406 | { |
407 | for ( Int_t i = 0; i < n; ++i ) |
408 | { |
8f7d7575 |
409 | store.Get(p->GetFirst(),p->GetSecond()); |
b3c7c475 |
410 | } |
411 | } |
5322694c |
412 | delete list; |
b3c7c475 |
413 | } |
414 | |
415 | //_____________________________________________________________________________ |
5322694c |
416 | Int_t makePedestalStore(AliMUONV2DStore& pedestalStore, Bool_t defaultValues) |
417 | { |
418 | TList* list = AliMpManuList::ManuList(); |
419 | TIter next(list); |
b3c7c475 |
420 | |
8f7d7575 |
421 | AliMpIntPair* p; |
b3c7c475 |
422 | |
5322694c |
423 | Int_t nchannels(0); |
424 | Int_t nmanus(0); |
b3c7c475 |
425 | |
426 | Bool_t replace = kFALSE; |
427 | |
8f7d7575 |
428 | const Int_t nChannels(64); |
5322694c |
429 | const Float_t kPedestalMeanMean(150); |
430 | const Float_t kPedestalMeanSigma(10); |
431 | const Float_t kPedestalSigmaMean(1.0); |
432 | const Float_t kPedestalSigmaSigma(0.2); |
8f7d7575 |
433 | |
434 | while ( ( p = (AliMpIntPair*)next() ) ) |
b3c7c475 |
435 | { |
5322694c |
436 | ++nmanus; |
437 | AliMUONVCalibParam* ped = new AliMUONCalibParam2F(nChannels,AliMUONVCalibParam::InvalidFloatValue()); |
438 | |
439 | Int_t detElemId = p->GetFirst(); |
b70d763d |
440 | |
5322694c |
441 | Int_t manuId = p->GetSecond(); |
442 | |
3e8e7033 |
443 | const AliMpVSegmentation* seg = |
444 | AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId); |
5322694c |
445 | |
8f7d7575 |
446 | for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel ) |
b3c7c475 |
447 | { |
5322694c |
448 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE); |
449 | if (!pad.IsValid()) continue; |
450 | |
451 | ++nchannels; |
452 | |
8f7d7575 |
453 | Float_t meanPedestal; |
454 | Float_t sigmaPedestal; |
5322694c |
455 | |
8f7d7575 |
456 | if ( defaultValues ) |
b3c7c475 |
457 | { |
8f7d7575 |
458 | meanPedestal = 0.0; |
459 | sigmaPedestal = 1.0; |
b3c7c475 |
460 | } |
8f7d7575 |
461 | else |
b3c7c475 |
462 | { |
8f7d7575 |
463 | meanPedestal = -1; |
464 | while ( meanPedestal < 0 ) |
465 | { |
5322694c |
466 | meanPedestal = gRandom->Gaus(kPedestalMeanMean,kPedestalMeanSigma); |
8f7d7575 |
467 | } |
468 | sigmaPedestal = -1; |
469 | while ( sigmaPedestal < 0 ) |
470 | { |
5322694c |
471 | sigmaPedestal = gRandom->Gaus(kPedestalSigmaMean,kPedestalSigmaSigma); |
8f7d7575 |
472 | } |
b3c7c475 |
473 | } |
8f7d7575 |
474 | ped->SetValueAsFloat(manuChannel,0,meanPedestal); |
475 | ped->SetValueAsFloat(manuChannel,1,sigmaPedestal); |
8f7d7575 |
476 | |
5322694c |
477 | } |
478 | Bool_t ok = pedestalStore.Set(detElemId,manuId,ped,replace); |
479 | if (!ok) |
480 | { |
481 | cout << "Could not set DetElemId=" << detElemId << " manuId=" |
482 | << manuId << endl; |
483 | } |
484 | } |
485 | |
486 | delete list; |
487 | cout << nmanus << " Manus and " << nchannels << " channels." << endl; |
488 | return nchannels; |
489 | |
490 | } |
491 | |
492 | //_____________________________________________________________________________ |
493 | Int_t makeGainStore(AliMUONV2DStore& gainStore, Bool_t defaultValues) |
494 | { |
495 | TList* list = AliMpManuList::ManuList(); |
496 | TIter next(list); |
497 | |
498 | AliMpIntPair* p; |
499 | |
500 | Int_t nchannels(0); |
501 | Int_t nmanus(0); |
502 | |
503 | Bool_t replace = kFALSE; |
504 | |
505 | const Int_t nChannels(64); |
506 | const Double_t kSaturation(3000); |
507 | const Double_t kGainMean(1.0); |
508 | const Double_t kGainSigma(0.05); |
509 | |
510 | while ( ( p = (AliMpIntPair*)next() ) ) |
511 | { |
512 | ++nmanus; |
513 | AliMUONVCalibParam* gain = new AliMUONCalibParam2F(nChannels,AliMUONVCalibParam::InvalidFloatValue()); |
514 | |
515 | Int_t detElemId = p->GetFirst(); |
516 | Int_t manuId = p->GetSecond(); |
517 | |
3e8e7033 |
518 | const AliMpVSegmentation* seg = |
519 | AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId); |
5322694c |
520 | |
521 | for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel ) |
522 | { |
523 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE); |
524 | if (!pad.IsValid()) continue; |
525 | |
526 | ++nchannels; |
527 | |
528 | Float_t meanGain; |
529 | Float_t saturation(kSaturation); |
530 | |
531 | if ( defaultValues ) |
b3c7c475 |
532 | { |
5322694c |
533 | meanGain = 1.0; |
534 | } |
535 | else |
536 | { |
537 | meanGain = -1; |
538 | while ( meanGain < 0 ) |
8f7d7575 |
539 | { |
5322694c |
540 | meanGain = gRandom->Gaus(kGainMean,kGainSigma); |
8f7d7575 |
541 | } |
b3c7c475 |
542 | } |
5322694c |
543 | gain->SetValueAsFloat(manuChannel,0,meanGain); |
544 | gain->SetValueAsFloat(manuChannel,1,saturation); |
545 | |
b3c7c475 |
546 | } |
5322694c |
547 | Bool_t ok = gainStore.Set(detElemId,manuId,gain,replace); |
548 | if (!ok) |
b3c7c475 |
549 | { |
550 | cout << "Could not set DetElemId=" << detElemId << " manuId=" |
8f7d7575 |
551 | << manuId << endl; |
b3c7c475 |
552 | } |
b3c7c475 |
553 | } |
554 | |
5322694c |
555 | delete list; |
556 | cout << nmanus << " Manus and " << nchannels << " channels." << endl; |
557 | return nchannels; |
b3c7c475 |
558 | } |
559 | |
560 | //_____________________________________________________________________________ |
5322694c |
561 | Int_t makeDeadStore(AliMUONV2DStore& deadStore, Bool_t defaultValues) |
562 | { |
563 | TList* list = AliMpManuList::ManuList(); |
564 | TIter next(list); |
b3c7c475 |
565 | |
5322694c |
566 | AliMpIntPair* p; |
b3c7c475 |
567 | |
5322694c |
568 | Int_t nchannels(0); |
569 | Int_t nmanus(0); |
b3c7c475 |
570 | |
5322694c |
571 | Bool_t replace = kFALSE; |
b3c7c475 |
572 | |
5322694c |
573 | const Int_t nChannels(64); |
574 | const Double_t deadProba = 1.0; // 1% |
b3c7c475 |
575 | |
5322694c |
576 | while ( ( p = (AliMpIntPair*)next() ) ) |
b3c7c475 |
577 | { |
5322694c |
578 | ++nmanus; |
579 | AliMUONVCalibParam* dead = new AliMUONCalibParam1I(nChannels,-9999); |
580 | |
581 | Int_t detElemId = p->GetFirst(); |
582 | Int_t manuId = p->GetSecond(); |
583 | |
3e8e7033 |
584 | const AliMpVSegmentation* seg = |
585 | AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId); |
5322694c |
586 | |
587 | for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel ) |
b3c7c475 |
588 | { |
5322694c |
589 | AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE); |
590 | if (!pad.IsValid()) continue; |
591 | |
592 | ++nchannels; |
593 | |
594 | if (!defaultValues) |
b3c7c475 |
595 | { |
5322694c |
596 | // probability that this channel is dead ~ 1% |
597 | if ( gRandom->Uniform(100.0) < deadProba ) |
8f7d7575 |
598 | { |
5322694c |
599 | Int_t reason = 5; // that value could be used to distinguish |
600 | // why the channel is dead or how it was flagged bad (online, |
601 | // offline, by chance...). 5 is of course a fake number. |
602 | dead->SetValueAsInt(manuChannel,0,reason); |
603 | } |
b3c7c475 |
604 | } |
605 | } |
5322694c |
606 | Bool_t ok = deadStore.Set(detElemId,manuId,dead,replace); |
607 | if (!ok) |
608 | { |
609 | cout << "Could not set DetElemId=" << detElemId << " manuId=" |
610 | << manuId << endl; |
611 | } |
b3c7c475 |
612 | } |
613 | |
5322694c |
614 | delete list; |
615 | cout << nmanus << " Manus and " << nchannels << " channels." << endl; |
616 | return nchannels; |
b3c7c475 |
617 | } |
618 | |
619 | //_____________________________________________________________________________ |
8f7d7575 |
620 | void testMakeStores(Int_t readLoop) |
b3c7c475 |
621 | { |
8f7d7575 |
622 | AliMUONV2DStore* pedestalStore = new AliMUON2DMap; |
623 | AliMUONV2DStore* gainStore = new AliMUON2DMap; |
624 | AliMUONV2DStore* deadStore = new AliMUON2DMap; |
b3c7c475 |
625 | |
626 | TStopwatch timer; |
627 | |
628 | cout << "Creating" << endl; |
629 | |
5322694c |
630 | Bool_t defaultValues = kTRUE; |
631 | |
b3c7c475 |
632 | timer.Start(kTRUE); |
5322694c |
633 | makePedestalStore(*pedestalStore,defaultValues); |
634 | makeGainStore(*gainStore,defaultValues); |
635 | makeDeadStore(*deadStore,defaultValues); |
b3c7c475 |
636 | timer.Print(); |
637 | |
638 | cout << "Reading..." << endl; |
639 | timer.Start(kTRUE); |
640 | testReadStore(*pedestalStore,readLoop); |
641 | testReadStore(*gainStore,readLoop); |
8f7d7575 |
642 | testReadStore(*deadStore,readLoop); |
b3c7c475 |
643 | cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop |
644 | <<" samples." << endl; |
645 | |
646 | delete pedestalStore; |
647 | delete gainStore; |
8f7d7575 |
648 | delete deadStore; |
b3c7c475 |
649 | } |
650 | |
d29760d6 |
651 | //_____________________________________________________________________________ |
652 | void generateTrigger(const char* cdbpath) |
653 | { |
654 | // |
655 | // Generate trigger related conditions : |
656 | // |
657 | // - trigger masks for board (locals, regionals, global) |
658 | // - trigger lut |
659 | // - trigger efficiency |
660 | // - trigger switches (to be implemented FIXME) |
661 | // |
662 | const Int_t nlboards = 234; |
663 | AliMUONV1DStore* localBoardMasks = new AliMUON1DArray(nlboards+1); |
664 | |
665 | // Generate fake mask values for 234 localboards and put that into |
666 | // one single container (localBoardMasks) |
667 | for ( Int_t i = 1; i <= nlboards; ++i ) |
668 | { |
669 | AliMUONVCalibParam* localBoard = new AliMUONCalibParam1I(8); |
670 | for ( Int_t x = 0; x < 2; ++x ) |
671 | { |
672 | for ( Int_t y = 0; y < 4; ++y ) |
673 | { |
674 | Int_t index = x*4+y; |
675 | localBoard->SetValueAsInt(index,0,0xFFFF); |
676 | } |
677 | } |
678 | localBoardMasks->Set(i,localBoard,kFALSE); |
679 | } |
680 | |
681 | // Generate values for regional boards |
682 | const Int_t nrboards = 16; |
683 | AliMUONV1DStore* regionalBoardMasks = new AliMUON1DArray(16); |
684 | |
685 | for ( Int_t i = 0; i < nrboards; ++i ) |
686 | { |
687 | AliMUONVCalibParam* regionalBoard = new AliMUONCalibParam1I(16); |
688 | for ( Int_t j = 0; j < 16; ++j ) |
689 | { |
690 | regionalBoard->SetValueAsInt(j,0,0x3F); |
691 | } |
692 | regionalBoardMasks->Set(i,regionalBoard,kFALSE); |
693 | } |
694 | |
695 | // Generate values for global board |
696 | AliMUONVCalibParam* globalBoardMasks = new AliMUONCalibParam1I(16); |
697 | |
698 | for ( Int_t j = 0; j < 16; ++j ) |
699 | { |
700 | globalBoardMasks->SetValueAsInt(j,0,0xFFF); |
701 | } |
702 | |
703 | AliMUONTriggerLut lut; |
bc6da0f1 |
704 | lut.ReadFromFile("$(ALICE_ROOT)/MUON/data/lutAptLpt1Hpt1p7.root"); |
d29760d6 |
705 | |
706 | AliMUONTriggerEfficiencyCells cells("$ALICE_ROOT/MUON/data/efficiencyCells.dat"); |
707 | |
708 | //-------------------------------------------- |
709 | // Store the resulting containers into the CDB |
710 | Int_t ever = 99999999; |
711 | |
712 | AliCDBId id("MUON/Calib/LocalTriggerBoardMasks",0,ever); |
713 | |
714 | AliCDBMetaData md; |
715 | md.SetBeamPeriod(1); |
716 | md.SetAliRootVersion(gROOT->GetVersion()); |
717 | md.SetComment("Test with default values"); |
718 | md.SetResponsible("Rachid Guernane"); |
719 | |
720 | AliCDBManager* man = AliCDBManager::Instance(); |
721 | man->SetDefaultStorage(cdbpath); |
722 | man->Put(localBoardMasks,id,&md); |
723 | |
724 | id.SetPath("MUON/Calib/RegionalTriggerBoardMasks"); |
725 | |
726 | man->Put(regionalBoardMasks,id,(AliCDBMetaData*)md.Clone()); |
727 | |
728 | id.SetPath("MUON/Calib/GlobalTriggerBoardMasks"); |
729 | |
730 | man->Put(globalBoardMasks,id,(AliCDBMetaData*)md.Clone()); |
731 | |
732 | id.SetPath("MUON/Calib/TriggerLut"); |
733 | |
734 | man->Put(&lut,id,(AliCDBMetaData*)md.Clone()); |
735 | |
736 | id.SetPath("MUON/Calib/TriggerEfficiency"); |
737 | md.SetResponsible("Diego Stocco"); |
738 | |
739 | man->Put(&cells,id,(AliCDBMetaData*)md.Clone()); |
740 | |
741 | delete localBoardMasks; |
742 | delete regionalBoardMasks; |
743 | delete globalBoardMasks; |
744 | } |
745 | |
5322694c |
746 | |
b3c7c475 |
747 | //_____________________________________________________________________________ |
5322694c |
748 | void writeToCDB(const char* cdbpath, const char* calibpath, TObject* object, |
749 | Int_t startRun, Int_t endRun, Bool_t defaultValues) |
b3c7c475 |
750 | { |
5322694c |
751 | AliCDBId id(calibpath,startRun,endRun); |
b3c7c475 |
752 | AliCDBMetaData md; |
753 | md.SetBeamPeriod(1); |
754 | md.SetAliRootVersion(gROOT->GetVersion()); |
755 | if ( defaultValues ) |
756 | { |
757 | md.SetComment("Test with default values"); |
758 | } |
759 | else |
760 | { |
761 | md.SetComment("Test with random values"); |
762 | } |
763 | md.SetResponsible("Laurent Aphecetche"); |
764 | |
765 | AliCDBManager* man = AliCDBManager::Instance(); |
766 | man->SetDefaultStorage(cdbpath); |
5322694c |
767 | man->Put(object,id,&md); |
768 | } |
769 | |
770 | //_____________________________________________________________________________ |
771 | void writePedestals(const char* cdbpath, Bool_t defaultValues, |
772 | Int_t startRun, Int_t endRun) |
773 | { |
774 | AliMUONV2DStore* pedestalStore = new AliMUON2DMap; |
775 | Int_t ngenerated = makePedestalStore(*pedestalStore,defaultValues); |
776 | cout << "Ngenerated = " << ngenerated << endl; |
b3c7c475 |
777 | |
5322694c |
778 | writeToCDB(cdbpath,"MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues); |
779 | } |
780 | |
781 | //_____________________________________________________________________________ |
782 | void writeGains(const char* cdbpath, Bool_t defaultValues, |
783 | Int_t startRun, Int_t endRun) |
784 | { |
785 | AliMUONV2DStore* gainStore = new AliMUON2DMap; |
786 | Int_t ngenerated = makeGainStore(*gainStore,defaultValues); |
787 | cout << "Ngenerated = " << ngenerated << endl; |
8f7d7575 |
788 | |
5322694c |
789 | writeToCDB(cdbpath,"MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues); |
790 | } |
791 | |
792 | //_____________________________________________________________________________ |
793 | void writeDeadChannels(const char* cdbpath, Bool_t defaultValues, |
794 | Int_t startRun, Int_t endRun) |
795 | { |
796 | AliMUONV2DStore* deadStore = new AliMUON2DMap; |
797 | Int_t ngenerated = makeDeadStore(*deadStore,defaultValues); |
798 | cout << "Ngenerated = " << ngenerated << endl; |
8f7d7575 |
799 | |
5322694c |
800 | writeToCDB(cdbpath,"MUON/Calib/DeadChannels",deadStore,startRun,endRun,defaultValues); |
b3c7c475 |
801 | } |
802 | |
803 | |