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>
103 using std::ostringstream;
108 //_____________________________________________________________________________
109 AliMUONVStore* Create2DMap()
111 return new AliMUON2DMap(true);
114 //_____________________________________________________________________________
115 void getBoundaries(const AliMUONVStore& store, Int_t dim,
116 Float_t* xmin, Float_t* xmax)
118 /// Assuming the store contains AliMUONVCalibParam objects, compute the
119 /// limits of the value contained in the VCalibParam, for each of its dimensions
120 /// xmin and xmax must be of dimension dim
122 for ( Int_t i = 0; i < dim; ++i )
128 TIter next(store.CreateIterator());
129 AliMUONVCalibParam* value;
131 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
133 Int_t detElemId = value->ID0();
134 Int_t manuId = value->ID1();
136 const AliMpVSegmentation* seg =
137 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
141 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
143 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
144 if (!pad.IsValid()) continue;
146 for ( Int_t i = 0; i < dim; ++i )
148 Float_t x0 = value->ValueAsFloat(manuChannel,i);
150 xmin[i] = TMath::Min(xmin[i],x0);
151 xmax[i] = TMath::Max(xmax[i],x0);
156 for ( Int_t i = 0; i < dim; ++i )
158 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
166 //_____________________________________________________________________________
167 Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
170 if ( mustBePositive )
174 x = gRandom->Gaus(mean,sigma);
179 x = gRandom->Gaus(mean,sigma);
186 //_____________________________________________________________________________
187 Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
189 /// Check that OCDB path and run number are properly set
191 AliCDBManager* man = AliCDBManager::Instance();
194 if (!man->IsDefaultStorageSet()) {
195 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
199 // then run number if required
200 if (pathOnly) return kTRUE;
201 if (man->GetRun() < 0) {
202 AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
210 //_____________________________________________________________________________
211 Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
213 /// Check that the mapping has been loaded
215 // first the segmentation
216 if (!AliMpSegmentation::Instance(false)) {
217 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
221 // then the others if required
222 if (segmentationOnly) return kTRUE;
223 if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
224 AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
232 //_____________________________________________________________________________
233 Bool_t AliMUONCDB::LoadField()
235 /// Load magnetic field (existing field will be deleted).
236 /// OCDB path and run number are supposed to be set.
238 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
240 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
242 AliGRPManager grpMan;
244 // make sure the old field is deleted even if it is locked
245 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
247 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
248 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
256 //_____________________________________________________________________________
257 Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
259 /// Load mapping (existing mapping will be unloaded).
260 /// OCDB path and run number are supposed to be set.
262 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
264 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
266 // in case it has already been set
267 AliMpCDB::UnloadAll();
269 if (segmentationOnly) {
271 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
272 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
278 if (!AliMpCDB::LoadAll(kTRUE)) {
279 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
289 //_____________________________________________________________________________
290 AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
292 /// Load and return reconstruction parameters.
293 /// OCDB path is supposed to be set.
295 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
297 if (!AliMUONCDB::CheckOCDB()) return 0x0;
299 AliMUONRecoParam* recoParam = 0x0;
300 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
304 // load recoParam according OCDB content (single or array)
305 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
307 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
308 // recoParamArray->SetOwner(kTRUE); // FIXME: this should be done, but is causing a problem at the end of the reco... investigate why...
310 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
311 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
312 if (recoParam->IsDefault()) break;
320 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
326 //_____________________________________________________________________________
327 TClonesArray* AliMUONCDB::LoadAlignmentData()
329 /// Load and return the array of alignment objects.
331 AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
333 if (!AliMUONCDB::CheckOCDB()) return 0x0;
335 TClonesArray* alignmentArray = 0x0;
336 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
339 // load alignement array
340 alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
343 if (!alignmentArray) {
344 AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
347 return alignmentArray;
350 //_____________________________________________________________________________
352 AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
355 /// creates a store which contains store1-store2
356 /// if opt="abs" the difference is absolute one,
357 /// if opt="rel" then what is stored is (store1-store2)/store1
358 /// if opt="percent" then what is stored is rel*100
360 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
365 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
367 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
371 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
373 TIter next(d->CreateIterator());
375 AliMUONVCalibParam* param;
377 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
379 Int_t detElemId = param->ID0();
380 Int_t manuId = param->ID1();
382 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
383 //FIXME: this might happen. Handle it.
386 cerr << "param2 is null : FIXME : this might happen !" << endl;
391 for ( Int_t i = 0; i < param->Size(); ++i )
393 for ( Int_t j = 0; j < param->Dimension(); ++j )
396 if ( sopt.Contains("ABS") )
398 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
400 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
402 if ( param->ValueAsFloat(i,j) )
404 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
410 if ( sopt.Contains("PERCENT") ) value *= 100.0;
412 param->SetValueAsFloat(i,j,value);
419 //_____________________________________________________________________________
421 AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
423 /// Make histograms of each dimension of the AliMUONVCalibParam
424 /// contained inside store.
425 /// It produces histograms named name_0, name_1, etc...
427 if (!AliMUONCDB::CheckMapping(kTRUE)) return 0x0;
429 TIter next(store.CreateIterator());
430 AliMUONVCalibParam* param;
432 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
433 Int_t* nPerStation = new Int_t[kNStations];
436 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
438 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
442 Int_t dim = param->Dimension();
444 Float_t* xmin = new Float_t[dim];
445 Float_t* xmax = new Float_t[dim];
446 getBoundaries(store,dim,xmin,xmax);
448 for ( Int_t i = 0; i < dim; ++i )
450 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
451 nbins,xmin[i],xmax[i]);
452 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
458 Int_t detElemId = param->ID0();
459 Int_t manuId = param->ID1();
460 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
462 const AliMpVSegmentation* seg =
463 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
467 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
469 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
470 if (!pad.IsValid()) continue;
473 ++nPerStation[station];
475 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
477 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
482 for ( Int_t i = 0; i < kNStations; ++i )
484 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
487 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
489 delete[] nPerStation;
494 //_____________________________________________________________________________
496 AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
498 /// Create a HV store
500 if (!AliMUONCDB::CheckMapping()) return 0;
502 AliMpDCSNamer hvNamer("TRACKER");
504 TObjArray* aliases = hvNamer.GenerateAliases();
509 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
511 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
512 TString& aliasName = alias->String();
513 if ( aliasName.Contains("sw") )
515 // HV Switch (St345 only)
516 TObjArray* valueSet = new TObjArray;
517 valueSet->SetOwner(kTRUE);
519 Bool_t value = kTRUE;
523 Float_t r = gRandom->Uniform();
524 if ( r < 0.007 ) value = kFALSE;
527 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
529 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
530 valueSet->Add(dcsValue);
532 aliasMap.Add(new TObjString(*alias),valueSet);
537 TObjArray* valueSet = new TObjArray;
538 valueSet->SetOwner(kTRUE);
539 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
541 Float_t value = 1500;
542 if (!defaultValues) value = GetRandom(1750,62.5,true);
543 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
544 valueSet->Add(dcsValue);
546 aliasMap.Add(new TObjString(*alias),valueSet);
553 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
555 return nChannels+nSwitch;
558 //_____________________________________________________________________________
560 AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
562 /// Create a Trigger HV and Currents store
564 if (!AliMUONCDB::CheckMapping()) return 0;
566 AliMpDCSNamer triggerDCSNamer("TRIGGER");
568 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
570 Int_t nChannels[2] = {0, 0};
572 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
574 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
575 TString& aliasName = alias->String();
577 TObjArray* valueSet = new TObjArray;
578 valueSet->SetOwner(kTRUE);
580 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
581 if ( measureType < 0 ) {
582 AliErrorGeneralStream("AliMUONCDB")
583 << "Failed to get DCS variable from an alias (trigger): "
584 << aliasName.Data() << endl;
588 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
591 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
592 if (!defaultValues) {
593 switch (measureType){
594 case AliMpDCSNamer::kDCSI:
595 value = GetRandom(2.,0.4,true);
597 case AliMpDCSNamer::kDCSHV:
598 value = GetRandom(8000.,16.,true);
602 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
603 valueSet->Add(dcsValue);
605 aliasMap.Add(new TObjString(*alias),valueSet);
606 ++nChannels[measureType];
611 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
613 return nChannels[0] + nChannels[1];
616 //_____________________________________________________________________________
618 AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
620 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
621 /// otherwise mean and sigma are from a gaussian (with parameters
622 /// defined below by the kPedestal* constants)
624 AliCodeTimerAutoGeneral("",0);
626 if (!AliMUONCDB::CheckMapping()) return 0;
631 const Int_t kChannels(AliMpConstants::ManuNofChannels());
634 const Float_t kPedestalMeanMeanB(200.);
635 const Float_t kPedestalMeanSigmaB(10.);
636 const Float_t kPedestalSigmaMeanB(1.);
637 const Float_t kPedestalSigmaSigmaB(0.2);
640 const Float_t kPedestalMeanMeanNB(200.);
641 const Float_t kPedestalMeanSigmaNB(10.);
642 const Float_t kPedestalSigmaMeanNB(1.);
643 const Float_t kPedestalSigmaSigmaNB(0.2);
645 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
650 AliMpManuIterator it;
652 while ( it.Next(detElemId,manuId) )
654 // skip a given fraction of manus
655 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
659 AliMUONVCalibParam* ped =
660 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
662 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
664 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
666 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
670 Float_t meanPedestal;
671 Float_t sigmaPedestal;
680 Bool_t positive(kTRUE);
683 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
685 while ( meanPedestal == 0.0 ) // avoid strict zero
687 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
689 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
691 } else { // manu in bending plane
693 while ( meanPedestal == 0.0 ) // avoid strict zero
695 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
697 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
703 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
704 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
707 Bool_t ok = pedestalStore.Add(ped);
710 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
714 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
718 //_____________________________________________________________________________
720 AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
722 /// Create a reject list
724 AliCodeTimerAutoGeneral("",0);
726 AliMUONRejectList* rl = new AliMUONRejectList;
730 rl->SetDetectionElementProbability(510);
731 rl->SetDetectionElementProbability(508);
738 //_____________________________________________________________________________
740 AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
742 /// Create an occupancy map.
744 AliCodeTimerAutoGeneral("",0);
746 if (!AliMUONCDB::CheckMapping()) return 0;
753 AliMpManuIterator it;
757 while ( it.Next(detElemId,manuId) )
761 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
765 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
767 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
769 if (!defaultValues) occ = gRandom->Rndm(1);
771 Double_t sumn = occ*nevents;
773 occupancy->SetValueAsFloat(0,0,sumn);
774 occupancy->SetValueAsFloat(0,1,sumn);
775 occupancy->SetValueAsFloat(0,2,sumn);
776 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
777 occupancy->SetValueAsInt(0,4,nevents);
779 Bool_t ok = occupancyMapStore.Add(occupancy);
782 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
789 //_____________________________________________________________________________
791 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
793 /// Read the capacitance values from file and append them to the capaStore
795 if (!AliMUONCDB::CheckMapping()) return 0;
797 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
800 //_____________________________________________________________________________
802 AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
804 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
805 /// otherwise they are from a gaussian with parameters defined in the
806 /// kCapa* constants below.
808 AliCodeTimerAutoGeneral("",0);
810 if (!AliMUONCDB::CheckMapping()) return 0;
814 Int_t nmanusOK(0); // manus for which we got the serial number
816 const Float_t kCapaMean(0.3);
817 const Float_t kCapaSigma(0.1);
818 const Float_t kInjectionGainMean(3);
819 const Float_t kInjectionGainSigma(1);
824 AliMpManuIterator it;
826 while ( it.Next(detElemId,manuId) )
830 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
831 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
833 if ( serialNumber <= 0 ) continue;
837 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
841 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
842 Bool_t ok = capaStore.Add(capa);
845 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
849 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
851 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
856 Float_t injectionGain;
865 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
866 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
868 capa->SetValueAsFloat(manuChannel,0,capaValue);
869 capa->SetValueAsFloat(manuChannel,1,injectionGain);
874 if ( nmanus ) percent = 100*nmanusOK/nmanus;
875 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
876 nmanusOK,nmanus,percent));
877 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
880 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
886 //_____________________________________________________________________________
888 AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
890 /// Create a gain store. if defaultValues=true, all gains set so that
891 /// charge = (adc-ped)
893 /// otherwise parameters are taken from gaussians with parameters
894 /// defined in the k* constants below.
896 AliCodeTimerAutoGeneral("",0);
898 if (!AliMUONCDB::CheckMapping()) return 0;
903 const Int_t kSaturation(3000);
904 const Double_t kA0Mean(1.2);
905 const Double_t kA0Sigma(0.1);
906 const Double_t kA1Mean(1E-5);
907 const Double_t kA1Sigma(1E-6);
908 const Double_t kQualMean(0xFF);
909 const Double_t kQualSigma(0x10);
910 const Int_t kThresMean(1600);
911 const Int_t kThresSigma(100);
916 AliMpManuIterator it;
918 while ( it.Next(detElemId,manuId) )
922 AliMUONVCalibParam* gain =
923 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
926 AliMUONVCalibParam::InvalidFloatValue());
928 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
930 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
932 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
938 gain->SetValueAsFloat(manuChannel,0,1.0);
939 gain->SetValueAsFloat(manuChannel,1,0.0);
940 gain->SetValueAsInt(manuChannel,2,4095);
941 gain->SetValueAsInt(manuChannel,3,1);
942 gain->SetValueAsInt(manuChannel,4,kSaturation);
946 Bool_t positive(kTRUE);
947 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
948 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
949 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
950 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
951 gain->SetValueAsInt(manuChannel,4,kSaturation);
955 Bool_t ok = gainStore.Add(gain);
958 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
962 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
966 //_____________________________________________________________________________
968 AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
970 /// Generate local trigger masks store. All masks are set to FFFF
972 AliCodeTimerAutoGeneral("",0);
975 // Generate fake mask values for all localboards and put that into
976 // one single container (localBoardMasks)
977 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
979 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
980 for ( Int_t x = 0; x < 2; ++x )
982 for ( Int_t y = 0; y < 4; ++y )
985 localBoard->SetValueAsInt(index,0,0xFFFF);
989 localBoardMasks.Add(localBoard);
994 //_____________________________________________________________________________
996 AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
998 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
1000 AliCodeTimerAutoGeneral("",0);
1002 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
1003 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
1007 return rtm.GetNofTriggerCrates();
1011 //_____________________________________________________________________________
1013 AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
1015 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
1017 AliCodeTimerAutoGeneral("",0);
1019 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
1023 //_____________________________________________________________________________
1025 AliMUONCDB::MakeTriggerLUT(const char* file)
1027 /// Make a triggerlut object, from a file.
1029 AliCodeTimerAutoGeneral("",0);
1031 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1032 lut->ReadFromFile(file);
1036 //_____________________________________________________________________________
1037 AliMUONTriggerEfficiencyCells*
1038 AliMUONCDB::MakeTriggerEfficiency(const char* file)
1040 /// Make a trigger efficiency object from a file.
1042 AliCodeTimerAutoGeneral("",0);
1044 return new AliMUONTriggerEfficiencyCells(file);
1047 //_____________________________________________________________________________
1049 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1050 Int_t startRun, Int_t endRun,
1051 const char* filename)
1053 /// Write a given object to OCDB
1055 TString comment(gSystem->ExpandPathName(filename));
1057 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1060 //_____________________________________________________________________________
1062 AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
1063 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1065 /// Write a given object to OCDB
1068 if ( defaultValues ) comment += "Test with default values";
1069 else comment += "Test with random values";
1071 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1074 //_____________________________________________________________________________
1076 AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1077 const char* comment, const char* responsible)
1079 /// Write a given object to OCDB
1081 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1083 AliCDBId id(calibpath,startRun,endRun);
1085 md.SetAliRootVersion(gROOT->GetVersion());
1086 md.SetComment(comment);
1087 md.SetResponsible(responsible);
1088 AliCDBManager::Instance()->Put(object,id,&md);
1091 //_____________________________________________________________________________
1093 AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
1095 /// Fill the neighbours store with, for each channel, a TObjArray of its
1096 /// neighbouring pads (including itself)
1098 AliCodeTimerAutoGeneral("",0);
1100 if (!AliMUONCDB::CheckMapping()) return 0;
1102 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
1111 AliMpManuIterator it;
1113 while ( it.Next(detElemId,manuId) )
1115 const AliMpVSegmentation* seg =
1116 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1118 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
1121 Int_t dimension(11);
1122 Int_t size(AliMpConstants::ManuNofChannels());
1123 Int_t defaultValue(-1);
1124 Int_t packingFactor(size);
1126 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1127 Bool_t ok = neighbourStore.Add(calibParam);
1130 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
1135 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
1137 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
1143 seg->GetNeighbours(pad,tmp,true,true);
1144 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1146 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1148 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
1151 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
1154 // AliError("Could not pack value. Something is seriously wrong. Please check");
1155 // StdoutToAliError(pad->Print(););
1158 calibParam->SetValueAsInt(manuChannel,i,x);
1167 //_____________________________________________________________________________
1169 AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1171 /// Write local trigger masks to OCDB
1173 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
1174 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
1175 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1178 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1183 //_____________________________________________________________________________
1185 AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
1187 /// Write regional trigger masks to OCDB
1189 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1190 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
1191 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1194 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
1200 //_____________________________________________________________________________
1202 AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
1204 /// Write global trigger masks to OCDB
1206 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
1208 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
1209 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1212 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
1218 //_____________________________________________________________________________
1220 AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1222 /// Write trigger LUT to OCDB
1224 AliMUONTriggerLut* lut = MakeTriggerLUT();
1227 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1232 //_____________________________________________________________________________
1234 AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1236 /// Write trigger efficiency to OCDB
1238 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1241 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1246 //_____________________________________________________________________________
1248 AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1250 /// Write neighbours to OCDB
1252 AliMUONVStore* neighbours = Create2DMap();
1253 Int_t ngenerated = MakeNeighbourStore(*neighbours);
1254 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1257 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1262 //_____________________________________________________________________________
1264 AliMUONCDB::WriteHV(Bool_t defaultValues,
1265 Int_t startRun, Int_t endRun)
1267 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
1268 /// if defaultValues=false, see makeHVStore) and
1269 /// store them into CDB located at cdbpath, with a validity period
1270 /// ranging from startRun to endRun
1272 TMap* hvStore = new TMap;
1273 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
1274 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1277 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1282 //_____________________________________________________________________________
1284 AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1285 Int_t startRun, Int_t endRun)
1287 /// generate Trigger HV and current values (either const if defaultValues=true or random
1288 /// if defaultValues=false, see makeTriggerDCSStore) and
1289 /// store them into CDB located at cdbpath, with a validity period
1290 /// ranging from startRun to endRun
1292 TMap* triggerDCSStore = new TMap;
1293 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
1294 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1297 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1299 delete triggerDCSStore;
1302 //_____________________________________________________________________________
1304 AliMUONCDB::WritePedestals(Bool_t defaultValues,
1305 Int_t startRun, Int_t endRun)
1307 /// generate pedestal values (either 0 if defaultValues=true or random
1308 /// if defaultValues=false, see makePedestalStore) and
1309 /// store them into CDB located at cdbpath, with a validity period
1310 /// ranging from startRun to endRun
1312 AliMUONVStore* pedestalStore = Create2DMap();
1313 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
1314 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1315 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1316 delete pedestalStore;
1319 //_____________________________________________________________________________
1321 AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1322 Int_t startRun, Int_t endRun)
1324 /// generate occupancy map values (either empty one if defaultValues=true, or
1325 /// random one, see MakeOccupancyMapStore) and
1326 /// store them into CDB located at cdbpath, with a validity period
1327 /// ranging from startRun to endRun
1329 AliMUONVStore* occupancyMapStore = Create2DMap();
1330 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
1331 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1332 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1333 delete occupancyMapStore;
1336 //_____________________________________________________________________________
1338 AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1339 Int_t startRun, Int_t endRun)
1341 /// generate reject list values (either empty one if defaultValues=true, or
1342 /// random one, see MakeRejectListStore) and
1343 /// store them into CDB located at cdbpath, with a validity period
1344 /// ranging from startRun to endRun
1346 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1347 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1352 //_____________________________________________________________________________
1354 AliMUONCDB::WriteGains(Bool_t defaultValues,
1355 Int_t startRun, Int_t endRun)
1357 /// generate gain values (either 1 if defaultValues=true or random
1358 /// if defaultValues=false, see makeGainStore) and
1359 /// store them into CDB located at cdbpath, with a validity period
1360 /// ranging from startRun to endRun
1362 AliMUONVStore* gainStore = Create2DMap();
1363 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
1364 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1365 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1369 //_____________________________________________________________________________
1371 AliMUONCDB::WriteCapacitances(const char* filename,
1372 Int_t startRun, Int_t endRun)
1374 /// read manu capacitance and injection gain values from file
1375 /// and store them into CDB located at cdbpath, with a validity period
1376 /// ranging from startRun to endRun
1378 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1379 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
1380 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1381 if ( ngenerated > 0 )
1383 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1388 //_____________________________________________________________________________
1390 AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1391 Int_t startRun, Int_t endRun)
1393 /// generate manu capacitance values (either 1 if defaultValues=true or random
1394 /// if defaultValues=false, see makeCapacitanceStore) and
1395 /// store them into CDB located at cdbpath, with a validity period
1396 /// ranging from startRun to endRun
1398 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1399 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
1400 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
1401 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1405 //_____________________________________________________________________________
1407 AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1409 /// Writes all Trigger related calibration to CDB
1410 WriteTriggerDCS(defaultValues,startRun,endRun);
1411 WriteLocalTriggerMasks(startRun,endRun);
1412 WriteRegionalTriggerConfig(startRun,endRun);
1413 WriteGlobalTriggerConfig(startRun,endRun);
1414 WriteTriggerLut(startRun,endRun);
1415 WriteTriggerEfficiency(startRun,endRun);
1418 //_____________________________________________________________________________
1420 AliMUONCDB::WriteConfig(Int_t startRun, Int_t endRun)
1422 /// Write complete tracker configuration to OCDB
1423 ostringstream lines;
1424 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1426 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
1428 for (Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu)
1430 lines << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
1434 AliMUON2DMap config(kTRUE);
1436 AliMUONTrackerIO::DecodeConfig(lines.str().c_str(),config);
1438 WriteToCDB("MUON/Calib/Config",&config,startRun,endRun,kTRUE);
1441 //_____________________________________________________________________________
1443 AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1445 /// Writes all Tracker related calibration to CDB
1446 WriteHV(defaultValues,startRun,endRun);
1447 WritePedestals(defaultValues,startRun,endRun);
1448 WriteGains(defaultValues,startRun,endRun);
1449 WriteCapacitances(defaultValues,startRun,endRun);
1450 WriteNeighbours(startRun,endRun);
1451 WriteOccupancyMap(defaultValues,startRun,endRun);
1452 WriteRejectList(defaultValues,startRun,endRun);
1453 WriteConfig(startRun,endRun);
1456 //_____________________________________________________________________________
1458 AliMUONCDB::ShowCapacitances()
1460 /// Show briefly the number of capa values we have in the OCDB,
1461 /// and the list of manu that are actually in the config and for which
1462 /// we miss the capa (if any).
1464 if (!AliMUONCDB::CheckOCDB()) return;
1466 AliMUONCDB::LoadMapping();
1468 if (!AliMUONCDB::CheckMapping()) return;
1470 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1474 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1476 e = AliCDBManager::Instance()->Get("MUON/Calib/Capacitances");
1480 AliMUONVStore* capacitances = static_cast<AliMUONVStore*>(e->GetObject());
1482 AliInfoGeneral("ShowCapacitances",Form("%d capacitances are in OCDB",capacitances->GetSize()));
1484 TIter nextManu(config->CreateIterator());
1485 AliMUONVCalibParam* param;
1487 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1489 Int_t detElemId = param->ID0();
1490 Int_t manuId = param->ID1();
1493 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
1497 AliErrorGeneral("ShowCapacitances",Form("Did not find serial for DE %04d MANUID %04d",detElemId,manuId));
1501 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capacitances->FindObject(serialNumber));
1504 AliErrorGeneral("ShowCapacitances",Form("Did not find capacitance for DE %04d MANUID %04d SERIAL %d",detElemId,manuId,serialNumber));
1511 //_____________________________________________________________________________
1513 AliMUONCDB::ShowConfig(Bool_t withStatusMap)
1515 /// Dumps the current tracker configuration, i.e. number and identity of missing buspatches
1516 /// If statusMap is true, will also take into account the status map to report the number
1517 /// of good channels
1519 if (!AliMUONCDB::CheckOCDB()) return;
1521 AliMUONCDB::LoadMapping();
1523 if (!AliMUONCDB::CheckMapping()) return;
1525 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1529 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1531 AliMUONPadStatusMapMaker* statusMapMaker(0x0);
1532 AliMUONCalibrationData* cd(0x0);
1533 AliMUONPadStatusMaker* statusMaker(0x0);
1535 if ( withStatusMap )
1537 cd = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
1539 statusMaker = new AliMUONPadStatusMaker(*cd);
1541 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
1545 AliErrorGeneral("AliMUONCDB::ShowConfig","Cannot get recoParams from OCDB !");
1549 statusMaker->SetLimits(*recoParam);
1551 UInt_t mask = recoParam->PadGoodnessMask();
1555 const Bool_t deferredInitialization = kFALSE;
1557 statusMapMaker = new AliMUONPadStatusMapMaker(*cd,mask,deferredInitialization);
1560 TIter nextManu(config->CreateIterator());
1561 AliMUONVCalibParam* param;
1563 AliMpExMap buspatches;
1565 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1567 Int_t detElemId = param->ID0();
1568 Int_t manuId = param->ID1();
1569 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1570 if ( buspatches.GetValue(busPatchId) == 0x0 )
1572 buspatches.Add(busPatchId,new TObjString(Form("BP%04d",busPatchId)));
1576 TArrayI removed(buspatches.GetSize());
1578 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1584 // accounting of bus patches first
1586 while ( ( bp = static_cast<AliMpBusPatch*>(next())))
1588 if ( buspatches.GetValue(bp->GetId()) )
1594 removed.SetAt(bp->GetId(),nremoved++);
1598 // accounting of channels
1600 AliMpManuIterator it;
1602 Int_t totalNumberOfChannels(0);
1603 Int_t removedChannels(0);
1604 Int_t badChannels(0);
1605 Int_t badAndRemovedChannels(0);
1606 Int_t badOrRemovedChannels(0);
1608 Int_t detElemId, manuId;
1610 while ( it.Next(detElemId,manuId) )
1612 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1613 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
1615 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1617 if ( de->IsConnectedChannel(manuId,i) )
1619 ++totalNumberOfChannels;
1620 Bool_t badBusPatch = ( buspatches.GetValue(busPatchId) == 0x0 );
1622 if ( withStatusMap )
1624 Bool_t badChannel = ( ( statusMapMaker->StatusMap(detElemId,manuId,i) & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0);
1625 if ( badChannel ) ++badChannels;
1626 if ( badBusPatch && badChannel ) ++badAndRemovedChannels;
1627 if ( badBusPatch || badChannel ) ++badOrRemovedChannels;
1630 if ( badBusPatch) ++removedChannels;
1636 Int_t* indices = new Int_t[nremoved];
1638 TMath::Sort(nremoved,removed.GetArray(),indices,kFALSE);
1640 for ( Int_t i = 0; i < nremoved; ++i )
1642 Int_t busPatchId = removed[indices[i]];
1643 bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1650 cout << Form("Bus patches n=%3d nok=%3d nremoved=%3d",n,nok,nremoved) << endl;
1652 cout << Form("Channels n=%6d nremoved=%6d bad=%6d bad and removed=%6d bad or removed=%6d",
1653 totalNumberOfChannels,removedChannels,badChannels,badAndRemovedChannels,badOrRemovedChannels) << endl;
1655 if (totalNumberOfChannels>0)
1657 cout << Form("Percentage of readout channels %5.1f %%",removedChannels*100.0/totalNumberOfChannels) << endl;
1658 if ( withStatusMap )
1660 cout << Form("Percentage of non useable channels (bad or removed) %5.1f %%",
1661 badOrRemovedChannels*100.0/totalNumberOfChannels) << endl;
1666 delete statusMapMaker;
1671 //______________________________________________________________________________
1672 void AliMUONCDB::ReadIntegers(const char* filename, std::vector<int>& integers)
1674 /// Read integers from filename, where integers are either
1675 /// separated by "," or by return carriage
1676 ifstream in(gSystem->ExpandPathName(filename));
1679 std::set<int> runset;
1683 in.getline(line,10000,'\n');
1685 TString sline(line);
1687 if (sline.Contains(","))
1689 TObjArray* a = sline.Tokenize(",");
1692 while ( ( s = static_cast<TObjString*>(next()) ) )
1694 runset.insert(s->String().Atoi());
1700 runset.insert(sline.Atoi());
1708 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
1710 integers.push_back((*it));
1713 std::sort(integers.begin(),integers.end());
1716 //______________________________________________________________________________
1717 void AliMUONCDB::ShowFaultyBusPatches(const char* runlist, double occLimit,
1718 const char* outputBaseName,
1719 const char* ocdbPath)
1721 /// Shows the list of bus patches above a given occupancy limit,
1722 /// for each run in the runlist
1724 AliLog::GetRootLogger()->SetGlobalLogLevel(AliLog::kError);
1726 // AliLog::SetPrintType(AliLog::kInfo,kFALSE);
1727 // AliLog::SetPrintType(AliLog::kWarning,kFALSE);
1728 // gErrorIgnoreLevel=kError; // to avoid all the TAlienFile::Open messages...
1730 AliCDBManager* man = AliCDBManager::Instance();
1732 man->SetDefaultStorage(ocdbPath);
1734 Bool_t first(kTRUE);
1736 std::vector<int> runnumbers;
1738 ReadIntegers(runlist,runnumbers);
1740 AliMUON2DMap bpValues(kFALSE);
1742 std::ofstream outfile(Form("%s.txt",outputBaseName));
1744 for ( unsigned int i = 0 ; i < runnumbers.size(); ++i )
1746 int runNumber = runnumbers[i];
1748 man->SetRun(runNumber);
1752 AliMpCDB::LoadAll();
1756 AliCDBEntry* e = man->Get("MUON/Calib/OccupancyMap",runNumber);
1760 AliErrorGeneral("AliMUONCDB::ShowFaultyBusPatches",
1761 Form("Could not get OccupancyMap for run %09d",runNumber));
1765 AliMUONVStore* occmap = static_cast<AliMUONVStore*>(e->GetObject());
1767 AliMUONTrackerData td("occ","occ",*occmap);
1769 TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1771 std::set<int> buspatches;
1772 Double_t sumn = 1000.0;
1774 while ( ( bp = static_cast<AliMpBusPatch*>(nextBP()) ) )
1776 Double_t occ = td.BusPatch(bp->GetId(),2);
1780 buspatches.insert(bp->GetId());
1782 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(bpValues.FindObject(bp->GetId()));
1786 param = new AliMUONCalibParamND(5, 1, bp->GetId(), 0);
1787 bpValues.Add(param);
1789 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(bp->GetId());
1790 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1794 for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
1796 Int_t manuId = bp->GetManuId(imanu);
1797 nchannels += de->NofChannelsInManu(manuId);
1800 param->SetValueAsDouble(0,2,sumn);
1801 param->SetValueAsDouble(0,3,nchannels);
1802 param->SetValueAsDouble(0,4,1);
1805 Double_t sumw = sumn*(param->ValueAsDouble(0)/sumn+1.0/runnumbers.size());
1806 Double_t sumw2 = 0.0; //(sumn-1)*ey*ey+sumw*sumw/sumn;
1808 param->SetValueAsDouble(0,0,sumw);
1809 param->SetValueAsDouble(0,1,sumw2);
1814 outfile << Form("RUN %09d",runNumber);
1816 for ( std::set<int>::const_iterator bit = buspatches.begin(); bit != buspatches.end(); ++bit )
1818 outfile << Form(" %4d",*bit);
1825 const char* name = "BPfailureRate";
1827 AliMUONTrackerData* mpData = new AliMUONTrackerData(name,name,bpValues,2);
1828 mpData->SetDimensionName(0,name);
1830 TFile f(Form("%s.root",outputBaseName),"recreate");
1834 cout << Form("Results are in %s.txt and %s.root",outputBaseName,outputBaseName) << endl;
1836 gSystem->Exec(Form("cat %s.txt",outputBaseName));
1840 //______________________________________________________________________________
1841 void AliMUONCDB::CheckHV(Int_t runNumber, Int_t verbose)
1843 /// Check the HV values in OCDB for a given run
1846 messages.SetOwner(kTRUE);
1848 Bool_t patched(kTRUE);
1850 if (!AliCDBManager::Instance()->IsDefaultStorageSet())
1852 AliCDBManager::Instance()->SetDefaultStorage("raw://");
1855 AliCDBManager::Instance()->SetRun(runNumber);
1859 AliMUONCalibrationData::CreateHV(runNumber,0,patched,&messages);
1861 AliMUONCalibrationData cd(runNumber,true);
1863 AliMUONPadStatusMaker statusMaker(cd);
1865 AliMUONRecoParam* rp = AliMUONCDB::LoadRecoParam();
1869 AliErrorGeneral("AliMUONCDB::CheckHV","Could not get RecoParam !!!");
1873 statusMaker.SetLimits(*rp);
1875 TIter next(&messages);
1877 AliMpDCSNamer hvNamer("TRACKER");
1880 while ( ( s = static_cast<TObjString*>(next()) ) )
1882 TObjArray* a = s->String().Tokenize(":");
1884 TString name(static_cast<TObjString*>(a->At(0))->String());
1886 if ( name.Contains("sw") || name.Contains("SUMMARY") ) {delete a; continue;}
1888 Int_t index = hvNamer.DCSIndexFromDCSAlias(name.Data());
1890 Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
1892 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1896 AliErrorGeneral("AliMUONCDB::CheckHV",Form("Could not get detElemId from dcsAlias %s",name.Data()));
1905 const AliMpArrayI* array = de->ManusForHV(index);
1906 manuId = array->GetValue(0);
1911 AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(de->GetBusPatchId(0));
1913 manuId = bp->GetManuId(0);
1916 Int_t status = statusMaker.HVStatus(detElemId,manuId);
1918 log.Log(AliMUONPadStatusMaker::AsString(status).Data());
1920 s->String() += Form(" (DE %4d) ",detElemId);
1921 s->String() += AliMUONPadStatusMaker::AsString(status).Data();
1926 TIter nextMessage(&messages);
1929 while ( ( msg = static_cast<TObjString*>(nextMessage()) ) )
1931 if ( verbose > 0 || msg->String().Contains("SUMMARY") )
1933 AliInfoGeneral("AliMUONCDB::CheckHV",Form("RUN %09d HVchannel %s",runNumber,msg->String().Data()));
1941 while (log.Next(lmsg,occurance))
1943 totalLog += Form("%s(%d)",lmsg.Data(),occurance);
1947 AliInfoGeneral("AliMUONCDB::CheckHV",Form("RUN %09d %s",runNumber,totalLog.Data()));
1949 // one last loop to get the list of problematic HV channels
1950 nextMessage.Reset();
1952 while ( ( msg = static_cast<TObjString*>(nextMessage()) ) )
1954 if ( msg->String().Contains("HV ") )
1956 AliInfoGeneral("AliMUONCDB::CheckHV",Form(" Problem at %s",msg->String().Data()));
1960 AliCDBManager::Instance()->ClearCache();