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.8 2006/05/24 13:58:50 ivana Exp $
21 #include "AliMpMotif.h"
22 #include "AliMpMotifPosition.h"
23 #include "AliMpMotifSpecial.h"
24 #include "AliMpMotifType.h"
27 #include "Riostream.h"
34 /// A PCB for station 3,4 or 5
36 /// A PCB is a group of pads having the same size
37 /// Pads are grouped in motifs, where 1 motif = 1 MANU
39 /// The notion of PCB enveloppe is due to the fact that not all PCBs are
40 /// "full" of pads, e.g. the rounded or short ones miss some pads,
41 /// but the enveloppe is a virtual size that should be constant
42 /// across the slats, and is 400x400 mm.
43 /// It's a usefull notion to compute e.g. slat center in a uniform way,
44 /// considering that a slat is N PCBs, of the same "virtual" size, that of
47 /// \author L. Aphecetche
53 //_____________________________________________________________________________
76 //_____________________________________________________________________________
77 AliMpPCB::AliMpPCB(const char* id, Double_t padSizeX, Double_t padSizeY,
78 Double_t enveloppeSizeX, Double_t enveloppeSizeY)
83 fEnveloppeSizeX(enveloppeSizeX),
84 fEnveloppeSizeY(enveloppeSizeY),
96 // Normal ctor. Must be fed with the PCB's name (id), the pad dimensions
97 // and the global dimension of the virtual enveloppe of the PCB
98 // (usually 400x400 mm)
101 //_____________________________________________________________________________
102 AliMpPCB::AliMpPCB(const AliMpPCB& o)
122 //_____________________________________________________________________________
123 AliMpPCB::AliMpPCB(const char* id, AliMpMotifSpecial* ms)
128 fEnveloppeSizeX(ms->Dimensions().X()*2.0),
129 fEnveloppeSizeY(ms->Dimensions().Y()*2.0),
132 fActiveXmax(fEnveloppeSizeX),
134 fIxmax(ms->GetMotifType()->GetNofPadsX()-1),
136 fIymax(ms->GetMotifType()->GetNofPadsY()-1),
138 fNofPads(ms->GetMotifType()->GetNofPads())
141 // Very special ctor to be used by trigger stations only (and for a very
144 // Note that in this very case, we only allow one (special) motif per PCB.
145 // This limitation might not be justified, except that it's all we need
149 TVector2 position(ms->Dimensions());
150 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,ms,position);
151 mp->SetLowIndicesLimit(AliMpIntPair(fIxmin,fIymin));
152 mp->SetHighIndicesLimit(AliMpIntPair(fIxmax,fIymax));
156 fMotifs.push_back(mp);
160 //_____________________________________________________________________________
162 AliMpPCB::operator=(const AliMpPCB& o)
168 //_____________________________________________________________________________
169 AliMpPCB::~AliMpPCB()
176 //_____________________________________________________________________________
178 AliMpPCB::ActiveXmin() const
181 // Returns the mininum x for which there is a pad in this PCB.
182 // Different from Xmin only for PCB which are not full of pads.
188 //_____________________________________________________________________________
190 AliMpPCB::ActiveXmax() const
193 // Returns the maximum x for which there is a pad in this PCB.
194 // Different from Xmax only for PCB which are not full of pads.
200 //_____________________________________________________________________________
202 AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
205 // Add a motif to this PCB. (ix,iy) indicates one corner position of the motif
206 // where the sign of ix and iy is used to indicate which corner is the
207 // reference (then for values, abs(ix) and abs(iy) are used indeed) :
209 // (ix>0,iy>0) : bottom-left corner
210 // (ix<0,iy>0) : bottom-right corner
211 // (ix<0,iy<0) : top-right corner
212 // (ix>0,iy<0) : top-left corner.
215 new AliMpMotif(mt->GetID(),mt,TVector2(PadSizeX()/2.0,PadSizeY()/2.0));
220 if ( ix >= 0 && iy >= 0 )
222 position.Set(ix*PadSizeX(),iy*PadSizeY());
227 if ( ix >= 0 && iy < 0 )
229 position.Set(ix*PadSizeX(),Ymax()+iy*PadSizeY());
231 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
234 if ( ix < 0 && iy < 0 )
236 position.Set(Xmax()+ix*PadSizeX(),Ymax()+iy*PadSizeY());
237 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
238 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
241 if ( ix < 0 && iy >=0 )
243 position.Set(Xmax()+ix*PadSizeX(),iy*PadSizeY());
244 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
248 position += motif->Dimensions();
250 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,motif,position);
251 Int_t ixmax = ixmin + mt->GetNofPadsX() - 1;
252 Int_t iymax = iymin + mt->GetNofPadsY() - 1;
254 mp->SetLowIndicesLimit(AliMpIntPair(ixmin,iymin));
255 mp->SetHighIndicesLimit(AliMpIntPair(ixmax,iymax));
260 fMotifs.push_back(mp);
263 fIxmin = std::min(fIxmin,ixmin);
264 fIxmax = std::max(fIxmax,ixmax);
265 fIymin = std::min(fIymin,iymin);
266 fIymax = std::max(fIymax,iymax);
268 fActiveXmin = fIxmin*PadSizeX();
269 fActiveXmax = (fIxmax+1)*PadSizeX();
270 fNofPads += mt->GetNofPads();
273 //_____________________________________________________________________________
275 AliMpPCB::Clone(const char* /*newname*/) const
278 // Return a full copy of this object.
280 return new AliMpPCB(*this);
283 //_____________________________________________________________________________
285 AliMpPCB::Clone(const TArrayI& manuids, Int_t ixOffset, Double_t xOffset) const
288 // Get a full copy of *this, and then apply 2 changes to it :
290 // a) define the relationship motifType <-> manu id
291 // b) define the x-offset
292 // c) shift ix indices backwards to insure that e.g. the first
293 // pcb of a slat will start at ix=0 (only relevant for rounded pcbs).
296 // First get a full clone.
297 AliMpPCB* pcb = static_cast<AliMpPCB*>(Clone());
299 if ( Int_t(pcb->GetSize()) != manuids.GetSize() )
301 AliError(Form("Cannot Clone PCB %s because I do not get the correct number of "
302 "manu ids (got %d, wanted %d)",pcb->GetID(),
303 manuids.GetSize(),pcb->GetSize()));
307 AliMpIntPair shift(-fIxmin,0);
309 // Then change the internal MotifPositions wrt manu id
310 // and position (offset in x).
311 for ( Size_t i = 0; i < pcb->GetSize(); ++i )
313 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
314 mp->SetID(manuids[i]);
315 mp->SetPosition(mp->Position() + TVector2(xOffset,0));
316 mp->SetLowIndicesLimit(mp->GetLowIndicesLimit()+
318 AliMpIntPair(ixOffset,0));
319 mp->SetHighIndicesLimit(mp->GetHighIndicesLimit()+
321 AliMpIntPair(ixOffset,0));
324 pcb->fIxmin += ixOffset + shift.GetFirst();
325 pcb->fIxmax += ixOffset + shift.GetFirst();
326 pcb->fXoffset = xOffset;
328 pcb->fActiveXmin += xOffset;
329 pcb->fActiveXmax += xOffset;
334 //_____________________________________________________________________________
336 AliMpPCB::Copy(TObject& o) const
341 AliMpPCB& pcb = static_cast<AliMpPCB&>(o);
343 pcb.fPadSizeX = fPadSizeX;
344 pcb.fPadSizeY = fPadSizeY;
345 pcb.fEnveloppeSizeX = fEnveloppeSizeX;
346 pcb.fEnveloppeSizeY = fEnveloppeSizeY;
347 pcb.fXoffset = fXoffset;
352 pcb.fActiveXmin = fActiveXmin;
353 pcb.fActiveXmax = fActiveXmax;
362 for ( Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
364 for ( Size_t i = 0; i < fMotifs.size(); ++i )
367 AliMpMotifPosition* pos = (AliMpMotifPosition*)fMotifs[i];
368 AliMpMotifPosition* pcbpos =
369 new AliMpMotifPosition(pos->GetID(),pos->GetMotif(),pos->Position());
370 pcbpos->SetLowIndicesLimit(pos->GetLowIndicesLimit());
371 pcbpos->SetHighIndicesLimit(pos->GetHighIndicesLimit());
373 pcb.fMotifs.AddLast(pcbpos);
375 pcb.fMotifs.push_back(pcbpos);
379 pcb.fNofPads = fNofPads;
382 //_____________________________________________________________________________
384 AliMpPCB::ActiveDX() const
387 // Half-length (in x-direction) occupied by pads
390 return GetNofPadsX()*fPadSizeX/2.0;
393 //_____________________________________________________________________________
398 // Half-length (in x-direction) of the PCB.
399 // This length is the one of the virtual enveloppe of the PCB and might
400 // be bigger than the length occupied by pads (e.g. for rounded or short
402 // See also ActiveDX().
405 return fEnveloppeSizeX/2.0;
408 //_____________________________________________________________________________
410 AliMpPCB::ActiveDY() const
413 // Half-length (in y-direction) occupied by pads
416 return GetNofPadsY()*fPadSizeY/2.0;
419 //_____________________________________________________________________________
424 // Half-length (in y-direction) of the PCB.
425 // This length is the one of the virtual enveloppe of the PCB and might
426 // be bigger than the length occupied by pads (e.g. for rounded or short
428 // See also ActiveDY().
431 return fEnveloppeSizeY/2.0;
434 //_____________________________________________________________________________
436 AliMpPCB::FindMotifPosition(Int_t ix, Int_t iy) const
439 // Returns the motifPosition located at the position referenced by
440 // integer indices (ix,iy).
444 for (Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
446 for (Size_t i = 0; i < fMotifs.size(); ++i )
449 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifs[i];
450 if ( mp->HasPad(AliMpIntPair(ix,iy)) )
458 //_____________________________________________________________________________
460 AliMpPCB::FindMotifPosition(Double_t x, Double_t y) const
463 // Returns the motifPosition located at position (x,y)
467 for (Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
469 for (Size_t i = 0; i < fMotifs.size(); ++i )
472 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifs[i];
474 TVector2 localPos( TVector2(x,y) - mp->Position() );
476 AliMpIntPair localIndices(mp->GetMotif()->PadIndicesLocal(localPos));
478 if ( localIndices.IsValid() && mp->GetMotif()->GetMotifType()->HasPad(localIndices) )
486 //_____________________________________________________________________________
488 AliMpPCB::GetID() const
491 // Returns the name of this PCB.
497 //_____________________________________________________________________________
499 AliMpPCB::GetMotifPosition(AliMpPCB::Size_t i) const
502 // Get the i-th motifPosition stored in this PCB's internal array.
506 if ( i >= fMotifs.GetEntriesFast() ) return 0;
508 if ( i >= fMotifs.size() ) return 0;
510 return (AliMpMotifPosition*)fMotifs[i];
513 //_____________________________________________________________________________
515 AliMpPCB::GetNofPadsX() const
518 // Returns the number of pads in x-direction.
521 return fIxmax-fIxmin+1;
524 //_____________________________________________________________________________
526 AliMpPCB::GetNofPadsY() const
529 // Returns the number of pads in y-direction.
532 return fIymax-fIymin+1;
535 //_____________________________________________________________________________
537 AliMpPCB::GetSize() const
540 // Returns the number of motifPositions stored in this PCB.
544 return fMotifs.GetEntriesFast();
546 return fMotifs.size();
551 //_____________________________________________________________________________
553 AliMpPCB::Ixmin() const
556 // Returns the index value of the leftmost pad.
562 //_____________________________________________________________________________
564 AliMpPCB::Ixmax() const
567 // Returns the index value of the rightmost pad.
570 return Ixmin() + GetNofPadsX() - 1;
573 //_____________________________________________________________________________
575 AliMpPCB::Iymin() const
578 // Returns the index value of the bottom pad.
584 //_____________________________________________________________________________
586 AliMpPCB::Iymax() const
589 // Returns the index value of the top pad.
592 return Iymin() + GetNofPadsY() - 1;
595 //_____________________________________________________________________________
597 AliMpPCB::PadSizeX() const
600 // Returns the pad size in x-direction (in mm)
606 //_____________________________________________________________________________
608 AliMpPCB::PadSizeY() const
611 // Returns the pad size in y-direction (in mm)
617 //_____________________________________________________________________________
619 AliMpPCB::Print(Option_t* option) const
622 // Printout of this PCB.
623 // If option="M", the contained motifs are printed too.
626 cout << "PCB " << GetID() << " PADSIZES=(" << fPadSizeX << ","
627 << fPadSizeY << ") iMin=(" << fIxmin << "," << fIymin << ") "
628 << "iMax=(" << fIxmax << "," << fIymax << ") "
629 << " EnvXmin,max=(" << Xmin() << "," << Xmax()
630 << ") Xmin,max=(" << ActiveXmin() << "," << ActiveXmax() << ")"
633 if ( option && option[0] == 'M' )
636 for ( Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
638 for ( Size_t i = 0; i < fMotifs.size(); ++i )
643 fMotifs[i]->Print(option+1);
653 //_____________________________________________________________________________
658 // Returns the x-position of the PCB center.
661 return fXoffset + DX();
664 //_____________________________________________________________________________
666 AliMpPCB::Xmin() const
669 // Returns the leftmost x-position in this PCB.
675 //_____________________________________________________________________________
677 AliMpPCB::Xmax() const
680 // Returns the rightmost x-position in this PCB.
686 //_____________________________________________________________________________
691 // Returns the y-position of the PCB center.
694 return DY(); // this works as PCB are organized in a single row within slats.
697 //_____________________________________________________________________________
699 AliMpPCB::Ymin() const
702 // Returns the smallest y-position in this PCB.
708 //_____________________________________________________________________________
710 AliMpPCB::Ymax() const
713 // Returns the largest y-position in this PCB.