Jpp  test_elongated_shower_pde
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JProject3D.cc File Reference

Auxiliary program to project 3D histograms. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include "TROOT.h"
#include "TFile.h"
#include "TKey.h"
#include "TH3.h"
#include "TProfile3D.h"
#include "TString.h"
#include "TRegexp.h"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.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 project 3D histograms.

Author
mdejong

Definition in file JProject3D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 28 of file JProject3D.cc.

29 {
30  using namespace std;
31  using namespace JPP;
32 
33  vector<JRootObjectID> inputFile;
34  string outputFile;
35  char project;
36  int debug;
37 
38  try {
39 
40  JParser<> zap("Auxiliary program to project 3D histograms.");
41 
42  zap['f'] = make_field(inputFile, "<input file>:<object name>");
43  zap['P'] = make_field(project, "projection") = ' ', 'x', 'X', 'y', 'Y', 'z', 'Z';
44  zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "project.root";
45  zap['d'] = make_field(debug) = 1;
46 
47  zap(argc, argv);
48  }
49  catch(const exception &error) {
50  FATAL(error.what() << endl);
51  }
52 
53  const bool px = (project == 'x' || project == 'X'); // projection on x-axis
54  const bool py = (project == 'y' || project == 'Y'); // projection on y-axis
55  const bool pz = (project == 'z' || project == 'Z'); // projection on z-axis
56 
57  if ((px ? 1 : 0) +
58  (py ? 1 : 0) +
59  (pz ? 1 : 0) != 1) {
60  FATAL("Invalid operation: "
61  << (px ? "" : "no") << " X projection " << " and "
62  << (py ? "" : "no") << " Y projection " << " and "
63  << (pz ? "" : "no") << " Z projection " << endl);
64  }
65 
66  vector<TObject*> listOfObjects;
67 
68  for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
69 
70  DEBUG("Input: " << *input << endl);
71 
72  TDirectory* dir = getDirectory(*input);
73 
74  if (dir == NULL) {
75  ERROR("File: " << input->getFullFilename() << " not opened." << endl);
76  continue;
77  }
78 
79  const TRegexp regexp(input->getObjectName());
80 
81  TIter iter(dir->GetListOfKeys());
82 
83  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
84 
85  const TString tag(key->GetName());
86 
87  DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
88 
89  // option match
90 
91  if (tag.Contains(regexp) && isTObject(key)) {
92 
93  TH3* h3 = dynamic_cast<TH3*>(key->ReadObj());
94 
95  if (h3 != NULL) {
96 
97  if (px)
98  listOfObjects.push_back(h3->ProjectionX(MAKE_CSTRING(h3->GetName() << "_px")));
99  else if (py)
100  listOfObjects.push_back(h3->ProjectionY(MAKE_CSTRING(h3->GetName() << "_py")));
101  else if (pz)
102  listOfObjects.push_back(h3->ProjectionZ(MAKE_CSTRING(h3->GetName() << "_pz")));
103  }
104  }
105  }
106  }
107 
108  if (!listOfObjects.empty()) {
109 
110  TFile out(outputFile.c_str(), "recreate");
111 
112  for (vector<TObject*>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
113  (*i)->Write();
114  }
115 
116  out.Write();
117  out.Close();
118  }
119 }
Utility class to parse command line options.
Definition: JParser.hh:1500
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:68
#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
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.