Hello Philippe,
Allow me to share the current implementation of the main function in the macro that I am trying to use. Included are lines commented out from previous attempts.
void refactorPolarityTestsFileA4() {
// Open original format file and access its trees.
TFile polarityTestsFile("waisPolCutFilesA4/polarityTestsFileA4.root");
TTree * eventTree = (TTree *) polarityTestsFile.Get("eventTree");
TTree * waisPointingTree = (TTree *) polarityTestsFile.Get("waisPointingTree");
TTree * polarityTestsTree = (TTree *) polarityTestsFile.Get("polarityTestsTree");
TTree * deconvPolarityTestsTree = (TTree *) polarityTestsFile.Get("deconvPolarityTestsTree");
TTree * windowedPolarityTestsTree = (TTree *) polarityTestsFile.Get("windowedPolarityTestsTree");
TTree * windowedDeconvPolarityTestsTree = (TTree *) polarityTestsFile.Get("windowedDeconvPolarityTestsTree");
// Create file to store trees in, then new tree to store 4 trees.
TFile reformattedFile("waisPolCutFilesA4/polarityTestsFileA4reformatted.root", "recreate");
TTree reformattedTree("polarityTestsTree", "TTree storing polarity test results");
TBranch waveformTests, deconvTests, windowedTests, windowedDeconvTests;
reformattedTree.Branch("waveformTests.", & waveformTests);
reformattedTree.Branch("deconvTests.", & deconvTests);
reformattedTree.Branch("windowedTests.", & windowedTests);
reformattedTree.Branch("windowedDeconvTests.", & windowedDeconvTests);
// Structure the branches of the reformatted tree.
// TBranch waveformBranch[6], deconvBranch[6], windowedBranch[6], windowedDeconvBranch[6];
// polarity waveformStruct[6], deconvStruct[6], windowedStruct[6], windowedDeconvStruct[6];
// addSubbranches(waveformTests, waveformBranch, waveformStruct);
// addSubbranches(deconvTests, deconvBranch, deconvStruct);
// addSubbranches(windowedTests, windowedBranch, windowedStruct);
// addSubbbranches(windowedDeconvTests, windowedDeconvBranch, windowedDeconvStruct);
// Now, copy the branches.
CollectBranches(polarityTestsTree -> GetListOfBranches(), waveformTests.GetListOfBranches());
reformattedTree.CollectBranches(deconvPolarityTestsTree -> GetListOfBranches(), deconvTests.GetListOfBranches());
reformattedTree.CollectBranches(windowedPolarityTestsTree -> GetListOfBranches(), windowedTests.GetListOfBranches());
reformattedTree.CollectBranches(windowedDeconvPolarityTestsTree -> GetListOfBranches(), windowedDeconvTests.GetListOfBranches());
// waveformTests.GetListOfBranches() -> Add((TObjArray *) polarityTestsTree -> GetListOfBranches() -> Clone());
// deconvTests.GetListOfBranches() -> Add((TObjArray *) deconvPolarityTestsTree -> GetListOfBranches() -> Clone());
// windowedTests.GetListOfBranches() -> Add((TObjArray *) windowedPolarityTestsTree -> GetListOfBranches() -> Clone());
// windowedDeconvTests.GetListOfBranches() -> Add((TObjArray *) windowedDeconvPolarityTestsTree -> GetListOfBranches() -> Clone());
// branchCopy(polarityTestsTree, waveformTests);
// branchCopy(deconvPolarityTestsTree, deconvTests);
// branchCopy(windowedPolarityTestsTree, windowedTests);
// branchCopy(windowedDeconvPolarityTestsTree, windowedDeconvTests);
// Now, to write to this new tree.
// for (int entryNum = 0; entryNum < waisPointingTree -> GetEntries(); ++entryNum) {
//
// polarityTestsTree -> GetEntry(entryNum);
// deconvPolarityTestsTree -> GetEntry(entryNum);
// windowedPolarityTestsTree -> GetEntry(entryNum);
// windowedDeconvPolarityTestsTree -> GetEntry(entryNum);
//
//// reformattedTree.Fill();
// waveformTests.Fill();
// deconvTests.Fill();
// windowedTests.Fill();
// windowedDeconvTests.Fill();
// }
// Write to the relevant trees to the reformatted file.
reformattedFile.cd();
eventTree -> CloneTree() -> Write();
waisPointingTree -> CloneTree() -> Write();
reformattedTree.Write();
// Closing files.
reformattedFile.Close();
polarityTestsFile.Close();
}