2 // $MpId: testSlatPads.C,v 1.1 2005/09/19 19:02:53 ivana Exp $
4 /// Macro to check segmentation of slats.
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.
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...
20 #if !defined(__CINT__) || defined(__MAKECINT__)
21 #include "AliMpSlat.h"
22 #include "AliMpSlatSegmentation.h"
24 #include "AliMpVPadIterator.h"
25 #include "AliMpArea.h"
26 #include "AliMpSt345Reader.h"
27 #include "AliMpSlatMotifMap.h"
28 #include "AliMpPlaneType.h"
29 #include "TObjArray.h"
30 #include "TObjString.h"
31 #include "Riostream.h"
33 #include "AliMpIntPair.h"
34 #include "TStopwatch.h"
37 #include "Riostream.h"
40 //______________________________________________________________________________
41 Int_t CircularTest(const AliMpSlat& slat)
44 AliMpSlatSegmentation seg(&slat);
46 for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i )
48 for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j )
50 AliMpPad pad = seg.PadByIndices(AliMpIntPair(i,j),kFALSE);
55 AliMpPad xcheck = seg.PadByPosition(pad.Position(),kFALSE);
58 cout << "(ix,iy)=" << i << "," << j << " ";
70 //______________________________________________________________________________
71 Int_t Count(const AliMpSlat& slat)
74 AliMpSlatSegmentation seg(&slat);
76 for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i )
78 for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j )
80 if ( seg.HasPad(AliMpIntPair(i,j)) )
86 Int_t n2 = seg.NofPads();
89 cout << Form("Count (%d) and NofPads (%d) give different results for slat %s",
90 n,n2,slat.GetName()) << endl;
95 //______________________________________________________________________________
96 Int_t Iterate(const AliMpSlat& slat)
98 AliMpSlatSegmentation seg(&slat);
100 AliMpArea area(TVector2(0.0,0.0),slat.Dimensions());
102 AliMpVPadIterator* it = seg.CreateIterator(area);
108 while ( !it->IsDone() )
117 //______________________________________________________________________________
118 Int_t Contains(const TList& list, const AliMpPad& pad)
124 while ( ( p = (AliMpPad*)next() ) )
126 if ( pad == *p ) ++n;
131 //______________________________________________________________________________
132 void CheckMultiple(const TList& list, const char* title, const char* what)
134 // check whether the list contains each pad only once
138 while ( ( pad = (AliMpPad*)next() ) )
140 if ( Contains(list,*pad) != 1 )
142 cout << title << " " << what << " pad found more than once : " << endl;
149 //______________________________________________________________________________
150 void XCheck(const AliMpSlat& slat)
152 // find out which pads are not found by iterator, as compared to HasPad method
157 AliMpSlatSegmentation seg(&slat);
159 for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i )
161 for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j )
163 AliMpPad pad = seg.PadByIndices(AliMpIntPair(i,j),kFALSE);
166 l1.Add(new AliMpPad(pad));
171 AliMpArea area(TVector2(0.0,0.0),slat.Dimensions());
173 AliMpVPadIterator* it = seg.CreateIterator(area);
177 while ( !it->IsDone() )
179 l2.Add(new AliMpPad(it->CurrentItem()));
185 while ( ( pad = (AliMpPad*)next() ) )
187 if ( Contains(l2,*pad) != 1)
189 cout << "The following pad is not found by iterator : " << endl;
194 CheckMultiple(l2,slat.GetName(),"iterator");
196 CheckMultiple(l1,slat.GetName(),"padByIndices");
199 //______________________________________________________________________________
200 void testSlatPads(const char* slatlist)
202 ifstream in(slatlist);
204 TObjArray slatsToTest;
205 slatsToTest.SetOwner(kTRUE);
207 TStopwatch timerCount;
208 TStopwatch timerIterate;
211 timerCount.Start(true); timerCount.Stop();
212 timerIterate.Start(true); timerIterate.Stop();
213 timerCT.Start(true); timerCT.Stop();
216 while ( in.getline(line,80) )
218 if ( line[0] == '#' ) continue;
219 slatsToTest.AddLast(new TObjString(line));
224 AliMpSlatMotifMap mm;
225 AliMpSt345Reader reader(mm);
227 for ( Int_t i = 0; i < slatsToTest.GetEntriesFast(); ++i )
229 TString slatName( ((TObjString*)slatsToTest[i])->String());
231 AliMpSlat* bending = reader.ReadSlat(slatName.Data(),kBendingPlane);
232 AliMpSlat* nonbending = reader.ReadSlat(slatName.Data(),kNonBendingPlane);
234 timerCount.Start(false);
235 Int_t NumberOfBendingPads = Count(*bending);
236 Int_t NumberOfNonBendingPads = Count(*nonbending);
239 timerIterate.Start(false);
240 Int_t xcheck_b = Iterate(*bending);
241 Int_t xcheck_nb = Iterate(*nonbending);
244 timerCT.Start(false);
245 Int_t nc_b = CircularTest(*bending);
246 Int_t nc_nb = CircularTest(*nonbending);
249 cout << setw(10) << slatName
250 << " BENDING : " << setw(5) << NumberOfBendingPads
251 << " NONBENDING : " << setw(5) << NumberOfNonBendingPads
252 << " CT for " << (nc_b+nc_nb) << " pads ";
253 if ( nc_b>0 && nc_nb>0 )
266 if ( xcheck_b != NumberOfBendingPads )
268 cout << setw(20) << " Bending : HasPad and Iterator give different results !"
269 << " " << NumberOfBendingPads << " vs " << xcheck_b << endl;
271 if ( xcheck_nb != NumberOfNonBendingPads )
273 cout << setw(20) << " NonBending : HasPad and Iterator give different results !"
274 << " " << NumberOfNonBendingPads << " vs " << xcheck_nb << endl;
281 cout << "Iterate : ";
282 timerIterate.Print();