Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 326 | f9daq | 1 | #include "TH2D.h" | 
        
| 2 | #include "..\cvi\H2D.h" | 
        ||
| 3 | |||
| 4 | double H2DGetBinContent(H2D *h2d,int atx, int aty){  | 
        ||
| 5 | |||
| 6 | int idx;  | 
        ||
| 7 | if (!h2d) return 0;  | 
        ||
| 8 | if (h2d->nx <= atx) return 0;  | 
        ||
| 9 | if (h2d->ny <= aty) return 0;  | 
        ||
| 10 | idx = atx+aty*h2d->nx;  | 
        ||
| 11 | if (idx < h2d->size ) return h2d->data[idx];  | 
        ||
| 12 | |||
| 13 | |||
| 14 | return 0;  | 
        ||
| 15 | } | 
        ||
| 16 | |||
| 17 | |||
| 18 | int H2Dload(char *fname){  | 
        ||
| 19 | |||
| 20 | FILE *fp= fopen(fname ,"rb");  | 
        ||
| 21 | if (!fp) return -1;  | 
        ||
| 22 | H2D *h = new H2D;  | 
        ||
| 23 | int size=sizeof(H2D);  | 
        ||
| 24 | int nb1 = fread(h,1, size,fp);  | 
        ||
| 25 | if (size + h->size !=h->len ) printf("WRONG HEADER ! Check sizeof H2D on CVI\n");  | 
        ||
| 26 | |||
| 27 | size=h->size;  | 
        ||
| 28 | h->data = new double[size];  | 
        ||
| 29 | int nb = fread(h->data,1, size,fp);  | 
        ||
| 30 | printf("hdr nb=%d sizeof(HDR)=%d len=%d datasize=%d\t",nb1,sizeof(H2D),h->len, h->size);  | 
        ||
| 31 | printf("data nb=%d size=%d\n",nb,size);  | 
        ||
| 32 | |||
| 33 | TH2D *h2d = new TH2D(h->name, h->title,  | 
        ||
| 34 | h->nx, h->minx-0.5*h->stepx,h->minx+(h->nx-0.5)*h->stepx,  | 
        ||
| 35 | h->ny, h->miny-0.5*h->stepy,h->miny+(h->ny-0.5)*h->stepy);  | 
        ||
| 36 | h2d->SetTitle(h->title);  | 
        ||
| 37 | h2d->SetTitle("");  | 
        ||
| 38 | h2d->GetXaxis()->SetTitle(h->titlex);  | 
        ||
| 39 | h2d->GetYaxis()->SetTitle(h->titley);  | 
        ||
| 40 | printf("TH2D name=%s %s %s %s\nnx=%d %f %f \nny=%d %f %f\n",h->name, h->title,h->titlex, h->titley,  | 
        ||
| 41 | h->nx, h->minx-0.5*h->stepx,h->minx+(h->nx-0.5)*h->stepx,  | 
        ||
| 42 | h->ny, h->miny-0.5*h->stepy,h->miny+(h->ny-0.5)*h->stepy);  | 
        ||
| 43 | |||
| 44 | |||
| 45 | //h2d->ls(); | 
        ||
| 46 | //h2d->Print(); | 
        ||
| 47 | |||
| 48 | for (int ix=0;ix<h->nx;ix++){  | 
        ||
| 49 | for (int iy=0;iy<h->ny;iy++){  | 
        ||
| 50 | double g=H2DGetBinContent(h,ix,iy);  | 
        ||
| 51 | h2d->SetBinContent(ix+1,iy+1, g);  | 
        ||
| 52 | //       if (g>0) printf("i %d j %d v %g\n",ix+1,iy+1,g); | 
        ||
| 53 |   } | 
        ||
| 54 | |||
| 55 | } | 
        ||
| 56 | |||
| 57 | gStyle->SetOptStat(0);  | 
        ||
| 58 | h2d->Draw("colz");  | 
        ||
| 59 | char hname[100];  | 
        ||
| 60 | sprintf(hname,"%s.pdf",fname);  | 
        ||
| 61 | gPad->SaveAs(hname);  | 
        ||
| 62 | } |