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>
89 #include <TClonesArray.h>
94 //_____________________________________________________________________________
95 AliMUONVStore* Create2DMap()
97 return new AliMUON2DMap(true);
100 //_____________________________________________________________________________
101 void getBoundaries(const AliMUONVStore& store, Int_t dim,
102 Float_t* xmin, Float_t* xmax)
104 /// Assuming the store contains AliMUONVCalibParam objects, compute the
105 /// limits of the value contained in the VCalibParam, for each of its dimensions
106 /// xmin and xmax must be of dimension dim
108 for ( Int_t i = 0; i < dim; ++i )
114 TIter next(store.CreateIterator());
115 AliMUONVCalibParam* value;
117 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
119 Int_t detElemId = value->ID0();
120 Int_t manuId = value->ID1();
122 const AliMpVSegmentation* seg =
123 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
125 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
127 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
128 if (!pad.IsValid()) continue;
130 for ( Int_t i = 0; i < dim; ++i )
132 Float_t x0 = value->ValueAsFloat(manuChannel,i);
134 xmin[i] = TMath::Min(xmin[i],x0);
135 xmax[i] = TMath::Max(xmax[i],x0);
140 for ( Int_t i = 0; i < dim; ++i )
142 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
150 //_____________________________________________________________________________
151 Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
154 if ( mustBePositive )
158 x = gRandom->Gaus(mean,sigma);
163 x = gRandom->Gaus(mean,sigma);
170 //_____________________________________________________________________________
171 Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
173 /// Check that OCDB path and run number are properly set
175 AliCDBManager* man = AliCDBManager::Instance();
178 if (!man->IsDefaultStorageSet()) {
179 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
183 // then run number if required
184 if (pathOnly) return kTRUE;
185 if (man->GetRun() < 0) {
186 AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
194 //_____________________________________________________________________________
195 Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
197 /// Check that the mapping has been loaded
199 // first the segmentation
200 if (!AliMpSegmentation::Instance(false)) {
201 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
205 // then the others if required
206 if (segmentationOnly) return kTRUE;
207 if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
208 AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
216 //_____________________________________________________________________________
217 Bool_t AliMUONCDB::LoadField()
219 /// Load magnetic field (existing field will be deleted).
220 /// OCDB path and run number are supposed to be set.
222 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
224 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
226 AliGRPManager grpMan;
228 // make sure the old field is deleted even if it is locked
229 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
231 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
232 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
240 //_____________________________________________________________________________
241 Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
243 /// Load mapping (existing mapping will be unloaded).
244 /// OCDB path and run number are supposed to be set.
246 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
248 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
250 // in case it has already been set
251 AliMpCDB::UnloadAll();
253 if (segmentationOnly) {
255 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
256 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
262 if (!AliMpCDB::LoadAll(kTRUE)) {
263 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
273 //_____________________________________________________________________________
274 AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
276 /// Load and return reconstruction parameters.
277 /// OCDB path is supposed to be set.
279 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
281 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
283 AliMUONRecoParam* recoParam = 0x0;
284 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
288 // load recoParam according OCDB content (single or array)
289 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
291 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
293 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
294 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
295 if (recoParam->IsDefault()) break;
303 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
309 //_____________________________________________________________________________
310 TClonesArray* AliMUONCDB::LoadAlignmentData()
312 /// Load and return the array of alignment objects.
314 AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
316 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
318 TClonesArray* alignmentArray = 0x0;
319 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
322 // load alignement array
323 alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
326 if (!alignmentArray) {
327 AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
330 return alignmentArray;
333 //_____________________________________________________________________________
335 AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
338 /// creates a store which contains store1-store2
339 /// if opt="abs" the difference is absolute one,
340 /// if opt="rel" then what is stored is (store1-store2)/store1
341 /// if opt="percent" then what is stored is rel*100
343 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
348 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
350 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
354 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
356 TIter next(d->CreateIterator());
358 AliMUONVCalibParam* param;
360 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
362 Int_t detElemId = param->ID0();
363 Int_t manuId = param->ID1();
365 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
366 //FIXME: this might happen. Handle it.
369 cerr << "param2 is null : FIXME : this might happen !" << endl;
374 for ( Int_t i = 0; i < param->Size(); ++i )
376 for ( Int_t j = 0; j < param->Dimension(); ++j )
379 if ( sopt.Contains("ABS") )
381 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
383 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
385 if ( param->ValueAsFloat(i,j) )
387 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
393 if ( sopt.Contains("PERCENT") ) value *= 100.0;
395 param->SetValueAsFloat(i,j,value);
402 //_____________________________________________________________________________
404 AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
406 /// Make histograms of each dimension of the AliMUONVCalibParam
407 /// contained inside store.
408 /// It produces histograms named name_0, name_1, etc...
410 if (!AliMUONCDB::CheckMapping(kTRUE)) return;
412 TIter next(store.CreateIterator());
413 AliMUONVCalibParam* param;
415 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
416 Int_t* nPerStation = new Int_t[kNStations];
419 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
421 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
425 Int_t dim = param->Dimension();
427 Float_t* xmin = new Float_t[dim];
428 Float_t* xmax = new Float_t[dim];
429 getBoundaries(store,dim,xmin,xmax);
431 for ( Int_t i = 0; i < dim; ++i )
433 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
434 nbins,xmin[i],xmax[i]);
435 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
439 Int_t detElemId = param->ID0();
440 Int_t manuId = param->ID1();
441 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
443 const AliMpVSegmentation* seg =
444 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
446 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
448 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
449 if (!pad.IsValid()) continue;
452 ++nPerStation[station];
454 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
456 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
461 for ( Int_t i = 0; i < kNStations; ++i )
463 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
466 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
468 delete[] nPerStation;
471 //_____________________________________________________________________________
473 AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
475 /// Create a HV store
477 if (!AliMUONCDB::CheckMapping()) return 0;
479 AliMpDCSNamer hvNamer("TRACKER");
481 TObjArray* aliases = hvNamer.GenerateAliases();
486 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
488 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
489 TString& aliasName = alias->String();
490 if ( aliasName.Contains("sw") )
492 // HV Switch (St345 only)
493 TObjArray* valueSet = new TObjArray;
494 valueSet->SetOwner(kTRUE);
496 Bool_t value = kTRUE;
500 Float_t r = gRandom->Uniform();
501 if ( r < 0.007 ) value = kFALSE;
504 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
506 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
507 valueSet->Add(dcsValue);
509 aliasMap.Add(new TObjString(*alias),valueSet);
514 TObjArray* valueSet = new TObjArray;
515 valueSet->SetOwner(kTRUE);
516 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
518 Float_t value = 1500;
519 if (!defaultValues) value = GetRandom(1750,62.5,true);
520 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
521 valueSet->Add(dcsValue);
523 aliasMap.Add(new TObjString(*alias),valueSet);
530 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
532 return nChannels+nSwitch;
535 //_____________________________________________________________________________
537 AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
539 /// Create a Trigger HV and Currents store
541 if (!AliMUONCDB::CheckMapping()) return 0;
543 AliMpDCSNamer triggerDCSNamer("TRIGGER");
545 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
547 Int_t nChannels[2] = {0, 0};
549 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
551 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
552 TString& aliasName = alias->String();
554 TObjArray* valueSet = new TObjArray;
555 valueSet->SetOwner(kTRUE);
556 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
557 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
560 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
561 if (!defaultValues) {
562 switch (measureType){
563 case AliMpDCSNamer::kDCSI:
564 value = GetRandom(2.,0.4,true);
566 case AliMpDCSNamer::kDCSHV:
567 value = GetRandom(8000.,16.,true);
571 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
572 valueSet->Add(dcsValue);
574 aliasMap.Add(new TObjString(*alias),valueSet);
575 ++nChannels[measureType];
580 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
582 return nChannels[0] + nChannels[1];
585 //_____________________________________________________________________________
587 AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
589 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
590 /// otherwise mean and sigma are from a gaussian (with parameters
591 /// defined below by the kPedestal* constants)
593 AliCodeTimerAutoGeneral("",0);
595 if (!AliMUONCDB::CheckMapping()) return 0;
600 const Int_t kChannels(AliMpConstants::ManuNofChannels());
603 const Float_t kPedestalMeanMeanB(200.);
604 const Float_t kPedestalMeanSigmaB(10.);
605 const Float_t kPedestalSigmaMeanB(1.);
606 const Float_t kPedestalSigmaSigmaB(0.2);
609 const Float_t kPedestalMeanMeanNB(200.);
610 const Float_t kPedestalMeanSigmaNB(10.);
611 const Float_t kPedestalSigmaMeanNB(1.);
612 const Float_t kPedestalSigmaSigmaNB(0.2);
614 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
619 AliMpManuIterator it;
621 while ( it.Next(detElemId,manuId) )
623 // skip a given fraction of manus
624 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
628 AliMUONVCalibParam* ped =
629 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
631 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
633 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
635 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
639 Float_t meanPedestal;
640 Float_t sigmaPedestal;
649 Bool_t positive(kTRUE);
652 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
654 while ( meanPedestal == 0.0 ) // avoid strict zero
656 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
658 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
660 } else { // manu in bending plane
662 while ( meanPedestal == 0.0 ) // avoid strict zero
664 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
666 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
672 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
673 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
676 Bool_t ok = pedestalStore.Add(ped);
679 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
683 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
687 //_____________________________________________________________________________
689 AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
691 /// Create a reject list
693 AliCodeTimerAutoGeneral("",0);
695 AliMUONRejectList* rl = new AliMUONRejectList;
699 rl->SetDetectionElementProbability(510);
700 rl->SetDetectionElementProbability(508);
707 //_____________________________________________________________________________
709 AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
711 /// Create an occupancy map.
713 AliCodeTimerAutoGeneral("",0);
715 if (!AliMUONCDB::CheckMapping()) return 0;
722 AliMpManuIterator it;
726 while ( it.Next(detElemId,manuId) )
730 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
734 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
736 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
738 if (!defaultValues) occ = gRandom->Rndm(1);
740 Double_t sumn = occ*nevents;
742 occupancy->SetValueAsFloat(0,0,sumn);
743 occupancy->SetValueAsFloat(0,1,sumn);
744 occupancy->SetValueAsFloat(0,2,sumn);
745 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
746 occupancy->SetValueAsInt(0,4,nevents);
748 Bool_t ok = occupancyMapStore.Add(occupancy);
751 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
758 //_____________________________________________________________________________
760 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
762 /// Read the capacitance values from file and append them to the capaStore
764 if (!AliMUONCDB::CheckMapping()) return 0;
766 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
769 //_____________________________________________________________________________
771 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
773 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
774 /// otherwise they are from a gaussian with parameters defined in the
775 /// kCapa* constants below.
777 AliCodeTimerAutoGeneral("",0);
779 if (!AliMUONCDB::CheckMapping()) return 0;
783 Int_t nmanusOK(0); // manus for which we got the serial number
785 const Float_t kCapaMean(0.3);
786 const Float_t kCapaSigma(0.1);
787 const Float_t kInjectionGainMean(3);
788 const Float_t kInjectionGainSigma(1);
793 AliMpManuIterator it;
795 while ( it.Next(detElemId,manuId) )
799 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
800 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
802 if ( serialNumber <= 0 ) continue;
806 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
810 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
811 Bool_t ok = capaStore.Add(capa);
814 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
818 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
820 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
825 Float_t injectionGain;
834 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
835 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
837 capa->SetValueAsFloat(manuChannel,0,capaValue);
838 capa->SetValueAsFloat(manuChannel,1,injectionGain);
843 if ( nmanus ) percent = 100*nmanusOK/nmanus;
844 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
845 nmanusOK,nmanus,percent));
846 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
849 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
855 //_____________________________________________________________________________
857 AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
859 /// Create a gain store. if defaultValues=true, all gains set so that
860 /// charge = (adc-ped)
862 /// otherwise parameters are taken from gaussians with parameters
863 /// defined in the k* constants below.
865 AliCodeTimerAutoGeneral("",0);
867 if (!AliMUONCDB::CheckMapping()) return 0;
872 const Int_t kSaturation(3000);
873 const Double_t kA0Mean(1.2);
874 const Double_t kA0Sigma(0.1);
875 const Double_t kA1Mean(1E-5);
876 const Double_t kA1Sigma(1E-6);
877 const Double_t kQualMean(0xFF);
878 const Double_t kQualSigma(0x10);
879 const Int_t kThresMean(1600);
880 const Int_t kThresSigma(100);
885 AliMpManuIterator it;
887 while ( it.Next(detElemId,manuId) )
891 AliMUONVCalibParam* gain =
892 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
895 AliMUONVCalibParam::InvalidFloatValue());
897 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
899 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
901 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
907 gain->SetValueAsFloat(manuChannel,0,1.0);
908 gain->SetValueAsFloat(manuChannel,1,0.0);
909 gain->SetValueAsInt(manuChannel,2,4095);
910 gain->SetValueAsInt(manuChannel,3,1);
911 gain->SetValueAsInt(manuChannel,4,kSaturation);
915 Bool_t positive(kTRUE);
916 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
917 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
918 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
919 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
920 gain->SetValueAsInt(manuChannel,4,kSaturation);
924 Bool_t ok = gainStore.Add(gain);
927 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
931 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
935 //_____________________________________________________________________________
937 AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
939 /// Generate local trigger masks store. All masks are set to FFFF
941 AliCodeTimerAutoGeneral("",0);
944 // Generate fake mask values for all localboards and put that into
945 // one single container (localBoardMasks)
946 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
948 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
949 for ( Int_t x = 0; x < 2; ++x )
951 for ( Int_t y = 0; y < 4; ++y )
954 localBoard->SetValueAsInt(index,0,0xFFFF);
958 localBoardMasks.Add(localBoard);
963 //_____________________________________________________________________________
965 AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
967 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
969 AliCodeTimerAutoGeneral("",0);
971 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
972 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
976 return rtm.GetNofTriggerCrates();
980 //_____________________________________________________________________________
982 AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
984 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
986 AliCodeTimerAutoGeneral("",0);
988 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
992 //_____________________________________________________________________________
994 AliMUONCDB::MakeTriggerLUT(const char* file)
996 /// Make a triggerlut object, from a file.
998 AliCodeTimerAutoGeneral("",0);
1000 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1001 lut->ReadFromFile(file);
1005 //_____________________________________________________________________________
1006 AliMUONTriggerEfficiencyCells*
1007 AliMUONCDB::MakeTriggerEfficiency(const char* file)
1009 /// Make a trigger efficiency object from a file.
1011 AliCodeTimerAutoGeneral("",0);
1013 return new AliMUONTriggerEfficiencyCells(file);
1016 //_____________________________________________________________________________
1018 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1019 Int_t startRun, Int_t endRun,
1020 const char* filename)
1022 /// Write a given object to OCDB
1024 TString comment(gSystem->ExpandPathName(filename));
1026 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1029 //_____________________________________________________________________________
1031 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1032 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1034 /// Write a given object to OCDB
1037 if ( defaultValues ) comment += "Test with default values";
1038 else comment += "Test with random values";
1040 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1043 //_____________________________________________________________________________
1045 AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1046 const char* comment, const char* responsible)
1048 /// Write a given object to OCDB
1050 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1052 AliCDBId id(calibpath,startRun,endRun);
1054 md.SetAliRootVersion(gROOT->GetVersion());
1055 md.SetComment(comment);
1056 md.SetResponsible(responsible);
1057 AliCDBManager::Instance()->Put(object,id,&md);
1060 //_____________________________________________________________________________
1062 AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
1064 /// Fill the neighbours store with, for each channel, a TObjArray of its
1065 /// neighbouring pads (including itself)
1067 AliCodeTimerAutoGeneral("",0);
1069 if (!AliMUONCDB::CheckMapping()) return 0;
1071 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
1080 AliMpManuIterator it;
1082 while ( it.Next(detElemId,manuId) )
1084 const AliMpVSegmentation* seg =
1085 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1087 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
1090 Int_t dimension(11);
1091 Int_t size(AliMpConstants::ManuNofChannels());
1092 Int_t defaultValue(-1);
1093 Int_t packingFactor(size);
1095 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1096 Bool_t ok = neighbourStore.Add(calibParam);
1099 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
1104 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
1106 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
1112 seg->GetNeighbours(pad,tmp,true,true);
1113 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1115 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1117 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
1120 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
1123 // AliError("Could not pack value. Something is seriously wrong. Please check");
1124 // StdoutToAliError(pad->Print(););
1127 calibParam->SetValueAsInt(manuChannel,i,x);
1136 //_____________________________________________________________________________
1138 AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1140 /// Write local trigger masks to OCDB
1142 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
1143 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
1144 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1147 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1152 //_____________________________________________________________________________
1154 AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
1156 /// Write regional trigger masks to OCDB
1158 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1159 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
1160 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1163 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
1169 //_____________________________________________________________________________
1171 AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
1173 /// Write global trigger masks to OCDB
1175 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
1177 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
1178 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1181 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
1187 //_____________________________________________________________________________
1189 AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1191 /// Write trigger LUT to OCDB
1193 AliMUONTriggerLut* lut = MakeTriggerLUT();
1196 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1201 //_____________________________________________________________________________
1203 AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1205 /// Write trigger efficiency to OCDB
1207 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1210 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1215 //_____________________________________________________________________________
1217 AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1219 /// Write neighbours to OCDB
1221 AliMUONVStore* neighbours = Create2DMap();
1222 Int_t ngenerated = MakeNeighbourStore(*neighbours);
1223 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1226 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1231 //_____________________________________________________________________________
1233 AliMUONCDB::WriteHV(Bool_t defaultValues,
1234 Int_t startRun, Int_t endRun)
1236 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
1237 /// if defaultValues=false, see makeHVStore) and
1238 /// store them into CDB located at cdbpath, with a validity period
1239 /// ranging from startRun to endRun
1241 TMap* hvStore = new TMap;
1242 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
1243 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1246 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1251 //_____________________________________________________________________________
1253 AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1254 Int_t startRun, Int_t endRun)
1256 /// generate Trigger HV and current values (either const if defaultValues=true or random
1257 /// if defaultValues=false, see makeTriggerDCSStore) and
1258 /// store them into CDB located at cdbpath, with a validity period
1259 /// ranging from startRun to endRun
1261 TMap* triggerDCSStore = new TMap;
1262 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
1263 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1266 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1268 delete triggerDCSStore;
1271 //_____________________________________________________________________________
1273 AliMUONCDB::WritePedestals(Bool_t defaultValues,
1274 Int_t startRun, Int_t endRun)
1276 /// generate pedestal values (either 0 if defaultValues=true or random
1277 /// if defaultValues=false, see makePedestalStore) and
1278 /// store them into CDB located at cdbpath, with a validity period
1279 /// ranging from startRun to endRun
1281 AliMUONVStore* pedestalStore = Create2DMap();
1282 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
1283 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1284 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1285 delete pedestalStore;
1288 //_____________________________________________________________________________
1290 AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1291 Int_t startRun, Int_t endRun)
1293 /// generate occupancy map values (either empty one if defaultValues=true, or
1294 /// random one, see MakeOccupancyMapStore) and
1295 /// store them into CDB located at cdbpath, with a validity period
1296 /// ranging from startRun to endRun
1298 AliMUONVStore* occupancyMapStore = Create2DMap();
1299 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
1300 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1301 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1302 delete occupancyMapStore;
1305 //_____________________________________________________________________________
1307 AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1308 Int_t startRun, Int_t endRun)
1310 /// generate reject list values (either empty one if defaultValues=true, or
1311 /// random one, see MakeRejectListStore) and
1312 /// store them into CDB located at cdbpath, with a validity period
1313 /// ranging from startRun to endRun
1315 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1316 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1321 //_____________________________________________________________________________
1323 AliMUONCDB::WriteGains(Bool_t defaultValues,
1324 Int_t startRun, Int_t endRun)
1326 /// generate gain values (either 1 if defaultValues=true or random
1327 /// if defaultValues=false, see makeGainStore) and
1328 /// store them into CDB located at cdbpath, with a validity period
1329 /// ranging from startRun to endRun
1331 AliMUONVStore* gainStore = Create2DMap();
1332 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
1333 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1334 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1338 //_____________________________________________________________________________
1340 AliMUONCDB::WriteCapacitances(const char* filename,
1341 Int_t startRun, Int_t endRun)
1343 /// read manu capacitance and injection gain values from file
1344 /// and store them into CDB located at cdbpath, with a validity period
1345 /// ranging from startRun to endRun
1347 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1348 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
1349 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1350 if ( ngenerated > 0 )
1352 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1357 //_____________________________________________________________________________
1359 AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1360 Int_t startRun, Int_t endRun)
1362 /// generate manu capacitance values (either 1 if defaultValues=true or random
1363 /// if defaultValues=false, see makeCapacitanceStore) and
1364 /// store them into CDB located at cdbpath, with a validity period
1365 /// ranging from startRun to endRun
1367 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1368 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
1369 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1370 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1374 //_____________________________________________________________________________
1376 AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1378 /// Writes all Trigger related calibration to CDB
1379 WriteTriggerDCS(defaultValues,startRun,endRun);
1380 WriteLocalTriggerMasks(startRun,endRun);
1381 WriteRegionalTriggerConfig(startRun,endRun);
1382 WriteGlobalTriggerConfig(startRun,endRun);
1383 WriteTriggerLut(startRun,endRun);
1384 WriteTriggerEfficiency(startRun,endRun);
1387 //_____________________________________________________________________________
1389 AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1391 /// Writes all Tracker related calibration to CDB
1392 WriteHV(defaultValues,startRun,endRun);
1393 WritePedestals(defaultValues,startRun,endRun);
1394 WriteGains(defaultValues,startRun,endRun);
1395 WriteCapacitances(defaultValues,startRun,endRun);
1396 WriteNeighbours(startRun,endRun);
1397 WriteOccupancyMap(defaultValues,startRun,endRun);
1398 WriteRejectList(defaultValues,startRun,endRun);