Hi everyone,
I am trying to write a variable array branch to a cloned root file. Another program clones the trees but without one branch on one tree that is to be written with the current program. After much trial and error, the code below successfully extracts the data from one tree and prints to the terminal. However, when simply assigning this data to a variable array to be written to a new branch in another file, an incorrect histogram is produced. A portion of the code is reproduced below:
TFile *file = new TFile("originalFile.root", "READ");
TTree *tree = (TTree*)file->Get("TCluster");
TFile *File = new TFile("clonedFile.root","update");
TTree *Tree = (TTree*)File->Get("TCluster");
//Number of entries
int N = tree->GetEntries();
cout << "Number of entries: " << N << endl;
int nclust, maximum;
int clustNum[N];
tree->SetBranchAddress("nclust", &nclust);
for (int i = 0; i < N; i++){
tree->GetEntry(i);
clustNum[i] = nclust;
}
maximum = clustNum[0];
//Find maximum to create arrays
for (int a = 1; a < N; a++){
if (clustNum[a] > maximum){
maximum = clustNum[a];
}
}
Float_t clustADC[maximum];
Float_t clustADCs[maximum];
TBranch *Branch = Tree->Branch("clustADCs", clustADCs, "clustADCs[nclust]/F");
tree->SetBranchAddress("clustADCs", clustADC);
int pos = 0;
for (int i = 0; i< N; i++){
for (int j = 0; j < clustNum[i]; j++){
tree->GetEntry(pos);
cout << clustADC[j] << endl;
clustADCs[j] = clustADC[j];
cout << clustADCs[j] << endl;
}
Branch->Fill();
}
Attached are histograms displaying this change (both with the same range and binning). Below is the histogram from the original file:
And the new histogram written to the new file:
Does anyone know why this is occurring or what could be causing this?
Thank you,
Stephen
ROOT Version: 6.14/00
Platform: MacOS High Sierra, v.10.13.4
Compiler: gcc version 5.1.0