Subversion Repositories f9daq

Rev

Rev 258 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. #include <TH1D.h>
  2. #include <TStyle.h>
  3. #include <TPad.h>
  4. #include "mH1D.h"
  5. #include <TSystem.h>
  6.  
  7. double H1DGetBinContent(H1D *h1d,int atx){
  8.  
  9. if (!h1d) return 0;
  10. if (h1d->nx <= atx)  return 0;  
  11. if (atx < h1d->size ) return h1d->data[atx];
  12.  
  13.  
  14. return 0;
  15. }
  16.  
  17.  
  18. int H1Dload(char *fname){
  19.  
  20. TString dfile( gSystem->Getenv("USERPROFILE") );
  21. dfile.ReplaceAll("\\","/");
  22. dfile += TString("/Desktop/data/") + fname;
  23. fprintf(stderr, "Filename %s\n",dfile.Data());
  24. FILE *fp= fopen(dfile.Data() ,"rb");
  25.  
  26. if (!fp) return -1;
  27. H1D *h = new H1D;
  28. int size=sizeof(H1D);
  29. int nb1 = fread(h,1, size,fp);
  30. if (size + h->size !=h->len ) printf("WRONG HEADER ! Check sizeof H2D on CVI\n");
  31.  
  32. size=h->size;
  33. h->data = new double[size];
  34. int nb  = fread(h->data,1, size,fp);
  35. printf("hdr nb=%d : sizeof(HDR)=%d +datasize=%d == len=%d\t",nb1,sizeof(H1D), h->size, h->len);
  36. printf("data nb=%d size=%d\n",nb,size);
  37. fclose(fp);
  38. TH1D *h1d = new TH1D(h->name, h->title,
  39.                      h->nx, h->minx-0.5*h->stepx,h->minx+(h->nx-0.5)*h->stepx );
  40. h1d->SetTitle(h->title);
  41. h1d->SetTitle("");
  42. h1d->GetXaxis()->SetTitle(h->titlex);
  43. h1d->GetYaxis()->SetTitle(h->titley);
  44. printf("TH1D name='%s' title='%s' x='%s' y='%s'\nnx=%d min=%f max=%f \n",h->name, h->title,h->titlex, h->titley,
  45.                      h->nx, h->minx,h->minx+h->nx*h->stepx);
  46.  
  47.                      
  48. //h2d->ls();
  49. //h2d->Print();
  50.  
  51. for (int ix=0;ix<h->nx;ix++){
  52.  
  53.          double g=H1DGetBinContent(h,ix);
  54.      h1d->SetBinContent(ix+1, g);
  55. //       if (g>0) printf("i %d j %d v %g\n",ix+1,iy+1,g);
  56.  
  57. }
  58. h1d->SetEntries(h->nentries);
  59. gStyle->SetOptStat(1);
  60. gStyle->SetOptFit(1);
  61. h1d->Draw("colz");
  62.  
  63. TString hname;
  64. //sprintf(hname,"%s.pdf",dfile.Data());
  65. hname = dfile + ".pdf";
  66. gPad->SaveAs(hname);
  67.  
  68. //sprintf(hname,"%s.root",dfile.Data());
  69. hname = dfile + ".root";
  70. //printf("%s\n",hname);
  71. printf("%s\n",hname.Data());
  72. gPad->SaveAs(hname);
  73. h1d->FitPanel();
  74. return 0;
  75. }
  76.