Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JProject3D.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5#include <vector>
6#include <cmath>
7
8#include "TROOT.h"
9#include "TFile.h"
10#include "TKey.h"
11#include "TH3.h"
12#include "TProfile3D.h"
13#include "TString.h"
14#include "TRegexp.h"
15
18
19#include "Jeep/JParser.hh"
20#include "Jeep/JMessage.hh"
21#include "Jeep/JPrint.hh"
22
23
24/**
25 * \file
26 * Auxiliary program to project 3D histograms.
27 * \author mdejong
28 */
29int main(int argc, char **argv)
30{
31 using namespace std;
32 using namespace JPP;
33
34 vector<JRootObjectID> inputFile;
35 string outputFile;
36 char project;
37 int debug;
38
39 try {
40
41 JParser<> zap("Auxiliary program to project 3D histograms.");
42
43 zap['f'] = make_field(inputFile, "<input file>:<object name>");
44 zap['P'] = make_field(project, "projection") = ' ', 'x', 'X', 'y', 'Y', 'z', 'Z';
45 zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "project.root";
46 zap['d'] = make_field(debug) = 1;
47
48 zap(argc, argv);
49 }
50 catch(const exception &error) {
51 FATAL(error.what() << endl);
52 }
53
54 const bool px = (project == 'x' || project == 'X'); // projection on x-axis
55 const bool py = (project == 'y' || project == 'Y'); // projection on y-axis
56 const bool pz = (project == 'z' || project == 'Z'); // projection on z-axis
57
58 if ((px ? 1 : 0) +
59 (py ? 1 : 0) +
60 (pz ? 1 : 0) != 1) {
61 FATAL("Invalid operation: "
62 << (px ? "" : "no") << " X projection " << " and "
63 << (py ? "" : "no") << " Y projection " << " and "
64 << (pz ? "" : "no") << " Z projection " << endl);
65 }
66
67 vector<TObject*> listOfObjects;
68
69 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
70
71 DEBUG("Input: " << *input << endl);
72
73 TDirectory* dir = getDirectory(*input);
74
75 if (dir == NULL) {
76 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
77 continue;
78 }
79
80 const TRegexp regexp(input->getObjectName());
81
82 TIter iter(dir->GetListOfKeys());
83
84 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
85
86 const TString tag(key->GetName());
87
88 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
89
90 // option match
91
92 if (tag.Contains(regexp) && isTObject(key)) {
93
94 TH3* h3 = dynamic_cast<TH3*>(key->ReadObj());
95
96 if (h3 != NULL) {
97
98 if (px)
99 listOfObjects.push_back(h3->ProjectionX(MAKE_CSTRING(h3->GetName() << "_px")));
100 else if (py)
101 listOfObjects.push_back(h3->ProjectionY(MAKE_CSTRING(h3->GetName() << "_py")));
102 else if (pz)
103 listOfObjects.push_back(h3->ProjectionZ(MAKE_CSTRING(h3->GetName() << "_pz")));
104 }
105 }
106 }
107 }
108
109 if (!listOfObjects.empty()) {
110
111 TFile out(outputFile.c_str(), "recreate");
112
113 for (vector<TObject*>::const_iterator i = listOfObjects.begin(); i != listOfObjects.end(); ++i) {
114 (*i)->Write();
115 }
116
117 out.Write();
118 out.Close();
119 }
120}
string outputFile
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
int main(int argc, char **argv)
Definition JProject3D.cc:29
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).