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