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 //-----------------------------------------------------------------------------
19 /// \namespace AliMUONCDB
21 /// Helper functions to experience the OCDB
23 /// They allow to read magnetic field, mapping and recoParam from OCDB
25 /// And also to generate dummy (but complete) containers for all the
26 /// calibration data types we have for tracker and trigger, and to write
29 /// For more information, please see READMEcalib
31 // \author Laurent Aphecetche
32 //-----------------------------------------------------------------------------
34 #include "AliMUONCDB.h"
36 #include "AliMUON1DArray.h"
37 #include "AliMUON1DMap.h"
38 #include "AliMUON2DMap.h"
39 #include "AliMUON2DStoreValidator.h"
40 #include "AliMUONCalibParamND.h"
41 #include "AliMUONCalibParamNF.h"
42 #include "AliMUONCalibParamNI.h"
43 #include "AliMUONConstants.h"
44 #include "AliMUONRejectList.h"
45 #include "AliMUONTrackerIO.h"
46 #include "AliMUONTriggerEfficiencyCells.h"
47 #include "AliMUONTriggerLut.h"
48 #include "AliMUONVStore.h"
49 #include "AliMUONVCalibParam.h"
50 #include "AliMUONVCalibParam.h"
51 #include "AliMUONGlobalCrateConfig.h"
52 #include "AliMUONRegionalTriggerConfig.h"
53 #include "AliMUONRecoParam.h"
56 #include "AliMpConstants.h"
57 #include "AliMpDEStore.h"
58 #include "AliMpDDLStore.h"
59 #include "AliMpManuStore.h"
60 #include "AliMpDEManager.h"
61 #include "AliMpDetElement.h"
62 #include "AliMpFiles.h"
63 #include "AliMpDCSNamer.h"
64 #include "AliMpManuIterator.h"
65 #include "AliMpSegmentation.h"
66 #include "AliMpStationType.h"
67 #include "AliMpVSegmentation.h"
69 #include "AliCodeTimer.h"
70 #include "AliCDBEntry.h"
71 #include "AliCDBManager.h"
72 #include "AliGRPManager.h"
73 #include "AliDCSValue.h"
76 #include <Riostream.h>
82 #include <TObjString.h>
85 #include <TStopwatch.h>
88 #include <TGeoGlobalMagField.h>
93 //_____________________________________________________________________________
94 AliMUONVStore* Create2DMap()
96 return new AliMUON2DMap(true);
99 //_____________________________________________________________________________
100 void getBoundaries(const AliMUONVStore& store, Int_t dim,
101 Float_t* xmin, Float_t* xmax)
103 /// Assuming the store contains AliMUONVCalibParam objects, compute the
104 /// limits of the value contained in the VCalibParam, for each of its dimensions
105 /// xmin and xmax must be of dimension dim
107 for ( Int_t i = 0; i < dim; ++i )
113 TIter next(store.CreateIterator());
114 AliMUONVCalibParam* value;
116 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
118 Int_t detElemId = value->ID0();
119 Int_t manuId = value->ID1();
121 const AliMpVSegmentation* seg =
122 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
124 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
126 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
127 if (!pad.IsValid()) continue;
129 for ( Int_t i = 0; i < dim; ++i )
131 Float_t x0 = value->ValueAsFloat(manuChannel,i);
133 xmin[i] = TMath::Min(xmin[i],x0);
134 xmax[i] = TMath::Max(xmax[i],x0);
139 for ( Int_t i = 0; i < dim; ++i )
141 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
149 //_____________________________________________________________________________
150 Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
153 if ( mustBePositive )
157 x = gRandom->Gaus(mean,sigma);
162 x = gRandom->Gaus(mean,sigma);
169 //_____________________________________________________________________________
170 Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
172 /// Check that OCDB path and run number are properly set
174 AliCDBManager* man = AliCDBManager::Instance();
177 if (!man->IsDefaultStorageSet()) {
178 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
182 // then run number if required
183 if (pathOnly) return kTRUE;
184 if (man->GetRun() < 0) {
185 AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
193 //_____________________________________________________________________________
194 Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
196 /// Check that the mapping has been loaded
198 // first the segmentation
199 if (!AliMpSegmentation::Instance(false)) {
200 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
204 // then the others if required
205 if (segmentationOnly) return kTRUE;
206 if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
207 AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
215 //_____________________________________________________________________________
216 Bool_t AliMUONCDB::LoadField()
218 /// Load magnetic field (existing field will be deleted).
219 /// OCDB path and run number are supposed to be set.
221 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
223 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
225 AliGRPManager grpMan;
227 // make sure the old field is deleted even if it is locked
228 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
230 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
231 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
239 //_____________________________________________________________________________
240 Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
242 /// Load mapping (existing mapping will be unloaded).
243 /// OCDB path and run number are supposed to be set.
245 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
247 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
249 // in case it has already been set
250 AliMpCDB::UnloadAll();
252 if (segmentationOnly) {
254 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
255 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
261 if (!AliMpCDB::LoadAll(kTRUE)) {
262 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
272 //_____________________________________________________________________________
273 AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
275 /// Load and return reconstruction parameters.
276 /// OCDB path is supposed to be set.
278 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
280 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
282 AliMUONRecoParam* recoParam = 0x0;
283 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
287 // load recoParam according OCDB content (single or array)
288 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
290 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
292 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
293 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
294 if (recoParam->IsDefault()) break;
302 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
308 //_____________________________________________________________________________
310 AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
313 /// creates a store which contains store1-store2
314 /// if opt="abs" the difference is absolute one,
315 /// if opt="rel" then what is stored is (store1-store2)/store1
316 /// if opt="percent" then what is stored is rel*100
318 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
323 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
325 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
329 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
331 TIter next(d->CreateIterator());
333 AliMUONVCalibParam* param;
335 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
337 Int_t detElemId = param->ID0();
338 Int_t manuId = param->ID1();
340 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
341 //FIXME: this might happen. Handle it.
344 cerr << "param2 is null : FIXME : this might happen !" << endl;
349 for ( Int_t i = 0; i < param->Size(); ++i )
351 for ( Int_t j = 0; j < param->Dimension(); ++j )
354 if ( sopt.Contains("ABS") )
356 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
358 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
360 if ( param->ValueAsFloat(i,j) )
362 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
368 if ( sopt.Contains("PERCENT") ) value *= 100.0;
370 param->SetValueAsFloat(i,j,value);
377 //_____________________________________________________________________________
379 AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
381 /// Make histograms of each dimension of the AliMUONVCalibParam
382 /// contained inside store.
383 /// It produces histograms named name_0, name_1, etc...
385 if (!AliMUONCDB::CheckMapping(kTRUE)) return;
387 TIter next(store.CreateIterator());
388 AliMUONVCalibParam* param;
390 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
391 Int_t* nPerStation = new Int_t[kNStations];
394 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
396 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
400 Int_t dim = param->Dimension();
402 Float_t* xmin = new Float_t[dim];
403 Float_t* xmax = new Float_t[dim];
404 getBoundaries(store,dim,xmin,xmax);
406 for ( Int_t i = 0; i < dim; ++i )
408 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
409 nbins,xmin[i],xmax[i]);
410 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
414 Int_t detElemId = param->ID0();
415 Int_t manuId = param->ID1();
416 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
418 const AliMpVSegmentation* seg =
419 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
421 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
423 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
424 if (!pad.IsValid()) continue;
427 ++nPerStation[station];
429 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
431 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
436 for ( Int_t i = 0; i < kNStations; ++i )
438 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
441 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
443 delete[] nPerStation;
446 //_____________________________________________________________________________
448 AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
450 /// Create a HV store
452 if (!AliMUONCDB::CheckMapping()) return 0;
454 AliMpDCSNamer hvNamer("TRACKER");
456 TObjArray* aliases = hvNamer.GenerateAliases();
461 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
463 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
464 TString& aliasName = alias->String();
465 if ( aliasName.Contains("sw") )
467 // HV Switch (St345 only)
468 TObjArray* valueSet = new TObjArray;
469 valueSet->SetOwner(kTRUE);
471 Bool_t value = kTRUE;
475 Float_t r = gRandom->Uniform();
476 if ( r < 0.007 ) value = kFALSE;
479 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
481 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
482 valueSet->Add(dcsValue);
484 aliasMap.Add(new TObjString(*alias),valueSet);
489 TObjArray* valueSet = new TObjArray;
490 valueSet->SetOwner(kTRUE);
491 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
493 Float_t value = 1500;
494 if (!defaultValues) value = GetRandom(1750,62.5,true);
495 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
496 valueSet->Add(dcsValue);
498 aliasMap.Add(new TObjString(*alias),valueSet);
505 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
507 return nChannels+nSwitch;
510 //_____________________________________________________________________________
512 AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
514 /// Create a Trigger HV and Currents store
516 if (!AliMUONCDB::CheckMapping()) return 0;
518 AliMpDCSNamer triggerDCSNamer("TRIGGER");
520 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
522 Int_t nChannels[2] = {0, 0};
524 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
526 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
527 TString& aliasName = alias->String();
529 TObjArray* valueSet = new TObjArray;
530 valueSet->SetOwner(kTRUE);
531 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
532 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
535 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
536 if (!defaultValues) {
537 switch (measureType){
538 case AliMpDCSNamer::kDCSI:
539 value = GetRandom(2.,0.4,true);
541 case AliMpDCSNamer::kDCSHV:
542 value = GetRandom(8000.,16.,true);
546 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
547 valueSet->Add(dcsValue);
549 aliasMap.Add(new TObjString(*alias),valueSet);
550 ++nChannels[measureType];
555 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
557 return nChannels[0] + nChannels[1];
560 //_____________________________________________________________________________
562 AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
564 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
565 /// otherwise mean and sigma are from a gaussian (with parameters
566 /// defined below by the kPedestal* constants)
568 AliCodeTimerAutoGeneral("",0);
570 if (!AliMUONCDB::CheckMapping()) return 0;
575 const Int_t kChannels(AliMpConstants::ManuNofChannels());
578 const Float_t kPedestalMeanMeanB(200.);
579 const Float_t kPedestalMeanSigmaB(10.);
580 const Float_t kPedestalSigmaMeanB(1.);
581 const Float_t kPedestalSigmaSigmaB(0.2);
584 const Float_t kPedestalMeanMeanNB(200.);
585 const Float_t kPedestalMeanSigmaNB(10.);
586 const Float_t kPedestalSigmaMeanNB(1.);
587 const Float_t kPedestalSigmaSigmaNB(0.2);
589 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
594 AliMpManuIterator it;
596 while ( it.Next(detElemId,manuId) )
598 // skip a given fraction of manus
599 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
603 AliMUONVCalibParam* ped =
604 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
606 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
608 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
610 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
614 Float_t meanPedestal;
615 Float_t sigmaPedestal;
624 Bool_t positive(kTRUE);
627 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
629 while ( meanPedestal == 0.0 ) // avoid strict zero
631 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
633 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
635 } else { // manu in bending plane
637 while ( meanPedestal == 0.0 ) // avoid strict zero
639 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
641 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
647 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
648 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
651 Bool_t ok = pedestalStore.Add(ped);
654 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
658 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
662 //_____________________________________________________________________________
664 AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
666 /// Create a reject list
668 AliCodeTimerAutoGeneral("",0);
670 AliMUONRejectList* rl = new AliMUONRejectList;
674 rl->SetDetectionElementProbability(510);
675 rl->SetDetectionElementProbability(508);
682 //_____________________________________________________________________________
684 AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
686 /// Create an occupancy map.
688 AliCodeTimerAutoGeneral("",0);
690 if (!AliMUONCDB::CheckMapping()) return 0;
697 AliMpManuIterator it;
701 while ( it.Next(detElemId,manuId) )
705 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
709 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
711 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
713 if (!defaultValues) occ = gRandom->Rndm(1);
715 Double_t sumn = occ*nevents;
717 occupancy->SetValueAsFloat(0,0,sumn);
718 occupancy->SetValueAsFloat(0,1,sumn);
719 occupancy->SetValueAsFloat(0,2,sumn);
720 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
721 occupancy->SetValueAsInt(0,4,nevents);
723 Bool_t ok = occupancyMapStore.Add(occupancy);
726 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
733 //_____________________________________________________________________________
735 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
737 /// Read the capacitance values from file and append them to the capaStore
739 if (!AliMUONCDB::CheckMapping()) return 0;
741 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
744 //_____________________________________________________________________________
746 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
748 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
749 /// otherwise they are from a gaussian with parameters defined in the
750 /// kCapa* constants below.
752 AliCodeTimerAutoGeneral("",0);
754 if (!AliMUONCDB::CheckMapping()) return 0;
758 Int_t nmanusOK(0); // manus for which we got the serial number
760 const Float_t kCapaMean(0.3);
761 const Float_t kCapaSigma(0.1);
762 const Float_t kInjectionGainMean(3);
763 const Float_t kInjectionGainSigma(1);
768 AliMpManuIterator it;
770 while ( it.Next(detElemId,manuId) )
774 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
775 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
777 if ( serialNumber <= 0 ) continue;
781 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
785 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
786 Bool_t ok = capaStore.Add(capa);
789 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
793 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
795 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
800 Float_t injectionGain;
809 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
810 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
812 capa->SetValueAsFloat(manuChannel,0,capaValue);
813 capa->SetValueAsFloat(manuChannel,1,injectionGain);
818 if ( nmanus ) percent = 100*nmanusOK/nmanus;
819 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
820 nmanusOK,nmanus,percent));
821 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
824 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
830 //_____________________________________________________________________________
832 AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
834 /// Create a gain store. if defaultValues=true, all gains set so that
835 /// charge = (adc-ped)
837 /// otherwise parameters are taken from gaussians with parameters
838 /// defined in the k* constants below.
840 AliCodeTimerAutoGeneral("",0);
842 if (!AliMUONCDB::CheckMapping()) return 0;
847 const Int_t kSaturation(3000);
848 const Double_t kA0Mean(1.2);
849 const Double_t kA0Sigma(0.1);
850 const Double_t kA1Mean(1E-5);
851 const Double_t kA1Sigma(1E-6);
852 const Double_t kQualMean(0xFF);
853 const Double_t kQualSigma(0x10);
854 const Int_t kThresMean(1600);
855 const Int_t kThresSigma(100);
860 AliMpManuIterator it;
862 while ( it.Next(detElemId,manuId) )
866 AliMUONVCalibParam* gain =
867 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
870 AliMUONVCalibParam::InvalidFloatValue());
872 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
874 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
876 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
882 gain->SetValueAsFloat(manuChannel,0,1.0);
883 gain->SetValueAsFloat(manuChannel,1,0.0);
884 gain->SetValueAsInt(manuChannel,2,4095);
885 gain->SetValueAsInt(manuChannel,3,1);
886 gain->SetValueAsInt(manuChannel,4,kSaturation);
890 Bool_t positive(kTRUE);
891 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
892 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
893 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
894 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
895 gain->SetValueAsInt(manuChannel,4,kSaturation);
899 Bool_t ok = gainStore.Add(gain);
902 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
906 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
910 //_____________________________________________________________________________
912 AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
914 /// Generate local trigger masks store. All masks are set to FFFF
916 AliCodeTimerAutoGeneral("",0);
919 // Generate fake mask values for all localboards and put that into
920 // one single container (localBoardMasks)
921 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
923 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
924 for ( Int_t x = 0; x < 2; ++x )
926 for ( Int_t y = 0; y < 4; ++y )
929 localBoard->SetValueAsInt(index,0,0xFFFF);
933 localBoardMasks.Add(localBoard);
938 //_____________________________________________________________________________
940 AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
942 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
944 AliCodeTimerAutoGeneral("",0);
946 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
947 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
951 return rtm.GetNofTriggerCrates();
955 //_____________________________________________________________________________
957 AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
959 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
961 AliCodeTimerAutoGeneral("",0);
963 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
967 //_____________________________________________________________________________
969 AliMUONCDB::MakeTriggerLUT(const char* file)
971 /// Make a triggerlut object, from a file.
973 AliCodeTimerAutoGeneral("",0);
975 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
976 lut->ReadFromFile(file);
980 //_____________________________________________________________________________
981 AliMUONTriggerEfficiencyCells*
982 AliMUONCDB::MakeTriggerEfficiency(const char* file)
984 /// Make a trigger efficiency object from a file.
986 AliCodeTimerAutoGeneral("",0);
988 return new AliMUONTriggerEfficiencyCells(file);
991 //_____________________________________________________________________________
993 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
994 Int_t startRun, Int_t endRun,
995 const char* filename)
997 /// Write a given object to OCDB
999 TString comment(gSystem->ExpandPathName(filename));
1001 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1004 //_____________________________________________________________________________
1006 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1007 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1009 /// Write a given object to OCDB
1012 if ( defaultValues ) comment += "Test with default values";
1013 else comment += "Test with random values";
1015 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1018 //_____________________________________________________________________________
1020 AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1021 const char* comment, const char* responsible)
1023 /// Write a given object to OCDB
1025 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1027 AliCDBId id(calibpath,startRun,endRun);
1029 md.SetAliRootVersion(gROOT->GetVersion());
1030 md.SetComment(comment);
1031 md.SetResponsible(responsible);
1032 AliCDBManager::Instance()->Put(object,id,&md);
1035 //_____________________________________________________________________________
1037 AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
1039 /// Fill the neighbours store with, for each channel, a TObjArray of its
1040 /// neighbouring pads (including itself)
1042 AliCodeTimerAutoGeneral("",0);
1044 if (!AliMUONCDB::CheckMapping()) return 0;
1046 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
1055 AliMpManuIterator it;
1057 while ( it.Next(detElemId,manuId) )
1059 const AliMpVSegmentation* seg =
1060 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1062 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
1065 Int_t dimension(11);
1066 Int_t size(AliMpConstants::ManuNofChannels());
1067 Int_t defaultValue(-1);
1068 Int_t packingFactor(size);
1070 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1071 Bool_t ok = neighbourStore.Add(calibParam);
1074 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
1079 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
1081 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
1087 seg->GetNeighbours(pad,tmp,true,true);
1088 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1090 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1092 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
1095 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
1098 // AliError("Could not pack value. Something is seriously wrong. Please check");
1099 // StdoutToAliError(pad->Print(););
1102 calibParam->SetValueAsInt(manuChannel,i,x);
1111 //_____________________________________________________________________________
1113 AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1115 /// Write local trigger masks to OCDB
1117 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
1118 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
1119 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1122 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1127 //_____________________________________________________________________________
1129 AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
1131 /// Write regional trigger masks to OCDB
1133 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1134 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
1135 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1138 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
1144 //_____________________________________________________________________________
1146 AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
1148 /// Write global trigger masks to OCDB
1150 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
1152 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
1153 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1156 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
1162 //_____________________________________________________________________________
1164 AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1166 /// Write trigger LUT to OCDB
1168 AliMUONTriggerLut* lut = MakeTriggerLUT();
1171 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1176 //_____________________________________________________________________________
1178 AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1180 /// Write trigger efficiency to OCDB
1182 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1185 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1190 //_____________________________________________________________________________
1192 AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1194 /// Write neighbours to OCDB
1196 AliMUONVStore* neighbours = Create2DMap();
1197 Int_t ngenerated = MakeNeighbourStore(*neighbours);
1198 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1201 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1206 //_____________________________________________________________________________
1208 AliMUONCDB::WriteHV(Bool_t defaultValues,
1209 Int_t startRun, Int_t endRun)
1211 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
1212 /// if defaultValues=false, see makeHVStore) and
1213 /// store them into CDB located at cdbpath, with a validity period
1214 /// ranging from startRun to endRun
1216 TMap* hvStore = new TMap;
1217 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
1218 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1221 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1226 //_____________________________________________________________________________
1228 AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1229 Int_t startRun, Int_t endRun)
1231 /// generate Trigger HV and current values (either const if defaultValues=true or random
1232 /// if defaultValues=false, see makeTriggerDCSStore) and
1233 /// store them into CDB located at cdbpath, with a validity period
1234 /// ranging from startRun to endRun
1236 TMap* triggerDCSStore = new TMap;
1237 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
1238 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1241 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1243 delete triggerDCSStore;
1246 //_____________________________________________________________________________
1248 AliMUONCDB::WritePedestals(Bool_t defaultValues,
1249 Int_t startRun, Int_t endRun)
1251 /// generate pedestal values (either 0 if defaultValues=true or random
1252 /// if defaultValues=false, see makePedestalStore) and
1253 /// store them into CDB located at cdbpath, with a validity period
1254 /// ranging from startRun to endRun
1256 AliMUONVStore* pedestalStore = Create2DMap();
1257 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
1258 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1259 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1260 delete pedestalStore;
1263 //_____________________________________________________________________________
1265 AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1266 Int_t startRun, Int_t endRun)
1268 /// generate occupancy map values (either empty one if defaultValues=true, or
1269 /// random one, see MakeOccupancyMapStore) and
1270 /// store them into CDB located at cdbpath, with a validity period
1271 /// ranging from startRun to endRun
1273 AliMUONVStore* occupancyMapStore = Create2DMap();
1274 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
1275 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1276 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1277 delete occupancyMapStore;
1280 //_____________________________________________________________________________
1282 AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1283 Int_t startRun, Int_t endRun)
1285 /// generate reject list values (either empty one if defaultValues=true, or
1286 /// random one, see MakeRejectListStore) and
1287 /// store them into CDB located at cdbpath, with a validity period
1288 /// ranging from startRun to endRun
1290 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1291 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1296 //_____________________________________________________________________________
1298 AliMUONCDB::WriteGains(Bool_t defaultValues,
1299 Int_t startRun, Int_t endRun)
1301 /// generate gain values (either 1 if defaultValues=true or random
1302 /// if defaultValues=false, see makeGainStore) and
1303 /// store them into CDB located at cdbpath, with a validity period
1304 /// ranging from startRun to endRun
1306 AliMUONVStore* gainStore = Create2DMap();
1307 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
1308 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1309 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1313 //_____________________________________________________________________________
1315 AliMUONCDB::WriteCapacitances(const char* filename,
1316 Int_t startRun, Int_t endRun)
1318 /// read manu capacitance and injection gain values from file
1319 /// and store them into CDB located at cdbpath, with a validity period
1320 /// ranging from startRun to endRun
1322 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1323 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
1324 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1325 if ( ngenerated > 0 )
1327 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1332 //_____________________________________________________________________________
1334 AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1335 Int_t startRun, Int_t endRun)
1337 /// generate manu capacitance values (either 1 if defaultValues=true or random
1338 /// if defaultValues=false, see makeCapacitanceStore) and
1339 /// store them into CDB located at cdbpath, with a validity period
1340 /// ranging from startRun to endRun
1342 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1343 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
1344 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1345 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1349 //_____________________________________________________________________________
1351 AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1353 /// Writes all Trigger related calibration to CDB
1354 WriteTriggerDCS(defaultValues,startRun,endRun);
1355 WriteLocalTriggerMasks(startRun,endRun);
1356 WriteRegionalTriggerConfig(startRun,endRun);
1357 WriteGlobalTriggerConfig(startRun,endRun);
1358 WriteTriggerLut(startRun,endRun);
1359 WriteTriggerEfficiency(startRun,endRun);
1362 //_____________________________________________________________________________
1364 AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1366 /// Writes all Tracker related calibration to CDB
1367 WriteHV(defaultValues,startRun,endRun);
1368 WritePedestals(defaultValues,startRun,endRun);
1369 WriteGains(defaultValues,startRun,endRun);
1370 WriteCapacitances(defaultValues,startRun,endRun);
1371 WriteNeighbours(startRun,endRun);
1372 WriteOccupancyMap(defaultValues,startRun,endRun);
1373 WriteRejectList(defaultValues,startRun,endRun);