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();
194 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
196 AliError(Form("Could not remove %s from preclusters[%d]",
197 preCluster->AsString().Data(),cathode));
198 StdoutToAliDebug(1,DumpPreClusters());
202 cluster.AddCluster(a);
204 // loop on the *other* cathode
205 TIter next(fPreClusters[1-cathode]);
206 AliMUONCluster* testCluster;
208 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
210 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
212 AddPreCluster(cluster,testCluster);
218 //_____________________________________________________________________________
220 AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
222 /// Add a pad to a cluster
223 AliMUONPad* addedPad = cluster.AddPad(*pad);
225 Int_t cathode = pad->Cathode();
226 TClonesArray& padArray = *fPads[cathode];
227 padArray.Remove(pad);
228 TIter next(&padArray);
231 while ( ( testPad = static_cast<AliMUONPad*>(next())))
233 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
235 AddPad(cluster,testPad);
240 //_____________________________________________________________________________
242 AliMUONPreClusterFinderV3::NextCluster()
244 /// Returns the next cluster
246 return static_cast<AliMUONCluster*>(fIterator->Next());
249 //_____________________________________________________________________________
251 AliMUONPreClusterFinderV3::MakeClusters()
253 /// Associate (proto)preclusters to form (pre)clusters
255 // AliCodeTimerAuto("")
257 for ( Int_t cathode = 0; cathode < 2; ++cathode )
259 TClonesArray& preclusters = *(fPreClusters[cathode]);
261 TIter next(&preclusters);
262 AliMUONCluster* preCluster(0x0);
264 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
266 Int_t id(fClusters->GetLast()+1);
267 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
268 cluster->SetUniqueID(id);
269 AddPreCluster(*cluster,preCluster);
274 //_____________________________________________________________________________
276 AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
278 /// Build (proto)preclusters from digits on a given cathode
280 // AliCodeTimerAuto(Form("Cathode %d",cathode))
282 while ( fPads[cathode]->GetLast() > 0 )
284 TIter next(fPads[cathode]);
285 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
287 if (!pad) AliFatal("");
289 Int_t id = fPreClusters[cathode]->GetLast()+1;
290 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
291 cluster->SetUniqueID(id);
293 // Builds (recursively) a cluster on first cathode only
294 AddPad(*cluster,pad);
296 if ( cluster->Multiplicity() <= 1 )
298 if ( cluster->Multiplicity() == 0 )
300 // no pad is suspicious
301 AliWarning("Got an empty cluster...");
303 // else only 1 pad (not suspicious, but kind of useless, probably noise)
304 // so we remove it from our list
305 fPreClusters[cathode]->Remove(cluster);
306 // then proceed further