Why the value of some branch changed?

I have a root file, and I have checked that the value of some branch i need is normal; and I also checked that they are also normal if I draw them in “tree->Draw()” ;but in my following code, a for loop,I found that the value of them has changed (the first three numbers changed;but the last three numbers are normal)
In this figure,the right is the real number in root file;the left is the wrong number in my “for loop”
Can you find where is the matter?
Thank you!

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided



The 1d plot of one of the abnormal branch drawn by tree->Draw is like this.

We need to have the code of your “for loop” to understand what’s going on.

ok ,this is my code. I didn’t do any calculation before the for loop; and I also check the type of array dsca[16] and other defination and I can’t find any problem.
and now I meet another problem. ROOT will report an error when I run my code like this and I don’t know why.


#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <fstream>  
#include "TCanvas.h"
#include "TMath.h"
#include "TH1.h"
#include "TF1.h"
#include "TRandom.h"
#include "TSpectrum.h"
#include "TVirtualFitter.h"
#include "THStack.h"
#include "cut.h"
using namespace std;
int test()
{
    TChain *cccs=new TChain("cccs","");
    cccs->Add("/mnt/data500/CCCS2018/zhangmx/15C/ET/workz011.root");
    cccs->Add("/mnt/data500/CCCS2018/zhangmx/15C/ET/workz012.root");

    TFile *c11=new TFile("tofss.root");TCutG *f1=(TCutG*)c11->Get("tofss");f1->SetName("tofss");
    TFile *c2=new TFile("mu1start.root");TCutG *f2=(TCutG*)c2->Get("mu1start");f2->SetName("mu1start");
    TFile *c3=new TFile("mu1stop.root");TCutG *f3=(TCutG*)c3->Get("mu1stop");f3->SetName("mu1stop");
    TFile *c4=new TFile("mu1.root");TCutG *f4=(TCutG*)c4->Get("mu1");f4->SetName("mu1");
    TFile *c5=new TFile("tof.root");TCutG *f5=(TCutG*)c5->Get("tof");f5->SetName("tof");
    float adc[32],qdc[32],tof1,xp[2],yp[2],th[2],ph[2],xb[10],yb[10],xa[10],ya[10],dene,decor;
    float gdrft[16],dedx[16],prax[16],chibest[4],dxx[16],chimax,infdxx[4],infdyy[4],chiinf[4];
    int events,dsca[16],mhit[16],hitnumber[4];

    cccs->SetBranchAddress("tof1",&tof1,0);
    cccs->SetBranchAddress("adc[32]",&adc,0);
    cccs->SetBranchAddress("qdc[32]",&qdc,0);
    cccs->SetBranchAddress("dsca[16]",&dsca,0);
    cccs->SetBranchAddress("xb",&xb,0);
    cccs->SetBranchAddress("yb",&yb,0);
    cccs->SetBranchAddress("xa",&xa,0);
    cccs->SetBranchAddress("ya",&ya,0);
    cccs->SetBranchAddress("xp",&xp,0);
    cccs->SetBranchAddress("yp",&yp,0);
    cccs->SetBranchAddress("th",&th,0);
    cccs->SetBranchAddress("ph",&ph,0);
    cccs->SetBranchAddress("gdrft",&gdrft,0);
    cccs->SetBranchAddress("dedx",&dedx,0);
    cccs->SetBranchAddress("prax",&prax,0);
    cccs->SetBranchAddress("mhit",&mhit,0);
    cccs->SetBranchAddress("dxx",&dxx,0);
    cccs->SetBranchAddress("chimax",&chimax,0);
    cccs->SetBranchAddress("hitnumber",&hitnumber,0);


TCut first="adc[0]<3500&&adc[0]>400&&adc[1]<3500&&adc[1]>400&&adc[2]<2500&&adc[2]>1400&&qdc[3]<2200&&qdc[3]>500&&qdc[5]<4000&&qdc[5]>140&&qdc[7]<4000&&qdc[7]>140&&adc[16]<3840&&adc[16]>200&&adc[17]<3840&&adc[17]>200&&adc[3]<10&&adc[3]>0&&dsca[10]==1&&tof1<125&&tof1>110&&dsca[1]<=2";
 
 TCanvas *can5=new TCanvas("can5","hh",0,0,800,800);can5->Divide(2,1);
can5->cd(1);cccs->Draw("(adc[16]+adc[17])/2+73*yb[1]:tof1>>hhhh(400,110,124,500,0,4000)",first&&"tof"&&"mu1"&&"mu1stop"&&"mu1start"&&"tofss","col");
can5->cd(2);cccs->Draw("dsca[1]>>hh(100,0,100");
   TCanvas *can1=new TCanvas("can1","",0,0,900,900);//can1->Divide(2,2);
   TCanvas *can2=new TCanvas("can2","",0,0,900,900);//can2->Divide(2,1);

TH2F *h2001=new TH2F("h2001","",400,-5,5,1000,0,3000);
TH2F *h2002=new TH2F("h2002","",400,-5,5,500,0,3000);

    int ninf,noutf;
    float gamma;
    int n1=0,n2=0;

   // events=cccs->GetEntries();
   events=100;
    //printf("%d\n",events);
    for(int i=0;i<events;i++)
    {
        cccs->GetEntry(i);
        dene=(adc[16]+adc[17])/2;
        printf("%d %d %d %d %d %d %d\n",i,dsca[1],dsca[2],dsca[3],dsca[4],dsca[5],dsca[10]);
    // &&dsca[1]<=2
        if(adc[0]<3500&&adc[0]>400&&adc[1]<3500&&adc[1]>400&&adc[2]<2500&&adc[2]>1400&&qdc[3]<2200&&qdc[3]>500&&qdc[5]<4000&&qdc[5]>140&&qdc[7]<4000&&qdc[7]>140&&adc[16]<3840&&adc[16]>200&&adc[17]<3840&&adc[17]>200&&adc[3]<10&&adc[3]>0&&dsca[10]==1&&tof1<125&&tof1>110&&f1->IsInside(sqrt(qdc[5]*qdc[7]),qdc[3])&&f2->IsInside(qdc[3],(adc[16]+adc[17])/2)&&f3->IsInside(sqrt(qdc[5]*qdc[7]),(adc[16]+adc[17])/2)&&f4->IsInside(adc[17],adc[16])&&f5->IsInside(adc[1],adc[0]))
        { 
            n1++;
            h2001->Fill(yb[1],dene); 
             if(dsca[1]<=2) 
             {
             n2++;
             //===energy loss correction
             h2002->Fill(yb[1],dene);            
             } 
        } 
    }
    printf("%d %d %d\n",n1,n2,ninf);

    can1->cd();h2001->Draw("col");

    can2->cd();h2002->Draw("col");
}

The two files building the chain are missing too.

I didn’t understand. What do you mean?

We cannot run your macro because you did not post the two files you are using in the chain.

Hi,
as Olivier mentioned we cannot run your macro locally without the data, but from the output you posted and the crash the most likely scenario is that you are accessing non-existing array elements.
You can check e.g. by compiling your code (e.g. adding the required headers and compiling with g++ -o macro macro.C $(root-config --libs --cflags)) and running it inside valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp

Cheers,
Enrico

This is my root file;

link [REDACTED by Axel - possibly malware]
password:work

you can upload this app to download root file(because the file is too large to upload here)
or you can give me your email and i send it to you.
and now I found that out of the for loop,dsca[1]-dsca[3] is also not right, so it has nothing to do with the for loop;this is my new code(I delete some “cut”) and root file, you can help me find where is the matter.

#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <cmath>
#include <stdlib.h>
#include <fstream>  
#include "TCanvas.h"
#include "TMath.h"
#include "TH1.h"
#include "TF1.h"
#include "TRandom.h"
#include "TSpectrum.h"
#include "TVirtualFitter.h"
#include "THStack.h"
#include "cut.h"
using namespace std;
int test()
{
    TChain *cccs=new TChain("cccs","");
    cccs->Add("/mnt/data500/CCCS2018/zhangmx/15C/ET/workz011.root");
    cccs->Add("/mnt/data500/CCCS2018/zhangmx/15C/ET/workz012.root");

    float adc[32],qdc[32],tof1,xp[2],yp[2],th[2],ph[2],xb[10],yb[10],xa[10],ya[10],dene,decor;
    float gdrft[16],dedx[16],prax[16],chibest[4],dxx[16],chimax,infdxx[4],infdyy[4],chiinf[4];
    int events,dsca[16],mhit[16],hitnumber[4];

    cccs->SetBranchAddress("tof1",&tof1,0);
    cccs->SetBranchAddress("adc[32]",&adc,0);
    cccs->SetBranchAddress("qdc[32]",&qdc,0);
    cccs->SetBranchAddress("dsca[16]",&dsca,0);
    cccs->SetBranchAddress("xb",&xb,0);
    cccs->SetBranchAddress("yb",&yb,0);
    cccs->SetBranchAddress("xa",&xa,0);
    cccs->SetBranchAddress("ya",&ya,0);
    cccs->SetBranchAddress("xp",&xp,0);
    cccs->SetBranchAddress("yp",&yp,0);
    cccs->SetBranchAddress("th",&th,0);
    cccs->SetBranchAddress("ph",&ph,0);
    cccs->SetBranchAddress("gdrft",&gdrft,0);
    cccs->SetBranchAddress("dedx",&dedx,0);
    cccs->SetBranchAddress("prax",&prax,0);
    cccs->SetBranchAddress("mhit",&mhit,0);
    cccs->SetBranchAddress("dxx",&dxx,0);
    cccs->SetBranchAddress("chimax",&chimax,0);
    cccs->SetBranchAddress("hitnumber",&hitnumber,0);


TCut first="adc[0]<3500&&adc[0]>400&&adc[1]<3500&&adc[1]>400&&adc[2]<2500&&adc[2]>1400&&qdc[3]<2200&&qdc[3]>500&&qdc[5]<4000&&qdc[5]>140&&qdc[7]<4000&&qdc[7]>140&&adc[16]<3840&&adc[16]>200&&adc[17]<3840&&adc[17]>200&&adc[3]<10&&adc[3]>0&&dsca[10]==1&&tof1<125&&tof1>110&&dsca[1]<=2";
 
 TCanvas *can5=new TCanvas("can5","hh",0,0,800,800);can5->Divide(2,1);
can5->cd(1);cccs->Draw("(adc[16]+adc[17])/2+73*yb[1]:tof1>>hhhh(400,110,124,500,0,4000)",first,"col");
can5->cd(2);cccs->Draw("dsca[1]>>hh(100,0,100");
cccs->GetEntry(11);
cout<<dsca[1]<<" "<<dsca[2]<<" "<<dsca[3]<<" "<<dsca[4]<<" "<<dsca[5]<<" "<<dsca[10]<<endl;

   TCanvas *can1=new TCa
nvas("can1","",0,0,900,900);//can1->Divide(2,2);
   TCanvas *can2=new TCanvas("can2","",0,0,900,900);//can2->Divide(2,1);
/*
TH2F *h2001=new TH2F("h2001","",400,-5,5,1000,0,3000);
TH2F *h2002=new TH2F("h2002","",400,-5,5,500,0,3000);

    int ninf,noutf;
    float gamma;
    int n1=0,n2=0;
   // events=cccs->GetEntries();
   events=100;
    //printf("%d\n",events);
    for(int i=0;i<events;i++)
    {
        cccs->GetEntry(i);
        dene=(adc[16]+adc[17])/2;
      //  printf("%d %d %d %d %d %d %d\n",i,dsca[1],dsca[2],dsca[3],dsca[4],dsca[5],dsca[10]);
    // &&dsca[1]<=2
        if(adc[0]<3500&&adc[0]>400&&adc[1]<3500&&adc[1]>400&&adc[2]<2500&&adc[2]>1400&&qdc[3]<2200&&qdc[3]>500&&qdc[5]<4000&&qdc[5]>140&&qdc[7]<4000&&qdc[7]>140&&adc[16]<3840&&adc[16]>200&&adc[17]<3840&&adc[17]>200&&adc[3]<10&&adc[3]>0&&dsca[10]==1&&tof1<125&&tof1>110)
        { 
            n1++;
            h2001->Fill(yb[1],dene); 
             if(dsca[1]<=2) 
             {
             n2++;
             //===energy loss correction
             h2002->Fill(yb[1],dene);            
             } 
        } 
    }
    printf("%d %d %d\n",n1,n2,ninf);

    can1->cd();h2001->Draw("col");

    can2->cd();h2002->Draw("col");
*/
}

The link you posted did not work for me. It seems some additional software is required to download your file. Plus it is all in Chinese which makes it difficult to understand (at least for me). The new version of your code does almost nothing. The “loop part” is commented. Should we start form that new version ?

I am hiding the link, this has a fair chance of installing malware as a side-effect. @meixue please use a different mechanism to share ROOT files, one that does not ask for the install of software.

Sorry for my wrong link. And now I have correct my code, just definite dsca[16] again in another raw . It can run well. It is a strange reason.

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