4 // Class AliMpPlaneSegmentation
5 // ----------------------------
6 // Class describing the segmentation of the plane.
8 // Transformation of pad characteristics according to sectors:
10 // I. ( posId, Guassi ), ( i, j), ( x, y) II. | I.
11 // II. ( posId', Guassi'), (-i, j), (-x, y) _____ | ____
12 // III. (-posId, Guassi), (-i,-j), (-x,-y) |
13 // IV. (-posId', Guassi'), ( i,-j), ( x,-y) III. | IV.
15 // Where (posId', Guassi') is the location of the pad
16 // in the clipped sector.
18 // Authors: David Guez, Ivana Hrivnacova; IPN Orsay
20 #include <Riostream.h>
24 #include "AliMpPlaneSegmentation.h"
25 #include "AliMpPlaneAreaPadIterator.h"
26 #include "AliMpPlane.h"
27 #include "AliMpSectorPosition.h"
28 #include "AliMpSectorSegmentation.h"
30 ClassImp(AliMpPlaneSegmentation)
32 //_____________________________________________________________________________
33 AliMpPlaneSegmentation::AliMpPlaneSegmentation(const AliMpPlane* plane)
34 : AliMpVSegmentation(),
36 fFrontSectorSegmentation(0),
37 fBackSectorSegmentation(0)
40 fFrontSectorSegmentation = new AliMpSectorSegmentation(plane->GetFrontSector());
41 fBackSectorSegmentation = new AliMpSectorSegmentation(plane->GetBackSector());
43 for (Int_t i=0; i<fkPlane->GetNofSectorPositions(); i++) {
46 fTransformers.push_back(
47 new AliMpTransformer(fkPlane->GetSectorPosition(i)->GetOffset(),
48 fkPlane->GetSectorPosition(i)->GetScale()));
53 new AliMpTransformer(fkPlane->GetSectorPosition(i)->GetOffset(),
54 fkPlane->GetSectorPosition(i)->GetScale()));
59 ///_____________________________________________________________________________
60 AliMpPlaneSegmentation::AliMpPlaneSegmentation()
61 : AliMpVSegmentation(),
63 fFrontSectorSegmentation(0),
64 fBackSectorSegmentation(0)
69 //_____________________________________________________________________________
70 AliMpPlaneSegmentation::AliMpPlaneSegmentation(
71 const AliMpPlaneSegmentation& right)
72 : AliMpVSegmentation(right) {
74 Fatal("AliMpPlaneSegmentation", "Copy constructor not provided.");
77 //_____________________________________________________________________________
78 AliMpPlaneSegmentation::~AliMpPlaneSegmentation() {
80 delete fFrontSectorSegmentation;
81 delete fBackSectorSegmentation;
83 for (Int_t i=0; i<GetNofTransformers(); i++)
84 delete GetTransformer(i);
91 //_____________________________________________________________________________
92 AliMpPlaneSegmentation&
93 AliMpPlaneSegmentation::operator=(const AliMpPlaneSegmentation& right)
95 // check assignement to self
96 if (this == &right) return *this;
98 Fatal("operator =", "Assignement operator not provided.");
107 //_____________________________________________________________________________
108 const AliMpTransformer*
109 AliMpPlaneSegmentation::GetTransformer(const AliMpIntPair& scale) const
111 // Returns the sector position specified by scale.
114 for (Int_t i=0; i<GetNofTransformers(); i++)
115 if (GetTransformer(i)->GetScale() == scale) return GetTransformer(i);
117 Fatal("GetTransformer", "Wrong scale");
121 //_____________________________________________________________________________
122 AliMpIntPair AliMpPlaneSegmentation::GetScale(const AliMpIntPair& pair) const
124 // Returns pair of the signs of the values of the given pair.
127 AliMpIntPair scale(1, 1);
129 if (pair.GetFirst() < 0) scale.SetFirst(-1);
130 if (pair.GetSecond() < 0) scale.SetSecond(-1);
135 //_____________________________________________________________________________
136 AliMpIntPair AliMpPlaneSegmentation::GetScale(const TVector2& vector) const
138 // Returns pair of the signs of the values of the given vector.
141 AliMpIntPair scale(1, 1);
143 if (vector.X() < 0) scale.SetFirst(-1);
144 if (vector.Y() < 0) scale.SetSecond(-1);
149 //_____________________________________________________________________________
151 AliMpPlaneSegmentation::GetLocationScale(const AliMpIntPair& location) const
153 // Returns the scale transformation of the specified location.
158 if (fFrontSectorSegmentation
159 ->HasMotifPosition(TMath::Abs(location.GetFirst())))
161 else if (fBackSectorSegmentation
162 ->HasMotifPosition(TMath::Abs(location.GetFirst())))
165 Fatal("GetLocationScale", "Motif position not found.");
166 return AliMpIntPair();
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);
175 Fatal("GetLocationScale", "Condition failed.");
176 return AliMpIntPair();
180 //_____________________________________________________________________________
181 AliMpSectorSegmentation*
182 AliMpPlaneSegmentation::GetSectorSegmentation(const AliMpIntPair& scale) const
184 // Returns front sector or back sector segmentation
185 // according to quadrant specified by scale.
188 if (scale.GetFirst()*scale.GetSecond() > 0) {
190 return fFrontSectorSegmentation;
194 return fBackSectorSegmentation;
198 //_____________________________________________________________________________
199 AliMpSectorSegmentation*
200 AliMpPlaneSegmentation::GetSectorSegmentation(Int_t motifPositionId) const
202 // Returns front sector or back sector segmentation
203 // according to specified motifPositionId
206 if (fFrontSectorSegmentation->HasMotifPosition(motifPositionId))
207 return fFrontSectorSegmentation;
208 else if (fBackSectorSegmentation->HasMotifPosition(motifPositionId))
209 return fBackSectorSegmentation;
211 Fatal("GetSectorSegmentation", "Motif position not found.");
220 //_____________________________________________________________________________
222 AliMpPlaneSegmentation::CreateIterator(const AliMpArea& area) const
224 // Creates the are iterator.
225 // (The inherited method cannot be used)
228 return new AliMpPlaneAreaPadIterator(this, area);
231 //______________________________________________________________________________
232 AliMpPad AliMpPlaneSegmentation::PadByLocation(const AliMpIntPair& location,
233 Bool_t warning) const
235 // Find the pad which corresponds to the given location
239 AliMpSectorSegmentation* segmentation
240 = GetSectorSegmentation(TMath::Abs(location.GetFirst()));
242 // Get pad in the segmentation
246 AliMpIntPair(TMath::Abs(location.GetFirst()),location.GetSecond()),
249 // Get transformation
250 AliMpIntPair scale = GetLocationScale(location);
251 const AliMpTransformer* kTransformer = GetTransformer(scale);
253 // Transform pad characteristics
254 return kTransformer->Transform(pad);
257 //______________________________________________________________________________
258 AliMpPad AliMpPlaneSegmentation::PadByIndices (const AliMpIntPair& indices,
259 Bool_t warning ) const
261 // Find the pad which corresponds to the given indices
264 AliMpIntPair scale = GetScale(indices);
265 const AliMpTransformer* kTransformer = GetTransformer(scale);
267 AliMpIntPair scaledIndices = kTransformer->Scale(indices);
269 = GetSectorSegmentation(scale)->PadByIndices(scaledIndices, warning);
271 return kTransformer->Transform(pad);
274 //_____________________________________________________________________________
275 AliMpPad AliMpPlaneSegmentation::PadByPosition(const TVector2& position,
276 Bool_t warning) const
278 // Find the pad which corresponds to the given position
281 AliMpIntPair scale = GetScale(position);
282 const AliMpTransformer* kTransformer = GetTransformer(scale);
284 TVector2 scaledPosition = kTransformer->ITransform(position);
286 = GetSectorSegmentation(scale)->PadByPosition(scaledPosition, warning);
288 return kTransformer->Transform(pad);
291 //_____________________________________________________________________________
292 Bool_t AliMpPlaneSegmentation::HasPad(const AliMpIntPair& indices) const
294 // Does the pad located by <indices> exists ?
297 AliMpIntPair scale = GetScale(indices);
298 const AliMpTransformer* kTransformer = GetTransformer(scale);
300 AliMpIntPair scaledIndices = kTransformer->Scale(indices);
302 return GetSectorSegmentation(scale)->HasPad(scaledIndices);
305 //_____________________________________________________________________________
306 Int_t AliMpPlaneSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
308 // Returns the zone index of the zone containing the specified pad.
309 // This zone index is different from the zone ID,
310 // as it is unique for each pad dimensions.
311 // It is composed in this way:
312 // sectorID*100 + zoneID*10 + specific index
313 // Where sectorID = 0,1 for front/back sector.
314 // Specific index is present only for zones containing special motifs.
317 if (!pad.IsValid()) {
318 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
322 AliMpIntPair scale = GetScale(pad.GetIndices());
323 const AliMpTransformer* kTransformer = GetTransformer(scale);
325 AliMpPad scaledPad = kTransformer->ITransform(pad);
327 AliMpSectorSegmentation* segmentation = GetSectorSegmentation(scale);
328 Int_t zoneID = segmentation->Zone(scaledPad, warning);
330 // Distinguish zones from front/back sector
331 // For back sector - add 10
332 if (segmentation == fBackSectorSegmentation) zoneID += 100;
337 //_____________________________________________________________________________
339 AliMpPlaneSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
341 // Returns the pad dimensions for the zone with the specified zone index.
345 return fFrontSectorSegmentation->PadDimensions(zone, warning);
347 return fBackSectorSegmentation->PadDimensions(zone - 100, warning);
350 //_____________________________________________________________________________
351 Bool_t AliMpPlaneSegmentation::CircleTest(const AliMpIntPair& indices) const
353 // Verifies that all methods for retrieving pads are consistents between them.
354 // Returns true if the pad with specified indices was found and verified,
358 if (!HasPad(indices)) return false;
360 // Verify the indice->location->position->indice way
361 AliMpIntPair location = PadByIndices(indices).GetLocation();
362 TVector2 position = PadByLocation(location).Position();
363 AliMpIntPair retIndices = PadByPosition(position).GetIndices();
365 if (retIndices != indices) {
366 cout << "Pad " << indices << " lead to inconsistency" << endl;
367 cout << "in indice->location->position->indice way..." << endl;
368 cout << "starting from " << indices << "-->" << location << "-->"
369 << '(' << position.X() << ',' << position.Y() << ')'
370 << " and retIndices: " << retIndices << endl;
374 // Verify the indice->position->location->indice way
375 position = PadByIndices(indices).Position();
376 location = PadByPosition(position).GetLocation();
377 retIndices = PadByLocation(location).GetIndices();
379 if (retIndices != indices) {
380 cout << "Pad " << indices << " lead to inconsistency" << endl;
381 cout << "in indice->position->location->indice way..." <<endl;
382 cout << "starting from " << indices
383 << " and retIndices: " << retIndices << endl;
390 //_____________________________________________________________________________
391 Int_t AliMpPlaneSegmentation::GetNofTransformers() const
393 // Returns number of transformers.
397 return fTransformers.size();
401 return fTransformers.GetEntriesFast();
406 //_____________________________________________________________________________
407 AliMpTransformer* AliMpPlaneSegmentation::GetTransformer(Int_t i) const
409 // Returns i-th transformer.
413 return fTransformers[i];
417 return (AliMpTransformer*)fTransformers[i];