Problem: Reading a TH1F as TObject

I want to get the GetSumOfWeights of the histograms in: run_01.root (842.2 KB)

I use the following code:

void read_root(TString path, TString keyNominal){
	TFile* file = new TFile(path, "READ");
	// Keys
	std::vector<TString> keys = {};
	// Cross sections
	std::map<string, Double_t>xs = {};	
	TIter next(file->GetListOfKeys());
    TKey *key;
    while ((key = (TKey*)next())) {
        cout << key->GetName() << endl;
		xs[key->GetName()] = file->Get(key->GetName())->GetSumOfWeights();

But I get:

/mnt/d/Sync1/Estudios/IFICCSIC/JAEICUIFIC2122/MadGraph/Project2/pp2ttbarllbar_SMEFTsim_analysis/xs_param.c:63:51: error: no member named 'GetSumOfWeights' in 'TObject'
                xs[key->GetName()] = file->Get(key->GetName())->GetSumOfWeights();
                                     ~~~~~~~~~~~~~~~~~~~~~~~~~  ^

But that things are TH1F, not TObject.

ROOT Version:ROOT 6.24/06
Platform: Debian, Windows Subsystem for Linux
Compiler: Not Provided

If all your keys are TH1F, you can simply use:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.