Jpp  15.0.5
the software that should make you happy
 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  string title;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to create TGraph2D from input file with ASCII data.");
45 
46  zap['f'] = make_field(inputFile);
47  zap['o'] = make_field(outputFile);
48  zap['T'] = make_field(title) = "";
49  zap['d'] = make_field(debug) = 1;
50 
51  zap(argc, argv);
52  }
53  catch(const exception &error) {
54  FATAL(error.what() << endl);
55  }
56 
57  using namespace JPP;
58 
59  TFile out(outputFile.c_str(), "recreate");
60 
61 
62  for (vector<string>::const_iterator file_name = inputFile.begin(); file_name != inputFile.end(); ++file_name) {
63 
64  const string gname = (title != "" ? title : getFilename(*file_name));
65 
66  ifstream in(file_name->c_str());
67 
68  while (in.peek() == '#') {
69  in.ignore(numeric_limits<streamsize>::max(), '\n');
70  }
71 
72  Double_t x, y, z, ex, ey, ez;
73 
80 
81  for (string buffer; getline(in,buffer); ) {
82 
83  istringstream is(buffer);
84 
85  if (is >> x) X .push_back(x);
86  if (is >> y) Y .push_back(y);
87  if (is >> z) Z .push_back(z);
88  if (is >> ex) EX.push_back(ex);
89  if (is >> ey) EY.push_back(ey);
90  if (is >> ez) EZ.push_back(ez);
91  }
92 
93  if (X.size() != Y.size() || X.size() != Z.size()) {
94  FATAL("Number of points " << X.size() << ' ' << Y.size() << ' ' << Z.size() << endl);
95  }
96 
97  TGraph2D* graph = NULL;
98 
99  if (EX.empty()) {
100 
101  graph = new TGraph2D(X.size(), X.data(), Y.data(), Z.data());
102 
103  } else {
104 
105  if (X.size() != EX.size()) {
106  FATAL("Number of x points " << X.size() << ' ' << EX.size() << endl);
107  }
108 
109  if (EZ.empty()) {
110  EZ.swap(EX);
111  EX.resize(X.size(), 0.0);
112  EY.resize(Y.size(), 0.0);
113  }
114 
115  if (Y.size() != EY.size()) {
116  FATAL("Number of y points " << Y.size() << ' ' << EY.size() << endl);
117  }
118 
119  if (Z.size() != EZ.size()) {
120  FATAL("Number of z points " << Z.size() << ' ' << EZ.size() << endl);
121  }
122 
123  graph = new TGraph2DErrors(X.size(), X.data(), Y.data(), Z.data(), EX.data(), EY.data(), EZ.data());
124  }
125 
126  if (graph != NULL) {
127 
128  graph->SetName(gname.c_str());
129 
130  setLimits(*graph);
131 
132  DEBUG("TGraph " << graph->GetName() << endl);
133 
134  //graph->Write();
135  }
136 
137  in.close();
138  }
139 
140  out.Write();
141  out.Close();
142 }
Utility class to parse command line options.
Definition: JParser.hh:1500
void setLimits(TGraph &g1)
Set limits of TGraph.
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
string outputFile
is
Definition: JDAQCHSM.chsm:167
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
then break fi done getCenter read X Y Z let X
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:63
#define FATAL(A)
Definition: JMessage.hh:67
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
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
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41