]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliSignal.cxx
removed unused variables warnings
[u/mrichter/AliRoot.git] / RALICE / AliSignal.cxx
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 // $Id$
17
18 ///////////////////////////////////////////////////////////////////////////
19 // Class AliSignal
20 // Generic handling of (extrapolated) detector 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 // 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();
53 //
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
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
74 //- Modified: NvE $Date$ UU-SAP Utrecht
75 ///////////////////////////////////////////////////////////////////////////
76
77 #include "AliSignal.h"
78  
79 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
80  
81 AliSignal::AliSignal(Int_t n)
82 {
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.
87  fSignal=0;
88  fDsignal=0;
89  fName="Unspecified";
90 }
91 ///////////////////////////////////////////////////////////////////////////
92 AliSignal::~AliSignal()
93 {
94 // Destructor to delete dynamically allocated memory
95  if (fSignal)
96  {
97   delete fSignal;
98   fSignal=0;
99  }
100  if (fDsignal)
101  {
102   delete fDsignal;
103   fDsignal=0;
104  }
105 }
106 ///////////////////////////////////////////////////////////////////////////
107 AliSignal::AliSignal(AliSignal& s)
108 {
109 // Copy constructor
110  fSignal=0;
111  fDsignal=0;
112  fName=s.GetName();
113  
114  SetPosition((Ali3Vector&)s);
115
116  Int_t nvalues=s.GetNvalues();
117  Double_t sig;
118  for (Int_t i=1; i<=nvalues; i++)
119  {
120   sig=s.GetSignal(i);
121   SetSignal(sig,i);
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);
130  } 
131 }
132 ///////////////////////////////////////////////////////////////////////////
133 void AliSignal::Reset(Int_t mode)
134 {
135 // Reset all signal and position values and errors to 0.
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().
151
152  if (mode<0 || mode>1)
153  {
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();
167  }
168 }
169 ///////////////////////////////////////////////////////////////////////////
170 void AliSignal::ResetSignals(Int_t mode)
171 {
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.
179
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))
188  {
189   for (Int_t i=0; i<fSignal->GetSize(); i++)
190   {
191    fSignal->AddAt(0,i);
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);
200   }
201  }
202 }
203 ///////////////////////////////////////////////////////////////////////////
204 void 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 ///////////////////////////////////////////////////////////////////////////
234 void AliSignal::ResetPosition()
235 {
236 // Reset the position and corresponding errors to 0.
237  Double_t r[3]={0,0,0};
238  SetPosition(r,"sph");
239  SetErrors(r,"car");
240 }
241 ///////////////////////////////////////////////////////////////////////////
242 void AliSignal::SetSignal(Double_t sig,Int_t j)
243 {
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.
249
250  if (!fSignal)
251  {
252   fSignal=new TArrayF(j);
253   ResetSignals(1);
254  }
255
256  Int_t size=fSignal->GetSize();
257
258  if (j>size)
259  {
260   fSignal->Set(j);
261  }
262
263  fSignal->AddAt(float(sig),j-1);
264 }
265 ///////////////////////////////////////////////////////////////////////////
266 void 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.
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.
273
274  if (!fSignal)
275  {
276   fSignal=new TArrayF(j);
277   ResetSignals(1);
278  }
279
280  Int_t size=fSignal->GetSize();
281
282  if (j>size)
283  {
284   fSignal->Set(j);
285  }
286
287  Float_t sum=(fSignal->At(j-1))+sig;
288  fSignal->AddAt(sum,j-1);
289 }
290 ///////////////////////////////////////////////////////////////////////////
291 Float_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.
295 // In case no signal is present or the argument j is invalid, 0 is returned.
296  Float_t sig=0;
297  if (fSignal)
298  {
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   } 
307  }
308  return sig;
309 }
310 ///////////////////////////////////////////////////////////////////////////
311 void 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.
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.
318
319  if (!fDsignal)
320  {
321   fDsignal=new TArrayF(j);
322   ResetSignals(2);
323  }
324
325  Int_t size=fDsignal->GetSize();
326
327  if (j>size)
328  {
329   fDsignal->Set(j);
330  }
331
332  fDsignal->AddAt(float(dsig),j-1);
333 }
334 ///////////////////////////////////////////////////////////////////////////
335 Float_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.
339 // In case no signal is present or the argument j is invalid, 0 is returned.
340  Float_t err=0;
341  if (fDsignal)
342  {
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   } 
351  }
352  return err;
353 }
354 ///////////////////////////////////////////////////////////////////////////
355 void AliSignal::Data(TString f)
356 {
357 // Provide signal information within the coordinate frame f
358  cout << " *AliSignal::Data* Signal of kind : " << fName << endl;
359  cout << " Position";
360  Ali3Vector::Data(f);
361
362  Int_t nvalues=GetNvalues();
363  Int_t nerrors=GetNerrors();
364
365  if (fSignal)
366  {
367   for (Int_t i=0; i<nvalues; i++)
368   {
369    cout << "   Signal value : " << fSignal->At(i);
370    if (fDsignal && i<nerrors) cout << " error : " << fDsignal->At(i);
371    cout << endl;
372   }
373  }
374
375 ///////////////////////////////////////////////////////////////////////////
376 void AliSignal::SetName(TString name)
377 {
378 // Set the name tag to indicate the kind of signal.
379  fName=name;
380 }
381 ///////////////////////////////////////////////////////////////////////////
382 TString AliSignal::GetName()
383 {
384 // Provide the name tag indicating the kind of signal.
385  return fName;
386 }
387 ///////////////////////////////////////////////////////////////////////////
388 Int_t AliSignal::GetNvalues()
389 {
390 // Provide the number of values for this signal.
391  Int_t n=0;
392  if (fSignal) n=fSignal->GetSize();
393  return n;
394 }
395 ///////////////////////////////////////////////////////////////////////////
396 Int_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();
401  return n;
402 }
403 ///////////////////////////////////////////////////////////////////////////