Reading asc file in 2D histogram

Hello
This file given below is the file for read an “asc” file named foo.asc. But I need 2D histogram. One axis contains foo.asc data and the other contain, say, foo2.asc. Is there a way to do this?

Best wishes,

Serkan


#include
#include
// #include

#include “TH1.h”

void readasc()
{

vector<Float_t> dat;
ifstream in;
in.open(“foo.asc”);

//read file
while( in.good() )
{
Double_t num;
in >> num;
// std::cout << “in.fail():” << in.fail() << “; num=” << num << std::endl;
if( in.fail() )
break;
dat.push_back(num);
}

// fill histo
Int_t numbins = dat.size();
TH1F* h = new TH1F(“h1”,“h1”, numbins, 0, numbins );
for ( Int_t i=0; i != numbins; ++i )
{
h->SetBinContent( i+1, dat.at(i) );
h->SetEntries( h->GetEntries()+i );
}

//draw histo
h->Draw();

}


foo.asc.tar.gz (146 Bytes)

Hi,

you could do it once for X, once for Y, and then fill the histogram.

Axel.

In the same code?
Thank you

Hi,

yes, why not? You’ll need two vectors of course, say “datX” and “datY”.

Axel.

Thank you so much, it works :slight_smile:

Best wishes to you