TSelector crashes when filling a new Tree for some root files

Dear Root experts;

I am running a TSlector that clones the tree and add more branches to it. The problem is that this code works for half of the files and has a *** Break *** segmentation violation for half of them, so I dont understand why this happens to some of the files.

You can find enclosed the code, however I highlight here what I think are the main features of my TSelector (“MetSign”):

In MetSign.C:

#define MetSign_cxx

#include "MetSign.h"
#include <TH2.h>
#include <TStyle.h>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <TCanvas.h>
#include <TLorentzVector.h>
#include <TDirectoryFile.h>
#include "TFile.h"
#include "TTree.h"

using namespace std;

Int_t fNumberOfEvents; // Total number of events

void MetSign::Begin(TTree * /*tree*/)
 {
  fNumberOfEvents = 0 ;
  t_tree  = 0;
  vesseltree = 0;
 }
  
void MetSign::SlaveBegin(TTree * /*tree*/)
 {
  TString treefile = "/data/atlas0/dportill/DougNtuples/mc15_13TeV.363379.Sherpa_NNPDF30NNLO_Zmumu_Pt700_1000_CVetoBVeto.merge.DAOD_SUSY5.e4716_s2726_r7725_r7676_p2666.root";
  TFile *ftree = new TFile(treefile);
  vesseltree = (TTree*)ftree->Get("CollectionTree");
  
  //create the new file
  TFile *g = new TFile("./NTuples/test.root", "RECREATE");

  t_tree = new TTree("testtree","Ntuples for Met Significance study");
  t_tree = vesseltree ->CloneTree(0);
  t_tree->Branch("Significance",&MetSig_t);
  
  fOutput->Add(t_tree);
  }
  
Bool_t MetSign::Process(Long64_t entry)
 {
  vesseltree ->GetEntry(fNumberOfEvents);
  MetSig_t = 1; //Some calculation
  t_tree->Fill();
  return kTRUE;
 }

void MetSign::Terminate()
 {
  TFile f1("./HISTOS/Zmumu_Pt700_1000_CVetoBVeto.root","RECREATE");//
  f1.Close(); 
}

In MetSign.h

#ifndef MetSign_h
#define MetSign_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TSelector.h>
#include <TH2.h>
#include <TH3.h>
#include <TLorentzVector.h>
#include <TVector3.h>
#include <set>
#include <tuple>

class MetSign : public TSelector {
public :
   TTree          *fChain;   //!pointer to the analyzed TTree or TChain

// Tree Ntuple
TTree *t_tree; //!
TTree *vesseltree; //!
Double_t MetSig_t;

}

The root files I am using in the TSlector are:
[]The one that do not runs: /afs/cern.ch/work/d/dportill/public/NTuples/mc15_13TeV.363377.Sherpa_NNPDF30NNLO_Zmumu_Pt500_700_CFilterBVeto.merge.DAOD_SUSY5.e4716_s2726_r7725_r7676_p2666.root
[
]The one that runs: /afs/cern.ch/work/d/dportill/public/NTuples/mc15_13TeV.363379.Sherpa_NNPDF30NNLO_Zmumu_Pt700_1000_CVetoBVeto.merge.DAOD_SUSY5.e4716_s2726_r7725_r7676_p2666.root

This is the error message I am obtaining when I run it direct ( CollectionTree->Process(“MetSign.C+”) ):

And this one when I run it in proof:

I really appreciate if someone can help me to spot the problem.

Thanks!!
MetSign.h (104 KB)
MetSign.C (47.6 KB)

Hi,

Nothing obvious. Can you send us an example ROOT file so that we can reproduce this problem?

Alternative can you run your failing example with valgrind (i.e. valgrind --suppressions=$ROOTSYS/etc/valgrind-root.supp root.exe … )

Cheers,
Philippe.