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)),
90 for ( Int_t i = 0; i < 2; ++i )
92 fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
96 //_____________________________________________________________________________
97 AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
101 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(Int_t detElemId,
127 TClonesArray* pads[2],
128 const AliMpArea& area,
129 const AliMpVSegmentation* seg[2])
131 /// Prepare for clustering, by giving access to segmentations and digit lists
133 if ( area.IsValid() )
135 AliError("Handling of area not yet implemented for this class. Please check.");
138 fkSegmentations = seg;
141 fClusters->Clear("C");
142 for ( Int_t i = 0; i < 2; ++i )
144 fPreClusters[i]->Clear("C");
147 fDetElemId = detElemId;
149 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
151 // no pad at all, nothing to do...
155 MakeCathodePreClusters(0);
156 MakeCathodePreClusters(1);
160 fIterator = fClusters->MakeIterator();
165 //_____________________________________________________________________________
167 AliMUONPreClusterFinderV3::DumpPreClusters() const
171 TIter next0(fPreClusters[0]);
172 TIter next1(fPreClusters[1]);
173 cout << "Cath0" << endl;
174 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
176 cout << c->AsString().Data() << endl;
178 cout << "Cath1" << endl;
179 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
181 cout << c->AsString().Data() << endl;
185 //_____________________________________________________________________________
187 AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
189 /// Add a pad to a cluster
191 AliMUONCluster a(*preCluster);
193 Int_t cathode = preCluster->Cathode();
195 AliError(Form("Cathod undefined: %d",cathode));
199 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
201 AliError(Form("Could not remove %s from preclusters[%d]",
202 preCluster->AsString().Data(),cathode));
203 StdoutToAliDebug(1,DumpPreClusters());
207 cluster.AddCluster(a);
209 // loop on the *other* cathode
210 TIter next(fPreClusters[1-cathode]);
211 AliMUONCluster* testCluster;
213 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
215 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
217 AddPreCluster(cluster,testCluster);
223 //_____________________________________________________________________________
225 AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
227 /// Add a pad to a cluster
228 AliMUONPad* addedPad = cluster.AddPad(*pad);
230 Int_t cathode = pad->Cathode();
231 TClonesArray& padArray = *fPads[cathode];
232 padArray.Remove(pad);
233 TIter next(&padArray);
236 while ( ( testPad = static_cast<AliMUONPad*>(next())))
238 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
240 AddPad(cluster,testPad);
245 //_____________________________________________________________________________
247 AliMUONPreClusterFinderV3::NextCluster()
249 /// Returns the next cluster
251 return static_cast<AliMUONCluster*>(fIterator->Next());
254 //_____________________________________________________________________________
256 AliMUONPreClusterFinderV3::MakeClusters()
258 /// Associate (proto)preclusters to form (pre)clusters
260 // AliCodeTimerAuto("",0)
262 for ( Int_t cathode = 0; cathode < 2; ++cathode )
264 TClonesArray& preclusters = *(fPreClusters[cathode]);
266 TIter next(&preclusters);
267 AliMUONCluster* preCluster(0x0);
269 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
271 Int_t id(fClusters->GetLast()+1);
272 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
273 cluster->SetUniqueID(id);
274 AddPreCluster(*cluster,preCluster);
279 //_____________________________________________________________________________
281 AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
283 /// Build (proto)preclusters from digits on a given cathode
285 // AliCodeTimerAuto(Form("Cathode %d",cathode),0)
287 while ( fPads[cathode]->GetLast() > 0 )
289 TIter next(fPads[cathode]);
290 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
292 if (!pad) AliFatal("");
294 Int_t id = fPreClusters[cathode]->GetLast()+1;
295 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
296 cluster->SetUniqueID(id);
298 // Builds (recursively) a cluster on first cathode only
299 AddPad(*cluster,pad);
301 if ( cluster->Multiplicity() <= 1 )
303 if ( cluster->Multiplicity() == 0 )
305 // no pad is suspicious
306 AliWarning("Got an empty cluster...");
308 // else only 1 pad (not suspicious, but kind of useless, probably noise)
309 // so we remove it from our list
310 fPreClusters[cathode]->Remove(cluster);
311 // then proceed further