BluetAnalyzer/main.cc

71 lines
2.1 KiB
C++
Raw Permalink Normal View History

2024-11-23 16:56:50 +08:00
#include "BluetAnalyzer.hh"
2024-11-24 21:12:20 +08:00
#include "clipp.h"
#include "stringhandle.hh"
2024-11-23 16:56:50 +08:00
#include "iostream"
using namespace clipp;
2024-11-23 16:56:50 +08:00
using namespace std;
2024-11-24 21:12:20 +08:00
const string datapath = "/home/liuyihui/BluetAnalyzer/data";
2024-11-23 16:56:50 +08:00
int main(int argc, char **argv) {
2024-11-24 21:12:20 +08:00
string cfgfile;
string datafile;
string outputfile = "bluetAnalyzer.root";
bool draw = false;
2024-11-24 21:12:20 +08:00
vector<string> ranges;
vector<string> runfiles;
Long_t rl, rr;
auto cfg = value("config file", cfgfile);
auto data = ((required("-f", "--file").doc("data file path") &
value("data file", datafile)) |
(required("-r", "--range").doc("data file number range") &
values("number1 number2", ranges)));
auto output = (option("-o", "--output")
.doc("output file path, default: bluetAnalyzer.root") &
value("output file", outputfile),
option("-d", "--draw").doc("draw histograms").set(draw, true));
2024-11-24 21:12:20 +08:00
auto cmd = (cfg & data & output);
auto fmt = doc_formatting{}.first_column(4);
if (!parse(argc, const_cast<char **>(argv), cmd)) {
cerr << make_man_page(cmd, "BluetAnalyzer", fmt)
.prepend_section("DESCRIPTION",
" Program for MTPC Data Analysis.")
<< endl;
2024-11-23 16:56:50 +08:00
return 1;
}
2024-11-24 21:12:20 +08:00
if (ranges.size() == 0) {
runfiles.push_back(datafile);
} else {
std::vector<std::string> ifiles;
bluet::GetAllFiles(datapath, ifiles);
rl = stoll(ranges[0]);
rr = stoll(ranges[1]);
for (size_t j = 0; j < ifiles.size(); j++) {
if (bluet::SplitString(ifiles[j], '.')[4] != string("root"))
continue;
long long number = stoll(bluet::SplitString(ifiles[j], '.')[2]);
if (number >= rl && number <= rr)
runfiles.push_back(datapath + "/" + ifiles[j]);
}
}
2024-11-23 16:56:50 +08:00
BluetAnalyzer *bluet = new BluetAnalyzer();
bluet->readCutParameters(cfgfile);
bluet->defineFitFunctions();
bluet->defineHistograms();
bluet->readTreeData(runfiles);
bluet->FillHistograms();
bluet->postOperations();
bluet->saveHistograms(outputfile);
if (draw)
bluet->drawHistograms();
2024-11-23 16:56:50 +08:00
return 0;
}