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