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; // In the example below a signal contains the
55 // // following data : timing, ADC and dE/dx
56 // q.SetName("TOF hit");
57 // q.SetPosition(pos,"car");
58 // q.SetPositionErrors(err,"car");
59 // signal=82.5; // e.g. signal time in ns
61 // q.SetSignal(signal,1);
62 // q.SetSignalError(error,1);
63 // signal=268.1; // e.g. ADC value of signal
65 // q.SetSignal(signal,2);
66 // q.SetSignalError(error,2);
67 // signal=23.7; // e.g. corresponding dE/dx value
69 // q.SetSignal(signal,3);
70 // q.SetSignalError(error,3);
72 //--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
73 //- Modified: NvE $Date$ UU-SAP Utrecht
74 ///////////////////////////////////////////////////////////////////////////
76 #include "AliSignal.h"
77 #include "Riostream.h"
79 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
81 AliSignal::AliSignal() : TObject(),AliPosition()
83 // Creation of an AliSignal object and initialisation of parameters.
84 // Several 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.
92 ///////////////////////////////////////////////////////////////////////////
93 AliSignal::~AliSignal()
95 // Destructor to delete dynamically allocated memory
112 ///////////////////////////////////////////////////////////////////////////
113 AliSignal::AliSignal(AliSignal& s) : TObject(s),AliPosition(s)
121 Int_t nvalues=s.GetNvalues();
123 for (Int_t i=1; i<=nvalues; i++)
129 Int_t nerrors=s.GetNerrors();
131 for (Int_t j=1; j<=nerrors; j++)
133 err=s.GetSignalError(j);
134 SetSignalError(err,j);
137 TH1F* hist=s.GetWaveform();
138 if (hist) fHwaveform=new TH1F(*hist);
140 ///////////////////////////////////////////////////////////////////////////
141 void AliSignal::Reset(Int_t mode)
143 // Reset all signal and position values and errors to 0.
145 // mode = 0 Reset position and all signal values and their errors to 0.
146 // The waveform histogram is reset.
147 // 1 Reset position and delete the signal and error storage arrays.
148 // The waveform histogram is deleted.
150 // The default when invoking Reset() corresponds to mode=0.
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.
159 // For more specific actions see ResetPosition(), ResetSignals()
160 // and DeleteSignals().
163 if (mode<0 || mode>1)
165 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
166 cout << " Default mode=0 will be used." << endl;
180 ///////////////////////////////////////////////////////////////////////////
181 void AliSignal::ResetSignals(Int_t mode)
183 // Reset various signal data according to user selection.
185 // mode = 0 Reset all signal values and their errors to 0.
186 // 1 Reset only signal values
187 // 2 Reset only signal errors
189 // The default when invoking ResetSignals() corresponds to mode=0.
191 // Irrespective of the mode, the waveform histogram is reset.
193 if (mode<0 || mode>2)
195 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
196 cout << " Default mode=0 will be used." << endl;
200 if (fSignal && (mode==0 || mode==1))
202 for (Int_t i=0; i<fSignal->GetSize(); i++)
208 if (fDsignal && (mode==0 || mode==2))
210 for (Int_t j=0; j<fDsignal->GetSize(); j++)
212 fDsignal->AddAt(0,j);
216 if (fHwaveform) fHwaveform->Reset();
218 ///////////////////////////////////////////////////////////////////////////
219 void AliSignal::DeleteSignals(Int_t mode)
221 // Delete storage arrays of various signal data according to user selection.
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
227 // The default when invoking DeleteSignals() corresponds to mode=0.
229 // Irrespective of the mode, the waveform histogram is deleted.
231 if (mode<0 || mode>2)
233 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
234 cout << " Default mode=0 will be used." << endl;
238 if (fSignal && (mode==0 || mode==1))
244 if (fDsignal && (mode==0 || mode==2))
256 ///////////////////////////////////////////////////////////////////////////
257 void AliSignal::ResetPosition()
259 // Reset the position and corresponding errors to 0.
260 Double_t r[3]={0,0,0};
261 SetPosition(r,"sph");
264 ///////////////////////////////////////////////////////////////////////////
265 void AliSignal::SetSignal(Double_t sig,Int_t j)
267 // Store j-th (default j=1) signal value.
268 // Note : The first signal value is at j=1.
269 // In case the value of the index j exceeds the maximum number of reserved
270 // slots for signal values, the number of reserved slots for the
271 // signal values is increased automatically.
275 fSignal=new TArrayF(j);
279 Int_t size=fSignal->GetSize();
286 fSignal->AddAt(float(sig),j-1);
288 ///////////////////////////////////////////////////////////////////////////
289 void AliSignal::AddSignal(Double_t sig,Int_t j)
291 // Add value to j-th (default j=1) signal value.
292 // Note : The first signal value is at j=1.
293 // In case the value of the index j exceeds the maximum number of reserved
294 // slots for signal values, the number of reserved slots for the
295 // signal values is increased automatically.
299 fSignal=new TArrayF(j);
303 Int_t size=fSignal->GetSize();
310 Float_t sum=(fSignal->At(j-1))+sig;
311 fSignal->AddAt(sum,j-1);
313 ///////////////////////////////////////////////////////////////////////////
314 Float_t AliSignal::GetSignal(Int_t j)
316 // Provide j-th (default j=1) signal value.
317 // Note : The first signal value is at j=1.
318 // In case no signal is present or the argument j is invalid, 0 is returned.
322 if (j>0 && j<=(fSignal->GetSize()))
324 sig=fSignal->At(j-1);
328 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
333 ///////////////////////////////////////////////////////////////////////////
334 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
336 // Store error on j-th (default j=1) signal value.
337 // Note : The error on the first signal value is at j=1.
338 // In case the value of the index j exceeds the maximum number of reserved
339 // slots for signal error values, the number of reserved slots for the
340 // signal errors is increased automatically.
344 fDsignal=new TArrayF(j);
348 Int_t size=fDsignal->GetSize();
355 fDsignal->AddAt(float(dsig),j-1);
357 ///////////////////////////////////////////////////////////////////////////
358 Float_t AliSignal::GetSignalError(Int_t j)
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.
362 // In case no signal is present or the argument j is invalid, 0 is returned.
366 if (j>0 && j<=(fDsignal->GetSize()))
368 err=fDsignal->At(j-1);
372 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
377 ///////////////////////////////////////////////////////////////////////////
378 void AliSignal::Data(TString f)
380 // Provide signal information within the coordinate frame f
381 cout << " *AliSignal::Data* Signal of kind : " << fName.Data() << endl;
385 Int_t nvalues=GetNvalues();
386 Int_t nerrors=GetNerrors();
390 for (Int_t i=0; i<nvalues; i++)
392 cout << " Signal value : " << fSignal->At(i);
393 if (fDsignal && i<nerrors) cout << " error : " << fDsignal->At(i);
398 ///////////////////////////////////////////////////////////////////////////
399 void AliSignal::SetName(TString name)
401 // Set the name tag to indicate the kind of signal.
404 ///////////////////////////////////////////////////////////////////////////
405 TString AliSignal::GetName()
407 // Provide the name tag indicating the kind of signal.
410 ///////////////////////////////////////////////////////////////////////////
411 Int_t AliSignal::GetNvalues()
413 // Provide the number of values for this signal.
415 if (fSignal) n=fSignal->GetSize();
418 ///////////////////////////////////////////////////////////////////////////
419 Int_t AliSignal::GetNerrors()
421 // Provide the number specified errors on the values for this signal.
423 if (fDsignal) n=fDsignal->GetSize();
426 ///////////////////////////////////////////////////////////////////////////
427 TH1F* AliSignal::GetWaveform()
429 // Provide pointer to the 1D waveform histogram.
432 ///////////////////////////////////////////////////////////////////////////
433 void AliSignal::SetWaveform(TH1F* waveform)
435 // Set the 1D waveform histogram.
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.
441 // In case the input argument is zero, the current waveform histogram
442 // is deleted and the pointer set to zero.
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
448 if (waveform != fHwaveform)
455 if (waveform) fHwaveform=new TH1F(*waveform);
458 ///////////////////////////////////////////////////////////////////////////
459 AliSignal* AliSignal::MakeCopy(AliSignal& s)
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.
469 AliSignal* sig=new AliSignal(s);
472 ///////////////////////////////////////////////////////////////////////////