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)
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));
172 fMotifPositions.SetOwner(kTRUE);
174 TVector2 position(ms->Dimensions());
175 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,ms,position);
176 mp->SetLowIndicesLimit(AliMpIntPair(fIxmin,fIymin));
177 mp->SetHighIndicesLimit(AliMpIntPair(fIxmax,fIymax));
179 fMotifPositions.AddLast(mp);
181 fMotifPositions.push_back(mp);
185 //_____________________________________________________________________________
187 AliMpPCB::operator=(const AliMpPCB& o)
189 AliDebug(1,Form("this=%p (assignment op) : begin",this));
191 AliDebug(1,Form("this=%p (assignment op) : end",this));
195 //_____________________________________________________________________________
196 AliMpPCB::~AliMpPCB()
201 AliDebug(1,Form("this=%p",this));
203 for ( size_t i = 0; i < fMotifPositions.size(); ++i )
205 delete fMotifPositions[i];
211 //_____________________________________________________________________________
213 AliMpPCB::ActiveXmin() const
216 // Returns the mininum x for which there is a pad in this PCB.
217 // Different from Xmin only for PCB which are not full of pads.
223 //_____________________________________________________________________________
225 AliMpPCB::ActiveXmax() const
228 // Returns the maximum x for which there is a pad in this PCB.
229 // Different from Xmax only for PCB which are not full of pads.
235 //_____________________________________________________________________________
237 AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
240 // Add a motif to this PCB. (ix,iy) indicates one corner position of the motif
241 // where the sign of ix and iy is used to indicate which corner is the
242 // reference (then for values, abs(ix) and abs(iy) are used indeed) :
244 // (ix>0,iy>0) : bottom-left corner
245 // (ix<0,iy>0) : bottom-right corner
246 // (ix<0,iy<0) : top-right corner
247 // (ix>0,iy<0) : top-left corner.
249 TString id(Form("%s-%e-%e",mt->GetID().Data(),PadSizeX(),PadSizeY()));
251 AliMpVMotif* motif = fMotifMap->FindMotif(id);
255 motif = new AliMpMotif(id,mt,TVector2(PadSizeX()/2.0,PadSizeY()/2.0));
256 AliDebug(1,Form("Adding motif %s to motifMap",id.Data()));
257 fMotifMap->AddMotif(motif);
261 AliDebug(1,Form("Got motif %s from motifMap",id.Data()));
268 if ( ix >= 0 && iy >= 0 )
270 position.Set(ix*PadSizeX(),iy*PadSizeY());
275 if ( ix >= 0 && iy < 0 )
277 position.Set(ix*PadSizeX(),Ymax()+iy*PadSizeY());
279 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
282 if ( ix < 0 && iy < 0 )
284 position.Set(Xmax()+ix*PadSizeX(),Ymax()+iy*PadSizeY());
285 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
286 iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
289 if ( ix < 0 && iy >=0 )
291 position.Set(Xmax()+ix*PadSizeX(),iy*PadSizeY());
292 ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
296 position += motif->Dimensions();
298 AliMpMotifPosition* mp = new AliMpMotifPosition(-1,motif,position);
299 Int_t ixmax = ixmin + mt->GetNofPadsX() - 1;
300 Int_t iymax = iymin + mt->GetNofPadsY() - 1;
302 mp->SetLowIndicesLimit(AliMpIntPair(ixmin,iymin));
303 mp->SetHighIndicesLimit(AliMpIntPair(ixmax,iymax));
306 fMotifPositions.AddLast(mp);
308 fMotifPositions.push_back(mp);
311 fIxmin = std::min(fIxmin,ixmin);
312 fIxmax = std::max(fIxmax,ixmax);
313 fIymin = std::min(fIymin,iymin);
314 fIymax = std::max(fIymax,iymax);
316 fActiveXmin = fIxmin*PadSizeX();
317 fActiveXmax = (fIxmax+1)*PadSizeX();
318 fNofPads += mt->GetNofPads();
321 //_____________________________________________________________________________
323 AliMpPCB::Area() const
325 return AliMpArea(TVector2( (Xmin()+Xmax())/2.0,DY()),
326 TVector2( DX(), DY() ) );
329 //_____________________________________________________________________________
331 AliMpPCB::Clone(const char* /*newname*/) const
334 // Return a full copy of this object.
337 TObject* object = new AliMpPCB(*this);
342 //_____________________________________________________________________________
344 AliMpPCB::Clone(const TArrayI& manuids, Int_t ixOffset, Double_t xOffset) const
347 // Get a full copy of *this, and then apply 2 changes to it :
349 // a) define the relationship motifType <-> manu id
350 // b) define the x-offset
351 // c) shift ix indices backwards to insure that e.g. the first
352 // pcb of a slat will start at ix=0 (only relevant for rounded pcbs).
357 // First get a full clone.
358 AliMpPCB* pcb = static_cast<AliMpPCB*>(Clone());
360 if ( Int_t(pcb->GetSize()) != manuids.GetSize() )
362 AliError(Form("Cannot Clone PCB %s because I do not get the correct number of "
363 "manu ids (got %d, wanted %d)",pcb->GetID(),
364 manuids.GetSize(),pcb->GetSize()));
368 AliMpIntPair shift(-fIxmin+ixOffset,0);
370 // Then change the internal MotifPositions wrt manu id
371 // and position (offset in x).
372 for ( Size_t i = 0; i < pcb->GetSize(); ++i )
374 AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
375 mp->SetID(manuids[i]);
376 TVector2 pos(mp->Position());
377 pos += TVector2(xOffset,0);
378 mp->SetPosition(pos);
379 AliMpIntPair offset(ixOffset,0);
380 AliMpIntPair low(mp->GetLowIndicesLimit());
382 mp->SetLowIndicesLimit(low);
383 AliMpIntPair high(mp->GetHighIndicesLimit());
385 mp->SetHighIndicesLimit(high);
388 pcb->fIxmin += shift.GetFirst();
389 pcb->fIxmax += shift.GetFirst();
390 pcb->fXoffset = xOffset;
392 pcb->fActiveXmin += xOffset;
393 pcb->fActiveXmax += xOffset;
400 //_____________________________________________________________________________
402 AliMpPCB::Copy(TObject& o) const
409 AliMpPCB& pcb = static_cast<AliMpPCB&>(o);
411 pcb.fPadSizeX = fPadSizeX;
412 pcb.fPadSizeY = fPadSizeY;
413 pcb.fEnveloppeSizeX = fEnveloppeSizeX;
414 pcb.fEnveloppeSizeY = fEnveloppeSizeY;
415 pcb.fXoffset = fXoffset;
420 pcb.fActiveXmin = fActiveXmin;
421 pcb.fActiveXmax = fActiveXmax;
424 AliDebug(1,"Deleting pcb.fMotifPositions");
425 pcb.fMotifPositions.Delete();
426 AliDebug(1,"Deleting pcb.fMotifPositions : done");
428 for ( Size_t i = 0; i < pcb.fMotifPositions.size(); ++i )
430 delete pcb.fMotifPositions[i];
435 for ( Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
437 for ( Size_t i = 0; i < fMotifPositions.size(); ++i )
440 AliMpMotifPosition* pos = (AliMpMotifPosition*)fMotifPositions[i];
441 AliMpMotifPosition* pcbpos = new AliMpMotifPosition(pos->GetID(),
444 pcbpos->SetLowIndicesLimit(pos->GetLowIndicesLimit());
445 pcbpos->SetHighIndicesLimit(pos->GetHighIndicesLimit());
447 pcb.fMotifPositions.AddLast(pcbpos);
449 pcb.fMotifPositions.push_back(pcbpos);
453 pcb.fNofPads = fNofPads;
455 pcb.fMotifMap = fMotifMap; // warning : we do share the motifmap.
460 //_____________________________________________________________________________
462 AliMpPCB::ActiveDX() const
465 // Half-length (in x-direction) occupied by pads
468 return GetNofPadsX()*fPadSizeX/2.0;
471 //_____________________________________________________________________________
476 // Half-length (in x-direction) of the PCB.
477 // This length is the one of the virtual enveloppe of the PCB and might
478 // be bigger than the length occupied by pads (e.g. for rounded or short
480 // See also ActiveDX().
483 return fEnveloppeSizeX/2.0;
486 //_____________________________________________________________________________
488 AliMpPCB::ActiveDY() const
491 // Half-length (in y-direction) occupied by pads
494 return GetNofPadsY()*fPadSizeY/2.0;
497 //_____________________________________________________________________________
502 // Half-length (in y-direction) of the PCB.
503 // This length is the one of the virtual enveloppe of the PCB and might
504 // be bigger than the length occupied by pads (e.g. for rounded or short
506 // See also ActiveDY().
509 return fEnveloppeSizeY/2.0;
512 //_____________________________________________________________________________
514 AliMpPCB::FindMotifPosition(Int_t ix, Int_t iy) const
517 // Returns the motifPosition located at the position referenced by
518 // integer indices (ix,iy).
522 for (Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
524 for (Size_t i = 0; i < fMotifPositions.size(); ++i )
527 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
528 if ( mp->HasPad(AliMpIntPair(ix,iy)) )
536 //_____________________________________________________________________________
538 AliMpPCB::FindMotifPosition(Double_t x, Double_t y) const
541 // Returns the motifPosition located at position (x,y)
545 for (Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
547 for (Size_t i = 0; i < fMotifPositions.size(); ++i )
550 AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
552 TVector2 localPos( TVector2(x,y) - mp->Position() );
554 AliMpIntPair localIndices(mp->GetMotif()->PadIndicesLocal(localPos));
556 if ( localIndices.IsValid() && mp->GetMotif()->GetMotifType()->HasPad(localIndices) )
564 //_____________________________________________________________________________
566 AliMpPCB::GetID() const
569 // Returns the name of this PCB.
575 //_____________________________________________________________________________
577 AliMpPCB::GetMotifPosition(AliMpPCB::Size_t i) const
580 // Get the i-th motifPosition stored in this PCB's internal array.
584 if ( i >= fMotifPositions.GetEntriesFast() ) return 0;
586 if ( i >= fMotifPositions.size() ) return 0;
588 return (AliMpMotifPosition*)fMotifPositions[i];
591 //_____________________________________________________________________________
593 AliMpPCB::GetNofPadsX() const
596 // Returns the number of pads in x-direction.
599 return fIxmax-fIxmin+1;
602 //_____________________________________________________________________________
604 AliMpPCB::GetNofPadsY() const
607 // Returns the number of pads in y-direction.
610 return fIymax-fIymin+1;
613 //_____________________________________________________________________________
615 AliMpPCB::GetSize() const
618 // Returns the number of motifPositions stored in this PCB.
622 return fMotifPositions.GetEntriesFast();
624 return fMotifPositions.size();
629 //_____________________________________________________________________________
631 AliMpPCB::Ixmin() const
634 // Returns the index value of the leftmost pad.
640 //_____________________________________________________________________________
642 AliMpPCB::Ixmax() const
645 // Returns the index value of the rightmost pad.
648 return Ixmin() + GetNofPadsX() - 1;
651 //_____________________________________________________________________________
653 AliMpPCB::Iymin() const
656 // Returns the index value of the bottom pad.
662 //_____________________________________________________________________________
664 AliMpPCB::Iymax() const
667 // Returns the index value of the top pad.
670 return Iymin() + GetNofPadsY() - 1;
673 //_____________________________________________________________________________
675 AliMpPCB::PadSizeX() const
678 // Returns the pad size in x-direction (in mm)
684 //_____________________________________________________________________________
686 AliMpPCB::PadSizeY() const
689 // Returns the pad size in y-direction (in mm)
695 //_____________________________________________________________________________
697 AliMpPCB::Print(Option_t* option) const
700 // Printout of this PCB.
701 // If option="M", the contained motifs are printed too.
704 cout << "PCB " << GetID() << " PADSIZES=(" << fPadSizeX << ","
705 << fPadSizeY << ") iMin=(" << fIxmin << "," << fIymin << ") "
706 << "iMax=(" << fIxmax << "," << fIymax << ") "
707 << " EnvXmin,max=(" << Xmin() << "," << Xmax()
708 << ") Xmin,max=(" << ActiveXmin() << "," << ActiveXmax() << ")"
711 if ( option && option[0] == 'M' )
714 for ( Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
716 for ( Size_t i = 0; i < fMotifPositions.size(); ++i )
721 fMotifPositions[i]->Print(option+1);
725 fMotifPositions[i]->Print();
731 //_____________________________________________________________________________
733 AliMpPCB::Save() const
735 TString fileName(fId);
738 lines.SetOwner(kTRUE);
740 for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
742 AliMpMotifPosition* pos = GetMotifPosition(i);
743 AliMpVMotif* motif = pos->GetMotif();
744 TVector2 lowerLeft(pos->Position()-pos->Dimensions());
745 TString id(motif->GetID());
746 // id is supposed to be of the form %s-%e-%e, and we're only
747 // interested in the %s part of it
748 Ssiz_t index = id.Index("-");
751 AliError(Form("id=%s does not meet expectations",id.Data()));
754 TString motifName(id(0,index));
755 lines.Add(new TObjString(Form("MOTIF %s %d %d",
757 TMath::Nint(lowerLeft.X()/fPadSizeX),
758 TMath::Nint(lowerLeft.Y()/fPadSizeY))));
761 ofstream out(fileName.Data());
763 out << "SIZES " << fPadSizeX << " " << fPadSizeY
764 << " " << fEnveloppeSizeX << " " << fEnveloppeSizeY
769 while ( ( s = (TObjString*)next() ) )
771 out << s->String().Data() << endl;
776 //_____________________________________________________________________________
781 // Returns the x-position of the PCB center.
784 return fXoffset + DX();
787 //_____________________________________________________________________________
789 AliMpPCB::Xmin() const
792 // Returns the leftmost x-position in this PCB.
798 //_____________________________________________________________________________
800 AliMpPCB::Xmax() const
803 // Returns the rightmost x-position in this PCB.
809 //_____________________________________________________________________________
814 // Returns the y-position of the PCB center.
817 return DY(); // this works as PCB are organized in a single row within slats.
820 //_____________________________________________________________________________
822 AliMpPCB::Ymin() const
825 // Returns the smallest y-position in this PCB.
831 //_____________________________________________________________________________
833 AliMpPCB::Ymax() const
836 // Returns the largest y-position in this PCB.