KaliVeda
Toolkit for HIC analysis
KVArgType.h
1 #ifndef KVARGTYPE_H
2 #define KVARGTYPE_H
3 
4 #include "TVector3.h"
5 #include "TLorentzVector.h"
6 #include "TString.h"
7 
8 namespace KVArgType {
9 
20  template<typename Type, typename BuiltIn>
21  class ArgType {
22  protected:
23  BuiltIn _val;
24  public:
25  ArgType() : _val() {}
26  ArgType(const BuiltIn& v) : _val(v) {}
27  operator BuiltIn() const
28  {
29  return _val;
30  }
31  BuiltIn operator()() const
32  {
33  return _val;
34  }
35  };
47  template<typename Type, typename Class>
48  class ArgTypeClass {
49  protected:
51  public:
52  ArgTypeClass() : _val() {}
53  ArgTypeClass(const Class& v) : _val(v) {}
55  {
56  return &_val;
57  }
58  operator const Class& () const
59  {
60  return _val;
61  }
62  };
63 
64 #define DeclareNewNumericType(_type,_var) \
65  class _type : public ArgType<_type,_var>\
66  {\
67  public:\
68  _type() : ArgType<_type,_var>() {}\
69  _type(const _var& v) : ArgType<_type,_var>(v) {}\
70  _type& operator+=(const _var& v)\
71  {\
72  _val+=v;\
73  return (*this);\
74  }\
75  _type& operator-=(const _var& v)\
76  {\
77  _val-=v;\
78  return (*this);\
79  }\
80  _type& operator*=(const _var& v)\
81  {\
82  _val*=v;\
83  return (*this);\
84  }\
85  _type& operator/=(const _var& v)\
86  {\
87  _val/=v;\
88  return (*this);\
89  }\
90  _type operator-()\
91  {\
92  _type tmp(-_val);\
93  return tmp;\
94  }\
95  static const char* get_encapsulated_typename() { return #_var ; }\
96  static const char* get_typename() { return #_type ; }\
97  virtual ~_type() {}\
98  ClassDef(_type,0)\
99  }
100 #define DeclareNewClassType(_type,_var) \
101  class _type : public ArgTypeClass<_type,_var>\
102  {\
103  public:\
104  _type() : ArgTypeClass<_type,_var>() {}\
105  _type(const _var& v) : ArgTypeClass<_type,_var>(v) {}\
106  static const char* get_encapsulated_typename() { return #_var ; }\
107  static const char* get_typename() { return #_type ; }\
108  virtual ~_type() {}\
109  ClassDef(_type,0)\
110  }
111 #define DeclareNewVectorType(_type) \
112  class _type : public ArgTypeClass<_type,TVector3>\
113  {\
114  public:\
115  virtual ~_type() {}\
116  _type() : ArgTypeClass<_type,TVector3>() {}\
117  _type(const TVector3& v) : ArgTypeClass<_type,TVector3>(v) {}\
118  _type(Double_t x,Double_t y,Double_t z) : ArgTypeClass<_type,TVector3>(TVector3(x,y,z)) {}\
119  _type& operator+=(const TVector3& v)\
120  {\
121  _val+=v;\
122  return (*this);\
123  }\
124  _type& operator-=(const TVector3& v)\
125  {\
126  _val-=v;\
127  return (*this);\
128  }\
129  static const char* get_encapsulated_typename() { return "TVector3" ; }\
130  static const char* get_typename() { return #_type ; }\
131  DeclareNewNumericType(XComponent,Double_t);\
132  DeclareNewNumericType(YComponent,Double_t);\
133  DeclareNewNumericType(ZComponent,Double_t);\
134  DeclareNewNumericType(TransverseComponent,Double_t);\
135  DeclareNewNumericType(Magnitude,Double_t);\
136  XComponent X() const { return _val.X(); }\
137  YComponent Y() const { return _val.Y(); }\
138  ZComponent Z() const { return _val.Z(); }\
139  TransverseComponent Perp() const { return _val.Perp(); }\
140  Magnitude Mag() const { return _val.Mag(); }\
141  ClassDef(_type,0)\
142  }
143 #define DeclareNewStringType(_type) \
144  class _type : public ArgTypeClass<_type,TString>\
145  {\
146  public:\
147  _type() : ArgTypeClass<_type,TString>() {}\
148  _type(const TString& v) : ArgTypeClass<_type,TString>(v) {}\
149  _type(const char* v) : ArgTypeClass<_type,TString>(v) {}\
150  operator const char* () const { return _val.Data(); }\
151  friend std::ostream& operator<<(std::ostream& os, const _type& obj)\
152  {\
153  os << obj._val.Data();\
154  return os;\
155  }\
156  Bool_t operator==(const TString& v) const { return _val==v; }\
157  Bool_t operator!=(const TString& v) const { return _val!=v; }\
158  Bool_t operator==(const char* v) const { return _val==v; }\
159  Bool_t operator!=(const char* v) const { return _val!=v; }\
160  static const char* get_encapsulated_typename() { return "TString" ; }\
161  static const char* get_typename() { return #_type ; }\
162  virtual ~_type() {}\
163  ClassDef(_type,0)\
164  }
165 
166 #define DeclareNumericTypeOperator(_op,_ret,_t1,_t2) _ret operator _op (const _t1 & A, const _t2 & B)
167 #define DeclareNumericTypeOperatorCommutative(_op,_ret,_t1,_t2)\
168  DeclareNumericTypeOperator(_op,_ret,_t1,_t2);\
169  DeclareNumericTypeOperator(_op,_ret,_t2,_t1)
170 #define DeclareNumericTypeSubtraction(_ret,_t1,_t2)\
171  DeclareNumericTypeOperatorCommutative(-,_ret,_t1,_t2);\
172  DeclareNumericTypeOperatorCommutative(+,_t1,_ret,_t2);\
173  DeclareNumericTypeOperatorCommutative(-,_t2,_t1,_ret)
174 #define DeclareNumericTypeAddition(_ret,_t1,_t2)\
175  DeclareNumericTypeOperatorCommutative(+,_ret,_t1,_t2);\
176  DeclareNumericTypeOperatorCommutative(-,_t1,_ret,_t2);\
177  DeclareNumericTypeOperatorCommutative(-,_t2,_t1,_ret)
178 #define DeclareNumericTypeDivision(_ret,_t1,_t2)\
179  DeclareNumericTypeOperator(/,_ret,_t1,_t2);\
180  DeclareNumericTypeOperator(/,_t2,_t1,_ret);\
181  DeclareNumericTypeOperatorCommutative(*,_t1,_t2,_ret)
182 #define DeclareNumericTypeMultiplication(_ret,_t1,_t2)\
183  DeclareNumericTypeOperator(/,_t1,_ret,_t2);\
184  DeclareNumericTypeOperator(/,_t2,_ret,_t1);\
185  DeclareNumericTypeOperatorCommutative(*,_ret,_t1,_t2)
186 #define ImplementNumericTypeOperator(_op,_ret,_t1,_t2)\
187  _ret operator _op (const _t1 & A, const _t2 & B)\
188  {\
189  return _ret(A() _op B());\
190  }
191 #define ImplementNumericTypeOperatorCommutative(_op,_ret,_t1,_t2)\
192  ImplementNumericTypeOperator(_op,_ret,_t1,_t2)\
193  ImplementNumericTypeOperator(_op,_ret,_t2,_t1)
194 #define ImplementNumericTypeSubtraction(_ret,_t1,_t2)\
195  ImplementNumericTypeOperatorCommutative(-,_ret,_t1,_t2)\
196  ImplementNumericTypeOperatorCommutative(+,_t1,_ret,_t2)\
197  ImplementNumericTypeOperatorCommutative(-,_t2,_t1,_ret)
198 #define ImplementNumericTypeAddition(_ret,_t1,_t2)\
199  ImplementNumericTypeOperatorCommutative(+,_ret,_t1,_t2)\
200  ImplementNumericTypeOperatorCommutative(-,_t1,_ret,_t2)\
201  ImplementNumericTypeOperatorCommutative(-,_t2,_t1,_ret)
202 #define ImplementNumericTypeDivision(_ret,_t1,_t2)\
203  ImplementNumericTypeOperator(/,_ret,_t1,_t2)\
204  ImplementNumericTypeOperator(/,_t2,_t1,_ret)\
205  ImplementNumericTypeOperatorCommutative(*,_t1,_t2,_ret)
206 #define ImplementNumericTypeMultiplication(_ret,_t1,_t2)\
207  ImplementNumericTypeOperator(/,_t1,_ret,_t2)\
208  ImplementNumericTypeOperator(/,_t2,_ret,_t1)\
209  ImplementNumericTypeOperatorCommutative(*,_ret,_t1,_t2)
210 
215  typedef Energy Mass;
220  DeclareNewNumericType(AzimuthalAngle, Double_t);
221  DeclareNewStringType(AngularDistributionType);
223  DeclareNewNumericType(ExcitationEnergy, Double_t);
225  DeclareNewNumericType(BindingEnergyPerNucleon, Double_t);
226  DeclareNewNumericType(ExcitationEnergyPerNucleon, Double_t);
227  DeclareNewNumericType(KineticEnergyPerNucleon, Double_t);
228  DeclareNewNumericType(AtomicNumber, Int_t);
232  DeclareNewNumericType(ChargeAsymmetry, Double_t);
233  DeclareNewNumericType(NeutronExcess, Int_t);
239  DeclareNewVectorType(RelativeVelocity);
242  DeclareNewVectorType(AngularMomentum);
244  DeclareNewStringType(MomentumComponentType);
245 
247  DeclareNumericTypeAddition(MassNumber, NeutronNumber, AtomicNumber);
248  DeclareNumericTypeSubtraction(NeutronExcess, NeutronNumber, AtomicNumber);
249  DeclareNumericTypeDivision(ChargeAsymmetry, NeutronExcess, MassNumber);
251  DeclareNumericTypeDivision(AOverZ, MassNumber, AtomicNumber);
252  RelativeVelocity operator-(Velocity, Velocity);
253  DeclareNumericTypeDivision(BindingEnergyPerNucleon, BindingEnergy, MassNumber);
254  DeclareNumericTypeDivision(ExcitationEnergyPerNucleon, ExcitationEnergy, MassNumber);
255  DeclareNumericTypeDivision(KineticEnergyPerNucleon, KineticEnergy, MassNumber);
256 }
257 #endif // KVARGTYPE_H
int Int_t
double Double_t
Base class for explicit argument types (class types)
Definition: KVArgType.h:48
ArgTypeClass(const Class &v)
Definition: KVArgType.h:53
Base class for explicit argument types.
Definition: KVArgType.h:21
BuiltIn operator()() const
Definition: KVArgType.h:31
ArgType(const BuiltIn &v)
Definition: KVArgType.h:26
RooCmdArg Name(const char *name)
AtomicNumber AtomicNumber BindingEnergy
Definition: KVArgType.cpp:13
DeclareNumericTypeSubtraction(NeutronExcess, NeutronNumber, AtomicNumber)
DeclareNumericTypeAddition(MassNumber, NeutronNumber, AtomicNumber)
Special operations.
DeclareNewStringType(Name)
DeclareNewNumericType(Number, Int_t)
basic properties
DeclareNewClassType(FourMomentum, TLorentzVector)
DeclareNumericTypeDivision(ChargeAsymmetry, NeutronExcess, MassNumber)
Energy Mass
Definition: KVArgType.h:215
RelativeVelocity operator-(Velocity, Velocity)
DeclareNewVectorType(Direction)
const char * Class
v