#include <stdlib.h>
#include <stdio.h>
#include <TH1F.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TStyle.h>
#include <TBufferJSON.h>
//#include <TBufferXML.h>
class Hdr{
public:
int id;
int len;
int progress;
};
void send_message(int id, TString msg, int progress){
static Hdr hdr;
hdr.id = id;
hdr.len= msg.Length();
hdr.progress= progress;
fwrite(&hdr,3*sizeof(int),1,stdout);
fwrite(msg.Data(),hdr.len,1,stdout);
fflush(stdout);
}
int th1fit(Double_t *data, const char *name, const char *title, int xbins, double xmin, double xmax, double min=0, double max=1,const char *func=NULL, const char *pars=NULL){
TH1F *h = new TH1F(name,title,xbins, xmin,xmax);
for (int i=0;i<xbins+2;i++) h->SetBinContent(i,data[i]);
gStyle->SetOptFit(1111);
TF1 *f = new TF1("f",func,min,max);
//TCanvas *v =new TCanvas();
h->Fit(f,"RQ");
h->Draw();
//v->Modified();
//v->Update();
send_message(1,TBufferJSON::ConvertToJSON(h),0 );
return 0;
}