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