]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPreClusterFinder.cxx
In AliMUONVPainter:
[u/mrichter/AliRoot.git] / MUON / AliMUONPreClusterFinder.cxx
CommitLineData
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
2103dc37 20#include "AliCodeTimer.h"
21
18466557 22#include "AliMUONCluster.h"
18466557 23#include "AliMUONPad.h"
3887d11e 24#include "AliMUONVDigit.h"
25#include "AliMUONVDigitStore.h"
e22f734a 26
27#include "AliMpArea.h"
28#include "AliMpConstants.h"
29#include "AliMpVSegmentation.h"
30
31#include "AliLog.h"
32
33#include <Riostream.h>
34#include <TClonesArray.h>
35#include <TVector2.h>
18466557 36
3d1463c8 37//-----------------------------------------------------------------------------
18466557 38/// \class AliMUONPreClusterFinder
39///
40/// Implementation of AliMUONVClusterFinder
41///
42/// This class simply find adjacent pads to form clusters
43///
44/// \author Laurent Aphecetche
3d1463c8 45//-----------------------------------------------------------------------------
18466557 46
47ClassImp(AliMUONPreClusterFinder)
48
49//_____________________________________________________________________________
50AliMUONPreClusterFinder::AliMUONPreClusterFinder()
51: AliMUONVClusterFinder(),
9ec6a948 52 fClusters("AliMUONCluster"),
e22f734a 53 fPads(0x0),
54 fDetElemId(0),
861d6ce8 55 fArea(),
56 fShouldAbort(kFALSE)
18466557 57{
e22f734a 58 /// ctor
18466557 59}
60
61//_____________________________________________________________________________
62AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
63{
e22f734a 64 /// dtor : note we're owner of the clusters, but not of the pads
18466557 65}
66
67//_____________________________________________________________________________
68Bool_t
69AliMUONPreClusterFinder::UsePad(const AliMUONPad& pad)
70{
71 /// Add a pad to the list of pads to be considered
72 if ( pad.DetElemId() != fDetElemId )
73 {
74 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
75 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
76 return kFALSE;
77 }
78
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
81 return kTRUE;
82}
83
84//_____________________________________________________________________________
85Bool_t
e22f734a 86AliMUONPreClusterFinder::Prepare(Int_t detElemId,
87 TClonesArray* pads[2],
88 const AliMpArea& area)
18466557 89{
90 /// Prepare for clustering, by giving access to segmentations and digit lists
e22f734a 91
9ec6a948 92 fClusters.Clear("C");
93
e22f734a 94 fPads = pads;
95 fDetElemId = detElemId;
96 fArea = area;
d592a053 97
861d6ce8 98 fShouldAbort = kFALSE;
99
18466557 100 return kTRUE;
101}
102
103//_____________________________________________________________________________
104void
105AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
106{
107 /// Add a pad to a cluster
861d6ce8 108
2103dc37 109 if ( cluster.IsMonoCathode() && cluster.Multiplicity() > 199 )
861d6ce8 110 {
2103dc37 111 /// FIXME : we should at that point really find a better way to remove "bad" preclusters,
112 /// like e.g. computing the charge dispersion (the lower, the most probably we have noise cluster)
113 /// and/or mean charge per pad (if too close to LowestPadCharge, again that's a noise cluster...
114 /// *BUT* this needs carefull testing !
861d6ce8 115 fShouldAbort = kTRUE;
116 return;
117 }
118
18466557 119 cluster.AddPad(*pad);
120
121 Int_t cathode = pad->Cathode();
122 TClonesArray& padArray = *fPads[cathode];
d592a053 123 // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
124 // present (otherwise just compares pointers) : so that one must be correct
125 // if implemented !
18466557 126 padArray.Remove(pad);
d592a053 127 // TObject* o = padArray.Remove(pad);
128// if (!o)
129// {
130// AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
131// " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
132// " as the first suspect for failed remove");
133// }
18466557 134 TIter next(&padArray);
135 AliMUONPad* testPad;
d592a053 136
18466557 137 while ( ( testPad = static_cast<AliMUONPad*>(next())))
138 {
139 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
140 {
141 AddPad(cluster,testPad);
142 }
143 }
144}
145
146//_____________________________________________________________________________
147Bool_t
148AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
149{
150 /// Whether the pad overlaps with the cluster
151
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 )
155 {
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
161 // overlapping.
162 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
163 {
164 return kTRUE;
165 }
166 }
167 return kFALSE;
168}
169
e22f734a 170//_____________________________________________________________________________
171AliMUONPad*
172AliMUONPreClusterFinder::GetNextPad(Int_t cathode) const
173{
5bec63e7 174/// Return the next unused pad of given cathode, which is within fArea
175
e22f734a 176 TIter next(fPads[cathode]);
177
178 if ( !fArea.IsValid() )
179 {
180 return static_cast<AliMUONPad*>(next());
181 }
182 else
183 {
184 AliMUONPad* pad;
185 while ( ( pad = static_cast<AliMUONPad*>(next())) )
186 {
6e97fbb8 187 AliMpArea padArea(pad->X(), pad->Y(), pad->DX(), pad->DY());
e22f734a 188
189 if (fArea.Overlap(padArea)) return pad;
190
191 }
192 return 0x0;
193 }
194}
195
57f3728e 196//_____________________________________________________________________________
197AliMUONCluster*
198AliMUONPreClusterFinder::NewCluster()
199{
200 /// Create a new (empty) cluster
201 Int_t id = fClusters.GetLast()+1;
202 AliMUONCluster* cluster = new (fClusters[id]) AliMUONCluster;
203 cluster->SetUniqueID(id);
204 return cluster;
205}
206
207//_____________________________________________________________________________
208void
209AliMUONPreClusterFinder::RemoveCluster(AliMUONCluster* cluster)
210{
211 /// Remove a cluster
2103dc37 212 /// Note that we are *not* releasing the pads, so they won't be used further on
57f3728e 213 fClusters.Remove(cluster);
214 fClusters.Compress();
215}
216
18466557 217//_____________________________________________________________________________
218AliMUONCluster*
219AliMUONPreClusterFinder::NextCluster()
220{
221 /// Builds the next cluster, and returns it.
d592a053 222
18466557 223 // Start a new cluster
18466557 224
e22f734a 225 AliMUONPad* pad = GetNextPad(0);
18466557 226
57f3728e 227 AliMUONCluster* cluster(0x0);
228
18466557 229 if (!pad) // protection against no pad in first cathode, which might happen
230 {
231 // try other cathode
e22f734a 232 pad = GetNextPad(1);
18466557 233 if (!pad)
234 {
18466557 235 return 0x0;
236 }
57f3728e 237 else
238 {
239 cluster = NewCluster();
240 // Builds (recursively) a cluster on second cathode only
241 AddPad(*cluster,pad);
242 }
18466557 243 }
244 else
245 {
246 // Builds (recursively) a cluster on first cathode only
57f3728e 247
248 cluster = NewCluster();
18466557 249 AddPad(*cluster,pad);
250
861d6ce8 251 if ( !ShouldAbort() )
18466557 252 {
861d6ce8 253 // On the 2nd cathode, only add pads overlapping with the current cluster
254 TClonesArray& padArray = *fPads[1];
255 TIter next(&padArray);
256 AliMUONPad* testPad;
257
258 while ( ( testPad = static_cast<AliMUONPad*>(next())) && !ShouldAbort() )
18466557 259 {
861d6ce8 260 if (AreOverlapping(*testPad,*cluster) )
261 {
262 AddPad(*cluster,testPad);
263 }
18466557 264 }
265 }
266 }
267
861d6ce8 268 if ( ShouldAbort() )
269 {
fdee8d81 270 AliCodeTimerAuto(Form("Skipping a precluster in DE %d because it got too many pads",fDetElemId),0);
57f3728e 271 RemoveCluster(cluster);
2103dc37 272 return NextCluster();
861d6ce8 273 }
274
18466557 275 if ( cluster->Multiplicity() <= 1 )
276 {
277 if ( cluster->Multiplicity() == 0 )
278 {
279 // no pad is suspicious
280 AliWarning("Got an empty cluster...");
281 }
282 // else only 1 pad (not suspicious, but kind of useless, probably noise)
283 // so we remove it from our list
57f3728e 284 RemoveCluster(cluster);
18466557 285 // then proceed further
286 return NextCluster();
287 }
288
289 return cluster;
290}