#include #include #include #include #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" /* * Gets list of keys in a ROOT TDirectory and stores it on a vector. * * \param dir The ROOT directory * \param v Vector to store the list of keys. */ inline void readDir(TDirectory* dir,std::vector &v){ TIter iter(dir->GetListOfKeys()); for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) { if (key->IsFolder()){ dir->cd(key->GetName()); TDirectory *subdir = gDirectory; readDir(subdir,v); dir->cd(); }else{ const TString fullPath(dir->GetPath()); TObjArray* t = fullPath.Tokenize(":"); v.push_back(TString(((TObjString *)(t->At(1)))->String() + "/" + (TString)key->GetName())); } } } /** * \file * Auxiliary application to plot Run by Run comparisons. * * \author rgruiz */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; vector inputFile; string steeringFile; string outputFileRoot; string outputFileTxt; string regexp; int labelInterval; int debug; try { JParser<> zap("Auxiliary application to plot PMT parameters."); zap['f'] = make_field(inputFile, "JCompare output files"); zap['s'] = make_field(steeringFile, "JCompare steering file"); zap['o'] = make_field(outputFileRoot,"output file.") = "out.root"; zap['t'] = make_field(outputFileTxt, "output file.") = "out.txt"; zap['r'] = make_field(regexp, "regular expresion to extract bin labels for the x-axis") = " "; zap['L'] = make_field(labelInterval, "interval between x-axis bins for which labels are shown") = 1; zap['d'] = make_field(debug, "debug") = 0; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } const int NUMBER_OF_FILES = inputFile.size(); JManager manager (new TH1D("%", NULL, NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5)); JManager summaryManager(new TH1D("%", NULL, NUMBER_OF_FILES, -0.5, NUMBER_OF_FILES - 0.5)); if (regexp != " "){ const int n = (NUMBER_OF_FILES < labelInterval) ? 1 : labelInterval; const TPRegexp buffer(regexp); for (int i = 0; i != NUMBER_OF_FILES; ++i){ if(i%n == 0){ manager->GetXaxis()->SetBinLabel(i+1 , parse(buffer , TString(inputFile[i].c_str()))); summaryManager->GetXaxis()->SetBinLabel(i+1 , parse(buffer , TString(inputFile[i].c_str()))); }else{ manager->GetXaxis()->SetBinLabel(i+1 , " "); summaryManager->GetXaxis()->SetBinLabel(i+1 , " "); } } } int c = 0; map > quantiles; for (vector::const_iterator file = inputFile.begin() ; file != inputFile.end() ; ++file){ if (TFile::Open((*file).c_str()) == NULL) { ERROR("File: " << *file << " not opened." << endl); c++; continue; }else{ TFile* f = TFile::Open((*file).c_str()); vector keys; readDir(f,keys); for (vector::const_iterator key = keys.begin() ; key != keys.end() ; ++key) { TObject* o = (TObject*)f -> Get(*key); if(!(dynamic_cast(o) == NULL) || !(dynamic_cast(o) == NULL)){ istringstream iss(o->GetTitle()); JResultTitle t; t.read(iss); quantiles[MAKE_STRING(t.parameter)][c].put(t.value); summaryManager[MAKE_STRING(t.parameter)]->Fill(c , t.value); manager[MAKE_STRING((*key).Data())]->Fill(c , t.value); manager[MAKE_STRING((*key).Data())]->GetYaxis()->SetTitle(t.parameter.c_str()); } } } c++; } TFile* out = new TFile(outputFileRoot.c_str(),"recreate"); out->cd(); map map; JTestDictionary d; ifstream infile(steeringFile); vector tests; string line; string name; int id; while (getline(infile, line)) { while (line.length()==0) getline(infile, line); tests.push_back(line); istringstream iss(line); iss >> name >> id; map[d[id]->getParameter()]++; } ofstream summary; summary.open (outputFileTxt); for (typename JManager < string , TH1D >::const_iterator i = summaryManager.begin() ; i != summaryManager.end() ; ++i){ string name = MAKE_STRING(i->second->GetName()); int n = map[name]; i->second->Scale(1./n); summary << "File_ID\t" << i->first << "\t" << i->first + "(ERROR)\t" << endl; cout << "File_ID\t" << i->first << "\t" << i->first + "(ERROR)\t" << endl; for (int bin=1 ; binsecond->GetNbinsX() ; ++bin){ i->second->SetBinError(bin,quantiles[name][bin].getSTDev()/sqrt(n)); summary << i->second->GetXaxis()->GetBinLabel(bin) << "\t" << i->second->GetBinContent(bin) << "\t" << i->second->GetBinError(bin) << endl; cout << i->second->GetXaxis()->GetBinLabel(bin) << "\t" << i->second->GetBinContent(bin) << "\t" << i->second->GetBinError(bin) << endl; } // for (int bin=0 ; binsecond->GetNbinsX() ; ++bin){i->second->SetBinError(bin,0.0);cout << quantiles[name][bin].getCount() << endl;} i->second->Write(); } for (typename JManager < string , TH1D >::const_iterator i = manager.begin() ; i != manager.end() ; ++i){ string fullpath = MAKE_STRING(i->second->GetName()); string path = MAKE_STRING(fullpath.substr (fullpath.find ('/') + 1 , fullpath.rfind ('/'))); if (out->GetDirectory(path.c_str()) == 0) out->mkdir(path.c_str()); out->cd(path.c_str()); i -> second -> SetName(MAKE_CSTRING(fullpath.substr (fullpath.rfind ('/') + 1))); for (int bin=0 ; binsecond->GetNbinsX()+1 ; ++bin){i->second->SetBinError(bin,0.0);} i -> second -> Write(); } out->Close(); }