]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONCDB.cxx
New classes for finding multiple vertices (in case of pile-up). They will be used...
[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//-----------------------------------------------------------------------------
de01cdf0 19/// \class AliMUONCDB
20///
21/// Helper class to experience the OCDB
22/// It allows to generate dummy (but complete) containers for all the
23/// calibration data types we have for tracker and trigger, and to write
24/// them into OCDB.
25///
26/// For more information, please see READMECDB
27///
28// \author Laurent Aphecetche
3d1463c8 29//-----------------------------------------------------------------------------
de01cdf0 30
31#include "AliMUONCDB.h"
32
de01cdf0 33#include "AliMUON1DArray.h"
34#include "AliMUON1DMap.h"
35#include "AliMUON2DMap.h"
36#include "AliMUON2DStoreValidator.h"
37#include "AliMUONCalibParamNF.h"
38#include "AliMUONCalibParamNI.h"
39#include "AliMUONConstants.h"
49419555 40#include "AliMUONTrackerIO.h"
de01cdf0 41#include "AliMUONTriggerEfficiencyCells.h"
42#include "AliMUONTriggerLut.h"
a0eca509 43#include "AliMUONVStore.h"
de01cdf0 44#include "AliMUONVCalibParam.h"
45#include "AliMUONVCalibParam.h"
92c23b09 46#include "AliMUONGlobalCrateConfig.h"
47#include "AliMUONRegionalTriggerConfig.h"
92e36663 48
25e1df3e 49#include "AliMpCDB.h"
a0eca509 50#include "AliMpConstants.h"
de01cdf0 51#include "AliMpDDLStore.h"
ab167304 52#include "AliMpManuStore.h"
de01cdf0 53#include "AliMpDEManager.h"
54#include "AliMpDetElement.h"
92c23b09 55#include "AliMpFiles.h"
409de10f 56#include "AliMpHVNamer.h"
57#include "AliMpManuIterator.h"
de01cdf0 58#include "AliMpSegmentation.h"
59#include "AliMpStationType.h"
60#include "AliMpVSegmentation.h"
92e36663 61
62#include "AliCodeTimer.h"
63#include "AliCDBEntry.h"
64#include "AliCDBManager.h"
65#include "AliDCSValue.h"
66#include "AliLog.h"
67
de01cdf0 68#include <Riostream.h>
69#include <TArrayI.h>
70#include <TClass.h>
71#include <TH1F.h>
72#include <TList.h>
73#include <TMap.h>
74#include <TObjString.h>
75#include <TROOT.h>
76#include <TRandom.h>
77#include <TStopwatch.h>
78#include <TSystem.h>
cf27231a 79#include <TMath.h>
de01cdf0 80
c05673c9 81
de01cdf0 82/// \cond CLASSIMP
83ClassImp(AliMUONCDB)
84/// \endcond
85
de01cdf0 86namespace
87{
409de10f 88 //_____________________________________________________________________________
89AliMUONVStore* Create2DMap()
90{
91 return new AliMUON2DMap(true);
92}
93
94 //_____________________________________________________________________________
046e5fd4 95void getBoundaries(const AliMUONVStore& store, Int_t dim,
96 Float_t* xmin, Float_t* xmax)
de01cdf0 97{
046e5fd4 98 /// Assuming the store contains AliMUONVCalibParam objects, compute the
99 /// limits of the value contained in the VCalibParam, for each of its dimensions
100 /// xmin and xmax must be of dimension dim
101
102 for ( Int_t i = 0; i < dim; ++i )
103 {
104 xmin[i]=1E30;
105 xmax[i]=-1E30;
106 }
de01cdf0 107
a0eca509 108 TIter next(store.CreateIterator());
109 AliMUONVCalibParam* value;
de01cdf0 110
a0eca509 111 while ( ( value = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 112 {
a0eca509 113 Int_t detElemId = value->ID0();
114 Int_t manuId = value->ID1();
de01cdf0 115
116 const AliMpVSegmentation* seg =
117 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
118
119 for ( Int_t manuChannel = 0; manuChannel < value->Size(); ++manuChannel )
120 {
121 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
122 if (!pad.IsValid()) continue;
123
046e5fd4 124 for ( Int_t i = 0; i < dim; ++i )
de01cdf0 125 {
046e5fd4 126 Float_t x0 = value->ValueAsFloat(manuChannel,i);
127
128 xmin[i] = TMath::Min(xmin[i],x0);
129 xmax[i] = TMath::Max(xmax[i],x0);
de01cdf0 130 }
131 }
046e5fd4 132 }
133
134 for ( Int_t i = 0; i < dim; ++i )
135 {
136 if ( TMath::Abs(xmin[i]-xmax[i]) < 1E-3 )
137 {
138 xmin[i] -= 1;
139 xmax[i] += 1;
140 }
141 }
de01cdf0 142}
143
cf27231a 144//_____________________________________________________________________________
145Double_t GetRandom(Double_t mean, Double_t sigma, Bool_t mustBePositive)
146{
147 Double_t x(-1);
148 if ( mustBePositive )
149 {
150 while ( x < 0 )
151 {
152 x = gRandom->Gaus(mean,sigma);
153 }
154 }
155 else
156 {
157 x = gRandom->Gaus(mean,sigma);
158 }
159 return x;
160}
161
de01cdf0 162}
163
164//_____________________________________________________________________________
165AliMUONCDB::AliMUONCDB(const char* cdbpath)
166: TObject(),
167 fCDBPath(cdbpath),
046e5fd4 168 fMaxNofChannelsToGenerate(-1)
de01cdf0 169{
409de10f 170 /// ctor
92e36663 171 // Load mapping
0145e89a 172 if ( ! AliMpCDB::LoadDDLStore() ) {
92e36663 173 AliFatal("Could not access mapping from OCDB !");
174 }
ab167304 175
176 if ( ! AliMpCDB::LoadManuStore() ) {
177 AliFatal("Could not access run-dependent mapping from OCDB !");
178 }
de01cdf0 179}
180
181//_____________________________________________________________________________
182AliMUONCDB::~AliMUONCDB()
183{
184 /// dtor
a0eca509 185}
186
187//_____________________________________________________________________________
188AliMUONVStore*
189AliMUONCDB::Diff(AliMUONVStore& store1, AliMUONVStore& store2,
de01cdf0 190 const char* opt)
191{
192 /// creates a store which contains store1-store2
193 /// if opt="abs" the difference is absolute one,
194 /// if opt="rel" then what is stored is (store1-store2)/store1
046e5fd4 195 /// if opt="percent" then what is stored is rel*100
196 ///
de01cdf0 197 /// WARNING Works only for stores which holds AliMUONVCalibParam objects
198
199 TString sopt(opt);
200 sopt.ToUpper();
201
046e5fd4 202 if ( !sopt.Contains("ABS") && !sopt.Contains("REL") && !sopt.Contains("PERCENT") )
de01cdf0 203 {
046e5fd4 204 AliErrorClass(Form("opt %s not supported. Only ABS, REL, PERCENT are",opt));
de01cdf0 205 return 0x0;
206 }
207
a0eca509 208 AliMUONVStore* d = static_cast<AliMUONVStore*>(store1.Clone());
de01cdf0 209
a0eca509 210 TIter next(d->CreateIterator());
de01cdf0 211
a0eca509 212 AliMUONVCalibParam* param;
de01cdf0 213
a0eca509 214 while ( ( param = dynamic_cast<AliMUONVCalibParam*>(next() ) ) )
de01cdf0 215 {
a0eca509 216 Int_t detElemId = param->ID0();
217 Int_t manuId = param->ID1();
de01cdf0 218
a0eca509 219 AliMUONVCalibParam* param2 = dynamic_cast<AliMUONVCalibParam*>(store2.FindObject(detElemId,manuId));
de01cdf0 220 //FIXME: this might happen. Handle it.
221 if (!param2)
222 {
223 cerr << "param2 is null : FIXME : this might happen !" << endl;
224 delete d;
225 return 0;
226 }
227
228 for ( Int_t i = 0; i < param->Size(); ++i )
229 {
230 for ( Int_t j = 0; j < param->Dimension(); ++j )
231 {
232 Float_t value(0);
233 if ( sopt.Contains("ABS") )
234 {
235 value = param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j);
236 }
046e5fd4 237 else if ( sopt.Contains("REL") || sopt.Contains("PERCENT") )
de01cdf0 238 {
239 if ( param->ValueAsFloat(i,j) )
240 {
241 value = (param->ValueAsFloat(i,j) - param2->ValueAsFloat(i,j))/param->ValueAsFloat(i,j);
242 }
243 else
244 {
245 continue;
246 }
046e5fd4 247 if ( sopt.Contains("PERCENT") ) value *= 100.0;
de01cdf0 248 }
249 param->SetValueAsFloat(i,j,value);
250 }
251 }
de01cdf0 252 }
253 return d;
254}
255
256//_____________________________________________________________________________
257void
a0eca509 258AliMUONCDB::Plot(const AliMUONVStore& store, const char* name, Int_t nbins)
de01cdf0 259{
046e5fd4 260 /// Make histograms of each dimension of the AliMUONVCalibParam
de01cdf0 261 /// contained inside store.
262 /// It produces histograms named name_0, name_1, etc...
263
046e5fd4 264 TIter next(store.CreateIterator());
265 AliMUONVCalibParam* param;
de01cdf0 266 Int_t n(0);
046e5fd4 267 const Int_t kNStations = AliMpConstants::NofTrackingChambers()/2;
268 Int_t* nPerStation = new Int_t[kNStations];
269 TH1** h(0x0);
de01cdf0 270
046e5fd4 271 for ( Int_t i = 0; i < kNStations; ++i ) nPerStation[i]=0;
de01cdf0 272
046e5fd4 273 while ( ( param = static_cast<AliMUONVCalibParam*>(next()) ) )
de01cdf0 274 {
046e5fd4 275 if (!h)
276 {
277 Int_t dim = param->Dimension();
278 h = new TH1*[dim];
279 Float_t* xmin = new Float_t[dim];
280 Float_t* xmax = new Float_t[dim];
281 getBoundaries(store,dim,xmin,xmax);
282
283 for ( Int_t i = 0; i < dim; ++i )
284 {
285 h[i] = new TH1F(Form("%s_%d",name,i),Form("%s_%d",name,i),
286 nbins,xmin[i],xmax[i]);
287 AliInfo(Form("Created histogram %s",h[i]->GetName()));
288 }
289 }
290
291 Int_t detElemId = param->ID0();
292 Int_t manuId = param->ID1();
293 Int_t station = AliMpDEManager::GetChamberId(detElemId)/2;
de01cdf0 294
295 const AliMpVSegmentation* seg =
296 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
297
046e5fd4 298 for ( Int_t manuChannel = 0; manuChannel < param->Size(); ++manuChannel )
de01cdf0 299 {
046e5fd4 300 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
301 if (!pad.IsValid()) continue;
de01cdf0 302
046e5fd4 303 ++n;
304 ++nPerStation[station];
305
306 for ( Int_t dim = 0; dim < param->Dimension(); ++dim )
307 {
308 h[dim]->Fill(param->ValueAsFloat(manuChannel,dim));
de01cdf0 309 }
310 }
046e5fd4 311 }
de01cdf0 312
046e5fd4 313 for ( Int_t i = 0; i < kNStations; ++i )
de01cdf0 314 {
315 AliInfo(Form("Station %d %d ",(i+1),nPerStation[i]));
316 }
046e5fd4 317
318 AliInfo(Form("Number of channels = %d",n));
319
320 delete[] nPerStation;
de01cdf0 321}
322
323//_____________________________________________________________________________
324Int_t
325AliMUONCDB::MakeHVStore(TMap& aliasMap, Bool_t defaultValues)
326{
327 /// Create a HV store
328
409de10f 329 AliMpHVNamer hvNamer;
de01cdf0 330
331 TObjArray* aliases = hvNamer.GenerateAliases();
332
333 Int_t nSwitch(0);
334 Int_t nChannels(0);
335
336 for ( Int_t i = 0; i < aliases->GetEntries(); ++i )
337 {
338 TObjString* alias = static_cast<TObjString*>(aliases->At(i));
339 TString& aliasName = alias->String();
340 if ( aliasName.Contains("sw") )
341 {
342 // HV Switch (St345 only)
343 TObjArray* valueSet = new TObjArray;
344 valueSet->SetOwner(kTRUE);
345
346 Bool_t value = kTRUE;
347
348 if (!defaultValues)
349 {
a0eca509 350 Float_t r = gRandom->Uniform();
de01cdf0 351 if ( r < 0.007 ) value = kFALSE;
352 }
353
354 for ( UInt_t timeStamp = 0; timeStamp < 60*3; timeStamp += 60 )
355 {
356 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
357 valueSet->Add(dcsValue);
358 }
359 aliasMap.Add(new TObjString(*alias),valueSet);
360 ++nSwitch;
361 }
362 else
363 {
364 TObjArray* valueSet = new TObjArray;
365 valueSet->SetOwner(kTRUE);
366 for ( UInt_t timeStamp = 0; timeStamp < 60*15; timeStamp += 120 )
367 {
368 Float_t value = 1500;
cf27231a 369 if (!defaultValues) value = GetRandom(1750,62.5,true);
de01cdf0 370 AliDCSValue* dcsValue = new AliDCSValue(value,timeStamp);
371 valueSet->Add(dcsValue);
372 }
373 aliasMap.Add(new TObjString(*alias),valueSet);
374 ++nChannels;
375 }
376 }
377
378 delete aliases;
379
380 AliInfo(Form("%d HV channels and %d switches",nChannels,nSwitch));
381
382 return nChannels+nSwitch;
383}
384
385//_____________________________________________________________________________
386Int_t
a0eca509 387AliMUONCDB::MakePedestalStore(AliMUONVStore& pedestalStore, Bool_t defaultValues)
de01cdf0 388{
389 /// Create a pedestal store. if defaultValues=true, ped.mean=ped.sigma=1,
390 /// otherwise mean and sigma are from a gaussian (with parameters
391 /// defined below by the kPedestal* constants)
409de10f 392
393 AliCodeTimerAuto("");
de01cdf0 394
395 Int_t nchannels(0);
396 Int_t nmanus(0);
397
a0eca509 398 const Int_t kChannels(AliMpConstants::ManuNofChannels());
de01cdf0 399 const Float_t kPedestalMeanMean(200);
400 const Float_t kPedestalMeanSigma(10);
401 const Float_t kPedestalSigmaMean(1.0);
402 const Float_t kPedestalSigmaSigma(0.2);
409de10f 403
404 Int_t detElemId;
405 Int_t manuId;
406
407 AliMpManuIterator it;
de01cdf0 408
409de10f 409 while ( it.Next(detElemId,manuId) )
de01cdf0 410 {
411 ++nmanus;
a0eca509 412
046e5fd4 413 AliMUONVCalibParam* ped =
414 new AliMUONCalibParamNF(2,kChannels,detElemId,manuId,AliMUONVCalibParam::InvalidFloatValue());
409de10f 415
416 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 417
418 for ( Int_t manuChannel = 0; manuChannel < kChannels; ++manuChannel )
419 {
409de10f 420 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 421
422 ++nchannels;
423
424 Float_t meanPedestal;
425 Float_t sigmaPedestal;
426
427 if ( defaultValues )
428 {
429 meanPedestal = 0.0;
430 sigmaPedestal = 1.0;
431 }
432 else
433 {
cf27231a 434 Bool_t positive(kTRUE);
046e5fd4 435 meanPedestal = 0.0;
436 while ( meanPedestal == 0.0 ) // avoid strict zero
437 {
438 meanPedestal = GetRandom(kPedestalMeanMean,kPedestalMeanSigma,positive);
439 }
cf27231a 440 sigmaPedestal = GetRandom(kPedestalSigmaMean,kPedestalSigmaSigma,positive);
de01cdf0 441 }
442 ped->SetValueAsFloat(manuChannel,0,meanPedestal);
443 ped->SetValueAsFloat(manuChannel,1,sigmaPedestal);
444
445 }
a0eca509 446 Bool_t ok = pedestalStore.Add(ped);
de01cdf0 447 if (!ok)
448 {
449 AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
450 }
046e5fd4 451 if ( fMaxNofChannelsToGenerate > 0 && nchannels >= fMaxNofChannelsToGenerate ) break;
de01cdf0 452 }
453
454 AliInfo(Form("%d Manus and %d channels.",nmanus,nchannels));
455 return nchannels;
de01cdf0 456}
457
25e1df3e 458//_____________________________________________________________________________
459Int_t
460AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, const char* file)
461{
6687de6d 462 /// Read the capacitance values from file and append them to the capaStore
463
49419555 464 return AliMUONTrackerIO::ReadCapacitances(file,capaStore);
25e1df3e 465}
466
de01cdf0 467//_____________________________________________________________________________
468Int_t
a0eca509 469AliMUONCDB::MakeCapacitanceStore(AliMUONVStore& capaStore, Bool_t defaultValues)
de01cdf0 470{
471 /// Create a capacitance store. if defaultValues=true, all capa are 1.0,
472 /// otherwise they are from a gaussian with parameters defined in the
473 /// kCapa* constants below.
409de10f 474
475 AliCodeTimerAuto("");
de01cdf0 476
477 Int_t nchannels(0);
478 Int_t nmanus(0);
479 Int_t nmanusOK(0); // manus for which we got the serial number
a0eca509 480
25e1df3e 481 const Float_t kCapaMean(0.3);
482 const Float_t kCapaSigma(0.1);
483 const Float_t kInjectionGainMean(3);
484 const Float_t kInjectionGainSigma(1);
409de10f 485
486 Int_t detElemId;
487 Int_t manuId;
488
489 AliMpManuIterator it;
de01cdf0 490
409de10f 491 while ( it.Next(detElemId,manuId) )
de01cdf0 492 {
493 ++nmanus;
494
de01cdf0 495 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
ab167304 496 Int_t serialNumber = AliMpManuStore::Instance()->GetManuSerial(detElemId, manuId);
de01cdf0 497
a0eca509 498 if ( serialNumber <= 0 ) continue;
499
500 ++nmanusOK;
de01cdf0 501
a0eca509 502 AliMUONVCalibParam* capa = static_cast<AliMUONVCalibParam*>(capaStore.FindObject(serialNumber));
de01cdf0 503
504 if (!capa)
505 {
25e1df3e 506 capa = new AliMUONCalibParamNF(2,AliMpConstants::ManuNofChannels(),serialNumber,0,1.0);
a0eca509 507 Bool_t ok = capaStore.Add(capa);
de01cdf0 508 if (!ok)
509 {
510 AliError(Form("Could not set serialNumber=%d manuId=%d",serialNumber,manuId));
511 }
512 }
513
514 for ( Int_t manuChannel = 0; manuChannel < capa->Size(); ++manuChannel )
515 {
409de10f 516 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 517
518 ++nchannels;
519
520 Float_t capaValue;
25e1df3e 521 Float_t injectionGain;
de01cdf0 522
523 if ( defaultValues )
524 {
525 capaValue = 1.0;
25e1df3e 526 injectionGain = 1.0;
de01cdf0 527 }
528 else
529 {
cf27231a 530 capaValue = GetRandom(kCapaMean,kCapaSigma,kTRUE);
25e1df3e 531 injectionGain = GetRandom(kInjectionGainMean,kInjectionGainSigma,kTRUE);
de01cdf0 532 }
533 capa->SetValueAsFloat(manuChannel,0,capaValue);
25e1df3e 534 capa->SetValueAsFloat(manuChannel,1,injectionGain);
de01cdf0 535 }
536 }
537
538 Float_t percent = 0;
539 if ( nmanus ) percent = 100*nmanusOK/nmanus;
540 AliInfo(Form("%5d manus with serial number (out of %5d manus = %3.0f%%)",
541 nmanusOK,nmanus,percent));
542 AliInfo(Form("%5d channels",nchannels));
543 if ( percent < 100 )
544 {
545 AliWarning("Did not get all serial numbers. capaStore is incomplete !!!!");
546 }
547 return nchannels;
548
549}
550
551//_____________________________________________________________________________
552Int_t
a0eca509 553AliMUONCDB::MakeGainStore(AliMUONVStore& gainStore, Bool_t defaultValues)
de01cdf0 554{
cf27231a 555 /// Create a gain store. if defaultValues=true, all gains set so that
556 /// charge = (adc-ped)
557 ///
558 /// otherwise parameters are taken from gaussians with parameters
559 /// defined in the k* constants below.
de01cdf0 560
409de10f 561 AliCodeTimerAuto("");
de01cdf0 562
563 Int_t nchannels(0);
564 Int_t nmanus(0);
a0eca509 565
cf27231a 566 const Int_t kSaturation(3000);
567 const Double_t kA0Mean(1.2);
409de10f 568 const Double_t kA0Sigma(0.1);
569 const Double_t kA1Mean(1E-5);
570 const Double_t kA1Sigma(1E-6);
cf27231a 571 const Double_t kQualMean(0xFF);
572 const Double_t kQualSigma(0x10);
573 const Int_t kThresMean(1600);
409de10f 574 const Int_t kThresSigma(100);
575
576 Int_t detElemId;
577 Int_t manuId;
de01cdf0 578
409de10f 579 AliMpManuIterator it;
580
581 while ( it.Next(detElemId,manuId) )
de01cdf0 582 {
583 ++nmanus;
de01cdf0 584
a0eca509 585 AliMUONVCalibParam* gain =
cf27231a 586 new AliMUONCalibParamNF(5,AliMpConstants::ManuNofChannels(),
a0eca509 587 detElemId,
588 manuId,
589 AliMUONVCalibParam::InvalidFloatValue());
590
409de10f 591 AliMpDetElement* de = AliMpDDLStore::Instance()->GetDetElement(detElemId);
de01cdf0 592
593 for ( Int_t manuChannel = 0; manuChannel < gain->Size(); ++manuChannel )
594 {
409de10f 595 if ( ! de->IsConnectedChannel(manuId,manuChannel) ) continue;
de01cdf0 596
597 ++nchannels;
598
de01cdf0 599 if ( defaultValues )
600 {
cf27231a 601 gain->SetValueAsFloat(manuChannel,0,1.0);
602 gain->SetValueAsFloat(manuChannel,1,0.0);
603 gain->SetValueAsInt(manuChannel,2,4095);
604 gain->SetValueAsInt(manuChannel,3,1);
605 gain->SetValueAsInt(manuChannel,4,kSaturation);
de01cdf0 606 }
607 else
608 {
cf27231a 609 Bool_t positive(kTRUE);
610 gain->SetValueAsFloat(manuChannel,0,GetRandom(kA0Mean,kA0Sigma,positive));
611 gain->SetValueAsFloat(manuChannel,1,GetRandom(kA1Mean,kA1Sigma,!positive));
612 gain->SetValueAsInt(manuChannel,2,(Int_t)TMath::Nint(GetRandom(kThresMean,kThresSigma,positive)));
613 gain->SetValueAsInt(manuChannel,3,(Int_t)TMath::Nint(GetRandom(kQualMean,kQualSigma,positive)));
614 gain->SetValueAsInt(manuChannel,4,kSaturation);
de01cdf0 615 }
de01cdf0 616
617 }
a0eca509 618 Bool_t ok = gainStore.Add(gain);
de01cdf0 619 if (!ok)
620 {
621 AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
622 }
046e5fd4 623 if ( fMaxNofChannelsToGenerate > 0 && nchannels >= fMaxNofChannelsToGenerate ) break;
de01cdf0 624 }
625
626 AliInfo(Form("%d Manus and %d channels.",nmanus,nchannels));
627 return nchannels;
628}
629
630//_____________________________________________________________________________
631Int_t
a0eca509 632AliMUONCDB::MakeLocalTriggerMaskStore(AliMUONVStore& localBoardMasks) const
de01cdf0 633{
634 /// Generate local trigger masks store. All masks are set to FFFF
635
409de10f 636 AliCodeTimerAuto("");
637
de01cdf0 638 Int_t ngenerated(0);
630711ed 639 // Generate fake mask values for all localboards and put that into
de01cdf0 640 // one single container (localBoardMasks)
0145e89a 641 for ( Int_t i = 1; i <= AliMpConstants::TotalNofLocalBoards(); ++i )
de01cdf0 642 {
a0eca509 643 AliMUONVCalibParam* localBoard = new AliMUONCalibParamNI(1,8,i,0,0);
de01cdf0 644 for ( Int_t x = 0; x < 2; ++x )
645 {
646 for ( Int_t y = 0; y < 4; ++y )
647 {
648 Int_t index = x*4+y;
649 localBoard->SetValueAsInt(index,0,0xFFFF);
650 ++ngenerated;
651 }
652 }
a0eca509 653 localBoardMasks.Add(localBoard);
de01cdf0 654 }
655 return ngenerated;
656}
657
658//_____________________________________________________________________________
659Int_t
92c23b09 660AliMUONCDB::MakeRegionalTriggerConfigStore(AliMUONRegionalTriggerConfig& rtm) const
de01cdf0 661{
92c23b09 662 /// Make a regional trigger config store. Mask is set to FFFF for each local board (Ch.F.)
de01cdf0 663
409de10f 664 AliCodeTimerAuto("");
665
5cc125b2 666 if ( ! rtm.ReadData(AliMpFiles::LocalTriggerBoardMapping()) ) {
667 AliErrorStream() << "Error when reading from mapping file" << endl;
668 return 0;
669 }
670
671 return rtm.GetNofTriggerCrates();
de01cdf0 672}
673
92c23b09 674
de01cdf0 675//_____________________________________________________________________________
676Int_t
92c23b09 677AliMUONCDB::MakeGlobalTriggerConfigStore(AliMUONGlobalCrateConfig& gtm) const
de01cdf0 678{
92c23b09 679 /// Make a global trigger config store. All masks (disable) set to 0x00 for each Darc board (Ch.F.)
de01cdf0 680
409de10f 681 AliCodeTimerAuto("");
913f1b43 682
683 return gtm.ReadData(AliMpFiles::GlobalTriggerBoardMapping());
de01cdf0 684}
685
92c23b09 686
de01cdf0 687//_____________________________________________________________________________
688AliMUONTriggerLut*
689AliMUONCDB::MakeTriggerLUT(const char* file) const
690{
691 /// Make a triggerlut object, from a file.
692
409de10f 693 AliCodeTimerAuto("");
694
de01cdf0 695 AliMUONTriggerLut* lut = new AliMUONTriggerLut;
696 lut->ReadFromFile(file);
697 return lut;
698}
699
700//_____________________________________________________________________________
701AliMUONTriggerEfficiencyCells*
702AliMUONCDB::MakeTriggerEfficiency(const char* file) const
703{
704 /// Make a trigger efficiency object from a file.
705
409de10f 706 AliCodeTimerAuto("");
707
de01cdf0 708 return new AliMUONTriggerEfficiencyCells(file);
709}
710
25e1df3e 711//_____________________________________________________________________________
712void
713AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
714 Int_t startRun, Int_t endRun,
715 const char* filename)
716{
717 /// Write a given object to OCDB
718
913f1b43 719 TString comment(gSystem->ExpandPathName(filename));
720
721 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
25e1df3e 722}
723
de01cdf0 724//_____________________________________________________________________________
725void
726AliMUONCDB::WriteToCDB(const char* calibpath, TObject* object,
727 Int_t startRun, Int_t endRun, Bool_t defaultValues)
728{
729 /// Write a given object to OCDB
730
913f1b43 731 TString comment;
732 if ( defaultValues ) comment += "Test with default values";
733 else comment += "Test with random values";
734
735 WriteToCDB(object, calibpath, startRun, endRun, comment.Data());
736}
737
738//_____________________________________________________________________________
739void
740AliMUONCDB::WriteToCDB(TObject* object, const char* calibpath, Int_t startRun, Int_t endRun,
741 const char* comment, const char* responsible)
742{
743 /// Write a given object to OCDB
744
de01cdf0 745 AliCDBId id(calibpath,startRun,endRun);
746 AliCDBMetaData md;
747 md.SetAliRootVersion(gROOT->GetVersion());
913f1b43 748 md.SetComment(comment);
749 md.SetResponsible(responsible);
de01cdf0 750 AliCDBManager* man = AliCDBManager::Instance();
913f1b43 751 if (!man->IsDefaultStorageSet()) man->SetDefaultStorage(fCDBPath);
de01cdf0 752 man->Put(object,id,&md);
753}
754
755//_____________________________________________________________________________
756Int_t
a0eca509 757AliMUONCDB::MakeNeighbourStore(AliMUONVStore& neighbourStore)
de01cdf0 758{
759 /// Fill the neighbours store with, for each channel, a TObjArray of its
760 /// neighbouring pads (including itself)
761
409de10f 762 AliCodeTimerAuto("");
de01cdf0 763
409de10f 764 AliInfo("Generating NeighbourStore. This will take a while. Please be patient.");
de01cdf0 765
766 Int_t nchannels(0);
767
768 TObjArray tmp;
409de10f 769
770 Int_t detElemId;
771 Int_t manuId;
de01cdf0 772
409de10f 773 AliMpManuIterator it;
774
775 while ( it.Next(detElemId,manuId) )
de01cdf0 776 {
de01cdf0 777 const AliMpVSegmentation* seg =
778 AliMpSegmentation::Instance()->GetMpSegmentationByElectronics(detElemId,manuId);
779
a0eca509 780 AliMUONVCalibParam* calibParam = static_cast<AliMUONVCalibParam*>(neighbourStore.FindObject(detElemId,manuId));
de01cdf0 781 if (!calibParam)
782 {
783 Int_t dimension(11);
a0eca509 784 Int_t size(AliMpConstants::ManuNofChannels());
de01cdf0 785 Int_t defaultValue(-1);
a0eca509 786 Int_t packingFactor(size);
de01cdf0 787
a0eca509 788 calibParam = new AliMUONCalibParamNI(dimension,size,detElemId,manuId,defaultValue,packingFactor);
789 Bool_t ok = neighbourStore.Add(calibParam);
de01cdf0 790 if (!ok)
791 {
792 AliError(Form("Could not set DetElemId=%d manuId=%d",detElemId,manuId));
793 return -1;
794 }
795 }
796
a0eca509 797 for ( Int_t manuChannel = 0; manuChannel < AliMpConstants::ManuNofChannels(); ++manuChannel )
de01cdf0 798 {
799 AliMpPad pad = seg->PadByLocation(AliMpIntPair(manuId,manuChannel),kFALSE);
800
801 if (pad.IsValid())
802 {
803 ++nchannels;
804
805 seg->GetNeighbours(pad,tmp,true,true);
806 Int_t nofPadNeighbours = tmp.GetEntriesFast();
807
808 for ( Int_t i = 0; i < nofPadNeighbours; ++i )
809 {
bf0d3528 810 AliMpPad* p = static_cast<AliMpPad*>(tmp.UncheckedAt(i));
de01cdf0 811 Int_t x;
409de10f 812// Bool_t ok =
bf0d3528 813 calibParam->PackValues(p->GetLocation().GetFirst(),p->GetLocation().GetSecond(),x);
409de10f 814// if (!ok)
815// {
816// AliError("Could not pack value. Something is seriously wrong. Please check");
817// StdoutToAliError(pad->Print(););
818// return -1;
819// }
de01cdf0 820 calibParam->SetValueAsInt(manuChannel,i,x);
821 }
822 }
823 }
824 }
825
de01cdf0 826 return nchannels;
827}
828
046e5fd4 829//_____________________________________________________________________________
830void
831AliMUONCDB::SetMaxNofChannelsToGenerate(Int_t n)
832{
833 /// Set the maximum number of channels to generate (used for testing only)
834 /// n < 0 means no limit
835 fMaxNofChannelsToGenerate = n;
836}
837
de01cdf0 838//_____________________________________________________________________________
839void
840AliMUONCDB::WriteLocalTriggerMasks(Int_t startRun, Int_t endRun)
841{
842 /// Write local trigger masks to OCDB
843
630711ed 844 AliMUONVStore* ltm = new AliMUON1DArray(AliMpConstants::TotalNofLocalBoards()+1);
de01cdf0 845 Int_t ngenerated = MakeLocalTriggerMaskStore(*ltm);
846 AliInfo(Form("Ngenerated = %d",ngenerated));
847 if (ngenerated>0)
848 {
849 WriteToCDB("MUON/Calib/LocalTriggerBoardMasks",ltm,startRun,endRun,true);
850 }
851 delete ltm;
852}
853
854//_____________________________________________________________________________
855void
92c23b09 856AliMUONCDB::WriteRegionalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 857{
858 /// Write regional trigger masks to OCDB
859
92c23b09 860 AliMUONRegionalTriggerConfig* rtm = new AliMUONRegionalTriggerConfig();
861 Int_t ngenerated = MakeRegionalTriggerConfigStore(*rtm);
de01cdf0 862 AliInfo(Form("Ngenerated = %d",ngenerated));
863 if (ngenerated>0)
864 {
92c23b09 865 WriteToCDB("MUON/Calib/RegionalTriggerConfig",rtm,startRun,endRun,true);
de01cdf0 866 }
867 delete rtm;
868}
869
92c23b09 870
de01cdf0 871//_____________________________________________________________________________
872void
92c23b09 873AliMUONCDB::WriteGlobalTriggerConfig(Int_t startRun, Int_t endRun)
de01cdf0 874{
875 /// Write global trigger masks to OCDB
876
92c23b09 877 AliMUONGlobalCrateConfig* gtm = new AliMUONGlobalCrateConfig();
de01cdf0 878
92c23b09 879 Int_t ngenerated = MakeGlobalTriggerConfigStore(*gtm);
de01cdf0 880 AliInfo(Form("Ngenerated = %d",ngenerated));
881 if (ngenerated>0)
882 {
92c23b09 883 WriteToCDB("MUON/Calib/GlobalTriggerCrateConfig",gtm,startRun,endRun,true);
de01cdf0 884 }
885 delete gtm;
886}
887
92c23b09 888
de01cdf0 889//_____________________________________________________________________________
890void
891AliMUONCDB::WriteTriggerLut(Int_t startRun, Int_t endRun)
892{
893 /// Write trigger LUT to OCDB
894
895 AliMUONTriggerLut* lut = MakeTriggerLUT();
896 if (lut)
897 {
898 WriteToCDB("MUON/Calib/TriggerLut",lut,startRun,endRun,true);
899 }
900 delete lut;
901}
902
903//_____________________________________________________________________________
904void
905AliMUONCDB::WriteTriggerEfficiency(Int_t startRun, Int_t endRun)
906{
907 /// Write trigger efficiency to OCDB
908
909 AliMUONTriggerEfficiencyCells* eff = MakeTriggerEfficiency();
910 if (eff)
911 {
912 WriteToCDB("MUON/Calib/TriggerEfficiency",eff,startRun,endRun,true);
913 }
914 delete eff;
915}
916
917//_____________________________________________________________________________
918void
919AliMUONCDB::WriteNeighbours(Int_t startRun, Int_t endRun)
920{
921 /// Write neighbours to OCDB
922
409de10f 923 AliMUONVStore* neighbours = Create2DMap();
de01cdf0 924 Int_t ngenerated = MakeNeighbourStore(*neighbours);
925 AliInfo(Form("Ngenerated = %d",ngenerated));
926 if (ngenerated>0)
927 {
928 WriteToCDB("MUON/Calib/Neighbours",neighbours,startRun,endRun,true);
929 }
930 delete neighbours;
931}
932
933//_____________________________________________________________________________
934void
935AliMUONCDB::WriteHV(Bool_t defaultValues,
936 Int_t startRun, Int_t endRun)
937{
938 /// generate HV values (either cste = 1500 V) if defaultValues=true or random
939 /// if defaultValues=false, see makeHVStore) and
940 /// store them into CDB located at cdbpath, with a validity period
941 /// ranging from startRun to endRun
942
943 TMap* hvStore = new TMap;
944 Int_t ngenerated = MakeHVStore(*hvStore,defaultValues);
945 AliInfo(Form("Ngenerated = %d",ngenerated));
946 if (ngenerated>0)
947 {
948 WriteToCDB("MUON/Calib/HV",hvStore,startRun,endRun,defaultValues);
949 }
950 delete hvStore;
951}
952
953//_____________________________________________________________________________
954void
955AliMUONCDB::WritePedestals(Bool_t defaultValues,
956 Int_t startRun, Int_t endRun)
957{
958 /// generate pedestal values (either 0 if defaultValues=true or random
959 /// if defaultValues=false, see makePedestalStore) and
960 /// store them into CDB located at cdbpath, with a validity period
961 /// ranging from startRun to endRun
962
409de10f 963 AliMUONVStore* pedestalStore = Create2DMap();
de01cdf0 964 Int_t ngenerated = MakePedestalStore(*pedestalStore,defaultValues);
965 AliInfo(Form("Ngenerated = %d",ngenerated));
966 WriteToCDB("MUON/Calib/Pedestals",pedestalStore,startRun,endRun,defaultValues);
967 delete pedestalStore;
968}
969
970
971//_____________________________________________________________________________
972void
973AliMUONCDB::WriteGains(Bool_t defaultValues,
974 Int_t startRun, Int_t endRun)
975{
976 /// generate gain values (either 1 if defaultValues=true or random
977 /// if defaultValues=false, see makeGainStore) and
978 /// store them into CDB located at cdbpath, with a validity period
979 /// ranging from startRun to endRun
980
409de10f 981 AliMUONVStore* gainStore = Create2DMap();
de01cdf0 982 Int_t ngenerated = MakeGainStore(*gainStore,defaultValues);
983 AliInfo(Form("Ngenerated = %d",ngenerated));
984 WriteToCDB("MUON/Calib/Gains",gainStore,startRun,endRun,defaultValues);
985 delete gainStore;
986}
987
25e1df3e 988//_____________________________________________________________________________
989void
990AliMUONCDB::WriteCapacitances(const char* filename,
991 Int_t startRun, Int_t endRun)
992{
993 /// read manu capacitance and injection gain values from file
994 /// and store them into CDB located at cdbpath, with a validity period
995 /// ranging from startRun to endRun
996
997 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
998 Int_t ngenerated = MakeCapacitanceStore(*capaStore,filename);
999 AliInfo(Form("Ngenerated = %d",ngenerated));
1000 if ( ngenerated > 0 )
1001 {
1002 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,filename);
1003 }
1004 delete capaStore;
1005}
1006
de01cdf0 1007//_____________________________________________________________________________
1008void
1009AliMUONCDB::WriteCapacitances(Bool_t defaultValues,
1010 Int_t startRun, Int_t endRun)
1011{
1012 /// generate manu capacitance values (either 1 if defaultValues=true or random
1013 /// if defaultValues=false, see makeCapacitanceStore) and
1014 /// store them into CDB located at cdbpath, with a validity period
1015 /// ranging from startRun to endRun
1016
a0eca509 1017 AliMUONVStore* capaStore = new AliMUON1DMap(16828);
de01cdf0 1018 Int_t ngenerated = MakeCapacitanceStore(*capaStore,defaultValues);
1019 AliInfo(Form("Ngenerated = %d",ngenerated));
1020 WriteToCDB("MUON/Calib/Capacitances",capaStore,startRun,endRun,defaultValues);
1021 delete capaStore;
1022}
1023
1024//_____________________________________________________________________________
1025void
1026AliMUONCDB::WriteTrigger(Int_t startRun, Int_t endRun)
1027{
1028 /// Writes all Trigger related calibration to CDB
1029 WriteLocalTriggerMasks(startRun,endRun);
92c23b09 1030 WriteRegionalTriggerConfig(startRun,endRun);
1031 WriteGlobalTriggerConfig(startRun,endRun);
de01cdf0 1032 WriteTriggerLut(startRun,endRun);
1033 WriteTriggerEfficiency(startRun,endRun);
1034}
1035
1036//_____________________________________________________________________________
1037void
1038AliMUONCDB::WriteTracker(Bool_t defaultValues, Int_t startRun, Int_t endRun)
1039{
1040 /// Writes all Tracker related calibration to CDB
1041 WriteHV(defaultValues,startRun,endRun);
1042 WritePedestals(defaultValues,startRun,endRun);
1043 WriteGains(defaultValues,startRun,endRun);
1044 WriteCapacitances(defaultValues,startRun,endRun);
1045 WriteNeighbours(startRun,endRun);
1046}
913f1b43 1047