Hi!
I have a problem. I like to read an ASCII file with one colume and make a Graph or a Histogramm withe the values over the bins, afte that i like to do a Sinus-fit. Mz problem is, that i did it with Histograms, so when i fit the Histogramm, he couldn´t find the middle of the oscillation, because there is more data in below. Is there a possibility to fill just the amplitude of each bin in a Histogram or a TGraph?
I tried it with just give him the middle of the Graph, but that won´t work i think, because the Histogramm goes down to zero somewhere so my minimum would be zero, anyway here is what i did until now:
#include <Riostream.h>
#include <fstream.h>
#include <stdio.h>
#include <TH1D.h>
#include <TH2D.h>
#include "TTree.h"
#include "TFile.h"
#include "TROOT.h"
#include <iostream>
void reading1()
{
Int_t counts;
ifstream in;
in.open("c:/root/macros/Datei.txt");
TFile *f = new TFile("c:/root/macros/Datei.root","RECREATE");
TH1D *h1 = new TH1D("h1","test",1000,0,1000);
Int_t min = 999999999999;
Int_t max = 0;
Int_t nlines = 0;
while(!in.eof())
{
in >> counts;
if(counts<min) min = counts;
if(counts>max) max = counts;
if (!in.good()) break;
h1->Fill(nlines,counts);
nlines++;
}
Double_t mid = (max-min)/2;
//MyFunction *half = new MyFunction("(h1->GetMaximum-h1->GetMinimum)/2");
Double_t myfunction(Double_t *x, Double_t *par, Double_t mid)
{
Float_t xx =x[0];
Double_t f = mid+par[0]*sin(2*pi*(xx-par[1])/par[2]);
return f;
}
TF1 *fit = new TF1("fit",myfunction,0,2);
h1->Fit("fit","+QEM");
in.close();
h1->Draw();
f->Write();
}