BluetAnalyzer/main.cc

67 lines
2.0 KiB
C++

#include "BluetAnalyzer.hh"
#include "clipp.h"
#include "stringhandle.hh"
#include "iostream"
using namespace clipp;
using namespace std;
const string datapath = "/home/liuyihui/BluetAnalyzer/data";
int main(int argc, char **argv) {
string cfgfile;
string datafile;
string outputfile = "bluetAnalyzer.root";
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))),
option("-o", "--output")
.doc("output file path, default: bluetAnalyzer.root") &
value("output file", outputfile));
auto fmt = doc_formatting{}.first_column(4);
if (!parse(argc, const_cast<char **>(argv), cfg & data)) {
cerr << make_man_page(cfg & data, "BluetAnalyzer", fmt)
.prepend_section("DESCRIPTION",
" Program for MTPC Data Analysis.")
<< endl;
return 1;
}
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]);
}
}
BluetAnalyzer *bluet = new BluetAnalyzer();
bluet->readCutParameters(cfgfile);
bluet->defineFitFunctions();
bluet->defineHistograms();
bluet->readTreeData(runfiles);
bluet->FillHistograms();
bluet->postOperations();
bluet->saveHistograms(outputfile);
bluet->drawHistograms();
return 0;
}