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"
29 //#include "AliCodeTimer.h"
31 //-----------------------------------------------------------------------------
32 /// \class AliMUONPreClusterFinder
34 /// Implementation of AliMUONVClusterFinder
36 /// This class simply find adjacent pads to form clusters
38 /// \author Laurent Aphecetche
39 //-----------------------------------------------------------------------------
41 ClassImp(AliMUONPreClusterFinder)
43 //_____________________________________________________________________________
44 AliMUONPreClusterFinder::AliMUONPreClusterFinder()
45 : AliMUONVClusterFinder(),
51 for ( Int_t i = 0; i < 2; ++i )
57 //_____________________________________________________________________________
58 AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
60 /// dtor : note we're owner of the pads and the clusters, but not of
61 /// the remaining objects (digits, segmentations)
63 for ( Int_t i = 0; i < 2; ++i )
69 //_____________________________________________________________________________
71 AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
73 /// Add a pad to the list of pads to be considered
74 if ( pad.DetElemId() != fDetElemId )
76 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
77 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
81 new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
82 // FIXME: should set the ClusterId of that new pad to be -1
86 //_____________________________________________________________________________
88 AliMUONPreClusterFinder::Prepare(const AliMpVSegmentation* segmentations[2],
89 const AliMUONVDigitStore& digitStore)
90 // FIXME : add area on which to look for clusters here.
92 /// Prepare for clustering, by giving access to segmentations and digit lists
94 fSegmentations = segmentations;
97 fClusters = new TClonesArray("AliMUONCluster");
98 for ( Int_t i = 0; i < 2; ++i )
101 fPads[i] = new TClonesArray("AliMUONPad");
106 TIter next(digitStore.CreateIterator());
109 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
111 Int_t ix = d->PadX();
112 Int_t iy = d->PadY();
113 Int_t cathode = d->Cathode();
114 AliMpPad pad = fSegmentations[cathode]->PadByIndices(AliMpIntPair(ix,iy));
115 TClonesArray& padArray = *(fPads[cathode]);
116 if ( fDetElemId == -1 )
118 fDetElemId = d->DetElemId();
122 if ( d->DetElemId() != fDetElemId )
124 AliError("Something is seriously wrong with DE. Aborting clustering");
129 AliMUONPad mpad(fDetElemId,cathode,
130 ix,iy,pad.Position().X(),pad.Position().Y(),
131 pad.Dimensions().X(),pad.Dimensions().Y(),
133 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
134 new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);
136 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
138 // no pad at all, nothing to do...
145 //_____________________________________________________________________________
147 AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
149 /// Add a pad to a cluster
150 cluster.AddPad(*pad);
152 Int_t cathode = pad->Cathode();
153 TClonesArray& padArray = *fPads[cathode];
154 // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
155 // present (otherwise just compares pointers) : so that one must be correct
157 padArray.Remove(pad);
158 // TObject* o = padArray.Remove(pad);
161 // AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
162 // " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
163 // " as the first suspect for failed remove");
165 TIter next(&padArray);
168 while ( ( testPad = static_cast<AliMUONPad*>(next())))
170 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
172 AddPad(cluster,testPad);
177 //_____________________________________________________________________________
179 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
181 /// Whether the pad overlaps with the cluster
183 static Double_t precision = 1E-4; // cm
184 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
185 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
187 AliMUONPad* testPad = cluster.Pad(i);
188 // Note: we use negative precision numbers, meaning
189 // the area of the pads will be *increased* by these small numbers
190 // prior to check the overlap by the AreOverlapping method,
191 // so pads touching only by the corners will be considered as
193 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
201 //_____________________________________________________________________________
203 AliMUONPreClusterFinder::NextCluster()
205 /// Builds the next cluster, and returns it.
207 // AliCodeTimerAuto("")
209 // Start a new cluster
210 Int_t id = fClusters->GetLast()+1;
211 AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
212 cluster->SetUniqueID(id);
214 TIter next(fPads[0]);
215 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
217 if (!pad) // protection against no pad in first cathode, which might happen
220 TIter next(fPads[1]);
221 pad = static_cast<AliMUONPad*>(next());
227 // Builds (recursively) a cluster on second cathode only
228 AddPad(*cluster,pad);
232 // Builds (recursively) a cluster on first cathode only
233 AddPad(*cluster,pad);
235 // On the 2nd cathode, only add pads overlapping with the current cluster
236 TClonesArray& padArray = *fPads[1];
237 TIter next(&padArray);
240 while ( ( testPad = static_cast<AliMUONPad*>(next())))
242 if ( AreOverlapping(*testPad,*cluster) )
244 AddPad(*cluster,testPad);
249 if ( cluster->Multiplicity() <= 1 )
251 if ( cluster->Multiplicity() == 0 )
253 // no pad is suspicious
254 AliWarning("Got an empty cluster...");
256 // else only 1 pad (not suspicious, but kind of useless, probably noise)
257 // so we remove it from our list
258 fClusters->Remove(cluster);
259 fClusters->Compress();
260 // then proceed further
261 return NextCluster();