Rev 268 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 268 | Rev 269 | ||
---|---|---|---|
1 | #include <stdlib.h> |
1 | #include <stdlib.h> |
2 | #include <stdio.h> |
2 | #include <stdio.h> |
3 | #include <TH1F.h> |
3 | #include <TH1F.h> |
4 | #include <TCanvas.h> |
4 | #include <TCanvas.h> |
5 | #include <TF1.h> |
5 | #include <TF1.h> |
6 | #include <TStyle.h> |
6 | #include <TStyle.h> |
7 | #include <TBufferJSON.h> |
7 | #include <TBufferJSON.h> |
- | 8 | #include <TString.h> |
|
- | 9 | #include <TObjString.h> |
|
- | 10 | #include <string.h> |
|
8 | //#include <TBufferXML.h> |
11 | //#include <TBufferXML.h> |
9 | class Hdr{ |
12 | class Hdr{ |
10 | public: |
13 | public: |
11 | int id; |
14 | int id; |
12 | int len; |
15 | int len; |
13 | int progress; |
16 | int progress; |
14 | }; |
17 | }; |
15 | 18 | ||
16 | void send_message(int id, TString msg, int progress){ |
19 | void send_message(int id, TString msg, int progress){ |
17 | static Hdr hdr; |
20 | static Hdr hdr; |
18 | 21 | ||
19 | hdr.id = id; |
22 | hdr.id = id; |
20 | hdr.len= msg.Length(); |
23 | hdr.len= msg.Length(); |
21 | hdr.progress= progress; |
24 | hdr.progress= progress; |
22 | fwrite(&hdr,3*sizeof(int),1,stdout); |
25 | fwrite(&hdr,3*sizeof(int),1,stdout); |
23 | fwrite(msg.Data(),hdr.len,1,stdout); |
26 | fwrite(msg.Data(),hdr.len,1,stdout); |
24 | fflush(stdout); |
27 | fflush(stdout); |
25 | 28 | ||
26 | } |
29 | } |
27 | 30 | ||
28 | 31 | ||
29 | 32 | ||
30 | 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){ |
33 | 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){ |
31 | 34 | ||
32 | TH1F *h = new TH1F(name,title,xbins, xmin,xmax); |
35 | TH1F *h = new TH1F(name,title,xbins, xmin,xmax); |
33 | for (int i=0;i<xbins+2;i++) h->SetBinContent(i,data[i]); |
36 | for (int i=0;i<xbins+2;i++) h->SetBinContent(i,data[i]); |
34 | 37 | ||
35 | gStyle->SetOptFit(1111); |
38 | gStyle->SetOptFit(1111); |
36 | TF1 *f = new TF1("f",func,min,max); |
39 | TF1 *f = new TF1("f",func,min,max); |
- | 40 | ||
- | 41 | char *s = (char *)pars; |
|
- | 42 | ||
- | 43 | int cntr=0; |
|
- | 44 | char *p = strchr(s,','); |
|
- | 45 | if (p!=NULL){ |
|
- | 46 | do { |
|
- | 47 | char tok[0xFF]; |
|
- | 48 | strncpy(tok, s, p-s); |
|
- | 49 | tok[p-s]=0; |
|
- | 50 | ||
- | 51 | if (strlen(tok)) { |
|
- | 52 | //printf("*"); |
|
- | 53 | f->SetParameter(cntr,atof(tok)); |
|
- | 54 | } |
|
- | 55 | //printf("-----[%d] length=%d %s\n", cntr, strlen(tok),tok); |
|
- | 56 | s = p + 1; |
|
- | 57 | cntr++; |
|
- | 58 | p = strchr(s,','); |
|
- | 59 | } while (p!=NULL); |
|
- | 60 | } |
|
- | 61 | if (strlen(s)>0) { |
|
- | 62 | f->SetParameter(cntr,atof(s)); |
|
37 | / |
63 | //printf("----[0x] %s\n",s); |
- | 64 | } |
|
- | 65 | ||
- | 66 | ||
38 | h->Fit(f,"RQ"); |
67 | h->Fit(f,"RQ"); |
39 | h->Draw(); |
68 | h->Draw(); |
40 | //v->Modified(); |
- | |
41 | //v->Update(); |
69 | |
42 | send_message(1,TBufferJSON::ConvertToJSON(h),0 ); |
70 | send_message(1,TBufferJSON::ConvertToJSON(h),0 ); |
43 | return 0; |
71 | return 0; |
44 | } |
72 | } |
45 | 73 |