KaliVeda
Toolkit for HIC analysis
KVEventClassifier.cpp
1 #include "KVEventClassifier.h"
2 
3 
5 
7 {
8  double value_to_test;
9  if (fWithExpression) {
10  int nval = 0;
11  for (auto& p : fValues) {
12  fFormula->SetParameter(nval, fVar->GetValue(p.c_str()));
13  ++nval;
14  }
15  value_to_test = fFormula->Eval(0);
16  }
17  else if (fWithVal) {
18  value_to_test = fVar->GetValue(fVal);
19  }
20  else {
21  value_to_test = fVar->GetValue();
22  }
23  if (fIntegerVariable) {
24  value_to_test = value_to_test + gRandom->Uniform();
25  }
26  std::vector<double>::const_iterator result = std::find_if(fCuts.begin(), fCuts.end(),
27  [value_to_test](double x) {
28  return x > value_to_test;
29  }
30  );
31  return std::distance(fCuts.begin(), result);
32 }
33 
34 
35 
40 
42 {
43  // Sort cuts/bins into ascending order
44  //
45  // Also set up TFormula if we need to use an expression
46 
47  fIntegerVariable = false;
48  fWithExpression = false;
49  std::sort(fCuts.begin(), fCuts.end());
50  if (fWithVal && !fVar->HasValue(fVal)) {
51  // assume fVal is an expression using the named values of the variable
52  int nval = 0;
53  for (auto& p : fVar->GetValueNameList()) {
54  if (fVal.Contains(p.GetName())) {
55  fValues.push_back(std::string(p.GetName()));
56  fVal.ReplaceAll(p.GetName(), Form("[%d]", nval));
57  ++nval;
58  }
59  }
60  if (nval) {
61  fFormula.reset(new TFormula("EC_formula", fVal));
63  }
64  else {
65  Error("Init()", "Tried to make event classifier for variable %s using expression: %s", fVar->GetName(), fVal.Data());
66  }
67  }
68  if (!fWithExpression) {
69  // using simple single-valued variable (or the default value) or 1 named value
70  // check if it is an integer value
71  if (fWithVal)
73  else
74  fIntegerVariable = (fVar->GetValueType(0) == 'I');
75  }
76 }
77 
78 
80 
81 
82 
constexpr Bool_t kTRUE
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
R__EXTERN TRandom * gRandom
char * Form(const char *fmt,...)
Simple class for sorting events according to global variables.
std::unique_ptr< TFormula > fFormula
in case a combination of values is used
bool fWithExpression
true if an expression using several values is used
std::vector< double > fCuts
cuts in variable to define event classes
std::vector< std::string > fValues
indices of values in parsed expression
bool fWithVal
true if named value given
bool fIntegerVariable
true if global variable used for cuts has integer values
KVVarGlob * fVar
variable used for event classification
TString fVal
optional name of value calculated by variable to use
const KVNameValueList & GetValueNameList() const
Definition: KVVarGlob.h:663
Double_t GetValue(void) const
Definition: KVVarGlob.h:443
Bool_t HasValue(const Char_t *name) const
Definition: KVVarGlob.h:436
Int_t GetNameIndex(const Char_t *name) const
Definition: KVVarGlob.cpp:254
virtual Char_t GetValueType(Int_t) const
Definition: KVVarGlob.h:668
const char * GetName() const override
virtual const char * GetName() const
virtual void Error(const char *method, const char *msgfmt,...) const
virtual Double_t Uniform(Double_t x1, Double_t x2)
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
TString & ReplaceAll(const char *s1, const char *s2)
Double_t x[n]
ClassImp(TPyArg)