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();
231 Int_t station = detElemId/100 - 1;
233 AliMUONVCalibParam* value =
234 dynamic_cast<AliMUONVCalibParam*>(store->Get(detElemId,manuId));
238 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
241 ++nPerStation[station];
244 h->Fill(value->ValueAsFloat(manuChannel,0));
245 h2->Fill(value->ValueAsFloat(manuChannel,1));
249 if( value->ValueAsInt(manuChannel) )
259 cout << "Got a null value for DE=" << detElemId << " manuId="
264 cout << "Number of channels = " << n << endl;
265 for ( Int_t i = 0; i < 7; ++i )
267 cout << "Station " << (i+1) << " " << nPerStation[i] << endl;
270 if (n && c == "MUON/Calib/DeadChannels")
272 cout << "Number of dead channels=" << ndead << endl;
277 //_____________________________________________________________________________
278 void testReadStore(const AliMUONV2DStore& store, Int_t n)
280 TIter next(manuList());
283 while ( ( p = (AliMpIntPair*)next() ) )
285 for ( Int_t i = 0; i < n; ++i )
287 store.Get(p->GetFirst(),p->GetSecond());
292 //_____________________________________________________________________________
293 Int_t makeStores(AliMUONV2DStore& pedestalStore,
294 AliMUONV2DStore& gainStore,
295 AliMUONV2DStore& deadStore,
296 Bool_t defaultValues)
298 TIter next(manuList());
304 Bool_t replace = kFALSE;
306 const Int_t nChannels(64);
308 while ( ( p = (AliMpIntPair*)next() ) )
310 AliMUONVCalibParam* ped = new AliMUONCalibParam2F(nChannels);
311 AliMUONVCalibParam* gain = new AliMUONCalibParam2F(nChannels);
312 AliMUONVCalibParam* dead = new AliMUONCalibParam1I(nChannels);
314 for ( Int_t manuChannel = 0; manuChannel < nChannels; ++manuChannel )
316 Float_t meanPedestal;
317 Float_t sigmaPedestal;
319 Float_t saturation(3000);
330 while ( meanPedestal < 0 )
332 meanPedestal = gRandom->Gaus(150,10);
335 while ( sigmaPedestal < 0 )
337 sigmaPedestal = gRandom->Gaus(1,0.2);
340 while ( meanGain < 0 )
342 meanGain = gRandom->Gaus(1,0.05);
345 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
346 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
347 gain->SetValueAsFloat(manuChannel,0,meanGain);
348 gain->SetValueAsFloat(manuChannel,1,saturation);
352 // probability that this channel is dead ~ 1%
353 if ( gRandom->Uniform(100.0) < 1.0 )
355 Int_t reason = 5; // that value could be used to distinguish
356 // why the channel is dead or how it was flagged bad (online,
357 // offline, by chance...). 5 is of course a fake number.
358 dead->SetValueAsInt(manuChannel,0,reason);
362 Int_t detElemId = p->GetFirst();
363 Int_t manuId = p->GetSecond();
364 Bool_t ok1 = pedestalStore.Set(detElemId,manuId,ped,replace);
365 Bool_t ok2 = gainStore.Set(detElemId,manuId,gain,replace);
366 Bool_t ok3 = deadStore.Set(detElemId,manuId,dead,replace);
367 if (!ok1 || !ok2 || !ok3)
369 cout << "Could not set DetElemId=" << detElemId << " manuId="
381 //_____________________________________________________________________________
382 TList* manuList(Bool_t reset)
384 static TList* fgmanuList = new TList;
388 fgmanuList->Delete();
392 if (!fgmanuList->IsEmpty()) return fgmanuList;
396 cout << "Generating manu list. Please wait" << endl;
398 fgmanuList->SetOwner(kTRUE);
406 while ( !it.IsDone() )
408 Int_t detElemId = it.CurrentDE();
409 AliMpStationType stationType = AliMpDEManager::GetStationType(detElemId);
410 if ( stationType != kStationTrigger )
412 for ( Int_t cath = 0; cath <=1 ; ++cath )
414 AliMpVSegmentation* seg = segFactory()->CreateMpSegmentation(detElemId,cath);
418 seg->GetAllElectronicCardIDs(manus);
420 for ( Int_t im = 0; im < manus.GetSize(); ++im )
422 fgmanuList->Add(new AliMpIntPair(detElemId,manus[im]));
429 cout << "Time to make the manu list = ";
435 //_____________________________________________________________________________
436 void testMakeStores(Int_t readLoop)
440 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
441 AliMUONV2DStore* gainStore = new AliMUON2DMap;
442 AliMUONV2DStore* deadStore = new AliMUON2DMap;
446 cout << "Creating" << endl;
449 makeStores(*pedestalStore,*gainStore,*deadStore,true);
452 cout << "Reading..." << endl;
454 testReadStore(*pedestalStore,readLoop);
455 testReadStore(*gainStore,readLoop);
456 testReadStore(*deadStore,readLoop);
457 cout << timer.CpuTime()/readLoop << " CPUs (mean of " << readLoop
458 <<" samples." << endl;
460 delete pedestalStore;
465 //_____________________________________________________________________________
466 void generateTrigger(const char* cdbpath)
469 // Generate trigger related conditions :
471 // - trigger masks for board (locals, regionals, global)
473 // - trigger efficiency
474 // - trigger switches (to be implemented FIXME)
476 const Int_t nlboards = 234;
477 AliMUONV1DStore* localBoardMasks = new AliMUON1DArray(nlboards+1);
479 // Generate fake mask values for 234 localboards and put that into
480 // one single container (localBoardMasks)
481 for ( Int_t i = 1; i <= nlboards; ++i )
483 AliMUONVCalibParam* localBoard = new AliMUONCalibParam1I(8);
484 for ( Int_t x = 0; x < 2; ++x )
486 for ( Int_t y = 0; y < 4; ++y )
489 localBoard->SetValueAsInt(index,0,0xFFFF);
492 localBoardMasks->Set(i,localBoard,kFALSE);
495 // Generate values for regional boards
496 const Int_t nrboards = 16;
497 AliMUONV1DStore* regionalBoardMasks = new AliMUON1DArray(16);
499 for ( Int_t i = 0; i < nrboards; ++i )
501 AliMUONVCalibParam* regionalBoard = new AliMUONCalibParam1I(16);
502 for ( Int_t j = 0; j < 16; ++j )
504 regionalBoard->SetValueAsInt(j,0,0x3F);
506 regionalBoardMasks->Set(i,regionalBoard,kFALSE);
509 // Generate values for global board
510 AliMUONVCalibParam* globalBoardMasks = new AliMUONCalibParam1I(16);
512 for ( Int_t j = 0; j < 16; ++j )
514 globalBoardMasks->SetValueAsInt(j,0,0xFFF);
517 AliMUONTriggerLut lut;
518 lut.ReadFromFile("$(ALICE_ROOT)/MUON/data/lutAptLpt1Hpt1p7.root");
520 AliMUONTriggerEfficiencyCells cells("$ALICE_ROOT/MUON/data/efficiencyCells.dat");
522 //--------------------------------------------
523 // Store the resulting containers into the CDB
524 Int_t ever = 99999999;
526 AliCDBId id("MUON/Calib/LocalTriggerBoardMasks",0,ever);
530 md.SetAliRootVersion(gROOT->GetVersion());
531 md.SetComment("Test with default values");
532 md.SetResponsible("Rachid Guernane");
534 AliCDBManager* man = AliCDBManager::Instance();
535 man->SetDefaultStorage(cdbpath);
536 man->Put(localBoardMasks,id,&md);
538 id.SetPath("MUON/Calib/RegionalTriggerBoardMasks");
540 man->Put(regionalBoardMasks,id,(AliCDBMetaData*)md.Clone());
542 id.SetPath("MUON/Calib/GlobalTriggerBoardMasks");
544 man->Put(globalBoardMasks,id,(AliCDBMetaData*)md.Clone());
546 id.SetPath("MUON/Calib/TriggerLut");
548 man->Put(&lut,id,(AliCDBMetaData*)md.Clone());
550 id.SetPath("MUON/Calib/TriggerEfficiency");
551 md.SetResponsible("Diego Stocco");
553 man->Put(&cells,id,(AliCDBMetaData*)md.Clone());
555 delete localBoardMasks;
556 delete regionalBoardMasks;
557 delete globalBoardMasks;
560 //_____________________________________________________________________________
561 void generateCalibrations(const char* cdbpath, Bool_t defaultValues)
567 AliMUONV2DStore* pedestalStore = new AliMUON2DMap;
568 AliMUONV2DStore* gainStore = new AliMUON2DMap;
569 AliMUONV2DStore* deadStore = new AliMUON2DMap;
571 makeStores(*pedestalStore,*gainStore,*deadStore,defaultValues);
573 Int_t ever = 99999999;
575 AliCDBId id("MUON/Calib/Pedestals",0,ever);
578 md.SetAliRootVersion(gROOT->GetVersion());
581 md.SetComment("Test with default values");
585 md.SetComment("Test with random values");
587 md.SetResponsible("Laurent Aphecetche");
589 AliCDBManager* man = AliCDBManager::Instance();
590 man->SetDefaultStorage(cdbpath);
591 man->Put(pedestalStore,id,&md);
593 id.SetPath("MUON/Calib/Gains");
595 man->Put(gainStore,id,(AliCDBMetaData*)md.Clone());
597 id.SetPath("MUON/Calib/DeadChannels");
599 man->Put(deadStore,id,(AliCDBMetaData*)md.Clone());
602 delete pedestalStore;