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(),
52 //_____________________________________________________________________________
53 AliMUONPreClusterFinderV2::~AliMUONPreClusterFinderV2()
55 /// dtor : note we're owner of the clusters, but not of the pads
59 //_____________________________________________________________________________
61 AliMUONPreClusterFinderV2::UsePad(const AliMUONPad& pad)
63 /// Add a pad to the list of pads to be considered
64 if ( pad.DetElemId() != fDetElemId )
66 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
67 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
71 new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
72 // FIXME: should set the ClusterId of that new pad to be -1
76 //_____________________________________________________________________________
78 AliMUONPreClusterFinderV2::Prepare(Int_t detElemId,
79 TClonesArray* pads[2],
80 const AliMpArea& area,
81 const AliMpVSegmentation* seg[2])
83 /// Prepare for clustering, by giving access to segmentations and digit lists
87 AliError("Handling of area not yet implemented for this class. Please check");
91 fClusters = new TClonesArray("AliMUONCluster");
96 fDetElemId = detElemId;
98 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
100 // no pad at all, nothing to do...
107 //_____________________________________________________________________________
109 AliMUONPreClusterFinderV2::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
111 /// Add a pad to a cluster
113 cluster.AddPad(*pad);
114 pad->SetClusterId(cluster.GetUniqueID());
116 Int_t cathode = pad->Cathode();
117 TClonesArray& padArray = *fPads[cathode];
118 padArray.Remove(pad);
119 TIter next(&padArray);
122 TObjArray neighbours;
123 AliMpPad p = fSegmentations[pad->Cathode()]->PadByIndices(AliMpIntPair(pad->Ix(),pad->Iy()),kTRUE);
124 Int_t nn = fSegmentations[pad->Cathode()]->GetNeighbours(p,neighbours);
125 for (Int_t in = 0; in < nn; ++in)
127 AliMpPad* p1 = static_cast<AliMpPad*>(neighbours.At(in));
129 TIter next2(&padArray);
132 while ( ( p2 = static_cast<AliMUONPad*>(next2()) ) )
134 if ( !p2->IsUsed() && p2->Ix()==p1->GetIndices().GetFirst()
135 && p2->Iy() == p1->GetIndices().GetSecond() &&
136 p2->Cathode() == pad->Cathode() )
141 } // for (Int_t in = 0;
146 //_____________________________________________________________________________
148 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
150 /// Whether the pad overlaps with the cluster
152 static Double_t precision = 1E-4; // cm
153 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
154 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
156 AliMUONPad* testPad = cluster.Pad(i);
157 // Note: we use negative precision numbers, meaning
158 // the area of the pads will be *increased* by these small numbers
159 // prior to check the overlap by the AreOverlapping method,
160 // so pads touching only by the corners will be considered as
162 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
171 //_____________________________________________________________________________
173 AliMUONPreClusterFinderV2::NextCluster()
175 /// Builds the next cluster, and returns it.
177 // Start a new cluster
178 Int_t id = fClusters->GetLast()+1;
179 AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster;
180 cluster->SetUniqueID(id);
183 TIter next(fPads[0]);
184 while ( ( pad = static_cast<AliMUONPad*>(next())) && pad->IsUsed() );
186 if (!pad) // protection against no pad in first cathode, which might happen
189 TIter next2(fPads[1]);
190 while ( ( pad = static_cast<AliMUONPad*>(next2())) && pad->IsUsed() );
196 // Builds (recursively) a cluster on second cathode only
197 AddPad(*cluster,pad);
201 // Builds (recursively) a cluster on first cathode only
203 AddPad(*cluster,pad);
205 // On the 2nd cathode, only add pads overlapping with the current cluster
206 TIter next1(fPads[1]);
209 while ( ( testPad = static_cast<AliMUONPad*>(next1())))
211 if ( !testPad->IsUsed() && AreOverlapping(*testPad,*cluster) )
213 AddPad(*cluster,testPad);
218 if ( cluster->Multiplicity() <= 1 )
220 if ( cluster->Multiplicity() == 0 )
222 // no pad is suspicious
223 AliWarning("Got an empty cluster...");
225 // else only 1 pad (not suspicious, but kind of useless, probably noise)
226 // so we remove it from our list
227 fClusters->Remove(cluster);
228 fClusters->Compress();
229 // then proceed further
230 return NextCluster();