Segmentation violation and odd behavior (TTree branches)

Dear ROOT experts,

I have the following problem: I try to execute a modified version of the TMVA tutorial file TMVAClassificationApplication.C after training and testing of a BDT and some neural nets (DNN and MLP). When I want to input the signal file and essentially trying to do this:

TMVA::Reader *reader = new TMVA::Reader( "!Color:!Silent" );
...
float zzed_hadronic_jetNo = 0.;
float zzed_hadronic_subjets_E1 = 0.;

reader->AddVariable( "zed_hadronic_jetNo[0]", &zzed_hadronic_jetNo );
reader->AddVariable( "zed_hadronic_subjets_E1[0]", &zzed_hadronic_subjets_E1 );
...
TFile *inputS_qqH(0);
inputS_qqH = TFile::Open("/inputdirectory/wzp6_ee_qqH_ecm240.root", "UPDATE");

TTree* theTree = (TTree*)inputS_qqH->Get("events;1");

theTree->SetBranchStatus("zed_hadronic_jetNo", 1);
theTree->SetBranchStatus("zed_hadronic_subjets_E1", 1);

std::vector<float> *zed_hadronic_jetNo = 0;
std::vector<float> *zed_hadronic_subjets_E1 = 0;

theTree->SetBranchAddress( "zed_hadronic_jetNo", &zed_hadronic_jetNo );
theTree->SetBranchAddress( "zed_hadronic_subjets_E1", &zed_hadronic_subjets_E1 );

Long64_t nentries = theTree->GetEntries();
for (Long64_t ievt=0; ievt<nentries;ievt++) {
   theTree->GetEntry(ievt);
   zzed_hadronic_jetNo = (*zed_hadronic_jetNo)[0];
   zzed_hadronic_subjets_E1 = (*zed_hadronic_subjets_E1)[0];
}
...

I get the following segmentation violation error:

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCling.so] TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libCore.so] TApplication::ExecuteFile(char const*, int*, bool) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/Users/Nico/root_dir/root_install/lib/libRint.so] TRint::Run(bool) (no debug info)
[/Users/Nico/root_dir/root_install/bin/root.exe] main (no debug info)
[/usr/lib/dyld] start (no debug info)

The interesting thing is, that when I comment out zzed_hadronic_subjets_E1 = (*zed_hadronic_subjets_E1)[0]; it compiles without any issue. Can somebody explain, why I get this error and why the compilation works, if the latter part of the code is removed (I am a C beginner)? The only difference between the entries of the two branches is, that the zed_hadronic_jetNo refers to a discrete variable (Number of jets per event) while the zed_hadronic_subjets_E1 refers to a continuous variable (energy of one jet).

Thank you very much for your help. :slight_smile:

Best,
Nico


ROOT Version: 6.26/00
Platform: macosx64
Compiler: Not Provided


Try:

   zzed_hadronic_jetNo = ((zed_hadronic_jetNo && (zed_hadronic_jetNo->size() > 0)) ? (*zed_hadronic_jetNo)[0] : 0);
   zzed_hadronic_subjets_E1 = ((zed_hadronic_subjets_E1 && (zed_hadronic_subjets_E1->size() > 0)) ? (*zed_hadronic_subjets_E1)[0] : 0);

Worked like a charm. Thank you very much! :smiley:

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