]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONCDB.C
Changing the default behavior of AliMUONv1
[u/mrichter/AliRoot.git] / MUON / MUONCDB.C
CommitLineData
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__)
21#include "MUONCDB.h"
22#include "AliCDBEntry.h"
23#include "AliCDBManager.h"
8f7d7575 24#include "AliMUON2DMap.h"
25#include "AliMUONV2DStore.h"
26#include "AliMUONVCalibParam.h"
27#include "AliMUONCalibParam1I.h"
28#include "AliMUONCalibParam2F.h"
b3c7c475 29#include "AliMpDEIterator.h"
30#include "AliMpDEManager.h"
b3c7c475 31#include "AliMpSegFactory.h"
32#include "AliMpStationType.h"
33#include "AliMpVSegmentation.h"
34#include "Riostream.h"
35#include "TH1F.h"
36#include "TList.h"
37#include "TRandom.h"
38#include "TStopwatch.h"
39#include "TSystem.h"
40#endif
41
8f7d7575 42//static const char* CDBPath = "local://$ALICE_ROOT/MUON/CDB/Random";
43static const char* CDBPath = "local://$ALICE_ROOT/MUON/CDB/Default";
b3c7c475 44
45//_____________________________________________________________________________
46AliMpSegFactory* segFactory()
47{
48 static AliMpSegFactory* sf = new AliMpSegFactory();
49 return sf;
50}
51
52//_____________________________________________________________________________
8f7d7575 53AliMUONV2DStore* readCDB(const char* calibType)
b3c7c475 54{
55 AliCDBManager* man = AliCDBManager::Instance();
56 man->SetDefaultStorage(CDBPath);
57
58 AliCDBEntry* entry = man->Get(calibType,0);
59
60 if (entry)
61 {
8f7d7575 62 return (AliMUONV2DStore*)entry->GetObject();
b3c7c475 63 }
64 return 0;
65}
66
67//_____________________________________________________________________________
8f7d7575 68void checkCDB(const char* calibType)
69{
70 TString c(calibType);
71 Float_t refValue(0);
72
73 if ( c == "MUON/Calib/DeadChannels" )
74 {
75 refValue=5;
76 }
77
78 AliMUONV2DStore* store = readCDB(calibType);
79 if (!store) return;
80
81 TIter next(manuList());
82 AliMpIntPair* p;
83
84 while ( ( p = (AliMpIntPair*)next() ) )
85 {
86 Int_t detElemId = p->GetFirst();
87 Int_t manuId = p->GetSecond();
88
89 AliMUONVCalibParam* value =
90 dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId));
91
92 if (value)
93 {
94 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
95 {
96 Float_t testValue = value->ValueAsFloat(manuChannel,0);
97 if ( testValue && testValue != refValue )
98 {
99 cout << "Got a strange value for DE=" << detElemId << " manuId="
100 << manuId << " manuChannel=" << manuChannel << " was expecting "
101 << refValue << " and I got " << testValue << endl;
102 }
103 }
104 }
105 else
106 {
107 cout << "Got a null value for DE=" << detElemId << " manuId="
108 << manuId << endl;
109 }
110 }
111
112 delete store;
113}
114
115
116//_____________________________________________________________________________
117void plotCDB(const char* calibType)
b3c7c475 118{
119 TString c(calibType);
120
121 TH1* h = 0;
8f7d7575 122 TH1* h2 = 0;
b3c7c475 123
124 if ( c == "MUON/Calib/Gains" )
125 {
8f7d7575 126 h = new TH1F("gains_mean","mean gain",100,0,1.5);
127 h2 = new TH1F("saturation","adc saturation",4096,-0.5,4095.5);
b3c7c475 128 }
129 else if ( c == "MUON/Calib/Pedestals" )
130 {
8f7d7575 131 h = new TH1F("pedestals_mean","pedestals_mean",4096,-0.5,4095.5);
132 h2 = new TH1F("pedestals_sigma","pedestals_sigma",100,0,20);
133 }
134 else if ( c == "MUON/Calib/DeadChannels" )
135 {
136 h = new TH1F("dead_channels","dead channels per DE",1500,-0.5,1499.5);
b3c7c475 137 }
138 else
139 {
140 cerr << "Don't know how to deal with " << calibType << endl;
141 return;
142 }
143
8f7d7575 144 AliMUONV2DStore* store = readCDB(calibType);
b3c7c475 145 if (!store) return;
146
8f7d7575 147 TIter next(manuList());
148 AliMpIntPair* p;
149 Int_t n(0);
150 Int_t ndead(0);
151 Int_t nPerStation[7];
152
153 for ( Int_t i = 0; i < 7; ++i ) nPerStation[i]=0;
b3c7c475 154
8f7d7575 155 while ( ( p = (AliMpIntPair*)next() ) )
b3c7c475 156 {
8f7d7575 157 Int_t detElemId = p->GetFirst();
158 Int_t manuId = p->GetSecond();
159
160 Int_t station = detElemId/100 - 1;
161
162 AliMUONVCalibParam* value =
163 dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId));
b3c7c475 164
b3c7c475 165 if (value)
166 {
8f7d7575 167 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
168 {
169 ++n;
170 ++nPerStation[station];
171 if (h2)
172 {
173 h->Fill(value->ValueAsFloat(manuChannel,0));
174 h2->Fill(value->ValueAsFloat(manuChannel,1));
175 }
176 else
177 {
178 if( value->ValueAsInt(manuChannel) )
179 {
180 h->Fill(detElemId);
181 ++ndead;
182 }
183 }
184 }
b3c7c475 185 }
186 else
187 {
188 cout << "Got a null value for DE=" << detElemId << " manuId="
8f7d7575 189 << manuId << endl;
b3c7c475 190 }
191 }
192
8f7d7575 193 cout << "Number of channels = " << n << endl;
194 for ( Int_t i = 0; i < 7; ++i )
195 {
196 cout << "Station " << (i+1) << " " << nPerStation[i] << endl;
197 }
198
199 if (n && c == "MUON/Calib/DeadChannels")
200 {
201 cout << "Number of dead channels=" << ndead << endl;
202 }
b3c7c475 203 delete store;
204}
205
206//_____________________________________________________________________________
8f7d7575 207void testReadStore(const AliMUONV2DStore& store, Int_t n)
b3c7c475 208{
8f7d7575 209 TIter next(manuList());
210 AliMpIntPair* p;
b3c7c475 211
8f7d7575 212 while ( ( p = (AliMpIntPair*)next() ) )
b3c7c475 213 {
214 for ( Int_t i = 0; i < n; ++i )
215 {
8f7d7575 216 store.Get(p->GetFirst(),p->GetSecond());
b3c7c475 217 }
218 }
219}
220
221//_____________________________________________________________________________
8f7d7575 222Int_t makeStores(AliMUONV2DStore& pedestalStore,
223 AliMUONV2DStore& gainStore,
224 AliMUONV2DStore& deadStore,
b3c7c475 225 Bool_t defaultValues)
226{
8f7d7575 227 TIter next(manuList());
b3c7c475 228
8f7d7575 229 AliMpIntPair* p;
b3c7c475 230
231 Int_t ngenerated(0);
232
233 Bool_t replace = kFALSE;
234
8f7d7575 235 const Int_t nChannels(64);
236
237 while ( ( p = (AliMpIntPair*)next() ) )
b3c7c475 238 {
8f7d7575 239 AliMUONVCalibParam* ped = new AliMUONCalibParam2F(nChannels);
240 AliMUONVCalibParam* gain = new AliMUONCalibParam2F(nChannels);
241 AliMUONVCalibParam* dead = new AliMUONCalibParam1I(nChannels);
242
243 for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
b3c7c475 244 {
8f7d7575 245 Float_t meanPedestal;
246 Float_t sigmaPedestal;
247 Float_t meanGain;
248 Float_t saturation(3000);
249
250 if ( defaultValues )
b3c7c475 251 {
8f7d7575 252 meanPedestal = 0.0;
253 sigmaPedestal = 1.0;
254 meanGain = 1.0;
b3c7c475 255 }
8f7d7575 256 else
b3c7c475 257 {
8f7d7575 258 meanPedestal = -1;
259 while ( meanPedestal < 0 )
260 {
261 meanPedestal = gRandom->Gaus(150,10);
262 }
263 sigmaPedestal = -1;
264 while ( sigmaPedestal < 0 )
265 {
266 sigmaPedestal = gRandom->Gaus(1,0.2);
267 }
268 meanGain = -1;
269 while ( meanGain < 0 )
270 {
271 meanGain = gRandom->Gaus(1,0.05);
272 }
b3c7c475 273 }
8f7d7575 274 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
275 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
276 gain->SetValueAsFloat(manuChannel,0,meanGain);
277 gain->SetValueAsFloat(manuChannel,1,saturation);
278
279 if (!defaultValues)
b3c7c475 280 {
8f7d7575 281 // probability that this channel is dead ~ 1%
282 if ( gRandom->Uniform(100.0) < 1.0 )
283 {
284 Int_t reason = 5; // that value could be used to distinguish
285 // why the channel is dead or how it was flagged bad (online,
286 // offline, by chance...). 5 is of course a fake number.
287 dead->SetValueAsInt(manuChannel,0,reason);
288 }
b3c7c475 289 }
290 }
8f7d7575 291 Int_t detElemId = p->GetFirst();
292 Int_t manuId = p->GetSecond();
293 Bool_t ok1 = pedestalStore.Set(detElemId,manuId,ped,replace);
294 Bool_t ok2 = gainStore.Set(detElemId,manuId,gain,replace);
295 Bool_t ok3 = deadStore.Set(detElemId,manuId,dead,replace);
296 if (!ok1 || !ok2 || !ok3)
b3c7c475 297 {
298 cout << "Could not set DetElemId=" << detElemId << " manuId="
8f7d7575 299 << manuId << endl;
b3c7c475 300 }
301 else
302 {
303 ++ngenerated;
304 }
305 }
306
307 return ngenerated;
308}
309
310//_____________________________________________________________________________
8f7d7575 311TList* manuList(Bool_t reset)
b3c7c475 312{
8f7d7575 313 static TList* fgmanuList = new TList;
b3c7c475 314
315 if (reset)
316 {
8f7d7575 317 fgmanuList->Delete();
318 return fgmanuList;
b3c7c475 319 }
320
8f7d7575 321 if (!fgmanuList->IsEmpty()) return fgmanuList;
b3c7c475 322
323 TStopwatch timer;
324
8f7d7575 325 cout << "Generating manu list. Please wait" << endl;
b3c7c475 326
8f7d7575 327 fgmanuList->SetOwner(kTRUE);
b3c7c475 328
329 timer.Start();
330
331 AliMpDEIterator it;
332
333 it.First();
334
335 while ( !it.IsDone() )
336 {
337 Int_t detElemId = it.CurrentDE();
338 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
339 if ( stationType != kStationTrigger )
340 {
341 for ( Int_t cath = 0; cath <=1 ; ++cath )
342 {
343 AliMpVSegmentation* seg = segFactory()->CreateMpSegmentation(detElemId,cath);
b3c7c475 344
8f7d7575 345 TArrayI manus;
346
347 seg->GetAllElectronicCardIDs(manus);
348
349 for ( Int_t im = 0; im < manus.GetSize(); ++im )
350 {
351 fgmanuList->Add(new AliMpIntPair(detElemId,manus[im]));
352 }
b3c7c475 353 }
354 }
355 it.Next();
356 }
357
8f7d7575 358 cout << "Time to make the manu list = ";
b3c7c475 359 timer.Print();
360
8f7d7575 361 return fgmanuList;
b3c7c475 362}
363
364//_____________________________________________________________________________
8f7d7575 365void testMakeStores(Int_t readLoop)
b3c7c475 366{
8f7d7575 367 manuList();
b3c7c475 368
8f7d7575 369 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
370 AliMUONV2DStore* gainStore = new AliMUON2DMap;
371 AliMUONV2DStore* deadStore = new AliMUON2DMap;
b3c7c475 372
373 TStopwatch timer;
374
375 cout << "Creating" << endl;
376
377 timer.Start(kTRUE);
8f7d7575 378 makeStores(*pedestalStore,*gainStore,*deadStore,true);
b3c7c475 379 timer.Print();
380
381 cout << "Reading..." << endl;
382 timer.Start(kTRUE);
383 testReadStore(*pedestalStore,readLoop);
384 testReadStore(*gainStore,readLoop);
8f7d7575 385 testReadStore(*deadStore,readLoop);
b3c7c475 386 cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop
387 <<" samples." << endl;
388
389 delete pedestalStore;
390 delete gainStore;
8f7d7575 391 delete deadStore;
b3c7c475 392}
393
394//_____________________________________________________________________________
8f7d7575 395void generateCalibrations(const char* cdbpath, Bool_t defaultValues)
b3c7c475 396{
397 //
398 //
399 //
400
8f7d7575 401 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
402 AliMUONV2DStore* gainStore = new AliMUON2DMap;
403 AliMUONV2DStore* deadStore = new AliMUON2DMap;
404
405 makeStores(*pedestalStore,*gainStore,*deadStore,defaultValues);
b3c7c475 406
407 Int_t ever = 99999999;
408
409 AliCDBId id("MUON/Calib/Pedestals",0,ever);
410 AliCDBMetaData md;
411 md.SetBeamPeriod(1);
412 md.SetAliRootVersion(gROOT->GetVersion());
413 if ( defaultValues )
414 {
415 md.SetComment("Test with default values");
416 }
417 else
418 {
419 md.SetComment("Test with random values");
420 }
421 md.SetResponsible("Laurent Aphecetche");
422
423 AliCDBManager* man = AliCDBManager::Instance();
424 man->SetDefaultStorage(cdbpath);
425 man->Put(pedestalStore,id,&md);
426
427 id.SetPath("MUON/Calib/Gains");
428
429 man->Put(gainStore,id,(AliCDBMetaData*)md.Clone());
430
8f7d7575 431 id.SetPath("MUON/Calib/DeadChannels");
432
433 man->Put(deadStore,id,(AliCDBMetaData*)md.Clone());
434
435 delete deadStore;
b3c7c475 436 delete pedestalStore;
437 delete gainStore;
438}
439
440