]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/mapping/macros/testSlatPads.C
473733770aae000ee8b0185214c350d04d9c0e88
[u/mrichter/AliRoot.git] / MUON / mapping / macros / testSlatPads.C
1 // $Id$
2 // $MpId: testSlatPads.C,v 1.1 2005/09/19 19:02:53 ivana Exp $
3
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
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"
27 #include "AliMpSlatMotifMap.h"
28 #include "AliMpPlaneType.h"
29 #include "TObjArray.h"
30 #include "TObjString.h"
31 #include "Riostream.h"
32 #include "TString.h"
33 #include "AliMpIntPair.h"
34 #include "TStopwatch.h"
35 #include <fstream>
36 #else
37 #include "Riostream.h"
38 #endif
39
40 //______________________________________________________________________________
41 Int_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;
55         AliMpPad xcheck = seg.PadByPosition(pad.Position(),kFALSE);
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 //______________________________________________________________________________
71 Int_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   }
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   }
92   return n;
93 }
94
95 //______________________________________________________________________________
96 Int_t Iterate(const AliMpSlat& slat)
97 {
98   AliMpSlatSegmentation seg(&slat);
99   
100   AliMpArea area(TVector2(0.0,0.0),slat.Dimensions());
101   
102   AliMpVPadIterator* it = seg.CreateIterator(area);
103   
104   it->First();
105   
106   Int_t n = 0;
107   
108   while ( !it->IsDone() )
109   {
110     it->Next();
111     ++n;
112   }
113   
114   return n;
115 }
116
117 //______________________________________________________________________________
118 Int_t Contains(const TList& list, const AliMpPad& pad)
119 {
120   TIter next(&list);
121   AliMpPad* p;
122   Int_t n(0);
123   
124   while ( ( p = (AliMpPad*)next() ) )
125   {
126     if ( pad == *p ) ++n;
127   }
128   return n;
129 }
130
131 //______________________________________________________________________________
132 void CheckMultiple(const TList& list, const char* title, const char* what)
133 {
134   // check whether the list contains each pad only once
135   
136   TIter next(&list);
137   AliMpPad* pad;
138   while ( ( pad = (AliMpPad*)next() ) )
139   {
140     if ( Contains(list,*pad) != 1 )
141     {
142       cout << title << " " << what << " pad found more than once : " << endl;
143       pad->Print();
144     }
145   }
146       
147 }
148
149 //______________________________________________________________________________
150 void XCheck(const AliMpSlat& slat)
151 {
152   // find out which pads are not found by iterator, as compared to HasPad method
153   TList l1,l2;
154   l1.SetOwner(kTRUE);
155   l2.SetOwner(kTRUE);
156   
157   AliMpSlatSegmentation seg(&slat);
158   
159   for ( Int_t i = 0; i <= seg.MaxPadIndexX(); ++i )
160   {
161     for ( Int_t j = 0; j <= seg.MaxPadIndexY(); ++j )
162     {
163       AliMpPad pad = seg.PadByIndices(AliMpIntPair(i,j),kFALSE);
164       if ( pad.IsValid() )
165       {
166         l1.Add(new AliMpPad(pad));
167       }
168     }
169   }
170   
171   AliMpArea area(TVector2(0.0,0.0),slat.Dimensions());
172   
173   AliMpVPadIterator* it = seg.CreateIterator(area);
174   
175   it->First();
176     
177   while ( !it->IsDone() )
178   {
179     l2.Add(new AliMpPad(it->CurrentItem()));
180     it->Next();
181   }
182
183   TIter next(&l1);
184   AliMpPad* pad;
185   while ( ( pad = (AliMpPad*)next() ) )
186   {
187     if ( Contains(l2,*pad) != 1)
188     {
189       cout << "The following pad is not found by iterator : " << endl;
190       pad->Print();
191     }
192   }
193   
194   CheckMultiple(l2,slat.GetName(),"iterator");
195
196   CheckMultiple(l1,slat.GetName(),"padByIndices");
197 }
198
199 //______________________________________________________________________________
200 void testSlatPads(const char* slatlist)
201 {
202   ifstream in(slatlist);
203   char line[80];
204   TObjArray slatsToTest;
205   slatsToTest.SetOwner(kTRUE);
206   
207   TStopwatch timerCount;
208   TStopwatch timerIterate;
209   TStopwatch timerCT;
210   
211   timerCount.Start(true); timerCount.Stop();
212   timerIterate.Start(true); timerIterate.Stop();
213   timerCT.Start(true); timerCT.Stop();
214   
215   
216   while ( in.getline(line,80) )
217   {
218     if ( line[0] == '#' ) continue;
219     slatsToTest.AddLast(new TObjString(line));
220   }
221   
222   in.close();
223   
224   AliMpSlatMotifMap mm;
225   AliMpSt345Reader reader(mm);
226   
227   for ( Int_t i = 0; i < slatsToTest.GetEntriesFast(); ++i )
228   {
229     TString slatName( ((TObjString*)slatsToTest[i])->String());
230     
231     AliMpSlat* bending = reader.ReadSlat(slatName.Data(),kBendingPlane);
232     AliMpSlat* nonbending = reader.ReadSlat(slatName.Data(),kNonBendingPlane);
233   
234     timerCount.Start(false);
235     Int_t NumberOfBendingPads = Count(*bending);
236     Int_t NumberOfNonBendingPads = Count(*nonbending);
237     timerCount.Stop();
238     
239     timerIterate.Start(false);
240     Int_t xcheck_b = Iterate(*bending);   
241     Int_t xcheck_nb = Iterate(*nonbending);
242     timerIterate.Stop();
243     
244     timerCT.Start(false);
245     Int_t nc_b = CircularTest(*bending);   
246     Int_t nc_nb = CircularTest(*nonbending);
247     timerCT.Stop();
248     
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 ) 
254     {
255       cout << "OK.";
256     }
257     else
258     {
259       cout << "FAILED.";
260     }
261     cout << endl;
262
263     XCheck(*nonbending);
264     XCheck(*bending);
265
266     if ( xcheck_b != NumberOfBendingPads )
267     {
268       cout << setw(20) << " Bending : HasPad and Iterator give different results !" 
269       << " " << NumberOfBendingPads << " vs " << xcheck_b << endl;
270     }
271     if ( xcheck_nb != NumberOfNonBendingPads )
272     {
273       cout << setw(20) << " NonBending : HasPad and Iterator give different results !"
274       << " " << NumberOfNonBendingPads << " vs " << xcheck_nb << endl;
275     }
276     
277    }
278   
279   cout << "Count : "; 
280   timerCount.Print();
281   cout << "Iterate : ";
282   timerIterate.Print();
283   cout << "CT : ";
284   timerCT.Print();
285   
286 }