#include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TGraph2D.h" #include "TGraph2DErrors.h" #include "JGizmo/JGizmoToolkit.hh" #include "Jeep/JeepToolkit.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \file * Auxiliary program to create TGraph2D from input file with ASCII data. * * Supported input file formats: *
 *     x y z
 *     x y z ez
 *     x y z ex ey ez
 * 
* * Lines starting with a '#' are skipped. * \author mdejong */ int main(int argc, char **argv) { using namespace std; vector inputFile; string outputFile; string title; int debug; try { JParser<> zap("Auxiliary program to create TGraph2D from input file with ASCII data."); zap['f'] = make_field(inputFile); zap['o'] = make_field(outputFile); zap['T'] = make_field(title) = ""; zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; TFile out(outputFile.c_str(), "recreate"); for (vector::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) { const string gname = (title != "" ? title : getFilename(*file_name)); ifstream in(file_name->c_str()); while (in.peek() == '#') { in.ignore(numeric_limits::max(), '\n'); } Double_t x, y, z, ex, ey, ez; vector X; vector Y; vector Z; vector EX; vector EY; vector EZ; for (string buffer; getline(in,buffer); ) { istringstream is(buffer); if (is >> x) X .push_back(x); if (is >> y) Y .push_back(y); if (is >> z) Z .push_back(z); if (is >> ex) EX.push_back(ex); if (is >> ey) EY.push_back(ey); if (is >> ez) EZ.push_back(ez); } if (X.size() != Y.size() || X.size() != Z.size()) { FATAL("Number of points " << X.size() << ' ' << Y.size() << ' ' << Z.size() << endl); } TGraph2D* graph = NULL; if (EX.empty()) { graph = new TGraph2D(X.size(), X.data(), Y.data(), Z.data()); } else { if (X.size() != EX.size()) { FATAL("Number of x points " << X.size() << ' ' << EX.size() << endl); } if (EZ.empty()) { EZ.swap(EX); EX.resize(X.size(), 0.0); EY.resize(Y.size(), 0.0); } if (Y.size() != EY.size()) { FATAL("Number of y points " << Y.size() << ' ' << EY.size() << endl); } if (Z.size() != EZ.size()) { FATAL("Number of z points " << Z.size() << ' ' << EZ.size() << endl); } graph = new TGraph2DErrors(X.size(), X.data(), Y.data(), Z.data(), EX.data(), EY.data(), EZ.data()); } if (graph != NULL) { graph->SetName(gname.c_str()); setLimits(*graph); DEBUG("TGraph " << graph->GetName() << endl); //graph->Write(); } in.close(); } out.Write(); out.Close(); }