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 "AliMUONCalibrationData.h"
44 #include "AliMUONConstants.h"
45 #include "AliMUONGlobalCrateConfig.h"
46 #include "AliMUONPadStatusMaker.h"
47 #include "AliMUONPadStatusMapMaker.h"
48 #include "AliMUONRecoParam.h"
49 #include "AliMUONRegionalTriggerConfig.h"
50 #include "AliMUONRejectList.h"
51 #include "AliMUONTrackerIO.h"
52 #include "AliMUONTriggerEfficiencyCells.h"
53 #include "AliMUONTriggerLut.h"
54 #include "AliMUONVCalibParam.h"
55 #include "AliMUONVCalibParam.h"
56 #include "AliMUONVStore.h"
60 #include "AliMpConstants.h"
61 #include "AliMpDEStore.h"
62 #include "AliMpDDLStore.h"
63 #include "AliMpManuStore.h"
64 #include "AliMpDEManager.h"
65 #include "AliMpDetElement.h"
66 #include "AliMpFiles.h"
67 #include "AliMpDCSNamer.h"
68 #include "AliMpManuIterator.h"
69 #include "AliMpSegmentation.h"
70 #include "AliMpStationType.h"
71 #include "AliMpVSegmentation.h"
73 #include "AliCodeTimer.h"
74 #include "AliCDBEntry.h"
75 #include "AliCDBManager.h"
76 #include "AliGRPManager.h"
77 #include "AliDCSValue.h"
79 #include "AliMpBusPatch.h"
81 #include <Riostream.h>
87 #include <TObjString.h>
90 #include <TStopwatch.h>
93 #include <TGeoGlobalMagField.h>
94 #include <TClonesArray.h>
99 //_____________________________________________________________________________
100 AliMUONVStore* Create2DMap()
102 return new AliMUON2DMap(true);
105 //_____________________________________________________________________________
106 void getBoundaries(const AliMUONVStore& store, Int_t dim,
107 Float_t* xmin, Float_t* xmax)
109 /// Assuming the store contains AliMUONVCalibParam objects, compute the
110 /// limits of the value contained in the VCalibParam, for each of its dimensions
111 /// xmin and xmax must be of dimension dim
113 for ( Int_t i = 0; i < dim; ++i )
119 TIter next(store.CreateIterator());
120 AliMUONVCalibParam* value;
122 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
124 Int_t detElemId = value->ID0();
125 Int_t manuId = value->ID1();
127 const AliMpVSegmentation* seg =
128 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
130 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
132 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
133 if (!pad.IsValid()) continue;
135 for ( Int_t i = 0; i < dim; ++i )
137 Float_t x0 = value->ValueAsFloat(manuChannel,i);
139 xmin[i] = TMath::Min(xmin[i],x0);
140 xmax[i] = TMath::Max(xmax[i],x0);
145 for ( Int_t i = 0; i < dim; ++i )
147 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
155 //_____________________________________________________________________________
156 Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
159 if ( mustBePositive )
163 x = gRandom->Gaus(mean,sigma);
168 x = gRandom->Gaus(mean,sigma);
175 //_____________________________________________________________________________
176 Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
178 /// Check that OCDB path and run number are properly set
180 AliCDBManager* man = AliCDBManager::Instance();
183 if (!man->IsDefaultStorageSet()) {
184 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
188 // then run number if required
189 if (pathOnly) return kTRUE;
190 if (man->GetRun() < 0) {
191 AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
199 //_____________________________________________________________________________
200 Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
202 /// Check that the mapping has been loaded
204 // first the segmentation
205 if (!AliMpSegmentation::Instance(false)) {
206 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
210 // then the others if required
211 if (segmentationOnly) return kTRUE;
212 if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
213 AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
221 //_____________________________________________________________________________
222 Bool_t AliMUONCDB::LoadField()
224 /// Load magnetic field (existing field will be deleted).
225 /// OCDB path and run number are supposed to be set.
227 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
229 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
231 AliGRPManager grpMan;
233 // make sure the old field is deleted even if it is locked
234 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
236 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
237 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
245 //_____________________________________________________________________________
246 Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
248 /// Load mapping (existing mapping will be unloaded).
249 /// OCDB path and run number are supposed to be set.
251 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
253 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
255 // in case it has already been set
256 AliMpCDB::UnloadAll();
258 if (segmentationOnly) {
260 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
261 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
267 if (!AliMpCDB::LoadAll(kTRUE)) {
268 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
278 //_____________________________________________________________________________
279 AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
281 /// Load and return reconstruction parameters.
282 /// OCDB path is supposed to be set.
284 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
286 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
288 AliMUONRecoParam* recoParam = 0x0;
289 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
293 // load recoParam according OCDB content (single or array)
294 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
296 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
298 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
299 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
300 if (recoParam->IsDefault()) break;
308 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
314 //_____________________________________________________________________________
315 TClonesArray* AliMUONCDB::LoadAlignmentData()
317 /// Load and return the array of alignment objects.
319 AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
321 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
323 TClonesArray* alignmentArray = 0x0;
324 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
327 // load alignement array
328 alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
331 if (!alignmentArray) {
332 AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
335 return alignmentArray;
338 //_____________________________________________________________________________
340 AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
343 /// creates a store which contains store1-store2
344 /// if opt="abs" the difference is absolute one,
345 /// if opt="rel" then what is stored is (store1-store2)/store1
346 /// if opt="percent" then what is stored is rel*100
348 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
353 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
355 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
359 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
361 TIter next(d->CreateIterator());
363 AliMUONVCalibParam* param;
365 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
367 Int_t detElemId = param->ID0();
368 Int_t manuId = param->ID1();
370 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
371 //FIXME: this might happen. Handle it.
374 cerr << "param2 is null : FIXME : this might happen !" << endl;
379 for ( Int_t i = 0; i < param->Size(); ++i )
381 for ( Int_t j = 0; j < param->Dimension(); ++j )
384 if ( sopt.Contains("ABS") )
386 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
388 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
390 if ( param->ValueAsFloat(i,j) )
392 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
398 if ( sopt.Contains("PERCENT") ) value *= 100.0;
400 param->SetValueAsFloat(i,j,value);
407 //_____________________________________________________________________________
409 AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
411 /// Make histograms of each dimension of the AliMUONVCalibParam
412 /// contained inside store.
413 /// It produces histograms named name_0, name_1, etc...
415 if (!AliMUONCDB::CheckMapping(kTRUE)) return;
417 TIter next(store.CreateIterator());
418 AliMUONVCalibParam* param;
420 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
421 Int_t* nPerStation = new Int_t[kNStations];
424 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
426 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
430 Int_t dim = param->Dimension();
432 Float_t* xmin = new Float_t[dim];
433 Float_t* xmax = new Float_t[dim];
434 getBoundaries(store,dim,xmin,xmax);
436 for ( Int_t i = 0; i < dim; ++i )
438 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
439 nbins,xmin[i],xmax[i]);
440 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
444 Int_t detElemId = param->ID0();
445 Int_t manuId = param->ID1();
446 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
448 const AliMpVSegmentation* seg =
449 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
451 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
453 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
454 if (!pad.IsValid()) continue;
457 ++nPerStation[station];
459 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
461 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
466 for ( Int_t i = 0; i < kNStations; ++i )
468 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
471 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
473 delete[] nPerStation;
476 //_____________________________________________________________________________
478 AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
480 /// Create a HV store
482 if (!AliMUONCDB::CheckMapping()) return 0;
484 AliMpDCSNamer hvNamer("TRACKER");
486 TObjArray* aliases = hvNamer.GenerateAliases();
491 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
493 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
494 TString& aliasName = alias->String();
495 if ( aliasName.Contains("sw") )
497 // HV Switch (St345 only)
498 TObjArray* valueSet = new TObjArray;
499 valueSet->SetOwner(kTRUE);
501 Bool_t value = kTRUE;
505 Float_t r = gRandom->Uniform();
506 if ( r < 0.007 ) value = kFALSE;
509 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
511 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
512 valueSet->Add(dcsValue);
514 aliasMap.Add(new TObjString(*alias),valueSet);
519 TObjArray* valueSet = new TObjArray;
520 valueSet->SetOwner(kTRUE);
521 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
523 Float_t value = 1500;
524 if (!defaultValues) value = GetRandom(1750,62.5,true);
525 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
526 valueSet->Add(dcsValue);
528 aliasMap.Add(new TObjString(*alias),valueSet);
535 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
537 return nChannels+nSwitch;
540 //_____________________________________________________________________________
542 AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
544 /// Create a Trigger HV and Currents store
546 if (!AliMUONCDB::CheckMapping()) return 0;
548 AliMpDCSNamer triggerDCSNamer("TRIGGER");
550 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
552 Int_t nChannels[2] = {0, 0};
554 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
556 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
557 TString& aliasName = alias->String();
559 TObjArray* valueSet = new TObjArray;
560 valueSet->SetOwner(kTRUE);
561 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
562 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
565 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
566 if (!defaultValues) {
567 switch (measureType){
568 case AliMpDCSNamer::kDCSI:
569 value = GetRandom(2.,0.4,true);
571 case AliMpDCSNamer::kDCSHV:
572 value = GetRandom(8000.,16.,true);
576 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
577 valueSet->Add(dcsValue);
579 aliasMap.Add(new TObjString(*alias),valueSet);
580 ++nChannels[measureType];
585 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
587 return nChannels[0] + nChannels[1];
590 //_____________________________________________________________________________
592 AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
594 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
595 /// otherwise mean and sigma are from a gaussian (with parameters
596 /// defined below by the kPedestal* constants)
598 AliCodeTimerAutoGeneral("",0);
600 if (!AliMUONCDB::CheckMapping()) return 0;
605 const Int_t kChannels(AliMpConstants::ManuNofChannels());
608 const Float_t kPedestalMeanMeanB(200.);
609 const Float_t kPedestalMeanSigmaB(10.);
610 const Float_t kPedestalSigmaMeanB(1.);
611 const Float_t kPedestalSigmaSigmaB(0.2);
614 const Float_t kPedestalMeanMeanNB(200.);
615 const Float_t kPedestalMeanSigmaNB(10.);
616 const Float_t kPedestalSigmaMeanNB(1.);
617 const Float_t kPedestalSigmaSigmaNB(0.2);
619 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
624 AliMpManuIterator it;
626 while ( it.Next(detElemId,manuId) )
628 // skip a given fraction of manus
629 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
633 AliMUONVCalibParam* ped =
634 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
636 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
638 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
640 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
644 Float_t meanPedestal;
645 Float_t sigmaPedestal;
654 Bool_t positive(kTRUE);
657 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
659 while ( meanPedestal == 0.0 ) // avoid strict zero
661 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
663 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
665 } else { // manu in bending plane
667 while ( meanPedestal == 0.0 ) // avoid strict zero
669 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
671 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
677 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
678 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
681 Bool_t ok = pedestalStore.Add(ped);
684 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
688 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
692 //_____________________________________________________________________________
694 AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
696 /// Create a reject list
698 AliCodeTimerAutoGeneral("",0);
700 AliMUONRejectList* rl = new AliMUONRejectList;
704 rl->SetDetectionElementProbability(510);
705 rl->SetDetectionElementProbability(508);
712 //_____________________________________________________________________________
714 AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
716 /// Create an occupancy map.
718 AliCodeTimerAutoGeneral("",0);
720 if (!AliMUONCDB::CheckMapping()) return 0;
727 AliMpManuIterator it;
731 while ( it.Next(detElemId,manuId) )
735 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
739 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
741 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
743 if (!defaultValues) occ = gRandom->Rndm(1);
745 Double_t sumn = occ*nevents;
747 occupancy->SetValueAsFloat(0,0,sumn);
748 occupancy->SetValueAsFloat(0,1,sumn);
749 occupancy->SetValueAsFloat(0,2,sumn);
750 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
751 occupancy->SetValueAsInt(0,4,nevents);
753 Bool_t ok = occupancyMapStore.Add(occupancy);
756 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
763 //_____________________________________________________________________________
765 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
767 /// Read the capacitance values from file and append them to the capaStore
769 if (!AliMUONCDB::CheckMapping()) return 0;
771 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
774 //_____________________________________________________________________________
776 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
778 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
779 /// otherwise they are from a gaussian with parameters defined in the
780 /// kCapa* constants below.
782 AliCodeTimerAutoGeneral("",0);
784 if (!AliMUONCDB::CheckMapping()) return 0;
788 Int_t nmanusOK(0); // manus for which we got the serial number
790 const Float_t kCapaMean(0.3);
791 const Float_t kCapaSigma(0.1);
792 const Float_t kInjectionGainMean(3);
793 const Float_t kInjectionGainSigma(1);
798 AliMpManuIterator it;
800 while ( it.Next(detElemId,manuId) )
804 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
805 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
807 if ( serialNumber <= 0 ) continue;
811 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
815 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
816 Bool_t ok = capaStore.Add(capa);
819 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
823 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
825 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
830 Float_t injectionGain;
839 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
840 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
842 capa->SetValueAsFloat(manuChannel,0,capaValue);
843 capa->SetValueAsFloat(manuChannel,1,injectionGain);
848 if ( nmanus ) percent = 100*nmanusOK/nmanus;
849 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
850 nmanusOK,nmanus,percent));
851 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
854 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
860 //_____________________________________________________________________________
862 AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
864 /// Create a gain store. if defaultValues=true, all gains set so that
865 /// charge = (adc-ped)
867 /// otherwise parameters are taken from gaussians with parameters
868 /// defined in the k* constants below.
870 AliCodeTimerAutoGeneral("",0);
872 if (!AliMUONCDB::CheckMapping()) return 0;
877 const Int_t kSaturation(3000);
878 const Double_t kA0Mean(1.2);
879 const Double_t kA0Sigma(0.1);
880 const Double_t kA1Mean(1E-5);
881 const Double_t kA1Sigma(1E-6);
882 const Double_t kQualMean(0xFF);
883 const Double_t kQualSigma(0x10);
884 const Int_t kThresMean(1600);
885 const Int_t kThresSigma(100);
890 AliMpManuIterator it;
892 while ( it.Next(detElemId,manuId) )
896 AliMUONVCalibParam* gain =
897 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
900 AliMUONVCalibParam::InvalidFloatValue());
902 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
904 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
906 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
912 gain->SetValueAsFloat(manuChannel,0,1.0);
913 gain->SetValueAsFloat(manuChannel,1,0.0);
914 gain->SetValueAsInt(manuChannel,2,4095);
915 gain->SetValueAsInt(manuChannel,3,1);
916 gain->SetValueAsInt(manuChannel,4,kSaturation);
920 Bool_t positive(kTRUE);
921 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
922 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
923 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
924 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
925 gain->SetValueAsInt(manuChannel,4,kSaturation);
929 Bool_t ok = gainStore.Add(gain);
932 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
936 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
940 //_____________________________________________________________________________
942 AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
944 /// Generate local trigger masks store. All masks are set to FFFF
946 AliCodeTimerAutoGeneral("",0);
949 // Generate fake mask values for all localboards and put that into
950 // one single container (localBoardMasks)
951 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
953 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
954 for ( Int_t x = 0; x < 2; ++x )
956 for ( Int_t y = 0; y < 4; ++y )
959 localBoard->SetValueAsInt(index,0,0xFFFF);
963 localBoardMasks.Add(localBoard);
968 //_____________________________________________________________________________
970 AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
972 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
974 AliCodeTimerAutoGeneral("",0);
976 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
977 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
981 return rtm.GetNofTriggerCrates();
985 //_____________________________________________________________________________
987 AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
989 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
991 AliCodeTimerAutoGeneral("",0);
993 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
997 //_____________________________________________________________________________
999 AliMUONCDB::MakeTriggerLUT(const char* file)
1001 /// Make a triggerlut object, from a file.
1003 AliCodeTimerAutoGeneral("",0);
1005 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1006 lut->ReadFromFile(file);
1010 //_____________________________________________________________________________
1011 AliMUONTriggerEfficiencyCells*
1012 AliMUONCDB::MakeTriggerEfficiency(const char* file)
1014 /// Make a trigger efficiency object from a file.
1016 AliCodeTimerAutoGeneral("",0);
1018 return new AliMUONTriggerEfficiencyCells(file);
1021 //_____________________________________________________________________________
1023 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1024 Int_t startRun, Int_t endRun,
1025 const char* filename)
1027 /// Write a given object to OCDB
1029 TString comment(gSystem->ExpandPathName(filename));
1031 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1034 //_____________________________________________________________________________
1036 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1037 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1039 /// Write a given object to OCDB
1042 if ( defaultValues ) comment += "Test with default values";
1043 else comment += "Test with random values";
1045 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1048 //_____________________________________________________________________________
1050 AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1051 const char* comment, const char* responsible)
1053 /// Write a given object to OCDB
1055 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1057 AliCDBId id(calibpath,startRun,endRun);
1059 md.SetAliRootVersion(gROOT->GetVersion());
1060 md.SetComment(comment);
1061 md.SetResponsible(responsible);
1062 AliCDBManager::Instance()->Put(object,id,&md);
1065 //_____________________________________________________________________________
1067 AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
1069 /// Fill the neighbours store with, for each channel, a TObjArray of its
1070 /// neighbouring pads (including itself)
1072 AliCodeTimerAutoGeneral("",0);
1074 if (!AliMUONCDB::CheckMapping()) return 0;
1076 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
1085 AliMpManuIterator it;
1087 while ( it.Next(detElemId,manuId) )
1089 const AliMpVSegmentation* seg =
1090 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1092 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
1095 Int_t dimension(11);
1096 Int_t size(AliMpConstants::ManuNofChannels());
1097 Int_t defaultValue(-1);
1098 Int_t packingFactor(size);
1100 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1101 Bool_t ok = neighbourStore.Add(calibParam);
1104 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
1109 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
1111 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
1117 seg->GetNeighbours(pad,tmp,true,true);
1118 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1120 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1122 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
1125 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
1128 // AliError("Could not pack value. Something is seriously wrong. Please check");
1129 // StdoutToAliError(pad->Print(););
1132 calibParam->SetValueAsInt(manuChannel,i,x);
1141 //_____________________________________________________________________________
1143 AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1145 /// Write local trigger masks to OCDB
1147 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
1148 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
1149 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1152 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1157 //_____________________________________________________________________________
1159 AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
1161 /// Write regional trigger masks to OCDB
1163 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1164 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
1165 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1168 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
1174 //_____________________________________________________________________________
1176 AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
1178 /// Write global trigger masks to OCDB
1180 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
1182 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
1183 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1186 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
1192 //_____________________________________________________________________________
1194 AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1196 /// Write trigger LUT to OCDB
1198 AliMUONTriggerLut* lut = MakeTriggerLUT();
1201 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1206 //_____________________________________________________________________________
1208 AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1210 /// Write trigger efficiency to OCDB
1212 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1215 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1220 //_____________________________________________________________________________
1222 AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1224 /// Write neighbours to OCDB
1226 AliMUONVStore* neighbours = Create2DMap();
1227 Int_t ngenerated = MakeNeighbourStore(*neighbours);
1228 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1231 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1236 //_____________________________________________________________________________
1238 AliMUONCDB::WriteHV(Bool_t defaultValues,
1239 Int_t startRun, Int_t endRun)
1241 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
1242 /// if defaultValues=false, see makeHVStore) and
1243 /// store them into CDB located at cdbpath, with a validity period
1244 /// ranging from startRun to endRun
1246 TMap* hvStore = new TMap;
1247 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
1248 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1251 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1256 //_____________________________________________________________________________
1258 AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1259 Int_t startRun, Int_t endRun)
1261 /// generate Trigger HV and current values (either const if defaultValues=true or random
1262 /// if defaultValues=false, see makeTriggerDCSStore) and
1263 /// store them into CDB located at cdbpath, with a validity period
1264 /// ranging from startRun to endRun
1266 TMap* triggerDCSStore = new TMap;
1267 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
1268 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1271 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1273 delete triggerDCSStore;
1276 //_____________________________________________________________________________
1278 AliMUONCDB::WritePedestals(Bool_t defaultValues,
1279 Int_t startRun, Int_t endRun)
1281 /// generate pedestal values (either 0 if defaultValues=true or random
1282 /// if defaultValues=false, see makePedestalStore) and
1283 /// store them into CDB located at cdbpath, with a validity period
1284 /// ranging from startRun to endRun
1286 AliMUONVStore* pedestalStore = Create2DMap();
1287 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
1288 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1289 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1290 delete pedestalStore;
1293 //_____________________________________________________________________________
1295 AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1296 Int_t startRun, Int_t endRun)
1298 /// generate occupancy map values (either empty one if defaultValues=true, or
1299 /// random one, see MakeOccupancyMapStore) and
1300 /// store them into CDB located at cdbpath, with a validity period
1301 /// ranging from startRun to endRun
1303 AliMUONVStore* occupancyMapStore = Create2DMap();
1304 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
1305 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1306 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1307 delete occupancyMapStore;
1310 //_____________________________________________________________________________
1312 AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1313 Int_t startRun, Int_t endRun)
1315 /// generate reject list values (either empty one if defaultValues=true, or
1316 /// random one, see MakeRejectListStore) and
1317 /// store them into CDB located at cdbpath, with a validity period
1318 /// ranging from startRun to endRun
1320 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1321 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1326 //_____________________________________________________________________________
1328 AliMUONCDB::WriteGains(Bool_t defaultValues,
1329 Int_t startRun, Int_t endRun)
1331 /// generate gain values (either 1 if defaultValues=true or random
1332 /// if defaultValues=false, see makeGainStore) and
1333 /// store them into CDB located at cdbpath, with a validity period
1334 /// ranging from startRun to endRun
1336 AliMUONVStore* gainStore = Create2DMap();
1337 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
1338 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1339 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1343 //_____________________________________________________________________________
1345 AliMUONCDB::WriteCapacitances(const char* filename,
1346 Int_t startRun, Int_t endRun)
1348 /// read manu capacitance and injection gain values from file
1349 /// and store them into CDB located at cdbpath, with a validity period
1350 /// ranging from startRun to endRun
1352 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1353 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
1354 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1355 if ( ngenerated > 0 )
1357 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1362 //_____________________________________________________________________________
1364 AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1365 Int_t startRun, Int_t endRun)
1367 /// generate manu capacitance values (either 1 if defaultValues=true or random
1368 /// if defaultValues=false, see makeCapacitanceStore) and
1369 /// store them into CDB located at cdbpath, with a validity period
1370 /// ranging from startRun to endRun
1372 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1373 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
1374 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1375 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1379 //_____________________________________________________________________________
1381 AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1383 /// Writes all Trigger related calibration to CDB
1384 WriteTriggerDCS(defaultValues,startRun,endRun);
1385 WriteLocalTriggerMasks(startRun,endRun);
1386 WriteRegionalTriggerConfig(startRun,endRun);
1387 WriteGlobalTriggerConfig(startRun,endRun);
1388 WriteTriggerLut(startRun,endRun);
1389 WriteTriggerEfficiency(startRun,endRun);
1392 //_____________________________________________________________________________
1394 AliMUONCDB::WriteConfig(Int_t startRun, Int_t endRun)
1396 /// Write complete tracker configuration to OCDB
1397 ostringstream lines;
1398 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1400 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
1402 for (Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu)
1404 lines << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
1408 AliMUON2DMap config(kTRUE);
1410 AliMUONTrackerIO::DecodeConfig(lines.str().c_str(),config);
1412 WriteToCDB("MUON/Calib/Config",&config,startRun,endRun,kTRUE);
1415 //_____________________________________________________________________________
1417 AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1419 /// Writes all Tracker related calibration to CDB
1420 WriteHV(defaultValues,startRun,endRun);
1421 WritePedestals(defaultValues,startRun,endRun);
1422 WriteGains(defaultValues,startRun,endRun);
1423 WriteCapacitances(defaultValues,startRun,endRun);
1424 WriteNeighbours(startRun,endRun);
1425 WriteOccupancyMap(defaultValues,startRun,endRun);
1426 WriteRejectList(defaultValues,startRun,endRun);
1427 WriteConfig(startRun,endRun);
1430 //_____________________________________________________________________________
1432 AliMUONCDB::ShowConfig(Bool_t withStatusMap)
1434 /// Dumps the current tracker configuration, i.e. number and identity of missing buspatches
1435 /// If statusMap is true, will also take into account the status map to report the number
1436 /// of good channels
1438 if (!AliMUONCDB::CheckOCDB()) return;
1440 AliMUONCDB::LoadMapping();
1442 if (!AliMUONCDB::CheckMapping()) return;
1444 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1448 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1450 AliMUONPadStatusMapMaker* statusMapMaker(0x0);
1451 AliMUONCalibrationData* cd(0x0);
1452 AliMUONPadStatusMaker* statusMaker(0x0);
1454 if ( withStatusMap )
1456 cd = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
1458 statusMaker = new AliMUONPadStatusMaker(*cd);
1460 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
1462 statusMaker->SetLimits(*recoParam);
1466 UInt_t mask = recoParam->PadGoodnessMask();
1468 const Bool_t deferredInitialization = kFALSE;
1470 statusMapMaker = new AliMUONPadStatusMapMaker(*cd,mask,deferredInitialization);
1473 TIter nextManu(config->CreateIterator());
1474 AliMUONVCalibParam* param;
1476 AliMpExMap buspatches;
1478 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1480 Int_t detElemId = param->ID0();
1481 Int_t manuId = param->ID1();
1482 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1483 if ( buspatches.GetValue(busPatchId) == 0x0 )
1485 buspatches.Add(busPatchId,new TObjString(Form("BP%04d",busPatchId)));
1489 TArrayI removed(buspatches.GetSize());
1491 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1497 // accounting of bus patches first
1499 while ( ( bp = static_cast<AliMpBusPatch*>(next())))
1501 if ( buspatches.GetValue(bp->GetId()) )
1507 removed.SetAt(bp->GetId(),nremoved++);
1511 // accounting of channels
1513 AliMpManuIterator it;
1515 Int_t totalNumberOfChannels(0);
1516 Int_t removedChannels(0);
1517 Int_t badChannels(0);
1518 Int_t badAndRemovedChannels(0);
1519 Int_t badOrRemovedChannels(0);
1521 Int_t detElemId, manuId;
1523 while ( it.Next(detElemId,manuId) )
1525 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1526 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
1528 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1530 if ( de->IsConnectedChannel(manuId,i) )
1532 ++totalNumberOfChannels;
1533 Bool_t badBusPatch = ( buspatches.GetValue(busPatchId) == 0x0 );
1535 if ( withStatusMap )
1537 Bool_t badChannel = ( statusMapMaker->StatusMap(detElemId,manuId,i) & AliMUONPadStatusMapMaker::SelfDeadMask() != 0);
1538 if ( badChannel ) ++badChannels;
1539 if ( badBusPatch && badChannel ) ++badAndRemovedChannels;
1540 if ( badBusPatch || badChannel ) ++badOrRemovedChannels;
1543 if ( badBusPatch) ++removedChannels;
1549 Int_t* indices = new Int_t[nremoved];
1551 TMath::Sort(nremoved,removed.GetArray(),indices,kFALSE);
1553 for ( Int_t i = 0; i < nremoved; ++i )
1555 Int_t busPatchId = removed[indices[i]];
1556 bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1563 cout << Form("Bus patches n=%3d nok=%3d nremoved=%3d",n,nok,nremoved) << endl;
1565 cout << Form("Channels n=%6d nremoved=%6d bad=%6d bad and removed=%6d bad or removed=%6d",
1566 totalNumberOfChannels,removedChannels,badChannels,badAndRemovedChannels,badOrRemovedChannels) << endl;
1568 if (totalNumberOfChannels>0)
1570 cout << Form("Percentage of readout channels %5.1f %%",removedChannels*100.0/totalNumberOfChannels) << endl;
1571 if ( withStatusMap )
1573 cout << Form("Percentage of non useable channels (bad or removed) %5.1f %%",
1574 badOrRemovedChannels*100.0/totalNumberOfChannels) << endl;
1579 delete statusMapMaker;