]> git.uio.no Git - u/mrichter/AliRoot.git/blame - FMD/scripts/TestFloatMap.C
Whoops
[u/mrichter/AliRoot.git] / FMD / scripts / TestFloatMap.C
CommitLineData
9c35f272 1#include <STEER/AliFMDFloatMap.h>
2#include <cstdio>
3#include <STEER/AliLog.h>
4
5//____________________________________________________________________
6struct Printer : public AliFMDMap::ForOne
7{
8 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t v)
9 {
10 printf("FMD%d%c[%2d,%3d] = %8.3f\n", d, r, s, t, v);
11 return kTRUE;
12 }
13 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Int_t v)
14 {
15 printf("FMD%d%c[%2d,%3d] = %d\n", d, r, s, t, v);
16 return kTRUE;
17 }
18};
19//____________________________________________________________________
20struct Tester : public AliFMDMap::ForOne
21{
22 Tester(AliFMDFloatMap& m) : fMap(&m) { }
23 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t)
24 {
25 Int_t idx = fMap->CalcIndex(d, r, s, t);
26 UShort_t rd, rs, rt;
27 Char_t rr;
28 fMap->CalcCoords(idx, rd, rr, rs, rt);
29
30 if (d != rd || r != rr || s != rs || t != rt)
31 printf("Mismatch FMD%d%c[%2d,%3d] -> %5d -> FMD%d%c[%2d,%3d]\n",
32 d, r, s, t, idx, rd, rr, rs, rt);
33 return kTRUE;
34 }
35 Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t){return kTRUE;}
36 AliFMDFloatMap* fMap;
37};
38//____________________________________________________________________
39struct Filler : public AliFMDMap::ForOne
40{
41 Filler(AliFMDFloatMap& map) : fMap(&map) {}
42 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t)
43 {
44 fMap->operator()(d, r, s, t) = MakeVal(d, r, s, t);
45 return kTRUE;
46 }
47 Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t)
48 {
49 return kTRUE;
50 }
51 static Float_t MakeVal(UShort_t d, Char_t r, UShort_t s, UShort_t t)
52 {
53 UShort_t ir = r == 'I' ? 0 : 1;
54 Float_t val = d * 1000 + ir * 100 + s + 0.001 * t;
55 return val;
56 }
57 AliFMDFloatMap* fMap;
58};
59
60//____________________________________________________________________
61struct Unity : public AliFMDMap::ForOne
62{
63 Unity(AliFMDFloatMap& map) : fMap(&map) {}
64 Bool_t operator()(UShort_t d, Char_t r, UShort_t s, UShort_t t, Float_t)
65 {
66 fMap->operator()(d, r, s, t) = 1;
67 return kTRUE;
68 }
69 Bool_t operator()(UShort_t, Char_t, UShort_t, UShort_t, Int_t) {return kTRUE;}
70 AliFMDFloatMap* fMap;
71};
72
73//____________________________________________________________________
74void
75FillMap(AliFMDFloatMap& m, Bool_t useFiller=kTRUE)
76{
77 if (useFiller) {
78 Filler f(m);
79 m.ForEach(f);
80 return;
81 }
82 for (UShort_t d = 1; d <= 3; d++) {
83 UShort_t nRng = (d == 1 ? 1 : 2);
84 for (UShort_t q = 0; q < nRng; q++) {
85 Char_t r = (q == 0 ? 'I' : 'O');
86 UShort_t nSec = 1; // (q == 0 ? 20 : 40);
87 UShort_t nStr = (q == 0 ? 512 : 256);
88 for (UShort_t s = 0; s < nSec; s++) {
89 for (UShort_t t = 0; t < nStr; t++) {
90 m(d, r, s, t) = Filler::MakeVal(d, r, s, t);
91 }
92 }
93 }
94 }
95}
96//____________________________________________________________________
97void
98PrintMap(AliFMDFloatMap& map)
99{
100 Printer p;
101 map.ForEach(p);
102}
103//____________________________________________________________________
104void
105FillOne(AliFMDFloatMap& map)
106{
107 Unity u(map);
108 map.ForEach(u);
109}
110
111//____________________________________________________________________
112void
113TestIndex(AliFMDFloatMap& map, Bool_t useTester=kTRUE)
114{
115 if (useTester) {
116 Tester t(map);
117 map.ForEach(t);
118 return;
119 }
120 for (UShort_t d = 1; d <= 3; d++) {
121 UShort_t nRng = (d == 1 ? 1 : 2);
122 for (UShort_t q = 0; q < nRng; q++) {
123 Char_t r = (q == 0 ? 'I' : 'O');
124 UShort_t nSec = 1; // (q == 0 ? 20 : 40);
125 UShort_t nStr = (q == 0 ? 512 : 256);
126 for (UShort_t s = 0; s < nSec; s++) {
127 for (UShort_t t = 0; t < nStr; t++) {
128 Int_t idx = map.CalcIndex(d, r, s, t);
129
130 UShort_t rd, rs, rt;
131 Char_t rr;
132 map.CalcCoords(idx, rd, rr, rs, rt);
133
134 if (d != rd || r != rr || s != rs || t != rt)
135 printf("Mismatch FMD%d%c[%2d,%3d] -> %5d -> FMD%d%c[%2d,%3d]\n",
136 d, r, s, t, idx, rd, rr, rs, rt);
137 }
138 }
139 }
140 }
141}
142
143void
144TestFloatMap()
145{
146 // AliLog::SetModuleDebugLevel("FMD", 1);
147 AliFMDFloatMap m1(0, 0, 0, 0);
148 FillMap(m1);
149 // PrintMap(m1);
150 TestIndex(m1);
151
152 AliFMDFloatMap m2;
153 FillOne(m2);
154 // m2 *= m1;
155 // m2 /= m1;
156 m2 += m2;
157 // PrintMap(m2);
158
159 AliFMDFloatMap m3(3, 2, 1, 512);
160 TestIndex(m3, kFALSE);
161 FillMap(m3, kFALSE);
162 // PrintMap(m3);
163 FillOne(m2);
164 m2 *= m3;
165 PrintMap(m2);
166}