1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 #include "AliMUONPreClusterFinder.h"
20 #include "AliMUONCluster.h"
21 #include "AliMUONPad.h"
22 #include "AliMUONVDigit.h"
23 #include "AliMUONVDigitStore.h"
25 #include "AliMpArea.h"
26 #include "AliMpConstants.h"
27 #include "AliMpVSegmentation.h"
31 #include <Riostream.h>
32 #include <TClonesArray.h>
35 //-----------------------------------------------------------------------------
36 /// \class AliMUONPreClusterFinder
38 /// Implementation of AliMUONVClusterFinder
40 /// This class simply find adjacent pads to form clusters
42 /// \author Laurent Aphecetche
43 //-----------------------------------------------------------------------------
45 ClassImp(AliMUONPreClusterFinder)
47 //_____________________________________________________________________________
48 AliMUONPreClusterFinder::AliMUONPreClusterFinder()
49 : AliMUONVClusterFinder(),
59 //_____________________________________________________________________________
60 AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
62 /// dtor : note we're owner of the clusters, but not of the pads
66 //_____________________________________________________________________________
68 AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
70 /// Add a pad to the list of pads to be considered
71 if ( pad.DetElemId() != fDetElemId )
73 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
74 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
78 new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
79 // FIXME: should set the ClusterId of that new pad to be -1
83 //_____________________________________________________________________________
85 AliMUONPreClusterFinder::Prepare(Int_t detElemId,
86 TClonesArray* pads[2],
87 const AliMpArea& area)
89 /// Prepare for clustering, by giving access to segmentations and digit lists
92 fClusters = new TClonesArray("AliMUONCluster");
95 fDetElemId = detElemId;
98 fShouldAbort = kFALSE;
103 //_____________________________________________________________________________
105 AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
107 /// Add a pad to a cluster
109 if ( cluster.Multiplicity() > 500 )
111 fShouldAbort = kTRUE;
115 cluster.AddPad(*pad);
117 Int_t cathode = pad->Cathode();
118 TClonesArray& padArray = *fPads[cathode];
119 // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
120 // present (otherwise just compares pointers) : so that one must be correct
122 padArray.Remove(pad);
123 // TObject* o = padArray.Remove(pad);
126 // AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
127 // " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
128 // " as the first suspect for failed remove");
130 TIter next(&padArray);
133 while ( ( testPad = static_cast<AliMUONPad*>(next())))
135 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
137 AddPad(cluster,testPad);
142 //_____________________________________________________________________________
144 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
146 /// Whether the pad overlaps with the cluster
148 static Double_t precision = 1E-4; // cm
149 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
150 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
152 AliMUONPad* testPad = cluster.Pad(i);
153 // Note: we use negative precision numbers, meaning
154 // the area of the pads will be *increased* by these small numbers
155 // prior to check the overlap by the AreOverlapping method,
156 // so pads touching only by the corners will be considered as
158 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
166 //_____________________________________________________________________________
168 AliMUONPreClusterFinder::GetNextPad(Int_t cathode) const
170 /// Return the next unused pad of given cathode, which is within fArea
172 TIter next(fPads[cathode]);
174 if ( !fArea.IsValid() )
176 return static_cast<AliMUONPad*>(next());
181 while ( ( pad = static_cast<AliMUONPad*>(next())) )
183 AliMpArea padArea(pad->Position(),pad->Dimensions());
185 if (fArea.Overlap(padArea)) return pad;
192 //_____________________________________________________________________________
194 AliMUONPreClusterFinder::NextCluster()
196 /// Builds the next cluster, and returns it.
197 // AliCodeTimerAuto("pre-clustering")
199 // Start a new cluster
200 Int_t id = fClusters->GetLast()+1;
201 AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
202 cluster->SetUniqueID(id);
204 AliMUONPad* pad = GetNextPad(0);
206 if (!pad) // protection against no pad in first cathode, which might happen
215 // Builds (recursively) a cluster on second cathode only
216 AddPad(*cluster,pad);
220 // Builds (recursively) a cluster on first cathode only
221 AddPad(*cluster,pad);
223 if ( !ShouldAbort() )
225 // On the 2nd cathode, only add pads overlapping with the current cluster
226 TClonesArray& padArray = *fPads[1];
227 TIter next(&padArray);
230 while ( ( testPad = static_cast<AliMUONPad*>(next())) && !ShouldAbort() )
232 if (AreOverlapping(*testPad,*cluster) )
234 AddPad(*cluster,testPad);
242 AliError("Aborting clustering of that DE because we've got too many pads");
243 fClusters->Remove(cluster);
244 fClusters->Compress();
248 if ( cluster->Multiplicity() <= 1 )
250 if ( cluster->Multiplicity() == 0 )
252 // no pad is suspicious
253 AliWarning("Got an empty cluster...");
255 // else only 1 pad (not suspicious, but kind of useless, probably noise)
256 // so we remove it from our list
257 fClusters->Remove(cluster);
258 fClusters->Compress();
259 // then proceed further
260 return NextCluster();