Error with TBranch Fill

Hi,

I’m having problems with TBranch Fill. I get the following errors when I run my code:

Error in <TBranch::WriteBasketImpl>: basket's WriteBuffer failed.
Error in <TBranch::TBranch::Fill>: Failed to write out basket.

I get these errors for only some of the events and despite the errors the output seems to be correct. The code is for the CMS Open Data guide so I need to know the reason behind the error, even though the code seems to work, because it might confuse the users.

Here is the code. I create new branches to my TTree:

int maxmuon=1000;
Float_t Dimuon_mass;
Float_t Dimuon_mass_cor;
Float_t Muon_pt_cor[maxmuon];
Float_t Muon_eta_cor[maxmuon];
Float_t Muon_phi_cor[maxmuon];
Float_t Muon_mass_cor[maxmuon];

TBranch *bDimuon_mass = DataTree->Branch("Dimuon_mass", &Dimuon_mass, "Dimuon_mass/F");
TBranch *bDimuon_mass_cor = DataTree->Branch("Dimuon_mass_cor", &Dimuon_mass_cor, "Dimuon_mass_cor/F");
TBranch *bMuon_pt_cor = DataTree->Branch("Muon_pt_cor", &Muon_pt_cor, "Muon_pt_cor[nMuon]/F");
TBranch *bMuon_eta_cor = DataTree->Branch("Muon_eta_cor", &Muon_eta_cor, "Muon_eta_cor[nMuon]/F");
TBranch *bMuon_phi_cor = DataTree->Branch("Muon_phi_cor", &Muon_phi_cor, "Muon_phi_cor[nMuon]/F");
TBranch *bMuon_mass_cor = DataTree->Branch("Muon_mass_cor", &Muon_mass_cor, "Muon_mass_cor[nMuon]/F");

Then I loop over the events. I get the error when I call Fill for the new branches. I’ve checked that the values I try to fill the branches with are correct and I can find the same values when I check the output file.

  Int_t nEntries = (Int_t)DataTree->GetEntries();

  for (Int_t k=0; k<nEntries; k++) {
    DataTree->GetEntry(k);

    // Select events with exactly two muons
    if (nMuon == 2 ) {
      // Select events with two muons of opposite charge
      if (Muon_charge[0] != Muon_charge[1]) {

        // Compute Dimuon_mass value
        // ...
        bDimuon_mass->Fill(); // Fill the branch

        // Loop over muons in event
        for (UInt_t i=0; i<nMuon; i++) {

          // Compute new (corrected) values
          // ...
        }

        // Fill branches
        bMuon_eta_pos->Fill();
        bMuon_eta_neg->Fill();
        bMuon_pt_cor->Fill();
        bMuon_eta_cor->Fill();
        bMuon_phi_cor->Fill();
        bMuon_mass_cor->Fill();

        // Compute Dimuon_mass_cor value
        // ...
        bDimuon_mass_cor->Fill(); // Fill the branch

        //Fill the corrected values to the new tree
        DataTreeCor->Fill();

        }

      }
    }

I looked at the ROOT source code and I believe that the error is caused on either line 1138, 1170 or 1291 in the code. I don’t how to find out which one it is and how to fix it. I also couldn’t find a way to not print this error without ignoring all errors (this solution would be okay as well).

-Anniina


ROOT Version: 6.22.08


What code did you use to create the TFile object and TTree object? (Most likely the TFile is not writeable)

I first create a TFile and TTree like this:

TFile *f1 = TFile::Open((pathToFile).c_str());
TTree *DataTree = (TTree*)f1->Get("Events");

where pathToFile is "root://eospublic.cern.ch//eos/opendata/cms/upload/stefan/HiggsToFourLeptonsNanoAODOutreachAnalysis/ZZTo2e2mu.root".

I then create another TFile and TTree for output:

TFile *f2 = new TFile(("./RochesterCorrections/Test/" + filename + "_Cor.root").c_str(),"recreate");
TTree *DataTreeCor = DataTree->CloneTree(0);

I managed to get rid of the errors by creating the new branches using DataTreeCor instead of DataTree. Example:

TBranch *bDimuon_mass = DataTreeCor->Branch("Dimuon_mass", &Dimuon_mass, "Dimuon_mass/F");

But now DataTreeCor is not filled with correct values.

Here is the solution if someone is having the same problem:

Create the new branches to the new tree as in the post above. The branches do not need to be filled separately. Filling the new tree inside the loop is enough.

  Int_t nEntries = (Int_t)DataTree->GetEntries();

  for (Int_t k=0; k<nEntries; k++) {
    DataTree->GetEntry(k);

    // Select events with exactly two muons
    if (nMuon == 2 ) {
      // Select events with two muons of opposite charge
      if (Muon_charge[0] != Muon_charge[1]) {

        // Compute Dimuon_mass value
        // ...

        // Loop over muons in event
        for (UInt_t i=0; i<nMuon; i++) {

          // Compute new (corrected) values
          // ...
        }

        // Compute Dimuon_mass_cor value
        // ...

        //Fill the corrected values to the new tree
        DataTreeCor->Fill();

        }

      }
    }

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