]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPreClusterFinderV3.cxx
Using At instead of UncheckedAt (Marian)
[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"
9e41a340 23#include "TObjArray.h"
c13ab450 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
9e41a340 119 AliMUONPad* p = new AliMUONPad(pad);
c13ab450 120 p->SetClusterId(-1);
9e41a340 121 fPads[pad.Cathode()]->Add(p);
c13ab450 122 return kTRUE;
123}
124
125//_____________________________________________________________________________
126Bool_t
24935e58 127AliMUONPreClusterFinderV3::Prepare(Int_t detElemId,
9e41a340 128 TObjArray* pads[2],
24935e58 129 const AliMpArea& area,
130 const AliMpVSegmentation* seg[2])
c13ab450 131{
132 /// Prepare for clustering, by giving access to segmentations and digit lists
c13ab450 133
24935e58 134 if ( area.IsValid() )
135 {
136 AliError("Handling of area not yet implemented for this class. Please check.");
137 }
138
72dae9ff 139 fkSegmentations = seg;
24935e58 140 fPads = pads;
c13ab450 141
142 fClusters->Clear("C");
143 for ( Int_t i = 0; i < 2; ++i )
144 {
c13ab450 145 fPreClusters[i]->Clear("C");
146 }
147
24935e58 148 fDetElemId = detElemId;
c13ab450 149
c13ab450 150 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
151 {
152 // no pad at all, nothing to do...
153 return kFALSE;
154 }
155
156 MakeCathodePreClusters(0);
157 MakeCathodePreClusters(1);
158 MakeClusters();
159
160 delete fIterator;
161 fIterator = fClusters->MakeIterator();
162
163 return kTRUE;
164}
165
166//_____________________________________________________________________________
167void
168AliMUONPreClusterFinderV3::DumpPreClusters() const
169{
170 /// Dump preclusters
171 AliMUONCluster *c;
172 TIter next0(fPreClusters[0]);
173 TIter next1(fPreClusters[1]);
174 cout << "Cath0" << endl;
175 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
176 {
177 cout << c->AsString().Data() << endl;
178 }
179 cout << "Cath1" << endl;
180 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
181 {
182 cout << c->AsString().Data() << endl;
183 }
184}
185
186//_____________________________________________________________________________
187void
188AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
189{
190 /// Add a pad to a cluster
191
192 AliMUONCluster a(*preCluster);
193
194 Int_t cathode = preCluster->Cathode();
1e875d50 195 if ( cathode < 0 ) {
196 AliError(Form("Cathod undefined: %d",cathode));
197 AliFatal("");
5d48f035 198 return;
1e875d50 199 }
200
c13ab450 201 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
202 {
203 AliError(Form("Could not remove %s from preclusters[%d]",
204 preCluster->AsString().Data(),cathode));
205 StdoutToAliDebug(1,DumpPreClusters());
206 AliFatal("");
5d48f035 207 return;
c13ab450 208 }
209
210 cluster.AddCluster(a);
211
212 // loop on the *other* cathode
213 TIter next(fPreClusters[1-cathode]);
214 AliMUONCluster* testCluster;
215
216 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
217 {
218 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
219 {
220 AddPreCluster(cluster,testCluster);
221 }
222 }
223}
224
225
226//_____________________________________________________________________________
227void
228AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
229{
230 /// Add a pad to a cluster
231 AliMUONPad* addedPad = cluster.AddPad(*pad);
232
233 Int_t cathode = pad->Cathode();
9e41a340 234 TObjArray& padArray = *fPads[cathode];
ed90feae 235 delete padArray.Remove(pad);
236
c13ab450 237 TIter next(&padArray);
238 AliMUONPad* testPad;
239
240 while ( ( testPad = static_cast<AliMUONPad*>(next())))
241 {
242 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
243 {
244 AddPad(cluster,testPad);
245 }
246 }
247}
248
249//_____________________________________________________________________________
250AliMUONCluster*
251AliMUONPreClusterFinderV3::NextCluster()
252{
253 /// Returns the next cluster
254
255 return static_cast<AliMUONCluster*>(fIterator->Next());
256}
257
258//_____________________________________________________________________________
259void
260AliMUONPreClusterFinderV3::MakeClusters()
261{
262 /// Associate (proto)preclusters to form (pre)clusters
263
99c136e1 264// AliCodeTimerAuto("",0)
c13ab450 265
266 for ( Int_t cathode = 0; cathode < 2; ++cathode )
267 {
268 TClonesArray& preclusters = *(fPreClusters[cathode]);
269
270 TIter next(&preclusters);
271 AliMUONCluster* preCluster(0x0);
272
273 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
274 {
275 Int_t id(fClusters->GetLast()+1);
276 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
277 cluster->SetUniqueID(id);
278 AddPreCluster(*cluster,preCluster);
279 }
280 }
281}
282
283//_____________________________________________________________________________
284void
285AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
286{
287 /// Build (proto)preclusters from digits on a given cathode
288
99c136e1 289// AliCodeTimerAuto(Form("Cathode %d",cathode),0)
c13ab450 290
291 while ( fPads[cathode]->GetLast() > 0 )
292 {
293 TIter next(fPads[cathode]);
294 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
295
296 if (!pad) AliFatal("");
297
298 Int_t id = fPreClusters[cathode]->GetLast()+1;
299 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
300 cluster->SetUniqueID(id);
301
302 // Builds (recursively) a cluster on first cathode only
303 AddPad(*cluster,pad);
304
305 if ( cluster->Multiplicity() <= 1 )
306 {
307 if ( cluster->Multiplicity() == 0 )
308 {
309 // no pad is suspicious
310 AliWarning("Got an empty cluster...");
311 }
312 // else only 1 pad (not suspicious, but kind of useless, probably noise)
313 // so we remove it from our list
314 fPreClusters[cathode]->Remove(cluster);
315 // then proceed further
316 }
317 }
318
319}