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 "AliMUONLogger.h"
47 #include "AliMUONPadStatusMaker.h"
48 #include "AliMUONPadStatusMapMaker.h"
49 #include "AliMUONRecoParam.h"
50 #include "AliMUONRegionalTriggerConfig.h"
51 #include "AliMUONRejectList.h"
52 #include "AliMUONTrackerData.h"
53 #include "AliMUONTrackerIO.h"
54 #include "AliMUONTriggerEfficiencyCells.h"
55 #include "AliMUONTriggerLut.h"
56 #include "AliMUONVCalibParam.h"
57 #include "AliMUONVCalibParam.h"
58 #include "AliMUONVStore.h"
61 #include "AliMpConstants.h"
62 #include "AliMpDEStore.h"
63 #include "AliMpDDLStore.h"
64 #include "AliMpManuStore.h"
65 #include "AliMpDEManager.h"
66 #include "AliMpDetElement.h"
67 #include "AliMpFiles.h"
68 #include "AliMpDCSNamer.h"
69 #include "AliMpManuIterator.h"
70 #include "AliMpSegmentation.h"
71 #include "AliMpStationType.h"
72 #include "AliMpVSegmentation.h"
74 #include "AliCodeTimer.h"
75 #include "AliCDBEntry.h"
76 #include "AliCDBManager.h"
77 #include "AliGRPManager.h"
78 #include "AliDCSValue.h"
80 #include "AliMpBusPatch.h"
82 #include <Riostream.h>
89 #include <TObjString.h>
92 #include <TStopwatch.h>
95 #include <TGeoGlobalMagField.h>
96 #include <TClonesArray.h>
102 //_____________________________________________________________________________
103 AliMUONVStore* Create2DMap()
105 return new AliMUON2DMap(true);
108 //_____________________________________________________________________________
109 void getBoundaries(const AliMUONVStore& store, Int_t dim,
110 Float_t* xmin, Float_t* xmax)
112 /// Assuming the store contains AliMUONVCalibParam objects, compute the
113 /// limits of the value contained in the VCalibParam, for each of its dimensions
114 /// xmin and xmax must be of dimension dim
116 for ( Int_t i = 0; i < dim; ++i )
122 TIter next(store.CreateIterator());
123 AliMUONVCalibParam* value;
125 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
127 Int_t detElemId = value->ID0();
128 Int_t manuId = value->ID1();
130 const AliMpVSegmentation* seg =
131 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
135 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
137 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
138 if (!pad.IsValid()) continue;
140 for ( Int_t i = 0; i < dim; ++i )
142 Float_t x0 = value->ValueAsFloat(manuChannel,i);
144 xmin[i] = TMath::Min(xmin[i],x0);
145 xmax[i] = TMath::Max(xmax[i],x0);
150 for ( Int_t i = 0; i < dim; ++i )
152 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
160 //_____________________________________________________________________________
161 Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
164 if ( mustBePositive )
168 x = gRandom->Gaus(mean,sigma);
173 x = gRandom->Gaus(mean,sigma);
180 //_____________________________________________________________________________
181 Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
183 /// Check that OCDB path and run number are properly set
185 AliCDBManager* man = AliCDBManager::Instance();
188 if (!man->IsDefaultStorageSet()) {
189 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
193 // then run number if required
194 if (pathOnly) return kTRUE;
195 if (man->GetRun() < 0) {
196 AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
204 //_____________________________________________________________________________
205 Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
207 /// Check that the mapping has been loaded
209 // first the segmentation
210 if (!AliMpSegmentation::Instance(false)) {
211 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
215 // then the others if required
216 if (segmentationOnly) return kTRUE;
217 if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
218 AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
226 //_____________________________________________________________________________
227 Bool_t AliMUONCDB::LoadField()
229 /// Load magnetic field (existing field will be deleted).
230 /// OCDB path and run number are supposed to be set.
232 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
234 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
236 AliGRPManager grpMan;
238 // make sure the old field is deleted even if it is locked
239 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
241 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
242 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
250 //_____________________________________________________________________________
251 Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
253 /// Load mapping (existing mapping will be unloaded).
254 /// OCDB path and run number are supposed to be set.
256 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
258 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
260 // in case it has already been set
261 AliMpCDB::UnloadAll();
263 if (segmentationOnly) {
265 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
266 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
272 if (!AliMpCDB::LoadAll(kTRUE)) {
273 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
283 //_____________________________________________________________________________
284 AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
286 /// Load and return reconstruction parameters.
287 /// OCDB path is supposed to be set.
289 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
291 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
293 AliMUONRecoParam* recoParam = 0x0;
294 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
298 // load recoParam according OCDB content (single or array)
299 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
301 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
302 // recoParamArray->SetOwner(kTRUE); // FIXME: this should be done, but is causing a problem at the end of the reco... investigate why...
304 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
305 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
306 if (recoParam->IsDefault()) break;
314 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
320 //_____________________________________________________________________________
321 TClonesArray* AliMUONCDB::LoadAlignmentData()
323 /// Load and return the array of alignment objects.
325 AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
327 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
329 TClonesArray* alignmentArray = 0x0;
330 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
333 // load alignement array
334 alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
337 if (!alignmentArray) {
338 AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
341 return alignmentArray;
344 //_____________________________________________________________________________
346 AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
349 /// creates a store which contains store1-store2
350 /// if opt="abs" the difference is absolute one,
351 /// if opt="rel" then what is stored is (store1-store2)/store1
352 /// if opt="percent" then what is stored is rel*100
354 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
359 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
361 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
365 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
367 TIter next(d->CreateIterator());
369 AliMUONVCalibParam* param;
371 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
373 Int_t detElemId = param->ID0();
374 Int_t manuId = param->ID1();
376 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
377 //FIXME: this might happen. Handle it.
380 cerr << "param2 is null : FIXME : this might happen !" << endl;
385 for ( Int_t i = 0; i < param->Size(); ++i )
387 for ( Int_t j = 0; j < param->Dimension(); ++j )
390 if ( sopt.Contains("ABS") )
392 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
394 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
396 if ( param->ValueAsFloat(i,j) )
398 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
404 if ( sopt.Contains("PERCENT") ) value *= 100.0;
406 param->SetValueAsFloat(i,j,value);
413 //_____________________________________________________________________________
415 AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
417 /// Make histograms of each dimension of the AliMUONVCalibParam
418 /// contained inside store.
419 /// It produces histograms named name_0, name_1, etc...
421 if (!AliMUONCDB::CheckMapping(kTRUE)) return 0x0;
423 TIter next(store.CreateIterator());
424 AliMUONVCalibParam* param;
426 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
427 Int_t* nPerStation = new Int_t[kNStations];
430 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
432 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
436 Int_t dim = param->Dimension();
438 Float_t* xmin = new Float_t[dim];
439 Float_t* xmax = new Float_t[dim];
440 getBoundaries(store,dim,xmin,xmax);
442 for ( Int_t i = 0; i < dim; ++i )
444 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
445 nbins,xmin[i],xmax[i]);
446 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
452 Int_t detElemId = param->ID0();
453 Int_t manuId = param->ID1();
454 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
456 const AliMpVSegmentation* seg =
457 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
461 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
463 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
464 if (!pad.IsValid()) continue;
467 ++nPerStation[station];
469 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
471 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
476 for ( Int_t i = 0; i < kNStations; ++i )
478 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
481 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
483 delete[] nPerStation;
488 //_____________________________________________________________________________
490 AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
492 /// Create a HV store
494 if (!AliMUONCDB::CheckMapping()) return 0;
496 AliMpDCSNamer hvNamer("TRACKER");
498 TObjArray* aliases = hvNamer.GenerateAliases();
503 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
505 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
506 TString& aliasName = alias->String();
507 if ( aliasName.Contains("sw") )
509 // HV Switch (St345 only)
510 TObjArray* valueSet = new TObjArray;
511 valueSet->SetOwner(kTRUE);
513 Bool_t value = kTRUE;
517 Float_t r = gRandom->Uniform();
518 if ( r < 0.007 ) value = kFALSE;
521 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
523 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
524 valueSet->Add(dcsValue);
526 aliasMap.Add(new TObjString(*alias),valueSet);
531 TObjArray* valueSet = new TObjArray;
532 valueSet->SetOwner(kTRUE);
533 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
535 Float_t value = 1500;
536 if (!defaultValues) value = GetRandom(1750,62.5,true);
537 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
538 valueSet->Add(dcsValue);
540 aliasMap.Add(new TObjString(*alias),valueSet);
547 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
549 return nChannels+nSwitch;
552 //_____________________________________________________________________________
554 AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
556 /// Create a Trigger HV and Currents store
558 if (!AliMUONCDB::CheckMapping()) return 0;
560 AliMpDCSNamer triggerDCSNamer("TRIGGER");
562 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
564 Int_t nChannels[2] = {0, 0};
566 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
568 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
569 TString& aliasName = alias->String();
571 TObjArray* valueSet = new TObjArray;
572 valueSet->SetOwner(kTRUE);
574 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
575 if ( measureType < 0 ) {
576 AliErrorGeneralStream("AliMUONCDB")
577 << "Failed to get DCS variable from an alias (trigger): "
578 << aliasName.Data() << endl;
582 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
585 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
586 if (!defaultValues) {
587 switch (measureType){
588 case AliMpDCSNamer::kDCSI:
589 value = GetRandom(2.,0.4,true);
591 case AliMpDCSNamer::kDCSHV:
592 value = GetRandom(8000.,16.,true);
596 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
597 valueSet->Add(dcsValue);
599 aliasMap.Add(new TObjString(*alias),valueSet);
600 ++nChannels[measureType];
605 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
607 return nChannels[0] + nChannels[1];
610 //_____________________________________________________________________________
612 AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
614 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
615 /// otherwise mean and sigma are from a gaussian (with parameters
616 /// defined below by the kPedestal* constants)
618 AliCodeTimerAutoGeneral("",0);
620 if (!AliMUONCDB::CheckMapping()) return 0;
625 const Int_t kChannels(AliMpConstants::ManuNofChannels());
628 const Float_t kPedestalMeanMeanB(200.);
629 const Float_t kPedestalMeanSigmaB(10.);
630 const Float_t kPedestalSigmaMeanB(1.);
631 const Float_t kPedestalSigmaSigmaB(0.2);
634 const Float_t kPedestalMeanMeanNB(200.);
635 const Float_t kPedestalMeanSigmaNB(10.);
636 const Float_t kPedestalSigmaMeanNB(1.);
637 const Float_t kPedestalSigmaSigmaNB(0.2);
639 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
644 AliMpManuIterator it;
646 while ( it.Next(detElemId,manuId) )
648 // skip a given fraction of manus
649 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
653 AliMUONVCalibParam* ped =
654 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
656 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
658 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
660 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
664 Float_t meanPedestal;
665 Float_t sigmaPedestal;
674 Bool_t positive(kTRUE);
677 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
679 while ( meanPedestal == 0.0 ) // avoid strict zero
681 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
683 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
685 } else { // manu in bending plane
687 while ( meanPedestal == 0.0 ) // avoid strict zero
689 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
691 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
697 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
698 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
701 Bool_t ok = pedestalStore.Add(ped);
704 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
708 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
712 //_____________________________________________________________________________
714 AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
716 /// Create a reject list
718 AliCodeTimerAutoGeneral("",0);
720 AliMUONRejectList* rl = new AliMUONRejectList;
724 rl->SetDetectionElementProbability(510);
725 rl->SetDetectionElementProbability(508);
732 //_____________________________________________________________________________
734 AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
736 /// Create an occupancy map.
738 AliCodeTimerAutoGeneral("",0);
740 if (!AliMUONCDB::CheckMapping()) return 0;
747 AliMpManuIterator it;
751 while ( it.Next(detElemId,manuId) )
755 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
759 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
761 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
763 if (!defaultValues) occ = gRandom->Rndm(1);
765 Double_t sumn = occ*nevents;
767 occupancy->SetValueAsFloat(0,0,sumn);
768 occupancy->SetValueAsFloat(0,1,sumn);
769 occupancy->SetValueAsFloat(0,2,sumn);
770 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
771 occupancy->SetValueAsInt(0,4,nevents);
773 Bool_t ok = occupancyMapStore.Add(occupancy);
776 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
783 //_____________________________________________________________________________
785 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
787 /// Read the capacitance values from file and append them to the capaStore
789 if (!AliMUONCDB::CheckMapping()) return 0;
791 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
794 //_____________________________________________________________________________
796 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
798 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
799 /// otherwise they are from a gaussian with parameters defined in the
800 /// kCapa* constants below.
802 AliCodeTimerAutoGeneral("",0);
804 if (!AliMUONCDB::CheckMapping()) return 0;
808 Int_t nmanusOK(0); // manus for which we got the serial number
810 const Float_t kCapaMean(0.3);
811 const Float_t kCapaSigma(0.1);
812 const Float_t kInjectionGainMean(3);
813 const Float_t kInjectionGainSigma(1);
818 AliMpManuIterator it;
820 while ( it.Next(detElemId,manuId) )
824 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
825 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
827 if ( serialNumber <= 0 ) continue;
831 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
835 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
836 Bool_t ok = capaStore.Add(capa);
839 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
843 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
845 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
850 Float_t injectionGain;
859 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
860 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
862 capa->SetValueAsFloat(manuChannel,0,capaValue);
863 capa->SetValueAsFloat(manuChannel,1,injectionGain);
868 if ( nmanus ) percent = 100*nmanusOK/nmanus;
869 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
870 nmanusOK,nmanus,percent));
871 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
874 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
880 //_____________________________________________________________________________
882 AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
884 /// Create a gain store. if defaultValues=true, all gains set so that
885 /// charge = (adc-ped)
887 /// otherwise parameters are taken from gaussians with parameters
888 /// defined in the k* constants below.
890 AliCodeTimerAutoGeneral("",0);
892 if (!AliMUONCDB::CheckMapping()) return 0;
897 const Int_t kSaturation(3000);
898 const Double_t kA0Mean(1.2);
899 const Double_t kA0Sigma(0.1);
900 const Double_t kA1Mean(1E-5);
901 const Double_t kA1Sigma(1E-6);
902 const Double_t kQualMean(0xFF);
903 const Double_t kQualSigma(0x10);
904 const Int_t kThresMean(1600);
905 const Int_t kThresSigma(100);
910 AliMpManuIterator it;
912 while ( it.Next(detElemId,manuId) )
916 AliMUONVCalibParam* gain =
917 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
920 AliMUONVCalibParam::InvalidFloatValue());
922 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
924 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
926 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
932 gain->SetValueAsFloat(manuChannel,0,1.0);
933 gain->SetValueAsFloat(manuChannel,1,0.0);
934 gain->SetValueAsInt(manuChannel,2,4095);
935 gain->SetValueAsInt(manuChannel,3,1);
936 gain->SetValueAsInt(manuChannel,4,kSaturation);
940 Bool_t positive(kTRUE);
941 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
942 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
943 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
944 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
945 gain->SetValueAsInt(manuChannel,4,kSaturation);
949 Bool_t ok = gainStore.Add(gain);
952 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
956 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
960 //_____________________________________________________________________________
962 AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
964 /// Generate local trigger masks store. All masks are set to FFFF
966 AliCodeTimerAutoGeneral("",0);
969 // Generate fake mask values for all localboards and put that into
970 // one single container (localBoardMasks)
971 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
973 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
974 for ( Int_t x = 0; x < 2; ++x )
976 for ( Int_t y = 0; y < 4; ++y )
979 localBoard->SetValueAsInt(index,0,0xFFFF);
983 localBoardMasks.Add(localBoard);
988 //_____________________________________________________________________________
990 AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
992 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
994 AliCodeTimerAutoGeneral("",0);
996 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
997 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
1001 return rtm.GetNofTriggerCrates();
1005 //_____________________________________________________________________________
1007 AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
1009 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
1011 AliCodeTimerAutoGeneral("",0);
1013 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
1017 //_____________________________________________________________________________
1019 AliMUONCDB::MakeTriggerLUT(const char* file)
1021 /// Make a triggerlut object, from a file.
1023 AliCodeTimerAutoGeneral("",0);
1025 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1026 lut->ReadFromFile(file);
1030 //_____________________________________________________________________________
1031 AliMUONTriggerEfficiencyCells*
1032 AliMUONCDB::MakeTriggerEfficiency(const char* file)
1034 /// Make a trigger efficiency object from a file.
1036 AliCodeTimerAutoGeneral("",0);
1038 return new AliMUONTriggerEfficiencyCells(file);
1041 //_____________________________________________________________________________
1043 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1044 Int_t startRun, Int_t endRun,
1045 const char* filename)
1047 /// Write a given object to OCDB
1049 TString comment(gSystem->ExpandPathName(filename));
1051 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1054 //_____________________________________________________________________________
1056 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1057 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1059 /// Write a given object to OCDB
1062 if ( defaultValues ) comment += "Test with default values";
1063 else comment += "Test with random values";
1065 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1068 //_____________________________________________________________________________
1070 AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1071 const char* comment, const char* responsible)
1073 /// Write a given object to OCDB
1075 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1077 AliCDBId id(calibpath,startRun,endRun);
1079 md.SetAliRootVersion(gROOT->GetVersion());
1080 md.SetComment(comment);
1081 md.SetResponsible(responsible);
1082 AliCDBManager::Instance()->Put(object,id,&md);
1085 //_____________________________________________________________________________
1087 AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
1089 /// Fill the neighbours store with, for each channel, a TObjArray of its
1090 /// neighbouring pads (including itself)
1092 AliCodeTimerAutoGeneral("",0);
1094 if (!AliMUONCDB::CheckMapping()) return 0;
1096 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
1105 AliMpManuIterator it;
1107 while ( it.Next(detElemId,manuId) )
1109 const AliMpVSegmentation* seg =
1110 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1112 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
1115 Int_t dimension(11);
1116 Int_t size(AliMpConstants::ManuNofChannels());
1117 Int_t defaultValue(-1);
1118 Int_t packingFactor(size);
1120 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1121 Bool_t ok = neighbourStore.Add(calibParam);
1124 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
1129 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
1131 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
1137 seg->GetNeighbours(pad,tmp,true,true);
1138 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1140 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1142 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
1145 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
1148 // AliError("Could not pack value. Something is seriously wrong. Please check");
1149 // StdoutToAliError(pad->Print(););
1152 calibParam->SetValueAsInt(manuChannel,i,x);
1161 //_____________________________________________________________________________
1163 AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1165 /// Write local trigger masks to OCDB
1167 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
1168 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
1169 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1172 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1177 //_____________________________________________________________________________
1179 AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
1181 /// Write regional trigger masks to OCDB
1183 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1184 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
1185 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1188 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
1194 //_____________________________________________________________________________
1196 AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
1198 /// Write global trigger masks to OCDB
1200 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
1202 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
1203 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1206 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
1212 //_____________________________________________________________________________
1214 AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1216 /// Write trigger LUT to OCDB
1218 AliMUONTriggerLut* lut = MakeTriggerLUT();
1221 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1226 //_____________________________________________________________________________
1228 AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1230 /// Write trigger efficiency to OCDB
1232 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1235 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1240 //_____________________________________________________________________________
1242 AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1244 /// Write neighbours to OCDB
1246 AliMUONVStore* neighbours = Create2DMap();
1247 Int_t ngenerated = MakeNeighbourStore(*neighbours);
1248 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1251 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1256 //_____________________________________________________________________________
1258 AliMUONCDB::WriteHV(Bool_t defaultValues,
1259 Int_t startRun, Int_t endRun)
1261 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
1262 /// if defaultValues=false, see makeHVStore) and
1263 /// store them into CDB located at cdbpath, with a validity period
1264 /// ranging from startRun to endRun
1266 TMap* hvStore = new TMap;
1267 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
1268 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1271 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1276 //_____________________________________________________________________________
1278 AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1279 Int_t startRun, Int_t endRun)
1281 /// generate Trigger HV and current values (either const if defaultValues=true or random
1282 /// if defaultValues=false, see makeTriggerDCSStore) and
1283 /// store them into CDB located at cdbpath, with a validity period
1284 /// ranging from startRun to endRun
1286 TMap* triggerDCSStore = new TMap;
1287 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
1288 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1291 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1293 delete triggerDCSStore;
1296 //_____________________________________________________________________________
1298 AliMUONCDB::WritePedestals(Bool_t defaultValues,
1299 Int_t startRun, Int_t endRun)
1301 /// generate pedestal values (either 0 if defaultValues=true or random
1302 /// if defaultValues=false, see makePedestalStore) and
1303 /// store them into CDB located at cdbpath, with a validity period
1304 /// ranging from startRun to endRun
1306 AliMUONVStore* pedestalStore = Create2DMap();
1307 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
1308 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1309 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1310 delete pedestalStore;
1313 //_____________________________________________________________________________
1315 AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1316 Int_t startRun, Int_t endRun)
1318 /// generate occupancy map values (either empty one if defaultValues=true, or
1319 /// random one, see MakeOccupancyMapStore) and
1320 /// store them into CDB located at cdbpath, with a validity period
1321 /// ranging from startRun to endRun
1323 AliMUONVStore* occupancyMapStore = Create2DMap();
1324 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
1325 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1326 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1327 delete occupancyMapStore;
1330 //_____________________________________________________________________________
1332 AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1333 Int_t startRun, Int_t endRun)
1335 /// generate reject list values (either empty one if defaultValues=true, or
1336 /// random one, see MakeRejectListStore) and
1337 /// store them into CDB located at cdbpath, with a validity period
1338 /// ranging from startRun to endRun
1340 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1341 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1346 //_____________________________________________________________________________
1348 AliMUONCDB::WriteGains(Bool_t defaultValues,
1349 Int_t startRun, Int_t endRun)
1351 /// generate gain values (either 1 if defaultValues=true or random
1352 /// if defaultValues=false, see makeGainStore) and
1353 /// store them into CDB located at cdbpath, with a validity period
1354 /// ranging from startRun to endRun
1356 AliMUONVStore* gainStore = Create2DMap();
1357 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
1358 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1359 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1363 //_____________________________________________________________________________
1365 AliMUONCDB::WriteCapacitances(const char* filename,
1366 Int_t startRun, Int_t endRun)
1368 /// read manu capacitance and injection gain values from file
1369 /// and 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,filename);
1374 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1375 if ( ngenerated > 0 )
1377 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1382 //_____________________________________________________________________________
1384 AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1385 Int_t startRun, Int_t endRun)
1387 /// generate manu capacitance values (either 1 if defaultValues=true or random
1388 /// if defaultValues=false, see makeCapacitanceStore) and
1389 /// store them into CDB located at cdbpath, with a validity period
1390 /// ranging from startRun to endRun
1392 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1393 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
1394 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1395 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1399 //_____________________________________________________________________________
1401 AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1403 /// Writes all Trigger related calibration to CDB
1404 WriteTriggerDCS(defaultValues,startRun,endRun);
1405 WriteLocalTriggerMasks(startRun,endRun);
1406 WriteRegionalTriggerConfig(startRun,endRun);
1407 WriteGlobalTriggerConfig(startRun,endRun);
1408 WriteTriggerLut(startRun,endRun);
1409 WriteTriggerEfficiency(startRun,endRun);
1412 //_____________________________________________________________________________
1414 AliMUONCDB::WriteConfig(Int_t startRun, Int_t endRun)
1416 /// Write complete tracker configuration to OCDB
1417 ostringstream lines;
1418 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1420 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
1422 for (Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu)
1424 lines << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
1428 AliMUON2DMap config(kTRUE);
1430 AliMUONTrackerIO::DecodeConfig(lines.str().c_str(),config);
1432 WriteToCDB("MUON/Calib/Config",&config,startRun,endRun,kTRUE);
1435 //_____________________________________________________________________________
1437 AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1439 /// Writes all Tracker related calibration to CDB
1440 WriteHV(defaultValues,startRun,endRun);
1441 WritePedestals(defaultValues,startRun,endRun);
1442 WriteGains(defaultValues,startRun,endRun);
1443 WriteCapacitances(defaultValues,startRun,endRun);
1444 WriteNeighbours(startRun,endRun);
1445 WriteOccupancyMap(defaultValues,startRun,endRun);
1446 WriteRejectList(defaultValues,startRun,endRun);
1447 WriteConfig(startRun,endRun);
1450 //_____________________________________________________________________________
1452 AliMUONCDB::ShowCapacitances()
1454 /// Show briefly the number of capa values we have in the OCDB,
1455 /// and the list of manu that are actually in the config and for which
1456 /// we miss the capa (if any).
1458 if (!AliMUONCDB::CheckOCDB()) return;
1460 AliMUONCDB::LoadMapping();
1462 if (!AliMUONCDB::CheckMapping()) return;
1464 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1468 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1470 e = AliCDBManager::Instance()->Get("MUON/Calib/Capacitances");
1474 AliMUONVStore* capacitances = static_cast<AliMUONVStore*>(e->GetObject());
1476 AliInfoGeneral("ShowCapacitances",Form("%d capacitances are in OCDB",capacitances->GetSize()));
1478 TIter nextManu(config->CreateIterator());
1479 AliMUONVCalibParam* param;
1481 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1483 Int_t detElemId = param->ID0();
1484 Int_t manuId = param->ID1();
1487 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
1491 AliErrorGeneral("ShowCapacitances",Form("Did not find serial for DE %04d MANUID %04d",detElemId,manuId));
1495 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capacitances->FindObject(serialNumber));
1498 AliErrorGeneral("ShowCapacitances",Form("Did not find capacitance for DE %04d MANUID %04d SERIAL %d",detElemId,manuId,serialNumber));
1505 //_____________________________________________________________________________
1507 AliMUONCDB::ShowConfig(Bool_t withStatusMap)
1509 /// Dumps the current tracker configuration, i.e. number and identity of missing buspatches
1510 /// If statusMap is true, will also take into account the status map to report the number
1511 /// of good channels
1513 if (!AliMUONCDB::CheckOCDB()) return;
1515 AliMUONCDB::LoadMapping();
1517 if (!AliMUONCDB::CheckMapping()) return;
1519 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1523 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1525 AliMUONPadStatusMapMaker* statusMapMaker(0x0);
1526 AliMUONCalibrationData* cd(0x0);
1527 AliMUONPadStatusMaker* statusMaker(0x0);
1529 if ( withStatusMap )
1531 cd = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
1533 statusMaker = new AliMUONPadStatusMaker(*cd);
1535 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
1537 statusMaker->SetLimits(*recoParam);
1539 UInt_t mask = recoParam->PadGoodnessMask();
1543 const Bool_t deferredInitialization = kFALSE;
1545 statusMapMaker = new AliMUONPadStatusMapMaker(*cd,mask,deferredInitialization);
1548 TIter nextManu(config->CreateIterator());
1549 AliMUONVCalibParam* param;
1551 AliMpExMap buspatches;
1553 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1555 Int_t detElemId = param->ID0();
1556 Int_t manuId = param->ID1();
1557 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1558 if ( buspatches.GetValue(busPatchId) == 0x0 )
1560 buspatches.Add(busPatchId,new TObjString(Form("BP%04d",busPatchId)));
1564 TArrayI removed(buspatches.GetSize());
1566 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1572 // accounting of bus patches first
1574 while ( ( bp = static_cast<AliMpBusPatch*>(next())))
1576 if ( buspatches.GetValue(bp->GetId()) )
1582 removed.SetAt(bp->GetId(),nremoved++);
1586 // accounting of channels
1588 AliMpManuIterator it;
1590 Int_t totalNumberOfChannels(0);
1591 Int_t removedChannels(0);
1592 Int_t badChannels(0);
1593 Int_t badAndRemovedChannels(0);
1594 Int_t badOrRemovedChannels(0);
1596 Int_t detElemId, manuId;
1598 while ( it.Next(detElemId,manuId) )
1600 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1601 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
1603 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1605 if ( de->IsConnectedChannel(manuId,i) )
1607 ++totalNumberOfChannels;
1608 Bool_t badBusPatch = ( buspatches.GetValue(busPatchId) == 0x0 );
1610 if ( withStatusMap )
1612 Bool_t badChannel = ( ( statusMapMaker->StatusMap(detElemId,manuId,i) & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0);
1613 if ( badChannel ) ++badChannels;
1614 if ( badBusPatch && badChannel ) ++badAndRemovedChannels;
1615 if ( badBusPatch || badChannel ) ++badOrRemovedChannels;
1618 if ( badBusPatch) ++removedChannels;
1624 Int_t* indices = new Int_t[nremoved];
1626 TMath::Sort(nremoved,removed.GetArray(),indices,kFALSE);
1628 for ( Int_t i = 0; i < nremoved; ++i )
1630 Int_t busPatchId = removed[indices[i]];
1631 bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1638 cout << Form("Bus patches n=%3d nok=%3d nremoved=%3d",n,nok,nremoved) << endl;
1640 cout << Form("Channels n=%6d nremoved=%6d bad=%6d bad and removed=%6d bad or removed=%6d",
1641 totalNumberOfChannels,removedChannels,badChannels,badAndRemovedChannels,badOrRemovedChannels) << endl;
1643 if (totalNumberOfChannels>0)
1645 cout << Form("Percentage of readout channels %5.1f %%",removedChannels*100.0/totalNumberOfChannels) << endl;
1646 if ( withStatusMap )
1648 cout << Form("Percentage of non useable channels (bad or removed) %5.1f %%",
1649 badOrRemovedChannels*100.0/totalNumberOfChannels) << endl;
1654 delete statusMapMaker;
1659 //______________________________________________________________________________
1660 void AliMUONCDB::ReadIntegers(const char* filename, std::vector<int>& integers)
1662 /// Read integers from filename, where integers are either
1663 /// separated by "," or by return carriage
1664 ifstream in(gSystem->ExpandPathName(filename));
1667 std::set<int> runset;
1671 in.getline(line,10000,'\n');
1673 TString sline(line);
1675 if (sline.Contains(","))
1677 TObjArray* a = sline.Tokenize(",");
1680 while ( ( s = static_cast<TObjString*>(next()) ) )
1682 runset.insert(s->String().Atoi());
1688 runset.insert(sline.Atoi());
1696 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
1698 integers.push_back((*it));
1701 std::sort(integers.begin(),integers.end());
1704 //______________________________________________________________________________
1705 void AliMUONCDB::ShowFaultyBusPatches(const char* runlist, double occLimit,
1706 const char* outputBaseName,
1707 const char* ocdbPath)
1709 /// Shows the list of bus patches above a given occupancy limit,
1710 /// for each run in the runlist
1712 AliLog::GetRootLogger()->SetGlobalLogLevel(AliLog::kError);
1714 // AliLog::SetPrintType(AliLog::kInfo,kFALSE);
1715 // AliLog::SetPrintType(AliLog::kWarning,kFALSE);
1716 // gErrorIgnoreLevel=kError; // to avoid all the TAlienFile::Open messages...
1718 AliCDBManager* man = AliCDBManager::Instance();
1720 man->SetDefaultStorage(ocdbPath);
1722 Bool_t first(kTRUE);
1724 std::vector<int> runnumbers;
1726 ReadIntegers(runlist,runnumbers);
1728 AliMUON2DMap bpValues(kFALSE);
1730 std::ofstream outfile(Form("%s.txt",outputBaseName));
1732 for ( unsigned int i = 0 ; i < runnumbers.size(); ++i )
1734 int runNumber = runnumbers[i];
1736 man->SetRun(runNumber);
1740 AliMpCDB::LoadAll();
1744 AliCDBEntry* e = man->Get("MUON/Calib/OccupancyMap",runNumber);
1748 AliErrorGeneral("AliMUONCDB::ShowFaultyBusPatches",
1749 Form("Could not get OccupancyMap for run %09d",runNumber));
1753 AliMUONVStore* occmap = static_cast<AliMUONVStore*>(e->GetObject());
1755 AliMUONTrackerData td("occ","occ",*occmap);
1757 TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1759 std::set<int> buspatches;
1760 Double_t sumn = 1000.0;
1762 while ( ( bp = static_cast<AliMpBusPatch*>(nextBP()) ) )
1764 Double_t occ = td.BusPatch(bp->GetId(),2);
1768 buspatches.insert(bp->GetId());
1770 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(bpValues.FindObject(bp->GetId()));
1774 param = new AliMUONCalibParamND(5, 1, bp->GetId(), 0);
1775 bpValues.Add(param);
1777 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(bp->GetId());
1778 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1782 for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
1784 Int_t manuId = bp->GetManuId(imanu);
1785 nchannels += de->NofChannelsInManu(manuId);
1788 param->SetValueAsDouble(0,2,sumn);
1789 param->SetValueAsDouble(0,3,nchannels);
1790 param->SetValueAsDouble(0,4,1);
1793 Double_t sumw = sumn*(param->ValueAsDouble(0)/sumn+1.0/runnumbers.size());
1794 Double_t sumw2 = 0.0; //(sumn-1)*ey*ey+sumw*sumw/sumn;
1796 param->SetValueAsDouble(0,0,sumw);
1797 param->SetValueAsDouble(0,1,sumw2);
1802 outfile << Form("RUN %09d",runNumber);
1804 for ( std::set<int>::const_iterator bit = buspatches.begin(); bit != buspatches.end(); ++bit )
1806 outfile << Form(" %4d",*bit);
1813 const char* name = "BPfailureRate";
1815 AliMUONTrackerData* mpData = new AliMUONTrackerData(name,name,bpValues,2);
1816 mpData->SetDimensionName(0,name);
1818 TFile f(Form("%s.root",outputBaseName),"recreate");
1822 cout << Form("Results are in %s.txt and %s.root",outputBaseName,outputBaseName) << endl;
1824 gSystem->Exec(Form("cat %s.txt",outputBaseName));
1828 //______________________________________________________________________________
1829 void AliMUONCDB::CheckHV(Int_t runNumber, Int_t verbose)
1831 /// Check the HV values in OCDB for a given run
1834 messages.SetOwner(kTRUE);
1836 Bool_t patched(kTRUE);
1838 if (!AliCDBManager::Instance()->IsDefaultStorageSet())
1840 AliCDBManager::Instance()->SetDefaultStorage("raw://");
1843 AliCDBManager::Instance()->SetRun(runNumber);
1847 AliMUONCalibrationData::CreateHV(runNumber,0,patched,&messages);
1849 AliMUONCalibrationData cd(runNumber,true);
1851 AliMUONPadStatusMaker statusMaker(cd);
1853 AliMUONRecoParam* rp = AliMUONCDB::LoadRecoParam();
1857 AliErrorGeneral("AliMUONCDB::CheckHV","Could not get RecoParam !!!");
1861 statusMaker.SetLimits(*rp);
1863 TIter next(&messages);
1865 AliMpDCSNamer hvNamer("TRACKER");
1868 while ( ( s = static_cast<TObjString*>(next()) ) )
1870 TObjArray* a = s->String().Tokenize(":");
1872 TString name(static_cast<TObjString*>(a->At(0))->String());
1874 if ( name.Contains("sw") || name.Contains("SUMMARY") ) continue;
1876 Int_t index = hvNamer.DCSIndexFromDCSAlias(name.Data());
1878 Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
1880 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1884 AliErrorGeneral("AliMUONCDB::CheckHV",Form("Could not get detElemId from dcsAlias %s",name.Data()));
1892 const AliMpArrayI* array = de->ManusForHV(index);
1893 manuId = array->GetValue(0);
1898 AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(de->GetBusPatchId(0));
1900 manuId = bp->GetManuId(0);
1903 Int_t status = statusMaker.HVStatus(detElemId,manuId);
1905 log.Log(AliMUONPadStatusMaker::AsString(status).Data());
1907 s->String() += Form(" (DE %4d) ",detElemId);
1908 s->String() += AliMUONPadStatusMaker::AsString(status).Data();
1913 TIter nextMessage(&messages);
1916 while ( ( msg = static_cast<TObjString*>(nextMessage()) ) )
1918 if ( verbose > 0 || msg->String().Contains("SUMMARY") )
1920 AliInfoGeneral("AliMUONCDB::CheckHV",Form("RUN %09d HVchannel %s",runNumber,msg->String().Data()));
1928 while (log.Next(lmsg,occurance))
1930 totalLog += Form("%s(%d)",lmsg.Data(),occurance);
1934 AliInfoGeneral("AliMUONCDB::CheckHV",Form("RUN %09d %s",runNumber,totalLog.Data()));
1936 // one last loop to get the list of problematic HV channels
1937 nextMessage.Reset();
1939 while ( ( msg = static_cast<TObjString*>(nextMessage()) ) )
1941 if ( msg->String().Contains("HV ") )
1943 AliInfoGeneral("AliMUONCDB::CheckHV",Form(" Problem at %s",msg->String().Data()));
1947 AliCDBManager::Instance()->ClearCache();