]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONrec/AliMUONPreClusterFinderV3.cxx
MUON + CheckCompiler
[u/mrichter/AliRoot.git] / MUON / MUONrec / 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
cdd730d0 50using std::endl;
51using std::cout;
c13ab450 52ClassImp(AliMUONPreClusterFinderV3)
53
c13ab450 54//_____________________________________________________________________________
55AliMUONPreClusterFinderV3::AliMUONPreClusterFinderV3()
56: AliMUONVClusterFinder(),
57 fClusters(new TClonesArray("AliMUONCluster",10)),
72dae9ff 58 fkSegmentations(0x0),
24935e58 59 fPads(0x0),
c13ab450 60 fDetElemId(0),
61 fIterator(0x0)
62{
63 /// ctor
13242232 64 AliInfo("");
c13ab450 65 for ( Int_t i = 0; i < 2; ++i )
66 {
c13ab450 67 fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
68 }
69}
70
71//_____________________________________________________________________________
72AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
73{
24935e58 74 /// dtor
c13ab450 75 delete fClusters;
76 for ( Int_t i = 0; i < 2; ++i )
77 {
c13ab450 78 delete fPreClusters[i];
79 }
80}
81
82//_____________________________________________________________________________
83Bool_t
84AliMUONPreClusterFinderV3::UsePad(const AliMUONPad& pad)
85{
86 /// Add a pad to the list of pads to be considered
87 if ( pad.DetElemId() != fDetElemId )
88 {
89 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
90 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
91 return kFALSE;
92 }
93
9e41a340 94 AliMUONPad* p = new AliMUONPad(pad);
c13ab450 95 p->SetClusterId(-1);
9e41a340 96 fPads[pad.Cathode()]->Add(p);
c13ab450 97 return kTRUE;
98}
99
100//_____________________________________________________________________________
101Bool_t
24935e58 102AliMUONPreClusterFinderV3::Prepare(Int_t detElemId,
9e41a340 103 TObjArray* pads[2],
24935e58 104 const AliMpArea& area,
105 const AliMpVSegmentation* seg[2])
c13ab450 106{
107 /// Prepare for clustering, by giving access to segmentations and digit lists
c13ab450 108
24935e58 109 if ( area.IsValid() )
110 {
111 AliError("Handling of area not yet implemented for this class. Please check.");
112 }
113
72dae9ff 114 fkSegmentations = seg;
24935e58 115 fPads = pads;
c13ab450 116
117 fClusters->Clear("C");
118 for ( Int_t i = 0; i < 2; ++i )
119 {
c13ab450 120 fPreClusters[i]->Clear("C");
121 }
122
24935e58 123 fDetElemId = detElemId;
c13ab450 124
c13ab450 125 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
126 {
127 // no pad at all, nothing to do...
128 return kFALSE;
129 }
130
131 MakeCathodePreClusters(0);
132 MakeCathodePreClusters(1);
133 MakeClusters();
134
135 delete fIterator;
136 fIterator = fClusters->MakeIterator();
137
138 return kTRUE;
139}
140
141//_____________________________________________________________________________
142void
143AliMUONPreClusterFinderV3::DumpPreClusters() const
144{
145 /// Dump preclusters
146 AliMUONCluster *c;
147 TIter next0(fPreClusters[0]);
148 TIter next1(fPreClusters[1]);
149 cout << "Cath0" << endl;
150 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
151 {
152 cout << c->AsString().Data() << endl;
153 }
154 cout << "Cath1" << endl;
155 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
156 {
157 cout << c->AsString().Data() << endl;
158 }
159}
160
161//_____________________________________________________________________________
162void
163AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
164{
165 /// Add a pad to a cluster
166
167 AliMUONCluster a(*preCluster);
168
169 Int_t cathode = preCluster->Cathode();
1e875d50 170 if ( cathode < 0 ) {
171 AliError(Form("Cathod undefined: %d",cathode));
172 AliFatal("");
5d48f035 173 return;
1e875d50 174 }
175
c13ab450 176 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
177 {
178 AliError(Form("Could not remove %s from preclusters[%d]",
179 preCluster->AsString().Data(),cathode));
180 StdoutToAliDebug(1,DumpPreClusters());
181 AliFatal("");
5d48f035 182 return;
c13ab450 183 }
184
185 cluster.AddCluster(a);
186
187 // loop on the *other* cathode
188 TIter next(fPreClusters[1-cathode]);
189 AliMUONCluster* testCluster;
190
191 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
192 {
193 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
194 {
195 AddPreCluster(cluster,testCluster);
196 }
197 }
198}
199
200
201//_____________________________________________________________________________
202void
203AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
204{
205 /// Add a pad to a cluster
206 AliMUONPad* addedPad = cluster.AddPad(*pad);
207
208 Int_t cathode = pad->Cathode();
9e41a340 209 TObjArray& padArray = *fPads[cathode];
ed90feae 210 delete padArray.Remove(pad);
211
c13ab450 212 TIter next(&padArray);
213 AliMUONPad* testPad;
214
215 while ( ( testPad = static_cast<AliMUONPad*>(next())))
216 {
217 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
218 {
219 AddPad(cluster,testPad);
220 }
221 }
222}
223
224//_____________________________________________________________________________
225AliMUONCluster*
226AliMUONPreClusterFinderV3::NextCluster()
227{
228 /// Returns the next cluster
229
230 return static_cast<AliMUONCluster*>(fIterator->Next());
231}
232
233//_____________________________________________________________________________
234void
235AliMUONPreClusterFinderV3::MakeClusters()
236{
237 /// Associate (proto)preclusters to form (pre)clusters
238
99c136e1 239// AliCodeTimerAuto("",0)
c13ab450 240
241 for ( Int_t cathode = 0; cathode < 2; ++cathode )
242 {
243 TClonesArray& preclusters = *(fPreClusters[cathode]);
244
245 TIter next(&preclusters);
246 AliMUONCluster* preCluster(0x0);
247
248 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
249 {
250 Int_t id(fClusters->GetLast()+1);
251 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
252 cluster->SetUniqueID(id);
253 AddPreCluster(*cluster,preCluster);
254 }
255 }
256}
257
258//_____________________________________________________________________________
259void
260AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
261{
262 /// Build (proto)preclusters from digits on a given cathode
263
99c136e1 264// AliCodeTimerAuto(Form("Cathode %d",cathode),0)
c13ab450 265
266 while ( fPads[cathode]->GetLast() > 0 )
267 {
268 TIter next(fPads[cathode]);
269 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
270
271 if (!pad) AliFatal("");
272
273 Int_t id = fPreClusters[cathode]->GetLast()+1;
274 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
275 cluster->SetUniqueID(id);
276
277 // Builds (recursively) a cluster on first cathode only
278 AddPad(*cluster,pad);
279
280 if ( cluster->Multiplicity() <= 1 )
281 {
282 if ( cluster->Multiplicity() == 0 )
283 {
284 // no pad is suspicious
285 AliWarning("Got an empty cluster...");
286 }
287 // else only 1 pad (not suspicious, but kind of useless, probably noise)
288 // so we remove it from our list
289 fPreClusters[cathode]->Remove(cluster);
290 // then proceed further
291 }
292 }
293
294}