]>
Commit | Line | Data |
---|---|---|
18466557 | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
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 | **************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | ||
18 | #include "AliMUONPreClusterFinder.h" | |
19 | ||
18466557 | 20 | #include "AliMUONCluster.h" |
18466557 | 21 | #include "AliMUONPad.h" |
3887d11e | 22 | #include "AliMUONVDigit.h" |
23 | #include "AliMUONVDigitStore.h" | |
e22f734a | 24 | |
25 | #include "AliMpArea.h" | |
26 | #include "AliMpConstants.h" | |
27 | #include "AliMpVSegmentation.h" | |
28 | ||
29 | #include "AliLog.h" | |
30 | ||
31 | #include <Riostream.h> | |
32 | #include <TClonesArray.h> | |
33 | #include <TVector2.h> | |
18466557 | 34 | |
3d1463c8 | 35 | //----------------------------------------------------------------------------- |
18466557 | 36 | /// \class AliMUONPreClusterFinder |
37 | /// | |
38 | /// Implementation of AliMUONVClusterFinder | |
39 | /// | |
40 | /// This class simply find adjacent pads to form clusters | |
41 | /// | |
42 | /// \author Laurent Aphecetche | |
3d1463c8 | 43 | //----------------------------------------------------------------------------- |
18466557 | 44 | |
45 | ClassImp(AliMUONPreClusterFinder) | |
46 | ||
47 | //_____________________________________________________________________________ | |
48 | AliMUONPreClusterFinder::AliMUONPreClusterFinder() | |
49 | : AliMUONVClusterFinder(), | |
50 | fClusters(0x0), | |
e22f734a | 51 | fPads(0x0), |
52 | fDetElemId(0), | |
53 | fArea() | |
18466557 | 54 | { |
e22f734a | 55 | /// ctor |
18466557 | 56 | } |
57 | ||
58 | //_____________________________________________________________________________ | |
59 | AliMUONPreClusterFinder::~AliMUONPreClusterFinder() | |
60 | { | |
e22f734a | 61 | /// dtor : note we're owner of the clusters, but not of the pads |
18466557 | 62 | delete fClusters; |
18466557 | 63 | } |
64 | ||
65 | //_____________________________________________________________________________ | |
66 | Bool_t | |
67 | AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad) | |
68 | { | |
69 | /// Add a pad to the list of pads to be considered | |
70 | if ( pad.DetElemId() != fDetElemId ) | |
71 | { | |
72 | AliError(Form("Cannot add pad from DE %d to this cluster finder which is " | |
73 | "currently dealing with DE %d",pad.DetElemId(),fDetElemId)); | |
74 | return kFALSE; | |
75 | } | |
76 | ||
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 | |
79 | return kTRUE; | |
80 | } | |
81 | ||
82 | //_____________________________________________________________________________ | |
83 | Bool_t | |
e22f734a | 84 | AliMUONPreClusterFinder::Prepare(Int_t detElemId, |
85 | TClonesArray* pads[2], | |
86 | const AliMpArea& area) | |
18466557 | 87 | { |
88 | /// Prepare for clustering, by giving access to segmentations and digit lists | |
89 | ||
18466557 | 90 | delete fClusters; |
91 | fClusters = new TClonesArray("AliMUONCluster"); | |
e22f734a | 92 | |
93 | fPads = pads; | |
94 | fDetElemId = detElemId; | |
95 | fArea = area; | |
d592a053 | 96 | |
18466557 | 97 | return kTRUE; |
98 | } | |
99 | ||
100 | //_____________________________________________________________________________ | |
101 | void | |
102 | AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad) | |
103 | { | |
104 | /// Add a pad to a cluster | |
105 | cluster.AddPad(*pad); | |
106 | ||
107 | Int_t cathode = pad->Cathode(); | |
108 | TClonesArray& padArray = *fPads[cathode]; | |
d592a053 | 109 | // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is |
110 | // present (otherwise just compares pointers) : so that one must be correct | |
111 | // if implemented ! | |
18466557 | 112 | padArray.Remove(pad); |
d592a053 | 113 | // TObject* o = padArray.Remove(pad); |
114 | // if (!o) | |
115 | // { | |
116 | // AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway " | |
117 | // " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method" | |
118 | // " as the first suspect for failed remove"); | |
119 | // } | |
18466557 | 120 | TIter next(&padArray); |
121 | AliMUONPad* testPad; | |
d592a053 | 122 | |
18466557 | 123 | while ( ( testPad = static_cast<AliMUONPad*>(next()))) |
124 | { | |
125 | if ( AliMUONPad::AreNeighbours(*testPad,*pad) ) | |
126 | { | |
127 | AddPad(cluster,testPad); | |
128 | } | |
129 | } | |
130 | } | |
131 | ||
132 | //_____________________________________________________________________________ | |
133 | Bool_t | |
134 | AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster) | |
135 | { | |
136 | /// Whether the pad overlaps with the cluster | |
137 | ||
138 | static Double_t precision = 1E-4; // cm | |
139 | static TVector2 precisionAdjustment(precision,precision);//-precision,-precision); | |
140 | for ( Int_t i = 0; i < cluster.Multiplicity(); ++i ) | |
141 | { | |
142 | AliMUONPad* testPad = cluster.Pad(i); | |
143 | // Note: we use negative precision numbers, meaning | |
144 | // the area of the pads will be *increased* by these small numbers | |
145 | // prior to check the overlap by the AreOverlapping method, | |
146 | // so pads touching only by the corners will be considered as | |
147 | // overlapping. | |
148 | if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) ) | |
149 | { | |
150 | return kTRUE; | |
151 | } | |
152 | } | |
153 | return kFALSE; | |
154 | } | |
155 | ||
e22f734a | 156 | //_____________________________________________________________________________ |
157 | AliMUONPad* | |
158 | AliMUONPreClusterFinder::GetNextPad(Int_t cathode) const | |
159 | { | |
5bec63e7 | 160 | /// Return the next unused pad of given cathode, which is within fArea |
161 | ||
e22f734a | 162 | TIter next(fPads[cathode]); |
163 | ||
164 | if ( !fArea.IsValid() ) | |
165 | { | |
166 | return static_cast<AliMUONPad*>(next()); | |
167 | } | |
168 | else | |
169 | { | |
170 | AliMUONPad* pad; | |
171 | while ( ( pad = static_cast<AliMUONPad*>(next())) ) | |
172 | { | |
173 | AliMpArea padArea(pad->Position(),pad->Dimensions()); | |
174 | ||
175 | if (fArea.Overlap(padArea)) return pad; | |
176 | ||
177 | } | |
178 | return 0x0; | |
179 | } | |
180 | } | |
181 | ||
18466557 | 182 | //_____________________________________________________________________________ |
183 | AliMUONCluster* | |
184 | AliMUONPreClusterFinder::NextCluster() | |
185 | { | |
186 | /// Builds the next cluster, and returns it. | |
2060b217 | 187 | // AliCodeTimerAuto("pre-clustering") |
d592a053 | 188 | |
18466557 | 189 | // Start a new cluster |
190 | Int_t id = fClusters->GetLast()+1; | |
191 | AliMUONCluster* cluster = new ((*fClusters)[id]) AliMUONCluster; | |
192 | cluster->SetUniqueID(id); | |
193 | ||
e22f734a | 194 | AliMUONPad* pad = GetNextPad(0); |
18466557 | 195 | |
196 | if (!pad) // protection against no pad in first cathode, which might happen | |
197 | { | |
198 | // try other cathode | |
e22f734a | 199 | pad = GetNextPad(1); |
18466557 | 200 | if (!pad) |
201 | { | |
202 | // we are done. | |
203 | return 0x0; | |
204 | } | |
205 | // Builds (recursively) a cluster on second cathode only | |
206 | AddPad(*cluster,pad); | |
207 | } | |
208 | else | |
209 | { | |
210 | // Builds (recursively) a cluster on first cathode only | |
211 | AddPad(*cluster,pad); | |
212 | ||
213 | // On the 2nd cathode, only add pads overlapping with the current cluster | |
214 | TClonesArray& padArray = *fPads[1]; | |
215 | TIter next(&padArray); | |
216 | AliMUONPad* testPad; | |
217 | ||
218 | while ( ( testPad = static_cast<AliMUONPad*>(next()))) | |
219 | { | |
e22f734a | 220 | if (AreOverlapping(*testPad,*cluster) ) |
18466557 | 221 | { |
222 | AddPad(*cluster,testPad); | |
223 | } | |
224 | } | |
225 | } | |
226 | ||
227 | if ( cluster->Multiplicity() <= 1 ) | |
228 | { | |
229 | if ( cluster->Multiplicity() == 0 ) | |
230 | { | |
231 | // no pad is suspicious | |
232 | AliWarning("Got an empty cluster..."); | |
233 | } | |
234 | // else only 1 pad (not suspicious, but kind of useless, probably noise) | |
235 | // so we remove it from our list | |
236 | fClusters->Remove(cluster); | |
237 | fClusters->Compress(); | |
238 | // then proceed further | |
239 | return NextCluster(); | |
240 | } | |
241 | ||
242 | return cluster; | |
243 | } |