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.SetNameTitle("Hybrid","Test for multiple signal data");
61 // q.SetPosition(pos,"car");
62 // q.SetPositionErrors(err,"car");
63 // signal=82.5; // e.g. signal time in ns
66 // q.SetSlotName("TOF");
67 // q.SetSignal(signal,1);
68 // q.SetSignalError(error,1);
69 // q.SetOffset(offset,1);
70 // signal=268.1; // e.g. ADC value of signal
73 // // Addressing via name specification instead of index
74 // q.SetSlotName("ADC");
75 // q.SetSignal(signal,"ADC");
76 // q.SetSignalError(error,"ADC");
77 // q.SetGain(gain,"ADC");
78 // signal=23.7; // e.g. corresponding dE/dx value
82 // q.SetSlotName("dE/dx");
83 // q.SetSignal(signal,3);
84 // q.SetSignalError(error,3);
85 // q.SetOffset(offset,3);
88 // Float_t dedx=q.GetSignal("dE/dx");
90 //--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
91 //- Modified: NvE $Date$ UU-SAP Utrecht
92 ///////////////////////////////////////////////////////////////////////////
94 #include "AliSignal.h"
96 #include "Riostream.h"
98 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
100 AliSignal::AliSignal() : TNamed(),AliPosition(),AliAttrib()
102 // Creation of an AliSignal object and initialisation of parameters.
103 // Several signal values (with errors) can be stored in different slots.
104 // If needed, the storage for values (and errors) will be expanded automatically
105 // when entering values and/or errors.
112 ///////////////////////////////////////////////////////////////////////////
113 AliSignal::~AliSignal()
115 // Destructor to delete dynamically allocated memory
133 // Remove this signal from all related tracks
134 for (Int_t i=1; i<=fLinks->GetNobjects(); i++)
136 TObject* obj=fLinks->GetObject(i);
138 if (obj->InheritsFrom("AliTrack"))
140 AliTrack* tx=(AliTrack*)obj;
141 tx->RemoveSignal(*this);
148 ///////////////////////////////////////////////////////////////////////////
149 AliSignal::AliSignal(const AliSignal& s) : TNamed(s),AliPosition(s),AliAttrib(s)
157 // Don't copy the owning device pointer for the copy
160 Int_t n=s.GetNvalues();
162 for (Int_t i=1; i<=n; i++)
169 for (Int_t j=1; j<=n; j++)
171 val=s.GetSignalError(j);
172 SetSignalError(val,j);
176 for (Int_t k=1; k<=n; k++)
178 TH1F* hist=s.GetWaveform(k);
179 if (hist) SetWaveform(hist,k);
185 n=s.GetIndices(dum,slotarr,posarr);
187 for (Int_t idx=0; idx<n; idx++)
189 slot=slotarr.At(idx);
191 TObject* obj=s.GetLink(slot,pos);
192 if (obj) SetLink(obj,slot,pos);
195 ///////////////////////////////////////////////////////////////////////////
196 void AliSignal::Reset(Int_t mode)
198 // Reset all signal and position values and errors to 0.
200 // mode = 0 Reset position and all signal values and their errors to 0.
201 // The waveform histograms are reset, but the calibration
202 // constants (i.e. gains and offsets) are kept.
203 // 1 Reset position and delete the signal and error storage arrays.
204 // Also the waveform histograms, gains and offset arrays are deleted.
206 // The default when invoking Reset() corresponds to mode=0.
208 // Note : In all cases the storage of the various links will be reset.
209 // The UniqueID, name and title will NOT be reset.
210 // In case the user wants to reset these attributes, this has to
211 // be done explicitly via the SET facilities.
213 // The usage of mode=0 allows to re-use the allocated memory for new
214 // signal (and error) values. This behaviour is preferable (i.e. faster)
215 // in case the various signals always contain the same number of values
216 // and have the same calibration constants.
217 // The usage of mode=1 is slower, but allows a more efficient memory
218 // occupation (and smaller output file size) in case the different
219 // signals have a variable number of values.
221 // For more specific actions see ResetPosition(), ResetSignals(),
222 // DeleteSignals(), ResetGain(), ResetOffset(), ResetLink(), ResetWaveform(),
223 // DeleteWaveform() and DeleteCalibrations().
226 if (mode<0 || mode>1)
228 cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
229 cout << " Default mode=0 will be used." << endl;
241 DeleteCalibrations();
244 if (fLinks) fLinks->Reset();
247 ///////////////////////////////////////////////////////////////////////////
248 void AliSignal::ResetSignals(Int_t mode)
250 // Reset various signal data according to user selection.
252 // mode = 0 Reset all signal values and their errors to 0.
253 // 1 Reset only signal values
254 // 2 Reset only signal errors
256 // The default when invoking ResetSignals() corresponds to mode=0.
258 // Irrespective of the mode, the waveform histograms are reset.
260 if (mode<0 || mode>2)
262 cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
263 cout << " Default mode=0 will be used." << endl;
267 if (fSignals && (mode==0 || mode==1))
269 for (Int_t i=0; i<fSignals->GetSize(); i++)
271 fSignals->AddAt(0,i);
275 if (fDsignals && (mode==0 || mode==2))
277 for (Int_t j=0; j<fDsignals->GetSize(); j++)
279 fDsignals->AddAt(0,j);
285 ///////////////////////////////////////////////////////////////////////////
286 void AliSignal::DeleteSignals(Int_t mode)
288 // Delete storage arrays of various signal data according to user selection.
290 // mode = 0 Delete arrays of both signal values and their errors.
291 // 1 Delete only signal values array
292 // 2 Delete only signal errors array
294 // The default when invoking DeleteSignals() corresponds to mode=0.
296 // Irrespective of the mode, the waveform histograms are deleted.
298 if (mode<0 || mode>2)
300 cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
301 cout << " Default mode=0 will be used." << endl;
305 if (fSignals && (mode==0 || mode==1))
311 if (fDsignals && (mode==0 || mode==2))
319 ///////////////////////////////////////////////////////////////////////////
320 void AliSignal::SetSignal(Double_t sig,Int_t j)
322 // Store signal value for the j-th (default j=1) slot.
323 // Note : The first signal slot is at j=1.
324 // In case the value of the index j exceeds the maximum number of reserved
325 // slots for signal values, the number of reserved slots for the
326 // signal values is increased automatically.
330 fSignals=new TArrayF(j);
334 Int_t size=fSignals->GetSize();
341 fSignals->AddAt(float(sig),j-1);
343 ///////////////////////////////////////////////////////////////////////////
344 void AliSignal::SetSignal(Double_t sig,TString name)
346 // Store signal value for the name-specified slot.
348 // This procedure involves a slot-index search based on the specified name
349 // at each invokation. This may become slow in case many slots have been
350 // defined and/or when this procedure is invoked many times.
351 // In such cases it is preferable to use indexed addressing in the user code
352 // either directly or via a few invokations of GetSlotIndex().
354 Int_t j=GetSlotIndex(name);
355 if (j>0) SetSignal(sig,j);
357 ///////////////////////////////////////////////////////////////////////////
358 void AliSignal::AddSignal(Double_t sig,Int_t j)
360 // Add value to the signal of the j-th (default j=1) slot.
361 // Note : The first signal slot is at j=1.
362 // In case the value of the index j exceeds the maximum number of reserved
363 // slots for signal values, the number of reserved slots for the
364 // signal values is increased automatically.
368 fSignals=new TArrayF(j);
372 Int_t size=fSignals->GetSize();
379 Float_t sum=(fSignals->At(j-1))+sig;
380 fSignals->AddAt(sum,j-1);
382 ///////////////////////////////////////////////////////////////////////////
383 void AliSignal::AddSignal(Double_t sig,TString name)
385 // Add value to the signal of the name-specified slot.
387 // This procedure involves a slot-index search based on the specified name
388 // at each invokation. This may become slow in case many slots have been
389 // defined and/or when this procedure is invoked many times.
390 // In such cases it is preferable to use indexed addressing in the user code
391 // either directly or via a few invokations of GetSlotIndex().
393 Int_t j=GetSlotIndex(name);
394 if (j>0) AddSignal(sig,j);
396 ///////////////////////////////////////////////////////////////////////////
397 Float_t AliSignal::GetSignal(Int_t j,Int_t mode) const
399 // Provide signal value of the j-th (default j=1) slot.
400 // Note : The first signal slot is at j=1.
401 // In case no signal is present or the argument j is invalid, 0 is returned.
402 // The parameter "mode" allows for automatic gain etc... correction of the signal.
404 // mode = 0 : Just the j-th signal is returned.
405 // 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
406 // In case the gain value was not set, gain=1 will be assumed.
407 // In case the gain value was 0, a signal value of 0 is returned.
408 // In case the offset value was not set, offset=0 will be assumed.
409 // In case the j-th slot was marked dead, 0 is returned.
411 // The corrected signal (sigc) is determined as follows :
413 // sigc=(signal/gain)-offset
415 // The default is mode=0.
422 if (j>0 && j<=(fSignals->GetSize()))
424 sig=fSignals->At(j-1);
426 if (mode==0) return sig;
428 // Correct the signal for the gain, offset, dead flag etc...
429 if (GetDeadValue(j)) return 0;
431 if (GetGainFlag(j)) gain=GetGain(j);
432 if (GetOffsetFlag(j)) offset=GetOffset(j);
436 sig=(sig/gain)-offset;
445 cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
450 ///////////////////////////////////////////////////////////////////////////
451 Float_t AliSignal::GetSignal(TString name,Int_t mode) const
453 // Provide signal value of the name-specified slot.
454 // In case no signal is present, 0 is returned.
455 // The parameter "mode" allows for automatic gain etc... correction of the signal.
457 // mode = 0 : Just the j-th signal is returned.
458 // 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
459 // In case the gain value was not set, gain=1 will be assumed.
460 // In case the gain value was 0, a signal value of 0 is returned.
461 // In case the offset value was not set, offset=0 will be assumed.
462 // In case the j-th slot was marked dead, 0 is returned.
464 // The corrected signal (sigc) is determined as follows :
466 // sigc=(signal/gain)-offset
468 // The default is mode=0.
470 // This procedure involves a slot-index search based on the specified name
471 // at each invokation. This may become slow in case many slots have been
472 // defined and/or when this procedure is invoked many times.
473 // In such cases it is preferable to use indexed addressing in the user code
474 // either directly or via a few invokations of GetSlotIndex().
476 Int_t j=GetSlotIndex(name);
478 if (j>0) val=GetSignal(j,mode);
481 ///////////////////////////////////////////////////////////////////////////
482 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
484 // Store error on the signal for the j-th (default j=1) slot.
485 // Note : The first signal slot is at j=1.
486 // In case the value of the index j exceeds the maximum number of reserved
487 // slots for signal error values, the number of reserved slots for the
488 // signal errors is increased automatically.
492 fDsignals=new TArrayF(j);
496 Int_t size=fDsignals->GetSize();
503 fDsignals->AddAt(float(dsig),j-1);
505 ///////////////////////////////////////////////////////////////////////////
506 void AliSignal::SetSignalError(Double_t dsig,TString name)
508 // Store error on the signal for the name-specified slot.
510 // This procedure involves a slot-index search based on the specified name
511 // at each invokation. This may become slow in case many slots have been
512 // defined and/or when this procedure is invoked many times.
513 // In such cases it is preferable to use indexed addressing in the user code
514 // either directly or via a few invokations of GetSlotIndex().
516 Int_t j=GetSlotIndex(name);
517 if (j>0) SetSignalError(dsig,j);
519 ///////////////////////////////////////////////////////////////////////////
520 Float_t AliSignal::GetSignalError(Int_t j) const
522 // Provide error on the signal of the j-th (default j=1) slot.
523 // Note : The first signal slot is at j=1.
524 // In case no signal is present or the argument j is invalid, 0 is returned.
528 if (j>0 && j<=(fDsignals->GetSize()))
530 err=fDsignals->At(j-1);
534 cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
539 ///////////////////////////////////////////////////////////////////////////
540 Float_t AliSignal::GetSignalError(TString name) const
542 // Provide error on the signal of the name-specified slot.
544 // This procedure involves a slot-index search based on the specified name
545 // at each invokation. This may become slow in case many slots have been
546 // defined and/or when this procedure is invoked many times.
547 // In such cases it is preferable to use indexed addressing in the user code
548 // either directly or via a few invokations of GetSlotIndex().
550 Int_t j=GetSlotIndex(name);
552 if (j>0) val=GetSignalError(j);
555 ///////////////////////////////////////////////////////////////////////////
556 void AliSignal::Data(TString f) const
558 // Provide all signal information within the coordinate frame f.
560 const char* name=GetName();
561 const char* title=GetTitle();
563 cout << " *" << ClassName() << "::Data* Id : " << GetUniqueID();
564 if (strlen(name)) cout << " Name : " << name;
565 if (strlen(title)) cout << " Title : " << title;
571 const char* devname=fDevice->GetName();
572 const char* devtitle=fDevice->GetTitle();
573 cout << " Owned by device : " << fDevice->ClassName()
574 << " Id : " << fDevice->GetUniqueID();
575 if (strlen(devname)) cout << " Name : " << devname;
576 if (strlen(devtitle)) cout << " Title : " << devtitle;
580 // Provide an overview of the stored waveforms
583 // Provide an overview of all the data and attribute slots
586 ///////////////////////////////////////////////////////////////////////////
587 void AliSignal::List(Int_t j) const
589 // Provide signal information for the j-th slot.
590 // The first slot is at j=1.
591 // In case j=0 (default) the data of all slots will be listed.
592 // In case j=-1 the data of all slots will be listed, but the header
593 // information will be suppressed.
597 cout << " *AliSignal::List* Invalid argument j = " << j << endl;
603 const char* name=GetName();
604 const char* title=GetTitle();
606 cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
607 if (strlen(name)) cout << " Name : " << name;
608 if (strlen(title)) cout << " Title : " << title;
612 const char* devname=fDevice->GetName();
613 const char* devtitle=fDevice->GetTitle();
614 cout << " Owned by device : " << fDevice->ClassName();
615 if (strlen(devname)) cout << " Name : " << devname;
616 if (strlen(devtitle)) cout << " Title : " << devtitle;
621 Int_t nvalues=GetNvalues();
622 Int_t nerrors=GetNerrors();
624 if (fLinks) nlinkslots=fLinks->GetMaxColumn();
626 if (nerrors>n) n=nerrors;
627 if (nlinkslots>n) n=nlinkslots;
636 for (Int_t i=1; i<=n; i++)
638 cout << " Slot : " << i;
639 if (i<=nvalues) cout << " Signal value : " << GetSignal(i);
640 if (i<=nerrors) cout << " error : " << GetSignalError(i);
644 nrefs=GetIndices(obj,i,posarr);
645 for (Int_t k=0; k<nrefs; k++)
651 cout << " Link at position " << pos << " to : " << obj->ClassName();
652 if (obj->InheritsFrom("TNamed"))
654 const char* lname=obj->GetName();
655 const char* ltitle=obj->GetTitle();
656 if (strlen(lname)) cout << " Name : " << lname;
657 if (strlen(ltitle)) cout << " Title : " << ltitle;
668 cout << " Slot : " << j;
669 if (j<=nvalues) cout << " Signal value : " << GetSignal(j);
670 if (j<=nerrors) cout << " error : " << GetSignalError(j);
674 nrefs=GetIndices(obj,j,posarr);
675 for (Int_t kj=0; kj<nrefs; kj++)
681 cout << " Link at position " << pos << " to : " << obj->ClassName();
682 if (obj->InheritsFrom("TNamed"))
684 const char* lnamej=obj->GetName();
685 const char* ltitlej=obj->GetTitle();
686 if (strlen(lnamej)) cout << " Name : " << lnamej;
687 if (strlen(ltitlej)) cout << " Title : " << ltitlej;
695 ///////////////////////////////////////////////////////////////////////////
696 void AliSignal::List(TString name) const
698 // Provide signal information for the name-specified slot.
700 // This procedure involves a slot-index search based on the specified name
701 // at each invokation. This may become slow in case many slots have been
702 // defined and/or when this procedure is invoked many times.
703 // In such cases it is preferable to use indexed addressing in the user code
704 // either directly or via a few invokations of GetSlotIndex().
706 Int_t j=GetSlotIndex(name);
709 ///////////////////////////////////////////////////////////////////////////
710 void AliSignal::ListWaveform(Int_t j) const
712 // Provide information for the j-th waveform.
713 // The first waveform is at j=1.
714 // In case j=0 (default) the info of all waveforms will be listed.
715 // In case j=-1 the info of all waveforms will be listed, but the header
716 // information will be suppressed.
720 cout << " *AliSignal::ListWaveform* Invalid argument j = " << j << endl;
726 const char* name=GetName();
727 const char* title=GetTitle();
729 cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
730 if (strlen(name)) cout << " Name : " << name;
731 if (strlen(title)) cout << " Title : " << title;
735 const char* devname=fDevice->GetName();
736 const char* devtitle=fDevice->GetTitle();
737 cout << " Owned by device : " << fDevice->ClassName();
738 if (strlen(devname)) cout << " Name : " << devname;
739 if (strlen(devtitle)) cout << " Title : " << devtitle;
744 Int_t n=GetNwaveforms();
749 for (Int_t i=1; i<=n; i++)
754 const char* wfname=obj->GetName();
755 const char* wftitle=obj->GetTitle();
756 cout << " Waveform " << i << " : " << obj->ClassName();
757 if (strlen(wfname)) cout << " Name : " << wfname;
758 if (strlen(wftitle)) cout << " Title : " << wftitle;
770 const char* wfnamej=obj->GetName();
771 const char* wftitlej=obj->GetTitle();
772 cout << " Waveform " << j << " : " << obj->ClassName();
773 if (strlen(wfnamej)) cout << " Name : " << wfnamej;
774 if (strlen(wftitlej)) cout << " Title : " << wftitlej;
780 ///////////////////////////////////////////////////////////////////////////
781 Int_t AliSignal::GetNvalues() const
783 // Provide the number of values for this signal.
785 if (fSignals) n=fSignals->GetSize();
788 ///////////////////////////////////////////////////////////////////////////
789 Int_t AliSignal::GetNerrors() const
791 // Provide the number specified errors on the values for this signal.
793 if (fDsignals) n=fDsignals->GetSize();
796 ///////////////////////////////////////////////////////////////////////////
797 Int_t AliSignal::GetNwaveforms() const
799 // Provide the number of specified waveforms for this signal.
800 // Actually the return value is the highest index of the stored waveforms.
801 // This allows an index dependent meaning of waveform info (e.g. waveforms
802 // with various gain values).
803 // So, when all waveforms are stored in consequetive positions (e.g. 1,2,3),
804 // this memberfunction returns 3, being both the highest filled position
805 // and the actual number of waveforms.
806 // In case only waveforms are stored at positions 1,2,5,7 this memberfunction
807 // returns a value 7 whereas only 4 actual waveforms are present.
808 // This implies that when looping over the various waveform slots, one
809 // always has to check whether the returned pointer value is non-zero
810 // (which is a good practice anyhow).
812 if (fWaveforms) n=fWaveforms->GetLast();
815 ///////////////////////////////////////////////////////////////////////////
816 TH1F* AliSignal::GetWaveform(Int_t j) const
818 // Provide pointer to the j-th waveform histogram.
820 if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
823 ///////////////////////////////////////////////////////////////////////////
824 TH1F* AliSignal::GetWaveform(TString name) const
826 // Provide pointer to the waveform histogram with the specified name.
827 // In case no match is found, zero is returned.
828 Int_t n=GetNwaveforms();
830 for (Int_t i=1; i<=n; i++)
832 TH1F* waveform=GetWaveform(i);
835 str=waveform->GetName();
836 if (str == name) return waveform;
839 return 0; // No match found
841 ///////////////////////////////////////////////////////////////////////////
842 Int_t AliSignal::GetWaveformIndex(TString name) const
844 // Provide index to the waveform histogram with the specified name.
845 // In case no match is found, zero is returned.
846 Int_t n=GetNwaveforms();
848 for (Int_t i=1; i<=n; i++)
850 TH1F* waveform=GetWaveform(i);
853 str=waveform->GetName();
854 if (str == name) return i;
857 return 0; // No match found
859 ///////////////////////////////////////////////////////////////////////////
860 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
862 // Set the 1D waveform histogram for the j-th waveform.
865 // The first waveform position at j=1.
866 // j=1 is the default value.
868 // In case the value of the index j exceeds the maximum number of reserved
869 // positions for the waveforms, the number of reserved positions for the waveforms
870 // is increased automatically.
872 // In case the histo pointer argument has the same value as the current waveform
873 // histogram pointer value, no action is taken since the user has already
874 // modified the actual histogram.
876 // In case the histo pointer argument is zero, the current waveform histogram
877 // is deleted and the pointer set to zero.
879 // In all other cases the current waveform histogram is deleted and a new
880 // copy of the input histogram is created which becomes the current waveform
887 fWaveforms=new TObjArray(j);
888 fWaveforms->SetOwner();
891 if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
893 TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
894 if (waveform != hcur)
898 fWaveforms->Remove(hcur);
904 hcur=new TH1F(*waveform);
905 fWaveforms->AddAt(hcur,j-1);
909 ///////////////////////////////////////////////////////////////////////////
910 void AliSignal::ResetWaveform(Int_t j)
912 // Reset the histogram of the j-th (default j=1) waveform.
913 // This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
914 // To actually delete the histograms from memory, use DeleteWaveform().
915 // Notes : The first position is at j=1.
916 // j=0 ==> All waveforms will be reset.
918 if (!fWaveforms) return;
920 Int_t size=fWaveforms->GetSize();
922 if ((j>=0) && (j<=size))
926 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
927 if (hwave) hwave->Reset();
931 for (Int_t i=0; i<size; i++)
933 TH1F* hwave=(TH1F*)fWaveforms->At(i);
934 if (hwave) hwave->Reset();
940 cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
944 ///////////////////////////////////////////////////////////////////////////
945 void AliSignal::ResetWaveform(TString name)
947 // Reset the waveform with the specified name.
948 Int_t j=GetWaveformIndex(name);
949 if (j>0) ResetWaveform(j);
951 ///////////////////////////////////////////////////////////////////////////
952 void AliSignal::DeleteWaveform(Int_t j)
954 // Delete the histogram of the j-th (default j=1) waveform.
955 // Notes : The first position is at j=1.
956 // j=0 ==> All waveforms will be deleted.
958 if (!fWaveforms) return;
960 Int_t size=fWaveforms->GetSize();
962 if ((j>=0) && (j<=size))
966 TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
969 fWaveforms->Remove(hwave);
981 cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
985 ///////////////////////////////////////////////////////////////////////////
986 void AliSignal::DeleteWaveform(TString name)
988 // Delete the waveform with the specified name.
989 Int_t j=GetWaveformIndex(name);
990 if (j>0) DeleteWaveform(j);
992 ///////////////////////////////////////////////////////////////////////////
993 Int_t AliSignal::GetNlinks(TObject* obj,Int_t j) const
995 // Provide the number of links to the specified object for the j-th slot.
996 // If j=0 (default) all slots will be scanned for the specified object.
997 // If obj=0 (default) all encountered objects for the specified slot will be counted.
998 // So, invokation of the default GetNlinks() will return the total number of
999 // all references to all sorts of stored objects.
1002 cout << " *AliSignal::GetNlinks* Index j = " << j << " invalid." << endl;
1009 if (fLinks) n=fLinks->GetNrefs(obj);
1014 n=GetIndices(obj,j,posarr);
1018 ///////////////////////////////////////////////////////////////////////////
1019 Int_t AliSignal::GetNlinks(TObject* obj,TString name) const
1021 // Provide the number of links to the specified object for the name-spec. slot.
1022 // If obj=0 all encountered objects for the specified slot will be counted.
1024 // This procedure involves a slot-index search based on the specified name
1025 // at each invokation. This may become slow in case many slots have been
1026 // defined and/or when this procedure is invoked many times.
1027 // In such cases it is preferable to use indexed addressing in the user code
1028 // either directly or via a few invokations of GetSlotIndex().
1030 Int_t j=GetSlotIndex(name);
1032 if (j>0) n=GetNlinks(obj,j);
1035 ///////////////////////////////////////////////////////////////////////////
1036 TObject* AliSignal::GetLink(Int_t j,Int_t k) const
1038 // Provide pointer of the object linked to the j-th slot at position k.
1041 // Note : In the internal storage matrix slots=columns positions=rows
1042 if (fLinks) obj=fLinks->GetObject(k,j);
1045 ///////////////////////////////////////////////////////////////////////////
1046 TObject* AliSignal::GetLink(TString name,Int_t k) const
1048 // Provide pointer of the object linked to the name-spec. slot at position k.
1050 // This procedure involves a slot-index search based on the specified name
1051 // at each invokation. This may become slow in case many slots have been
1052 // defined and/or when this procedure is invoked many times.
1053 // In such cases it is preferable to use indexed addressing in the user code
1054 // either directly or via a few invokations of GetSlotIndex().
1056 Int_t j=GetSlotIndex(name);
1058 if (j>0) obj=GetLink(j,k);
1061 ///////////////////////////////////////////////////////////////////////////
1062 void AliSignal::SetLink(TObject* obj,Int_t j,Int_t k)
1064 // Introduce a link (=pointer) to an object for the j-th slot at position k.
1065 // Only the pointer values are stored for (backward) reference, meaning
1066 // that the objects of which the pointers are stored are NOT owned
1067 // by the AliSignal object.
1070 // The first slot is at j=1 and the first position is at k=1.
1071 // j=1 and k=1 are the default values.
1073 // If needed, the storage area for the links is increased automatically.
1075 // In case the pointer argument is zero, indeed a value of zero will be
1076 // stored at the specified position (k) for the specified slot (j).
1078 // In principle any object derived from TObject can be referred to by this
1080 // However, this "linking back" facility was introduced to enable AliSignal slots
1081 // to refer directly to the various AliTracks to which the AliSignal object itself
1082 // is related (see AliTrack::AddSignal).
1083 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1084 // object, the current signal is automatically related to this AliTrack
1085 // (or derived) object.
1087 // Please also have a look at the docs of the memberfunction ResetLink()
1088 // to prevent the situation of stored pointers to non-existent object.
1090 if (!fLinks && obj) fLinks=new AliObjMatrix();
1092 if (!fLinks) return;
1094 // Note : In the internal storage matrix slots=columns positions=rows
1095 fLinks->EnterObject(k,j,obj);
1098 if (obj->InheritsFrom("AliTrack"))
1100 AliTrack* t=(AliTrack*)obj;
1101 t->AddSignal(*this);
1105 ///////////////////////////////////////////////////////////////////////////
1106 void AliSignal::SetLink(TObject* obj,TString name,Int_t k)
1108 // Introduce a link (=pointer) to an object for the name-spec. slot at position k.
1109 // Only the pointer values are stored for (backward) reference, meaning
1110 // that the objects of which the pointers are stored are NOT owned
1111 // by the AliSignal object.
1113 // This procedure involves a slot-index search based on the specified name
1114 // at each invokation. This may become slow in case many slots have been
1115 // defined and/or when this procedure is invoked many times.
1116 // In such cases it is preferable to use indexed addressing in the user code
1117 // either directly or via a few invokations of GetSlotIndex().
1119 Int_t j=GetSlotIndex(name);
1120 if (j>0) SetLink(obj,j,k);
1122 ///////////////////////////////////////////////////////////////////////////
1123 void AliSignal::AddLink(TObject* obj,Int_t j)
1125 // Introduce a link (=pointer) to an object for the j-th slot at the first
1127 // Only the pointer values are stored for (backward) reference, meaning
1128 // that the objects of which the pointers are stored are NOT owned
1129 // by the AliSignal object.
1132 // The first slot is at j=1 and the first position is at k=1.
1133 // j=1 is the default value.
1135 // If needed, the storage area for the links is increased automatically.
1137 // In case the pointer argument is zero, no link will be added.
1139 // In principle any object derived from TObject can be referred to by this
1141 // However, this "linking back" facility was introduced to enable AliSignal slots
1142 // to refer directly to the various AliTracks to which the AliSignal object itself
1143 // is related (see AliTrack::AddSignal).
1144 // Therefore, in case the input argument "obj" points to an AliTrack (or derived)
1145 // object, the current signal is automatically related to this AliTrack
1146 // (or derived) object.
1148 // Please also have a look at the docs of the memberfunction ResetLink()
1149 // to prevent the situation of stored pointers to non-existent object.
1151 if (!obj || j<=0) return;
1153 if (!fLinks) fLinks=new AliObjMatrix();
1156 Int_t n=GetNlinks(dum,j);
1158 for (Int_t k=1; k<=n; k++)
1167 ///////////////////////////////////////////////////////////////////////////
1168 void AliSignal::AddLink(TObject* obj,TString name)
1170 // Introduce a link (=pointer) to an object for the name-spec slot at the first
1172 // Only the pointer values are stored for (backward) reference, meaning
1173 // that the objects of which the pointers are stored are NOT owned
1174 // by the AliSignal object.
1176 // This procedure involves a slot-index search based on the specified name
1177 // at each invokation. This may become slow in case many slots have been
1178 // defined and/or when this procedure is invoked many times.
1179 // In such cases it is preferable to use indexed addressing in the user code
1180 // either directly or via a few invokations of GetSlotIndex().
1182 Int_t j=GetSlotIndex(name);
1183 if (j>0) AddLink(obj,j);
1185 ///////////////////////////////////////////////////////////////////////////
1186 void AliSignal::ResetLink(Int_t j,Int_t k)
1188 // Reset the link of the j-th slot at position k.
1191 // The first slot is at j=1 and the first position is at k=1.
1192 // j=1 and k=1 are the default values.
1194 // This memberfunction is intended to reset only 1 specified link location.
1195 // For extended functionality, please refer to the memberfuction ResetLinks().
1197 // In general the user should take care of properly clearing the corresponding
1198 // pointer here when the referred object is deleted.
1199 // However, this "linking back" facility was introduced to enable AliSignal slots
1200 // to refer directly to the various AliTracks to which the AliSignal object itself
1201 // is related (see AliTrack::AddSignal).
1202 // As such, the AliTrack destructor already takes care of clearing the corresponding
1203 // links from the various AliSignal slots for all the AliSignal objects that were
1204 // related to that AliTrack.
1205 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1206 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1207 // the AliSignal object when the corresponding AliTrack object is deleted.
1209 // Note : In the internal storage matrix slots=columns positions=rows
1210 if (fLinks) fLinks->RemoveObject(k,j);
1212 ///////////////////////////////////////////////////////////////////////////
1213 void AliSignal::ResetLink(TString name,Int_t k)
1215 // Reset the link of the name-specified slot at position k.
1217 // This memberfunction is intended to reset only 1 specified link location.
1218 // For extended functionality, please refer to the memberfuction ResetLinks().
1220 // This procedure involves a slot-index search based on the specified name
1221 // at each invokation. This may become slow in case many slots have been
1222 // defined and/or when this procedure is invoked many times.
1223 // In such cases it is preferable to use indexed addressing in the user code
1224 // either directly or via a few invokations of GetSlotIndex().
1226 Int_t j=GetSlotIndex(name);
1227 if (j>0) ResetLink(j,k);
1229 ///////////////////////////////////////////////////////////////////////////
1230 void AliSignal::ResetLinks(TObject* obj,Int_t j,Int_t k)
1232 // Reset single or multiple link(s) according to user specified selections.
1234 // A link is only reset if the stored reference matches the argument "obj".
1235 // In case obj=0 no check on the matching of the stored reference is performed
1236 // and the stored link is always reset in accordance with the other
1237 // selection criteria.
1239 // In case the slot argument "j" is specified, only the links from that
1240 // specified slot will be deleted.
1241 // In case j=0 (default) no checking on the slot index is performed.
1243 // In case the position argument "k" is specified, only the links from that
1244 // specified position will be deleted.
1245 // In case k=0 (default) no checking on the position index is performed.
1247 // So, invokation of ResetLinks(obj) will remove all references to the
1248 // object "obj" from the total AliSignal, whereas ResetLinks(obj,j)
1249 // will remove all references to the object "obj" only from slot "j".
1253 // The first slot is indicated as j=1, whereas the first position is at k=1.
1255 // Invokation of ResetLinks(0,row,col) is equivalent to invoking the
1256 // memberfunction ResetLink(row,col).
1257 // Invoking the latter directly is slightly faster.
1259 // Invokation of ResetLinks(0) will reset all stored references in this AliSignal.
1261 // In general the user should take care of properly clearing the corresponding
1262 // pointer here when the referred object is deleted.
1263 // However, this "linking back" facility was introduced to enable AliSignal slots
1264 // to refer directly to the various AliTracks to which the AliSignal object itself
1265 // is related (see AliTrack::AddSignal).
1266 // As such, the AliTrack destructor already takes care of clearing the corresponding
1267 // links from the various AliSignal slots for all the AliSignal objects that were
1268 // related to that AliTrack.
1269 // So, in case the link introduced via SetLink() is the pointer of an AliTrack object,
1270 // the user doesn't have to worry about clearing the corresponding AliTrack link from
1271 // the AliSignal object when the corresponding AliTrack object is deleted.
1273 if (!fLinks) return;
1275 if (!obj && !j && !k)
1281 // Note : In the internal storage matrix slots=columns positions=rows
1282 fLinks->RemoveObjects(obj,k,j);
1285 ///////////////////////////////////////////////////////////////////////////
1286 void AliSignal::ResetLinks(TObject* obj,TString name,Int_t k)
1288 // Reset single or multiple link(s) according to user specified selections.
1290 // A link is only reset if the stored reference matches the argument "obj".
1291 // In case obj=0 no check on the matching of the stored reference is performed
1292 // and the stored link is always reset in accordance with the other
1293 // selection criteria.
1295 // In case the position argument "k" is specified, only the links from that
1296 // specified position will be deleted.
1297 // In case k=0 (default) no checking on the position index is performed.
1299 // This procedure involves a slot-index search based on the specified name
1300 // at each invokation. This may become slow in case many slots have been
1301 // defined and/or when this procedure is invoked many times.
1302 // In such cases it is preferable to use indexed addressing in the user code
1303 // either directly or via a few invokations of GetSlotIndex().
1305 Int_t j=GetSlotIndex(name);
1306 if (j>0) ResetLinks(obj,j,k);
1308 ///////////////////////////////////////////////////////////////////////////
1309 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,TArrayI& ks) const
1311 // Provide the slot and position indices of all the storage locations
1312 // of the specified object.
1313 // The slot (j) and pos. (k) indices are returned in the two separate TArrayI arrays
1314 // from which the (j,k) pairs can be obtained from the corresponding
1315 // array indices like (j,k)=(js.At(i),ks.At(i)).
1316 // The integer return argument represents the number of (j,k) pairs which
1317 // were encountered for the specified object.
1319 // If obj=0 no object selection is performed and all (j,k) indices
1320 // of the stored references for all objects are returned.
1324 // As usual the convention is that slot and position numbering starts at 1.
1326 // This memberfunction always resets the two TArrayI arrays at the start.
1328 // This memberfunction can only be used to obtain the (j,k) indices
1329 // of the object as stored via the SetLink() or AddLink() memberfunction.
1330 // This means that in case the user has entered a TObjArray as object
1331 // (to increase the dimension of the resulting structure), the (j,k)
1332 // indices of that TObjArray are obtained and NOT the indices of the
1333 // actual objects contained in that TObjArray structure.
1338 // Note : In the internal storage matrix slots=columns positions=rows
1339 if (fLinks) nrefs=fLinks->GetIndices(obj,ks,js);
1342 ///////////////////////////////////////////////////////////////////////////
1343 Int_t AliSignal::GetIndices(TObject* obj,Int_t j,TArrayI& ks) const
1345 // Provide the position indices of all the storage locations of the
1346 // specified object in the j-th slot of this AliSignal.
1347 // The position indices are returned in the TArrayI array.
1348 // The integer return argument represents the number of storage locations which
1349 // were encountered for the specified object in the j-th slot.
1351 // If obj=0 no object selection is performed and all position indices
1352 // of the stored references for all objects of the j-th slot are returned.
1354 // If j=0 all slots will be scanned and all position indices matching the
1355 // object selection are returned.
1356 // Note that in this case multiple appearances of the same position index
1357 // will only be recorded once in the returned TArrayI array.
1361 // As usual the convention is that slot and position numbering starts at 1.
1363 // This memberfunction always resets the TArrayI array at the start.
1365 // This memberfunction can only be used to obtain the position indices
1366 // of the object as stored via the SetLink() or AddLink() memberfunction.
1367 // This means that in case the user has entered a TObjArray as object
1368 // (to increase the dimension of the resulting structure), the position
1369 // indices of that TObjArray are obtained and NOT the indices of the
1370 // actual objects contained in that TObjArray structure.
1374 // Note : In the internal storage matrix slots=columns positions=rows
1375 if (fLinks) nrefs=fLinks->GetIndices(obj,ks,j);
1378 ///////////////////////////////////////////////////////////////////////////
1379 Int_t AliSignal::GetIndices(TObject* obj,TString name,TArrayI& ks) const
1381 // Provide the position indices of all the storage locations of the
1382 // specified object in the name-specified slot of this AliSignal.
1383 // The position indices are returned in the TArrayI array.
1384 // The integer return argument represents the number of storage locations which
1385 // were encountered for the specified object in the j-th slot.
1387 // If obj=0 no object selection is performed and all position indices
1388 // of the stored references for all objects of the j-th slot are returned.
1390 // This procedure involves a slot-index search based on the specified name
1391 // at each invokation. This may become slow in case many slots have been
1392 // defined and/or when this procedure is invoked many times.
1393 // In such cases it is preferable to use indexed addressing in the user code
1394 // either directly or via a few invokations of GetSlotIndex().
1396 Int_t j=GetSlotIndex(name);
1398 if (j>0) n=GetIndices(obj,j,ks);
1401 ///////////////////////////////////////////////////////////////////////////
1402 Int_t AliSignal::GetIndices(TObject* obj,TArrayI& js,Int_t k) const
1404 // Provide the slot indices of all the storage locations of the
1405 // specified object for the k-th position in this AliSignal.
1406 // The slot indices are returned in the TArrayI array.
1407 // The integer return argument represents the number of storage locations which
1408 // were encountered for the specified object in the k-th position.
1410 // If obj=0 no object selection is performed and all slot indices
1411 // of the stored references for all objects in the k-th position are returned.
1413 // If k=0 all positions will be scanned and all slot indices matching the
1414 // object selection are returned.
1415 // Note that in this case multiple appearances of the same slot index
1416 // will only be recorded once in the returned TArrayI array.
1420 // As usual the convention is that slot and position numbering starts at 1.
1422 // This memberfunction always resets the TArrayI array at the start.
1424 // This memberfunction can only be used to obtain the slot indices
1425 // of the object as stored via the SetLink() or AddLink() memberfunction.
1426 // This means that in case the user has entered a TObjArray as object
1427 // (to increase the dimension of the resulting structure), the slot
1428 // indices of that TObjArray are obtained and NOT the indices of the
1429 // actual objects contained in that TObjArray structure.
1433 // Note : In the internal storage matrix slots=columns positions=rows
1434 if (fLinks) nrefs=fLinks->GetIndices(obj,k,js);
1437 ///////////////////////////////////////////////////////////////////////////
1438 void AliSignal::SetSwapMode(Int_t swap)
1440 // Set swapmode flag for the internal link storage.
1441 // In case for the stored links the maximum slot number differs considerably
1442 // from the maximum position number, it might be more efficient
1443 // (w.r.t. memory usage and/or output file size) to internally store the
1444 // link reference matrix with the rows and colums swapped.
1445 // This swapping is only related with the internal storage and as such
1446 // is completely hidden for the user.
1447 // At invokation of this memberfunction the default argument is swap=1.
1449 // Note : The swap mode can only be set as long as no links are
1450 // stored in the AliSignal (i.e. a new instance of AliSignal
1451 // or after invokation of the Reset() or ResetLinks() function).
1453 if (!fLinks) fLinks=new AliObjMatrix();
1454 fLinks->SetSwapMode(swap);
1456 ///////////////////////////////////////////////////////////////////////////
1457 Int_t AliSignal::GetSwapMode() const
1459 // Provide swapmode flag of the link storage.
1461 if (fLinks) swap=fLinks->GetSwapMode();
1464 ///////////////////////////////////////////////////////////////////////////
1465 void AliSignal::SetDevice(TObject* dev)
1467 // Store the pointer to the device which owns this AliSignal object.
1468 // This memberfunction is meant for internal use in AliDevice.
1471 ///////////////////////////////////////////////////////////////////////////
1472 AliDevice* AliSignal::GetDevice() const
1474 // Provide the pointer to the device which owns this AliSignal object.
1475 return (AliDevice*)fDevice;
1477 ///////////////////////////////////////////////////////////////////////////
1478 TObject* AliSignal::Clone(const char* name) const
1480 // Make a deep copy of the current object and provide the pointer to the copy.
1481 // This memberfunction enables automatic creation of new objects of the
1482 // correct type depending on the object type, a feature which may be very useful
1483 // for containers when adding objects in case the container owns the objects.
1484 // This feature allows e.g. AliTrack to store either AliSignal objects or
1485 // objects derived from AliSignal via the AddSignal memberfunction, provided
1486 // these derived classes also have a proper Clone memberfunction.
1488 AliSignal* sig=new AliSignal(*this);
1491 if (strlen(name)) sig->SetName(name);
1495 ///////////////////////////////////////////////////////////////////////////