Error while returning two values from the same function

Hi,

I am trying to get the eff. & eff. error from the same function.
But while compiling & running I am getting the following error.

Error: Symbol make_pair is not defined in current scope EffAndError.C:77:
Error: Symbol double is not defined in current scope EffAndError.C:77:

I am putting the code snippet below.
Can anyone help please?

Thanks & regards.

#include
#include
#include
#include
#include
#include
#include
#include <TGraphAsymmErrors.h>
#include <math.h>
#include

using namespace std;

void EffAndError(){
vectorstd::stringinputfile;
inputfile.push_back(“First_file.root”);
inputfile.push_back(“Second_file.root”);
inputfile.push_back(“Third_file.root”);

//and so on

std::pair<double,std::pair<double,double>> getEfficiency(int passed,int total)
{
double theEff = double(passed)/double(total);
double theEffError= sqrt(theEff*(1.-theEff)/double(total));

pair<double,double>theEffErrors = make_pair<double,double>(theEffError,theEffError);

if((theEff + theEffError) >= 1. || (theEff - theEffError <= 0.)){
//do one bin histo && extract bayes eff
TH1F* theNumHisto = new TH1F(“theNumHisto”,“theNumHisto”,1,0,1);
theNumHisto->SetBinContent(1,passed);
theNumHisto->Sumw2();
TH1F* theDenHisto = new TH1F(“theDenHisto”,"",1,0,1);
theDenHisto->SetBinContent(1,total);
theDenHisto->Sumw2();
TGraphAsymmErrors* bayesEff = new TGraphAsymmErrors();
bayesEff->BayesDivide(theNumHisto,theDenHisto,“b”);
double effErrorHigh = bayesEff->GetErrorYhigh(0);
double effErrorLow = bayesEff->GetErrorYlow(0);
theEffErrors = make_pair<double, double>(effErrorLow, effErrorHigh);

delete theNumHisto;
delete theDenHisto;
delete bayesEff;
}

pair<double,pair<double,double> > theEffAndError = make_pair<double,pair<double,double> >(theEff,theEffErrors);
return theEffAndError;
}
//---------------------------------------------------------------------------
for (int i=0;i<inputfile.size();++i){
TFile *h1 = TFile::Open(inputfile[i].c_str());
gDirectory->cd(“analyzeHiMassTau”);

int passed = Events->GetBinContent(2);
int total = Events->GetBinContent(1);

pair<double,pair<double,double> > efficiency = getEfficiency(passed,total);
double Eff = efficiency.first;
pair<double, double> EffErr = efficiency.second;

}
}

Hi,

To get this to work in interpreted code you need to include the pair header file:

Cheers,
Philippe.

Hi Philippe,

I included the header file in my macro.But I am still getting the same error.

Thanks & regards.

Hi,

Can you send me a complete running example showing the problem?

Thanks,
Philippe.

Sorry to ask you in this thread, but this exactly what I am looking for.

Here is exact error:
Error: Symbol pair<double is not defined in current scope mypicodst.C:161:
Error: type pair<double not defined mypicodst.C LINE:161
*** Interpreter error recovered ***

Here is part of the code, where error is coming from (only place where “pair” is used)
pair<double,double> *tmps;
tmps = new pair<double,double> [10];
cout<<tmps[j].first<<"\t"<<tmps[j].second<<endl;

I have already added #include and #include in supporting header file of main code.

Please help.

Thank you.

Hi,

This is a limitation of the CINT interpreter when it comes to create array of template class objects.

Use either ROOT v6.04 (which use the new interpreter cling) or the work-around:

pair<double,double> *tmps; typedef pair<double,double> pairdd_t; tmps = new pairdd_t [10];

Cheers,
Philippe.

Hi Philippe,
Thank you for your quick reply.

I used your coding as it was & following error appeared:

Limitation: In function typedef not allowed in cint mypicodst.C:162:
Error: Symbol pairdd_t is not defined in current scope mypicodst.C:164:
Error: type pairdd_t not defined mypicodst.C LINE:164
*** Interpreter error recovered ***

So I putted following two lines in header instead of writing them inside code & things worked.

pair<double,double> *tmps;
typedef pair<double,double> pairdd_t;

Thank you very much.

Hi,

Move the typedef outside the function :slight_smile:

Cheers,
Philippe.

I already did that Philippe.
Thank you again :slight_smile: