1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
#include "Alignment/CocoaModel/interface/ALIUnitsTable.h"
#include <CLHEP/Units/SystemOfUnits.h>
#include <iomanip>
#include <cstdlib>
#include <cmath> // include floating-point std::abs functions
ALIUnitsTable ALIUnitDefinition::theUnitsTable;
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIUnitDefinition::ALIUnitDefinition(ALIstring name, ALIstring symbol, ALIstring category, ALIdouble value)
: Name(name), SymbolName(symbol), Value(value) {
//
//does the Category objet already exist ?
size_t nbCat = theUnitsTable.size();
size_t i = 0;
while ((i < nbCat) && (theUnitsTable[i]->GetName() != category))
i++;
if (i == nbCat)
theUnitsTable.push_back(new ALIUnitsCategory(category));
CategoryIndex = i;
//
//insert this Unit in the Unitstable
(theUnitsTable[CategoryIndex]->GetUnitsList()).emplace_back(shared_from_this());
//update ALIstring max length for name and symbol
theUnitsTable[i]->UpdateNameMxLen((ALIint)name.length());
theUnitsTable[i]->UpdateSymbMxLen((ALIint)symbol.length());
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIUnitDefinition::~ALIUnitDefinition() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIUnitDefinition::ALIUnitDefinition(ALIUnitDefinition& right)
: std::enable_shared_from_this<ALIUnitDefinition>(right) {
*this = right;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIUnitDefinition& ALIUnitDefinition::operator=(const ALIUnitDefinition& right) {
if (this != &right) {
Name = right.Name;
SymbolName = right.SymbolName;
Value = right.Value;
CategoryIndex = right.CategoryIndex;
}
return *this;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIint ALIUnitDefinition::operator==(const ALIUnitDefinition& right) const { return (this == &right); }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIint ALIUnitDefinition::operator!=(const ALIUnitDefinition& right) const { return (this != &right); }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIdouble ALIUnitDefinition::GetValueOf(ALIstring stri) {
if (theUnitsTable.empty())
BuildUnitsTable();
ALIstring name, symbol;
for (size_t i = 0; i < theUnitsTable.size(); i++) {
ALIUnitsContainer& units = theUnitsTable[i]->GetUnitsList();
for (size_t j = 0; j < units.size(); j++) {
name = units[j]->GetName();
symbol = units[j]->GetSymbol();
if (stri == name || stri == symbol)
return units[j]->GetValue();
}
}
std::cout << "Warning from ALIUnitDefinition::GetValueOf(" << stri << ")."
<< " The unit " << stri << " does not exist in UnitsTable."
<< " Return Value = 0." << std::endl;
return 0.;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIstring ALIUnitDefinition::GetCategory(ALIstring stri) {
if (theUnitsTable.empty())
BuildUnitsTable();
ALIstring name, symbol;
for (size_t i = 0; i < theUnitsTable.size(); i++) {
ALIUnitsContainer& units = theUnitsTable[i]->GetUnitsList();
for (size_t j = 0; j < units.size(); j++) {
name = units[j]->GetName();
symbol = units[j]->GetSymbol();
if (stri == name || stri == symbol)
return theUnitsTable[i]->GetName();
}
}
std::cout << "Warning from ALIUnitDefinition::GetCategory(" << stri << ")."
<< " The unit " << stri << " does not exist in UnitsTable."
<< " Return category = None" << std::endl;
name = "None";
return name;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void ALIUnitDefinition::PrintDefinition() {
ALIint nameL = theUnitsTable[CategoryIndex]->GetNameMxLen();
ALIint symbL = theUnitsTable[CategoryIndex]->GetSymbMxLen();
std::cout << std::setw(nameL) << Name << " (" << std::setw(symbL) << SymbolName << ") = " << Value << std::endl;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void ALIUnitDefinition::BuildUnitsTable() {
using namespace CLHEP;
//Length
std::make_shared<ALIUnitDefinition>("kilometer", "km", "Length", kilometer);
std::make_shared<ALIUnitDefinition>("meter", "m", "Length", meter);
std::make_shared<ALIUnitDefinition>("centimeter", "cm", "Length", centimeter);
std::make_shared<ALIUnitDefinition>("millimeter", "mm", "Length", millimeter);
std::make_shared<ALIUnitDefinition>("micrometer", "mum", "Length", micrometer);
std::make_shared<ALIUnitDefinition>("nanometer", "nm", "Length", nanometer);
std::make_shared<ALIUnitDefinition>("angstrom", "Ang", "Length", angstrom);
std::make_shared<ALIUnitDefinition>("fermi", "fm", "Length", fermi);
//Surface
std::make_shared<ALIUnitDefinition>("kilometer2", "km2", "Surface", kilometer2);
std::make_shared<ALIUnitDefinition>("meter2", "m2", "Surface", meter2);
std::make_shared<ALIUnitDefinition>("centimeter2", "cm2", "Surface", centimeter2);
std::make_shared<ALIUnitDefinition>("millimeter2", "mm2", "Surface", millimeter2);
std::make_shared<ALIUnitDefinition>("barn", "barn", "Surface", barn);
std::make_shared<ALIUnitDefinition>("millibarn", "mbarn", "Surface", millibarn);
std::make_shared<ALIUnitDefinition>("microbarn", "mubarn", "Surface", microbarn);
std::make_shared<ALIUnitDefinition>("nanobarn", "nbarn", "Surface", nanobarn);
std::make_shared<ALIUnitDefinition>("picobarn", "pbarn", "Surface", picobarn);
//Volume
std::make_shared<ALIUnitDefinition>("kilometer3", "km3", "Volume", kilometer3);
std::make_shared<ALIUnitDefinition>("meter3", "m3", "Volume", meter3);
std::make_shared<ALIUnitDefinition>("centimeter3", "cm3", "Volume", centimeter3);
std::make_shared<ALIUnitDefinition>("millimeter3", "mm3", "Volume", millimeter3);
//Angle
std::make_shared<ALIUnitDefinition>("radian", "rad", "Angle", radian);
std::make_shared<ALIUnitDefinition>("milliradian", "mrad", "Angle", milliradian);
std::make_shared<ALIUnitDefinition>("milliradian", "murad", "Angle", 0.001 * milliradian);
std::make_shared<ALIUnitDefinition>("steradian", "sr", "Angle", steradian);
std::make_shared<ALIUnitDefinition>("degree", "deg", "Angle", degree);
//Time
std::make_shared<ALIUnitDefinition>("second", "s", "Time", second);
std::make_shared<ALIUnitDefinition>("millisecond", "ms", "Time", millisecond);
std::make_shared<ALIUnitDefinition>("microsecond", "mus", "Time", microsecond);
std::make_shared<ALIUnitDefinition>("nanosecond", "ns", "Time", nanosecond);
std::make_shared<ALIUnitDefinition>("picosecond", "ps", "Time", picosecond);
//Frequency
std::make_shared<ALIUnitDefinition>("hertz", "Hz", "Frequency", hertz);
std::make_shared<ALIUnitDefinition>("kilohertz", "kHz", "Frequency", kilohertz);
std::make_shared<ALIUnitDefinition>("megahertz", "MHz", "Frequency", megahertz);
//Electric charge
std::make_shared<ALIUnitDefinition>("eplus", "e+", "Electric charge", eplus);
std::make_shared<ALIUnitDefinition>("coulomb", "C", "Electric charge", coulomb);
//Energy
std::make_shared<ALIUnitDefinition>("electronvolt", "eV", "Energy", electronvolt);
std::make_shared<ALIUnitDefinition>("kiloelectronvolt", "keV", "Energy", kiloelectronvolt);
std::make_shared<ALIUnitDefinition>("megaelectronvolt", "MeV", "Energy", megaelectronvolt);
std::make_shared<ALIUnitDefinition>("gigaelectronvolt", "GeV", "Energy", gigaelectronvolt);
std::make_shared<ALIUnitDefinition>("teraelectronvolt", "TeV", "Energy", teraelectronvolt);
std::make_shared<ALIUnitDefinition>("petaelectronvolt", "PeV", "Energy", petaelectronvolt);
std::make_shared<ALIUnitDefinition>("joule", "J", "Energy", joule);
//Mass
std::make_shared<ALIUnitDefinition>("milligram", "mg", "Mass", milligram);
std::make_shared<ALIUnitDefinition>("gram", "g", "Mass", gram);
std::make_shared<ALIUnitDefinition>("kilogram", "kg", "Mass", kilogram);
//Volumic Mass
std::make_shared<ALIUnitDefinition>("g/cm3", "g/cm3", "Volumic Mass", g / cm3);
std::make_shared<ALIUnitDefinition>("mg/cm3", "mg/cm3", "Volumic Mass", mg / cm3);
std::make_shared<ALIUnitDefinition>("kg/m3", "kg/m3", "Volumic Mass", kg / m3);
//Power
std::make_shared<ALIUnitDefinition>("watt", "W", "Power", watt);
//Force
std::make_shared<ALIUnitDefinition>("newton", "N", "Force", newton);
//Pressure
std::make_shared<ALIUnitDefinition>("pascal", "Pa", "Pressure", pascal);
std::make_shared<ALIUnitDefinition>("bar", "bar", "Pressure", bar);
std::make_shared<ALIUnitDefinition>("atmosphere", "atm", "Pressure", atmosphere);
//Electric current
std::make_shared<ALIUnitDefinition>("ampere", "A", "Electric current", ampere);
std::make_shared<ALIUnitDefinition>("milliampere", "mA", "Electric current", milliampere);
std::make_shared<ALIUnitDefinition>("microampere", "muA", "Electric current", microampere);
std::make_shared<ALIUnitDefinition>("nanoampere", "nA", "Electric current", nanoampere);
//Electric potential
std::make_shared<ALIUnitDefinition>("volt", "V", "Electric potential", volt);
std::make_shared<ALIUnitDefinition>("kilovolt", "kV", "Electric potential", kilovolt);
std::make_shared<ALIUnitDefinition>("megavolt", "MV", "Electric potential", megavolt);
//Magnetic flux
std::make_shared<ALIUnitDefinition>("weber", "Wb", "Magnetic flux", weber);
//Magnetic flux density
std::make_shared<ALIUnitDefinition>("tesla", "T", "Magnetic flux density", tesla);
std::make_shared<ALIUnitDefinition>("kilogauss", "kG", "Magnetic flux density", kilogauss);
std::make_shared<ALIUnitDefinition>("gauss", "G", "Magnetic flux density", gauss);
//Temperature
std::make_shared<ALIUnitDefinition>("kelvin", "K", "Temperature", kelvin);
//Amount of substance
std::make_shared<ALIUnitDefinition>("mole", "mol", "Amount of substance", mole);
//Activity
std::make_shared<ALIUnitDefinition>("becquerel", "Bq", "Activity", becquerel);
std::make_shared<ALIUnitDefinition>("curie", "Ci", "Activity", curie);
//Dose
std::make_shared<ALIUnitDefinition>("gray", "Gy", "Dose", gray);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void ALIUnitDefinition::PrintUnitsTable() {
std::cout << "\n ----- The Table of Units ----- \n";
for (size_t i = 0; i < theUnitsTable.size(); i++)
theUnitsTable[i]->PrintCategory();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIUnitsCategory::ALIUnitsCategory(ALIstring name) : Name(name), NameMxLen(0), SymbMxLen(0) {
UnitsList = *(new ALIUnitsContainer);
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIUnitsCategory::~ALIUnitsCategory() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIUnitsCategory::ALIUnitsCategory(ALIUnitsCategory& right) { *this = right; }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIUnitsCategory& ALIUnitsCategory::operator=(const ALIUnitsCategory& right) {
if (this != &right) {
Name = right.Name;
UnitsList = right.UnitsList;
NameMxLen = right.NameMxLen;
SymbMxLen = right.SymbMxLen;
}
return *this;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIint ALIUnitsCategory::operator==(const ALIUnitsCategory& right) const { return (this == &right); }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIint ALIUnitsCategory::operator!=(const ALIUnitsCategory& right) const { return (this != &right); }
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
void ALIUnitsCategory::PrintCategory() {
std::cout << "\n category: " << Name << std::endl;
for (size_t i = 0; i < UnitsList.size(); i++)
UnitsList[i]->PrintDefinition();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIBestUnit::ALIBestUnit(ALIdouble value, ALIstring category) {
// find the category
ALIUnitsTable& theUnitsTable = ALIUnitDefinition::GetUnitsTable();
size_t nbCat = theUnitsTable.size();
size_t i = 0;
while ((i < nbCat) && (theUnitsTable[i]->GetName() != category))
i++;
if (i == nbCat) {
std::cout << " ALIBestUnit: the category " << category << " does not exist !!" << std::endl;
std::cerr << "Missing unit category !" << std::endl;
abort();
}
//
IndexOfCategory = i;
nbOfVals = 1;
Value[0] = value;
Value[1] = 0.;
Value[2] = 0.;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIBestUnit::ALIBestUnit(const CLHEP::Hep3Vector& value, ALIstring category) {
// find the category
ALIUnitsTable& theUnitsTable = ALIUnitDefinition::GetUnitsTable();
size_t nbCat = theUnitsTable.size();
size_t i = 0;
while ((i < nbCat) && (theUnitsTable[i]->GetName() != category))
i++;
if (i == nbCat) {
std::cerr << " ALIBestUnit: the category " << category << " does not exist." << std::endl;
std::cerr << "Unit category not existing !" << std::endl;
abort();
}
//
IndexOfCategory = i;
nbOfVals = 3;
Value[0] = value.x();
Value[1] = value.y();
Value[2] = value.z();
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
ALIBestUnit::~ALIBestUnit() {}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
std::ostream& operator<<(std::ostream& flux, ALIBestUnit a) {
ALIUnitsTable& theUnitsTable = ALIUnitDefinition::GetUnitsTable();
ALIUnitsContainer& List = theUnitsTable[a.IndexOfCategory]->GetUnitsList();
ALIint len = theUnitsTable[a.IndexOfCategory]->GetSymbMxLen();
ALIint ksup(-1), kinf(-1);
ALIdouble umax(0.), umin(1.E12);
ALIdouble rsup(1.E12), rinf(0.);
//for a ThreeVector, choose the best unit for the biggest value
ALIdouble value = std::max(std::max(std::abs(a.Value[0]), std::abs(a.Value[1])), std::abs(a.Value[2]));
for (size_t k = 0; k < List.size(); k++) {
ALIdouble unit = List[k]->GetValue();
if (value == 1.E12) {
if (unit > umax) {
umax = unit;
ksup = k;
}
} else if (value <= -1.E12) {
if (unit < umin) {
umin = unit;
kinf = k;
}
}
else {
ALIdouble ratio = value / unit;
if ((ratio >= 1.) && (ratio < rsup)) {
rsup = ratio;
ksup = k;
}
if ((ratio < 1.) && (ratio > rinf)) {
rinf = ratio;
kinf = k;
}
}
}
ALIint index = ksup;
if (index == -1)
index = kinf;
if (index == -1)
index = 0;
for (ALIint j = 0; j < a.nbOfVals; j++) {
flux << a.Value[j] / (List[index]->GetValue()) << " ";
}
#ifdef ALIUSE_STD_NAMESPACE
std::ios::fmtflags oldform = std::cout.flags();
#else
// ALIint oldform = std::cout.flags();
#endif
flux.setf(std::ios::left, std::ios::adjustfield);
flux << std::setw(len) << List[index]->GetSymbol();
//?? flux.flags(oldform);
return flux;
}
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
|