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