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>
23 #include "AliMpPlaneSegmentation.h"
24 #include "AliMpPlaneAreaPadIterator.h"
25 #include "AliMpPlane.h"
26 #include "AliMpSectorPosition.h"
27 #include "AliMpSectorSegmentation.h"
29 ClassImp(AliMpPlaneSegmentation)
31 //_____________________________________________________________________________
32 AliMpPlaneSegmentation::AliMpPlaneSegmentation(const AliMpPlane* plane)
33 : AliMpVSegmentation(),
35 fFrontSectorSegmentation(0),
36 fBackSectorSegmentation(0)
39 fFrontSectorSegmentation = new AliMpSectorSegmentation(plane->GetFrontSector());
40 fBackSectorSegmentation = new AliMpSectorSegmentation(plane->GetBackSector());
42 for (Int_t i=0; i<fkPlane->GetNofSectorPositions(); i++) {
45 fTransformers.push_back(
46 new AliMpTransformer(fkPlane->GetSectorPosition(i)->GetOffset(),
47 fkPlane->GetSectorPosition(i)->GetScale()));
52 new AliMpTransformer(fkPlane->GetSectorPosition(i)->GetOffset(),
53 fkPlane->GetSectorPosition(i)->GetScale()));
58 ///_____________________________________________________________________________
59 AliMpPlaneSegmentation::AliMpPlaneSegmentation()
60 : AliMpVSegmentation(),
62 fFrontSectorSegmentation(0),
63 fBackSectorSegmentation(0)
68 //_____________________________________________________________________________
69 AliMpPlaneSegmentation::~AliMpPlaneSegmentation() {
71 delete fFrontSectorSegmentation;
72 delete fBackSectorSegmentation;
74 for (Int_t i=0; i<GetNofTransformers(); i++)
75 delete GetTransformer(i);
82 //_____________________________________________________________________________
83 const AliMpTransformer*
84 AliMpPlaneSegmentation::GetTransformer(const AliMpIntPair& scale) const
86 // Returns the sector position specified by scale.
89 for (Int_t i=0; i<GetNofTransformers(); i++)
90 if (GetTransformer(i)->GetScale() == scale) return GetTransformer(i);
92 Fatal("GetTransformer", "Wrong scale");
96 //_____________________________________________________________________________
97 AliMpIntPair AliMpPlaneSegmentation::GetScale(const AliMpIntPair& pair) const
99 // Returns pair of the signs of the values of the given pair.
102 AliMpIntPair scale(1, 1);
104 if (pair.GetFirst() < 0) scale.SetFirst(-1);
105 if (pair.GetSecond() < 0) scale.SetSecond(-1);
110 //_____________________________________________________________________________
111 AliMpIntPair AliMpPlaneSegmentation::GetScale(const TVector2& vector) const
113 // Returns pair of the signs of the values of the given vector.
116 AliMpIntPair scale(1, 1);
118 if (vector.X() < 0) scale.SetFirst(-1);
119 if (vector.Y() < 0) scale.SetSecond(-1);
124 //_____________________________________________________________________________
126 AliMpPlaneSegmentation::GetLocationScale(const AliMpIntPair& location) const
128 // Returns the scale transformation of the specified location.
133 if (fFrontSectorSegmentation
134 ->HasMotifPosition(TMath::Abs(location.GetFirst())))
136 else if (fBackSectorSegmentation
137 ->HasMotifPosition(TMath::Abs(location.GetFirst())))
140 Fatal("GetLocationScale", "Motif position not found.");
141 return AliMpIntPair();
144 if (inFront && location.GetFirst() > 0) return AliMpIntPair(1, 1);
145 else if (inFront && location.GetFirst() < 0) return AliMpIntPair(-1, -1);
146 else if (!inFront && location.GetFirst() > 0) return AliMpIntPair(-1, 1);
147 else if (!inFront && location.GetFirst() < 0) return AliMpIntPair( 1,-1);
150 Fatal("GetLocationScale", "Condition failed.");
151 return AliMpIntPair();
155 //_____________________________________________________________________________
156 AliMpSectorSegmentation*
157 AliMpPlaneSegmentation::GetSectorSegmentation(const AliMpIntPair& scale) const
159 // Returns front sector or back sector segmentation
160 // according to quadrant specified by scale.
163 if (scale.GetFirst()*scale.GetSecond() > 0) {
165 return fFrontSectorSegmentation;
169 return fBackSectorSegmentation;
173 //_____________________________________________________________________________
174 AliMpSectorSegmentation*
175 AliMpPlaneSegmentation::GetSectorSegmentation(Int_t motifPositionId) const
177 // Returns front sector or back sector segmentation
178 // according to specified motifPositionId
181 if (fFrontSectorSegmentation->HasMotifPosition(motifPositionId))
182 return fFrontSectorSegmentation;
183 else if (fBackSectorSegmentation->HasMotifPosition(motifPositionId))
184 return fBackSectorSegmentation;
186 Fatal("GetSectorSegmentation", "Motif position not found.");
195 //_____________________________________________________________________________
197 AliMpPlaneSegmentation::CreateIterator(const AliMpArea& area) const
199 // Creates the are iterator.
200 // (The inherited method cannot be used)
203 return new AliMpPlaneAreaPadIterator(this, area);
206 //______________________________________________________________________________
207 AliMpPad AliMpPlaneSegmentation::PadByLocation(const AliMpIntPair& location,
208 Bool_t warning) const
210 // Find the pad which corresponds to the given location
214 AliMpSectorSegmentation* segmentation
215 = GetSectorSegmentation(TMath::Abs(location.GetFirst()));
217 // Get pad in the segmentation
221 AliMpIntPair(TMath::Abs(location.GetFirst()),location.GetSecond()),
224 // Get transformation
225 AliMpIntPair scale = GetLocationScale(location);
226 const AliMpTransformer* kTransformer = GetTransformer(scale);
228 // Transform pad characteristics
229 return kTransformer->Transform(pad);
232 //______________________________________________________________________________
233 AliMpPad AliMpPlaneSegmentation::PadByIndices (const AliMpIntPair& indices,
234 Bool_t warning ) const
236 // Find the pad which corresponds to the given indices
239 AliMpIntPair scale = GetScale(indices);
240 const AliMpTransformer* kTransformer = GetTransformer(scale);
242 AliMpIntPair scaledIndices = kTransformer->Scale(indices);
244 = GetSectorSegmentation(scale)->PadByIndices(scaledIndices, warning);
246 return kTransformer->Transform(pad);
249 //_____________________________________________________________________________
250 AliMpPad AliMpPlaneSegmentation::PadByPosition(const TVector2& position,
251 Bool_t warning) const
253 // Find the pad which corresponds to the given position
256 AliMpIntPair scale = GetScale(position);
257 const AliMpTransformer* kTransformer = GetTransformer(scale);
259 TVector2 scaledPosition = kTransformer->ITransform(position);
261 = GetSectorSegmentation(scale)->PadByPosition(scaledPosition, warning);
263 return kTransformer->Transform(pad);
266 //_____________________________________________________________________________
267 Bool_t AliMpPlaneSegmentation::HasPad(const AliMpIntPair& indices) const
269 // Does the pad located by <indices> exists ?
272 AliMpIntPair scale = GetScale(indices);
273 const AliMpTransformer* kTransformer = GetTransformer(scale);
275 AliMpIntPair scaledIndices = kTransformer->Scale(indices);
277 return GetSectorSegmentation(scale)->HasPad(scaledIndices);
280 //_____________________________________________________________________________
281 Int_t AliMpPlaneSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
283 // Returns the zone index of the zone containing the specified pad.
284 // This zone index is different from the zone ID,
285 // as it is unique for each pad dimensions.
286 // It is composed in this way:
287 // sectorID*100 + zoneID*10 + specific index
288 // Where sectorID = 0,1 for front/back sector.
289 // Specific index is present only for zones containing special motifs.
292 if (!pad.IsValid()) {
293 if (warning) Warning("Zone(AliMpPad)", "Invalid pad");
297 AliMpIntPair scale = GetScale(pad.GetIndices());
298 const AliMpTransformer* kTransformer = GetTransformer(scale);
300 AliMpPad scaledPad = kTransformer->ITransform(pad);
302 AliMpSectorSegmentation* segmentation = GetSectorSegmentation(scale);
303 Int_t zoneID = segmentation->Zone(scaledPad, warning);
305 // Distinguish zones from front/back sector
306 // For back sector - add 10
307 if (segmentation == fBackSectorSegmentation) zoneID += 100;
312 //_____________________________________________________________________________
314 AliMpPlaneSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
316 // Returns the pad dimensions for the zone with the specified zone index.
320 return fFrontSectorSegmentation->PadDimensions(zone, warning);
322 return fBackSectorSegmentation->PadDimensions(zone - 100, warning);
325 //_____________________________________________________________________________
326 Bool_t AliMpPlaneSegmentation::CircleTest(const AliMpIntPair& indices) const
328 // Verifies that all methods for retrieving pads are consistents between them.
329 // Returns true if the pad with specified indices was found and verified,
333 if (!HasPad(indices)) return false;
335 // Verify the indice->location->position->indice way
336 AliMpIntPair location = PadByIndices(indices).GetLocation();
337 TVector2 position = PadByLocation(location).Position();
338 AliMpIntPair retIndices = PadByPosition(position).GetIndices();
340 if (retIndices != indices) {
341 cout << "Pad " << indices << " lead to inconsistency" << endl;
342 cout << "in indice->location->position->indice way..." << endl;
343 cout << "starting from " << indices << "-->" << location << "-->"
344 << '(' << position.X() << ',' << position.Y() << ')'
345 << " and retIndices: " << retIndices << endl;
349 // Verify the indice->position->location->indice way
350 position = PadByIndices(indices).Position();
351 location = PadByPosition(position).GetLocation();
352 retIndices = PadByLocation(location).GetIndices();
354 if (retIndices != indices) {
355 cout << "Pad " << indices << " lead to inconsistency" << endl;
356 cout << "in indice->position->location->indice way..." <<endl;
357 cout << "starting from " << indices
358 << " and retIndices: " << retIndices << endl;
365 //_____________________________________________________________________________
366 Int_t AliMpPlaneSegmentation::GetNofTransformers() const
368 // Returns number of transformers.
372 return fTransformers.size();
376 return fTransformers.GetEntriesFast();
381 //_____________________________________________________________________________
382 AliMpTransformer* AliMpPlaneSegmentation::GetTransformer(Int_t i) const
384 // Returns i-th transformer.
388 return fTransformers[i];
392 return (AliMpTransformer*)fTransformers[i];