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.6 2006/03/17 16:42:33 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
51 //_____________________________________________________________________________
54 fPadSizeX(0), fPadSizeY(0),
55 fEnveloppeSizeX(0), fEnveloppeSizeY(0),
57 fActiveXmin(0), fActiveXmax(0),
58 fIxmin(99999), fIxmax(0), fIymin(99999), fIymax(0),
66 //_____________________________________________________________________________
67 AliMpPCB::AliMpPCB(const char* id, Double_t padSizeX, Double_t padSizeY,
68 Double_t enveloppeSizeX, Double_t enveloppeSizeY)
70 fPadSizeX(padSizeX), fPadSizeY(padSizeY),
71 fEnveloppeSizeX(enveloppeSizeX), fEnveloppeSizeY(enveloppeSizeY),
73 fActiveXmin(0), fActiveXmax(0),
74 fIxmin(99999), fIxmax(0), fIymin(99999), fIymax(0),
78 // Normal ctor. Must be fed with the PCB's name (id), the pad dimensions
79 // and the global dimension of the virtual enveloppe of the PCB
80 // (usually 400x400 mm)
83 //_____________________________________________________________________________
84 AliMpPCB::AliMpPCB(const AliMpPCB& o)
86 fPadSizeX(0), fPadSizeY(0),
87 fEnveloppeSizeX(0), fEnveloppeSizeY(0),
89 fActiveXmin(0), fActiveXmax(0),
90 fIxmin(99999), fIxmax(0), fIymin(99999), fIymax(0),
96 //_____________________________________________________________________________
97 AliMpPCB::AliMpPCB(const char* id, AliMpMotifSpecial* ms)
98 : TObject(), fId(id), fPadSizeX(-1.0), fPadSizeY(-1.0),
102 // Very special ctor to be used by trigger stations only (and for a very
105 // Note that in this very case, we only allow one (special) motif per PCB.
106 // This limitation might not be justified, except that it's all we need
110 fEnveloppeSizeX = ms->Dimensions().X()*2.0;
111 fEnveloppeSizeY = ms->Dimensions().Y()*2.0;
113 fActiveXmax = fEnveloppeSizeX;
115 fIxmax = ms->GetMotifType()->GetNofPadsX()-1;
116 fIymax = ms->GetMotifType()->GetNofPadsY()-1;
117 TVector2 position(ms->Dimensions());
118 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,ms,position);
119 mp->SetLowIndicesLimit(AliMpIntPair(fIxmin,fIymin));
120 mp->SetHighIndicesLimit(AliMpIntPair(fIxmax,fIymax));
124 fMotifs.push_back(mp);
126 fNofPads = ms->GetMotifType()->GetNofPads();
129 //_____________________________________________________________________________
131 AliMpPCB::operator=(const AliMpPCB& o)
137 //_____________________________________________________________________________
138 AliMpPCB::~AliMpPCB()
145 //_____________________________________________________________________________
147 AliMpPCB::ActiveXmin() const
150 // Returns the mininum x for which there is a pad in this PCB.
151 // Different from Xmin only for PCB which are not full of pads.
157 //_____________________________________________________________________________
159 AliMpPCB::ActiveXmax() const
162 // Returns the maximum x for which there is a pad in this PCB.
163 // Different from Xmax only for PCB which are not full of pads.
169 //_____________________________________________________________________________
171 AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
174 // Add a motif to this PCB. (ix,iy) indicates one corner position of the motif
175 // where the sign of ix and iy is used to indicate which corner is the
176 // reference (then for values, abs(ix) and abs(iy) are used indeed) :
178 // (ix>0,iy>0) : bottom-left corner
179 // (ix<0,iy>0) : bottom-right corner
180 // (ix<0,iy<0) : top-right corner
181 // (ix>0,iy<0) : top-left corner.
184 new AliMpMotif(mt->GetID(),mt,TVector2(PadSizeX()/2.0,PadSizeY()/2.0));
189 if ( ix >= 0 && iy >= 0 )
191 position.Set(ix*PadSizeX(),iy*PadSizeY());
196 if ( ix >= 0 && iy < 0 )
198 position.Set(ix*PadSizeX(),Ymax()+iy*PadSizeY());
200 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
203 if ( ix < 0 && iy < 0 )
205 position.Set(Xmax()+ix*PadSizeX(),Ymax()+iy*PadSizeY());
206 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
207 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
210 if ( ix < 0 && iy >=0 )
212 position.Set(Xmax()+ix*PadSizeX(),iy*PadSizeY());
213 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
217 position += motif->Dimensions();
219 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,motif,position);
220 Int_t ixmax = ixmin + mt->GetNofPadsX() - 1;
221 Int_t iymax = iymin + mt->GetNofPadsY() - 1;
223 mp->SetLowIndicesLimit(AliMpIntPair(ixmin,iymin));
224 mp->SetHighIndicesLimit(AliMpIntPair(ixmax,iymax));
229 fMotifs.push_back(mp);
232 fIxmin = std::min(fIxmin,ixmin);
233 fIxmax = std::max(fIxmax,ixmax);
234 fIymin = std::min(fIymin,iymin);
235 fIymax = std::max(fIymax,iymax);
237 fActiveXmin = fIxmin*PadSizeX();
238 fActiveXmax = (fIxmax+1)*PadSizeX();
239 fNofPads += mt->GetNofPads();
242 //_____________________________________________________________________________
244 AliMpPCB::Clone(const char* /*newname*/) const
247 // Return a full copy of this object.
249 return new AliMpPCB(*this);
252 //_____________________________________________________________________________
254 AliMpPCB::Clone(const TArrayI& manuids, Int_t ixOffset, Double_t xOffset) const
257 // Get a full copy of *this, and then apply 2 changes to it :
259 // a) define the relationship motifType <-> manu id
260 // b) define the x-offset
261 // c) shift ix indices backwards to insure that e.g. the first
262 // pcb of a slat will start at ix=0 (only relevant for rounded pcbs).
265 // First get a full clone.
266 AliMpPCB* pcb = static_cast<AliMpPCB*>(Clone());
268 if ( Int_t(pcb->GetSize()) != manuids.GetSize() )
270 AliError(Form("Cannot Clone PCB %s because I do not get the correct number of "
271 "manu ids (got %d, wanted %d)",pcb->GetID(),
272 manuids.GetSize(),pcb->GetSize()));
276 AliMpIntPair shift(-fIxmin,0);
278 // Then change the internal MotifPositions wrt manu id
279 // and position (offset in x).
280 for ( Size_t i = 0; i < pcb->GetSize(); ++i )
282 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
283 mp->SetID(manuids[i]);
284 mp->SetPosition(mp->Position() + TVector2(xOffset,0));
285 mp->SetLowIndicesLimit(mp->GetLowIndicesLimit()+
287 AliMpIntPair(ixOffset,0));
288 mp->SetHighIndicesLimit(mp->GetHighIndicesLimit()+
290 AliMpIntPair(ixOffset,0));
293 pcb->fIxmin += ixOffset + shift.GetFirst();
294 pcb->fIxmax += ixOffset + shift.GetFirst();
295 pcb->fXoffset = xOffset;
297 pcb->fActiveXmin += xOffset;
298 pcb->fActiveXmax += xOffset;
303 //_____________________________________________________________________________
305 AliMpPCB::Copy(TObject& o) const
310 AliMpPCB& pcb = static_cast<AliMpPCB&>(o);
312 pcb.fPadSizeX = fPadSizeX;
313 pcb.fPadSizeY = fPadSizeY;
314 pcb.fEnveloppeSizeX = fEnveloppeSizeX;
315 pcb.fEnveloppeSizeY = fEnveloppeSizeY;
316 pcb.fXoffset = fXoffset;
321 pcb.fActiveXmin = fActiveXmin;
322 pcb.fActiveXmax = fActiveXmax;
331 for ( Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
333 for ( Size_t i = 0; i < fMotifs.size(); ++i )
336 AliMpMotifPosition* pos = (AliMpMotifPosition*)fMotifs[i];
337 AliMpMotifPosition* pcbpos =
338 new AliMpMotifPosition(pos->GetID(),pos->GetMotif(),pos->Position());
339 pcbpos->SetLowIndicesLimit(pos->GetLowIndicesLimit());
340 pcbpos->SetHighIndicesLimit(pos->GetHighIndicesLimit());
342 pcb.fMotifs.AddLast(pcbpos);
344 pcb.fMotifs.push_back(pcbpos);
348 pcb.fNofPads = fNofPads;
351 //_____________________________________________________________________________
353 AliMpPCB::ActiveDX() const
356 // Half-length (in x-direction) occupied by pads
359 return GetNofPadsX()*fPadSizeX/2.0;
362 //_____________________________________________________________________________
367 // Half-length (in x-direction) of the PCB.
368 // This length is the one of the virtual enveloppe of the PCB and might
369 // be bigger than the length occupied by pads (e.g. for rounded or short
371 // See also ActiveDX().
374 return fEnveloppeSizeX/2.0;
377 //_____________________________________________________________________________
379 AliMpPCB::ActiveDY() const
382 // Half-length (in y-direction) occupied by pads
385 return GetNofPadsY()*fPadSizeY/2.0;
388 //_____________________________________________________________________________
393 // Half-length (in y-direction) of the PCB.
394 // This length is the one of the virtual enveloppe of the PCB and might
395 // be bigger than the length occupied by pads (e.g. for rounded or short
397 // See also ActiveDY().
400 return fEnveloppeSizeY/2.0;
403 //_____________________________________________________________________________
405 AliMpPCB::FindMotifPosition(Int_t ix, Int_t iy) const
408 // Returns the motifPosition located at the position referenced by
409 // integer indices (ix,iy).
413 for (Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
415 for (Size_t i = 0; i < fMotifs.size(); ++i )
418 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifs[i];
419 if ( mp->HasPad(AliMpIntPair(ix,iy)) )
427 //_____________________________________________________________________________
429 AliMpPCB::FindMotifPosition(Double_t x, Double_t y) const
432 // Returns the motifPosition located at position (x,y)
436 for (Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
438 for (Size_t i = 0; i < fMotifs.size(); ++i )
441 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifs[i];
443 TVector2 localPos( TVector2(x,y) - mp->Position() );
445 AliMpIntPair localIndices(mp->GetMotif()->PadIndicesLocal(localPos));
447 if ( localIndices.IsValid() && mp->GetMotif()->GetMotifType()->HasPad(localIndices) )
455 //_____________________________________________________________________________
457 AliMpPCB::GetID() const
460 // Returns the name of this PCB.
466 //_____________________________________________________________________________
468 AliMpPCB::GetMotifPosition(AliMpPCB::Size_t i) const
471 // Get the i-th motifPosition stored in this PCB's internal array.
475 if ( i >= fMotifs.GetEntriesFast() ) return 0;
477 if ( i >= fMotifs.size() ) return 0;
479 return (AliMpMotifPosition*)fMotifs[i];
482 //_____________________________________________________________________________
484 AliMpPCB::GetNofPadsX() const
487 // Returns the number of pads in x-direction.
490 return fIxmax-fIxmin+1;
493 //_____________________________________________________________________________
495 AliMpPCB::GetNofPadsY() const
498 // Returns the number of pads in y-direction.
501 return fIymax-fIymin+1;
504 //_____________________________________________________________________________
506 AliMpPCB::GetSize() const
509 // Returns the number of motifPositions stored in this PCB.
513 return fMotifs.GetEntriesFast();
515 return fMotifs.size();
520 //_____________________________________________________________________________
522 AliMpPCB::Ixmin() const
525 // Returns the index value of the leftmost pad.
531 //_____________________________________________________________________________
533 AliMpPCB::Ixmax() const
536 // Returns the index value of the rightmost pad.
539 return Ixmin() + GetNofPadsX() - 1;
542 //_____________________________________________________________________________
544 AliMpPCB::Iymin() const
547 // Returns the index value of the bottom pad.
553 //_____________________________________________________________________________
555 AliMpPCB::Iymax() const
558 // Returns the index value of the top pad.
561 return Iymin() + GetNofPadsY() - 1;
564 //_____________________________________________________________________________
566 AliMpPCB::PadSizeX() const
569 // Returns the pad size in x-direction (in mm)
575 //_____________________________________________________________________________
577 AliMpPCB::PadSizeY() const
580 // Returns the pad size in y-direction (in mm)
586 //_____________________________________________________________________________
588 AliMpPCB::Print(Option_t* option) const
591 // Printout of this PCB.
592 // If option="M", the contained motifs are printed too.
595 cout << "PCB " << GetID() << " PADSIZES=(" << fPadSizeX << ","
596 << fPadSizeY << ") iMin=(" << fIxmin << "," << fIymin << ") "
597 << "iMax=(" << fIxmax << "," << fIymax << ") "
598 << " EnvXmin,max=(" << Xmin() << "," << Xmax()
599 << ") Xmin,max=(" << ActiveXmin() << "," << ActiveXmax() << ")"
602 if ( option && option[0] == 'M' )
605 for ( Size_t i = 0; i < fMotifs.GetEntriesFast(); ++i )
607 for ( Size_t i = 0; i < fMotifs.size(); ++i )
612 fMotifs[i]->Print(option+1);
622 //_____________________________________________________________________________
627 // Returns the x-position of the PCB center.
630 return fXoffset + DX();
633 //_____________________________________________________________________________
635 AliMpPCB::Xmin() const
638 // Returns the leftmost x-position in this PCB.
644 //_____________________________________________________________________________
646 AliMpPCB::Xmax() const
649 // Returns the rightmost x-position in this PCB.
655 //_____________________________________________________________________________
660 // Returns the y-position of the PCB center.
663 return DY(); // this works as PCB are organized in a single row within slats.
666 //_____________________________________________________________________________
668 AliMpPCB::Ymin() const
671 // Returns the smallest y-position in this PCB.
677 //_____________________________________________________________________________
679 AliMpPCB::Ymax() const
682 // Returns the largest y-position in this PCB.