]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/mapping/AliMpPlaneSegmentation.cxx
mapping/AliMpPlaneSegmentation.cxx
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPlaneSegmentation.cxx
CommitLineData
5f91c9e8 1// $Id$
2// Category: plane
3//
4// Class AliMpPlaneSegmentation
5// ----------------------------
6// Class describing the segmentation of the plane.
7//
8// Transformation of pad characteristics according to sectors:
5f91c9e8 9// I. ( posId, Guassi ), ( i, j), ( x, y) II. | I.
10// II. ( posId', Guassi'), (-i, j), (-x, y) _____ | ____
11// III. (-posId, Guassi), (-i,-j), (-x,-y) |
12// IV. (-posId', Guassi'), ( i,-j), ( x,-y) III. | IV.
13//
14// Where (posId', Guassi') is the location of the pad
15// in the clipped sector.
16//
dbe945cc 17// Included in AliRoot: 2003/05/02
5f91c9e8 18// Authors: David Guez, Ivana Hrivnacova; IPN Orsay
19
20#include <Riostream.h>
21#include <TMath.h>
fb1bf5c0 22#include <TError.h>
5f91c9e8 23
24#include "AliMpPlaneSegmentation.h"
25#include "AliMpPlaneAreaPadIterator.h"
26#include "AliMpPlane.h"
27#include "AliMpSectorPosition.h"
28#include "AliMpSectorSegmentation.h"
29
30ClassImp(AliMpPlaneSegmentation)
31
32//_____________________________________________________________________________
33AliMpPlaneSegmentation::AliMpPlaneSegmentation(const AliMpPlane* plane)
34 : AliMpVSegmentation(),
35 fkPlane(plane),
36 fFrontSectorSegmentation(0),
37 fBackSectorSegmentation(0)
38{
39//
40 fFrontSectorSegmentation = new AliMpSectorSegmentation(plane->GetFrontSector());
41 fBackSectorSegmentation = new AliMpSectorSegmentation(plane->GetBackSector());
42
43 for (Int_t i=0; i<fkPlane->GetNofSectorPositions(); i++) {
f79c58a5 44
45#ifdef WITH_STL
5f91c9e8 46 fTransformers.push_back(
47 new AliMpTransformer(fkPlane->GetSectorPosition(i)->GetOffset(),
48 fkPlane->GetSectorPosition(i)->GetScale()));
f79c58a5 49#endif
50
51#ifdef WITH_ROOT
52 fTransformers.Add(
53 new AliMpTransformer(fkPlane->GetSectorPosition(i)->GetOffset(),
54 fkPlane->GetSectorPosition(i)->GetScale()));
55#endif
56 }
5f91c9e8 57}
58
59///_____________________________________________________________________________
60AliMpPlaneSegmentation::AliMpPlaneSegmentation()
61 : AliMpVSegmentation(),
62 fkPlane(0),
63 fFrontSectorSegmentation(0),
64 fBackSectorSegmentation(0)
65{
66//
67}
68
fb1bf5c0 69//_____________________________________________________________________________
70AliMpPlaneSegmentation::AliMpPlaneSegmentation(
71 const AliMpPlaneSegmentation& right)
72 : AliMpVSegmentation(right) {
73//
74 Fatal("AliMpPlaneSegmentation", "Copy constructor not provided.");
75}
76
5f91c9e8 77//_____________________________________________________________________________
78AliMpPlaneSegmentation::~AliMpPlaneSegmentation() {
79//
80 delete fFrontSectorSegmentation;
81 delete fBackSectorSegmentation;
82
83 for (Int_t i=0; i<GetNofTransformers(); i++)
84 delete GetTransformer(i);
85}
86
fb1bf5c0 87//
88// operators
89//
90
91//_____________________________________________________________________________
92AliMpPlaneSegmentation&
93AliMpPlaneSegmentation::operator=(const AliMpPlaneSegmentation& right)
94{
95 // check assignement to self
96 if (this == &right) return *this;
97
98 Fatal("operator =", "Assignement operator not provided.");
99
100 return *this;
101}
102
5f91c9e8 103//
104// private methods
105//
106
107//_____________________________________________________________________________
108const AliMpTransformer*
109AliMpPlaneSegmentation::GetTransformer(const AliMpIntPair& scale) const
110{
111// Returns the sector position specified by scale.
112// ---
113
f79c58a5 114 for (Int_t i=0; i<GetNofTransformers(); i++)
115 if (GetTransformer(i)->GetScale() == scale) return GetTransformer(i);
5f91c9e8 116
117 Fatal("GetTransformer", "Wrong scale");
118 return 0;
119}
120
121//_____________________________________________________________________________
122AliMpIntPair AliMpPlaneSegmentation::GetScale(const AliMpIntPair& pair) const
123{
124// Returns pair of the signs of the values of the given pair.
125// ---
126
127 AliMpIntPair scale(1, 1);
128
129 if (pair.GetFirst() < 0) scale.SetFirst(-1);
130 if (pair.GetSecond() < 0) scale.SetSecond(-1);
131
132 return scale;
133}
134
135//_____________________________________________________________________________
136AliMpIntPair AliMpPlaneSegmentation::GetScale(const TVector2& vector) const
137{
138// Returns pair of the signs of the values of the given vector.
139// ---
140
141 AliMpIntPair scale(1, 1);
142
143 if (vector.X() < 0) scale.SetFirst(-1);
144 if (vector.Y() < 0) scale.SetSecond(-1);
145
146 return scale;
147}
148
149//_____________________________________________________________________________
150AliMpIntPair
151AliMpPlaneSegmentation::GetLocationScale(const AliMpIntPair& location) const
152{
153// Returns the scale transformation of the specified location.
154// ---
155
156 // Find the sector
157 Bool_t inFront;
158 if (fFrontSectorSegmentation
159 ->HasMotifPosition(TMath::Abs(location.GetFirst())))
160 inFront = true;
161 else if (fBackSectorSegmentation
162 ->HasMotifPosition(TMath::Abs(location.GetFirst())))
163 inFront = false;
164 else {
165 Fatal("GetLocationScale", "Motif position not found.");
166 return AliMpIntPair();
167 }
168
169 if (inFront && location.GetFirst() > 0) return AliMpIntPair(1, 1);
170 else if (inFront && location.GetFirst() < 0) return AliMpIntPair(-1, -1);
171 else if (!inFront && location.GetFirst() > 0) return AliMpIntPair(-1, 1);
172 else if (!inFront && location.GetFirst() < 0) return AliMpIntPair( 1,-1);
173
174 // cannot get there
175 Fatal("GetLocationScale", "Condition failed.");
176 return AliMpIntPair();
177}
178
179
180//_____________________________________________________________________________
181AliMpSectorSegmentation*
182AliMpPlaneSegmentation::GetSectorSegmentation(const AliMpIntPair& scale) const
183{
184// Returns front sector or back sector segmentation
185// according to quadrant specified by scale.
186// ---
187
188 if (scale.GetFirst()*scale.GetSecond() > 0) {
189 // quadrant I or III
190 return fFrontSectorSegmentation;
191 }
192 else {
193 // quadrant II or IV
194 return fBackSectorSegmentation;
195 }
196}
197
198//_____________________________________________________________________________
199AliMpSectorSegmentation*
200AliMpPlaneSegmentation::GetSectorSegmentation(Int_t motifPositionId) const
201{
202// Returns front sector or back sector segmentation
203// according to specified motifPositionId
204// ---
205
206 if (fFrontSectorSegmentation->HasMotifPosition(motifPositionId))
207 return fFrontSectorSegmentation;
208 else if (fBackSectorSegmentation->HasMotifPosition(motifPositionId))
209 return fBackSectorSegmentation;
210 else {
211 Fatal("GetSectorSegmentation", "Motif position not found.");
212 return 0;
213 }
214}
215
216//
217// public methods
218//
219
220//_____________________________________________________________________________
221AliMpVPadIterator*
222AliMpPlaneSegmentation::CreateIterator(const AliMpArea& area) const
223{
224// Creates the are iterator.
225// (The inherited method cannot be used)
226// ---
227
228 return new AliMpPlaneAreaPadIterator(this, area);
229}
230
231//______________________________________________________________________________
232AliMpPad AliMpPlaneSegmentation::PadByLocation(const AliMpIntPair& location,
233 Bool_t warning) const
234{
235// Find the pad which corresponds to the given location
236// ---
237
238 // Get segmentation
239 AliMpSectorSegmentation* segmentation
240 = GetSectorSegmentation(TMath::Abs(location.GetFirst()));
241
242 // Get pad in the segmentation
243 AliMpPad pad
244 = segmentation
245 ->PadByLocation(
b490b812 246 AliMpIntPair(TMath::Abs(location.GetFirst()),location.GetSecond()),
247 warning);
5f91c9e8 248
249 // Get transformation
250 AliMpIntPair scale = GetLocationScale(location);
251 const AliMpTransformer* kTransformer = GetTransformer(scale);
252
253 // Transform pad characteristics
254 return kTransformer->Transform(pad);
255}
256
257//______________________________________________________________________________
258AliMpPad AliMpPlaneSegmentation::PadByIndices (const AliMpIntPair& indices,
259 Bool_t warning ) const
260{
261// Find the pad which corresponds to the given indices
262//
263
264 AliMpIntPair scale = GetScale(indices);
265 const AliMpTransformer* kTransformer = GetTransformer(scale);
266
267 AliMpIntPair scaledIndices = kTransformer->Scale(indices);
268 AliMpPad pad
269 = GetSectorSegmentation(scale)->PadByIndices(scaledIndices, warning);
270
271 return kTransformer->Transform(pad);
272}
273
274//_____________________________________________________________________________
275AliMpPad AliMpPlaneSegmentation::PadByPosition(const TVector2& position,
276 Bool_t warning) const
277{
278// Find the pad which corresponds to the given position
279// ---
280
281 AliMpIntPair scale = GetScale(position);
282 const AliMpTransformer* kTransformer = GetTransformer(scale);
283
284 TVector2 scaledPosition = kTransformer->ITransform(position);
285 AliMpPad pad
286 = GetSectorSegmentation(scale)->PadByPosition(scaledPosition, warning);
287
288 return kTransformer->Transform(pad);
289}
290
580c28fd 291//______________________________________________________________________________
292Int_t AliMpPlaneSegmentation::MaxPadIndexX()
293{
294// Return maximum pad index in x
295
296 Fatal("MaxPadIndexX", " not implemented.");
297
298 return 0;
299}
300
301//______________________________________________________________________________
302Int_t AliMpPlaneSegmentation::MaxPadIndexY()
303{
304// Return maximum pad index in y
305
306 Fatal("MaxPadIndexY", " not implemented.");
307
308 return 0;
309}
310
5f91c9e8 311//_____________________________________________________________________________
312Bool_t AliMpPlaneSegmentation::HasPad(const AliMpIntPair& indices) const
313{
314// Does the pad located by <indices> exists ?
315// ---
316
317 AliMpIntPair scale = GetScale(indices);
318 const AliMpTransformer* kTransformer = GetTransformer(scale);
319
320 AliMpIntPair scaledIndices = kTransformer->Scale(indices);
321
322 return GetSectorSegmentation(scale)->HasPad(scaledIndices);
323}
324
325//_____________________________________________________________________________
326Int_t AliMpPlaneSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
327{
328// Returns the zone index of the zone containing the specified pad.
329// This zone index is different from the zone ID,
330// as it is unique for each pad dimensions.
331// It is composed in this way:
332// sectorID*100 + zoneID*10 + specific index
333// Where sectorID = 0,1 for front/back sector.
334// Specific index is present only for zones containing special motifs.
335// ---
336
337 if (!pad.IsValid()) {
338 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
339 return 0;
340 }
341
342 AliMpIntPair scale = GetScale(pad.GetIndices());
343 const AliMpTransformer* kTransformer = GetTransformer(scale);
344
345 AliMpPad scaledPad = kTransformer->ITransform(pad);
346
347 AliMpSectorSegmentation* segmentation = GetSectorSegmentation(scale);
348 Int_t zoneID = segmentation->Zone(scaledPad, warning);
349
350 // Distinguish zones from front/back sector
351 // For back sector - add 10
352 if (segmentation == fBackSectorSegmentation) zoneID += 100;
353
354 return zoneID;
355}
356
357//_____________________________________________________________________________
358TVector2
359AliMpPlaneSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
360{
361// Returns the pad dimensions for the zone with the specified zone index.
362// ---
363
364 if (zone < 100)
365 return fFrontSectorSegmentation->PadDimensions(zone, warning);
366 else
367 return fBackSectorSegmentation->PadDimensions(zone - 100, warning);
368}
369
370//_____________________________________________________________________________
371Bool_t AliMpPlaneSegmentation::CircleTest(const AliMpIntPair& indices) const
372{
373// Verifies that all methods for retrieving pads are consistents between them.
374// Returns true if the pad with specified indices was found and verified,
375// false otherwise.
376// ---
377
378 if (!HasPad(indices)) return false;
379
380 // Verify the indice->location->position->indice way
381 AliMpIntPair location = PadByIndices(indices).GetLocation();
382 TVector2 position = PadByLocation(location).Position();
383 AliMpIntPair retIndices = PadByPosition(position).GetIndices();
384
385 if (retIndices != indices) {
386 cout << "Pad " << indices << " lead to inconsistency" << endl;
387 cout << "in indice->location->position->indice way..." << endl;
388 cout << "starting from " << indices << "-->" << location << "-->"
389 << '(' << position.X() << ',' << position.Y() << ')'
390 << " and retIndices: " << retIndices << endl;
391 }
392
393
394 // Verify the indice->position->location->indice way
395 position = PadByIndices(indices).Position();
396 location = PadByPosition(position).GetLocation();
397 retIndices = PadByLocation(location).GetIndices();
398
399 if (retIndices != indices) {
400 cout << "Pad " << indices << " lead to inconsistency" << endl;
401 cout << "in indice->position->location->indice way..." <<endl;
402 cout << "starting from " << indices
403 << " and retIndices: " << retIndices << endl;
404 }
405
406 return true;
407
408}
409
410//_____________________________________________________________________________
411Int_t AliMpPlaneSegmentation::GetNofTransformers() const
412{
413// Returns number of transformers.
414// ---
415
f79c58a5 416#ifdef WITH_STL
5f91c9e8 417 return fTransformers.size();
f79c58a5 418#endif
419
420#ifdef WITH_ROOT
421 return fTransformers.GetEntriesFast();
422#endif
5f91c9e8 423}
424
425
426//_____________________________________________________________________________
427AliMpTransformer* AliMpPlaneSegmentation::GetTransformer(Int_t i) const
428{
429// Returns i-th transformer.
430// ---
431
f79c58a5 432#ifdef WITH_STL
5f91c9e8 433 return fTransformers[i];
f79c58a5 434#endif
435
436#ifdef WITH_ROOT
437 return (AliMpTransformer*)fTransformers[i];
438#endif
5f91c9e8 439}
440
441