]> git.uio.no Git - u/mrichter/AliRoot.git/blame - RALICE/AliSignal.cxx
08-mar-2003 NvE Compiler option /GR introduced for MSVC++ in mklibs.bat to explicitly...
[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//
c72198f1 54// AliSignal q; // In the example below a signal contains the
959fbac5 55// // following data : timing, ADC and dE/dx
7a5c405b 56// q.SetName("TOF hit");
959fbac5 57// q.SetPosition(pos,"car");
58// q.SetPositionErrors(err,"car");
7a5c405b 59// signal=82.5; // e.g. signal time in ns
959fbac5 60// error=2.01;
61// q.SetSignal(signal,1);
62// q.SetSignalError(error,1);
63// signal=268.1; // e.g. ADC value of signal
64// error=3.75;
65// q.SetSignal(signal,2);
66// q.SetSignalError(error,2);
67// signal=23.7; // e.g. corresponding dE/dx value
68// error=0.48;
69// q.SetSignal(signal,3);
70// q.SetSignalError(error,3);
71//
72//--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
f531a546 73//- Modified: NvE $Date$ UU-SAP Utrecht
959fbac5 74///////////////////////////////////////////////////////////////////////////
75
d88f97cc 76#include "AliSignal.h"
c72198f1 77#include "Riostream.h"
d88f97cc 78
79ClassImp(AliSignal) // Class implementation to enable ROOT I/O
80
c72198f1 81AliSignal::AliSignal() : TObject(),AliPosition()
d88f97cc 82{
959fbac5 83// Creation of an AliSignal object and initialisation of parameters.
c72198f1 84// Several 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";
c72198f1 90 fHwaveform=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 }
c72198f1 106 if (fHwaveform)
107 {
108 delete fHwaveform;
109 fHwaveform=0;
110 }
d88f97cc 111}
112///////////////////////////////////////////////////////////////////////////
c72198f1 113AliSignal::AliSignal(AliSignal& s) : TObject(s),AliPosition(s)
8e8e6c7f 114{
115// Copy constructor
8e8e6c7f 116 fSignal=0;
117 fDsignal=0;
c72198f1 118 fName=s.fName;
119 fHwaveform=0;
8e8e6c7f 120
dafe31a2 121 Int_t nvalues=s.GetNvalues();
fdadc78a 122 Double_t sig;
dafe31a2 123 for (Int_t i=1; i<=nvalues; i++)
8e8e6c7f 124 {
125 sig=s.GetSignal(i);
8e8e6c7f 126 SetSignal(sig,i);
fdadc78a 127 }
128
129 Int_t nerrors=s.GetNerrors();
130 Double_t err;
131 for (Int_t j=1; j<=nerrors; j++)
132 {
133 err=s.GetSignalError(j);
134 SetSignalError(err,j);
c72198f1 135 }
136
137 TH1F* hist=s.GetWaveform();
138 if (hist) fHwaveform=new TH1F(*hist);
8e8e6c7f 139}
140///////////////////////////////////////////////////////////////////////////
fdadc78a 141void AliSignal::Reset(Int_t mode)
d88f97cc 142{
959fbac5 143// Reset all signal and position values and errors to 0.
fdadc78a 144//
145// mode = 0 Reset position and all signal values and their errors to 0.
c72198f1 146// The waveform histogram is reset.
fdadc78a 147// 1 Reset position and delete the signal and error storage arrays.
c72198f1 148// The waveform histogram is deleted.
fdadc78a 149//
150// The default when invoking Reset() corresponds to mode=0.
151//
152// The usage of mode=0 allows to re-use the allocated memory for new
153// signal (and error) values. This behaviour is preferable (i.e. faster)
154// in case the various signals always contain the same number of values.
155// The usage of mode=1 is slower, but allows a more efficient memory
156// occupation (and smaller output file size) in case the different
157// signals have a variable number of values.
158//
159// For more specific actions see ResetPosition(), ResetSignals()
160// and DeleteSignals().
c72198f1 161//
959fbac5 162
fdadc78a 163 if (mode<0 || mode>1)
959fbac5 164 {
fdadc78a 165 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
166 cout << " Default mode=0 will be used." << endl;
167 mode=0;
168 }
169
170 ResetPosition();
171 if (!mode)
172 {
173 ResetSignals();
174 }
175 else
176 {
177 DeleteSignals();
959fbac5 178 }
179}
180///////////////////////////////////////////////////////////////////////////
fdadc78a 181void AliSignal::ResetSignals(Int_t mode)
959fbac5 182{
fdadc78a 183// Reset various signal data according to user selection.
184//
185// mode = 0 Reset all signal values and their errors to 0.
186// 1 Reset only signal values
187// 2 Reset only signal errors
188//
189// The default when invoking ResetSignals() corresponds to mode=0.
c72198f1 190//
191// Irrespective of the mode, the waveform histogram is reset.
959fbac5 192
fdadc78a 193 if (mode<0 || mode>2)
194 {
195 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
196 cout << " Default mode=0 will be used." << endl;
197 mode=0;
198 }
199
200 if (fSignal && (mode==0 || mode==1))
959fbac5 201 {
dafe31a2 202 for (Int_t i=0; i<fSignal->GetSize(); i++)
203 {
204 fSignal->AddAt(0,i);
fdadc78a 205 }
206 }
207
208 if (fDsignal && (mode==0 || mode==2))
209 {
210 for (Int_t j=0; j<fDsignal->GetSize(); j++)
211 {
212 fDsignal->AddAt(0,j);
dafe31a2 213 }
959fbac5 214 }
c72198f1 215
216 if (fHwaveform) fHwaveform->Reset();
d88f97cc 217}
218///////////////////////////////////////////////////////////////////////////
fdadc78a 219void AliSignal::DeleteSignals(Int_t mode)
220{
221// Delete storage arrays of various signal data according to user selection.
222//
223// mode = 0 Delete arrays of both signal values and their errors.
224// 1 Delete only signal values array
225// 2 Delete only signal errors array
226//
227// The default when invoking DeleteSignals() corresponds to mode=0.
c72198f1 228//
229// Irrespective of the mode, the waveform histogram is deleted.
fdadc78a 230
231 if (mode<0 || mode>2)
232 {
233 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
234 cout << " Default mode=0 will be used." << endl;
235 mode=0;
236 }
237
238 if (fSignal && (mode==0 || mode==1))
239 {
240 delete fSignal;
241 fSignal=0;
242 }
243
244 if (fDsignal && (mode==0 || mode==2))
245 {
246 delete fDsignal;
247 fDsignal=0;
248 }
c72198f1 249
250 if (fHwaveform)
251 {
252 delete fHwaveform;
253 fHwaveform=0;
254 }
fdadc78a 255}
256///////////////////////////////////////////////////////////////////////////
959fbac5 257void AliSignal::ResetPosition()
d88f97cc 258{
dafe31a2 259// Reset the position and corresponding errors to 0.
959fbac5 260 Double_t r[3]={0,0,0};
261 SetPosition(r,"sph");
262 SetErrors(r,"car");
d88f97cc 263}
264///////////////////////////////////////////////////////////////////////////
959fbac5 265void AliSignal::SetSignal(Double_t sig,Int_t j)
d88f97cc 266{
959fbac5 267// Store j-th (default j=1) signal value.
268// Note : The first signal value is at j=1.
dafe31a2 269// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 270// slots for signal values, the number of reserved slots for the
271// signal values is increased automatically.
959fbac5 272
fdadc78a 273 if (!fSignal)
959fbac5 274 {
dafe31a2 275 fSignal=new TArrayF(j);
fdadc78a 276 ResetSignals(1);
959fbac5 277 }
dafe31a2 278
279 Int_t size=fSignal->GetSize();
280
281 if (j>size)
959fbac5 282 {
dafe31a2 283 fSignal->Set(j);
959fbac5 284 }
dafe31a2 285
286 fSignal->AddAt(float(sig),j-1);
d88f97cc 287}
288///////////////////////////////////////////////////////////////////////////
959fbac5 289void AliSignal::AddSignal(Double_t sig,Int_t j)
290{
291// Add value to j-th (default j=1) signal value.
292// Note : The first signal value is at j=1.
dafe31a2 293// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 294// slots for signal values, the number of reserved slots for the
295// signal values is increased automatically.
959fbac5 296
fdadc78a 297 if (!fSignal)
959fbac5 298 {
dafe31a2 299 fSignal=new TArrayF(j);
fdadc78a 300 ResetSignals(1);
959fbac5 301 }
dafe31a2 302
303 Int_t size=fSignal->GetSize();
304
305 if (j>size)
959fbac5 306 {
dafe31a2 307 fSignal->Set(j);
959fbac5 308 }
dafe31a2 309
310 Float_t sum=(fSignal->At(j-1))+sig;
311 fSignal->AddAt(sum,j-1);
959fbac5 312}
313///////////////////////////////////////////////////////////////////////////
314Float_t AliSignal::GetSignal(Int_t j)
315{
316// Provide j-th (default j=1) signal value.
317// Note : The first signal value is at j=1.
fdadc78a 318// In case no signal is present or the argument j is invalid, 0 is returned.
319 Float_t sig=0;
959fbac5 320 if (fSignal)
321 {
fdadc78a 322 if (j>0 && j<=(fSignal->GetSize()))
323 {
324 sig=fSignal->At(j-1);
325 }
326 else
327 {
328 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
329 }
959fbac5 330 }
fdadc78a 331 return sig;
959fbac5 332}
333///////////////////////////////////////////////////////////////////////////
334void AliSignal::SetSignalError(Double_t dsig,Int_t j)
335{
336// Store error on j-th (default j=1) signal value.
337// Note : The error on the first signal value is at j=1.
dafe31a2 338// In case the value of the index j exceeds the maximum number of reserved
fdadc78a 339// slots for signal error values, the number of reserved slots for the
340// signal errors is increased automatically.
959fbac5 341
fdadc78a 342 if (!fDsignal)
959fbac5 343 {
dafe31a2 344 fDsignal=new TArrayF(j);
fdadc78a 345 ResetSignals(2);
959fbac5 346 }
dafe31a2 347
348 Int_t size=fDsignal->GetSize();
349
350 if (j>size)
959fbac5 351 {
dafe31a2 352 fDsignal->Set(j);
959fbac5 353 }
dafe31a2 354
355 fDsignal->AddAt(float(dsig),j-1);
959fbac5 356}
357///////////////////////////////////////////////////////////////////////////
358Float_t AliSignal::GetSignalError(Int_t j)
359{
360// Provide error on the j-th (default j=1) signal value.
361// Note : The error on the first signal value is at j=1.
fdadc78a 362// In case no signal is present or the argument j is invalid, 0 is returned.
363 Float_t err=0;
959fbac5 364 if (fDsignal)
365 {
fdadc78a 366 if (j>0 && j<=(fDsignal->GetSize()))
367 {
368 err=fDsignal->At(j-1);
369 }
370 else
371 {
372 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
373 }
959fbac5 374 }
fdadc78a 375 return err;
959fbac5 376}
377///////////////////////////////////////////////////////////////////////////
84bb7c66 378void AliSignal::Data(TString f)
959fbac5 379{
380// Provide signal information within the coordinate frame f
c72198f1 381 cout << " *AliSignal::Data* Signal of kind : " << fName.Data() << endl;
959fbac5 382 cout << " Position";
fdadc78a 383 Ali3Vector::Data(f);
384
385 Int_t nvalues=GetNvalues();
386 Int_t nerrors=GetNerrors();
387
388 if (fSignal)
959fbac5 389 {
fdadc78a 390 for (Int_t i=0; i<nvalues; i++)
959fbac5 391 {
fdadc78a 392 cout << " Signal value : " << fSignal->At(i);
393 if (fDsignal && i<nerrors) cout << " error : " << fDsignal->At(i);
394 cout << endl;
959fbac5 395 }
396 }
397}
398///////////////////////////////////////////////////////////////////////////
7a5c405b 399void AliSignal::SetName(TString name)
400{
b31dbd22 401// Set the name tag to indicate the kind of signal.
7a5c405b 402 fName=name;
403}
404///////////////////////////////////////////////////////////////////////////
405TString AliSignal::GetName()
406{
b31dbd22 407// Provide the name tag indicating the kind of signal.
7a5c405b 408 return fName;
409}
410///////////////////////////////////////////////////////////////////////////
8e8e6c7f 411Int_t AliSignal::GetNvalues()
412{
413// Provide the number of values for this signal.
dafe31a2 414 Int_t n=0;
fdadc78a 415 if (fSignal) n=fSignal->GetSize();
416 return n;
417}
418///////////////////////////////////////////////////////////////////////////
419Int_t AliSignal::GetNerrors()
420{
421// Provide the number specified errors on the values for this signal.
422 Int_t n=0;
423 if (fDsignal) n=fDsignal->GetSize();
dafe31a2 424 return n;
8e8e6c7f 425}
426///////////////////////////////////////////////////////////////////////////
c72198f1 427TH1F* AliSignal::GetWaveform()
428{
429// Provide pointer to the 1D waveform histogram.
430 return fHwaveform;
431}
432///////////////////////////////////////////////////////////////////////////
433void AliSignal::SetWaveform(TH1F* waveform)
434{
435// Set the 1D waveform histogram.
436//
437// In case the input argument has the same value as the current waveform
438// histogram pointer value, no action is taken since the user has already
439// modified the actual histogram.
440//
441// In case the input argument is zero, the current waveform histogram
442// is deleted and the pointer set to zero.
443//
444// In all other cases the current waveform histogram is deleted and a new
445// copy of the input histogram is created which becomes the current waveform
446// histogram.
447
448 if (waveform != fHwaveform)
449 {
450 if (fHwaveform)
451 {
452 delete fHwaveform;
453 fHwaveform=0;
454 }
455 if (waveform) fHwaveform=new TH1F(*waveform);
456 }
457}
458///////////////////////////////////////////////////////////////////////////
459AliSignal* AliSignal::MakeCopy(AliSignal& s)
460{
461// Make a deep copy of the input object and provide the pointer to the copy.
462// This memberfunction enables automatic creation of new objects of the
463// correct type depending on the argument type, a feature which may be very useful
464// for containers when adding objects in case the container owns the objects.
465// This feature allows e.g. AliTrack to store either AliSignal objects or
466// objects derived from AliSignal via the AddSignal memberfunction, provided
467// these derived classes also have a proper MakeCopy memberfunction.
468
469 AliSignal* sig=new AliSignal(s);
470 return sig;
471}
472///////////////////////////////////////////////////////////////////////////