Macro in ROOT5 don't work in ROOT6

Hello ROOTers,

I received a macro written for ROOT5 and im trying to execute it in ROOT6.22:

void Miniarray_RUN4_barometric_coefficient()
{
	// Read the miniarray tree file to evaluate barometric coefficient
	// from pressure-shower rate scatter plot  

    Int_t seconds2007, nanosec, mult, nevents, ntrending,neff;
    Int_t nshower[31][5000];
    Float_t press,pressure[5000];
    
    for(Int_t is=1; is<=30; is++) {
   	 for(Int_t im=0; im<5000; im++) {
     nshower[is][im]=0;
     }
    }


TChain chain("tree_arduino");
chain.Add("RUN4_prova1.root");
chain.Add("RUN4_2.root");  
chain.Add("RUN4_3.root");
chain.Add("RUN4_4.root");
chain.Add("RUN4_5.root");
chain.Add("RUN4_6.root");

	//TFile *f = new TFile("RUN4_6.root");	
	nevents=tree_arduino->GetEntries();
	cout<<"N.events: "<<nevents<<endl;

	tree_arduino->SetBranchAddress("seconds2007", &seconds2007);
	tree_arduino->SetBranchAddress("nanosec", &nanosec);				
	tree_arduino->SetBranchAddress("mult", &mult);  
    
  tree_arduino->GetEntry(0);
  Float_t t0=seconds2007;
  cout<<"t0= "<<t0<<endl;
  
  Int_t im=0;
  for(Int_t iev = 1; iev < nevents; iev++){  //Loop on event-by-event tree_Arduino
   tree_arduino->GetEntry(iev);
   if(seconds2007<t0+1860) nshower[mult][im]++;
   if(seconds2007>t0+1860) {
   	 //cout<<im<<"  "<<seconds2007<<"  "<<nshower[4][im]<<endl;
     im++;
	 t0=seconds2007;
	}    

  }  // End loop on events in the file
	
 
TChain chain("tree_trending");
chain.Add("RUN4_prova1.root");
chain.Add("RUN4_2.root");
chain.Add("RUN4_3.root");
chain.Add("RUN4_4.root");
chain.Add("RUN4_5.root");
chain.Add("RUN4_6.root");

tree_trending->SetBranchAddress("press", &press);
tree_trending->SetBranchAddress("seconds2007", &seconds2007);

ntrending = tree_trending->GetEntries();
cout << "Overall number of points: " << ntrending << endl;
for (Int_t itrend = 0; itrend < ntrending; itrend++)
{ //Loop on trending values
  tree_trending->GetEntry(itrend);
  pressure[itrend] = press;
  //cout<<itrend<<"  "<<seconds2007<<"  "<<press<<endl;
   
  }  // End loop 



    Float_t nshower_integrated[5000];
    Int_t mult_min=5;
    Int_t mult_max=7;
    cout<<"Analysis for events with multiplicity: "<<mult_min<<"-"<<mult_max<<endl;
    for(Int_t j = 0; j < ntrending; j++){ 
     nshower_integrated[j]=0;
     for(Int_t m = mult_min; m <= mult_max; m++){
      nshower_integrated[j]=nshower_integrated[j]+nshower[m][j];
     }
    }

    Float_t average_rate=0.0;
    for(Int_t j = 0; j < ntrending; j++){ 
    average_rate=average_rate+nshower_integrated[j];
     //cout<<j<<"  "<<pressure[j]<<"  "<<nshower_integrated[j]<<endl;
    }
    average_rate=average_rate/ntrending;
    cout<<"Average rate of all showers with mult "<<mult_min<<"-"<<mult_max<<" : "<<average_rate<<endl;
    
    TCanvas *c1 = new TCanvas("c1","",1000,700);
    TGraph *gr1 = new TGraph(ntrending,pressure,nshower_integrated);
    gr1->SetTitle("");
    gr1->SetMarkerColor(4);
    gr1->SetMarkerStyle(22);
    gr1->Draw("AP");

/*
    TCanvas *c2 = new TCanvas("c2","",1000,700);
   
    Float_t pressure_notzero[5000],yield_notzero[5000];
    Int_t j_notzero=0;
    
    Float_t average_rate=0.0;
    for(Int_t j = 0; j < ntrending; j++){ 
       if(nshower_integrated[j]>0) {
	     yield_notzero[j_notzero]=nshower_integrated[j];
	     average_rate=average_rate+yield_notzero[j_notzero];
         pressure_notzero[j_notzero]=pressure[j]; 
         //cout<<j_notzero<<"  "<<pressure_notzero[j_notzero]<<"  "<<yield_notzero[j_notzero]<<endl;
         j_notzero++;
         }
    }
    j_notzero--;
    
    TGraph *gr2 = new TGraph(j_notzero,pressure_notzero,yield_notzero);
    gr2->SetTitle("");
    gr2->SetMarkerColor(4);
    gr2->SetMarkerStyle(22);
    gr2->Draw("AP");

    average_rate=average_rate/j_notzero;
    cout<<"Average rate (different from 0) with mult: "<<mult_min<<"-"<<mult_max<<" : "<<average_rate<<endl;
    cout<<"Number of points with at least one shower in 30': "<<j_notzero<<endl;

*/

}

But doesn’t work:

error: use of undeclared identifier 'tree_arduino'
        nevents=tree_arduino->GetEntries();
                ^
error: use of undeclared identifier 'tree_arduino'
        tree_arduino->SetBranchAddress("seconds2007", &seconds2007);
        ^
error: use of undeclared identifier 'tree_arduino'
        tree_arduino->SetBranchAddress("nanosec", &nanosec);                            
        ^
error: use of undeclared identifier 'tree_arduino'
        tree_arduino->SetBranchAddress("mult", &mult);  
        ^
error: use of undeclared identifier 'tree_arduino'
  tree_arduino->GetEntry(0);
  ^
error: use of undeclared identifier 'tree_arduino'
   tree_arduino->GetEntry(iev);
   ^
error: redefinition of 'chain'
TChain chain("tree_trending");
       ^
note: previous definition is here
TChain chain("tree_arduino");
       ^
error: use of undeclared identifier 'tree_trending'
tree_trending->SetBranchAddress("press", &press);
^
error: use of undeclared identifier 'tree_trending'
tree_trending->SetBranchAddress("seconds2007", &seconds2007);
^
error: use of undeclared identifier 'tree_trending'
ntrending = tree_trending->GetEntries();
            ^
error: use of undeclared identifier 'tree_trending'
  tree_trending->GetEntry(itrend);
  ^

What i can do in order to run it? I post also the root file
RUN4_prova1.root (680,7 KB)

This code run on root5, it is normal that dont run in root6? Why?

Thanks in advance.


ROOT Version: 6.22
Platform: Ubuntu 20.10
Compiler: gcc 9.3


   TFile *f = TFile::Open("RUN4_prova1.root");
   if (!file) {
      std::cout << "error opening the file\n";
      return;
   }
   TTree *tree_arduino = nullptr;
   f->GetObject("tree_arduino", tree_arduino);
   if  (!tree_arduino) {
      std::cout << "error reading the tree\n";
      return;
   }

where should i paste it? should i comment something in the code?

Before the first use of tree_arduino

You mean this:

void Miniarray_RUN4_barometric_coefficient()
{
	// Read the miniarray tree file to evaluate barometric coefficient
	// from pressure-shower rate scatter plot  

    Int_t seconds2007, nanosec, mult, nevents, ntrending,neff;
    Int_t nshower[31][5000];
    Float_t press,pressure[5000];
    
    for(Int_t is=1; is<=30; is++) {
   	 for(Int_t im=0; im<5000; im++) {
     nshower[is][im]=0;
     }
    }

    TFile *f = TFile::Open("RUN4_prova1.root");
    if (!file)
    {
      std::cout << "error opening the file\n";
      return;
    }
    TTree *tree_arduino = nullptr;
    f->GetObject("tree_arduino", tree_arduino);
    if (!tree_arduino)
    {
      std::cout << "error reading the tree\n";
      return;
    }

TChain chain("tree_arduino");
chain.Add("RUN4_prova1.root");
chain.Add("RUN4_2.root");  
chain.Add("RUN4_3.root");
chain.Add("RUN4_4.root");
chain.Add("RUN4_5.root");
chain.Add("RUN4_6.root");

	//TFile *f = new TFile("RUN4_6.root");	
	nevents=tree_arduino->GetEntries();
	cout<<"N.events: "<<nevents<<endl;

	tree_arduino->SetBranchAddress("seconds2007", &seconds2007);
	tree_arduino->SetBranchAddress("nanosec", &nanosec);				
	tree_arduino->SetBranchAddress("mult", &mult);  
    
  tree_arduino->GetEntry(0);
  Float_t t0=seconds2007;
  cout<<"t0= "<<t0<<endl;
  
  Int_t im=0;
  for(Int_t iev = 1; iev < nevents; iev++){  //Loop on event-by-event tree_Arduino
   tree_arduino->GetEntry(iev);
   if(seconds2007<t0+1860) nshower[mult][im]++;
   if(seconds2007>t0+1860) {
   	 //cout<<im<<"  "<<seconds2007<<"  "<<nshower[4][im]<<endl;
     im++;
	 t0=seconds2007;
	}    

  }  // End loop on events in the file
	
 
TChain chain("tree_trending");
chain.Add("RUN4_prova1.root");
chain.Add("RUN4_2.root");
chain.Add("RUN4_3.root");
chain.Add("RUN4_4.root");
chain.Add("RUN4_5.root");
chain.Add("RUN4_6.root");

tree_trending->SetBranchAddress("press", &press);
tree_trending->SetBranchAddress("seconds2007", &seconds2007);

ntrending = tree_trending->GetEntries();
cout << "Overall number of points: " << ntrending << endl;
for (Int_t itrend = 0; itrend < ntrending; itrend++)
{ //Loop on trending values
  tree_trending->GetEntry(itrend);
  pressure[itrend] = press;
  //cout<<itrend<<"  "<<seconds2007<<"  "<<press<<endl;
   
  }  // End loop 



    Float_t nshower_integrated[5000];
    Int_t mult_min=5;
    Int_t mult_max=7;
    cout<<"Analysis for events with multiplicity: "<<mult_min<<"-"<<mult_max<<endl;
    for(Int_t j = 0; j < ntrending; j++){ 
     nshower_integrated[j]=0;
     for(Int_t m = mult_min; m <= mult_max; m++){
      nshower_integrated[j]=nshower_integrated[j]+nshower[m][j];
     }
    }

    Float_t average_rate=0.0;
    for(Int_t j = 0; j < ntrending; j++){ 
    average_rate=average_rate+nshower_integrated[j];
     //cout<<j<<"  "<<pressure[j]<<"  "<<nshower_integrated[j]<<endl;
    }
    average_rate=average_rate/ntrending;
    cout<<"Average rate of all showers with mult "<<mult_min<<"-"<<mult_max<<" : "<<average_rate<<endl;
    
    TCanvas *c1 = new TCanvas("c1","",1000,700);
    TGraph *gr1 = new TGraph(ntrending,pressure,nshower_integrated);
    gr1->SetTitle("");
    gr1->SetMarkerColor(4);
    gr1->SetMarkerStyle(22);
    gr1->Draw("AP");

/*
    TCanvas *c2 = new TCanvas("c2","",1000,700);
   
    Float_t pressure_notzero[5000],yield_notzero[5000];
    Int_t j_notzero=0;
    
    Float_t average_rate=0.0;
    for(Int_t j = 0; j < ntrending; j++){ 
       if(nshower_integrated[j]>0) {
	     yield_notzero[j_notzero]=nshower_integrated[j];
	     average_rate=average_rate+yield_notzero[j_notzero];
         pressure_notzero[j_notzero]=pressure[j]; 
         //cout<<j_notzero<<"  "<<pressure_notzero[j_notzero]<<"  "<<yield_notzero[j_notzero]<<endl;
         j_notzero++;
         }
    }
    j_notzero--;
    
    TGraph *gr2 = new TGraph(j_notzero,pressure_notzero,yield_notzero);
    gr2->SetTitle("");
    gr2->SetMarkerColor(4);
    gr2->SetMarkerStyle(22);
    gr2->Draw("AP");

    average_rate=average_rate/j_notzero;
    cout<<"Average rate (different from 0) with mult: "<<mult_min<<"-"<<mult_max<<" : "<<average_rate<<endl;
    cout<<"Number of points with at least one shower in 30': "<<j_notzero<<endl;

*/

}

?

In this case the code doesn’t work…

Sorry, I overlooked at your code. There are too many errors, I’ll try later and let you know

1 Like

Ok, thanks you so much.

Can you try to replace:

TChain chain("tree_arduino");
chain.Add("RUN4_prova1.root");
chain.Add("RUN4_2.root");  
chain.Add("RUN4_3.root");
chain.Add("RUN4_4.root");
chain.Add("RUN4_5.root");
chain.Add("RUN4_6.root");

by:

TChain *tree_arduino = new TChain("tree_arduino");
tree_arduino->Add("RUN4_prova1.root");
tree_arduino->Add("RUN4_2.root");  
tree_arduino->Add("RUN4_3.root");
tree_arduino->Add("RUN4_4.root");
tree_arduino->Add("RUN4_5.root");
tree_arduino->Add("RUN4_6.root");

And:

TChain chain("tree_trending");
chain.Add("RUN4_prova1.root");
chain.Add("RUN4_2.root");
chain.Add("RUN4_3.root");
chain.Add("RUN4_4.root");
chain.Add("RUN4_5.root");
chain.Add("RUN4_6.root");

by:

TChain *tree_trending = new TChain("tree_trending");
tree_trending->Add("RUN4_prova1.root");
tree_trending->Add("RUN4_2.root");
tree_trending->Add("RUN4_3.root");
tree_trending->Add("RUN4_4.root");
tree_trending->Add("RUN4_5.root");
tree_trending->Add("RUN4_6.root");
1 Like

Almost work!

I see new errors:

N.events: 63735
t0= 8.2557e+08
Overall number of points: 0
Analysis for events with multiplicity: 5-7
Average rate of all showers with mult 5-7 : -nan
Error in <TGraphPainter::PaintGraph>: illegal number of points (0)

When i run the code it open a white and empy canvas.

I’ll take a deeper look at your code as soon as I find some time

1 Like

Thanks a lot!

Please check your data. This cannot work with:

Overall number of points: 0

Here is the content of the tree_trending tree:

******************************************************************************
*Tree    :tree_trending: tree_trending                                          *
*Entries :        0 : Total =           18621 bytes  File  Size =       1170 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :seconds2007 : seconds2007/I                                        *
*Entries :        0 : Total  Size=        509 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :temp      : temp/F                                                 *
*Entries :        0 : Total  Size=        481 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    2 :press     : press/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    3 :nsat      : nsat/I                                                 *
*Entries :        0 : Total  Size=        481 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    4 :rate2     : rate2/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    5 :rate3     : rate3/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    6 :rate4     : rate4/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    7 :rate5     : rate5/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    8 :rate6     : rate6/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    9 :rate7     : rate7/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   10 :rate8     : rate8/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   11 :rate9     : rate9/F                                                *
*Entries :        0 : Total  Size=        485 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   12 :rate10    : rate10/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   13 :rate11    : rate11/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   14 :rate12    : rate12/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   15 :rate13    : rate13/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   16 :rate14    : rate14/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   17 :rate15    : rate15/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   18 :rate16    : rate16/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   19 :rate17    : rate17/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   20 :rate18    : rate18/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   21 :rate19    : rate19/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   22 :rate20    : rate20/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   23 :rate21    : rate21/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   24 :rate22    : rate22/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   25 :rate23    : rate23/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   26 :rate24    : rate24/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   27 :rate25    : rate25/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   28 :rate26    : rate26/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   29 :rate27    : rate27/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   30 :rate28    : rate28/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   31 :rate29    : rate29/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   32 :rate30    : rate30/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   33 :rate31    : rate31/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   34 :rate32    : rate32/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   35 :rate33    : rate33/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br   36 :rate34    : rate34/F                                               *
*Entries :        0 : Total  Size=        489 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*

(and it obviously doesn’t work with ROOT 5 either BTW)

This is right. It appears that the data is not being loaded to generate the various graphs mmm…

It is a problem of code or data conteined in the root file? @bellenot

Well, all I can tell is that the tree_trending tree is empty, so check your data or the code filling the tree

1 Like

Perfect, thanks!

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