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"
90 #include "Riostream.h"
92 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
94 AliSignal::AliSignal() : TNamed(),AliPosition(),AliAttrib()
96 // Creation of an AliSignal object and initialisation of parameters.
97 // Several signal values (with errors) can be stored in different slots.
98 // If needed, the storage for values (and errors) will be expanded automatically
99 // when entering values and/or errors.
105 ///////////////////////////////////////////////////////////////////////////
106 AliSignal::~AliSignal()
108 // Destructor to delete dynamically allocated memory
130 ///////////////////////////////////////////////////////////////////////////
131 AliSignal::AliSignal(AliSignal& s) : TNamed(s),AliPosition(s),AliAttrib(s)
139 Int_t n=s.GetNvalues();
141 for (Int_t i=1; i<=n; i++)
148 for (Int_t j=1; j<=n; j++)
150 val=s.GetSignalError(j);
151 SetSignalError(val,j);
155 for (Int_t k=1; k<=n; k++)
157 TH1F* hist=s.GetWaveform(k);
158 if (hist) SetWaveform(hist,k);
162 for (Int_t il=1; il<=n; il++)
164 TObject* obj=s.GetLink(il);
165 if (obj) SetLink(obj,il);
168 ///////////////////////////////////////////////////////////////////////////
169 void AliSignal::Reset(Int_t mode)
171 // Reset all signal and position values and errors to 0.
173 // mode = 0 Reset position and all signal values and their errors to 0.
174 // The waveform histograms are reset, but the calibration
175 // constants (i.e. gains and offsets) are kept.
176 // 1 Reset position and delete the signal and error storage arrays.
177 // Also the waveform histograms, gains and offset arrays are deleted.
179 // The default when invoking Reset() corresponds to mode=0.
181 // Note : In all cases the storage of the various links will be cleared
182 // and the container itself will be deleted to recover the memory.
184 // The usage of mode=0 allows to re-use the allocated memory for new
185 // signal (and error) values. This behaviour is preferable (i.e. faster)
186 // in case the various signals always contain the same number of values
187 // and have the same calibration constants.
188 // The usage of mode=1 is slower, but allows a more efficient memory
189 // occupation (and smaller output file size) in case the different
190 // signals have a variable number of values.
192 // For more specific actions see ResetPosition(), ResetSignals(),
193 // DeleteSignals(), ResetGain(), ResetOffset() and DeleteCalibrations().
196 if (mode<0 || mode>1)
198 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
199 cout << " Default mode=0 will be used." << endl;
211 DeleteCalibrations();
220 ///////////////////////////////////////////////////////////////////////////
221 void AliSignal::ResetSignals(Int_t mode)
223 // Reset various signal data according to user selection.
225 // mode = 0 Reset all signal values and their errors to 0.
226 // 1 Reset only signal values
227 // 2 Reset only signal errors
229 // The default when invoking ResetSignals() corresponds to mode=0.
231 // Irrespective of the mode, the waveform histograms are reset.
233 if (mode<0 || mode>2)
235 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
236 cout << " Default mode=0 will be used." << endl;
240 if (fSignals && (mode==0 || mode==1))
242 for (Int_t i=0; i<fSignals->GetSize(); i++)
244 fSignals->AddAt(0,i);
248 if (fDsignals && (mode==0 || mode==2))
250 for (Int_t j=0; j<fDsignals->GetSize(); j++)
252 fDsignals->AddAt(0,j);
258 ///////////////////////////////////////////////////////////////////////////
259 void AliSignal::DeleteSignals(Int_t mode)
261 // Delete storage arrays of various signal data according to user selection.
263 // mode = 0 Delete arrays of both signal values and their errors.
264 // 1 Delete only signal values array
265 // 2 Delete only signal errors array
267 // The default when invoking DeleteSignals() corresponds to mode=0.
269 // Irrespective of the mode, the waveform histograms are deleted.
271 if (mode<0 || mode>2)
273 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
274 cout << " Default mode=0 will be used." << endl;
278 if (fSignals && (mode==0 || mode==1))
284 if (fDsignals && (mode==0 || mode==2))
292 ///////////////////////////////////////////////////////////////////////////
293 void AliSignal::SetSignal(Double_t sig,Int_t j)
295 // Store value in the j-th (default j=1) signal slot.
296 // Note : The first signal slot is at j=1.
297 // In case the value of the index j exceeds the maximum number of reserved
298 // slots for signal values, the number of reserved slots for the
299 // signal values is increased automatically.
303 fSignals=new TArrayF(j);
307 Int_t size=fSignals->GetSize();
314 fSignals->AddAt(float(sig),j-1);
316 ///////////////////////////////////////////////////////////////////////////
317 void AliSignal::AddSignal(Double_t sig,Int_t j)
319 // Add value to the j-th (default j=1) signal slot.
320 // Note : The first signal slot is at j=1.
321 // In case the value of the index j exceeds the maximum number of reserved
322 // slots for signal values, the number of reserved slots for the
323 // signal values is increased automatically.
327 fSignals=new TArrayF(j);
331 Int_t size=fSignals->GetSize();
338 Float_t sum=(fSignals->At(j-1))+sig;
339 fSignals->AddAt(sum,j-1);
341 ///////////////////////////////////////////////////////////////////////////
342 Float_t AliSignal::GetSignal(Int_t j,Int_t mode)
344 // Provide value of the j-th (default j=1) signal slot.
345 // Note : The first signal slot is at j=1.
346 // In case no signal is present or the argument j is invalid, 0 is returned.
347 // The parameter "mode" allows for automatic gain etc... correction of the signal.
349 // mode = 0 : Just the j-th signal is returned.
350 // 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
351 // In case the gain value was not set, gain=1 will be assumed.
352 // In case the gain value was 0, a signal value of 0 is returned.
353 // In case the offset value was not set, offset=0 will be assumed.
354 // In case the j-th slot was marked dead, 0 is returned.
356 // The corrected signal (sigc) is determined as follows :
358 // sigc=(signal/gain)-offset
360 // The default is mode=0.
367 if (j>0 && j<=(fSignals->GetSize()))
369 sig=fSignals->At(j-1);
371 if (mode==0) return sig;
373 // Correct the signal for the gain, offset, dead flag etc...
374 if (GetDeadValue(j)) return 0;
376 if (GetGainFlag(j)) gain=GetGain(j);
377 if (GetOffsetFlag(j)) offset=GetOffset(j);
381 sig=(sig/gain)-offset;
390 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
395 ///////////////////////////////////////////////////////////////////////////
396 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
398 // Store error for the j-th (default j=1) signal slot.
399 // Note : The first signal slot is at j=1.
400 // In case the value of the index j exceeds the maximum number of reserved
401 // slots for signal error values, the number of reserved slots for the
402 // signal errors is increased automatically.
406 fDsignals=new TArrayF(j);
410 Int_t size=fDsignals->GetSize();
417 fDsignals->AddAt(float(dsig),j-1);
419 ///////////////////////////////////////////////////////////////////////////
420 Float_t AliSignal::GetSignalError(Int_t j)
422 // Provide error of the j-th (default j=1) signal slot.
423 // Note : The first signal slot is at j=1.
424 // In case no signal is present or the argument j is invalid, 0 is returned.
428 if (j>0 && j<=(fDsignals->GetSize()))
430 err=fDsignals->At(j-1);
434 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
439 ///////////////////////////////////////////////////////////////////////////
440 void AliSignal::Data(TString f)
442 // Provide all signal information within the coordinate frame f.
444 const char* name=GetName();
445 const char* title=GetTitle();
447 cout << " *" << ClassName() << "::Data*";
448 if (strlen(name)) cout << " Name : " << name;
449 if (strlen(title)) cout << " Title : " << title;
456 ///////////////////////////////////////////////////////////////////////////
457 void AliSignal::List(Int_t j)
459 // Provide signal information for the j-th slot.
460 // The first slot is at j=1.
461 // In case j=0 (default) the data of all slots will be listed.
462 // In case j=-1 the data of all slots will be listed, but the header
463 // information will be suppressed.
467 cout << " *AliSignal::List* Invalid argument j = " << j << endl;
473 const char* name=GetName();
474 const char* title=GetTitle();
476 cout << " *" << ClassName() << "::Data*";
477 if (strlen(name)) cout << " Name : " << name;
478 if (strlen(title)) cout << " Title : " << title;
482 Int_t nvalues=GetNvalues();
483 Int_t nerrors=GetNerrors();
484 Int_t nwforms=GetNwaveforms();
485 Int_t nlinks=GetNlinks();
487 if (nerrors>n) n=nerrors;
488 if (nwforms>n) n=nwforms;
489 if (nlinks>n) n=nlinks;
495 for (Int_t i=1; i<=n; i++)
498 if (i<=nvalues) cout << " value : " << GetSignal(i);
499 if (i<=nerrors) cout << " error : " << GetSignalError(i);
505 const char* wfname=obj->GetName();
506 const char* wftitle=obj->GetTitle();
507 cout << " Waveform : " << obj->ClassName();
508 if (strlen(wfname)) cout << " Name : " << wfname;
509 if (strlen(wftitle)) cout << " Title : " << wftitle;
515 const char* lname=obj->GetName();
516 const char* ltitle=obj->GetTitle();
517 cout << " Link to : " << obj->ClassName();
518 if (strlen(lname)) cout << " Name : " << lname;
519 if (strlen(ltitle)) cout << " Title : " << ltitle;
529 if (j<=nvalues) cout << " value : " << GetSignal(j);
530 if (j<=nerrors) cout << " error : " << GetSignalError(j);
536 const char* wfnamej=obj->GetName();
537 const char* wftitlej=obj->GetTitle();
538 cout << " Waveform : " << obj->ClassName();
539 if (strlen(wfnamej)) cout << " Name : " << wfnamej;
540 if (strlen(wftitlej)) cout << " Title : " << wftitlej;
546 const char* lnamej=obj->GetName();
547 const char* ltitlej=obj->GetTitle();
548 cout << " Link to : " << obj->ClassName();
549 if (strlen(lnamej)) cout << " Name : " << lnamej;
550 if (strlen(ltitlej)) cout << " Title : " << ltitlej;
556 ///////////////////////////////////////////////////////////////////////////
557 Int_t AliSignal::GetNvalues()
559 // Provide the number of values for this signal.
561 if (fSignals) n=fSignals->GetSize();
564 ///////////////////////////////////////////////////////////////////////////
565 Int_t AliSignal::GetNerrors()
567 // Provide the number specified errors on the values for this signal.
569 if (fDsignals) n=fDsignals->GetSize();
572 ///////////////////////////////////////////////////////////////////////////
573 Int_t AliSignal::GetNwaveforms()
575 // Provide the number specified waveforms for this signal.
577 if (fWaveforms) n=fWaveforms->GetSize();
580 ///////////////////////////////////////////////////////////////////////////
581 TH1F* AliSignal::GetWaveform(Int_t j)
583 // Provide pointer to the j-th waveform histogram.
585 if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
588 ///////////////////////////////////////////////////////////////////////////
589 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
591 // Set the 1D waveform histogram corresponding to the j-th signal value.
594 // The waveform of the first signal value is at j=1.
595 // j=1 is the default value.
597 // In case the value of the index j exceeds the maximum number of reserved
598 // slots for the waveforms, the number of reserved slots for the waveforms
599 // is increased automatically.
601 // In case the histo pointer argument has the same value as the current waveform
602 // histogram pointer value, no action is taken since the user has already
603 // modified the actual histogram.
605 // In case the histo pointer argument is zero, the current waveform histogram
606 // is deleted and the pointer set to zero.
608 // In all other cases the current waveform histogram is deleted and a new
609 // copy of the input histogram is created which becomes the current waveform
614 fWaveforms=new TObjArray(j);
615 fWaveforms->SetOwner();
618 if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
620 TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
621 if (waveform != hcur)
625 fWaveforms->Remove(hcur);
631 hcur=new TH1F(*waveform);
632 fWaveforms->AddAt(hcur,j-1);
636 ///////////////////////////////////////////////////////////////////////////
637 void AliSignal::ResetWaveform(Int_t j)
639 // Reset the waveform of the j-th (default j=1) signal value.
640 // This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
641 // To actually delete the histograms from memory, use DeleteWaveform().
642 // Notes : The first signal value is at j=1.
643 // j=0 ==> All waveforms will be reset.
645 if (!fWaveforms) return;
647 Int_t size=fWaveforms->GetSize();
649 if ((j>=0) && (j<=size))
653 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
654 if (hwave) hwave->Reset();
658 for (Int_t i=0; i<size; i++)
660 TH1F* hwave=(TH1F*)fWaveforms->At(i);
661 if (hwave) hwave->Reset();
667 cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
671 ///////////////////////////////////////////////////////////////////////////
672 void AliSignal::DeleteWaveform(Int_t j)
674 // Delete the waveform of the j-th (default j=1) signal value.
675 // Notes : The first signal value is at j=1.
676 // j=0 ==> All waveforms will be deleted.
678 if (!fWaveforms) return;
680 Int_t size=fWaveforms->GetSize();
682 if ((j>=0) && (j<=size))
686 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
689 fWaveforms->Remove(hwave);
701 cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
705 ///////////////////////////////////////////////////////////////////////////
706 Int_t AliSignal::GetNlinks()
708 // Provide the highest slot number with a specified link for this signal.
710 if (fLinks) n=fLinks->GetSize();
713 ///////////////////////////////////////////////////////////////////////////
714 TObject* AliSignal::GetLink(Int_t j)
716 // Provide pointer of the object linked to the j-th slot.
718 if (j <= GetNlinks()) obj=fLinks->At(j-1);
721 ///////////////////////////////////////////////////////////////////////////
722 void AliSignal::SetLink(TObject* obj,Int_t j)
724 // Introduce a link (=pointer) to an object for the j-th slot.
725 // Only the pointer values are stored for (backward) reference, meaning
726 // that the objects of which the pointers are stored are NOT owned
727 // by the AliSignal object.
730 // The link of the first slot is at j=1.
731 // j=1 is the default value.
733 // In case the value of the index j exceeds the maximum number of reserved
734 // slots for the links, the number of reserved slots for the links
735 // is increased automatically (unless the pointer argument is zero).
737 // In case the pointer argument is zero, indeed a value of zero will be
738 // stored for the specified slot (unless j exceeds the current maximum).
740 // In principle any object derived from TObject can be referred to by this
742 // However, this "linking back" facility was introduced to enable AliSignal slots
743 // to refer directly to the various AliTracks to which the AliSignal object itself
744 // is related (see AliTrack::AddSignal).
745 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
746 // object, the current signal is automatically related to this AliTrack
747 // (or derived) object.
749 // Please also have a look at the docs of the memberfunction ResetLink()
750 // to prevent the situation of stored pointers to non-existent object.
754 fLinks=new TObjArray(j);
757 if (j>fLinks->GetSize() && obj) fLinks->Expand(j);
759 if (j<=fLinks->GetSize())
761 fLinks->AddAt(obj,j-1);
764 if (obj->InheritsFrom("AliTrack"))
766 AliTrack* t=(AliTrack*)obj;
772 ///////////////////////////////////////////////////////////////////////////
773 void AliSignal::ResetLink(Int_t j)
775 // Reset the link of the j-th (default j=1) slot.
776 // Notes : The first link position is at j=1.
777 // j=0 ==> All links will be reset and the storage array deleted.
779 // In general the user should take care of properly clearing the corresponding
780 // pointer here when the referred object is deleted.
781 // However, this "linking back" facility was introduced to enable AliSignal slots
782 // to refer directly to the various AliTracks to which the AliSignal object itself
783 // is related (see AliTrack::AddSignal).
784 // As such, the AliTrack destructor already takes care of clearing the corresponding
785 // links from the various AliSignal slots for all the AliSignal objects that were
786 // related to that AliTrack.
787 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
788 // the user doesn't have to worry about clearing the corresponding AliTrack link from
789 // the AliSignal object when the corresponding AliTrack object is deleted.
791 if (!fLinks || j<0) return;
805 ///////////////////////////////////////////////////////////////////////////
806 void AliSignal::ResetLink(TObject* obj)
808 // Reset the link of the all the slots referring to the specified object.
810 // In general the user should take care of properly clearing the corresponding
811 // pointer here when the referred object is deleted.
812 // However, this "linking back" facility was introduced to enable AliSignal slots
813 // to refer directly to the various AliTracks to which the AliSignal object itself
814 // is related (see AliTrack::AddSignal).
815 // As such, the AliTrack destructor already takes care of clearing the corresponding
816 // links from the various AliSignal slots for all the AliSignal objects that were
817 // related to that AliTrack.
818 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
819 // the user doesn't have to worry about clearing the corresponding AliTrack link from
820 // the AliSignal object when the corresponding AliTrack object is deleted.
822 if (!fLinks || !obj) return;
824 Int_t nlinks=GetNlinks();
825 for (Int_t i=1; i<=nlinks; i++)
827 TObject* obj2=GetLink(i);
828 if (obj2==obj) ResetLink(i);
831 ///////////////////////////////////////////////////////////////////////////
832 TObject* AliSignal::Clone(char* name)
834 // Make a deep copy of the current object and provide the pointer to the copy.
835 // This memberfunction enables automatic creation of new objects of the
836 // correct type depending on the object type, a feature which may be very useful
837 // for containers when adding objects in case the container owns the objects.
838 // This feature allows e.g. AliTrack to store either AliSignal objects or
839 // objects derived from AliSignal via the AddSignal memberfunction, provided
840 // these derived classes also have a proper Clone memberfunction.
842 AliSignal* sig=new AliSignal(*this);
845 if (strlen(name)) sig->SetName(name);
849 ///////////////////////////////////////////////////////////////////////////