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(),
50 fClusters("AliMUONCluster"),
59 //_____________________________________________________________________________
60 AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
62 /// dtor : note we're owner of the clusters, but not of the pads
65 //_____________________________________________________________________________
67 AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
69 /// Add a pad to the list of pads to be considered
70 if ( pad.DetElemId() != fDetElemId )
72 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
73 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
77 new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
78 // FIXME: should set the ClusterId of that new pad to be -1
82 //_____________________________________________________________________________
84 AliMUONPreClusterFinder::Prepare(Int_t detElemId,
85 TClonesArray* pads[2],
86 const AliMpArea& area)
88 /// Prepare for clustering, by giving access to segmentations and digit lists
93 fDetElemId = detElemId;
96 fShouldAbort = kFALSE;
101 //_____________________________________________________________________________
103 AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
105 /// Add a pad to a cluster
107 if ( cluster.Multiplicity() > 500 )
109 fShouldAbort = kTRUE;
113 cluster.AddPad(*pad);
115 Int_t cathode = pad->Cathode();
116 TClonesArray& padArray = *fPads[cathode];
117 // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
118 // present (otherwise just compares pointers) : so that one must be correct
120 padArray.Remove(pad);
121 // TObject* o = padArray.Remove(pad);
124 // AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
125 // " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
126 // " as the first suspect for failed remove");
128 TIter next(&padArray);
131 while ( ( testPad = static_cast<AliMUONPad*>(next())))
133 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
135 AddPad(cluster,testPad);
140 //_____________________________________________________________________________
142 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
144 /// Whether the pad overlaps with the cluster
146 static Double_t precision = 1E-4; // cm
147 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
148 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
150 AliMUONPad* testPad = cluster.Pad(i);
151 // Note: we use negative precision numbers, meaning
152 // the area of the pads will be *increased* by these small numbers
153 // prior to check the overlap by the AreOverlapping method,
154 // so pads touching only by the corners will be considered as
156 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
164 //_____________________________________________________________________________
166 AliMUONPreClusterFinder::GetNextPad(Int_t cathode) const
168 /// Return the next unused pad of given cathode, which is within fArea
170 TIter next(fPads[cathode]);
172 if ( !fArea.IsValid() )
174 return static_cast<AliMUONPad*>(next());
179 while ( ( pad = static_cast<AliMUONPad*>(next())) )
181 AliMpArea padArea(pad->Position(),pad->Dimensions());
183 if (fArea.Overlap(padArea)) return pad;
190 //_____________________________________________________________________________
192 AliMUONPreClusterFinder::NextCluster()
194 /// Builds the next cluster, and returns it.
195 // AliCodeTimerAuto("pre-clustering")
197 // Start a new cluster
198 Int_t id = fClusters.GetLast()+1;
199 AliMUONCluster* cluster = new (fClusters[id]) AliMUONCluster;
200 cluster->SetUniqueID(id);
202 AliMUONPad* pad = GetNextPad(0);
204 if (!pad) // protection against no pad in first cathode, which might happen
213 // Builds (recursively) a cluster on second cathode only
214 AddPad(*cluster,pad);
218 // Builds (recursively) a cluster on first cathode only
219 AddPad(*cluster,pad);
221 if ( !ShouldAbort() )
223 // On the 2nd cathode, only add pads overlapping with the current cluster
224 TClonesArray& padArray = *fPads[1];
225 TIter next(&padArray);
228 while ( ( testPad = static_cast<AliMUONPad*>(next())) && !ShouldAbort() )
230 if (AreOverlapping(*testPad,*cluster) )
232 AddPad(*cluster,testPad);
240 AliError("Aborting clustering of that DE because we've got too many pads");
241 fClusters.Remove(cluster);
242 fClusters.Compress();
246 if ( cluster->Multiplicity() <= 1 )
248 if ( cluster->Multiplicity() == 0 )
250 // no pad is suspicious
251 AliWarning("Got an empty cluster...");
253 // else only 1 pad (not suspicious, but kind of useless, probably noise)
254 // so we remove it from our list
255 fClusters.Remove(cluster);
256 fClusters.Compress();
257 // then proceed further
258 return NextCluster();