]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added test scripts.
authorcholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 2 Jul 2009 10:44:24 +0000 (10:44 +0000)
committercholm <cholm@f7af4fe6-9843-0410-8265-dc069ae4e863>
Thu, 2 Jul 2009 10:44:24 +0000 (10:44 +0000)
FMD/scripts/TestESD.C [new file with mode: 0644]
FMD/scripts/TestESDCompat.C [new file with mode: 0644]
FMD/scripts/TestESDPhi.C [new file with mode: 0644]
FMD/scripts/TestFloatMap.C [new file with mode: 0644]

diff --git a/FMD/scripts/TestESD.C b/FMD/scripts/TestESD.C
new file mode 100644 (file)
index 0000000..2d599b3
--- /dev/null
@@ -0,0 +1,125 @@
+#include <iomanip>
+/**
+ * Script to test for compatibility to read/write ESD information 
+ */
+
+Float_t EtaValue(UShort_t d, Char_t r, UShort_t t)
+{
+  return (d * 1000 + (r == 'I' || r == 'i' ? 0 : 1) * 100 + 0.001 * t);
+}
+Float_t MultValue(UShort_t d, Char_t r, UShort_t s, UShort_t t)
+{
+  return (EtaValue(d, r, t) + s);
+}
+
+void 
+FillESD(AliESDFMD* esd)
+{
+  for (UShort_t d = 1; d <= 3; d++) { 
+    UShort_t nRng = (d == 1 ? 1 : 2);
+    for (UShort_t i = 0; i < nRng; i++) {
+      Char_t   r    = (i == 0 ? 'I' : 'O');
+      UShort_t nSec = (i == 0 ?  20 :  40);
+      UShort_t nStr = (i == 0 ? 512 : 256);
+      for (UShort_t s = 0; s < nSec; s++) { 
+       for (UShort_t t = 0; t < nStr; t++) {
+         if (s == 0) esd->SetEta(d, r, 0, t, EtaValue(d, r, t));
+         esd->SetMultiplicity(d, r, s, t, MultValue(d, r, s, t));
+       }
+      } // for s
+    } // for i 
+  } // for d
+}
+         
+void 
+WriteESD(const char* fileName)
+{
+  TFile*     file = TFile::Open(fileName, "RECREATE");
+  TTree*     tree = new TTree("T", "T");
+  AliESDFMD* fmd  = new AliESDFMD();
+  tree->Branch("FMD", "AliESDFMD", &fmd);
+  
+  for (UShort_t i = 0; i < 10; i++) { 
+    FillESD(fmd);
+    tree->Fill();
+  }
+  file->Write();
+  file->Close();
+}
+
+Bool_t 
+PrintOne(UShort_t d, Char_t r, UShort_t s, UShort_t t, 
+        Float_t  m, Float_t e)
+{
+  Float_t em = MultValue(d, r, s, t);
+  Float_t ee = EtaValue(d, r, t);
+  if (m != em || ee != e) {
+    std::cerr << "FMD" << d << r << '[' 
+             << std::setw(2) << s  << ',' 
+             << std::setw(3) << t  << "]: " 
+             << std::setw(8) << m  << " (" 
+             << std::setw(8) << em << ' ' 
+             << (m == em ? "ok" : "bad") << ") @ "
+             << std::setw(8) << e << " ("
+             << std::setw(8) << ee << ' ' 
+             << (ee == e ? "ok" : "bad") << ')' << std::endl;
+    return kFALSE;
+  }
+  return kTRUE;
+}
+
+Bool_t
+PrintESD(AliESDFMD* esd)
+{
+
+  Bool_t ret = kTRUE;
+  for (UShort_t d = 1; d <= 3; d++) { 
+    UShort_t nRng = (d == 1 ? 1 : 2);
+    for (UShort_t i = 0; i < nRng; i++) {
+      Char_t   r    = (i == 0 ? 'I' : 'O');
+      UShort_t nSec = (i == 0 ?  20 :  40);
+      UShort_t nStr = (i == 0 ? 512 : 256);
+      for (UShort_t s = 0; s < nSec; s++) { 
+       for (UShort_t t = 0; t < nStr; t++) {
+         Float_t m = esd->Multiplicity(d, r, s, t);
+         Float_t e = esd->Eta(d, r, s, t);
+         if (!PrintOne(d, r, s, t, m, e)) ret = kFALSE;
+       }
+      }
+    }
+  }
+  return ret;
+}
+  
+void
+ReadESD(const char* fileName)
+{
+  TFile*     file = TFile::Open(fileName, "READ");
+  TTree*     tree = static_cast<TTree*>(file->Get("T"));
+  AliESDFMD* fmd  = new AliESDFMD();
+  tree->SetBranchAddress("FMD", &fmd);
+
+  Bool_t ret = kTRUE;
+  for (UShort_t i = 0; i < 10; i++) {
+    fmd->Clear();
+    tree->GetEntry(i);
+    if (!PrintESD(fmd)) ret = kFALSE;
+  }
+  file->Close();
+  if (!ret) 
+    std::cerr << "There have been errors!" << std::endl;
+  else 
+    std::cout << "All correct" << std::endl;
+
+}
+
+
+void
+TestESD(const char* fileName=0)
+{
+  if (!fileName) { 
+    WriteESD("esd_test.root");
+    return;
+  }
+  ReadESD(fileName);
+}
diff --git a/FMD/scripts/TestESDCompat.C b/FMD/scripts/TestESDCompat.C
new file mode 100644 (file)
index 0000000..17bbef7
--- /dev/null
@@ -0,0 +1,125 @@
+#include <iomanip>
+/**
+ * Script to test for compatibility to read/write ESD information 
+ */
+
+Float_t EtaValue(UShort_t d, Char_t r, UShort_t t)
+{
+  return (d * 1000 + (r == 'I' || r == 'i' ? 0 : 1) * 100 + 0.001 * t);
+}
+Float_t MultValue(UShort_t d, Char_t r, UShort_t s, UShort_t t)
+{
+  return (EtaValue(d, r, t) + s);
+}
+
+void 
+FillESD(AliESDFMD* esd)
+{
+  for (UShort_t d = 1; d <= 3; d++) { 
+    UShort_t nRng = (d == 1 ? 1 : 2);
+    for (UShort_t i = 0; i < nRng; i++) {
+      Char_t   r    = (i == 0 ? 'I' : 'O');
+      UShort_t nSec = (i == 0 ?  20 :  40);
+      UShort_t nStr = (i == 0 ? 512 : 256);
+      for (UShort_t s = 0; s < nSec; s++) { 
+       for (UShort_t t = 0; t < nStr; t++) {
+         if (s == 0) esd->SetEta(d, r, 0, t, EtaValue(d, r, t));
+         esd->SetMultiplicity(d, r, s, t, MultValue(d, r, s, t));
+       }
+      } // for s
+    } // for i 
+  } // for d
+}
+         
+void 
+WriteESD(const char* fileName)
+{
+  TFile*     file = TFile::Open(fileName, "RECREATE");
+  TTree*     tree = new TTree("T", "T");
+  AliESDFMD* fmd  = new AliESDFMD();
+  tree->Branch("FMD", "AliESDFMD", &fmd);
+  
+  for (UShort_t i = 0; i < 10; i++) { 
+    FillESD(fmd);
+    tree->Fill();
+  }
+  file->Write();
+  file->Close();
+}
+
+Bool_t 
+PrintOne(UShort_t d, Char_t r, UShort_t s, UShort_t t, 
+        Float_t  m, Float_t e)
+{
+  Float_t em = MultValue(d, r, s, t);
+  Float_t ee = EtaValue(d, r, t);
+  if (m != em || ee != e) {
+    std::cerr << "FMD" << d << r << '[' 
+             << std::setw(2) << s  << ',' 
+             << std::setw(3) << t  << "]: " 
+             << std::setw(8) << m  << " (" 
+             << std::setw(8) << em << ' ' 
+             << (m == em ? "ok" : "bad") << ") @ "
+             << std::setw(8) << e << " ("
+             << std::setw(8) << ee << ' ' 
+             << (ee == e ? "ok" : "bad") << ')' << std::endl;
+    return kFALSE;
+  }
+  return kTRUE;
+}
+
+Bool_t
+PrintESD(AliESDFMD* esd)
+{
+
+  Bool_t ret = kTRUE;
+  for (UShort_t d = 1; d <= 3; d++) { 
+    UShort_t nRng = (d == 1 ? 1 : 2);
+    for (UShort_t i = 0; i < nRng; i++) {
+      Char_t   r    = (i == 0 ? 'I' : 'O');
+      UShort_t nSec = (i == 0 ?  20 :  40);
+      UShort_t nStr = (i == 0 ? 512 : 256);
+      for (UShort_t s = 0; s < nSec; s++) { 
+       for (UShort_t t = 0; t < nStr; t++) {
+         Float_t m = esd->Multiplicity(d, r, s, t);
+         Float_t e = esd->Eta(d, r, s, t);
+         if (!PrintOne(d, r, s, t, m, e)) ret = kFALSE;
+       }
+      }
+    }
+  }
+  return ret;
+}
+  
+void
+ReadESD(const char* fileName)
+{
+  TFile*     file = TFile::Open(fileName, "READ");
+  TTree*     tree = static_cast<TTree*>(file->Get("T"));
+  AliESDFMD* fmd  = new AliESDFMD();
+  tree->SetBranchAddress("FMD", &fmd);
+
+  Bool_t ret = kTRUE;
+  for (UShort_t i = 0; i < 10; i++) {
+    fmd->Clear();
+    tree->GetEntry(i);
+    if (!PrintESD(fmd)) ret = kFALSE;
+  }
+  file->Close();
+  if (!ret) 
+    std::cerr << "There have been errors!" << std::endl;
+  else 
+    std::cout << "All correct" << std::endl;
+
+}
+
+
+void
+TestESDCompat(const char* fileName=0)
+{
+  if (!fileName) { 
+    WriteESD("esd_test.root");
+    return;
+  }
+  ReadESD(fileName);
+}
diff --git a/FMD/scripts/TestESDPhi.C b/FMD/scripts/TestESDPhi.C
new file mode 100644 (file)
index 0000000..354a5f7
--- /dev/null
@@ -0,0 +1,45 @@
+void
+TestESDPhi()
+{
+  AliCDBManager::Instance()->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
+  AliCDBManager::Instance()->SetRun(0);
+  
+  AliGeomManager::LoadGeometry();
+  
+  AliFMDGeometry* geom = AliFMDGeometry::Instance();
+  geom->Init();
+  geom->InitTransformations();
+
+  AliESDFMD esd;
+  
+  for (UShort_t d = 1; d <= 3; d++) { 
+    UShort_t nRng = (d == 1 ? 1 : 2);
+    for (UShort_t q = 0; q < nRng; q++) { 
+      Char_t   r    = (q == 0 ? 'I' : 'O');
+      UShort_t nSec = (q == 0 ?  20 :  40);
+      for (UShort_t s = 0; s < nSec; s++) {
+       Double_t x, y, z;
+       geom->Detector2XYZ(d, r, s, 0, x, y, z);
+       Double_t a = TMath::ATan2(y, x);
+       Double_t p = esd.Phi(d, r, s, 0);
+       
+       if (a < 0) a+= 2 * TMath::Pi();
+       a *= 180 / TMath::Pi();
+
+       Printf("FMD%d%c[%2d]: Geom: %5.1f, ESD: %5.1f", d, r, s, a, p);
+      }
+    }
+  }
+  for (UShort_t q = 0; q < nRng; q++) { 
+    Char_t   r    = (q == 0 ? 'I' : 'O');
+    UShort_t nStr = (q == 0 ? 512 : 256);
+    for (UShort_t t = 0; t < nStr; t++) {
+      Double_t x, y, z;
+      geom->Detector2XYZ(2, r, 0, t, x, y, z);
+      Double_t l = TMath::Sqrt(x * x + y * y);
+      Double_t v = esd.R(2, r, 0, t);
+
+      Printf("FMD%c[%3d]: Geom: %6.3f, ESD: %6.3f", r, t, l, v);
+    }
+  }
+}
diff --git a/FMD/scripts/TestFloatMap.C b/FMD/scripts/TestFloatMap.C
new file mode 100644 (file)
index 0000000..1671eb3
--- /dev/null
@@ -0,0 +1,166 @@
+#include <STEER/AliFMDFloatMap.h>
+#include <cstdio>
+#include <STEER/AliLog.h>
+
+//____________________________________________________________________
+struct Printer : public AliFMDMap::ForOne
+{
+  Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t v)
+  {
+    printf("FMD%d%c[%2d,%3d] = %8.3f\n", d, r, s, t, v);
+    return kTRUE;
+  }
+  Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Int_t v)
+  {
+    printf("FMD%d%c[%2d,%3d] = %d\n", d, r, s, t, v);
+    return kTRUE;
+  }
+};
+//____________________________________________________________________
+struct Tester : public AliFMDMap::ForOne
+{
+  Tester(AliFMDFloatMap& m) : fMap(&m) { }
+  Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t)
+  {
+    Int_t    idx = fMap->CalcIndex(d, r, s, t);
+    UShort_t rd, rs, rt;
+    Char_t   rr;
+    fMap->CalcCoords(idx, rd, rr, rs, rt);
+         
+    if (d != rd || r != rr || s != rs || t != rt) 
+      printf("Mismatch FMD%d%c[%2d,%3d] -> %5d -> FMD%d%c[%2d,%3d]\n",
+            d, r, s, t, idx, rd, rr, rs, rt);
+    return kTRUE;
+  }
+  Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t){return kTRUE;}
+  AliFMDFloatMap* fMap;
+};
+//____________________________________________________________________
+struct Filler : public AliFMDMap::ForOne
+{
+  Filler(AliFMDFloatMap& map) : fMap(&map) {}
+  Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t)
+  {
+    fMap->operator()(d, r, s, t) = MakeVal(d, r, s, t);
+    return kTRUE;
+  }
+  Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t)
+  {
+    return kTRUE;
+  }
+  static Float_t MakeVal(UShort_t d, Char_t r, UShort_t s, UShort_t t)
+  {
+    UShort_t ir  = r == 'I' ? 0 : 1;
+    Float_t  val = d * 1000 + ir * 100 + s + 0.001 * t;
+    return val;
+  }
+  AliFMDFloatMap* fMap;
+};
+
+//____________________________________________________________________
+struct Unity : public AliFMDMap::ForOne
+{
+  Unity(AliFMDFloatMap& map) : fMap(&map) {}
+  Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t)
+  {
+    fMap->operator()(d, r, s, t) = 1;
+    return kTRUE;
+  }
+  Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t) {return kTRUE;}
+  AliFMDFloatMap* fMap;
+};
+  
+//____________________________________________________________________
+void
+FillMap(AliFMDFloatMap& m, Bool_t useFiller=kTRUE)
+{
+  if (useFiller) {
+    Filler f(m);
+    m.ForEach(f);
+    return;
+  }
+  for (UShort_t d = 1; d <= 3; d++) { 
+    UShort_t nRng = (d == 1 ? 1 : 2);
+    for (UShort_t q = 0; q < nRng; q++) { 
+      Char_t   r    = (q == 0 ? 'I' : 'O');
+      UShort_t nSec = 1; // (q == 0 ?  20 :  40);
+      UShort_t nStr = (q == 0 ? 512 : 256);
+      for (UShort_t s = 0; s < nSec; s++) { 
+       for (UShort_t t = 0; t < nStr; t++) {
+         m(d, r, s, t) = Filler::MakeVal(d, r, s, t);
+       }
+      }
+    }
+  }
+}
+//____________________________________________________________________
+void
+PrintMap(AliFMDFloatMap& map)
+{
+  Printer p;
+  map.ForEach(p);
+}
+//____________________________________________________________________
+void
+FillOne(AliFMDFloatMap& map)
+{
+  Unity u(map);
+  map.ForEach(u);
+}
+  
+//____________________________________________________________________
+void
+TestIndex(AliFMDFloatMap& map, Bool_t useTester=kTRUE)
+{
+  if (useTester) { 
+    Tester t(map);
+    map.ForEach(t);
+    return;
+  }
+  for (UShort_t d = 1; d <= 3; d++) { 
+    UShort_t nRng = (d == 1 ? 1 : 2);
+    for (UShort_t q = 0; q < nRng; q++) { 
+      Char_t   r    = (q == 0 ? 'I' : 'O');
+      UShort_t nSec = 1; // (q == 0 ?  20 :  40);
+      UShort_t nStr = (q == 0 ? 512 : 256);
+      for (UShort_t s = 0; s < nSec; s++) { 
+       for (UShort_t t = 0; t < nStr; t++) {
+         Int_t idx = map.CalcIndex(d, r, s, t);
+         
+         UShort_t rd, rs, rt;
+         Char_t   rr;
+         map.CalcCoords(idx, rd, rr, rs, rt);
+         
+         if (d != rd || r != rr || s != rs || t != rt) 
+           printf("Mismatch FMD%d%c[%2d,%3d] -> %5d -> FMD%d%c[%2d,%3d]\n",
+                  d, r, s, t, idx, rd, rr, rs, rt);
+       }
+      }
+    }
+  }
+}
+
+void 
+TestFloatMap()
+{
+  // AliLog::SetModuleDebugLevel("FMD", 1);
+  AliFMDFloatMap m1(0, 0, 0, 0);
+  FillMap(m1);
+  // PrintMap(m1);
+  TestIndex(m1);
+
+  AliFMDFloatMap m2;
+  FillOne(m2);
+  // m2 *= m1;
+  // m2 /= m1;
+  m2 += m2;
+  // PrintMap(m2);
+  
+  AliFMDFloatMap m3(3, 2, 1, 512);
+  TestIndex(m3, kFALSE); 
+  FillMap(m3, kFALSE);
+  // PrintMap(m3);
+  FillOne(m2);
+  m2 *= m3;
+  PrintMap(m2);
+}