1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 #include "AliMUONPreClusterFinderV3.h"
21 #include "AliMUONCluster.h"
22 #include "AliMpVSegmentation.h"
23 #include "TClonesArray.h"
24 #include "AliMpArea.h"
26 #include "AliMUONPad.h"
27 #include "AliMUONVDigit.h"
28 #include "AliMUONVDigitStore.h"
29 #include <Riostream.h>
30 //#include "AliCodeTimer.h"
32 /// \class AliMUONPreClusterFinderV3
34 /// Implementation of AliMUONVClusterFinder
36 /// This version uses a 2 steps approach :
38 /// we first clusterize each cathode independently to form proto-preclusters,
39 /// and then we try to "merge" proto-preclusters from the two cathodes
40 /// when thoses proto-preclusters overlap, thus ending up with preclusters
41 /// spanning the two cathodes.
43 /// This implementation, on the contrary to PreClusterFinder or PreClusterFinderV2
44 /// should not depend on the order of the input digits.
46 /// \author Laurent Aphecetche
48 ClassImp(AliMUONPreClusterFinderV3)
52 //___________________________________________________________________________
54 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
56 /// Whether the pad overlaps with the cluster
58 static Double_t precision = 1E-4; // cm
59 static TVector2 precisionAdjustment(precision,precision);//-precision,-precision);
60 for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
62 AliMUONPad* testPad = cluster.Pad(i);
63 // Note: we use negative precision numbers, meaning
64 // the area of the pads will be *increased* by these small numbers
65 // prior to check the overlap by the AreOverlapping method,
66 // so pads touching only by the corners will be considered as
68 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
77 //_____________________________________________________________________________
78 AliMUONPreClusterFinderV3::AliMUONPreClusterFinderV3()
79 : AliMUONVClusterFinder(),
80 fClusters(new TClonesArray("AliMUONCluster",10)),
87 for ( Int_t i = 0; i < 2; ++i )
89 fPads[i] = new TClonesArray("AliMUONPad",100);
90 fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
94 //_____________________________________________________________________________
95 AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
97 /// dtor : note we're owner of the pads and the clusters, but not of
98 /// the remaining objects (digits, segmentations)
100 for ( Int_t i = 0; i < 2; ++i )
103 delete fPreClusters[i];
107 //_____________________________________________________________________________
109 AliMUONPreClusterFinderV3::UsePad(const AliMUONPad& pad)
111 /// Add a pad to the list of pads to be considered
112 if ( pad.DetElemId() != fDetElemId )
114 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
115 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
119 AliMUONPad* p = new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
124 //_____________________________________________________________________________
126 AliMUONPreClusterFinderV3::Prepare(const AliMpVSegmentation* segmentations[2],
127 const AliMUONVDigitStore& digitStore)
129 /// Prepare for clustering, by giving access to segmentations and digit lists
130 // FIXME : add area on which to look for clusters here.
132 fSegmentations = segmentations;
134 fClusters->Clear("C");
135 for ( Int_t i = 0; i < 2; ++i )
137 fPads[i]->Clear("C");
138 fPreClusters[i]->Clear("C");
143 TIter next(digitStore.CreateIterator());
146 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
148 Int_t ix = d->PadX();
149 Int_t iy = d->PadY();
150 Int_t cathode = d->Cathode();
151 AliMpPad pad = fSegmentations[cathode]->PadByIndices(AliMpIntPair(ix,iy));
152 TClonesArray& padArray = *(fPads[cathode]);
153 if ( fDetElemId == -1 )
155 fDetElemId = d->DetElemId();
159 if ( d->DetElemId() != fDetElemId )
161 AliError("Something is seriously wrong with DE. Aborting clustering");
166 AliMUONPad mpad(fDetElemId,cathode,
167 ix,iy,pad.Position().X(),pad.Position().Y(),
168 pad.Dimensions().X(),pad.Dimensions().Y(),
170 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
171 new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);
173 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
175 // no pad at all, nothing to do...
179 MakeCathodePreClusters(0);
180 MakeCathodePreClusters(1);
184 fIterator = fClusters->MakeIterator();
189 //_____________________________________________________________________________
191 AliMUONPreClusterFinderV3::DumpPreClusters() const
195 TIter next0(fPreClusters[0]);
196 TIter next1(fPreClusters[1]);
197 cout << "Cath0" << endl;
198 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
200 cout << c->AsString().Data() << endl;
202 cout << "Cath1" << endl;
203 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
205 cout << c->AsString().Data() << endl;
209 //_____________________________________________________________________________
211 AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
213 /// Add a pad to a cluster
215 AliMUONCluster a(*preCluster);
217 Int_t cathode = preCluster->Cathode();
218 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
220 AliError(Form("Could not remove %s from preclusters[%d]",
221 preCluster->AsString().Data(),cathode));
222 StdoutToAliDebug(1,DumpPreClusters());
226 cluster.AddCluster(a);
228 // loop on the *other* cathode
229 TIter next(fPreClusters[1-cathode]);
230 AliMUONCluster* testCluster;
232 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
234 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
236 AddPreCluster(cluster,testCluster);
242 //_____________________________________________________________________________
244 AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
246 /// Add a pad to a cluster
247 AliMUONPad* addedPad = cluster.AddPad(*pad);
249 Int_t cathode = pad->Cathode();
250 TClonesArray& padArray = *fPads[cathode];
251 padArray.Remove(pad);
252 TIter next(&padArray);
255 while ( ( testPad = static_cast<AliMUONPad*>(next())))
257 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
259 AddPad(cluster,testPad);
264 //_____________________________________________________________________________
266 AliMUONPreClusterFinderV3::NextCluster()
268 /// Returns the next cluster
270 return static_cast<AliMUONCluster*>(fIterator->Next());
273 //_____________________________________________________________________________
275 AliMUONPreClusterFinderV3::MakeClusters()
277 /// Associate (proto)preclusters to form (pre)clusters
279 // AliCodeTimerAuto("")
281 for ( Int_t cathode = 0; cathode < 2; ++cathode )
283 TClonesArray& preclusters = *(fPreClusters[cathode]);
285 TIter next(&preclusters);
286 AliMUONCluster* preCluster(0x0);
288 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
290 Int_t id(fClusters->GetLast()+1);
291 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
292 cluster->SetUniqueID(id);
293 AddPreCluster(*cluster,preCluster);
298 //_____________________________________________________________________________
300 AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
302 /// Build (proto)preclusters from digits on a given cathode
304 // AliCodeTimerAuto(Form("Cathode %d",cathode))
306 while ( fPads[cathode]->GetLast() > 0 )
308 TIter next(fPads[cathode]);
309 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
311 if (!pad) AliFatal("");
313 Int_t id = fPreClusters[cathode]->GetLast()+1;
314 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
315 cluster->SetUniqueID(id);
317 // Builds (recursively) a cluster on first cathode only
318 AddPad(*cluster,pad);
320 if ( cluster->Multiplicity() <= 1 )
322 if ( cluster->Multiplicity() == 0 )
324 // no pad is suspicious
325 AliWarning("Got an empty cluster...");
327 // else only 1 pad (not suspicious, but kind of useless, probably noise)
328 // so we remove it from our list
329 fPreClusters[cathode]->Remove(cluster);
330 // then proceed further