Hello, I am facing a problem in running a simple code on ROOT . The TTree(“LHEF”) was generated using MG5 .I am trying to plot a histogram giving invariant mass of all the particles in the TBranch(or TTree). The TBranch (named “Particles”) is a TClonesArray containing particle objects (where ‘M’ is one of the leaf) and there are 10000 events in all.
Following is the code:
And their histogram when actually using LHEF->Draw(“M”) or LHEF->Draw(“Partcicle.M”) gives me a plot (as expected) of signal of higgs to 4 leptons (that is what the TTree consisted of!)
Sir, the following error message gets displayed:
error: member reference base type ‘Double_t *’
(aka ‘double *’) is not a structure or union
for (Int_t j = 0; j < Particle_M->GetEntriesFast(); j++)
~~~~~~~~~~^ ~~~~~~~~~~~~~~
Thanks! I have edited the post. I tried to solve this issue by using MakeClass but I am getting two errors while loading the makeclass.c file :
error: invalid use of non-static data
member 'kMaxParticle’
Int_t Particle_Status[kMaxParticle]; //[Particle_]
^~~~~~~~~~~~
error: invalid use of non-static data
member 'kMaxParticle’
Int_t Particle_Mother1[kMaxParticle]; //[Particle_]
^~~~~~~~~~~~
And so on for Declaration of all Leaf types from the header file.Also I get an error:
use of undeclared identifier
’hfile’
hfile = new TFile(“unweighted.root”, “RECREATE”, “ROOT histograms”);
^
even though the class TTree is included in the header file.
Sir, even if I make a MakeFile and load it without making any changes to it, still the above mentioned errors get displayed.
Thanking youunweighted.h (9.9 KB) unweighted.C (2.4 KB)
Here are Makefiles generated using the TTree uploaded(code for histogram plotting was added by me)
Thanks a lot Sir. Also I tried to get the same plot(for the same .root file/TTree) using class TTreeReader as suggested by Phillipe Sir (@pcanal) but I am getting an error in loading it. I am attaching the .c file of the code written by me. The error message which gets displayed is : error:
indirection requires pointer operand (‘TTreeReaderArray’ invalid)
{ double k = *(ParticleM)
^~~~~~~~~~~~ tests.c (657 Bytes)
The ROOT version is 6.08/00. Sir, on using the command you gave me, the moment I complete the second ‘for’ loop(i.e. looping over all entries, I get a huge written error of which the last statements are : Error in HandleInterpreterException>: Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
ROOT_prompt_49:1:4: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
k=*(Particle_M[j]);
^~~~~~~~~~~~~~~
Also Sir, could you also help me to correct the code I wrote using TTrreReader object which I had attached to my previous reply…
With refernce to the usage of C++ code which I had written(file attached:massclass.c) -
On removing the star , I get the error : error: assigning to ‘Double_t’ (aka ‘double’) from incompatible type ‘Double_t *’
(aka ‘double *’); dereference with *
k=(Particle_M[j]);
^~~~~~~~~~~~~~~~
*
And on putting the star back, the system crashes while the execution. I am attaching the .c file for your refernce.
With reference to the usage of TTreeReader object (file:tests.c) I am encountering following error while loading it:
error: no viable conversion from ‘TTreeReaderArray’ to ‘double’
double k = ParticleM
^ ~~~~~~~~~
Sir, I had attached the DropBox link in one of my replies which had the .root file with the TTree in it.
Thanking you
Krunal
As an important side note, this statement is actually incorrect. The number of particles in the file you provide is often 8 but is also sometimes 7 and, ‘worse’, sometimes 9 (which means that if you use a fixed size array of 8 to read the date you will get memory over-write and hence crashes).
Thanks a lot Philippe Sir (as well as @Wile_E_Coyote Sir) for your help. Now, all the codes ( original C++ code, using MakeClass and using TTreeReader object) are working fine. I did learn a lot. Once again thank you for help
Krunal