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 //-----------------------------------------------------------------------------
33 /// \class AliMUONPreClusterFinderV3
35 /// Implementation of AliMUONVClusterFinder
37 /// This version uses a 2 steps approach :
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.
44 /// This implementation, on the contrary to PreClusterFinder or PreClusterFinderV2
45 /// should not depend on the order of the input digits.
47 /// \author Laurent Aphecetche
48 //-----------------------------------------------------------------------------
50 ClassImp(AliMUONPreClusterFinderV3)
54 //___________________________________________________________________________
56 AreOverlapping(const AliMUONPad& pad, const AliMUONCluster& cluster)
58 /// Whether the pad overlaps with the cluster
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 )
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
70 if ( AliMUONPad::AreOverlapping(*testPad,pad,precisionAdjustment) )
79 //_____________________________________________________________________________
80 AliMUONPreClusterFinderV3::AliMUONPreClusterFinderV3()
81 : AliMUONVClusterFinder(),
82 fClusters(new TClonesArray("AliMUONCluster",10)),
89 for ( Int_t i = 0; i < 2; ++i )
91 fPads[i] = new TClonesArray("AliMUONPad",100);
92 fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
96 //_____________________________________________________________________________
97 AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
99 /// dtor : note we're owner of the pads and the clusters, but not of
100 /// the remaining objects (digits, segmentations)
102 for ( Int_t i = 0; i < 2; ++i )
105 delete fPreClusters[i];
109 //_____________________________________________________________________________
111 AliMUONPreClusterFinderV3::UsePad(const AliMUONPad& pad)
113 /// Add a pad to the list of pads to be considered
114 if ( pad.DetElemId() != fDetElemId )
116 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
117 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
121 AliMUONPad* p = new ((*fPads[pad.Cathode()])[fPads[pad.Cathode()]->GetLast()+1]) AliMUONPad(pad);
126 //_____________________________________________________________________________
128 AliMUONPreClusterFinderV3::Prepare(const AliMpVSegmentation* segmentations[2],
129 const AliMUONVDigitStore& digitStore)
131 /// Prepare for clustering, by giving access to segmentations and digit lists
132 // FIXME : add area on which to look for clusters here.
134 fSegmentations = segmentations;
136 fClusters->Clear("C");
137 for ( Int_t i = 0; i < 2; ++i )
139 fPads[i]->Clear("C");
140 fPreClusters[i]->Clear("C");
145 TIter next(digitStore.CreateIterator());
148 while ( ( d = static_cast<AliMUONVDigit*>(next()) ) )
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 )
157 fDetElemId = d->DetElemId();
161 if ( d->DetElemId() != fDetElemId )
163 AliError("Something is seriously wrong with DE. Aborting clustering");
168 AliMUONPad mpad(fDetElemId,cathode,
169 ix,iy,pad.Position().X(),pad.Position().Y(),
170 pad.Dimensions().X(),pad.Dimensions().Y(),
172 if ( d->IsSaturated() ) mpad.SetSaturated(kTRUE);
173 new (padArray[padArray.GetLast()+1]) AliMUONPad(mpad);
175 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
177 // no pad at all, nothing to do...
181 MakeCathodePreClusters(0);
182 MakeCathodePreClusters(1);
186 fIterator = fClusters->MakeIterator();
191 //_____________________________________________________________________________
193 AliMUONPreClusterFinderV3::DumpPreClusters() const
197 TIter next0(fPreClusters[0]);
198 TIter next1(fPreClusters[1]);
199 cout << "Cath0" << endl;
200 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
202 cout << c->AsString().Data() << endl;
204 cout << "Cath1" << endl;
205 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
207 cout << c->AsString().Data() << endl;
211 //_____________________________________________________________________________
213 AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
215 /// Add a pad to a cluster
217 AliMUONCluster a(*preCluster);
219 Int_t cathode = preCluster->Cathode();
220 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
222 AliError(Form("Could not remove %s from preclusters[%d]",
223 preCluster->AsString().Data(),cathode));
224 StdoutToAliDebug(1,DumpPreClusters());
228 cluster.AddCluster(a);
230 // loop on the *other* cathode
231 TIter next(fPreClusters[1-cathode]);
232 AliMUONCluster* testCluster;
234 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
236 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
238 AddPreCluster(cluster,testCluster);
244 //_____________________________________________________________________________
246 AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
248 /// Add a pad to a cluster
249 AliMUONPad* addedPad = cluster.AddPad(*pad);
251 Int_t cathode = pad->Cathode();
252 TClonesArray& padArray = *fPads[cathode];
253 padArray.Remove(pad);
254 TIter next(&padArray);
257 while ( ( testPad = static_cast<AliMUONPad*>(next())))
259 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
261 AddPad(cluster,testPad);
266 //_____________________________________________________________________________
268 AliMUONPreClusterFinderV3::NextCluster()
270 /// Returns the next cluster
272 return static_cast<AliMUONCluster*>(fIterator->Next());
275 //_____________________________________________________________________________
277 AliMUONPreClusterFinderV3::MakeClusters()
279 /// Associate (proto)preclusters to form (pre)clusters
281 // AliCodeTimerAuto("")
283 for ( Int_t cathode = 0; cathode < 2; ++cathode )
285 TClonesArray& preclusters = *(fPreClusters[cathode]);
287 TIter next(&preclusters);
288 AliMUONCluster* preCluster(0x0);
290 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
292 Int_t id(fClusters->GetLast()+1);
293 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
294 cluster->SetUniqueID(id);
295 AddPreCluster(*cluster,preCluster);
300 //_____________________________________________________________________________
302 AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
304 /// Build (proto)preclusters from digits on a given cathode
306 // AliCodeTimerAuto(Form("Cathode %d",cathode))
308 while ( fPads[cathode]->GetLast() > 0 )
310 TIter next(fPads[cathode]);
311 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
313 if (!pad) AliFatal("");
315 Int_t id = fPreClusters[cathode]->GetLast()+1;
316 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
317 cluster->SetUniqueID(id);
319 // Builds (recursively) a cluster on first cathode only
320 AddPad(*cluster,pad);
322 if ( cluster->Multiplicity() <= 1 )
324 if ( cluster->Multiplicity() == 0 )
326 // no pad is suspicious
327 AliWarning("Got an empty cluster...");
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