]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/AliFMDParameters.cxx
Fixing coding violations from FC
[u/mrichter/AliRoot.git] / FMD / AliFMDParameters.cxx
CommitLineData
1a1fdef7 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 **************************************************************************/
1a1fdef7 15/* $Id$ */
c2fc1258 16/** @file AliFMDParameters.cxx
17 @author Christian Holm Christensen <cholm@nbi.dk>
18 @date Mon Mar 27 12:44:26 2006
19 @brief Manager of FMD parameters
20*/
1a1fdef7 21//____________________________________________________________________
22//
23// Forward Multiplicity Detector based on Silicon wafers.
24//
25// This class is a singleton that handles various parameters of
26// the FMD detectors.
6169f936 27// The manager normally serves the parameters from the Conditions
28// Database (CDB). These are retrivied by the member function
29// `Init'. Optionally, the class can serve hard-coded constants, if
30// no CDB is available.
1a1fdef7 31//
f95a63c4 32#include "AliFMDDebug.h" // ALILOG_H
8f6ee336 33#include "AliFMDParameters.h" // ALIFMDPARAMETERS_H
34#include "AliFMDGeometry.h" // ALIFMDGEOMETRY_H
35#include "AliFMDRing.h" // ALIFMDRING_H
36#include "AliFMDCalibGain.h" // ALIFMDCALIBGAIN_H
37#include "AliFMDCalibPedestal.h" // ALIFMDCALIBPEDESTAL_H
c2fc1258 38#include "AliFMDCalibSampleRate.h" // ALIFMDCALIBSAMPLERATE_H
39#include "AliFMDCalibStripRange.h" // ALIFMDCALIBSTRIPRANGE_H
57c3c593 40#include "AliFMDAltroMapping.h" // ALIFMDALTROMAPPING_H
41#include <AliCDBManager.h> // ALICDBMANAGER_H
42#include <AliCDBEntry.h> // ALICDBMANAGER_H
dc02d468 43#include <AliFMDPreprocessor.h>
44#include <AliLog.h>
1a1fdef7 45#include <Riostream.h>
8ec606c2 46#include <sstream>
dc02d468 47#include <TSystem.h>
6169f936 48#include <TArrayF.h>
49#include <TH2D.h>
1a1fdef7 50
51//====================================================================
52ClassImp(AliFMDParameters)
53#if 0
54 ; // This is here to keep Emacs for indenting the next line
55#endif
56
57//____________________________________________________________________
58AliFMDParameters* AliFMDParameters::fgInstance = 0;
59
57c3c593 60//____________________________________________________________________
77186f44 61const char* AliFMDParameters::fgkPulseGain = "FMD/Calib/PulseGain";
62const char* AliFMDParameters::fgkPedestal = "FMD/Calib/Pedestal";
63const char* AliFMDParameters::fgkDead = "FMD/Calib/Dead";
64const char* AliFMDParameters::fgkSampleRate = "FMD/Calib/SampleRate";
65const char* AliFMDParameters::fgkAltroMap = "FMD/Calib/AltroMap";
66const char* AliFMDParameters::fgkZeroSuppression = "FMD/Calib/ZeroSuppression";
67const char* AliFMDParameters::fgkStripRange = "FMD/Calib/StripRange";
68const char* AliFMDParameters::fkPedestalShuttleID = "pedestals";
69const char* AliFMDParameters::fkGainShuttleID = "gains";
70const char* AliFMDParameters::fkConditionsShuttleID = "conditions";
57c3c593 71
1a1fdef7 72//____________________________________________________________________
73AliFMDParameters*
74AliFMDParameters::Instance()
75{
76 // Get static instance
77 if (!fgInstance) fgInstance = new AliFMDParameters;
78 return fgInstance;
79}
80
81//____________________________________________________________________
82AliFMDParameters::AliFMDParameters()
57c3c593 83 : fIsInit(kFALSE),
02a27b50 84 fkSiDeDxMip(1.664),
b5ee4425 85 fVA1MipRange(0),
86 fAltroChannelSize(0),
87 fChannelsPerAltro(0),
88 fPedestalFactor(0),
cce354f6 89 fZSPre(0),
90 fZSPost(0),
91 fZSPedSubtract(kFALSE),
b5ee4425 92 fFixedPedestal(0),
93 fFixedPedestalWidth(0),
94 fFixedZeroSuppression(0),
95 fFixedSampleRate(0),
96 fFixedThreshold(0),
97 fFixedMinStrip(0),
98 fFixedMaxStrip(0),
8f6ee336 99 fFixedPulseGain(0),
100 fEdepMip(0),
625d7886 101 fHasCompleteHeader(kTRUE),
8f6ee336 102 fZeroSuppression(0),
103 fSampleRate(0),
104 fPedestal(0),
105 fPulseGain(0),
57c3c593 106 fDeadMap(0),
c2fc1258 107 fAltroMap(0),
3d7ed4ed 108 fStripRange(0)
1a1fdef7 109{
110 // Default constructor
111 SetVA1MipRange();
112 SetAltroChannelSize();
113 SetChannelsPerAltro();
114 SetZeroSuppression();
115 SetSampleRate();
116 SetPedestal();
117 SetPedestalWidth();
118 SetPedestalFactor();
8f6ee336 119 SetThreshold();
c2fc1258 120 SetStripRange();
06ca6759 121 fAltroMap = new AliFMDAltroMapping;
1a1fdef7 122}
123
57c3c593 124//__________________________________________________________________
125void
f6449cc0 126AliFMDParameters::Init(Bool_t forceReInit, UInt_t what)
57c3c593 127{
128 // Initialize the parameters manager. We need to get stuff from the
129 // CDB here.
a9579262 130 if (forceReInit) fIsInit = kFALSE;
57c3c593 131 if (fIsInit) return;
f6449cc0 132 if (what & kPulseGain) InitPulseGain();
133 if (what & kPedestal) InitPedestal();
134 if (what & kDeadMap) InitDeadMap();
135 if (what & kSampleRate) InitSampleRate();
136 if (what & kZeroSuppression) InitZeroSuppression();
137 if (what & kAltroMap) InitAltroMap();
6bf06d81 138 if (what & kStripRange) InitStripRange();
1e8f773e 139 fIsInit = kTRUE;
dc02d468 140}
141//__________________________________________________________________
142void
143AliFMDParameters::Init(AliFMDPreprocessor* pp, Bool_t forceReInit, UInt_t what)
144{
145 // Initialize the parameters manager. We need to get stuff from the
146 // CDB here.
147 if (forceReInit) fIsInit = kFALSE;
148 if (fIsInit) return;
149 if (what & kPulseGain) InitPulseGain(pp);
150 if (what & kPedestal) InitPedestal(pp);
151 if (what & kDeadMap) InitDeadMap(pp);
152 if (what & kSampleRate) InitSampleRate(pp);
153 if (what & kZeroSuppression) InitZeroSuppression(pp);
154 if (what & kAltroMap) InitAltroMap(pp);
6bf06d81 155 if (what & kStripRange) InitStripRange(pp);
dc02d468 156 fIsInit = kTRUE;
1e8f773e 157}
c2fc1258 158
f560b28c 159//__________________________________________________________________
160Bool_t
161AliFMDParameters::CheckFile(const char* prefix,
162 const char* path,
163 int number,
164 TString& f) const
165{
166 f = (Form("%s%d.csv", prefix, number));
167 AliFMDDebug(5, ("Checking if %s exists in %s ...", f.Data(), path));
168 f = gSystem->Which(path, f.Data());
169 AliFMDDebug(5, ("Got back '%s'", f.Data()));
170 return !f.IsNull();
171}
172
173//__________________________________________________________________
174void
175AliFMDParameters::Init(const char* path, Bool_t forceReInit, UInt_t what)
176{
177 // Initialize the parameters manager. Pedestals, gains, strip
178 // range, and sample rate is read from local comma separated value
179 // files if available. Otherwise, the calibrations are obtained
180 // from OCDB.
181 if (forceReInit) fIsInit = kFALSE;
182 if (fIsInit) return;
183
184 AliFMDCalibStripRange* range = 0;
185 AliFMDCalibSampleRate* rate = 0;
186 AliFMDCalibPedestal* peds = 0;
187 AliFMDCalibGain* gains = 0;
188
189 for (Int_t i = 1; i <= 3; i++) {
190 TString f;
191 if (((what & kSampleRate) || (what & kStripRange)) &&
192 CheckFile("conditions", path, i, f)) {
193 if (!rate && (what & kSampleRate)) rate = new AliFMDCalibSampleRate;
194 if (!range && (what & kStripRange)) range = new AliFMDCalibStripRange;
195 std::ifstream in(f.Data());
196 if (range) range->ReadFromFile(in);
197 if (rate) rate->ReadFromFile(in);
198 in.close();
199 }
200 if ((what & kPedestal) && CheckFile("peds", path, i, f)) {
201 if (!peds) peds = new AliFMDCalibPedestal;
202 std::ifstream in(f.Data());
203 peds->ReadFromFile(in);
204 in.close();
205 }
206 if ((what & kPulseGain) && CheckFile("gains", path, i, f)) {
207 if (!gains) gains = new AliFMDCalibGain;
208 std::ifstream in(f.Data());
209 gains->ReadFromFile(in);
210 in.close();
211 }
212 }
213
214 if (range) what &= ~kStripRange;
215 if (rate) what &= ~kSampleRate;
216 if (peds) what &= ~kPedestal;
217 if (gains) what &= ~kPulseGain;
218
219 Init(kFALSE, what);
220
221 if (range) SetStripRange(range);
222 if (rate) SetSampleRate(rate);
223 if (peds) SetPedestal(peds);
224 if (gains) SetGain(gains);
225
226 fIsInit = kTRUE;
227}
228
229//__________________________________________________________________
230void
231AliFMDParameters::MakeDeadMap(Float_t maxNoise,
232 Float_t minGain,
233 Float_t maxGain)
234{
235 if (fPedestal)
236 fDeadMap = fPedestal->MakeDeadMap(maxNoise, fDeadMap);
237 if (fPulseGain)
238 fDeadMap = fPulseGain->MakeDeadMap(minGain, maxGain, fDeadMap);
239}
6169f936 240//__________________________________________________________________
241#define DET2IDX(det,ring,sec,str) \
a9579262 242 (det * 1000 + (ring == 'I' ? 0 : 512) + str)
6169f936 243
244//__________________________________________________________________
245void
246AliFMDParameters::Draw(Option_t* option)
247{
248 TString opt(option);
249 enum {
458e52e8 250 kLocalPulseGain, // Path to PulseGain calib object
251 kLocalThreshold, // Path to PulseGain calib object
252 kLocalPedestal, // Path to Pedestal calib object
253 kLocalPedestalWidth, // Path to Pedestal calib object
254 kLocalDead, // Path to Dead calib object
255 kLocalSampleRate, // Path to SampleRate calib object
256 kLocalAltroMap, // Path to AltroMap calib object
257 kLocalZeroSuppression, // Path to ZeroSuppression cal object
258 kLocalMinStripRange, // Path to strip range cal object
259 kLocalMaxStripRange // Path to strip range cal object
6169f936 260 } what;
6169f936 261
262 if (opt.Contains("dead", TString::kIgnoreCase))
458e52e8 263 what = kLocalDead;
6169f936 264 else if (opt.Contains("threshold",TString::kIgnoreCase))
458e52e8 265 what = kLocalThreshold;
6169f936 266 else if (opt.Contains("gain",TString::kIgnoreCase))
458e52e8 267 what = kLocalPulseGain;
6169f936 268 else if (opt.Contains("pedestal",TString::kIgnoreCase))
458e52e8 269 what = kLocalPedestal;
6169f936 270 else if (opt.Contains("noise",TString::kIgnoreCase))
458e52e8 271 what = kLocalPedestalWidth;
6169f936 272 else if (opt.Contains("zero",TString::kIgnoreCase))
458e52e8 273 what = kLocalZeroSuppression;
6169f936 274 else if (opt.Contains("rate",TString::kIgnoreCase))
458e52e8 275 what = kLocalSampleRate;
6169f936 276 else if (opt.Contains("min",TString::kIgnoreCase))
458e52e8 277 what = kLocalMinStripRange;
6169f936 278 else if (opt.Contains("max",TString::kIgnoreCase))
458e52e8 279 what = kLocalMaxStripRange;
6169f936 280 else if (opt.Contains("map",TString::kIgnoreCase))
458e52e8 281 what = kLocalAltroMap;
6169f936 282 else {
283 Warning("Draw", "unknown parameter: %s\n\tShould be one of\n\t"
284 "dead, threshold, gain, pedestal, noise, zero, rate, "
285 "min, max, map",
286 option);
287 return;
288 }
289
290 TArrayD xbins(3 * 512 + 2 * 256 + 5);
291 Int_t i = 1;
292 Bool_t skip = kTRUE;
293 for (UShort_t det = 1; det <= 3; det++) {
294 UShort_t nRings = (det == 1 ? 1 : 2);
295 for (UShort_t iring = 0; iring < nRings; iring++) {
296 UShort_t nStrip = (iring == 0 ? 512 : 256);
297 Char_t ring = (iring == 0 ? 'I' : 'O');
298 for (UShort_t str = 0; str < nStrip; str++) {
a9579262 299 // UShort_t nSec = (iring == 0 ? 20 : 40);
300 // Char_t ring = (iring == 0 ? 'I' : 'O');
301 // for (UShort_t sec = 0; sec < nSec; sec++) {
6169f936 302 Int_t idx = DET2IDX(det, ring, 0, str);
a9579262 303 // Int_t idx = DET2IDX(det, ring, sec, 0);
6169f936 304 if (skip) {
305 xbins[i-1] = idx - .5;
306 skip = kFALSE;
307 }
308 xbins[i] = idx + .5;
309 i++;
310 }
311 skip = kTRUE;
312 i++;
313 }
314 }
315 TArrayD ybins(41);
458e52e8 316 for (/*Int_t*/ i = 0; i < ybins.fN; i++) ybins[i] = Float_t(i - .5);
6169f936 317 TH2D* hist = new TH2D("calib", Form("Calibration %s", option),
318 xbins.fN-1, xbins.fArray,
319 ybins.fN-1, ybins.fArray);
a9579262 320 hist->GetXaxis()->SetTitle("1000 #times detector + 512 #times ring + strip");
321 hist->GetYaxis()->SetTitle("sector");
322
6169f936 323 // hist->Draw("Lego");
324 // return;
325
326 for (UShort_t det = 1; det <= 3; det++) {
327 UShort_t nRings = (det == 1 ? 1 : 2);
328 for (UShort_t iring = 0; iring < nRings; iring++) {
329 UShort_t nSector = (iring == 0 ? 20 : 40);
330 UShort_t nStrip = (iring == 0 ? 512 : 256);
331 Char_t ring = (iring == 0 ? 'I' : 'O');
332 for (UShort_t sec = 0; sec < nSector; sec++) {
333 for (UShort_t str = 0; str < nStrip; str++) {
334 Int_t idx = DET2IDX(det, ring, sec, str);
b995fc28 335 UShort_t ddl, addr, time, sam=0;
6169f936 336 Double_t val = 0;
337 switch (what) {
458e52e8 338 case kLocalPulseGain: // Path to PulseGain calib object
6169f936 339 val = GetPulseGain(det,ring,sec,str); break;
458e52e8 340 case kLocalThreshold: // Path to PulseGain calib object
6169f936 341 val = GetThreshold(); break;
458e52e8 342 case kLocalPedestal: // Path to Pedestal calib object
6169f936 343 val = GetPedestal(det,ring,sec,str); break;
458e52e8 344 case kLocalPedestalWidth: // Path to Pedestal calib object
6169f936 345 val = GetPedestalWidth(det,ring,sec,str); break;
458e52e8 346 case kLocalDead: // Path to Dead calib object
6169f936 347 val = IsDead(det,ring,sec,str); break;
458e52e8 348 case kLocalSampleRate: // Path to SampleRate calib object
6169f936 349 val = GetSampleRate(det,ring,sec,str); break;
458e52e8 350 case kLocalAltroMap: // Path to AltroMap calib object
b995fc28 351 Detector2Hardware(det,ring,sec,str,sam,ddl,addr,time);
6169f936 352 val = addr; break;
458e52e8 353 case kLocalZeroSuppression: // Path to ZeroSuppression cal object
6169f936 354 val = GetZeroSuppression(det,ring,sec,str); break;
458e52e8 355 case kLocalMinStripRange: // Path to strip range cal object
6169f936 356 val = GetMinStrip(det,ring,sec,str); break;
458e52e8 357 case kLocalMaxStripRange: // Path to strip range cal object
6169f936 358 val = GetMaxStrip(det,ring,sec,str); break;
359 }
360 hist->Fill(idx,sec,val);
a9579262 361 // hist->Fill(idx,str,val);
6169f936 362 }
363 }
364 }
365 }
366 hist->Draw("lego");
367}
368
c2fc1258 369//__________________________________________________________________
370void
371AliFMDParameters::Print(Option_t* option) const
372{
02a27b50 373 // Print information.
374 // If option contains an 'A' then everything is printed.
a9579262 375 // If the option contains the string "FMD" the function will search
376 // for detector, ring, sector, and strip numbers to print, in the
377 // format
378 //
379 // FMD<detector><ring>[<sector>,<string>]
380 //
381 // The wild card '*' means all of <detector>, <ring>, <sector>, or
382 // <strip>.
c2fc1258 383 TString opt(option);
a9579262 384 Bool_t showStrips = opt.Contains("a", TString::kIgnoreCase);
385 UShort_t ds[] = { 1, 2, 3, 0 };
386 Char_t rs[] = { 'I', 'O', '\0' };
387 UShort_t minStrip = 0;
388 UShort_t maxStrip = 512;
389 UShort_t minSector = 0;
390 UShort_t maxSector = 40;
391
392
8ec606c2 393 if (opt.Contains("fmd",TString::kIgnoreCase)) {
7868d9e2 394 Int_t i = opt.Index("fmd",TString::kIgnoreCase);
395 Int_t j = opt.Index("]",TString::kIgnoreCase);
396 if (j != kNPOS)
397 showStrips = kTRUE;
398 else
399 j = opt.Length();
a9579262 400 enum {
97e94238 401 kReadDet,
402 kReadRing,
403 kReadLbrack,
404 kReadSector,
405 kReadComma,
406 kReadStrip,
407 kReadRbrack,
408 kEnd
409 } state = kReadDet;
8ec606c2 410 std::stringstream s(opt(i+4, j-i-3).Data());
97e94238 411 while (state != kEnd) {
a9579262 412 Char_t tmp = s.peek();
413 if (tmp == ' ' || tmp == '\t') {
414 s.get();
415 continue;
416 }
417 switch (state) {
97e94238 418 case kReadDet: { // First, try to kRead the detector
a9579262 419 if (tmp == '*') s.get();
420 else {
421 UShort_t det;
422 s >> det;
423 if (!s.bad()) {
424 ds[0] = det;
425 ds[1] = 0;
426 }
427 }
97e94238 428 state = (s.bad() ? kEnd : kReadRing);
a9579262 429 } break;
97e94238 430 case kReadRing: { // Then try to read the ring;
a9579262 431 Char_t ring;
432 s >> ring;
433 if (ring != '*' && !s.bad()) {
434 rs[0] = ring;
435 rs[1] = '\0';
436 }
97e94238 437 state = (s.bad() ? kEnd : kReadLbrack);
a9579262 438 } break;
97e94238 439 case kReadLbrack: { // Try to read a left bracket
a9579262 440 Char_t lbrack;
441 s >> lbrack;
97e94238 442 state = (s.bad() ? kEnd : kReadSector);
a9579262 443 } break;
97e94238 444 case kReadSector: { // Try to read a sector
a9579262 445 if (tmp == '*') s.get();
446 else {
447 UShort_t sec;
448 s >> sec;
449 if (!s.bad()) {
450 minSector = sec;
451 maxSector = sec + 1;
452 }
453 }
97e94238 454 state = (s.bad() ? kEnd : kReadComma);
a9579262 455 } break;
97e94238 456 case kReadComma: { // Try to read a left bracket
a9579262 457 Char_t comma;
458 s >> comma;
97e94238 459 state = (s.bad() ? kEnd : kReadStrip);
a9579262 460 } break;
97e94238 461 case kReadStrip: { // Try to read a strip
a9579262 462 if (tmp == '*') s.get();
463 else {
464 UShort_t str;
465 s >> str;
466 if (!s.bad()) {
467 minStrip = str;
468 maxStrip = str + 1;
469 }
470 }
97e94238 471 state = (s.bad() ? kEnd : kReadRbrack);
a9579262 472 } break;
97e94238 473 case kReadRbrack: { // Try to read a left bracket
a9579262 474 Char_t rbrack;
475 s >> rbrack;
97e94238 476 state = kEnd;
a9579262 477 } break;
97e94238 478 case kEnd:
a9579262 479 break;
480 }
481 }
8ec606c2 482 }
a9579262 483 UShort_t* dp = ds;
484 UShort_t det;
485 while ((det = *(dp++))) {
486
487 Char_t* rp = rs;
488 Char_t ring;
489 while ((ring = *(rp++))) {
490 if (det == 1 && ring == 'O') continue;
491 UShort_t min = GetMinStrip(det, ring, 0, 0);
492 UShort_t max = GetMaxStrip(det, ring, 0, 0);
a9579262 493 std::cout << "FMD" << det << ring
494 << " Strip range: "
495 << std::setw(3) << min << ","
ef8e8623 496 << std::setw(3) << max << std::endl;
a9579262 497
a9579262 498 UShort_t nSec = ( ring == 'I' ? 20 : 40 );
499 UShort_t nStr = ( ring == 'I' ? 512 : 256 );
500 for (UShort_t sec = minSector; sec < maxSector && sec < nSec; sec++) {
ef8e8623 501
502 UShort_t rate = GetSampleRate(det, ring, sec, 0);
503 std::cout << "FMD" << det << ring << "[" << std::setw(2) << sec
504 << "] sample rate: " << rate << std::endl;
505
506 if (!showStrips) continue;
c2fc1258 507 std::cout
8ec606c2 508 << " Strip | Pedestal | Gain | ZS thr. | Address\n"
509 << "--------+-------------------+------------+---------+---------"
c2fc1258 510 << std::endl;
a9579262 511 for (UShort_t str = minStrip; str < nStr && str < maxStrip; str++) {
512 if (str == minStrip) std::cout << std::setw(3) << sec << ",";
513 else std::cout << " ";
514 std::cout << std::setw(3) << str << " | ";
515 if (IsDead(det, ring, sec, str)) {
c2fc1258 516 std::cout << "dead" << std::endl;
517 continue;
518 }
b995fc28 519 UShort_t ddl, addr, time, sam=0;
520 Detector2Hardware(det, ring, sec, str, sam, ddl, addr, time);
a9579262 521 std::cout << std::setw(7) << GetPedestal(det, ring, sec, str)
c2fc1258 522 << "+/-" << std::setw(7)
a9579262 523 << GetPedestalWidth(det, ring, sec, str)
8ec606c2 524 << " | " << std::setw(10)
a9579262 525 << GetPulseGain(det, ring, sec, str)
526 << " | " << std::setw(7)
527 << GetZeroSuppression(det, ring, sec, str)
c2fc1258 528 << " | 0x" << std::hex << std::setw(4)
529 << std::setfill('0') << ddl << ",0x" << std::setw(3)
530 << addr << std::dec << std::setfill(' ') << std::endl;
a9579262 531 } // for (strip)
532 } // for (sector)
533 std::cout
534 << "============================================================="
535 << std::endl;
536 } // while (ring)
537 } // while (det)
538
c2fc1258 539}
540
541//__________________________________________________________________
542void
543AliFMDParameters::SetStripRange(UShort_t min, UShort_t max)
544{
02a27b50 545 // Set fixed strip range
c2fc1258 546 fFixedMinStrip = min;
547 fFixedMaxStrip = max;
548}
549
dc02d468 550//__________________________________________________________________
551AliCDBEntry*
552AliFMDParameters::GetEntry(const char* path, AliFMDPreprocessor* pp,
553 Bool_t fatal) const
554{
555 // Get an entry from the CDB or via preprocessor
556 AliCDBEntry* entry = 0;
557 if (!pp) {
558 AliCDBManager* cdb = AliCDBManager::Instance();
559 entry = cdb->Get(path);
560 }
561 else {
562 const char* third = gSystem->BaseName(path);
563 const char* second = gSystem->BaseName(gSystem->DirName(path));
564 entry = pp->GetFromCDB(second, third);
565 }
566 if (!entry) {
567 TString msg(Form("No %s found in CDB, perhaps you need to "
568 "use AliFMDCalibFaker?", path));
569 if (fatal) { AliFatal(msg.Data()); }
570 else AliLog::Message(AliLog::kWarning, msg.Data(), "FMD",
571 "AliFMDParameters", "GetEntry", __FILE__,
572 __LINE__);
573 return 0;
574 }
575 return entry;
576}
577
578
1e8f773e 579//__________________________________________________________________
580void
dc02d468 581AliFMDParameters::InitPulseGain(AliFMDPreprocessor* pp)
1e8f773e 582{
02a27b50 583 // Get pulse gain from CDB or used fixed
dc02d468 584 AliCDBEntry* gain = GetEntry(fgkPulseGain, pp);
585 if (!gain) return;
57c3c593 586
42f1b2f5 587 AliFMDDebug(5, ("Got gain from CDB"));
1e8f773e 588 fPulseGain = dynamic_cast<AliFMDCalibGain*>(gain->GetObject());
f95a63c4 589 if (!fPulseGain) AliFatal("Invalid pulser gain object from CDB");
1e8f773e 590}
591//__________________________________________________________________
592void
dc02d468 593AliFMDParameters::InitPedestal(AliFMDPreprocessor* pp)
1e8f773e 594{
02a27b50 595 // Initialize the pedestals from CDB
dc02d468 596 AliCDBEntry* pedestal = GetEntry(fgkPedestal, pp);
597 if (!pedestal) return;
598
42f1b2f5 599 AliFMDDebug(5, ("Got pedestal from CDB"));
1e8f773e 600 fPedestal = dynamic_cast<AliFMDCalibPedestal*>(pedestal->GetObject());
f95a63c4 601 if (!fPedestal) AliFatal("Invalid pedestal object from CDB");
1e8f773e 602}
603
604//__________________________________________________________________
605void
dc02d468 606AliFMDParameters::InitDeadMap(AliFMDPreprocessor* pp)
1e8f773e 607{
02a27b50 608 // Get Dead-channel-map from CDB
dc02d468 609 AliCDBEntry* deadMap = GetEntry(fgkDead, pp);
610 if (!deadMap) return;
611
42f1b2f5 612 AliFMDDebug(5, ("Got dead map from CDB"));
1e8f773e 613 fDeadMap = dynamic_cast<AliFMDCalibDeadMap*>(deadMap->GetObject());
f95a63c4 614 if (!fDeadMap) AliFatal("Invalid dead map object from CDB");
1e8f773e 615}
616
617//__________________________________________________________________
618void
dc02d468 619AliFMDParameters::InitZeroSuppression(AliFMDPreprocessor* pp)
1e8f773e 620{
02a27b50 621 // Get 0-suppression from CDB
dc02d468 622 AliCDBEntry* zeroSup = GetEntry(fgkZeroSuppression, pp);
623 if (!zeroSup) return;
42f1b2f5 624 AliFMDDebug(5, ("Got zero suppression from CDB"));
1e8f773e 625 fZeroSuppression =
626 dynamic_cast<AliFMDCalibZeroSuppression*>(zeroSup->GetObject());
f95a63c4 627 if (!fZeroSuppression)AliFatal("Invalid zero suppression object from CDB");
1e8f773e 628}
629
630//__________________________________________________________________
631void
dc02d468 632AliFMDParameters::InitSampleRate(AliFMDPreprocessor* pp)
1e8f773e 633{
02a27b50 634 // get Sample rate from CDB
dc02d468 635 AliCDBEntry* sampRat = GetEntry(fgkSampleRate, pp);
636 if (!sampRat) return;
42f1b2f5 637 AliFMDDebug(5, ("Got zero suppression from CDB"));
1e8f773e 638 fSampleRate = dynamic_cast<AliFMDCalibSampleRate*>(sampRat->GetObject());
f95a63c4 639 if (!fSampleRate) AliFatal("Invalid zero suppression object from CDB");
1e8f773e 640}
641
642//__________________________________________________________________
643void
dc02d468 644AliFMDParameters::InitAltroMap(AliFMDPreprocessor* pp)
1e8f773e 645{
02a27b50 646 // Get hardware mapping from CDB
06ca6759 647 if (fAltroMap) {
648 delete fAltroMap;
649 fAltroMap = 0;
650 }
458e52e8 651 AliCDBEntry* hwMap = GetEntry(fgkAltroMap, pp, kFALSE);
dc02d468 652 if (!hwMap) return;
653
42f1b2f5 654 AliFMDDebug(5, ("Got ALTRO map from CDB"));
1e8f773e 655 fAltroMap = dynamic_cast<AliFMDAltroMapping*>(hwMap->GetObject());
656 if (!fAltroMap) {
f95a63c4 657 AliFatal("Invalid ALTRO map object from CDB");
1e8f773e 658 fAltroMap = new AliFMDAltroMapping;
57c3c593 659 }
57c3c593 660}
661
c2fc1258 662//__________________________________________________________________
663void
dc02d468 664AliFMDParameters::InitStripRange(AliFMDPreprocessor* pp)
c2fc1258 665{
02a27b50 666 // Get strips read-out from CDB
dc02d468 667 AliCDBEntry* range = GetEntry(fgkStripRange, pp);
668 if (!range) return;
42f1b2f5 669 AliFMDDebug(5, ("Got strip range from CDB"));
c2fc1258 670 fStripRange = dynamic_cast<AliFMDCalibStripRange*>(range->GetObject());
f95a63c4 671 if (!fStripRange) AliFatal("Invalid strip range object from CDB");
c2fc1258 672}
673
1e8f773e 674
8f6ee336 675//__________________________________________________________________
676Float_t
677AliFMDParameters::GetThreshold() const
678{
02a27b50 679 // Get threshold from CDB
8f6ee336 680 if (!fPulseGain) return fFixedThreshold;
681 return fPulseGain->Threshold();
682}
683
684//__________________________________________________________________
685Float_t
686AliFMDParameters::GetPulseGain(UShort_t detector, Char_t ring,
687 UShort_t sector, UShort_t strip) const
688{
689 // Returns the pulser calibrated gain for strip # strip in sector #
690 // sector or ring id ring of detector # detector.
691 //
692 // For simulation, this is normally set to
693 //
694 // VA1_MIP_Range
695 // ------------------ * MIP_Energy_Loss
696 // ALTRO_channel_size
697 //
698 if (!fPulseGain) {
699 if (fFixedPulseGain <= 0)
700 fFixedPulseGain = fVA1MipRange * GetEdepMip() / fAltroChannelSize;
701 return fFixedPulseGain;
702 }
f95a63c4 703 AliFMDDebug(50, ("pulse gain for FMD%d%c[%2d,%3d]=%f",
1e8f773e 704 detector, ring, sector, strip,
705 fPulseGain->Value(detector, ring, sector, strip)));
8f6ee336 706 return fPulseGain->Value(detector, ring, sector, strip);
707}
708
709//__________________________________________________________________
710Bool_t
711AliFMDParameters::IsDead(UShort_t detector, Char_t ring,
712 UShort_t sector, UShort_t strip) const
713{
02a27b50 714 // Check if the channel is dead
8f6ee336 715 if (!fDeadMap) return kFALSE;
f95a63c4 716 AliFMDDebug(50, ("Dead for FMD%d%c[%2d,%3d]=%s",
1e8f773e 717 detector, ring, sector, strip,
718 fDeadMap->operator()(detector, ring, sector, strip) ?
719 "no" : "yes"));
8f6ee336 720 return fDeadMap->operator()(detector, ring, sector, strip);
721}
722
723//__________________________________________________________________
724UShort_t
725AliFMDParameters::GetZeroSuppression(UShort_t detector, Char_t ring,
726 UShort_t sector, UShort_t strip) const
727{
02a27b50 728 // Get zero suppression threshold
8f6ee336 729 if (!fZeroSuppression) return fFixedZeroSuppression;
730 // Need to map strip to ALTRO chip.
f95a63c4 731 AliFMDDebug(50, ("zero sup. for FMD%d%c[%2d,%3d]=%f",
1e8f773e 732 detector, ring, sector, strip,
733 fZeroSuppression->operator()(detector, ring,
734 sector, strip)));
8f6ee336 735 return fZeroSuppression->operator()(detector, ring, sector, strip/128);
736}
737
738//__________________________________________________________________
739UShort_t
c2fc1258 740AliFMDParameters::GetSampleRate(UShort_t det, Char_t ring, UShort_t sector,
741 UShort_t str) const
8f6ee336 742{
02a27b50 743 // Get sampl rate
8f6ee336 744 if (!fSampleRate) return fFixedSampleRate;
745 // Need to map sector to digitizier card.
c2fc1258 746 UInt_t ret = fSampleRate->Rate(det, ring, sector, str);
f95a63c4 747 AliFMDDebug(50, ("Sample rate for FMD%d%c[%2d,%3d]=%d",
c2fc1258 748 det, ring, sector, str, ret));
749 return ret;
750}
751
752//__________________________________________________________________
753UShort_t
754AliFMDParameters::GetMinStrip(UShort_t det, Char_t ring, UShort_t sector,
755 UShort_t str) const
756{
02a27b50 757 // Get strip range read out
c2fc1258 758 if (!fStripRange) return fFixedMinStrip;
759 // Need to map sector to digitizier card.
760 UInt_t ret = fStripRange->Min(det, ring, sector, str);
f95a63c4 761 AliFMDDebug(50, ("Min strip # for FMD%d%c[%2d,%3d]=%d",
c2fc1258 762 det, ring, sector, str, ret));
763 return ret;
764}
765
766//__________________________________________________________________
767UShort_t
768AliFMDParameters::GetMaxStrip(UShort_t det, Char_t ring, UShort_t sector,
769 UShort_t str) const
770{
02a27b50 771 // Get strip range read out
c2fc1258 772 if (!fStripRange) return fFixedMaxStrip;
773 // Need to map sector to digitizier card.
774 UInt_t ret = fStripRange->Max(det, ring, sector, str);
f95a63c4 775 AliFMDDebug(50, ("Max strip # for FMD%d%c[%2d,%3d]=%d",
c2fc1258 776 det, ring, sector, str, ret));
777 return ret;
8f6ee336 778}
1a1fdef7 779
8f6ee336 780//__________________________________________________________________
781Float_t
782AliFMDParameters::GetPedestal(UShort_t detector, Char_t ring,
783 UShort_t sector, UShort_t strip) const
784{
02a27b50 785 // Get the pedesal
8f6ee336 786 if (!fPedestal) return fFixedPedestal;
f95a63c4 787 AliFMDDebug(50, ("pedestal for FMD%d%c[%2d,%3d]=%f",
1e8f773e 788 detector, ring, sector, strip,
789 fPedestal->Value(detector, ring, sector, strip)));
8f6ee336 790 return fPedestal->Value(detector, ring, sector, strip);
791}
792
793//__________________________________________________________________
794Float_t
795AliFMDParameters::GetPedestalWidth(UShort_t detector, Char_t ring,
796 UShort_t sector, UShort_t strip) const
797{
02a27b50 798 // Get the pedesal
8f6ee336 799 if (!fPedestal) return fFixedPedestalWidth;
f95a63c4 800 AliFMDDebug(50, ("pedetal width for FMD%d%c[%2d,%3d]=%f",
1e8f773e 801 detector, ring, sector, strip,
802 fPedestal->Width(detector, ring, sector, strip)));
8f6ee336 803 return fPedestal->Width(detector, ring, sector, strip);
804}
805
1a1fdef7 806//__________________________________________________________________
57c3c593 807AliFMDAltroMapping*
808AliFMDParameters::GetAltroMap() const
809{
02a27b50 810 // Get the hardware address to detector index map
57c3c593 811 return fAltroMap;
1a1fdef7 812}
813
57c3c593 814
f38b1653 815//____________________________________________________________________
816Bool_t
b995fc28 817AliFMDParameters::Hardware2Detector(UShort_t ddl, UShort_t addr,
f38b1653 818 UShort_t timebin,
b995fc28 819 UShort_t& det, Char_t& ring,
f38b1653 820 UShort_t& sec, Short_t& str,
821 UShort_t& sam) const
822{
823 // Translate a hardware address to detector coordinates.
824 //
825 // See also Hardware2Detector that accepts 4 inputs
b995fc28 826 if (!fAltroMap) return kFALSE;
827 UShort_t board, chip, chan;
828 fAltroMap->ChannelAddress(addr, board, chip, chan);
829 return Hardware2Detector(ddl,board,chip,chan,timebin,det,ring,sec,str,sam);
f38b1653 830}
831//____________________________________________________________________
832Bool_t
b995fc28 833AliFMDParameters::Hardware2Detector(UShort_t ddl, UShort_t board,
834 UShort_t chip, UShort_t chan,
f38b1653 835 UShort_t timebin,
836 UShort_t& det, Char_t& ring,
837 UShort_t& sec, Short_t& str,
838 UShort_t& sam) const
839{
840 // Translate a hardware address to detector coordinates.
841 //
842 // See also Hardware2Detector that accepts 4 inputs
b995fc28 843 if (!fAltroMap) return kFALSE;
844 if (fAltroMap->DDL2Detector(ddl) < 0) return kFALSE;
845 Short_t stripBase = 0;
846 if (!fAltroMap->Channel2StripBase(board,chip,chan, ring, sec, stripBase))
847 return kFALSE;
848 UShort_t preSamples = GetPreSamples(det, ring, sec, stripBase);
849 UShort_t sampleRate = GetSampleRate(det, ring, sec, stripBase);
850 Short_t stripOff = 0;
851 fAltroMap->Timebin2Strip(sec, timebin, preSamples, sampleRate, stripOff, sam);
852 str = stripBase + stripOff;
853 AliFMDDebug(50, ("%d/0x%02x/0x%x/0x%x/%04d -> FMD%d%c[%02d,%03d]-%d"
854 " (pre=%2d, rate=%d)",
855 ddl, board, chip, chan, timebin,
856 det, ring, sec, str, sam, preSamples, sampleRate));
f38b1653 857 return kTRUE;
858}
859
b995fc28 860#if 0
bf000c32 861//__________________________________________________________________
862Bool_t
b995fc28 863AliFMDParameters::Hardware2Detector(UShort_t ddl, UShort_t board,
864 UShort_t chip, UShort_t chan,
f6449cc0 865 UShort_t& det, Char_t& ring,
f38b1653 866 UShort_t& sec, Short_t& str) const
f6449cc0 867{
868 // Map hardware address to detector index
869 if (!fAltroMap) return kFALSE;
870 return fAltroMap->Hardware2Detector(ddl,board,chip,chan, det,ring,sec,str);
871}
872//__________________________________________________________________
873Bool_t
b995fc28 874AliFMDParameters::Hardware2Detector(UShort_t ddl, UShort_t addr,
f6449cc0 875 UShort_t& det, Char_t& ring,
f38b1653 876 UShort_t& sec, Short_t& str) const
bf000c32 877{
02a27b50 878 // Map hardware address to detector index
57c3c593 879 if (!fAltroMap) return kFALSE;
880 return fAltroMap->Hardware2Detector(ddl, addr, det, ring, sec, str);
bf000c32 881}
b995fc28 882#endif
bf000c32 883
f38b1653 884//____________________________________________________________________
885Bool_t
886AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring,
887 UShort_t sec, UShort_t str,
888 UShort_t sam,
b995fc28 889 UShort_t& ddl, UShort_t& board,
890 UShort_t& altro, UShort_t& channel,
f38b1653 891 UShort_t& timebin) const
892{
893 if (!fAltroMap) return kFALSE;
894 UShort_t preSamples = GetPreSamples(det, ring, sec, str);
895 UShort_t sampleRate = GetSampleRate(det, ring, sec, str);
896 UShort_t strip = str - GetMinStrip(det,ring,sec,str);
897 return fAltroMap->Detector2Hardware(det, ring, sec, strip, sam,
898 preSamples, sampleRate,
899 ddl, board, altro, channel, timebin);
900}
901
902
903
f38b1653 904//____________________________________________________________________
905Bool_t
906AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring,
907 UShort_t sec, UShort_t str,
908 UShort_t sam,
b995fc28 909 UShort_t& ddl, UShort_t& addr,
f38b1653 910 UShort_t& timebin) const
911{
912 if (!fAltroMap) return kFALSE;
913 UShort_t preSamples = GetPreSamples(det, ring, sec, str);
914 UShort_t sampleRate = GetSampleRate(det, ring, sec, str);
915 UShort_t strip = str - GetMinStrip(det,ring,sec,str);
916 return fAltroMap->Detector2Hardware(det, ring, sec, strip, sam,
917 preSamples, sampleRate,
918 ddl, addr, timebin);
919}
920
b995fc28 921#if 0
922//__________________________________________________________________
923Bool_t
924AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring,
925 UShort_t sec, UShort_t str,
926 UShort_t& ddl, UShort_t& board,
927 UShort_t& chip, UShort_t& chan) const
928{
929 // Map detector index to hardware address
930 if (!fAltroMap) return kFALSE;
931 return fAltroMap->Detector2Hardware(det,ring,sec,str, ddl,board,chip,chan);
932}
933
f6449cc0 934//__________________________________________________________________
935Bool_t
936AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring,
937 UShort_t sec, UShort_t str,
b995fc28 938 UShort_t& ddl, UShort_t& addr) const
bf000c32 939{
02a27b50 940 // Map detector index to hardware address
57c3c593 941 if (!fAltroMap) return kFALSE;
942 return fAltroMap->Detector2Hardware(det, ring, sec, str, ddl, addr);
bf000c32 943}
b995fc28 944#endif
57c3c593 945
946//__________________________________________________________________
947Float_t
948AliFMDParameters::GetEdepMip() const
949{
950 // Get energy deposited by a MIP in the silicon sensors
951 if (fEdepMip <= 0){
952 AliFMDGeometry* fmd = AliFMDGeometry::Instance();
02a27b50 953 fEdepMip = (fkSiDeDxMip
57c3c593 954 * fmd->GetRing('I')->GetSiThickness()
955 * fmd->GetSiDensity());
956 }
957 return fEdepMip;
958}
68aba90a 959//____________________________________________________________________
960Float_t
961AliFMDParameters::GetDACPerMIP() const
962{
963 //This is the conversion from the Digital-to-Analog-Converter setting
964 // to the number of MIPs. The number was measured in the NBI lab during
965 // August 2008.
bf000c32 966
68aba90a 967 return 29.67;
bf000c32 968
68aba90a 969}
970
1a1fdef7 971//____________________________________________________________________
972//
973// EOF
974//