]>
Commit | Line | Data |
---|---|---|
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 | /* $Id$ */ | |
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 | */ | |
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. | |
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. | |
31 | // | |
32 | #include "AliFMDDebug.h" // ALILOG_H | |
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 | |
38 | #include "AliFMDCalibSampleRate.h" // ALIFMDCALIBSAMPLERATE_H | |
39 | #include "AliFMDCalibStripRange.h" // ALIFMDCALIBSTRIPRANGE_H | |
40 | #include "AliFMDAltroMapping.h" // ALIFMDALTROMAPPING_H | |
41 | #include <AliCDBManager.h> // ALICDBMANAGER_H | |
42 | #include <AliCDBEntry.h> // ALICDBMANAGER_H | |
43 | #include <AliFMDPreprocessor.h> | |
44 | #include <AliLog.h> | |
45 | #include <Riostream.h> | |
46 | #include <sstream> | |
47 | #include <TSystem.h> | |
48 | #include <TArrayF.h> | |
49 | #include <TH2D.h> | |
50 | ||
51 | //==================================================================== | |
52 | ClassImp(AliFMDParameters) | |
53 | #if 0 | |
54 | ; // This is here to keep Emacs for indenting the next line | |
55 | #endif | |
56 | ||
57 | //____________________________________________________________________ | |
58 | AliFMDParameters* AliFMDParameters::fgInstance = 0; | |
59 | ||
60 | //____________________________________________________________________ | |
61 | const char* AliFMDParameters::fgkPulseGain = "FMD/Calib/PulseGain"; | |
62 | const char* AliFMDParameters::fgkPedestal = "FMD/Calib/Pedestal"; | |
63 | const char* AliFMDParameters::fgkDead = "FMD/Calib/Dead"; | |
64 | const char* AliFMDParameters::fgkSampleRate = "FMD/Calib/SampleRate"; | |
65 | const char* AliFMDParameters::fgkAltroMap = "FMD/Calib/AltroMap"; | |
66 | const char* AliFMDParameters::fgkZeroSuppression = "FMD/Calib/ZeroSuppression"; | |
67 | const char* AliFMDParameters::fgkStripRange = "FMD/Calib/StripRange"; | |
68 | const char* AliFMDParameters::fkPedestalShuttleID = "pedestals"; | |
69 | const char* AliFMDParameters::fkGainShuttleID = "gains"; | |
70 | const char* AliFMDParameters::fkConditionsShuttleID = "conditions"; | |
71 | ||
72 | //____________________________________________________________________ | |
73 | AliFMDParameters* | |
74 | AliFMDParameters::Instance() | |
75 | { | |
76 | // Get static instance | |
77 | if (!fgInstance) fgInstance = new AliFMDParameters; | |
78 | return fgInstance; | |
79 | } | |
80 | ||
81 | //____________________________________________________________________ | |
82 | AliFMDParameters::AliFMDParameters() | |
83 | : fIsInit(kFALSE), | |
84 | fkSiDeDxMip(1.664), | |
85 | fVA1MipRange(0), | |
86 | fAltroChannelSize(0), | |
87 | fChannelsPerAltro(0), | |
88 | fPedestalFactor(0), | |
89 | fZSPre(0), | |
90 | fZSPost(0), | |
91 | fZSPedSubtract(kFALSE), | |
92 | fFixedPedestal(0), | |
93 | fFixedPedestalWidth(0), | |
94 | fFixedZeroSuppression(0), | |
95 | fFixedSampleRate(0), | |
96 | fFixedThreshold(0), | |
97 | fFixedMinStrip(0), | |
98 | fFixedMaxStrip(0), | |
99 | fFixedPulseGain(0), | |
100 | fEdepMip(0), | |
101 | fHasCompleteHeader(kTRUE), | |
102 | fZeroSuppression(0), | |
103 | fSampleRate(0), | |
104 | fPedestal(0), | |
105 | fPulseGain(0), | |
106 | fDeadMap(0), | |
107 | fAltroMap(0), | |
108 | fStripRange(0) | |
109 | { | |
110 | // Default constructor | |
111 | SetVA1MipRange(); | |
112 | SetAltroChannelSize(); | |
113 | SetChannelsPerAltro(); | |
114 | SetZeroSuppression(); | |
115 | SetSampleRate(); | |
116 | SetPedestal(); | |
117 | SetPedestalWidth(); | |
118 | SetPedestalFactor(); | |
119 | SetThreshold(); | |
120 | SetStripRange(); | |
121 | fAltroMap = new AliFMDAltroMapping; | |
122 | } | |
123 | ||
124 | //__________________________________________________________________ | |
125 | void | |
126 | AliFMDParameters::Init(Bool_t forceReInit, UInt_t what) | |
127 | { | |
128 | // Initialize the parameters manager. We need to get stuff from the | |
129 | // CDB here. | |
130 | if (forceReInit) fIsInit = kFALSE; | |
131 | if (fIsInit) return; | |
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(); | |
138 | if (what & kStripRange) InitStripRange(); | |
139 | fIsInit = kTRUE; | |
140 | } | |
141 | //__________________________________________________________________ | |
142 | void | |
143 | AliFMDParameters::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); | |
155 | if (what & kStripRange) InitStripRange(pp); | |
156 | fIsInit = kTRUE; | |
157 | } | |
158 | ||
159 | //__________________________________________________________________ | |
160 | Bool_t | |
161 | AliFMDParameters::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 | //__________________________________________________________________ | |
174 | void | |
175 | AliFMDParameters::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 | //__________________________________________________________________ | |
230 | void | |
231 | AliFMDParameters::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 | } | |
240 | //__________________________________________________________________ | |
241 | #define DET2IDX(det,ring,sec,str) \ | |
242 | (det * 1000 + (ring == 'I' ? 0 : 512) + str) | |
243 | ||
244 | //__________________________________________________________________ | |
245 | void | |
246 | AliFMDParameters::Draw(Option_t* option) | |
247 | { | |
248 | TString opt(option); | |
249 | enum { | |
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 | |
260 | } what; | |
261 | ||
262 | if (opt.Contains("dead", TString::kIgnoreCase)) | |
263 | what = kLocalDead; | |
264 | else if (opt.Contains("threshold",TString::kIgnoreCase)) | |
265 | what = kLocalThreshold; | |
266 | else if (opt.Contains("gain",TString::kIgnoreCase)) | |
267 | what = kLocalPulseGain; | |
268 | else if (opt.Contains("pedestal",TString::kIgnoreCase)) | |
269 | what = kLocalPedestal; | |
270 | else if (opt.Contains("noise",TString::kIgnoreCase)) | |
271 | what = kLocalPedestalWidth; | |
272 | else if (opt.Contains("zero",TString::kIgnoreCase)) | |
273 | what = kLocalZeroSuppression; | |
274 | else if (opt.Contains("rate",TString::kIgnoreCase)) | |
275 | what = kLocalSampleRate; | |
276 | else if (opt.Contains("min",TString::kIgnoreCase)) | |
277 | what = kLocalMinStripRange; | |
278 | else if (opt.Contains("max",TString::kIgnoreCase)) | |
279 | what = kLocalMaxStripRange; | |
280 | else if (opt.Contains("map",TString::kIgnoreCase)) | |
281 | what = kLocalAltroMap; | |
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++) { | |
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++) { | |
302 | Int_t idx = DET2IDX(det, ring, 0, str); | |
303 | // Int_t idx = DET2IDX(det, ring, sec, 0); | |
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); | |
316 | for (/*Int_t*/ i = 0; i < ybins.fN; i++) ybins[i] = Float_t(i - .5); | |
317 | TH2D* hist = new TH2D("calib", Form("Calibration %s", option), | |
318 | xbins.fN-1, xbins.fArray, | |
319 | ybins.fN-1, ybins.fArray); | |
320 | hist->GetXaxis()->SetTitle("1000 #times detector + 512 #times ring + strip"); | |
321 | hist->GetYaxis()->SetTitle("sector"); | |
322 | ||
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); | |
335 | UShort_t ddl, addr, time, sam=0; | |
336 | Double_t val = 0; | |
337 | switch (what) { | |
338 | case kLocalPulseGain: // Path to PulseGain calib object | |
339 | val = GetPulseGain(det,ring,sec,str); break; | |
340 | case kLocalThreshold: // Path to PulseGain calib object | |
341 | val = GetThreshold(); break; | |
342 | case kLocalPedestal: // Path to Pedestal calib object | |
343 | val = GetPedestal(det,ring,sec,str); break; | |
344 | case kLocalPedestalWidth: // Path to Pedestal calib object | |
345 | val = GetPedestalWidth(det,ring,sec,str); break; | |
346 | case kLocalDead: // Path to Dead calib object | |
347 | val = IsDead(det,ring,sec,str); break; | |
348 | case kLocalSampleRate: // Path to SampleRate calib object | |
349 | val = GetSampleRate(det,ring,sec,str); break; | |
350 | case kLocalAltroMap: // Path to AltroMap calib object | |
351 | Detector2Hardware(det,ring,sec,str,sam,ddl,addr,time); | |
352 | val = addr; break; | |
353 | case kLocalZeroSuppression: // Path to ZeroSuppression cal object | |
354 | val = GetZeroSuppression(det,ring,sec,str); break; | |
355 | case kLocalMinStripRange: // Path to strip range cal object | |
356 | val = GetMinStrip(det,ring,sec,str); break; | |
357 | case kLocalMaxStripRange: // Path to strip range cal object | |
358 | val = GetMaxStrip(det,ring,sec,str); break; | |
359 | } | |
360 | hist->Fill(idx,sec,val); | |
361 | // hist->Fill(idx,str,val); | |
362 | } | |
363 | } | |
364 | } | |
365 | } | |
366 | hist->Draw("lego"); | |
367 | } | |
368 | ||
369 | //__________________________________________________________________ | |
370 | void | |
371 | AliFMDParameters::Print(Option_t* option) const | |
372 | { | |
373 | // Print information. | |
374 | // If option contains an 'A' then everything is printed. | |
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>. | |
383 | TString opt(option); | |
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 | ||
393 | if (opt.Contains("fmd",TString::kIgnoreCase)) { | |
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(); | |
400 | enum { | |
401 | kReadDet, | |
402 | kReadRing, | |
403 | kReadLbrack, | |
404 | kReadSector, | |
405 | kReadComma, | |
406 | kReadStrip, | |
407 | kReadRbrack, | |
408 | kEnd | |
409 | } state = kReadDet; | |
410 | std::stringstream s(opt(i+4, j-i-3).Data()); | |
411 | while (state != kEnd) { | |
412 | Char_t tmp = s.peek(); | |
413 | if (tmp == ' ' || tmp == '\t') { | |
414 | s.get(); | |
415 | continue; | |
416 | } | |
417 | switch (state) { | |
418 | case kReadDet: { // First, try to kRead the detector | |
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 | } | |
428 | state = (s.bad() ? kEnd : kReadRing); | |
429 | } break; | |
430 | case kReadRing: { // Then try to read the ring; | |
431 | Char_t ring; | |
432 | s >> ring; | |
433 | if (ring != '*' && !s.bad()) { | |
434 | rs[0] = ring; | |
435 | rs[1] = '\0'; | |
436 | } | |
437 | state = (s.bad() ? kEnd : kReadLbrack); | |
438 | } break; | |
439 | case kReadLbrack: { // Try to read a left bracket | |
440 | Char_t lbrack; | |
441 | s >> lbrack; | |
442 | state = (s.bad() ? kEnd : kReadSector); | |
443 | } break; | |
444 | case kReadSector: { // Try to read a sector | |
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 | } | |
454 | state = (s.bad() ? kEnd : kReadComma); | |
455 | } break; | |
456 | case kReadComma: { // Try to read a left bracket | |
457 | Char_t comma; | |
458 | s >> comma; | |
459 | state = (s.bad() ? kEnd : kReadStrip); | |
460 | } break; | |
461 | case kReadStrip: { // Try to read a strip | |
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 | } | |
471 | state = (s.bad() ? kEnd : kReadRbrack); | |
472 | } break; | |
473 | case kReadRbrack: { // Try to read a left bracket | |
474 | Char_t rbrack; | |
475 | s >> rbrack; | |
476 | state = kEnd; | |
477 | } break; | |
478 | case kEnd: | |
479 | break; | |
480 | } | |
481 | } | |
482 | } | |
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); | |
493 | std::cout << "FMD" << det << ring | |
494 | << " Strip range: " | |
495 | << std::setw(3) << min << "," | |
496 | << std::setw(3) << max << std::endl; | |
497 | ||
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++) { | |
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; | |
507 | std::cout | |
508 | << " Strip | Pedestal | Gain | ZS thr. | Address\n" | |
509 | << "--------+-------------------+------------+---------+---------" | |
510 | << std::endl; | |
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)) { | |
516 | std::cout << "dead" << std::endl; | |
517 | continue; | |
518 | } | |
519 | UShort_t ddl, addr, time, sam=0; | |
520 | Detector2Hardware(det, ring, sec, str, sam, ddl, addr, time); | |
521 | std::cout << std::setw(7) << GetPedestal(det, ring, sec, str) | |
522 | << "+/-" << std::setw(7) | |
523 | << GetPedestalWidth(det, ring, sec, str) | |
524 | << " | " << std::setw(10) | |
525 | << GetPulseGain(det, ring, sec, str) | |
526 | << " | " << std::setw(7) | |
527 | << GetZeroSuppression(det, ring, sec, str) | |
528 | << " | 0x" << std::hex << std::setw(4) | |
529 | << std::setfill('0') << ddl << ",0x" << std::setw(3) | |
530 | << addr << std::dec << std::setfill(' ') << std::endl; | |
531 | } // for (strip) | |
532 | } // for (sector) | |
533 | std::cout | |
534 | << "=============================================================" | |
535 | << std::endl; | |
536 | } // while (ring) | |
537 | } // while (det) | |
538 | ||
539 | } | |
540 | ||
541 | //__________________________________________________________________ | |
542 | void | |
543 | AliFMDParameters::SetStripRange(UShort_t min, UShort_t max) | |
544 | { | |
545 | // Set fixed strip range | |
546 | fFixedMinStrip = min; | |
547 | fFixedMaxStrip = max; | |
548 | } | |
549 | ||
550 | //__________________________________________________________________ | |
551 | AliCDBEntry* | |
552 | AliFMDParameters::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 | ||
579 | //__________________________________________________________________ | |
580 | void | |
581 | AliFMDParameters::InitPulseGain(AliFMDPreprocessor* pp) | |
582 | { | |
583 | // Get pulse gain from CDB or used fixed | |
584 | AliCDBEntry* gain = GetEntry(fgkPulseGain, pp); | |
585 | if (!gain) return; | |
586 | ||
587 | AliFMDDebug(5, ("Got gain from CDB")); | |
588 | fPulseGain = dynamic_cast<AliFMDCalibGain*>(gain->GetObject()); | |
589 | if (!fPulseGain) AliFatal("Invalid pulser gain object from CDB"); | |
590 | } | |
591 | //__________________________________________________________________ | |
592 | void | |
593 | AliFMDParameters::InitPedestal(AliFMDPreprocessor* pp) | |
594 | { | |
595 | // Initialize the pedestals from CDB | |
596 | AliCDBEntry* pedestal = GetEntry(fgkPedestal, pp); | |
597 | if (!pedestal) return; | |
598 | ||
599 | AliFMDDebug(5, ("Got pedestal from CDB")); | |
600 | fPedestal = dynamic_cast<AliFMDCalibPedestal*>(pedestal->GetObject()); | |
601 | if (!fPedestal) AliFatal("Invalid pedestal object from CDB"); | |
602 | } | |
603 | ||
604 | //__________________________________________________________________ | |
605 | void | |
606 | AliFMDParameters::InitDeadMap(AliFMDPreprocessor* pp) | |
607 | { | |
608 | // Get Dead-channel-map from CDB | |
609 | AliCDBEntry* deadMap = GetEntry(fgkDead, pp); | |
610 | if (!deadMap) return; | |
611 | ||
612 | AliFMDDebug(5, ("Got dead map from CDB")); | |
613 | fDeadMap = dynamic_cast<AliFMDCalibDeadMap*>(deadMap->GetObject()); | |
614 | if (!fDeadMap) AliFatal("Invalid dead map object from CDB"); | |
615 | } | |
616 | ||
617 | //__________________________________________________________________ | |
618 | void | |
619 | AliFMDParameters::InitZeroSuppression(AliFMDPreprocessor* pp) | |
620 | { | |
621 | // Get 0-suppression from CDB | |
622 | AliCDBEntry* zeroSup = GetEntry(fgkZeroSuppression, pp); | |
623 | if (!zeroSup) return; | |
624 | AliFMDDebug(5, ("Got zero suppression from CDB")); | |
625 | fZeroSuppression = | |
626 | dynamic_cast<AliFMDCalibZeroSuppression*>(zeroSup->GetObject()); | |
627 | if (!fZeroSuppression)AliFatal("Invalid zero suppression object from CDB"); | |
628 | } | |
629 | ||
630 | //__________________________________________________________________ | |
631 | void | |
632 | AliFMDParameters::InitSampleRate(AliFMDPreprocessor* pp) | |
633 | { | |
634 | // get Sample rate from CDB | |
635 | AliCDBEntry* sampRat = GetEntry(fgkSampleRate, pp); | |
636 | if (!sampRat) return; | |
637 | AliFMDDebug(5, ("Got zero suppression from CDB")); | |
638 | fSampleRate = dynamic_cast<AliFMDCalibSampleRate*>(sampRat->GetObject()); | |
639 | if (!fSampleRate) AliFatal("Invalid zero suppression object from CDB"); | |
640 | } | |
641 | ||
642 | //__________________________________________________________________ | |
643 | void | |
644 | AliFMDParameters::InitAltroMap(AliFMDPreprocessor* pp) | |
645 | { | |
646 | // Get hardware mapping from CDB | |
647 | if (fAltroMap) { | |
648 | delete fAltroMap; | |
649 | fAltroMap = 0; | |
650 | } | |
651 | AliCDBEntry* hwMap = GetEntry(fgkAltroMap, pp, kFALSE); | |
652 | if (!hwMap) return; | |
653 | ||
654 | AliFMDDebug(5, ("Got ALTRO map from CDB")); | |
655 | fAltroMap = dynamic_cast<AliFMDAltroMapping*>(hwMap->GetObject()); | |
656 | if (!fAltroMap) { | |
657 | AliFatal("Invalid ALTRO map object from CDB"); | |
658 | fAltroMap = new AliFMDAltroMapping; | |
659 | } | |
660 | } | |
661 | ||
662 | //__________________________________________________________________ | |
663 | void | |
664 | AliFMDParameters::InitStripRange(AliFMDPreprocessor* pp) | |
665 | { | |
666 | // Get strips read-out from CDB | |
667 | AliCDBEntry* range = GetEntry(fgkStripRange, pp); | |
668 | if (!range) return; | |
669 | AliFMDDebug(5, ("Got strip range from CDB")); | |
670 | fStripRange = dynamic_cast<AliFMDCalibStripRange*>(range->GetObject()); | |
671 | if (!fStripRange) AliFatal("Invalid strip range object from CDB"); | |
672 | } | |
673 | ||
674 | ||
675 | //__________________________________________________________________ | |
676 | Float_t | |
677 | AliFMDParameters::GetThreshold() const | |
678 | { | |
679 | // Get threshold from CDB | |
680 | if (!fPulseGain) return fFixedThreshold; | |
681 | return fPulseGain->Threshold(); | |
682 | } | |
683 | ||
684 | //__________________________________________________________________ | |
685 | Float_t | |
686 | AliFMDParameters::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 | } | |
703 | AliFMDDebug(50, ("pulse gain for FMD%d%c[%2d,%3d]=%f", | |
704 | detector, ring, sector, strip, | |
705 | fPulseGain->Value(detector, ring, sector, strip))); | |
706 | return fPulseGain->Value(detector, ring, sector, strip); | |
707 | } | |
708 | ||
709 | //__________________________________________________________________ | |
710 | Bool_t | |
711 | AliFMDParameters::IsDead(UShort_t detector, Char_t ring, | |
712 | UShort_t sector, UShort_t strip) const | |
713 | { | |
714 | // Check if the channel is dead | |
715 | if (!fDeadMap) return kFALSE; | |
716 | AliFMDDebug(50, ("Dead for FMD%d%c[%2d,%3d]=%s", | |
717 | detector, ring, sector, strip, | |
718 | fDeadMap->operator()(detector, ring, sector, strip) ? | |
719 | "no" : "yes")); | |
720 | return fDeadMap->operator()(detector, ring, sector, strip); | |
721 | } | |
722 | ||
723 | //__________________________________________________________________ | |
724 | UShort_t | |
725 | AliFMDParameters::GetZeroSuppression(UShort_t detector, Char_t ring, | |
726 | UShort_t sector, UShort_t strip) const | |
727 | { | |
728 | // Get zero suppression threshold | |
729 | if (!fZeroSuppression) return fFixedZeroSuppression; | |
730 | // Need to map strip to ALTRO chip. | |
731 | AliFMDDebug(50, ("zero sup. for FMD%d%c[%2d,%3d]=%f", | |
732 | detector, ring, sector, strip, | |
733 | fZeroSuppression->operator()(detector, ring, | |
734 | sector, strip))); | |
735 | return fZeroSuppression->operator()(detector, ring, sector, strip/128); | |
736 | } | |
737 | ||
738 | //__________________________________________________________________ | |
739 | UShort_t | |
740 | AliFMDParameters::GetSampleRate(UShort_t det, Char_t ring, UShort_t sector, | |
741 | UShort_t str) const | |
742 | { | |
743 | // Get sampl rate | |
744 | if (!fSampleRate) return fFixedSampleRate; | |
745 | // Need to map sector to digitizier card. | |
746 | UInt_t ret = fSampleRate->Rate(det, ring, sector, str); | |
747 | AliFMDDebug(50, ("Sample rate for FMD%d%c[%2d,%3d]=%d", | |
748 | det, ring, sector, str, ret)); | |
749 | return ret; | |
750 | } | |
751 | ||
752 | //__________________________________________________________________ | |
753 | UShort_t | |
754 | AliFMDParameters::GetMinStrip(UShort_t det, Char_t ring, UShort_t sector, | |
755 | UShort_t str) const | |
756 | { | |
757 | // Get strip range read out | |
758 | if (!fStripRange) return fFixedMinStrip; | |
759 | // Need to map sector to digitizier card. | |
760 | UInt_t ret = fStripRange->Min(det, ring, sector, str); | |
761 | AliFMDDebug(50, ("Min strip # for FMD%d%c[%2d,%3d]=%d", | |
762 | det, ring, sector, str, ret)); | |
763 | return ret; | |
764 | } | |
765 | ||
766 | //__________________________________________________________________ | |
767 | UShort_t | |
768 | AliFMDParameters::GetMaxStrip(UShort_t det, Char_t ring, UShort_t sector, | |
769 | UShort_t str) const | |
770 | { | |
771 | // Get strip range read out | |
772 | if (!fStripRange) return fFixedMaxStrip; | |
773 | // Need to map sector to digitizier card. | |
774 | UInt_t ret = fStripRange->Max(det, ring, sector, str); | |
775 | AliFMDDebug(50, ("Max strip # for FMD%d%c[%2d,%3d]=%d", | |
776 | det, ring, sector, str, ret)); | |
777 | return ret; | |
778 | } | |
779 | ||
780 | //__________________________________________________________________ | |
781 | Float_t | |
782 | AliFMDParameters::GetPedestal(UShort_t detector, Char_t ring, | |
783 | UShort_t sector, UShort_t strip) const | |
784 | { | |
785 | // Get the pedesal | |
786 | if (!fPedestal) return fFixedPedestal; | |
787 | AliFMDDebug(50, ("pedestal for FMD%d%c[%2d,%3d]=%f", | |
788 | detector, ring, sector, strip, | |
789 | fPedestal->Value(detector, ring, sector, strip))); | |
790 | return fPedestal->Value(detector, ring, sector, strip); | |
791 | } | |
792 | ||
793 | //__________________________________________________________________ | |
794 | Float_t | |
795 | AliFMDParameters::GetPedestalWidth(UShort_t detector, Char_t ring, | |
796 | UShort_t sector, UShort_t strip) const | |
797 | { | |
798 | // Get the pedesal | |
799 | if (!fPedestal) return fFixedPedestalWidth; | |
800 | AliFMDDebug(50, ("pedetal width for FMD%d%c[%2d,%3d]=%f", | |
801 | detector, ring, sector, strip, | |
802 | fPedestal->Width(detector, ring, sector, strip))); | |
803 | return fPedestal->Width(detector, ring, sector, strip); | |
804 | } | |
805 | ||
806 | //__________________________________________________________________ | |
807 | AliFMDAltroMapping* | |
808 | AliFMDParameters::GetAltroMap() const | |
809 | { | |
810 | // Get the hardware address to detector index map | |
811 | return fAltroMap; | |
812 | } | |
813 | ||
814 | ||
815 | //____________________________________________________________________ | |
816 | Bool_t | |
817 | AliFMDParameters::Hardware2Detector(UShort_t ddl, UShort_t addr, | |
818 | UShort_t timebin, | |
819 | UShort_t& det, Char_t& ring, | |
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 | |
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); | |
830 | } | |
831 | //____________________________________________________________________ | |
832 | Bool_t | |
833 | AliFMDParameters::Hardware2Detector(UShort_t ddl, UShort_t board, | |
834 | UShort_t chip, UShort_t chan, | |
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 | |
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)); | |
857 | return kTRUE; | |
858 | } | |
859 | ||
860 | #if 0 | |
861 | //__________________________________________________________________ | |
862 | Bool_t | |
863 | AliFMDParameters::Hardware2Detector(UShort_t ddl, UShort_t board, | |
864 | UShort_t chip, UShort_t chan, | |
865 | UShort_t& det, Char_t& ring, | |
866 | UShort_t& sec, Short_t& str) const | |
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 | //__________________________________________________________________ | |
873 | Bool_t | |
874 | AliFMDParameters::Hardware2Detector(UShort_t ddl, UShort_t addr, | |
875 | UShort_t& det, Char_t& ring, | |
876 | UShort_t& sec, Short_t& str) const | |
877 | { | |
878 | // Map hardware address to detector index | |
879 | if (!fAltroMap) return kFALSE; | |
880 | return fAltroMap->Hardware2Detector(ddl, addr, det, ring, sec, str); | |
881 | } | |
882 | #endif | |
883 | ||
884 | //____________________________________________________________________ | |
885 | Bool_t | |
886 | AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring, | |
887 | UShort_t sec, UShort_t str, | |
888 | UShort_t sam, | |
889 | UShort_t& ddl, UShort_t& board, | |
890 | UShort_t& altro, UShort_t& channel, | |
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 | ||
904 | //____________________________________________________________________ | |
905 | Bool_t | |
906 | AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring, | |
907 | UShort_t sec, UShort_t str, | |
908 | UShort_t sam, | |
909 | UShort_t& ddl, UShort_t& addr, | |
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 | ||
921 | #if 0 | |
922 | //__________________________________________________________________ | |
923 | Bool_t | |
924 | AliFMDParameters::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 | ||
934 | //__________________________________________________________________ | |
935 | Bool_t | |
936 | AliFMDParameters::Detector2Hardware(UShort_t det, Char_t ring, | |
937 | UShort_t sec, UShort_t str, | |
938 | UShort_t& ddl, UShort_t& addr) const | |
939 | { | |
940 | // Map detector index to hardware address | |
941 | if (!fAltroMap) return kFALSE; | |
942 | return fAltroMap->Detector2Hardware(det, ring, sec, str, ddl, addr); | |
943 | } | |
944 | #endif | |
945 | ||
946 | //__________________________________________________________________ | |
947 | Float_t | |
948 | AliFMDParameters::GetEdepMip() const | |
949 | { | |
950 | // Get energy deposited by a MIP in the silicon sensors | |
951 | if (fEdepMip <= 0){ | |
952 | AliFMDGeometry* fmd = AliFMDGeometry::Instance(); | |
953 | fEdepMip = (fkSiDeDxMip | |
954 | * fmd->GetRing('I')->GetSiThickness() | |
955 | * fmd->GetSiDensity()); | |
956 | } | |
957 | return fEdepMip; | |
958 | } | |
959 | //____________________________________________________________________ | |
960 | Float_t | |
961 | AliFMDParameters::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. | |
966 | ||
967 | return 29.67; | |
968 | ||
969 | } | |
970 | ||
971 | //____________________________________________________________________ | |
972 | // | |
973 | // EOF | |
974 | // |