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 std::pair< std::string, std::string >
getTypeAndVars(
const TObject* resHelper ) {
45 const std::string
name{ resHelper->GetName() };
46 const std::string keyWord{
"Helper" };
47 const size_t pos =
name.find( keyWord );
48 const size_t pos2 =
pos + keyWord.size();
49 return {
name.substr( 0,
pos ),
name.substr( pos2 ) };
56 std::cerr <<
"Could not find existing histogram "<<
name<<
" - will not postprocess "<<std::endl;
59 auto *ret =
dynamic_cast<TH1*
>(
h->Clone(
name.c_str()));
61 std::cerr <<
"Found an existing object "<<
name<<
", but it is not a histogram ("<<
h->IsA()->GetName()<<
") - will not postprocess "<<std::endl;
69 return {
"resolution",
"resmean"};
71 else if (
type ==
"pull"){
72 return {
"pullwidth",
"pullmean"};
75 std::cerr <<
" Not able to identify the histogram names for a resolution type "<<
type<<
" - supported are 'res' and 'pull'. "<<std::endl;
90 TH2* resHelper2D =
dynamic_cast<TH2*
>(resHelper);
92 std::cerr <<
"Unable to reduce the histogram "<<resHelper->GetName()<<
" to a TH2 - this histo can not yet be postprocessed! " <<std::endl;
118 auto *
keys =
dir->GetListOfKeys();
121 TDirectory* theDir =
dynamic_cast<TDirectory*
>(
dir->Get(
key->GetName()));
128 std::unique_ptr<TObject> gotIt(
dir->Get(
key->GetName()));
139 int pproc_file(
const std::string& p_infile,
const std::string& methodStr ) {
144 std::unique_ptr<TFile>
infile(TFile::Open(p_infile.c_str(),
"UPDATE"));
146 std::cerr <<
"could not open input file "<<p_infile<<
" for updating "<< std::endl;
151 using methodMap_t = std::unordered_map<
153 methodMap_t methodMap = {
160 methodMap_t::const_iterator mitr = methodMap.find( methodStr );
161 if( mitr == methodMap.end() ) {
162 std::cerr <<
"Error: Method " << methodStr <<
163 " not found. Using iterRMS by default." << std::endl;
166 theMethod = mitr->second;
177 std::string methodStr{
"iterRMS"};
181 if(
argc == 3 ) methodStr =
argv[2];
184 std::cerr<<
" Usage: postProcessIDTPMHistos <File to post-process> <resolution method>"<<std::endl;
185 std::cerr<<
" where the file is typically obtained by hadding" << std::endl;
186 std::cerr<<
" outputs of several independent IDTPM runs." << std::endl;
187 std::cerr<<
" The resolution method (optional) is set by default to iterRMS_convergence." << std::endl;
192 std::cerr <<
"Error: invalid input file: " <<
infile << std::endl;
196 std::cout <<
" Post-processing file " <<
infile <<
"\n" << std::endl;