Problem with Filling ROOT Trees

Hello,

I am having issues with my branch being filled with zeros. This is how I declare my array, tree, and branch.

double integral_HUGE_x[4][128];
TTree * t_HUGE_x = new TTree("HUGE_x","HUGE_x");
TBranch * b_integral_HUGE_x = t_HUGE_x->Branch("integral_HUGE_x",integral_HUGE_x,"integral_HUGE_x[4][128]");

And this is how I attempt to fill it.

	for (int iapv = 0; iapv < 4 ; iapv++) 
	{
		for (int ich = 0; ich < 128; ich++)
		{
			h_raw_title = Form("h_2_%d_%d",iapv,ich);
			h_wfm = (TH1D*) gROOT->FindObject(h_raw_title);
			integral_HUGE_x[iapv][ich] = h_wfm->Integral(1,sample_length);
		}
	}
	t_HUGE_x->Fill();

If I use cout to check the values of integral_HUGE_x before and after I call t_HUGE_x->Fill(), I see non-zero values. But for some reason, when saved they appear as zeroes (and a couple 7s). Also, changing t_Huge_x->Fill() to b_integral_HUGE_x->Fill(); results in no histogram showing up when I click on the tree in TBrowser.

Oddly enough, when I use the same exact code for two arrays before this one, it works fine. It is only this tree (and one that comes after it) that is giving me a problem.

Thank you in advance for the assistance.


ROOT Version: 5.34/30
Platform: Not Provided
Compiler: Not Provided


TBranch *b_integral_HUGE_x = t_HUGE_x->Branch("integral_HUGE_x", integral_HUGE_x, "integral_HUGE_x[4][128]/D");

Tried it, still getting the same issue

Try (something that works fine for me):

{
  double integral_HUGE_x[4][128];
  TTree *t_HUGE_x = new TTree("HUGE_x", "HUGE_x");
  TBranch *b_integral_HUGE_x = t_HUGE_x->Branch("integral_HUGE_x", integral_HUGE_x, "integral_HUGE_x[4][128]/D");
  for (int i = 0; i < 4; i++) for (int j = 0; j < 128; j++) integral_HUGE_x[i][j] = (i + 1) * 1000 + (j + 1);
  t_HUGE_x->Fill(); // just one entry
  t_HUGE_x->ResetBranchAddresses(); // disconnect from local variables
  t_HUGE_x->Print();
  t_HUGE_x->Scan(); // do you see correct values printed?
}

It prints out either 0 or 7 with some decimals at the end for me.

So, it is probably a bug in your (very old) ROOT 5 version.
Try the head of the v5-34-00-patches branch for ROOT 5 or the newest ROOT 6 release.

Yikes. Unfortunately the SRS system my lab uses is only compatible with that specific ROOT version. Thank you for trying though, really appreciate it.

Can you post here the output of t_HUGE_x->Print();

Note that the “head of the v5-34-00-patches branch” contains mostly various bug fixes as compared to your ROOT 5.34/30 so your “SRS system” should also be compatible with it (well, maybe you just need to rebuild it from scratch).


******************************************************************************
*Tree    :HUGE_x    : HUGE_x                                                 *
*Entries :        1 : Total =            3048 bytes  File  Size =          0 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :integral_HUGE_x : Float_t integral_HUGE_x[4][128]                  *
*Entries :        1 : Total  Size=       2760 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
***********************************
*    Row   * Instance * integral_ *
***********************************
*        0 *        0 *         0 *
*        0 *        1 * 7.4802246 *
*        0 *        2 *         0 *
*        0 *        3 * 7.4824218 *
*        0 *        4 *         0 *
*        0 *        5 * 7.4960327 *
*        0 *        6 *         0 *
*        0 *        7 * 7.5000915 *
*        0 *        8 *         0 *
*        0 *        9 * 7.4935607 *
*        0 *       10 *         0 *
*        0 *       11 * 7.4938049 *
*        0 *       12 *         0 *
*        0 *       13 * 7.4962310 *
*        0 *       14 *         0 *
*        0 *       15 * 7.4924774 *
*        0 *       16 *         0 *
*        0 *       17 * 7.4907074 *
*        0 *       18 *         0 *
*        0 *       19 * 7.4967956 *
*        0 *       20 *         0 *
*        0 *       21 * 7.5024490 *
*        0 *       22 *         0 *
*        0 *       23 * 7.4958953 *
*        0 *       24 *         0 *
Type <CR> to continue or q to quit ==> *        0 *       25 * 7.5019073 *

The “Print” output that you show does NOT correspond to my test macro (and then the “Scan” output is wrong, of course).
Please RUN my test macro AS IS, WITHOUT ANY MODIFICATIONS (i.e. use “copy” + “paste” my source code, do NOT edit / modify it).

My mistake. Here is the output.

Processing test.c...
******************************************************************************
*Tree    :HUGE_x    : HUGE_x                                                 *
*Entries :        1 : Total =            5106 bytes  File  Size =          0 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :integral_HUGE_x : integral_HUGE_x[4][128]/D                        *
*Entries :        1 : Total  Size=       4818 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
***********************************
*    Row   * Instance * integral_ *
***********************************
*        0 *        0 *      1001 *
*        0 *        1 *      1002 *
*        0 *        2 *      1003 *
*        0 *        3 *      1004 *
*        0 *        4 *      1005 *
*        0 *        5 *      1006 *
*        0 *        6 *      1007 *
*        0 *        7 *      1008 *
*        0 *        8 *      1009 *
*        0 *        9 *      1010 *
*        0 *       10 *      1011 *
*        0 *       11 *      1012 *
*        0 *       12 *      1013 *
*        0 *       13 *      1014 *
*        0 *       14 *      1015 *
*        0 *       15 *      1016 *
*        0 *       16 *      1017 *
*        0 *       17 *      1018 *
*        0 *       18 *      1019 *
*        0 *       19 *      1020 *
*        0 *       20 *      1021 *
*        0 *       21 *      1022 *
*        0 *       22 *      1023 *
*        0 *       23 *      1024 *
*        0 *       24 *      1025 *
Type <CR> to continue or q to quit ==>

So, your very old ROOT 5 version is fine enough, as you can see.

BTW. When you post “source code” or “output” here, do remember to enclose them into two lines which contain just three characters ``` (see how your post has been edited above).

Okay. But when I tested that code, I tested it in its own separate .c file. When I paste your code right into the .c file I need to run, it produces results similar to what I posted originally (with 4s instead of 7s).

The only difference is that your code is now in an additional for loop (looping over multiple events), therefore the declaration of the array, branch, and tree are outside that additional for loop.

“Copy” + “paste” the source code (which created the branch) from my very first post above AS IS, WITHOUT ANY MODIFICATIONS.
Then run your macro and check the output of t_HUGE_x->Print(); and make sure that you see *Br 0 :integral_HUGE_x : integral_HUGE_x[4][128]/D *

Alright, now your code is giving the right results, even when I place it in the spot I need it to be in. Now, how would I go about modifying it to give the values I need?

Thank you for your patience as well.

I just corrected the bug in your branch definition.
I have no idea what another bugs you may have in your code.
Looking at the source code snippet in your first post above, I would at least try:

integral_HUGE_x[iapv][ich] = (h_wfm ? h_wfm->Integral(1,sample_length) : 0.);

I will keep working on it. Thanks for everything

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