]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliSignal.cxx
08-feb-2003 NvE Class AliSignal modified such that the maximum number of signal slots is
[u/mrichter/AliRoot.git] / RALICE / AliSignal.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 AliSignal
dafe31a2 20// Generic handling of (extrapolated) detector signals.
959fbac5 21//
22// Note :
23// ------
24// Signal positions (r) and reference frames (f) are specified via
25// SetPosition(r,f) under the following conventions :
26//
27// f="car" ==> r is Cartesian (x,y,z)
28// f="sph" ==> r is Spherical (r,theta,phi)
29// f="cyl" ==> r is Cylindrical (rho,phi,z)
30//
31// The same holds for SetPositionErrors().
32//
33// All angles are in radians.
34//
35// Example :
36// ---------
37//
38// AliSignal s;
7a5c405b 39// s.SetName("Start counter");
959fbac5 40// Float_t pos[3]={-1,25,7};
41// Float_t err[3]={0.03,0.7,0.18};
42// Float_t signal=120.8;
43// Float_t error=1.73;
44// s.SetPosition(pos,"car");
45// s.SetPositionErrors(err,"car");
46// s.SetSignal(signal);
47// s.SetSignalError(error);
48// Float_t loc[3],dr[3],sigma;
49// s.GetPosition(loc,"sph");
50// s.GetPositionErrors(dr,"sph");
51// Float_t adc=s.GetSignal();
52// Float_t sigma=s.GetSignalError();
53//
dafe31a2 54// AliSignal q(3); // q can store initially 3 signal values with their errors
959fbac5 55// // In the example below a signal contains the
56// // following data : timing, ADC and dE/dx
7a5c405b 57// q.SetName("TOF hit");
959fbac5 58// q.SetPosition(pos,"car");
59// q.SetPositionErrors(err,"car");
7a5c405b 60// signal=82.5; // e.g. signal time in ns
959fbac5 61// error=2.01;
62// q.SetSignal(signal,1);
63// q.SetSignalError(error,1);
64// signal=268.1; // e.g. ADC value of signal
65// error=3.75;
66// q.SetSignal(signal,2);
67// q.SetSignalError(error,2);
68// signal=23.7; // e.g. corresponding dE/dx value
69// error=0.48;
70// q.SetSignal(signal,3);
71// q.SetSignalError(error,3);
72//
73//--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
f531a546 74//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 75///////////////////////////////////////////////////////////////////////////
76
d88f97cc 77#include "AliSignal.h"
78
79ClassImp(AliSignal) // Class implementation to enable ROOT I/O
80
959fbac5 81AliSignal::AliSignal(Int_t n)
d88f97cc 82{
959fbac5 83// Creation of an AliSignal object and initialisation of parameters.
dafe31a2 84// Initially a total of n (default n=1) values (with errors) can be stored.
85// If needed, the number of values (and errors) will be increased automatically
86// when entering values.
959fbac5 87 fSignal=0;
88 fDsignal=0;
dafe31a2 89 fName="Unspecified";
d88f97cc 90}
91///////////////////////////////////////////////////////////////////////////
92AliSignal::~AliSignal()
93{
94// Destructor to delete dynamically allocated memory
959fbac5 95 if (fSignal)
96 {
97 delete fSignal;
98 fSignal=0;
99 }
100 if (fDsignal)
101 {
102 delete fDsignal;
103 fDsignal=0;
104 }
d88f97cc 105}
106///////////////////////////////////////////////////////////////////////////
8e8e6c7f 107AliSignal::AliSignal(AliSignal& s)
108{
109// Copy constructor
8e8e6c7f 110 fSignal=0;
111 fDsignal=0;
112 fName=s.GetName();
113
114 SetPosition((Ali3Vector&)s);
115
dafe31a2 116 Int_t nvalues=s.GetNvalues();
8e8e6c7f 117 Double_t sig,err;
dafe31a2 118 for (Int_t i=1; i<=nvalues; i++)
8e8e6c7f 119 {
120 sig=s.GetSignal(i);
121 err=s.GetSignalError(i);
122 SetSignal(sig,i);
123 SetSignalError(err,i);
124 }
125}
126///////////////////////////////////////////////////////////////////////////
d88f97cc 127void AliSignal::Reset()
128{
959fbac5 129// Reset all signal and position values and errors to 0.
959fbac5 130
dafe31a2 131 if (fSignal && fDsignal)
959fbac5 132 {
dafe31a2 133 Double_t r[3]={0,0,0};
134 SetPosition(r,"sph");
135 SetErrors(r,"car");
136 for (Int_t i=0; i<fSignal->GetSize(); i++)
137 {
138 fSignal->AddAt(0,i);
139 fDsignal->AddAt(0,i);
140 }
959fbac5 141 }
142}
143///////////////////////////////////////////////////////////////////////////
144void AliSignal::ResetSignals()
145{
dafe31a2 146// Reset all signal values and their errors to 0.
959fbac5 147
dafe31a2 148 if (fSignal && fDsignal)
959fbac5 149 {
dafe31a2 150 for (Int_t i=0; i<fSignal->GetSize(); i++)
151 {
152 fSignal->AddAt(0,i);
153 fDsignal->AddAt(0,i);
154 }
959fbac5 155 }
d88f97cc 156}
157///////////////////////////////////////////////////////////////////////////
959fbac5 158void AliSignal::ResetPosition()
d88f97cc 159{
dafe31a2 160// Reset the position and corresponding errors to 0.
959fbac5 161 Double_t r[3]={0,0,0};
162 SetPosition(r,"sph");
163 SetErrors(r,"car");
d88f97cc 164}
165///////////////////////////////////////////////////////////////////////////
959fbac5 166void AliSignal::SetSignal(Double_t sig,Int_t j)
d88f97cc 167{
959fbac5 168// Store j-th (default j=1) signal value.
169// Note : The first signal value is at j=1.
dafe31a2 170// In case the value of the index j exceeds the maximum number of reserved
171// slots for signal values, the number of reserved slots for both the
172// signal values and errors is increased automatically.
959fbac5 173
dafe31a2 174 if (!fSignal && !fDsignal)
959fbac5 175 {
dafe31a2 176 fSignal=new TArrayF(j);
177 fDsignal=new TArrayF(j);
178 ResetSignals();
959fbac5 179 }
dafe31a2 180
181 Int_t size=fSignal->GetSize();
182
183 if (j>size)
959fbac5 184 {
dafe31a2 185 fSignal->Set(j);
186 fDsignal->Set(j);
959fbac5 187 }
dafe31a2 188
189 fSignal->AddAt(float(sig),j-1);
d88f97cc 190}
191///////////////////////////////////////////////////////////////////////////
959fbac5 192void AliSignal::AddSignal(Double_t sig,Int_t j)
193{
194// Add value to j-th (default j=1) signal value.
195// Note : The first signal value is at j=1.
dafe31a2 196// In case the value of the index j exceeds the maximum number of reserved
197// slots for signal values, the number of reserved slots for both the
198// signal values and errors is increased automatically.
959fbac5 199
dafe31a2 200 if (!fSignal && !fDsignal)
959fbac5 201 {
dafe31a2 202 fSignal=new TArrayF(j);
203 fDsignal=new TArrayF(j);
204 ResetSignals();
959fbac5 205 }
dafe31a2 206
207 Int_t size=fSignal->GetSize();
208
209 if (j>size)
959fbac5 210 {
dafe31a2 211 fSignal->Set(j);
212 fDsignal->Set(j);
959fbac5 213 }
dafe31a2 214
215 Float_t sum=(fSignal->At(j-1))+sig;
216 fSignal->AddAt(sum,j-1);
959fbac5 217}
218///////////////////////////////////////////////////////////////////////////
219Float_t AliSignal::GetSignal(Int_t j)
220{
221// Provide j-th (default j=1) signal value.
222// Note : The first signal value is at j=1.
223 if (fSignal)
224 {
225 return fSignal->At(j-1);
226 }
227 else
228 {
229 return 0;
230 }
231}
232///////////////////////////////////////////////////////////////////////////
233void AliSignal::SetSignalError(Double_t dsig,Int_t j)
234{
235// Store error on j-th (default j=1) signal value.
236// Note : The error on the first signal value is at j=1.
dafe31a2 237// In case the value of the index j exceeds the maximum number of reserved
238// slots for signal error values, the number of reserved slots for both the
239// signal values and errors is increased automatically.
959fbac5 240
dafe31a2 241 if (!fSignal && !fDsignal)
959fbac5 242 {
dafe31a2 243 fSignal=new TArrayF(j);
244 fDsignal=new TArrayF(j);
245 ResetSignals();
959fbac5 246 }
dafe31a2 247
248 Int_t size=fDsignal->GetSize();
249
250 if (j>size)
959fbac5 251 {
dafe31a2 252 fSignal->Set(j);
253 fDsignal->Set(j);
959fbac5 254 }
dafe31a2 255
256 fDsignal->AddAt(float(dsig),j-1);
959fbac5 257}
258///////////////////////////////////////////////////////////////////////////
259Float_t AliSignal::GetSignalError(Int_t j)
260{
261// Provide error on the j-th (default j=1) signal value.
262// Note : The error on the first signal value is at j=1.
263 if (fDsignal)
264 {
265 return fDsignal->At(j-1);
266 }
267 else
268 {
269 return 0;
270 }
271}
272///////////////////////////////////////////////////////////////////////////
84bb7c66 273void AliSignal::Data(TString f)
959fbac5 274{
275// Provide signal information within the coordinate frame f
84bb7c66 276 cout << " *AliSignal::Data* For signal of kind : " << fName << endl;
959fbac5 277 cout << " Position";
84bb7c66 278 Ali3Vector::Data(f);
959fbac5 279
280 if (fSignal && fDsignal)
281 {
282 for (Int_t i=0; i<fSignal->GetSize(); i++)
283 {
284 cout << " Signal value : " << fSignal->At(i)
285 << " error : " << fDsignal->At(i) << endl;
286 }
287 }
288}
289///////////////////////////////////////////////////////////////////////////
7a5c405b 290void AliSignal::SetName(TString name)
291{
b31dbd22 292// Set the name tag to indicate the kind of signal.
7a5c405b 293 fName=name;
294}
295///////////////////////////////////////////////////////////////////////////
296TString AliSignal::GetName()
297{
b31dbd22 298// Provide the name tag indicating the kind of signal.
7a5c405b 299 return fName;
300}
301///////////////////////////////////////////////////////////////////////////
8e8e6c7f 302Int_t AliSignal::GetNvalues()
303{
304// Provide the number of values for this signal.
dafe31a2 305 Int_t n=0;
306 if (fSignal && fDsignal) n=fSignal->GetSize();
307 return n;
8e8e6c7f 308}
309///////////////////////////////////////////////////////////////////////////