#include #include #include #include void UpdateBranch(const char* filename, const char* treename, Double_t a, Double_t b) { TFile *file = new TFile(filename, "UPDATE"); TTree *data = (TTree*)file->Get(treename); // Create new branch for the updated energy values Double_t energy_updated1; // Updated energy values Double_t energy; // energy values data->SetBranchAddress("detector.energy", &energy); TBranch *newBranch = data->Branch("energy_updated1", &energy_updated1, "energy_updated1/D"); Int_t nEntries = data->GetEntries(); for (Int_t entry = 0; entry < nEntries; entry++) { data->GetEntry(entry); energy_updated1 = a + b * energy; // Apply the calibration newBranch->Fill(); } // Write the new branch back to the tree data->Write("", TObject::kOverwrite); file->Close(); }