]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/macros/testSlatPads.C
Adding new libraries
[u/mrichter/AliRoot.git] / MUON / mapping / macros / testSlatPads.C
CommitLineData
dd3e6c2b 1// $Id$
2// $MpId: testSlatPads.C,v 1.1 2005/09/19 19:02:53 ivana Exp $
3
cb0dc3f3 4/// Macro to check segmentation of slats.
5///
6/// What is tested :
7/// - first, that we can read both bending and non-bending for each slat
8/// - next, for each plane (b,nb), we retrieve all the pads
9/// in two different ways a) using a loop and HasPad method
10/// b) and using pad iterator. We check that both lead to the same set of pads
11/// and that each pad is retrieved only once ;-)
12/// - finally we do a "circular test" for all pads, i.e. we get a pad p1
13/// by indices and use p1's position to feed PadByPosition which gives us a
14/// pad p2. p1 should be equal to p2, of course.
15///
16/// Usage : .L testSlatPads.C++
17/// testSlatPads("slats.list"); where slats.list contains
18/// the list of slats' name to be tested, e.g. 112233NR3, etc...
19
dd3e6c2b 20#if !defined(__CINT__) || defined(__MAKECINT__)
21#include "AliMpSlat.h"
22#include "AliMpSlatSegmentation.h"
23#include "AliMpPad.h"
24#include "AliMpVPadIterator.h"
25#include "AliMpArea.h"
26#include "AliMpSt345Reader.h"
cb0dc3f3 27#include "AliMpSlatMotifMap.h"
dd3e6c2b 28#include "AliMpPlaneType.h"
29#include "TObjArray.h"
30#include "TObjString.h"
31#include "Riostream.h"
32#include "TString.h"
33#include "AliMpIntPair.h"
cb0dc3f3 34#include "TStopwatch.h"
dd3e6c2b 35#include <fstream>
36#else
37#include "Riostream.h"
38#endif
39
40//______________________________________________________________________________
41Int_t CircularTest(const AliMpSlat& slat)
42{
43 Int_t n = -1;
44 AliMpSlatSegmentation seg(&slat);
45
46 for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i )
47 {
48 for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j )
49 {
50 AliMpPad pad = seg.PadByIndices(AliMpIntPair(i,j),kFALSE);
51
52 if ( pad.IsValid() )
53 {
54 ++n;
cb0dc3f3 55 AliMpPad xcheck = seg.PadByPosition(pad.Position(),kFALSE);
dd3e6c2b 56 if ( pad != xcheck )
57 {
58 cout << "(ix,iy)=" << i << "," << j << " ";
59 pad.Print();
60 cout << endl;
61 xcheck.Print();
62 return kFALSE;
63 }
64 }
65 }
66 }
67 return n;
68}
69
70//______________________________________________________________________________
71Int_t Count(const AliMpSlat& slat)
72{
73 Int_t n = 0;
74 AliMpSlatSegmentation seg(&slat);
75
76 for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i )
77 {
78 for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j )
79 {
80 if ( seg.HasPad(AliMpIntPair(i,j)) )
81 {
82 ++n;
83 }
84 }
85 }
cb0dc3f3 86 Int_t n2 = seg.NofPads();
87 if ( n2 != n )
88 {
89 cout << Form("Count (%d) and NofPads (%d) give different results for slat %s",
90 n,n2,slat.GetName()) << endl;
91 }
dd3e6c2b 92 return n;
93}
94
95//______________________________________________________________________________
96Int_t Iterate(const AliMpSlat& slat)
97{
98 AliMpSlatSegmentation seg(&slat);
99
bcba5939 100 AliMpVPadIterator* it = seg.CreateIterator();
dd3e6c2b 101
102 it->First();
103
104 Int_t n = 0;
105
106 while ( !it->IsDone() )
107 {
108 it->Next();
109 ++n;
110 }
111
112 return n;
113}
114
115//______________________________________________________________________________
cb0dc3f3 116Int_t Contains(const TList& list, const AliMpPad& pad)
117{
118 TIter next(&list);
119 AliMpPad* p;
120 Int_t n(0);
121
122 while ( ( p = (AliMpPad*)next() ) )
123 {
124 if ( pad == *p ) ++n;
125 }
126 return n;
127}
128
129//______________________________________________________________________________
130void CheckMultiple(const TList& list, const char* title, const char* what)
131{
132 // check whether the list contains each pad only once
133
134 TIter next(&list);
135 AliMpPad* pad;
136 while ( ( pad = (AliMpPad*)next() ) )
137 {
138 if ( Contains(list,*pad) != 1 )
139 {
140 cout << title << " " << what << " pad found more than once : " << endl;
141 pad->Print();
142 }
143 }
144
145}
146
147//______________________________________________________________________________
148void XCheck(const AliMpSlat& slat)
dd3e6c2b 149{
cb0dc3f3 150 // find out which pads are not found by iterator, as compared to HasPad method
151 TList l1,l2;
152 l1.SetOwner(kTRUE);
153 l2.SetOwner(kTRUE);
154
155 AliMpSlatSegmentation seg(&slat);
156
157 for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i )
158 {
159 for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j )
160 {
161 AliMpPad pad = seg.PadByIndices(AliMpIntPair(i,j),kFALSE);
162 if ( pad.IsValid() )
163 {
164 l1.Add(new AliMpPad(pad));
165 }
166 }
167 }
168
bcba5939 169 AliMpVPadIterator* it = seg.CreateIterator();
cb0dc3f3 170
171 it->First();
172
173 while ( !it->IsDone() )
174 {
175 l2.Add(new AliMpPad(it->CurrentItem()));
176 it->Next();
177 }
178
179 TIter next(&l1);
180 AliMpPad* pad;
181 while ( ( pad = (AliMpPad*)next() ) )
182 {
183 if ( Contains(l2,*pad) != 1)
184 {
185 cout << "The following pad is not found by iterator : " << endl;
186 pad->Print();
187 }
188 }
189
190 CheckMultiple(l2,slat.GetName(),"iterator");
191
192 CheckMultiple(l1,slat.GetName(),"padByIndices");
193}
194
195//______________________________________________________________________________
196void testSlatPads(const char* slatlist)
197{
198 ifstream in(slatlist);
dd3e6c2b 199 char line[80];
200 TObjArray slatsToTest;
cb0dc3f3 201 slatsToTest.SetOwner(kTRUE);
202
203 TStopwatch timerCount;
204 TStopwatch timerIterate;
205 TStopwatch timerCT;
206
207 timerCount.Start(true); timerCount.Stop();
208 timerIterate.Start(true); timerIterate.Stop();
209 timerCT.Start(true); timerCT.Stop();
210
dd3e6c2b 211
212 while ( in.getline(line,80) )
213 {
214 if ( line[0] == '#' ) continue;
215 slatsToTest.AddLast(new TObjString(line));
216 }
217
218 in.close();
cb0dc3f3 219
220 AliMpSlatMotifMap mm;
221 AliMpSt345Reader reader(mm);
222
dd3e6c2b 223 for ( Int_t i = 0; i < slatsToTest.GetEntriesFast(); ++i )
224 {
225 TString slatName( ((TObjString*)slatsToTest[i])->String());
226
cddd101e 227 AliMpSlat* bending = reader.ReadSlat(slatName.Data(),AliMp::kBendingPlane);
228 AliMpSlat* nonbending = reader.ReadSlat(slatName.Data(),AliMp::kNonBendingPlane);
cb0dc3f3 229
230 timerCount.Start(false);
dd3e6c2b 231 Int_t NumberOfBendingPads = Count(*bending);
232 Int_t NumberOfNonBendingPads = Count(*nonbending);
cb0dc3f3 233 timerCount.Stop();
dd3e6c2b 234
cb0dc3f3 235 timerIterate.Start(false);
dd3e6c2b 236 Int_t xcheck_b = Iterate(*bending);
237 Int_t xcheck_nb = Iterate(*nonbending);
cb0dc3f3 238 timerIterate.Stop();
dd3e6c2b 239
cb0dc3f3 240 timerCT.Start(false);
dd3e6c2b 241 Int_t nc_b = CircularTest(*bending);
242 Int_t nc_nb = CircularTest(*nonbending);
cb0dc3f3 243 timerCT.Stop();
dd3e6c2b 244
245 cout << setw(10) << slatName
246 << " BENDING : " << setw(5) << NumberOfBendingPads
247 << " NONBENDING : " << setw(5) << NumberOfNonBendingPads
248 << " CT for " << (nc_b+nc_nb) << " pads ";
249 if ( nc_b>0 && nc_nb>0 )
250 {
251 cout << "OK.";
252 }
253 else
254 {
255 cout << "FAILED.";
256 }
257 cout << endl;
cb0dc3f3 258
259 XCheck(*nonbending);
260 XCheck(*bending);
261
dd3e6c2b 262 if ( xcheck_b != NumberOfBendingPads )
263 {
264 cout << setw(20) << " Bending : HasPad and Iterator give different results !"
265 << " " << NumberOfBendingPads << " vs " << xcheck_b << endl;
266 }
267 if ( xcheck_nb != NumberOfNonBendingPads )
268 {
269 cout << setw(20) << " NonBending : HasPad and Iterator give different results !"
270 << " " << NumberOfNonBendingPads << " vs " << xcheck_nb << endl;
271 }
272
273 }
cb0dc3f3 274
275 cout << "Count : ";
276 timerCount.Print();
277 cout << "Iterate : ";
278 timerIterate.Print();
279 cout << "CT : ";
280 timerCT.Print();
281
dd3e6c2b 282}