1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
20 // Generic handling of (extrapolated) detector signals.
24 // Signal positions (r) and reference frames (f) are specified via
25 // SetPosition(r,f) under the following conventions :
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)
31 // The same holds for SetPositionErrors().
33 // All angles are in radians.
39 // s.SetName("Start counter");
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();
54 // AliSignal q(3); // q can store initially 3 signal values with their errors
55 // // In the example below a signal contains the
56 // // following data : timing, ADC and dE/dx
57 // q.SetName("TOF hit");
58 // q.SetPosition(pos,"car");
59 // q.SetPositionErrors(err,"car");
60 // signal=82.5; // e.g. signal time in ns
62 // q.SetSignal(signal,1);
63 // q.SetSignalError(error,1);
64 // signal=268.1; // e.g. ADC value of signal
66 // q.SetSignal(signal,2);
67 // q.SetSignalError(error,2);
68 // signal=23.7; // e.g. corresponding dE/dx value
70 // q.SetSignal(signal,3);
71 // q.SetSignalError(error,3);
73 //--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
74 //- Modified: NvE $Date$ UU-SAP Utrecht
75 ///////////////////////////////////////////////////////////////////////////
77 #include "AliSignal.h"
79 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
81 AliSignal::AliSignal(Int_t n)
83 // Creation of an AliSignal object and initialisation of parameters.
84 // Initially a total of n (default n=1) values (with errors) can be stored.
85 // If needed, the storage for values (and errors) will be expanded automatically
86 // when entering values and/or errors.
91 ///////////////////////////////////////////////////////////////////////////
92 AliSignal::~AliSignal()
94 // Destructor to delete dynamically allocated memory
106 ///////////////////////////////////////////////////////////////////////////
107 AliSignal::AliSignal(AliSignal& s)
114 SetPosition((Ali3Vector&)s);
116 Int_t nvalues=s.GetNvalues();
118 for (Int_t i=1; i<=nvalues; i++)
124 Int_t nerrors=s.GetNerrors();
126 for (Int_t j=1; j<=nerrors; j++)
128 err=s.GetSignalError(j);
129 SetSignalError(err,j);
132 ///////////////////////////////////////////////////////////////////////////
133 void AliSignal::Reset(Int_t mode)
135 // Reset all signal and position values and errors to 0.
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.
140 // The default when invoking Reset() corresponds to mode=0.
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.
149 // For more specific actions see ResetPosition(), ResetSignals()
150 // and DeleteSignals().
152 if (mode<0 || mode>1)
154 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
155 cout << " Default mode=0 will be used." << endl;
169 ///////////////////////////////////////////////////////////////////////////
170 void AliSignal::ResetSignals(Int_t mode)
172 // Reset various signal data according to user selection.
174 // mode = 0 Reset all signal values and their errors to 0.
175 // 1 Reset only signal values
176 // 2 Reset only signal errors
178 // The default when invoking ResetSignals() corresponds to mode=0.
180 if (mode<0 || mode>2)
182 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
183 cout << " Default mode=0 will be used." << endl;
187 if (fSignal && (mode==0 || mode==1))
189 for (Int_t i=0; i<fSignal->GetSize(); i++)
195 if (fDsignal && (mode==0 || mode==2))
197 for (Int_t j=0; j<fDsignal->GetSize(); j++)
199 fDsignal->AddAt(0,j);
203 ///////////////////////////////////////////////////////////////////////////
204 void AliSignal::DeleteSignals(Int_t mode)
206 // Delete storage arrays of various signal data according to user selection.
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
212 // The default when invoking DeleteSignals() corresponds to mode=0.
214 if (mode<0 || mode>2)
216 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
217 cout << " Default mode=0 will be used." << endl;
221 if (fSignal && (mode==0 || mode==1))
227 if (fDsignal && (mode==0 || mode==2))
233 ///////////////////////////////////////////////////////////////////////////
234 void AliSignal::ResetPosition()
236 // Reset the position and corresponding errors to 0.
237 Double_t r[3]={0,0,0};
238 SetPosition(r,"sph");
241 ///////////////////////////////////////////////////////////////////////////
242 void AliSignal::SetSignal(Double_t sig,Int_t j)
244 // Store j-th (default j=1) signal value.
245 // Note : The first signal value is at j=1.
246 // In case the value of the index j exceeds the maximum number of reserved
247 // slots for signal values, the number of reserved slots for the
248 // signal values is increased automatically.
252 fSignal=new TArrayF(j);
256 Int_t size=fSignal->GetSize();
263 fSignal->AddAt(float(sig),j-1);
265 ///////////////////////////////////////////////////////////////////////////
266 void AliSignal::AddSignal(Double_t sig,Int_t j)
268 // Add value to j-th (default j=1) signal value.
269 // Note : The first signal value is at j=1.
270 // In case the value of the index j exceeds the maximum number of reserved
271 // slots for signal values, the number of reserved slots for the
272 // signal values is increased automatically.
276 fSignal=new TArrayF(j);
280 Int_t size=fSignal->GetSize();
287 Float_t sum=(fSignal->At(j-1))+sig;
288 fSignal->AddAt(sum,j-1);
290 ///////////////////////////////////////////////////////////////////////////
291 Float_t AliSignal::GetSignal(Int_t j)
293 // Provide j-th (default j=1) signal value.
294 // Note : The first signal value is at j=1.
295 // In case no signal is present or the argument j is invalid, 0 is returned.
299 if (j>0 && j<=(fSignal->GetSize()))
301 sig=fSignal->At(j-1);
305 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
310 ///////////////////////////////////////////////////////////////////////////
311 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
313 // Store error on j-th (default j=1) signal value.
314 // Note : The error on the first signal value is at j=1.
315 // In case the value of the index j exceeds the maximum number of reserved
316 // slots for signal error values, the number of reserved slots for the
317 // signal errors is increased automatically.
321 fDsignal=new TArrayF(j);
325 Int_t size=fDsignal->GetSize();
332 fDsignal->AddAt(float(dsig),j-1);
334 ///////////////////////////////////////////////////////////////////////////
335 Float_t AliSignal::GetSignalError(Int_t j)
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.
339 // In case no signal is present or the argument j is invalid, 0 is returned.
343 if (j>0 && j<=(fDsignal->GetSize()))
345 err=fDsignal->At(j-1);
349 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
354 ///////////////////////////////////////////////////////////////////////////
355 void AliSignal::Data(TString f)
357 // Provide signal information within the coordinate frame f
358 cout << " *AliSignal::Data* Signal of kind : " << fName << endl;
362 Int_t nvalues=GetNvalues();
363 Int_t nerrors=GetNerrors();
367 for (Int_t i=0; i<nvalues; i++)
369 cout << " Signal value : " << fSignal->At(i);
370 if (fDsignal && i<nerrors) cout << " error : " << fDsignal->At(i);
375 ///////////////////////////////////////////////////////////////////////////
376 void AliSignal::SetName(TString name)
378 // Set the name tag to indicate the kind of signal.
381 ///////////////////////////////////////////////////////////////////////////
382 TString AliSignal::GetName()
384 // Provide the name tag indicating the kind of signal.
387 ///////////////////////////////////////////////////////////////////////////
388 Int_t AliSignal::GetNvalues()
390 // Provide the number of values for this signal.
392 if (fSignal) n=fSignal->GetSize();
395 ///////////////////////////////////////////////////////////////////////////
396 Int_t AliSignal::GetNerrors()
398 // Provide the number specified errors on the values for this signal.
400 if (fDsignal) n=fDsignal->GetSize();
403 ///////////////////////////////////////////////////////////////////////////