]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliSignal.cxx
Bug correction: PID Cut did not have the default ctor
[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.
fdadc78a 85// If needed, the storage for values (and errors) will be expanded automatically
86// when entering values and/or errors.
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();
fdadc78a 117 Double_t sig;
dafe31a2 118 for (Int_t i=1; i<=nvalues; i++)
8e8e6c7f 119 {
120 sig=s.GetSignal(i);
8e8e6c7f 121 SetSignal(sig,i);
fdadc78a 122 }
123
124 Int_t nerrors=s.GetNerrors();
125 Double_t err;
126 for (Int_t j=1; j<=nerrors; j++)
127 {
128 err=s.GetSignalError(j);
129 SetSignalError(err,j);
8e8e6c7f 130 }
131}
132///////////////////////////////////////////////////////////////////////////
fdadc78a 133void AliSignal::Reset(Int_t mode)
d88f97cc 134{
959fbac5 135// Reset all signal and position values and errors to 0.
fdadc78a 136//
137// mode = 0 Reset position and all signal values and their errors to 0.
138// 1 Reset position and delete the signal and error storage arrays.
139//
140// The default when invoking Reset() corresponds to mode=0.
141//
142// The usage of mode=0 allows to re-use the allocated memory for new
143// signal (and error) values. This behaviour is preferable (i.e. faster)
144// in case the various signals always contain the same number of values.
145// The usage of mode=1 is slower, but allows a more efficient memory
146// occupation (and smaller output file size) in case the different
147// signals have a variable number of values.
148//
149// For more specific actions see ResetPosition(), ResetSignals()
150// and DeleteSignals().
959fbac5 151
fdadc78a 152 if (mode<0 || mode>1)
959fbac5 153 {
fdadc78a 154 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
155 cout << " Default mode=0 will be used." << endl;
156 mode=0;
157 }
158
159 ResetPosition();
160 if (!mode)
161 {
162 ResetSignals();
163 }
164 else
165 {
166 DeleteSignals();
959fbac5 167 }
168}
169///////////////////////////////////////////////////////////////////////////
fdadc78a 170void AliSignal::ResetSignals(Int_t mode)
959fbac5 171{
fdadc78a 172// Reset various signal data according to user selection.
173//
174// mode = 0 Reset all signal values and their errors to 0.
175// 1 Reset only signal values
176// 2 Reset only signal errors
177//
178// The default when invoking ResetSignals() corresponds to mode=0.
959fbac5 179
fdadc78a 180 if (mode<0 || mode>2)
181 {
182 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
183 cout << " Default mode=0 will be used." << endl;
184 mode=0;
185 }
186
187 if (fSignal && (mode==0 || mode==1))
959fbac5 188 {
dafe31a2 189 for (Int_t i=0; i<fSignal->GetSize(); i++)
190 {
191 fSignal->AddAt(0,i);
fdadc78a 192 }
193 }
194
195 if (fDsignal && (mode==0 || mode==2))
196 {
197 for (Int_t j=0; j<fDsignal->GetSize(); j++)
198 {
199 fDsignal->AddAt(0,j);
dafe31a2 200 }
959fbac5 201 }
d88f97cc 202}
203///////////////////////////////////////////////////////////////////////////
fdadc78a 204void AliSignal::DeleteSignals(Int_t mode)
205{
206// Delete storage arrays of various signal data according to user selection.
207//
208// mode = 0 Delete arrays of both signal values and their errors.
209// 1 Delete only signal values array
210// 2 Delete only signal errors array
211//
212// The default when invoking DeleteSignals() corresponds to mode=0.
213
214 if (mode<0 || mode>2)
215 {
216 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
217 cout << " Default mode=0 will be used." << endl;
218 mode=0;
219 }
220
221 if (fSignal && (mode==0 || mode==1))
222 {
223 delete fSignal;
224 fSignal=0;
225 }
226
227 if (fDsignal && (mode==0 || mode==2))
228 {
229 delete fDsignal;
230 fDsignal=0;
231 }
232}
233///////////////////////////////////////////////////////////////////////////
959fbac5 234void AliSignal::ResetPosition()
d88f97cc 235{
dafe31a2 236// Reset the position and corresponding errors to 0.
959fbac5 237 Double_t r[3]={0,0,0};
238 SetPosition(r,"sph");
239 SetErrors(r,"car");
d88f97cc 240}
241///////////////////////////////////////////////////////////////////////////
959fbac5 242void AliSignal::SetSignal(Double_t sig,Int_t j)
d88f97cc 243{
959fbac5 244// Store j-th (default j=1) signal value.
245// Note : The first signal value is at j=1.
dafe31a2 246// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 247// slots for signal values, the number of reserved slots for the
248// signal values is increased automatically.
959fbac5 249
fdadc78a 250 if (!fSignal)
959fbac5 251 {
dafe31a2 252 fSignal=new TArrayF(j);
fdadc78a 253 ResetSignals(1);
959fbac5 254 }
dafe31a2 255
256 Int_t size=fSignal->GetSize();
257
258 if (j>size)
959fbac5 259 {
dafe31a2 260 fSignal->Set(j);
959fbac5 261 }
dafe31a2 262
263 fSignal->AddAt(float(sig),j-1);
d88f97cc 264}
265///////////////////////////////////////////////////////////////////////////
959fbac5 266void AliSignal::AddSignal(Double_t sig,Int_t j)
267{
268// Add value to j-th (default j=1) signal value.
269// Note : The first signal value is at j=1.
dafe31a2 270// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 271// slots for signal values, the number of reserved slots for the
272// signal values is increased automatically.
959fbac5 273
fdadc78a 274 if (!fSignal)
959fbac5 275 {
dafe31a2 276 fSignal=new TArrayF(j);
fdadc78a 277 ResetSignals(1);
959fbac5 278 }
dafe31a2 279
280 Int_t size=fSignal->GetSize();
281
282 if (j>size)
959fbac5 283 {
dafe31a2 284 fSignal->Set(j);
959fbac5 285 }
dafe31a2 286
287 Float_t sum=(fSignal->At(j-1))+sig;
288 fSignal->AddAt(sum,j-1);
959fbac5 289}
290///////////////////////////////////////////////////////////////////////////
291Float_t AliSignal::GetSignal(Int_t j)
292{
293// Provide j-th (default j=1) signal value.
294// Note : The first signal value is at j=1.
fdadc78a 295// In case no signal is present or the argument j is invalid, 0 is returned.
296 Float_t sig=0;
959fbac5 297 if (fSignal)
298 {
fdadc78a 299 if (j>0 && j<=(fSignal->GetSize()))
300 {
301 sig=fSignal->At(j-1);
302 }
303 else
304 {
305 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
306 }
959fbac5 307 }
fdadc78a 308 return sig;
959fbac5 309}
310///////////////////////////////////////////////////////////////////////////
311void AliSignal::SetSignalError(Double_t dsig,Int_t j)
312{
313// Store error on j-th (default j=1) signal value.
314// Note : The error on the first signal value is at j=1.
dafe31a2 315// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 316// slots for signal error values, the number of reserved slots for the
317// signal errors is increased automatically.
959fbac5 318
fdadc78a 319 if (!fDsignal)
959fbac5 320 {
dafe31a2 321 fDsignal=new TArrayF(j);
fdadc78a 322 ResetSignals(2);
959fbac5 323 }
dafe31a2 324
325 Int_t size=fDsignal->GetSize();
326
327 if (j>size)
959fbac5 328 {
dafe31a2 329 fDsignal->Set(j);
959fbac5 330 }
dafe31a2 331
332 fDsignal->AddAt(float(dsig),j-1);
959fbac5 333}
334///////////////////////////////////////////////////////////////////////////
335Float_t AliSignal::GetSignalError(Int_t j)
336{
337// Provide error on the j-th (default j=1) signal value.
338// Note : The error on the first signal value is at j=1.
fdadc78a 339// In case no signal is present or the argument j is invalid, 0 is returned.
340 Float_t err=0;
959fbac5 341 if (fDsignal)
342 {
fdadc78a 343 if (j>0 && j<=(fDsignal->GetSize()))
344 {
345 err=fDsignal->At(j-1);
346 }
347 else
348 {
349 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
350 }
959fbac5 351 }
fdadc78a 352 return err;
959fbac5 353}
354///////////////////////////////////////////////////////////////////////////
84bb7c66 355void AliSignal::Data(TString f)
959fbac5 356{
357// Provide signal information within the coordinate frame f
fdadc78a 358 cout << " *AliSignal::Data* Signal of kind : " << fName << endl;
959fbac5 359 cout << " Position";
fdadc78a 360 Ali3Vector::Data(f);
361
362 Int_t nvalues=GetNvalues();
363 Int_t nerrors=GetNerrors();
364
365 if (fSignal)
959fbac5 366 {
fdadc78a 367 for (Int_t i=0; i<nvalues; i++)
959fbac5 368 {
fdadc78a 369 cout << " Signal value : " << fSignal->At(i);
370 if (fDsignal && i<nerrors) cout << " error : " << fDsignal->At(i);
371 cout << endl;
959fbac5 372 }
373 }
374}
375///////////////////////////////////////////////////////////////////////////
7a5c405b 376void AliSignal::SetName(TString name)
377{
b31dbd22 378// Set the name tag to indicate the kind of signal.
7a5c405b 379 fName=name;
380}
381///////////////////////////////////////////////////////////////////////////
382TString AliSignal::GetName()
383{
b31dbd22 384// Provide the name tag indicating the kind of signal.
7a5c405b 385 return fName;
386}
387///////////////////////////////////////////////////////////////////////////
8e8e6c7f 388Int_t AliSignal::GetNvalues()
389{
390// Provide the number of values for this signal.
dafe31a2 391 Int_t n=0;
fdadc78a 392 if (fSignal) n=fSignal->GetSize();
393 return n;
394}
395///////////////////////////////////////////////////////////////////////////
396Int_t AliSignal::GetNerrors()
397{
398// Provide the number specified errors on the values for this signal.
399 Int_t n=0;
400 if (fDsignal) n=fDsignal->GetSize();
dafe31a2 401 return n;
8e8e6c7f 402}
403///////////////////////////////////////////////////////////////////////////