2#include "CompressionMap.h"
8#include <TClonesArray.h>
9#include <TCollection.h>
11#include <TDirectory.h>
13#include <TLorentzVector.h>
19#include <TSeqCollection.h>
22#include <TSystemDirectory.h>
24#include <TVirtualPad.h>
30NamespaceImp(Hal::Std);
33 void CopyFiles(TString from, TString to, Bool_t hidden) {
34 TSystemFile file(from, from);
35 TString full_name = file.GetName();
36 full_name.ReplaceAll(
"//",
"");
37 if (full_name.EndsWith(
"/")) { full_name = TString(full_name(0, full_name.Length() - 1)); }
38 TString name(full_name(full_name.Last(
'/'), full_name.Length()));
39 if (name.BeginsWith(
".") && hidden == kFALSE)
return;
40 if (name.EqualTo(
".") || name.EqualTo(
".."))
return;
41 if (file.IsDirectory()) {
43 TSystemDirectory dir(from, from);
44 TList* list = dir.GetListOfFiles();
45 for (
int i = 0; i < list->GetEntries(); i++) {
46 TSystemFile* subfile = (TSystemFile*) list->At(i);
47 TString subname = subfile->GetName();
48 if (subname.EqualTo(
".") || subname.EqualTo(
".."))
continue;
49 TString from_path = Form(
"%s/%s", from.Data(), subname.Data());
50 TString to_path = Form(
"%s//%s", to.Data(), subname.Data());
51 CopyFiles(from_path, to_path);
54 if (name.Contains(
".."))
return;
55 if ((name.BeginsWith(
".")) && hidden == kFALSE)
return;
56 gSystem->CopyFile(from, to);
61 TDatime* time =
new TDatime();
62 Int_t day = time->GetDay();
63 Int_t month = time->GetMonth();
64 Int_t year = time->GetYear();
66 return Form(
"%04d-%02d-%02d", year, month, day);
70 TDatime* time =
new TDatime();
71 Int_t h = time->GetHour();
72 Int_t m = time->GetMinute();
74 return Form(
"%02d:%02d", h, m);
77 TString GetUniqueName(TString name) {
78 TObject* obj = gDirectory->Get(name);
79 if (obj == NULL)
return name;
81 while (gDirectory->Get(Form(
"%s_%i", name.Data(),
id))) {
84 return Form(
"%s_%i", name.Data(),
id);
87 TString UpdateEnumToString(Hal::ECutUpdate upd) {
89 case Hal::ECutUpdate::kNo:
return "";
break;
90 case Hal::ECutUpdate::kEvent:
return "Event";
break;
91 case Hal::ECutUpdate::kTrack:
return "Track";
break;
92 case Hal::ECutUpdate::kTwoTrack:
return "TwoTrack";
break;
93 case Hal::ECutUpdate::kTwoTrackBackground:
return "TwoTrackBackground";
break;
94 default:
return "";
break;
98 TString GetConfigParameter(TString par_name) {
99 TString home = gSystem->Getenv(
"HOME");
100 Hal::XMLFile parser(Form(
"%s/.hal_config.xml", home.Data()));
102 std::vector<TString> arr = Hal::Std::ExplodeString(par_name,
'/');
104 for (
int i = 1; i < (int) arr.size(); i++) {
107 if (node ==
nullptr) {
108 Hal::Cout::PrintInfo(Form(
"Node %s not found in hal configuration file", par_name.Data()), Hal::EInfo::kLowWarning);
115 std::vector<TString> GetListOfFiles(TString path, TString extension, Bool_t fullPath, Int_t recursive) {
116 TString pathLocal, pathFull;
117 TString pathPwd = gSystem->pwd();
120 pathFull = Form(
"%s", pathPwd.Data());
121 }
else if (path.BeginsWith(
"/")) {
126 pathFull = Form(
"%s/%s", pathPwd.Data(), pathLocal.Data());
128 if (path.EndsWith(
"/")) { path = path(0, path.Length() - 1); }
129 if (pathLocal.EndsWith(
"/")) { pathLocal = pathLocal(0, pathLocal.Length() - 1); }
130 if (pathFull.EndsWith(
"/")) { pathFull = pathFull(0, pathFull.Length() - 1); }
132 TSystemDirectory* dir =
new TSystemDirectory(pathLocal, pathLocal);
133 TList* list = dir->GetListOfFiles();
134 std::vector<TString> listOfFiles;
135 for (
int i = 0; i < list->GetEntries(); i++) {
136 TSystemFile* subfile = (TSystemFile*) list->At(i);
137 TString filename = subfile->GetName();
138 if (filename ==
"." || filename ==
"..")
continue;
139 if (filename.EndsWith(Form(
".%s", extension.Data())) && extension.Length()) {
141 listOfFiles.push_back(Form(
"%s/%s", pathFull.Data(), filename.Data()));
143 if (path.Length() != 0) {
144 listOfFiles.push_back(Form(
"%s/%s", path.Data(), filename.Data()));
146 listOfFiles.push_back(filename);
150 if (subfile->IsDirectory() && recursive != 0) {
151 std::vector<TString> sublist =
152 GetListOfFiles(Form(
"%s/%s", path.Data(), filename.Data()), extension, fullPath, recursive - 1);
153 listOfFiles.insert(std::end(listOfFiles), std::begin(sublist), std::end(sublist));
161 std::vector<std::vector<TVirtualPad*>> GetGridPad(Int_t x_pads, Int_t y_pads, Float_t x_margin, Float_t y_margin) {
162 TPad* padsav = (TPad*) gPad;
164 TCanvas* c =
new TCanvas();
166 padsav = (TPad*) gPad;
168 std::vector<std::vector<TVirtualPad*>> array2d;
169 ResizeVector2D(array2d, x_pads, y_pads);
170 Double_t colls = x_pads;
171 Double_t rows = y_pads;
172 Double_t x_active = 1.0 - TMath::Abs(x_margin);
173 Double_t y_active = 1.0 - TMath::Abs(y_margin);
174 Double_t x_shift = 1.0 / (colls - 1 + 1. / x_active);
175 Double_t y_shift = 1.0 / (rows - 1 + 1. / y_active);
176 Double_t x_pad = x_shift / x_active;
177 Double_t y_pad = y_shift / y_active;
180 double x1, x2, y1, y2;
181 auto trimPads = [&](
double i,
double j,
double m1,
double m2,
double m3,
double m4) {
184 y2 = 1. - j * y_shift;
194 auto* pad =
new TPad(Form(
"pad_%i_%i",
int(i),
int(j)), Form(
"pad_%i_%i",
int(i),
int(j)), x1, y1, x2, y2);
195 pad->SetTopMargin(m1);
196 pad->SetRightMargin(m2);
197 pad->SetBottomMargin(m3);
198 pad->SetLeftMargin(m4);
200 array2d[int(i)][int(j)] = pad;
205 if (x_margin >= 0 && y_margin >= 0) {
206 for (
int i = x_pads - 1; i >= 0; i--) {
207 for (
int j = 0; j < y_pads; j++) {
208 trimPads(i, j, 0, 0.0, y_margin, x_margin);
212 if (x_margin >= 0 && y_margin < 0) {
213 y_margin = TMath::Abs(y_margin);
214 for (
int i = x_pads - 1; i >= 0; i--) {
215 for (
int j = y_pads - 1; j >= 0; j--) {
216 trimPads(i, j, y_margin, 0, 0, x_margin);
221 if (x_margin < 0 && y_margin < 0) {
222 y_margin = TMath::Abs(y_margin);
223 x_margin = TMath::Abs(x_margin);
224 for (
int i = 0; i < x_pads; i++) {
225 for (
int j = y_pads - 1; j >= 0; j--) {
226 trimPads(i, j, y_margin, x_margin, 0, 0);
231 if (x_margin < 0 && y_margin >= 0) {
232 x_margin = TMath::Abs(x_margin);
233 for (
int i = 0; i < x_pads; i++) {
234 for (
int j = 0; j < y_pads; j++) {
235 trimPads(i, j, 0, x_margin, y_margin, 0);
242 TString GetHalrootPlus() {
243 TString hal_var = gSystem->Getenv(
"HAL");
244 TString vmcworkdir = gSystem->Getenv(
"VMCWORKDIR");
245 TString main_dir = hal_var;
246 TString internalPathXml =
"hal_plus/conversion_table/generators_patterns.xml";
248 std::vector<TString> location;
249 if (hal_var.Length() == 0) {
250 mainVal = vmcworkdir;
251 location.push_back(
"%s/../share/");
252 location.push_back(
"%s/../../share/");
253 location.push_back(
"%s/external/Hal/features/");
254 location.push_back(
"%s/hal/features/");
255 location.push_back(
"%s/../external/hal/features/");
256 location.push_back(
"%s/external/hal/features/");
258 location.push_back(
"%s/share/");
259 location.push_back(
"%s/../hal/features/");
262 for (
unsigned int i = 0; i < location.size(); i++) {
263 TString make_install = Form(location[i].Data(), mainVal.Data());
264 make_install = make_install + internalPathXml;
265 if (FileExists(make_install)) {
266 make_install.ReplaceAll(
"conversion_table/generators_patterns.xml",
"");
275 TString GetJsRoot() {
276 TString jsrootdir = gSystem->Getenv(
"JSROOT");
277 TString rootdir = gSystem->Getenv(
"ROOTSYS");
278 TString coreName =
"JSRootCore.js";
279 if (GetJsRootVer() >= 6) { coreName =
"JSRoot.core.js"; }
281 TString rootdirFair = rootdir +
"/share/root/js/scripts/" + coreName;
282 rootdir = rootdir +
"/js/scripts/" + coreName;
283 rootdir.ReplaceAll(
"//",
"/");
284 std::cout <<
"PATH " << rootdir << std::endl;
285 std::vector<TString> location;
286 location.push_back(rootdirFair);
287 location.push_back(rootdir);
288 TString mainVal =
"";
289 if (jsrootdir.Length() > 0) {
return jsrootdir; }
291 for (
auto place : location) {
292 if (FileExists(place)) {
293 place.ReplaceAll(
"scripts/" + coreName,
"");
301 Int_t VersionId(TString name) {
302 TString year(name(3, 4));
303 Int_t year_ver = year.Atoi();
304 TString month(name(0, 3));
306 TString month_arr[12] = {
"jan",
"feb",
"mar",
"apr",
"may",
"jun",
"jul",
"sep",
"oct",
"nov",
"dec"};
307 for (
int i = 0; i < 12; i++) {
308 if (month.EqualTo(month_arr[i])) month_ver = i + 1;
310 return year_ver * 100 + month_ver;
313 TVector3 CalcualteBoostVector(Double_t energy_per_nucleon, Int_t n_proj, Int_t p_proj, Int_t n_tar, Int_t p_tar) {
314 Double_t Np = n_proj;
315 Double_t Pp = p_proj;
318 Double_t mass1 = Hal::Const::NeutronMass() * Np + Hal::Const::ProtonMass() * Pp;
319 Double_t mass2 = Hal::Const::NeutronMass() * Nt + Hal::Const::ProtonMass() * Pt;
320 Double_t energy1 = energy_per_nucleon * (Np + Pp);
321 Double_t energy2 = mass2;
322 Double_t mom1 = TMath::Sqrt(energy1 * energy1 - mass1 * mass1);
323 TLorentzVector vec1(0, 0, mom1, energy1), vec2(0, 0, 0, energy2);
324 return -(vec1 + vec2).BoostVector();
327 Bool_t FileExists(TString path) {
328 std::ifstream test_file;
329 test_file.open(path);
330 if (test_file.good()) {
339 void CompressArray(TClonesArray* array,
const CompressionMap& map) {
340 for (
int i = 0; i < map.GetSize(); i++) {
341 if (map.GetNewIndex(i) == -1) { array->RemoveAt(i); }
347Int_t Hal::Std::GetJsRootVer() {
348 Int_t ver = ::ROOT::GetROOT()->GetVersionInt();
349 if (ver < 62400)
return 5;
static void PrintInfo(TString text, Hal::EInfo status)
XMLNode * GetChild(TString name, Int_t count=0) const