32 return !gSystem->AccessPathName(p_name.c_str(), kFileExists);
37 const std::string objName{entry->GetName()};
38 return ((objName.find(
"resHelper") == 0 || objName.find(
"pullHelper") == 0) &&
dynamic_cast<TH1*
>(entry));
44 const std::string name{resHelper->GetName()};
45 const std::string keyWord {
"Helper_"};
46 const size_t offset = keyWord.size();
47 auto start = name.find(keyWord)+offset;
48 auto sep = name.find(
'_',start);
49 auto sep2 = name.find(
'_',sep+1);
51 std::string first = name.substr(start, sep - start);
54 if (sep2 == std::string::npos) {
56 second = name.substr(sep + 1);
58 second = name.substr(sep + 1, sep2 - sep - 1);
59 third = name.substr(sep2 + 1);
62 return {first, second, third};
67 std::string
aux{resHelper->GetName()};
68 return aux.substr(0,
aux.find(
"Helper"));
73 auto *
h = gDirectory->Get(name.c_str());
75 std::cerr <<
"Could not find existing histogram "<<name<<
" - will not postprocess "<<std::endl;
78 auto *ret =
dynamic_cast<TH1*
>(
h->Clone(name.c_str()));
80 std::cerr <<
"Found an existing object "<<name<<
", but it is not a histogram ("<<
h->IsA()->GetName()<<
") - will not postprocess "<<std::endl;
88 return {
"resolution",
"resmean"};
90 else if (
type ==
"pull"){
91 return {
"pullwidth",
"pullmean"};
94 std::cerr <<
" Not able to identify the histogram names for a resolution type "<<
type<<
" - supported are 'res' and 'pull'. "<<std::endl;
104 TH2* resHelper2D =
dynamic_cast<TH2*
>(resHelper);
106 std::cerr <<
"Unable to reduce the histogram "<<resHelper->GetName()<<
" to a TH2 - this histo can not yet be postprocessed! " <<std::endl;
111 std::string suffix =
"_vs_"+vars[0]+
"_"+vars[1];
112 if(!vars[2].
empty()) suffix +=
"_" + vars[2];
128 auto theCWD = gDirectory;
131 auto *keys = dir->GetListOfKeys();
132 for (
auto *
const key : *keys){
134 TDirectory* theDir =
dynamic_cast<TDirectory*
>(dir->Get(key->GetName()));
141 std::unique_ptr<TObject> gotIt(dir->Get(key->GetName()));
155 std::unique_ptr<TFile> infile(TFile::Open(p_infile.c_str(),
"UPDATE"));
156 if (!infile || infile->IsZombie()) {
157 std::cerr <<
"could not open input file "<<p_infile<<
" for updating "<< std::endl;
166int main(
int argc,
char* argv[]) {
168 std::string infile{
""};
177 else if (argc == 4 && std::string(argv[1]) == std::string{
"-f"}){
179 gSystem->CopyFile(argv[3],argv[2],
true);
184 std::cerr<<
" Usage: postProcessIDPVMHistos <File to post-process>"<<std::endl;
185 std::cerr<<
" where the file is typically obtained by hadding" << std::endl;
186 std::cerr<<
" outputs of several independent IDPVM runs." << std::endl;
187 std::cerr<<
" Alternative usage: postProcessIDPVMHistos -f <desired output file name> <File to post-process>"<<std::endl;
188 std::cerr<<
" imitates a hadd-like signature for PhysVal merging." << std::endl;
193 std::cerr <<
"Error: invalid input file: " << infile << std::endl;
197 std::cout <<
" Post-processing file " << infile <<
"\n" << std::endl;
std::pair< std::vector< unsigned int >, bool > res
static const Attributes_t empty
Header file for AthHistogramAlgorithm.
void makeResolutions(const TH2 *h_input2D, TH1 *hwidth, TH1 *hmean, TH1 *hproj[], bool saveProjections, IDPVM::ResolutionHelper::methods theMethod=IDPVM::ResolutionHelper::iterRMS_convergence)
extract 1D resolution plots from a 2D "residual vs observable" histogram.
std::string getResoType(const TObject *resHelper)
int pproc_file(const std::string &p_infile)
TH1 * cloneExisting(const std::string &name)
int postProcessDir(TDirectory *dir, IDPVM::ResolutionHelper &theHelper)
bool isResolutionHelper(TObject *entry)
std::vector< std::string > getObservableAndResoAndSuffix(const TObject *resHelper)
std::pair< std::string, std::string > getPullAndResoNames(const std::string &type)
bool file_exists(const string &p_name)
int postProcessHistos(TObject *resHelper, IDPVM::ResolutionHelper &theHelper)