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