I wrote a macro name simple_code ,inside that i used TLorentzVector after compiling that i face error.also i added loader file.can anybody help me out how to use TLorentzvector?simple_code.C (1.91 KB)
Thank you
cp
loader.C (117 Bytes)
I wrote a macro name simple_code ,inside that i used TLorentzVector after compiling that i face error.also i added loader file.can anybody help me out how to use TLorentzvector?simple_code.C (1.91 KB)
Thank you
cp
Hi cp,
the selection is correct but the dictionary has not been found. What file are you actually running and how? For the time being, you can have a look to this post
which could already contain a solution for you (dictionaries, trees, aclic).
Cheers,
Danilo
Hi ,
I did the following things, i write a header file(link.h) for including TLorentzvector dictionary and also write a makefile to compile my code (acccode.C) still i am getting following error.
Error in TTree::SetBranchAddress: The class requested (vector) for the branch “genDecayLVec” refer to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector)
Error in TTree::SetBranchAddress: The class requested (vector) for the branch “jetsLVec” refer to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector)
Error in TTree::SetBranchAddress: The class requested (vector) for the branch “muonsLVec” refer to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector)
my makefile is written below
IDIR =.
ODIR = obj
CXX =g++
CXXFLAGS += -I. -std=c++0x -I${CMSSW_BASE}/src/
##optimization flag
CXXFLAGS += -g #-03
#CXXFLAGS += -Wall -Wextra -Weffc++ -g
CXXFLAGS += (shell root-config --cflags)
CXXDEPFLAGS = -MMD -MP
LD =g++
LDFLAGS =
LIBS =(shell root-config --glibs)
#OBJS =(patsubst %,(ODIR)/%,$(OBJ))
PROGRAMS = acccode
all: (PROGRAMS) (ODIR)/%.o : (IDIR)/%.C (CXX) (CXXFLAGS) (CXXDEPFLAGS) -o$@ -c $<
(ODIR)/%.o : (IDIR)/%.cc
(CXX) (CXXFLAGS) (CXXDEPFLAGS) -o@ -c <
acccode :(ODIR)/acccode.o
(LD) ^ (LIBS) -L{CMSSW_BASE}/lib/{SCRAM_ARCH}/ -o @
clean:
rm -f (ODIR)/*.o (ODIR)/.d (PROGRAMS) core
-include (ODIR)/.d
Please help me to fix this bug.
Thanks
cp
link.h (268 Bytes)
acccode.C (4.46 KB)
Hi cp,
a refactor of your code is needed:
the LinkDef:
#ifdef __CLING__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class vector<TLorentzVector>+;
#endif
notice the usage of CLING instead of CINT and the replacement of “of” to “off”.
the “umbrella header” classes.h:
#include "TLorentzVector.h"
#include <stdio.h>
#include <stdlib.h>
The lines to build the dictionary and the library necessary to the IO of stl collections:
rootcling dict.cxx -rml libmylib.so -rmf myrootmap.rootmap classes.h LinkDef.h
g++ -o libmylib.so dict.cxx `root-config --cflags --libs` -shared -fPIC
Notice that the rootmap file is necessary for the code to automatically load the library and the dictionary while running the macro.
Cheers,
Danilo
Hi Danilo
I did the above part but i don’t know how to add “rootcling dict.cxx -rml libmylib.so -rmf myrootmap.rootmap classes.h LinkDef.h
g++ -o libmylib.so dict.cxx root-config --cflags --libs
-shared -fPIC” to Makefile.
can you help me ?
my Makefile is
[
IDIR =.
ODIR = obj
CXX =g++
CXXFLAGS += -I. -std=c++0x -I${CMSSW_BASE}/src/
##optimization flag
CXXFLAGS += -g #-03
#CXXFLAGS += -Wall -Wextra -Weffc++ -g
CXXFLAGS += $(shell root-config --cflags)
CXXDEPFLAGS = -MMD -MP
LD =g++
LDFLAGS =
LIBS =$(shell root-config --glibs)
#OBJS =$(patsubst %,$(ODIR)/%,$(OBJ))
PROGRAMS = acccode
all: $(PROGRAMS)
$(ODIR)/%.o : $(IDIR)/%.C
$(CXX) $(CXXFLAGS) $(CXXDEPFLAGS) -o $@ -c $<
$(ODIR)/%.o : $(IDIR)/%.cc
$(CXX) $(CXXFLAGS) $(CXXDEPFLAGS) -o $@ -c $<
acccode :$(ODIR)/acccode.o
$(LD) $^ $(LIBS) -L${CMSSW_BASE}/lib/${SCRAM_ARCH}/ -o $@
clean:
rm -f $(ODIR)/.o $(ODIR)/.d $(PROGRAMS) core
-include $(ODIR)/*.d
]
Thank you
cp
you can always add these lines at the beginning of your macro:
#ifdef __CLING__
#pragma link C++ class vector<TLorentzVector>+;
#endif
and run the macro with aclic, i.e.
~> root simple_code.C+
This will generate the necessary dictionary for you to read vector of TLorentzVectors and buy you some time to become more familiar with Makefile syntax.
Cheers,
Danilo
Hi,
I follow your instruction and add it to in my macro
#ifdef CLING
#pragma link C++ class vector+;
#endif
and
root acccode.C+
still i get error.
Info in TUnixSystem::ACLiC: creating shared library /afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode_C.so
In file included from /afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/acccode_C_ACLiC_dict.h:34,
from /afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/acccode_C_ACLiC_dict.cxx:17:
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C: In function ‘void acccode()’:
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:97: warning: unused variable ‘NJET’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:98: warning: unused variable ‘genmu’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:98: warning: unused variable ‘accmu’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:99: warning: unused variable ‘doneacc’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:59: warning: unused variable ‘hadtauflag’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:60: warning: unused variable ‘nelectron’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:60: warning: unused variable ‘nmuon’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:60: warning: unused variable ‘njet’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:61: warning: unused variable ‘dphi1’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:61: warning: unused variable ‘dphi0’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:61: warning: unused variable ‘dphi2’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:64: warning: unused variable ‘hjetspt’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:65: warning: unused variable ‘hjetseta’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:66: warning: unused variable ‘hjetsphi’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:67: warning: unused variable ‘hgenmupt’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:68: warning: unused variable ‘hgenmueta’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:69: warning: unused variable ‘hgenmuphi’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:70: warning: unused variable ‘helec’
/afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode.C:74: warning: unused variable ‘hmuon’
Error in TTree::SetBranchAddress: Unable to determine the type given for the address for “genDecayLVec”. The class expected (vector) refers to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector)
Error in TTree::SetBranchAddress: Unable to determine the type given for the address for “jetsLVec”. The class expected (vector) refers to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector)
Error in TTree::SetBranchAddress: Unable to determine the type given for the address for “muonsLVec”. The class expected (vector) refers to an stl collection and do not have a compiled CollectionProxy. Please generate the dictionary for this class (vector)
49729
*** Break *** segmentation violation
Thank you
cp
Hi,
perhaps something is not under control in your setup.
If I use vanilla ROOT on lxplus or the one of CMSSW_7_4_15 (gcc491 platform)
. /afs/cern.ch/sw/lcg/external/gcc/4.9/x86_64-slc6-gcc49-opt/setup.sh
. /afs/cern.ch/sw/lcg/app/releases/ROOT/6.06.02/x86_64-slc6-gcc49-opt/root/bin/thisroot.sh
or
cmrel CMSSW_7_5_14
cd CMSSW_7_4_15
cmsenv
and follow the recipe we discussed,see macro below
#include "TLorentzVector.h"
#include "TClass.h"
#include <vector>
#include <iostream>
#ifdef __CLING__
#pragma link C++ class vector<TLorentzVector>+;
#endif
void test(){
auto c=TClass::GetClass("vector<TLorentzVector>");
std::cout << "Class has " << (c->HasDictionary()?"a ":"no ") << "dictionary" << std::endl;
std::cout << c->GetCollectionProxy() << std::endl;
}
I get
[...]
Class has dictionary
0x20cc3e0
which implies that the vector has both a dictionary and a collection proxy, i.e. ROOT is able to carry out IO with it.
Can you verify you get the same output with that simple example?
D
Hi,
I did not get the same result.Instead that i get this.
root [0]
Processing test.C…
Class has no dictionary
0x38d89a0
Thanks
What root version are you using? Are i surr you used aclic?
D
Hi
I had to check out the CMSSW_7_4_15 again and I am getting the same result as yours .
But when I am running my macro acccode.C and getting following error
root [0]
Processing acccode.C+…
Info in TUnixSystem::ACLiC: creating shared library /afs/cern.ch/user/c/ckar/CMSSW_7_4_15/src/lostlepton/./acccode_C.so
In file included from input_line_12:9:
././acccode.C:87:27: error: no member named ‘Pt’ in 'std::vector<TLorentzVector, std::allocator >'
hjetspt->Fill(jetsLVec[k].Pt());
~~~~~~~~~~~ ^
././acccode.C:88:28: error: no member named ‘Eta’ in 'std::vector<TLorentzVector, std::allocator >'
hjetseta->Fill(jetsLVec[k].Eta());
~~~~~~~~~~~ ^
././acccode.C:89:28: error: no member named ‘Phi’ in 'std::vector<TLorentzVector, std::allocator >'
hjetsphi->Fill(jetsLVec[k].Phi());
~~~~~~~~~~~ ^
Error in : Dictionary generation failed!
root [1] .q
I am using root version 6.02/05.
Thank you
cp
this is a standard compiler error.
The entity jetsLVec[k] is a vector of lorentz vectors and not a single jet (jetsLVec is a collection of vector of lorentz vectors). You have to loop on the elements of jetsLVec[k] and fill your histograms.
Hi
The problem was that it cannot access the [ ]( in jetsLVec[k]). when i write jetsLVec->at(k) it gives the result.
Thank you very much
cp
Ok,
so it was a pointer to a vector rather than a collection.
Good that you could fix this.
D