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