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)
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 AliMUONPad(pad);
121 fPads[pad.Cathode()]->Add(p);
125 //_____________________________________________________________________________
127 AliMUONPreClusterFinderV3::Prepare(Int_t detElemId,
129 const AliMpArea& area,
130 const AliMpVSegmentation* seg[2])
132 /// Prepare for clustering, by giving access to segmentations and digit lists
134 if ( area.IsValid() )
136 AliError("Handling of area not yet implemented for this class. Please check.");
139 fkSegmentations = seg;
142 fClusters->Clear("C");
143 for ( Int_t i = 0; i < 2; ++i )
145 fPreClusters[i]->Clear("C");
148 fDetElemId = detElemId;
150 if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
152 // no pad at all, nothing to do...
156 MakeCathodePreClusters(0);
157 MakeCathodePreClusters(1);
161 fIterator = fClusters->MakeIterator();
166 //_____________________________________________________________________________
168 AliMUONPreClusterFinderV3::DumpPreClusters() const
172 TIter next0(fPreClusters[0]);
173 TIter next1(fPreClusters[1]);
174 cout << "Cath0" << endl;
175 while ( ( c = static_cast<AliMUONCluster*>(next0())) )
177 cout << c->AsString().Data() << endl;
179 cout << "Cath1" << endl;
180 while ( ( c = static_cast<AliMUONCluster*>(next1())) )
182 cout << c->AsString().Data() << endl;
186 //_____________________________________________________________________________
188 AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
190 /// Add a pad to a cluster
192 AliMUONCluster a(*preCluster);
194 Int_t cathode = preCluster->Cathode();
196 AliError(Form("Cathod undefined: %d",cathode));
201 if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) )
203 AliError(Form("Could not remove %s from preclusters[%d]",
204 preCluster->AsString().Data(),cathode));
205 StdoutToAliDebug(1,DumpPreClusters());
210 cluster.AddCluster(a);
212 // loop on the *other* cathode
213 TIter next(fPreClusters[1-cathode]);
214 AliMUONCluster* testCluster;
216 while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
218 if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
220 AddPreCluster(cluster,testCluster);
226 //_____________________________________________________________________________
228 AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
230 /// Add a pad to a cluster
231 AliMUONPad* addedPad = cluster.AddPad(*pad);
233 Int_t cathode = pad->Cathode();
234 TObjArray& padArray = *fPads[cathode];
235 padArray.Remove(pad);
236 TIter next(&padArray);
239 while ( ( testPad = static_cast<AliMUONPad*>(next())))
241 if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
243 AddPad(cluster,testPad);
248 //_____________________________________________________________________________
250 AliMUONPreClusterFinderV3::NextCluster()
252 /// Returns the next cluster
254 return static_cast<AliMUONCluster*>(fIterator->Next());
257 //_____________________________________________________________________________
259 AliMUONPreClusterFinderV3::MakeClusters()
261 /// Associate (proto)preclusters to form (pre)clusters
263 // AliCodeTimerAuto("",0)
265 for ( Int_t cathode = 0; cathode < 2; ++cathode )
267 TClonesArray& preclusters = *(fPreClusters[cathode]);
269 TIter next(&preclusters);
270 AliMUONCluster* preCluster(0x0);
272 while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
274 Int_t id(fClusters->GetLast()+1);
275 AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
276 cluster->SetUniqueID(id);
277 AddPreCluster(*cluster,preCluster);
282 //_____________________________________________________________________________
284 AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
286 /// Build (proto)preclusters from digits on a given cathode
288 // AliCodeTimerAuto(Form("Cathode %d",cathode),0)
290 while ( fPads[cathode]->GetLast() > 0 )
292 TIter next(fPads[cathode]);
293 AliMUONPad* pad = static_cast<AliMUONPad*>(next());
295 if (!pad) AliFatal("");
297 Int_t id = fPreClusters[cathode]->GetLast()+1;
298 AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
299 cluster->SetUniqueID(id);
301 // Builds (recursively) a cluster on first cathode only
302 AddPad(*cluster,pad);
304 if ( cluster->Multiplicity() <= 1 )
306 if ( cluster->Multiplicity() == 0 )
308 // no pad is suspicious
309 AliWarning("Got an empty cluster...");
311 // else only 1 pad (not suspicious, but kind of useless, probably noise)
312 // so we remove it from our list
313 fPreClusters[cathode]->Remove(cluster);
314 // then proceed further