SND@LHC Software
Loading...
Searching...
No Matches
sndGeometryGetter.cxx
Go to the documentation of this file.
1#include "sndGeometryGetter.h"
2
3#include <string>
4#include <utility>
5#include <stdexcept>
6#include <cstdlib>
7
8#include "Scifi.h"
9#include "MuFilter.h"
10#include "TPython.h"
11#include "TROOT.h"
12
13// Get geometry full path, works with test beam too
14// 2022 constants are included in the 2023 geofile
15std::string snd::analysis_tools::GetGeoPath(int run_number, std::string csv_file_path)
16{
17 if (csv_file_path.empty()) {
18 csv_file_path = std::string(getenv("SNDSW_ROOT")) + "/analysis/tools/geo_paths.csv";
19 }
20 std::ifstream file(csv_file_path);
21 if (!file.is_open()) {
22 throw std::runtime_error("Could not open CSV file: " + csv_file_path);
23 }
24
25 std::string line;
26 std::getline(file, line); // skip header
27
28 while (std::getline(file, line)) {
29 std::istringstream ss(line);
30 std::string token;
31
32 std::getline(ss, token, ',');
33 int min_run = std::stoi(token);
34
35 std::getline(ss, token, ',');
36 int max_run = std::stoi(token);
37
38 std::getline(ss, token);
39 std::string path = token;
40
41 if (run_number >= min_run && run_number <= max_run) {
42 return path;
43 }
44 }
45 throw std::runtime_error("Run number not found in CSV mapping.");
46}
47
48// Get SciFi and MuFilter geometries
49std::pair<Scifi *, MuFilter *> snd::analysis_tools::GetGeometry(const std::string& geometry_path)
50{
51 TPython::Exec("import SndlhcGeo");
52 TPython::Exec(("SndlhcGeo.GeoInterface('" + geometry_path + "')").c_str());
53
54 // Init detectors
55 Scifi *scifi = new Scifi("Scifi", kTRUE);
56 MuFilter *mufilter = new MuFilter("MuFilter", kTRUE);
57
58 // Retrieve the detectors from ROOT's global list
59 scifi = dynamic_cast<Scifi *>(gROOT->GetListOfGlobals()->FindObject("Scifi"));
60 mufilter = dynamic_cast<MuFilter *>(gROOT->GetListOfGlobals()->FindObject("MuFilter"));
61
62 return std::make_pair(scifi, mufilter);
63}
64
65// Get SciFi and MuFilter geometries directly from run number
66std::pair<Scifi *, MuFilter *> snd::analysis_tools::GetGeometry(int run_number, const std::string& csv_file_path)
67{
68 std::string geometry_path = GetGeoPath(run_number, csv_file_path);
69
70 return GetGeometry(geometry_path);
71}
Definition Scifi.h:20
std::string GetGeoPath(int run_number, std::string csv_file_path="")
std::pair< Scifi *, MuFilter * > GetGeometry(const std::string &geometry_path)