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 //-----------------------------------------------------------------------------
61 //_____________________________________________________________________________
83 fMotifPositions.SetOwner(kTRUE);
84 AliDebug(1,Form("this=%p",this));
87 //_____________________________________________________________________________
88 AliMpPCB::AliMpPCB(AliMpSlatMotifMap* motifMap, const char* id, Double_t padSizeX, Double_t padSizeY,
89 Double_t enveloppeSizeX, Double_t enveloppeSizeY)
94 fEnveloppeSizeX(enveloppeSizeX),
95 fEnveloppeSizeY(enveloppeSizeY),
108 /// Normal ctor. Must be fed with the PCB's name (id), the pad dimensions
109 /// and the global dimension of the virtual enveloppe of the PCB
110 /// (usually 400x400 mm)
111 fMotifPositions.SetOwner(kTRUE);
112 AliDebug(1,Form("this=%p id=%s",this,id));
115 //_____________________________________________________________________________
116 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->DimensionX()*2.0),
151 fEnveloppeSizeY(ms->DimensionY()*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));
174 fMotifPositions.SetOwner(kTRUE);
176 Double_t posx = ms->DimensionX();
177 Double_t posy = ms->DimensionY();
178 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,ms,posx,posy);
179 mp->SetLowIndicesLimit(fIxmin,fIymin);
180 mp->SetHighIndicesLimit(fIxmax,fIymax);
181 fMotifPositions.AddLast(mp);
184 //_____________________________________________________________________________
186 AliMpPCB::operator=(const AliMpPCB& o)
188 /// Assignment operator
190 AliDebug(1,Form("this=%p (assignment op) : begin",this));
192 AliDebug(1,Form("this=%p (assignment op) : end",this));
196 //_____________________________________________________________________________
197 AliMpPCB::~AliMpPCB()
202 AliDebug(1,Form("this=%p",this));
205 //_____________________________________________________________________________
207 AliMpPCB::ActiveXmin() const
210 /// Returns the mininum x for which there is a pad in this PCB.
211 /// Different from Xmin only for PCB which are not full of pads.
217 //_____________________________________________________________________________
219 AliMpPCB::ActiveXmax() const
222 /// Returns the maximum x for which there is a pad in this PCB.
223 /// Different from Xmax only for PCB which are not full of pads.
229 //_____________________________________________________________________________
231 AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
234 /// Add a motif to this PCB. (ix,iy) indicates one corner position of the motif
235 /// where the sign of ix and iy is used to indicate which corner is the
236 /// reference (then for values, abs(ix) and abs(iy) are used indeed) :
238 /// (ix>0,iy>0) : bottom-left corner
239 /// (ix<0,iy>0) : bottom-right corner
240 /// (ix<0,iy<0) : top-right corner
241 /// (ix>0,iy<0) : top-left corner.
243 TString id(Form("%s-%e-%e",mt->GetID().Data(),PadSizeX(),PadSizeY()));
245 AliMpVMotif* motif = fMotifMap->FindMotif(id);
249 motif = new AliMpMotif(id,mt,PadSizeX()/2.0,PadSizeY()/2.0);
250 AliDebug(1,Form("Adding motif %s to motifMap",id.Data()));
251 fMotifMap->AddMotif(motif);
255 AliDebug(1,Form("Got motif %s from motifMap",id.Data()));
263 if ( ix >= 0 && iy >= 0 )
265 posx = ix*PadSizeX();
266 posy = iy*PadSizeY();
271 if ( ix >= 0 && iy < 0 )
273 posx = ix*PadSizeX();
274 posy = Ymax()+iy*PadSizeY();
276 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
279 if ( ix < 0 && iy < 0 )
281 posx = Xmax()+ix*PadSizeX();
282 posy = Ymax()+iy*PadSizeY();
283 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
284 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
287 if ( ix < 0 && iy >=0 )
289 posx = Xmax()+ix*PadSizeX();
290 posy = iy*PadSizeY();
291 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
295 posx += motif->DimensionX();
296 posy += motif->DimensionY();
297 AliMpMotifPosition* mp
298 = new AliMpMotifPosition(-1,motif,posx, posy);
300 Int_t ixmax = ixmin + mt->GetNofPadsX() - 1;
301 Int_t iymax = iymin + mt->GetNofPadsY() - 1;
302 mp->SetLowIndicesLimit(ixmin,iymin);
303 mp->SetHighIndicesLimit(ixmax,iymax);
305 fMotifPositions.AddLast(mp);
307 fIxmin = TMath::Min(fIxmin,ixmin);
308 fIxmax = TMath::Max(fIxmax,ixmax);
309 fIymin = TMath::Min(fIymin,iymin);
310 fIymax = TMath::Max(fIymax,iymax);
312 fActiveXmin = fIxmin*PadSizeX();
313 fActiveXmax = (fIxmax+1)*PadSizeX();
314 fNofPads += mt->GetNofPads();
317 //_____________________________________________________________________________
319 AliMpPCB::Area() const
321 /// Return the area of this PCB
323 return AliMpArea((Xmin()+Xmax())/2.0,DY(), DX(), DY() );
326 //_____________________________________________________________________________
328 AliMpPCB::Clone(const char* /*newname*/) const
331 /// Return a full copy of this object.
334 TObject* object = new AliMpPCB(*this);
339 //_____________________________________________________________________________
341 AliMpPCB::Clone(const TArrayI& manuids, Int_t ixOffset, Double_t xOffset) const
344 /// Get a full copy of *this, and then apply 2 changes to it :
346 /// a) define the relationship motifType <-> manu id
347 /// b) define the x-offset
348 /// c) shift ix indices backwards to insure that e.g. the first
349 /// pcb of a slat will start at ix=0 (only relevant for rounded pcbs).
354 // First get a full clone.
355 AliMpPCB* pcb = static_cast<AliMpPCB*>(Clone());
357 if ( Int_t(pcb->GetSize()) != manuids.GetSize() )
359 AliError(Form("Cannot Clone PCB %s because I do not get the correct number of "
360 "manu ids (got %d, wanted %d)",pcb->GetID(),
361 manuids.GetSize(),pcb->GetSize()));
365 MpPair_t shift = AliMp::Pair(-fIxmin+ixOffset,0);
367 // Then change the internal MotifPositions wrt manu id
368 // and position (offset in x).
369 for ( Int_t i = 0; i < pcb->GetSize(); ++i )
371 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
372 mp->SetID(manuids[i]);
373 Double_t posx = mp->GetPositionX() + xOffset;
374 Double_t posy = mp->GetPositionY();
375 mp->SetPosition(posx, posy);
376 MpPair_t low = mp->GetLowIndicesLimit();
378 mp->SetLowIndicesLimit(low);
379 MpPair_t high = mp->GetHighIndicesLimit();
381 mp->SetHighIndicesLimit(high);
384 pcb->fIxmin += AliMp::PairFirst(shift);
385 pcb->fIxmax += AliMp::PairFirst(shift);
386 pcb->fXoffset = xOffset;
388 pcb->fActiveXmin += xOffset;
389 pcb->fActiveXmax += xOffset;
396 //_____________________________________________________________________________
398 AliMpPCB::Copy(TObject& o) const
400 /// Copy *this into o
405 AliMpPCB& pcb = static_cast<AliMpPCB&>(o);
407 pcb.fPadSizeX = fPadSizeX;
408 pcb.fPadSizeY = fPadSizeY;
409 pcb.fEnveloppeSizeX = fEnveloppeSizeX;
410 pcb.fEnveloppeSizeY = fEnveloppeSizeY;
411 pcb.fXoffset = fXoffset;
416 pcb.fActiveXmin = fActiveXmin;
417 pcb.fActiveXmax = fActiveXmax;
419 AliDebug(1,"Deleting pcb.fMotifPositions");
420 pcb.fMotifPositions.Delete();
421 AliDebug(1,"Deleting pcb.fMotifPositions : done");
423 for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
425 AliMpMotifPosition* pos = (AliMpMotifPosition*)fMotifPositions[i];
426 AliMpMotifPosition* pcbpos
427 = new AliMpMotifPosition(pos->GetID(), pos->GetMotif(),
428 pos->GetPositionX(), pos->GetPositionY());
429 pcbpos->SetLowIndicesLimit(pos->GetLowIndicesLimit());
430 pcbpos->SetHighIndicesLimit(pos->GetHighIndicesLimit());
431 pcb.fMotifPositions.AddLast(pcbpos);
434 pcb.fNofPads = fNofPads;
436 pcb.fMotifMap = fMotifMap; // warning : we do share the motifmap.
441 //_____________________________________________________________________________
443 AliMpPCB::ActiveDX() const
446 /// Half-length (in x-direction) occupied by pads
449 return GetNofPadsX()*fPadSizeX/2.0;
452 //_____________________________________________________________________________
457 /// Half-length (in x-direction) of the PCB.
458 /// This length is the one of the virtual enveloppe of the PCB and might
459 /// be bigger than the length occupied by pads (e.g. for rounded or short
461 /// See also ActiveDX().
464 return fEnveloppeSizeX/2.0;
467 //_____________________________________________________________________________
469 AliMpPCB::ActiveDY() const
472 /// Half-length (in y-direction) occupied by pads
475 return GetNofPadsY()*fPadSizeY/2.0;
478 //_____________________________________________________________________________
483 /// Half-length (in y-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 ActiveDY().
490 return fEnveloppeSizeY/2.0;
493 //_____________________________________________________________________________
495 AliMpPCB::FindMotifPosition(Int_t ix, Int_t iy) const
498 /// Returns the motifPosition located at the position referenced by
499 /// integer indices (ix,iy).
502 for (Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
504 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
505 if ( mp->HasPadByIndices(AliMp::Pair(ix,iy)) )
513 //_____________________________________________________________________________
515 AliMpPCB::FindMotifPosition(Double_t x, Double_t y) const
518 /// Returns the motifPosition located at position (x,y)
521 for (Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
523 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
525 Double_t localPosX = x - mp->GetPositionX();
526 Double_t localPosY = y - mp->GetPositionY();
528 MpPair_t localIndices(
529 mp->GetMotif()->PadIndicesLocal(localPosX, localPosY));
531 if ( localIndices >= 0 &&
532 mp->GetMotif()->GetMotifType()->HasPadByLocalIndices(localIndices) )
540 //_____________________________________________________________________________
542 AliMpPCB::GetID() const
545 /// Returns the name of this PCB.
551 //_____________________________________________________________________________
553 AliMpPCB::GetMotifPosition(Int_t i) const
556 /// Get the i-th motifPosition stored in this PCB's internal array.
559 if ( i >= fMotifPositions.GetEntriesFast() ) return 0;
561 return (AliMpMotifPosition*)fMotifPositions[i];
564 //_____________________________________________________________________________
566 AliMpPCB::GetNofPadsX() const
569 /// Returns the number of pads in x-direction.
572 return fIxmax-fIxmin+1;
575 //_____________________________________________________________________________
577 AliMpPCB::GetNofPadsY() const
580 /// Returns the number of pads in y-direction.
583 return fIymax-fIymin+1;
586 //_____________________________________________________________________________
588 AliMpPCB::GetSize() const
591 /// Returns the number of motifPositions stored in this PCB.
594 return fMotifPositions.GetEntriesFast();
597 //_____________________________________________________________________________
599 AliMpPCB::HasMotifPositionID(Int_t manuId) const
601 /// Returns whether or not we have manuId
603 TIter next(&fMotifPositions);
604 AliMpMotifPosition* pos;
605 while ( ( pos = static_cast<AliMpMotifPosition*>(next()) ) )
607 if ( pos->GetID() == manuId ) return kTRUE;
613 //_____________________________________________________________________________
615 AliMpPCB::Ixmin() const
618 /// Returns the index value of the leftmost pad.
624 //_____________________________________________________________________________
626 AliMpPCB::Ixmax() const
629 /// Returns the index value of the rightmost pad.
632 return Ixmin() + GetNofPadsX() - 1;
635 //_____________________________________________________________________________
637 AliMpPCB::Iymin() const
640 /// Returns the index value of the bottom pad.
646 //_____________________________________________________________________________
648 AliMpPCB::Iymax() const
651 /// Returns the index value of the top pad.
654 return Iymin() + GetNofPadsY() - 1;
657 //_____________________________________________________________________________
659 AliMpPCB::PadSizeX() const
662 /// Returns the pad size in x-direction (in mm)
668 //_____________________________________________________________________________
670 AliMpPCB::PadSizeY() const
673 /// Returns the pad size in y-direction (in mm)
679 //_____________________________________________________________________________
681 AliMpPCB::Print(Option_t* option) const
684 /// Printout of this PCB.
685 /// If option="M", the contained motifs are printed too.
688 cout << "PCB " << GetID() << " PADSIZES=(" << fPadSizeX << ","
689 << fPadSizeY << ") iMin=(" << fIxmin << "," << fIymin << ") "
690 << "iMax=(" << fIxmax << "," << fIymax << ") "
691 << " EnvXmin,max=(" << Xmin() << "," << Xmax()
692 << ") Xmin,max=(" << ActiveXmin() << "," << ActiveXmax() << ")"
695 if ( option && option[0] == 'M' )
697 for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
699 fMotifPositions[i]->Print(option+1);
704 //_____________________________________________________________________________
706 AliMpPCB::Save() const
709 /// Save this PCB in the file
711 TString fileName(fId);
714 lines.SetOwner(kTRUE);
716 for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
718 AliMpMotifPosition* pos = GetMotifPosition(i);
719 AliMpVMotif* motif = pos->GetMotif();
721 Double_t lowerLeftX = pos->GetPositionX()-pos->GetDimensionX();
722 Double_t lowerLeftY = pos->GetPositionY()-pos->GetDimensionY();
723 TString id(motif->GetID());
724 // id is supposed to be of the form %s-%e-%e, and we're only
725 // interested in the %s part of it
726 Ssiz_t index = id.Index("-");
729 AliError(Form("id=%s does not meet expectations",id.Data()));
732 TString motifName(id(0,index));
733 lines.Add(new TObjString(Form("MOTIF %s %d %d",
735 TMath::Nint(lowerLeftX/fPadSizeX),
736 TMath::Nint(lowerLeftY/fPadSizeY))));
739 ofstream out(fileName.Data());
741 out << "SIZES " << fPadSizeX << " " << fPadSizeY
742 << " " << fEnveloppeSizeX << " " << fEnveloppeSizeY
747 while ( ( s = (TObjString*)next() ) )
749 out << s->String().Data() << endl;
754 //_____________________________________________________________________________
759 /// Returns the x-position of the PCB center.
762 return fXoffset + DX();
765 //_____________________________________________________________________________
767 AliMpPCB::Xmin() const
770 /// Returns the leftmost x-position in this PCB.
776 //_____________________________________________________________________________
778 AliMpPCB::Xmax() const
781 /// Returns the rightmost x-position in this PCB.
787 //_____________________________________________________________________________
792 /// Returns the y-position of the PCB center.
795 return DY(); // this works as PCB are organized in a single row within slats.
798 //_____________________________________________________________________________
800 AliMpPCB::Ymin() const
803 /// Returns the smallest y-position in this PCB.
809 //_____________________________________________________________________________
811 AliMpPCB::Ymax() const
814 /// Returns the largest y-position in this PCB.