Calcul Sigma for each event

Hi Rooter,

I want to draw histogram TProfil from two other histogram for example:

 TFile *g = new TFile("Mc.root");
   Double_t,TST_Ntest, TST_Vtest;
   g->Get("t4");
   TTree *t = (TTree*)g->Get("t4");
   TTree *t4 = (TTree*)g->Get("t4");
   t->SetBranchAddress("TST_Vtest",&TST_Vtest);
   t4->SetBranchAddress("TST_Ntest",&TST_Ntest);
   t4->SetBranchAddress("h_Sigma_TST",&h_Sigma_TST);

  TH1D *TST_N   = new TH1D("TST_N","",50, 0.0, 250.);
   TH1D *TST_V   = new TH1D("TST_N","",50, 0.0, 250.);
TProfile *Sigma_TST  = new TProfile("h_Sigma_TST","",60, 0 , 250, -5.0,5.0); 
     
Double_t nentries = t4->GetEntries();  
   Double_t sig_TST[nentries];      
   for (Long64_t i=0;i<nentries;i++) {
       t4->GetEntry(i);      
      TST_N->Fill(TST_Ntest);
      TST_V->Fill(TST_Vtest);
      sig_TST[i] = (TST_Ntest[i]-TST_Vtest[i])/TST_Ntest[i];
      //cout<<"sig_tst :"<<sig_TST<<endl;
     Sigma_TST->Fill(TST_Ntest[i],sig_TST[i]);
  }
     Sigma_TST->Draw("E1"); 

I want to calculate sig_TST for each event. But when I running the macro I have got the following error :
Error: Non-static-const variable in array dimension macro.c:67:
(cint allows this only in interactive command and special form macro which
is special extension. It is not allowed in source code. Please ignore
subsequent errors.)

Please could you help me how I can to fix this issue.

Cheers,
Souad

Double_t *sig_TST = new Double_t[nentries];
// ...
delete [] sig_TST; // cleanup

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).

Hi Wile_E_Coote,

Thank for your reply,
I changed Double_t sig_TST[nentries] with Double_t *sig_TST = new Double_t[nentries]. but when I running I have got the following error messages:
libGL error: failed to open drm device: No such file or directory
libGL error: failed to load driver: i965
Info in TCanvas::MakeDefCanvas: created default TCanvas with name c1

And also I have got a plot for sigma, but when I compared by ratio of TST_N and TST_V I noticed that there are some points are equal (TST_N = TST_V) so I expect Sigma= zero.
but the Sigma is not zero

Could you please explain me why I have this issue,

Thanks,
SS,
Cheers

The statement “Double_t TST_Ntest, TST_Vtest;” defines ordinary variables, not tables / arrays. So, you must not use “TST_Ntest[i]” nor “TST_Vtest[i]”.

Always try to pre-compile your source code using ACLiC (the compiler will find many possible source code bugs) … root [0] .L MySourceCode.cxx++

I running with .L macro.c but I have got :
reloading /afs/cern.ch/work/s/sbatlamo/Trackvariation/Plot/user.sbatlamo.Test_Fake_T.root_MYSTREAM/./macro.c 0
reloading TH1F.h 0
reloading TH2F.h 0
reloading TMath.h 0
reloading string.h 0
reloading stdio.h 0
reloading stdfunc.dll 0
reloading stdlib.h 0
reloading iomanip 0
reloading sstream 0
reloading fstream 0
reloading fstream.h 0
reloading math.h 0
reloading memory 0
reloading _memory 0
reloading _memory.h 0
reloading /usr/share/root/plugins/TArchiveFile/P010_TZIPFile.C 0
reloading /usr/share/root/plugins/TVirtualStreamerInfo/P010_TStreamerInfo.C 0
reloading /usr/share/root/plugins/TImage/P010_TASImage.C 0
reloading /usr/lib64/root/libASImage.so 0
reloading /usr/lib64/root/libCint.so 0
reloading /usr/share/root/plugins/TVirtualHistPainter/P010_THistPainter.C 0
reloading /usr/lib64/root/libHistPainter.so 0

Try to execute (fix all reported bugs and warnings):

`root-config --cxx --cflags` -O2 -Wall -Wextra -c MySourceCode.cxx

I did it but I have the following messages:

root [0] root-config --cxx --cflags -O2 -Wall -Wextra -c MySourceCode.cxx
Error: Symbol root is not defined in current scope (tmpfile):1: Error: Symbol config is not defined in current scope (tmpfile):1: Error: Symbol cxx is not defined in current scope (tmpfile):1: Error: Symbol cflags is not defined in current scope (tmpfile):1:
Error: Symbol O2 is not defined in current scope (tmpfile):1:
Error: Symbol Wall is not defined in current scope (tmpfile):1:
Error: Symbol Wextra is not defined in current scope (tmpfile):1:
Error: Invalid type ‘c’ in declaration of ‘MySourceCode’ (tmpfile):1:
Error: Invalid type ‘c’ in declaration of ‘MySourceCode’ (tmpfile):1:
Error: Symbol c MySourceCode is not defined in current scope (tmpfile):1:
Error: Failed to evaluate c MySourceCode.cxx
(const int)0
*** Interpreter error recovered ***

ROOT Primer -> ROOT Macros -> Interpretation and Compilation

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