TLorentzeVector and Tree.Fill

Hi,

    I have a root file which I was trying to analyse. I created a class for this root file using MakeClass method. ( Please find the code attached with this mail.)

  I am reading the data from the root file ..do some caclulation and store output  in other output root file with a tree.  During this process I use TLorenzeVector which make things little easier for me.  

 As soon as I add the following line at the last part of my code it gives me segmentation voliation.... otherwise it works fine.  Infact If i add these line  at some other place it gives the same errror.  Error occures at Tree.Fill()  line!!

TLorentzVector tempRecPhot;
vector RecPhot;
RecPhot.clear();

If I keep the above lines in my code and remove  Tree.Fill();  line then the code works ok.  

Does anyone know what could be the cause for the above problem.

Thanks in advance.

with best,
sushil
Analyzer.C (13.3 KB)

Hi,

You must provide a dictionary for the vector in order for the I/O to work.

To do so is as simple as adding the following lines towards the top of your file:#include <vector> #include "TLorentzVector.h" #ifdef __MAKECINT__ #pragma link C++ class vector<TLorentzVector>; #endif
and you need to compile the result with ACLiC:.L Analyzer.C+Note: you may have to correct C++ syntax error if you took advantages of CINT shortcuts :slight_smile:

Cheers,
Philippe

Hi ,

 Thanks for the help.

I have included the lines you sent........I am just confused when to run this command .L Analyzer.C+ ???  
  As I use a makefile to make "Analyser.so" and then run the code as :

gSystem->Load(“libPhysics”);
.L Analyser.so;
Analyser t;
t.Loop();

Now should I generated the dictionary before doing these or have to modified my make file?? and how?

Meantime it seems the dictionary is not gereated… with .L Anlyser.C+ command… I am using 5.14 version.
Here is the output of .L Analyser.C+

Info in TUnixSystem::ACLiC: creating shared library /home/sushil/CIT/./Analyzer_C.so
In file included from /tmp/file1A1GAf_rootcint.h:3,
from /tmp/lyp0NW_cint.cxx:1:
/home/sushil/CIT/./Analyzer.C:19:2: invalid preprocessing directive #pragmak
Error: external preprocessing failed. :0:
!!!Removing /home/sushil/CIT/./fileTDzkDJ.cxx /home/sushil/CIT/./fileTDzkDJ.h !!!
Error: rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
In file included from /home/sushil/CIT/./Analyzer.C:2:
/home/sushil/CIT/./Analyzer.h:1235: warning: unused parameter ‘entry’
In file included from /usr/lib/gcc/i386-redhat-linux/3.4.6/…/…/…/…/include/c++/3.4.6/backward/iostream.h:31,
from /home/sushil/CIT/./Analyzer.C:6:
/usr/lib/gcc/i386-redhat-linux/3.4.6/…/…/…/…/include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the <X.h> header for C++ includes, or instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/home/sushil/CIT/./Analyzer.C: In member function `virtual void Analyzer::Loop()’:
/home/sushil/CIT/./Analyzer.C:281: warning: comparison between signed and unsigned integer expressions
/home/sushil/CIT/./Analyzer.C:384: warning: comparison between signed and unsigned integer expressions
/home/sushil/CIT/./Analyzer.C:39: warning: unused variable ‘rPhot_r9’
/home/sushil/CIT/./Analyzer.C:41: warning: unused variable ‘pPhotJet_CosTheta’
/home/sushil/CIT/./Analyzer.C:152: warning: unused variable ‘idebug1’
/home/sushil/CIT/./Analyzer.C:153: warning: unused variable ‘idebug2’
/home/sushil/CIT/./Analyzer.C:154: warning: unused variable ‘idebug3’
/home/sushil/CIT/./Analyzer.C:155: warning: unused variable ‘idebug4’
/home/sushil/CIT/./Analyzer.C:156: warning: unused variable ‘idebug5’
/home/sushil/CIT/./Analyzer.C:157: warning: unused variable ‘idebug6’
/home/sushil/CIT/./Analyzer.C:158: warning: unused variable ‘idebug7’
/home/sushil/CIT/./Analyzer.C:159: warning: unused variable ‘idebug8’
/home/sushil/CIT/./Analyzer.C:166: warning: unused variable 'RecJet_PtLow_'
Info in : The compiler has not found any problem with your macro.
Probably your macro uses something rootcint can’t parse.
Check root.cern.ch/root/Cint.phtml?limitations for Cint’s limitations.
root [1]

===================================

thanks in advance,
with best,
sushil

[quote]Meantime it seems the dictionary is not generated… with .L Anlyser.C+ command… I am using 5.14 version. [/quote]Sorry, there was a typo in my example (i.e. there was pragmak where pragma is needed)

[quote] As I use a makefile to make “Analyser.so” and then run the code as : [/quote]Since you have your own makefile and, seemingly, you are already running rootcint and compiling the result of running rootcint, you simply need to add the line#pragma link C++ class vector<TLorentzVector>; to you linkdef file.

Cheers,
Philippe.

Hi Phillippe,

    I  defined a LinDef.h file as:

===========================
#ifndef LinkDef_h
#define LinkDef_h

#pragma link C++ class vector;

#endif

Please find my MakeFile attached.

On make command I get the followoing error:


Making Analyzerdict.C Analyzerdict.h
rm -f Analyzerdict.C Analyzerdict.h
rootcint Analyzerdict.C -c -I/home/sushil/ROOT_5.16/root_514/include Analyzer.h LinkDef.h
Error: class,struct,union or type TLorentzVector not defined prec_stl/memory:37:
Error: class,struct,union or type TLorentzVector not defined prec_stl/memory:38:
Error: class,struct,union or type TLorentzVector not defined prec_stl/memory:43:
Error: class,struct,union or type TLorentzVector not defined prec_stl/memory:44:
Error: class,struct,union or type TLorentzVector not defined prec_stl/memory:45:
Error: class,struct,union or type TLorentzVector not defined prec_stl/vector:51:
Error: Function TLorentzVector() is not defined in current scope prec_stl/vector:422:
Error: Function TLorentzVector() is not defined in current scope prec_stl/vector:422:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing Analyzerdict.C Analyzerdict.h !!!
Error: rootcint: error loading headers…
make: *** [Analyzerdict] Error 1

How I can make a linkdef.h file and complie it also ??

Thanks and with best,
sushil

sorry Makefile is here…

— compiler configuration ---------------------------------

CC = g++
CCFLAGS = -O -Wall -fPIC -shared
INCLUDES = -I$(ROOTSYS)/include

— root libraries -------

ROOTSYS ?= ERROR_RootSysIsNotDefined
LD_LIBRARY_PATH:=$(ROOTSYS)/lib
ROOTCFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags)
ROOTLIBS = $(shell $(ROOTSYS)/bin/root-config --libs)
ROOTGLIBS = $(shell $(ROOTSYS)/bin/root-config --glibs)

#HISTOS := -L dsigma.C

— packagename -----------

#PACKAGE =gPlusJet
PACKAGE =Analyzer
#---------------------------------------------------------------

default : $(PACKAGE).so

$(PACKAGE)dict : $(PACKAGE).h
@echo "Making $@.C $@.h"
rm -f $@.C $@.h
rootcint $@.C -c $(INCLUDES) $(PACKAGE).h LinkDef.h

$(PACKAGE).so : $(PACKAGE).C $(PACKAGE)dict
@echo “Compiling $<”
$(CC) -o $@ $(CCFLAGS) $(INCLUDES) $(PACKAGE)dict.C $(PACKAGE).C

clean :
@echo removing $(PACKAGE)dict.C $(PACKAGE)dict.h $(PACKAGE).so
rm $(PACKAGE)dict.C $(PACKAGE)dict.h $(PACKAGE).so

=============================

HI,

Your problem is the missing #include for vector and TLorentzVector.
So either add them to Analyzer.h or use

[code]#ifndef LinkDef_h
#define LinkDef_h

#include
#include

#pragma extra_include “vector”;
#pragma extra_include “TLorentzVector.h”;

#pragma link C++ class Analyzer-; // No I/O needed for the Analyzer itself
#pragma link C++ class vector;

#endif [/code]

Cheers,
Philippe.

Hi Philippe,

 I just added the things in LInkDef.h instead of Analyzer.h......... and the run "make" command:

I get the following


Making Analyzerdict.C Analyzerdict.h
rm -f Analyzerdict.C Analyzerdict.h
rootcint Analyzerdict.C -c -I/home/sushil/ROOT_5.16/root_514/include Analyzer.h LinkDef.h
Error: Symbol vector is not defined in current scope LinkDef.h:7:
Syntax Error: vector> LinkDef.h:7:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing Analyzerdict.C Analyzerdict.h !!!
Error: rootcint: error loading headers…
make: *** [Analyzerdict] Error 1

with best,
sushil

In the example I replaced#pragma extra_include <vector>;
with #pragma extra_include "vector";
Cheers,
Philippe

Hi Philippe,

Now the code compiles but again the same problem!!! If I declare one more TLorenzeVector then I get the segmentation voilation…This is excactly I was getting in the beginng.

Problem is still there…

with best,
sushil

Hi sushil,

Then I don’t know what the problem really is :slight_smile: and I would need a complete running example to be able to debug the problem and/or you might be able to find the cause by using valgrind.

Cheers,
Philippe

Hi Phillippe,

   Thanks for your help and efforts.  I really do not know if I am doing some silly mistake in my code .....but not able to detect it. 

Anyway I have kept the tar ball at the following link. …If possible please have a look…

schauhan.web.cern.ch/schauhan/BSM/Root_Problem/

The input root file is also there…I am using root verson 5.14.

As soon as you uncomment the Lorenze vector declaration inbetween the "===== " lines in .C file it give segmentation voilation

Thanks and with best,
sushil

Hi,

You must initialize your variable, in particular the array size (by the way, they are actually never set but I assume this is work in progress):[code] Int_t pPhot_N = 0;
Int_t pJet_N = 0;
Int_t gJet_N = 0;
Int_t Events = 0;

Int_t rPhot_N = 0;
Int_t rJet_N = 0;[/code]
Cheers,
Philippe.

PS. The un-initialize variable leads to ‘random’ behavior’, just adding a couple more variable just lead the random behavior to be a core dump.

Hi Phillippe,

Thanks a lot. It worked…I never thought this could lead to such a problem…

with best,
sushil