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: AliMpPCB.cxx,v 1.3 2005/09/19 19:01:31 ivana Exp $
21 #include "AliMpMotif.h"
22 #include "AliMpMotifPosition.h"
23 #include "AliMpMotifType.h"
26 #include "Riostream.h"
31 //_____________________________________________________________________________
34 fPadSizeX(0), fPadSizeY(0),
35 fEnveloppeSizeX(0), fEnveloppeSizeY(0),
37 fActiveXmin(0), fActiveXmax(0),
38 fIxmin(99999), fIxmax(0), fIymin(99999), fIymax(0)
45 //_____________________________________________________________________________
46 AliMpPCB::AliMpPCB(const char* id, Double_t padSizeX, Double_t padSizeY,
47 Double_t enveloppeSizeX, Double_t enveloppeSizeY)
49 fPadSizeX(padSizeX), fPadSizeY(padSizeY),
50 fEnveloppeSizeX(enveloppeSizeX), fEnveloppeSizeY(enveloppeSizeY),
52 fActiveXmin(0), fActiveXmax(0),
53 fIxmin(99999), fIxmax(0), fIymin(99999), fIymax(0)
56 // Normal ctor. Must be fed with the PCB's name (id), the pad dimensions
57 // and the global dimension of the virtual enveloppe of the PCB
58 // (usually 400x400 mm)
61 //_____________________________________________________________________________
62 AliMpPCB::AliMpPCB(const AliMpPCB& o)
64 fPadSizeX(0), fPadSizeY(0),
65 fEnveloppeSizeX(0), fEnveloppeSizeY(0),
67 fActiveXmin(0), fActiveXmax(0),
68 fIxmin(0), fIxmax(0), fIymin(0), fIymax(0)
73 //_____________________________________________________________________________
75 AliMpPCB::operator=(const AliMpPCB& o)
81 //_____________________________________________________________________________
89 //_____________________________________________________________________________
91 AliMpPCB::ActiveXmin() const
94 // Returns the mininum x for which there is a pad in this PCB.
95 // Different from Xmin only for PCB which are not full of pads.
101 //_____________________________________________________________________________
103 AliMpPCB::ActiveXmax() const
106 // Returns the maximum x for which there is a pad in this PCB.
107 // Different from Xmax only for PCB which are not full of pads.
113 //_____________________________________________________________________________
115 AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
118 // Add a motif to this PCB. (ix,iy) is the lower-left position of the motif.
122 new AliMpMotif(mt->GetID(),mt,TVector2(PadSizeX()/2.0,PadSizeY()/2.0));
123 TVector2 position(ix*PadSizeX(),iy*PadSizeY());
124 position += motif->Dimensions();
126 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,motif,position);
129 Int_t ixmax = ix + mt->GetNofPadsX() - 1;
130 Int_t iymax = iy + mt->GetNofPadsY() - 1;
132 mp->SetLowIndicesLimit(AliMpIntPair(ixmin,iymin));
133 mp->SetHighIndicesLimit(AliMpIntPair(ixmax,iymax));
138 fMotifs.push_back(mp);
141 fIxmin = std::min(fIxmin,ixmin);
142 fIxmax = std::max(fIxmax,ixmax);
143 fIymin = std::min(fIymin,iymin);
144 fIymax = std::max(fIymax,iymax);
146 fActiveXmin = fIxmin*PadSizeX();
147 fActiveXmax = (fIxmax+1)*PadSizeX();
150 //_____________________________________________________________________________
152 AliMpPCB::Clone(const char* /*newname*/) const
155 // Return a full copy of this object.
157 return new AliMpPCB(*this);
160 //_____________________________________________________________________________
162 AliMpPCB::Clone(const TArrayI& manuids, Int_t ixOffset, Double_t xOffset) const
165 // Get a full copy of *this, and then apply 2 changes to it :
167 // a) define the relationship motifType <-> manu id
168 // b) define the x-offset
169 // c) shift ix indices backwards to insure that e.g. the first
170 // pcb of a slat will start at ix=0 (only relevant for rounded pcbs).
173 // First get a full clone.
174 AliMpPCB* pcb = static_cast<AliMpPCB*>(Clone());
176 if ( pcb->GetSize() != manuids.GetSize() )
178 AliError(Form("Cannot Clone because I do not get the correct number of "
179 "manu ids (got %d, wanted %d)",
180 manuids.GetSize(),pcb->GetSize()));
184 AliMpIntPair shift(-fIxmin,0);
186 // Then change the internal MotifPositions wrt manu id
187 // and position (offset in x).
188 for ( Size_t i = 0; i < pcb->GetSize(); ++i )
190 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
191 mp->SetID(manuids[i]);
192 mp->SetPosition(mp->Position() + TVector2(xOffset,0));
193 mp->SetLowIndicesLimit(mp->GetLowIndicesLimit()+
195 AliMpIntPair(ixOffset,0));
196 mp->SetHighIndicesLimit(mp->GetHighIndicesLimit()+
198 AliMpIntPair(ixOffset,0));
201 pcb->fIxmin += ixOffset + shift.GetFirst();
202 pcb->fIxmax += ixOffset + shift.GetFirst();
203 pcb->fXoffset = xOffset;
205 pcb->fActiveXmin += xOffset;
206 pcb->fActiveXmax += xOffset;
211 //_____________________________________________________________________________
213 AliMpPCB::Copy(TObject& o) const
216 AliMpPCB& pcb = static_cast<AliMpPCB&>(o);
218 pcb.fPadSizeX = fPadSizeX;
219 pcb.fPadSizeY = fPadSizeY;
220 pcb.fEnveloppeSizeX = fEnveloppeSizeX;
221 pcb.fEnveloppeSizeY = fEnveloppeSizeY;
222 pcb.fXoffset = fXoffset;
227 pcb.fActiveXmin = fActiveXmin;
228 pcb.fActiveXmax = fActiveXmax;
237 for ( Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
239 for ( Size_t i = 0; i < fMotifs.size(); ++i )
242 AliMpMotifPosition* pos = (AliMpMotifPosition*)fMotifs[i];
243 AliMpMotifPosition* pcbpos =
244 new AliMpMotifPosition(pos->GetID(),pos->GetMotif(),pos->Position());
245 pcbpos->SetLowIndicesLimit(pos->GetLowIndicesLimit());
246 pcbpos->SetHighIndicesLimit(pos->GetHighIndicesLimit());
248 pcb.fMotifs.AddLast(pcbpos);
250 pcb.fMotifs.push_back(pcbpos);
255 //_____________________________________________________________________________
257 AliMpPCB::ActiveDX() const
260 // Half-length (in x-direction) occupied by pads
263 return GetNofPadsX()*fPadSizeX/2.0;
266 //_____________________________________________________________________________
271 // Half-length (in x-direction) of the PCB.
272 // This length is the one of the virtual enveloppe of the PCB and might
273 // be bigger than the length occupied by pads (e.g. for rounded or short
275 // See also ActiveDX().
278 return fEnveloppeSizeX/2.0;
281 //_____________________________________________________________________________
283 AliMpPCB::ActiveDY() const
286 // Half-length (in y-direction) occupied by pads
289 return GetNofPadsY()*fPadSizeY/2.0;
292 //_____________________________________________________________________________
297 // Half-length (in y-direction) of the PCB.
298 // This length is the one of the virtual enveloppe of the PCB and might
299 // be bigger than the length occupied by pads (e.g. for rounded or short
301 // See also ActiveDY().
304 return fEnveloppeSizeY/2.0;
307 //_____________________________________________________________________________
309 AliMpPCB::FindMotifPosition(Int_t ix, Int_t iy) const
312 // Returns the motifPosition located at the position referenced by
313 // integer indices (ix,iy).
317 for (Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
319 for (Size_t i = 0; i < fMotifs.size(); ++i )
322 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifs[i];
323 if ( mp->HasPad(AliMpIntPair(ix,iy)) )
331 //_____________________________________________________________________________
333 AliMpPCB::FindMotifPosition(Double_t x, Double_t y) const
336 // Returns the motifPosition located at position (x,y)
340 for (Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
342 for (Size_t i = 0; i < fMotifs.size(); ++i )
345 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifs[i];
347 TVector2 localPos( TVector2(x,y) - mp->Position() );
349 AliMpIntPair localIndices(mp->GetMotif()->PadIndicesLocal(localPos));
351 if ( mp->GetMotif()->GetMotifType()->HasPad(localIndices) )
359 //_____________________________________________________________________________
361 AliMpPCB::GetID() const
364 // Returns the name of this PCB.
370 //_____________________________________________________________________________
372 AliMpPCB::GetMotifPosition(AliMpPCB::Size_t i) const
375 // Get the i-th motifPosition stored in this PCB's internal array.
379 if ( i >= fMotifs.GetEntriesFast() ) return 0;
381 if ( i >= fMotifs.size() ) return 0;
383 return (AliMpMotifPosition*)fMotifs[i];
386 //_____________________________________________________________________________
388 AliMpPCB::GetNofPadsX() const
391 // Returns the number of pads in x-direction.
394 return fIxmax-fIxmin+1;
397 //_____________________________________________________________________________
399 AliMpPCB::GetNofPadsY() const
402 // Returns the number of pads in y-direction.
405 return fIymax-fIymin+1;
408 //_____________________________________________________________________________
410 AliMpPCB::GetSize() const
413 // Returns the number of motifPositions stored in this PCB.
417 return fMotifs.GetEntriesFast();
419 return fMotifs.size();
424 //_____________________________________________________________________________
426 AliMpPCB::Ixmin() const
429 // Returns the index value of the leftmost pad.
435 //_____________________________________________________________________________
437 AliMpPCB::Ixmax() const
440 // Returns the index value of the rightmost pad.
443 return Ixmin() + GetNofPadsX() - 1;
446 //_____________________________________________________________________________
448 AliMpPCB::PadSizeX() const
451 // Returns the pad size in x-direction (in mm)
457 //_____________________________________________________________________________
459 AliMpPCB::PadSizeY() const
462 // Returns the pad size in y-direction (in mm)
468 //_____________________________________________________________________________
470 AliMpPCB::Print(Option_t* option) const
473 // Printout of this PCB.
474 // If option="M", the contained motifs are printed too.
477 cout << "PCB " << GetID() << " PADSIZES=(" << fPadSizeX << ","
478 << fPadSizeY << ") iMin=(" << fIxmin << "," << fIymin << ") "
479 << "iMax=(" << fIxmax << "," << fIymax << ") "
480 << " EnvXmin,max=(" << Xmin() << "," << Xmax()
481 << ") Xmin,max=(" << ActiveXmin() << "," << ActiveXmax() << ")"
484 if ( option && option[0] == 'M' )
487 for ( Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
489 for ( Size_t i = 0; i < fMotifs.size(); ++i )
494 fMotifs[i]->Print(option+1);
504 //_____________________________________________________________________________
509 // Returns the x-position of the PCB center.
512 return fXoffset + DX();
515 //_____________________________________________________________________________
517 AliMpPCB::Xmin() const
520 // Returns the leftmost x-position in this PCB.
526 //_____________________________________________________________________________
528 AliMpPCB::Xmax() const
531 // Returns the rightmost x-position in this PCB.
537 //_____________________________________________________________________________
542 // Returns the y-position of the PCB center.
545 return DY(); // this works as PCB are organized in a single row within slats.
548 //_____________________________________________________________________________
550 AliMpPCB::Ymin() const
553 // Returns the smallest y-position in this PCB.
559 //_____________________________________________________________________________
561 AliMpPCB::Ymax() const
564 // Returns the largest y-position in this PCB.