1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
17 // $MpId: AliMpSlatSegmentation.cxx,v 1.12 2006/05/24 13:58:50 ivana Exp $
19 //-----------------------------------------------------------------------------
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 //-----------------------------------------------------------------------------
27 #include "AliMpSlatSegmentation.h"
30 #include "AliMpArea.h"
31 #include "AliMpConnection.h"
32 #include "AliMpConstants.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"
42 ClassImp(AliMpSlatSegmentation)
45 //_____________________________________________________________________________
46 AliMpSlatSegmentation::AliMpSlatSegmentation()
47 : AliMpVSegmentation(),
52 /// Default ctor. Not to be used really.
54 AliDebug(1,Form("this=%p Empty ctor",this));
57 //_____________________________________________________________________________
58 AliMpSlatSegmentation::AliMpSlatSegmentation(const AliMpSlat* slat, Bool_t own)
59 : AliMpVSegmentation(),
66 AliDebug(1,Form("this=%p Normal ctor slat=%p",this,slat));
69 //_____________________________________________________________________________
70 AliMpSlatSegmentation::~AliMpSlatSegmentation()
76 if ( fIsOwner ) delete fkSlat;
78 // Int_t i(0);//just to be able to put a breakpoint in gdb
79 AliDebug(1,Form("this=%p",this));
82 //_____________________________________________________________________________
84 AliMpSlatSegmentation::CreateIterator(const AliMpArea& area) const
87 /// Returns an iterator to loop over the pad contained within given area.
89 AliMpArea a(area.GetPositionX()+fkSlat->GetPositionX(),
90 area.GetPositionY()+fkSlat->GetPositionY(),
92 area.GetDimensionY());
93 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()));
101 return new AliMpSlatPadIterator(fkSlat,a);
104 //_____________________________________________________________________________
106 AliMpSlatSegmentation::CreateIterator() const
108 /// Returns an iterator to loop over all pads of that segmentation
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.
114 AliMpArea area(0.0,0.0,fkSlat->DX(),fkSlat->DY());
115 return CreateIterator(area);
118 //_____________________________________________________________________________
120 AliMpSlatSegmentation::GetNeighbours(const AliMpPad& pad,
121 TObjArray& neighbours,
123 Bool_t includeVoid) const
125 /// Uses default implementation
126 return AliMpVSegmentation::GetNeighbours(pad,neighbours,includeSelf,includeVoid);
129 //_____________________________________________________________________________
131 AliMpSlatSegmentation::GetDimensionX() const
133 /// Return slat x dimensions
137 //_____________________________________________________________________________
139 AliMpSlatSegmentation::GetDimensionY() const
141 /// Return slat y dimensions
145 //_____________________________________________________________________________
147 AliMpSlatSegmentation::GetAllElectronicCardIDs(TArrayI& ecn) const
149 /// Fill the array ecn with all manuIds
151 Slat()->GetAllMotifPositionsIDs(ecn);
154 //_____________________________________________________________________________
156 AliMpSlatSegmentation::GetName() const
158 /// The name of this segmentation is "SlatSegmentation"+slatName
160 TString name("SlatSegmentation");
164 name += fkSlat->GetName();
169 //_____________________________________________________________________________
171 AliMpSlatSegmentation::MaxPadIndexX() const
174 /// Returns the value of the largest pad index in x-direction.
177 return fkSlat->GetMaxPadIndexX();
180 //_____________________________________________________________________________
182 AliMpSlatSegmentation::MaxPadIndexY() const
185 /// Returns the value of the largest pad index in y-direction.
188 return fkSlat->GetMaxNofPadsY()-1;
191 //_____________________________________________________________________________
193 AliMpSlatSegmentation::NofPads() const
195 /// Return number of pads defined in the slat
197 return fkSlat->NofPads();
200 //_____________________________________________________________________________
202 AliMpSlatSegmentation::PadByLocation(Int_t manuId, Int_t manuChannel,
203 Bool_t warning) const
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
211 /// AliMpPad::Invalid() is returned if there's no pad at the given location.
213 AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(manuId);
219 AliWarning(Form("Manu ID %d not found in slat %s",
220 manuId, fkSlat->GetID()));
222 return AliMpPad::Invalid();
224 AliMpVMotif* motif = motifPos->GetMotif();
225 MpPair_t localIndices =
226 motif->GetMotifType()->FindLocalIndicesByGassiNum(manuChannel);
228 if ( localIndices < 0 )
232 AliWarning(Form("The pad number %d doesn't exists",
235 return AliMpPad::Invalid();
239 motif->PadPositionLocal(localIndices, posx, posy);
240 posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
241 posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
244 motif->GetPadDimensionsByIndices(localIndices, dx, dy);
246 return AliMpPad(manuId, manuChannel,
247 motifPos->GlobalIndices(localIndices),
251 //_____________________________________________________________________________
253 AliMpSlatSegmentation::PadByIndices(Int_t ix, Int_t iy,
254 Bool_t warning) const
257 /// Returns the pad specified by its integer indices.
258 /// If warning=kTRUE and the pad does not exist, a warning message is
261 /// AliMpPad::Invalid() is returned if there's no pad at the given location.
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.
268 AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(ix,iy);
274 AliWarning(Form("No motif found containing pad location (%d,%d)",ix,iy));
276 return AliMpPad::Invalid();
279 AliMpVMotif* motif = motifPos->GetMotif();
280 AliMpMotifType* motifType = motif->GetMotifType();
281 MpPair_t localIndices = AliMp::Pair(ix,iy) - motifPos->GetLowIndicesLimit();
282 AliMpConnection* connection
283 = motifType->FindConnectionByLocalIndices(localIndices);
289 AliWarning(Form("No connection for pad location (%d,%d)",ix,iy));
291 return AliMpPad::Invalid();
295 motif->PadPositionLocal(localIndices, posx, posy);
296 posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
297 posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
300 motif->GetPadDimensionsByIndices(localIndices, dx, dy);
302 return AliMpPad(motifPos->GetID(),connection->GetManuChannel(),
303 ix, iy, posx, posy, dx, dy);
306 //_____________________________________________________________________________
308 AliMpSlatSegmentation::PadByPosition(Double_t x, Double_t y,
309 Bool_t warning) const
312 /// Returns the pad specified by its (floating point) position.
313 /// If warning=kTRUE and the pad does not exist, a warning message is
316 /// AliMpPad::Invalid() is returned if there's no pad at the given location.
322 blPosX += fkSlat->GetPositionX();
323 blPosY += fkSlat->GetPositionY(); // position relative to bottom-left of the slat.
325 AliMpMotifPosition* motifPos = fkSlat->FindMotifPosition(blPosX,blPosY);
331 AliWarning(Form("Slat %s Position (%e,%e)/center (%e,%e)/bottom-left cm "
332 " outside limits",fkSlat->GetID(),x,y,
335 return AliMpPad::Invalid();
338 AliMpVMotif* motif = motifPos->GetMotif();
340 blPosX -= motifPos->GetPositionX();
341 blPosY -= motifPos->GetPositionY();
342 MpPair_t localIndices = motif->PadIndicesLocal(blPosX, blPosY);
344 AliMpConnection* connect =
345 motif->GetMotifType()->FindConnectionByLocalIndices(localIndices);
351 AliWarning(Form("Slat %s localIndices (%d,%d) outside motif %s limits",
352 fkSlat->GetID(),AliMp::PairFirst(localIndices),
353 AliMp::PairSecond(localIndices),motif->GetID().Data()));
355 return AliMpPad::Invalid();
359 motif->PadPositionLocal(localIndices, posx, posy);
360 posx += motifPos->GetPositionX() - fkSlat->GetPositionX();
361 posy += motifPos->GetPositionY() - fkSlat->GetPositionY();
364 motif->GetPadDimensionsByIndices(localIndices, dx, dy);
366 return AliMpPad(motifPos->GetID(),connect->GetManuChannel(),
367 motifPos->GlobalIndices(localIndices),
371 //_____________________________________________________________________________
373 AliMpSlatSegmentation::PlaneType() const
375 return Slat()->PlaneType();
378 //_____________________________________________________________________________
380 AliMpSlatSegmentation::Print(Option_t* opt) const
387 //_____________________________________________________________________________
389 AliMpSlatSegmentation::Slat() const
392 /// Returns the pointer to the referenced slat.
398 //_____________________________________________________________________________
400 AliMpSlatSegmentation::HasPadByIndices(Int_t ix, Int_t iy) const
402 /// Tell whether we have a pad at indices=(ix,iy)
404 AliMpMotifPosition* motifPos = Slat()->FindMotifPosition(ix, iy);
406 if (motifPos) return motifPos->HasPadByIndices(AliMp::Pair(ix, iy));
411 //_____________________________________________________________________________
413 AliMpSlatSegmentation::HasPadByLocation(Int_t manuId, Int_t manuChannel) const
415 /// Tell whether we have a pad at location=(manuId,manuChannel)
417 AliMpMotifPosition* motifPos = Slat()->FindMotifPosition(manuId);
419 if ( motifPos ) return motifPos->HasPadByManuChannel(manuChannel);
425 //_____________________________________________________________________________
427 AliMpSlatSegmentation::GetNofElectronicCards() const
429 /// Get the number of manus of this slat
430 return Slat()->GetNofElectronicCards();
434 //_____________________________________________________________________________
436 AliMpSlatSegmentation::GetPositionX() const
438 /// Return x position of slat origin
439 return Slat()->GetPositionX();
442 //_____________________________________________________________________________
444 AliMpSlatSegmentation::GetPositionY() const
446 /// Return y position of slat origin
448 return Slat()->GetPositionY();
451 //_____________________________________________________________________________
453 AliMpSlatSegmentation::HasMotifPosition(Int_t manuId) const
455 /// Use default implementation
456 return AliMpVSegmentation::HasMotifPosition(manuId);
459 //_____________________________________________________________________________
461 AliMpSlatSegmentation::MotifPosition(Int_t manuId) const
463 /// Get back a given manu
464 return Slat()->FindMotifPosition(manuId);