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 /// \class AliMUONPreClusterFinderV2
31 /// Implementation of AliMUONVClusterFinder
33 /// This one ressembles the preclustering stage in the original ClusterFinderAZ
35 /// \author Laurent Aphecetche
37 ClassImp(AliMUONPreClusterFinderV2)
39 //_____________________________________________________________________________
40 AliMUONPreClusterFinderV2::AliMUONPreClusterFinderV2()
41 : AliMUONVClusterFinder(),
47 for ( Int_t i = 0; i < 2; ++i )
53 //_____________________________________________________________________________
54 AliMUONPreClusterFinderV2::~AliMUONPreClusterFinderV2()
56 /// dtor : note we're owner of the pads and the clusters, but not of
57 /// the remaining objects (digits, segmentations)
59 for ( Int_t i = 0; i < 2; ++i )
65 //_____________________________________________________________________________
67 AliMUONPreClusterFinderV2::UsePad(const AliMUONPad& pad)
69 /// Add a pad to the list of pads to be considered
70 if ( pad.DetElemId() != fDetElemId )
72 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
73 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
77 new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
78 // FIXME: should set the ClusterId of that new pad to be -1
82 //_____________________________________________________________________________
84 AliMUONPreClusterFinderV2::Prepare(const AliMpVSegmentation* segmentations[2],
85 const AliMUONVDigitStore& digitStore)
86 // FIXME : add area on which to look for clusters here.
88 /// Prepare for clustering, by giving access to segmentations and digit lists
90 fSegmentations = segmentations;
93 fClusters = new TClonesArray("AliMUONCluster");
94 for ( Int_t i = 0; i < 2; ++i )
97 fPads[i] = new TClonesArray("AliMUONPad");
102 TIter next(digitStore.CreateIterator());
105 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
107 Int_t ix = d->PadX();
108 Int_t iy = d->PadY();
109 Int_t cathode = d->Cathode();
110 AliMpPad pad = fSegmentations[cathode]->PadByIndices(AliMpIntPair(ix,iy));
111 TClonesArray& padArray = *(fPads[cathode]);
112 if ( fDetElemId == -1 )
114 fDetElemId = d->DetElemId();
118 if ( d->DetElemId() != fDetElemId )
120 AliError("Something is seriously wrong with DE. Aborting clustering");
125 AliMUONPad mpad(fDetElemId,cathode,
126 ix,iy,pad.Position().X(),pad.Position().Y(),
127 pad.Dimensions().X(),pad.Dimensions().Y(),
129 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
130 new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);
132 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
134 // no pad at all, nothing to do...
141 //_____________________________________________________________________________
143 AliMUONPreClusterFinderV2::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
145 /// Add a pad to a cluster
147 cluster.AddPad(*pad);
148 pad->SetClusterId(cluster.GetUniqueID());
150 Int_t cathode = pad->Cathode();
151 TClonesArray& padArray = *fPads[cathode];
152 padArray.Remove(pad);
153 TIter next(&padArray);
156 TObjArray neighbours;
157 AliMpPad p = fSegmentations[pad->Cathode()]->PadByIndices(AliMpIntPair(pad->Ix(),pad->Iy()),kTRUE);
158 Int_t nn = fSegmentations[pad->Cathode()]->GetNeighbours(p,neighbours);
159 for (Int_t in = 0; in < nn; ++in)
161 AliMpPad* p = static_cast<AliMpPad*>(neighbours.At(in));
163 TIter next(&padArray);
166 while ( ( p2 = static_cast<AliMUONPad*>(next()) ) )
168 if ( !p2->IsUsed() && p2->Ix()==p->GetIndices().GetFirst()
169 && p2->Iy() == p->GetIndices().GetSecond() &&
170 p2->Cathode() == pad->Cathode() )
175 } // for (Int_t in = 0;
180 //_____________________________________________________________________________
182 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
184 /// Whether the pad overlaps with the cluster
186 static Double_t precision = 1E-4; // cm
187 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
188 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
190 AliMUONPad* testPad = cluster.Pad(i);
191 // Note: we use negative precision numbers, meaning
192 // the area of the pads will be *increased* by these small numbers
193 // prior to check the overlap by the AreOverlapping method,
194 // so pads touching only by the corners will be considered as
196 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
205 //_____________________________________________________________________________
207 AliMUONPreClusterFinderV2::NextCluster()
209 /// Builds the next cluster, and returns it.
211 // Start a new cluster
212 Int_t id = fClusters->GetLast()+1;
213 AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
214 cluster->SetUniqueID(id);
217 TIter next(fPads[0]);
218 while ( ( pad = static_cast<AliMUONPad*>(next())) && pad->IsUsed() );
220 if (!pad) // protection against no pad in first cathode, which might happen
223 TIter next(fPads[1]);
224 while ( ( pad = static_cast<AliMUONPad*>(next())) && pad->IsUsed() );
230 // Builds (recursively) a cluster on second cathode only
231 AddPad(*cluster,pad);
235 // Builds (recursively) a cluster on first cathode only
237 AddPad(*cluster,pad);
239 // On the 2nd cathode, only add pads overlapping with the current cluster
240 TIter next1(fPads[1]);
243 while ( ( testPad = static_cast<AliMUONPad*>(next1())))
245 if ( !testPad->IsUsed() && AreOverlapping(*testPad,*cluster) )
247 AddPad(*cluster,testPad);
252 if ( cluster->Multiplicity() <= 1 )
254 if ( cluster->Multiplicity() == 0 )
256 // no pad is suspicious
257 AliWarning("Got an empty cluster...");
259 // else only 1 pad (not suspicious, but kind of useless, probably noise)
260 // so we remove it from our list
261 fClusters->Remove(cluster);
262 fClusters->Compress();
263 // then proceed further
264 return NextCluster();