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