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"
35 //-----------------------------------------------------------------------------
38 /// A PCB for station 3,4 or 5
40 /// A PCB is a group of pads having the same size
41 /// Pads are grouped in motifs, where 1 motif = 1 MANU
43 /// The notion of PCB enveloppe is due to the fact that not all PCBs are
44 /// "full" of pads, e.g. the rounded or short ones miss some pads,
45 /// but the enveloppe is a virtual size that should be constant
46 /// across the slats, and is 400x400 mm.
47 /// It's a usefull notion to compute e.g. slat center in a uniform way,
48 /// considering that a slat is N PCBs, of the same "virtual" size, that of
51 /// \author L. Aphecetche
52 //-----------------------------------------------------------------------------
58 //_____________________________________________________________________________
80 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)
108 fMotifPositions.SetOwner(kTRUE);
109 AliDebug(1,Form("this=%p id=%s",this,id));
112 //_____________________________________________________________________________
113 AliMpPCB::AliMpPCB(const AliMpPCB& o)
134 fMotifPositions.SetOwner(kTRUE);
136 AliDebug(1,Form("this=%p (copy ctor) : begin",this));
138 AliDebug(1,Form("this=%p (copy ctor) : end",this));
141 //_____________________________________________________________________________
142 AliMpPCB::AliMpPCB(const char* id, AliMpMotifSpecial* ms)
147 fEnveloppeSizeX(ms->Dimensions().X()*2.0),
148 fEnveloppeSizeY(ms->Dimensions().Y()*2.0),
151 fActiveXmax(fEnveloppeSizeX),
153 fIxmax(ms->GetMotifType()->GetNofPadsX()-1),
155 fIymax(ms->GetMotifType()->GetNofPadsY()-1),
157 fNofPads(ms->GetMotifType()->GetNofPads()),
161 /// Very special ctor to be used by trigger stations only (and for a very
164 /// Note that in this very case, we only allow one (special) motif per PCB.
165 /// This limitation might not be justified, except that it's all we need
169 AliDebug(1,Form("this=%p (ctor special motif)",this));
171 fMotifPositions.SetOwner(kTRUE);
173 TVector2 position(ms->Dimensions());
174 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,ms,position);
175 mp->SetLowIndicesLimit(AliMpIntPair(fIxmin,fIymin));
176 mp->SetHighIndicesLimit(AliMpIntPair(fIxmax,fIymax));
177 fMotifPositions.AddLast(mp);
180 //_____________________________________________________________________________
182 AliMpPCB::operator=(const AliMpPCB& o)
184 /// Assignment operator
186 AliDebug(1,Form("this=%p (assignment op) : begin",this));
188 AliDebug(1,Form("this=%p (assignment op) : end",this));
192 //_____________________________________________________________________________
193 AliMpPCB::~AliMpPCB()
198 AliDebug(1,Form("this=%p",this));
201 //_____________________________________________________________________________
203 AliMpPCB::ActiveXmin() const
206 /// Returns the mininum x for which there is a pad in this PCB.
207 /// Different from Xmin only for PCB which are not full of pads.
213 //_____________________________________________________________________________
215 AliMpPCB::ActiveXmax() const
218 /// Returns the maximum x for which there is a pad in this PCB.
219 /// Different from Xmax only for PCB which are not full of pads.
225 //_____________________________________________________________________________
227 AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
230 /// Add a motif to this PCB. (ix,iy) indicates one corner position of the motif
231 /// where the sign of ix and iy is used to indicate which corner is the
232 /// reference (then for values, abs(ix) and abs(iy) are used indeed) :
234 /// (ix>0,iy>0) : bottom-left corner
235 /// (ix<0,iy>0) : bottom-right corner
236 /// (ix<0,iy<0) : top-right corner
237 /// (ix>0,iy<0) : top-left corner.
239 TString id(Form("%s-%e-%e",mt->GetID().Data(),PadSizeX(),PadSizeY()));
241 AliMpVMotif* motif = fMotifMap->FindMotif(id);
245 motif = new AliMpMotif(id,mt,TVector2(PadSizeX()/2.0,PadSizeY()/2.0));
246 AliDebug(1,Form("Adding motif %s to motifMap",id.Data()));
247 fMotifMap->AddMotif(motif);
251 AliDebug(1,Form("Got motif %s from motifMap",id.Data()));
258 if ( ix >= 0 && iy >= 0 )
260 position.Set(ix*PadSizeX(),iy*PadSizeY());
265 if ( ix >= 0 && iy < 0 )
267 position.Set(ix*PadSizeX(),Ymax()+iy*PadSizeY());
269 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
272 if ( ix < 0 && iy < 0 )
274 position.Set(Xmax()+ix*PadSizeX(),Ymax()+iy*PadSizeY());
275 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
276 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
279 if ( ix < 0 && iy >=0 )
281 position.Set(Xmax()+ix*PadSizeX(),iy*PadSizeY());
282 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
286 position += motif->Dimensions();
288 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,motif,position);
289 Int_t ixmax = ixmin + mt->GetNofPadsX() - 1;
290 Int_t iymax = iymin + mt->GetNofPadsY() - 1;
292 mp->SetLowIndicesLimit(AliMpIntPair(ixmin,iymin));
293 mp->SetHighIndicesLimit(AliMpIntPair(ixmax,iymax));
295 fMotifPositions.AddLast(mp);
297 fIxmin = TMath::Min(fIxmin,ixmin);
298 fIxmax = TMath::Max(fIxmax,ixmax);
299 fIymin = TMath::Min(fIymin,iymin);
300 fIymax = TMath::Max(fIymax,iymax);
302 fActiveXmin = fIxmin*PadSizeX();
303 fActiveXmax = (fIxmax+1)*PadSizeX();
304 fNofPads += mt->GetNofPads();
307 //_____________________________________________________________________________
309 AliMpPCB::Area() const
311 /// Return the area of this PCB
313 return AliMpArea(TVector2( (Xmin()+Xmax())/2.0,DY()),
314 TVector2( DX(), DY() ) );
317 //_____________________________________________________________________________
319 AliMpPCB::Clone(const char* /*newname*/) const
322 /// Return a full copy of this object.
325 TObject* object = new AliMpPCB(*this);
330 //_____________________________________________________________________________
332 AliMpPCB::Clone(const TArrayI& manuids, Int_t ixOffset, Double_t xOffset) const
335 /// Get a full copy of *this, and then apply 2 changes to it :
337 /// a) define the relationship motifType <-> manu id
338 /// b) define the x-offset
339 /// c) shift ix indices backwards to insure that e.g. the first
340 /// pcb of a slat will start at ix=0 (only relevant for rounded pcbs).
345 // First get a full clone.
346 AliMpPCB* pcb = static_cast<AliMpPCB*>(Clone());
348 if ( Int_t(pcb->GetSize()) != manuids.GetSize() )
350 AliError(Form("Cannot Clone PCB %s because I do not get the correct number of "
351 "manu ids (got %d, wanted %d)",pcb->GetID(),
352 manuids.GetSize(),pcb->GetSize()));
356 AliMpIntPair shift(-fIxmin+ixOffset,0);
358 // Then change the internal MotifPositions wrt manu id
359 // and position (offset in x).
360 for ( Int_t i = 0; i < pcb->GetSize(); ++i )
362 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
363 mp->SetID(manuids[i]);
364 TVector2 pos(mp->Position());
365 pos += TVector2(xOffset,0);
366 mp->SetPosition(pos);
367 AliMpIntPair offset(ixOffset,0);
368 AliMpIntPair low(mp->GetLowIndicesLimit());
370 mp->SetLowIndicesLimit(low);
371 AliMpIntPair high(mp->GetHighIndicesLimit());
373 mp->SetHighIndicesLimit(high);
376 pcb->fIxmin += shift.GetFirst();
377 pcb->fIxmax += shift.GetFirst();
378 pcb->fXoffset = xOffset;
380 pcb->fActiveXmin += xOffset;
381 pcb->fActiveXmax += xOffset;
388 //_____________________________________________________________________________
390 AliMpPCB::Copy(TObject& o) const
392 /// Copy *this into o
397 AliMpPCB& pcb = static_cast<AliMpPCB&>(o);
399 pcb.fPadSizeX = fPadSizeX;
400 pcb.fPadSizeY = fPadSizeY;
401 pcb.fEnveloppeSizeX = fEnveloppeSizeX;
402 pcb.fEnveloppeSizeY = fEnveloppeSizeY;
403 pcb.fXoffset = fXoffset;
408 pcb.fActiveXmin = fActiveXmin;
409 pcb.fActiveXmax = fActiveXmax;
411 AliDebug(1,"Deleting pcb.fMotifPositions");
412 pcb.fMotifPositions.Delete();
413 AliDebug(1,"Deleting pcb.fMotifPositions : done");
415 for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
417 AliMpMotifPosition* pos = (AliMpMotifPosition*)fMotifPositions[i];
418 AliMpMotifPosition* pcbpos = new AliMpMotifPosition(pos->GetID(),
421 pcbpos->SetLowIndicesLimit(pos->GetLowIndicesLimit());
422 pcbpos->SetHighIndicesLimit(pos->GetHighIndicesLimit());
423 pcb.fMotifPositions.AddLast(pcbpos);
426 pcb.fNofPads = fNofPads;
428 pcb.fMotifMap = fMotifMap; // warning : we do share the motifmap.
433 //_____________________________________________________________________________
435 AliMpPCB::ActiveDX() const
438 /// Half-length (in x-direction) occupied by pads
441 return GetNofPadsX()*fPadSizeX/2.0;
444 //_____________________________________________________________________________
449 /// Half-length (in x-direction) of the PCB.
450 /// This length is the one of the virtual enveloppe of the PCB and might
451 /// be bigger than the length occupied by pads (e.g. for rounded or short
453 /// See also ActiveDX().
456 return fEnveloppeSizeX/2.0;
459 //_____________________________________________________________________________
461 AliMpPCB::ActiveDY() const
464 /// Half-length (in y-direction) occupied by pads
467 return GetNofPadsY()*fPadSizeY/2.0;
470 //_____________________________________________________________________________
475 /// Half-length (in y-direction) of the PCB.
476 /// This length is the one of the virtual enveloppe of the PCB and might
477 /// be bigger than the length occupied by pads (e.g. for rounded or short
479 /// See also ActiveDY().
482 return fEnveloppeSizeY/2.0;
485 //_____________________________________________________________________________
487 AliMpPCB::FindMotifPosition(Int_t ix, Int_t iy) const
490 /// Returns the motifPosition located at the position referenced by
491 /// integer indices (ix,iy).
494 for (Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
496 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
497 if ( mp->HasPadByIndices(AliMpIntPair(ix,iy)) )
505 //_____________________________________________________________________________
507 AliMpPCB::FindMotifPosition(Double_t x, Double_t y) const
510 /// Returns the motifPosition located at position (x,y)
513 for (Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
515 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
517 TVector2 localPos( TVector2(x,y) - mp->Position() );
519 AliMpIntPair localIndices(mp->GetMotif()->PadIndicesLocal(localPos));
521 if ( localIndices.IsValid() && mp->GetMotif()->GetMotifType()->HasPadByLocalIndices(localIndices) )
529 //_____________________________________________________________________________
531 AliMpPCB::GetID() const
534 /// Returns the name of this PCB.
540 //_____________________________________________________________________________
542 AliMpPCB::GetMotifPosition(Int_t i) const
545 /// Get the i-th motifPosition stored in this PCB's internal array.
548 if ( i >= fMotifPositions.GetEntriesFast() ) return 0;
550 return (AliMpMotifPosition*)fMotifPositions[i];
553 //_____________________________________________________________________________
555 AliMpPCB::GetNofPadsX() const
558 /// Returns the number of pads in x-direction.
561 return fIxmax-fIxmin+1;
564 //_____________________________________________________________________________
566 AliMpPCB::GetNofPadsY() const
569 /// Returns the number of pads in y-direction.
572 return fIymax-fIymin+1;
575 //_____________________________________________________________________________
577 AliMpPCB::GetSize() const
580 /// Returns the number of motifPositions stored in this PCB.
583 return fMotifPositions.GetEntriesFast();
586 //_____________________________________________________________________________
588 AliMpPCB::HasMotifPositionID(Int_t manuId) const
590 /// Returns whether or not we have manuId
592 TIter next(&fMotifPositions);
593 AliMpMotifPosition* pos;
594 while ( ( pos = static_cast<AliMpMotifPosition*>(next()) ) )
596 if ( pos->GetID() == manuId ) return kTRUE;
602 //_____________________________________________________________________________
604 AliMpPCB::Ixmin() const
607 /// Returns the index value of the leftmost pad.
613 //_____________________________________________________________________________
615 AliMpPCB::Ixmax() const
618 /// Returns the index value of the rightmost pad.
621 return Ixmin() + GetNofPadsX() - 1;
624 //_____________________________________________________________________________
626 AliMpPCB::Iymin() const
629 /// Returns the index value of the bottom pad.
635 //_____________________________________________________________________________
637 AliMpPCB::Iymax() const
640 /// Returns the index value of the top pad.
643 return Iymin() + GetNofPadsY() - 1;
646 //_____________________________________________________________________________
648 AliMpPCB::PadSizeX() const
651 /// Returns the pad size in x-direction (in mm)
657 //_____________________________________________________________________________
659 AliMpPCB::PadSizeY() const
662 /// Returns the pad size in y-direction (in mm)
668 //_____________________________________________________________________________
670 AliMpPCB::Print(Option_t* option) const
673 /// Printout of this PCB.
674 /// If option="M", the contained motifs are printed too.
677 cout << "PCB " << GetID() << " PADSIZES=(" << fPadSizeX << ","
678 << fPadSizeY << ") iMin=(" << fIxmin << "," << fIymin << ") "
679 << "iMax=(" << fIxmax << "," << fIymax << ") "
680 << " EnvXmin,max=(" << Xmin() << "," << Xmax()
681 << ") Xmin,max=(" << ActiveXmin() << "," << ActiveXmax() << ")"
684 if ( option && option[0] == 'M' )
686 for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
690 fMotifPositions[i]->Print(option+1);
694 fMotifPositions[i]->Print();
700 //_____________________________________________________________________________
702 AliMpPCB::Save() const
705 /// Save this PCB in the file
707 TString fileName(fId);
710 lines.SetOwner(kTRUE);
712 for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
714 AliMpMotifPosition* pos = GetMotifPosition(i);
715 AliMpVMotif* motif = pos->GetMotif();
716 TVector2 lowerLeft(pos->Position()-pos->Dimensions());
717 TString id(motif->GetID());
718 // id is supposed to be of the form %s-%e-%e, and we're only
719 // interested in the %s part of it
720 Ssiz_t index = id.Index("-");
723 AliError(Form("id=%s does not meet expectations",id.Data()));
726 TString motifName(id(0,index));
727 lines.Add(new TObjString(Form("MOTIF %s %d %d",
729 TMath::Nint(lowerLeft.X()/fPadSizeX),
730 TMath::Nint(lowerLeft.Y()/fPadSizeY))));
733 ofstream out(fileName.Data());
735 out << "SIZES " << fPadSizeX << " " << fPadSizeY
736 << " " << fEnveloppeSizeX << " " << fEnveloppeSizeY
741 while ( ( s = (TObjString*)next() ) )
743 out << s->String().Data() << endl;
748 //_____________________________________________________________________________
753 /// Returns the x-position of the PCB center.
756 return fXoffset + DX();
759 //_____________________________________________________________________________
761 AliMpPCB::Xmin() const
764 /// Returns the leftmost x-position in this PCB.
770 //_____________________________________________________________________________
772 AliMpPCB::Xmax() const
775 /// Returns the rightmost x-position in this PCB.
781 //_____________________________________________________________________________
786 /// Returns the y-position of the PCB center.
789 return DY(); // this works as PCB are organized in a single row within slats.
792 //_____________________________________________________________________________
794 AliMpPCB::Ymin() const
797 /// Returns the smallest y-position in this PCB.
803 //_____________________________________________________________________________
805 AliMpPCB::Ymax() const
808 /// Returns the largest y-position in this PCB.