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