LCOV - code coverage report
Current view: top level - FMD/FMDbase - AliFMDParameters.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 185 509 36.3 %
Date: 2016-06-14 17:26:59 Functions: 26 36 72.2 %

          Line data    Source code
       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             : /**
      17             :  * @file    AliFMDParameters.cxx
      18             :  * @author  Christian Holm Christensen <cholm@nbi.dk>
      19             :  * @date    Mon Mar 27 12:44:26 2006
      20             :  * @brief   Manager of FMD parameters     
      21             :  */
      22             : //____________________________________________________________________
      23             : //                                                                          
      24             : // Forward Multiplicity Detector based on Silicon wafers. 
      25             : //
      26             : // This class is a singleton that handles various parameters of
      27             : // the FMD detectors.  
      28             : // The manager normally serves the parameters from the Conditions
      29             : // Database (CDB).  These are retrivied by the member function
      30             : // `Init'.  Optionally, the class can serve hard-coded constants, if
      31             : // no CDB is available. 
      32             : //                                                       
      33             : #include "AliFMDDebug.h"                 // ALILOG_H
      34             : #include "AliFMDParameters.h"    // ALIFMDPARAMETERS_H
      35             : #include "AliFMDGeometry.h"      // ALIFMDGEOMETRY_H
      36             : #include "AliFMDRing.h"                  // ALIFMDRING_H
      37             : #include "AliFMDCalibGain.h"       // ALIFMDCALIBGAIN_H
      38             : #include "AliFMDCalibPedestal.h"   // ALIFMDCALIBPEDESTAL_H
      39             : #include "AliFMDCalibSampleRate.h" // ALIFMDCALIBSAMPLERATE_H
      40             : #include "AliFMDCalibStripRange.h" // ALIFMDCALIBSTRIPRANGE_H
      41             : #include "AliFMDAltroMapping.h"    // ALIFMDALTROMAPPING_H
      42             : #include <AliCDBManager.h>         // ALICDBMANAGER_H
      43             : #include <AliCDBEntry.h>           // ALICDBMANAGER_H
      44             : #include <AliFMDPreprocessor.h>
      45             : #include <AliLog.h>
      46             : #include <Riostream.h>
      47             : #include <sstream>
      48             : #include <TSystem.h>
      49             : #include <TArrayF.h>
      50             : #include <TH2D.h>
      51             : 
      52             : //====================================================================
      53          12 : ClassImp(AliFMDParameters)
      54             : #if 0
      55             :   ; // This is here to keep Emacs for indenting the next line
      56             : #endif
      57             : 
      58             : //____________________________________________________________________
      59             : AliFMDParameters* AliFMDParameters::fgInstance = 0;
      60             : 
      61             : //____________________________________________________________________
      62             : const char* AliFMDParameters::fgkPulseGain          = "FMD/Calib/PulseGain";
      63             : const char* AliFMDParameters::fgkPedestal           = "FMD/Calib/Pedestal";
      64             : const char* AliFMDParameters::fgkDead               = "FMD/Calib/Dead";
      65             : const char* AliFMDParameters::fgkSampleRate         = "FMD/Calib/SampleRate";
      66             : const char* AliFMDParameters::fgkAltroMap           = "FMD/Calib/AltroMap";
      67             : const char* AliFMDParameters::fgkZeroSuppression    = "FMD/Calib/ZeroSuppression";
      68             : const char* AliFMDParameters::fgkStripRange         = "FMD/Calib/StripRange";
      69             : const char* AliFMDParameters::fkPedestalShuttleID   = "pedestals";
      70             : const char* AliFMDParameters::fkGainShuttleID       = "gains";
      71             : const char* AliFMDParameters::fkConditionsShuttleID = "conditions";
      72             : 
      73             : //____________________________________________________________________
      74             : AliFMDParameters* 
      75             : AliFMDParameters::Instance() 
      76             : {
      77             :   // 
      78             :   // Get static instance 
      79             :   //
      80     5489570 :   if (!fgInstance) fgInstance = new AliFMDParameters;
      81     2744782 :   return fgInstance;
      82           0 : }
      83             : 
      84             : //____________________________________________________________________
      85           3 : AliFMDParameters::AliFMDParameters() 
      86           3 :   : fIsInit(kFALSE),
      87           3 :     fkSiDeDxMip(1.664), 
      88           3 :     fVA1MipRange(0),
      89           3 :     fAltroChannelSize(0),
      90           3 :     fChannelsPerAltro(0),
      91           3 :     fPedestalFactor(0),
      92           3 :     fZSPre(1),
      93           3 :     fZSPost(1),
      94           3 :     fZSPedSubtract(kTRUE),
      95           3 :     fFixedPedestal(100),
      96           3 :     fFixedPedestalWidth(2),
      97           3 :     fFixedZeroSuppression(1),
      98           3 :     fFixedSampleRate(2),
      99           3 :     fFixedThreshold(0),
     100           3 :     fFixedMinStrip(0),
     101           3 :     fFixedMaxStrip(127),
     102           3 :     fFixedPulseGain(2), 
     103           3 :     fEdepMip(0),
     104           3 :     fHasCompleteHeader(kTRUE),
     105           3 :     fZeroSuppression(0), 
     106           3 :     fSampleRate(0), 
     107           3 :     fPedestal(0), 
     108           3 :     fPulseGain(0), 
     109           3 :     fDeadMap(0), 
     110           3 :     fAltroMap(0), 
     111           3 :   fStripRange(0),
     112           3 :   fRunNo(-1)
     113          15 : {
     114             :   //
     115             :   // Default constructor 
     116             :   //
     117           3 :   SetVA1MipRange();
     118           3 :   SetAltroChannelSize();
     119           3 :   SetChannelsPerAltro();
     120           3 :   SetZeroSuppression();
     121           3 :   SetSampleRate();
     122           3 :   SetPedestal();
     123           3 :   SetPedestalWidth();
     124           3 :   SetPedestalFactor();
     125           3 :   SetThreshold();
     126           3 :   SetStripRange();
     127           3 :   SetGain();
     128           9 :   fAltroMap = new AliFMDAltroMapping;
     129           3 :   fAltroMap->SetBit(TObject::kCanDelete);
     130           6 : }
     131             : 
     132             : //__________________________________________________________________
     133             : Bool_t
     134             : AliFMDParameters::CheckForNewRun()
     135             : {
     136          10 :   Int_t run = AliCDBManager::Instance()->GetRun();
     137           5 :   if (run != fRunNo) { 
     138           3 :     fIsInit = false;
     139           3 :     fRunNo = run;
     140           3 :   }
     141           5 :   return run != fRunNo;
     142             : }
     143             : 
     144             : //__________________________________________________________________
     145             : UShort_t
     146             : AliFMDParameters::Init(Bool_t forceReInit, UInt_t what)
     147             : {
     148             :   // 
     149             :   // Initialize the manager.  This tries to read the parameters from
     150             :   // CDB.  If that fails, the class uses the hard-coded parameters.
     151             :   // 
     152             :   // Parameters:
     153             :   //    forceReInit Force (re-)initalize flag
     154             :   //    what        What to initialize 
     155             :   //
     156           7 :   if (forceReInit) fIsInit = kFALSE;
     157           5 :   CheckForNewRun();
     158             : 
     159           7 :   if (fIsInit) return 0;
     160             : 
     161             :   UShort_t errMask = 0;
     162           6 :   if (what & kPulseGain)       errMask |= InitPulseGain();
     163           6 :   if (what & kPedestal)        errMask |= InitPedestal();
     164           6 :   if (what & kDeadMap)         errMask |= InitDeadMap();
     165           6 :   if (what & kSampleRate)      errMask |= InitSampleRate();
     166           6 :   if (what & kZeroSuppression) errMask |= InitZeroSuppression();
     167           6 :   if (what & kAltroMap)        errMask |= InitAltroMap();
     168           6 :   if (what & kStripRange)      errMask |= InitStripRange();
     169           3 :   fIsInit = kTRUE;
     170             : 
     171             :   return errMask;
     172           5 : }
     173             : //__________________________________________________________________
     174             : UShort_t
     175             : AliFMDParameters::Init(AliFMDPreprocessor* pp, Bool_t forceReInit, UInt_t what)
     176             : {
     177             :   // 
     178             :   // Initialize the manager.  This tries to read the parameters from
     179             :   // CDB.  If that fails, the class uses the hard-coded parameters.
     180             :   // 
     181             :   // Parameters:
     182             :   //    pp          Preprocessor 
     183             :   //    forceReInit Force (re-)initalize flag
     184             :   //    what        What to initialize 
     185             :   //
     186           0 :   if (forceReInit) fIsInit = kFALSE;
     187           0 :   CheckForNewRun();
     188             : 
     189           0 :   if (fIsInit) return 0;
     190             : 
     191             :   UShort_t errMask = 0;
     192           0 :   if (what & kPulseGain)       errMask |= InitPulseGain(pp);
     193           0 :   if (what & kPedestal)        errMask |= InitPedestal(pp);
     194           0 :   if (what & kDeadMap)         errMask |= InitDeadMap(pp);
     195           0 :   if (what & kSampleRate)      errMask |= InitSampleRate(pp);
     196           0 :   if (what & kZeroSuppression) errMask |= InitZeroSuppression(pp);
     197           0 :   if (what & kAltroMap)        errMask |= InitAltroMap(pp);
     198           0 :   if (what & kStripRange)      errMask |= InitStripRange(pp);
     199           0 :   fIsInit = kTRUE;
     200             : 
     201             :   return errMask;
     202           0 : }
     203             : 
     204             : //__________________________________________________________________
     205             : Bool_t
     206             : AliFMDParameters::CheckFile(const char* prefix, 
     207             :                             const char* path, 
     208             :                             int         number, 
     209             :                             TString&    f) const
     210             : {
     211             :   // 
     212             :   // Check if the file <i>prefix</i><i>number</i> exists in @a path, 
     213             :   // and write the full path to @a f.  
     214             :   // 
     215             :   // Parameters:
     216             :   //    prefix  File prefix (cond, peds, gains, ...)
     217             :   //    path    Path to files
     218             :   //    number  Detector number (1, 2, or 3)
     219             :   //    f       On return full path to file (if found)
     220             :   // 
     221             :   // Return:
     222             :   //    @c true if file exists and is readable, @c false otherwise
     223             :   //
     224           0 :   f = (Form("%s%d.csv", prefix, number));
     225           0 :   AliFMDDebug(5, ("Checking if %s exists in %s ...", f.Data(), path));
     226           0 :   f = gSystem->Which(path, f.Data());
     227           0 :   AliFMDDebug(5, ("Got back '%s'", f.Data()));
     228           0 :   return !f.IsNull();
     229             : }
     230             : 
     231             : //__________________________________________________________________
     232             : UShort_t
     233             : AliFMDParameters::Init(const char* path, Bool_t forceReInit, UInt_t what)
     234             : {
     235             :   // 
     236             :   // Initialize the manager.  This will try to read some calibrations
     237             :   // (sample rate, strip range, gains, pedestals) from local comma
     238             :   // separated value (CSV) files in the directory pointed at by @a
     239             :   // path.  If they are not found, then they will be retrieved from
     240             :   // OCDB as appropriately.   Other calibrations are always read from
     241             :   // OCDB.  
     242             :   // 
     243             :   // The CSV files should be named as 
     244             :   // 
     245             :   // - Pedestals: <tt>peds</tt><i>det_number</i><tt>.csv</tt>
     246             :   // - Gains: <tt>gains</tt><i>det_number</i><tt>.csv</tt>
     247             :   // - Sample Rate: <tt>conditions</tt><i>det_number</i><tt>.csv</tt>
     248             :   // - Strip Range: <tt>conditions</tt><i>det_number</i><tt>.csv</tt>
     249             :   //
     250             :   // where <i>det_number</i> is the detector number (1, 2, or 3). 
     251             :   // 
     252             :   // Parameters:
     253             :   //    path        Where to look for the CSV files
     254             :   //    forceReInit Always reinitialise 
     255             :   //    what        What calibrations to load. 
     256             :   //  
     257           0 :   if (forceReInit) fIsInit = kFALSE;
     258           0 :   CheckForNewRun();
     259             : 
     260           0 :   if (fIsInit) return 0;
     261             : 
     262             :   AliFMDCalibStripRange*  range = 0;
     263             :   AliFMDCalibSampleRate*  rate  = 0;
     264             :   AliFMDCalibPedestal*    peds  = 0;
     265             :   AliFMDCalibGain*        gains = 0;
     266             : 
     267           0 :   for (Int_t i = 1; i <= 3; i++) { 
     268           0 :     TString f;
     269           0 :     if (((what & kSampleRate) || (what & kStripRange)) && 
     270           0 :         CheckFile("conditions", path, i, f)) {
     271           0 :       if (!rate  && (what & kSampleRate)) rate  = new AliFMDCalibSampleRate;
     272           0 :       if (!range && (what & kStripRange)) range = new AliFMDCalibStripRange;
     273           0 :       std::ifstream in(f.Data());
     274           0 :       if (range) range->ReadFromFile(in);
     275           0 :       if (rate)  rate->ReadFromFile(in);
     276           0 :       in.close();
     277           0 :     }
     278           0 :     if ((what & kPedestal) && CheckFile("peds", path, i, f)) {
     279           0 :       if (!peds) peds  = new AliFMDCalibPedestal;
     280           0 :       std::ifstream in(f.Data());
     281           0 :       peds->ReadFromFile(in);
     282           0 :       in.close();
     283           0 :     }
     284           0 :     if ((what & kPulseGain) && CheckFile("gains", path, i, f)) { 
     285           0 :       if (!gains) gains = new AliFMDCalibGain;
     286           0 :       std::ifstream in(f.Data());
     287           0 :       gains->ReadFromFile(in);
     288           0 :       in.close();
     289           0 :     }
     290           0 :   }
     291             : 
     292           0 :   if (range) what &= ~kStripRange;
     293           0 :   if (rate)  what &= ~kSampleRate;
     294           0 :   if (peds)  what &= ~kPedestal;
     295           0 :   if (gains) what &= ~kPulseGain;
     296             : 
     297           0 :   UShort_t ret = Init(kFALSE, what);
     298             :   
     299           0 :   if (range) SetStripRange(range);
     300           0 :   if (rate)  SetSampleRate(rate);
     301           0 :   if (peds)  SetPedestal(peds);
     302           0 :   if (gains) SetGain(gains);
     303             : 
     304           0 :   fIsInit = kTRUE;
     305             : 
     306             :   return ret;
     307           0 : }
     308             : 
     309             : //__________________________________________________________________
     310             : void
     311             : AliFMDParameters::MakeDeadMap(Float_t maxNoise, 
     312             :                               Float_t minGain, 
     313             :                               Float_t maxGain)
     314             : {
     315             :   // 
     316             :   // Automatically generate a dead map from the pedestals and gains.
     317             :   // A channel is marked as dead of the noise is too high (currently
     318             :   // more than 10 ADC counts), or the gain is unreasonable (currently
     319             :   // larger than 10, or smaller than 0.1). 
     320             :   // 
     321             :   // The procedure does not overwrite channels previously marked as
     322             :   // dead - e.g., channels marked as dead in the calibration loaded
     323             :   // from OCDB will continue to be marked as dead.  That is, this
     324             :   // procedure will never make a channel un-dead. 
     325             :   // 
     326             :   // Parameters:
     327             :   //    maxNoise  Maximum noise value before a channel is marked
     328             :   // as dead. 
     329             :   //    minGain   Minimum value of the calibrated gain before a
     330             :   // channel is considered dead. 
     331             :   //    maxGain   Maximum value of the calibrated gain before a
     332             :   // channel is considered dead. 
     333             :   //
     334           0 :   if (fPedestal)  
     335           0 :     fDeadMap = fPedestal->MakeDeadMap(maxNoise, fDeadMap);
     336           0 :   if (fPulseGain) 
     337           0 :     fDeadMap = fPulseGain->MakeDeadMap(minGain, maxGain, fDeadMap);
     338           0 : }
     339             : //__________________________________________________________________
     340             : #define DET2IDX(det,ring,sec,str) \
     341             :   (det * 1000 + (ring == 'I' ? 0 : 512) + str)  
     342             :   
     343             : //__________________________________________________________________
     344             : void
     345             : AliFMDParameters::Draw(Option_t* option)
     346             : {
     347             :   // 
     348             :   // Draw parameters. 
     349             :   // 
     350             :   // Parameters:
     351             :   //    option What to draw. Should be one of 
     352             :   // - dead       Dead channels
     353             :   // - threshold Threshold
     354             :   // - gain       Gain
     355             :   // - pedestal  Pedestal
     356             :   // - noise      Noise (or pedestal width)
     357             :   // - zero       Zero suppression
     358             :   // - rate       Sampling rate (VA1 clock / ALTRO clock)
     359             :   // - min        Minimum strip read out
     360             :   // - max        Maximum strip read out
     361             :   // - map        hardware address
     362             :   //
     363           0 :   TString opt(option);
     364             :   enum {
     365             :     kLocalPulseGain,       // Path to PulseGain calib object
     366             :     kLocalThreshold,       // Path to PulseGain calib object
     367             :     kLocalPedestal,        // Path to Pedestal calib object
     368             :     kLocalPedestalWidth,   // Path to Pedestal calib object
     369             :     kLocalDead,            // Path to Dead calib object
     370             :     kLocalSampleRate,      // Path to SampleRate calib object
     371             :     kLocalAltroMap,        // Path to AltroMap calib object
     372             :     kLocalZeroSuppression, // Path to ZeroSuppression cal object
     373             :     kLocalMinStripRange,   // Path to strip range cal object
     374             :     kLocalMaxStripRange    // Path to strip range cal object
     375             :   } what;
     376             :     
     377           0 :   if      (opt.Contains("dead", TString::kIgnoreCase)) 
     378           0 :     what = kLocalDead;
     379           0 :   else if (opt.Contains("threshold",TString::kIgnoreCase)) 
     380           0 :     what = kLocalThreshold;
     381           0 :   else if (opt.Contains("gain",TString::kIgnoreCase)) 
     382           0 :     what = kLocalPulseGain;
     383           0 :   else if (opt.Contains("pedestal",TString::kIgnoreCase)) 
     384           0 :     what = kLocalPedestal;
     385           0 :   else if (opt.Contains("noise",TString::kIgnoreCase)) 
     386           0 :     what = kLocalPedestalWidth;
     387           0 :   else if (opt.Contains("zero",TString::kIgnoreCase)) 
     388           0 :     what = kLocalZeroSuppression;
     389           0 :   else if (opt.Contains("rate",TString::kIgnoreCase)) 
     390           0 :     what = kLocalSampleRate;
     391           0 :   else if (opt.Contains("min",TString::kIgnoreCase)) 
     392           0 :     what = kLocalMinStripRange;
     393           0 :   else if (opt.Contains("max",TString::kIgnoreCase)) 
     394           0 :     what = kLocalMaxStripRange;
     395           0 :   else if (opt.Contains("map",TString::kIgnoreCase)) 
     396             :     what = kLocalAltroMap;
     397             :   else {
     398           0 :     Warning("Draw", "unknown parameter: %s\n\tShould be one of\n\t"
     399             :             "dead, threshold, gain, pedestal, noise, zero, rate, "
     400             :             "min, max, map",  
     401             :             option); 
     402           0 :     return;
     403             :   }
     404             : 
     405           0 :   TArrayD xbins(3 * 512 + 2 * 256 + 5);
     406             :   Int_t i = 1;
     407             :   Bool_t skip = kTRUE;
     408           0 :   for (UShort_t det = 1; det <= 3; det++) {
     409           0 :     UShort_t nRings = (det == 1 ? 1 : 2);
     410           0 :     for (UShort_t iring = 0; iring < nRings; iring++) {
     411           0 :       UShort_t nStrip  = (iring == 0 ? 512 : 256);
     412           0 :       Char_t   ring    = (iring == 0 ? 'I' : 'O');
     413           0 :       for (UShort_t str = 0; str < nStrip; str++) {
     414             :         // UShort_t nSec    = (iring == 0 ? 20  : 40);
     415             :         // Char_t   ring    = (iring == 0 ? 'I' : 'O');
     416             :         // for (UShort_t sec = 0; sec < nSec; sec++) {
     417           0 :         Int_t idx = DET2IDX(det, ring, 0, str);
     418             :         // Int_t idx = DET2IDX(det, ring, sec, 0);
     419           0 :         if (skip) {
     420           0 :           xbins[i-1] = idx - .5;
     421             :           skip  = kFALSE;
     422           0 :         }
     423           0 :         xbins[i] = idx + .5;
     424           0 :         i++;
     425             :       }
     426             :       skip = kTRUE;
     427           0 :       i++;
     428             :     }
     429             :   }
     430           0 :   TArrayD ybins(41);
     431           0 :   for (/*Int_t*/ i = 0; i < ybins.fN; i++) ybins[i] = Float_t(i - .5);
     432           0 :   TH2D* hist = new TH2D("calib", Form("Calibration %s", option), 
     433           0 :                         xbins.fN-1, xbins.fArray,  
     434           0 :                         ybins.fN-1, ybins.fArray);
     435           0 :   hist->GetXaxis()->SetTitle("1000 #times detector + 512 #times ring + strip");
     436           0 :   hist->GetYaxis()->SetTitle("sector");
     437             :   
     438             :   // hist->Draw("Lego");
     439             :   // return;
     440             :   
     441           0 :   for (UShort_t det = 1; det <= 3; det++) {
     442           0 :     UShort_t nRings = (det == 1 ? 1 : 2);
     443           0 :     for (UShort_t iring = 0; iring < nRings; iring++) {
     444           0 :       UShort_t nSector = (iring == 0 ?  20 : 40);
     445           0 :       UShort_t nStrip  = (iring == 0 ? 512 : 256);
     446           0 :       Char_t   ring    = (iring == 0 ? 'I' : 'O');
     447           0 :       for (UShort_t sec = 0; sec < nSector; sec++) {
     448           0 :         for (UShort_t str = 0; str < nStrip; str++) {
     449           0 :           Int_t idx = DET2IDX(det, ring, sec, str);
     450           0 :           UShort_t ddl, addr, time, sam=0;
     451             :           Double_t val = 0;
     452           0 :           switch (what) {
     453             :           case kLocalPulseGain:       // Path to PulseGain calib object
     454           0 :             val = GetPulseGain(det,ring,sec,str); break;
     455             :           case kLocalThreshold:       // Path to PulseGain calib object
     456           0 :             val = GetThreshold(); break;
     457             :           case kLocalPedestal:        // Path to Pedestal calib object
     458           0 :             val = GetPedestal(det,ring,sec,str); break;
     459             :           case kLocalPedestalWidth:   // Path to Pedestal calib object
     460           0 :             val = GetPedestalWidth(det,ring,sec,str); break;
     461             :           case kLocalDead:            // Path to Dead calib object
     462           0 :             val = IsDead(det,ring,sec,str); break;
     463             :           case kLocalSampleRate:      // Path to SampleRate calib object
     464           0 :             val = GetSampleRate(det,ring,sec,str); break;
     465             :           case kLocalAltroMap:        // Path to AltroMap calib object
     466           0 :             Detector2Hardware(det,ring,sec,str,sam,ddl,addr,time); 
     467           0 :             val = addr; break;
     468             :           case kLocalZeroSuppression: // Path to ZeroSuppression cal object
     469           0 :             val = GetZeroSuppression(det,ring,sec,str); break;
     470             :           case kLocalMinStripRange:   // Path to strip range cal object
     471           0 :             val = GetMinStrip(det,ring,sec,str); break;
     472             :           case kLocalMaxStripRange:    // Path to strip range cal object
     473           0 :             val = GetMaxStrip(det,ring,sec,str); break;
     474             :           }
     475           0 :           hist->Fill(idx,sec,val);
     476             :           // hist->Fill(idx,str,val);
     477           0 :         }
     478             :       }
     479             :     }
     480             :   }
     481           0 :   hist->Draw("lego");
     482           0 : }
     483             : 
     484             : //__________________________________________________________________
     485             : void
     486             : AliFMDParameters::Print(Option_t* option) const
     487             : {
     488             :   // Print information. 
     489             :   // If option contains an 'A' then everything is printed. 
     490             :   // If the option contains the string "FMD" the function will search 
     491             :   // for detector, ring, sector, and strip numbers to print, in the
     492             :   // format 
     493             :   // 
     494             :   //    FMD<detector><ring>[<sector>,<string>] 
     495             :   // 
     496             :   // The wild card '*' means all of <detector>, <ring>, <sector>, or 
     497             :   // <strip>. 
     498           0 :   TString opt(option);
     499           0 :   Bool_t showStrips  = opt.Contains("a", TString::kIgnoreCase);
     500           0 :   UShort_t ds[]      = { 1, 2, 3, 0 };
     501           0 :   Char_t   rs[]      = { 'I', 'O', '\0' };
     502             :   UShort_t minStrip  = 0;
     503             :   UShort_t maxStrip  = 512;
     504             :   UShort_t minSector = 0;
     505             :   UShort_t maxSector = 40;
     506             :   
     507             :   
     508           0 :   if (opt.Contains("fmd",TString::kIgnoreCase)) {
     509           0 :     Int_t   i    = opt.Index("fmd",TString::kIgnoreCase);
     510           0 :     Int_t   j    = opt.Index("]",TString::kIgnoreCase);
     511           0 :     if (j != kNPOS)
     512           0 :       showStrips    = kTRUE;
     513             :     else 
     514           0 :       j = opt.Length();
     515             :     enum {
     516             :       kReadDet, 
     517             :       kReadRing, 
     518             :       kReadLbrack,
     519             :       kReadSector,
     520             :       kReadComma,
     521             :       kReadStrip,
     522             :       kReadRbrack, 
     523             :       kEnd
     524             :     } state = kReadDet;
     525           0 :     std::stringstream s(opt(i+4, j-i-3).Data());
     526           0 :     while (state != kEnd) {
     527           0 :       Char_t tmp = s.peek();
     528           0 :       if (tmp == ' ' || tmp == '\t') {
     529           0 :         s.get();
     530           0 :         continue;
     531             :       }
     532           0 :       switch (state) {
     533             :       case kReadDet: { // First, try to kRead the detector 
     534           0 :         if (tmp == '*') s.get();
     535             :         else { 
     536           0 :           UShort_t det;
     537           0 :           s >> det;
     538           0 :           if (!s.bad()) {
     539           0 :             ds[0] = det;
     540           0 :             ds[1] = 0;
     541           0 :           }
     542           0 :         }
     543           0 :         state = (s.bad() ? kEnd : kReadRing);
     544           0 :       } break;
     545             :       case kReadRing: { // Then try to read the ring;
     546           0 :         Char_t ring;
     547           0 :         s >> ring;
     548           0 :         if (ring != '*' && !s.bad()) {
     549           0 :           rs[0] = ring;
     550           0 :           rs[1] = '\0';
     551           0 :         }
     552           0 :         state = (s.bad() ? kEnd : kReadLbrack);
     553           0 :       } break;
     554             :       case kReadLbrack: { // Try to read a left bracket 
     555           0 :         Char_t lbrack;
     556           0 :         s >> lbrack;
     557           0 :         state = (s.bad() ? kEnd : kReadSector);
     558           0 :       } break;
     559             :       case kReadSector: { // Try to read a sector 
     560           0 :         if (tmp == '*') s.get();
     561             :         else {
     562           0 :           UShort_t sec;
     563           0 :           s >> sec;
     564           0 :           if (!s.bad()) {
     565           0 :             minSector = sec;
     566           0 :             maxSector = sec + 1;
     567           0 :           }
     568           0 :         }
     569           0 :         state = (s.bad() ? kEnd : kReadComma);
     570           0 :       } break;
     571             :       case kReadComma: { // Try to read a left bracket 
     572           0 :         Char_t comma;
     573           0 :         s >> comma;
     574           0 :         state = (s.bad() ? kEnd : kReadStrip);
     575           0 :       } break;
     576             :       case kReadStrip: { // Try to read a strip 
     577           0 :         if (tmp == '*') s.get();
     578             :         else {
     579           0 :           UShort_t str;
     580           0 :           s >> str;
     581           0 :           if (!s.bad()) {
     582           0 :             minStrip = str;
     583           0 :             maxStrip = str + 1;
     584           0 :           }
     585           0 :         }
     586           0 :         state = (s.bad() ? kEnd : kReadRbrack);
     587           0 :       } break;
     588             :       case kReadRbrack: { // Try to read a left bracket 
     589           0 :         Char_t rbrack;
     590           0 :         s >> rbrack;
     591             :         state = kEnd;
     592           0 :       } break;
     593             :       case kEnd: 
     594             :         break;
     595             :       }
     596           0 :     }
     597           0 :   }
     598           0 :   UShort_t* dp = ds;
     599             :   UShort_t  det;
     600           0 :   while ((det = *(dp++))) {
     601             : 
     602           0 :     Char_t* rp = rs;
     603             :     Char_t  ring;
     604           0 :     while ((ring = *(rp++))) {
     605           0 :       if (det == 1 && ring == 'O') continue;
     606           0 :       UShort_t min  = GetMinStrip(det, ring, 0, 0);
     607           0 :       UShort_t max  = GetMaxStrip(det, ring, 0, 0);
     608           0 :       std::cout << "FMD" << det << ring 
     609           0 :                 << "  Strip range: " 
     610           0 :                 << std::setw(3) << min << "," 
     611           0 :                 << std::setw(3) << max << std::endl;
     612             : 
     613           0 :       UShort_t nSec = ( ring == 'I' ? 20  :  40 );
     614           0 :       UShort_t nStr = ( ring == 'I' ? 512 : 256 );
     615           0 :       for (UShort_t sec = minSector; sec < maxSector && sec < nSec; sec++) {
     616             : 
     617           0 :         UShort_t rate = GetSampleRate(det, ring, sec, 0);
     618           0 :         std::cout << "FMD" << det << ring << "[" << std::setw(2) << sec 
     619           0 :                   << "] sample rate: " << rate << std::endl;
     620             : 
     621           0 :         if (!showStrips) continue;
     622             :         std::cout 
     623           0 :           << "  Strip |     Pedestal      |    Gain    | ZS thr. | Address\n" 
     624           0 :           << "--------+-------------------+------------+---------+---------" 
     625           0 :           << std::endl;
     626           0 :         for (UShort_t str = minStrip; str < nStr && str < maxStrip; str++) {
     627           0 :           if (str == minStrip) std::cout << std::setw(3) << sec << ",";
     628           0 :           else std::cout << "    ";
     629           0 :           std::cout << std::setw(3) << str << " | ";
     630           0 :           if (IsDead(det, ring, sec, str)) {
     631           0 :             std::cout << "dead" << std::endl;
     632             :             continue;
     633             :           }
     634           0 :           UShort_t ddl, addr, time, sam=0;
     635           0 :           Detector2Hardware(det, ring, sec, str, sam, ddl, addr, time);
     636           0 :           std::cout << std::setw(7) << GetPedestal(det, ring, sec, str) 
     637           0 :                     << "+/-" << std::setw(7) 
     638           0 :                     << GetPedestalWidth(det, ring, sec, str) 
     639           0 :                     << " | " << std::setw(10) 
     640           0 :                     << GetPulseGain(det, ring, sec, str) 
     641           0 :                     << " | " << std::setw(7) 
     642           0 :                     << GetZeroSuppression(det, ring, sec, str) 
     643           0 :                     << " | 0x" << std::hex << std::setw(4) 
     644           0 :                     << std::setfill('0') << ddl << ",0x" << std::setw(3) 
     645           0 :                     << addr << std::dec << std::setfill(' ') << std::endl;
     646           0 :         } // for (strip)
     647           0 :       } // for (sector)
     648             :       std::cout
     649           0 :         << "=============================================================" 
     650           0 :         << std::endl;
     651             :     } // while (ring)
     652             :   } // while (det)
     653             :   
     654           0 : }
     655             : 
     656             : //__________________________________________________________________
     657             : AliCDBEntry*
     658             : AliFMDParameters::GetEntry(const char* path, AliFMDPreprocessor* pp, 
     659             :                            Bool_t fatal) const
     660             : {
     661             :   // 
     662             :   // Get an entry from either global AliCDBManager or passed
     663             :   // AliFMDPreprocessor. 
     664             :   // 
     665             :   // Parameters:
     666             :   //    path  Path to CDB object. 
     667             :   //    pp    AliFMDPreprocessor 
     668             :   //    fatal If true, raise a fatal flag if we didn't get the entry.
     669             :   // Return:
     670             :   //    AliCDBEntry if found 
     671             :   // 
     672             :   AliCDBEntry* entry = 0;
     673          21 :   if (!pp) {
     674          21 :     AliCDBManager* cdb = AliCDBManager::Instance();
     675          42 :     entry              = cdb->Get(path);
     676          21 :   }
     677             :   else {
     678           0 :     const char* third  = gSystem->BaseName(path);
     679           0 :     const char* second = gSystem->BaseName(gSystem->DirName(path));
     680           0 :     entry              = pp->GetFromCDB(second, third);
     681             :   }
     682          21 :   if (!entry) { 
     683           0 :     TString msg(Form("No %s found in CDB, perhaps you need to "
     684             :                      "use AliFMDCalibFaker?", path));
     685           0 :     if (fatal) { AliFatal(msg.Data()); }
     686           0 :     else       AliLog::Message(AliLog::kWarning, msg.Data(), "FMD", 
     687             :                                "AliFMDParameters", "GetEntry", __FILE__, 
     688             :                                __LINE__);
     689             :     return 0;
     690           0 :   }
     691          42 :   if (entry && AliLog::GetDebugLevel("FMD", "") > 0) { 
     692           0 :     AliInfoF("Got entry %p for %s", entry, path);
     693           0 :     entry->PrintId();
     694           0 :     entry->PrintMetaData();                  
     695           0 :     entry->Print();
     696           0 :   }
     697          21 :   return entry;
     698          21 : }
     699             : 
     700             :     
     701             : //__________________________________________________________________
     702             : UShort_t
     703             : AliFMDParameters::InitPulseGain(AliFMDPreprocessor* pp)
     704             : {
     705             :   // 
     706             :   // Initialize gains.  Try to get them from CDB 
     707             :   // 
     708             :   // Parameters:
     709             :   //    pp Pre-processor if called from shuttle
     710             :   //
     711           6 :   AliCDBEntry*   gain     = GetEntry(fgkPulseGain, pp);
     712           3 :   if (!gain) return kPulseGain;
     713             :   
     714           6 :   AliFMDDebug(5, ("Got gain from CDB"));
     715           9 :   fPulseGain = dynamic_cast<AliFMDCalibGain*>(gain->GetObject());
     716           3 :   if (!fPulseGain) { 
     717           0 :     AliError("Invalid pulser gain object from CDB");
     718           0 :     return kPulseGain;
     719             :   }
     720           3 :   if (!fPulseGain->Values().Ptr()) {
     721           0 :     AliError("Empty pulser gain object from CDB");
     722           0 :     return kPulseGain;
     723             :   }
     724           3 :   return 0;
     725           3 : }
     726             : //__________________________________________________________________
     727             : UShort_t
     728             : AliFMDParameters::InitPedestal(AliFMDPreprocessor* pp)
     729             : {
     730             :   //
     731             :   // Initialize pedestals.  Try to get them from CDB
     732             :   // 
     733             :   // Parameters:
     734             :   //    pp Pre-processor if called from shuttle
     735             :   //
     736           6 :   AliCDBEntry*   pedestal = GetEntry(fgkPedestal, pp);
     737           3 :   if (!pedestal) return kPedestal;
     738             : 
     739           6 :   AliFMDDebug(5, ("Got pedestal from CDB"));
     740           9 :   fPedestal = dynamic_cast<AliFMDCalibPedestal*>(pedestal->GetObject());
     741           3 :   if (!fPedestal) {
     742           0 :     AliError("Invalid pedestal object from CDB");
     743           0 :     return kPedestal;
     744             :   }
     745           3 :   if (!fPedestal->Values().Ptr()) {
     746           0 :     AliError("Empty pedestal object from CDB");
     747           0 :     return kPedestal;
     748             :   }
     749           3 :   return 0;
     750           3 : }
     751             : 
     752             : //__________________________________________________________________
     753             : UShort_t
     754             : AliFMDParameters::InitDeadMap(AliFMDPreprocessor* pp)
     755             : {
     756             :   //
     757             :   // Initialize dead map.  Try to get it from CDB
     758             :   // 
     759             :   // Parameters:
     760             :   //    pp Pre-processor if called from shuttle
     761             :   //
     762           6 :   AliCDBEntry*   deadMap  = GetEntry(fgkDead, pp);
     763           3 :   if (!deadMap) return kDeadMap;
     764             :   
     765           6 :   AliFMDDebug(5, ("Got dead map from CDB"));
     766           9 :   fDeadMap = dynamic_cast<AliFMDCalibDeadMap*>(deadMap->GetObject());
     767           3 :   if (!fDeadMap) { 
     768           0 :     AliError("Invalid dead map object from CDB");
     769           0 :     return kDeadMap;
     770             :   }
     771           3 :   if (!fDeadMap->Ptr()) {
     772           0 :     AliError("Empty dead map object from CDB");
     773           0 :     return kDeadMap;
     774             :   }
     775           3 :   return 0;
     776           3 : }
     777             : 
     778             : //__________________________________________________________________
     779             : UShort_t
     780             : AliFMDParameters::InitZeroSuppression(AliFMDPreprocessor* pp)
     781             : {
     782             :   //
     783             :   // Initialize zero suppression thresholds.  Try to get them from CDB
     784             :   // 
     785             :   // Parameters:
     786             :   //    pp Pre-processor if called from shuttle
     787             :   //
     788           6 :   AliCDBEntry*   zeroSup  = GetEntry(fgkZeroSuppression, pp);
     789           3 :   if (!zeroSup) return kZeroSuppression;
     790             : 
     791           6 :   AliFMDDebug(5, ("Got zero suppression from CDB"));
     792           3 :   fZeroSuppression = 
     793           9 :     dynamic_cast<AliFMDCalibZeroSuppression*>(zeroSup->GetObject());
     794           3 :   if (!fZeroSuppression) {
     795           0 :     AliError("Invalid zero suppression object from CDB");
     796           0 :     return kZeroSuppression;
     797             :   }
     798           3 :   if (!fZeroSuppression->Ptr()) {
     799           0 :     AliWarningF("Empty zero suppression object from CDB, assuming %d",
     800             :                 fFixedZeroSuppression);
     801           0 :     AliCDBManager* cdbMan = AliCDBManager::Instance();
     802           0 :     if(!cdbMan || !cdbMan->GetCacheFlag())
     803           0 :       delete fZeroSuppression;
     804           0 :     fZeroSuppression = 0;
     805           0 :   }
     806           3 :   return 0;
     807           3 : }
     808             : 
     809             : //__________________________________________________________________
     810             : UShort_t
     811             : AliFMDParameters::InitSampleRate(AliFMDPreprocessor* pp)
     812             : {
     813             :   //
     814             :   // Initialize sample rates.  Try to get them from CDB
     815             :   // 
     816             :   // Parameters:
     817             :   //    pp Pre-processor if called from shuttle
     818             :   //
     819           6 :   AliCDBEntry*   sampRat  = GetEntry(fgkSampleRate, pp);
     820           3 :   if (!sampRat) return kSampleRate;
     821             : 
     822           6 :   AliFMDDebug(5, ("Got zero suppression from CDB"));
     823           9 :   fSampleRate = dynamic_cast<AliFMDCalibSampleRate*>(sampRat->GetObject());
     824           3 :   if (!fSampleRate) {
     825           0 :     AliError("Invalid sample rate object from CDB");
     826           0 :     return kSampleRate;
     827             :   }
     828           3 :   if (!fSampleRate->Rates().Ptr()) { 
     829           0 :     AliError("empty sample rate object from CDB");
     830           0 :     return kSampleRate;
     831             :   }
     832           3 :   return 0;
     833           3 : }
     834             : 
     835             : //__________________________________________________________________
     836             : UShort_t
     837             : AliFMDParameters::InitAltroMap(AliFMDPreprocessor* pp)
     838             : {
     839             :   //
     840             :   // Initialize hardware map.  Try to get it from CDB
     841             :   // 
     842             :   // Parameters:
     843             :   //    pp Pre-processor if called from shuttle
     844             :   //
     845           9 :   if (fAltroMap && fAltroMap->TestBit(TObject::kCanDelete)) {
     846             :     // Let's remove it from possible CDB manager cache
     847           3 :     AliCDBManager::Instance()->UnloadFromCache(fgkAltroMap);
     848           6 :     delete fAltroMap;
     849           3 :     fAltroMap = 0;
     850           3 :   }
     851           3 :   AliCDBEntry*   hwMap    = GetEntry(fgkAltroMap, pp, kFALSE);       
     852           6 :   if (hwMap && hwMap->GetObject()) {
     853           6 :     AliFMDDebug(5, ("Got ALTRO map from CDB"));
     854           9 :     fAltroMap = dynamic_cast<AliFMDAltroMapping*>(hwMap->GetObject());
     855           6 :     if (fAltroMap) fAltroMap->ResetBit(TObject::kCanDelete);
     856             :   }
     857           3 :   if (!fAltroMap) {
     858           0 :     AliError("Invalid ALTRO map object from CDB");
     859           0 :     fAltroMap = new AliFMDAltroMapping;
     860           0 :     fAltroMap->SetBit(TObject::kCanDelete);
     861             :     // return kAltroMap;
     862           0 :   }
     863           3 :   return 0;
     864           0 : }
     865             : 
     866             : //__________________________________________________________________
     867             : UShort_t
     868             : AliFMDParameters::InitStripRange(AliFMDPreprocessor* pp)
     869             : {
     870             :   //
     871             :   // Initialize strip range.  Try to get it from CDB
     872             :   // 
     873             :   // Parameters:
     874             :   //    pp Pre-processor if called from shuttle
     875             :   //
     876           6 :   AliCDBEntry*   range    = GetEntry(fgkStripRange, pp);
     877           3 :   if (!range) return kStripRange;
     878             : 
     879           6 :   AliFMDDebug(5, ("Got strip range from CDB"));
     880           9 :   fStripRange = dynamic_cast<AliFMDCalibStripRange*>(range->GetObject());
     881             : 
     882           3 :   if (!fStripRange) {
     883           0 :     AliError("Invalid strip range object from CDB");
     884           0 :     return kStripRange;
     885             :   }
     886           3 :   if (!fStripRange->Ranges().Ptr()) {
     887           0 :     AliError("Empty strip range object from CDB");
     888           0 :     return kStripRange;
     889             :   }
     890           3 :   return 0;
     891           3 : }
     892             : 
     893             : 
     894             : //__________________________________________________________________
     895             : Float_t
     896             : AliFMDParameters::GetThreshold() const
     897             : {
     898             :   // 
     899             :   // Get the threshold in the pulser gain 
     900             :   // 
     901             :   // 
     902             :   // Return:
     903             :   //    Threshold from pulser 
     904             :   //
     905           0 :   if (!fPulseGain) return fFixedThreshold;
     906           0 :   return fPulseGain->Threshold();
     907           0 : }
     908             : 
     909             : //__________________________________________________________________
     910             : Float_t
     911             : AliFMDParameters::GetPulseGain(UShort_t detector, Char_t ring, 
     912             :                                UShort_t sector, UShort_t strip) const
     913             : {
     914             :   // 
     915             :   // Gain of pre-amp. for strip, sector, ring, detector 
     916             :   //
     917             :   // For simulations this is normally set to 
     918             :   //
     919             :   // @f[ 
     920             :   //  \frac{\mbox{VA1_MIP_Range}{\mbox{ALTRO_channel_size}}\mbox{MIP_Energy_Loss}
     921             :   // @f]
     922             :   // 
     923             :   // 
     924             :   // Parameters:
     925             :   //    detector Detector # (1-3)
     926             :   //    ring     Ring ID ('I' or 'O')
     927             :   //    sector   Sector number (0-39)
     928             :   //    strip    Strip number (0-511)
     929             :   //
     930             :   // Return:
     931             :   //    Gain of pre-amp.  
     932             :   //
     933      980266 :   if (!fPulseGain) { 
     934           0 :     if (fFixedPulseGain <= 0)
     935           0 :       fFixedPulseGain = fVA1MipRange * GetEdepMip() / fAltroChannelSize;
     936           0 :     return fFixedPulseGain;
     937             :   }  
     938      980266 :   AliFMDDebug(50, ("pulse gain for FMD%d%c[%2d,%3d]=%f",
     939             :                     detector, ring, sector, strip,
     940             :                     fPulseGain->Value(detector, ring, sector, strip)));
     941      490133 :   return fPulseGain->Value(detector, ring, sector, strip);
     942      490133 : }
     943             : 
     944             : //__________________________________________________________________
     945             : Bool_t
     946             : AliFMDParameters::IsDead(UShort_t detector, Char_t ring, 
     947             :                          UShort_t sector, UShort_t strip) const
     948             : {
     949             :   // 
     950             :   // Whether the strip is considered dead
     951             :   // 
     952             :   // Parameters:
     953             :   //    detector Detector # (1-3)
     954             :   //    ring     Ring ID ('I' or 'O')
     955             :   //    sector   Sector number (0-39)
     956             :   //    strip    Strip number (0-511)
     957             :   //
     958             :   // Return:
     959             :   //    @c true if the strip is considered dead, @c false if it's
     960             :   // OK.
     961             :   //
     962     1638832 :   if (!fDeadMap) return kFALSE;
     963     1638832 :   AliFMDDebug(50, ("Dead for FMD%d%c[%2d,%3d]=%s",
     964             :                     detector, ring, sector, strip,
     965             :                     fDeadMap->operator()(detector, ring, sector, strip) ? 
     966             :                     "no" : "yes"));
     967      819416 :   return fDeadMap->operator()(detector, ring, sector, strip);
     968      819416 : }
     969             : 
     970             : //__________________________________________________________________
     971             : UShort_t
     972             : AliFMDParameters::GetZeroSuppression(UShort_t detector, Char_t ring, 
     973             :                                      UShort_t sector, UShort_t strip) const
     974             : {
     975             :   // 
     976             :   // zero suppression threshold (in ADC counts)
     977             :   // 
     978             :   // Parameters:
     979             :   //    detector Detector # (1-3)
     980             :   //    ring     Ring ID ('I' or 'O')
     981             :   //    sector   Sector number (0-39)
     982             :   //    strip    Strip number (0-511)
     983             :   //
     984             :   // Return:
     985             :   //    zero suppression threshold (in ADC counts) 
     986             :   //
     987      409600 :   if (!fZeroSuppression) return fFixedZeroSuppression;
     988             : 
     989             :   // In case of empty zero suppression objects. 
     990      409600 :   if (!fZeroSuppression->Ptr() || 
     991      204800 :       fZeroSuppression->MaxIndex() <= 0) return fFixedZeroSuppression;
     992             : 
     993             :   // Need to map strip to ALTRO chip. 
     994      409600 :   AliFMDDebug(50, ("zero sup. for FMD%d%c[%2d,%3d]=%d",
     995             :                     detector, ring, sector, strip,
     996             :                     fZeroSuppression->operator()(detector, ring, 
     997             :                                                  sector, strip)));
     998      204800 :   return fZeroSuppression->operator()(detector, ring, sector, strip/128);
     999      204800 : }
    1000             : 
    1001             : //__________________________________________________________________
    1002             : UShort_t
    1003             : AliFMDParameters::GetSampleRate(UShort_t det, Char_t ring, UShort_t sector, 
    1004             :                                 UShort_t str) const
    1005             : {
    1006             :   // 
    1007             :   // Get the sampling rate
    1008             :   // 
    1009             :   // Parameters:
    1010             :   //    detector Detector # (1-3)
    1011             :   //    ring     Ring ID ('I' or 'O')
    1012             :   //    sector   Sector number (0-39)
    1013             :   //    strip    Strip number (0-511)
    1014             :   //
    1015             :   // Return:
    1016             :   //    The sampling rate 
    1017             :   //
    1018     2867200 :   if (!fSampleRate) return fFixedSampleRate;
    1019             :   // Need to map sector to digitizier card. 
    1020     1433600 :   UInt_t ret = fSampleRate->Rate(det, ring, sector, str);
    1021     2867200 :   AliFMDDebug(50, ("Sample rate for FMD%d%c[%2d,%3d]=%d", 
    1022             :                     det, ring, sector, str, ret));
    1023     1433600 :   return ret;
    1024     1433600 : }
    1025             : 
    1026             : //__________________________________________________________________
    1027             : UShort_t
    1028             : AliFMDParameters::GetMinStrip(UShort_t det, Char_t ring, UShort_t sector, 
    1029             :                               UShort_t str) const
    1030             : {
    1031             :   // 
    1032             :   // Get the minimum strip in the read-out range
    1033             :   // 
    1034             :   // Parameters:
    1035             :   //    detector Detector # (1-3)
    1036             :   //    ring     Ring ID ('I' or 'O')
    1037             :   //    sector   Sector number (0-39)
    1038             :   //    strip    Strip number (0-511)
    1039             :   //
    1040             :   // Return:
    1041             :   //    Minimum strip 
    1042             :   //
    1043     1641600 :   if (!fStripRange) return fFixedMinStrip;
    1044             :   // Need to map sector to digitizier card. 
    1045      820800 :   UInt_t ret = fStripRange->Min(det, ring, sector, str);
    1046     1641600 :   AliFMDDebug(50, ("Min strip # for FMD%d%c[%2d,%3d]=%d", 
    1047             :                     det, ring, sector, str, ret));
    1048      820800 :   return ret;
    1049      820800 : }
    1050             : 
    1051             : //__________________________________________________________________
    1052             : UShort_t
    1053             : AliFMDParameters::GetMaxStrip(UShort_t det, Char_t ring, UShort_t sector, 
    1054             :                               UShort_t str) const
    1055             : {
    1056             :   // 
    1057             :   // Get the maximum strip in the read-out range
    1058             :   // 
    1059             :   // Parameters:
    1060             :   //    detector Detector # (1-3)
    1061             :   //    ring     Ring ID ('I' or 'O')
    1062             :   //    sector   Sector number (0-39)
    1063             :   //    strip    Strip number (0-511)
    1064             :   //
    1065             :   // Return:
    1066             :   //    Maximum strip 
    1067             :   //
    1068        3200 :   if (!fStripRange) return fFixedMaxStrip;
    1069             :   // Need to map sector to digitizier card. 
    1070        1600 :   UInt_t ret = fStripRange->Max(det, ring, sector, str);
    1071        3200 :   AliFMDDebug(50, ("Max strip # for FMD%d%c[%2d,%3d]=%d", 
    1072             :                     det, ring, sector, str, ret));
    1073        1600 :   return ret;
    1074        1600 : }
    1075             : 
    1076             : //__________________________________________________________________
    1077             : Float_t
    1078             : AliFMDParameters::GetPedestal(UShort_t detector, Char_t ring, 
    1079             :                               UShort_t sector, UShort_t strip) const
    1080             : {
    1081             :   // 
    1082             :   // Get mean of pedestal
    1083             :   // 
    1084             :   // Parameters:
    1085             :   //    detector Detector # (1-3)
    1086             :   //    ring     Ring ID ('I' or 'O')
    1087             :   //    sector   Sector number (0-39)
    1088             :   //    strip    Strip number (0-511)
    1089             :   //
    1090             :   // Return:
    1091             :   //    Mean of pedestal 
    1092             :   //
    1093     2867200 :   if (!fPedestal) return fFixedPedestal;
    1094     2867200 :   AliFMDDebug(50, ("pedestal for FMD%d%c[%2d,%3d]=%f",
    1095             :                     detector, ring, sector, strip,
    1096             :                     fPedestal->Value(detector, ring, sector, strip)));
    1097     1433600 :   return fPedestal->Value(detector, ring, sector, strip);
    1098     1433600 : }
    1099             : 
    1100             : //__________________________________________________________________
    1101             : Float_t
    1102             : AliFMDParameters::GetPedestalWidth(UShort_t detector, Char_t ring, 
    1103             :                                    UShort_t sector, UShort_t strip) const
    1104             : {
    1105             :   // 
    1106             :   // Width of pedestal
    1107             :   // 
    1108             :   // Parameters:
    1109             :   //    detector Detector # (1-3)
    1110             :   //    ring     Ring ID ('I' or 'O')
    1111             :   //    sector   Sector number (0-39)
    1112             :   //    strip    Strip number (0-511)
    1113             :   //
    1114             :   // Return:
    1115             :   //    Width of pedestal 
    1116             :   //
    1117     2867200 :   if (!fPedestal) return fFixedPedestalWidth;
    1118     2867200 :   AliFMDDebug(50, ("pedetal width for FMD%d%c[%2d,%3d]=%f",
    1119             :                     detector, ring, sector, strip,
    1120             :                     fPedestal->Width(detector, ring, sector, strip)));
    1121     1433600 :   return fPedestal->Width(detector, ring, sector, strip);
    1122     1433600 : }
    1123             :   
    1124             : //__________________________________________________________________
    1125             : AliFMDAltroMapping*
    1126             : AliFMDParameters::GetAltroMap() const
    1127             : {
    1128             :   // 
    1129             :   // Get the map that translates hardware to detector coordinates 
    1130             :   //
    1131             :   // Return:
    1132             :   //    Get the map that translates hardware to detector
    1133             :   // coordinates 
    1134             :   // 
    1135     1641656 :   return fAltroMap;
    1136             : }
    1137             : 
    1138             : 
    1139             : //____________________________________________________________________
    1140             : Bool_t 
    1141             : AliFMDParameters::Hardware2Detector(UShort_t  ddl,       UShort_t addr,
    1142             :                                     UShort_t  timebin,   
    1143             :                                     UShort_t& det,       Char_t&  ring, 
    1144             :                                     UShort_t& sec,       Short_t& str,
    1145             :                                     UShort_t& sam) const
    1146             : {
    1147             :   // 
    1148             :   // Map a hardware address into a detector index. 
    1149             :   // 
    1150             :   // Parameters:
    1151             :   //    ddl        Hardware DDL number 
    1152             :   //    addr       Hardware address.  
    1153             :   //    timebin    Timebin 
    1154             :   //    det        On return, the detector #
    1155             :   //    ring       On return, the ring ID
    1156             :   //    sec        On return, the sector #
    1157             :   //    str        On return, the base of strip #
    1158             :   //    sam        On return, the sample number for this strip
    1159             :   //
    1160             :   // Return:
    1161             :   //    @c true on success, false otherwise 
    1162             :   //
    1163           0 :   if (!fAltroMap) return kFALSE;
    1164           0 :   UShort_t board, chip, chan;
    1165           0 :   fAltroMap->ChannelAddress(addr, board, chip, chan);
    1166           0 :   return Hardware2Detector(ddl,board,chip,chan,timebin,det,ring,sec,str,sam);
    1167           0 : }
    1168             : //____________________________________________________________________
    1169             : Bool_t 
    1170             : AliFMDParameters::Hardware2Detector(UShort_t  ddl,       UShort_t   board,
    1171             :                                     UShort_t  chip,      UShort_t   chan,
    1172             :                                     UShort_t  timebin,   
    1173             :                                     UShort_t& det,       Char_t&   ring, 
    1174             :                                     UShort_t& sec,       Short_t& str,
    1175             :                                     UShort_t& sam) const
    1176             : {
    1177             :   // 
    1178             :   // Map a hardware address into a detector index. 
    1179             :   // 
    1180             :   // Parameters:
    1181             :   //    ddl        Hardware DDL number 
    1182             :   //    board      FEC number
    1183             :   //    altro      ALTRO number 
    1184             :   //    channel    Channel number 
    1185             :   //    timebin    Timebin 
    1186             :   //    det        On return, the detector #
    1187             :   //    ring       On return, the ring ID
    1188             :   //    sec        On return, the sector #
    1189             :   //    str        On return, the base of strip #
    1190             :   //    sam        On return, the sample number for this strip
    1191             :   //
    1192             :   // Return:
    1193             :   //    @c true on success, false otherwise 
    1194             :   //
    1195           0 :   if (!fAltroMap) {
    1196           0 :     AliFMDDebug(1, ("No ALTRO map available"));
    1197           0 :     return kFALSE;
    1198             :   }
    1199           0 :   if (fAltroMap->DDL2Detector(ddl) < 0) { 
    1200           0 :     AliFMDDebug(1, ("Invalid DDL number %d", ddl));
    1201           0 :     return kFALSE;
    1202             :   }
    1203           0 :   det = fAltroMap->DDL2Detector(ddl);
    1204           0 :   Short_t stripBase = 0;
    1205           0 :   if (!fAltroMap->Channel2StripBase(board,chip,chan, ring, sec, stripBase)) {
    1206           0 :     AliFMDDebug(1, ("Failed to translate  "
    1207             :                     "%d/0x%02x/0x%x/0x%x/%04d -> "
    1208             :                     "FMD%d%c[%2d,%3d] to detector", 
    1209             :                     ddl, board, chip, chan, timebin, 
    1210             :                     det, ring, sec, stripBase));
    1211           0 :     return kFALSE;
    1212             :   }
    1213           0 :   UShort_t preSamples = GetPreSamples(det, ring, sec, stripBase);
    1214           0 :   UShort_t sampleRate = GetSampleRate(det, ring, sec, stripBase);
    1215           0 :   Short_t stripOff = 0;
    1216           0 :   fAltroMap->Timebin2Strip(sec, timebin, preSamples, sampleRate, stripOff, sam);
    1217           0 :   str = stripBase + stripOff;
    1218           0 :   AliFMDDebug(50, ("%d/0x%02x/0x%x/0x%x/%04d -> FMD%d%c[%02d,%03d]-%d"
    1219             :                   " (pre=%2d, rate=%d)", 
    1220             :                    ddl, board, chip, chan, timebin, 
    1221             :                    det, ring, sec, str, sam, preSamples, sampleRate));
    1222             :   return kTRUE;
    1223           0 : }
    1224             : 
    1225             : 
    1226             : //____________________________________________________________________
    1227             : Bool_t 
    1228             : AliFMDParameters::Detector2Hardware(UShort_t  det,        Char_t    ring, 
    1229             :                                     UShort_t  sec,        UShort_t  str,
    1230             :                                     UShort_t  sam, 
    1231             :                                     UShort_t& ddl,        UShort_t& board, 
    1232             :                                     UShort_t& altro,      UShort_t& channel, 
    1233             :                                     UShort_t& timebin) const
    1234             : {
    1235             :   // 
    1236             :   // Map a detector index into a hardware address. 
    1237             :   // 
    1238             :   // Parameters:
    1239             :   //    det         The detector #
    1240             :   //    ring        The ring ID
    1241             :   //    sec         The sector #
    1242             :   //    str         The strip #
    1243             :   //    sam         The sample number 
    1244             :   //    ddl         On return, hardware DDL number 
    1245             :   //    board       On return, the FEC board address (local to DDL)
    1246             :   //    altro       On return, the ALTRO number (local to FEC)
    1247             :   //    channel     On return, the channel number (local to ALTRO)
    1248             :   //    timebin     On return, the timebin number (local to ALTRO)
    1249             :   //
    1250             :   // Return:
    1251             :   //    @c true on success, false otherwise 
    1252             :   //
    1253           0 :   if (!fAltroMap) { 
    1254           0 :     AliFMDDebug(1, ("No ALTRO map available"));
    1255           0 :     return kFALSE;
    1256             :   }
    1257           0 :   UShort_t preSamples = GetPreSamples(det, ring, sec, str);
    1258           0 :   UShort_t sampleRate = GetSampleRate(det, ring, sec, str);
    1259           0 :   UShort_t strip      = str - GetMinStrip(det,ring,sec,str);
    1260           0 :   return fAltroMap->Detector2Hardware(det, ring, sec, strip, sam,
    1261             :                                       preSamples, sampleRate,
    1262             :                                       ddl, board, altro, channel, timebin);
    1263           0 : }
    1264             : 
    1265             :   
    1266             : 
    1267             : //____________________________________________________________________
    1268             : Bool_t 
    1269             : AliFMDParameters::Detector2Hardware(UShort_t  det,        Char_t    ring, 
    1270             :                                     UShort_t  sec,        UShort_t  str,
    1271             :                                     UShort_t  sam, 
    1272             :                                     UShort_t&   ddl,        UShort_t&   addr,
    1273             :                                     UShort_t& timebin) const
    1274             : {
    1275             :   // 
    1276             :   // Map a detector index into a hardware address. 
    1277             :   // 
    1278             :   // Parameters:
    1279             :   //    det         The detector #
    1280             :   //    ring        The ring ID
    1281             :   //    sec         The sector #
    1282             :   //    str         The strip #
    1283             :   //    sam         The sample number 
    1284             :   //    ddl         On return, hardware DDL number 
    1285             :   //    addr      On return, hardware address.  
    1286             :   //    timebin     On return, the timebin number (local to ALTRO)
    1287             :   //
    1288             :   // Return:
    1289             :   //    @c true on success, false otherwise 
    1290             :   //
    1291     1638400 :   if (!fAltroMap) return kFALSE;
    1292      819200 :   UShort_t preSamples = GetPreSamples(det, ring, sec, str);
    1293      819200 :   UShort_t sampleRate = GetSampleRate(det, ring, sec, str);
    1294      819200 :   UShort_t strip      = str - GetMinStrip(det,ring,sec,str);
    1295      819200 :   return fAltroMap->Detector2Hardware(det, ring, sec, strip, sam,
    1296             :                                       preSamples, sampleRate,
    1297             :                                       ddl, addr, timebin);
    1298      819200 : }
    1299             : 
    1300             : 
    1301             : //__________________________________________________________________
    1302             : Float_t
    1303             : AliFMDParameters::GetEdepMip() const 
    1304             : { 
    1305             :   // 
    1306             :   // Return:
    1307             :   //    The average energy deposited by one MIP 
    1308             :   //
    1309     1799466 :   if (fEdepMip <= 0){
    1310           3 :     AliFMDGeometry* fmd = AliFMDGeometry::Instance();
    1311           6 :     fEdepMip = (fkSiDeDxMip 
    1312           3 :                 * fmd->GetRing('I')->GetSiThickness() 
    1313           3 :                 * fmd->GetSiDensity());
    1314           3 :   }
    1315      899733 :   return fEdepMip;
    1316             : }
    1317             : //____________________________________________________________________
    1318             : Float_t  
    1319             : AliFMDParameters::GetDACPerMIP() const
    1320             : {
    1321             :   // 
    1322             :   // This is the conversion from Digital-to-Analog-Converter setting
    1323             :   // to the number of MIPs. The number was measured in the NBI lab during
    1324             :   // August 2008.
    1325             :   //
    1326             :   // Return:
    1327             :   //    The conversion factor from DAC to ADC 
    1328             :   //
    1329      980266 :   return 29.67;
    1330             :   
    1331             : }
    1332             :  
    1333             : //____________________________________________________________________
    1334             : //
    1335             : // EOF
    1336             : //

Generated by: LCOV version 1.11