00001 #include <stdio.h>
00002 #include <assert.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "L2Histo.h"
00015
00016 #include "TH1F.h"
00017 #include "TH2F.h"
00018 #include "TFile.h"
00019 #include "TString.h"
00020
00021
00022 void create1D( L2Histo & h, char *hname) {
00023 TString name="h";name+=h.getId();
00024 if(hname[0]) name=hname;
00025 TString title=h.getTitle();
00026 int nbin=h.getNbin();
00027 int sum=h.getNunder()+h.getNover();
00028
00029 TH1F *hout=new TH1F(name,title,nbin,0,nbin);
00030 float * y=hout->GetArray();
00031 const int *data=h.getData();
00032 for ( int ii=0;ii<nbin;ii++ ){
00033 y[ii+1]= data[ii];
00034 sum+= data[ii];
00035 }
00036 y[0]=h.getNunder();
00037 y[nbin+1]=h.getNover();
00038 hout->SetEntries(sum);
00039 hout->SetLineColor(kBlue);
00040 hout->Write();
00041 }
00042
00043
00044 void create2D( L2Histo & h) {
00045 TString name="h";name+=h.getId();
00046 TString title=h.getTitle();
00047 int nbin=h.getNbin();
00048 int nbinX=h.getNbinX();
00049 int nbinY=h.getNbin()/nbinX;
00050 int sum=h.getNunder()+h.getNover();
00051
00052 TH2F *hout=new TH2F(name,title,nbinX,0,nbinX,nbinY,0,nbinY);
00053
00054 const int *data=h.getData();
00055 for ( int i =0;i <nbin;i ++ ){
00056 int ix=i%nbinX;
00057 int iy=i/nbinX;
00058
00059 hout->SetBinContent(ix+1,iy+1,data[i]);
00060 sum+=data[i];
00061 }
00062
00063
00064 hout->SetEntries(sum);
00065
00066 hout->Write();
00067 }
00068
00069
00070
00071 int main(int argc, char ** argv ) {
00072 printf("Converting L2-bin-histos to root histos START...");
00073
00074 if(argc!=3) {
00075 printf("\nERROR: must specify an input and output file, e.g.:\n %s inp.hist.bin out.hist.root\n STOP\n",argv[0]);
00076 exit(1);
00077 }
00078
00079 char *histFname=argv[1];
00080
00081
00082 FILE *histFd=fopen(histFname,"r");
00083 assert(histFd);
00084
00085 TString ofilename=argv[2];
00086 printf("outfile=%s\n",ofilename.Data());
00087
00088 TFile *ofile=new TFile(ofilename,"recreate");
00089
00090 int nh=0;
00091 while(1) {
00092 L2Histo h;
00093 int ret=h.read(histFd);
00094 if(ret) break;
00095 nh++;
00096 int iMax=-3, iFWHM=-4;
00097 h.findMax( &iMax, &iFWHM);
00098 if(h.getId()<1000) printf("h%d, '%s' binMax=%d \n",h.getId(),h.getTitle(),iMax);
00099
00100 char hname[100];
00101 hname[0]=0;
00102
00103
00104 if(h.getId()>9999) {
00105
00106 hname[0]='a';
00107 strncpy(hname+1,h.getTitle()+5,6);
00108 hname[7]=0;
00109
00110 }
00111
00112 if(h.is1D()) create1D(h,hname);
00113 else create2D(h);
00114
00115
00116
00117 }
00118
00119 ofile->Close();
00120 delete ofile;
00121
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133