Subversion Repositories f9daq

Rev

Rev 268 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  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>
  8. #include <TString.h>
  9. #include <TObjString.h>
  10. #include <string.h>
  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.  
  38. gStyle->SetOptFit(1111);
  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));
  63.     //printf("----[0x] %s\n",s);
  64. }
  65.  
  66.  
  67. h->Fit(f,"RQ");
  68. h->Draw();
  69.  
  70. send_message(1,TBufferJSON::ConvertToJSON(h),0 );
  71. return 0;
  72. }
  73.