]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONPreClusterFinderV3.cxx
Generation of generic AOD by the test script of MUON
[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)),
83 fSegmentations(0x0),
84 fDetElemId(0),
85 fIterator(0x0)
86{
87 /// ctor
88 AliInfo("")
89 for ( Int_t i = 0; i < 2; ++i )
90 {
91 fPads[i] = new TClonesArray("AliMUONPad",100);
92 fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
93 }
94}
95
96//_____________________________________________________________________________
97AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
98{
99 /// dtor : note we're owner of the pads and the clusters, but not of
100 /// the remaining objects (digits, segmentations)
101 delete fClusters;
102 for ( Int_t i = 0; i < 2; ++i )
103 {
104 delete fPads[i];
105 delete fPreClusters[i];
106 }
107}
108
109//_____________________________________________________________________________
110Bool_t
111AliMUONPreClusterFinderV3::UsePad(const AliMUONPad& pad)
112{
113 /// Add a pad to the list of pads to be considered
114 if ( pad.DetElemId() != fDetElemId )
115 {
116 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
117 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
118 return kFALSE;
119 }
120
121 AliMUONPad* p = new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
122 p->SetClusterId(-1);
123 return kTRUE;
124}
125
126//_____________________________________________________________________________
127Bool_t
128AliMUONPreClusterFinderV3::Prepare(const AliMpVSegmentation* segmentations[2],
129 const AliMUONVDigitStore& digitStore)
130{
131 /// Prepare for clustering, by giving access to segmentations and digit lists
132 // FIXME : add area on which to look for clusters here.
133
134 fSegmentations = segmentations;
135
136 fClusters->Clear("C");
137 for ( Int_t i = 0; i < 2; ++i )
138 {
139 fPads[i]->Clear("C");
140 fPreClusters[i]->Clear("C");
141 }
142
143 fDetElemId = -1;
144
145 TIter next(digitStore.CreateIterator());
146 AliMUONVDigit* d;
147
148 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
149 {
150 Int_t ix = d->PadX();
151 Int_t iy = d->PadY();
152 Int_t cathode = d->Cathode();
153 AliMpPad pad = fSegmentations[cathode]->PadByIndices(AliMpIntPair(ix,iy));
154 TClonesArray& padArray = *(fPads[cathode]);
155 if ( fDetElemId == -1 )
156 {
157 fDetElemId = d->DetElemId();
158 }
159 else
160 {
161 if ( d->DetElemId() != fDetElemId )
162 {
163 AliError("Something is seriously wrong with DE. Aborting clustering");
164 return kFALSE;
165 }
166 }
167
168 AliMUONPad mpad(fDetElemId,cathode,
169 ix,iy,pad.Position().X(),pad.Position().Y(),
170 pad.Dimensions().X(),pad.Dimensions().Y(),
171 d->Charge());
172 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
173 new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);
174 }
175 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
176 {
177 // no pad at all, nothing to do...
178 return kFALSE;
179 }
180
181 MakeCathodePreClusters(0);
182 MakeCathodePreClusters(1);
183 MakeClusters();
184
185 delete fIterator;
186 fIterator = fClusters->MakeIterator();
187
188 return kTRUE;
189}
190
191//_____________________________________________________________________________
192void
193AliMUONPreClusterFinderV3::DumpPreClusters() const
194{
195 /// Dump preclusters
196 AliMUONCluster *c;
197 TIter next0(fPreClusters[0]);
198 TIter next1(fPreClusters[1]);
199 cout << "Cath0" << endl;
200 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
201 {
202 cout << c->AsString().Data() << endl;
203 }
204 cout << "Cath1" << endl;
205 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
206 {
207 cout << c->AsString().Data() << endl;
208 }
209}
210
211//_____________________________________________________________________________
212void
213AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
214{
215 /// Add a pad to a cluster
216
217 AliMUONCluster a(*preCluster);
218
219 Int_t cathode = preCluster->Cathode();
220 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
221 {
222 AliError(Form("Could not remove %s from preclusters[%d]",
223 preCluster->AsString().Data(),cathode));
224 StdoutToAliDebug(1,DumpPreClusters());
225 AliFatal("");
226 }
227
228 cluster.AddCluster(a);
229
230 // loop on the *other* cathode
231 TIter next(fPreClusters[1-cathode]);
232 AliMUONCluster* testCluster;
233
234 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
235 {
236 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
237 {
238 AddPreCluster(cluster,testCluster);
239 }
240 }
241}
242
243
244//_____________________________________________________________________________
245void
246AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
247{
248 /// Add a pad to a cluster
249 AliMUONPad* addedPad = cluster.AddPad(*pad);
250
251 Int_t cathode = pad->Cathode();
252 TClonesArray& padArray = *fPads[cathode];
253 padArray.Remove(pad);
254 TIter next(&padArray);
255 AliMUONPad* testPad;
256
257 while ( ( testPad = static_cast<AliMUONPad*>(next())))
258 {
259 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
260 {
261 AddPad(cluster,testPad);
262 }
263 }
264}
265
266//_____________________________________________________________________________
267AliMUONCluster*
268AliMUONPreClusterFinderV3::NextCluster()
269{
270 /// Returns the next cluster
271
272 return static_cast<AliMUONCluster*>(fIterator->Next());
273}
274
275//_____________________________________________________________________________
276void
277AliMUONPreClusterFinderV3::MakeClusters()
278{
279 /// Associate (proto)preclusters to form (pre)clusters
280
281// AliCodeTimerAuto("")
282
283 for ( Int_t cathode = 0; cathode < 2; ++cathode )
284 {
285 TClonesArray& preclusters = *(fPreClusters[cathode]);
286
287 TIter next(&preclusters);
288 AliMUONCluster* preCluster(0x0);
289
290 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
291 {
292 Int_t id(fClusters->GetLast()+1);
293 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
294 cluster->SetUniqueID(id);
295 AddPreCluster(*cluster,preCluster);
296 }
297 }
298}
299
300//_____________________________________________________________________________
301void
302AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
303{
304 /// Build (proto)preclusters from digits on a given cathode
305
306// AliCodeTimerAuto(Form("Cathode %d",cathode))
307
308 while ( fPads[cathode]->GetLast() > 0 )
309 {
310 TIter next(fPads[cathode]);
311 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
312
313 if (!pad) AliFatal("");
314
315 Int_t id = fPreClusters[cathode]->GetLast()+1;
316 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
317 cluster->SetUniqueID(id);
318
319 // Builds (recursively) a cluster on first cathode only
320 AddPad(*cluster,pad);
321
322 if ( cluster->Multiplicity() <= 1 )
323 {
324 if ( cluster->Multiplicity() == 0 )
325 {
326 // no pad is suspicious
327 AliWarning("Got an empty cluster...");
328 }
329 // else only 1 pad (not suspicious, but kind of useless, probably noise)
330 // so we remove it from our list
331 fPreClusters[cathode]->Remove(cluster);
332 // then proceed further
333 }
334 }
335
336}