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 "AliMpSlatMotifMap.h"
23 #include "AliMpMotifPosition.h"
24 #include "AliMpMotifSpecial.h"
25 #include "AliMpMotifType.h"
28 #include "Riostream.h"
30 #include "TObjString.h"
37 /// A PCB for station 3,4 or 5
39 /// A PCB is a group of pads having the same size
40 /// Pads are grouped in motifs, where 1 motif = 1 MANU
42 /// The notion of PCB enveloppe is due to the fact that not all PCBs are
43 /// "full" of pads, e.g. the rounded or short ones miss some pads,
44 /// but the enveloppe is a virtual size that should be constant
45 /// across the slats, and is 400x400 mm.
46 /// It's a usefull notion to compute e.g. slat center in a uniform way,
47 /// considering that a slat is N PCBs, of the same "virtual" size, that of
50 /// \author L. Aphecetche
56 //_____________________________________________________________________________
79 fMotifPositions.SetOwner(kTRUE);
81 AliDebug(1,Form("this=%p",this));
84 //_____________________________________________________________________________
85 AliMpPCB::AliMpPCB(AliMpSlatMotifMap* motifMap, const char* id, Double_t padSizeX, Double_t padSizeY,
86 Double_t enveloppeSizeX, Double_t enveloppeSizeY)
91 fEnveloppeSizeX(enveloppeSizeX),
92 fEnveloppeSizeY(enveloppeSizeY),
105 /// Normal ctor. Must be fed with the PCB's name (id), the pad dimensions
106 /// and the global dimension of the virtual enveloppe of the PCB
107 /// (usually 400x400 mm)
109 fMotifPositions.SetOwner(kTRUE);
111 AliDebug(1,Form("this=%p id=%s",this,id));
114 //_____________________________________________________________________________
115 AliMpPCB::AliMpPCB(const AliMpPCB& o)
137 fMotifPositions.SetOwner(kTRUE);
139 AliDebug(1,Form("this=%p (copy ctor) : begin",this));
141 AliDebug(1,Form("this=%p (copy ctor) : end",this));
144 //_____________________________________________________________________________
145 AliMpPCB::AliMpPCB(const char* id, AliMpMotifSpecial* ms)
150 fEnveloppeSizeX(ms->Dimensions().X()*2.0),
151 fEnveloppeSizeY(ms->Dimensions().Y()*2.0),
154 fActiveXmax(fEnveloppeSizeX),
156 fIxmax(ms->GetMotifType()->GetNofPadsX()-1),
158 fIymax(ms->GetMotifType()->GetNofPadsY()-1),
160 fNofPads(ms->GetMotifType()->GetNofPads()),
164 /// Very special ctor to be used by trigger stations only (and for a very
167 /// Note that in this very case, we only allow one (special) motif per PCB.
168 /// This limitation might not be justified, except that it's all we need
172 AliDebug(1,Form("this=%p (ctor special motif)",this));
175 fMotifPositions.SetOwner(kTRUE);
177 TVector2 position(ms->Dimensions());
178 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,ms,position);
179 mp->SetLowIndicesLimit(AliMpIntPair(fIxmin,fIymin));
180 mp->SetHighIndicesLimit(AliMpIntPair(fIxmax,fIymax));
182 fMotifPositions.AddLast(mp);
184 fMotifPositions.push_back(mp);
188 //_____________________________________________________________________________
190 AliMpPCB::operator=(const AliMpPCB& o)
192 /// Assignment operator
194 AliDebug(1,Form("this=%p (assignment op) : begin",this));
196 AliDebug(1,Form("this=%p (assignment op) : end",this));
200 //_____________________________________________________________________________
201 AliMpPCB::~AliMpPCB()
206 AliDebug(1,Form("this=%p",this));
208 for ( size_t i = 0; i < fMotifPositions.size(); ++i )
210 delete fMotifPositions[i];
216 //_____________________________________________________________________________
218 AliMpPCB::ActiveXmin() const
221 /// Returns the mininum x for which there is a pad in this PCB.
222 /// Different from Xmin only for PCB which are not full of pads.
228 //_____________________________________________________________________________
230 AliMpPCB::ActiveXmax() const
233 /// Returns the maximum x for which there is a pad in this PCB.
234 /// Different from Xmax only for PCB which are not full of pads.
240 //_____________________________________________________________________________
242 AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
245 /// Add a motif to this PCB. (ix,iy) indicates one corner position of the motif
246 /// where the sign of ix and iy is used to indicate which corner is the
247 /// reference (then for values, abs(ix) and abs(iy) are used indeed) :
249 /// (ix>0,iy>0) : bottom-left corner
250 /// (ix<0,iy>0) : bottom-right corner
251 /// (ix<0,iy<0) : top-right corner
252 /// (ix>0,iy<0) : top-left corner.
254 TString id(Form("%s-%e-%e",mt->GetID().Data(),PadSizeX(),PadSizeY()));
256 AliMpVMotif* motif = fMotifMap->FindMotif(id);
260 motif = new AliMpMotif(id,mt,TVector2(PadSizeX()/2.0,PadSizeY()/2.0));
261 AliDebug(1,Form("Adding motif %s to motifMap",id.Data()));
262 fMotifMap->AddMotif(motif);
266 AliDebug(1,Form("Got motif %s from motifMap",id.Data()));
273 if ( ix >= 0 && iy >= 0 )
275 position.Set(ix*PadSizeX(),iy*PadSizeY());
280 if ( ix >= 0 && iy < 0 )
282 position.Set(ix*PadSizeX(),Ymax()+iy*PadSizeY());
284 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
287 if ( ix < 0 && iy < 0 )
289 position.Set(Xmax()+ix*PadSizeX(),Ymax()+iy*PadSizeY());
290 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
291 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
294 if ( ix < 0 && iy >=0 )
296 position.Set(Xmax()+ix*PadSizeX(),iy*PadSizeY());
297 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
301 position += motif->Dimensions();
303 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,motif,position);
304 Int_t ixmax = ixmin + mt->GetNofPadsX() - 1;
305 Int_t iymax = iymin + mt->GetNofPadsY() - 1;
307 mp->SetLowIndicesLimit(AliMpIntPair(ixmin,iymin));
308 mp->SetHighIndicesLimit(AliMpIntPair(ixmax,iymax));
311 fMotifPositions.AddLast(mp);
313 fMotifPositions.push_back(mp);
316 fIxmin = TMath::Min(fIxmin,ixmin);
317 fIxmax = TMath::Max(fIxmax,ixmax);
318 fIymin = TMath::Min(fIymin,iymin);
319 fIymax = TMath::Max(fIymax,iymax);
321 fActiveXmin = fIxmin*PadSizeX();
322 fActiveXmax = (fIxmax+1)*PadSizeX();
323 fNofPads += mt->GetNofPads();
326 //_____________________________________________________________________________
328 AliMpPCB::Area() const
330 /// Return the area of this PCB
332 return AliMpArea(TVector2( (Xmin()+Xmax())/2.0,DY()),
333 TVector2( DX(), DY() ) );
336 //_____________________________________________________________________________
338 AliMpPCB::Clone(const char* /*newname*/) const
341 /// Return a full copy of this object.
344 TObject* object = new AliMpPCB(*this);
349 //_____________________________________________________________________________
351 AliMpPCB::Clone(const TArrayI& manuids, Int_t ixOffset, Double_t xOffset) const
354 /// Get a full copy of *this, and then apply 2 changes to it :
356 /// a) define the relationship motifType <-> manu id
357 /// b) define the x-offset
358 /// c) shift ix indices backwards to insure that e.g. the first
359 /// pcb of a slat will start at ix=0 (only relevant for rounded pcbs).
364 // First get a full clone.
365 AliMpPCB* pcb = static_cast<AliMpPCB*>(Clone());
367 if ( Int_t(pcb->GetSize()) != manuids.GetSize() )
369 AliError(Form("Cannot Clone PCB %s because I do not get the correct number of "
370 "manu ids (got %d, wanted %d)",pcb->GetID(),
371 manuids.GetSize(),pcb->GetSize()));
375 AliMpIntPair shift(-fIxmin+ixOffset,0);
377 // Then change the internal MotifPositions wrt manu id
378 // and position (offset in x).
379 for ( Size_t i = 0; i < pcb->GetSize(); ++i )
381 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
382 mp->SetID(manuids[i]);
383 TVector2 pos(mp->Position());
384 pos += TVector2(xOffset,0);
385 mp->SetPosition(pos);
386 AliMpIntPair offset(ixOffset,0);
387 AliMpIntPair low(mp->GetLowIndicesLimit());
389 mp->SetLowIndicesLimit(low);
390 AliMpIntPair high(mp->GetHighIndicesLimit());
392 mp->SetHighIndicesLimit(high);
395 pcb->fIxmin += shift.GetFirst();
396 pcb->fIxmax += shift.GetFirst();
397 pcb->fXoffset = xOffset;
399 pcb->fActiveXmin += xOffset;
400 pcb->fActiveXmax += xOffset;
407 //_____________________________________________________________________________
409 AliMpPCB::Copy(TObject& o) const
411 /// Copy *this into o
416 AliMpPCB& pcb = static_cast<AliMpPCB&>(o);
418 pcb.fPadSizeX = fPadSizeX;
419 pcb.fPadSizeY = fPadSizeY;
420 pcb.fEnveloppeSizeX = fEnveloppeSizeX;
421 pcb.fEnveloppeSizeY = fEnveloppeSizeY;
422 pcb.fXoffset = fXoffset;
427 pcb.fActiveXmin = fActiveXmin;
428 pcb.fActiveXmax = fActiveXmax;
431 AliDebug(1,"Deleting pcb.fMotifPositions");
432 pcb.fMotifPositions.Delete();
433 AliDebug(1,"Deleting pcb.fMotifPositions : done");
435 for ( Size_t i = 0; i < pcb.fMotifPositions.size(); ++i )
437 delete pcb.fMotifPositions[i];
442 for ( Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
444 for ( Size_t i = 0; i < fMotifPositions.size(); ++i )
447 AliMpMotifPosition* pos = (AliMpMotifPosition*)fMotifPositions[i];
448 AliMpMotifPosition* pcbpos = new AliMpMotifPosition(pos->GetID(),
451 pcbpos->SetLowIndicesLimit(pos->GetLowIndicesLimit());
452 pcbpos->SetHighIndicesLimit(pos->GetHighIndicesLimit());
454 pcb.fMotifPositions.AddLast(pcbpos);
456 pcb.fMotifPositions.push_back(pcbpos);
460 pcb.fNofPads = fNofPads;
462 pcb.fMotifMap = fMotifMap; // warning : we do share the motifmap.
467 //_____________________________________________________________________________
469 AliMpPCB::ActiveDX() const
472 /// Half-length (in x-direction) occupied by pads
475 return GetNofPadsX()*fPadSizeX/2.0;
478 //_____________________________________________________________________________
483 /// Half-length (in x-direction) of the PCB.
484 /// This length is the one of the virtual enveloppe of the PCB and might
485 /// be bigger than the length occupied by pads (e.g. for rounded or short
487 /// See also ActiveDX().
490 return fEnveloppeSizeX/2.0;
493 //_____________________________________________________________________________
495 AliMpPCB::ActiveDY() const
498 /// Half-length (in y-direction) occupied by pads
501 return GetNofPadsY()*fPadSizeY/2.0;
504 //_____________________________________________________________________________
509 /// Half-length (in y-direction) of the PCB.
510 /// This length is the one of the virtual enveloppe of the PCB and might
511 /// be bigger than the length occupied by pads (e.g. for rounded or short
513 /// See also ActiveDY().
516 return fEnveloppeSizeY/2.0;
519 //_____________________________________________________________________________
521 AliMpPCB::FindMotifPosition(Int_t ix, Int_t iy) const
524 /// Returns the motifPosition located at the position referenced by
525 /// integer indices (ix,iy).
529 for (Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
531 for (Size_t i = 0; i < fMotifPositions.size(); ++i )
534 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
535 if ( mp->HasPad(AliMpIntPair(ix,iy)) )
543 //_____________________________________________________________________________
545 AliMpPCB::FindMotifPosition(Double_t x, Double_t y) const
548 /// Returns the motifPosition located at position (x,y)
552 for (Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
554 for (Size_t i = 0; i < fMotifPositions.size(); ++i )
557 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
559 TVector2 localPos( TVector2(x,y) - mp->Position() );
561 AliMpIntPair localIndices(mp->GetMotif()->PadIndicesLocal(localPos));
563 if ( localIndices.IsValid() && mp->GetMotif()->GetMotifType()->HasPad(localIndices) )
571 //_____________________________________________________________________________
573 AliMpPCB::GetID() const
576 /// Returns the name of this PCB.
582 //_____________________________________________________________________________
584 AliMpPCB::GetMotifPosition(AliMpPCB::Size_t i) const
587 /// Get the i-th motifPosition stored in this PCB's internal array.
591 if ( i >= fMotifPositions.GetEntriesFast() ) return 0;
593 if ( i >= fMotifPositions.size() ) return 0;
595 return (AliMpMotifPosition*)fMotifPositions[i];
598 //_____________________________________________________________________________
600 AliMpPCB::GetNofPadsX() const
603 /// Returns the number of pads in x-direction.
606 return fIxmax-fIxmin+1;
609 //_____________________________________________________________________________
611 AliMpPCB::GetNofPadsY() const
614 /// Returns the number of pads in y-direction.
617 return fIymax-fIymin+1;
620 //_____________________________________________________________________________
622 AliMpPCB::GetSize() const
625 /// Returns the number of motifPositions stored in this PCB.
629 return fMotifPositions.GetEntriesFast();
631 return fMotifPositions.size();
636 //_____________________________________________________________________________
638 AliMpPCB::Ixmin() const
641 /// Returns the index value of the leftmost pad.
647 //_____________________________________________________________________________
649 AliMpPCB::Ixmax() const
652 /// Returns the index value of the rightmost pad.
655 return Ixmin() + GetNofPadsX() - 1;
658 //_____________________________________________________________________________
660 AliMpPCB::Iymin() const
663 /// Returns the index value of the bottom pad.
669 //_____________________________________________________________________________
671 AliMpPCB::Iymax() const
674 /// Returns the index value of the top pad.
677 return Iymin() + GetNofPadsY() - 1;
680 //_____________________________________________________________________________
682 AliMpPCB::PadSizeX() const
685 /// Returns the pad size in x-direction (in mm)
691 //_____________________________________________________________________________
693 AliMpPCB::PadSizeY() const
696 /// Returns the pad size in y-direction (in mm)
702 //_____________________________________________________________________________
704 AliMpPCB::Print(Option_t* option) const
707 /// Printout of this PCB.
708 /// If option="M", the contained motifs are printed too.
711 cout << "PCB " << GetID() << " PADSIZES=(" << fPadSizeX << ","
712 << fPadSizeY << ") iMin=(" << fIxmin << "," << fIymin << ") "
713 << "iMax=(" << fIxmax << "," << fIymax << ") "
714 << " EnvXmin,max=(" << Xmin() << "," << Xmax()
715 << ") Xmin,max=(" << ActiveXmin() << "," << ActiveXmax() << ")"
718 if ( option && option[0] == 'M' )
721 for ( Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
723 for ( Size_t i = 0; i < fMotifPositions.size(); ++i )
728 fMotifPositions[i]->Print(option+1);
732 fMotifPositions[i]->Print();
738 //_____________________________________________________________________________
740 AliMpPCB::Save() const
743 /// Save this PCB in the file
745 TString fileName(fId);
748 lines.SetOwner(kTRUE);
751 for ( Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
753 for ( Size_t i = 0; i < fMotifPositions.size(); ++i )
756 AliMpMotifPosition* pos = GetMotifPosition(i);
757 AliMpVMotif* motif = pos->GetMotif();
758 TVector2 lowerLeft(pos->Position()-pos->Dimensions());
759 TString id(motif->GetID());
760 // id is supposed to be of the form %s-%e-%e, and we're only
761 // interested in the %s part of it
762 Ssiz_t index = id.Index("-");
765 AliError(Form("id=%s does not meet expectations",id.Data()));
768 TString motifName(id(0,index));
769 lines.Add(new TObjString(Form("MOTIF %s %d %d",
771 TMath::Nint(lowerLeft.X()/fPadSizeX),
772 TMath::Nint(lowerLeft.Y()/fPadSizeY))));
775 ofstream out(fileName.Data());
777 out << "SIZES " << fPadSizeX << " " << fPadSizeY
778 << " " << fEnveloppeSizeX << " " << fEnveloppeSizeY
783 while ( ( s = (TObjString*)next() ) )
785 out << s->String().Data() << endl;
790 //_____________________________________________________________________________
795 /// Returns the x-position of the PCB center.
798 return fXoffset + DX();
801 //_____________________________________________________________________________
803 AliMpPCB::Xmin() const
806 /// Returns the leftmost x-position in this PCB.
812 //_____________________________________________________________________________
814 AliMpPCB::Xmax() const
817 /// Returns the rightmost x-position in this PCB.
823 //_____________________________________________________________________________
828 /// Returns the y-position of the PCB center.
831 return DY(); // this works as PCB are organized in a single row within slats.
834 //_____________________________________________________________________________
836 AliMpPCB::Ymin() const
839 /// Returns the smallest y-position in this PCB.
845 //_____________________________________________________________________________
847 AliMpPCB::Ymax() const
850 /// Returns the largest y-position in this PCB.