]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPreClusterFinder.cxx
Simplifications, now that pedestal subprocessor is taking care of deciding whether...
[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
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
45ClassImp(AliMUONPreClusterFinder)
46
47//_____________________________________________________________________________
48AliMUONPreClusterFinder::AliMUONPreClusterFinder()
49: AliMUONVClusterFinder(),
9ec6a948 50 fClusters("AliMUONCluster"),
e22f734a 51 fPads(0x0),
52 fDetElemId(0),
861d6ce8 53 fArea(),
54 fShouldAbort(kFALSE)
18466557 55{
e22f734a 56 /// ctor
18466557 57}
58
59//_____________________________________________________________________________
60AliMUONPreClusterFinder::~AliMUONPreClusterFinder()
61{
e22f734a 62 /// dtor : note we're owner of the clusters, but not of the pads
18466557 63}
64
65//_____________________________________________________________________________
66Bool_t
67AliMUONPreClusterFinder::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//_____________________________________________________________________________
83Bool_t
e22f734a 84AliMUONPreClusterFinder::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
e22f734a 89
9ec6a948 90 fClusters.Clear("C");
91
e22f734a 92 fPads = pads;
93 fDetElemId = detElemId;
94 fArea = area;
d592a053 95
861d6ce8 96 fShouldAbort = kFALSE;
97
18466557 98 return kTRUE;
99}
100
101//_____________________________________________________________________________
102void
103AliMUONPreClusterFinder::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
104{
105 /// Add a pad to a cluster
861d6ce8 106
107 if ( cluster.Multiplicity() > 500 )
108 {
109 fShouldAbort = kTRUE;
110 return;
111 }
112
18466557 113 cluster.AddPad(*pad);
114
115 Int_t cathode = pad->Cathode();
116 TClonesArray& padArray = *fPads[cathode];
d592a053 117 // WARNING: this Remove method uses the AliMUONPad::IsEqual if that method is
118 // present (otherwise just compares pointers) : so that one must be correct
119 // if implemented !
18466557 120 padArray.Remove(pad);
d592a053 121 // TObject* o = padArray.Remove(pad);
122// if (!o)
123// {
124// AliFatal("Oups. Could not remove pad from pads to consider. Aborting as anyway "
125// " we'll get an infinite loop. Please check the AliMUONPad::IsEqual method"
126// " as the first suspect for failed remove");
127// }
18466557 128 TIter next(&padArray);
129 AliMUONPad* testPad;
d592a053 130
18466557 131 while ( ( testPad = static_cast<AliMUONPad*>(next())))
132 {
133 if ( AliMUONPad::AreNeighbours(*testPad,*pad) )
134 {
135 AddPad(cluster,testPad);
136 }
137 }
138}
139
140//_____________________________________________________________________________
141Bool_t
142AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
143{
144 /// Whether the pad overlaps with the cluster
145
146 static Double_t precision = 1E-4; // cm
147 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
148 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
149 {
150 AliMUONPad* testPad = cluster.Pad(i);
151 // Note: we use negative precision numbers, meaning
152 // the area of the pads will be *increased* by these small numbers
153 // prior to check the overlap by the AreOverlapping method,
154 // so pads touching only by the corners will be considered as
155 // overlapping.
156 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
157 {
158 return kTRUE;
159 }
160 }
161 return kFALSE;
162}
163
e22f734a 164//_____________________________________________________________________________
165AliMUONPad*
166AliMUONPreClusterFinder::GetNextPad(Int_t cathode) const
167{
5bec63e7 168/// Return the next unused pad of given cathode, which is within fArea
169
e22f734a 170 TIter next(fPads[cathode]);
171
172 if ( !fArea.IsValid() )
173 {
174 return static_cast<AliMUONPad*>(next());
175 }
176 else
177 {
178 AliMUONPad* pad;
179 while ( ( pad = static_cast<AliMUONPad*>(next())) )
180 {
6e97fbb8 181 AliMpArea padArea(pad->X(), pad->Y(), pad->DX(), pad->DY());
e22f734a 182
183 if (fArea.Overlap(padArea)) return pad;
184
185 }
186 return 0x0;
187 }
188}
189
57f3728e 190//_____________________________________________________________________________
191AliMUONCluster*
192AliMUONPreClusterFinder::NewCluster()
193{
194 /// Create a new (empty) cluster
195 Int_t id = fClusters.GetLast()+1;
196 AliMUONCluster* cluster = new (fClusters[id]) AliMUONCluster;
197 cluster->SetUniqueID(id);
198 return cluster;
199}
200
201//_____________________________________________________________________________
202void
203AliMUONPreClusterFinder::RemoveCluster(AliMUONCluster* cluster)
204{
205 /// Remove a cluster
206 fClusters.Remove(cluster);
207 fClusters.Compress();
208}
209
18466557 210//_____________________________________________________________________________
211AliMUONCluster*
212AliMUONPreClusterFinder::NextCluster()
213{
214 /// Builds the next cluster, and returns it.
99c136e1 215// AliCodeTimerAuto("pre-clustering",0)
d592a053 216
18466557 217 // Start a new cluster
18466557 218
e22f734a 219 AliMUONPad* pad = GetNextPad(0);
18466557 220
57f3728e 221 AliMUONCluster* cluster(0x0);
222
18466557 223 if (!pad) // protection against no pad in first cathode, which might happen
224 {
225 // try other cathode
e22f734a 226 pad = GetNextPad(1);
18466557 227 if (!pad)
228 {
18466557 229 return 0x0;
230 }
57f3728e 231 else
232 {
233 cluster = NewCluster();
234 // Builds (recursively) a cluster on second cathode only
235 AddPad(*cluster,pad);
236 }
18466557 237 }
238 else
239 {
240 // Builds (recursively) a cluster on first cathode only
57f3728e 241
242 cluster = NewCluster();
18466557 243 AddPad(*cluster,pad);
244
861d6ce8 245 if ( !ShouldAbort() )
18466557 246 {
861d6ce8 247 // On the 2nd cathode, only add pads overlapping with the current cluster
248 TClonesArray& padArray = *fPads[1];
249 TIter next(&padArray);
250 AliMUONPad* testPad;
251
252 while ( ( testPad = static_cast<AliMUONPad*>(next())) && !ShouldAbort() )
18466557 253 {
861d6ce8 254 if (AreOverlapping(*testPad,*cluster) )
255 {
256 AddPad(*cluster,testPad);
257 }
18466557 258 }
259 }
260 }
261
861d6ce8 262 if ( ShouldAbort() )
263 {
aa5b2908 264 AliError(Form("Aborting clustering of DE %d because we've got too many pads",fDetElemId));
57f3728e 265 RemoveCluster(cluster);
861d6ce8 266 return 0x0;
267 }
268
18466557 269 if ( cluster->Multiplicity() <= 1 )
270 {
271 if ( cluster->Multiplicity() == 0 )
272 {
273 // no pad is suspicious
274 AliWarning("Got an empty cluster...");
275 }
276 // else only 1 pad (not suspicious, but kind of useless, probably noise)
277 // so we remove it from our list
57f3728e 278 RemoveCluster(cluster);
18466557 279 // then proceed further
280 return NextCluster();
281 }
282
283 return cluster;
284}