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 //-----------------------------------------------------------------------------
52 ClassImp(AliMUONPreClusterFinderV3)
54 //_____________________________________________________________________________
55 AliMUONPreClusterFinderV3::AliMUONPreClusterFinderV3()
56 : AliMUONVClusterFinder(),
57 fClusters(new TClonesArray("AliMUONCluster",10)),
65 for ( Int_t i = 0; i < 2; ++i )
67 fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
71 //_____________________________________________________________________________
72 AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
76 for ( Int_t i = 0; i < 2; ++i )
78 delete fPreClusters[i];
82 //_____________________________________________________________________________
84 AliMUONPreClusterFinderV3::UsePad(const AliMUONPad& pad)
86 /// Add a pad to the list of pads to be considered
87 if ( pad.DetElemId() != fDetElemId )
89 AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
90 "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
94 AliMUONPad* p = new AliMUONPad(pad);
96 fPads[pad.Cathode()]->Add(p);
100 //_____________________________________________________________________________
102 AliMUONPreClusterFinderV3::Prepare(Int_t detElemId,
104 const AliMpArea& area,
105 const AliMpVSegmentation* seg[2])
107 /// Prepare for clustering, by giving access to segmentations and digit lists
109 if ( area.IsValid() )
111 AliError("Handling of area not yet implemented for this class. Please check.");
114 fkSegmentations = seg;
117 fClusters->Clear("C");
118 for ( Int_t i = 0; i < 2; ++i )
120 fPreClusters[i]->Clear("C");
123 fDetElemId = detElemId;
125 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
127 // no pad at all, nothing to do...
131 MakeCathodePreClusters(0);
132 MakeCathodePreClusters(1);
136 fIterator = fClusters->MakeIterator();
141 //_____________________________________________________________________________
143 AliMUONPreClusterFinderV3::DumpPreClusters() const
147 TIter next0(fPreClusters[0]);
148 TIter next1(fPreClusters[1]);
149 cout << "Cath0" << endl;
150 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
152 cout << c->AsString().Data() << endl;
154 cout << "Cath1" << endl;
155 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
157 cout << c->AsString().Data() << endl;
161 //_____________________________________________________________________________
163 AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
165 /// Add a pad to a cluster
167 AliMUONCluster a(*preCluster);
169 Int_t cathode = preCluster->Cathode();
171 AliError(Form("Cathod undefined: %d",cathode));
176 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
178 AliError(Form("Could not remove %s from preclusters[%d]",
179 preCluster->AsString().Data(),cathode));
180 StdoutToAliDebug(1,DumpPreClusters());
185 cluster.AddCluster(a);
187 // loop on the *other* cathode
188 TIter next(fPreClusters[1-cathode]);
189 AliMUONCluster* testCluster;
191 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
193 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
195 AddPreCluster(cluster,testCluster);
201 //_____________________________________________________________________________
203 AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
205 /// Add a pad to a cluster
206 AliMUONPad* addedPad = cluster.AddPad(*pad);
208 Int_t cathode = pad->Cathode();
209 TObjArray& padArray = *fPads[cathode];
210 delete padArray.Remove(pad);
212 TIter next(&padArray);
215 while ( ( testPad = static_cast<AliMUONPad*>(next())))
217 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
219 AddPad(cluster,testPad);
224 //_____________________________________________________________________________
226 AliMUONPreClusterFinderV3::NextCluster()
228 /// Returns the next cluster
230 return static_cast<AliMUONCluster*>(fIterator->Next());
233 //_____________________________________________________________________________
235 AliMUONPreClusterFinderV3::MakeClusters()
237 /// Associate (proto)preclusters to form (pre)clusters
239 // AliCodeTimerAuto("",0)
241 for ( Int_t cathode = 0; cathode < 2; ++cathode )
243 TClonesArray& preclusters = *(fPreClusters[cathode]);
245 TIter next(&preclusters);
246 AliMUONCluster* preCluster(0x0);
248 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
250 Int_t id(fClusters->GetLast()+1);
251 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
252 cluster->SetUniqueID(id);
253 AddPreCluster(*cluster,preCluster);
258 //_____________________________________________________________________________
260 AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
262 /// Build (proto)preclusters from digits on a given cathode
264 // AliCodeTimerAuto(Form("Cathode %d",cathode),0)
266 while ( fPads[cathode]->GetLast() > 0 )
268 TIter next(fPads[cathode]);
269 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
271 if (!pad) AliFatal("");
273 Int_t id = fPreClusters[cathode]->GetLast()+1;
274 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
275 cluster->SetUniqueID(id);
277 // Builds (recursively) a cluster on first cathode only
278 AddPad(*cluster,pad);
280 if ( cluster->Multiplicity() <= 1 )
282 if ( cluster->Multiplicity() == 0 )
284 // no pad is suspicious
285 AliWarning("Got an empty cluster...");
287 // else only 1 pad (not suspicious, but kind of useless, probably noise)
288 // so we remove it from our list
289 fPreClusters[cathode]->Remove(cluster);
290 // then proceed further