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