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 "AliMUONPreClusterFinderV2.h"
21 #include "AliMUONCluster.h"
22 #include "AliMpVSegmentation.h"
23 #include "TClonesArray.h"
25 #include "AliMUONPad.h"
26 #include "AliMUONVDigit.h"
27 #include "AliMUONVDigitStore.h"
29 //-----------------------------------------------------------------------------
30 /// \class AliMUONPreClusterFinderV2
32 /// Implementation of AliMUONVClusterFinder
34 /// This one ressembles the preclustering stage in the original ClusterFinderAZ
36 /// \author Laurent Aphecetche
37 //-----------------------------------------------------------------------------
39 ClassImp(AliMUONPreClusterFinderV2)
41 //_____________________________________________________________________________
42 AliMUONPreClusterFinderV2::AliMUONPreClusterFinderV2()
43 : AliMUONVClusterFinder(),
49 for ( Int_t i = 0; i < 2; ++i )
55 //_____________________________________________________________________________
56 AliMUONPreClusterFinderV2::~AliMUONPreClusterFinderV2()
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 AliMUONPreClusterFinderV2::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 AliMUONPreClusterFinderV2::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 AliMUONPreClusterFinderV2::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
147 /// Add a pad to a cluster
149 cluster.AddPad(*pad);
150 pad->SetClusterId(cluster.GetUniqueID());
152 Int_t cathode = pad->Cathode();
153 TClonesArray& padArray = *fPads[cathode];
154 padArray.Remove(pad);
155 TIter next(&padArray);
158 TObjArray neighbours;
159 AliMpPad p = fSegmentations[pad->Cathode()]->PadByIndices(AliMpIntPair(pad->Ix(),pad->Iy()),kTRUE);
160 Int_t nn = fSegmentations[pad->Cathode()]->GetNeighbours(p,neighbours);
161 for (Int_t in = 0; in < nn; ++in)
163 AliMpPad* p = static_cast<AliMpPad*>(neighbours.At(in));
165 TIter next(&padArray);
168 while ( ( p2 = static_cast<AliMUONPad*>(next()) ) )
170 if ( !p2->IsUsed() && p2->Ix()==p->GetIndices().GetFirst()
171 && p2->Iy() == p->GetIndices().GetSecond() &&
172 p2->Cathode() == pad->Cathode() )
177 } // for (Int_t in = 0;
182 //_____________________________________________________________________________
184 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
186 /// Whether the pad overlaps with the cluster
188 static Double_t precision = 1E-4; // cm
189 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
190 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
192 AliMUONPad* testPad = cluster.Pad(i);
193 // Note: we use negative precision numbers, meaning
194 // the area of the pads will be *increased* by these small numbers
195 // prior to check the overlap by the AreOverlapping method,
196 // so pads touching only by the corners will be considered as
198 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
207 //_____________________________________________________________________________
209 AliMUONPreClusterFinderV2::NextCluster()
211 /// Builds the next cluster, and returns it.
213 // Start a new cluster
214 Int_t id = fClusters->GetLast()+1;
215 AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
216 cluster->SetUniqueID(id);
219 TIter next(fPads[0]);
220 while ( ( pad = static_cast<AliMUONPad*>(next())) && pad->IsUsed() );
222 if (!pad) // protection against no pad in first cathode, which might happen
225 TIter next(fPads[1]);
226 while ( ( pad = static_cast<AliMUONPad*>(next())) && pad->IsUsed() );
232 // Builds (recursively) a cluster on second cathode only
233 AddPad(*cluster,pad);
237 // Builds (recursively) a cluster on first cathode only
239 AddPad(*cluster,pad);
241 // On the 2nd cathode, only add pads overlapping with the current cluster
242 TIter next1(fPads[1]);
245 while ( ( testPad = static_cast<AliMUONPad*>(next1())))
247 if ( !testPad->IsUsed() && AreOverlapping(*testPad,*cluster) )
249 AddPad(*cluster,testPad);
254 if ( cluster->Multiplicity() <= 1 )
256 if ( cluster->Multiplicity() == 0 )
258 // no pad is suspicious
259 AliWarning("Got an empty cluster...");
261 // else only 1 pad (not suspicious, but kind of useless, probably noise)
262 // so we remove it from our list
263 fClusters->Remove(cluster);
264 fClusters->Compress();
265 // then proceed further
266 return NextCluster();