]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONPreClusterFinderV3.cxx
In AliMUONPedestal:
[u/mrichter/AliRoot.git] / MUON / AliMUONPreClusterFinderV3.cxx
1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 *                                                                        *
4 * Author: The ALICE Off-line Project.                                    *
5 * Contributors are mentioned in the code where appropriate.              *
6 *                                                                        *
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 **************************************************************************/
15
16 // $Id$
17
18 #include "AliMUONPreClusterFinderV3.h"
19
20 #include "AliLog.h"
21 #include "AliMUONCluster.h"
22 #include "AliMpVSegmentation.h"
23 #include "TObjArray.h"
24 #include "AliMpArea.h"
25 #include "TVector2.h"
26 #include "AliMUONPad.h"
27 #include "AliMUONVDigit.h"
28 #include "AliMUONVDigitStore.h"
29 #include <Riostream.h>
30 //#include "AliCodeTimer.h"
31
32 //-----------------------------------------------------------------------------
33 /// \class AliMUONPreClusterFinderV3
34 ///
35 /// Implementation of AliMUONVClusterFinder
36 ///
37 /// This version uses a 2 steps approach :
38 ///
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.
43 ///
44 /// This implementation, on the contrary to PreClusterFinder or PreClusterFinderV2
45 /// should not depend on the order of the input digits.
46 ///
47 /// \author Laurent Aphecetche
48 //-----------------------------------------------------------------------------
49
50 ClassImp(AliMUONPreClusterFinderV3)
51
52 //_____________________________________________________________________________
53 AliMUONPreClusterFinderV3::AliMUONPreClusterFinderV3()
54 : AliMUONVClusterFinder(),
55   fClusters(new TClonesArray("AliMUONCluster",10)),
56   fkSegmentations(0x0),
57   fPads(0x0),
58   fDetElemId(0),
59   fIterator(0x0)
60 {
61     /// ctor
62   AliInfo("");
63   for ( Int_t i = 0; i < 2; ++i )
64   {
65     fPreClusters[i] = new TClonesArray("AliMUONCluster",10);
66   } 
67 }
68
69 //_____________________________________________________________________________
70 AliMUONPreClusterFinderV3::~AliMUONPreClusterFinderV3()
71 {
72   /// dtor
73   delete fClusters;
74   for ( Int_t i = 0; i < 2; ++i )
75   {
76     delete fPreClusters[i];
77   } 
78 }
79
80 //_____________________________________________________________________________
81 Bool_t
82 AliMUONPreClusterFinderV3::UsePad(const AliMUONPad& pad)
83 {
84   /// Add a pad to the list of pads to be considered
85   if ( pad.DetElemId() != fDetElemId )
86   {
87     AliError(Form("Cannot add pad from DE %d to this cluster finder which is "
88                   "currently dealing with DE %d",pad.DetElemId(),fDetElemId));
89     return kFALSE;
90   }
91   
92   AliMUONPad* p = new AliMUONPad(pad); 
93   p->SetClusterId(-1);
94   fPads[pad.Cathode()]->Add(p); 
95   return kTRUE;
96 }
97
98 //_____________________________________________________________________________
99 Bool_t
100 AliMUONPreClusterFinderV3::Prepare(Int_t detElemId,
101                                    TObjArray* pads[2],
102                                    const AliMpArea& area,
103                                    const AliMpVSegmentation* seg[2])
104 {
105   /// Prepare for clustering, by giving access to segmentations and digit lists
106   
107   if ( area.IsValid() ) 
108   {
109     AliError("Handling of area not yet implemented for this class. Please check.");
110   }
111   
112   fkSegmentations = seg;
113   fPads = pads;
114   
115   fClusters->Clear("C");
116   for ( Int_t i = 0; i < 2; ++i )
117   {
118     fPreClusters[i]->Clear("C");
119   }
120   
121   fDetElemId = detElemId;
122   
123   if ( fPads[0]->GetLast() < 0 && fPads[1]->GetLast() < 0 )
124   {
125     // no pad at all, nothing to do...
126     return kFALSE;
127   }
128   
129   MakeCathodePreClusters(0);  
130   MakeCathodePreClusters(1);  
131   MakeClusters();
132   
133   delete fIterator;
134   fIterator = fClusters->MakeIterator();
135   
136   return kTRUE;
137 }
138
139 //_____________________________________________________________________________
140 void
141 AliMUONPreClusterFinderV3::DumpPreClusters() const
142 {
143   /// Dump preclusters 
144   AliMUONCluster *c;
145   TIter next0(fPreClusters[0]);
146   TIter next1(fPreClusters[1]);
147   cout << "Cath0" << endl;
148   while ( ( c = static_cast<AliMUONCluster*>(next0())) ) 
149   {
150     cout << c->AsString().Data() << endl;
151   }
152   cout << "Cath1" << endl;
153   while ( ( c = static_cast<AliMUONCluster*>(next1())) ) 
154   {
155     cout << c->AsString().Data() << endl;
156   }
157 }
158
159 //_____________________________________________________________________________
160 void
161 AliMUONPreClusterFinderV3::AddPreCluster(AliMUONCluster& cluster, AliMUONCluster* preCluster)
162 {
163   /// Add a pad to a cluster
164
165   AliMUONCluster a(*preCluster);
166
167   Int_t cathode = preCluster->Cathode();
168   if ( cathode < 0 ) {
169     AliError(Form("Cathod undefined: %d",cathode));
170     AliFatal("");
171     return;
172   }
173   
174   if ( cathode <=1 && !fPreClusters[cathode]->Remove(preCluster) ) 
175   {
176     AliError(Form("Could not remove %s from preclusters[%d]",
177                   preCluster->AsString().Data(),cathode));
178     StdoutToAliDebug(1,DumpPreClusters());
179     AliFatal("");
180     return;
181   }
182              
183   cluster.AddCluster(a);
184   
185   // loop on the *other* cathode
186   TIter next(fPreClusters[1-cathode]);
187   AliMUONCluster* testCluster;
188   
189   while ( ( testCluster = static_cast<AliMUONCluster*>(next())))
190   {
191     if ( AliMUONCluster::AreOverlapping(a,*testCluster) )
192     {
193       AddPreCluster(cluster,testCluster);
194     }
195   }
196 }
197
198
199 //_____________________________________________________________________________
200 void
201 AliMUONPreClusterFinderV3::AddPad(AliMUONCluster& cluster, AliMUONPad* pad)
202 {
203   /// Add a pad to a cluster
204   AliMUONPad* addedPad = cluster.AddPad(*pad);
205   
206   Int_t cathode = pad->Cathode();
207   TObjArray& padArray = *fPads[cathode];
208   delete padArray.Remove(pad);
209   
210   TIter next(&padArray);
211   AliMUONPad* testPad;
212   
213   while ( ( testPad = static_cast<AliMUONPad*>(next())))
214   {
215     if ( AliMUONPad::AreNeighbours(*testPad,*addedPad) )
216     {
217       AddPad(cluster,testPad);
218     }
219   }
220 }
221
222 //_____________________________________________________________________________
223 AliMUONCluster* 
224 AliMUONPreClusterFinderV3::NextCluster()
225 {
226   /// Returns the next cluster
227   
228   return static_cast<AliMUONCluster*>(fIterator->Next());
229 }
230
231 //_____________________________________________________________________________
232 void
233 AliMUONPreClusterFinderV3::MakeClusters()
234 {
235   /// Associate (proto)preclusters to form (pre)clusters
236   
237 //  AliCodeTimerAuto("",0)
238   
239   for ( Int_t cathode = 0; cathode < 2; ++cathode ) 
240   {
241     TClonesArray& preclusters = *(fPreClusters[cathode]);
242     
243     TIter next(&preclusters);
244     AliMUONCluster* preCluster(0x0);
245     
246     while ( ( preCluster = static_cast<AliMUONCluster*>(next()) ) )
247     {
248       Int_t id(fClusters->GetLast()+1);
249       AliMUONCluster* cluster = new((*fClusters)[id]) AliMUONCluster;
250       cluster->SetUniqueID(id);      
251       AddPreCluster(*cluster,preCluster);
252     }
253   }
254 }
255
256 //_____________________________________________________________________________
257 void
258 AliMUONPreClusterFinderV3::MakeCathodePreClusters(Int_t cathode)
259 {
260   /// Build (proto)preclusters from digits on a given cathode
261   
262 //  AliCodeTimerAuto(Form("Cathode %d",cathode),0)
263   
264   while ( fPads[cathode]->GetLast() > 0  )
265   {  
266     TIter next(fPads[cathode]);
267     AliMUONPad* pad = static_cast<AliMUONPad*>(next());
268   
269     if (!pad) AliFatal("");
270
271     Int_t id = fPreClusters[cathode]->GetLast()+1;
272     AliMUONCluster* cluster = new ((*fPreClusters[cathode])[id]) AliMUONCluster;
273     cluster->SetUniqueID(id);
274     
275     // Builds (recursively) a cluster on first cathode only
276     AddPad(*cluster,pad);
277     
278     if ( cluster->Multiplicity() <= 1 )
279     {
280       if ( cluster->Multiplicity() == 0 ) 
281       {
282         // no pad is suspicious
283         AliWarning("Got an empty cluster...");
284       }
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
289     }
290   }
291   
292 }