KaliVeda
Toolkit for HIC analysis
KVEventClassifier.cpp
1 #include "KVEventClassifier.h"
2 #include "TRandom.h"
3 
4 
6 
8 {
9  double value_to_test;
10  if (fWithExpression) {
11  int nval = 0;
12  for (auto& p : fValues) {
13  fFormula->SetParameter(nval, fVar->GetValue(p.c_str()));
14  ++nval;
15  }
16  value_to_test = fFormula->Eval(0);
17  }
18  else if (fWithVal) {
19  value_to_test = fVar->GetValue(fVal);
20  }
21  else {
22  value_to_test = fVar->GetValue();
23  }
24  if (fIntegerVariable) {
25  value_to_test = value_to_test + gRandom->Uniform();
26  }
27  std::vector<double>::const_iterator result = std::find_if(fCuts.begin(), fCuts.end(),
28  [value_to_test](double x) {
29  return x > value_to_test;
30  }
31  );
32  return std::distance(fCuts.begin(), result);
33 }
34 
35 
36 
41 
43 {
44  // Sort cuts/bins into ascending order
45  //
46  // Also set up TFormula if we need to use an expression
47 
48  fIntegerVariable = false;
49  fWithExpression = false;
50  std::sort(fCuts.begin(), fCuts.end());
51  if (fWithVal && !fVar->HasValue(fVal)) {
52  // assume fVal is an expression using the named values of the variable
53  int nval = 0;
54  for (auto& p : fVar->GetValueNameList()) {
55  if (fVal.Contains(p.GetName())) {
56  fValues.push_back(std::string(p.GetName()));
57  fVal.ReplaceAll(p.GetName(), Form("[%d]", nval));
58  ++nval;
59  }
60  }
61  if (nval) {
62  fFormula.reset(new TFormula("EC_formula", fVal));
64  }
65  else {
66  Error("Init()", "Tried to make event classifier for variable %s using expression: %s", fVar->GetName(), fVal.Data());
67  }
68  }
69  if (!fWithExpression) {
70  // using simple single-valued variable (or the default value) or 1 named value
71  // check if it is an integer value
72  if (fWithVal)
74  else
75  fIntegerVariable = (fVar->GetValueType(0) == 'I');
76  }
77 }
78 
79 
81 
82 
83 
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
void Init() override
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)