New version of RALICE introduced
[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
16/*
17$Log$
959fbac5 18Revision 1.2 1999/09/29 09:24:28 fca
19Introduction of the Copyright and cvs Log
20
4c039060 21*/
22
959fbac5 23///////////////////////////////////////////////////////////////////////////
24// Class AliSignal
25// Handling of ALICE (extrapolated) signals.
26//
27// Note :
28// ------
29// Signal positions (r) and reference frames (f) are specified via
30// SetPosition(r,f) under the following conventions :
31//
32// f="car" ==> r is Cartesian (x,y,z)
33// f="sph" ==> r is Spherical (r,theta,phi)
34// f="cyl" ==> r is Cylindrical (rho,phi,z)
35//
36// The same holds for SetPositionErrors().
37//
38// All angles are in radians.
39//
40// Example :
41// ---------
42//
43// AliSignal s;
44// Float_t pos[3]={-1,25,7};
45// Float_t err[3]={0.03,0.7,0.18};
46// Float_t signal=120.8;
47// Float_t error=1.73;
48// s.SetPosition(pos,"car");
49// s.SetPositionErrors(err,"car");
50// s.SetSignal(signal);
51// s.SetSignalError(error);
52// Float_t loc[3],dr[3],sigma;
53// s.GetPosition(loc,"sph");
54// s.GetPositionErrors(dr,"sph");
55// Float_t adc=s.GetSignal();
56// Float_t sigma=s.GetSignalError();
57//
58// AliSignal q(3); // q can store 3 signal values with their errors
59// // In the example below a signal contains the
60// // following data : timing, ADC and dE/dx
61// q.SetPosition(pos,"car");
62// q.SetPositionErrors(err,"car");
63// signal=82.5; // e.q. signal time in ns
64// error=2.01;
65// q.SetSignal(signal,1);
66// q.SetSignalError(error,1);
67// signal=268.1; // e.g. ADC value of signal
68// error=3.75;
69// q.SetSignal(signal,2);
70// q.SetSignalError(error,2);
71// signal=23.7; // e.g. corresponding dE/dx value
72// error=0.48;
73// q.SetSignal(signal,3);
74// q.SetSignalError(error,3);
75//
76//--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
77//- Modified: NvE 30-oct-1999 UU-SAP Utrecht
78///////////////////////////////////////////////////////////////////////////
79
d88f97cc 80#include "AliSignal.h"
81
82ClassImp(AliSignal) // Class implementation to enable ROOT I/O
83
959fbac5 84AliSignal::AliSignal(Int_t n)
d88f97cc 85{
959fbac5 86// Creation of an AliSignal object and initialisation of parameters.
87// A total of n (default n=1) values (with errors) can be stored.
88 fNvalues=n;
89 fSignal=0;
90 fDsignal=0;
d88f97cc 91}
92///////////////////////////////////////////////////////////////////////////
93AliSignal::~AliSignal()
94{
95// Destructor to delete dynamically allocated memory
959fbac5 96 if (fSignal)
97 {
98 delete fSignal;
99 fSignal=0;
100 }
101 if (fDsignal)
102 {
103 delete fDsignal;
104 fDsignal=0;
105 }
d88f97cc 106}
107///////////////////////////////////////////////////////////////////////////
108void AliSignal::Reset()
109{
959fbac5 110// Reset all signal and position values and errors to 0.
111// The data arrays are also created if not already existing.
112
113 if (!fSignal) fSignal=new TArrayF(fNvalues);
114 if (!fDsignal) fDsignal=new TArrayF(fNvalues);
115
116 Double_t r[3]={0,0,0};
d88f97cc 117 SetPosition(r,"sph");
959fbac5 118 SetErrors(r,"car");
119 for (Int_t i=0; i<fSignal->GetSize(); i++)
120 {
121 fSignal->AddAt(0,i);
122 fDsignal->AddAt(0,i);
123 }
124}
125///////////////////////////////////////////////////////////////////////////
126void AliSignal::ResetSignals()
127{
128// Reset all signal 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 for (Int_t i=0; i<fSignal->GetSize(); i++)
135 {
136 fSignal->AddAt(0,i);
137 fDsignal->AddAt(0,i);
138 }
d88f97cc 139}
140///////////////////////////////////////////////////////////////////////////
959fbac5 141void AliSignal::ResetPosition()
d88f97cc 142{
959fbac5 143// Reset position and errors to 0.
144 Double_t r[3]={0,0,0};
145 SetPosition(r,"sph");
146 SetErrors(r,"car");
d88f97cc 147}
148///////////////////////////////////////////////////////////////////////////
959fbac5 149void AliSignal::SetSignal(Double_t sig,Int_t j)
d88f97cc 150{
959fbac5 151// Store j-th (default j=1) signal value.
152// Note : The first signal value is at j=1.
153
154 if (!fSignal) ResetSignals();
155
156 Int_t size=fSignal->GetSize();
157 if (j<=size)
158 {
159 fSignal->AddAt(float(sig),j-1);
160 }
161 else
162 {
163 cout << "*AliSignal::SetSignal* Index mismatch j : " << j
164 << " size : " << size << endl;
165 }
d88f97cc 166}
167///////////////////////////////////////////////////////////////////////////
959fbac5 168void AliSignal::AddSignal(Double_t sig,Int_t j)
169{
170// Add value to j-th (default j=1) signal value.
171// Note : The first signal value is at j=1.
172
173 if (!fSignal) ResetSignals();
174
175 Int_t size=fSignal->GetSize();
176 if (j<=size)
177 {
178 Float_t sum=(fSignal->At(j-1))+sig;
179 fSignal->AddAt(sum,j-1);
180 }
181 else
182 {
183 cout << "*AliSignal::AddSignal* Index mismatch j : " << j
184 << " size : " << size << endl;
185 }
186}
187///////////////////////////////////////////////////////////////////////////
188Float_t AliSignal::GetSignal(Int_t j)
189{
190// Provide j-th (default j=1) signal value.
191// Note : The first signal value is at j=1.
192 if (fSignal)
193 {
194 return fSignal->At(j-1);
195 }
196 else
197 {
198 return 0;
199 }
200}
201///////////////////////////////////////////////////////////////////////////
202void AliSignal::SetSignalError(Double_t dsig,Int_t j)
203{
204// Store error on j-th (default j=1) signal value.
205// Note : The error on the first signal value is at j=1.
206
207 if (!fDsignal) ResetSignals();
208
209 Int_t size=fDsignal->GetSize();
210 if (j<=size)
211 {
212 fDsignal->AddAt(float(dsig),j-1);
213 }
214 else
215 {
216 cout << "*AliSignal::SetSignalError* Index mismatch j : " << j
217 << " size : " << size << endl;
218 }
219}
220///////////////////////////////////////////////////////////////////////////
221Float_t AliSignal::GetSignalError(Int_t j)
222{
223// Provide error on the j-th (default j=1) signal value.
224// Note : The error on the first signal value is at j=1.
225 if (fDsignal)
226 {
227 return fDsignal->At(j-1);
228 }
229 else
230 {
231 return 0;
232 }
233}
234///////////////////////////////////////////////////////////////////////////
235void AliSignal::Info(TString f)
236{
237// Provide signal information within the coordinate frame f
238 cout << " *AliSignal::Info* " << endl;
239 cout << " Position";
240 Ali3Vector::Info(f);
241
242 if (fSignal && fDsignal)
243 {
244 for (Int_t i=0; i<fSignal->GetSize(); i++)
245 {
246 cout << " Signal value : " << fSignal->At(i)
247 << " error : " << fDsignal->At(i) << endl;
248 }
249 }
250}
251///////////////////////////////////////////////////////////////////////////