]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDParameters.cxx
Realisation of VEventHandler for input events.
[u/mrichter/AliRoot.git] / FMD / AliFMDParameters.cxx
index 546f20c181e559c1055a6cf741a94fcaa7975201..6ff951ab7c356edad12788fae62da5c88887b9b6 100644 (file)
@@ -29,7 +29,7 @@
 // `Init'.  Optionally, the class can serve hard-coded constants, if
 // no CDB is available. 
 //                                                       
-#include "AliLog.h"               // ALILOG_H
+#include "AliFMDDebug.h"                  // ALILOG_H
 #include "AliFMDParameters.h"     // ALIFMDPARAMETERS_H
 #include "AliFMDGeometry.h"       // ALIFMDGEOMETRY_H
 #include "AliFMDRing.h"                   // ALIFMDRING_H
@@ -77,6 +77,17 @@ AliFMDParameters::Instance()
 AliFMDParameters::AliFMDParameters() 
   : fIsInit(kFALSE),
     fkSiDeDxMip(1.664), 
+    fVA1MipRange(0),
+    fAltroChannelSize(0),
+    fChannelsPerAltro(0),
+    fPedestalFactor(0),
+    fFixedPedestal(0),
+    fFixedPedestalWidth(0),
+    fFixedZeroSuppression(0),
+    fFixedSampleRate(0),
+    fFixedThreshold(0),
+    fFixedMinStrip(0),
+    fFixedMaxStrip(0),
     fFixedPulseGain(0), 
     fEdepMip(0),
     fZeroSuppression(0), 
@@ -102,10 +113,11 @@ AliFMDParameters::AliFMDParameters()
 
 //__________________________________________________________________
 void
-AliFMDParameters::Init()
+AliFMDParameters::Init(Bool_t forceReInit)
 {
   // Initialize the parameters manager.  We need to get stuff from the
   // CDB here. 
+  if (forceReInit) fIsInit = kFALSE;
   if (fIsInit) return;
   InitPulseGain();
   InitPedestal();
@@ -119,7 +131,7 @@ AliFMDParameters::Init()
 
 //__________________________________________________________________
 #define DET2IDX(det,ring,sec,str) \
-  (det * 10000 + (ring == 'I' ? 0 : 1000) + str)  
+  (det * 1000 + (ring == 'I' ? 0 : 512) + str)  
   
 //__________________________________________________________________
 void
@@ -177,7 +189,11 @@ AliFMDParameters::Draw(Option_t* option)
       UShort_t nStrip  = (iring == 0 ? 512 : 256);
       Char_t   ring    = (iring == 0 ? 'I' : 'O');
       for (UShort_t str = 0; str < nStrip; str++) {
+       // UShort_t nSec    = (iring == 0 ? 20  : 40);
+       // Char_t   ring    = (iring == 0 ? 'I' : 'O');
+       // for (UShort_t sec = 0; sec < nSec; sec++) {
        Int_t idx = DET2IDX(det, ring, 0, str);
+       // Int_t idx = DET2IDX(det, ring, sec, 0);
        if (skip) {
          xbins[i-1] = idx - .5;
          skip  = kFALSE;
@@ -190,11 +206,13 @@ AliFMDParameters::Draw(Option_t* option)
     }
   }
   TArrayD ybins(41);
-  for (Int_t i = 0; i < 41; i++) ybins[i] = Float_t(i - .5);
+  for (Int_t i = 0; i < ybins.fN; i++) ybins[i] = Float_t(i - .5);
   TH2D* hist = new TH2D("calib", Form("Calibration %s", option), 
                        xbins.fN-1, xbins.fArray,  
                        ybins.fN-1, ybins.fArray);
-
+  hist->GetXaxis()->SetTitle("1000 #times detector + 512 #times ring + strip");
+  hist->GetYaxis()->SetTitle("sector");
+  
   // hist->Draw("Lego");
   // return;
   
@@ -233,6 +251,7 @@ AliFMDParameters::Draw(Option_t* option)
             val = GetMaxStrip(det,ring,sec,str); break;
          }
          hist->Fill(idx,sec,val);
+         // hist->Fill(idx,str,val);
        }
       }
     }
@@ -246,76 +265,164 @@ AliFMDParameters::Print(Option_t* option) const
 {
   // Print information. 
   // If option contains an 'A' then everything is printed. 
+  // If the option contains the string "FMD" the function will search 
+  // for detector, ring, sector, and strip numbers to print, in the
+  // format 
+  // 
+  //    FMD<detector><ring>[<sector>,<string>] 
+  // 
+  // The wild card '*' means all of <detector>, <ring>, <sector>, or 
+  // <strip>. 
   TString opt(option);
-  Bool_t showStrips = opt.Contains("a", TString::kIgnoreCase);
+  Bool_t showStrips  = opt.Contains("a", TString::kIgnoreCase);
+  UShort_t ds[]      = { 1, 2, 3, 0 };
+  Char_t   rs[]      = { 'I', 'O', '\0' };
+  UShort_t minStrip  = 0;
+  UShort_t maxStrip  = 512;
+  UShort_t minSector = 0;
+  UShort_t maxSector = 40;
+  
+  
   if (opt.Contains("fmd",TString::kIgnoreCase)) {
-    size_t   i   = opt.Index("fmd",TString::kIgnoreCase);
-    size_t   j   = opt.Index("]",TString::kIgnoreCase);
-    UShort_t det, sec, str;
-    Char_t ring, lbrack, rbrack, comma;
-    UInt_t ddl, addr;
-    Detector2Hardware(det, ring, sec, str, ddl, addr);
+    showStrips    = kTRUE;
+    size_t   i    = opt.Index("fmd",TString::kIgnoreCase);
+    size_t   j    = opt.Index("]",TString::kIgnoreCase);
+    enum {
+      kReadDet, 
+      kReadRing, 
+      kReadLbrack,
+      kReadSector,
+      kReadComma,
+      kReadStrip,
+      kReadRbrack, 
+      kEnd
+    } state = kReadDet;
     std::stringstream s(opt(i+4, j-i-3).Data());
-    s >> det >> ring >> lbrack >> sec >> comma >> str >> rbrack;
-    std::cout 
-      << "     Strip    |     Pedestal      |    Gain    | ZS thr. | Address\n"
-      << "--------------+-------------------+------------+---------+---------" 
-      << "\nFMD" << det << ring << "[" << std::setw(2) << sec << "," 
-      << std::setw(3) << str << "] | " 
-      << std::setw(7) << GetPedestal(det, ring, sec, str) 
-      << "+/-" << std::setw(7) 
-      << GetPedestalWidth(det, ring, sec, str) 
-      << " | " << std::setw(10) 
-      << GetPulseGain(det, ring, sec, str) 
-      << " | " << std::setw(7) 
-      << GetZeroSuppression(det, ring, sec, str) 
-      << " | 0x" << std::hex << std::setw(4) 
-      << std::setfill('0') << ddl << ",0x" << std::setw(3) 
-      << addr << std::dec << std::setfill(' ') << std::endl;
-    return;
+    while (state != kEnd) {
+      Char_t tmp = s.peek();
+      if (tmp == ' ' || tmp == '\t') {
+       s.get();
+       continue;
+      }
+      switch (state) {
+      case kReadDet: { // First, try to kRead the detector 
+       if (tmp == '*') s.get();
+       else { 
+         UShort_t det;
+         s >> det;
+         if (!s.bad()) {
+           ds[0] = det;
+           ds[1] = 0;
+         }
+       }
+       state = (s.bad() ? kEnd : kReadRing);
+      } break;
+      case kReadRing: { // Then try to read the ring;
+       Char_t ring;
+       s >> ring;
+       if (ring != '*' && !s.bad()) {
+         rs[0] = ring;
+         rs[1] = '\0';
+       }
+       state = (s.bad() ? kEnd : kReadLbrack);
+      } break;
+      case kReadLbrack: { // Try to read a left bracket 
+       Char_t lbrack;
+       s >> lbrack;
+       state = (s.bad() ? kEnd : kReadSector);
+      } break;
+      case kReadSector: { // Try to read a sector 
+       if (tmp == '*') s.get();
+       else {
+         UShort_t sec;
+         s >> sec;
+         if (!s.bad()) {
+           minSector = sec;
+           maxSector = sec + 1;
+         }
+       }
+       state = (s.bad() ? kEnd : kReadComma);
+      } break;
+      case kReadComma: { // Try to read a left bracket 
+       Char_t comma;
+       s >> comma;
+       state = (s.bad() ? kEnd : kReadStrip);
+      } break;
+      case kReadStrip: { // Try to read a strip 
+       if (tmp == '*') s.get();
+       else {
+         UShort_t str;
+         s >> str;
+         if (!s.bad()) {
+           minStrip = str;
+           maxStrip = str + 1;
+         }
+       }
+       state = (s.bad() ? kEnd : kReadRbrack);
+      } break;
+      case kReadRbrack: { // Try to read a left bracket 
+       Char_t rbrack;
+       s >> rbrack;
+       state = kEnd;
+      } break;
+      case kEnd: 
+       break;
+      }
+    }
   }
-  for (UShort_t det=1 ; det <= 3; det++) {
-    std::cout << "FMD" << det << std::endl;
-    Char_t rings[] = { 'I', (det == 1 ? '\0' : 'O'), '\0' };
-    for (Char_t* ring = rings; *ring != '\0'; ring++) {
-      std::cout << " Ring " << *ring << std::endl;
-      UShort_t nSec = ( *ring == 'I' ? 20  :  40 );
-      UShort_t nStr = ( *ring == 'I' ? 512 : 256 );
-      for (UShort_t sec = 0; sec < nSec; sec++) {
-       UShort_t min  = GetMinStrip(det, *ring, sec, 0);
-       UShort_t max  = GetMaxStrip(det, *ring, sec, 0);
-       UShort_t rate = GetSampleRate(det, *ring, sec, 0);
-       std::cout << "  Sector " << std::setw(2) << sec 
-                 << "  Strip range: " << std::setw(3) << min << "," 
-                 << std::setw(3) << max << "  Rate: " << std::setw(2) 
-                 << rate << std::endl;
-       if (!showStrips) continue;
+  UShort_t* dp = ds;
+  UShort_t  det;
+  while ((det = *(dp++))) {
+
+    Char_t* rp = rs;
+    Char_t  ring;
+    while ((ring = *(rp++))) {
+      if (det == 1 && ring == 'O') continue;
+      UShort_t min  = GetMinStrip(det, ring, 0, 0);
+      UShort_t max  = GetMaxStrip(det, ring, 0, 0);
+      UShort_t rate = GetSampleRate(det, ring, 0, 0);
+      std::cout << "FMD" << det << ring 
+               << "  Strip range: " 
+               << std::setw(3) << min << "," 
+               << std::setw(3) << max << "  Rate: " 
+               << std::setw(2) << rate << std::endl;
+
+      if (!showStrips) continue;
+      UShort_t nSec = ( ring == 'I' ? 20  :  40 );
+      UShort_t nStr = ( ring == 'I' ? 512 : 256 );
+      for (UShort_t sec = minSector; sec < maxSector && sec < nSec; sec++) {
        std::cout 
          << "  Strip |     Pedestal      |    Gain    | ZS thr. | Address\n" 
          << "--------+-------------------+------------+---------+---------" 
          << std::endl;
-        for (UShort_t str = 0; str < nStr; str++) {
-         std::cout << "    " << std::setw(3) << str << " | ";
-         if (IsDead(det, *ring, sec, str)) {
+        for (UShort_t str = minStrip; str < nStr && str < maxStrip; str++) {
+         if (str == minStrip) std::cout << std::setw(3) << sec << ",";
+         else std::cout << "    ";
+         std::cout << std::setw(3) << str << " | ";
+         if (IsDead(det, ring, sec, str)) {
            std::cout << "dead" << std::endl;
            continue;
          }
          UInt_t ddl, addr;
-         Detector2Hardware(det, *ring, sec, str, ddl, addr);
-         std::cout << std::setw(7) << GetPedestal(det, *ring, sec, str) 
+         Detector2Hardware(det, ring, sec, str, ddl, addr);
+         std::cout << std::setw(7) << GetPedestal(det, ring, sec, str) 
                    << "+/-" << std::setw(7) 
-                   << GetPedestalWidth(det, *ring, sec, str) 
+                   << GetPedestalWidth(det, ring, sec, str) 
                    << " | " << std::setw(10) 
-                   << GetPulseGain(det, *ring, sec, str) 
-                   << " | " << std::setw(5
-                   << GetZeroSuppression(det, *ring, sec, str) 
+                   << GetPulseGain(det, ring, sec, str) 
+                   << " | " << std::setw(7
+                   << GetZeroSuppression(det, ring, sec, str) 
                    << " | 0x" << std::hex << std::setw(4) 
                    << std::setfill('0') << ddl << ",0x" << std::setw(3) 
                    << addr << std::dec << std::setfill(' ') << std::endl;
-        }
-      }
-    }
-  }
+        } // for (strip)
+      } // for (sector)
+      std::cout
+       << "=============================================================" 
+       << std::endl;
+    } // while (ring)
+  } // while (det)
+  
 }
 
 //__________________________________________________________________
@@ -335,14 +442,14 @@ AliFMDParameters::InitPulseGain()
   AliCDBManager* cdb      = AliCDBManager::Instance();
   AliCDBEntry*   gain     = cdb->Get(fgkPulseGain);
   if (!gain) {
-    AliWarning(Form("No %s found in CDB, perhaps you need to "
+    AliFatal(Form("No %s found in CDB, perhaps you need to "
                    "use AliFMDCalibFaker?", fgkPulseGain));
     return;
   }
   
-  AliDebug(1, Form("Got gain from CDB"));
+  AliFMDDebug(1, ("Got gain from CDB"));
   fPulseGain = dynamic_cast<AliFMDCalibGain*>(gain->GetObject());
-  if (!fPulseGain) AliWarning("Invalid pulser gain object from CDB");
+  if (!fPulseGain) AliFatal("Invalid pulser gain object from CDB");
 }
 //__________________________________________________________________
 void
@@ -352,13 +459,13 @@ AliFMDParameters::InitPedestal()
   AliCDBManager* cdb      = AliCDBManager::Instance();
   AliCDBEntry*   pedestal = cdb->Get(fgkPedestal);
   if (!pedestal) {
-    AliWarning(Form("No %s found in CDB, perhaps you need to "
+    AliFatal(Form("No %s found in CDB, perhaps you need to "
                    "use AliFMDCalibFaker?", fgkPedestal));
     return;
   }
-  AliDebug(1, Form("Got pedestal from CDB"));
+  AliFMDDebug(1, ("Got pedestal from CDB"));
   fPedestal = dynamic_cast<AliFMDCalibPedestal*>(pedestal->GetObject());
-  if (!fPedestal) AliWarning("Invalid pedestal object from CDB");
+  if (!fPedestal) AliFatal("Invalid pedestal object from CDB");
 }
 
 //__________________________________________________________________
@@ -369,13 +476,13 @@ AliFMDParameters::InitDeadMap()
   AliCDBManager* cdb      = AliCDBManager::Instance();
   AliCDBEntry*   deadMap  = cdb->Get(fgkDead);
   if (!deadMap) {
-    AliWarning(Form("No %s found in CDB, perhaps you need to "
+    AliFatal(Form("No %s found in CDB, perhaps you need to "
                    "use AliFMDCalibFaker?", fgkDead));
     return;
   }
-  AliDebug(1, Form("Got dead map from CDB"));
+  AliFMDDebug(1, ("Got dead map from CDB"));
   fDeadMap = dynamic_cast<AliFMDCalibDeadMap*>(deadMap->GetObject());
-  if (!fDeadMap) AliWarning("Invalid dead map object from CDB");
+  if (!fDeadMap) AliFatal("Invalid dead map object from CDB");
 }
 
 //__________________________________________________________________
@@ -386,14 +493,14 @@ AliFMDParameters::InitZeroSuppression()
   AliCDBManager* cdb      = AliCDBManager::Instance();
   AliCDBEntry*   zeroSup  = cdb->Get(fgkZeroSuppression);
   if (!zeroSup) {
-    AliWarning(Form("No %s found in CDB, perhaps you need to "
+    AliFatal(Form("No %s found in CDB, perhaps you need to "
                    "use AliFMDCalibFaker?", fgkZeroSuppression));
     return;
   }
-  AliDebug(1, Form("Got zero suppression from CDB"));
+  AliFMDDebug(1, ("Got zero suppression from CDB"));
   fZeroSuppression = 
     dynamic_cast<AliFMDCalibZeroSuppression*>(zeroSup->GetObject());
-  if (!fZeroSuppression)AliWarning("Invalid zero suppression object from CDB");
+  if (!fZeroSuppression)AliFatal("Invalid zero suppression object from CDB");
 }
 
 //__________________________________________________________________
@@ -404,13 +511,13 @@ AliFMDParameters::InitSampleRate()
   AliCDBManager* cdb      = AliCDBManager::Instance();
   AliCDBEntry*   sampRat  = cdb->Get(fgkSampleRate);
   if (!sampRat) {
-    AliWarning(Form("No %s found in CDB, perhaps you need to "
+    AliFatal(Form("No %s found in CDB, perhaps you need to "
                    "use AliFMDCalibFaker?", fgkSampleRate));
     return;
   }
-  AliDebug(1, Form("Got zero suppression from CDB"));
+  AliFMDDebug(1, ("Got zero suppression from CDB"));
   fSampleRate = dynamic_cast<AliFMDCalibSampleRate*>(sampRat->GetObject());
-  if (!fSampleRate) AliWarning("Invalid zero suppression object from CDB");
+  if (!fSampleRate) AliFatal("Invalid zero suppression object from CDB");
 }
 
 //__________________________________________________________________
@@ -421,15 +528,15 @@ AliFMDParameters::InitAltroMap()
   AliCDBManager* cdb      = AliCDBManager::Instance();
   AliCDBEntry*   hwMap    = cdb->Get(fgkAltroMap);       
   if (!hwMap) {
-    AliWarning(Form("No %s found in CDB, perhaps you need to "
+    AliFatal(Form("No %s found in CDB, perhaps you need to "
                    "use AliFMDCalibFaker?", fgkAltroMap));
     fAltroMap = new AliFMDAltroMapping;
     return;
   }
-  AliDebug(1, Form("Got ALTRO map from CDB"));
+  AliFMDDebug(1, ("Got ALTRO map from CDB"));
   fAltroMap = dynamic_cast<AliFMDAltroMapping*>(hwMap->GetObject());
   if (!fAltroMap) {
-    AliWarning("Invalid ALTRO map object from CDB");
+    AliFatal("Invalid ALTRO map object from CDB");
     fAltroMap = new AliFMDAltroMapping;
   }
 }
@@ -442,13 +549,13 @@ AliFMDParameters::InitStripRange()
   AliCDBManager* cdb      = AliCDBManager::Instance();
   AliCDBEntry*   range    = cdb->Get(fgkStripRange);
   if (!range) {
-    AliWarning(Form("No %s found in CDB, perhaps you need to "
+    AliFatal(Form("No %s found in CDB, perhaps you need to "
                    "use AliFMDCalibFaker?", fgkStripRange));
     return;
   }
-  AliDebug(1, Form("Got strip range from CDB"));
+  AliFMDDebug(1, ("Got strip range from CDB"));
   fStripRange = dynamic_cast<AliFMDCalibStripRange*>(range->GetObject());
-  if (!fStripRange) AliWarning("Invalid strip range object from CDB");
+  if (!fStripRange) AliFatal("Invalid strip range object from CDB");
 }
 
 
@@ -480,7 +587,7 @@ AliFMDParameters::GetPulseGain(UShort_t detector, Char_t ring,
       fFixedPulseGain = fVA1MipRange * GetEdepMip() / fAltroChannelSize;
     return fFixedPulseGain;
   }  
-  AliDebug(50, Form("pulse gain for FMD%d%c[%2d,%3d]=%f",
+  AliFMDDebug(50, ("pulse gain for FMD%d%c[%2d,%3d]=%f",
                    detector, ring, sector, strip,
                    fPulseGain->Value(detector, ring, sector, strip)));
   return fPulseGain->Value(detector, ring, sector, strip);
@@ -493,7 +600,7 @@ AliFMDParameters::IsDead(UShort_t detector, Char_t ring,
 {
   // Check if the channel is dead 
   if (!fDeadMap) return kFALSE;
-  AliDebug(50, Form("Dead for FMD%d%c[%2d,%3d]=%s",
+  AliFMDDebug(50, ("Dead for FMD%d%c[%2d,%3d]=%s",
                    detector, ring, sector, strip,
                    fDeadMap->operator()(detector, ring, sector, strip) ? 
                    "no" : "yes"));
@@ -508,7 +615,7 @@ AliFMDParameters::GetZeroSuppression(UShort_t detector, Char_t ring,
   // Get zero suppression threshold 
   if (!fZeroSuppression) return fFixedZeroSuppression;
   // Need to map strip to ALTRO chip. 
-  AliDebug(50, Form("zero sup. for FMD%d%c[%2d,%3d]=%f",
+  AliFMDDebug(50, ("zero sup. for FMD%d%c[%2d,%3d]=%f",
                    detector, ring, sector, strip,
                    fZeroSuppression->operator()(detector, ring, 
                                                 sector, strip)));
@@ -524,7 +631,7 @@ AliFMDParameters::GetSampleRate(UShort_t det, Char_t ring, UShort_t sector,
   if (!fSampleRate) return fFixedSampleRate;
   // Need to map sector to digitizier card. 
   UInt_t ret = fSampleRate->Rate(det, ring, sector, str);
-  AliDebug(50, Form("Sample rate for FMD%d%c[%2d,%3d]=%d", 
+  AliFMDDebug(50, ("Sample rate for FMD%d%c[%2d,%3d]=%d", 
                    det, ring, sector, str, ret));
   return ret;
 }
@@ -538,7 +645,7 @@ AliFMDParameters::GetMinStrip(UShort_t det, Char_t ring, UShort_t sector,
   if (!fStripRange) return fFixedMinStrip;
   // Need to map sector to digitizier card. 
   UInt_t ret = fStripRange->Min(det, ring, sector, str);
-  AliDebug(50, Form("Min strip # for FMD%d%c[%2d,%3d]=%d", 
+  AliFMDDebug(50, ("Min strip # for FMD%d%c[%2d,%3d]=%d", 
                    det, ring, sector, str, ret));
   return ret;
 }
@@ -552,7 +659,7 @@ AliFMDParameters::GetMaxStrip(UShort_t det, Char_t ring, UShort_t sector,
   if (!fStripRange) return fFixedMaxStrip;
   // Need to map sector to digitizier card. 
   UInt_t ret = fStripRange->Max(det, ring, sector, str);
-  AliDebug(50, Form("Max strip # for FMD%d%c[%2d,%3d]=%d", 
+  AliFMDDebug(50, ("Max strip # for FMD%d%c[%2d,%3d]=%d", 
                    det, ring, sector, str, ret));
   return ret;
 }
@@ -564,7 +671,7 @@ AliFMDParameters::GetPedestal(UShort_t detector, Char_t ring,
 {
   // Get the pedesal 
   if (!fPedestal) return fFixedPedestal;
-  AliDebug(50, Form("pedestal for FMD%d%c[%2d,%3d]=%f",
+  AliFMDDebug(50, ("pedestal for FMD%d%c[%2d,%3d]=%f",
                    detector, ring, sector, strip,
                    fPedestal->Value(detector, ring, sector, strip)));
   return fPedestal->Value(detector, ring, sector, strip);
@@ -577,7 +684,7 @@ AliFMDParameters::GetPedestalWidth(UShort_t detector, Char_t ring,
 {
   // Get the pedesal 
   if (!fPedestal) return fFixedPedestalWidth;
-  AliDebug(50, Form("pedetal width for FMD%d%c[%2d,%3d]=%f",
+  AliFMDDebug(50, ("pedetal width for FMD%d%c[%2d,%3d]=%f",
                    detector, ring, sector, strip,
                    fPedestal->Width(detector, ring, sector, strip)));
   return fPedestal->Width(detector, ring, sector, strip);