]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - MUON/AliMUONPreClusterFinder.cxx
Compilation on Windows/Cygwin. Corrected dependences
[u/mrichter/AliRoot.git] / MUON / AliMUONPreClusterFinder.cxx
index ce8cfca42bce05fc9617c50930af63c3b0cf1e9d..bd098848b91bd093ef71d35290b0e1bd60c482a2 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 "AliMUONDigit.h"
+#include "AliMUONVDigit.h"
+#include "AliMUONVDigitStore.h"
+
+#include "AliMpArea.h"
+#include "AliMpConstants.h"
+#include "AliMpVSegmentation.h"
 
+#include "AliLog.h"
+
+#include <Riostream.h>
+#include <TClonesArray.h>
+#include <TVector2.h>
+
+//-----------------------------------------------------------------------------
 /// \class AliMUONPreClusterFinder
 ///
 /// Implementation of AliMUONVClusterFinder
@@ -33,6 +40,7 @@
 /// This class simply find adjacent pads to form clusters
 ///
 /// \author Laurent Aphecetche
+//-----------------------------------------------------------------------------
 
 ClassImp(AliMUONPreClusterFinder)
 
@@ -40,27 +48,18 @@ ClassImp(AliMUONPreClusterFinder)
 AliMUONPreClusterFinder::AliMUONPreClusterFinder()
 : AliMUONVClusterFinder(),
   fClusters(0x0),
-  fSegmentations(0x0),
-  fDigits(0x0),
-  fDetElemId(0)
+  fPads(0x0),
+  fDetElemId(0),
+  fArea()
 {
-    /// 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)
+  /// dtor : note we're owner of the clusters, but not of the pads
   delete fClusters;
-  for ( Int_t i = 0; i < 2; ++i )
-  {
-    delete fPads[i];
-  }  
 }
 
 //_____________________________________________________________________________
@@ -82,65 +81,19 @@ AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
 
 //_____________________________________________________________________________
 Bool_t
-AliMUONPreClusterFinder::Prepare(const AliMpVSegmentation* segmentations[2],
-                                 TClonesArray* digits[2]) 
-// 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
   
-  fSegmentations = segmentations;
-  fDigits = digits;
-  
   delete fClusters;
   fClusters = new TClonesArray("AliMUONCluster");
-  for ( Int_t i = 0; i < 2; ++i )
-  {
-    delete fPads[i];
-    fPads[i] = new TClonesArray("AliMUONPad");
-  }
-  
-  fDetElemId = -1;
-  
-  // Converts digits into pads
-  for ( Int_t cathode = 0; cathode < 2; ++cathode )
-  {
-    if ( !digits[cathode] ) continue;
-
-    AliMUONDigit* d;
-    TIter next(digits[cathode]);
-    while ( ( d = static_cast<AliMUONDigit*>(next())))
-    {
-      Int_t ix = d->PadX();
-      Int_t iy = d->PadY();
-      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->Signal());
-      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;
-  }
 
+  fPads = pads;
+  fDetElemId = detElemId;
+  fArea = area;
+  
   return kTRUE;
 }
 
@@ -153,11 +106,20 @@ AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
   
   Int_t cathode = pad->Cathode();
   TClonesArray& padArray = *fPads[cathode];
+  // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
+  // present (otherwise just compares pointers) : so that one must be correct
+  // if implemented !
   padArray.Remove(pad);
-  padArray.Compress();
+ // TObject* o = padArray.Remove(pad); 
+//  if (!o)
+//  {
+//    AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
+//             " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
+//             " as the first suspect for failed remove");
+//  }  
   TIter next(&padArray);
   AliMUONPad* testPad;
-  
+
   while ( ( testPad = static_cast<AliMUONPad*>(next())))
   {
     if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
@@ -191,23 +153,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->Position(),pad->Dimensions());
+      
+      if (fArea.Overlap(padArea)) return pad;
+
+    }
+    return 0x0;
+  }
+}
+
 //_____________________________________________________________________________
 AliMUONCluster* 
 AliMUONPreClusterFinder::NextCluster()
 {
   /// Builds the next cluster, and returns it.
+//  AliCodeTimerAuto("pre-clustering")
   
   // Start a new cluster
   Int_t id = fClusters->GetLast()+1;
   AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
   cluster->SetUniqueID(id);
   
-  AliMUONPad* pad = static_cast<AliMUONPad*>(fPads[0]->First());
+  AliMUONPad* pad = GetNextPad(0);
   
   if (!pad) // protection against no pad in first cathode, which might happen
   {
     // try other cathode
-    pad = static_cast<AliMUONPad*>(fPads[1]->First());
+    pad = GetNextPad(1);
     if (!pad) 
     {
       // we are done.
@@ -228,7 +217,7 @@ AliMUONPreClusterFinder::NextCluster()
   
     while ( ( testPad = static_cast<AliMUONPad*>(next())))
     {
-      if ( AreOverlapping(*testPad,*cluster) )
+      if (AreOverlapping(*testPad,*cluster) )
       {
         AddPad(*cluster,testPad);
       }