]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MUON/AliMUONClusterFinderCOG.cxx
Initial version (Laurent)
[u/mrichter/AliRoot.git] / MUON / AliMUONClusterFinderCOG.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 "AliMUONClusterFinderCOG.h"
19
20 #include "AliLog.h"
21 #include "AliMUONCluster.h"
22 #include "AliMUONVDigit.h"
23 #include "AliMUONPad.h"
24 #include "AliMpArea.h"
25 #include "TVector2.h"
26 #include "AliMUONVDigitStore.h"
27
28 //-----------------------------------------------------------------------------
29 /// \class AliMUONClusterFinderCOG
30 ///
31 /// A very basic (and mostly useless, probably) cluster finder.
32 /// 
33 /// We use AliMUONPreClusterFinder to actually build the cluster,
34 /// and then we simply use center-of-gravity to get the coordinates
35 /// of the cluster.
36 /// Only point to note is that we compute separately both
37 /// cathodes when doing, in order to take the positions from the 
38 /// direction with the better resolution.
39 ///
40 /// \author Laurent Aphecetche
41 //-----------------------------------------------------------------------------
42
43 /// \cond CLASSIMP
44 ClassImp(AliMUONClusterFinderCOG)
45 /// \endcond
46
47 //_____________________________________________________________________________
48 AliMUONClusterFinderCOG::AliMUONClusterFinderCOG(AliMUONVClusterFinder* clusterFinder)
49 : AliMUONVClusterFinder(),
50 fPreClusterFinder(clusterFinder)
51 {
52   /// ctor
53 }
54
55 //_____________________________________________________________________________
56 AliMUONClusterFinderCOG::~AliMUONClusterFinderCOG()
57 {
58   /// dtor
59   delete fPreClusterFinder;
60 }
61
62 //_____________________________________________________________________________
63 Bool_t 
64 AliMUONClusterFinderCOG::Prepare(const AliMpVSegmentation* segmentations[2],
65                                  const AliMUONVDigitStore& digitStore)
66 {
67   /// Prepare for clustering
68   
69   // Find out the DetElemId
70   Int_t detElemId(-1);
71   
72   TIter next(digitStore.CreateIterator());
73   AliMUONVDigit* d;
74
75   d = static_cast<AliMUONVDigit*>(next());
76
77   if (d)
78   {
79     detElemId = d->DetElemId();
80   }
81   
82   if ( detElemId < 0 )
83   {
84     AliWarning("Could not find DE. Probably no digits at all ?");
85     return kFALSE;
86   }
87   
88   return fPreClusterFinder->Prepare(segmentations,digitStore);
89 }
90
91 //_____________________________________________________________________________
92 AliMUONCluster* 
93 AliMUONClusterFinderCOG::NextCluster()
94 {
95   /// Get next cluster
96   
97   if ( !fPreClusterFinder ) return 0x0;
98   AliMUONCluster* cluster = fPreClusterFinder->NextCluster();
99   if ( cluster )
100   {
101     ComputePosition(*cluster);
102
103     if ( cluster->Charge() < 7 )
104     {
105       // skip that one
106       return NextCluster();
107     }    
108   }
109   return cluster;
110 }
111
112 //_____________________________________________________________________________
113 void 
114 AliMUONClusterFinderCOG::ComputePosition(AliMUONCluster& cluster)
115 {
116   /// Compute a first estimate of cluster position by a basic center-of-gravity
117   
118   Double_t xmin = 1E9;
119   Double_t ymin = 1E9;
120   Double_t xmax = -1E9;
121   Double_t ymax = -1E9;
122   
123   Double_t x[] = { 0.0, 0.0 };
124   Double_t y[] = { 0.0, 0.0 };
125   
126   Double_t xsize[] = { 0.0, 0.0 } ;
127   Double_t ysize[] = { 0.0, 0.0 } ;
128   
129   for ( Int_t cathode = 0; cathode < 2; ++cathode )
130   {
131     for ( Int_t i = 0; i < cluster.Multiplicity(); ++i )
132     {
133       AliMUONPad* pad = cluster.Pad(i);
134       TVector2 padPosition = pad->Position();
135       AliMpArea area(pad->Position(),pad->Dimensions());
136       xmin = TMath::Min(area.LeftBorder(),xmin);
137       xmax = TMath::Max(area.RightBorder(),xmax);
138       ymin = TMath::Min(area.DownBorder(),ymin);
139       ymax = TMath::Max(area.UpBorder(),ymax);
140       if ( cathode == pad->Cathode() )
141       {
142         x[cathode] += padPosition.X()*pad->Charge();
143         y[cathode] += padPosition.Y()*pad->Charge();
144         xsize[cathode] += pad->Dimensions().X();
145         ysize[cathode] += pad->Dimensions().Y();
146       }
147     }
148     if ( cluster.Charge(cathode) )
149     {
150       x[cathode] /= cluster.Charge(cathode);
151       y[cathode] /= cluster.Charge(cathode);
152     }
153     if ( cluster.Multiplicity(cathode) )
154     {
155       xsize[cathode] /= cluster.Multiplicity(cathode);
156       ysize[cathode] /= cluster.Multiplicity(cathode);
157     }
158   }
159   
160   Double_t xCOG = 0;
161   Double_t yCOG = 0;
162
163   // take the positions from the direction with the better resolution
164   xCOG = ( xsize[0] < xsize[1] ) ? x[0] : x[1];
165   yCOG = ( ysize[0] < ysize[1] ) ? y[0] : y[1];
166   
167   AliDebug(1,Form("Cluster mult %d (x,y)=(%e,%e) boundaries=(xmin,ymin,xmax,ymax)=(%e,%e,%e,%e)"
168                   " (x0,y0,x1,y1)=(%e,%e,%e,%e) ",
169                   cluster.Multiplicity(),xCOG,yCOG,xmin,ymin,xmax,ymax,
170                   x[0],y[0],x[1],y[1]));
171   
172   cluster.SetPosition(TVector2(xCOG,yCOG),cluster.Pad(0)->Dimensions()); // FIXME: what to put as an error here ?
173 }
174
175
176