]> git.uio.no Git - u/mrichter/AliRoot.git/blob - RALICE/AliSignal.cxx
4048a0fc4525ec0891c558f26860447cc27a9027
[u/mrichter/AliRoot.git] / RALICE / AliSignal.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 // $Id$
17
18 ///////////////////////////////////////////////////////////////////////////
19 // Class AliSignal
20 // Generic handling of (extrapolated) detector signals.
21 //
22 // Note :
23 // ------
24 // Signal positions (r) and reference frames (f) are specified via
25 // SetPosition(r,f) under the following conventions :
26 //
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)
30 //
31 // The same holds for SetPositionErrors().
32 //
33 // All angles are in radians.
34 //
35 // Example :
36 // ---------
37 //
38 // AliSignal s;
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;
45 // Float_t gain=250;
46 // s.SetPosition(pos,"car");
47 // s.SetPositionErrors(err,"car");
48 // s.SetSignal(signal);
49 // s.SetSignalError(error);
50 // s.SetOffset(offset);
51 // s.SetGain(gain);
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();
57 //
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
64 // error=2.01;
65 // offset=0.003;
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
70 // error=3.75;
71 // gain=120.78;
72 // q.SetSignal(signal,2);
73 // q.SetSignalError(error,2);
74 // q.SetGain(gain,2);
75 // signal=23.7; // e.g. corresponding dE/dx value
76 // error=0.48;
77 // offset=0.2;
78 // gain=150;
79 // q.SetSignal(signal,3);
80 // q.SetSignalError(error,3);
81 // q.SetOffset(offset,3);
82 // q.SetGain(gain,3);
83 //
84 //--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
85 //- Modified: NvE $Date$ UU-SAP Utrecht
86 ///////////////////////////////////////////////////////////////////////////
87
88 #include "AliSignal.h"
89 #include "AliTrack.h"
90 #include "Riostream.h"
91  
92 ClassImp(AliSignal) // Class implementation to enable ROOT I/O
93  
94 AliSignal::AliSignal() : TNamed(),AliPosition(),AliAttrib()
95 {
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.
100  fSignals=0;
101  fDsignals=0;
102  fWaveforms=0;
103  fLinks=0;
104 }
105 ///////////////////////////////////////////////////////////////////////////
106 AliSignal::~AliSignal()
107 {
108 // Destructor to delete dynamically allocated memory
109  if (fSignals)
110  {
111   delete fSignals;
112   fSignals=0;
113  }
114  if (fDsignals)
115  {
116   delete fDsignals;
117   fDsignals=0;
118  }
119  if (fWaveforms)
120  {
121   delete fWaveforms;
122   fWaveforms=0;
123  }
124  if (fLinks)
125  {
126   delete fLinks;
127   fLinks=0;
128  }
129 }
130 ///////////////////////////////////////////////////////////////////////////
131 AliSignal::AliSignal(AliSignal& s) : TNamed(s),AliPosition(s),AliAttrib(s)
132 {
133 // Copy constructor
134  fSignals=0;
135  fDsignals=0;
136  fWaveforms=0;
137  fLinks=0;
138
139  Int_t n=s.GetNvalues();
140  Double_t val;
141  for (Int_t i=1; i<=n; i++)
142  {
143   val=s.GetSignal(i);
144   SetSignal(val,i);
145  } 
146
147  n=s.GetNerrors();
148  for (Int_t j=1; j<=n; j++)
149  {
150   val=s.GetSignalError(j);
151   SetSignalError(val,j);
152  }
153
154  n=s.GetNwaveforms();
155  for (Int_t k=1; k<=n; k++)
156  {
157   TH1F* hist=s.GetWaveform(k);
158   if (hist) SetWaveform(hist,k); 
159  }
160
161  n=s.GetNlinks();
162  for (Int_t il=1; il<=n; il++)
163  {
164   TObject* obj=s.GetLink(il);
165   if (obj) SetLink(obj,il); 
166  }
167 }
168 ///////////////////////////////////////////////////////////////////////////
169 void AliSignal::Reset(Int_t mode)
170 {
171 // Reset all signal and position values and errors to 0.
172 //
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.
178 //
179 // The default when invoking Reset() corresponds to mode=0.
180 //
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.
183 //
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.
191 //
192 // For more specific actions see ResetPosition(), ResetSignals(),
193 // DeleteSignals(), ResetGain(), ResetOffset() and DeleteCalibrations().
194 //
195
196  if (mode<0 || mode>1)
197  {
198   cout << " *AliSignal::Reset* Invalid argument mode = " << mode << endl;
199   cout << " Default mode=0 will be used." << endl;
200   mode=0;
201  }
202
203  ResetPosition();
204  if (!mode)
205  {
206   ResetSignals();
207  }
208  else
209  {
210   DeleteSignals();
211   DeleteCalibrations();
212  }
213
214  if (fLinks)
215  {
216   delete fLinks;
217   fLinks=0;
218  }
219 }
220 ///////////////////////////////////////////////////////////////////////////
221 void AliSignal::ResetSignals(Int_t mode)
222 {
223 // Reset various signal data according to user selection.
224 //
225 // mode = 0 Reset all signal values and their errors to 0.
226 //        1 Reset only signal values
227 //        2 Reset only signal errors
228 //
229 // The default when invoking ResetSignals() corresponds to mode=0.
230 //
231 // Irrespective of the mode, the waveform histograms are reset.
232
233  if (mode<0 || mode>2)
234  {
235   cout << " *AliSignal::ResetSignals* Invalid argument mode = " << mode << endl;
236   cout << " Default mode=0 will be used." << endl;
237   mode=0;
238  }
239
240  if (fSignals && (mode==0 || mode==1))
241  {
242   for (Int_t i=0; i<fSignals->GetSize(); i++)
243   {
244    fSignals->AddAt(0,i);
245   }
246  }
247
248  if (fDsignals && (mode==0 || mode==2))
249  {
250   for (Int_t j=0; j<fDsignals->GetSize(); j++)
251   {
252    fDsignals->AddAt(0,j);
253   }
254  }
255
256  ResetWaveform(0);
257 }
258 ///////////////////////////////////////////////////////////////////////////
259 void AliSignal::DeleteSignals(Int_t mode)
260 {
261 // Delete storage arrays of various signal data according to user selection.
262 //
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
266 //
267 // The default when invoking DeleteSignals() corresponds to mode=0.
268 //
269 // Irrespective of the mode, the waveform histograms are deleted.
270
271  if (mode<0 || mode>2)
272  {
273   cout << " *AliSignal::DeleteSignals* Invalid argument mode = " << mode << endl;
274   cout << " Default mode=0 will be used." << endl;
275   mode=0;
276  }
277
278  if (fSignals && (mode==0 || mode==1))
279  {
280   delete fSignals;
281   fSignals=0;
282  }
283
284  if (fDsignals && (mode==0 || mode==2))
285  {
286   delete fDsignals;
287   fDsignals=0;
288  }
289
290  DeleteWaveform(0);
291 }
292 ///////////////////////////////////////////////////////////////////////////
293 void AliSignal::SetSignal(Double_t sig,Int_t j)
294 {
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.
300
301  if (!fSignals)
302  {
303   fSignals=new TArrayF(j);
304   ResetSignals(1);
305  }
306
307  Int_t size=fSignals->GetSize();
308
309  if (j>size)
310  {
311   fSignals->Set(j);
312  }
313
314  fSignals->AddAt(float(sig),j-1);
315 }
316 ///////////////////////////////////////////////////////////////////////////
317 void AliSignal::AddSignal(Double_t sig,Int_t j)
318 {
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.
324
325  if (!fSignals)
326  {
327   fSignals=new TArrayF(j);
328   ResetSignals(1);
329  }
330
331  Int_t size=fSignals->GetSize();
332
333  if (j>size)
334  {
335   fSignals->Set(j);
336  }
337
338  Float_t sum=(fSignals->At(j-1))+sig;
339  fSignals->AddAt(sum,j-1);
340 }
341 ///////////////////////////////////////////////////////////////////////////
342 Float_t AliSignal::GetSignal(Int_t j,Int_t mode)
343 {
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.
348 //
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.
355 //
356 // The corrected signal (sigc) is determined as follows :
357 //
358 //              sigc=(signal/gain)-offset 
359 //
360 // The default is mode=0.
361
362  Float_t sig=0;
363  Float_t gain=1;
364  Float_t offset=0;
365  if (fSignals)
366  {
367   if (j>0 && j<=(fSignals->GetSize()))
368   {
369    sig=fSignals->At(j-1);
370
371    if (mode==0) return sig;
372
373    // Correct the signal for the gain, offset, dead flag etc...
374    if (GetDeadValue(j)) return 0;
375
376    if (GetGainFlag(j)) gain=GetGain(j);
377    if (GetOffsetFlag(j)) offset=GetOffset(j);
378
379    if (fabs(gain)>0.)
380    {
381     sig=(sig/gain)-offset;
382    }
383    else
384    {
385     sig=0;
386    }
387   }
388   else
389   {
390    cout << " *AliSignal::GetSignal* Index j = " << j << " invalid." << endl;
391   } 
392  }
393  return sig;
394 }
395 ///////////////////////////////////////////////////////////////////////////
396 void AliSignal::SetSignalError(Double_t dsig,Int_t j)
397 {
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.
403
404  if (!fDsignals)
405  {
406   fDsignals=new TArrayF(j);
407   ResetSignals(2);
408  }
409
410  Int_t size=fDsignals->GetSize();
411
412  if (j>size)
413  {
414   fDsignals->Set(j);
415  }
416
417  fDsignals->AddAt(float(dsig),j-1);
418 }
419 ///////////////////////////////////////////////////////////////////////////
420 Float_t AliSignal::GetSignalError(Int_t j)
421 {
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.
425  Float_t err=0;
426  if (fDsignals)
427  {
428   if (j>0 && j<=(fDsignals->GetSize()))
429   {
430    err=fDsignals->At(j-1);
431   }
432   else
433   {
434    cout << " *AliSignal::GetSignalError* Index j = " << j << " invalid." << endl;
435   } 
436  }
437  return err;
438 }
439 ///////////////////////////////////////////////////////////////////////////
440 void AliSignal::Data(TString f)
441 {
442 // Provide all signal information within the coordinate frame f.
443
444  const char* name=GetName();
445  const char* title=GetTitle();
446
447  cout << " *" << ClassName() << "::Data*";
448  if (strlen(name))  cout << " Name : " << name;
449  if (strlen(title)) cout << " Title : " << title;
450  cout << endl;
451  cout << " Position";
452  Ali3Vector::Data(f);
453
454  List(-1);
455
456 ///////////////////////////////////////////////////////////////////////////
457 void AliSignal::List(Int_t j)
458 {
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.
464
465  if (j<-1) 
466  {
467   cout << " *AliSignal::List* Invalid argument j = " << j << endl;
468   return;
469  }
470
471  if (j != -1)
472  {
473   const char* name=GetName();
474   const char* title=GetTitle();
475
476   cout << " *" << ClassName() << "::Data*";
477   if (strlen(name))  cout << " Name : " << name;
478   if (strlen(title)) cout << " Title : " << title;
479   cout << endl;
480  }
481
482  Int_t nvalues=GetNvalues();
483  Int_t nerrors=GetNerrors();
484  Int_t nwforms=GetNwaveforms();
485  Int_t nlinks=GetNlinks();
486  Int_t n=nvalues;
487  if (nerrors>n) n=nerrors;
488  if (nwforms>n) n=nwforms;
489  if (nlinks>n) n=nlinks;
490
491  TObject* obj=0;
492
493  if (j<=0)
494  {
495   for (Int_t i=1; i<=n; i++)
496   {
497    cout << "   Signal";
498    if (i<=nvalues) cout << " value : " << GetSignal(i);
499    if (i<=nerrors) cout << " error : " << GetSignalError(i);
500    AliAttrib::List(i);
501    cout << endl;
502    obj=GetWaveform(i);
503    if (obj)
504    {
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;
510     cout << endl;
511    }
512    obj=GetLink(i);
513    if (obj)
514    {
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;
520     cout << endl;
521    }
522   }
523  }
524  else
525  {
526   if (j<=n)
527   {
528    cout << "   Signal";
529    if (j<=nvalues) cout << " value : " << GetSignal(j);
530    if (j<=nerrors) cout << " error : " << GetSignalError(j);
531    AliAttrib::List(j);
532    cout << endl;
533    obj=GetWaveform(j);
534    if (obj)
535    {
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;
541     cout << endl;
542    }
543    obj=GetLink(j);
544    if (obj)
545    {
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;
551     cout << endl;
552    }
553   }
554  }
555
556 ///////////////////////////////////////////////////////////////////////////
557 Int_t AliSignal::GetNvalues()
558 {
559 // Provide the number of values for this signal.
560  Int_t n=0;
561  if (fSignals) n=fSignals->GetSize();
562  return n;
563 }
564 ///////////////////////////////////////////////////////////////////////////
565 Int_t AliSignal::GetNerrors()
566 {
567 // Provide the number specified errors on the values for this signal.
568  Int_t n=0;
569  if (fDsignals) n=fDsignals->GetSize();
570  return n;
571 }
572 ///////////////////////////////////////////////////////////////////////////
573 Int_t AliSignal::GetNwaveforms()
574 {
575 // Provide the number specified waveforms for this signal.
576  Int_t n=0;
577  if (fWaveforms) n=fWaveforms->GetSize();
578  return n;
579 }
580 ///////////////////////////////////////////////////////////////////////////
581 TH1F* AliSignal::GetWaveform(Int_t j)
582 {
583 // Provide pointer to the j-th waveform histogram.
584  TH1F* waveform=0;
585  if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
586  return waveform;
587 }
588 ///////////////////////////////////////////////////////////////////////////
589 void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
590 {
591 // Set the 1D waveform histogram corresponding to the j-th signal value.
592 //
593 // Notes :
594 //  The waveform of the first signal value is at j=1.
595 //  j=1 is the default value.
596 //
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.
600 //
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.
604 //
605 // In case the histo pointer argument is zero, the current waveform histogram
606 // is deleted and the pointer set to zero.
607 //
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
610 // histogram.
611
612  if (!fWaveforms)
613  {
614   fWaveforms=new TObjArray(j);
615   fWaveforms->SetOwner();
616  }
617
618  if (j > fWaveforms->GetSize()) fWaveforms->Expand(j);
619
620  TH1F* hcur=(TH1F*)fWaveforms->At(j-1);
621  if (waveform != hcur)
622  {
623   if (hcur)
624   {
625    fWaveforms->Remove(hcur);
626    delete hcur;
627    hcur=0;
628   }
629   if (waveform)
630   {
631    hcur=new TH1F(*waveform);
632    fWaveforms->AddAt(hcur,j-1);
633   }
634  } 
635 }
636 ///////////////////////////////////////////////////////////////////////////
637 void AliSignal::ResetWaveform(Int_t j)
638 {
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.
644  
645  if (!fWaveforms) return;
646
647  Int_t size=fWaveforms->GetSize();
648
649  if ((j>=0) && (j<=size))
650  {
651   if (j)
652   {
653    TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
654    if (hwave) hwave->Reset();
655   }
656   else
657   {
658    for (Int_t i=0; i<size; i++)
659    {
660     TH1F* hwave=(TH1F*)fWaveforms->At(i);
661     if (hwave) hwave->Reset();
662    }
663   }
664  }
665  else
666  {
667   cout << " *AliSignal::ResetWaveform* Index j = " << j << " invalid." << endl;
668   return;
669  }
670 }
671 ///////////////////////////////////////////////////////////////////////////
672 void AliSignal::DeleteWaveform(Int_t j)
673 {
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.
677  
678  if (!fWaveforms) return;
679
680  Int_t size=fWaveforms->GetSize();
681
682  if ((j>=0) && (j<=size))
683  {
684   if (j)
685   {
686    TH1F* hwave=(TH1F*)fWaveforms->At(j-1);
687    if (hwave)
688    {
689     fWaveforms->Remove(hwave);
690     delete hwave;
691    }
692   }
693   else
694   {
695    delete fWaveforms;
696    fWaveforms=0;
697   }
698  }
699  else
700  {
701   cout << " *AliSignal::DeleteWaveform* Index j = " << j << " invalid." << endl;
702   return;
703  }
704 }
705 ///////////////////////////////////////////////////////////////////////////
706 Int_t AliSignal::GetNlinks()
707 {
708 // Provide the highest slot number with a specified link for this signal.
709  Int_t n=0;
710  if (fLinks) n=fLinks->GetSize();
711  return n;
712 }
713 ///////////////////////////////////////////////////////////////////////////
714 TObject* AliSignal::GetLink(Int_t j)
715 {
716 // Provide pointer of the object linked to the j-th slot.
717  TObject* obj=0;
718  if (j <= GetNlinks()) obj=fLinks->At(j-1);
719  return obj;
720 }
721 ///////////////////////////////////////////////////////////////////////////
722 void AliSignal::SetLink(TObject* obj,Int_t j)
723 {
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.
728 //
729 // Notes :
730 //  The link of the first slot is at j=1.
731 //  j=1 is the default value.
732 //
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).
736 //
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).
739 //
740 // In principle any object derived from TObject can be referred to by this
741 // mechanism.
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.
748 // 
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. 
751
752  if (!fLinks && obj)
753  {
754   fLinks=new TObjArray(j);
755  }
756
757  if (j>fLinks->GetSize() && obj) fLinks->Expand(j);
758
759  if (j<=fLinks->GetSize())
760  {
761   fLinks->AddAt(obj,j-1);
762   if (obj) 
763   {
764    if (obj->InheritsFrom("AliTrack"))
765    {
766     AliTrack* t=(AliTrack*)obj;
767     t->AddSignal(*this);
768    }
769   }
770  }
771 }
772 ///////////////////////////////////////////////////////////////////////////
773 void AliSignal::ResetLink(Int_t j)
774 {
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.
778 //
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.
790  
791  if (!fLinks || j<0) return;
792
793  TObject* obj=0;
794
795  if (j)
796  {
797   SetLink(obj,j);
798  }
799  else
800  {
801   delete fLinks;
802   fLinks=0;
803  }
804 }
805 ///////////////////////////////////////////////////////////////////////////
806 void AliSignal::ResetLink(TObject* obj)
807 {
808 // Reset the link of the all the slots referring to the specified object.
809 //
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.
821  
822  if (!fLinks || !obj) return;
823
824  Int_t nlinks=GetNlinks();
825  for (Int_t i=1; i<=nlinks; i++)
826  {
827   TObject* obj2=GetLink(i);
828   if (obj2==obj) ResetLink(i);
829  }
830 }
831 ///////////////////////////////////////////////////////////////////////////
832 TObject* AliSignal::Clone(char* name)
833 {
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. 
841
842  AliSignal* sig=new AliSignal(*this);
843  if (name)
844  {
845   if (strlen(name)) sig->SetName(name);
846  }
847  return sig;
848 }
849 ///////////////////////////////////////////////////////////////////////////