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 cout << " Link to : " << obj->ClassName();
516 if (obj->InheritsFrom("TNamed"))
518 const char* lname=obj->GetName();
519 const char* ltitle=obj->GetTitle();
520 if (strlen(lname)) cout << " Name : " << lname;
521 if (strlen(ltitle)) cout << " Title : " << ltitle;
532 if (j<=nvalues) cout << " value : " << GetSignal(j);
533 if (j<=nerrors) cout << " error : " << GetSignalError(j);
539 const char* wfnamej=obj->GetName();
540 const char* wftitlej=obj->GetTitle();
541 cout << " Waveform : " << obj->ClassName();
542 if (strlen(wfnamej)) cout << " Name : " << wfnamej;
543 if (strlen(wftitlej)) cout << " Title : " << wftitlej;
549 cout << " Link to : " << obj->ClassName();
550 if (obj->InheritsFrom("TNamed"))
552 const char* lnamej=obj->GetName();
553 const char* ltitlej=obj->GetTitle();
554 if (strlen(lnamej)) cout << " Name : " << lnamej;
555 if (strlen(ltitlej)) cout << " Title : " << ltitlej;
562 ///////////////////////////////////////////////////////////////////////////
563 Int_t AliSignal::GetNvalues()
565 // Provide the number of values for this signal.
567 if (fSignals) n=fSignals->GetSize();
570 ///////////////////////////////////////////////////////////////////////////
571 Int_t AliSignal::GetNerrors()
573 // Provide the number specified errors on the values for this signal.
575 if (fDsignals) n=fDsignals->GetSize();
578 ///////////////////////////////////////////////////////////////////////////
579 Int_t AliSignal::GetNwaveforms()
581 // Provide the number specified waveforms for this signal.
583 if (fWaveforms) n=fWaveforms->GetSize();
586 ///////////////////////////////////////////////////////////////////////////
587 TH1F* AliSignal::GetWaveform(Int_t j)
589 // Provide pointer to the j-th waveform histogram.
591 if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
594 ///////////////////////////////////////////////////////////////////////////
595 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
597 // Set the 1D waveform histogram corresponding to the j-th signal value.
600 // The waveform of the first signal value is at j=1.
601 // j=1 is the default value.
603 // In case the value of the index j exceeds the maximum number of reserved
604 // slots for the waveforms, the number of reserved slots for the waveforms
605 // is increased automatically.
607 // In case the histo pointer argument has the same value as the current waveform
608 // histogram pointer value, no action is taken since the user has already
609 // modified the actual histogram.
611 // In case the histo pointer argument is zero, the current waveform histogram
612 // is deleted and the pointer set to zero.
614 // In all other cases the current waveform histogram is deleted and a new
615 // copy of the input histogram is created which becomes the current waveform
620 fWaveforms=new TObjArray(j);
621 fWaveforms->SetOwner();
624 if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
626 TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
627 if (waveform != hcur)
631 fWaveforms->Remove(hcur);
637 hcur=new TH1F(*waveform);
638 fWaveforms->AddAt(hcur,j-1);
642 ///////////////////////////////////////////////////////////////////////////
643 void AliSignal::ResetWaveform(Int_t j)
645 // Reset the waveform of the j-th (default j=1) signal value.
646 // This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
647 // To actually delete the histograms from memory, use DeleteWaveform().
648 // Notes : The first signal value is at j=1.
649 // j=0 ==> All waveforms will be reset.
651 if (!fWaveforms) return;
653 Int_t size=fWaveforms->GetSize();
655 if ((j>=0) && (j<=size))
659 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
660 if (hwave) hwave->Reset();
664 for (Int_t i=0; i<size; i++)
666 TH1F* hwave=(TH1F*)fWaveforms->At(i);
667 if (hwave) hwave->Reset();
673 cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
677 ///////////////////////////////////////////////////////////////////////////
678 void AliSignal::DeleteWaveform(Int_t j)
680 // Delete the waveform of the j-th (default j=1) signal value.
681 // Notes : The first signal value is at j=1.
682 // j=0 ==> All waveforms will be deleted.
684 if (!fWaveforms) return;
686 Int_t size=fWaveforms->GetSize();
688 if ((j>=0) && (j<=size))
692 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
695 fWaveforms->Remove(hwave);
707 cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
711 ///////////////////////////////////////////////////////////////////////////
712 Int_t AliSignal::GetNlinks()
714 // Provide the highest slot number with a specified link for this signal.
716 if (fLinks) n=fLinks->GetSize();
719 ///////////////////////////////////////////////////////////////////////////
720 TObject* AliSignal::GetLink(Int_t j)
722 // Provide pointer of the object linked to the j-th slot.
724 if (j <= GetNlinks()) obj=fLinks->At(j-1);
727 ///////////////////////////////////////////////////////////////////////////
728 void AliSignal::SetLink(TObject* obj,Int_t j)
730 // Introduce a link (=pointer) to an object for the j-th slot.
731 // Only the pointer values are stored for (backward) reference, meaning
732 // that the objects of which the pointers are stored are NOT owned
733 // by the AliSignal object.
736 // The link of the first slot is at j=1.
737 // j=1 is the default value.
739 // In case the value of the index j exceeds the maximum number of reserved
740 // slots for the links, the number of reserved slots for the links
741 // is increased automatically (unless the pointer argument is zero).
743 // In case the pointer argument is zero, indeed a value of zero will be
744 // stored for the specified slot (unless j exceeds the current maximum).
746 // In principle any object derived from TObject can be referred to by this
748 // However, this "linking back" facility was introduced to enable AliSignal slots
749 // to refer directly to the various AliTracks to which the AliSignal object itself
750 // is related (see AliTrack::AddSignal).
751 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
752 // object, the current signal is automatically related to this AliTrack
753 // (or derived) object.
755 // Please also have a look at the docs of the memberfunction ResetLink()
756 // to prevent the situation of stored pointers to non-existent object.
760 fLinks=new TObjArray(j);
763 if (j>fLinks->GetSize() && obj) fLinks->Expand(j);
765 if (j<=fLinks->GetSize())
767 fLinks->AddAt(obj,j-1);
770 if (obj->InheritsFrom("AliTrack"))
772 AliTrack* t=(AliTrack*)obj;
778 ///////////////////////////////////////////////////////////////////////////
779 void AliSignal::ResetLink(Int_t j)
781 // Reset the link of the j-th (default j=1) slot.
782 // Notes : The first link position is at j=1.
783 // j=0 ==> All links will be reset and the storage array deleted.
785 // In general the user should take care of properly clearing the corresponding
786 // pointer here when the referred object is deleted.
787 // However, this "linking back" facility was introduced to enable AliSignal slots
788 // to refer directly to the various AliTracks to which the AliSignal object itself
789 // is related (see AliTrack::AddSignal).
790 // As such, the AliTrack destructor already takes care of clearing the corresponding
791 // links from the various AliSignal slots for all the AliSignal objects that were
792 // related to that AliTrack.
793 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
794 // the user doesn't have to worry about clearing the corresponding AliTrack link from
795 // the AliSignal object when the corresponding AliTrack object is deleted.
797 if (!fLinks || j<0) return;
811 ///////////////////////////////////////////////////////////////////////////
812 void AliSignal::ResetLink(TObject* obj)
814 // Reset the link of the all the slots referring to the specified object.
816 // In general the user should take care of properly clearing the corresponding
817 // pointer here when the referred object is deleted.
818 // However, this "linking back" facility was introduced to enable AliSignal slots
819 // to refer directly to the various AliTracks to which the AliSignal object itself
820 // is related (see AliTrack::AddSignal).
821 // As such, the AliTrack destructor already takes care of clearing the corresponding
822 // links from the various AliSignal slots for all the AliSignal objects that were
823 // related to that AliTrack.
824 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
825 // the user doesn't have to worry about clearing the corresponding AliTrack link from
826 // the AliSignal object when the corresponding AliTrack object is deleted.
828 if (!fLinks || !obj) return;
830 Int_t nlinks=GetNlinks();
831 for (Int_t i=1; i<=nlinks; i++)
833 TObject* obj2=GetLink(i);
834 if (obj2==obj) ResetLink(i);
837 ///////////////////////////////////////////////////////////////////////////
838 TObject* AliSignal::Clone(char* name)
840 // Make a deep copy of the current object and provide the pointer to the copy.
841 // This memberfunction enables automatic creation of new objects of the
842 // correct type depending on the object type, a feature which may be very useful
843 // for containers when adding objects in case the container owns the objects.
844 // This feature allows e.g. AliTrack to store either AliSignal objects or
845 // objects derived from AliSignal via the AddSignal memberfunction, provided
846 // these derived classes also have a proper Clone memberfunction.
848 AliSignal* sig=new AliSignal(*this);
851 if (strlen(name)) sig->SetName(name);
855 ///////////////////////////////////////////////////////////////////////////