new functionality and new class added
[u/mrichter/AliRoot.git] / MUON / AliMUONPreClusterFinderV3.cxx
CommitLineData
c13ab450 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 "AliMUONPreClusterFinderV3.h"
19
20#include "AliLog.h"
21#include "AliMUONCluster.h"
22#include "AliMpVSegmentation.h"
23#include "TClonesArray.h"
24#include "AliMpArea.h"
25#include "TVector2.h"
26#include "AliMUONPad.h"
27#include "AliMUONVDigit.h"
28#include "AliMUONVDigitStore.h"
29#include <Riostream.h>
30//#include "AliCodeTimer.h"
31
3d1463c8 32//-----------------------------------------------------------------------------
c13ab450 33/// \class AliMUONPreClusterFinderV3
34///
35/// Implementation of AliMUONVClusterFinder
36///
37/// This version uses a 2 steps approach :
38///
39/// we first clusterize each cathode independently to form proto-preclusters,
40/// and then we try to "merge" proto-preclusters from the two cathodes
41/// when thoses proto-preclusters overlap, thus ending up with preclusters
42/// spanning the two cathodes.
43///
44/// This implementation, on the contrary to PreClusterFinder or PreClusterFinderV2
45/// should not depend on the order of the input digits.
46///
47/// \author Laurent Aphecetche
3d1463c8 48//-----------------------------------------------------------------------------
c13ab450 49
50ClassImp(AliMUONPreClusterFinderV3)
51
52namespace
53{
54 //___________________________________________________________________________
55 Bool_t
56 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
57 {
58 /// Whether the pad overlaps with the cluster
59
60 static Double_t precision = 1E-4; // cm
61 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
62 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
63 {
64 AliMUONPad* testPad = cluster.Pad(i);
65 // Note: we use negative precision numbers, meaning
66 // the area of the pads will be *increased* by these small numbers
67 // prior to check the overlap by the AreOverlapping method,
68 // so pads touching only by the corners will be considered as
69 // overlapping.
70 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
71 {
72 return kTRUE;
73 }
74 }
75 return kFALSE;
76 }
77}
78
79//_____________________________________________________________________________
80AliMUONPreClusterFinderV3::AliMUONPreClusterFinderV3()
81: AliMUONVClusterFinder(),
82 fClusters(new TClonesArray("AliMUONCluster",10)),
72dae9ff 83 fkSegmentations(0x0),
24935e58 84 fPads(0x0),
c13ab450 85 fDetElemId(0),
86 fIterator(0x0)
87{
88 /// ctor
89 AliInfo("")
90 for ( Int_t i = 0; i < 2; ++i )
91 {
c13ab450 92 fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
93 }
94}
95
96//_____________________________________________________________________________
97AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
98{
24935e58 99 /// dtor
c13ab450 100 delete fClusters;
101 for ( Int_t i = 0; i < 2; ++i )
102 {
c13ab450 103 delete fPreClusters[i];
104 }
105}
106
107//_____________________________________________________________________________
108Bool_t
109AliMUONPreClusterFinderV3::UsePad(const AliMUONPad& pad)
110{
111 /// Add a pad to the list of pads to be considered
112 if ( pad.DetElemId() != fDetElemId )
113 {
114 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
115 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
116 return kFALSE;
117 }
118
119 AliMUONPad* p = new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
120 p->SetClusterId(-1);
121 return kTRUE;
122}
123
124//_____________________________________________________________________________
125Bool_t
24935e58 126AliMUONPreClusterFinderV3::Prepare(Int_t detElemId,
127 TClonesArray* pads[2],
128 const AliMpArea& area,
129 const AliMpVSegmentation* seg[2])
c13ab450 130{
131 /// Prepare for clustering, by giving access to segmentations and digit lists
c13ab450 132
24935e58 133 if ( area.IsValid() )
134 {
135 AliError("Handling of area not yet implemented for this class. Please check.");
136 }
137
72dae9ff 138 fkSegmentations = seg;
24935e58 139 fPads = pads;
c13ab450 140
141 fClusters->Clear("C");
142 for ( Int_t i = 0; i < 2; ++i )
143 {
c13ab450 144 fPreClusters[i]->Clear("C");
145 }
146
24935e58 147 fDetElemId = detElemId;
c13ab450 148
c13ab450 149 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
150 {
151 // no pad at all, nothing to do...
152 return kFALSE;
153 }
154
155 MakeCathodePreClusters(0);
156 MakeCathodePreClusters(1);
157 MakeClusters();
158
159 delete fIterator;
160 fIterator = fClusters->MakeIterator();
161
162 return kTRUE;
163}
164
165//_____________________________________________________________________________
166void
167AliMUONPreClusterFinderV3::DumpPreClusters() const
168{
169 /// Dump preclusters
170 AliMUONCluster *c;
171 TIter next0(fPreClusters[0]);
172 TIter next1(fPreClusters[1]);
173 cout << "Cath0" << endl;
174 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
175 {
176 cout << c->AsString().Data() << endl;
177 }
178 cout << "Cath1" << endl;
179 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
180 {
181 cout << c->AsString().Data() << endl;
182 }
183}
184
185//_____________________________________________________________________________
186void
187AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
188{
189 /// Add a pad to a cluster
190
191 AliMUONCluster a(*preCluster);
192
193 Int_t cathode = preCluster->Cathode();
194 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
195 {
196 AliError(Form("Could not remove %s from preclusters[%d]",
197 preCluster->AsString().Data(),cathode));
198 StdoutToAliDebug(1,DumpPreClusters());
199 AliFatal("");
200 }
201
202 cluster.AddCluster(a);
203
204 // loop on the *other* cathode
205 TIter next(fPreClusters[1-cathode]);
206 AliMUONCluster* testCluster;
207
208 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
209 {
210 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
211 {
212 AddPreCluster(cluster,testCluster);
213 }
214 }
215}
216
217
218//_____________________________________________________________________________
219void
220AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
221{
222 /// Add a pad to a cluster
223 AliMUONPad* addedPad = cluster.AddPad(*pad);
224
225 Int_t cathode = pad->Cathode();
226 TClonesArray& padArray = *fPads[cathode];
227 padArray.Remove(pad);
228 TIter next(&padArray);
229 AliMUONPad* testPad;
230
231 while ( ( testPad = static_cast<AliMUONPad*>(next())))
232 {
233 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
234 {
235 AddPad(cluster,testPad);
236 }
237 }
238}
239
240//_____________________________________________________________________________
241AliMUONCluster*
242AliMUONPreClusterFinderV3::NextCluster()
243{
244 /// Returns the next cluster
245
246 return static_cast<AliMUONCluster*>(fIterator->Next());
247}
248
249//_____________________________________________________________________________
250void
251AliMUONPreClusterFinderV3::MakeClusters()
252{
253 /// Associate (proto)preclusters to form (pre)clusters
254
99c136e1 255// AliCodeTimerAuto("",0)
c13ab450 256
257 for ( Int_t cathode = 0; cathode < 2; ++cathode )
258 {
259 TClonesArray& preclusters = *(fPreClusters[cathode]);
260
261 TIter next(&preclusters);
262 AliMUONCluster* preCluster(0x0);
263
264 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
265 {
266 Int_t id(fClusters->GetLast()+1);
267 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
268 cluster->SetUniqueID(id);
269 AddPreCluster(*cluster,preCluster);
270 }
271 }
272}
273
274//_____________________________________________________________________________
275void
276AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
277{
278 /// Build (proto)preclusters from digits on a given cathode
279
99c136e1 280// AliCodeTimerAuto(Form("Cathode %d",cathode),0)
c13ab450 281
282 while ( fPads[cathode]->GetLast() > 0 )
283 {
284 TIter next(fPads[cathode]);
285 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
286
287 if (!pad) AliFatal("");
288
289 Int_t id = fPreClusters[cathode]->GetLast()+1;
290 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
291 cluster->SetUniqueID(id);
292
293 // Builds (recursively) a cluster on first cathode only
294 AddPad(*cluster,pad);
295
296 if ( cluster->Multiplicity() <= 1 )
297 {
298 if ( cluster->Multiplicity() == 0 )
299 {
300 // no pad is suspicious
301 AliWarning("Got an empty cluster...");
302 }
303 // else only 1 pad (not suspicious, but kind of useless, probably noise)
304 // so we remove it from our list
305 fPreClusters[cathode]->Remove(cluster);
306 // then proceed further
307 }
308 }
309
310}