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__)
24 #include "AliCDBEntry.h"
25 #include "AliCDBManager.h"
26 #include "AliMUON1DArray.h"
27 #include "AliMUON2DMap.h"
28 #include "AliMUONCalibParam1I.h"
29 #include "AliMUONCalibParam2F.h"
30 #include "AliMUONConstants.h"
31 #include "AliMUONTriggerLut.h"
32 #include "AliMUONV2DStore.h"
33 #include "AliMUONVCalibParam.h"
34 #include "AliMpDEIterator.h"
35 #include "AliMpDEManager.h"
36 #include "AliMpSegFactory.h"
37 #include "AliMpStationType.h"
38 #include "AliMpVSegmentation.h"
39 #include "AliMUONTriggerEfficiencyCells.h"
40 #include "Riostream.h"
44 #include "TStopwatch.h"
48 //_____________________________________________________________________________
49 Int_t countChannels(AliMpVSegmentation& seg)
53 for ( Int_t ix = 0; ix < seg.MaxPadIndexX(); ++ix )
55 for ( Int_t iy = 0; iy < seg.MaxPadIndexY(); ++iy )
57 if ( seg.HasPad(AliMpIntPair(ix,iy)) ) ++n;
63 //_____________________________________________________________________________
64 AliMpSegFactory* segFactory()
66 static AliMpSegFactory* sf = new AliMpSegFactory();
70 //_____________________________________________________________________________
78 for ( Int_t station = 0; station < AliMUONConstants::NCh(); ++station )
84 Int_t de = it.CurrentDE();
85 for ( Int_t cathode = 0; cathode < 2; ++cathode )
87 AliMpVSegmentation* seg = segFactory()->CreateMpSegmentation(de,cathode);
88 n += countChannels(*seg);
92 cout << "Station " << station << " has " << n << " channels" << endl;
93 if ( station < AliMUONConstants::NTrackingCh() )
103 cout << "Tracker channels = " << ntracker << endl;
104 cout << "Trigger channels = " << ntrigger << endl;
105 cout << "Total channels =" << ntotal << endl;
108 //_____________________________________________________________________________
109 AliMUONV2DStore* read2D(const char* calibType)
111 AliCDBManager* man = AliCDBManager::Instance();
112 man->SetDefaultStorage(CDBPath);
114 AliCDBEntry* entry = man->Get(calibType,0);
118 return (AliMUONV2DStore*)entry->GetObject();
123 //_____________________________________________________________________________
124 AliMUONV1DStore* read1D(const char* calibType)
126 AliCDBManager* man = AliCDBManager::Instance();
127 man->SetDefaultStorage(CDBPath);
129 AliCDBEntry* entry = man->Get(calibType,0);
133 return (AliMUONV1DStore*)entry->GetObject();
138 //_____________________________________________________________________________
139 void checkCDB(const char* calibType)
141 TString c(calibType);
144 if ( c == "MUON/Calib/DeadChannels" )
149 AliMUONV2DStore* store = read2D(calibType);
152 TIter next(manuList());
155 while ( ( p = (AliMpIntPair*)next() ) )
157 Int_t detElemId = p->GetFirst();
158 Int_t manuId = p->GetSecond();
160 AliMUONVCalibParam* value =
161 dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId));
165 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
167 Float_t testValue = value->ValueAsFloat(manuChannel,0);
168 if ( testValue && testValue != refValue )
170 cout << "Got a strange value for DE=" << detElemId << " manuId="
171 << manuId << " manuChannel=" << manuChannel << " was expecting "
172 << refValue << " and I got " << testValue << endl;
178 cout << "Got a null value for DE=" << detElemId << " manuId="
187 //_____________________________________________________________________________
188 void plotCDB(const char* calibType)
190 TString c(calibType);
195 if ( c == "MUON/Calib/Gains" )
197 h = new TH1F("gains_mean","mean gain",100,0,1.5);
198 h2 = new TH1F("saturation","adc saturation",4096,-0.5,4095.5);
200 else if ( c == "MUON/Calib/Pedestals" )
202 h = new TH1F("pedestals_mean","pedestals_mean",4096,-0.5,4095.5);
203 h2 = new TH1F("pedestals_sigma","pedestals_sigma",100,0,20);
205 else if ( c == "MUON/Calib/DeadChannels" )
207 h = new TH1F("dead_channels","dead channels per DE",1500,-0.5,1499.5);
211 cerr << "Don't know how to deal with " << calibType << endl;
215 AliMUONV2DStore* store = read2D(calibType);
218 TIter next(manuList());
222 Int_t nPerStation[7];
224 for ( Int_t i = 0; i < 7; ++i ) nPerStation[i]=0;
226 while ( ( p = (AliMpIntPair*)next() ) )
228 Int_t detElemId = p->GetFirst();
229 Int_t manuId = p->GetSecond();
230 Int_t station = AliMpDEmanager::GetChamberId(detElemId);
232 AliMUONVCalibParam* value =
233 dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId));
237 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
240 ++nPerStation[station];
243 h->Fill(value->ValueAsFloat(manuChannel,0));
244 h2->Fill(value->ValueAsFloat(manuChannel,1));
248 if( value->ValueAsInt(manuChannel) )
258 cout << "Got a null value for DE=" << detElemId << " manuId="
263 cout << "Number of channels = " << n << endl;
264 for ( Int_t i = 0; i < 7; ++i )
266 cout << "Station " << (i+1) << " " << nPerStation[i] << endl;
269 if (n && c == "MUON/Calib/DeadChannels")
271 cout << "Number of dead channels=" << ndead << endl;
276 //_____________________________________________________________________________
277 void testReadStore(const AliMUONV2DStore& store, Int_t n)
279 TIter next(manuList());
282 while ( ( p = (AliMpIntPair*)next() ) )
284 for ( Int_t i = 0; i < n; ++i )
286 store.Get(p->GetFirst(),p->GetSecond());
291 //_____________________________________________________________________________
292 Int_t makeStores(AliMUONV2DStore& pedestalStore,
293 AliMUONV2DStore& gainStore,
294 AliMUONV2DStore& deadStore,
295 Bool_t defaultValues)
297 TIter next(manuList());
303 Bool_t replace = kFALSE;
305 const Int_t nChannels(64);
307 while ( ( p = (AliMpIntPair*)next() ) )
309 AliMUONVCalibParam* ped = new AliMUONCalibParam2F(nChannels);
310 AliMUONVCalibParam* gain = new AliMUONCalibParam2F(nChannels);
311 AliMUONVCalibParam* dead = new AliMUONCalibParam1I(nChannels);
313 for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
315 Float_t meanPedestal;
316 Float_t sigmaPedestal;
318 Float_t saturation(3000);
329 while ( meanPedestal < 0 )
331 meanPedestal = gRandom->Gaus(150,10);
334 while ( sigmaPedestal < 0 )
336 sigmaPedestal = gRandom->Gaus(1,0.2);
339 while ( meanGain < 0 )
341 meanGain = gRandom->Gaus(1,0.05);
344 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
345 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
346 gain->SetValueAsFloat(manuChannel,0,meanGain);
347 gain->SetValueAsFloat(manuChannel,1,saturation);
351 // probability that this channel is dead ~ 1%
352 if ( gRandom->Uniform(100.0) < 1.0 )
354 Int_t reason = 5; // that value could be used to distinguish
355 // why the channel is dead or how it was flagged bad (online,
356 // offline, by chance...). 5 is of course a fake number.
357 dead->SetValueAsInt(manuChannel,0,reason);
361 Int_t detElemId = p->GetFirst();
362 Int_t manuId = p->GetSecond();
363 Bool_t ok1 = pedestalStore.Set(detElemId,manuId,ped,replace);
364 Bool_t ok2 = gainStore.Set(detElemId,manuId,gain,replace);
365 Bool_t ok3 = deadStore.Set(detElemId,manuId,dead,replace);
366 if (!ok1 || !ok2 || !ok3)
368 cout << "Could not set DetElemId=" << detElemId << " manuId="
380 //_____________________________________________________________________________
381 TList* manuList(Bool_t reset)
383 static TList* fgmanuList = new TList;
387 fgmanuList->Delete();
391 if (!fgmanuList->IsEmpty()) return fgmanuList;
395 cout << "Generating manu list. Please wait" << endl;
397 fgmanuList->SetOwner(kTRUE);
405 while ( !it.IsDone() )
407 Int_t detElemId = it.CurrentDE();
408 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
409 if ( stationType != kStationTrigger )
411 for ( Int_t cath = 0; cath <=1 ; ++cath )
413 AliMpVSegmentation* seg = segFactory()->CreateMpSegmentation(detElemId,cath);
417 seg->GetAllElectronicCardIDs(manus);
419 for ( Int_t im = 0; im < manus.GetSize(); ++im )
421 fgmanuList->Add(new AliMpIntPair(detElemId,manus[im]));
428 cout << "Time to make the manu list = ";
434 //_____________________________________________________________________________
435 void testMakeStores(Int_t readLoop)
439 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
440 AliMUONV2DStore* gainStore = new AliMUON2DMap;
441 AliMUONV2DStore* deadStore = new AliMUON2DMap;
445 cout << "Creating" << endl;
448 makeStores(*pedestalStore,*gainStore,*deadStore,true);
451 cout << "Reading..." << endl;
453 testReadStore(*pedestalStore,readLoop);
454 testReadStore(*gainStore,readLoop);
455 testReadStore(*deadStore,readLoop);
456 cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop
457 <<" samples." << endl;
459 delete pedestalStore;
464 //_____________________________________________________________________________
465 void generateTrigger(const char* cdbpath)
468 // Generate trigger related conditions :
470 // - trigger masks for board (locals, regionals, global)
472 // - trigger efficiency
473 // - trigger switches (to be implemented FIXME)
475 const Int_t nlboards = 234;
476 AliMUONV1DStore* localBoardMasks = new AliMUON1DArray(nlboards+1);
478 // Generate fake mask values for 234 localboards and put that into
479 // one single container (localBoardMasks)
480 for ( Int_t i = 1; i <= nlboards; ++i )
482 AliMUONVCalibParam* localBoard = new AliMUONCalibParam1I(8);
483 for ( Int_t x = 0; x < 2; ++x )
485 for ( Int_t y = 0; y < 4; ++y )
488 localBoard->SetValueAsInt(index,0,0xFFFF);
491 localBoardMasks->Set(i,localBoard,kFALSE);
494 // Generate values for regional boards
495 const Int_t nrboards = 16;
496 AliMUONV1DStore* regionalBoardMasks = new AliMUON1DArray(16);
498 for ( Int_t i = 0; i < nrboards; ++i )
500 AliMUONVCalibParam* regionalBoard = new AliMUONCalibParam1I(16);
501 for ( Int_t j = 0; j < 16; ++j )
503 regionalBoard->SetValueAsInt(j,0,0x3F);
505 regionalBoardMasks->Set(i,regionalBoard,kFALSE);
508 // Generate values for global board
509 AliMUONVCalibParam* globalBoardMasks = new AliMUONCalibParam1I(16);
511 for ( Int_t j = 0; j < 16; ++j )
513 globalBoardMasks->SetValueAsInt(j,0,0xFFF);
516 AliMUONTriggerLut lut;
517 lut.ReadFromFile("$(ALICE_ROOT)/MUON/data/lutAptLpt1Hpt1p7.root");
519 AliMUONTriggerEfficiencyCells cells("$ALICE_ROOT/MUON/data/efficiencyCells.dat");
521 //--------------------------------------------
522 // Store the resulting containers into the CDB
523 Int_t ever = 99999999;
525 AliCDBId id("MUON/Calib/LocalTriggerBoardMasks",0,ever);
529 md.SetAliRootVersion(gROOT->GetVersion());
530 md.SetComment("Test with default values");
531 md.SetResponsible("Rachid Guernane");
533 AliCDBManager* man = AliCDBManager::Instance();
534 man->SetDefaultStorage(cdbpath);
535 man->Put(localBoardMasks,id,&md);
537 id.SetPath("MUON/Calib/RegionalTriggerBoardMasks");
539 man->Put(regionalBoardMasks,id,(AliCDBMetaData*)md.Clone());
541 id.SetPath("MUON/Calib/GlobalTriggerBoardMasks");
543 man->Put(globalBoardMasks,id,(AliCDBMetaData*)md.Clone());
545 id.SetPath("MUON/Calib/TriggerLut");
547 man->Put(&lut,id,(AliCDBMetaData*)md.Clone());
549 id.SetPath("MUON/Calib/TriggerEfficiency");
550 md.SetResponsible("Diego Stocco");
552 man->Put(&cells,id,(AliCDBMetaData*)md.Clone());
554 delete localBoardMasks;
555 delete regionalBoardMasks;
556 delete globalBoardMasks;
559 //_____________________________________________________________________________
560 void generateCalibrations(const char* cdbpath, Bool_t defaultValues)
566 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
567 AliMUONV2DStore* gainStore = new AliMUON2DMap;
568 AliMUONV2DStore* deadStore = new AliMUON2DMap;
570 makeStores(*pedestalStore,*gainStore,*deadStore,defaultValues);
572 Int_t ever = 99999999;
574 AliCDBId id("MUON/Calib/Pedestals",0,ever);
577 md.SetAliRootVersion(gROOT->GetVersion());
580 md.SetComment("Test with default values");
584 md.SetComment("Test with random values");
586 md.SetResponsible("Laurent Aphecetche");
588 AliCDBManager* man = AliCDBManager::Instance();
589 man->SetDefaultStorage(cdbpath);
590 man->Put(pedestalStore,id,&md);
592 id.SetPath("MUON/Calib/Gains");
594 man->Put(gainStore,id,(AliCDBMetaData*)md.Clone());
596 id.SetPath("MUON/Calib/DeadChannels");
598 man->Put(deadStore,id,(AliCDBMetaData*)md.Clone());
601 delete pedestalStore;