4 #include <fmt/ranges.h>
6 #include <spdlog/sinks/stdout_color_sinks.h>
7 #include <spdlog/spdlog.h>
10 #include "TrdKCluster.h"
16 #include "NAIAVersion.h"
21 static constexpr
auto EXENAME = R
"(NtpMaker)";
22 static constexpr
auto USAGE = R
"(NtpMaker, NAIA ntuple version
25 NtpMaker (-i FILE...) (-o FILE) [-v | -vv] [options]
29 -i, --input-file=FILE Input file
30 -o, --output-file=FILE Output file
31 -w, --overwrite Overwrite results
32 -v... Verbosity level (once for Debug, twice for Trace)
33 -e, --from-event=EVNO Process from this event
34 -E, --single-event=EVNO Process only this event
35 -n, --nevents=NEV Process # events
36 --reprocess_rti Reprocess and replace the RTIInfo tree only
37 --use-getmcbeta Use GetMCBeta() instead of GetBeta() (default: false, needed before MC production 1308)
38 -h, --help Give this help list
44 spdlog::warn(
"Signal Handler called with signal {}", signum);
48 int main(
int argc,
char **argv) {
51 auto naiaVersion = NAIA::Version{};
52 auto versionString = fmt::format(
"{} v{}.{}.{}",
EXENAME, naiaVersion.major, naiaVersion.minor, naiaVersion.patch);
53 std::map<std::string, docopt::value>
arguments = docopt::docopt(
USAGE, {std::next(argv), std::next(argv, argc)},
60 spdlog::set_level(spdlog::level::debug);
63 spdlog::set_level(spdlog::level::trace);
68 auto inputFiles =
arguments[
"--input-file"].asStringList();
69 auto outputFile =
arguments[
"--output-file"].asString();
73 logger->info(
"Input files: {}", inputFiles);
74 logger->info(
"Output file: {}", outputFile);
76 logger->debug(
"Creating AMSChain");
77 auto amsChain = std::make_unique<AMSChain>();
78 if (spdlog::get_level() == spdlog::level::info) {
82 for (
const auto &filename : fileList) {
83 amsChain->Add(filename.c_str());
86 unsigned long long nEvents = amsChain->GetEntries();
87 logger->info(
"{} events in this file", nEvents);
90 AMSEventR *
event = amsChain->GetEvent(0);
91 bool isMC =
event->nMCEventg() > 0;
93 spdlog::debug(
"isMC = {}", isMC);
95 if (spdlog::get_level() == spdlog::level::info) {
100 unsigned long long EventNumber = 0;
101 unsigned long long firstev, lastev;
103 logger->debug(
"Run in single event mode");
104 EventNumber = amsChain->GetEntryNo(event->Run(),
arguments[
"--single-event"].asLong());
105 logger->debug(
" event no. {} - {}", event->Run(), EventNumber);
106 firstev = EventNumber;
107 lastev = EventNumber + 1;
109 logger->debug(
"Run in from-event mode");
110 EventNumber = amsChain->GetEntryNo(event->Run(),
arguments[
"--from_event"].asLong());
111 logger->debug(
" event no. {} - {}", event->Run(), EventNumber);
112 firstev = EventNumber;
113 lastev =
arguments[
"--nevents"] ? EventNumber +
arguments[
"--nevents"].asLong() : nEvents;
119 bool reprocess_rti =
arguments[
"--reprocess_rti"].asBool();
121 logger->info(
"Reprocessing RTIInfo tree only");
127 AMSSetupR::RTI::UseLatest(8);
129 AMSSetupR::SlowControlR::ReadFromExternalFile =
false;
132 TRMCFFKEY_DEF::ReadFromFile = 0;
133 TRFITFFKEY_DEF::ReadFromFile = 0;
134 TRFITFFKEY.ErcHeY = 0;
137 RichRingR::useEffectiveTemperatureCorrection =
true;
139 RichRingR::reloadRunTag =
true;
143 TrdKCluster::ForceReadAlignment = 0;
144 TrdKCluster::ForceReadCalibration = 0;
145 TrdKCluster::ForceReadXePressure = 0;
146 TrdKCluster::SetDefaultMCXePressure(900);
151 analysis.ReprocessRTI(reprocess_rti);
152 analysis.firstentry = firstev;
153 analysis.lastentry = lastev;
154 analysis.useGetMCBeta =
arguments[
"--use-getmcbeta"].asBool();
156 amsChain->Process(&analysis,
"", lastev - firstev, firstev);
158 logger->info(
"...exiting");