Dear experts,
I am writing an analysis code spread across several different classes with global inheritance form a base class object. The base class object is equipped with several helper functions (recursive directory creation, file counting, derivations, statistics functions, smoothing and iterative fitting).
I am passing a vector of doubles to the iterative fitting function and request the result of a Gaussian fit. The iterative fitting will try several binning and constraint combinations and return the best result based on a chi2/NDF test.
This works fine as long as I only want to get numerical values, (which are passed as references to the function) but I encounter a crash when i try to extract the TH1D object to save it to my ntuple.
The declaration of the function is the following:
int BaseCalss::IterativeFit(std::vector<double> *w, std::pair<double, double> &gmean, std::pair<double, double> &gsigma, TH1D* &FitHist, double &minchi2, std::string methode, std::pair<int, int> points)
Internally the function will create a vector of TH1D* with all the possible trials:
std::vector<TH1D* > Fits;
At some point at the end of the function, when I have decided which is the best fit, i do:
FitHist = (TH1D*)(Fits.at(indx))->Clone();
There exactly root will crash completely. No compiler errors, no warning messages other that:
===========================================================
#5 0x00007f4a32194865 in LGADBase::IterativeFit(std::vector<double, std::allocator<double> >*, std::pair<double, double>&, std::pair<double, double>&, TH1D*&, double&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::pair<int, int>) () from /afs/cern.ch/user/e/egkougko/private/LGADUtils/Root/LGADFits_cxx.so
#6 0x00007f4a31b5ff98 in WaveForm::Calculate() () from /afs/cern.ch/user/e/egkougko/private/LGADUtils/Root/WaveForm_cxx.so
#7 0x00007f4a3193ed0f in DUTChannel::AppendWaveform(WaveForm*, bool) () from /afs/cern.ch/user/e/egkougko/private/LGADUtils/Root/DUTChannel_cxx.so
#8 0x00007f4a3193fd4d in DUTChannel::AppendEvent(std::vector<double, std::allocator<double> >*, std::vector<double, std::allocator<double> >*, bool) () from /afs/cern.ch/user/e/egkougko/private/LGADUtils/Root/DUTChannel_cxx.so
#9 0x00007f4a3171b0b3 in LGADRun::Process(long long) () from /afs/cern.ch/user/e/egkougko/private/LGADUtils/Root/LGADRun_cxx.so
#10 0x00007f4a3391f360 in TTreePlayer::Process(TSelector*, char const*, long long, long long) () from /cvmfs/sft.cern.ch/lcg/releases/ROOT/6.14.04-0d8dc/x86_64-slc6-gcc62-opt/lib/libTreePlayer.so
#11 0x00007f4a3150cf47 in LGADUtils::Analyse(long long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >) () from /afs/cern.ch/user/e/egkougko/private/LGADUtils/Root/LGADUtils_cxx.so
#12 0x00007f4a469550aa in ?? ()
#13 0x0000000000000016 in ?? ()
#14 0x0000000000000000 in ?? ()
===========================================================
The code has been tried in windows (root 5.34/36) and linux (root 6.14/0.4) wih the same exact results.
What is the correct way to get the fit out of the function? I also tried instead of passing a reference to a pointer TH1D* to pass a reference to a TH1D and at the end assignment I set it using the de-referencing operator ( FitHist = *Fits.at(indx); ), but the results are the same.
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided