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 "AliCodeTimer.h"
22 #include "AliMUONCluster.h"
23 #include "AliMUONPad.h"
24 #include "AliMUONVDigit.h"
25 #include "AliMUONVDigitStore.h"
27 #include "AliMpArea.h"
28 #include "AliMpConstants.h"
29 #include "AliMpVSegmentation.h"
33 #include <Riostream.h>
34 #include <TClonesArray.h>
37 //-----------------------------------------------------------------------------
38 /// \class AliMUONPreClusterFinder
40 /// Implementation of AliMUONVClusterFinder
42 /// This class simply find adjacent pads to form clusters
44 /// \author Laurent Aphecetche
45 //-----------------------------------------------------------------------------
47 ClassImp(AliMUONPreClusterFinder)
49 //_____________________________________________________________________________
50 AliMUONPreClusterFinder::AliMUONPreClusterFinder()
51 : AliMUONVClusterFinder(),
52 fClusters("AliMUONCluster"),
61 //_____________________________________________________________________________
62 AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
64 /// dtor : note we're owner of the clusters, but not of the pads
67 //_____________________________________________________________________________
69 AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
71 /// Add a pad to the list of pads to be considered
72 if ( pad.DetElemId() != fDetElemId )
74 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
75 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
79 new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
80 // FIXME: should set the ClusterId of that new pad to be -1
84 //_____________________________________________________________________________
86 AliMUONPreClusterFinder::Prepare(Int_t detElemId,
87 TClonesArray* pads[2],
88 const AliMpArea& area)
90 /// Prepare for clustering, by giving access to segmentations and digit lists
95 fDetElemId = detElemId;
98 fShouldAbort = kFALSE;
103 //_____________________________________________________________________________
105 AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
107 /// Add a pad to a cluster
109 if ( cluster.IsMonoCathode() && cluster.Multiplicity() > 199 )
111 /// FIXME : we should at that point really find a better way to remove "bad" preclusters,
112 /// like e.g. computing the charge dispersion (the lower, the most probably we have noise cluster)
113 /// and/or mean charge per pad (if too close to LowestPadCharge, again that's a noise cluster...
114 /// *BUT* this needs carefull testing !
115 fShouldAbort = kTRUE;
119 cluster.AddPad(*pad);
121 Int_t cathode = pad->Cathode();
122 TClonesArray& padArray = *fPads[cathode];
123 // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
124 // present (otherwise just compares pointers) : so that one must be correct
126 padArray.Remove(pad);
127 // TObject* o = padArray.Remove(pad);
130 // AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
131 // " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
132 // " as the first suspect for failed remove");
134 TIter next(&padArray);
137 while ( ( testPad = static_cast<AliMUONPad*>(next())))
139 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
141 AddPad(cluster,testPad);
146 //_____________________________________________________________________________
148 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
150 /// Whether the pad overlaps with the cluster
152 static Double_t precision = 1E-4; // cm
153 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
154 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
156 AliMUONPad* testPad = cluster.Pad(i);
157 // Note: we use negative precision numbers, meaning
158 // the area of the pads will be *increased* by these small numbers
159 // prior to check the overlap by the AreOverlapping method,
160 // so pads touching only by the corners will be considered as
162 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
170 //_____________________________________________________________________________
172 AliMUONPreClusterFinder::GetNextPad(Int_t cathode) const
174 /// Return the next unused pad of given cathode, which is within fArea
176 TIter next(fPads[cathode]);
178 if ( !fArea.IsValid() )
180 return static_cast<AliMUONPad*>(next());
185 while ( ( pad = static_cast<AliMUONPad*>(next())) )
187 AliMpArea padArea(pad->X(), pad->Y(), pad->DX(), pad->DY());
189 if (fArea.Overlap(padArea)) return pad;
196 //_____________________________________________________________________________
198 AliMUONPreClusterFinder::NewCluster()
200 /// Create a new (empty) cluster
201 Int_t id = fClusters.GetLast()+1;
202 AliMUONCluster* cluster = new (fClusters[id]) AliMUONCluster;
203 cluster->SetUniqueID(id);
207 //_____________________________________________________________________________
209 AliMUONPreClusterFinder::RemoveCluster(AliMUONCluster* cluster)
212 /// Note that we are *not* releasing the pads, so they won't be used further on
213 fClusters.Remove(cluster);
214 fClusters.Compress();
217 //_____________________________________________________________________________
219 AliMUONPreClusterFinder::NextCluster()
221 /// Builds the next cluster, and returns it.
223 // Start a new cluster
225 AliMUONPad* pad = GetNextPad(0);
227 AliMUONCluster* cluster(0x0);
229 if (!pad) // protection against no pad in first cathode, which might happen
239 cluster = NewCluster();
240 // Builds (recursively) a cluster on second cathode only
241 AddPad(*cluster,pad);
246 // Builds (recursively) a cluster on first cathode only
248 cluster = NewCluster();
249 AddPad(*cluster,pad);
251 if ( !ShouldAbort() )
253 // On the 2nd cathode, only add pads overlapping with the current cluster
254 TClonesArray& padArray = *fPads[1];
255 TIter next(&padArray);
258 while ( ( testPad = static_cast<AliMUONPad*>(next())) && !ShouldAbort() )
260 if (AreOverlapping(*testPad,*cluster) )
262 AddPad(*cluster,testPad);
270 AliCodeTimerAuto(Form("Skipping a precluster in DE %d because it got too many pads",fDetElemId),0);
271 RemoveCluster(cluster);
272 return NextCluster();
275 if ( cluster->Multiplicity() <= 1 )
277 if ( cluster->Multiplicity() == 0 )
279 // no pad is suspicious
280 AliWarning("Got an empty cluster...");
282 // else only 1 pad (not suspicious, but kind of useless, probably noise)
283 // so we remove it from our list
284 RemoveCluster(cluster);
285 // then proceed further
286 return NextCluster();