Objects to remedy bug in FMD reconstruction - proper run number
[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$ */
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"
46#include "AliMUONPadStatusMaker.h"
47#include "AliMUONPadStatusMapMaker.h"
48#include "AliMUONRecoParam.h"
49#include "AliMUONRegionalTriggerConfig.h"
0045b488 50#include "AliMUONRejectList.h"
49419555 51#include "AliMUONTrackerIO.h"
de01cdf0 52#include "AliMUONTriggerEfficiencyCells.h"
53#include "AliMUONTriggerLut.h"
de01cdf0 54#include "AliMUONVCalibParam.h"
55#include "AliMUONVCalibParam.h"
207947f7 56#include "AliMUONVStore.h"
57
92e36663 58
25e1df3e 59#include "AliMpCDB.h"
a0eca509 60#include "AliMpConstants.h"
a99c3449 61#include "AliMpDEStore.h"
de01cdf0 62#include "AliMpDDLStore.h"
ab167304 63#include "AliMpManuStore.h"
de01cdf0 64#include "AliMpDEManager.h"
65#include "AliMpDetElement.h"
92c23b09 66#include "AliMpFiles.h"
49e110ec 67#include "AliMpDCSNamer.h"
409de10f 68#include "AliMpManuIterator.h"
de01cdf0 69#include "AliMpSegmentation.h"
70#include "AliMpStationType.h"
71#include "AliMpVSegmentation.h"
92e36663 72
73#include "AliCodeTimer.h"
74#include "AliCDBEntry.h"
75#include "AliCDBManager.h"
a99c3449 76#include "AliGRPManager.h"
92e36663 77#include "AliDCSValue.h"
78#include "AliLog.h"
a31df857 79#include "AliMpBusPatch.h"
92e36663 80
de01cdf0 81#include <Riostream.h>
82#include <TArrayI.h>
83#include <TClass.h>
84#include <TH1F.h>
85#include <TList.h>
86#include <TMap.h>
87#include <TObjString.h>
88#include <TROOT.h>
89#include <TRandom.h>
90#include <TStopwatch.h>
91#include <TSystem.h>
cf27231a 92#include <TMath.h>
a99c3449 93#include <TGeoGlobalMagField.h>
73d3aca5 94#include <TClonesArray.h>
a31df857 95#include <sstream>
c05673c9 96
de01cdf0 97namespace
98{
409de10f 99 //_____________________________________________________________________________
100AliMUONVStore* Create2DMap()
101{
102 return new AliMUON2DMap(true);
103}
104
105 //_____________________________________________________________________________
046e5fd4 106void getBoundaries(const AliMUONVStore& store, Int_t dim,
107 Float_t* xmin, Float_t* xmax)
de01cdf0 108{
046e5fd4 109 /// Assuming the store contains AliMUONVCalibParam objects, compute the
110 /// limits of the value contained in the VCalibParam, for each of its dimensions
111 /// xmin and xmax must be of dimension dim
112
113 for ( Int_t i = 0; i < dim; ++i )
114 {
115 xmin[i]=1E30;
116 xmax[i]=-1E30;
117 }
de01cdf0 118
a0eca509 119 TIter next(store.CreateIterator());
120 AliMUONVCalibParam* value;
de01cdf0 121
a0eca509 122 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 123 {
a0eca509 124 Int_t detElemId = value->ID0();
125 Int_t manuId = value->ID1();
de01cdf0 126
127 const AliMpVSegmentation* seg =
128 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
129
130 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
131 {
168e9c4d 132 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
de01cdf0 133 if (!pad.IsValid()) continue;
134
046e5fd4 135 for ( Int_t i = 0; i < dim; ++i )
de01cdf0 136 {
046e5fd4 137 Float_t x0 = value->ValueAsFloat(manuChannel,i);
138
139 xmin[i] = TMath::Min(xmin[i],x0);
140 xmax[i] = TMath::Max(xmax[i],x0);
de01cdf0 141 }
142 }
046e5fd4 143 }
144
145 for ( Int_t i = 0; i < dim; ++i )
146 {
147 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
148 {
149 xmin[i] -= 1;
150 xmax[i] += 1;
151 }
152 }
de01cdf0 153}
154
cf27231a 155//_____________________________________________________________________________
156Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
157{
158 Double_t x(-1);
159 if ( mustBePositive )
160 {
161 while ( x < 0 )
162 {
163 x = gRandom->Gaus(mean,sigma);
164 }
165 }
166 else
167 {
168 x = gRandom->Gaus(mean,sigma);
169 }
170 return x;
171}
172
de01cdf0 173}
174
175//_____________________________________________________________________________
a99c3449 176Bool_t AliMUONCDB::CheckOCDB(Bool_t pathOnly)
de01cdf0 177{
a99c3449 178 /// Check that OCDB path and run number are properly set
179
180 AliCDBManager* man = AliCDBManager::Instance();
181
182 // first OCDB path
183 if (!man->IsDefaultStorageSet()) {
184 AliErrorGeneral("AliMUONCDB", "OCDB path must be properly set");
185 return kFALSE;
186 }
187
188 // then run number if required
189 if (pathOnly) return kTRUE;
190 if (man->GetRun() < 0) {
191 AliErrorGeneral("AliMUONCDB", "Run number must be properly set");
192 return kFALSE;
193 }
194
195 return kTRUE;
196
197}
198
199//_____________________________________________________________________________
200Bool_t AliMUONCDB::CheckMapping(Bool_t segmentationOnly)
201{
202 /// Check that the mapping has been loaded
203
204 // first the segmentation
205 if (!AliMpSegmentation::Instance(false)) {
206 AliErrorGeneral("AliMUONCDB", "Mapping segmentation must be loaded first");
207 return kFALSE;
208 }
209
210 // then the others if required
211 if (segmentationOnly) return kTRUE;
212 if (!AliMpDDLStore::Instance(false) || !AliMpDEStore::Instance(false) || !AliMpManuStore::Instance(false)) {
213 AliErrorGeneral("AliMUONCDB", "Full mapping must be loaded first");
214 return kFALSE;
215 }
216
217 return kTRUE;
218
219}
220
221//_____________________________________________________________________________
222Bool_t AliMUONCDB::LoadField()
223{
224 /// Load magnetic field (existing field will be deleted).
225 /// OCDB path and run number are supposed to be set.
226
227 AliInfoGeneral("AliMUONCDB","Loading field map from GRP...");
228
229 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
230
231 AliGRPManager grpMan;
232
233 // make sure the old field is deleted even if it is locked
234 if(TGeoGlobalMagField::Instance()->IsLocked()) delete TGeoGlobalMagField::Instance();
235
236 if (!grpMan.ReadGRPEntry() || !grpMan.SetMagField()) {
237 AliErrorGeneral("AliMUONCDB", "failed to load magnetic field from OCDB");
238 return kFALSE;
239 }
240
241 return kTRUE;
242
243}
ab167304 244
a99c3449 245//_____________________________________________________________________________
246Bool_t AliMUONCDB::LoadMapping(Bool_t segmentationOnly)
247{
248 /// Load mapping (existing mapping will be unloaded).
249 /// OCDB path and run number are supposed to be set.
250
251 AliInfoGeneral("AliMUONCDB", "Loading mapping from OCDB...");
252
253 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
254
255 // in case it has already been set
256 AliMpCDB::UnloadAll();
257
258 if (segmentationOnly) {
259
260 if (!AliMpCDB::LoadMpSegmentation(kTRUE)){
261 AliErrorGeneral("AliMUONCDB", "failed to load segmentation from OCDB");
262 return kFALSE;
263 }
264
265 } else {
266
267 if (!AliMpCDB::LoadAll(kTRUE)) {
268 AliErrorGeneral("AliMUONCDB", "failed to load mapping from OCDB");
269 return kFALSE;
ab167304 270 }
a99c3449 271
272 }
273
274 return kTRUE;
275
de01cdf0 276}
277
278//_____________________________________________________________________________
a99c3449 279AliMUONRecoParam* AliMUONCDB::LoadRecoParam()
de01cdf0 280{
a99c3449 281 /// Load and return reconstruction parameters.
282 /// OCDB path is supposed to be set.
283
284 AliInfoGeneral("AliMUONCDB", "Loading RecoParam from OCDB...");
285
286 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
287
288 AliMUONRecoParam* recoParam = 0x0;
289 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Calib/RecoParam");
290
291 if(entry) {
292
293 // load recoParam according OCDB content (single or array)
294 if (!(recoParam = dynamic_cast<AliMUONRecoParam*>(entry->GetObject()))) {
295
296 TObjArray* recoParamArray = static_cast<TObjArray*>(entry->GetObject());
297
298 for(Int_t i = 0; i < recoParamArray->GetEntriesFast(); i++) {
299 recoParam = static_cast<AliMUONRecoParam*>(recoParamArray->UncheckedAt(i));
300 if (recoParam->IsDefault()) break;
301 recoParam = 0x0;
302 }
303
304 }
305
306 }
307
308 if (!recoParam) AliErrorGeneral("AliMUONCDB", "failed to load RecoParam from OCDB");
309
310 return recoParam;
311
a0eca509 312}
313
314//_____________________________________________________________________________
73d3aca5 315TClonesArray* AliMUONCDB::LoadAlignmentData()
316{
317 /// Load and return the array of alignment objects.
318
319 AliInfoGeneral("AliMUONCDB", "Loading Alignemnt from OCDB...");
320
321 if (!AliMUONCDB::CheckOCDB()) return kFALSE;
322
323 TClonesArray* alignmentArray = 0x0;
324 AliCDBEntry* entry = AliCDBManager::Instance()->Get("MUON/Align/Data");
325
326 if (entry) {
327 // load alignement array
328 alignmentArray = dynamic_cast<TClonesArray*>(entry->GetObject());
329 }
330
331 if (!alignmentArray) {
332 AliErrorGeneral("AliMUONCDB", "failed to load Alignemnt from OCDB");
333 }
334
335 return alignmentArray;
336}
337
338//_____________________________________________________________________________
a0eca509 339AliMUONVStore*
340AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
de01cdf0 341 const char* opt)
342{
343 /// creates a store which contains store1-store2
344 /// if opt="abs" the difference is absolute one,
345 /// if opt="rel" then what is stored is (store1-store2)/store1
046e5fd4 346 /// if opt="percent" then what is stored is rel*100
347 ///
de01cdf0 348 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
349
350 TString sopt(opt);
351 sopt.ToUpper();
352
046e5fd4 353 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
de01cdf0 354 {
a99c3449 355 AliErrorGeneral("AliMUONCDB", Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
de01cdf0 356 return 0x0;
357 }
358
a0eca509 359 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
de01cdf0 360
a0eca509 361 TIter next(d->CreateIterator());
de01cdf0 362
a0eca509 363 AliMUONVCalibParam* param;
de01cdf0 364
a0eca509 365 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 366 {
a0eca509 367 Int_t detElemId = param->ID0();
368 Int_t manuId = param->ID1();
de01cdf0 369
a0eca509 370 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
de01cdf0 371 //FIXME: this might happen. Handle it.
372 if (!param2)
373 {
374 cerr << "param2 is null : FIXME : this might happen !" << endl;
375 delete d;
376 return 0;
377 }
378
379 for ( Int_t i = 0; i < param->Size(); ++i )
380 {
381 for ( Int_t j = 0; j < param->Dimension(); ++j )
382 {
383 Float_t value(0);
384 if ( sopt.Contains("ABS") )
385 {
386 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
387 }
046e5fd4 388 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
de01cdf0 389 {
390 if ( param->ValueAsFloat(i,j) )
391 {
392 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
393 }
394 else
395 {
396 continue;
397 }
046e5fd4 398 if ( sopt.Contains("PERCENT") ) value *= 100.0;
de01cdf0 399 }
400 param->SetValueAsFloat(i,j,value);
401 }
402 }
de01cdf0 403 }
404 return d;
405}
406
407//_____________________________________________________________________________
408void
a0eca509 409AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
de01cdf0 410{
046e5fd4 411 /// Make histograms of each dimension of the AliMUONVCalibParam
de01cdf0 412 /// contained inside store.
413 /// It produces histograms named name_0, name_1, etc...
414
a99c3449 415 if (!AliMUONCDB::CheckMapping(kTRUE)) return;
416
046e5fd4 417 TIter next(store.CreateIterator());
418 AliMUONVCalibParam* param;
de01cdf0 419 Int_t n(0);
046e5fd4 420 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
421 Int_t* nPerStation = new Int_t[kNStations];
422 TH1** h(0x0);
de01cdf0 423
046e5fd4 424 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
de01cdf0 425
046e5fd4 426 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
de01cdf0 427 {
046e5fd4 428 if (!h)
429 {
430 Int_t dim = param->Dimension();
431 h = new TH1*[dim];
432 Float_t* xmin = new Float_t[dim];
433 Float_t* xmax = new Float_t[dim];
434 getBoundaries(store,dim,xmin,xmax);
435
436 for ( Int_t i = 0; i < dim; ++i )
437 {
438 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
439 nbins,xmin[i],xmax[i]);
a99c3449 440 AliInfoGeneral("AliMUONCDB", Form("Created histogram %s",h[i]->GetName()));
046e5fd4 441 }
442 }
443
444 Int_t detElemId = param->ID0();
445 Int_t manuId = param->ID1();
446 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
de01cdf0 447
448 const AliMpVSegmentation* seg =
449 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
450
046e5fd4 451 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
de01cdf0 452 {
168e9c4d 453 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
046e5fd4 454 if (!pad.IsValid()) continue;
de01cdf0 455
046e5fd4 456 ++n;
457 ++nPerStation[station];
458
459 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
460 {
461 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
de01cdf0 462 }
463 }
046e5fd4 464 }
de01cdf0 465
046e5fd4 466 for ( Int_t i = 0; i < kNStations; ++i )
de01cdf0 467 {
a99c3449 468 AliInfoGeneral("AliMUONCDB", Form("Station %d %d ",(i+1),nPerStation[i]));
de01cdf0 469 }
046e5fd4 470
a99c3449 471 AliInfoGeneral("AliMUONCDB", Form("Number of channels = %d",n));
046e5fd4 472
473 delete[] nPerStation;
de01cdf0 474}
475
476//_____________________________________________________________________________
477Int_t
478AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
479{
480 /// Create a HV store
481
a99c3449 482 if (!AliMUONCDB::CheckMapping()) return 0;
483
49e110ec 484 AliMpDCSNamer hvNamer("TRACKER");
de01cdf0 485
486 TObjArray* aliases = hvNamer.GenerateAliases();
487
488 Int_t nSwitch(0);
489 Int_t nChannels(0);
490
491 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
492 {
493 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
494 TString& aliasName = alias->String();
495 if ( aliasName.Contains("sw") )
496 {
497 // HV Switch (St345 only)
498 TObjArray* valueSet = new TObjArray;
499 valueSet->SetOwner(kTRUE);
500
501 Bool_t value = kTRUE;
502
503 if (!defaultValues)
504 {
a0eca509 505 Float_t r = gRandom->Uniform();
de01cdf0 506 if ( r < 0.007 ) value = kFALSE;
507 }
508
509 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
510 {
511 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
512 valueSet->Add(dcsValue);
513 }
514 aliasMap.Add(new TObjString(*alias),valueSet);
515 ++nSwitch;
516 }
517 else
518 {
519 TObjArray* valueSet = new TObjArray;
520 valueSet->SetOwner(kTRUE);
521 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
522 {
523 Float_t value = 1500;
cf27231a 524 if (!defaultValues) value = GetRandom(1750,62.5,true);
de01cdf0 525 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
526 valueSet->Add(dcsValue);
527 }
528 aliasMap.Add(new TObjString(*alias),valueSet);
529 ++nChannels;
530 }
531 }
532
533 delete aliases;
534
a99c3449 535 AliInfoGeneral("AliMUONCDB", Form("%d HV channels and %d switches",nChannels,nSwitch));
de01cdf0 536
537 return nChannels+nSwitch;
538}
539
540//_____________________________________________________________________________
541Int_t
49e110ec 542AliMUONCDB::MakeTriggerDCSStore(TMap& aliasMap, Bool_t defaultValues)
543{
544 /// Create a Trigger HV and Currents store
545
a99c3449 546 if (!AliMUONCDB::CheckMapping()) return 0;
547
49e110ec 548 AliMpDCSNamer triggerDCSNamer("TRIGGER");
549
550 TObjArray* aliases = triggerDCSNamer.GenerateAliases();
551
552 Int_t nChannels[2] = {0, 0};
553
554 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
555 {
556 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
557 TString& aliasName = alias->String();
558
559 TObjArray* valueSet = new TObjArray;
560 valueSet->SetOwner(kTRUE);
561 Int_t measureType = triggerDCSNamer.DCSvariableFromDCSAlias(aliasName.Data());
562 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
563 {
564 Float_t value =
9b1e069f 565 (measureType == AliMpDCSNamer::kDCSI) ? 2. : 8000.;
49e110ec 566 if (!defaultValues) {
567 switch (measureType){
568 case AliMpDCSNamer::kDCSI:
9b1e069f 569 value = GetRandom(2.,0.4,true);
49e110ec 570 break;
571 case AliMpDCSNamer::kDCSHV:
9b1e069f 572 value = GetRandom(8000.,16.,true);
49e110ec 573 break;
574 }
575 }
576 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
577 valueSet->Add(dcsValue);
578 }
579 aliasMap.Add(new TObjString(*alias),valueSet);
580 ++nChannels[measureType];
581 }
582
583 delete aliases;
584
a99c3449 585 AliInfoGeneral("AliMUONCDB", Form("Trigger channels I -> %i HV -> %i",nChannels[0], nChannels[1]));
49e110ec 586
587 return nChannels[0] + nChannels[1];
588}
589
590//_____________________________________________________________________________
591Int_t
a0eca509 592AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
de01cdf0 593{
594 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
595 /// otherwise mean and sigma are from a gaussian (with parameters
596 /// defined below by the kPedestal* constants)
409de10f 597
a99c3449 598 AliCodeTimerAutoGeneral("",0);
599
600 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 601
602 Int_t nchannels(0);
603 Int_t nmanus(0);
604
a0eca509 605 const Int_t kChannels(AliMpConstants::ManuNofChannels());
e7ee8d13 606
607 // bending
608 const Float_t kPedestalMeanMeanB(200.);
609 const Float_t kPedestalMeanSigmaB(10.);
610 const Float_t kPedestalSigmaMeanB(1.);
611 const Float_t kPedestalSigmaSigmaB(0.2);
612
613 // non bending
614 const Float_t kPedestalMeanMeanNB(200.);
615 const Float_t kPedestalMeanSigmaNB(10.);
616 const Float_t kPedestalSigmaMeanNB(1.);
617 const Float_t kPedestalSigmaSigmaNB(0.2);
618
619 const Float_t kFractionOfDeadManu(0.); // within [0.,1.]
409de10f 620
621 Int_t detElemId;
622 Int_t manuId;
623
624 AliMpManuIterator it;
de01cdf0 625
409de10f 626 while ( it.Next(detElemId,manuId) )
de01cdf0 627 {
e7ee8d13 628 // skip a given fraction of manus
629 if (kFractionOfDeadManu > 0. && gRandom->Uniform() < kFractionOfDeadManu) continue;
630
de01cdf0 631 ++nmanus;
a0eca509 632
046e5fd4 633 AliMUONVCalibParam* ped =
634 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
409de10f 635
636 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 637
638 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
639 {
409de10f 640 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 641
642 ++nchannels;
643
644 Float_t meanPedestal;
645 Float_t sigmaPedestal;
646
647 if ( defaultValues )
648 {
649 meanPedestal = 0.0;
650 sigmaPedestal = 1.0;
651 }
652 else
653 {
cf27231a 654 Bool_t positive(kTRUE);
046e5fd4 655 meanPedestal = 0.0;
e7ee8d13 656
657 if ( manuId & AliMpConstants::ManuMask(AliMp::kNonBendingPlane) ) { // manu in non bending plane
658
659 while ( meanPedestal == 0.0 ) // avoid strict zero
660 {
661 meanPedestal = GetRandom(kPedestalMeanMeanNB,kPedestalMeanSigmaNB,positive);
662 }
663 sigmaPedestal = GetRandom(kPedestalSigmaMeanNB,kPedestalSigmaSigmaNB,positive);
664
665 } else { // manu in bending plane
666
667 while ( meanPedestal == 0.0 ) // avoid strict zero
668 {
669 meanPedestal = GetRandom(kPedestalMeanMeanB,kPedestalMeanSigmaB,positive);
670 }
671 sigmaPedestal = GetRandom(kPedestalSigmaMeanB,kPedestalSigmaSigmaB,positive);
672
673 }
674
de01cdf0 675 }
e7ee8d13 676
de01cdf0 677 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
678 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
679
680 }
a0eca509 681 Bool_t ok = pedestalStore.Add(ped);
de01cdf0 682 if (!ok)
683 {
a99c3449 684 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 685 }
686 }
687
a99c3449 688 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
de01cdf0 689 return nchannels;
de01cdf0 690}
691
692//_____________________________________________________________________________
0045b488 693AliMUONRejectList*
694AliMUONCDB::MakeRejectListStore(Bool_t defaultValues)
695{
696 /// Create a reject list
697
a99c3449 698 AliCodeTimerAutoGeneral("",0);
0045b488 699
700 AliMUONRejectList* rl = new AliMUONRejectList;
701
702 if (!defaultValues)
703 {
704 rl->SetDetectionElementProbability(510);
705 rl->SetDetectionElementProbability(508);
706 return rl;
707 }
708
709 return rl;
710}
711
712//_____________________________________________________________________________
2b8a1212 713Int_t
7eafe398 714AliMUONCDB::MakeOccupancyMapStore(AliMUONVStore& occupancyMapStore, Bool_t defaultValues)
2b8a1212 715{
7eafe398 716 /// Create an occupancy map.
2b8a1212 717
a99c3449 718 AliCodeTimerAutoGeneral("",0);
719
720 if (!AliMUONCDB::CheckMapping()) return 0;
2b8a1212 721
2b8a1212 722 Int_t nmanus(0);
723
2b8a1212 724 Int_t detElemId;
725 Int_t manuId;
726
727 AliMpManuIterator it;
728
7eafe398 729 Int_t nevents(1000);
730
2b8a1212 731 while ( it.Next(detElemId,manuId) )
732 {
2b8a1212 733 ++nmanus;
734
7eafe398 735 AliMUONVCalibParam* occupancy = new AliMUONCalibParamND(5,1,detElemId,manuId,0);
2b8a1212 736
7eafe398 737 Double_t occ = 0.0;
738
2b8a1212 739 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
740
7eafe398 741 Int_t numberOfChannelsInManu = de->NofChannelsInManu(manuId);
742
a99c3449 743 if (!defaultValues) occ = gRandom->Rndm(1);
7eafe398 744
745 Double_t sumn = occ*nevents;
746
747 occupancy->SetValueAsFloat(0,0,sumn);
748 occupancy->SetValueAsFloat(0,1,sumn);
749 occupancy->SetValueAsFloat(0,2,sumn);
750 occupancy->SetValueAsInt(0,3,numberOfChannelsInManu);
751 occupancy->SetValueAsInt(0,4,nevents);
752
753 Bool_t ok = occupancyMapStore.Add(occupancy);
2b8a1212 754 if (!ok)
755 {
a99c3449 756 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
2b8a1212 757 }
2b8a1212 758 }
759
7eafe398 760 return nmanus;
2b8a1212 761}
762
763//_____________________________________________________________________________
25e1df3e 764Int_t
765AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
766{
6687de6d 767 /// Read the capacitance values from file and append them to the capaStore
768
a99c3449 769 if (!AliMUONCDB::CheckMapping()) return 0;
770
49419555 771 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
25e1df3e 772}
773
774//_____________________________________________________________________________
de01cdf0 775Int_t
a0eca509 776AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
de01cdf0 777{
778 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
779 /// otherwise they are from a gaussian with parameters defined in the
780 /// kCapa* constants below.
409de10f 781
a99c3449 782 AliCodeTimerAutoGeneral("",0);
783
784 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 785
786 Int_t nchannels(0);
787 Int_t nmanus(0);
788 Int_t nmanusOK(0); // manus for which we got the serial number
a0eca509 789
25e1df3e 790 const Float_t kCapaMean(0.3);
791 const Float_t kCapaSigma(0.1);
792 const Float_t kInjectionGainMean(3);
793 const Float_t kInjectionGainSigma(1);
409de10f 794
795 Int_t detElemId;
796 Int_t manuId;
797
798 AliMpManuIterator it;
de01cdf0 799
409de10f 800 while ( it.Next(detElemId,manuId) )
de01cdf0 801 {
802 ++nmanus;
803
de01cdf0 804 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
ab167304 805 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
de01cdf0 806
a0eca509 807 if ( serialNumber <= 0 ) continue;
808
809 ++nmanusOK;
de01cdf0 810
a0eca509 811 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
de01cdf0 812
813 if (!capa)
814 {
25e1df3e 815 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
a0eca509 816 Bool_t ok = capaStore.Add(capa);
de01cdf0 817 if (!ok)
818 {
a99c3449 819 AliErrorGeneral("AliMUONCDB", Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
de01cdf0 820 }
821 }
822
823 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
824 {
409de10f 825 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 826
827 ++nchannels;
828
829 Float_t capaValue;
25e1df3e 830 Float_t injectionGain;
de01cdf0 831
832 if ( defaultValues )
833 {
834 capaValue = 1.0;
25e1df3e 835 injectionGain = 1.0;
de01cdf0 836 }
837 else
838 {
cf27231a 839 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
25e1df3e 840 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
de01cdf0 841 }
842 capa->SetValueAsFloat(manuChannel,0,capaValue);
25e1df3e 843 capa->SetValueAsFloat(manuChannel,1,injectionGain);
de01cdf0 844 }
845 }
846
847 Float_t percent = 0;
848 if ( nmanus ) percent = 100*nmanusOK/nmanus;
a99c3449 849 AliInfoGeneral("AliMUONCDB", Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
de01cdf0 850 nmanusOK,nmanus,percent));
a99c3449 851 AliInfoGeneral("AliMUONCDB", Form("%5d channels",nchannels));
de01cdf0 852 if ( percent < 100 )
853 {
a99c3449 854 AliWarningGeneral("AliMUONCDB", "Did not get all serial numbers. capaStore is incomplete !!!!");
de01cdf0 855 }
856 return nchannels;
857
858}
859
860//_____________________________________________________________________________
861Int_t
a0eca509 862AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
de01cdf0 863{
cf27231a 864 /// Create a gain store. if defaultValues=true, all gains set so that
865 /// charge = (adc-ped)
866 ///
867 /// otherwise parameters are taken from gaussians with parameters
868 /// defined in the k* constants below.
de01cdf0 869
a99c3449 870 AliCodeTimerAutoGeneral("",0);
871
872 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 873
874 Int_t nchannels(0);
875 Int_t nmanus(0);
a0eca509 876
cf27231a 877 const Int_t kSaturation(3000);
878 const Double_t kA0Mean(1.2);
409de10f 879 const Double_t kA0Sigma(0.1);
880 const Double_t kA1Mean(1E-5);
881 const Double_t kA1Sigma(1E-6);
cf27231a 882 const Double_t kQualMean(0xFF);
883 const Double_t kQualSigma(0x10);
884 const Int_t kThresMean(1600);
409de10f 885 const Int_t kThresSigma(100);
886
887 Int_t detElemId;
888 Int_t manuId;
de01cdf0 889
409de10f 890 AliMpManuIterator it;
891
892 while ( it.Next(detElemId,manuId) )
de01cdf0 893 {
894 ++nmanus;
de01cdf0 895
a0eca509 896 AliMUONVCalibParam* gain =
cf27231a 897 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
a0eca509 898 detElemId,
899 manuId,
900 AliMUONVCalibParam::InvalidFloatValue());
901
409de10f 902 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 903
904 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
905 {
409de10f 906 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 907
908 ++nchannels;
909
de01cdf0 910 if ( defaultValues )
911 {
cf27231a 912 gain->SetValueAsFloat(manuChannel,0,1.0);
913 gain->SetValueAsFloat(manuChannel,1,0.0);
914 gain->SetValueAsInt(manuChannel,2,4095);
915 gain->SetValueAsInt(manuChannel,3,1);
916 gain->SetValueAsInt(manuChannel,4,kSaturation);
de01cdf0 917 }
918 else
919 {
cf27231a 920 Bool_t positive(kTRUE);
921 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
922 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
923 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
924 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
925 gain->SetValueAsInt(manuChannel,4,kSaturation);
de01cdf0 926 }
de01cdf0 927
928 }
a0eca509 929 Bool_t ok = gainStore.Add(gain);
de01cdf0 930 if (!ok)
931 {
a99c3449 932 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 933 }
934 }
935
a99c3449 936 AliInfoGeneral("AliMUONCDB", Form("%d Manus and %d channels.",nmanus,nchannels));
de01cdf0 937 return nchannels;
938}
939
940//_____________________________________________________________________________
941Int_t
a99c3449 942AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks)
de01cdf0 943{
944 /// Generate local trigger masks store. All masks are set to FFFF
945
a99c3449 946 AliCodeTimerAutoGeneral("",0);
409de10f 947
de01cdf0 948 Int_t ngenerated(0);
630711ed 949 // Generate fake mask values for all localboards and put that into
de01cdf0 950 // one single container (localBoardMasks)
0145e89a 951 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
de01cdf0 952 {
a0eca509 953 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
de01cdf0 954 for ( Int_t x = 0; x < 2; ++x )
955 {
956 for ( Int_t y = 0; y < 4; ++y )
957 {
958 Int_t index = x*4+y;
959 localBoard->SetValueAsInt(index,0,0xFFFF);
960 ++ngenerated;
961 }
962 }
a0eca509 963 localBoardMasks.Add(localBoard);
de01cdf0 964 }
965 return ngenerated;
966}
967
968//_____________________________________________________________________________
969Int_t
a99c3449 970AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm)
de01cdf0 971{
92c23b09 972 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
de01cdf0 973
a99c3449 974 AliCodeTimerAutoGeneral("",0);
409de10f 975
5cc125b2 976 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
a99c3449 977 AliErrorGeneral("AliMUONCDB", "Error when reading from mapping file");
5cc125b2 978 return 0;
979 }
980
981 return rtm.GetNofTriggerCrates();
de01cdf0 982}
983
92c23b09 984
de01cdf0 985//_____________________________________________________________________________
986Int_t
a99c3449 987AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm)
de01cdf0 988{
92c23b09 989 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
de01cdf0 990
a99c3449 991 AliCodeTimerAutoGeneral("",0);
913f1b43 992
993 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
de01cdf0 994}
995
92c23b09 996
de01cdf0 997//_____________________________________________________________________________
998AliMUONTriggerLut*
a99c3449 999AliMUONCDB::MakeTriggerLUT(const char* file)
de01cdf0 1000{
1001 /// Make a triggerlut object, from a file.
1002
a99c3449 1003 AliCodeTimerAutoGeneral("",0);
409de10f 1004
de01cdf0 1005 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
1006 lut->ReadFromFile(file);
1007 return lut;
1008}
1009
1010//_____________________________________________________________________________
1011AliMUONTriggerEfficiencyCells*
a99c3449 1012AliMUONCDB::MakeTriggerEfficiency(const char* file)
de01cdf0 1013{
1014 /// Make a trigger efficiency object from a file.
1015
a99c3449 1016 AliCodeTimerAutoGeneral("",0);
409de10f 1017
de01cdf0 1018 return new AliMUONTriggerEfficiencyCells(file);
1019}
1020
1021//_____________________________________________________________________________
1022void
1023AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
25e1df3e 1024 Int_t startRun, Int_t endRun,
1025 const char* filename)
1026{
1027 /// Write a given object to OCDB
1028
913f1b43 1029 TString comment(gSystem->ExpandPathName(filename));
1030
1031 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
25e1df3e 1032}
1033
1034//_____________________________________________________________________________
1035void
1036AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
de01cdf0 1037 Int_t startRun, Int_t endRun, Bool_t defaultValues)
1038{
1039 /// Write a given object to OCDB
1040
913f1b43 1041 TString comment;
1042 if ( defaultValues ) comment += "Test with default values";
1043 else comment += "Test with random values";
1044
1045 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
1046}
1047
1048//_____________________________________________________________________________
1049void
1050AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
1051 const char* comment, const char* responsible)
1052{
1053 /// Write a given object to OCDB
1054
a99c3449 1055 if (!AliMUONCDB::CheckOCDB(kTRUE)) return;
1056
de01cdf0 1057 AliCDBId id(calibpath,startRun,endRun);
1058 AliCDBMetaData md;
1059 md.SetAliRootVersion(gROOT->GetVersion());
913f1b43 1060 md.SetComment(comment);
1061 md.SetResponsible(responsible);
a99c3449 1062 AliCDBManager::Instance()->Put(object,id,&md);
de01cdf0 1063}
1064
1065//_____________________________________________________________________________
1066Int_t
a0eca509 1067AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
de01cdf0 1068{
1069 /// Fill the neighbours store with, for each channel, a TObjArray of its
1070 /// neighbouring pads (including itself)
1071
a99c3449 1072 AliCodeTimerAutoGeneral("",0);
1073
1074 if (!AliMUONCDB::CheckMapping()) return 0;
de01cdf0 1075
a99c3449 1076 AliInfoGeneral("AliMUONCDB", "Generating NeighbourStore. This will take a while. Please be patient.");
de01cdf0 1077
1078 Int_t nchannels(0);
1079
1080 TObjArray tmp;
409de10f 1081
1082 Int_t detElemId;
1083 Int_t manuId;
de01cdf0 1084
409de10f 1085 AliMpManuIterator it;
1086
1087 while ( it.Next(detElemId,manuId) )
de01cdf0 1088 {
de01cdf0 1089 const AliMpVSegmentation* seg =
1090 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
1091
a0eca509 1092 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
de01cdf0 1093 if (!calibParam)
1094 {
1095 Int_t dimension(11);
a0eca509 1096 Int_t size(AliMpConstants::ManuNofChannels());
de01cdf0 1097 Int_t defaultValue(-1);
a0eca509 1098 Int_t packingFactor(size);
de01cdf0 1099
a0eca509 1100 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
1101 Bool_t ok = neighbourStore.Add(calibParam);
de01cdf0 1102 if (!ok)
1103 {
a99c3449 1104 AliErrorGeneral("AliMUONCDB", Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
de01cdf0 1105 return -1;
1106 }
1107 }
1108
a0eca509 1109 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
de01cdf0 1110 {
168e9c4d 1111 AliMpPad pad = seg->PadByLocation(manuId,manuChannel,kFALSE);
de01cdf0 1112
1113 if (pad.IsValid())
1114 {
1115 ++nchannels;
1116
1117 seg->GetNeighbours(pad,tmp,true,true);
1118 Int_t nofPadNeighbours = tmp.GetEntriesFast();
1119
1120 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
1121 {
bf0d3528 1122 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
de01cdf0 1123 Int_t x;
409de10f 1124// Bool_t ok =
6e97fbb8 1125 calibParam->PackValues(p->GetManuId(),p->GetManuChannel(),x);
409de10f 1126// if (!ok)
1127// {
1128// AliError("Could not pack value. Something is seriously wrong. Please check");
1129// StdoutToAliError(pad->Print(););
1130// return -1;
1131// }
de01cdf0 1132 calibParam->SetValueAsInt(manuChannel,i,x);
1133 }
1134 }
1135 }
1136 }
1137
de01cdf0 1138 return nchannels;
1139}
1140
1141//_____________________________________________________________________________
1142void
1143AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
1144{
1145 /// Write local trigger masks to OCDB
1146
630711ed 1147 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
de01cdf0 1148 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
a99c3449 1149 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1150 if (ngenerated>0)
1151 {
1152 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
1153 }
1154 delete ltm;
1155}
1156
1157//_____________________________________________________________________________
1158void
92c23b09 1159AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 1160{
1161 /// Write regional trigger masks to OCDB
1162
92c23b09 1163 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
1164 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
a99c3449 1165 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1166 if (ngenerated>0)
1167 {
92c23b09 1168 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
de01cdf0 1169 }
1170 delete rtm;
1171}
1172
92c23b09 1173
de01cdf0 1174//_____________________________________________________________________________
1175void
92c23b09 1176AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 1177{
1178 /// Write global trigger masks to OCDB
1179
92c23b09 1180 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
de01cdf0 1181
92c23b09 1182 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
a99c3449 1183 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1184 if (ngenerated>0)
1185 {
92c23b09 1186 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
de01cdf0 1187 }
1188 delete gtm;
1189}
1190
92c23b09 1191
de01cdf0 1192//_____________________________________________________________________________
1193void
1194AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
1195{
1196 /// Write trigger LUT to OCDB
1197
1198 AliMUONTriggerLut* lut = MakeTriggerLUT();
1199 if (lut)
1200 {
1201 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
1202 }
1203 delete lut;
1204}
1205
1206//_____________________________________________________________________________
1207void
1208AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
1209{
1210 /// Write trigger efficiency to OCDB
1211
1212 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
1213 if (eff)
1214 {
1215 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
1216 }
1217 delete eff;
1218}
1219
1220//_____________________________________________________________________________
1221void
1222AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
1223{
1224 /// Write neighbours to OCDB
1225
409de10f 1226 AliMUONVStore* neighbours = Create2DMap();
de01cdf0 1227 Int_t ngenerated = MakeNeighbourStore(*neighbours);
a99c3449 1228 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1229 if (ngenerated>0)
1230 {
1231 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
1232 }
1233 delete neighbours;
1234}
1235
1236//_____________________________________________________________________________
1237void
1238AliMUONCDB::WriteHV(Bool_t defaultValues,
1239 Int_t startRun, Int_t endRun)
1240{
1241 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
1242 /// if defaultValues=false, see makeHVStore) and
1243 /// store them into CDB located at cdbpath, with a validity period
1244 /// ranging from startRun to endRun
1245
1246 TMap* hvStore = new TMap;
1247 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
a99c3449 1248 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1249 if (ngenerated>0)
1250 {
1251 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
1252 }
1253 delete hvStore;
1254}
1255
1256//_____________________________________________________________________________
1257void
49e110ec 1258AliMUONCDB::WriteTriggerDCS(Bool_t defaultValues,
1259 Int_t startRun, Int_t endRun)
1260{
1261 /// generate Trigger HV and current values (either const if defaultValues=true or random
1262 /// if defaultValues=false, see makeTriggerDCSStore) and
1263 /// store them into CDB located at cdbpath, with a validity period
1264 /// ranging from startRun to endRun
1265
1266 TMap* triggerDCSStore = new TMap;
1267 Int_t ngenerated = MakeTriggerDCSStore(*triggerDCSStore,defaultValues);
a99c3449 1268 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
49e110ec 1269 if (ngenerated>0)
1270 {
1271 WriteToCDB("MUON/Calib/TriggerDCS",triggerDCSStore,startRun,endRun,defaultValues);
1272 }
1273 delete triggerDCSStore;
1274}
1275
1276//_____________________________________________________________________________
1277void
de01cdf0 1278AliMUONCDB::WritePedestals(Bool_t defaultValues,
1279 Int_t startRun, Int_t endRun)
1280{
1281 /// generate pedestal values (either 0 if defaultValues=true or random
1282 /// if defaultValues=false, see makePedestalStore) and
1283 /// store them into CDB located at cdbpath, with a validity period
1284 /// ranging from startRun to endRun
1285
409de10f 1286 AliMUONVStore* pedestalStore = Create2DMap();
de01cdf0 1287 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
a99c3449 1288 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1289 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
1290 delete pedestalStore;
1291}
1292
2b8a1212 1293//_____________________________________________________________________________
1294void
7eafe398 1295AliMUONCDB::WriteOccupancyMap(Bool_t defaultValues,
1296 Int_t startRun, Int_t endRun)
2b8a1212 1297{
7eafe398 1298 /// generate occupancy map values (either empty one if defaultValues=true, or
1299 /// random one, see MakeOccupancyMapStore) and
2b8a1212 1300 /// store them into CDB located at cdbpath, with a validity period
1301 /// ranging from startRun to endRun
1302
7eafe398 1303 AliMUONVStore* occupancyMapStore = Create2DMap();
1304 Int_t ngenerated = MakeOccupancyMapStore(*occupancyMapStore,defaultValues);
a99c3449 1305 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
7eafe398 1306 WriteToCDB("MUON/Calib/OccupancyMap",occupancyMapStore,startRun,endRun,defaultValues);
1307 delete occupancyMapStore;
2b8a1212 1308}
1309
0045b488 1310//_____________________________________________________________________________
1311void
1312AliMUONCDB::WriteRejectList(Bool_t defaultValues,
1313 Int_t startRun, Int_t endRun)
1314{
1315 /// generate reject list values (either empty one if defaultValues=true, or
1316 /// random one, see MakeRejectListStore) and
1317 /// store them into CDB located at cdbpath, with a validity period
1318 /// ranging from startRun to endRun
1319
1320 AliMUONRejectList* rl = MakeRejectListStore(defaultValues);
1321 WriteToCDB("MUON/Calib/RejectList",rl,startRun,endRun,defaultValues);
1322 delete rl;
1323}
1324
de01cdf0 1325
1326//_____________________________________________________________________________
1327void
1328AliMUONCDB::WriteGains(Bool_t defaultValues,
1329 Int_t startRun, Int_t endRun)
1330{
1331 /// generate gain values (either 1 if defaultValues=true or random
1332 /// if defaultValues=false, see makeGainStore) and
1333 /// store them into CDB located at cdbpath, with a validity period
1334 /// ranging from startRun to endRun
1335
409de10f 1336 AliMUONVStore* gainStore = Create2DMap();
de01cdf0 1337 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
a99c3449 1338 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1339 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
1340 delete gainStore;
1341}
1342
1343//_____________________________________________________________________________
1344void
25e1df3e 1345AliMUONCDB::WriteCapacitances(const char* filename,
1346 Int_t startRun, Int_t endRun)
1347{
1348 /// read manu capacitance and injection gain values from file
1349 /// and store them into CDB located at cdbpath, with a validity period
1350 /// ranging from startRun to endRun
1351
1352 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
1353 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
a99c3449 1354 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
25e1df3e 1355 if ( ngenerated > 0 )
1356 {
1357 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1358 }
1359 delete capaStore;
1360}
1361
1362//_____________________________________________________________________________
1363void
de01cdf0 1364AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1365 Int_t startRun, Int_t endRun)
1366{
1367 /// generate manu capacitance values (either 1 if defaultValues=true or random
1368 /// if defaultValues=false, see makeCapacitanceStore) and
1369 /// store them into CDB located at cdbpath, with a validity period
1370 /// ranging from startRun to endRun
1371
a0eca509 1372 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
de01cdf0 1373 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
a99c3449 1374 AliInfoGeneral("AliMUONCDB", Form("Ngenerated = %d",ngenerated));
de01cdf0 1375 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1376 delete capaStore;
1377}
1378
1379//_____________________________________________________________________________
1380void
49e110ec 1381AliMUONCDB::WriteTrigger(Bool_t defaultValues, Int_t startRun, Int_t endRun)
de01cdf0 1382{
1383 /// Writes all Trigger related calibration to CDB
49e110ec 1384 WriteTriggerDCS(defaultValues,startRun,endRun);
de01cdf0 1385 WriteLocalTriggerMasks(startRun,endRun);
92c23b09 1386 WriteRegionalTriggerConfig(startRun,endRun);
1387 WriteGlobalTriggerConfig(startRun,endRun);
de01cdf0 1388 WriteTriggerLut(startRun,endRun);
1389 WriteTriggerEfficiency(startRun,endRun);
1390}
1391
1392//_____________________________________________________________________________
1393void
a31df857 1394AliMUONCDB::WriteConfig(Int_t startRun, Int_t endRun)
1395{
1396 /// Write complete tracker configuration to OCDB
1397 ostringstream lines;
1398 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1399 AliMpBusPatch* bp;
1400 while ( ( bp = static_cast<AliMpBusPatch*>(next()) ) )
1401 {
1402 for (Int_t imanu = 0; imanu < bp->GetNofManus(); ++imanu)
1403 {
1404 lines << bp->GetId() << " " << bp->GetManuId(imanu) << endl;
1405 }
1406 }
1407
1408 AliMUON2DMap config(kTRUE);
a31df857 1409
042cd64e 1410 AliMUONTrackerIO::DecodeConfig(lines.str().c_str(),config);
a31df857 1411
1412 WriteToCDB("MUON/Calib/Config",&config,startRun,endRun,kTRUE);
1413}
1414
1415//_____________________________________________________________________________
1416void
de01cdf0 1417AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1418{
1419 /// Writes all Tracker related calibration to CDB
1420 WriteHV(defaultValues,startRun,endRun);
1421 WritePedestals(defaultValues,startRun,endRun);
1422 WriteGains(defaultValues,startRun,endRun);
1423 WriteCapacitances(defaultValues,startRun,endRun);
1424 WriteNeighbours(startRun,endRun);
c21c5694 1425 WriteOccupancyMap(defaultValues,startRun,endRun);
1426 WriteRejectList(defaultValues,startRun,endRun);
a31df857 1427 WriteConfig(startRun,endRun);
de01cdf0 1428}
913f1b43 1429
5148da98 1430//_____________________________________________________________________________
1431void
207947f7 1432AliMUONCDB::ShowConfig(Bool_t withStatusMap)
5148da98 1433{
1434 /// Dumps the current tracker configuration, i.e. number and identity of missing buspatches
207947f7 1435 /// If statusMap is true, will also take into account the status map to report the number
1436 /// of good channels
1437
5148da98 1438 if (!AliMUONCDB::CheckOCDB()) return;
1439
1440 AliMUONCDB::LoadMapping();
1441
1442 if (!AliMUONCDB::CheckMapping()) return;
1443
1444 AliCDBEntry* e = AliCDBManager::Instance()->Get("MUON/Calib/Config");
1445
1446 if (!e) return ;
1447
1448 AliMUONVStore* config = static_cast<AliMUONVStore*>(e->GetObject());
1449
207947f7 1450 AliMUONPadStatusMapMaker* statusMapMaker(0x0);
1451 AliMUONCalibrationData* cd(0x0);
1452 AliMUONPadStatusMaker* statusMaker(0x0);
1453
1454 if ( withStatusMap )
1455 {
1456 cd = new AliMUONCalibrationData(AliCDBManager::Instance()->GetRun());
1457
1458 statusMaker = new AliMUONPadStatusMaker(*cd);
1459
1460 AliMUONRecoParam* recoParam = AliMUONCDB::LoadRecoParam();
1461
1462 statusMaker->SetLimits(*recoParam);
1463
1464 delete recoParam;
1465
1466 UInt_t mask = recoParam->PadGoodnessMask();
1467
1468 const Bool_t deferredInitialization = kFALSE;
1469
1470 statusMapMaker = new AliMUONPadStatusMapMaker(*cd,mask,deferredInitialization);
1471 }
1472
5148da98 1473 TIter nextManu(config->CreateIterator());
1474 AliMUONVCalibParam* param;
1475
1476 AliMpExMap buspatches;
1477
1478 while ( ( param = static_cast<AliMUONVCalibParam*>(nextManu()) ) )
1479 {
1480 Int_t detElemId = param->ID0();
1481 Int_t manuId = param->ID1();
1482 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1483 if ( buspatches.GetValue(busPatchId) == 0x0 )
1484 {
1485 buspatches.Add(busPatchId,new TObjString(Form("BP%04d",busPatchId)));
1486 }
1487 }
1488
1489 TArrayI removed(buspatches.GetSize());
1490
1491 TIter next(AliMpDDLStore::Instance()->CreateBusPatchIterator());
1492 AliMpBusPatch* bp;
1493 Int_t n(0);
1494 Int_t nok(0);
1495 Int_t nremoved(0);
1496
207947f7 1497 // accounting of bus patches first
1498
5148da98 1499 while ( ( bp = static_cast<AliMpBusPatch*>(next())))
1500 {
1501 if ( buspatches.GetValue(bp->GetId()) )
1502 {
1503 ++nok;
1504 }
1505 else
1506 {
1507 removed.SetAt(bp->GetId(),nremoved++);
1508 }
5148da98 1509 }
1510
207947f7 1511 // accounting of channels
1512
1513 AliMpManuIterator it;
1514
1515 Int_t totalNumberOfChannels(0);
1516 Int_t removedChannels(0);
1517 Int_t badChannels(0);
1518 Int_t badAndRemovedChannels(0);
1519 Int_t badOrRemovedChannels(0);
1520
1521 Int_t detElemId, manuId;
1522
1523 while ( it.Next(detElemId,manuId) )
1524 {
1525 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
1526 for ( Int_t i = 0; i < AliMpConstants::ManuNofChannels(); ++i )
1527 {
1528 Int_t busPatchId = AliMpDDLStore::Instance()->GetBusPatchId(detElemId,manuId);
1529
1530 if ( de->IsConnectedChannel(manuId,i) )
1531 {
1532 ++totalNumberOfChannels;
1533 Bool_t badBusPatch = ( buspatches.GetValue(busPatchId) == 0x0 );
1534
1535 if ( withStatusMap )
1536 {
1537 Bool_t badChannel = ( statusMapMaker->StatusMap(detElemId,manuId,i) & AliMUONPadStatusMapMaker::SelfDeadMask() != 0);
1538 if ( badChannel ) ++badChannels;
1539 if ( badBusPatch && badChannel ) ++badAndRemovedChannels;
1540 if ( badBusPatch || badChannel ) ++badOrRemovedChannels;
1541 }
1542
1543 if ( badBusPatch) ++removedChannels;
1544 }
1545 }
1546 }
1547
5148da98 1548
1549 Int_t* indices = new Int_t[nremoved];
1550
1551 TMath::Sort(nremoved,removed.GetArray(),indices,kFALSE);
1552
1553 for ( Int_t i = 0; i < nremoved; ++i )
1554 {
1555 Int_t busPatchId = removed[indices[i]];
1556 bp = AliMpDDLStore::Instance()->GetBusPatch(busPatchId);
1557 bp->Print();
1558 }
1559
1560 delete[] indices;
207947f7 1561
1562 cout << endl;
1563 cout << Form("Bus patches n=%3d nok=%3d nremoved=%3d",n,nok,nremoved) << endl;
1564
1565 cout << Form("Channels n=%6d nremoved=%6d bad=%6d bad and removed=%6d bad or removed=%6d",
1566 totalNumberOfChannels,removedChannels,badChannels,badAndRemovedChannels,badOrRemovedChannels) << endl;
1567
1568 if (totalNumberOfChannels>0)
1569 {
1570 cout << Form("Percentage of readout channels %5.1f %%",removedChannels*100.0/totalNumberOfChannels) << endl;
1571 if ( withStatusMap )
1572 {
1573 cout << Form("Percentage of non useable channels (bad or removed) %5.1f %%",
1574 badOrRemovedChannels*100.0/totalNumberOfChannels) << endl;
1575 }
1576 }
1577
1578
1579 delete statusMapMaker;
1580 delete cd;
1581 delete statusMaker;
5148da98 1582}