Read Valgrind log

Alright, can you please share the macro you use to produce simulazione.root too? :slight_smile:

The statement:

    new (&clone1[i]) Intpoint (0,0,0);

is likely meant to be:

    new ((*clone1)[i]) Intpoint (0,0,0);

i.e. the value passed to the placement part of operator new is supposed to be the return value (a TObject*) of TClonesArray::operator[] (while the original code is passing the value of the pointer arithmetic clones1 + i)

#include "TH3D.h"
#include "TVirtualFFT.h"
#include "TF1.h"
#include "TCanvas.h"
#include "TMath.h"
#include <iostream>
#include "TString.h"
#include "TFile.h"
#include "TTree.h"
#include "TSystem.h"
#include "TTreeReader.h"
#include "TTreeReaderValue.h"
#include "TRandom3.h"
#include "TClonesArray.h"
#include "TGraph2D.h"
#include  <vector>
#include <stdio.h>
#include <stdlib.h>

//headers includes

#include "Intpoint.h"
#include "Vertex.h"

using namespace std;

const double Rbp=3.08;//cm
const double R1=4.02;
const double R2=7.02;
const double L=27;

const double sigmax=0.01;
const double sigmay=0.01;
const double sigmaz=5.3;

const int kMaxim=20;
const double etamin=-2.;
const double etamax=+2.;
const TString mul="sì"; 

void simulazione(){
  unsigned int seed=18;

  TString filename="kinem.root";
  TString muldis="hmul";
  TString etadis="heta";
  char a;
  int accepted;
  int discarded;


  Vertex *vertice = NULL;

  TFile  *hfile = TFile::Open("simulazione.root","RECREATE");
  TTree *tree = new TTree("tree", "eventi");

TClonesArray *bp = new TClonesArray("Intpoint",100);  
 TClonesArray &intbp = *bp;
  //loop sul numero di vertici
  for(int i=0; i<kMaxim;i++){
   	vertice=new Vertex();    
     for (int j=0; j<accepted; j++){ new (intbp[j]) Intpoint (0,0,0) ;}
    if (accepted>0) tree->Fill(); else i--; 
    delete vertice;

This is a β€œtoy” (cut) version with the branches used by ricprova(). If you need all the complete macros and classes, I’ll ask permission and share all the files (10 files, almost 10^3 lines of code, so maybe GitHub)

This solves the problem,we go hide forever :see_no_evil: :see_no_evil: :see_no_evil:
Thanks a lot