KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVVarGlobMean.cpp
Go to the documentation of this file.
1 #include "Riostream.h"
2 #include "KVVarGlobMean.h"
3 #include "KVClassFactory.h"
4 
6 
7 
8 
10 void KVVarGlobMean::init(void)
11 {
12  SetNameIndex("Mean", 0);
13  SetNameIndex("RMS", 1);
14  SetNameIndex("SumVar", 2);
15  SetNameIndex("SumVarSquared", 3);
16  SetNameIndex("SumOfWeights", 4);
17  SetNameIndex("Min", 5);
18  SetNameIndex("Max", 6);
19 
20  SetMaxNumBranches(2);
21 }
22 
23 
24 
26 
28 {
29  svar += w * v;
30  svar2 += w * v * v;
31  sw += w;
32  if (v > max) max = v;
33  if (v < min) min = v;
34  calc = 0;
35 }
36 
37 
38 
40 
42 {
43  if (!calc) {
44  if (sw != 0) {
45  var = svar / sw;
46  if (svar2 / sw >= var * var) {
47  ect = TMath::Sqrt(svar2 / sw - var * var);
48  }
49  else {
50  ect = -1.;
51  }
52  }
53  else {
54  var = 0.;
55  ect = -1.;
56  }
57  calc = 1;
58  }
59 }
60 
61 
62 
65 
67 {
68  // Copy this to a
69 
71  KVVarGlobMean& _a = dynamic_cast<KVVarGlobMean&>(a);
72  _a.ect = ect;
73  _a.svar = svar;
74  _a.svar2 = svar2;
75  _a.sw = sw;
76  _a.min = min;
77  _a.max = max;
78  _a.calc = calc;
79 }
80 
81 
82 
84 
86 {
87  var = 0;
88  ect = 0;
89  svar = 0;
90  svar2 = 0;
91  sw = 0;
92  min = 1e6;
93  max = -1e6;
94  calc = 0;
95 }
96 
97 
98 
100 
102 {
103  Reset();
104 }
105 
106 
107 
109 
111 {
112  Double_t rval = 0;
113  switch (i) {
114  case 0:
115  rval = var;
116  break;
117 
118  case 1:
119  rval = ect;
120  break;
121 
122  case 2:
123  rval = svar;
124  break;
125 
126  case 3:
127  rval = svar2;
128  break;
129 
130  case 4:
131  rval = sw;
132  break;
133 
134  case 5:
135  rval = min;
136  break;
137 
138  case 6:
139  rval = max;
140  break;
141 
142  default:
143  rval = 0.;
144  break;
145  }
146  return rval;
147 }
148 
149 
150 
163 
164 void KVVarGlobMean::MakeClass(const Char_t* classname, const Char_t* classdesc, int type)
165 {
166  //Creates skeleton '.h' and '.cpp' files for a new global variable class which
167  //inherits from this class. Give a name for the new class and a short description
168  //which will be used to document the class.
169  //
170  // By default the new class will be of type 1-body. A Fill(KVNucleus*) method
171  // will be generated which the user should complete.
172  // For a 2-body variable, call MakeClass with type = KVVarGlob::kTwoBody.
173  // A skeleton Fill2(KVNucleus*,KVNucleus*) method will be generated.
174  // For a N-body variable, call MakeClass with type = KVVarGlob::kNBody.
175  // A skeleton FillN(KVEvent*) method will be generated.
176 
177  // basic class template
178  KVClassFactory cf(classname, classdesc, "KVVarGlobMean", kTRUE);
179 
180  KVString body;
181 
182  // add 'init' method
183  KVVarGlob::AddInitMethod(cf, body);
185 
186  // add 'Fill', 'Fill2', or 'FillN' method
188 
189  // body of 'Fill', 'Fill2', or 'FillN' method
191 
192  // add body of method
194 
195  cf.GenerateCode();
196 }
197 
198 
199 
203 
205 {
206  // PRIVATE method used by MakeClass.
207  // body of 'Fill', 'Fill2', or 'FillN' method
208 
210  switch (type) {
211  case kTwoBody:
212  body += "\n";
213  body += "Use the FillVar(v,w) method to increment the quantity of the global variable.\n";
214  body += "The value, v, and the weight, w, are to be evaluated from the properties of the\n";
215  body += "two KVNucleus pointers passed as argument.\n";
216  break;
217  case kNBody:
218  body += "\n";
219  body += "Use the FillVar(v,w) method to increment the quantity of the global variable.\n";
220  body += "The value, v, and the weight, w, are to be evaluated from the properties of the\n";
221  body += "KVEvent pointer passed as argument.\n";
222  break;
223  default:
224  body += "\n";
225  body += "Use the FillVar(v,w) method to increment the quantity of the global variable.\n";
226  body += "The value, v, and the weight, w, are to be evaluated from the properties of the \n";
227  body += "KVNucleus passed as argument. For example, to evaluate the mean parallel velocity\n";
228  body += "weighted by the charge of the nucleus, you may proceed as follows:\n";
229  body += "\n";
230  body += "FillVar(n->GetVpar(), n->GetZ());\n";
231  }
232 }
233 
234 
235 
int Int_t
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
char Char_t
double Double_t
const Bool_t kTRUE
int type
Factory class for generating skeleton files for new classes.
void GenerateCode()
Generate header and implementation file for currently-defined class.
Extension of ROOT TString class which allows backwards compatibility with ROOT v3....
Definition: KVString.h:72
Abstract base class for global variables which calculate a mean value.
Definition: KVVarGlobMean.h:34
Double_t svar2
Definition: KVVarGlobMean.h:38
Double_t min
Definition: KVVarGlobMean.h:41
static void MakeClass(const Char_t *classname, const Char_t *classdesc, int type=KVVarGlob::kOneBody)
Double_t max
Definition: KVVarGlobMean.h:42
static void FillMethodBody(KVString &body, int type)
virtual Double_t getvalue_int(Int_t i) const
void FillVar(Double_t v, Double_t w=1.)
void Copy(TObject &obj) const
Copy this to a.
Double_t svar
Definition: KVVarGlobMean.h:39
Double_t ect
Definition: KVVarGlobMean.h:37
Double_t var
Definition: KVVarGlobMean.h:36
static void AddInitMethod(KVClassFactory &cf, KVString &body)
Definition: KVVarGlob.cpp:148
void Copy(TObject &obj) const
Make a copy of this object.
Definition: KVVarGlob.h:328
static void AddFillMethodBody(KVClassFactory &cf, KVString &body, int type)
Definition: KVVarGlob.cpp:191
static void ImplementInitMethod(KVClassFactory &cf, KVString &body, int type)
Definition: KVVarGlob.cpp:111
static void AddFillMethod(KVClassFactory &cf, int type)
Definition: KVVarGlob.cpp:164
static void FillMethodBody(KVString &body, int type)
Definition: KVVarGlob.cpp:87
Double_t Sqrt(Double_t x)
v
auto * a