KaliVeda
Toolkit for HIC analysis
Loading...
Searching...
No Matches
KVVarGlob.h
1#ifndef KVVarGlob_h
2#define KVVarGlob_h
3#include "Riostream.h"
4#include "KVBase.h"
5#include "KVNucleus.h"
6#include "KVNameValueList.h"
7#include "KVString.h"
8#include "KVParticleCondition.h"
9
10class KVEvent;
11
76
91
97
224
233class KVVarGlob: public KVBase {
234
235public:
236 enum {
237 kOneBody, // one-body variable: Fill (KVNucleus*) must be defined
238 kTwoBody, // two-body variable: Fill2 (KVNucleus*, KVNucleus*) must be defined
239 kNBody // N-body variable: FillN (KVEvent*) must be defined
240 };
241
242protected:
245private:
254
255#ifdef USING_ROOT6
256 using EventSelector = std::function<bool(const KVVarGlob*)>;
258 using FrameSetter = std::function<void(KVEvent*, const KVVarGlob*)>;
260#endif
261
262 Bool_t fDefineGroupFromSelection{kFALSE};// kTRUE if all selected particles are to be added to a group with the name of the variable
263
264 void init();
265 static void AddExtraInitMethodComment(KVClassFactory& cf, KVString& body);
266
267protected:
268 void SetNameIndex(const Char_t* name, Int_t index);
270 {
272 nameList.Clear();
273 }
274 int GetIndexAtListPosition(int pos) const
275 {
277 return nameList.GetValue<int>(pos);
278 }
280 {
282 return nameList.GetNameAt(pos);
283 }
284
285 static void FillMethodBody(KVString& body, int type);
286 static void AddInitMethod(KVClassFactory& cf, KVString& body);
287 static void ImplementInitMethod(KVClassFactory& cf, KVString& body, int type);
288 static void AddFillMethod(KVClassFactory& cf, int type);
289 static void AddFillMethodBody(KVClassFactory& cf, KVString& body, int type);
290
291 virtual Double_t getvalue_void() const
292 {
294 return getvalue_int(0);
295 }
296 virtual Double_t getvalue_char(const Char_t* name) const
297 {
300
302 }
303 virtual Double_t getvalue_int(Int_t) const = 0;
304 virtual void fill(const KVNucleus*)
305 {
308 AbstractMethod("fill(KVNucleus*)");
309 }
310
311 virtual void fill2(const KVNucleus*, const KVNucleus*)
312 {
321 AbstractMethod("fill2(KVNucleus*,KVNucleus*)");
322 }
323
325 {
326 return fParameters;
327 }
329 {
330 return fParameters;
331 }
332
333public:
335 : KVBase("KVVarGlob", "KVVarGlob"), nameList("IndexList", "Correspondance variable name<->index")
336 {
337 init();
338 }
339 KVVarGlob(const Char_t* nom)
340 : KVBase(nom, nom), nameList("IndexList", "Correspondance variable name<->index")
341 {
342 init();
343 }
344 ROOT_COPY_CTOR(KVVarGlob, KVBase)
345 ROOT_COPY_ASSIGN_OP(KVVarGlob)
346 void Copy(TObject& obj) const
347 {
349 KVBase::Copy(obj);
350 KVVarGlob& vgobj = dynamic_cast<KVVarGlob&>(obj);
351 nameList.Copy(vgobj.nameList);
353 vgobj.fFrame = fFrame;
354 fOptions.Copy(vgobj.fOptions);
357 vgobj.fType = fType;
358 vgobj.fValueType = fValueType;
361#ifdef USING_ROOT6
364#endif
365 }
366 virtual ~KVVarGlob(void)
367 {}
368
370 {
372 return fType == kOneBody;
373 }
374
376 {
378 return fType == kTwoBody;
379 }
380
382 {
384 return fType == kNBody;
385 }
386
387 virtual Bool_t IsGlobalVariable() const
388 {
389 return kTRUE;
390 }
391
392 void ListInit()
393 {
396
397 if (!fIsInitialized) {
398 Init();
400 }
401 }
402 virtual void Init() = 0;
403 virtual void Reset() = 0;
404 virtual void Calculate() = 0;
405
406 void Fill(const KVNucleus* c)
407 {
414 const KVNucleus* c_in_frame = dynamic_cast<const KVNucleus*>(c->GetFrame(fFrame, false));
415 if (fSelection.Test(c_in_frame)) {
416 fill(c_in_frame);
417 if (fDefineGroupFromSelection) c->AddGroup(GetOptionString("GROUP_NAME"));
418 }
419 }
420 void Fill2(const KVNucleus* n1, const KVNucleus* n2)
421 {
425 const KVNucleus* n1_in_frame = dynamic_cast<const KVNucleus*>(n1->GetFrame(fFrame, false));
426 const KVNucleus* n2_in_frame = dynamic_cast<const KVNucleus*>(n2->GetFrame(fFrame, false));
427 if (fSelection.Test(n1_in_frame) && fSelection.Test(n2_in_frame))
428 fill2(n1_in_frame, n2_in_frame);
429 }
430 virtual void FillN(const KVEvent*)
431 {
434 AbstractMethod("FillN(KVEvent*)");
435 }
436 Bool_t HasValue(const Char_t* name) const
437 {
440
441 return nameList.HasParameter(name);
442 }
443 Double_t GetValue(void) const
444 {
450
451 return getvalue_void() / fNormalization;
452 }
453 Double_t GetValue(const Char_t* name) const
454 {
460
462 }
464 {
470
471 return getvalue_int(i) / fNormalization;
472 }
473 virtual std::vector<Double_t> GetValueVector(void) const
474 {
480
481 std::vector<Double_t> tmp;
482 for (int i = 0; i < GetNumberOfValues(); ++i) tmp.push_back(GetValue(i) / fNormalization);
483 return tmp;
484 }
485
487 {
488 return GetValue();
489 }
490
491 Double_t operator()(const Char_t* name) const
492 {
493 return GetValue(name);
494 }
495
497 {
498 return GetValue(i);
499 }
500
501 Int_t GetNameIndex(const Char_t* name) const;
502
503 static void MakeClass(const Char_t* classname, const Char_t* classdesc, int type = kOneBody);
504
505 void SetFrame(const Char_t* ref)
506 {
514 fFrame = ref;
515 }
516 const TString& GetFrame() const
517 {
518 return fFrame;
519 }
520
521 void SetOption(const Char_t* option, const Char_t* value)
522 {
524 KVString tmp(value);
526 fIsInitialized = kFALSE; //allow re-initialisation
527 }
528
530 {
532
533 return fOptions.HasParameter(opt);
534 }
535
537 {
539
540 return fOptions.GetTStringValue(opt);
541 }
542 void UnsetOption(const Char_t* opt)
543 {
545
547 }
548
549 void SetParameter(const Char_t* par, Double_t value)
550 {
552
553 TString Par(par);
556 if (Par == "Zmin" || Par == "Zmax" || Par == "Vmin" || Par == "Vmax")
557 Fatal("SetParameter", "Particle selection for global variables must be defined using SetSelection(const KVParticleCondition&).\nUpdate the use of variable \"%s\" in your analysis.",
558 GetName());
559 if (Par == "Normalization") SetNormalization(value);
560 else fParameters.SetValue(par, value);
561 fIsInitialized = kFALSE; //allow re-initialisation
562 }
563
564 virtual void SetNormalization(Double_t norm)
565 {
569 fNormalization = norm;
570 fValueType = 'D';
571 }
572
574 {
576 if (TString(par) == "Normalization") return (fNormalization != 1.0);
577 return fParameters.HasParameter(par);
578 }
579
580 Double_t GetParameter(const Char_t* par) const
581 {
583 if (TString(par) == "Normalization") return fNormalization;
584 return fParameters.GetDoubleValue(par);
585 }
586
588 {
589 return fNormalization;
590 }
591
592 void UnsetParameter(const Char_t* par)
593 {
595
596 if (TString(par) == "Normalization") fNormalization = 1.0;
598 }
599
601 {
612
613 fSelection = sel;
614 }
615
617 {
625
626 fSelection &= sel;
627 }
628
630 {
631 return GetValue();
632 }
633 operator double() const
634 {
635 return AsDouble();
636 }
637
638 virtual Int_t GetNumberOfValues() const
639 {
642 return nameList.GetNpar();
643 }
645 {
653 }
654 virtual TString GetValueName(Int_t i) const
655 {
658 for (int j = 0; j < GetNumberOfValues(); j++) {
659 if (nameList.GetIntValue(j) == i) return nameList.GetParameter(j)->GetName();
660 }
661 return TString("unknown");
662 }
664 {
666 return nameList;
667 }
668 virtual Char_t GetValueType(Int_t) const
669 {
680
681 return fValueType;
682 }
684 {
694 fMaxNumBranches = (n <= GetNumberOfValues() ? n : -1);
695 }
696 void Print(Option_t* = "") const;
697
698#ifdef USING_ROOT6
700 {
718 }
720 {
724
725 if (!fEventSelector) return true;
726 bool result = fEventSelector(this);
727 return result;
728 }
729 bool IsSelectingEvents() const
730 {
732 return (bool)fEventSelector;
733 }
735 {
743 fFrameSetter = f;
744 }
745 void DefineNewFrame(KVEvent* e) const
746 {
750 if (fFrameSetter) fFrameSetter(e, this);
751 }
753 {
755 return (bool)fFrameSetter;
756 }
757#endif
758 void SetDefineGroup(const KVString& groupname = "");
759
760 ClassDef(KVVarGlob, 7) // Base class for global variables
761};
762#endif
int Int_t
#define f(i)
#define c(i)
#define e(i)
bool Bool_t
char Char_t
constexpr Bool_t kFALSE
double Double_t
constexpr Bool_t kTRUE
const char Option_t
#define ClassDef(name, id)
Option_t Option_t option
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 Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t sel
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Base class for KaliVeda framework.
Definition KVBase.h:142
virtual void Copy(TObject &) const
Make a copy of this object.
Definition KVBase.cpp:394
Factory class for generating skeleton files for new classes.
Abstract base class container for multi-particle events.
Definition KVEvent.h:67
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
Int_t GetIntValue(const Char_t *name) const
Double_t GetDoubleValue(const Char_t *name) const
void SetValue(const Char_t *name, value_type value)
void RemoveParameter(const Char_t *name)
virtual void Clear(Option_t *opt="")
const Char_t * GetNameAt(Int_t idx) const
Int_t GetNpar() const
return the number of stored parameters
value_type GetValue(const Char_t *name) const
Bool_t HasParameter(const Char_t *name) const
TString GetTStringValue(const Char_t *name) const
void Copy(TObject &nvl) const
Description of properties and kinematics of atomic nuclei.
Definition KVNucleus.h:126
KVParticle const * GetFrame(const Char_t *frame, Bool_t warn_and_return_null_if_unknown=kTRUE) const
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition KVString.h:73
Bool_t Test(const ParticleType *nuc) const
Base class for all global variable implementations.
Definition KVVarGlob.h:233
void SetOption(const Char_t *option, const Char_t *value)
Definition KVVarGlob.h:521
KVVarGlob(const Char_t *nom)
Definition KVVarGlob.h:339
Double_t GetValue(const Char_t *name) const
Definition KVVarGlob.h:453
void ListInit()
Definition KVVarGlob.h:392
static void AddInitMethod(KVClassFactory &cf, KVString &body)
void Print(Option_t *="") const
Double_t operator()(void) const
Definition KVVarGlob.h:486
virtual void Calculate()=0
Bool_t IsOneBody() const
Definition KVVarGlob.h:369
Bool_t fDefineGroupFromSelection
Definition KVVarGlob.h:262
Double_t fNormalization
optional normalization parameter
Definition KVVarGlob.h:253
virtual Int_t GetNumberOfValues() const
Definition KVVarGlob.h:638
Double_t GetValue(void) const
Definition KVVarGlob.h:443
KVString fFrame
(optional) name of reference frame used for kinematics
Definition KVVarGlob.h:248
void Copy(TObject &obj) const
Definition KVVarGlob.h:346
Bool_t HasValue(const Char_t *name) const
Definition KVVarGlob.h:436
KVNameValueList fOptions
list of options
Definition KVVarGlob.h:249
Double_t AsDouble() const
Definition KVVarGlob.h:629
void SetNameIndex(const Char_t *name, Int_t index)
void SetNewFrameDefinition(const FrameSetter &f)
Definition KVVarGlob.h:734
KVNameValueList & GetParameters()
Definition KVVarGlob.h:324
const KVNameValueList & GetParameters() const
Definition KVVarGlob.h:328
Double_t GetValue(Int_t i) const
Definition KVVarGlob.h:463
void SetMaxNumBranches(Int_t n)
Definition KVVarGlob.h:683
void ClearNameIndex()
Definition KVVarGlob.h:269
Int_t GetNameIndex(const Char_t *name) const
void SetParameter(const Char_t *par, Double_t value)
Definition KVVarGlob.h:549
static void MakeClass(const Char_t *classname, const Char_t *classdesc, int type=kOneBody)
Definition KVVarGlob.cpp:45
EventSelector fEventSelector
used to select events in analysis based on value of variable
Definition KVVarGlob.h:257
FrameSetter fFrameSetter
used to define a new kinematical frame for event based on variable
Definition KVVarGlob.h:259
virtual void SetNormalization(Double_t norm)
Definition KVVarGlob.h:564
void UnsetOption(const Char_t *opt)
Definition KVVarGlob.h:542
virtual void fill2(const KVNucleus *, const KVNucleus *)
Definition KVVarGlob.h:311
bool IsDefiningNewFrame() const
Definition KVVarGlob.h:752
void Fill(const KVNucleus *c)
Definition KVVarGlob.h:406
TString GetOptionString(const Char_t *opt) const
Definition KVVarGlob.h:536
std::function< bool(const KVVarGlob *)> EventSelector
Definition KVVarGlob.h:256
static void AddFillMethodBody(KVClassFactory &cf, KVString &body, int type)
static void ImplementInitMethod(KVClassFactory &cf, KVString &body, int type)
virtual Double_t getvalue_int(Int_t) const =0
Double_t operator()(Int_t i) const
Definition KVVarGlob.h:496
Bool_t IsOptionGiven(const Char_t *opt)
Definition KVVarGlob.h:529
std::function< void(KVEvent *, const KVVarGlob *)> FrameSetter
Definition KVVarGlob.h:258
virtual void FillN(const KVEvent *)
Definition KVVarGlob.h:430
Bool_t fIsInitialized
flag set after initialisation
Definition KVVarGlob.h:247
static void AddFillMethod(KVClassFactory &cf, int type)
void AddSelection(const KVParticleCondition &sel)
Definition KVVarGlob.h:616
const KVNameValueList & GetValueNameList() const
Definition KVVarGlob.h:663
virtual void fill(const KVNucleus *)
Definition KVVarGlob.h:304
Double_t operator()(const Char_t *name) const
Definition KVVarGlob.h:491
Double_t GetParameter(const Char_t *par) const
Definition KVVarGlob.h:580
void SetEventSelection(const EventSelector &f)
Definition KVVarGlob.h:699
void init()
Definition KVVarGlob.cpp:16
static void FillMethodBody(KVString &body, int type)
Definition KVVarGlob.cpp:87
TString GetNameAtListPosition(int pos) const
Definition KVVarGlob.h:279
virtual std::vector< Double_t > GetValueVector(void) const
Definition KVVarGlob.h:473
KVNameValueList nameList
correspondence between variable name and index
Definition KVVarGlob.h:246
Int_t GetNumberOfBranches() const
Definition KVVarGlob.h:644
bool IsSelectingEvents() const
Definition KVVarGlob.h:729
virtual Double_t getvalue_void() const
Definition KVVarGlob.h:291
void Fill2(const KVNucleus *n1, const KVNucleus *n2)
Definition KVVarGlob.h:420
KVParticleCondition fSelection
(optional) condition used to select particles
Definition KVVarGlob.h:251
virtual Bool_t IsGlobalVariable() const
Definition KVVarGlob.h:387
KVNameValueList fParameters
list of parameters
Definition KVVarGlob.h:250
virtual TString GetValueName(Int_t i) const
Definition KVVarGlob.h:654
virtual Char_t GetValueType(Int_t) const
Definition KVVarGlob.h:668
Int_t fMaxNumBranches
max number of branches to create for multi-valued variable
Definition KVVarGlob.h:252
void SetFrame(const Char_t *ref)
Definition KVVarGlob.h:505
virtual void Init()=0
int GetIndexAtListPosition(int pos) const
Definition KVVarGlob.h:274
void SetSelection(const KVParticleCondition &sel)
Definition KVVarGlob.h:600
void DefineNewFrame(KVEvent *e) const
Definition KVVarGlob.h:745
static void AddExtraInitMethodComment(KVClassFactory &cf, KVString &body)
virtual void Reset()=0
Double_t GetNormalization() const
Definition KVVarGlob.h:587
bool TestEventSelection() const
Definition KVVarGlob.h:719
virtual ~KVVarGlob(void)
Definition KVVarGlob.h:366
Bool_t IsNBody() const
Definition KVVarGlob.h:381
virtual Double_t getvalue_char(const Char_t *name) const
Definition KVVarGlob.h:296
Int_t fType
type of variable global; = kOneBody, kTwoBody or kNBody
Definition KVVarGlob.h:243
Bool_t IsTwoBody() const
Definition KVVarGlob.h:375
const TString & GetFrame() const
Definition KVVarGlob.h:516
void SetDefineGroup(const KVString &groupname="")
Bool_t IsParameterSet(const Char_t *par)
Definition KVVarGlob.h:573
Char_t fValueType
type (='I' integer or 'D' double) of global variable value
Definition KVVarGlob.h:244
void UnsetParameter(const Char_t *par)
Definition KVVarGlob.h:592
const char * GetName() const override
void AbstractMethod(const char *method) const
virtual void Fatal(const char *method, const char *msgfmt,...) const
const Int_t n
void(off) SmallVectorTemplateBase< T