I am trying to perform pulse analysis using root, because my pulses are stored in root histograms.
What I need is to loop over a histogram and locate local maxima and minima values.
To do that, I found
so I downloaded the relevant files to my directory. Then I copied-pasted a simple example to check if it’s working which is the following
[code]#include “persistence1d.hpp”
using namespace std;
using namespace p1d;
int extrema()
{
//Create some data
vector< float > data;
data.push_back(2.0); data.push_back(5.0); data.push_back(7.0);
data.push_back(-12.0); data.push_back(-13.0); data.push_back(-7.0);
data.push_back(10.0); data.push_back(18.0); data.push_back(6.0);
data.push_back(8.0); data.push_back(7.0); data.push_back(4.0);
//Run persistence on data - this is the main call.
Persistence1D p;
p.RunPersistence(data);//<----------------This is where the code breaks
return 0;
}[/code]
However the code breaks and I am not able to run it. I am able to compile and run the code outside root but I want to do it in root in order to use the histogram functions.
The error I get when running the macro is
[quote]Error: Can’t call Persistence1D::RunPersistence(y) in current scope extrema.c:21:
Possible candidates are…
(in Persistence1D)
persistence1d.hpp 128:16 0 public: bool Persistence1D::RunPersistence(const vector& InputData);
*** Interpreter error recovered ***
[/quote]
Is there a way to implement into root an external .hpp file?
this is easily done in ROOT6.
Here you find a modernised (C++11) version of your example:
#include "persistence1d.hpp"
using namespace std;
using namespace p1d;
int extrema()
{
//Create some data
vector< float > data {2,5,7,-12,-13,-7,10,18,6,8,7,4};
//Run persistence on data - this is the main call.
Persistence1D p;
p.RunPersistence(data);
p.PrintResults();
return 0;
}
and this is the result I get after running root -b -q extrema.C:
Persistence: 2 minimum index: 8 maximum index: 9
Persistence: 5 minimum index: 0 maximum index: 2
Persistence: 14 minimum index: 11 maximum index: 7
Global minimum value: -13 index: 4
Thank you very much for your reply!
How am I going to use Root6 in lxplus?
I forgot to mention that I am running root in my lxplus account.
So if I type
I get the error
Processing extrema_root_forum.C...
Error: Variable name has bad character 'data{2,5,7,-12,-13,-7,10,18,6,8,7,4}' extrema_root_forum.C:9:
*** Interpreter error recovered ***
. /afs/cern.ch/sw/lcg/external/gcc/4.8/x86_64-slc6/setup.sh
. /afs/cern.ch/sw/lcg/app/releases/ROOT/6.02.02/ [This path continues on the next line]
x86_64-slc6-gcc48-opt/root/bin/thisroot.sh
Can it be that your login shell is a “[t]csh”?
If yes, try: source /afs/cern.ch/sw/lcg/external/gcc/4.8/x86_64-slc6/setup.csh
source /afs/cern.ch/sw/lcg/app/releases/ROOT/6.02.02/x86_64-slc6-gcc48-opt/root/bin/thisroot.csh
I am using a tcsh shell, indeed!
I typed your commands which returned no error. So I guess I must be able to run ROOT6.
However, I still cannot run it…
[astamato@lxplus0085 PSA-FIMG]$ root b q -l extrema.c
Warning in <TApplication::GetOptions>: macro b not found
Warning in <TApplication::GetOptions>: macro q not found
root [0]
Processing extrema.c...
Error: Variable name has bad character 'data{2,5,7,-12,-13,-7,10,18,6,8,7,4}' extrema.c:9:
*** Interpreter error recovered ***
Oops… I am sorry… That was very stupid of me… Even then, however I cannot run it
[astamato@lxplus0082 persistence1d]$ root -l -b -q extrema_root_forum.C
root [0]
Processing extrema_root_forum.C...
In file included from /afs/cern.ch/work/a/astamato/private/PSA-FIMG/Persistence1D/src/persistence1d/AutoDict_vector_p1d__TPairedExtrema_.cxx:1,
from /afs/cern.ch/work/a/astamato/private/PSA-FIMG/Persistence1D/src/persistence1d/AutoDict_vector_p1d__TPairedExtrema__cxx_ACLiC_dict.h:34,
from /afs/cern.ch/work/a/astamato/private/PSA-FIMG/Persistence1D/src/persistence1d/AutoDict_vector_p1d__TPairedExtrema__cxx_ACLiC_dict.cxx:17:
/afs/cern.ch/work/a/astamato/private/PSA-FIMG/Persistence1D/src/persistence1d/persistence1d.hpp: In member function ‘void p1d::Persistence1D::Watershed()’:
/afs/cern.ch/work/a/astamato/private/PSA-FIMG/Persistence1D/src/persistence1d/persistence1d.hpp:639: warning: comparison between signed and unsigned integer expressions
Error: Variable name has bad character 'data{2,5,7,-12,-13,-7,10,18,6,8,7,4}' extrema_root_forum.C:9:
*** Interpreter error recovered ***
This error looks like you were running ROOT 5 … try:
which root
type root
where root
(or simply run “root” without “-l -b” and see how it introduces itself).
But you do remember that the effects of “source …” are valid in the current shell only (i.e. in the same x-terminal window in which you executed it), unless you added them to your “${HOME}/.[t]cshrc”.
Try (see if you get ROOT 6 version specific entries “in front” of these variables):
echo ${ROOTSYS}
echo ${PATH}
echo ${LD_LIBRARY_PATH}