34int main(
int argc,
char** argv)
37 bpo::variables_map vm;
38 bpo::options_description opt_general(
"");
39 bpo::options_description opt_hidden(
"");
40 bpo::options_description opt_all;
41 bpo::positional_options_description opt_pos;
43 std::string CalibInputPath;
44 std::string ccdbServerPath;
45 bool doBadChannelCalib;
46 bool debugMode =
false;
49 bool doBCCalibWithTime =
false;
50 std::string nameCalibInputHist;
51 std::string nameCalibInputHistAdd;
52 std::string namePathStoreLocal;
53 unsigned int nthreads;
54 unsigned long rangestart;
55 unsigned long rangeend;
61 bpo::options_description desc(
"Allowed options");
62 desc.add_options()(
"help",
"Print this help message")(
"CalibInputPath", bpo::value<std::string>()->required(),
"Set root input histogram")(
"ccdbServerPath", bpo::value<std::string>()->default_value(
o2::base::NameConf::getCCDBServer()),
"Set path to ccdb server")(
"debug", bpo::value<bool>()->default_value(
false),
"Enable debug statements")(
"storeCalibLocally", bpo::value<bool>()->default_value(
false),
"Enable local storage of calib")(
"scaleBadChannelMap", bpo::value<bool>()->default_value(
false),
"Enable the application of scale factors")(
"mode", bpo::value<std::string>()->required(),
"Set if time or bad channel calib")(
"nameInputHisto", bpo::value<std::string>()->default_value(
"hCellIdVsTimeAbove300"),
"Set name of input histogram")(
"nameInputHistoAdditional", bpo::value<std::string>()->default_value(
""),
"Set name of additional input histogram")(
"nthreads", bpo::value<unsigned int>()->default_value(1),
"Set number of threads for OpenMP")(
"timestampStart", bpo::value<unsigned long>()->default_value(1635548552000),
"Set timestamp from start of run")(
"timestampEnd", bpo::value<unsigned long>()->default_value(1635553870000),
"Set timestamp from end of run")(
"namePathStoreLocal", bpo::value<std::string>()->default_value(
""),
"Set path to store histo of time calib locally")(
"timeRangeLow", bpo::value<double>()->default_value(1),
"Set lower boundary of fit interval for time calibration (in ns)")(
"timeRangeHigh", bpo::value<double>()->default_value(1000),
"Set upper boundary of fit interval for time calibration (in ns)");
64 bpo::store(bpo::parse_command_line(argc, argv, desc), vm);
66 if (vm.count(
"help")) {
67 std::cout <<
"Please specify: CalibInputPath :Path to TFile with input histograms: \n mode: time or badchannel \n nameInputHisto: name of input calibration histogram\n";
70 if (vm.count(
"CalibInputPath")) {
71 std::cout <<
"CalibInputPath was set to "
72 << vm[
"CalibInputPath"].as<std::string>() <<
".\n";
73 CalibInputPath = vm[
"CalibInputPath"].as<std::string>();
75 std::cout <<
"CalibInputPath was not set...\n";
78 if (vm.count(
"ccdbServerPath")) {
79 std::cout <<
"ccdbServerPath was set to "
80 << vm[
"ccdbServerPath"].as<std::string>() <<
".\n";
81 ccdbServerPath = vm[
"ccdbServerPath"].as<std::string>();
83 printf(
"ccdbServerPath was not set.\nWill use standard path %s", ccdbServerPath.c_str());
86 if (vm.count(
"debug")) {
87 std::cout <<
"Enable debug mode" << std::endl;
88 debugMode = vm[
"debug"].as<
bool>();
91 if (vm.count(
"storeCalibLocally")) {
92 std::cout <<
"Enable local storage of calib" << std::endl;
93 doLocal = vm[
"storeCalibLocally"].as<
bool>();
96 if (vm.count(
"scaleBadChannelMap")) {
97 doScale = vm[
"scaleBadChannelMap"].as<
bool>();
99 std::cout <<
"Enable scaling of the bad channel map" << std::endl;
103 if (vm.count(
"mode")) {
104 std::cout <<
"mode was set to "
105 << vm[
"mode"].as<std::string>() <<
".\n";
106 std::string smode = vm[
"mode"].as<std::string>();
107 if (smode.find(
"time") != std::string::npos) {
108 std::cout <<
"performing time calibration" << std::endl;
109 doBadChannelCalib =
false;
110 }
else if (smode.find(
"badchannel") != std::string::npos) {
111 std::cout <<
"performing bad channel calibration" << std::endl;
112 doBadChannelCalib =
true;
114 std::cout <<
"mode not set... returning\n";
119 if (vm.count(
"nameInputHisto")) {
120 std::cout <<
"nameInputHisto was set to "
121 << vm[
"nameInputHisto"].as<std::string>() <<
".\n";
122 nameCalibInputHist = vm[
"nameInputHisto"].as<std::string>();
125 if (vm.count(
"nameInputHistoAdditional")) {
126 std::cout <<
"nameInputHistoAdditional was set to "
127 << vm[
"nameInputHistoAdditional"].as<std::string>() <<
".\n";
128 nameCalibInputHistAdd = vm[
"nameInputHistoAdditional"].as<std::string>();
131 if (vm.count(
"nthreads")) {
132 std::cout <<
"number of threads was set to "
133 << vm[
"nthreads"].as<
unsigned int>() <<
".\n";
134 nthreads = vm[
"nthreads"].as<
unsigned int>();
137 if (vm.count(
"timestampStart")) {
138 std::cout <<
"timestampStart was set to "
139 << vm[
"timestampStart"].as<
unsigned long>() <<
".\n";
140 rangestart = vm[
"timestampStart"].as<
unsigned long>();
143 if (vm.count(
"timestampEnd")) {
144 std::cout <<
"timestampEnd was set to "
145 << vm[
"timestampEnd"].as<
unsigned long>() <<
".\n";
146 rangeend = vm[
"timestampEnd"].as<
unsigned long>();
149 if (vm.count(
"namePathStoreLocal")) {
150 std::cout <<
"namePathStoreLocal was set to "
151 << vm[
"namePathStoreLocal"].as<std::string>() <<
".\n";
152 namePathStoreLocal = vm[
"namePathStoreLocal"].as<std::string>();
155 if (vm.count(
"timeRangeLow")) {
156 std::cout <<
"timeRangeLow was set to "
157 << vm[
"timeRangeLow"].as<
double>() <<
".\n";
158 timeRangeLow = vm[
"timeRangeLow"].as<
double>();
160 if (vm.count(
"timeRangeHigh")) {
161 std::cout <<
"timeRangeHigh was set to "
162 << vm[
"timeRangeHigh"].as<
double>() <<
".\n";
163 timeRangeHigh = vm[
"timeRangeHigh"].as<
double>();
166 }
catch (bpo::error& e) {
167 std::cerr <<
"ERROR: " << e.what() << std::endl
169 std::cerr << opt_general << std::endl;
171 }
catch (std::exception& e) {
172 std::cerr << e.what() <<
", application will now exit" << std::endl;
177 fair::Logger::SetConsoleSeverity(
"debug");
179 fair::Logger::SetConsoleSeverity(
"info");
183 TFile* fTimeCalibInput = TFile::Open(CalibInputPath.c_str());
184 if (!fTimeCalibInput) {
185 printf(
"%s not there... returning\n", CalibInputPath.c_str());
190 TH2D* hCalibInputHist_ROOT = (TH2D*)fTimeCalibInput->Get(nameCalibInputHist.c_str());
191 if (!hCalibInputHist_ROOT) {
192 printf(
"%s not there... returning\n", nameCalibInputHist.c_str());
197 TH2D* hCalibInputHistAdd_ROOT =
nullptr;
198 if (!nameCalibInputHistAdd.empty()) {
199 doBCCalibWithTime =
true;
200 hCalibInputHistAdd_ROOT = (TH2D*)fTimeCalibInput->Get(nameCalibInputHistAdd.c_str());
201 if (!hCalibInputHistAdd_ROOT) {
202 printf(
"%s not there... returning\n", nameCalibInputHist.c_str());
212 boostHisto2d_VarAxis hCalibInputHist = o2::utils::boostHistoFromRoot_2D<boostHisto2d_VarAxis>(hCalibInputHist_ROOT);
217 if (doBadChannelCalib) {
218 std::map<std::string, std::string> dummymeta;
222 printf(
"perform bad channel analysis\n");
225 if (doBCCalibWithTime) {
226 boostHisto2d_VarAxis hCalibInputHistAdd = o2::utils::boostHistoFromRoot_2D<boostHisto2d_VarAxis>(hCalibInputHistAdd_ROOT);
233 std::unique_ptr<TFile> writer(TFile::Open(Form(
"bcm_%lu.root", rangestart),
"RECREATE"));
234 writer->WriteObjectAny(&BCMap,
"o2::emcal::BadChannelMap",
"ccdb_object");
236 std::map<std::string, std::string> metadata;
241 printf(
"perform time calibration analysis\n");
245 TCparams = CalibExtractor.
calibrateTime(hCalibInputHist, timeRangeLow, timeRangeHigh);
248 std::unique_ptr<TFile> writer(TFile::Open(Form(
"timecalib_%lu.root", rangestart),
"RECREATE"));
249 writer->WriteObjectAny(&TCparams,
"o2::emcal::TimeCalibrationParams",
"ccdb_object");
252 std::map<std::string, std::string> metadata;
256 if (namePathStoreLocal.find(
".root") != std::string::npos) {
257 TFile fLocalStorage(namePathStoreLocal.c_str(),
"update");
261 histTCparams->Write(nameTCHist.c_str(), TObject::kOverwrite);
262 fLocalStorage.Close();