Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JGraph2D.cc File Reference

Auxiliary program to create TGraph2D from input file with ASCII data. More...

#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <limits>
#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"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

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

Definition in file JGraph2D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file JGraph2D.cc.

34 {
35  using namespace std;
36 
37  vector<string> inputFile;
38  string outputFile;
39  int debug;
40 
41  try {
42 
43  JParser<> zap("Auxiliary program to create TGraph2D from input file with ASCII data.");
44 
45  zap['f'] = make_field(inputFile);
46  zap['o'] = make_field(outputFile);
47  zap['d'] = make_field(debug) = 1;
48 
49  zap(argc, argv);
50  }
51  catch(const exception &error) {
52  FATAL(error.what() << endl);
53  }
54 
55  using namespace JPP;
56 
57  TFile out(outputFile.c_str(), "recreate");
58 
59 
60  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
61 
62  const string title = getFilename(*file_name);
63 
64  ifstream in(file_name->c_str());
65 
66  while (in.peek() == '#') {
67  in.ignore(numeric_limits<streamsize>::max(), '\n');
68  }
69 
70  Double_t x, y, z, ex, ey, ez;
71 
78 
79  for (string buffer; getline(in,buffer); ) {
80 
81  istringstream is(buffer);
82 
83  if (is >> x) X .push_back(x);
84  if (is >> y) Y .push_back(y);
85  if (is >> z) Z .push_back(z);
86  if (is >> ex) EX.push_back(ex);
87  if (is >> ey) EY.push_back(ey);
88  if (is >> ez) EZ.push_back(ez);
89  }
90 
91  if (X.size() != Y.size() || X.size() != Z.size()) {
92  FATAL("Number of points " << X.size() << ' ' << Y.size() << ' ' << Z.size() << endl);
93  }
94 
95  TGraph2D* graph = NULL;
96 
97  if (EX.empty()) {
98 
99  graph = new TGraph2D(X.size(), X.data(), Y.data(), Z.data());
100 
101  } else {
102 
103  if (X.size() != EX.size()) {
104  FATAL("Number of x points " << X.size() << ' ' << EX.size() << endl);
105  }
106 
107  if (EZ.empty()) {
108  EZ.swap(EX);
109  EX.resize(X.size(), 0.0);
110  EY.resize(Y.size(), 0.0);
111  }
112 
113  if (Y.size() != EY.size()) {
114  FATAL("Number of y points " << Y.size() << ' ' << EY.size() << endl);
115  }
116 
117  if (Z.size() != EZ.size()) {
118  FATAL("Number of z points " << Z.size() << ' ' << EZ.size() << endl);
119  }
120 
121  graph = new TGraph2DErrors(X.size(), X.data(), Y.data(), Z.data(), EX.data(), EY.data(), EZ.data());
122  }
123 
124  if (graph != NULL) {
125 
126  graph->SetName(title.c_str());
127 
128  setLimits(*graph);
129 
130  DEBUG("TGraph " << graph->GetName() << endl);
131 
132  //graph->Write();
133  }
134 
135  in.close();
136  }
137 
138  out.Write();
139  out.Close();
140 }
Utility class to parse command line options.
Definition: JParser.hh:1493
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
Definition: JSirene.sh:45
void setLimits(TGraph &g1)
Set limits of TGraph.
string outputFile
is
Definition: JDAQCHSM.chsm:167
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1954
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
int debug
debug level
Definition: JSirene.cc:61
#define FATAL(A)
Definition: JMessage.hh:67
std::string getFilename(const std::string &file_name)
Get file name part, i.e. part after last JEEP::PATHNAME_SEPARATOR if any.
Definition: JeepToolkit.hh:88
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62