]> git.uio.no Git - u/mrichter/AliRoot.git/blob - FMD/AliFMDParameters.cxx
Several fixes (the Make-Federico-Happy-Commit):
[u/mrichter/AliRoot.git] / FMD / AliFMDParameters.cxx
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     fFixedPedestal(0),
90     fFixedPedestalWidth(0),
91     fFixedZeroSuppression(0),
92     fFixedSampleRate(0),
93     fFixedThreshold(0),
94     fFixedMinStrip(0),
95     fFixedMaxStrip(0),
96     fFixedPulseGain(0), 
97     fEdepMip(0),
98     fHasCompleteHeader(kTRUE),
99     fZeroSuppression(0), 
100     fSampleRate(0), 
101     fPedestal(0), 
102     fPulseGain(0), 
103     fDeadMap(0), 
104     fAltroMap(0), 
105     fStripRange(0)
106 {
107   // Default constructor 
108   SetVA1MipRange();
109   SetAltroChannelSize();
110   SetChannelsPerAltro();
111   SetZeroSuppression();
112   SetSampleRate();
113   SetPedestal();
114   SetPedestalWidth();
115   SetPedestalFactor();
116   SetThreshold();
117   SetStripRange();
118   fAltroMap = new AliFMDAltroMapping;
119 }
120
121 //__________________________________________________________________
122 void
123 AliFMDParameters::Init(Bool_t forceReInit, UInt_t what)
124 {
125   // Initialize the parameters manager.  We need to get stuff from the
126   // CDB here. 
127   if (forceReInit) fIsInit = kFALSE;
128   if (fIsInit) return;
129   if (what & kPulseGain)       InitPulseGain();
130   if (what & kPedestal)        InitPedestal();
131   if (what & kDeadMap)         InitDeadMap();
132   if (what & kSampleRate)      InitSampleRate();
133   if (what & kZeroSuppression) InitZeroSuppression();
134   if (what & kAltroMap)        InitAltroMap();
135   if (what & kStripRange)      InitStripRange();
136   fIsInit = kTRUE;
137 }
138 //__________________________________________________________________
139 void
140 AliFMDParameters::Init(AliFMDPreprocessor* pp, Bool_t forceReInit, UInt_t what)
141 {
142   // Initialize the parameters manager.  We need to get stuff from the
143   // CDB here. 
144   if (forceReInit) fIsInit = kFALSE;
145   if (fIsInit) return;
146   if (what & kPulseGain)       InitPulseGain(pp);
147   if (what & kPedestal)        InitPedestal(pp);
148   if (what & kDeadMap)         InitDeadMap(pp);
149   if (what & kSampleRate)      InitSampleRate(pp);
150   if (what & kZeroSuppression) InitZeroSuppression(pp);
151   if (what & kAltroMap)        InitAltroMap(pp);
152   if (what & kStripRange)      InitStripRange(pp);
153   fIsInit = kTRUE;
154 }
155
156 //__________________________________________________________________
157 #define DET2IDX(det,ring,sec,str) \
158   (det * 1000 + (ring == 'I' ? 0 : 512) + str)  
159   
160 //__________________________________________________________________
161 void
162 AliFMDParameters::Draw(Option_t* option)
163 {
164   TString opt(option);
165   enum {
166     kLocalPulseGain,       // Path to PulseGain calib object
167     kLocalThreshold,       // Path to PulseGain calib object
168     kLocalPedestal,        // Path to Pedestal calib object
169     kLocalPedestalWidth,   // Path to Pedestal calib object
170     kLocalDead,            // Path to Dead calib object
171     kLocalSampleRate,      // Path to SampleRate calib object
172     kLocalAltroMap,        // Path to AltroMap calib object
173     kLocalZeroSuppression, // Path to ZeroSuppression cal object
174     kLocalMinStripRange,   // Path to strip range cal object
175     kLocalMaxStripRange    // Path to strip range cal object
176   } what;
177     
178   if      (opt.Contains("dead", TString::kIgnoreCase)) 
179     what = kLocalDead;
180   else if (opt.Contains("threshold",TString::kIgnoreCase)) 
181     what = kLocalThreshold;
182   else if (opt.Contains("gain",TString::kIgnoreCase)) 
183     what = kLocalPulseGain;
184   else if (opt.Contains("pedestal",TString::kIgnoreCase)) 
185     what = kLocalPedestal;
186   else if (opt.Contains("noise",TString::kIgnoreCase)) 
187     what = kLocalPedestalWidth;
188   else if (opt.Contains("zero",TString::kIgnoreCase)) 
189     what = kLocalZeroSuppression;
190   else if (opt.Contains("rate",TString::kIgnoreCase)) 
191     what = kLocalSampleRate;
192   else if (opt.Contains("min",TString::kIgnoreCase)) 
193     what = kLocalMinStripRange;
194   else if (opt.Contains("max",TString::kIgnoreCase)) 
195     what = kLocalMaxStripRange;
196   else if (opt.Contains("map",TString::kIgnoreCase)) 
197     what = kLocalAltroMap;
198   else {
199     Warning("Draw", "unknown parameter: %s\n\tShould be one of\n\t"
200             "dead, threshold, gain, pedestal, noise, zero, rate, "
201             "min, max, map",  
202             option); 
203     return;
204   }
205
206   TArrayD xbins(3 * 512 + 2 * 256 + 5);
207   Int_t i = 1;
208   Bool_t skip = kTRUE;
209   for (UShort_t det = 1; det <= 3; det++) {
210     UShort_t nRings = (det == 1 ? 1 : 2);
211     for (UShort_t iring = 0; iring < nRings; iring++) {
212       UShort_t nStrip  = (iring == 0 ? 512 : 256);
213       Char_t   ring    = (iring == 0 ? 'I' : 'O');
214       for (UShort_t str = 0; str < nStrip; str++) {
215         // UShort_t nSec    = (iring == 0 ? 20  : 40);
216         // Char_t   ring    = (iring == 0 ? 'I' : 'O');
217         // for (UShort_t sec = 0; sec < nSec; sec++) {
218         Int_t idx = DET2IDX(det, ring, 0, str);
219         // Int_t idx = DET2IDX(det, ring, sec, 0);
220         if (skip) {
221           xbins[i-1] = idx - .5;
222           skip  = kFALSE;
223         }
224         xbins[i] = idx + .5;
225         i++;
226       }
227       skip = kTRUE;
228       i++;
229     }
230   }
231   TArrayD ybins(41);
232   for (/*Int_t*/ i = 0; i < ybins.fN; i++) ybins[i] = Float_t(i - .5);
233   TH2D* hist = new TH2D("calib", Form("Calibration %s", option), 
234                         xbins.fN-1, xbins.fArray,  
235                         ybins.fN-1, ybins.fArray);
236   hist->GetXaxis()->SetTitle("1000 #times detector + 512 #times ring + strip");
237   hist->GetYaxis()->SetTitle("sector");
238   
239   // hist->Draw("Lego");
240   // return;
241   
242   for (UShort_t det = 1; det <= 3; det++) {
243     UShort_t nRings = (det == 1 ? 1 : 2);
244     for (UShort_t iring = 0; iring < nRings; iring++) {
245       UShort_t nSector = (iring == 0 ?  20 : 40);
246       UShort_t nStrip  = (iring == 0 ? 512 : 256);
247       Char_t   ring    = (iring == 0 ? 'I' : 'O');
248       for (UShort_t sec = 0; sec < nSector; sec++) {
249         for (UShort_t str = 0; str < nStrip; str++) {
250           Int_t idx = DET2IDX(det, ring, sec, str);
251           UInt_t ddl, addr;
252           Double_t val = 0;
253           switch (what) {
254           case kLocalPulseGain:       // Path to PulseGain calib object
255             val = GetPulseGain(det,ring,sec,str); break;
256           case kLocalThreshold:       // Path to PulseGain calib object
257             val = GetThreshold(); break;
258           case kLocalPedestal:        // Path to Pedestal calib object
259             val = GetPedestal(det,ring,sec,str); break;
260           case kLocalPedestalWidth:   // Path to Pedestal calib object
261             val = GetPedestalWidth(det,ring,sec,str); break;
262           case kLocalDead:            // Path to Dead calib object
263             val = IsDead(det,ring,sec,str); break;
264           case kLocalSampleRate:      // Path to SampleRate calib object
265             val = GetSampleRate(det,ring,sec,str); break;
266           case kLocalAltroMap:        // Path to AltroMap calib object
267             Detector2Hardware(det,ring,sec,str, ddl, addr); 
268             val = addr; break;
269           case kLocalZeroSuppression: // Path to ZeroSuppression cal object
270             val = GetZeroSuppression(det,ring,sec,str); break;
271           case kLocalMinStripRange:   // Path to strip range cal object
272             val = GetMinStrip(det,ring,sec,str); break;
273           case kLocalMaxStripRange:    // Path to strip range cal object
274             val = GetMaxStrip(det,ring,sec,str); break;
275           }
276           hist->Fill(idx,sec,val);
277           // hist->Fill(idx,str,val);
278         }
279       }
280     }
281   }
282   hist->Draw("lego");
283 }
284
285 //__________________________________________________________________
286 void
287 AliFMDParameters::Print(Option_t* option) const
288 {
289   // Print information. 
290   // If option contains an 'A' then everything is printed. 
291   // If the option contains the string "FMD" the function will search 
292   // for detector, ring, sector, and strip numbers to print, in the
293   // format 
294   // 
295   //    FMD<detector><ring>[<sector>,<string>] 
296   // 
297   // The wild card '*' means all of <detector>, <ring>, <sector>, or 
298   // <strip>. 
299   TString opt(option);
300   Bool_t showStrips  = opt.Contains("a", TString::kIgnoreCase);
301   UShort_t ds[]      = { 1, 2, 3, 0 };
302   Char_t   rs[]      = { 'I', 'O', '\0' };
303   UShort_t minStrip  = 0;
304   UShort_t maxStrip  = 512;
305   UShort_t minSector = 0;
306   UShort_t maxSector = 40;
307   
308   
309   if (opt.Contains("fmd",TString::kIgnoreCase)) {
310     Int_t   i    = opt.Index("fmd",TString::kIgnoreCase);
311     Int_t   j    = opt.Index("]",TString::kIgnoreCase);
312     if (j != kNPOS)
313       showStrips    = kTRUE;
314     else 
315       j = opt.Length();
316     enum {
317       kReadDet, 
318       kReadRing, 
319       kReadLbrack,
320       kReadSector,
321       kReadComma,
322       kReadStrip,
323       kReadRbrack, 
324       kEnd
325     } state = kReadDet;
326     std::stringstream s(opt(i+4, j-i-3).Data());
327     while (state != kEnd) {
328       Char_t tmp = s.peek();
329       if (tmp == ' ' || tmp == '\t') {
330         s.get();
331         continue;
332       }
333       switch (state) {
334       case kReadDet: { // First, try to kRead the detector 
335         if (tmp == '*') s.get();
336         else { 
337           UShort_t det;
338           s >> det;
339           if (!s.bad()) {
340             ds[0] = det;
341             ds[1] = 0;
342           }
343         }
344         state = (s.bad() ? kEnd : kReadRing);
345       } break;
346       case kReadRing: { // Then try to read the ring;
347         Char_t ring;
348         s >> ring;
349         if (ring != '*' && !s.bad()) {
350           rs[0] = ring;
351           rs[1] = '\0';
352         }
353         state = (s.bad() ? kEnd : kReadLbrack);
354       } break;
355       case kReadLbrack: { // Try to read a left bracket 
356         Char_t lbrack;
357         s >> lbrack;
358         state = (s.bad() ? kEnd : kReadSector);
359       } break;
360       case kReadSector: { // Try to read a sector 
361         if (tmp == '*') s.get();
362         else {
363           UShort_t sec;
364           s >> sec;
365           if (!s.bad()) {
366             minSector = sec;
367             maxSector = sec + 1;
368           }
369         }
370         state = (s.bad() ? kEnd : kReadComma);
371       } break;
372       case kReadComma: { // Try to read a left bracket 
373         Char_t comma;
374         s >> comma;
375         state = (s.bad() ? kEnd : kReadStrip);
376       } break;
377       case kReadStrip: { // Try to read a strip 
378         if (tmp == '*') s.get();
379         else {
380           UShort_t str;
381           s >> str;
382           if (!s.bad()) {
383             minStrip = str;
384             maxStrip = str + 1;
385           }
386         }
387         state = (s.bad() ? kEnd : kReadRbrack);
388       } break;
389       case kReadRbrack: { // Try to read a left bracket 
390         Char_t rbrack;
391         s >> rbrack;
392         state = kEnd;
393       } break;
394       case kEnd: 
395         break;
396       }
397     }
398   }
399   UShort_t* dp = ds;
400   UShort_t  det;
401   while ((det = *(dp++))) {
402
403     Char_t* rp = rs;
404     Char_t  ring;
405     while ((ring = *(rp++))) {
406       if (det == 1 && ring == 'O') continue;
407       UShort_t min  = GetMinStrip(det, ring, 0, 0);
408       UShort_t max  = GetMaxStrip(det, ring, 0, 0);
409       std::cout << "FMD" << det << ring 
410                 << "  Strip range: " 
411                 << std::setw(3) << min << "," 
412                 << std::setw(3) << max << std::endl;
413
414       UShort_t nSec = ( ring == 'I' ? 20  :  40 );
415       UShort_t nStr = ( ring == 'I' ? 512 : 256 );
416       for (UShort_t sec = minSector; sec < maxSector && sec < nSec; sec++) {
417
418         UShort_t rate = GetSampleRate(det, ring, sec, 0);
419         std::cout << "FMD" << det << ring << "[" << std::setw(2) << sec 
420                   << "] sample rate: " << rate << std::endl;
421
422         if (!showStrips) continue;
423         std::cout 
424           << "  Strip |     Pedestal      |    Gain    | ZS thr. | Address\n" 
425           << "--------+-------------------+------------+---------+---------" 
426           << std::endl;
427         for (UShort_t str = minStrip; str < nStr && str < maxStrip; str++) {
428           if (str == minStrip) std::cout << std::setw(3) << sec << ",";
429           else std::cout << "    ";
430           std::cout << std::setw(3) << str << " | ";
431           if (IsDead(det, ring, sec, str)) {
432             std::cout << "dead" << std::endl;
433             continue;
434           }
435           UInt_t ddl, addr;
436           Detector2Hardware(det, ring, sec, str, ddl, addr);
437           std::cout << std::setw(7) << GetPedestal(det, ring, sec, str) 
438                     << "+/-" << std::setw(7) 
439                     << GetPedestalWidth(det, ring, sec, str) 
440                     << " | " << std::setw(10) 
441                     << GetPulseGain(det, ring, sec, str) 
442                     << " | " << std::setw(7) 
443                     << GetZeroSuppression(det, ring, sec, str) 
444                     << " | 0x" << std::hex << std::setw(4) 
445                     << std::setfill('0') << ddl << ",0x" << std::setw(3) 
446                     << addr << std::dec << std::setfill(' ') << std::endl;
447         } // for (strip)
448       } // for (sector)
449       std::cout
450         << "=============================================================" 
451         << std::endl;
452     } // while (ring)
453   } // while (det)
454   
455 }
456
457 //__________________________________________________________________
458 void
459 AliFMDParameters::SetStripRange(UShort_t min, UShort_t max) 
460 {
461   // Set fixed strip range 
462   fFixedMinStrip = min;
463   fFixedMaxStrip = max;
464 }
465
466 //__________________________________________________________________
467 AliCDBEntry*
468 AliFMDParameters::GetEntry(const char* path, AliFMDPreprocessor* pp, 
469                            Bool_t fatal) const
470 {
471   // Get an entry from the CDB or via preprocessor 
472   AliCDBEntry* entry = 0;
473   if (!pp) {
474     AliCDBManager* cdb = AliCDBManager::Instance();
475     entry              = cdb->Get(path);
476   }
477   else {
478     const char* third  = gSystem->BaseName(path);
479     const char* second = gSystem->BaseName(gSystem->DirName(path));
480     entry              = pp->GetFromCDB(second, third);
481   }
482   if (!entry) { 
483     TString msg(Form("No %s found in CDB, perhaps you need to "
484                      "use AliFMDCalibFaker?", path));
485     if (fatal) { AliFatal(msg.Data()); }
486     else       AliLog::Message(AliLog::kWarning, msg.Data(), "FMD", 
487                                "AliFMDParameters", "GetEntry", __FILE__, 
488                                __LINE__);
489     return 0;
490   }
491   return entry;
492 }
493
494     
495 //__________________________________________________________________
496 void
497 AliFMDParameters::InitPulseGain(AliFMDPreprocessor* pp)
498 {
499   // Get pulse gain from CDB or used fixed 
500   AliCDBEntry*   gain     = GetEntry(fgkPulseGain, pp);
501   if (!gain) return;
502   
503   AliFMDDebug(5, ("Got gain from CDB"));
504   fPulseGain = dynamic_cast<AliFMDCalibGain*>(gain->GetObject());
505   if (!fPulseGain) AliFatal("Invalid pulser gain object from CDB");
506 }
507 //__________________________________________________________________
508 void
509 AliFMDParameters::InitPedestal(AliFMDPreprocessor* pp)
510 {
511   // Initialize the pedestals from CDB 
512   AliCDBEntry*   pedestal = GetEntry(fgkPedestal, pp);
513   if (!pedestal) return;
514
515   AliFMDDebug(5, ("Got pedestal from CDB"));
516   fPedestal = dynamic_cast<AliFMDCalibPedestal*>(pedestal->GetObject());
517   if (!fPedestal) AliFatal("Invalid pedestal object from CDB");
518 }
519
520 //__________________________________________________________________
521 void
522 AliFMDParameters::InitDeadMap(AliFMDPreprocessor* pp)
523 {
524   // Get Dead-channel-map from CDB 
525   AliCDBEntry*   deadMap  = GetEntry(fgkDead, pp);
526   if (!deadMap) return;
527   
528   AliFMDDebug(5, ("Got dead map from CDB"));
529   fDeadMap = dynamic_cast<AliFMDCalibDeadMap*>(deadMap->GetObject());
530   if (!fDeadMap) AliFatal("Invalid dead map object from CDB");
531 }
532
533 //__________________________________________________________________
534 void
535 AliFMDParameters::InitZeroSuppression(AliFMDPreprocessor* pp)
536 {
537   // Get 0-suppression from CDB 
538   AliCDBEntry*   zeroSup  = GetEntry(fgkZeroSuppression, pp);
539   if (!zeroSup) return;
540   AliFMDDebug(5, ("Got zero suppression from CDB"));
541   fZeroSuppression = 
542     dynamic_cast<AliFMDCalibZeroSuppression*>(zeroSup->GetObject());
543   if (!fZeroSuppression)AliFatal("Invalid zero suppression object from CDB");
544 }
545
546 //__________________________________________________________________
547 void
548 AliFMDParameters::InitSampleRate(AliFMDPreprocessor* pp)
549 {
550   // get Sample rate from CDB
551   AliCDBEntry*   sampRat  = GetEntry(fgkSampleRate, pp);
552   if (!sampRat) return;
553   AliFMDDebug(5, ("Got zero suppression from CDB"));
554   fSampleRate = dynamic_cast<AliFMDCalibSampleRate*>(sampRat->GetObject());
555   if (!fSampleRate) AliFatal("Invalid zero suppression object from CDB");
556 }
557
558 //__________________________________________________________________
559 void
560 AliFMDParameters::InitAltroMap(AliFMDPreprocessor* pp)
561 {
562   // Get hardware mapping from CDB
563   if (fAltroMap) { 
564     delete fAltroMap;
565     fAltroMap = 0;
566   }
567   AliCDBEntry*   hwMap    = GetEntry(fgkAltroMap, pp, kFALSE);       
568   if (!hwMap) return;
569
570   AliFMDDebug(5, ("Got ALTRO map from CDB"));
571   fAltroMap = dynamic_cast<AliFMDAltroMapping*>(hwMap->GetObject());
572   if (!fAltroMap) {
573     AliFatal("Invalid ALTRO map object from CDB");
574     fAltroMap = new AliFMDAltroMapping;
575   }
576 }
577
578 //__________________________________________________________________
579 void
580 AliFMDParameters::InitStripRange(AliFMDPreprocessor* pp)
581 {
582   // Get strips read-out from CDB
583   AliCDBEntry*   range    = GetEntry(fgkStripRange, pp);
584   if (!range) return;
585   AliFMDDebug(5, ("Got strip range from CDB"));
586   fStripRange = dynamic_cast<AliFMDCalibStripRange*>(range->GetObject());
587   if (!fStripRange) AliFatal("Invalid strip range object from CDB");
588 }
589
590
591 //__________________________________________________________________
592 Float_t
593 AliFMDParameters::GetThreshold() const
594 {
595   // Get threshold from CDB
596   if (!fPulseGain) return fFixedThreshold;
597   return fPulseGain->Threshold();
598 }
599
600 //__________________________________________________________________
601 Float_t
602 AliFMDParameters::GetPulseGain(UShort_t detector, Char_t ring, 
603                                UShort_t sector, UShort_t strip) const
604 {
605   // Returns the pulser calibrated gain for strip # strip in sector #
606   // sector or ring id ring of detector # detector. 
607   // 
608   // For simulation, this is normally set to 
609   // 
610   //       VA1_MIP_Range 
611   //    ------------------ * MIP_Energy_Loss
612   //    ALTRO_channel_size
613   // 
614   if (!fPulseGain) { 
615     if (fFixedPulseGain <= 0)
616       fFixedPulseGain = fVA1MipRange * GetEdepMip() / fAltroChannelSize;
617     return fFixedPulseGain;
618   }  
619   AliFMDDebug(50, ("pulse gain for FMD%d%c[%2d,%3d]=%f",
620                     detector, ring, sector, strip,
621                     fPulseGain->Value(detector, ring, sector, strip)));
622   return fPulseGain->Value(detector, ring, sector, strip);
623 }
624
625 //__________________________________________________________________
626 Bool_t
627 AliFMDParameters::IsDead(UShort_t detector, Char_t ring, 
628                          UShort_t sector, UShort_t strip) const
629 {
630   // Check if the channel is dead 
631   if (!fDeadMap) return kFALSE;
632   AliFMDDebug(50, ("Dead for FMD%d%c[%2d,%3d]=%s",
633                     detector, ring, sector, strip,
634                     fDeadMap->operator()(detector, ring, sector, strip) ? 
635                     "no" : "yes"));
636   return fDeadMap->operator()(detector, ring, sector, strip);
637 }
638
639 //__________________________________________________________________
640 UShort_t
641 AliFMDParameters::GetZeroSuppression(UShort_t detector, Char_t ring, 
642                                      UShort_t sector, UShort_t strip) const
643 {
644   // Get zero suppression threshold 
645   if (!fZeroSuppression) return fFixedZeroSuppression;
646   // Need to map strip to ALTRO chip. 
647   AliFMDDebug(50, ("zero sup. for FMD%d%c[%2d,%3d]=%f",
648                     detector, ring, sector, strip,
649                     fZeroSuppression->operator()(detector, ring, 
650                                                  sector, strip)));
651   return fZeroSuppression->operator()(detector, ring, sector, strip/128);
652 }
653
654 //__________________________________________________________________
655 UShort_t
656 AliFMDParameters::GetSampleRate(UShort_t det, Char_t ring, UShort_t sector, 
657                                 UShort_t str) const
658 {
659   // Get sampl rate 
660   if (!fSampleRate) return fFixedSampleRate;
661   // Need to map sector to digitizier card. 
662   UInt_t ret = fSampleRate->Rate(det, ring, sector, str);
663   AliFMDDebug(50, ("Sample rate for FMD%d%c[%2d,%3d]=%d", 
664                     det, ring, sector, str, ret));
665   return ret;
666 }
667
668 //__________________________________________________________________
669 UShort_t
670 AliFMDParameters::GetMinStrip(UShort_t det, Char_t ring, UShort_t sector, 
671                               UShort_t str) const
672 {
673   // Get strip range read out 
674   if (!fStripRange) return fFixedMinStrip;
675   // Need to map sector to digitizier card. 
676   UInt_t ret = fStripRange->Min(det, ring, sector, str);
677   AliFMDDebug(50, ("Min strip # for FMD%d%c[%2d,%3d]=%d", 
678                     det, ring, sector, str, ret));
679   return ret;
680 }
681
682 //__________________________________________________________________
683 UShort_t
684 AliFMDParameters::GetMaxStrip(UShort_t det, Char_t ring, UShort_t sector, 
685                               UShort_t str) const
686 {
687   // Get strip range read out 
688   if (!fStripRange) return fFixedMaxStrip;
689   // Need to map sector to digitizier card. 
690   UInt_t ret = fStripRange->Max(det, ring, sector, str);
691   AliFMDDebug(50, ("Max strip # for FMD%d%c[%2d,%3d]=%d", 
692                     det, ring, sector, str, ret));
693   return ret;
694 }
695
696 //__________________________________________________________________
697 Float_t
698 AliFMDParameters::GetPedestal(UShort_t detector, Char_t ring, 
699                               UShort_t sector, UShort_t strip) const
700 {
701   // Get the pedesal 
702   if (!fPedestal) return fFixedPedestal;
703   AliFMDDebug(50, ("pedestal for FMD%d%c[%2d,%3d]=%f",
704                     detector, ring, sector, strip,
705                     fPedestal->Value(detector, ring, sector, strip)));
706   return fPedestal->Value(detector, ring, sector, strip);
707 }
708
709 //__________________________________________________________________
710 Float_t
711 AliFMDParameters::GetPedestalWidth(UShort_t detector, Char_t ring, 
712                                    UShort_t sector, UShort_t strip) const
713 {
714   // Get the pedesal 
715   if (!fPedestal) return fFixedPedestalWidth;
716   AliFMDDebug(50, ("pedetal width for FMD%d%c[%2d,%3d]=%f",
717                     detector, ring, sector, strip,
718                     fPedestal->Width(detector, ring, sector, strip)));
719   return fPedestal->Width(detector, ring, sector, strip);
720 }
721   
722 //__________________________________________________________________
723 AliFMDAltroMapping*
724 AliFMDParameters::GetAltroMap() const
725 {
726   // Get the hardware address to detector index map 
727   return fAltroMap;
728 }
729
730
731 //__________________________________________________________________
732 Bool_t
733 AliFMDParameters::Hardware2Detector(UInt_t    ddl,  UInt_t    board, 
734                                     UInt_t    chip, UInt_t    chan,
735                                     UShort_t& det,  Char_t&   ring, 
736                                     UShort_t& sec,  UShort_t& str) const
737 {
738   // Map hardware address to detector index
739   if (!fAltroMap) return kFALSE;
740   return fAltroMap->Hardware2Detector(ddl,board,chip,chan, det,ring,sec,str);
741 }
742 //__________________________________________________________________
743 Bool_t
744 AliFMDParameters::Hardware2Detector(UInt_t    ddl,  UInt_t    addr, 
745                                     UShort_t& det,  Char_t&   ring, 
746                                     UShort_t& sec,  UShort_t& str) const
747 {
748   // Map hardware address to detector index
749   if (!fAltroMap) return kFALSE;
750   return fAltroMap->Hardware2Detector(ddl, addr, det, ring, sec, str);
751 }
752
753 //__________________________________________________________________
754 Bool_t
755 AliFMDParameters::Detector2Hardware(UShort_t det,  Char_t   ring, 
756                                     UShort_t sec,  UShort_t str, 
757                                     UInt_t&  ddl,  UInt_t&  board, 
758                                     UInt_t&  chip, UInt_t&  chan) const
759 {
760   // Map detector index to hardware address
761   if (!fAltroMap) return kFALSE;
762   return fAltroMap->Detector2Hardware(det,ring,sec,str, ddl,board,chip,chan);
763 }
764
765 //__________________________________________________________________
766 Bool_t
767 AliFMDParameters::Detector2Hardware(UShort_t det, Char_t   ring, 
768                                     UShort_t sec, UShort_t str, 
769                                     UInt_t&  ddl, UInt_t&  addr) const
770 {
771   // Map detector index to hardware address
772   if (!fAltroMap) return kFALSE;
773   return fAltroMap->Detector2Hardware(det, ring, sec, str, ddl, addr);
774 }
775
776
777 //__________________________________________________________________
778 Float_t
779 AliFMDParameters::GetEdepMip() const 
780
781   // Get energy deposited by a MIP in the silicon sensors
782   if (fEdepMip <= 0){
783     AliFMDGeometry* fmd = AliFMDGeometry::Instance();
784     fEdepMip = (fkSiDeDxMip 
785                 * fmd->GetRing('I')->GetSiThickness() 
786                 * fmd->GetSiDensity());
787   }
788   return fEdepMip;
789 }
790
791
792   
793   
794   
795 //____________________________________________________________________
796 //
797 // EOF
798 //