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"
75 #include "AliMpBusPatch.h"
77 #include <Riostream.h>
83 #include <TObjString.h>
86 #include <TStopwatch.h>
89 #include <TGeoGlobalMagField.h>
90 #include <TClonesArray.h>
95 //_____________________________________________________________________________
96 AliMUONVStore* Create2DMap()
98 return new AliMUON2DMap(true);
101 //_____________________________________________________________________________
102 void getBoundaries(const AliMUONVStore& store, Int_t dim,
103 Float_t* xmin, Float_t* xmax)
105 /// Assuming the store contains AliMUONVCalibParam objects, compute the
106 /// limits of the value contained in the VCalibParam, for each of its dimensions
107 /// xmin and xmax must be of dimension dim
109 for ( Int_t i = 0; i < dim; ++i )
115 TIter next(store.CreateIterator());
116 AliMUONVCalibParam* value;
118 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
120 Int_t detElemId = value->ID0();
121 Int_t manuId = value->ID1();
123 const AliMpVSegmentation* seg =
124 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
126 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
128 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
129 if (!pad.IsValid()) continue;
131 for ( Int_t i = 0; i < dim; ++i )
133 Float_t x0 = value->ValueAsFloat(manuChannel,i);
135 xmin[i] = TMath::Min(xmin[i],x0);
136 xmax[i] = TMath::Max(xmax[i],x0);
141 for ( Int_t i = 0; i < dim; ++i )
143 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
151 //_____________________________________________________________________________
152 Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
155 if ( mustBePositive )
159 x = gRandom->Gaus(mean,sigma);
164 x = gRandom->Gaus(mean,sigma);
171 //_____________________________________________________________________________
172 Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
174 /// Check that OCDB path and run number are properly set
176 AliCDBManager* man = AliCDBManager::Instance();
179 if (!man->IsDefaultStorageSet()) {
180 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
184 // then run number if required
185 if (pathOnly) return kTRUE;
186 if (man->GetRun() < 0) {
187 AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
195 //_____________________________________________________________________________
196 Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
198 /// Check that the mapping has been loaded
200 // first the segmentation
201 if (!AliMpSegmentation::Instance(false)) {
202 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
206 // then the others if required
207 if (segmentationOnly) return kTRUE;
208 if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
209 AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
217 //_____________________________________________________________________________
218 Bool_t AliMUONCDB::LoadField()
220 /// Load magnetic field (existing field will be deleted).
221 /// OCDB path and run number are supposed to be set.
223 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
225 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
227 AliGRPManager grpMan;
229 // make sure the old field is deleted even if it is locked
230 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
232 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
233 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
241 //_____________________________________________________________________________
242 Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
244 /// Load mapping (existing mapping will be unloaded).
245 /// OCDB path and run number are supposed to be set.
247 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
249 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
251 // in case it has already been set
252 AliMpCDB::UnloadAll();
254 if (segmentationOnly) {
256 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
257 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
263 if (!AliMpCDB::LoadAll(kTRUE)) {
264 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
274 //_____________________________________________________________________________
275 AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
277 /// Load and return reconstruction parameters.
278 /// OCDB path is supposed to be set.
280 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
282 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
284 AliMUONRecoParam* recoParam = 0x0;
285 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
289 // load recoParam according OCDB content (single or array)
290 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
292 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
294 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
295 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
296 if (recoParam->IsDefault()) break;
304 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
310 //_____________________________________________________________________________
311 TClonesArray* AliMUONCDB::LoadAlignmentData()
313 /// Load and return the array of alignment objects.
315 AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
317 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
319 TClonesArray* alignmentArray = 0x0;
320 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
323 // load alignement array
324 alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
327 if (!alignmentArray) {
328 AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
331 return alignmentArray;
334 //_____________________________________________________________________________
336 AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
339 /// creates a store which contains store1-store2
340 /// if opt="abs" the difference is absolute one,
341 /// if opt="rel" then what is stored is (store1-store2)/store1
342 /// if opt="percent" then what is stored is rel*100
344 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
349 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
351 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
355 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
357 TIter next(d->CreateIterator());
359 AliMUONVCalibParam* param;
361 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
363 Int_t detElemId = param->ID0();
364 Int_t manuId = param->ID1();
366 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
367 //FIXME: this might happen. Handle it.
370 cerr << "param2 is null : FIXME : this might happen !" << endl;
375 for ( Int_t i = 0; i < param->Size(); ++i )
377 for ( Int_t j = 0; j < param->Dimension(); ++j )
380 if ( sopt.Contains("ABS") )
382 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
384 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
386 if ( param->ValueAsFloat(i,j) )
388 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
394 if ( sopt.Contains("PERCENT") ) value *= 100.0;
396 param->SetValueAsFloat(i,j,value);
403 //_____________________________________________________________________________
405 AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
407 /// Make histograms of each dimension of the AliMUONVCalibParam
408 /// contained inside store.
409 /// It produces histograms named name_0, name_1, etc...
411 if (!AliMUONCDB::CheckMapping(kTRUE)) return;
413 TIter next(store.CreateIterator());
414 AliMUONVCalibParam* param;
416 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
417 Int_t* nPerStation = new Int_t[kNStations];
420 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
422 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
426 Int_t dim = param->Dimension();
428 Float_t* xmin = new Float_t[dim];
429 Float_t* xmax = new Float_t[dim];
430 getBoundaries(store,dim,xmin,xmax);
432 for ( Int_t i = 0; i < dim; ++i )
434 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
435 nbins,xmin[i],xmax[i]);
436 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
440 Int_t detElemId = param->ID0();
441 Int_t manuId = param->ID1();
442 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
444 const AliMpVSegmentation* seg =
445 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
447 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
449 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
450 if (!pad.IsValid()) continue;
453 ++nPerStation[station];
455 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
457 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
462 for ( Int_t i = 0; i < kNStations; ++i )
464 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
467 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
469 delete[] nPerStation;
472 //_____________________________________________________________________________
474 AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
476 /// Create a HV store
478 if (!AliMUONCDB::CheckMapping()) return 0;
480 AliMpDCSNamer hvNamer("TRACKER");
482 TObjArray* aliases = hvNamer.GenerateAliases();
487 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
489 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
490 TString& aliasName = alias->String();
491 if ( aliasName.Contains("sw") )
493 // HV Switch (St345 only)
494 TObjArray* valueSet = new TObjArray;
495 valueSet->SetOwner(kTRUE);
497 Bool_t value = kTRUE;
501 Float_t r = gRandom->Uniform();
502 if ( r < 0.007 ) value = kFALSE;
505 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
507 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
508 valueSet->Add(dcsValue);
510 aliasMap.Add(new TObjString(*alias),valueSet);
515 TObjArray* valueSet = new TObjArray;
516 valueSet->SetOwner(kTRUE);
517 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
519 Float_t value = 1500;
520 if (!defaultValues) value = GetRandom(1750,62.5,true);
521 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
522 valueSet->Add(dcsValue);
524 aliasMap.Add(new TObjString(*alias),valueSet);
531 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
533 return nChannels+nSwitch;
536 //_____________________________________________________________________________
538 AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
540 /// Create a Trigger HV and Currents store
542 if (!AliMUONCDB::CheckMapping()) return 0;
544 AliMpDCSNamer triggerDCSNamer("TRIGGER");
546 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
548 Int_t nChannels[2] = {0, 0};
550 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
552 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
553 TString& aliasName = alias->String();
555 TObjArray* valueSet = new TObjArray;
556 valueSet->SetOwner(kTRUE);
557 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
558 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
561 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
562 if (!defaultValues) {
563 switch (measureType){
564 case AliMpDCSNamer::kDCSI:
565 value = GetRandom(2.,0.4,true);
567 case AliMpDCSNamer::kDCSHV:
568 value = GetRandom(8000.,16.,true);
572 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
573 valueSet->Add(dcsValue);
575 aliasMap.Add(new TObjString(*alias),valueSet);
576 ++nChannels[measureType];
581 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
583 return nChannels[0] + nChannels[1];
586 //_____________________________________________________________________________
588 AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
590 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
591 /// otherwise mean and sigma are from a gaussian (with parameters
592 /// defined below by the kPedestal* constants)
594 AliCodeTimerAutoGeneral("",0);
596 if (!AliMUONCDB::CheckMapping()) return 0;
601 const Int_t kChannels(AliMpConstants::ManuNofChannels());
604 const Float_t kPedestalMeanMeanB(200.);
605 const Float_t kPedestalMeanSigmaB(10.);
606 const Float_t kPedestalSigmaMeanB(1.);
607 const Float_t kPedestalSigmaSigmaB(0.2);
610 const Float_t kPedestalMeanMeanNB(200.);
611 const Float_t kPedestalMeanSigmaNB(10.);
612 const Float_t kPedestalSigmaMeanNB(1.);
613 const Float_t kPedestalSigmaSigmaNB(0.2);
615 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
620 AliMpManuIterator it;
622 while ( it.Next(detElemId,manuId) )
624 // skip a given fraction of manus
625 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
629 AliMUONVCalibParam* ped =
630 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
632 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
634 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
636 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
640 Float_t meanPedestal;
641 Float_t sigmaPedestal;
650 Bool_t positive(kTRUE);
653 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
655 while ( meanPedestal == 0.0 ) // avoid strict zero
657 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
659 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
661 } else { // manu in bending plane
663 while ( meanPedestal == 0.0 ) // avoid strict zero
665 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
667 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
673 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
674 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
677 Bool_t ok = pedestalStore.Add(ped);
680 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
684 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
688 //_____________________________________________________________________________
690 AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
692 /// Create a reject list
694 AliCodeTimerAutoGeneral("",0);
696 AliMUONRejectList* rl = new AliMUONRejectList;
700 rl->SetDetectionElementProbability(510);
701 rl->SetDetectionElementProbability(508);
708 //_____________________________________________________________________________
710 AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
712 /// Create an occupancy map.
714 AliCodeTimerAutoGeneral("",0);
716 if (!AliMUONCDB::CheckMapping()) return 0;
723 AliMpManuIterator it;
727 while ( it.Next(detElemId,manuId) )
731 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
735 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
737 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
739 if (!defaultValues) occ = gRandom->Rndm(1);
741 Double_t sumn = occ*nevents;
743 occupancy->SetValueAsFloat(0,0,sumn);
744 occupancy->SetValueAsFloat(0,1,sumn);
745 occupancy->SetValueAsFloat(0,2,sumn);
746 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
747 occupancy->SetValueAsInt(0,4,nevents);
749 Bool_t ok = occupancyMapStore.Add(occupancy);
752 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
759 //_____________________________________________________________________________
761 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
763 /// Read the capacitance values from file and append them to the capaStore
765 if (!AliMUONCDB::CheckMapping()) return 0;
767 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
770 //_____________________________________________________________________________
772 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
774 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
775 /// otherwise they are from a gaussian with parameters defined in the
776 /// kCapa* constants below.
778 AliCodeTimerAutoGeneral("",0);
780 if (!AliMUONCDB::CheckMapping()) return 0;
784 Int_t nmanusOK(0); // manus for which we got the serial number
786 const Float_t kCapaMean(0.3);
787 const Float_t kCapaSigma(0.1);
788 const Float_t kInjectionGainMean(3);
789 const Float_t kInjectionGainSigma(1);
794 AliMpManuIterator it;
796 while ( it.Next(detElemId,manuId) )
800 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
801 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
803 if ( serialNumber <= 0 ) continue;
807 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
811 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
812 Bool_t ok = capaStore.Add(capa);
815 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
819 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
821 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
826 Float_t injectionGain;
835 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
836 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
838 capa->SetValueAsFloat(manuChannel,0,capaValue);
839 capa->SetValueAsFloat(manuChannel,1,injectionGain);
844 if ( nmanus ) percent = 100*nmanusOK/nmanus;
845 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
846 nmanusOK,nmanus,percent));
847 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
850 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
856 //_____________________________________________________________________________
858 AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
860 /// Create a gain store. if defaultValues=true, all gains set so that
861 /// charge = (adc-ped)
863 /// otherwise parameters are taken from gaussians with parameters
864 /// defined in the k* constants below.
866 AliCodeTimerAutoGeneral("",0);
868 if (!AliMUONCDB::CheckMapping()) return 0;
873 const Int_t kSaturation(3000);
874 const Double_t kA0Mean(1.2);
875 const Double_t kA0Sigma(0.1);
876 const Double_t kA1Mean(1E-5);
877 const Double_t kA1Sigma(1E-6);
878 const Double_t kQualMean(0xFF);
879 const Double_t kQualSigma(0x10);
880 const Int_t kThresMean(1600);
881 const Int_t kThresSigma(100);
886 AliMpManuIterator it;
888 while ( it.Next(detElemId,manuId) )
892 AliMUONVCalibParam* gain =
893 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
896 AliMUONVCalibParam::InvalidFloatValue());
898 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
900 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
902 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
908 gain->SetValueAsFloat(manuChannel,0,1.0);
909 gain->SetValueAsFloat(manuChannel,1,0.0);
910 gain->SetValueAsInt(manuChannel,2,4095);
911 gain->SetValueAsInt(manuChannel,3,1);
912 gain->SetValueAsInt(manuChannel,4,kSaturation);
916 Bool_t positive(kTRUE);
917 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
918 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
919 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
920 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
921 gain->SetValueAsInt(manuChannel,4,kSaturation);
925 Bool_t ok = gainStore.Add(gain);
928 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
932 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
936 //_____________________________________________________________________________
938 AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
940 /// Generate local trigger masks store. All masks are set to FFFF
942 AliCodeTimerAutoGeneral("",0);
945 // Generate fake mask values for all localboards and put that into
946 // one single container (localBoardMasks)
947 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
949 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
950 for ( Int_t x = 0; x < 2; ++x )
952 for ( Int_t y = 0; y < 4; ++y )
955 localBoard->SetValueAsInt(index,0,0xFFFF);
959 localBoardMasks.Add(localBoard);
964 //_____________________________________________________________________________
966 AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
968 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
970 AliCodeTimerAutoGeneral("",0);
972 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
973 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
977 return rtm.GetNofTriggerCrates();
981 //_____________________________________________________________________________
983 AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
985 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
987 AliCodeTimerAutoGeneral("",0);
989 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
993 //_____________________________________________________________________________
995 AliMUONCDB::MakeTriggerLUT(const char* file)
997 /// Make a triggerlut object, from a file.
999 AliCodeTimerAutoGeneral("",0);
1001 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1002 lut->ReadFromFile(file);
1006 //_____________________________________________________________________________
1007 AliMUONTriggerEfficiencyCells*
1008 AliMUONCDB::MakeTriggerEfficiency(const char* file)
1010 /// Make a trigger efficiency object from a file.
1012 AliCodeTimerAutoGeneral("",0);
1014 return new AliMUONTriggerEfficiencyCells(file);
1017 //_____________________________________________________________________________
1019 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1020 Int_t startRun, Int_t endRun,
1021 const char* filename)
1023 /// Write a given object to OCDB
1025 TString comment(gSystem->ExpandPathName(filename));
1027 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1030 //_____________________________________________________________________________
1032 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1033 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1035 /// Write a given object to OCDB
1038 if ( defaultValues ) comment += "Test with default values";
1039 else comment += "Test with random values";
1041 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1044 //_____________________________________________________________________________
1046 AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1047 const char* comment, const char* responsible)
1049 /// Write a given object to OCDB
1051 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1053 AliCDBId id(calibpath,startRun,endRun);
1055 md.SetAliRootVersion(gROOT->GetVersion());
1056 md.SetComment(comment);
1057 md.SetResponsible(responsible);
1058 AliCDBManager::Instance()->Put(object,id,&md);
1061 //_____________________________________________________________________________
1063 AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
1065 /// Fill the neighbours store with, for each channel, a TObjArray of its
1066 /// neighbouring pads (including itself)
1068 AliCodeTimerAutoGeneral("",0);
1070 if (!AliMUONCDB::CheckMapping()) return 0;
1072 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
1081 AliMpManuIterator it;
1083 while ( it.Next(detElemId,manuId) )
1085 const AliMpVSegmentation* seg =
1086 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1088 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
1091 Int_t dimension(11);
1092 Int_t size(AliMpConstants::ManuNofChannels());
1093 Int_t defaultValue(-1);
1094 Int_t packingFactor(size);
1096 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1097 Bool_t ok = neighbourStore.Add(calibParam);
1100 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
1105 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
1107 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
1113 seg->GetNeighbours(pad,tmp,true,true);
1114 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1116 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1118 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
1121 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
1124 // AliError("Could not pack value. Something is seriously wrong. Please check");
1125 // StdoutToAliError(pad->Print(););
1128 calibParam->SetValueAsInt(manuChannel,i,x);
1137 //_____________________________________________________________________________
1139 AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1141 /// Write local trigger masks to OCDB
1143 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
1144 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
1145 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1148 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1153 //_____________________________________________________________________________
1155 AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
1157 /// Write regional trigger masks to OCDB
1159 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1160 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
1161 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1164 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
1170 //_____________________________________________________________________________
1172 AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
1174 /// Write global trigger masks to OCDB
1176 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
1178 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
1179 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1182 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
1188 //_____________________________________________________________________________
1190 AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1192 /// Write trigger LUT to OCDB
1194 AliMUONTriggerLut* lut = MakeTriggerLUT();
1197 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1202 //_____________________________________________________________________________
1204 AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1206 /// Write trigger efficiency to OCDB
1208 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1211 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1216 //_____________________________________________________________________________
1218 AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1220 /// Write neighbours to OCDB
1222 AliMUONVStore* neighbours = Create2DMap();
1223 Int_t ngenerated = MakeNeighbourStore(*neighbours);
1224 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1227 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1232 //_____________________________________________________________________________
1234 AliMUONCDB::WriteHV(Bool_t defaultValues,
1235 Int_t startRun, Int_t endRun)
1237 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
1238 /// if defaultValues=false, see makeHVStore) and
1239 /// store them into CDB located at cdbpath, with a validity period
1240 /// ranging from startRun to endRun
1242 TMap* hvStore = new TMap;
1243 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
1244 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1247 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1252 //_____________________________________________________________________________
1254 AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1255 Int_t startRun, Int_t endRun)
1257 /// generate Trigger HV and current values (either const if defaultValues=true or random
1258 /// if defaultValues=false, see makeTriggerDCSStore) and
1259 /// store them into CDB located at cdbpath, with a validity period
1260 /// ranging from startRun to endRun
1262 TMap* triggerDCSStore = new TMap;
1263 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
1264 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1267 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1269 delete triggerDCSStore;
1272 //_____________________________________________________________________________
1274 AliMUONCDB::WritePedestals(Bool_t defaultValues,
1275 Int_t startRun, Int_t endRun)
1277 /// generate pedestal values (either 0 if defaultValues=true or random
1278 /// if defaultValues=false, see makePedestalStore) and
1279 /// store them into CDB located at cdbpath, with a validity period
1280 /// ranging from startRun to endRun
1282 AliMUONVStore* pedestalStore = Create2DMap();
1283 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
1284 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1285 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1286 delete pedestalStore;
1289 //_____________________________________________________________________________
1291 AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1292 Int_t startRun, Int_t endRun)
1294 /// generate occupancy map values (either empty one if defaultValues=true, or
1295 /// random one, see MakeOccupancyMapStore) and
1296 /// store them into CDB located at cdbpath, with a validity period
1297 /// ranging from startRun to endRun
1299 AliMUONVStore* occupancyMapStore = Create2DMap();
1300 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
1301 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1302 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1303 delete occupancyMapStore;
1306 //_____________________________________________________________________________
1308 AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1309 Int_t startRun, Int_t endRun)
1311 /// generate reject list values (either empty one if defaultValues=true, or
1312 /// random one, see MakeRejectListStore) and
1313 /// store them into CDB located at cdbpath, with a validity period
1314 /// ranging from startRun to endRun
1316 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1317 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1322 //_____________________________________________________________________________
1324 AliMUONCDB::WriteGains(Bool_t defaultValues,
1325 Int_t startRun, Int_t endRun)
1327 /// generate gain values (either 1 if defaultValues=true or random
1328 /// if defaultValues=false, see makeGainStore) and
1329 /// store them into CDB located at cdbpath, with a validity period
1330 /// ranging from startRun to endRun
1332 AliMUONVStore* gainStore = Create2DMap();
1333 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
1334 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1335 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1339 //_____________________________________________________________________________
1341 AliMUONCDB::WriteCapacitances(const char* filename,
1342 Int_t startRun, Int_t endRun)
1344 /// read manu capacitance and injection gain values from file
1345 /// and store them into CDB located at cdbpath, with a validity period
1346 /// ranging from startRun to endRun
1348 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1349 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
1350 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1351 if ( ngenerated > 0 )
1353 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1358 //_____________________________________________________________________________
1360 AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1361 Int_t startRun, Int_t endRun)
1363 /// generate manu capacitance values (either 1 if defaultValues=true or random
1364 /// if defaultValues=false, see makeCapacitanceStore) and
1365 /// store them into CDB located at cdbpath, with a validity period
1366 /// ranging from startRun to endRun
1368 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1369 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
1370 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1371 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1375 //_____________________________________________________________________________
1377 AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1379 /// Writes all Trigger related calibration to CDB
1380 WriteTriggerDCS(defaultValues,startRun,endRun);
1381 WriteLocalTriggerMasks(startRun,endRun);
1382 WriteRegionalTriggerConfig(startRun,endRun);
1383 WriteGlobalTriggerConfig(startRun,endRun);
1384 WriteTriggerLut(startRun,endRun);
1385 WriteTriggerEfficiency(startRun,endRun);
1388 //_____________________________________________________________________________
1390 AliMUONCDB::WriteConfig(Int_t startRun, Int_t endRun)
1392 /// Write complete tracker configuration to OCDB
1393 ostringstream lines;
1394 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1396 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
1398 for (Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu)
1400 lines << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
1404 AliMUON2DMap config(kTRUE);
1406 AliMUONTrackerIO::DecodeConfig(lines.str().c_str(),config);
1408 WriteToCDB("MUON/Calib/Config",&config,startRun,endRun,kTRUE);
1411 //_____________________________________________________________________________
1413 AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1415 /// Writes all Tracker related calibration to CDB
1416 WriteHV(defaultValues,startRun,endRun);
1417 WritePedestals(defaultValues,startRun,endRun);
1418 WriteGains(defaultValues,startRun,endRun);
1419 WriteCapacitances(defaultValues,startRun,endRun);
1420 WriteNeighbours(startRun,endRun);
1421 WriteOccupancyMap(defaultValues,startRun,endRun);
1422 WriteRejectList(defaultValues,startRun,endRun);
1423 WriteConfig(startRun,endRun);