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"
21 #include "AliMUONCluster.h"
22 #include "AliMpVSegmentation.h"
23 #include "TClonesArray.h"
24 #include "AliMpArea.h"
26 #include "AliMUONPad.h"
27 #include "AliMUONDigit.h"
29 /// \class AliMUONPreClusterFinder
31 /// Implementation of AliMUONVClusterFinder
33 /// This class simply find adjacent pads to form clusters
35 /// \author Laurent Aphecetche
37 ClassImp(AliMUONPreClusterFinder)
39 //_____________________________________________________________________________
40 AliMUONPreClusterFinder::AliMUONPreClusterFinder()
41 : AliMUONVClusterFinder(),
48 for ( Int_t i = 0; i < 2; ++i )
54 //_____________________________________________________________________________
55 AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
57 /// dtor : note we're owner of the pads and the clusters, but not of
58 /// the remaining objects (digits, segmentations)
60 for ( Int_t i = 0; i < 2; ++i )
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(const AliMpVSegmentation* segmentations[2],
86 TClonesArray* digits[2])
87 // FIXME : add area on which to look for clusters here.
89 /// Prepare for clustering, by giving access to segmentations and digit lists
91 fSegmentations = segmentations;
95 fClusters = new TClonesArray("AliMUONCluster");
96 for ( Int_t i = 0; i < 2; ++i )
99 fPads[i] = new TClonesArray("AliMUONPad");
104 // Converts digits into pads
105 for ( Int_t cathode = 0; cathode < 2; ++cathode )
107 if ( !digits[cathode] ) continue;
110 TIter next(digits[cathode]);
111 while ( ( d = static_cast<AliMUONDigit*>(next())))
113 Int_t ix = d->PadX();
114 Int_t iy = d->PadY();
115 AliMpPad pad = fSegmentations[cathode]->PadByIndices(AliMpIntPair(ix,iy));
116 TClonesArray& padArray = *(fPads[cathode]);
117 if ( fDetElemId == -1 )
119 fDetElemId = d->DetElemId();
123 if ( d->DetElemId() != fDetElemId )
125 AliError("Something is seriously wrong with DE. Aborting clustering");
130 AliMUONPad mpad(fDetElemId,cathode,
131 ix,iy,pad.Position().X(),pad.Position().Y(),
132 pad.Dimensions().X(),pad.Dimensions().Y(),
134 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
135 new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);
138 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
140 // no pad at all, nothing to do...
147 //_____________________________________________________________________________
149 AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
151 /// Add a pad to a cluster
152 cluster.AddPad(*pad);
154 Int_t cathode = pad->Cathode();
155 TClonesArray& padArray = *fPads[cathode];
156 padArray.Remove(pad);
158 TIter next(&padArray);
161 while ( ( testPad = static_cast<AliMUONPad*>(next())))
163 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
165 AddPad(cluster,testPad);
170 //_____________________________________________________________________________
172 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
174 /// Whether the pad overlaps with the cluster
176 static Double_t precision = 1E-4; // cm
177 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
178 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
180 AliMUONPad* testPad = cluster.Pad(i);
181 // Note: we use negative precision numbers, meaning
182 // the area of the pads will be *increased* by these small numbers
183 // prior to check the overlap by the AreOverlapping method,
184 // so pads touching only by the corners will be considered as
186 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
194 //_____________________________________________________________________________
196 AliMUONPreClusterFinder::NextCluster()
198 /// Builds the next cluster, and returns it.
200 // Start a new cluster
201 Int_t id = fClusters->GetLast()+1;
202 AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
203 cluster->SetUniqueID(id);
205 AliMUONPad* pad = static_cast<AliMUONPad*>(fPads[0]->First());
207 if (!pad) // protection against no pad in first cathode, which might happen
210 pad = static_cast<AliMUONPad*>(fPads[1]->First());
216 // Builds (recursively) a cluster on second cathode only
217 AddPad(*cluster,pad);
221 // Builds (recursively) a cluster on first cathode only
222 AddPad(*cluster,pad);
224 // On the 2nd cathode, only add pads overlapping with the current cluster
225 TClonesArray& padArray = *fPads[1];
226 TIter next(&padArray);
229 while ( ( testPad = static_cast<AliMUONPad*>(next())))
231 if ( AreOverlapping(*testPad,*cluster) )
233 AddPad(*cluster,testPad);
238 if ( cluster->Multiplicity() <= 1 )
240 if ( cluster->Multiplicity() == 0 )
242 // no pad is suspicious
243 AliWarning("Got an empty cluster...");
245 // else only 1 pad (not suspicious, but kind of useless, probably noise)
246 // so we remove it from our list
247 fClusters->Remove(cluster);
248 fClusters->Compress();
249 // then proceed further
250 return NextCluster();