KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVValues.cpp
1//Created by KVClassFactory on Wed May 19 17:23:29 2010
2//Author: bonnet
3
4#include "KVValues.h"
5#include "KVNumberList.h"
6#include "KVList.h"
7
9
10
11//___________________________________________________________________________________________
12
13
19
20void KVValues::init_val_base()
21{
22//protected method
23//Mise en correspondance du noms des differentes valeurs a calculees
24//et de leur position dans le tableau values
25// Ex:
26// nom_valeurs -> id_valeurs -> values[id_valeurs]
27
28 KVString lname = "MIN MAX";
29 lname.Begin(" ");
30 kval_base = 0; //variables de base disponibles
31
32 kval_tot = 0; //nombre de variables totales disponibles
33 while (!lname.End()) {
34 KVString tamp = lname.Next();
35 SetValue(tamp.Data(), kval_tot++);
36 }
37 kdeb = kval_tot; //ici pos_deb=2 (par defaut)
38
39 KVString smoment;
40 for (Int_t mm = 0; mm <= kordre_mom_max; mm += 1) { //Ex: moment_max = 3
41 smoment.Form("SUM%d", mm);
42 SetValue(smoment.Data(), kval_tot++);
43 }
44 kval_base = kval_tot; //ici nbase=6 (par defaut)
45
46 values = new Double_t[knbre_val_max];
47 init_val();
48
49
50}
51
52
53
56
58{
59//protected method
60
61 kform_add = new KVList();
62 kpar_add = new KVList();
63
64 kval_add = 0;
65
67
68}
69
70
71
74
76{
77//protected method
78 values[GetIntValue("MIN")] = 1e6;
79 values[GetIntValue("MAX")] = -1e6;
80
81 for (Int_t nn = kdeb; nn < kval_tot; nn += 1)
82 values[nn] = 0;
83
85}
86
87
88
91
93{
94//default constructor
95}
96
97
98
101
102KVValues::KVValues(const Char_t* name, Int_t ordre_max, Int_t nbre_max)
103{
104//constructor
105 knbre_val_max = nbre_max; //nbre max de valeurs stockables
106 kordre_mom_max = ordre_max; //ordre max des moments calcules a chaque iteration
107 SetName(name); //nom correspondant aux valeurs calculees
108
110 init_val_add();
111}
112
113
114
116
118{
119
120 init_val();
122}
123
124
125
128
130{
131//destructeur
132 Clear();
133 delete [] values;
134 values = 0;
135 kval_tot = kval_base = kdeb = 0;
136}
137
138
139
140
142
144{
145
146 Reset();
147
148 delete kform_add;
149 kform_add = 0;
150 delete kpar_add;
151 kpar_add = 0;
152
153 kval_add = 0;
155
156}
157
158
159
162
164{
165 //Info("Print","%s : %d values computed",GetName(),kval_tot);
166 printf("KVValues::Print_NVL\n%s : %d values computed\n", GetName(), kval_tot);
167 for (Int_t nn = 0; nn < kval_tot; nn += 1) {
168 printf("- %d %s %lf\n", nn, GetNameAt(nn), GetValue(nn));
169 }
170}
171
172
173
175
177{
178 kpar_add->Add(nl);
179}
180
181
182
184
186{
187
188 if (min < 0) min = 0;
189 if (max == -1) max = kval_add;
190
191 KVNumberList* nl = 0;
192 TFormula* fm = 0;
193
194 for (Int_t ff = min; ff < max; ff += 1) {
195 nl = (KVNumberList*)kpar_add->At(ff);
196 fm = (TFormula*)kform_add->At(ff);
197 nl->Begin();
198 while (!nl->End()) {
199 Int_t nn = nl->Next();
200 fm->SetParameter(nn, values[nn]);
201 }
202 values[kval_tot - kval_add + ff] = fm->Eval(0);
203 }
204}
205
206
207
208
210
212{
213
214 if (HasParameter(name.Data())) {
215 Warning("DefineAdditionalValue", "le nom de variable %s est deja utilise", name.Data());
216 return;
217 }
218
219 KVString expr2 = expr;
221
222 if (nl) {
223 if (nl->IsEmpty()) {
224 Warning("DefineAdditionalValue", "la KVNumberList est vide #%s#", nl->GetList());
225 }
226 else {
227 if (AddFormula(name, expr2)) {
228 LinkParameters(nl);
230 }
231 }
232 }
233 else {
234 Error("DefineAdditionalValue", "La traduction de l'expression %s a echouee", expr.Data());
235 }
236}
237
238
239
241
243{
244
245 TFormula* fm = new TFormula(name.Data(), expr.Data());
246 if (fm->GetExpFormula().IsNull()) {
247 Warning("AddFormula", "%s considere comme nulle", expr.Data());
248 return kFALSE;
249 delete fm;
250 }
251 kform_add->Add(fm);
252 SetValue(name.Data(), kval_tot++);
253 kval_add += 1;
254 return kTRUE;
255}
256
257
258
260
262{
263
264 KVNumberList* nl = new KVNumberList();
265
266 const char* O = "[";
267 const char* F = "]";
268
270 clone.Form("%s", expr.Data());
271 const char* expression = clone.Data();
272
273 Int_t nouvert = 0, nferme = 0;
274 Int_t posouvert = 0, posferme = 0;
275 Int_t nvar = 0;
276
277 Int_t nsize = clone.Length();
278 for (Int_t ii = 0; ii <= nsize; ii += 1) {
279 if (expression[ii] == O[0]) {
280 nouvert += 1;
281 posouvert = ii;
282 }
283 else if (expression[ii] == F[0]) {
284 nferme += 1;
285 posferme = ii;
286 KVString st(clone(posouvert + 1, posferme - posouvert - 1));
287 if (st.IsDigit()) {
288 Int_t idx = st.Atoi();
289 if (0 <= idx && idx < kval_tot) {
290 nl->Add(idx);
291 nvar += 1;
292 }
293 else {
294 delete nl;
295 return 0;
296 }
297 }
298 else {
299
300 Int_t idx = GetValuePosition(st.Data());
301 if (idx == -1) {
302 delete nl;
303 return 0;
304 }
305 nl->Add(idx);
306 nvar += 1;
307 KVString s1;
308 s1.Form("[%s]", st.Data());
309 KVString s2;
310 s2.Form("[%d]", idx);
311 expr.ReplaceAll(s1, s2);
312 }
313 }
314 else {}
315 }
316
317 if (nouvert != nferme || nvar != nouvert) {
318 Error("TransformExpr", "nombre [ : %d - nombre de ] : %d - nombre de variables %d", nouvert, nferme, nvar);
319 }
320
321 return nl;
322
323}
324
325
326
328
330{
331
332 FillVar(val, 1.);
333
334}
335
336
337
339
341{
342
343 if (weight >= 0) {
344 if (val < values[0]) values[0] = val; //GetIntValue("MIN")=0
345 if (val > values[1]) values[1] = val; //GetIntValue("MAX")=1
346 }
347 for (Int_t nn = 0; nn <= kordre_mom_max; nn += 1) values[nn + kdeb] += weight * TMath::Power(val, Double_t(nn));
350}
351
352
353
355
357{
358
359 return kordre_mom_max;
360
361}
362
363
365
367{
368
370
371}
372
373
375
377{
378
379 return kdeb;
380
381}
382
383
384
386
388{
389
390 const_cast<KVValues*>(this)->ComputeAdditionalValues();
391 const_cast<KVValues*>(this)->kToBeRecalculated = kFALSE;
392 return values[idx];
393
394}
395
396
397
399
401{
402
404
405}
406
407
409
411{
412
413 return GetIntValue(name);
414
415}
416
417
418
420
422{
423
425 return GetValueExpression(idx);
426}
427
428
429
431
433{
434 Int_t new_idx = idx - kval_base;
435 if (new_idx < 0) {
436 Warning("GetValueExpression", "Cette methode n'est implementee que pour les valeurs additionelles idx > %d", kval_base);
437 return "";
438 }
439 return ((TFormula*)kform_add->At(new_idx))->GetExpFormula();
440}
441
442
443
445
447{
448 if (opt == "base") return kval_base;
449 else if (opt == "add") return kval_add;
450 else {
451 return GetNpar();
452 }
453}
454
455
456
458
460{
461 if (this->GetNValues("base") != val->GetNValues("base")) return kFALSE;
462 if (this->GetValue("MIN") > val->GetValue("MIN"))
463 values[GetValuePosition("MIN")] = val->GetValue("MIN");
464 if (this->GetValue("MAX") < val->GetValue("MAX"))
465 values[GetValuePosition("MAX")] = val->GetValue("MAX");
466
467 for (Int_t ii = kdeb; ii < this->GetNValues("base"); ii += 1) {
468 values[ii] += val->GetValue(ii);
469 }
471 return kTRUE;
472}
473
474
int Int_t
#define s1(x)
TObject * clone(const char *newname) const override
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
char name[80]
Extended TList class which owns its objects by default.
Definition KVList.h:28
Int_t GetIntValue(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
const Char_t * GetNameAt(Int_t idx) const
Int_t GetNpar() const
return the number of stored parameters
Bool_t HasParameter(const Char_t *name) const
Strings used to represent a set of ranges of values.
const Char_t * GetList() const
Bool_t End(void) const
void Begin(void) const
void Add(Int_t)
Add value 'n' to the list.
Bool_t IsEmpty() const
Int_t Next(void) const
virtual TObject * At(Int_t idx) const
virtual void Add(TObject *obj)
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
void Begin(TString delim) const
Definition KVString.cpp:565
Bool_t End() const
Definition KVString.cpp:634
KVString Next(Bool_t strip_whitespace=kFALSE) const
Definition KVString.cpp:695
Handle Operation on variable.
Definition KVValues.h:25
Int_t kval_tot
nbre total de valeurs definies kval_tot = kval_base+kval_add (=KVNameValueList::GetNpar())
Definition KVValues.h:33
void Clear(Option_t *option="")
Definition KVValues.cpp:143
Int_t GetNValues(KVString opt="base") const
Definition KVValues.cpp:446
Bool_t Add(KVValues *val)
Definition KVValues.cpp:459
KVNumberList * TransformExpression(KVString &expr)
Definition KVValues.cpp:261
Int_t kdeb
separation entre les valeurs MIN et MAX et les valeurs moments SUMd, par defaut kdeb=2
Definition KVValues.h:29
KVList * kpar_add
liste contenant les liste de parametres (stockees en KVNumberList)
Definition KVValues.h:47
void FillVar(Double_t val)
Definition KVValues.cpp:329
void Reset()
Definition KVValues.cpp:117
void LinkParameters(KVNumberList *nl)
Definition KVValues.cpp:176
void DefineAdditionalValue(KVString name, KVString expr)
Definition KVValues.cpp:211
Int_t GetShift() const
Definition KVValues.cpp:376
Double_t GetValue(Int_t idx) const
Definition KVValues.cpp:387
KVValues()
default constructor
Definition KVValues.cpp:92
Int_t GetValuePosition(const Char_t *name) const
Definition KVValues.cpp:410
Int_t kordre_mom_max
ordre maximum pour le calcul des moments (argument du constructeur)
Definition KVValues.h:36
void init_val_base()
Definition KVValues.cpp:20
Bool_t kToBeRecalculated
Definition KVValues.h:40
TString GetValueExpression(const Char_t *name) const
Definition KVValues.cpp:421
Bool_t AddFormula(KVString name, KVString expr)
Definition KVValues.cpp:242
KVList * kform_add
liste contenant les formules des variables additionnelle (stockees en TFormula)
Definition KVValues.h:46
Int_t GetNumberOfFilling() const
Definition KVValues.cpp:366
virtual ~KVValues()
destructeur
Definition KVValues.cpp:129
Int_t kval_base
nbre de valeurs de base definies par le constructeur, kval_base = kdeb+kordre_mom_max+1
Definition KVValues.h:31
void init_val_add()
protected method
Definition KVValues.cpp:57
Int_t kTimesFillVarIsCalled
nombre de fois ou la methode FillVar est appelee
Definition KVValues.h:37
void Print(Option_t *option="") const
Info("Print","%s : %d values computed",GetName(),kval_tot);.
Definition KVValues.cpp:163
void init_val()
protected method
Definition KVValues.cpp:75
Int_t GetOrdreMax() const
Definition KVValues.cpp:356
Int_t kval_add
nbre de valeurs additionelles definies via la methode DefineAdditionalValue
Definition KVValues.h:32
void ComputeAdditionalValues(Int_t min=-1, Int_t max=-1)
Definition KVValues.cpp:185
Int_t knbre_val_max
nombre maximum de valeurs pouvant etre calculees (argument du constructeur)
Definition KVValues.h:35
Double_t * values
[knbre_val_max] tableau ou sont stockees les valeurs
Definition KVValues.h:38
const char * GetName() const override
virtual void SetName(const char *name)
virtual void Warning(const char *method, const char *msgfmt,...) const
virtual void Error(const char *method, const char *msgfmt,...) const
Int_t Atoi() const
const char * Data() const
Bool_t IsDigit() const
void Form(const char *fmt,...)
TString & ReplaceAll(const char *s1, const char *s2)
#define F(x, y, z)
double min(double x, double y)
double max(double x, double y)
Double_t Power(Double_t x, Double_t y)
ClassImp(TPyArg)