I am running a macro and creating some variables like vetomupx, vetomupy etc. I want to save them in the form of tree i.e I want to create a tree of all variables. I donot understand it and it is giving a segmentation error. Kindly help me to resolve this issue.
new_macro.cc (10.5 KB)
can you share a minimal reproducer of the error you are dealing with together with the full information about your platform and the version of ROOT you are using?
I am sending you the path of the root file.
This is the root version installed on my server
Linux version 2.6.32-696.3.1.el6.x86_64 (email@example.com) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) ) #1 SMP Wed May 31 08:51:37 CEST 2017
sorry this is not a root version but rather a platform and I’d lile a minimal reproducer, not the full analysis.
May be i am not getting exactly what you want. I am asking about how ton create a tree. I am sending you some lines of my macro in which I have generated some containers like vetomupx, vetomupy etc using lorentz vector and in next step i want to store these containers in a TTree and recreate a root file containing them. By doing this I have done something wrong due to which I am getting this error. Kindly check these lines.
float VetoMuphi(0), VetoMupt(0), VetoMueta(0), lelectronpt(0), lelectroneta(0), VetoMupx(0), VetoMupy(0), VetoMupz(0), VetoMuen(0);
// plots pt and eta of leading muon
VetoMupt = selectedMuons.Pt();
VetoMueta = selectedMuons.Eta();
VetoMupx = selectedMuons.Px();
VetoMupy = selectedMuons.Py();
VetoMupz = selectedMuons.Pz();
VetoMuen = selectedMuons.E();
VetoMuphi = selectedMuons.Phi();
VetoMucharge = Mu_charge;
TFile *ff = new TFile(“output_Veto.root”,“RECREATE”);
TTree *t = new TTree(“AnaTree”,“an example tree”);
float VetoMupx, VetoMupy, VetoMupz, VetoMuen, VetoMucharge;
Without a reproducer one can only give general comments. A quick look at your file:
- You are including a lot of headers twice. Include them only once!
- You are using
new TFile(...) to open the input file. Use
TFile::Open("...") instead (especially because you are opening a
root://... file (which should be a TNetFile)) - and add a check that the file exists, i.e. check that
f != nullptr. Also check that the tree exists.
- In the following code fragment, the second and fourth if can never be true. ```
if (nSelLeptons != 3) continue;
if (nSelLeptons > 3) continue;
if (nvetoLeptons != 0) continue;
if (nvetoLeptons > 0) continue;
- your program should not compile because you are redefining `VetoMupx, VetoMupy, VetoMupz, VetoMuen, VetoMucharge;` (lines 194+231)
- There is some indentation in your code, yet your indentation doesn't help to find out to which block a line belongs. Use a tool like clang-format to reformat your code!
This also leads to the next point:
- you are opening the output file inside the event loop! Don't do that, your output tree will only have one event! (Also, you are missing the `delete ff; / delete f;`)
- finally a physics related question: is ` bool passVetoIso( Mu_id[m]==13 ? relIso<0.25 : true)` useful? For -13 no isolation? At least I would add a comment here.
Thank you so much for your suggestions. I will try to sort out it
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.