]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - FMD/AliFMDCalibGain.cxx
changes in the MagF constructor
[u/mrichter/AliRoot.git] / FMD / AliFMDCalibGain.cxx
index 831ed6c95db0d49a3e8431cda753e7a74d85d2ee..064e9a8c1fb5180e2ab26d782c4c6c89fed554de 100644 (file)
 // Gnus
 //
 #include "AliFMDCalibGain.h"   // ALIFMDCALIBGAIN_H
+#include <iostream>
+#include <TString.h>
+#include <AliLog.h>
+#include "AliFMDDebug.h"
+
+#include "AliFMDBoolMap.h"
+
+
 //____________________________________________________________________
 ClassImp(AliFMDCalibGain)
 #if 0
@@ -35,6 +43,8 @@ ClassImp(AliFMDCalibGain)
 
 //____________________________________________________________________
 AliFMDCalibGain::AliFMDCalibGain()
+  : fValue(0), // nDet == 0 mean 51200 slots
+    fThreshold(-1.)
 {
   // CTOR
   fValue.Reset(-1.);
@@ -43,7 +53,9 @@ AliFMDCalibGain::AliFMDCalibGain()
 
 //____________________________________________________________________
 AliFMDCalibGain::AliFMDCalibGain(const AliFMDCalibGain& o)
-  : TObject(o), fValue(o.fValue), fThreshold(o.fThreshold)
+  : TObject(o), 
+    fValue(o.fValue), 
+    fThreshold(o.fThreshold)
 {
   // Copy CTOR 
 }
@@ -77,6 +89,106 @@ AliFMDCalibGain::Value(UShort_t det, Char_t ring, UShort_t sec,
   return fValue(det, ring, sec, str);
 }
 
+//____________________________________________________________________
+namespace {
+  struct MakeDead : public AliFMDMap::ForOne
+  {
+    MakeDead(AliFMDBoolMap* dead, Float_t min, Float_t max) 
+      : fDead(dead), fMin(min), fMax(max), fCount(0)
+    {}
+    MakeDead(const MakeDead& other) 
+      : fDead(other.fDead), fMin(other.fMin), fMax(other.fMax), 
+       fCount(other.fCount)
+    {}
+    MakeDead& operator=(const MakeDead& other) 
+    { 
+      fDead   = other.fDead;
+      fMin    = other.fMin;
+      fMax    = other.fMax;
+      fCount  = other.fCount;
+      return *this;
+    }
+    Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t v)
+    {
+      AliDebugGeneral("AliFMDCalibGain::MakeDeadMap", 100, 
+                     Form("Checking if gain of FMD%d%c[%2d,%3d]=%f "
+                          "is out of range [%f,%f]", 
+                          d, r, s, t, v, fMin, fMax));
+      if (v > fMax || v < fMin) {
+       fDead->operator()(d,r,s,t) = kTRUE;
+       fCount++;
+      }
+      return kTRUE;
+    }
+    Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t) 
+    { return kFALSE; }
+    Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, UShort_t) 
+    { return kFALSE; }
+    Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Bool_t)
+    { return kFALSE; }
+    AliFMDBoolMap* fDead;
+    Float_t        fMin;
+    Float_t        fMax;
+    Int_t          fCount;
+  };
+}
+
+//____________________________________________________________________
+AliFMDBoolMap*
+AliFMDCalibGain::MakeDeadMap(Float_t min, Float_t max, 
+                            AliFMDBoolMap* dead) const
+{
+  if (!dead) { 
+    dead = new AliFMDBoolMap(0,0,0,0);
+    dead->Reset(kFALSE);
+  }
+  MakeDead dm(dead, min, max);
+  fValue.ForEach(dm);
+  AliFMDDebug(1, ("Found a total of %d dead channels", dm.fCount));
+  return dead;
+}
+
+//____________________________________________________________________
+Bool_t
+AliFMDCalibGain::ReadFromFile(std::istream& in)
+{
+  //Get header (how long is it ?)
+  TString header;
+  header.ReadLine(in);
+  header.ToLower();
+  if(!header.Contains("gains")) {
+    AliError("File does not contain gains!");
+    return kFALSE;;
+  }
+
+  // Read column headers
+  header.ReadLine(in);
+  
+  int lineno  = 2;
+  // Read until EOF 
+  while(in.peek()!=EOF) {
+    if(in.bad()) { 
+      AliError(Form("Bad read at line %d of input", lineno));
+      break;
+    }
+    UShort_t det, sec, strip;
+    Char_t ring;
+    
+    Float_t gain,error,  chi2ndf;
+    Char_t c[6];
+    
+    in >> det      >> c[0] 
+       >> ring     >> c[1]
+       >> sec      >> c[2]
+       >> strip    >> c[3]
+       >> gain     >> c[4]
+       >> error    >> c[5]
+       >> chi2ndf;
+    lineno++;
+    Set(det,ring,sec,strip,gain);
+  }
+  return kTRUE;
+}
 //____________________________________________________________________
 //
 // EOF