Update from Alberica. Addition of VZERO equalized signals and ZNC.
[u/mrichter/AliRoot.git] / MUON / AliMUONCDB.cxx
CommitLineData
de01cdf0 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
ee523da4 17
3d1463c8 18//-----------------------------------------------------------------------------
a99c3449 19/// \namespace AliMUONCDB
de01cdf0 20///
a99c3449 21/// Helper functions to experience the OCDB
22///
23/// They allow to read magnetic field, mapping and recoParam from OCDB
24///
25/// And also to generate dummy (but complete) containers for all the
de01cdf0 26/// calibration data types we have for tracker and trigger, and to write
27/// them into OCDB.
28///
a99c3449 29/// For more information, please see READMEcalib
de01cdf0 30///
baf1a7a0 31/// \author Laurent Aphecetche
3d1463c8 32//-----------------------------------------------------------------------------
de01cdf0 33
34#include "AliMUONCDB.h"
35
de01cdf0 36#include "AliMUON1DArray.h"
37#include "AliMUON1DMap.h"
38#include "AliMUON2DMap.h"
39#include "AliMUON2DStoreValidator.h"
7eafe398 40#include "AliMUONCalibParamND.h"
de01cdf0 41#include "AliMUONCalibParamNF.h"
42#include "AliMUONCalibParamNI.h"
207947f7 43#include "AliMUONCalibrationData.h"
de01cdf0 44#include "AliMUONConstants.h"
207947f7 45#include "AliMUONGlobalCrateConfig.h"
b37b9546 46#include "AliMUONLogger.h"
207947f7 47#include "AliMUONPadStatusMaker.h"
48#include "AliMUONPadStatusMapMaker.h"
49#include "AliMUONRecoParam.h"
50#include "AliMUONRegionalTriggerConfig.h"
0045b488 51#include "AliMUONRejectList.h"
9e7c4517 52#include "AliMUONTrackerData.h"
49419555 53#include "AliMUONTrackerIO.h"
de01cdf0 54#include "AliMUONTriggerEfficiencyCells.h"
55#include "AliMUONTriggerLut.h"
de01cdf0 56#include "AliMUONVCalibParam.h"
57#include "AliMUONVCalibParam.h"
207947f7 58#include "AliMUONVStore.h"
59
25e1df3e 60#include "AliMpCDB.h"
a0eca509 61#include "AliMpConstants.h"
a99c3449 62#include "AliMpDEStore.h"
de01cdf0 63#include "AliMpDDLStore.h"
ab167304 64#include "AliMpManuStore.h"
de01cdf0 65#include "AliMpDEManager.h"
66#include "AliMpDetElement.h"
92c23b09 67#include "AliMpFiles.h"
49e110ec 68#include "AliMpDCSNamer.h"
409de10f 69#include "AliMpManuIterator.h"
de01cdf0 70#include "AliMpSegmentation.h"
71#include "AliMpStationType.h"
72#include "AliMpVSegmentation.h"
92e36663 73
74#include "AliCodeTimer.h"
75#include "AliCDBEntry.h"
76#include "AliCDBManager.h"
a99c3449 77#include "AliGRPManager.h"
92e36663 78#include "AliDCSValue.h"
79#include "AliLog.h"
a31df857 80#include "AliMpBusPatch.h"
92e36663 81
de01cdf0 82#include <Riostream.h>
83#include <TArrayI.h>
84#include <TClass.h>
9e7c4517 85#include <TFile.h>
de01cdf0 86#include <TH1F.h>
87#include <TList.h>
88#include <TMap.h>
89#include <TObjString.h>
90#include <TROOT.h>
91#include <TRandom.h>
92#include <TStopwatch.h>
93#include <TSystem.h>
cf27231a 94#include <TMath.h>
a99c3449 95#include <TGeoGlobalMagField.h>
73d3aca5 96#include <TClonesArray.h>
a31df857 97#include <sstream>
9e7c4517 98#include <set>
c05673c9 99
cdd730d0 100using std::endl;
101using std::cout;
102using std::cerr;
103using std::ostringstream;
104using std::ifstream;
105
de01cdf0 106namespace
107{
409de10f 108 //_____________________________________________________________________________
109AliMUONVStore* Create2DMap()
110{
111 return new AliMUON2DMap(true);
112}
113
114 //_____________________________________________________________________________
046e5fd4 115void getBoundaries(const AliMUONVStore& store, Int_t dim,
116 Float_t* xmin, Float_t* xmax)
de01cdf0 117{
046e5fd4 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
121
122 for ( Int_t i = 0; i < dim; ++i )
123 {
124 xmin[i]=1E30;
125 xmax[i]=-1E30;
126 }
de01cdf0 127
a0eca509 128 TIter next(store.CreateIterator());
129 AliMUONVCalibParam* value;
de01cdf0 130
a0eca509 131 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 132 {
a0eca509 133 Int_t detElemId = value->ID0();
134 Int_t manuId = value->ID1();
de01cdf0 135
136 const AliMpVSegmentation* seg =
137 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
138
b37b9546 139 if (!seg) continue;
140
de01cdf0 141 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
142 {
168e9c4d 143 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
de01cdf0 144 if (!pad.IsValid()) continue;
145
046e5fd4 146 for ( Int_t i = 0; i < dim; ++i )
de01cdf0 147 {
046e5fd4 148 Float_t x0 = value->ValueAsFloat(manuChannel,i);
149
150 xmin[i] = TMath::Min(xmin[i],x0);
151 xmax[i] = TMath::Max(xmax[i],x0);
de01cdf0 152 }
153 }
046e5fd4 154 }
155
156 for ( Int_t i = 0; i < dim; ++i )
157 {
158 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
159 {
160 xmin[i] -= 1;
161 xmax[i] += 1;
162 }
163 }
de01cdf0 164}
165
cf27231a 166//_____________________________________________________________________________
167Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
168{
169 Double_t x(-1);
170 if ( mustBePositive )
171 {
172 while ( x < 0 )
173 {
174 x = gRandom->Gaus(mean,sigma);
175 }
176 }
177 else
178 {
179 x = gRandom->Gaus(mean,sigma);
180 }
181 return x;
182}
183
de01cdf0 184}
185
186//_____________________________________________________________________________
a99c3449 187Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
de01cdf0 188{
a99c3449 189 /// Check that OCDB path and run number are properly set
190
191 AliCDBManager* man = AliCDBManager::Instance();
192
193 // first OCDB path
194 if (!man->IsDefaultStorageSet()) {
195 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
196 return kFALSE;
197 }
198
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");
203 return kFALSE;
204 }
205
206 return kTRUE;
207
208}
209
210//_____________________________________________________________________________
211Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
212{
213 /// Check that the mapping has been loaded
214
215 // first the segmentation
216 if (!AliMpSegmentation::Instance(false)) {
217 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
218 return kFALSE;
219 }
220
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");
225 return kFALSE;
226 }
227
228 return kTRUE;
229
230}
231
232//_____________________________________________________________________________
233Bool_t AliMUONCDB::LoadField()
234{
235 /// Load magnetic field (existing field will be deleted).
236 /// OCDB path and run number are supposed to be set.
237
238 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
239
240 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
241
242 AliGRPManager grpMan;
243
244 // make sure the old field is deleted even if it is locked
245 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
246
247 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
248 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
249 return kFALSE;
250 }
251
252 return kTRUE;
253
254}
ab167304 255
a99c3449 256//_____________________________________________________________________________
257Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
258{
259 /// Load mapping (existing mapping will be unloaded).
260 /// OCDB path and run number are supposed to be set.
261
262 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
263
264 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
265
266 // in case it has already been set
267 AliMpCDB::UnloadAll();
268
269 if (segmentationOnly) {
270
271 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
272 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
273 return kFALSE;
274 }
275
276 } else {
277
278 if (!AliMpCDB::LoadAll(kTRUE)) {
279 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
280 return kFALSE;
ab167304 281 }
a99c3449 282
283 }
284
285 return kTRUE;
286
de01cdf0 287}
288
289//_____________________________________________________________________________
a99c3449 290AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
de01cdf0 291{
a99c3449 292 /// Load and return reconstruction parameters.
293 /// OCDB path is supposed to be set.
294
295 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
296
2ff3de0a 297 if (!AliMUONCDB::CheckOCDB()) return 0x0;
a99c3449 298
299 AliMUONRecoParam* recoParam = 0x0;
300 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
301
302 if(entry) {
303
304 // load recoParam according OCDB content (single or array)
305 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
306
307 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
cdffeaea 308// recoParamArray->SetOwner(kTRUE); // FIXME: this should be done, but is causing a problem at the end of the reco... investigate why...
a99c3449 309
310 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
311 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
312 if (recoParam->IsDefault()) break;
313 recoParam = 0x0;
314 }
315
316 }
317
318 }
319
320 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
321
322 return recoParam;
323
a0eca509 324}
325
326//_____________________________________________________________________________
73d3aca5 327TClonesArray* AliMUONCDB::LoadAlignmentData()
328{
329 /// Load and return the array of alignment objects.
330
331 AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
332
2ff3de0a 333 if (!AliMUONCDB::CheckOCDB()) return 0x0;
73d3aca5 334
335 TClonesArray* alignmentArray = 0x0;
336 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
337
338 if (entry) {
339 // load alignement array
340 alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
341 }
342
343 if (!alignmentArray) {
344 AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
345 }
346
347 return alignmentArray;
348}
349
350//_____________________________________________________________________________
a0eca509 351AliMUONVStore*
352AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
de01cdf0 353 const char* opt)
354{
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
046e5fd4 358 /// if opt="percent" then what is stored is rel*100
359 ///
de01cdf0 360 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
361
362 TString sopt(opt);
363 sopt.ToUpper();
364
046e5fd4 365 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
de01cdf0 366 {
a99c3449 367 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
de01cdf0 368 return 0x0;
369 }
370
a0eca509 371 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
de01cdf0 372
a0eca509 373 TIter next(d->CreateIterator());
de01cdf0 374
a0eca509 375 AliMUONVCalibParam* param;
de01cdf0 376
a0eca509 377 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 378 {
a0eca509 379 Int_t detElemId = param->ID0();
380 Int_t manuId = param->ID1();
de01cdf0 381
a0eca509 382 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
de01cdf0 383 //FIXME: this might happen. Handle it.
384 if (!param2)
385 {
386 cerr << "param2 is null : FIXME : this might happen !" << endl;
387 delete d;
388 return 0;
389 }
390
391 for ( Int_t i = 0; i < param->Size(); ++i )
392 {
393 for ( Int_t j = 0; j < param->Dimension(); ++j )
394 {
395 Float_t value(0);
396 if ( sopt.Contains("ABS") )
397 {
398 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
399 }
046e5fd4 400 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
de01cdf0 401 {
402 if ( param->ValueAsFloat(i,j) )
403 {
404 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
405 }
406 else
407 {
408 continue;
409 }
046e5fd4 410 if ( sopt.Contains("PERCENT") ) value *= 100.0;
de01cdf0 411 }
412 param->SetValueAsFloat(i,j,value);
413 }
414 }
de01cdf0 415 }
416 return d;
417}
418
419//_____________________________________________________________________________
b37b9546 420TH1**
a0eca509 421AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
de01cdf0 422{
046e5fd4 423 /// Make histograms of each dimension of the AliMUONVCalibParam
de01cdf0 424 /// contained inside store.
425 /// It produces histograms named name_0, name_1, etc...
426
b37b9546 427 if (!AliMUONCDB::CheckMapping(kTRUE)) return 0x0;
a99c3449 428
046e5fd4 429 TIter next(store.CreateIterator());
430 AliMUONVCalibParam* param;
de01cdf0 431 Int_t n(0);
046e5fd4 432 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
433 Int_t* nPerStation = new Int_t[kNStations];
434 TH1** h(0x0);
de01cdf0 435
046e5fd4 436 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
de01cdf0 437
046e5fd4 438 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
de01cdf0 439 {
046e5fd4 440 if (!h)
441 {
442 Int_t dim = param->Dimension();
443 h = new TH1*[dim];
444 Float_t* xmin = new Float_t[dim];
445 Float_t* xmax = new Float_t[dim];
446 getBoundaries(store,dim,xmin,xmax);
447
448 for ( Int_t i = 0; i < dim; ++i )
449 {
450 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
451 nbins,xmin[i],xmax[i]);
a99c3449 452 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
046e5fd4 453 }
f1bf7efd 454 delete [] xmin;
455 delete [] xmax;
046e5fd4 456 }
457
458 Int_t detElemId = param->ID0();
459 Int_t manuId = param->ID1();
460 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
de01cdf0 461
462 const AliMpVSegmentation* seg =
463 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
464
b37b9546 465 if (!seg) continue;
466
046e5fd4 467 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
de01cdf0 468 {
168e9c4d 469 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
046e5fd4 470 if (!pad.IsValid()) continue;
de01cdf0 471
046e5fd4 472 ++n;
473 ++nPerStation[station];
474
475 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
476 {
477 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
de01cdf0 478 }
479 }
046e5fd4 480 }
de01cdf0 481
046e5fd4 482 for ( Int_t i = 0; i < kNStations; ++i )
de01cdf0 483 {
a99c3449 484 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
de01cdf0 485 }
046e5fd4 486
a99c3449 487 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
046e5fd4 488
489 delete[] nPerStation;
b37b9546 490
491 return h;
de01cdf0 492}
493
494//_____________________________________________________________________________
495Int_t
496AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
497{
498 /// Create a HV store
499
a99c3449 500 if (!AliMUONCDB::CheckMapping()) return 0;
501
49e110ec 502 AliMpDCSNamer hvNamer("TRACKER");
de01cdf0 503
504 TObjArray* aliases = hvNamer.GenerateAliases();
505
506 Int_t nSwitch(0);
507 Int_t nChannels(0);
508
509 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
510 {
511 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
512 TString& aliasName = alias->String();
513 if ( aliasName.Contains("sw") )
514 {
515 // HV Switch (St345 only)
516 TObjArray* valueSet = new TObjArray;
517 valueSet->SetOwner(kTRUE);
518
519 Bool_t value = kTRUE;
520
521 if (!defaultValues)
522 {
a0eca509 523 Float_t r = gRandom->Uniform();
de01cdf0 524 if ( r < 0.007 ) value = kFALSE;
525 }
526
527 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
528 {
529 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
530 valueSet->Add(dcsValue);
531 }
532 aliasMap.Add(new TObjString(*alias),valueSet);
533 ++nSwitch;
534 }
535 else
536 {
537 TObjArray* valueSet = new TObjArray;
538 valueSet->SetOwner(kTRUE);
539 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
540 {
541 Float_t value = 1500;
cf27231a 542 if (!defaultValues) value = GetRandom(1750,62.5,true);
de01cdf0 543 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
544 valueSet->Add(dcsValue);
545 }
546 aliasMap.Add(new TObjString(*alias),valueSet);
547 ++nChannels;
548 }
549 }
550
551 delete aliases;
552
a99c3449 553 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
de01cdf0 554
555 return nChannels+nSwitch;
556}
557
558//_____________________________________________________________________________
559Int_t
49e110ec 560AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
561{
562 /// Create a Trigger HV and Currents store
563
a99c3449 564 if (!AliMUONCDB::CheckMapping()) return 0;
565
49e110ec 566 AliMpDCSNamer triggerDCSNamer("TRIGGER");
567
568 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
569
570 Int_t nChannels[2] = {0, 0};
571
572 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
573 {
574 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
575 TString& aliasName = alias->String();
576
577 TObjArray* valueSet = new TObjArray;
578 valueSet->SetOwner(kTRUE);
ad30b53f 579
49e110ec 580 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
ad30b53f 581 if ( measureType < 0 ) {
582 AliErrorGeneralStream("AliMUONCDB")
583 << "Failed to get DCS variable from an alias (trigger): "
584 << aliasName.Data() << endl;
585 return 0;
586 }
587
49e110ec 588 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
589 {
590 Float_t value =
9b1e069f 591 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
49e110ec 592 if (!defaultValues) {
593 switch (measureType){
594 case AliMpDCSNamer::kDCSI:
9b1e069f 595 value = GetRandom(2.,0.4,true);
49e110ec 596 break;
597 case AliMpDCSNamer::kDCSHV:
9b1e069f 598 value = GetRandom(8000.,16.,true);
49e110ec 599 break;
600 }
601 }
602 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
603 valueSet->Add(dcsValue);
604 }
605 aliasMap.Add(new TObjString(*alias),valueSet);
606 ++nChannels[measureType];
607 }
608
609 delete aliases;
610
a99c3449 611 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
49e110ec 612
613 return nChannels[0] + nChannels[1];
614}
615
616//_____________________________________________________________________________
617Int_t
a0eca509 618AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
de01cdf0 619{
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)
409de10f 623
a99c3449 624 AliCodeTimerAutoGeneral("",0);
625
626 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 627
628 Int_t nchannels(0);
629 Int_t nmanus(0);
630
a0eca509 631 const Int_t kChannels(AliMpConstants::ManuNofChannels());
e7ee8d13 632
633 // bending
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);
638
639 // non bending
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);
644
645 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
409de10f 646
647 Int_t detElemId;
648 Int_t manuId;
649
650 AliMpManuIterator it;
de01cdf0 651
409de10f 652 while ( it.Next(detElemId,manuId) )
de01cdf0 653 {
e7ee8d13 654 // skip a given fraction of manus
655 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
656
de01cdf0 657 ++nmanus;
a0eca509 658
046e5fd4 659 AliMUONVCalibParam* ped =
660 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
409de10f 661
662 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 663
664 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
665 {
409de10f 666 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 667
668 ++nchannels;
669
670 Float_t meanPedestal;
671 Float_t sigmaPedestal;
672
673 if ( defaultValues )
674 {
675 meanPedestal = 0.0;
676 sigmaPedestal = 1.0;
677 }
678 else
679 {
cf27231a 680 Bool_t positive(kTRUE);
046e5fd4 681 meanPedestal = 0.0;
e7ee8d13 682
683 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
684
685 while ( meanPedestal == 0.0 ) // avoid strict zero
686 {
687 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
688 }
689 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
690
691 } else { // manu in bending plane
692
693 while ( meanPedestal == 0.0 ) // avoid strict zero
694 {
695 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
696 }
697 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
698
699 }
700
de01cdf0 701 }
e7ee8d13 702
de01cdf0 703 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
704 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
705
706 }
a0eca509 707 Bool_t ok = pedestalStore.Add(ped);
de01cdf0 708 if (!ok)
709 {
a99c3449 710 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 711 }
712 }
713
a99c3449 714 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
de01cdf0 715 return nchannels;
de01cdf0 716}
717
718//_____________________________________________________________________________
0045b488 719AliMUONRejectList*
720AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
721{
722 /// Create a reject list
723
a99c3449 724 AliCodeTimerAutoGeneral("",0);
0045b488 725
726 AliMUONRejectList* rl = new AliMUONRejectList;
727
728 if (!defaultValues)
729 {
730 rl->SetDetectionElementProbability(510);
731 rl->SetDetectionElementProbability(508);
732 return rl;
733 }
734
735 return rl;
736}
737
738//_____________________________________________________________________________
2b8a1212 739Int_t
7eafe398 740AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
2b8a1212 741{
7eafe398 742 /// Create an occupancy map.
2b8a1212 743
a99c3449 744 AliCodeTimerAutoGeneral("",0);
745
746 if (!AliMUONCDB::CheckMapping()) return 0;
2b8a1212 747
2b8a1212 748 Int_t nmanus(0);
749
2b8a1212 750 Int_t detElemId;
751 Int_t manuId;
752
753 AliMpManuIterator it;
754
7eafe398 755 Int_t nevents(1000);
756
2b8a1212 757 while ( it.Next(detElemId,manuId) )
758 {
2b8a1212 759 ++nmanus;
760
7eafe398 761 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
2b8a1212 762
7eafe398 763 Double_t occ = 0.0;
764
2b8a1212 765 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
766
7eafe398 767 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
768
a99c3449 769 if (!defaultValues) occ = gRandom->Rndm(1);
7eafe398 770
771 Double_t sumn = occ*nevents;
772
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);
778
779 Bool_t ok = occupancyMapStore.Add(occupancy);
2b8a1212 780 if (!ok)
781 {
a99c3449 782 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
2b8a1212 783 }
2b8a1212 784 }
785
7eafe398 786 return nmanus;
2b8a1212 787}
788
789//_____________________________________________________________________________
25e1df3e 790Int_t
791AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
792{
6687de6d 793 /// Read the capacitance values from file and append them to the capaStore
794
a99c3449 795 if (!AliMUONCDB::CheckMapping()) return 0;
796
49419555 797 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
25e1df3e 798}
799
800//_____________________________________________________________________________
de01cdf0 801Int_t
a0eca509 802AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
de01cdf0 803{
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.
409de10f 807
a99c3449 808 AliCodeTimerAutoGeneral("",0);
809
810 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 811
812 Int_t nchannels(0);
813 Int_t nmanus(0);
814 Int_t nmanusOK(0); // manus for which we got the serial number
a0eca509 815
25e1df3e 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);
409de10f 820
821 Int_t detElemId;
822 Int_t manuId;
823
824 AliMpManuIterator it;
de01cdf0 825
409de10f 826 while ( it.Next(detElemId,manuId) )
de01cdf0 827 {
828 ++nmanus;
829
de01cdf0 830 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
ab167304 831 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
de01cdf0 832
a0eca509 833 if ( serialNumber <= 0 ) continue;
834
835 ++nmanusOK;
de01cdf0 836
a0eca509 837 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
de01cdf0 838
839 if (!capa)
840 {
25e1df3e 841 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
a0eca509 842 Bool_t ok = capaStore.Add(capa);
de01cdf0 843 if (!ok)
844 {
a99c3449 845 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
de01cdf0 846 }
847 }
848
849 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
850 {
409de10f 851 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 852
853 ++nchannels;
854
855 Float_t capaValue;
25e1df3e 856 Float_t injectionGain;
de01cdf0 857
858 if ( defaultValues )
859 {
860 capaValue = 1.0;
25e1df3e 861 injectionGain = 1.0;
de01cdf0 862 }
863 else
864 {
cf27231a 865 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
25e1df3e 866 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
de01cdf0 867 }
868 capa->SetValueAsFloat(manuChannel,0,capaValue);
25e1df3e 869 capa->SetValueAsFloat(manuChannel,1,injectionGain);
de01cdf0 870 }
871 }
872
873 Float_t percent = 0;
874 if ( nmanus ) percent = 100*nmanusOK/nmanus;
a99c3449 875 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
de01cdf0 876 nmanusOK,nmanus,percent));
a99c3449 877 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
de01cdf0 878 if ( percent < 100 )
879 {
a99c3449 880 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
de01cdf0 881 }
882 return nchannels;
883
884}
885
886//_____________________________________________________________________________
887Int_t
a0eca509 888AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
de01cdf0 889{
cf27231a 890 /// Create a gain store. if defaultValues=true, all gains set so that
891 /// charge = (adc-ped)
892 ///
893 /// otherwise parameters are taken from gaussians with parameters
894 /// defined in the k* constants below.
de01cdf0 895
a99c3449 896 AliCodeTimerAutoGeneral("",0);
897
898 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 899
900 Int_t nchannels(0);
901 Int_t nmanus(0);
a0eca509 902
cf27231a 903 const Int_t kSaturation(3000);
904 const Double_t kA0Mean(1.2);
409de10f 905 const Double_t kA0Sigma(0.1);
906 const Double_t kA1Mean(1E-5);
907 const Double_t kA1Sigma(1E-6);
cf27231a 908 const Double_t kQualMean(0xFF);
909 const Double_t kQualSigma(0x10);
910 const Int_t kThresMean(1600);
409de10f 911 const Int_t kThresSigma(100);
912
913 Int_t detElemId;
914 Int_t manuId;
de01cdf0 915
409de10f 916 AliMpManuIterator it;
917
918 while ( it.Next(detElemId,manuId) )
de01cdf0 919 {
920 ++nmanus;
de01cdf0 921
a0eca509 922 AliMUONVCalibParam* gain =
cf27231a 923 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
a0eca509 924 detElemId,
925 manuId,
926 AliMUONVCalibParam::InvalidFloatValue());
927
409de10f 928 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 929
930 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
931 {
409de10f 932 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 933
934 ++nchannels;
935
de01cdf0 936 if ( defaultValues )
937 {
cf27231a 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);
de01cdf0 943 }
944 else
945 {
cf27231a 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);
de01cdf0 952 }
de01cdf0 953
954 }
a0eca509 955 Bool_t ok = gainStore.Add(gain);
de01cdf0 956 if (!ok)
957 {
a99c3449 958 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 959 }
960 }
961
a99c3449 962 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
de01cdf0 963 return nchannels;
964}
965
966//_____________________________________________________________________________
967Int_t
a99c3449 968AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
de01cdf0 969{
970 /// Generate local trigger masks store. All masks are set to FFFF
971
a99c3449 972 AliCodeTimerAutoGeneral("",0);
409de10f 973
de01cdf0 974 Int_t ngenerated(0);
630711ed 975 // Generate fake mask values for all localboards and put that into
de01cdf0 976 // one single container (localBoardMasks)
0145e89a 977 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
de01cdf0 978 {
a0eca509 979 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
de01cdf0 980 for ( Int_t x = 0; x < 2; ++x )
981 {
982 for ( Int_t y = 0; y < 4; ++y )
983 {
984 Int_t index = x*4+y;
985 localBoard->SetValueAsInt(index,0,0xFFFF);
986 ++ngenerated;
987 }
988 }
a0eca509 989 localBoardMasks.Add(localBoard);
de01cdf0 990 }
991 return ngenerated;
992}
993
994//_____________________________________________________________________________
995Int_t
a99c3449 996AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
de01cdf0 997{
92c23b09 998 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
de01cdf0 999
a99c3449 1000 AliCodeTimerAutoGeneral("",0);
409de10f 1001
5cc125b2 1002 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
a99c3449 1003 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
5cc125b2 1004 return 0;
1005 }
1006
1007 return rtm.GetNofTriggerCrates();
de01cdf0 1008}
1009
92c23b09 1010
de01cdf0 1011//_____________________________________________________________________________
1012Int_t
a99c3449 1013AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
de01cdf0 1014{
92c23b09 1015 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
de01cdf0 1016
a99c3449 1017 AliCodeTimerAutoGeneral("",0);
913f1b43 1018
1019 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
de01cdf0 1020}
1021
92c23b09 1022
de01cdf0 1023//_____________________________________________________________________________
1024AliMUONTriggerLut*
a99c3449 1025AliMUONCDB::MakeTriggerLUT(const char* file)
de01cdf0 1026{
1027 /// Make a triggerlut object, from a file.
1028
a99c3449 1029 AliCodeTimerAutoGeneral("",0);
409de10f 1030
de01cdf0 1031 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1032 lut->ReadFromFile(file);
1033 return lut;
1034}
1035
1036//_____________________________________________________________________________
1037AliMUONTriggerEfficiencyCells*
a99c3449 1038AliMUONCDB::MakeTriggerEfficiency(const char* file)
de01cdf0 1039{
1040 /// Make a trigger efficiency object from a file.
1041
a99c3449 1042 AliCodeTimerAutoGeneral("",0);
409de10f 1043
de01cdf0 1044 return new AliMUONTriggerEfficiencyCells(file);
1045}
1046
1047//_____________________________________________________________________________
1048void
1049AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
25e1df3e 1050 Int_t startRun, Int_t endRun,
1051 const char* filename)
1052{
1053 /// Write a given object to OCDB
1054
913f1b43 1055 TString comment(gSystem->ExpandPathName(filename));
1056
1057 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
25e1df3e 1058}
1059
1060//_____________________________________________________________________________
1061void
1062AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
de01cdf0 1063 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1064{
1065 /// Write a given object to OCDB
1066
913f1b43 1067 TString comment;
1068 if ( defaultValues ) comment += "Test with default values";
1069 else comment += "Test with random values";
1070
1071 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1072}
1073
1074//_____________________________________________________________________________
1075void
1076AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1077 const char* comment, const char* responsible)
1078{
1079 /// Write a given object to OCDB
1080
a99c3449 1081 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1082
de01cdf0 1083 AliCDBId id(calibpath,startRun,endRun);
1084 AliCDBMetaData md;
1085 md.SetAliRootVersion(gROOT->GetVersion());
913f1b43 1086 md.SetComment(comment);
1087 md.SetResponsible(responsible);
a99c3449 1088 AliCDBManager::Instance()->Put(object,id,&md);
de01cdf0 1089}
1090
1091//_____________________________________________________________________________
1092Int_t
a0eca509 1093AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
de01cdf0 1094{
1095 /// Fill the neighbours store with, for each channel, a TObjArray of its
1096 /// neighbouring pads (including itself)
1097
a99c3449 1098 AliCodeTimerAutoGeneral("",0);
1099
1100 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 1101
a99c3449 1102 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
de01cdf0 1103
1104 Int_t nchannels(0);
1105
1106 TObjArray tmp;
409de10f 1107
1108 Int_t detElemId;
1109 Int_t manuId;
de01cdf0 1110
409de10f 1111 AliMpManuIterator it;
1112
1113 while ( it.Next(detElemId,manuId) )
de01cdf0 1114 {
de01cdf0 1115 const AliMpVSegmentation* seg =
1116 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1117
a0eca509 1118 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
de01cdf0 1119 if (!calibParam)
1120 {
1121 Int_t dimension(11);
a0eca509 1122 Int_t size(AliMpConstants::ManuNofChannels());
de01cdf0 1123 Int_t defaultValue(-1);
a0eca509 1124 Int_t packingFactor(size);
de01cdf0 1125
a0eca509 1126 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1127 Bool_t ok = neighbourStore.Add(calibParam);
de01cdf0 1128 if (!ok)
1129 {
a99c3449 1130 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 1131 return -1;
1132 }
1133 }
1134
a0eca509 1135 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
de01cdf0 1136 {
168e9c4d 1137 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
de01cdf0 1138
1139 if (pad.IsValid())
1140 {
1141 ++nchannels;
1142
1143 seg->GetNeighbours(pad,tmp,true,true);
1144 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1145
1146 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1147 {
bf0d3528 1148 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
de01cdf0 1149 Int_t x;
409de10f 1150// Bool_t ok =
6e97fbb8 1151 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
409de10f 1152// if (!ok)
1153// {
1154// AliError("Could not pack value. Something is seriously wrong. Please check");
1155// StdoutToAliError(pad->Print(););
1156// return -1;
1157// }
de01cdf0 1158 calibParam->SetValueAsInt(manuChannel,i,x);
1159 }
1160 }
1161 }
1162 }
1163
de01cdf0 1164 return nchannels;
1165}
1166
1167//_____________________________________________________________________________
1168void
1169AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1170{
1171 /// Write local trigger masks to OCDB
1172
630711ed 1173 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
de01cdf0 1174 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
a99c3449 1175 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1176 if (ngenerated>0)
1177 {
1178 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1179 }
1180 delete ltm;
1181}
1182
1183//_____________________________________________________________________________
1184void
92c23b09 1185AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 1186{
1187 /// Write regional trigger masks to OCDB
1188
92c23b09 1189 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1190 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
a99c3449 1191 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1192 if (ngenerated>0)
1193 {
92c23b09 1194 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
de01cdf0 1195 }
1196 delete rtm;
1197}
1198
92c23b09 1199
de01cdf0 1200//_____________________________________________________________________________
1201void
92c23b09 1202AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 1203{
1204 /// Write global trigger masks to OCDB
1205
92c23b09 1206 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
de01cdf0 1207
92c23b09 1208 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
a99c3449 1209 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1210 if (ngenerated>0)
1211 {
92c23b09 1212 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
de01cdf0 1213 }
1214 delete gtm;
1215}
1216
92c23b09 1217
de01cdf0 1218//_____________________________________________________________________________
1219void
1220AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1221{
1222 /// Write trigger LUT to OCDB
1223
1224 AliMUONTriggerLut* lut = MakeTriggerLUT();
1225 if (lut)
1226 {
1227 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1228 }
1229 delete lut;
1230}
1231
1232//_____________________________________________________________________________
1233void
1234AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1235{
1236 /// Write trigger efficiency to OCDB
1237
1238 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1239 if (eff)
1240 {
1241 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1242 }
1243 delete eff;
1244}
1245
1246//_____________________________________________________________________________
1247void
1248AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1249{
1250 /// Write neighbours to OCDB
1251
409de10f 1252 AliMUONVStore* neighbours = Create2DMap();
de01cdf0 1253 Int_t ngenerated = MakeNeighbourStore(*neighbours);
a99c3449 1254 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1255 if (ngenerated>0)
1256 {
1257 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1258 }
1259 delete neighbours;
1260}
1261
1262//_____________________________________________________________________________
1263void
1264AliMUONCDB::WriteHV(Bool_t defaultValues,
1265 Int_t startRun, Int_t endRun)
1266{
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
1271
1272 TMap* hvStore = new TMap;
1273 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
a99c3449 1274 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1275 if (ngenerated>0)
1276 {
1277 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1278 }
1279 delete hvStore;
1280}
1281
1282//_____________________________________________________________________________
1283void
49e110ec 1284AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1285 Int_t startRun, Int_t endRun)
1286{
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
1291
1292 TMap* triggerDCSStore = new TMap;
1293 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
a99c3449 1294 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
49e110ec 1295 if (ngenerated>0)
1296 {
1297 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1298 }
1299 delete triggerDCSStore;
1300}
1301
1302//_____________________________________________________________________________
1303void
de01cdf0 1304AliMUONCDB::WritePedestals(Bool_t defaultValues,
1305 Int_t startRun, Int_t endRun)
1306{
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
1311
409de10f 1312 AliMUONVStore* pedestalStore = Create2DMap();
de01cdf0 1313 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
a99c3449 1314 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1315 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1316 delete pedestalStore;
1317}
1318
2b8a1212 1319//_____________________________________________________________________________
1320void
7eafe398 1321AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1322 Int_t startRun, Int_t endRun)
2b8a1212 1323{
7eafe398 1324 /// generate occupancy map values (either empty one if defaultValues=true, or
1325 /// random one, see MakeOccupancyMapStore) and
2b8a1212 1326 /// store them into CDB located at cdbpath, with a validity period
1327 /// ranging from startRun to endRun
1328
7eafe398 1329 AliMUONVStore* occupancyMapStore = Create2DMap();
1330 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
a99c3449 1331 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
7eafe398 1332 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1333 delete occupancyMapStore;
2b8a1212 1334}
1335
0045b488 1336//_____________________________________________________________________________
1337void
1338AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1339 Int_t startRun, Int_t endRun)
1340{
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
1345
1346 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1347 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1348 delete rl;
1349}
1350
de01cdf0 1351
1352//_____________________________________________________________________________
1353void
1354AliMUONCDB::WriteGains(Bool_t defaultValues,
1355 Int_t startRun, Int_t endRun)
1356{
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
1361
409de10f 1362 AliMUONVStore* gainStore = Create2DMap();
de01cdf0 1363 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
a99c3449 1364 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1365 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1366 delete gainStore;
1367}
1368
1369//_____________________________________________________________________________
1370void
25e1df3e 1371AliMUONCDB::WriteCapacitances(const char* filename,
1372 Int_t startRun, Int_t endRun)
1373{
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
1377
1378 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1379 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
a99c3449 1380 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
25e1df3e 1381 if ( ngenerated > 0 )
1382 {
1383 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1384 }
1385 delete capaStore;
1386}
1387
1388//_____________________________________________________________________________
1389void
de01cdf0 1390AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1391 Int_t startRun, Int_t endRun)
1392{
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
1397
a0eca509 1398 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
de01cdf0 1399 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
a99c3449 1400 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1401 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1402 delete capaStore;
1403}
1404
1405//_____________________________________________________________________________
1406void
49e110ec 1407AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
de01cdf0 1408{
1409 /// Writes all Trigger related calibration to CDB
49e110ec 1410 WriteTriggerDCS(defaultValues,startRun,endRun);
de01cdf0 1411 WriteLocalTriggerMasks(startRun,endRun);
92c23b09 1412 WriteRegionalTriggerConfig(startRun,endRun);
1413 WriteGlobalTriggerConfig(startRun,endRun);
de01cdf0 1414 WriteTriggerLut(startRun,endRun);
1415 WriteTriggerEfficiency(startRun,endRun);
1416}
1417
1418//_____________________________________________________________________________
1419void
a31df857 1420AliMUONCDB::WriteConfig(Int_t startRun, Int_t endRun)
1421{
1422 /// Write complete tracker configuration to OCDB
1423 ostringstream lines;
1424 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1425 AliMpBusPatch* bp;
1426 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
1427 {
1428 for (Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu)
1429 {
1430 lines << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
1431 }
1432 }
1433
1434 AliMUON2DMap config(kTRUE);
a31df857 1435
042cd64e 1436 AliMUONTrackerIO::DecodeConfig(lines.str().c_str(),config);
a31df857 1437
1438 WriteToCDB("MUON/Calib/Config",&config,startRun,endRun,kTRUE);
1439}
1440
1441//_____________________________________________________________________________
1442void
de01cdf0 1443AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1444{
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);
c21c5694 1451 WriteOccupancyMap(defaultValues,startRun,endRun);
1452 WriteRejectList(defaultValues,startRun,endRun);
a31df857 1453 WriteConfig(startRun,endRun);
de01cdf0 1454}
913f1b43 1455
5148da98 1456//_____________________________________________________________________________
1457void
c241bfaa 1458AliMUONCDB::ShowCapacitances()
1459{
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).
1463
1464 if (!AliMUONCDB::CheckOCDB()) return;
1465
1466 AliMUONCDB::LoadMapping();
1467
1468 if (!AliMUONCDB::CheckMapping()) return;
1469
1470 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1471
1472 if (!e) return ;
1473
1474 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1475
1476 e = AliCDBManager::Instance()->Get("MUON/Calib/Capacitances");
1477
1478 if (!e) return;
1479
1480 AliMUONVStore* capacitances = static_cast<AliMUONVStore*>(e->GetObject());
1481
1482 AliInfoGeneral("ShowCapacitances",Form("%d capacitances are in OCDB",capacitances->GetSize()));
1483
1484 TIter nextManu(config->CreateIterator());
1485 AliMUONVCalibParam* param;
1486
1487 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1488 {
1489 Int_t detElemId = param->ID0();
1490 Int_t manuId = param->ID1();
1491
1492 Int_t serialNumber
1493 = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
1494
1495 if (serialNumber<0)
1496 {
1497 AliErrorGeneral("ShowCapacitances",Form("Did not find serial for DE %04d MANUID %04d",detElemId,manuId));
1498 }
1499 else
1500 {
1501 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capacitances->FindObject(serialNumber));
1502 if (!capa)
1503 {
1504 AliErrorGeneral("ShowCapacitances",Form("Did not find capacitance for DE %04d MANUID %04d SERIAL %d",detElemId,manuId,serialNumber));
1505 }
1506 }
1507 }
1508
1509}
1510
1511//_____________________________________________________________________________
1512void
207947f7 1513AliMUONCDB::ShowConfig(Bool_t withStatusMap)
5148da98 1514{
1515 /// Dumps the current tracker configuration, i.e. number and identity of missing buspatches
207947f7 1516 /// If statusMap is true, will also take into account the status map to report the number
1517 /// of good channels
1518
5148da98 1519 if (!AliMUONCDB::CheckOCDB()) return;
1520
1521 AliMUONCDB::LoadMapping();
1522
1523 if (!AliMUONCDB::CheckMapping()) return;
1524
1525 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1526
1527 if (!e) return ;
1528
1529 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1530
207947f7 1531 AliMUONPadStatusMapMaker* statusMapMaker(0x0);
1532 AliMUONCalibrationData* cd(0x0);
1533 AliMUONPadStatusMaker* statusMaker(0x0);
1534
1535 if ( withStatusMap )
1536 {
1537 cd = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
1538
1539 statusMaker = new AliMUONPadStatusMaker(*cd);
1540
1541 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
1542
0c53c46d 1543 if (!recoParam)
1544 {
1545 AliErrorGeneral("AliMUONCDB::ShowConfig","Cannot get recoParams from OCDB !");
1546 return;
1547 }
1548
207947f7 1549 statusMaker->SetLimits(*recoParam);
1550
207947f7 1551 UInt_t mask = recoParam->PadGoodnessMask();
9b780418 1552
1553 delete recoParam;
1554
207947f7 1555 const Bool_t deferredInitialization = kFALSE;
1556
1557 statusMapMaker = new AliMUONPadStatusMapMaker(*cd,mask,deferredInitialization);
1558 }
1559
5148da98 1560 TIter nextManu(config->CreateIterator());
1561 AliMUONVCalibParam* param;
1562
1563 AliMpExMap buspatches;
1564
1565 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1566 {
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 )
1571 {
1572 buspatches.Add(busPatchId,new TObjString(Form("BP%04d",busPatchId)));
1573 }
1574 }
1575
1576 TArrayI removed(buspatches.GetSize());
1577
1578 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1579 AliMpBusPatch* bp;
1580 Int_t n(0);
1581 Int_t nok(0);
1582 Int_t nremoved(0);
1583
207947f7 1584 // accounting of bus patches first
1585
5148da98 1586 while ( ( bp = static_cast<AliMpBusPatch*>(next())))
1587 {
1588 if ( buspatches.GetValue(bp->GetId()) )
1589 {
1590 ++nok;
1591 }
1592 else
1593 {
1594 removed.SetAt(bp->GetId(),nremoved++);
1595 }
5148da98 1596 }
1597
207947f7 1598 // accounting of channels
1599
1600 AliMpManuIterator it;
1601
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);
1607
1608 Int_t detElemId, manuId;
1609
1610 while ( it.Next(detElemId,manuId) )
1611 {
1612 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1613 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
1614 {
1615 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1616
1617 if ( de->IsConnectedChannel(manuId,i) )
1618 {
1619 ++totalNumberOfChannels;
1620 Bool_t badBusPatch = ( buspatches.GetValue(busPatchId) == 0x0 );
1621
1622 if ( withStatusMap )
1623 {
47274b13 1624 Bool_t badChannel = ( ( statusMapMaker->StatusMap(detElemId,manuId,i) & AliMUONPadStatusMapMaker::SelfDeadMask() ) != 0);
207947f7 1625 if ( badChannel ) ++badChannels;
1626 if ( badBusPatch && badChannel ) ++badAndRemovedChannels;
1627 if ( badBusPatch || badChannel ) ++badOrRemovedChannels;
1628 }
1629
1630 if ( badBusPatch) ++removedChannels;
1631 }
1632 }
1633 }
1634
5148da98 1635
1636 Int_t* indices = new Int_t[nremoved];
1637
1638 TMath::Sort(nremoved,removed.GetArray(),indices,kFALSE);
1639
1640 for ( Int_t i = 0; i < nremoved; ++i )
1641 {
1642 Int_t busPatchId = removed[indices[i]];
1643 bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1644 bp->Print();
1645 }
1646
1647 delete[] indices;
207947f7 1648
1649 cout << endl;
1650 cout << Form("Bus patches n=%3d nok=%3d nremoved=%3d",n,nok,nremoved) << endl;
1651
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;
1654
1655 if (totalNumberOfChannels>0)
1656 {
1657 cout << Form("Percentage of readout channels %5.1f %%",removedChannels*100.0/totalNumberOfChannels) << endl;
1658 if ( withStatusMap )
1659 {
1660 cout << Form("Percentage of non useable channels (bad or removed) %5.1f %%",
1661 badOrRemovedChannels*100.0/totalNumberOfChannels) << endl;
1662 }
1663 }
1664
1665
1666 delete statusMapMaker;
1667 delete cd;
1668 delete statusMaker;
5148da98 1669}
9e7c4517 1670
1671//______________________________________________________________________________
1672void AliMUONCDB::ReadIntegers(const char* filename, std::vector<int>& integers)
1673{
1674 /// Read integers from filename, where integers are either
1675 /// separated by "," or by return carriage
1676 ifstream in(gSystem->ExpandPathName(filename));
1677 int i;
1678
1679 std::set<int> runset;
1680
1681 char line[10000];
1682
1683 in.getline(line,10000,'\n');
1684
1685 TString sline(line);
1686
1687 if (sline.Contains(","))
1688 {
1689 TObjArray* a = sline.Tokenize(",");
1690 TIter next(a);
1691 TObjString* s;
1692 while ( ( s = static_cast<TObjString*>(next()) ) )
1693 {
1694 runset.insert(s->String().Atoi());
1695 }
1696 delete a;
1697 }
1698 else
1699 {
1700 runset.insert(sline.Atoi());
1701
1702 while ( in >> i )
1703 {
1704 runset.insert(i);
1705 }
1706 }
1707
1708 for ( std::set<int>::const_iterator it = runset.begin(); it != runset.end(); ++it )
1709 {
1710 integers.push_back((*it));
1711 }
1712
1713 std::sort(integers.begin(),integers.end());
1714}
1715
1716//______________________________________________________________________________
1717void AliMUONCDB::ShowFaultyBusPatches(const char* runlist, double occLimit,
1718 const char* outputBaseName,
1719 const char* ocdbPath)
1720{
1721 /// Shows the list of bus patches above a given occupancy limit,
1722 /// for each run in the runlist
1723
1724 AliLog::GetRootLogger()->SetGlobalLogLevel(AliLog::kError);
1725
1726 // AliLog::SetPrintType(AliLog::kInfo,kFALSE);
1727 // AliLog::SetPrintType(AliLog::kWarning,kFALSE);
1728 // gErrorIgnoreLevel=kError; // to avoid all the TAlienFile::Open messages...
1729
1730 AliCDBManager* man = AliCDBManager::Instance();
1731
1732 man->SetDefaultStorage(ocdbPath);
1733
1734 Bool_t first(kTRUE);
1735
1736 std::vector<int> runnumbers;
1737
1738 ReadIntegers(runlist,runnumbers);
1739
1740 AliMUON2DMap bpValues(kFALSE);
1741
1742 std::ofstream outfile(Form("%s.txt",outputBaseName));
1743
1744 for ( unsigned int i = 0 ; i < runnumbers.size(); ++i )
1745 {
1746 int runNumber = runnumbers[i];
1747
1748 man->SetRun(runNumber);
1749
1750 if ( first )
1751 {
1752 AliMpCDB::LoadAll();
1753 first = kFALSE;
1754 }
1755
1756 AliCDBEntry* e = man->Get("MUON/Calib/OccupancyMap",runNumber);
1757
b37b9546 1758 if (!e)
1759 {
1760 AliErrorGeneral("AliMUONCDB::ShowFaultyBusPatches",
1761 Form("Could not get OccupancyMap for run %09d",runNumber));
1762 continue;
1763 }
1764
9e7c4517 1765 AliMUONVStore* occmap = static_cast<AliMUONVStore*>(e->GetObject());
1766
1767 AliMUONTrackerData td("occ","occ",*occmap);
1768
1769 TIter nextBP(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1770 AliMpBusPatch* bp;
1771 std::set<int> buspatches;
1772 Double_t sumn = 1000.0;
1773
1774 while ( ( bp = static_cast<AliMpBusPatch*>(nextBP()) ) )
1775 {
1776 Double_t occ = td.BusPatch(bp->GetId(),2);
1777
1778 if (occ>occLimit)
1779 {
1780 buspatches.insert(bp->GetId());
1781
1782 AliMUONVCalibParam* param = static_cast<AliMUONVCalibParam*>(bpValues.FindObject(bp->GetId()));
1783
1784 if (!param)
1785 {
1786 param = new AliMUONCalibParamND(5, 1, bp->GetId(), 0);
1787 bpValues.Add(param);
1788
1789 Int_t detElemId = AliMpDDLStore::Instance()->GetDEfromBus(bp->GetId());
1790 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1791
1792 Int_t nchannels(0);
1793
1794 for ( Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu )
1795 {
1796 Int_t manuId = bp->GetManuId(imanu);
1797 nchannels += de->NofChannelsInManu(manuId);
1798 }
1799
1800 param->SetValueAsDouble(0,2,sumn);
1801 param->SetValueAsDouble(0,3,nchannels);
1802 param->SetValueAsDouble(0,4,1);
1803 }
1804
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;
1807
1808 param->SetValueAsDouble(0,0,sumw);
1809 param->SetValueAsDouble(0,1,sumw2);
1810
1811 }
1812 }
1813
1814 outfile << Form("RUN %09d",runNumber);
1815
1816 for ( std::set<int>::const_iterator bit = buspatches.begin(); bit != buspatches.end(); ++bit )
1817 {
1818 outfile << Form(" %4d",*bit);
1819 }
1820 outfile << endl;
1821 }
1822
1823 outfile.close();
1824
1825 const char* name = "BPfailureRate";
1826
1827 AliMUONTrackerData* mpData = new AliMUONTrackerData(name,name,bpValues,2);
1828 mpData->SetDimensionName(0,name);
1829
1830 TFile f(Form("%s.root",outputBaseName),"recreate");
1831 mpData->Write();
1832 f.Close();
1833
1834 cout << Form("Results are in %s.txt and %s.root",outputBaseName,outputBaseName) << endl;
1835
1836 gSystem->Exec(Form("cat %s.txt",outputBaseName));
1837
1838}
1839
b37b9546 1840//______________________________________________________________________________
1841void AliMUONCDB::CheckHV(Int_t runNumber, Int_t verbose)
1842{
1843 /// Check the HV values in OCDB for a given run
1844
1845 TList messages;
1846 messages.SetOwner(kTRUE);
1847
1848 Bool_t patched(kTRUE);
1849
1850 if (!AliCDBManager::Instance()->IsDefaultStorageSet())
1851 {
1852 AliCDBManager::Instance()->SetDefaultStorage("raw://");
1853 }
1854
1855 AliCDBManager::Instance()->SetRun(runNumber);
1856
1857 LoadMapping();
1858
1859 AliMUONCalibrationData::CreateHV(runNumber,0,patched,&messages);
1860
1861 AliMUONCalibrationData cd(runNumber,true);
1862
1863 AliMUONPadStatusMaker statusMaker(cd);
1864
1865 AliMUONRecoParam* rp = AliMUONCDB::LoadRecoParam();
1866
1867 if (!rp)
1868 {
1869 AliErrorGeneral("AliMUONCDB::CheckHV","Could not get RecoParam !!!");
1870 return;
1871 }
1872
1873 statusMaker.SetLimits(*rp);
1874
1875 TIter next(&messages);
1876 TObjString* s;
1877 AliMpDCSNamer hvNamer("TRACKER");
1878 AliMUONLogger log;
1879
1880 while ( ( s = static_cast<TObjString*>(next()) ) )
1881 {
1882 TObjArray* a = s->String().Tokenize(":");
1883
1884 TString name(static_cast<TObjString*>(a->At(0))->String());
1885
09d5920f 1886 if ( name.Contains("sw") || name.Contains("SUMMARY") ) {delete a; continue;}
b37b9546 1887
1888 Int_t index = hvNamer.DCSIndexFromDCSAlias(name.Data());
1889
1890 Int_t detElemId = hvNamer.DetElemIdFromDCSAlias(name.Data());
1891
1892 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1893
1894 if (!de)
1895 {
1896 AliErrorGeneral("AliMUONCDB::CheckHV",Form("Could not get detElemId from dcsAlias %s",name.Data()));
09d5920f 1897 delete a;
b37b9546 1898 continue;
1899 }
1900
1901 Int_t manuId;
1902
1903 if ( index >= 0 )
1904 {
1905 const AliMpArrayI* array = de->ManusForHV(index);
1906 manuId = array->GetValue(0);
1907 }
1908 else
1909
1910 {
1911 AliMpBusPatch* bp = AliMpDDLStore::Instance()->GetBusPatch(de->GetBusPatchId(0));
1912
1913 manuId = bp->GetManuId(0);
1914 }
1915
1916 Int_t status = statusMaker.HVStatus(detElemId,manuId);
1917
1918 log.Log(AliMUONPadStatusMaker::AsString(status).Data());
1919
1920 s->String() += Form(" (DE %4d) ",detElemId);
1921 s->String() += AliMUONPadStatusMaker::AsString(status).Data();
1922
1923 delete a;
1924 }
1925
1926 TIter nextMessage(&messages);
1927 TObjString* msg;
1928
1929 while ( ( msg = static_cast<TObjString*>(nextMessage()) ) )
1930 {
1931 if ( verbose > 0 || msg->String().Contains("SUMMARY") )
1932 {
1933 AliInfoGeneral("AliMUONCDB::CheckHV",Form("RUN %09d HVchannel %s",runNumber,msg->String().Data()));
1934 }
1935 }
1936
1937 TString lmsg;
1938 Int_t occurance;
1939 TString totalLog;
1940
1941 while (log.Next(lmsg,occurance))
1942 {
1943 totalLog += Form("%s(%d)",lmsg.Data(),occurance);
1944 totalLog += " | ";
1945 }
1946
1947 AliInfoGeneral("AliMUONCDB::CheckHV",Form("RUN %09d %s",runNumber,totalLog.Data()));
1948
1949 // one last loop to get the list of problematic HV channels
1950 nextMessage.Reset();
1951
1952 while ( ( msg = static_cast<TObjString*>(nextMessage()) ) )
1953 {
1954 if ( msg->String().Contains("HV ") )
1955 {
1956 AliInfoGeneral("AliMUONCDB::CheckHV",Form(" Problem at %s",msg->String().Data()));
1957 }
1958 }
1959
1960 AliCDBManager::Instance()->ClearCache();
1961}
1962
1963