KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVVGSum.cpp
Go to the documentation of this file.
1 /*
2 $Id: KVVGSum.cpp,v 1.2 2009/01/23 15:25:52 franklan Exp $
3 $Revision: 1.2 $
4 $Date: 2009/01/23 15:25:52 $
5 */
6 
7 //Created by KVClassFactory on Thu Nov 16 10:42:38 2006
8 //Author: John Frankland
9 
10 #include "KVVGSum.h"
11 #include "TClass.h"
12 #include "TROOT.h"
13 
15 
16 // KVVGSum
18 // General global variable for calculating sums of various quantities
19 //
20 //Most global variables involve a sum of some kind, whether it be
21 //summing up the number of times that particles meets certain
22 //criteria (multiplicity), summing some property of particles such as
23 //transverse energy or charge, or calculating the mean value of such a
24 //property for all particles.
25 //
26 //Therefore the actual act of summing up is always the same,
27 //the difference between one global variable and another is the
28 //quantity which is summed, and the information which is finally
29 //extracted from this sum.
30 //
31 //A KVVGSum has three modes of operation: mult, sum, mean
32 //In the first, "mult", it is used to count the number of times that a selection
33 //condition is successfully met.
34 //In "sum" mode, it is used to sum a property of all particles which meet
35 //a given selection condition.
36 //In "mean" mode, it calculates the mean value of a property of all particles
37 //which meet a given selection condition.
38 //
39 //SETTING THE MODE OF OPERATION
40 //Assuming a pointer to a KVVGSum, KVVGSum* vgs:
41 //
42 // vgs->SetOption("mode", "mult");
43 // vgs->SetOption("mode", "sum");
44 // vgs->SetOption("mode", "mean");
45 //
46 //SETTING THE PROPERTY TO BE SUMMED
47 //To set the property to be summed, you must give the name of the method
48 //to be called in order to obtain the desired quantity:
49 //
50 // vgs->SetOption("method", "GetREtran");
51 // vgs->SetOption("method", "GetZ");
52 //
53 //If you need to give arguments for the method call, use option "args", e.g.:
54 //
55 // vgs->SetOption("args", "3, \"string argument\", 0");
56 //
57 //By default, the method used must be defined in class KVNucleus or one of
58 //its base classes. If you need to access methods in some derived class,
59 //use the "class" option:
60 //
61 // vgs->SetOption("class", "MyOwnParticleClass");
62 //
63 //SETTING THE PARTICLE SELECTION CRITERIA
64 //Use a KVParticleCondition to set some selection criteria, then
65 //pass it as argument to base class method KVVVarGlob::SetSelection().
66 //
67 //Example: calculate multiplicity of nuclei with Z<3
68 // KVParticleCondition sel("_NUC_->GetZ()<3");
69 // vgs->SetSelection(sel);
70 // vgs->SetOption("mode", "mult");
71 //
72 //Example: calculate mean transverse energy of IMF with CM parallel
73 // velocities between -1.5 and +1.5 cm/ns
74 // KVParticleCondition imf("_NUC_->GetZ()>=3 && _NUC_->GetZ()<=20");
75 // KVParticleCondition vpar("_NUC_->GetFrame(\"CM\")->GetVpar()>=-1.5 && _NUC_->GetFrame(\"CM\")->GetVpar()<=1.5");
76 // KVParticleCondition sel = imf && vpar;
77 // vgs->SetSelection(sel);
78 // vgs->SetOption("mode", "mean");
79 // vgs->SetOption("method", "GetEtran");
81 
82 
83 
85 void KVVGSum::init(void)
86 {
87  ClearNameIndex();
88  SetMaxNumBranches(-1);
89  fClass = nullptr;
90  fVal = 0;
91 }
92 
93 
94 
95 
97 
98 void KVVGSum::fill(const KVNucleus* c)
99 {
100  if (fMethod.get()) {
101  fMethod->Execute(const_cast<KVNucleus*>(c), fVal);
102  FillVar(fVal, 1);
103  }
104  else
105  FillVar(1, 1);
106 }
107 
108 
109 
110 
115 
117 {
118  //Must be called at least once before beginning calculation in order to
119  //set mode of operation, get pointer to method used to calculate variable,
120  //etc. etc.
121 
123 
124  if (TestBit(kInitDone)) return;
125 
126  SetBit(kInitDone);
127 
128  //Analyse options and set internal flags
129  //Info("Init", "Called for %s", GetName());
130 
131  //SET MODE OF OPERATION
132  if (GetOptionString("mode") == "mult") {
133  SetBit(kMult);
134  fValueType = 'I'; // integer type for automatic TTree branch
135  SetNameIndex("Mult", 4);
136  }
137  else if (GetOptionString("mode") == "sum") {
138  SetBit(kSum);
139  SetNameIndex("Sum", 2);
140  }
141  else if (GetOptionString("mode") == "mean") {
142  SetBit(kMean);
143  // redefine "Mean" and "RMS" indices
144  SetNameIndex("Mean", 0);
145  SetNameIndex("RMS", 1);
146  }
147  else SetBit(kSum); //sum by default if unknown mode given
148 
149  //Info("Init", "mode=%s", GetOptionString("mode").Data());
150 
151  //SET UP METHOD CALL
152  if (IsOptionGiven("class")) fClass = TClass::GetClass(GetOptionString("class"));
153  else fClass = TClass::GetClass("KVNucleus");
154 
155  if (!fClass) {
156  Fatal("Init", "Failed to load class requested as option: %s", GetOptionString("class").Data());
157  }
158  if (IsOptionGiven("method")) {
159  if (IsOptionGiven("args"))
160  fMethod.reset(new TMethodCall(fClass, GetOptionString("method").Data(), GetOptionString("args").Data()));
161  else
162  fMethod.reset(new TMethodCall(fClass, GetOptionString("method").Data(), ""));
163  //Info("Init", "Method = %s Params = %s", fMethod->GetMethodName(),
164  // fMethod->GetParams());
165  // if we are summing an integer quantity, make automatic TTree branch with integer type
166  if (fMethod->ReturnType() == TMethodCall::kLong && TestBit(kSum)) fValueType = 'I';
167  }
168 }
169 
170 
171 
Cppyy::TCppType_t fClass
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
#define c(i)
Description of properties and kinematics of atomic nuclei.
Definition: KVNucleus.h:125
void fill(const KVNucleus *c)
Definition: KVVGSum.cpp:98
@ kMult
Definition: KVVGSum.h:25
@ kInitDone
Definition: KVVGSum.h:29
@ kSum
Definition: KVVGSum.h:26
@ kMean
Definition: KVVGSum.h:27
unique_ptr< TMethodCall > fMethod
method used to extract property of interest from particles
Definition: KVVGSum.h:21
Double_t fVal
used to retrieve value of property for each particle
Definition: KVVGSum.h:22
void Init()
Definition: KVVGSum.cpp:116
TClass * fClass
class used to represent particles
Definition: KVVGSum.h:20
void FillVar(Double_t v, Double_t w=1.)
void SetNameIndex(const Char_t *name, Int_t index)
Definition: KVVarGlob.cpp:223
TString GetOptionString(const Char_t *opt) const
Definition: KVVarGlob.h:505
Bool_t IsOptionGiven(const Char_t *opt)
Definition: KVVarGlob.h:498
Char_t fValueType
type (='I' integer or 'D' double) of global variable value
Definition: KVVarGlob.h:228
static TClass * GetClass(Bool_t load=kTRUE, Bool_t silent=kFALSE)
static const EReturnType kLong
void SetBit(UInt_t f)
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void Fatal(const char *method, const char *msgfmt,...) const