Hi,
I’ve been trying to print on .txt file the elements of an array rich_bdt_var contained in the homonym branch (one element in each column of the output file), but what I get printed seems random values that are not correct (I checked which are the correct one using scan() method).
This is the TTree:
******************************************************************************
*Tree :agl_sig_bdt_tree_even: Tree for training the BDT (signal AGL,even events) *
*Entries : 8887 : Total = 4638982 bytes File Size = 2102351 *
* : : Tree compression factor = 2.21 *
******************************************************************************
*Br 0 :rich_bdt_var : rich_bdt_var[130]/F *
*Entries : 8887 : Total Size= 4638519 bytes File Size = 2100532 *
*Baskets : 146 : Basket Size= 32000 bytes Compression= 2.21 *
*............................................................................*
and the code that I am using:
#include <fstream>
#include <iomanip>
#include <iostream>
void feat_from_bdtTree()
{
// define features array
double rich_bdt_var[130] = {};
// Open the output file
std::ofstream outputFile("features_bdtTree.txt");
// Set the column width for each element
int columnWidth = 40;
//Print first row
outputFile << std::setw(columnWidth) << "entry number" << "\t";
outputFile << std::setw(columnWidth) << "parity" << "\t";
outputFile << std::setw(columnWidth) << "sample" << "\t";
for (int i = 0; i < 130; ++i) {
outputFile << std::setw(columnWidth) << "Element_" << i+1 << "\t";
}
outputFile << "\n";
//------------------------------- Even signal events
TChain *Agl_Sig_even = new TChain("agl_sig_bdt_tree_even");
Agl_Sig_even->Add("BDT_TTrees/RICH_TREE_BDT_20160509.root");
Agl_Sig_even->SetBranchAddress("rich_bdt_var", &rich_bdt_var);
// Loop over the entries and access each element of the array
for (Long64_t entry = 0; entry < Agl_Sig_even->GetEntries(); ++entry) {
Agl_Sig_even->GetEntry(entry);
outputFile << std::setw(columnWidth) << entry << "\t";
outputFile << std::setw(columnWidth) << "even" << "\t";
outputFile << std::setw(columnWidth) << "signal" << "\t";
for (int i = 0; i < 130; ++i) {
double element = rich_bdt_var[i];
outputFile << std::setw(columnWidth) << element << "\t";
}
outputFile << "\n";
}
Can someone help me understand where is the mistake?
Thank you.