Subversion Repositories f9daq

Rev

Rev 269 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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