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