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 "AliMUONVDigit.h"
28 #include "AliMUONVDigitStore.h"
30 /// \class AliMUONPreClusterFinder
32 /// Implementation of AliMUONVClusterFinder
34 /// This class simply find adjacent pads to form clusters
36 /// \author Laurent Aphecetche
38 ClassImp(AliMUONPreClusterFinder)
40 //_____________________________________________________________________________
41 AliMUONPreClusterFinder::AliMUONPreClusterFinder()
42 : 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 const AliMUONVDigitStore& digitStore)
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;
94 fClusters = new TClonesArray("AliMUONCluster");
95 for ( Int_t i = 0; i < 2; ++i )
98 fPads[i] = new TClonesArray("AliMUONPad");
103 TIter next(digitStore.CreateIterator());
106 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
108 Int_t ix = d->PadX();
109 Int_t iy = d->PadY();
110 Int_t cathode = d->Cathode();
111 AliMpPad pad = fSegmentations[cathode]->PadByIndices(AliMpIntPair(ix,iy));
112 TClonesArray& padArray = *(fPads[cathode]);
113 if ( fDetElemId == -1 )
115 fDetElemId = d->DetElemId();
119 if ( d->DetElemId() != fDetElemId )
121 AliError("Something is seriously wrong with DE. Aborting clustering");
126 AliMUONPad mpad(fDetElemId,cathode,
127 ix,iy,pad.Position().X(),pad.Position().Y(),
128 pad.Dimensions().X(),pad.Dimensions().Y(),
130 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
131 new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);
133 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
135 // no pad at all, nothing to do...
142 //_____________________________________________________________________________
144 AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
146 /// Add a pad to a cluster
147 cluster.AddPad(*pad);
149 Int_t cathode = pad->Cathode();
150 TClonesArray& padArray = *fPads[cathode];
151 padArray.Remove(pad);
153 TIter next(&padArray);
156 while ( ( testPad = static_cast<AliMUONPad*>(next())))
158 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
160 AddPad(cluster,testPad);
165 //_____________________________________________________________________________
167 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
169 /// Whether the pad overlaps with the cluster
171 static Double_t precision = 1E-4; // cm
172 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
173 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
175 AliMUONPad* testPad = cluster.Pad(i);
176 // Note: we use negative precision numbers, meaning
177 // the area of the pads will be *increased* by these small numbers
178 // prior to check the overlap by the AreOverlapping method,
179 // so pads touching only by the corners will be considered as
181 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
189 //_____________________________________________________________________________
191 AliMUONPreClusterFinder::NextCluster()
193 /// Builds the next cluster, and returns it.
195 // Start a new cluster
196 Int_t id = fClusters->GetLast()+1;
197 AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
198 cluster->SetUniqueID(id);
200 AliMUONPad* pad = static_cast<AliMUONPad*>(fPads[0]->First());
202 if (!pad) // protection against no pad in first cathode, which might happen
205 pad = static_cast<AliMUONPad*>(fPads[1]->First());
211 // Builds (recursively) a cluster on second cathode only
212 AddPad(*cluster,pad);
216 // Builds (recursively) a cluster on first cathode only
217 AddPad(*cluster,pad);
219 // On the 2nd cathode, only add pads overlapping with the current cluster
220 TClonesArray& padArray = *fPads[1];
221 TIter next(&padArray);
224 while ( ( testPad = static_cast<AliMUONPad*>(next())))
226 if ( AreOverlapping(*testPad,*cluster) )
228 AddPad(*cluster,testPad);
233 if ( cluster->Multiplicity() <= 1 )
235 if ( cluster->Multiplicity() == 0 )
237 // no pad is suspicious
238 AliWarning("Got an empty cluster...");
240 // else only 1 pad (not suspicious, but kind of useless, probably noise)
241 // so we remove it from our list
242 fClusters->Remove(cluster);
243 fClusters->Compress();
244 // then proceed further
245 return NextCluster();