]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpPCB.cxx
In MUONChamberMaterialBudget.C
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpPCB.cxx
index cc42c60a748fbadfc2e4ddc7e145387c0b3e1452..13441a93e5bd570db33d37f800ce48119df1cd62 100644 (file)
@@ -31,7 +31,8 @@
 #include "TMath.h"
 #include <sstream>
 
-/// 
+//-----------------------------------------------------------------------------
 /// \class AliMpPCB
 ///
 /// A PCB for station 3,4 or 5
@@ -48,6 +49,7 @@
 /// the enveloppe.
 ///
 /// \author L. Aphecetche
+//-----------------------------------------------------------------------------
 
 /// \cond CLASSIMP
 ClassImp(AliMpPCB)
@@ -75,9 +77,7 @@ AliMpPCB::AliMpPCB()
       ///
       /// Default ctor.
       ///
-#ifdef WITH_ROOT
     fMotifPositions.SetOwner(kTRUE);
-#endif
     AliDebug(1,Form("this=%p",this));
 }
 
@@ -105,9 +105,7 @@ AliMpPCB::AliMpPCB(AliMpSlatMotifMap* motifMap, const char* id, Double_t padSize
       /// Normal ctor. Must be fed with the PCB's name (id), the pad dimensions
       /// and the global dimension of the virtual enveloppe of the PCB
       /// (usually 400x400 mm)
-#ifdef WITH_ROOT
     fMotifPositions.SetOwner(kTRUE);
-#endif
     AliDebug(1,Form("this=%p id=%s",this,id));
 }
 
@@ -133,9 +131,8 @@ AliMpPCB::AliMpPCB(const AliMpPCB& o)
   ///
   /// Copy constructor
 
-#ifdef WITH_ROOT
-    fMotifPositions.SetOwner(kTRUE);
-#endif
+  fMotifPositions.SetOwner(kTRUE);
+
   AliDebug(1,Form("this=%p (copy ctor) : begin",this));
   o.Copy(*this);
   AliDebug(1,Form("this=%p (copy ctor) : end",this));
@@ -147,8 +144,8 @@ AliMpPCB::AliMpPCB(const char* id, AliMpMotifSpecial* ms)
   fId(id), 
   fPadSizeX(-1.0), 
   fPadSizeY(-1.0),
-  fEnveloppeSizeX(ms->Dimensions().X()*2.0),
-  fEnveloppeSizeY(ms->Dimensions().Y()*2.0),
+  fEnveloppeSizeX(ms->DimensionX()*2.0),
+  fEnveloppeSizeY(ms->DimensionY()*2.0),
   fXoffset(0.0),
   fActiveXmin(0.0),
   fActiveXmax(fEnveloppeSizeX),
@@ -169,20 +166,16 @@ AliMpPCB::AliMpPCB(const char* id, AliMpMotifSpecial* ms)
   /// so far ;-)
   ///
  
-    AliDebug(1,Form("this=%p (ctor special motif)",this));
+  AliDebug(1,Form("this=%p (ctor special motif)",this));
     
-#ifdef WITH_ROOT
-    fMotifPositions.SetOwner(kTRUE);
-#endif
-  TVector2 position(ms->Dimensions());
-  AliMpMotifPosition* mp = new AliMpMotifPosition(-1,ms,position);
-  mp->SetLowIndicesLimit(AliMpIntPair(fIxmin,fIymin));
-  mp->SetHighIndicesLimit(AliMpIntPair(fIxmax,fIymax));
-#ifdef WITH_ROOT
+  fMotifPositions.SetOwner(kTRUE);
+
+  Double_t posx = ms->DimensionX();
+  Double_t posy = ms->DimensionY();
+  AliMpMotifPosition* mp = new AliMpMotifPosition(-1,ms,posx,posy);
+  mp->SetLowIndicesLimit(fIxmin,fIymin);
+  mp->SetHighIndicesLimit(fIxmax,fIymax);
   fMotifPositions.AddLast(mp);
-#else
-  fMotifPositions.push_back(mp);
-#endif
 }
 
 //_____________________________________________________________________________
@@ -204,13 +197,6 @@ AliMpPCB::~AliMpPCB()
   /// Dtor.
   ///
   AliDebug(1,Form("this=%p",this));
-#ifndef WITH_ROOT
-  for ( size_t i = 0; i < fMotifPositions.size(); ++i )
-  {
-    delete fMotifPositions[i];
-  }
-#endif
-  
 }
 
 //_____________________________________________________________________________
@@ -257,7 +243,7 @@ AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
   
   if (!motif)
   {
-    motif = new AliMpMotif(id,mt,TVector2(PadSizeX()/2.0,PadSizeY()/2.0));
+    motif = new AliMpMotif(id,mt,PadSizeX()/2.0,PadSizeY()/2.0);
     AliDebug(1,Form("Adding motif %s to motifMap",id.Data()));
     fMotifMap->AddMotif(motif);
   }
@@ -266,52 +252,54 @@ AliMpPCB::Add(AliMpMotifType* mt, Int_t ix, Int_t iy)
     AliDebug(1,Form("Got motif %s from motifMap",id.Data()));
   }
   
-  TVector2 position;
+  Double_t posx(0.);
+  Double_t posy(0.);
   Int_t ixmin(-1);
   Int_t iymin(-1);
   
   if ( ix >= 0 && iy >= 0 )
   {
-    position.Set(ix*PadSizeX(),iy*PadSizeY());
+    posx = ix*PadSizeX();
+    posy = iy*PadSizeY();
     ixmin = ix;
     iymin = iy;
   }
   else
   if ( ix >= 0 && iy < 0 )
   {
-    position.Set(ix*PadSizeX(),Ymax()+iy*PadSizeY());
+    posx = ix*PadSizeX();
+    posy = Ymax()+iy*PadSizeY();
     ixmin = ix;
     iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
   }
   else
   if ( ix < 0 && iy < 0 )
   {
-    position.Set(Xmax()+ix*PadSizeX(),Ymax()+iy*PadSizeY());
+    posx = Xmax()+ix*PadSizeX();
+    posy = Ymax()+iy*PadSizeY();
     ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
     iymin = TMath::Nint(Ymax()/PadSizeY()) + iy;
   }
   else
   if ( ix < 0 && iy >=0 )
   {
-    position.Set(Xmax()+ix*PadSizeX(),iy*PadSizeY());
+    posx = Xmax()+ix*PadSizeX();
+    posy = iy*PadSizeY();
     ixmin = TMath::Nint(Xmax()/PadSizeX()) + ix;
     iymin = iy;
   }
 
-  position += motif->Dimensions();
+  posx += motif->DimensionX();
+  posy += motif->DimensionY();
+  AliMpMotifPosition* mp 
+    = new AliMpMotifPosition(-1,motif,posx, posy);
 
-  AliMpMotifPosition* mp = new AliMpMotifPosition(-1,motif,position);
-  Int_t ixmax = ixmin + mt->GetNofPadsX() - 1;
+  Int_t ixmax = ixmin + mt->GetNofPadsX() - 1;  
   Int_t iymax = iymin + mt->GetNofPadsY() - 1;
+  mp->SetLowIndicesLimit(ixmin,iymin);
+  mp->SetHighIndicesLimit(ixmax,iymax);
 
-  mp->SetLowIndicesLimit(AliMpIntPair(ixmin,iymin));
-  mp->SetHighIndicesLimit(AliMpIntPair(ixmax,iymax));
-
-#ifdef WITH_ROOT
   fMotifPositions.AddLast(mp);
-#else
-  fMotifPositions.push_back(mp);
-#endif
 
   fIxmin = TMath::Min(fIxmin,ixmin);
   fIxmax = TMath::Max(fIxmax,ixmax);
@@ -329,8 +317,7 @@ AliMpPCB::Area() const
 {
   /// Return the area of this PCB
 
-  return AliMpArea(TVector2( (Xmin()+Xmax())/2.0,DY()),
-                   TVector2( DX(), DY() ) );
+  return AliMpArea((Xmin()+Xmax())/2.0,DY(), DX(), DY() );
 }
 
 //_____________________________________________________________________________
@@ -372,28 +359,27 @@ AliMpPCB::Clone(const TArrayI& manuids, Int_t ixOffset, Double_t xOffset) const
       return 0;
   }
 
-  AliMpIntPair shift(-fIxmin+ixOffset,0);
+  MpPair_t shift = AliMp::Pair(-fIxmin+ixOffset,0);
 
   // Then change the internal MotifPositions wrt manu id
   // and position (offset in x).
-  for ( Size_t i = 0; i < pcb->GetSize(); ++i )
+  for ( Int_t i = 0; i < pcb->GetSize(); ++i )
     {
       AliMpMotifPosition* mp = pcb->GetMotifPosition(i);
       mp->SetID(manuids[i]);
-      TVector2 pos(mp->Position());
-      pos += TVector2(xOffset,0);
-      mp->SetPosition(pos);
-      AliMpIntPair offset(ixOffset,0);
-      AliMpIntPair low(mp->GetLowIndicesLimit());
+      Double_t posx = mp->GetPositionX() + xOffset;
+      Double_t posy = mp->GetPositionY();
+      mp->SetPosition(posx, posy);
+      MpPair_t low = mp->GetLowIndicesLimit();
       low += shift;
       mp->SetLowIndicesLimit(low);
-      AliMpIntPair high(mp->GetHighIndicesLimit());
+      MpPair_t high = mp->GetHighIndicesLimit();
       high += shift;
       mp->SetHighIndicesLimit(high);
     }
   
-  pcb->fIxmin += shift.GetFirst();
-  pcb->fIxmax += shift.GetFirst();
+  pcb->fIxmin += AliMp::PairFirst(shift);
+  pcb->fIxmax += AliMp::PairFirst(shift);
   pcb->fXoffset = xOffset;
 
   pcb->fActiveXmin += xOffset;
@@ -427,34 +413,19 @@ AliMpPCB::Copy(TObject& o) const
   pcb.fActiveXmin = fActiveXmin;
   pcb.fActiveXmax = fActiveXmax;
 
-#ifdef WITH_ROOT
   AliDebug(1,"Deleting pcb.fMotifPositions");
   pcb.fMotifPositions.Delete();
   AliDebug(1,"Deleting pcb.fMotifPositions : done");
-#else
-  for ( Size_t i = 0; i < pcb.fMotifPositions.size(); ++i )
-  {
-    delete pcb.fMotifPositions[i];
-  }
-#endif
 
-#ifdef WITH_ROOT
-  for ( Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
-#else
-  for ( Size_t i = 0; i < fMotifPositions.size(); ++i )
-#endif  
+  for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
     {
       AliMpMotifPosition* pos = (AliMpMotifPosition*)fMotifPositions[i];
-      AliMpMotifPosition* pcbpos = new AliMpMotifPosition(pos->GetID(),
-                                                          pos->GetMotif(),
-                                                          pos->Position());
+      AliMpMotifPosition* pcbpos 
+        = new AliMpMotifPosition(pos->GetID(), pos->GetMotif(),
+                                 pos->GetPositionX(), pos->GetPositionY());
       pcbpos->SetLowIndicesLimit(pos->GetLowIndicesLimit());
       pcbpos->SetHighIndicesLimit(pos->GetHighIndicesLimit());
-#ifdef WITH_ROOT
       pcb.fMotifPositions.AddLast(pcbpos);
-#else      
-      pcb.fMotifPositions.push_back(pcbpos);
-#endif      
     }
     
     pcb.fNofPads = fNofPads;  
@@ -525,14 +496,10 @@ AliMpPCB::FindMotifPosition(Int_t ix, Int_t iy) const
   /// integer indices (ix,iy).
   ///
   
-#ifdef WITH_ROOT
-  for (Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
-#else  
-  for (Size_t i = 0; i < fMotifPositions.size(); ++i )
-#endif
+  for (Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
     {
       AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
-      if ( mp->HasPad(AliMpIntPair(ix,iy)) )
+      if ( mp->HasPadByIndices(AliMp::Pair(ix,iy)) )
       {
         return mp;
       }
@@ -548,19 +515,18 @@ AliMpPCB::FindMotifPosition(Double_t x, Double_t y) const
   /// Returns the motifPosition located at position (x,y)
   ///
   
-#ifdef WITH_ROOT
-  for (Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
-#else  
-  for (Size_t i = 0; i < fMotifPositions.size(); ++i )
-#endif   
+  for (Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
   {
     AliMpMotifPosition* mp = (AliMpMotifPosition*)fMotifPositions[i];
     
-    TVector2 localPos( TVector2(x,y) - mp->Position() );
+    Double_t localPosX = x - mp->GetPositionX(); 
+    Double_t localPosY = y - mp->GetPositionY();
     
-    AliMpIntPair localIndices(mp->GetMotif()->PadIndicesLocal(localPos));
+    MpPair_t localIndices(
+      mp->GetMotif()->PadIndicesLocal(localPosX, localPosY));
     
-    if ( localIndices.IsValid() && mp->GetMotif()->GetMotifType()->HasPad(localIndices) )
+    if ( localIndices >= 0 && 
+         mp->GetMotif()->GetMotifType()->HasPadByLocalIndices(localIndices) )
     {
       return mp;
     }
@@ -581,17 +547,14 @@ AliMpPCB::GetID() const
 
 //_____________________________________________________________________________
 AliMpMotifPosition*
-AliMpPCB::GetMotifPosition(AliMpPCB::Size_t i) const
+AliMpPCB::GetMotifPosition(Int_t i) const
 {
   ///
   /// Get the i-th motifPosition stored in this PCB's internal array.
   ///
   
-#ifdef WITH_ROOT
   if ( i >= fMotifPositions.GetEntriesFast() ) return 0;
-#else
-  if ( i >= fMotifPositions.size() ) return 0;
-#endif  
+
   return (AliMpMotifPosition*)fMotifPositions[i];
 }
 
@@ -618,18 +581,29 @@ AliMpPCB::GetNofPadsY() const
 }
 
 //_____________________________________________________________________________
-AliMpPCB::Size_t
+Int_t
 AliMpPCB::GetSize() const
 {
   ///
   /// Returns the number of motifPositions stored in this PCB.
   ///
   
-#ifdef WITH_ROOT
   return fMotifPositions.GetEntriesFast();
-#else  
-  return fMotifPositions.size();
-#endif  
+}
+
+//_____________________________________________________________________________
+Bool_t 
+AliMpPCB::HasMotifPositionID(Int_t manuId) const
+{
+  /// Returns whether or not we have manuId
+
+  TIter next(&fMotifPositions);
+  AliMpMotifPosition* pos;
+  while ( ( pos = static_cast<AliMpMotifPosition*>(next()) ) )
+  {
+    if ( pos->GetID() == manuId ) return kTRUE;
+  }
+  return kFALSE;
 }
 
 
@@ -717,11 +691,7 @@ AliMpPCB::Print(Option_t* option) const
   
   if ( option && option[0] == 'M' )
   {
-#ifdef WITH_ROOT
-    for ( Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
-#else  
-    for ( Size_t i = 0; i < fMotifPositions.size(); ++i )
-#endif    
+    for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
     {
       if (option)
            {
@@ -747,15 +717,13 @@ AliMpPCB::Save() const
   TList lines;
   lines.SetOwner(kTRUE);
   
-#ifdef WITH_ROOT
-  for ( Size_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
-#else  
-  for ( Size_t i = 0; i < fMotifPositions.size(); ++i )
-#endif    
+  for ( Int_t i = 0; i < fMotifPositions.GetEntriesFast(); ++i )
   {
     AliMpMotifPosition* pos = GetMotifPosition(i);
     AliMpVMotif* motif = pos->GetMotif();
-    TVector2 lowerLeft(pos->Position()-pos->Dimensions());
+    
+    Double_t lowerLeftX = pos->GetPositionX()-pos->GetDimensionX();
+    Double_t lowerLeftY = pos->GetPositionY()-pos->GetDimensionY();
     TString id(motif->GetID());
     // id is supposed to be of the form %s-%e-%e, and we're only
     // interested in the %s part of it
@@ -768,8 +736,8 @@ AliMpPCB::Save() const
     TString motifName(id(0,index));
     lines.Add(new TObjString(Form("MOTIF %s %d %d",
                                   motifName.Data(),
-                                  TMath::Nint(lowerLeft.X()/fPadSizeX),
-                                  TMath::Nint(lowerLeft.Y()/fPadSizeY))));
+                                  TMath::Nint(lowerLeftX/fPadSizeX),
+                                  TMath::Nint(lowerLeftY/fPadSizeY))));
   }
 
   ofstream out(fileName.Data());