]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONCluster.cxx
Make the Scan method public
[u/mrichter/AliRoot.git] / MUON / AliMUONCluster.cxx
index 68654dffbf48e417b905724596da0cce38f5be76..df5f10b58e4e9c7ef878cde48d7802507d91d1bb 100644 (file)
 #include <TVirtualX.h>
 
 #include "AliMUONCluster.h"
+#include "AliMUONPad.h"
+
+#include "AliMpEncodePair.h"
 
 #include "AliLog.h"
-#include "AliMUONPad.h"
 
 //-----------------------------------------------------------------------------
 /// \class AliMUONCluster
@@ -38,6 +40,8 @@
 ///
 //-----------------------------------------------------------------------------
 
+using std::cout;
+using std::endl;
 /// \cond CLASSIMP
 ClassImp(AliMUONCluster)
 /// \endcond
@@ -96,7 +100,7 @@ namespace
 //_____________________________________________________________________________
 AliMUONCluster::AliMUONCluster() 
 : TObject(), 
-fPads(0x0),
+fPads(),
 fHasPosition(kFALSE),
 fPosition(1E9,1E9),
 fPositionError(1E9,1E9),
@@ -108,12 +112,13 @@ fChi2(0)
   fRawCharge[0]=fRawCharge[1]=0;
   fCharge[0]=fCharge[1]=0;
   fIsSaturated[0]=fIsSaturated[1]=kFALSE;
+  fPads.SetOwner(kTRUE);
 }
 
 //_____________________________________________________________________________
 AliMUONCluster::AliMUONCluster(const AliMUONCluster& src)
 : TObject(src),
-fPads(0x0),
+fPads(),
 fHasPosition(kFALSE),
 fPosition(1E9,1E9),
 fPositionError(1E9,1E9),
@@ -121,6 +126,7 @@ fHasCharge(kFALSE),
 fChi2(0)
 {
   /// copy ctor
+  fPads.SetOwner(kTRUE);
   src.Copy(*this);
 }
 
@@ -129,8 +135,10 @@ AliMUONCluster&
 AliMUONCluster::operator=(const AliMUONCluster& src)
 {
   /// assignement operator
-  AliMUONCluster c(src);
-  c.Copy(*this);
+  if ( this != &src ) 
+  {
+    src.Copy(*this);
+  }
   return *this;
 }
 
@@ -138,7 +146,7 @@ AliMUONCluster::operator=(const AliMUONCluster& src)
 AliMUONCluster::~AliMUONCluster()
 {
   /// dtor : note that we're owner of our pads
-  delete fPads;
+//   fPads.Delete();
 }
 
 //_____________________________________________________________________________
@@ -146,7 +154,8 @@ void
 AliMUONCluster::Clear(Option_t*)
 {
   /// Clear our pad array
-  if (fPads) fPads->Clear("C");
+  fPads.Clear();
+//  fPads.Delete();
 }
 
 //_____________________________________________________________________________
@@ -154,7 +163,8 @@ Bool_t
 AliMUONCluster::Contains(const AliMUONPad& pad) const
 {
   /// Whether this cluster contains the pad
-  if (!fPads) return kFALSE;
+  if (fPads.IsEmpty()) return kFALSE;
+  
   for ( Int_t i = 0; i < Multiplicity(); ++i ) 
   {
     AliMUONPad* p = Pad(i);
@@ -188,14 +198,9 @@ AliMUONCluster::AddPad(const AliMUONPad& pad)
 {
   /// Add a pad to our pad array, and update some internal information
   /// accordingly.
-  
-  if (!fPads) 
-  {
-    fPads = new TObjArray(10);
-    fPads->SetOwner(kTRUE);
-  }
+
   AliMUONPad* p = new AliMUONPad(pad);
-  fPads->AddLast(p);
+  fPads.AddLast(p);
   p->SetClusterId(GetUniqueID());
   Int_t cathode = p->Cathode();
   ++(fMultiplicity[cathode]);
@@ -275,8 +280,8 @@ AliMUONCluster::Area() const
   }
 
   // then construct the area from those limits
-  return AliMpArea((lowerLeft+upperRight)/2,
-                   (upperRight-lowerLeft)/2);
+  return AliMpArea((lowerLeft+upperRight).X()/2,(lowerLeft+upperRight).Y()/2, 
+                   (upperRight-lowerLeft).X()/2, (upperRight-lowerLeft).Y()/2);
 }
 
 //_____________________________________________________________________________
@@ -290,20 +295,31 @@ AliMUONCluster::Area(Int_t cathode) const
   TVector2 lowerLeft(1E9,1E9);
   TVector2 upperRight(-1E9,-1E9);
   
-  for ( Int_t i = 0; i < Multiplicity(cathode); ++i )
+  for ( Int_t i = 0; i < Multiplicity(); ++i )
   {
     AliMUONPad* pad = Pad(i);
-    TVector2 ll = pad->Position() - pad->Dimensions();
-    TVector2 ur = pad->Position() + pad->Dimensions();
-    lowerLeft.Set( TMath::Min(ll.X(),lowerLeft.X()),
-                   TMath::Min(ll.Y(),lowerLeft.Y()) );
-    upperRight.Set( TMath::Max(ur.X(),upperRight.X()),
-                    TMath::Max(ur.Y(),upperRight.Y()) );
+    if ( pad->Cathode() == cathode ) 
+    {
+      TVector2 ll = pad->Position() - pad->Dimensions();
+      TVector2 ur = pad->Position() + pad->Dimensions();
+      lowerLeft.Set( TMath::Min(ll.X(),lowerLeft.X()),
+                     TMath::Min(ll.Y(),lowerLeft.Y()) );
+      upperRight.Set( TMath::Max(ur.X(),upperRight.X()),
+                      TMath::Max(ur.Y(),upperRight.Y()) );
+    }
   }
   
   // then construct the area from those limits
-  return AliMpArea((lowerLeft+upperRight)/2,
-                   (upperRight-lowerLeft)/2);
+  return AliMpArea((lowerLeft+upperRight).X()/2,(lowerLeft+upperRight).Y()/2,
+                   (upperRight-lowerLeft).X()/2, (upperRight-lowerLeft).Y()/2);
+}
+
+//_____________________________________________________________________________
+Bool_t
+AliMUONCluster::IsMonoCathode() const
+{
+  /// Whether we have signals only in one of the two cathodes
+  return (Cathode()<2);
 }
 
 //_____________________________________________________________________________
@@ -341,10 +357,14 @@ AliMUONCluster::Copy(TObject& obj) const
   ///
   TObject::Copy(obj);
   AliMUONCluster& dest = static_cast<AliMUONCluster&>(obj);
-  dest.fPads = 0x0;
-  if ( fPads )
+
+//  dest.fPads.Delete();
+  dest.fPads.Clear();
+  
+  for ( Int_t i = 0; i <= fPads.GetLast(); ++i ) 
   {
-    dest.fPads = static_cast<TObjArray*>(fPads->Clone());
+    AliMUONPad* p = static_cast<AliMUONPad*>(fPads.UncheckedAt(i));
+    dest.fPads.AddLast(new AliMUONPad(*p));
   }
   dest.fHasPosition = fHasPosition;
   dest.fPosition = fPosition;
@@ -365,7 +385,21 @@ Float_t
 AliMUONCluster::Charge() const
 {
   /// Return the average charge over both cathodes
-  return (Charge(0)+Charge(1))/2.0;
+  
+  if ( Multiplicity(0) && Multiplicity(1) )
+  {
+    return (Charge(0)+Charge(1))/2.0;
+  }
+  else if ( Multiplicity(0) ) 
+  {
+    return Charge(0);
+  }
+  else if ( Multiplicity(1) ) 
+  {
+    return Charge(1);
+  }
+  AliError("Should not be here ?!");
+  return -1.0;
 }
 
 //_____________________________________________________________________________
@@ -491,43 +525,43 @@ AliMUONCluster::Multiplicity(Int_t cathode) const
 }
 
 //_____________________________________________________________________________
-AliMpIntPair
+Long_t
 AliMUONCluster::NofPads(Int_t statusMask, Bool_t matchMask) const
 {
   /// Number of pads satisfying (or not, depending matchMask) a
-  /// given mask
+  /// given mask 
   
   Int_t nx, ny;
   
   TVector2 dim0(MinPadDimensions(0,statusMask,matchMask));
   TVector2 dim1(MinPadDimensions(1,statusMask,matchMask));
   
-  AliMpIntPair npad0(NofPads(0,statusMask,matchMask));
-  AliMpIntPair npad1(NofPads(1,statusMask,matchMask));
+  Long_t npad0(NofPads(0,statusMask,matchMask));
+  Long_t npad1(NofPads(1,statusMask,matchMask));
   
   if ( TMath::Abs( (dim0-dim1).X() ) < 1E-3 )
   {
-    nx = TMath::Max( npad0.GetFirst(), npad1.GetFirst() );
+    nx = TMath::Max( AliMp::PairFirst(npad0), AliMp::PairFirst(npad1) );
   }
   else
   {
-    nx = dim0.X() < dim1.X() ? npad0.GetFirst() : npad1.GetFirst();
+    nx = dim0.X() < dim1.X() ? AliMp::PairFirst(npad0) : AliMp::PairFirst(npad1);
   }
   
   if ( TMath::Abs( (dim0-dim1).Y() ) < 1E-3 )
   {
-    ny = TMath::Max( npad0.GetSecond(), npad1.GetSecond() );
+    ny = TMath::Max( AliMp::PairSecond(npad0), AliMp::PairSecond(npad1) );
   }
   else
   {
-    ny = dim0.Y() < dim1.Y() ? npad0.GetSecond() : npad1.GetSecond();
+    ny = dim0.Y() < dim1.Y() ? AliMp::PairSecond(npad0) : AliMp::PairSecond(npad1);
   }
   
-  return AliMpIntPair(nx,ny);
+  return AliMp::Pair(nx,ny);
 }
 
 //_____________________________________________________________________________
-AliMpIntPair
+Long_t
 AliMUONCluster::NofPads(Int_t cathode,
                         Int_t statusMask, Bool_t matchMask) const
 {
@@ -537,7 +571,7 @@ AliMUONCluster::NofPads(Int_t cathode,
   Int_t n = Multiplicity(cathode);
   if (!n) 
   {
-    return AliMpIntPair(0,0);
+    return 0;
   }
   Double_t* x = new Double_t[n];
   Double_t* y = new Double_t[n];
@@ -560,7 +594,7 @@ AliMUONCluster::NofPads(Int_t cathode,
   delete[] x;
   delete[] y;
   
-  return AliMpIntPair(cx,cy);
+  return AliMp::Pair(cx,cy);
 }
 
 //_____________________________________________________________________________
@@ -569,15 +603,15 @@ AliMUONCluster::Pad(Int_t index) const
 {
   /// Returns the index-th pad
   
-  if (!fPads) return 0x0;
-  if ( index < fPads->GetLast()+1 )
+  if (fPads.IsEmpty()) return 0x0;
+  if ( index < fPads.GetLast()+1 )
   {
-    return static_cast<AliMUONPad*>(fPads->At(index));
+    return static_cast<AliMUONPad*>(fPads.At(index));
   }
   else
   {
     AliError(Form("Requested index %d out of bounds (%d) Mult is %d",index,
-                  fPads->GetLast(),Multiplicity()));
+                  fPads.GetLast(),Multiplicity()));
     DumpMe();
   }
   return 0x0;
@@ -631,14 +665,11 @@ AliMUONCluster::DumpMe() const
   }
   cout << endl;
 //  cout << " " << Area() << endl;
-  if (fPads
+  for (Int_t i = 0; i < fPads.GetSize(); ++i
   {
-    for (Int_t i = 0; i < fPads->GetSize(); ++i) 
-    {
-      cout << Form("fPads[%d]=%x",i,fPads->At(i)) << endl;
-      if ( fPads->At(i) ) fPads->At(i)->Print();
-    }
-  }  
+    cout << Form("fPads[%d]=%p",i,fPads.At(i)) << endl;
+    if ( fPads.At(i) ) fPads.At(i)->Print();
+  }
 }
 
 
@@ -657,13 +688,11 @@ AliMUONCluster::Print(Option_t* opt) const
     cout << " (errX,errY)=(" << PositionError().X() << "," << PositionError().Y() << ")";
   }
   cout << " " << Area();
-  if (fPads) 
-  {
-    TObjArray* a = static_cast<TObjArray*>(fPads->Clone());
-    a->Sort();
-    a->Print("",opt);
-    delete a;
-  }
+
+  TObjArray* a = static_cast<TObjArray*>(fPads.Clone());
+  a->Sort();
+  a->Print("",opt);
+  delete a;
 }
 
 //_____________________________________________________________________________
@@ -692,21 +721,21 @@ AliMUONCluster::Compare(const TObject* obj) const
   AliMpArea carea(cluster->Area());
   AliMpArea area(Area());
 
-  if ( carea.Position().X() > area.Position().X() ) 
+  if ( carea.GetPositionX() > area.GetPositionX() ) 
   {
     return 1;
   }
-  else if ( carea.Position().X() < area.Position().X() ) 
+  else if ( carea.GetPositionX() < area.GetPositionX() ) 
   {
     return -1;
   }
   else 
   {
-    if ( carea.Position().Y() > area.Position().Y() ) 
+    if ( carea.GetPositionY() > area.GetPositionY() ) 
     {
       return 1;
     }
-    else if ( carea.Position().Y() < area.Position().Y() ) 
+    else if ( carea.GetPositionY() < area.GetPositionY() ) 
     {
       return -1;
     }
@@ -732,13 +761,14 @@ AliMUONCluster::RemovePad(AliMUONPad* pad)
   /// Remove a pad. 
   /// As a consequence, some internal information must be updated
   
-  fPads->Remove(pad);
-  fPads->Compress();
+  fPads.Remove(pad);
+  fPads.Compress();
+  delete pad;
   // update cluster's data
   fIsSaturated[0]=fIsSaturated[1]=kFALSE;
   fMultiplicity[0]=fMultiplicity[1]=0;
   fRawCharge[0]=fRawCharge[1]=0;
-  for ( Int_t i = 0; i <= fPads->GetLast(); ++i )
+  for ( Int_t i = 0; i <= fPads.GetLast(); ++i )
   {
     AliMUONPad* p = Pad(i);
     if ( p->IsSaturated() )