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