R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
neuland_cal_to_hit.cxx
Go to the documentation of this file.
1#include <FairParRootFileIo.h>
2#include <FairRootFileSink.h>
3#include <FairRunAna.h>
4#include <FairRuntimeDb.h>
5#include <R3BEventHeader.h>
7#include <R3BFileSource2.h>
8#include <R3BLogger.h>
10#include <R3BNeulandHitPar.h>
11#include <R3BProgramOptions.h>
12#include <TStopwatch.h>
13#include <filesystem>
14#include <fmt/core.h>
15#include <fmt/std.h>
16
17namespace fs = std::filesystem;
18constexpr int DEFAULT_EVENT_NUM = 0;
19constexpr auto NEULAND_GLOBAL_TIME_OFFSET_NS = -400.;
20
21using namespace std::string_literals;
22auto main(int argc, char** argv) -> int
23{
24
25 auto timer = TStopwatch{};
26 timer.Start();
27
28 auto programOptions = R3B::ProgramOptions("options for neuland exp cal to hit analysis");
29 auto help = programOptions.create_option<bool>("help,h", "help message", false);
30 auto logLevel = programOptions.create_option<std::string>("logLevel,v", "set log level of fairlog", "error");
31 auto input_file = programOptions.create_option<std::string>("in,i", "set the input files (regex)");
32 auto input_par = programOptions.create_option<std::string>("in-par,p", "set the input parameter");
33 auto output_file = programOptions.create_option<std::string>("out,o", "set the output file");
34 auto eventNum =
35 programOptions.create_option<int>("eventNum,n", "set the number of events per run", DEFAULT_EVENT_NUM);
36
37 if (!programOptions.verify(argc, argv))
38 {
39 return EXIT_FAILURE;
40 }
41
42 FairLogger::GetLogger()->SetLogScreenLevel(logLevel().c_str());
43 const auto outputDir = R3B::GetParentDir(output_file());
44 const auto outputfile_path = fs::path{ output_file() };
45 const auto outputParFileName =
46 outputDir / fmt::format("{}.par.{}", outputfile_path.stem(), outputfile_path.extension());
47 const auto input_filenames = R3B::GetFilesFromRegex(input_file());
48
49 R3BLOG(debug, fmt::format("input data file: {}", fmt::join(input_filenames, ";")).c_str());
50 R3BLOG(debug, fmt::format("input data par file: {}", input_par()).c_str());
51 R3BLOG(debug, fmt::format("output data file: {}", output_file()).c_str());
52
53 auto source = std::make_unique<R3BFileSource2>();
54 for (const auto& filename : input_filenames)
55 {
56 source->AddFile(filename);
57 }
58
59 auto sinkFile = R3B::make_rootfile(outputfile_path.c_str(), "RECREATE");
60 auto sink = std::make_unique<FairRootFileSink>(sinkFile.release());
61
62 auto run = std::make_unique<FairRunAna>();
63 FairRootManager::SetTreeName("evt");
64 try
65 {
66 auto EvntHeader = std::make_unique<R3BEventHeader>();
67 run->SetEventHeader(EvntHeader.release());
68 run->SetSource(source.release());
69 run->SetSink(sink.release());
70
71 auto fileio = std::make_unique<FairParRootFileIo>();
72 fileio->open(input_par().c_str());
73 run->GetRuntimeDb()->setFirstInput(fileio.release());
74
75 // Add analysis task --------------------------------------------------------
76 auto runIdTask = std::make_unique<R3BEventHeaderPropagator>();
77 run->AddTask(runIdTask.release());
78
79 auto cal2hit = std::make_unique<R3B::Neuland::Cal2HitTask>();
80 cal2hit->SetTrigger(R3B::Neuland::CalTrigger::onspill);
81 cal2hit->SetGlobalTimeOffset(NEULAND_GLOBAL_TIME_OFFSET_NS);
82 run->AddTask(cal2hit.release());
83
84 run->Init();
85
86 run->Run(eventNum());
87 }
88 catch (R3B::runtime_error& ex)
89 {
90 std::cout << "A runtime error has occured: \n";
91 std::cerr << ex.what();
92 std::cout << "\n\n";
93 }
94 catch (R3B::logic_error& ex)
95 {
96 std::cout << "A logic error has occured: \n";
97 std::cerr << ex.what();
98 std::cout << "\n\n";
99 }
100 catch (std::exception& ex)
101 {
102 std::cout << "A error has occured: \n";
103 std::cerr << ex.what();
104 std::cout << "\n\n";
105 }
106 catch (...)
107 {
108 std::cout << "An unrecognized error has occured: \n";
109 std::cout << "\n\n";
110 }
111
112 auto* sinkfile = run->GetSink();
113 if (sinkfile != nullptr)
114 {
115 sinkfile->Close();
116 }
117 return 0;
118}
#define R3BLOG(severity, x)
Definition R3BLogger.h:35
auto main() -> int
Definition ex_test.cxx:109
auto make_rootfile(Args &&... args)
Definition R3BShared.h:86
auto GetParentDir(std::string_view filename) -> fs::path
Definition R3BShared.h:176
auto GetFilesFromRegex(std::string_view filename_regex) -> std::vector< std::string >
Definition R3BShared.h:197
constexpr int DEFAULT_EVENT_NUM
constexpr auto NEULAND_GLOBAL_TIME_OFFSET_NS