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 /// \class AliMUONPreClusterFinder
33 /// Implementation of AliMUONVClusterFinder
35 /// This class simply find adjacent pads to form clusters
37 /// \author Laurent Aphecetche
39 ClassImp(AliMUONPreClusterFinder)
41 //_____________________________________________________________________________
42 AliMUONPreClusterFinder::AliMUONPreClusterFinder()
43 : AliMUONVClusterFinder(),
49 for ( Int_t i = 0; i < 2; ++i )
55 //_____________________________________________________________________________
56 AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
58 /// dtor : note we're owner of the pads and the clusters, but not of
59 /// the remaining objects (digits, segmentations)
61 for ( Int_t i = 0; i < 2; ++i )
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(const AliMpVSegmentation* segmentations[2],
87 const AliMUONVDigitStore& digitStore)
88 // FIXME : add area on which to look for clusters here.
90 /// Prepare for clustering, by giving access to segmentations and digit lists
92 fSegmentations = segmentations;
95 fClusters = new TClonesArray("AliMUONCluster");
96 for ( Int_t i = 0; i < 2; ++i )
99 fPads[i] = new TClonesArray("AliMUONPad");
104 TIter next(digitStore.CreateIterator());
107 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
109 Int_t ix = d->PadX();
110 Int_t iy = d->PadY();
111 Int_t cathode = d->Cathode();
112 AliMpPad pad = fSegmentations[cathode]->PadByIndices(AliMpIntPair(ix,iy));
113 TClonesArray& padArray = *(fPads[cathode]);
114 if ( fDetElemId == -1 )
116 fDetElemId = d->DetElemId();
120 if ( d->DetElemId() != fDetElemId )
122 AliError("Something is seriously wrong with DE. Aborting clustering");
127 AliMUONPad mpad(fDetElemId,cathode,
128 ix,iy,pad.Position().X(),pad.Position().Y(),
129 pad.Dimensions().X(),pad.Dimensions().Y(),
131 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
132 new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);
134 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
136 // no pad at all, nothing to do...
143 //_____________________________________________________________________________
145 AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
147 /// Add a pad to a cluster
148 cluster.AddPad(*pad);
150 Int_t cathode = pad->Cathode();
151 TClonesArray& padArray = *fPads[cathode];
152 // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
153 // present (otherwise just compares pointers) : so that one must be correct
155 padArray.Remove(pad);
156 // TObject* o = padArray.Remove(pad);
159 // AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
160 // " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
161 // " as the first suspect for failed remove");
163 TIter next(&padArray);
166 while ( ( testPad = static_cast<AliMUONPad*>(next())))
168 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
170 AddPad(cluster,testPad);
175 //_____________________________________________________________________________
177 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
179 /// Whether the pad overlaps with the cluster
181 static Double_t precision = 1E-4; // cm
182 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
183 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
185 AliMUONPad* testPad = cluster.Pad(i);
186 // Note: we use negative precision numbers, meaning
187 // the area of the pads will be *increased* by these small numbers
188 // prior to check the overlap by the AreOverlapping method,
189 // so pads touching only by the corners will be considered as
191 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
199 //_____________________________________________________________________________
201 AliMUONPreClusterFinder::NextCluster()
203 /// Builds the next cluster, and returns it.
205 // AliCodeTimerAuto("")
207 // Start a new cluster
208 Int_t id = fClusters->GetLast()+1;
209 AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
210 cluster->SetUniqueID(id);
212 TIter next(fPads[0]);
213 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
215 if (!pad) // protection against no pad in first cathode, which might happen
218 TIter next(fPads[1]);
219 pad = static_cast<AliMUONPad*>(next());
225 // Builds (recursively) a cluster on second cathode only
226 AddPad(*cluster,pad);
230 // Builds (recursively) a cluster on first cathode only
231 AddPad(*cluster,pad);
233 // On the 2nd cathode, only add pads overlapping with the current cluster
234 TClonesArray& padArray = *fPads[1];
235 TIter next(&padArray);
238 while ( ( testPad = static_cast<AliMUONPad*>(next())))
240 if ( AreOverlapping(*testPad,*cluster) )
242 AddPad(*cluster,testPad);
247 if ( cluster->Multiplicity() <= 1 )
249 if ( cluster->Multiplicity() == 0 )
251 // no pad is suspicious
252 AliWarning("Got an empty cluster...");
254 // else only 1 pad (not suspicious, but kind of useless, probably noise)
255 // so we remove it from our list
256 fClusters->Remove(cluster);
257 fClusters->Compress();
258 // then proceed further
259 return NextCluster();