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 "TObjArray.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)
52 //_____________________________________________________________________________
53 AliMUONPreClusterFinderV3::AliMUONPreClusterFinderV3()
54 : AliMUONVClusterFinder(),
55 fClusters(new TClonesArray("AliMUONCluster",10)),
63 for ( Int_t i = 0; i < 2; ++i )
65 fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
69 //_____________________________________________________________________________
70 AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
74 for ( Int_t i = 0; i < 2; ++i )
76 delete fPreClusters[i];
80 //_____________________________________________________________________________
82 AliMUONPreClusterFinderV3::UsePad(const AliMUONPad& pad)
84 /// Add a pad to the list of pads to be considered
85 if ( pad.DetElemId() != fDetElemId )
87 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
88 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
92 AliMUONPad* p = new AliMUONPad(pad);
94 fPads[pad.Cathode()]->Add(p);
98 //_____________________________________________________________________________
100 AliMUONPreClusterFinderV3::Prepare(Int_t detElemId,
102 const AliMpArea& area,
103 const AliMpVSegmentation* seg[2])
105 /// Prepare for clustering, by giving access to segmentations and digit lists
107 if ( area.IsValid() )
109 AliError("Handling of area not yet implemented for this class. Please check.");
112 fkSegmentations = seg;
115 fClusters->Clear("C");
116 for ( Int_t i = 0; i < 2; ++i )
118 fPreClusters[i]->Clear("C");
121 fDetElemId = detElemId;
123 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
125 // no pad at all, nothing to do...
129 MakeCathodePreClusters(0);
130 MakeCathodePreClusters(1);
134 fIterator = fClusters->MakeIterator();
139 //_____________________________________________________________________________
141 AliMUONPreClusterFinderV3::DumpPreClusters() const
145 TIter next0(fPreClusters[0]);
146 TIter next1(fPreClusters[1]);
147 cout << "Cath0" << endl;
148 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
150 cout << c->AsString().Data() << endl;
152 cout << "Cath1" << endl;
153 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
155 cout << c->AsString().Data() << endl;
159 //_____________________________________________________________________________
161 AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
163 /// Add a pad to a cluster
165 AliMUONCluster a(*preCluster);
167 Int_t cathode = preCluster->Cathode();
169 AliError(Form("Cathod undefined: %d",cathode));
174 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
176 AliError(Form("Could not remove %s from preclusters[%d]",
177 preCluster->AsString().Data(),cathode));
178 StdoutToAliDebug(1,DumpPreClusters());
183 cluster.AddCluster(a);
185 // loop on the *other* cathode
186 TIter next(fPreClusters[1-cathode]);
187 AliMUONCluster* testCluster;
189 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
191 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
193 AddPreCluster(cluster,testCluster);
199 //_____________________________________________________________________________
201 AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
203 /// Add a pad to a cluster
204 AliMUONPad* addedPad = cluster.AddPad(*pad);
206 Int_t cathode = pad->Cathode();
207 TObjArray& padArray = *fPads[cathode];
208 delete padArray.Remove(pad);
210 TIter next(&padArray);
213 while ( ( testPad = static_cast<AliMUONPad*>(next())))
215 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
217 AddPad(cluster,testPad);
222 //_____________________________________________________________________________
224 AliMUONPreClusterFinderV3::NextCluster()
226 /// Returns the next cluster
228 return static_cast<AliMUONCluster*>(fIterator->Next());
231 //_____________________________________________________________________________
233 AliMUONPreClusterFinderV3::MakeClusters()
235 /// Associate (proto)preclusters to form (pre)clusters
237 // AliCodeTimerAuto("",0)
239 for ( Int_t cathode = 0; cathode < 2; ++cathode )
241 TClonesArray& preclusters = *(fPreClusters[cathode]);
243 TIter next(&preclusters);
244 AliMUONCluster* preCluster(0x0);
246 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
248 Int_t id(fClusters->GetLast()+1);
249 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
250 cluster->SetUniqueID(id);
251 AddPreCluster(*cluster,preCluster);
256 //_____________________________________________________________________________
258 AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
260 /// Build (proto)preclusters from digits on a given cathode
262 // AliCodeTimerAuto(Form("Cathode %d",cathode),0)
264 while ( fPads[cathode]->GetLast() > 0 )
266 TIter next(fPads[cathode]);
267 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
269 if (!pad) AliFatal("");
271 Int_t id = fPreClusters[cathode]->GetLast()+1;
272 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
273 cluster->SetUniqueID(id);
275 // Builds (recursively) a cluster on first cathode only
276 AddPad(*cluster,pad);
278 if ( cluster->Multiplicity() <= 1 )
280 if ( cluster->Multiplicity() == 0 )
282 // no pad is suspicious
283 AliWarning("Got an empty cluster...");
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