Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JPlotZebraMantis.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4#include <vector>
5
6#include "TROOT.h"
7#include "TFile.h"
8#include "TH2D.h"
9
17#include "JROOT/JManager.hh"
19#include "JTools/JQuantile.hh"
20#include "JROOT/JRootToolkit.hh"
21
22#include "Jeep/JPrint.hh"
23#include "Jeep/JParser.hh"
24#include "Jeep/JMessage.hh"
25
28
29/*
30 * Gets list of keys in a ROOT TDirectory and stores it on a vector.
31 *
32 * \param dir The ROOT directory
33 * \param v Vector to store the list of keys.
34 */
35inline void readDir(TDirectory* dir,std::vector<TString> &v){
36
37 TIter iter(dir->GetListOfKeys());
38
39 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
40
41 if (key->IsFolder()){
42
43 dir->cd(key->GetName());
44 TDirectory *subdir = gDirectory;
45 readDir(subdir,v);
46 dir->cd();
47 }else{
48
49 const TString fullPath(dir->GetPath());
50 TObjArray* t = fullPath.Tokenize(":");
51 v.push_back(TString(((TObjString *)(t->At(1)))->String() + "/" + (TString)key->GetName()));
52 }
53 }
54}
55
56/**
57 * \file
58 * Auxiliary application to plot Run by Run comparisons.
59 *
60 * \author rgruiz
61 */
62
63int main(int argc, char **argv)
64{
65 using namespace std;
66 using namespace JPP;
67 using namespace KM3NETDAQ;
68
69 vector<string> inputFile;
70 string steeringFile;
71 string outputFileRoot;
72 string outputFileTxt;
73 string regexp;
74 int labelInterval;
75 int debug;
76
77 try {
78
79 JParser<> zap("Auxiliary application to plot PMT parameters.");
80
81 zap['f'] = make_field(inputFile, "JCompare output files");
82 zap['s'] = make_field(steeringFile, "JCompare steering file");
83 zap['o'] = make_field(outputFileRoot,"output file.") = "out.root";
84 zap['t'] = make_field(outputFileTxt, "output file.") = "out.txt";
85 zap['r'] = make_field(regexp, "regular expresion to extract bin labels for the x-axis") = " ";
86 zap['L'] = make_field(labelInterval, "interval between x-axis bins for which labels are shown") = 1;
87 zap['d'] = make_field(debug, "debug") = 0;
88
89 zap(argc, argv);
90 }
91 catch(const exception &error) {
92 FATAL(error.what() << endl);
93 }
94
95 const int NUMBER_OF_FILES = inputFile.size();
96
97 JManager<string, TH1D> manager (new TH1D("%", NULL, NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5));
98 JManager<string, TH1D> summaryManager(new TH1D("%", NULL, NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5));
99
100 if (regexp != " "){
101
102 const int n = (NUMBER_OF_FILES < labelInterval) ? 1 : labelInterval;
103
104 const TPRegexp buffer(regexp);
105
106 for (int i = 0; i != NUMBER_OF_FILES; ++i){
107
108 if(i%n == 0){
109 manager->GetXaxis()->SetBinLabel(i+1 , parse(buffer , TString(inputFile[i].c_str())));
110 summaryManager->GetXaxis()->SetBinLabel(i+1 , parse(buffer , TString(inputFile[i].c_str())));
111 }else{
112 manager->GetXaxis()->SetBinLabel(i+1 , " ");
113 summaryManager->GetXaxis()->SetBinLabel(i+1 , " ");
114 }
115 }
116 }
117
118 int c = 0;
119
121
122 for (vector<string>::const_iterator file = inputFile.begin() ; file != inputFile.end() ; ++file){
123
124 if (TFile::Open((*file).c_str()) == NULL) {
125 ERROR("File: " << *file << " not opened." << endl);
126 c++;
127 continue;
128 }else{
129 TFile* f = TFile::Open((*file).c_str());
130
131 vector<TString> keys;
132 readDir(f,keys);
133
134 for (vector<TString>::const_iterator key = keys.begin() ; key != keys.end() ; ++key) {
135
136 TObject* o = (TObject*)f -> Get(*key);
137
138 if(!(dynamic_cast<TH1*>(o) == NULL) || !(dynamic_cast<TH2*>(o) == NULL)){
139
140 istringstream iss(o->GetTitle());
141
142 JResultTitle t;
143 iss >> t;
144
145 quantiles[MAKE_STRING(t.parameterName)][c].put(t.value);
146 summaryManager[MAKE_STRING(t.parameterName)]->Fill(c , t.value);
147 manager[MAKE_STRING((*key).Data())]->Fill(c , t.value);
148 manager[MAKE_STRING((*key).Data())]->GetYaxis()->SetTitle(t.parameterName.c_str());
149 }
150 }
151 }
152 c++;
153 }
154
155 TFile* out = new TFile(outputFileRoot.c_str(),"recreate");
156 out->cd();
157
160
161 ifstream infile(steeringFile);
162 vector<string> tests;
163
164 string line;
165 string name;
166 int id;
167 while (getline(infile, line)) {
168 while (line.length()==0)
169 getline(infile, line);
170 tests.push_back(line);
171 istringstream iss(line);
172 iss >> name >> id;
173 map[d[id]->getTestName()]++;
174 }
175
176 ofstream summary;
177 summary.open (outputFileTxt);
178
179 for (typename JManager < string , TH1D >::const_iterator i = summaryManager.begin() ; i != summaryManager.end() ; ++i){
180 string name = MAKE_STRING(i->second->GetName());
181 int n = map[name];
182 i->second->Scale(1./n);
183 summary << "File_ID\t" << i->first << "\t" << i->first + "(ERROR)\t" << endl;
184 cout << "File_ID\t" << i->first << "\t" << i->first + "(ERROR)\t" << endl;
185
186 for (int bin=1 ; bin<i->second->GetNbinsX() ; ++bin){
187 i->second->SetBinError(bin,quantiles[name][bin].getSTDev()/sqrt(n));
188 summary << i->second->GetXaxis()->GetBinLabel(bin) << "\t" << i->second->GetBinContent(bin) << "\t" << i->second->GetBinError(bin) << endl;
189 cout << i->second->GetXaxis()->GetBinLabel(bin) << "\t" << i->second->GetBinContent(bin) << "\t" << i->second->GetBinError(bin) << endl;
190 }
191 // for (int bin=0 ; bin<i->second->GetNbinsX() ; ++bin){i->second->SetBinError(bin,0.0);cout << quantiles[name][bin].getCount() << endl;}
192 i->second->Write();
193 }
194
195 for (typename JManager < string , TH1D >::const_iterator i = manager.begin() ; i != manager.end() ; ++i){
196
197 string fullpath = MAKE_STRING(i->second->GetName());
198 string path = MAKE_STRING(fullpath.substr (fullpath.find ('/') + 1 , fullpath.rfind ('/')));
199
200 if (out->GetDirectory(path.c_str()) == 0) out->mkdir(path.c_str());
201 out->cd(path.c_str());
202
203 i -> second -> SetName(MAKE_CSTRING(fullpath.substr (fullpath.rfind ('/') + 1)));
204
205 for (int bin=0 ; bin<i->second->GetNbinsX()+1 ; ++bin){i->second->SetBinError(bin,0.0);}
206 i -> second -> Write();
207 }
208
209 out->Close();
210}
KM3NeT DAQ constants, bit handling, etc.
Detector support kit.
Data structure for detector geometry and calibration.
Dynamic ROOT object management.
General purpose messaging.
#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
int main(int argc, char **argv)
void readDir(TDirectory *dir, std::vector< TString > &v)
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
#define MAKE_STRING(A)
Make string.
Definition JPrint.hh:63
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Dictionary to map different tests to unique integer indices.
Utility class to parse command line options.
Definition JParser.hh:1698
const char * map
Definition elog.cc:87
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
KM3NeT DAQ data structures and auxiliaries.
Definition DataQueue.cc:39