graphToHist.cxx 1.35 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
using namespace std;

void graphToHist()
{
	
    TFile fr("calGraphs680.root");

	TGraph *fGraph[64];

    TList *gList = fr.GetListOfKeys();
    const Int_t nEntries = gList->GetEntries();
    if (nEntries!=64) {
        Error("cls_Calibrator::ImportGraphs", "Something wrong, only %d graphs found instead of 64", nEntries);
        return;
    }

    TString gName;
    for (Int_t i = 0; i < nEntries; i++) {
        gName.Form("gcal%d", i);
        fGraph[i] = (TGraph*)fr.Get(gName.Data());
        if ( fGraph[i] == 0) {
            Error("cls_Calibrator::ImportGraphs", "Graph %s was not found in file %s", gName.Data(), fr.GetName());
            fr.Close();
            return;
        }
    }//for

	fr.Close();

    TH1D* fLUT[64];

//LUT function

	TString hName;
	TString hTitle;
	const Double_t minX = -50.;
	const Double_t maxX = 4096.;

	Double_t xmin = 0;
	Double_t xmax = 0;
	Double_t ymin = 0;
	Double_t ymax = 0;

	for (Int_t i = 0; i < 64; i++) {
		hName.Form("calHist%d", i);
		hTitle.Form("do we need it for channel %d?", i);
		fLUT[i] = new TH1D(hName.Data(), hTitle.Data(), maxX - minX, minX, maxX);
//		fGraph[i]->ComputeRange(&xmin, &ymin, &xmax, &ymax);
		fGraph[i]->ComputeRange(xmin, ymin, xmax, ymax);
		cout << xmin << "\t" << xmax << endl;
		for (Int_t j = xmin; j <= xmax; j++) {
			fLUT[i]->SetBinContent(j, fGraph[i]->Eval(j) );
		}
	}//for



}