Line data Source code
1 : /**************************************************************************
2 : * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 : * *
4 : * Author: The ALICE Off-line Project. *
5 : * Contributors are mentioned in the code where appropriate. *
6 : * *
7 : * Permission to use, copy, modify and distribute this software and its *
8 : * documentation strictly for non-commercial purposes is hereby granted *
9 : * without fee, provided that the above copyright notice appears in all *
10 : * copies and that both the copyright notice and this permission notice *
11 : * appear in the supporting documentation. The authors make no claims *
12 : * about the suitability of this software for any purpose. It is *
13 : * provided "as is" without express or implied warranty. *
14 : **************************************************************************/
15 :
16 : // $Id$
17 : // $MpId: AliMpSlatSegmentation.cxx,v 1.12 2006/05/24 13:58:50 ivana Exp $
18 :
19 : //-----------------------------------------------------------------------------
20 : // Caution !!
21 : // Implementation note.
22 : // The position(s) used in the interface are supposed to be relative
23 : // to the slat center (AliMpSlat::Position()), whereas internally
24 : // the x,y are relative to bottom-left corner.
25 : //-----------------------------------------------------------------------------
26 :
27 : #include "AliMpSlatSegmentation.h"
28 :
29 : #include "AliLog.h"
30 : #include "AliMpArea.h"
31 : #include "AliMpConnection.h"
32 : #include "AliMpConstants.h"
33 : #include "AliLog.h"
34 : #include "AliMpMotif.h"
35 : #include "AliMpMotifPosition.h"
36 : #include "AliMpMotifType.h"
37 : #include "AliMpSlat.h"
38 : #include "AliMpSlatPadIterator.h"
39 : #include "AliMpEncodePair.h"
40 :
41 : /// \cond CLASSIMP
42 18 : ClassImp(AliMpSlatSegmentation)
43 : /// \endcond
44 :
45 : //_____________________________________________________________________________
46 : AliMpSlatSegmentation::AliMpSlatSegmentation()
47 0 : : AliMpVSegmentation(),
48 0 : fkSlat(0),
49 0 : fIsOwner(false)
50 0 : {
51 : ///
52 : /// Default ctor. Not to be used really.
53 : ///
54 0 : AliDebug(1,Form("this=%p Empty ctor",this));
55 0 : }
56 :
57 : //_____________________________________________________________________________
58 : AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlat* slat, Bool_t own)
59 968 : : AliMpVSegmentation(),
60 968 : fkSlat(slat),
61 968 : fIsOwner(own)
62 2904 : {
63 : ///
64 : /// Normal ctor.
65 : ///
66 4840 : AliDebug(1,Form("this=%p Normal ctor slat=%p",this,slat));
67 1936 : }
68 :
69 : //_____________________________________________________________________________
70 : AliMpSlatSegmentation::~AliMpSlatSegmentation()
71 4092 : {
72 : ///
73 : /// Dtor (empty).
74 : ///
75 :
76 1826 : if ( fIsOwner ) delete fkSlat;
77 :
78 : // Int_t i(0);//just to be able to put a breakpoint in gdb
79 3410 : AliDebug(1,Form("this=%p",this));
80 2046 : }
81 :
82 : //_____________________________________________________________________________
83 : AliMpVPadIterator*
84 : AliMpSlatSegmentation::CreateIterator(const AliMpArea& area) const
85 : {
86 : ///
87 : /// Returns an iterator to loop over the pad contained within given area.
88 : ///
89 306 : AliMpArea a(area.GetPositionX()+fkSlat->GetPositionX(),
90 102 : area.GetPositionY()+fkSlat->GetPositionY(),
91 102 : area.GetDimensionX(),
92 102 : area.GetDimensionY());
93 510 : AliDebug(3,Form("Converted input area wrt to slat center : "
94 : "%7.2f,%7.2f->%7.2f,%7.2f to wrt slat lower-left : "
95 : "%7.2f,%7.2f->%7.2f,%7.2f ",
96 : area.LeftBorder(),area.DownBorder(),
97 : area.RightBorder(),area.UpBorder(),
98 : a.LeftBorder(),a.DownBorder(),
99 : a.RightBorder(),a.UpBorder()));
100 :
101 306 : return new AliMpSlatPadIterator(fkSlat,a);
102 102 : }
103 :
104 : //_____________________________________________________________________________
105 : AliMpVPadIterator*
106 : AliMpSlatSegmentation::CreateIterator() const
107 : {
108 : /// Returns an iterator to loop over all pads of that segmentation
109 : ///
110 : /// FIXME: we currently just forward this to the other CreateIterator,
111 : /// with the proper region. Might be more efficient to write a dedicated
112 : /// iterator ? Test that idea.
113 :
114 0 : AliMpArea area(0.0,0.0,fkSlat->DX(),fkSlat->DY());
115 0 : return CreateIterator(area);
116 0 : }
117 :
118 : //_____________________________________________________________________________
119 : Int_t
120 : AliMpSlatSegmentation::GetNeighbours(const AliMpPad& pad,
121 : TObjArray& neighbours,
122 : Bool_t includeSelf,
123 : Bool_t includeVoid) const
124 : {
125 : /// Uses default implementation
126 0 : return AliMpVSegmentation::GetNeighbours(pad,neighbours,includeSelf,includeVoid);
127 : }
128 :
129 : //_____________________________________________________________________________
130 : Double_t
131 : AliMpSlatSegmentation::GetDimensionX() const
132 : {
133 : /// Return slat x dimensions
134 560 : return Slat()->DX();
135 : }
136 :
137 : //_____________________________________________________________________________
138 : Double_t
139 : AliMpSlatSegmentation::GetDimensionY() const
140 : {
141 : /// Return slat y dimensions
142 560 : return Slat()->DY();
143 : }
144 :
145 : //_____________________________________________________________________________
146 : void
147 : AliMpSlatSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
148 : {
149 : /// Fill the array ecn with all manuIds
150 :
151 5268 : Slat()->GetAllMotifPositionsIDs(ecn);
152 2634 : }
153 :
154 : //_____________________________________________________________________________
155 : const char*
156 : AliMpSlatSegmentation::GetName() const
157 : {
158 : /// The name of this segmentation is "SlatSegmentation"+slatName
159 :
160 0 : TString name("SlatSegmentation");
161 0 : if ( fkSlat)
162 : {
163 0 : name += ".";
164 0 : name += fkSlat->GetName();
165 : }
166 0 : return name.Data();
167 0 : }
168 :
169 : //_____________________________________________________________________________
170 : Int_t
171 : AliMpSlatSegmentation::MaxPadIndexX() const
172 : {
173 : ///
174 : /// Returns the value of the largest pad index in x-direction.
175 : ///
176 :
177 2240 : return fkSlat->GetMaxPadIndexX();
178 : }
179 :
180 : //_____________________________________________________________________________
181 : Int_t
182 : AliMpSlatSegmentation::MaxPadIndexY() const
183 : {
184 : ///
185 : /// Returns the value of the largest pad index in y-direction.
186 : ///
187 :
188 2240 : return fkSlat->GetMaxNofPadsY()-1;
189 : }
190 :
191 : //_____________________________________________________________________________
192 : Int_t
193 : AliMpSlatSegmentation::NofPads() const
194 : {
195 : /// Return number of pads defined in the slat
196 :
197 2240 : return fkSlat->NofPads();
198 : }
199 :
200 : //_____________________________________________________________________________
201 : AliMpPad
202 : AliMpSlatSegmentation::PadByLocation(Int_t manuId, Int_t manuChannel,
203 : Bool_t warning) const
204 : {
205 : ///
206 : /// Returns the pad specified by its location, where location is the
207 : /// pair (ManuID,ManuChannel).
208 : /// If warning=kTRUE and the pad does not exist, a warning message is
209 : /// printed.
210 : ///
211 : /// AliMpPad::Invalid() is returned if there's no pad at the given location.
212 : ///
213 617814 : AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(manuId);
214 :
215 617814 : if (!motifPos)
216 : {
217 95533 : if (warning)
218 : {
219 0 : AliWarning(Form("Manu ID %d not found in slat %s",
220 : manuId, fkSlat->GetID()));
221 0 : }
222 95533 : return AliMpPad::Invalid();
223 : }
224 522281 : AliMpVMotif* motif = motifPos->GetMotif();
225 : MpPair_t localIndices =
226 522281 : motif->GetMotifType()->FindLocalIndicesByGassiNum(manuChannel);
227 :
228 522281 : if ( localIndices < 0 )
229 : {
230 19200 : if (warning)
231 : {
232 0 : AliWarning(Form("The pad number %d doesn't exists",
233 : manuChannel));
234 0 : }
235 19200 : return AliMpPad::Invalid();
236 : }
237 :
238 503081 : Double_t posx, posy;
239 503081 : motif->PadPositionLocal(localIndices, posx, posy);
240 503081 : posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
241 503081 : posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
242 :
243 503081 : Double_t dx, dy;
244 503081 : motif->GetPadDimensionsByIndices(localIndices, dx, dy);
245 :
246 503081 : return AliMpPad(manuId, manuChannel,
247 503081 : motifPos->GlobalIndices(localIndices),
248 503081 : posx, posy, dx, dy);
249 1120895 : }
250 :
251 : //_____________________________________________________________________________
252 : AliMpPad
253 : AliMpSlatSegmentation::PadByIndices(Int_t ix, Int_t iy,
254 : Bool_t warning) const
255 : {
256 : ///
257 : /// Returns the pad specified by its integer indices.
258 : /// If warning=kTRUE and the pad does not exist, a warning message is
259 : /// printed.
260 : ///
261 : /// AliMpPad::Invalid() is returned if there's no pad at the given location.
262 : ///
263 : ///
264 : /// FIXME: except for the FindMotifPosition below, this method
265 : /// is exactly as the one in AliMpSectorSegmentation.
266 : /// See if we can merge them somehow.
267 :
268 924622 : AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(ix,iy);
269 :
270 924622 : if (!motifPos)
271 : {
272 126559 : if ( warning )
273 : {
274 0 : AliWarning(Form("No motif found containing pad location (%d,%d)",ix,iy));
275 0 : }
276 126559 : return AliMpPad::Invalid();
277 : }
278 :
279 798063 : AliMpVMotif* motif = motifPos->GetMotif();
280 798063 : AliMpMotifType* motifType = motif->GetMotifType();
281 798063 : MpPair_t localIndices = AliMp::Pair(ix,iy) - motifPos->GetLowIndicesLimit();
282 : AliMpConnection* connection
283 798063 : = motifType->FindConnectionByLocalIndices(localIndices);
284 :
285 798063 : if (!connection)
286 : {
287 0 : if ( warning )
288 : {
289 0 : AliWarning(Form("No connection for pad location (%d,%d)",ix,iy));
290 0 : }
291 0 : return AliMpPad::Invalid();
292 : }
293 :
294 798063 : Double_t posx, posy;
295 798063 : motif->PadPositionLocal(localIndices, posx, posy);
296 798063 : posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
297 798063 : posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
298 :
299 798063 : Double_t dx, dy;
300 798063 : motif->GetPadDimensionsByIndices(localIndices, dx, dy);
301 :
302 1596126 : return AliMpPad(motifPos->GetID(),connection->GetManuChannel(),
303 798063 : ix, iy, posx, posy, dx, dy);
304 1722685 : }
305 :
306 : //_____________________________________________________________________________
307 : AliMpPad
308 : AliMpSlatSegmentation::PadByPosition(Double_t x, Double_t y,
309 : Bool_t warning) const
310 : {
311 : ///
312 : /// Returns the pad specified by its (floating point) position.
313 : /// If warning=kTRUE and the pad does not exist, a warning message is
314 : /// printed.
315 : ///
316 : /// AliMpPad::Invalid() is returned if there's no pad at the given location.
317 : ///
318 :
319 : Double_t blPosX(x);
320 : Double_t blPosY(y);
321 :
322 907 : blPosX += fkSlat->GetPositionX();
323 907 : blPosY += fkSlat->GetPositionY(); // position relative to bottom-left of the slat.
324 :
325 907 : AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(blPosX,blPosY);
326 :
327 907 : if (!motifPos)
328 : {
329 160 : if (warning)
330 : {
331 0 : AliWarning(Form("Slat %s Position (%e,%e)/center (%e,%e)/bottom-left cm "
332 : " outside limits",fkSlat->GetID(),x,y,
333 : blPosX,blPosY));
334 0 : }
335 160 : return AliMpPad::Invalid();
336 : }
337 :
338 747 : AliMpVMotif* motif = motifPos->GetMotif();
339 :
340 747 : blPosX -= motifPos->GetPositionX();
341 747 : blPosY -= motifPos->GetPositionY();
342 747 : MpPair_t localIndices = motif->PadIndicesLocal(blPosX, blPosY);
343 :
344 : AliMpConnection* connect =
345 747 : motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
346 :
347 747 : if (!connect)
348 : {
349 0 : if (warning)
350 : {
351 0 : AliWarning(Form("Slat %s localIndices (%d,%d) outside motif %s limits",
352 : fkSlat->GetID(),AliMp::PairFirst(localIndices),
353 : AliMp::PairSecond(localIndices),motif->GetID().Data()));
354 0 : }
355 0 : return AliMpPad::Invalid();
356 : }
357 :
358 747 : Double_t posx, posy;
359 747 : motif->PadPositionLocal(localIndices, posx, posy);
360 747 : posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
361 747 : posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
362 :
363 747 : Double_t dx, dy;
364 747 : motif->GetPadDimensionsByIndices(localIndices, dx, dy);
365 :
366 1494 : return AliMpPad(motifPos->GetID(),connect->GetManuChannel(),
367 747 : motifPos->GlobalIndices(localIndices),
368 747 : posx, posy, dx, dy);
369 1654 : }
370 :
371 : //_____________________________________________________________________________
372 : AliMp::PlaneType
373 : AliMpSlatSegmentation::PlaneType() const
374 : {
375 898 : return Slat()->PlaneType();
376 : }
377 :
378 : //_____________________________________________________________________________
379 : void
380 : AliMpSlatSegmentation::Print(Option_t* opt) const
381 : {
382 : /// Printing
383 :
384 0 : fkSlat->Print(opt);
385 0 : }
386 :
387 : //_____________________________________________________________________________
388 : const AliMpSlat*
389 : AliMpSlatSegmentation::Slat() const
390 : {
391 : ///
392 : /// Returns the pointer to the referenced slat.
393 : ///
394 :
395 650040 : return fkSlat;
396 : }
397 :
398 : //_____________________________________________________________________________
399 : Bool_t
400 : AliMpSlatSegmentation::HasPadByIndices(Int_t ix, Int_t iy) const
401 : {
402 : /// Tell whether we have a pad at indices=(ix,iy)
403 :
404 0 : AliMpMotifPosition* motifPos = Slat()->FindMotifPosition(ix, iy);
405 :
406 0 : if (motifPos) return motifPos->HasPadByIndices(AliMp::Pair(ix, iy));
407 :
408 0 : return kFALSE;
409 0 : }
410 :
411 : //_____________________________________________________________________________
412 : Bool_t
413 : AliMpSlatSegmentation::HasPadByLocation(Int_t manuId, Int_t manuChannel) const
414 : {
415 : /// Tell whether we have a pad at location=(manuId,manuChannel)
416 :
417 526464 : AliMpMotifPosition* motifPos = Slat()->FindMotifPosition(manuId);
418 :
419 526464 : if ( motifPos ) return motifPos->HasPadByManuChannel(manuChannel);
420 :
421 0 : return kFALSE;
422 263232 : }
423 :
424 :
425 : //_____________________________________________________________________________
426 : Int_t
427 : AliMpSlatSegmentation::GetNofElectronicCards() const
428 : {
429 : /// Get the number of manus of this slat
430 0 : return Slat()->GetNofElectronicCards();
431 :
432 : }
433 :
434 : //_____________________________________________________________________________
435 : Double_t
436 : AliMpSlatSegmentation::GetPositionX() const
437 : {
438 : /// Return x position of slat origin
439 228 : return Slat()->GetPositionX();
440 : }
441 :
442 : //_____________________________________________________________________________
443 : Double_t
444 : AliMpSlatSegmentation::GetPositionY() const
445 : {
446 : /// Return y position of slat origin
447 :
448 228 : return Slat()->GetPositionY();
449 : }
450 :
451 : //_____________________________________________________________________________
452 : Bool_t
453 : AliMpSlatSegmentation::HasMotifPosition(Int_t manuId) const
454 : {
455 : /// Use default implementation
456 0 : return AliMpVSegmentation::HasMotifPosition(manuId);
457 : }
458 :
459 : //_____________________________________________________________________________
460 : AliMpMotifPosition*
461 : AliMpSlatSegmentation::MotifPosition(Int_t manuId) const
462 : {
463 : /// Get back a given manu
464 8226 : return Slat()->FindMotifPosition(manuId);
465 : }
466 :
|