25-apr-2002 NvE Projectile and target specifications introduced in AliEvent.
[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
20// Handling of ALICE (extrapolated) signals.
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//
54// AliSignal q(3); // q can store 3 signal values with their errors
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.
84// A total of n (default n=1) values (with errors) can be stored.
85 fNvalues=n;
86 fSignal=0;
87 fDsignal=0;
7a5c405b 88 fName=" ";
d88f97cc 89}
90///////////////////////////////////////////////////////////////////////////
91AliSignal::~AliSignal()
92{
93// Destructor to delete dynamically allocated memory
959fbac5 94 if (fSignal)
95 {
96 delete fSignal;
97 fSignal=0;
98 }
99 if (fDsignal)
100 {
101 delete fDsignal;
102 fDsignal=0;
103 }
d88f97cc 104}
105///////////////////////////////////////////////////////////////////////////
8e8e6c7f 106AliSignal::AliSignal(AliSignal& s)
107{
108// Copy constructor
109 fNvalues=s.GetNvalues();
110 fSignal=0;
111 fDsignal=0;
112 fName=s.GetName();
113
114 SetPosition((Ali3Vector&)s);
115
116 Double_t sig,err;
117 for (Int_t i=1; i<=fNvalues; i++)
118 {
119 sig=s.GetSignal(i);
120 err=s.GetSignalError(i);
121 SetSignal(sig,i);
122 SetSignalError(err,i);
123 }
124}
125///////////////////////////////////////////////////////////////////////////
d88f97cc 126void AliSignal::Reset()
127{
959fbac5 128// Reset all signal and position values and errors to 0.
129// The data arrays are also created if not already existing.
130
131 if (!fSignal) fSignal=new TArrayF(fNvalues);
132 if (!fDsignal) fDsignal=new TArrayF(fNvalues);
133
134 Double_t r[3]={0,0,0};
d88f97cc 135 SetPosition(r,"sph");
959fbac5 136 SetErrors(r,"car");
137 for (Int_t i=0; i<fSignal->GetSize(); i++)
138 {
139 fSignal->AddAt(0,i);
140 fDsignal->AddAt(0,i);
141 }
142}
143///////////////////////////////////////////////////////////////////////////
144void AliSignal::ResetSignals()
145{
146// Reset all signal values and errors to 0.
147// The data arrays are also created if not already existing.
148
149 if (!fSignal) fSignal=new TArrayF(fNvalues);
150 if (!fDsignal) fDsignal=new TArrayF(fNvalues);
151
152 for (Int_t i=0; i<fSignal->GetSize(); i++)
153 {
154 fSignal->AddAt(0,i);
155 fDsignal->AddAt(0,i);
156 }
d88f97cc 157}
158///////////////////////////////////////////////////////////////////////////
959fbac5 159void AliSignal::ResetPosition()
d88f97cc 160{
959fbac5 161// Reset position and errors to 0.
162 Double_t r[3]={0,0,0};
163 SetPosition(r,"sph");
164 SetErrors(r,"car");
d88f97cc 165}
166///////////////////////////////////////////////////////////////////////////
959fbac5 167void AliSignal::SetSignal(Double_t sig,Int_t j)
d88f97cc 168{
959fbac5 169// Store j-th (default j=1) signal value.
170// Note : The first signal value is at j=1.
171
172 if (!fSignal) ResetSignals();
173
174 Int_t size=fSignal->GetSize();
175 if (j<=size)
176 {
177 fSignal->AddAt(float(sig),j-1);
178 }
179 else
180 {
181 cout << "*AliSignal::SetSignal* Index mismatch j : " << j
182 << " size : " << size << endl;
183 }
d88f97cc 184}
185///////////////////////////////////////////////////////////////////////////
959fbac5 186void AliSignal::AddSignal(Double_t sig,Int_t j)
187{
188// Add value to j-th (default j=1) signal value.
189// Note : The first signal value is at j=1.
190
191 if (!fSignal) ResetSignals();
192
193 Int_t size=fSignal->GetSize();
194 if (j<=size)
195 {
196 Float_t sum=(fSignal->At(j-1))+sig;
197 fSignal->AddAt(sum,j-1);
198 }
199 else
200 {
201 cout << "*AliSignal::AddSignal* Index mismatch j : " << j
202 << " size : " << size << endl;
203 }
204}
205///////////////////////////////////////////////////////////////////////////
206Float_t AliSignal::GetSignal(Int_t j)
207{
208// Provide j-th (default j=1) signal value.
209// Note : The first signal value is at j=1.
210 if (fSignal)
211 {
212 return fSignal->At(j-1);
213 }
214 else
215 {
216 return 0;
217 }
218}
219///////////////////////////////////////////////////////////////////////////
220void AliSignal::SetSignalError(Double_t dsig,Int_t j)
221{
222// Store error on j-th (default j=1) signal value.
223// Note : The error on the first signal value is at j=1.
224
225 if (!fDsignal) ResetSignals();
226
227 Int_t size=fDsignal->GetSize();
228 if (j<=size)
229 {
230 fDsignal->AddAt(float(dsig),j-1);
231 }
232 else
233 {
234 cout << "*AliSignal::SetSignalError* Index mismatch j : " << j
235 << " size : " << size << endl;
236 }
237}
238///////////////////////////////////////////////////////////////////////////
239Float_t AliSignal::GetSignalError(Int_t j)
240{
241// Provide error on the j-th (default j=1) signal value.
242// Note : The error on the first signal value is at j=1.
243 if (fDsignal)
244 {
245 return fDsignal->At(j-1);
246 }
247 else
248 {
249 return 0;
250 }
251}
252///////////////////////////////////////////////////////////////////////////
253void AliSignal::Info(TString f)
254{
255// Provide signal information within the coordinate frame f
7a5c405b 256 cout << " *AliSignal::Info* For signal of kind : " << fName << endl;
959fbac5 257 cout << " Position";
258 Ali3Vector::Info(f);
259
260 if (fSignal && fDsignal)
261 {
262 for (Int_t i=0; i<fSignal->GetSize(); i++)
263 {
264 cout << " Signal value : " << fSignal->At(i)
265 << " error : " << fDsignal->At(i) << endl;
266 }
267 }
268}
269///////////////////////////////////////////////////////////////////////////
7a5c405b 270void AliSignal::SetName(TString name)
271{
b31dbd22 272// Set the name tag to indicate the kind of signal.
7a5c405b 273 fName=name;
274}
275///////////////////////////////////////////////////////////////////////////
276TString AliSignal::GetName()
277{
b31dbd22 278// Provide the name tag indicating the kind of signal.
7a5c405b 279 return fName;
280}
281///////////////////////////////////////////////////////////////////////////
8e8e6c7f 282Int_t AliSignal::GetNvalues()
283{
284// Provide the number of values for this signal.
285 return fNvalues;
286}
287///////////////////////////////////////////////////////////////////////////