1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 /// By Laurent Aphecetche
20 #if !defined(__CINT__) || defined(__MAKECINT__)
22 #include "AliCDBEntry.h"
23 #include "AliCDBManager.h"
24 #include "AliMUON2DMap.h"
25 #include "AliMUONV2DStore.h"
26 #include "AliMUONVCalibParam.h"
27 #include "AliMUONCalibParam1I.h"
28 #include "AliMUONCalibParam2F.h"
29 #include "AliMpDEIterator.h"
30 #include "AliMpDEManager.h"
31 #include "AliMpSegFactory.h"
32 #include "AliMpStationType.h"
33 #include "AliMpVSegmentation.h"
34 #include "Riostream.h"
38 #include "TStopwatch.h"
42 //static const char* CDBPath = "local://$ALICE_ROOT/MUON/CDB/Random";
43 static const char* CDBPath = "local://$ALICE_ROOT/MUON/CDB/Default";
45 //_____________________________________________________________________________
46 AliMpSegFactory* segFactory()
48 static AliMpSegFactory* sf = new AliMpSegFactory();
52 //_____________________________________________________________________________
53 AliMUONV2DStore* readCDB(const char* calibType)
55 AliCDBManager* man = AliCDBManager::Instance();
56 man->SetDefaultStorage(CDBPath);
58 AliCDBEntry* entry = man->Get(calibType,0);
62 return (AliMUONV2DStore*)entry->GetObject();
67 //_____________________________________________________________________________
68 void checkCDB(const char* calibType)
73 if ( c == "MUON/Calib/DeadChannels" )
78 AliMUONV2DStore* store = readCDB(calibType);
81 TIter next(manuList());
84 while ( ( p = (AliMpIntPair*)next() ) )
86 Int_t detElemId = p->GetFirst();
87 Int_t manuId = p->GetSecond();
89 AliMUONVCalibParam* value =
90 dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId));
94 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
96 Float_t testValue = value->ValueAsFloat(manuChannel,0);
97 if ( testValue && testValue != refValue )
99 cout << "Got a strange value for DE=" << detElemId << " manuId="
100 << manuId << " manuChannel=" << manuChannel << " was expecting "
101 << refValue << " and I got " << testValue << endl;
107 cout << "Got a null value for DE=" << detElemId << " manuId="
116 //_____________________________________________________________________________
117 void plotCDB(const char* calibType)
119 TString c(calibType);
124 if ( c == "MUON/Calib/Gains" )
126 h = new TH1F("gains_mean","mean gain",100,0,1.5);
127 h2 = new TH1F("saturation","adc saturation",4096,-0.5,4095.5);
129 else if ( c == "MUON/Calib/Pedestals" )
131 h = new TH1F("pedestals_mean","pedestals_mean",4096,-0.5,4095.5);
132 h2 = new TH1F("pedestals_sigma","pedestals_sigma",100,0,20);
134 else if ( c == "MUON/Calib/DeadChannels" )
136 h = new TH1F("dead_channels","dead channels per DE",1500,-0.5,1499.5);
140 cerr << "Don't know how to deal with " << calibType << endl;
144 AliMUONV2DStore* store = readCDB(calibType);
147 TIter next(manuList());
151 Int_t nPerStation[7];
153 for ( Int_t i = 0; i < 7; ++i ) nPerStation[i]=0;
155 while ( ( p = (AliMpIntPair*)next() ) )
157 Int_t detElemId = p->GetFirst();
158 Int_t manuId = p->GetSecond();
160 Int_t station = detElemId/100 - 1;
162 AliMUONVCalibParam* value =
163 dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId));
167 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
170 ++nPerStation[station];
173 h->Fill(value->ValueAsFloat(manuChannel,0));
174 h2->Fill(value->ValueAsFloat(manuChannel,1));
178 if( value->ValueAsInt(manuChannel) )
188 cout << "Got a null value for DE=" << detElemId << " manuId="
193 cout << "Number of channels = " << n << endl;
194 for ( Int_t i = 0; i < 7; ++i )
196 cout << "Station " << (i+1) << " " << nPerStation[i] << endl;
199 if (n && c == "MUON/Calib/DeadChannels")
201 cout << "Number of dead channels=" << ndead << endl;
206 //_____________________________________________________________________________
207 void testReadStore(const AliMUONV2DStore& store, Int_t n)
209 TIter next(manuList());
212 while ( ( p = (AliMpIntPair*)next() ) )
214 for ( Int_t i = 0; i < n; ++i )
216 store.Get(p->GetFirst(),p->GetSecond());
221 //_____________________________________________________________________________
222 Int_t makeStores(AliMUONV2DStore& pedestalStore,
223 AliMUONV2DStore& gainStore,
224 AliMUONV2DStore& deadStore,
225 Bool_t defaultValues)
227 TIter next(manuList());
233 Bool_t replace = kFALSE;
235 const Int_t nChannels(64);
237 while ( ( p = (AliMpIntPair*)next() ) )
239 AliMUONVCalibParam* ped = new AliMUONCalibParam2F(nChannels);
240 AliMUONVCalibParam* gain = new AliMUONCalibParam2F(nChannels);
241 AliMUONVCalibParam* dead = new AliMUONCalibParam1I(nChannels);
243 for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
245 Float_t meanPedestal;
246 Float_t sigmaPedestal;
248 Float_t saturation(3000);
259 while ( meanPedestal < 0 )
261 meanPedestal = gRandom->Gaus(150,10);
264 while ( sigmaPedestal < 0 )
266 sigmaPedestal = gRandom->Gaus(1,0.2);
269 while ( meanGain < 0 )
271 meanGain = gRandom->Gaus(1,0.05);
274 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
275 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
276 gain->SetValueAsFloat(manuChannel,0,meanGain);
277 gain->SetValueAsFloat(manuChannel,1,saturation);
281 // probability that this channel is dead ~ 1%
282 if ( gRandom->Uniform(100.0) < 1.0 )
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);
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)
298 cout << "Could not set DetElemId=" << detElemId << " manuId="
310 //_____________________________________________________________________________
311 TList* manuList(Bool_t reset)
313 static TList* fgmanuList = new TList;
317 fgmanuList->Delete();
321 if (!fgmanuList->IsEmpty()) return fgmanuList;
325 cout << "Generating manu list. Please wait" << endl;
327 fgmanuList->SetOwner(kTRUE);
335 while ( !it.IsDone() )
337 Int_t detElemId = it.CurrentDE();
338 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
339 if ( stationType != kStationTrigger )
341 for ( Int_t cath = 0; cath <=1 ; ++cath )
343 AliMpVSegmentation* seg = segFactory()->CreateMpSegmentation(detElemId,cath);
347 seg->GetAllElectronicCardIDs(manus);
349 for ( Int_t im = 0; im < manus.GetSize(); ++im )
351 fgmanuList->Add(new AliMpIntPair(detElemId,manus[im]));
358 cout << "Time to make the manu list = ";
364 //_____________________________________________________________________________
365 void testMakeStores(Int_t readLoop)
369 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
370 AliMUONV2DStore* gainStore = new AliMUON2DMap;
371 AliMUONV2DStore* deadStore = new AliMUON2DMap;
375 cout << "Creating" << endl;
378 makeStores(*pedestalStore,*gainStore,*deadStore,true);
381 cout << "Reading..." << endl;
383 testReadStore(*pedestalStore,readLoop);
384 testReadStore(*gainStore,readLoop);
385 testReadStore(*deadStore,readLoop);
386 cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop
387 <<" samples." << endl;
389 delete pedestalStore;
394 //_____________________________________________________________________________
395 void generateCalibrations(const char* cdbpath, Bool_t defaultValues)
401 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
402 AliMUONV2DStore* gainStore = new AliMUON2DMap;
403 AliMUONV2DStore* deadStore = new AliMUON2DMap;
405 makeStores(*pedestalStore,*gainStore,*deadStore,defaultValues);
407 Int_t ever = 99999999;
409 AliCDBId id("MUON/Calib/Pedestals",0,ever);
412 md.SetAliRootVersion(gROOT->GetVersion());
415 md.SetComment("Test with default values");
419 md.SetComment("Test with random values");
421 md.SetResponsible("Laurent Aphecetche");
423 AliCDBManager* man = AliCDBManager::Instance();
424 man->SetDefaultStorage(cdbpath);
425 man->Put(pedestalStore,id,&md);
427 id.SetPath("MUON/Calib/Gains");
429 man->Put(gainStore,id,(AliCDBMetaData*)md.Clone());
431 id.SetPath("MUON/Calib/DeadChannels");
433 man->Put(deadStore,id,(AliCDBMetaData*)md.Clone());
436 delete pedestalStore;