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

Auxiliary application to plot Run by Run comparisons. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include "TROOT.h"
#include "TFile.h"
#include "TH2D.h"
#include "km3net-dataformat/online/JDAQ.hh"
#include "JDetector/JDetector.hh"
#include "JDetector/JDetectorToolkit.hh"
#include "JDetector/JPMTParametersMap.hh"
#include "JDetector/JPMTParametersToolkit.hh"
#include "JDetector/JDetectorAddressMap.hh"
#include "JDetector/JDetectorAddressMapToolkit.hh"
#include "JROOT/JManager.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "JTools/JQuantile.hh"
#include "JROOT/JRootToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"
#include "JCompareHistograms/JTest_t.hh"
#include "JCompareHistograms/JTestDictionary.hh"

Go to the source code of this file.

Functions

void readDir (TDirectory *dir, std::vector< TString > &v)
 
int main (int argc, char **argv)
 

Detailed Description

Auxiliary application to plot Run by Run comparisons.

Author
rgruiz

Definition in file JPlotZebraMantis.cc.

Function Documentation

void readDir ( TDirectory *  dir,
std::vector< TString > &  v 
)
inline

Definition at line 35 of file JPlotZebraMantis.cc.

35  {
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 }
void readDir(TDirectory *dir, vector< TString > &v)
Definition: JZebraMantis.cc:26
int main ( int  argc,
char **  argv 
)

Definition at line 63 of file JPlotZebraMantis.cc.

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  JResultTitle t;
142  t.read(iss);
143 
144  quantiles[MAKE_STRING(t.parameter)][c].put(t.value);
145  summaryManager[MAKE_STRING(t.parameter)]->Fill(c , t.value);
146  manager[MAKE_STRING((*key).Data())]->Fill(c , t.value);
147  manager[MAKE_STRING((*key).Data())]->GetYaxis()->SetTitle(t.parameter.c_str());
148  }
149  }
150  }
151  c++;
152  }
153 
154  TFile* out = new TFile(outputFileRoot.c_str(),"recreate");
155  out->cd();
156 
159 
160  ifstream infile(steeringFile);
161  vector<string> tests;
162 
163  string line;
164  string name;
165  int id;
166  while (getline(infile, line)) {
167  while (line.length()==0)
168  getline(infile, line);
169  tests.push_back(line);
170  istringstream iss(line);
171  iss >> name >> id;
172  map[d[id]->getParameter()]++;
173  }
174 
175  ofstream summary;
176  summary.open (outputFileTxt);
177 
178  for (typename JManager < string , TH1D >::const_iterator i = summaryManager.begin() ; i != summaryManager.end() ; ++i){
179  string name = MAKE_STRING(i->second->GetName());
180  int n = map[name];
181  i->second->Scale(1./n);
182  summary << "File_ID\t" << i->first << "\t" << i->first + "(ERROR)\t" << endl;
183  cout << "File_ID\t" << i->first << "\t" << i->first + "(ERROR)\t" << endl;
184 
185  for (int bin=1 ; bin<i->second->GetNbinsX() ; ++bin){
186  i->second->SetBinError(bin,quantiles[name][bin].getSTDev()/sqrt(n));
187  summary << i->second->GetXaxis()->GetBinLabel(bin) << "\t" << i->second->GetBinContent(bin) << "\t" << i->second->GetBinError(bin) << endl;
188  cout << i->second->GetXaxis()->GetBinLabel(bin) << "\t" << i->second->GetBinContent(bin) << "\t" << i->second->GetBinError(bin) << endl;
189  }
190  // for (int bin=0 ; bin<i->second->GetNbinsX() ; ++bin){i->second->SetBinError(bin,0.0);cout << quantiles[name][bin].getCount() << endl;}
191  i->second->Write();
192  }
193 
194  for (typename JManager < string , TH1D >::const_iterator i = manager.begin() ; i != manager.end() ; ++i){
195 
196  string fullpath = MAKE_STRING(i->second->GetName());
197  string path = MAKE_STRING(fullpath.substr (fullpath.find ('/') + 1 , fullpath.rfind ('/')));
198 
199  if (out->GetDirectory(path.c_str()) == 0) out->mkdir(path.c_str());
200  out->cd(path.c_str());
201 
202  i -> second -> SetName(MAKE_CSTRING(fullpath.substr (fullpath.rfind ('/') + 1)));
203 
204  for (int bin=0 ; bin<i->second->GetNbinsX()+1 ; ++bin){i->second->SetBinError(bin,0.0);}
205  i -> second -> Write();
206  }
207 
208  out->Close();
209 }
Utility class to parse command line options.
Definition: JParser.hh:1500
bool read(const JEquation &equation)
Read equation.
Definition: JProperties.hh:677
Class dedicated to standardize the title of the graphical objects produced by the JTest_t() derived c...
Definition: JTest_t.hh:22
Definition: JRoot.hh:19
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then usage $script< string identifier >< detectorfile > input file(toashort file)+" "\nNote that the input files and toashort files should be one-to-one related." fi if (( $
#define MAKE_STRING(A)
Make string.
Definition: JPrint.hh:142
then JPizza f
Definition: JPizza.sh:46
do cat driver txt<< EOFevent ev_configure{RC_EVT%< ev_configure.txt > RC_DWRT path
boost::property_tree::ptree parse(std::string str)
Definition: configure.hh:24
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
Definition: JManager.hh:43
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition: JString.hh:478
do $DIR JTransitTime o
Definition: JTransitTime.sh:44
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
then echo n User name
Definition: JCookie.sh:45
then JMuonMCEvt f $INPUT_FILE o $INTERMEDIATE_FILE d
Definition: JMuonPath.sh:45
alias put_queue eval echo n
Definition: qlib.csh:19
void readDir(TDirectory *dir, vector< TString > &v)
Definition: JZebraMantis.cc:26
const char * map
Definition: elog.cc:87