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 // Float_t offset=-12.78;
46 // s.SetPosition(pos,"car");
47 // s.SetPositionErrors(err,"car");
48 // s.SetSignal(signal);
49 // s.SetSignalError(error);
50 // s.SetOffset(offset);
52 // Float_t loc[3],dr[3],sigma;
53 // s.GetPosition(loc,"sph");
54 // s.GetPositionErrors(dr,"sph");
55 // Float_t adc=s.GetSignal();
56 // Float_t sigma=s.GetSignalError();
58 // AliSignal q; // In the example below a signal contains the
59 // // following data : timing, ADC and dE/dx
60 // q.SetName("TOF hit");
61 // q.SetPosition(pos,"car");
62 // q.SetPositionErrors(err,"car");
63 // signal=82.5; // e.g. signal time in ns
66 // q.SetSignal(signal,1);
67 // q.SetSignalError(error,1);
68 // q.SetOffset(offset,1);
69 // signal=268.1; // e.g. ADC value of signal
72 // q.SetSignal(signal,2);
73 // q.SetSignalError(error,2);
75 // signal=23.7; // e.g. corresponding dE/dx value
79 // q.SetSignal(signal,3);
80 // q.SetSignalError(error,3);
81 // q.SetOffset(offset,3);
84 //--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
85 //- Modified: NvE $Date$ UU-SAP Utrecht
86 ///////////////////////////////////////////////////////////////////////////
88 #include "AliSignal.h"
89 #include "Riostream.h"
91 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
93 AliSignal::AliSignal() : TObject(),AliPosition(),AliAttrib()
95 // Creation of an AliSignal object and initialisation of parameters.
96 // Several signal values (with errors) can be stored in different slots.
97 // If needed, the storage for values (and errors) will be expanded automatically
98 // when entering values and/or errors.
104 ///////////////////////////////////////////////////////////////////////////
105 AliSignal::~AliSignal()
107 // Destructor to delete dynamically allocated memory
124 ///////////////////////////////////////////////////////////////////////////
125 AliSignal::AliSignal(AliSignal& s) : TObject(s),AliPosition(s),AliAttrib(s)
133 Int_t n=s.GetNvalues();
135 for (Int_t i=1; i<=n; i++)
142 for (Int_t j=1; j<=n; j++)
144 val=s.GetSignalError(j);
145 SetSignalError(val,j);
149 for (Int_t k=1; k<=n; k++)
151 TH1F* hist=s.GetWaveform(k);
152 if (hist) SetWaveform(hist,k);
155 ///////////////////////////////////////////////////////////////////////////
156 void AliSignal::Reset(Int_t mode)
158 // Reset all signal and position values and errors to 0.
160 // mode = 0 Reset position and all signal values and their errors to 0.
161 // The waveform histograms are reset, but the calibration
162 // constants (i.e. gains and offsets) are kept.
163 // 1 Reset position and delete the signal and error storage arrays.
164 // Also the waveform histograms, gains and offset arrays are deleted.
166 // The default when invoking Reset() corresponds to mode=0.
168 // The usage of mode=0 allows to re-use the allocated memory for new
169 // signal (and error) values. This behaviour is preferable (i.e. faster)
170 // in case the various signals always contain the same number of values
171 // and have the same calibration constants.
172 // The usage of mode=1 is slower, but allows a more efficient memory
173 // occupation (and smaller output file size) in case the different
174 // signals have a variable number of values.
176 // For more specific actions see ResetPosition(), ResetSignals(),
177 // DeleteSignals(), ResetGain(), ResetOffset() and DeleteCalibrations().
180 if (mode<0 || mode>1)
182 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
183 cout << " Default mode=0 will be used." << endl;
195 DeleteCalibrations();
198 ///////////////////////////////////////////////////////////////////////////
199 void AliSignal::ResetSignals(Int_t mode)
201 // Reset various signal data according to user selection.
203 // mode = 0 Reset all signal values and their errors to 0.
204 // 1 Reset only signal values
205 // 2 Reset only signal errors
207 // The default when invoking ResetSignals() corresponds to mode=0.
209 // Irrespective of the mode, the waveform histograms are reset.
211 if (mode<0 || mode>2)
213 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
214 cout << " Default mode=0 will be used." << endl;
218 if (fSignals && (mode==0 || mode==1))
220 for (Int_t i=0; i<fSignals->GetSize(); i++)
222 fSignals->AddAt(0,i);
226 if (fDsignals && (mode==0 || mode==2))
228 for (Int_t j=0; j<fDsignals->GetSize(); j++)
230 fDsignals->AddAt(0,j);
236 ///////////////////////////////////////////////////////////////////////////
237 void AliSignal::DeleteSignals(Int_t mode)
239 // Delete storage arrays of various signal data according to user selection.
241 // mode = 0 Delete arrays of both signal values and their errors.
242 // 1 Delete only signal values array
243 // 2 Delete only signal errors array
245 // The default when invoking DeleteSignals() corresponds to mode=0.
247 // Irrespective of the mode, the waveform histograms are deleted.
249 if (mode<0 || mode>2)
251 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
252 cout << " Default mode=0 will be used." << endl;
256 if (fSignals && (mode==0 || mode==1))
262 if (fDsignals && (mode==0 || mode==2))
270 ///////////////////////////////////////////////////////////////////////////
271 void AliSignal::ResetPosition()
273 // Reset the position and corresponding errors to 0.
274 Double_t r[3]={0,0,0};
275 SetPosition(r,"sph");
278 ///////////////////////////////////////////////////////////////////////////
279 void AliSignal::SetSignal(Double_t sig,Int_t j)
281 // Store value in the j-th (default j=1) signal slot.
282 // Note : The first signal slot is at j=1.
283 // In case the value of the index j exceeds the maximum number of reserved
284 // slots for signal values, the number of reserved slots for the
285 // signal values is increased automatically.
289 fSignals=new TArrayF(j);
293 Int_t size=fSignals->GetSize();
300 fSignals->AddAt(float(sig),j-1);
302 ///////////////////////////////////////////////////////////////////////////
303 void AliSignal::AddSignal(Double_t sig,Int_t j)
305 // Add value to the j-th (default j=1) signal slot.
306 // Note : The first signal slot is at j=1.
307 // In case the value of the index j exceeds the maximum number of reserved
308 // slots for signal values, the number of reserved slots for the
309 // signal values is increased automatically.
313 fSignals=new TArrayF(j);
317 Int_t size=fSignals->GetSize();
324 Float_t sum=(fSignals->At(j-1))+sig;
325 fSignals->AddAt(sum,j-1);
327 ///////////////////////////////////////////////////////////////////////////
328 Float_t AliSignal::GetSignal(Int_t j,Int_t mode)
330 // Provide value of the j-th (default j=1) signal slot.
331 // Note : The first signal slot is at j=1.
332 // In case no signal is present or the argument j is invalid, 0 is returned.
333 // The parameter "mode" allows for automatic gain etc... correction of the signal.
335 // mode = 0 : Just the j-th signal is returned.
336 // 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
337 // In case the gain value was not set, gain=1 will be assumed.
338 // In case the gain value was 0, a signal value of 0 is returned.
339 // In case the offset value was not set, offset=0 will be assumed.
340 // In case the j-th slot was marked dead, 0 is returned.
342 // The corrected signal (sigc) is determined as follows :
344 // sigc=(signal/gain)-offset
346 // The default is mode=0.
353 if (j>0 && j<=(fSignals->GetSize()))
355 sig=fSignals->At(j-1);
357 if (mode==0) return sig;
359 // Correct the signal for the gain, offset, dead flag etc...
360 if (GetDeadValue(j)) return 0;
362 if (GetGainFlag(j)) gain=GetGain(j);
363 if (GetOffsetFlag(j)) offset=GetOffset(j);
367 sig=(sig/gain)-offset;
376 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
381 ///////////////////////////////////////////////////////////////////////////
382 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
384 // Store error for the j-th (default j=1) signal slot.
385 // Note : The first signal slot is at j=1.
386 // In case the value of the index j exceeds the maximum number of reserved
387 // slots for signal error values, the number of reserved slots for the
388 // signal errors is increased automatically.
392 fDsignals=new TArrayF(j);
396 Int_t size=fDsignals->GetSize();
403 fDsignals->AddAt(float(dsig),j-1);
405 ///////////////////////////////////////////////////////////////////////////
406 Float_t AliSignal::GetSignalError(Int_t j)
408 // Provide error of the j-th (default j=1) signal slot.
409 // Note : The first signal slot is at j=1.
410 // In case no signal is present or the argument j is invalid, 0 is returned.
414 if (j>0 && j<=(fDsignals->GetSize()))
416 err=fDsignals->At(j-1);
420 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
425 ///////////////////////////////////////////////////////////////////////////
426 void AliSignal::Data(TString f,Int_t j)
428 // Provide signal information for the j-th slot within the coordinate frame f.
429 // The first slot is at j=1.
430 // In case j=0 (default) the data of all slots will be listed.
434 cout << " *AliSignal::Data* Invalid argument j = " << j << endl;
438 cout << " *AliSignal::Data* Signal of kind : " << fName.Data() << endl;
442 Int_t nvalues=GetNvalues();
443 Int_t nerrors=GetNerrors();
445 if (nerrors>n) n=nerrors;
449 for (Int_t i=1; i<=n; i++)
452 if (i<=nvalues) cout << " value : " << GetSignal(i);
453 if (i<=nerrors) cout << " error : " << GetSignalError(i);
463 if (j<=nvalues) cout << " value : " << GetSignal(j);
464 if (j<=nerrors) cout << " error : " << GetSignalError(j);
470 ///////////////////////////////////////////////////////////////////////////
471 void AliSignal::SetName(TString name)
473 // Set the name tag to indicate the kind of signal.
476 ///////////////////////////////////////////////////////////////////////////
477 TString AliSignal::GetName()
479 // Provide the name tag indicating the kind of signal.
482 ///////////////////////////////////////////////////////////////////////////
483 Int_t AliSignal::GetNvalues()
485 // Provide the number of values for this signal.
487 if (fSignals) n=fSignals->GetSize();
490 ///////////////////////////////////////////////////////////////////////////
491 Int_t AliSignal::GetNerrors()
493 // Provide the number specified errors on the values for this signal.
495 if (fDsignals) n=fDsignals->GetSize();
498 ///////////////////////////////////////////////////////////////////////////
499 Int_t AliSignal::GetNwaveforms()
501 // Provide the number specified waveforms for this signal.
503 if (fWaveforms) n=fWaveforms->GetSize();
506 ///////////////////////////////////////////////////////////////////////////
507 TH1F* AliSignal::GetWaveform(Int_t j)
509 // Provide pointer to the j-th waveform histogram.
511 if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
514 ///////////////////////////////////////////////////////////////////////////
515 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
517 // Set the 1D waveform histogram corresponding to the j-th signal value.
520 // The waveform of the first signal value is at j=1.
521 // j=1 is the default value.
523 // In case the value of the index j exceeds the maximum number of reserved
524 // slots for the waveforms, the number of reserved slots for the waveforms
525 // is increased automatically.
527 // In case the histo pointer argument has the same value as the current waveform
528 // histogram pointer value, no action is taken since the user has already
529 // modified the actual histogram.
531 // In case the histo pointer argument is zero, the current waveform histogram
532 // is deleted and the pointer set to zero.
534 // In all other cases the current waveform histogram is deleted and a new
535 // copy of the input histogram is created which becomes the current waveform
540 fWaveforms=new TObjArray(j);
541 fWaveforms->SetOwner();
544 if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
546 TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
547 if (waveform != hcur)
551 fWaveforms->Remove(hcur);
557 hcur=new TH1F(*waveform);
558 fWaveforms->AddAt(hcur,j-1);
562 ///////////////////////////////////////////////////////////////////////////
563 void AliSignal::ResetWaveform(Int_t j)
565 // Reset the waveform of the j-th (default j=1) signal value.
566 // This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
567 // To actually delete the histograms from memory, use DeleteWaveform().
568 // Notes : The first signal value is at j=1.
569 // j=0 ==> All waveforms will be reset.
571 if (!fWaveforms) return;
573 Int_t size=fWaveforms->GetSize();
575 if ((j>=0) && (j<=size))
579 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
580 if (hwave) hwave->Reset();
584 for (Int_t i=0; i<size; i++)
586 TH1F* hwave=(TH1F*)fWaveforms->At(i);
587 if (hwave) hwave->Reset();
593 cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
597 ///////////////////////////////////////////////////////////////////////////
598 void AliSignal::DeleteWaveform(Int_t j)
600 // Delete the waveform of the j-th (default j=1) signal value.
601 // Notes : The first signal value is at j=1.
602 // j=0 ==> All waveforms will be deleted.
604 if (!fWaveforms) return;
606 Int_t size=fWaveforms->GetSize();
608 if ((j>=0) && (j<=size))
612 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
615 fWaveforms->Remove(hwave);
627 cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
631 ///////////////////////////////////////////////////////////////////////////
632 AliSignal* AliSignal::MakeCopy(AliSignal& s)
634 // Make a deep copy of the input object and provide the pointer to the copy.
635 // This memberfunction enables automatic creation of new objects of the
636 // correct type depending on the argument type, a feature which may be very useful
637 // for containers when adding objects in case the container owns the objects.
638 // This feature allows e.g. AliTrack to store either AliSignal objects or
639 // objects derived from AliSignal via the AddSignal memberfunction, provided
640 // these derived classes also have a proper MakeCopy memberfunction.
642 AliSignal* sig=new AliSignal(s);
645 ///////////////////////////////////////////////////////////////////////////