]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/mapping/AliMpSectorSegmentation.cxx
mapping/AliMpPlaneSegmentation.cxx
[u/mrichter/AliRoot.git] / MUON / mapping / AliMpSectorSegmentation.cxx
index 7ba6a99b9d57152908c2c71fe2b9ea19e4329c65..62d5b89ef0a619020970c3418a8d513dde171031 100755 (executable)
@@ -12,6 +12,7 @@
 
 #include <Riostream.h>
 #include <TMath.h>
+#include <TError.h>
 
 #include "AliMpSectorSegmentation.h"
 #include "AliMpSector.h"
 
 ClassImp(AliMpSectorSegmentation)
 
+#ifdef WITH_ROOT
+const Double_t AliMpSectorSegmentation::fgkS1 = 10000.;
+const Double_t AliMpSectorSegmentation::fgkS2 = 100.;
+#endif
+
 //______________________________________________________________________________
 AliMpSectorSegmentation::AliMpSectorSegmentation(const AliMpSector* sector) 
   : AliMpVSegmentation(),
-    fkSector(sector)
+    fkSector(sector),
+    fMaxIndexInX(0),
+    fMaxIndexInY(0)
 {
 //
   fPadBuffer = new AliMpPad(AliMpPad::Invalid());
@@ -48,21 +56,68 @@ AliMpSectorSegmentation::AliMpSectorSegmentation()
   : AliMpVSegmentation(),
     fkSector(0),
     fPadBuffer(0),
-    fPadDimensionsMap()      
+    fPadDimensionsMap(),      
+    fMaxIndexInX(0),
+    fMaxIndexInY(0)
 {
 //
 }
 
+//_____________________________________________________________________________
+AliMpSectorSegmentation::AliMpSectorSegmentation(
+                                    const AliMpSectorSegmentation& right) 
+  : AliMpVSegmentation(right) {
+// 
+  Fatal("AliMpSectorSegmentation", "Copy constructor not provided.");
+}
+
 //______________________________________________________________________________
 AliMpSectorSegmentation::~AliMpSectorSegmentation() {
 // 
   delete fPadBuffer;
 }
 
+//
+// operators
+//
+
+//_____________________________________________________________________________
+AliMpSectorSegmentation& 
+AliMpSectorSegmentation::operator=(const AliMpSectorSegmentation& right)
+{
+  // check assignement to self
+  if (this == &right) return *this;
+
+  Fatal("operator =", "Assignement operator not provided.");
+    
+  return *this;  
+}    
+
 //
 // private methods
 //
 
+#ifdef WITH_ROOT
+//______________________________________________________________________________
+Long_t AliMpSectorSegmentation::GetIndex(const TVector2& vector2) const
+{
+// Converts the two vector to long.
+// ---
+
+  return Long_t(TMath::Floor((vector2.X()*fgkS1 + vector2.Y())*fgkS2));
+}  
+
+//______________________________________________________________________________
+TVector2  AliMpSectorSegmentation::GetVector(Long_t index) const
+{
+// Converts the long index to twovector.
+// ---
+
+  return TVector2( TMath::Floor(index/fgkS1)/fgkS2,
+                   (index - TMath::Floor(index/fgkS1)*fgkS1)/fgkS2 );
+}  
+#endif
+
 //______________________________________________________________________________
 void AliMpSectorSegmentation::FillPadDimensionsMap()
 {
@@ -74,8 +129,15 @@ void AliMpSectorSegmentation::FillPadDimensionsMap()
     Int_t  zoneID = zone->GetID();
     
     if (!AliMpConstants::IsEqual(zone->GetPadDimensions(), TVector2())) {
+
       // regular zone
+#ifdef WITH_STL
       fPadDimensionsMap[zoneID*10] = zone->GetPadDimensions();
+#endif
+#ifdef WITH_ROOT
+     fPadDimensionsMap.Add((Long_t)(zoneID*10), 
+                            GetIndex(zone->GetPadDimensions()));
+#endif
     }
     else {
       // special zone
@@ -86,7 +148,13 @@ void AliMpSectorSegmentation::FillPadDimensionsMap()
        
        for (Int_t k=0; k<motif->GetNofPadDimensions(); k++) {
          Int_t index = zoneID*10 +  subIndex++;
+#ifdef WITH_STL
           fPadDimensionsMap[index] = motif->GetPadDimensions(k);
+#endif
+#ifdef WITH_ROOT
+          fPadDimensionsMap.Add((Long_t)(index), 
+                            GetIndex(motif->GetPadDimensions(k)));
+#endif
        }
       }          
     }    
@@ -312,7 +380,10 @@ AliMpSectorSegmentation::PadByIndices(const AliMpIntPair& indices,
    
   AliMpMotifPosition* motifPos = FindMotifPosition(indices);
   if (!motifPos) {    
-    if (warning) Warning("PadByIndices","Pad indices not contained in any motif!");
+    if (warning) {
+      cout << "indices " <<  indices << endl;
+      Warning("PadByIndices","Pad indices not contained in any motif!");
+    }  
     return AliMpPad::Invalid();
   }
   
@@ -400,6 +471,34 @@ AliMpSectorSegmentation::PadByDirection(const TVector2& startPosition,
   return AliMpPad::Invalid();  
 }
 
+//______________________________________________________________________________
+Int_t  AliMpSectorSegmentation::MaxPadIndexX()
+{
+// Return maximum pad index in x
+
+  if (fMaxIndexInX) return fMaxIndexInX;
+  
+  for (Int_t i=0; i<fkSector->GetNofRows(); i++) {
+    Int_t ixh = fkSector->GetRow(i)->GetHighIndicesLimit().GetFirst();
+    if ( ixh > fMaxIndexInX ) fMaxIndexInX = ixh;
+  }  
+  return fMaxIndexInX;
+}
+
+//______________________________________________________________________________
+Int_t  AliMpSectorSegmentation::MaxPadIndexY()
+{
+// Return maximum pad index in y
+
+  if (fMaxIndexInY) return fMaxIndexInY;
+  
+  for (Int_t i=0; i<fkSector->GetNofRows(); i++) {
+    Int_t iyh = fkSector->GetRow(i)->GetHighIndicesLimit().GetSecond();
+    if ( iyh > fMaxIndexInY ) fMaxIndexInY = iyh;
+  }  
+  return fMaxIndexInY;
+}
+
 //______________________________________________________________________________
 Bool_t AliMpSectorSegmentation::HasPad(const AliMpIntPair& indices) const
 {
@@ -443,14 +542,27 @@ Int_t AliMpSectorSegmentation::Zone(const AliMpPad& pad, Bool_t warning) const
     return 0;
   }  
 
+#ifdef WITH_STL
   PadDimensionsMapCIterator it;
   for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
     if (AliMpConstants::IsEqual(it->second, pad.Dimensions()))
       return it->first;
   }
+#endif
+
+#ifdef WITH_ROOT
+  PadDimensionsMapCIterator it(&fPadDimensionsMap);
+  Long_t key, value;
+  while ( it.Next(key, value) ) {
+    TVector2 dimensions =  GetVector(value);
+    if (AliMpConstants::IsEqual(dimensions, pad.Dimensions()))
+      return (Int_t)key;
+  } 
+#endif
 
   // Should never happen
-  Fatal("Zone(AliMpPad)", "not found");
+  Error("Zone(AliMpPad)", "not found");
+  cerr << pad << endl;
   return 0;
 }  
 
@@ -461,8 +573,15 @@ AliMpSectorSegmentation::PadDimensions(Int_t zone, Bool_t warning) const
 // Returns the pad dimensions for the zone with the specified zone index.
 // ---
 
+#ifdef WITH_STL
   PadDimensionsMapCIterator it = fPadDimensionsMap.find(zone);
   if (it != fPadDimensionsMap.end()) return it->second;
+#endif
+
+#ifdef WITH_ROOT
+  Long_t value = fPadDimensionsMap.GetValue(zone);
+  if (value) return GetVector(value);
+#endif
 
   if (warning) Warning("PadDimensions(zone)", "not found");
   return TVector2();
@@ -506,3 +625,35 @@ Bool_t AliMpSectorSegmentation::CircleTest(const AliMpIntPair& indices) const
   
   return true;
 }
+
+//______________________________________________________________________________
+void AliMpSectorSegmentation::PrintZones() const
+{
+// Prints all zones and pads dimensions from the map.
+// ---
+
+  cout << "Zones: " << endl;
+
+#ifdef WITH_STL
+  PadDimensionsMapCIterator it;
+  for (it = fPadDimensionsMap.begin(); it != fPadDimensionsMap.end(); ++it) {
+    cout << "    zone: " <<   setw(4) << it->first;
+    cout << "    pad dimensions: ( " 
+         << it->second.X() << ", " << it->second.Y() << ")" << endl; 
+  }
+#endif
+
+#ifdef WITH_ROOT
+  PadDimensionsMapCIterator it(&fPadDimensionsMap);
+  Long_t key, value;
+  while ( it.Next(key, value) ) {
+    //cout << "Iterating over: " << key << ", " << value << endl;
+    TVector2 dimensions =  GetVector(value);
+
+    cout << "    zone: " <<   setw(4) << key;
+    cout << "    pad dimensions: ( " 
+         << dimensions.X() << ", " << dimensions.Y() << ")" << endl; 
+  }
+#endif
+}
+