29-jun-2001 NvE TrackCopy mode introduced in AliJet.
[u/mrichter/AliRoot.git] / RALICE / AliCalcluster.cxx
CommitLineData
4c039060 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
f531a546 16// $Id$
4c039060 17
959fbac5 18///////////////////////////////////////////////////////////////////////////
19// Class AliCalcluster
20// Description of a cluster of calorimeter modules.
21// A matrix geometry is assumed in which a cluster center
22// is identified by (row,col) and contains sig as signal
23// being the signal of the complete cluster.
24// Some info about cluster topology is provided in order
25// to enable EM or hadronic cluster identification.
26//
27//--- Author: Nick van Eijndhoven 13-jun-1997 UU-SAP Utrecht
f531a546 28//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 29///////////////////////////////////////////////////////////////////////////
30
d88f97cc 31#include "AliCalcluster.h"
32
33ClassImp(AliCalcluster) // Class implementation to enable ROOT I/O
34
35AliCalcluster::AliCalcluster()
36{
37// Default constructer, all data is set to 0
38 fCenter=0;
39 fSig=0.;
40 fNmods=0;
41 fSig11=0.;
42 fSig33=0.;
43 fSig55=0.;
44 fRowdisp=0.;
45 fColdisp=0.;
46 fNvetos=0;
47 fVetos=0;
48}
49///////////////////////////////////////////////////////////////////////////
50AliCalcluster::~AliCalcluster()
51{
52// Destructor to delete dynamically allocated memory
53 if (fVetos)
54 {
55 fVetos->Delete();
56 delete fVetos;
57 fVetos=0;
58 }
59}
60///////////////////////////////////////////////////////////////////////////
61AliCalcluster::AliCalcluster(AliCalmodule& m)
62{
63// Cluster constructor with module m as center.
f40f8fbd 64// Module data is only entered for a module which contains a signal,
65// has not been used in a cluster yet, and is not declared dead.
66//
67// Note :
68// It is advised NOT to start a cluster with modules situated at a detector edge.
69// This feature is automatically checked when using the built-in clustering
70// of AliCalorimeter.
d88f97cc 71
f40f8fbd 72 Ali3Vector r;
d88f97cc 73
f40f8fbd 74 if (m.GetClusteredSignal()>0. && m.GetDeadValue()==0)
d88f97cc 75 {
76 fCenter=&m;
f40f8fbd 77 r=m.GetPosition();
78 SetPosition(r);
d88f97cc 79 fSig=m.GetClusteredSignal();
80 fNmods=1;
81 fSig11=m.GetClusteredSignal();
82 fSig33=m.GetClusteredSignal();
83 fSig55=m.GetClusteredSignal();
84 fRowdisp=0.;
85 fColdisp=0.;
86 m.SetClusteredSignal(0.); // mark module as used in cluster
87 fNvetos=0;
88 fVetos=0;
89 }
90 else
91 {
92 fCenter=0;
f40f8fbd 93 SetPosition(r);
d88f97cc 94 fSig=0.;
95 fNmods=0;
96 fSig11=0.;
97 fSig33=0.;
98 fSig55=0.;
99 fRowdisp=0.;
100 fColdisp=0.;
101 fNvetos=0;
102 fVetos=0;
103}
104}
105///////////////////////////////////////////////////////////////////////////
106Int_t AliCalcluster::GetRow()
107{
108// Provide the row number of the cluster center
109 if (fCenter)
110 {
111 return fCenter->GetRow();
112 }
113 else
114 {
115 return 0;
116 }
117}
118///////////////////////////////////////////////////////////////////////////
119Int_t AliCalcluster::GetColumn()
120{
121// Provide the column number of the cluster center
122 if (fCenter)
123 {
124 return fCenter->GetColumn();
125 }
126 else
127 {
128 return 0;
129 }
130}
131///////////////////////////////////////////////////////////////////////////
132Float_t AliCalcluster::GetSignal(Int_t n)
133{
134// Provide the total signal of a module matrix of n modules around
135// the cluster center.
136// Example : n=9 --> total signal in the 3x3 matrix
137// 1 --> signal of central module
138// Note : n=0 provides the total cluster signal (Default)
139
140 Float_t signal=-1;
141
142 if (n == 0) signal=fSig;
143 if (n == 1) signal=fSig11;
144 if (n == 9) signal=fSig33;
145 if (n == 25) signal=fSig55;
146
147 if (signal > 0.)
148 {
149 return signal;
150 }
151 else
152 {
153 cout << " *AliCalcluster::GetSignal* Invalid argument n = " << n << endl;
154 return 0;
155 }
156}
157///////////////////////////////////////////////////////////////////////////
158Int_t AliCalcluster::GetNmodules()
159{
160// Provide the number of modules in the cluster
161 return fNmods;
162}
163///////////////////////////////////////////////////////////////////////////
164Float_t AliCalcluster::GetRowDispersion()
165{
166// Provide the normalised row dispersion of the cluster
167 if (fSig > 0.)
168 {
169 return fRowdisp/fSig;
170 }
171 else
172 {
173 return 0.;
174 }
175}
176///////////////////////////////////////////////////////////////////////////
177Float_t AliCalcluster::GetColumnDispersion()
178{
179// Provide the normalised column dispersion of the cluster
180 if (fSig > 0.)
181 {
182 return fColdisp/fSig;
183 }
184 else
185 {
186 return 0.;
187 }
188}
189///////////////////////////////////////////////////////////////////////////
190void AliCalcluster::Start(AliCalmodule& m)
191{
959fbac5 192// Reset cluster data and start with module m.
f40f8fbd 193// A module can only start a cluster when it contains a signal,
194// has not been used in a cluster yet, and is not declared dead.
195//
196// Note :
197// It is advised NOT to start a cluster with modules situated at a detector edge.
198// This feature is automatically checked when using the built-in clustering
199// of AliCalorimeter.
d88f97cc 200
f40f8fbd 201 Ali3Vector r;
d88f97cc 202
f40f8fbd 203 if (m.GetClusteredSignal()>0. && m.GetDeadValue()==0)
d88f97cc 204 {
205 fCenter=&m;
f40f8fbd 206 r=m.GetPosition();
207 SetPosition(r);
d88f97cc 208 fSig=m.GetSignal();
209 fNmods=1;
210 fSig11=m.GetSignal();
211 fSig33=m.GetSignal();
212 fSig55=m.GetSignal();
213 fRowdisp=0.;
214 fColdisp=0.;
215 m.SetClusteredSignal(0.); // mark module as used in cluster
216 }
217 else
218 {
219 fCenter=0;
f40f8fbd 220 SetPosition(r);
d88f97cc 221 fSig=0.;
222 fNmods=0;
223 fSig11=0.;
224 fSig33=0.;
225 fSig55=0.;
226 fRowdisp=0.;
227 fColdisp=0.;
228 }
229}
230///////////////////////////////////////////////////////////////////////////
231void AliCalcluster::Add(AliCalmodule& m)
232{
f40f8fbd 233// Add module data to the cluster.
234// Dead modules are NOT added to the cluster.
d88f97cc 235
236 Float_t signal=m.GetClusteredSignal();
237
f40f8fbd 238 if (signal>0. && m.GetDeadValue()==0) // only add unused modules
d88f97cc 239 {
240 fSig+=signal;
241 fNmods+=1;
242 Int_t drow=int(fabs(double(GetRow()-m.GetRow()))); // row distance to center
243 Int_t dcol=int(fabs(double(GetColumn()-m.GetColumn()))); // column distance to center
244 if ((drow < 2) && (dcol < 2)) fSig33+=signal;
245 if ((drow < 3) && (dcol < 3)) fSig55+=signal;
246 fRowdisp+=signal*float(drow*drow);
247 fColdisp+=signal*float(dcol*dcol);
248 m.SetClusteredSignal(0.); // mark module as used in cluster
249 }
250}
251///////////////////////////////////////////////////////////////////////////
252void AliCalcluster::AddVetoSignal(Float_t* r,TString f,Float_t s)
253{
959fbac5 254// Associate an (extrapolated) AliSignal at location r as veto to the cluster.
255// The signal value s indicates the confidence level of hit association
256// and has to be provided by the user.
d88f97cc 257// Note : The default signal value (s) is 0
258 if (!fVetos)
259 {
260 fNvetos=0;
261 fVetos=new TObjArray();
262 }
263
959fbac5 264 fVetos->Add(new AliSignal(1));
d88f97cc 265 fNvetos++;
266
267 ((AliSignal*)fVetos->At(fNvetos-1))->SetPosition(r,f);
268 ((AliSignal*)fVetos->At(fNvetos-1))->SetSignal(s);
269}
270///////////////////////////////////////////////////////////////////////////
271Int_t AliCalcluster::GetNvetos()
272{
273// Provide the number of veto signals associated to the cluster
274 return fNvetos;
275}
276///////////////////////////////////////////////////////////////////////////
277AliSignal* AliCalcluster::GetVetoSignal(Int_t i)
278{
959fbac5 279// Provide access to the i-th veto signal of this cluster.
280// Note : The first hit corresponds to i=1.
d88f97cc 281
282 if (i>0 && i<=fNvetos)
283 {
284 return (AliSignal*)fVetos->At(i-1);
285 }
286 else
287 {
288 cout << " *AliCalcluster::GetVetoSignal* Signal number " << i
289 << " out of range." << endl;
290 cout << " --- First signal (if any) returned." << endl;
291 return (AliSignal*)fVetos->At(0);
292 }
293}
294///////////////////////////////////////////////////////////////////////////
959fbac5 295Float_t AliCalcluster::GetVetoLevel()
296{
297// Provide the confidence level of best associated veto signal.
298 Float_t cl=0;
299 Float_t clmax=0;
300 if (fVetos)
301 {
302 for (Int_t i=0; i<fNvetos; i++)
303 {
304 cl=((AliSignal*)fVetos->At(i))->GetSignal();
305 if (cl>clmax) clmax=cl;
306 }
307 }
308 return clmax;
309}
310///////////////////////////////////////////////////////////////////////////
311Int_t AliCalcluster::HasVetoHit(Double_t cl)
312{
313// Investigate if cluster has an associated veto hit with conf. level > cl.
314// Returns 1 if there is such an associated veto hit, otherwise returns 0.
315// Note : This function is faster than GetVetoLevel().
316 if (fVetos)
317 {
318 for (Int_t i=0; i<fNvetos; i++)
319 {
320 if (((AliSignal*)fVetos->At(i))->GetSignal() > cl) return 1;
321 }
322 }
323 return 0;
324}
325///////////////////////////////////////////////////////////////////////////