pueoAnalysisTools
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1
7
8#include <filesystem>
9#include <regex>
10#include <iostream>
11#include "TChain.h"
12
13namespace Util {
21 inline int prepare_icefinal_chain(std::filesystem::path PUEO_MC_DATA,
22 std::unique_ptr<TChain> &passTree_chain_ptr,
23 std::unique_ptr<TChain> &allTree_chain_ptr)
24 {
25 passTree_chain_ptr = std::make_unique<TChain>("passTree");
26 allTree_chain_ptr = std::make_unique<TChain>("allTree");
27
28 std::regex re(R"(.*run(\d+))");
29 std::smatch match;
30 std::string run_name; // eg. run420/
31 std::string run_number; // eg. 420
32 std::filesystem::path icefinal_path; // eg. .../run35/IceFinal_35_allTree.root
33
34 // loop through the directory that contains all the runs
35 for (auto& p: std::filesystem::directory_iterator(PUEO_MC_DATA)){
36 run_name = p.path() // eg. /work/e513ad03_2025Feb28_f0ce4e36_2025Feb28_nnt_100_energy_20/run35
37 .filename() // eg. run35
38 .string();
39 // extract the number
40 if(std::regex_match(run_name, match, re)) {
41 run_number = match[1].str();
42 }
43
44 // check if the IceFinal_allTree.root file exists.
45 icefinal_path = p.path() / ("IceFinal_" + run_number + "_allTree.root");
46 if (!std::filesystem::exists(icefinal_path)){
47 std::cerr << "file not found: " << icefinal_path << "\n";
48 return 1;
49 }
50
51 passTree_chain_ptr -> Add(icefinal_path.string().c_str());
52 allTree_chain_ptr -> Add(icefinal_path.string().c_str());
53 }
54
55 return 0;
56 };
57
58}
int prepare_icefinal_chain(std::filesystem::path PUEO_MC_DATA, std::unique_ptr< TChain > &passTree_chain_ptr, std::unique_ptr< TChain > &allTree_chain_ptr)
Prepares two TChains that combine all the IceFinal_*_allTree.root files in the simulation output dire...
Definition util.h:21