How to correct the error: use of undeclared identifier 'plot_histogram'

const Int_t NEntry = 10000;
const double meanvalue = 1;
const double meanvalue2 = 1;
const double rmsvalue = 0.1;
const double rmsvalue2 = 0.1;

TMatrixD* produceSqrtMat( const TMatrixD& covMat )
{
Double_t sum = 0;
Int_t size = covMat.GetNrows();;
TMatrixD* sqrtMat = new TMatrixD( size, size );

for (Int_t i=0; i< size; i++) {
    
    sum = 0;
    for (Int_t j=0;j< i; j++) sum += (*sqrtMat)(i,j) * (*sqrtMat)(i,j);
    
    (*sqrtMat)(i,i) = TMath::Sqrt(TMath::Abs(covMat(i,i) - sum));
    
    for (Int_t k=i+1 ;k<size; k++) {
        
        sum = 0;
        for (Int_t l=0; l<i; l++) sum += (*sqrtMat)(k,l) * (*sqrtMat)(i,l);
        
        (*sqrtMat)(k,i) = (covMat(k,i) - sum) / (*sqrtMat)(i,i);
        
    }
}
return sqrtMat;

}

void getGaussRnd( TArrayD& v, const TMatrixD& sqrtMat, TRandom& R )
{
// generate “size” correlated Gaussian random numbers

// sanity check
const Int_t size = sqrtMat.GetNrows();
if (size != v.GetSize())
    cout << "<getGaussRnd> too short input vector: " << size << " " << v.GetSize() << endl;

Double_t* tmpVec = new Double_t[size];

for (Int_t i=0; i<size; i++) {
    Double_t x, y, z;
    y = R.Rndm();
    z = R.Rndm();
    x = 2*TMath::Pi()*z;
    tmpVec[i] = TMath::Sin(x) * TMath::Sqrt(-2.0*TMath::Log(y));
}

for (Int_t i=0; i<size; i++) {
    v[i] = 0;
    for (Int_t j=0; j<=i; j++) v[i] += sqrtMat(i,j) * tmpVec[j];
}

delete[] tmpVec;

}

void generate_2parameter(){
gROOT->ProcessLine(".x …/rootlogon.C");
ofstream opfile(“data4histogram_2d.txt”);

opfile<<"#entry #value1 #value2"<<endl;
//covariance matrix
TMatrixD* covmatrix = new TMatrixD(2,2);
/*Float_t offaxisVal = 0.45*rmsvalue*rmsvalue2;*/
Float_t offaxisVal = 0.0*rmsvalue*rmsvalue2;
(*covmatrix)(0,0) = rmsvalue*rmsvalue;
(*covmatrix)(1,1) = rmsvalue2*rmsvalue2;
(*covmatrix)(0,1) = offaxisVal*offaxisVal;
(*covmatrix)(1,0) = (*covmatrix)(0,1);
cout << "covariance matrix: " << endl;
covmatrix->Print();

//square-root matrix
TMatrixD* sqrtMatrix = produceSqrtMat(  *covmatrix );
cout << "Square root of covariance matrix: " << endl;
sqrtMatrix->Print();

TArrayD* v = new TArrayD( 2 );
Float_t xvar[2];
double_t xS[2] = {  meanvalue,  meanvalue2 };



//covariance matrix
TRandom R( 100 );
for (Int_t ientry=0; ientry<NEntry; ++ientry) {
    getGaussRnd( *v, *sqrtMatrix, R );
    for (Int_t ivar=0; ivar<2; ivar++) xvar[ivar] = (*v)[ivar] + xS[ivar];
    opfile<<ientry<<" "<<xvar[0]<<" "<<xvar[1]<<endl;
}
opfile.close();
plot_histogram_2d(); 

}

It looks like “plot_histogram_2d();” is a function call, so you need to talk to the author of your macro (who should be able to give you this function).

The later part of the code is:

void plot_histogram_2d(){
ifstream cfile(“data4histogram_2d.txt”);
string dummyline;
getline(cfile,dummyline);
Int_t ithentry;
double ithvalue;
double ithvaluey;
double maxvalue = meanvalue+4rmsvalue;
double minvalue = meanvalue-4
rmsvalue;
double maxvaluey = meanvalue2+4rmsvalue2;
double minvaluey = meanvalue2-4
rmsvalue2;
TH2F* hhisto = new TH2F( “Histogram”, " " ,50,minvalue,maxvalue,50,minvaluey,maxvaluey);
TH1F* hhisto_effect = new TH1F( “Histogram_effect”, " " ,100,0.5,1.5);
for (Int_t ientry=0; ientry<NEntry; ++ientry) {
cfile >> ithentry >> ithvalue>>ithvaluey;
//cout<<"entry “<<ithentry<<” values "<<ithvalue<<endl;
hhisto->Fill(ithvalue,ithvaluey);
hhisto_effect->Fill(ithvalue*ithvaluey);
}
hhisto->GetXaxis()->SetTitle(“Values of variable X”);
hhisto->GetYaxis()->SetTitle(“Values of variable Y”);
TH1D * projh2X = hhisto->ProjectionX();
TH1D * projh2Y = hhisto->ProjectionY();

TCanvas *c1 = new TCanvas("c1", "c1",900,900);
gStyle->SetOptStat(0);

// Create the three pads
TPad *center_pad = new TPad("center_pad", "center_pad",0.0,0.0,0.6,0.6);
center_pad->Draw();

TPad *right_pad = new TPad(“right_pad”, “right_pad”,0.6,0.0,1.0,0.6);
right_pad->Draw();

TPad *top_pad = new TPad(“top_pad”, “top_pad”,0.0,0.6,0.55,1.0);
top_pad->Draw();

TPad *topright_pad = new TPad(“topright_pad”, “topright_pad”,0.6,1.0,0.57,1.0);
topright_pad->Draw();

In the beginning of your macro file, add the declaration: void plot_histogram_2d();

2 Likes

Thank You so much.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.