4 #include "KVDetector.h"
5 #include "KVDetectorSignalExpression.h"
19 KVDetectorSignalExpression::KVDetectorSignalExpression(
const Char_t* type,
const KVString& _expr,
KVDetector* det)
37 if (expr.Contains(ds->GetName())) {
38 fSignals.push_back(ds);
39 if (!ds->
IsRaw()) fRaw = kFALSE;
40 expr.ReplaceAll(ds->GetName(), Form(
"[%d]", nsigs));
41 if (expr.CompareTo(_expr) != 0) ++nsigs;
45 fFormula.reset(
new TFormula(type, expr));
51 SetTitle(Form(
"Signal calculated as %s for detector %s", _expr.Data(), det->GetName()));
67 KVDetectorSignalExpression::KVDetectorSignalExpression(
const Char_t* type,
const KVString& _expr,
const KVSeqCollection* dets)
85 _expr.
Begin(
"+-*/()");
86 bool multidetexpr =
false;
87 bool explicit_det_reference =
false;
89 while (!_expr.
End()) {
92 if (t.Contains(
"::")) {
93 explicit_det_reference =
true;
96 auto det_label = t.
Next();
100 KVError::Error(
this,
"KVDetectorSignalExpression(const Char_t*,const KVString&,const KVSeqCollection*)",
101 "Use of reference to unknown detector with label %s in expression %s",
102 det_label.Data(), _expr.Data());
106 auto sig_name = t.
Next();
107 auto dsig = _det->GetDetectorSignal(sig_name);
108 KVString det_sig_ref = Form(
"%s::%s", det_label.Data(), sig_name.Data());
111 KVError::Error(
this,
"KVDetectorSignalExpression(const Char_t*,const KVString&,const KVSeqCollection*)",
112 "Use of reference to undefined signal %s for detector %s in expression %s : will evaluate as 0",
113 sig_name.Data(), _det->GetName(), _expr.Data());
114 expr.ReplaceAll(det_sig_ref,
"0");
117 if (expr.Contains(det_sig_ref)) {
118 expr.ReplaceAll(det_sig_ref, Form(
"[%d]", nsigs));
119 fSignals.push_back(dsig);
121 if (!dsig->IsRaw()) fRaw = kFALSE;
124 if (det && (_det != det)) multidetexpr =
true;
128 if (!explicit_det_reference) {
130 KVError::Error(
this,
"KVDetectorSignalExpression(const Char_t*,const KVString&,const KVSeqCollection*)",
131 "Expression %s must contain explicit references to detector labels",
136 fFormula.reset(
new TFormula(type, expr));
143 SetTitle(Form(
"Signal calculated as %s", _expr.Data()));
147 SetTitle(Form(
"Signal calculated as %s for detector %s", _expr.Data(), det->GetName()));
162 int nsigs = fSignals.size();
163 for (
int i = 0; i < nsigs; ++i) {
164 fFormula->SetParameter(i, fSignals[i]->
GetValue(params));
166 return fFormula->Eval(0);
void SetLabel(const Char_t *lab)
Signal output from a mathematical combination of other signals.
Double_t GetValue(const KVNameValueList ¶ms="") const override
Base class for output signal data produced by a detector.
virtual Bool_t IsRaw() const
void SetDetector(const KVDetector *d)
Base class for detector geometry description, interface to energy-loss calculations.
const KVSeqCollection & GetListOfDetectorSignals() const
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
KaliVeda extensions to ROOT collection classes.
virtual TObject * FindObjectByLabel(const Char_t *) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
void Begin(TString delim) const
KVString Next(Bool_t strip_whitespace=kFALSE) const
void Error(UserClass p, const char *location, const char *va_(fmt),...)