// Class AliSignal
// Generic handling of (extrapolated) detector signals.
//
+// The user can decide to store either calibrated or uncalibrated signals.
+// Via the specification of a gain and offset or/and an explicit
+// (de)calibration function both calibrated and uncalibrated signals
+// can always be obtained. For details see the documentation of the
+// memberfunction GetSignal() and the class AliAttrib.
+// The explicit specification of a (de)calibration function offers the
+// maximum flexibility and also allows automatic indication whether
+// calibrated or uncalibrated data has been stored.
+// The latter can be achieved by only specifying a calibration function
+// (and no de-calibration function) in case uncalibrated data is stored,
+// whereas in case of stored calibrated data the user should only
+// provide a de-calibration function (and no calibration function).
+//
// Note :
// ------
// Signal positions (r) and reference frames (f) are specified via
// signal=82.5; // e.g. signal time in ns
// error=2.01;
// offset=0.003;
-// q.SetSlotName("TOF");
+// q.SetSlotName("TOF",1);
// q.SetSignal(signal,1);
// q.SetSignalError(error,1);
// q.SetOffset(offset,1);
// signal=268.1; // e.g. ADC value of signal
// error=3.75;
// gain=120.78;
+// offset=1.5732;
// // Addressing via name specification instead of index
-// q.SetSlotName("ADC");
+// q.SetSlotName("ADC",2);
// q.SetSignal(signal,"ADC");
// q.SetSignalError(error,"ADC");
// q.SetGain(gain,"ADC");
+// q.SetOffset(offset,"ADC");
// signal=23.7; // e.g. corresponding dE/dx value
// error=0.48;
-// offset=0.2;
-// gain=150;
-// q.SetSlotName("dE/dx");
-// q.SetSignal(signal,3);
-// q.SetSignalError(error,3);
-// q.SetOffset(offset,3);
-// q.SetGain(gain,3);
-//
-// Float_t dedx=q.GetSignal("dE/dx");
+// TF1 f=("calib","[0]*pow(x,2)+[1]"); // dE/dx calib. function
+// f.SetParameter(0,3.285);
+// f.SetParameter(1,-18.67);
+// q.SetSlotName("dE/dx",3);
+// q.SetCalFunction(&f,"dE/dx");
+// q.SetSignal(signal,"dE/dx");
+// q.SetSignalError(error,"dE/dx");
+//
+// // Signal retrieval with various (de)calibration modes
+// Float_t tof=q.GetSignal("TOF");
+// Float_t adc=q.GetSignal("ADC",1);
+// Float_t dedx=q.GetSignal("dE/dx",3);
//
//--- Author: Nick van Eijndhoven 23-jan-1999 UU-SAP Utrecht
//- Modified: NvE $Date$ UU-SAP Utrecht
}
if (fLinks)
{
+ // Remove this signal from all related tracks
+ for (Int_t i=1; i<=fLinks->GetNobjects(); i++)
+ {
+ TObject* obj=fLinks->GetObject(i);
+ if (!obj) continue;
+ if (obj->InheritsFrom("AliTrack"))
+ {
+ AliTrack* tx=(AliTrack*)obj;
+ tx->RemoveSignal(*this);
+ }
+ }
delete fLinks;
fLinks=0;
}
{
// Provide signal value of the j-th (default j=1) slot.
// Note : The first signal slot is at j=1.
-// In case no signal is present or the argument j is invalid, 0 is returned.
-// The parameter "mode" allows for automatic gain etc... correction of the signal.
+// In case no signal is present or the input argument "j" or "mode" is invalid,
+// the value 0 is returned.
+// The parameter "mode" allows for automatic (de)calibration of the signal
+// (e.g. gain etc... correction or via explicit (de)calibration functions).
//
// mode = 0 : Just the j-th signal is returned.
// 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
+// In case the j-th slot was marked dead, 0 is returned.
// In case the gain value was not set, gain=1 will be assumed.
// In case the gain value was 0, a signal value of 0 is returned.
// In case the offset value was not set, offset=0 will be assumed.
+// 2 : Same as mode=1 but gain, offset dead flag etc... are taken from
+// the AliDevice which owns this AliSignal object.
+// The corresponding AliDevice slot is obtained via matching of
+// the slotnames. In case this fails, the slotindex "j" of the
+// input argument will be used.
+// In case this AliSignal object has no parent AliDevice, just
+// the j-th signal is returned (like with mode=0).
+// 3 : The j-th signal is corrected using the corresponding calibration
+// function.
// In case the j-th slot was marked dead, 0 is returned.
+// In case no calibration function is present, just the j-th signal
+// is returned (like with mode=0).
+// 4 : Same as mode=3 but the calibration function and dead flag are
+// taken from the AliDevice which owns this AliSignal object.
+// The corresponding AliDevice slot is obtained via matching of
+// the slotnames. In case this fails, the slotindex "j" of the
+// input argument will be used.
+// 5 : Same as mode=2 but in case no parent AliDevice is present
+// an automatic switch to mode=1 will be made.
+// 6 : Same as mode=4 but in case no parent AliDevice is present
+// an automatic switch to mode=3 will be made.
+// 7 : Same as mode=3 but in case no calibration function is present
+// an automatic switch to mode=4 will be made.
+// 8 : Same as mode=7 but also the corresponding dead flag of the
+// parent device (if any) will be checked.
+// If either the dead flag of the requested signal slot of this
+// AliSignal object or the corresponding parent device slot is
+// set, 0 is returned.
+//
+// <0 : The corresponding de-correction or de-calibration is performed
//
// The corrected signal (sigc) is determined as follows :
//
// sigc=(signal/gain)-offset
//
+// The de-corrected signal is determined as follows :
+//
+// signal=(sigc+offset)*gain
+//
// The default is mode=0.
+ if (abs(mode)>8) return 0;
+
+ Int_t jcal=j;
Float_t sig=0;
Float_t gain=1;
Float_t offset=0;
+
+ // Get the corresponding slot index (and dead flag) of the parent device
+ Int_t pj=0;
+ Int_t pdead=0;
+ AliSignal* parent=(AliSignal*)GetDevice();
+ if ((abs(mode)==2 || abs(mode)>=4) && parent)
+ {
+ TString name=GetSlotName(j);
+ if (strlen(name.Data())) pj=parent->GetSlotIndex(name);
+ if (abs(mode)==8 && pj) pdead=parent->GetDeadValue(pj);
+ }
+ if (mode==8) mode=7;
+ if (mode==-8) mode=-7;
+
+ AliSignal* sx=(AliSignal*)this;
+
+ TF1* f=0;
+ if (mode==7)
+ {
+ f=sx->GetCalFunction(jcal);
+ if (f)
+ {
+ mode=3;
+ }
+ else
+ {
+ mode=4;
+ }
+ }
+ if (mode==-7)
+ {
+ f=sx->GetDecalFunction(jcal);
+ if (f)
+ {
+ mode=-3;
+ }
+ else
+ {
+ mode=-4;
+ }
+ }
+
+ if (abs(mode)==2 || abs(mode)>=4)
+ {
+ sx=(AliSignal*)GetDevice();
+ if (pj) jcal=pj;
+ }
+ if (!sx && abs(mode)>=5) sx=(AliSignal*)this;
+ if (mode==5) mode=2;
+ if (mode==-5) mode=-2;
+ if (mode==6) mode=3;
+ if (mode==-6) mode=-3;
+
if (fSignals)
{
if (j>0 && j<=(fSignals->GetSize()))
{
sig=fSignals->At(j-1);
- if (mode==0) return sig;
-
- // Correct the signal for the gain, offset, dead flag etc...
- if (GetDeadValue(j)) return 0;
+ if (mode==0 || !sx) return sig;
- if (GetGainFlag(j)) gain=GetGain(j);
- if (GetOffsetFlag(j)) offset=GetOffset(j);
+ // Check for the dead flag setting
+ if (sx->GetDeadValue(jcal) || pdead) return 0;
- if (fabs(gain)>0.)
+ // (De)correct the signal for the gain and offset
+ if (abs(mode)==1 || abs(mode)==2)
{
- sig=(sig/gain)-offset;
+ if (sx->GetGainFlag(jcal)) gain=sx->GetGain(jcal);
+ if (sx->GetOffsetFlag(jcal)) offset=sx->GetOffset(jcal);
+
+ if (fabs(gain)>0.)
+ {
+ if (mode>0) sig=(sig/gain)-offset; // Gain and offset correction
+ if (mode<0) sig=(sig+offset)*gain; // Gain and offset de-correction
+ }
+ else
+ {
+ sig=0;
+ }
+ return sig;
}
- else
+
+ // (De)calibrate the signal with the corresponding (de)calibration function
+ if (abs(mode)==3 || abs(mode)==4)
{
- sig=0;
+ f=sx->GetCalFunction(jcal);
+ if (mode<0) f=sx->GetDecalFunction(jcal);
+ if (f) sig=f->Eval(sig);
+ return sig;
}
}
else
{
// Provide signal value of the name-specified slot.
// In case no signal is present, 0 is returned.
-// The parameter "mode" allows for automatic gain etc... correction of the signal.
-//
-// mode = 0 : Just the j-th signal is returned.
-// 1 : The j-th signal is corrected for the gain, offset, dead flag etc...
-// In case the gain value was not set, gain=1 will be assumed.
-// In case the gain value was 0, a signal value of 0 is returned.
-// In case the offset value was not set, offset=0 will be assumed.
-// In case the j-th slot was marked dead, 0 is returned.
-//
-// The corrected signal (sigc) is determined as follows :
-//
-// sigc=(signal/gain)-offset
+// The parameter "mode" allows for automatic (de)calibration of the signal
+// (e.g. gain etc... correction or via explicit (de)calibration functions).
+// For further details about the (de)calibration modes, please refer to the
+// corresponding slot-index based memberfunction.
//
// The default is mode=0.
//
return val;
}
///////////////////////////////////////////////////////////////////////////
-void AliSignal::Data(TString f) const
+void AliSignal::Data(TString f,TString u) const
{
// Provide all signal information within the coordinate frame f.
+//
+// The string argument "u" allows to choose between different angular units
+// in case e.g. a spherical frame is selected.
+// u = "rad" : angles provided in radians
+// "deg" : angles provided in degrees
+//
+// The defaults are f="car" and u="rad".
const char* name=GetName();
const char* title=GetTitle();
- cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
+ cout << " *" << ClassName() << "::Data* Id : " << GetUniqueID();
if (strlen(name)) cout << " Name : " << name;
if (strlen(title)) cout << " Title : " << title;
cout << endl;
cout << " Position";
- Ali3Vector::Data(f);
+ AliPosition::Data(f,u);
if (fDevice)
{
const char* devname=fDevice->GetName();
const char* devtitle=fDevice->GetTitle();
- cout << " Owned by device : " << fDevice->ClassName();
+ cout << " Owned by device : " << fDevice->ClassName()
+ << " Id : " << fDevice->GetUniqueID();
if (strlen(devname)) cout << " Name : " << devname;
if (strlen(devtitle)) cout << " Title : " << devtitle;
cout << endl;
}
+ // Provide an overview of the stored waveforms
+ ListWaveform(-1);
+
+ // Provide an overview of all the data and attribute slots
List(-1);
}
///////////////////////////////////////////////////////////////////////////
const char* name=GetName();
const char* title=GetTitle();
- cout << " *" << ClassName() << "::Data*";
+ cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
if (strlen(name)) cout << " Name : " << name;
if (strlen(title)) cout << " Title : " << title;
cout << endl;
+ if (fDevice)
+ {
+ const char* devname=fDevice->GetName();
+ const char* devtitle=fDevice->GetTitle();
+ cout << " Owned by device : " << fDevice->ClassName();
+ if (strlen(devname)) cout << " Name : " << devname;
+ if (strlen(devtitle)) cout << " Title : " << devtitle;
+ cout << endl;
+ }
}
Int_t nvalues=GetNvalues();
Int_t nerrors=GetNerrors();
- Int_t nwforms=GetNwaveforms();
Int_t nlinkslots=0;
if (fLinks) nlinkslots=fLinks->GetMaxColumn();
+ Int_t ncalibs=GetNcalflags();
+ Int_t ncalfuncs=GetNcalfuncs();
+ Int_t ndecalfuncs=GetNdecalfuncs();
+
Int_t n=nvalues;
if (nerrors>n) n=nerrors;
- if (nwforms>n) n=nwforms;
if (nlinkslots>n) n=nlinkslots;
-
+ if (InheritsFrom("AliDevice"))
+ {
+ if (ncalibs>n) n=ncalibs;
+ if (ncalfuncs>n) n=ncalfuncs;
+ if (ndecalfuncs>n) n=ndecalfuncs;
+ }
+
TObject* obj=0;
Int_t nrefs=0;
TArrayI posarr;
if (i<=nerrors) cout << " error : " << GetSignalError(i);
AliAttrib::List(i);
cout << endl;
- obj=GetWaveform(i);
- if (obj)
- {
- const char* wfname=obj->GetName();
- const char* wftitle=obj->GetTitle();
- cout << " Waveform : " << obj->ClassName();
- if (strlen(wfname)) cout << " Name : " << wfname;
- if (strlen(wftitle)) cout << " Title : " << wftitle;
- cout << endl;
- }
obj=0;
nrefs=GetIndices(obj,i,posarr);
for (Int_t k=0; k<nrefs; k++)
if (j<=nerrors) cout << " error : " << GetSignalError(j);
AliAttrib::List(j);
cout << endl;
- obj=GetWaveform(j);
- if (obj)
- {
- const char* wfnamej=obj->GetName();
- const char* wftitlej=obj->GetTitle();
- cout << " Waveform : " << obj->ClassName();
- if (strlen(wfnamej)) cout << " Name : " << wfnamej;
- if (strlen(wftitlej)) cout << " Title : " << wftitlej;
- cout << endl;
- }
obj=0;
nrefs=GetIndices(obj,j,posarr);
for (Int_t kj=0; kj<nrefs; kj++)
if (j>0) List(j);
}
///////////////////////////////////////////////////////////////////////////
+void AliSignal::ListWaveform(Int_t j) const
+{
+// Provide information for the j-th waveform.
+// The first waveform is at j=1.
+// In case j=0 (default) the info of all waveforms will be listed.
+// In case j=-1 the info of all waveforms will be listed, but the header
+// information will be suppressed.
+
+ if (j<-1)
+ {
+ cout << " *AliSignal::ListWaveform* Invalid argument j = " << j << endl;
+ return;
+ }
+
+ if (j != -1)
+ {
+ const char* name=GetName();
+ const char* title=GetTitle();
+
+ cout << " *" << ClassName() << "::Data* Id :" << GetUniqueID();
+ if (strlen(name)) cout << " Name : " << name;
+ if (strlen(title)) cout << " Title : " << title;
+ cout << endl;
+ if (fDevice)
+ {
+ const char* devname=fDevice->GetName();
+ const char* devtitle=fDevice->GetTitle();
+ cout << " Owned by device : " << fDevice->ClassName();
+ if (strlen(devname)) cout << " Name : " << devname;
+ if (strlen(devtitle)) cout << " Title : " << devtitle;
+ cout << endl;
+ }
+ }
+
+ Int_t n=GetNwaveforms();
+ TObject* obj=0;
+
+ if (j<=0)
+ {
+ for (Int_t i=1; i<=n; i++)
+ {
+ obj=GetWaveform(i);
+ if (obj)
+ {
+ const char* wfname=obj->GetName();
+ const char* wftitle=obj->GetTitle();
+ cout << " Waveform " << i << " : " << obj->ClassName();
+ if (strlen(wfname)) cout << " Name : " << wfname;
+ if (strlen(wftitle)) cout << " Title : " << wftitle;
+ cout << endl;
+ }
+ }
+ }
+ else
+ {
+ if (j<=n)
+ {
+ obj=GetWaveform(j);
+ if (obj)
+ {
+ const char* wfnamej=obj->GetName();
+ const char* wftitlej=obj->GetTitle();
+ cout << " Waveform " << j << " : " << obj->ClassName();
+ if (strlen(wfnamej)) cout << " Name : " << wfnamej;
+ if (strlen(wftitlej)) cout << " Title : " << wftitlej;
+ cout << endl;
+ }
+ }
+ }
+}
+///////////////////////////////////////////////////////////////////////////
Int_t AliSignal::GetNvalues() const
{
// Provide the number of values for this signal.
///////////////////////////////////////////////////////////////////////////
Int_t AliSignal::GetNwaveforms() const
{
-// Provide the number specified waveforms for this signal.
- Int_t n=0;
- if (fWaveforms) n=fWaveforms->GetSize();
- return n;
+// Provide the number of specified waveforms for this signal.
+// Actually the return value is the highest index of the stored waveforms.
+// This allows an index dependent meaning of waveform info (e.g. waveforms
+// with various gain values).
+// So, when all waveforms are stored in consequetive positions (e.g. 1,2,3),
+// this memberfunction returns 3, being both the highest filled position
+// and the actual number of waveforms.
+// In case only waveforms are stored at positions 1,2,5,7 this memberfunction
+// returns a value 7 whereas only 4 actual waveforms are present.
+// This implies that when looping over the various waveform slots, one
+// always has to check whether the returned pointer value is non-zero
+// (which is a good practice anyhow).
+ Int_t n=-1;
+ if (fWaveforms) n=fWaveforms->GetLast();
+ return (n+1);
}
///////////////////////////////////////////////////////////////////////////
TH1F* AliSignal::GetWaveform(Int_t j) const
{
-// Provide pointer to the waveform histogram of the j-th slot.
+// Provide pointer to the j-th waveform histogram.
TH1F* waveform=0;
if (j <= GetNwaveforms()) waveform=(TH1F*)fWaveforms->At(j-1);
return waveform;
///////////////////////////////////////////////////////////////////////////
TH1F* AliSignal::GetWaveform(TString name) const
{
-// Provide pointer to the waveform histogram of the name-specified slot.
-//
-// This procedure involves a slot-index search based on the specified name
-// at each invokation. This may become slow in case many slots have been
-// defined and/or when this procedure is invoked many times.
-// In such cases it is preferable to use indexed addressing in the user code
-// either directly or via a few invokations of GetSlotIndex().
-
- Int_t j=GetSlotIndex(name);
- TH1F* waveform=0;
- if (j>0) waveform=GetWaveform(j);
- return waveform;
+// Provide pointer to the waveform histogram with the specified name.
+// In case no match is found, zero is returned.
+ Int_t n=GetNwaveforms();
+ TString str;
+ for (Int_t i=1; i<=n; i++)
+ {
+ TH1F* waveform=GetWaveform(i);
+ if (waveform)
+ {
+ str=waveform->GetName();
+ if (str == name) return waveform;
+ }
+ }
+ return 0; // No match found
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliSignal::GetWaveformIndex(TString name) const
+{
+// Provide index to the waveform histogram with the specified name.
+// In case no match is found, zero is returned.
+ Int_t n=GetNwaveforms();
+ TString str;
+ for (Int_t i=1; i<=n; i++)
+ {
+ TH1F* waveform=GetWaveform(i);
+ if (waveform)
+ {
+ str=waveform->GetName();
+ if (str == name) return i;
+ }
+ }
+ return 0; // No match found
}
///////////////////////////////////////////////////////////////////////////
void AliSignal::SetWaveform(TH1F* waveform,Int_t j)
{
-// Set the 1D waveform histogram for the j-th slot.
+// Set the 1D waveform histogram for the j-th waveform.
//
// Notes :
-// The waveform of the first signal value is at j=1.
+// The first waveform position at j=1.
// j=1 is the default value.
//
// In case the value of the index j exceeds the maximum number of reserved
-// slots for the waveforms, the number of reserved slots for the waveforms
+// positions for the waveforms, the number of reserved positions for the waveforms
// is increased automatically.
//
// In case the histo pointer argument has the same value as the current waveform
// copy of the input histogram is created which becomes the current waveform
// histogram.
+ if (j<1) return;
+
if (!fWaveforms)
{
fWaveforms=new TObjArray(j);
}
}
///////////////////////////////////////////////////////////////////////////
-void AliSignal::SetWaveform(TH1F* waveform,TString name)
-{
-// Set the 1D waveform histogram corresponding for the name-specified slot.
-//
-// This procedure involves a slot-index search based on the specified name
-// at each invokation. This may become slow in case many slots have been
-// defined and/or when this procedure is invoked many times.
-// In such cases it is preferable to use indexed addressing in the user code
-// either directly or via a few invokations of GetSlotIndex().
-
- Int_t j=GetSlotIndex(name);
- if (j>0) SetWaveform(waveform,j);
-}
-///////////////////////////////////////////////////////////////////////////
void AliSignal::ResetWaveform(Int_t j)
{
-// Reset the waveform of the j-th (default j=1) slot.
+// Reset the histogram of the j-th (default j=1) waveform.
// This memberfunction invokes TH1F::Reset() for the corresponding waveform(s).
// To actually delete the histograms from memory, use DeleteWaveform().
-// Notes : The first signal value is at j=1.
+// Notes : The first position is at j=1.
// j=0 ==> All waveforms will be reset.
if (!fWaveforms) return;
///////////////////////////////////////////////////////////////////////////
void AliSignal::ResetWaveform(TString name)
{
-// Reset the waveform of the name-specified slot.
-//
-// This procedure involves a slot-index search based on the specified name
-// at each invokation. This may become slow in case many slots have been
-// defined and/or when this procedure is invoked many times.
-// In such cases it is preferable to use indexed addressing in the user code
-// either directly or via a few invokations of GetSlotIndex().
-
- Int_t j=GetSlotIndex(name);
+// Reset the waveform with the specified name.
+ Int_t j=GetWaveformIndex(name);
if (j>0) ResetWaveform(j);
}
///////////////////////////////////////////////////////////////////////////
void AliSignal::DeleteWaveform(Int_t j)
{
-// Delete the waveform of the j-th (default j=1) slot.
-// Notes : The first signal value is at j=1.
+// Delete the histogram of the j-th (default j=1) waveform.
+// Notes : The first position is at j=1.
// j=0 ==> All waveforms will be deleted.
if (!fWaveforms) return;
///////////////////////////////////////////////////////////////////////////
void AliSignal::DeleteWaveform(TString name)
{
-// Delete the waveform of the name-specified slot.
-//
-// This procedure involves a slot-index search based on the specified name
-// at each invokation. This may become slow in case many slots have been
-// defined and/or when this procedure is invoked many times.
-// In such cases it is preferable to use indexed addressing in the user code
-// either directly or via a few invokations of GetSlotIndex().
-
- Int_t j=GetSlotIndex(name);
+// Delete the waveform with the specified name.
+ Int_t j=GetWaveformIndex(name);
if (j>0) DeleteWaveform(j);
}
///////////////////////////////////////////////////////////////////////////