]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPreClusterFinder.cxx
temporary bugfix: the operator functions of the AliHLTReadoutList class did not work
[u/mrichter/AliRoot.git] / MUON / AliMUONPreClusterFinder.cxx
index a21124077eb1b0442855e8f3f4af4f57eb7cb2fd..5c43988fd66cd91338aa7fcbf8e602b1925ea1f9 100644 (file)
 
 #include "AliMUONPreClusterFinder.h"
 
-#include "AliLog.h"
 #include "AliMUONCluster.h"
-#include "AliMpVSegmentation.h"
-#include "TClonesArray.h"
-#include "AliMpArea.h"
-#include "TVector2.h"
 #include "AliMUONPad.h"
 #include "AliMUONVDigit.h"
 #include "AliMUONVDigitStore.h"
-//#include "AliCodeTimer.h"
+
+#include "AliMpArea.h"
+#include "AliMpConstants.h"
+#include "AliMpVSegmentation.h"
+
+#include "AliLog.h"
+
+#include <Riostream.h>
+#include <TClonesArray.h>
+#include <TVector2.h>
 
 //-----------------------------------------------------------------------------
 /// \class AliMUONPreClusterFinder
@@ -43,27 +47,19 @@ ClassImp(AliMUONPreClusterFinder)
 //_____________________________________________________________________________
 AliMUONPreClusterFinder::AliMUONPreClusterFinder()
 : AliMUONVClusterFinder(),
-  fClusters(0x0),
-  fSegmentations(0x0),
-  fDetElemId(0)
+  fClusters("AliMUONCluster"),
+  fPads(0x0),
+  fDetElemId(0),
+  fArea(),
+  fShouldAbort(kFALSE)
 {
-    /// ctor
-  for ( Int_t i = 0; i < 2; ++i )
-  {
-    fPads[i] = 0x0;
-  } 
+  /// ctor
 }
 
 //_____________________________________________________________________________
 AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
 {
-  /// dtor : note we're owner of the pads and the clusters, but not of
-  /// the remaining objects (digits, segmentations)
-  delete fClusters;
-  for ( Int_t i = 0; i < 2; ++i )
-  {
-    delete fPads[i];
-  }  
+  /// dtor : note we're owner of the clusters, but not of the pads
 }
 
 //_____________________________________________________________________________
@@ -85,59 +81,19 @@ AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
 
 //_____________________________________________________________________________
 Bool_t
-AliMUONPreClusterFinder::Prepare(const AliMpVSegmentation* segmentations[2],
-                                 const AliMUONVDigitStore& digitStore)
-// FIXME : add area on which to look for clusters here.
+AliMUONPreClusterFinder::Prepare(Int_t detElemId,
+                                 TClonesArray* pads[2],
+                                 const AliMpArea& area)
 {
   /// Prepare for clustering, by giving access to segmentations and digit lists
+
+  fClusters.Clear("C");
   
-  fSegmentations = segmentations;
-  
-  delete fClusters;
-  fClusters = new TClonesArray("AliMUONCluster");
-  for ( Int_t i = 0; i < 2; ++i )
-  {
-    delete fPads[i];
-    fPads[i] = new TClonesArray("AliMUONPad");
-  }
-  
-  fDetElemId = -1;
-  
-  TIter next(digitStore.CreateIterator());
-  AliMUONVDigit* d;
+  fPads = pads;
+  fDetElemId = detElemId;
+  fArea = area;
   
-  while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
-  {
-    Int_t ix = d->PadX();
-    Int_t iy = d->PadY();
-    Int_t cathode = d->Cathode();
-    AliMpPad pad = fSegmentations[cathode]->PadByIndices(AliMpIntPair(ix,iy));
-    TClonesArray& padArray = *(fPads[cathode]);
-    if ( fDetElemId == -1 ) 
-    {
-      fDetElemId = d->DetElemId();
-    }
-    else
-    {
-      if ( d->DetElemId() != fDetElemId ) 
-      {
-        AliError("Something is seriously wrong with DE. Aborting clustering");
-        return kFALSE;
-      }
-    }
-    
-    AliMUONPad mpad(fDetElemId,cathode,
-                    ix,iy,pad.Position().X(),pad.Position().Y(),
-                    pad.Dimensions().X(),pad.Dimensions().Y(),
-                    d->Charge());
-    if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE); 
-    new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);      
-  }
-  if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
-  {
-    // no pad at all, nothing to do...
-    return kFALSE;
-  }
+  fShouldAbort = kFALSE;
   
   return kTRUE;
 }
@@ -147,6 +103,13 @@ void
 AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
 {
   /// Add a pad to a cluster
+  
+  if ( cluster.Multiplicity() > 500 ) 
+  {
+    fShouldAbort = kTRUE;
+    return;
+  }
+  
   cluster.AddPad(*pad);
   
   Int_t cathode = pad->Cathode();
@@ -198,27 +161,50 @@ AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
   return kFALSE;
 }
 
+//_____________________________________________________________________________
+AliMUONPad*
+AliMUONPreClusterFinder::GetNextPad(Int_t cathode) const
+{
+/// Return the next unused pad of given cathode, which is within fArea
+
+  TIter next(fPads[cathode]);
+  
+  if ( !fArea.IsValid() )
+  {
+    return static_cast<AliMUONPad*>(next());
+  }
+  else
+  {
+    AliMUONPad* pad;
+    while ( ( pad = static_cast<AliMUONPad*>(next())) )
+    {
+      AliMpArea padArea(pad->X(), pad->Y(), pad->DX(), pad->DY());
+      
+      if (fArea.Overlap(padArea)) return pad;
+
+    }
+    return 0x0;
+  }
+}
+
 //_____________________________________________________________________________
 AliMUONCluster* 
 AliMUONPreClusterFinder::NextCluster()
 {
   /// Builds the next cluster, and returns it.
-  
-//  AliCodeTimerAuto("")
+//  AliCodeTimerAuto("pre-clustering")
   
   // Start a new cluster
-  Int_t id = fClusters->GetLast()+1;
-  AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
+  Int_t id = fClusters.GetLast()+1;
+  AliMUONCluster* cluster = new (fClusters[id]) AliMUONCluster;
   cluster->SetUniqueID(id);
   
-  TIter next(fPads[0]);
-  AliMUONPad* pad = static_cast<AliMUONPad*>(next());
+  AliMUONPad* pad = GetNextPad(0);
   
   if (!pad) // protection against no pad in first cathode, which might happen
   {
     // try other cathode
-    TIter next(fPads[1]);
-    pad = static_cast<AliMUONPad*>(next());
+    pad = GetNextPad(1);
     if (!pad) 
     {
       // we are done.
@@ -232,20 +218,31 @@ AliMUONPreClusterFinder::NextCluster()
     // Builds (recursively) a cluster on first cathode only
     AddPad(*cluster,pad);
     
-    // On the 2nd cathode, only add pads overlapping with the current cluster
-    TClonesArray& padArray = *fPads[1];
-    TIter next(&padArray);
-    AliMUONPad* testPad;
-  
-    while ( ( testPad = static_cast<AliMUONPad*>(next())))
+    if ( !ShouldAbort() ) 
     {
-      if ( AreOverlapping(*testPad,*cluster) )
+      // On the 2nd cathode, only add pads overlapping with the current cluster
+      TClonesArray& padArray = *fPads[1];
+      TIter next(&padArray);
+      AliMUONPad* testPad;
+      
+      while ( ( testPad = static_cast<AliMUONPad*>(next())) && !ShouldAbort() )
       {
-        AddPad(*cluster,testPad);
+        if (AreOverlapping(*testPad,*cluster) )
+        {
+          AddPad(*cluster,testPad);
+        }
       }
     }
   }
   
+  if ( ShouldAbort() ) 
+  {
+    AliError(Form("Aborting clustering of DE %d because we've got too many pads",fDetElemId));
+    fClusters.Remove(cluster);
+    fClusters.Compress();
+    return 0x0;
+  }
+  
   if ( cluster->Multiplicity() <= 1 )
   {
     if ( cluster->Multiplicity() == 0 ) 
@@ -255,8 +252,8 @@ AliMUONPreClusterFinder::NextCluster()
     }
     // else only 1 pad (not suspicious, but kind of useless, probably noise)
     // so we remove it from our list
-    fClusters->Remove(cluster);
-    fClusters->Compress();
+    fClusters.Remove(cluster);
+    fClusters.Compress();
     // then proceed further
     return NextCluster();
   }