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