#include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH2D.h" #include "km3net-dataformat/online/JDAQ.hh" #include "JDetector/JDetector.hh" #include "JDetector/JDetectorToolkit.hh" #include "JDetector/JModuleRouter.hh" #include "JROOT/JManager.hh" #include "JGizmo/JGizmoToolkit.hh" #include "JROOT/JRootToolkit.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * Auxiliary application to plot detector parameters. * * \author mdejong, rgruiz */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; vector detectorFileA; vector detectorFileB; string outputFile; string regexp; int labelInterval; int debug; try { JParser<> zap("Auxiliary application to plot detector parameters."); zap['a'] = make_field(detectorFileA, "detector file."); zap['b'] = make_field(detectorFileB, "detector file.") = JPARSER::initialised(); zap['o'] = make_field(outputFile, "output file.") = "detector_parameters.root"; zap['r'] = make_field(regexp, "regular expresion to extract bin labels for the x-axis") = " "; zap['L'] = make_field(labelInterval, "interval between x-axis bins for which labels are shown") = 1; zap['d'] = make_field(debug, "debug") = 2; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (detectorFileA.empty()) { FATAL("No detector file specified." << endl); } if (detectorFileB.size() != 0 && detectorFileB.size() != detectorFileA.size()) { FATAL("Detector file size " << detectorFileA.size() << " != " << detectorFileB.size() << endl); } const int NUMBER_OF_FILES = detectorFileA.size(); JManager manager(new TH2D("%", NULL, NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5, NUMBER_OF_PMTS, -0.5, NUMBER_OF_PMTS - 0.5)); manager->Sumw2(kFALSE); if (regexp != " "){ const int n = (NUMBER_OF_FILES < labelInterval) ? 1 : labelInterval; const TPRegexp buffer(regexp); for (int i = 0; i != NUMBER_OF_FILES; ++i){ if(i%n == 0) manager->GetXaxis()->SetBinLabel(i+1 , parse(buffer , TString(detectorFileA[i].c_str()))); else manager->GetXaxis()->SetBinLabel(i+1 , " "); } } if (detectorFileB.empty()) { JDetector detector; try { load(detectorFileA[0], detector); } catch(const JException& error) { FATAL(error); } if (detector.empty()) { FATAL("Empty detector." << endl); } for (int i = 0; i != NUMBER_OF_FILES; ++i) { NOTICE("Histogram " << detectorFileA[i] << " relative to " << detectorFileA[0] << endl); JDetector buffer; try { load(detectorFileA[i], buffer); } catch(const JException& error) { FATAL(error); } JModuleRouter router(buffer); for (JDetector::iterator module = detector.begin(); module != detector.end(); ++module) { TH2D* h2 = manager[MAKE_CSTRING(module->getID() << "." << "t0")]; for (size_t pmt = 0; pmt != module->size(); ++pmt) { h2->SetBinContent(i+1, pmt+1, router.getModule(module->getID()).getPMT(pmt).getT0() - module->getPMT(pmt).getT0()); } } } } else { for (int i = 0; i != NUMBER_OF_FILES; ++i) { NOTICE("Histogram " << detectorFileA[i] << " relative to " << detectorFileB[i] << endl); JDetector detectorA; JDetector detectorB; try { load(detectorFileA[i], detectorA); load(detectorFileB[i], detectorB); } catch(const JException& error) { FATAL(error); } JModuleRouter router(detectorB); for (JDetector::iterator module = detectorA.begin(); module != detectorA.end(); ++module) { TH2D* h2 = manager[MAKE_CSTRING(module->getID() << "." << "t0")]; for (size_t pmt = 0; pmt != module->size(); ++pmt) { h2->SetBinContent(i+1, pmt+1, router.getModule(module->getID()).getPMT(pmt).getT0() - module->getPMT(pmt).getT0()); } } } } for (JManager::iterator i = manager.begin(); i != manager.end(); ++i) { i->second->Sumw2(kFALSE); } manager.Write(outputFile.c_str()); }