#include "PelTools.h"
#ifndef DAMM
#define DAMM
struct drrheader
{
char label[12];
unsigned int nhis;
unsigned int nhalfword;
unsigned int year;
unsigned int month;
unsigned int day;
unsigned int hour;
unsigned int minute;
unsigned int second;
char title[40];
} DRRHEADER;
struct drrdir
{
unsigned short histdim;
unsigned short nhalfwordperchannel;
unsigned short histpar[4];
unsigned short lengthraw[4];
unsigned short lengthscaled[4];
unsigned short minchannel[4];
unsigned short maxchannel[4];
unsigned int offset;
char xlabel[6];
char ylabel[6];
float calib[4];
char title[4];
} DRRDIR;
#endif
ClassImp(PelTools)
PelTools::PelTools():TNamed("gPelTools","Pellectron Tools")
{
int i;
gROOT->Add(this);
mCutF = NULL;
mCut = NULL;
mList = NULL;
mBackLin = new TF1("___BACK___","[0]+[1]*x");
fMainFrame1186 = 0;
isGUIActive = false;
mIndex = 0;
mHist = new TContainer();
mHist->empty();
}
PelTools::~PelTools()
{
if(fMainFrame1186) delete fMainFrame1186;
if(mBackLin) delete mBackLin;
if(mHist) delete mHist;
}
TList* PelTools::makeList(char* name)
{
int i,n;
if(mList) {delete mList; mList = NULL;}
mList = new TList();
if(gPad)
{
TList *l = gPad->GetListOfPrimitives();
if(l)
{
n = l->GetSize();
if(n>0) for(i=0;i<n;i++)
{
TObject *o = l->At(i);
TString n = o->ClassName();
if(n.BeginsWith(name)) mList->AddLast(o);
}
}
}
n = mList->GetSize();
if(n==0) { delete mList; mList = NULL;}
return mList;
}
void PelTools::del(char* name)
{
mHist->remove(name);
return;
}
void PelTools::openFile(char *name, char* flag)
{
if(mCutF) closeFile();
mCutF = new TFile(name,flag);
}
void PelTools::createFile(char* name)
{
openFile(name,"RECREATE");
}
void PelTools::createFileGUI()
{
TGFileInfo fi;
new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),kFDSave,&fi);
if(fi.fFilename) openFile(fi.fFilename,"RECREATE");
}
void PelTools::openFileGUI()
{
TGFileInfo fi;
new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),kFDOpen,&fi);
if(fi.fFilename)openFile(fi.fFilename,"UPDATE");
}
void PelTools::closeFile()
{
if(mCutF) {mCutF->Close(); delete mCutF; mCutF=NULL;}
}
void PelTools::listFile()
{
if(!mCutF) { message(1,"Warning","There is no cut file open"); return;}
mCutF->ls();
}
void PelTools::saveCut(char* name)
{
if(!mCutF) { message(1,"Warning","There is no cut file open"); return;}
TCutG *cc = getCurrCut();
if(!cc) { message(1,"Warning","There is no cut available for saving"); return;}
cc->SetName(name);
mCutF->cd();
cc->Write();
}
TCutG* PelTools::getCurrCut()
{
TCutG *cc = NULL;
if(!cc) cc = mCut;
if(!cc) cc = (TCutG*)gROOT->FindObjectAny("CUTG");
mCut = cc;
return cc;
}
void PelTools::printCurrCut()
{
TCutG* cut = getCurrCut();
if(cut) cut->Print();
}
void PelTools::drawCurrCut()
{
TCutG* cut = getCurrCut();
if(cut) cut->Draw();
if(gPad) gPad->Update();
}
void PelTools::saveCutGUI()
{
if(!mCutF) { message(1,"Warning","There is no cut file open"); return;}
TCutG *cc = getCurrCut();
if(!cc) { message(1,"Warning","There is no cut available for saving"); return;}
char *title = " Save Cut";
TString label = " Enter the cut identifier ";
TString output = "";
int stat;
new TDialog(title,1,&label,&output,&stat);
char* name = (char*)output.Data();
if(stat==1) saveCut(name);
}
TCutG* PelTools::getCut(char* name)
{
if(!mCutF) { message(1,"Warning","There is no cut file open"); return NULL;}
mCut = (TCutG*)mCutF->Get(name);
return mCut;
}
TCutG* PelTools::getCutGUI()
{
if(!mCutF) { message(1,"Warning","There is no cut file open"); return NULL;}
char *title = " Load Cut";
TString label = " Enter the cut identifier ";
TString output = " ";
int stat;
new TDialog(title,1,&label,&output,&stat);
char* name = (char*)output.Data();
if(stat==1) mCut = getCut(name);
if(mCut) mCut->Draw();
if(gPad) gPad->Update();
return mCut;
}
TH2D* PelTools::extract(TH2D* h, TCutG* c)
{
int i,j,nx,ny,bin;
float X,Y,V;
if(!h) return NULL;
if(!c) return NULL;
TAxis *x = h->GetXaxis();
TAxis *y = h->GetYaxis();
nx = x->GetNbins();
ny = y->GetNbins();
float xmin = x->GetBinLowEdge(1);
float xmax = x->GetBinUpEdge(nx);
float ymin = y->GetBinLowEdge(1);
float ymax = y->GetBinUpEdge(ny);
TString name="ZZZZ_temp_extract_TH2_Cut_asdfghjkl";
del((char*)name.Data());
TH2D *hnew = new TH2D(name.Data(),name.Data(),nx,xmin,xmax,ny,ymin,ymax);
for(i=1; i<=nx;i++)
for(j=1;j<=ny;j++)
{
bin = h->GetBin(i,j);
X = x->GetBinCenter(i);
Y = y->GetBinCenter(j);
V = h->GetBinContent(bin);
if(c->IsInside(X,Y)) hnew->Fill(X,Y,V);
}
hnew->SetName(name.Data());
mHist->add(hnew);
return hnew;
}
void PelTools::drawProjectionCut(int m)
{
int i,id,n;
TH2D *hh = NULL;
TH2D *mHC = NULL;
TH1D *mP = NULL;
TCutG *cc = getCurrCut();
if(!cc) { message(1,"Warning","There is no cut available in the memory"); return;}
TList *l = makeList("TH2");
if(l)
{
n = l->GetSize();
for(i=0;i<n;i++)
{
hh = (TH2D*)l->At(i);
if(hh)
{
mHC = extract((TH2D*)hh,cc);
if(mHC)
{
TString n = mHC->GetName();
if(m==0) n+="_px";
else n+="_py";
n+=mIndex++;
del((char*)n.Data());
if(m==0) mP = mHC->ProjectionX();
else mP = mHC->ProjectionY();
mP->SetName(n.Data());
mP->SetEntries(mP->Integral());
mP->Draw();
mHist->add(mP);
}
}
}
} else { message(1,"Warning","There is no 2D histogram in the canvas"); return;}
if(gPad) gPad->Update();
return;
}
void PelTools::drawTH2Cut()
{
int i,id,n;
TH2D *hh = NULL;
TH2D *mHC = NULL;
TCutG *cc = getCurrCut();
if(!cc) { message(1,"Warning","There is no cut available in the memory"); return;}
TList *l = makeList("TH2");
if(l)
{
n = l->GetSize();
for(i=0;i<n;i++)
{
hh = (TH2D*)l->At(i);
if(hh)
{
mHC = extract((TH2D*)hh,cc);
if(mHC) { mHC->Draw(); mHC->SetEntries(mHC->Integral()); mCut = 0;}
}
}
} else { message(1,"Warning","There is no 2D histogram in the canvas"); return;}
if(gPad) gPad->Update();
return;
}
void PelTools::fitGUI()
{
int i,n=0;
TPeakFitGUI *gui = NULL;
if(!gPad) { message(1,"Warning","There is no TCanvas open"); return;}
TList *l = makeList("TH1");
TH1D *hh=NULL;
if(l)
{
n = l->GetSize();
for(i=0;i<n;i++)
{
hh = (TH1D*)l->At(i);
if(hh) gui = new TPeakFitGUI(hh,gPad);
}
} else message(1,"Warning","There is no 1D histogram displayed");
return;
}
float PelTools::counts(TH1D* h,float x1,float x2)
{
int bin1 = h->FindBin(x1);
int bin2 = h->FindBin(x2);
float integral = h->Integral(bin1,bin2-1);
return integral;
}
float PelTools::counts(TH2D* h,float x1,float x2,float y1, float y2)
{
int bin1 = h->GetXaxis()->FindBin(x1);
int bin2 = h->GetXaxis()->FindBin(x2);
int bin3 = h->GetYaxis()->FindBin(y1);
int bin4 = h->GetYaxis()->FindBin(y2);
float integral = h->Integral(bin1,bin2-1,bin3,bin4-1);
return integral;
}
float PelTools::integral(TH1D* h,float x1,float x2)
{
int bin1 = h->FindBin(x1);
int bin2 = h->FindBin(x2);
float integral = h->Integral(bin1,bin2-1,"width");
return integral;
}
float PelTools::integral(TH2D* h,float x1,float x2,float y1, float y2)
{
int bin1 = h->GetXaxis()->FindBin(x1);
int bin2 = h->GetXaxis()->FindBin(x2);
int bin3 = h->GetYaxis()->FindBin(y1);
int bin4 = h->GetYaxis()->FindBin(y2);
float integral = h->Integral(bin1,bin2-1,bin3,bin4-1,"width");
return integral;
}
void PelTools::integralDump(TH1D* h1, float xmin, float xmax, TLine *line)
{
if(!h1) return;
int i = 0, i1 = 0, i2 = 0;
double x1 = 0, y1 = 0;
double x2 = 0, y2 = 0;
double a = 0, b = 0;
double value = 0, x = 0;
double rms = 0;
double mean2 = 0;
double mean = 0;
float n = 0;
double ct = 0;
double it = 0;
i1 = h1->FindBin(xmin);
i2 = h1->FindBin(xmax)-1;
for(i = i1; i<i2; i++)
{
x = h1->GetBinCenter(i);
value = h1->GetBinContent(i);
mean2 += fabs(value)*x*x;
mean += fabs(value)*x;
n+=fabs(value);
}
if(n>0) { mean/=n; mean2/=n;}
rms = sqrt(mean2-mean*mean);
log(10,"Histogram name: %s",h1->GetName());
log(10," Values without background subtraction");
log(10," x limits = (%e, %e)",xmin,xmax);
log(10," Counts = %e",counts(h1,xmin,xmax));
log(10," Integral = %e (multiplied by bin size)",integral(h1,xmin,xmax));
log(10," RMS = %e FWHM = %e",rms,rms*2.354);
i1 = h1->FindBin(xmin);
i2 = h1->FindBin(xmax)-1;
x1 = h1->GetBinCenter(i1);
x2 = h1->GetBinCenter(i2);
y1 = h1->GetBinContent(i1);
y2 = h1->GetBinContent(i2);
if((x2-x1)!=0) a = (y2-y1)/(x2-x1);
b = y1 - a*xmin;
mBackLin->SetParameter(0,b);
mBackLin->SetParameter(1,a);
mBackLin->SetRange(x1,x2);
mean2 = 0;
mean = 0;
n = 0;
rms = 0;
ct = 0;
it = 0;
for(i = i1; i<i2; i++)
{
x = h1->GetBinCenter(i);
value = h1->GetBinContent(i)-mBackLin->Eval(x);
mean2 += fabs(value)*x*x;
mean += fabs(value)*x;
n+=fabs(value);
ct += value;
it += value*h1->GetBinWidth(i);
}
if(n>0) { mean/=n; mean2/=n;}
rms = sqrt(mean2-mean*mean);
log(10," Values with background subtraction (option 'S' from DAMN)");
log(10," x limits = (%e, %e)",xmin,xmax);
log(10," Counts = %e",ct);
log(10," Integral = %e (multiplied by bin size)",it);
log(10," RMS = %e FWHM = %e",rms,rms*2.354);
if(line)
{
x1 = line->GetX1();
x2 = line->GetX2();
y1 = line->GetY1();
y2 = line->GetY2();
i1 = h1->FindBin(x1);
i2 = h1->FindBin(x2);
a = 0;
if((x2-x1)!=0) a = (y2-y1)/(x2-x1);
b = y1 - a*x1;
mBackLin->SetParameter(0,b);
mBackLin->SetParameter(1,a);
mBackLin->SetRange(x1,x2);
mean2 = 0;
mean = 0;
n = 0;
rms = 0;
ct = 0;
it = 0;
for(i = i1; i<i2; i++)
{
x = h1->GetBinCenter(i);
value = h1->GetBinContent(i)-mBackLin->Eval(x);
mean2 += fabs(value)*x*x;
mean += fabs(value)*x;
n+=fabs(value);
ct += value;
it += value*h1->GetBinWidth(i);
}
if(n>0) { mean/=n; mean2/=n;}
rms = sqrt(mean2-mean*mean);
log(10," Values with background subtraction from TLine (option 'A' from DAMN)");
log(10," x limits = (%e, %e)",x1,x2);
log(10," Counts = %e",ct);
log(10," Integral = %e (multiplied by bin size)",it);
log(10," RMS = %e FWHM = %e",rms,rms*2.354);
}
}
void PelTools::integralDump(TH2D* h2, float xmin, float xmax, float ymin, float ymax)
{
if(!h2) return;
double rmsx = h2->GetRMS(1);
double rmsy = h2->GetRMS(2);
log(10,"Histogram name: %s",h2->GetName());
log(10," x = (%e, %e)",xmin,xmax);
log(10," y = (%e, %e)",ymin,ymax);
log(10," Counts = %e",counts(h2,xmin,xmax,ymin,ymax));
log(10," Integral = %e (multiplied by bin size)",integral(h2,xmin,xmax,ymin,ymax));
log(10," RMS X = %e FWHM X = %e",rmsx,rmsx*2.354);
log(10," RMS Y = %e FWHM Y = %e",rmsy,rmsy*2.354);
}
void PelTools::integralGUI()
{
int i,id,n;
float xmin,xmax,ymin,ymax;
TList *l = NULL;
TLine *LINE = NULL;
bool noHist = true;
char line[200];
if(!gPad) { message(1,"Warning","There is no TCanvas open"); return;}
TH1D *h1=NULL;
TH2D *h2=NULL;
xmin = gPad->GetUxmin();
xmax = gPad->GetUxmax();
ymin = gPad->GetUymin();
ymax = gPad->GetUymax();
l = makeList("TLine");
if(l)
{
LINE = (TLine*)l->At(l->LastIndex());
}
l = makeList("TH1");
if(l)
{
noHist = false;
n = l->GetSize();
for(i=0;i<n;i++)
{
h1 = (TH1D*) l->At(i);
if(h1)
{
log(10,"");
log(10,"Integral of 1D histogram");
log(10,"------------------------");
integralDump((TH1D*)h1,xmin,xmax,LINE);
}
}
}
l = makeList("TH2");
if(l)
{
noHist = false;
n = l->GetSize();
for(i=0;i<n;i++)
{
h2 = (TH2D*) l->At(i);
if(h2)
{
log(10,"");
log(10,"Integral of 2D histogram");
log(10,"------------------------");
integralDump((TH2D*)h2,xmin,xmax,ymin,ymax);
}
}
}
if(noHist) message(1,"Warning","There is no histogram in the current Canvas/pad");
return ;
}
void PelTools::integralCutGUI()
{
int i,id,n;
float xmin,xmax,ymin,ymax;
TList *l = NULL;
char line[200];
if(!gPad) { message(1,"Warning","There is no TCanvas open"); return;}
TH2D *h2=NULL;
TH2D *h3=NULL;
xmin = gPad->GetUxmin();
xmax = gPad->GetUxmax();
ymin = gPad->GetUymin();
ymax = gPad->GetUymax();
TCutG *cc = getCurrCut();
if(!cc) { message(1,"Warning","There is no cut available in the memory"); return;}
l = makeList("TH2");
if(l)
{
n = l->GetSize();
for(i=0;i<n;i++)
{
h2 = (TH2D*) l->At(i);
if(h2)
{
h3 = (TH2D*)extract(h2,cc);
log(10,"Integral of a 2D histogram inside the graphical cut");
log(10,"---------------------------------------------------");
integralDump(h3,xmin,xmax,ymin,ymax);
delete h3;
}
}
}
else message(1,"Warning","There is no 2D histogram in the current Canvas/pad");
return ;
}
void PelTools::exportAsciiGUI()
{
int i,n;
if(!yesno("Export .DAT","This function will export \nall histograms in the current PAD \nto an ASCII file \n\nWould you like to continue? ")) return;
if(!gPad) { message(1,"Warning","No active PAD"); return;}
TList *l = makeList("TH1");
if(!l) { message(1,"Warning","There is no 1D histograms in the current PAD"); return;}
n = l->GetSize();
float xmin = gPad->GetUxmin();
float xmax = gPad->GetUxmax();
for(i=0;i<n;i++)
{
TH1D *h = (TH1D*)l->At(i);
if(h)
{
TString name = h->GetName();
name+=".dat";
name.ReplaceAll(" ","_");
name.ReplaceAll("/","_");
name.ReplaceAll("{","_");
name.ReplaceAll("}","_");
name.ReplaceAll("(","_");
name.ReplaceAll(")","_");
name.ReplaceAll("<","_");
name.ReplaceAll(">","_");
name.ReplaceAll(";","_");
name.ReplaceAll("*","_");
name.ReplaceAll("&","_");
name.ReplaceAll("%","_");
name.ReplaceAll("@","_");
name.ReplaceAll("#","_");
exportAscii(h,(char*)name.Data(),xmin,xmax);
}
}
}
void PelTools::exportAscii(TH1D* h, char* file, float xmin, float xmax)
{
int j;
float x,y,e;
if(h)
{
int ibin_min = h->FindBin(xmin);
int ibin_max = h->FindBin(xmax);
ofstream out(file);
char line[100];
for(j=ibin_min; j<=ibin_max;j++)
{
x = h->GetBinCenter(j);
y = h->GetBinContent(j);
e = h->GetBinError(j);
sprintf(line,"%6.4e %6.4e %6.4e",x,y,e);
out << line<<endl;
}
out.close();
log(10,"%s is exported to file << %s >> ",h->GetName(),file);
log(10," limits in x = (%e, %e)",xmin,xmax);
}
}
void PelTools::importAsciiGUI()
{
TGFileInfo fi;
if(!yesno("Import .DAT","This function will import \nthe data in an ASCII file and will \ncreate an histogram. \n\nWould you like to continue? ")) return;
new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),kFDOpen,&fi);
if(fi.fFilename)
{
TDirectory *dir = (TDirectory*)gROOT->Get("Scan_Histograms");
if(!dir) dir = (TDirectory*)gROOT->Get("SPM_Histograms");
if(dir) dir->cd();
else gROOT->cd();
importAscii(fi.fFilename);
}
}
void PelTools::importDammGUI()
{
TGFileInfo fi;
if(!yesno("Import DAMM/HIS","This function will import \nthe data in an DAMM/HIS file and will \ncreate histograms. \n\nWould you like to continue? ")) return;
new TGFileDialog(gClient->GetRoot(),gClient->GetRoot(),kFDOpen,&fi);
if(fi.fFilename)
{
TDirectory *dir = (TDirectory*)gROOT->Get("Scan_Histograms");
if(!dir) dir = (TDirectory*)gROOT->Get("SPM_Histograms");
if(dir) dir->cd();
else gROOT->cd();
importDamm(fi.fFilename);
}
return;
}
TH1D* PelTools::importAscii(char* file)
{
int np = 0;
int i,j;
float x[4096],y[4096],e[4096];
char line[100];
TDirectory *dir = (TDirectory*)gROOT->Get("Scan_Histograms");
if(!dir) dir = (TDirectory*)gROOT->Get("SPM_Histograms");
if(dir) dir->cd();
else gROOT->cd();
TH1D* hist = NULL;
TString token=";, \t";
ifstream input(file);
log(10,"Importing file << %s >> ",file);
while(!input.eof())
{
input.getline(line,100);
TString L = line;
TObjArray *o = L.Tokenize(token);
int ni = 0;
int no = o->GetSize();
for(i=0;i<no;i++) if(!o->At(i)) {ni = i; break;}
if(ni>0)
{
if(ni<2) log(10," *** Line %d has less than 2 columns. Skipping...",np+1);
else
{
if(ni>3) log(10," *** Line %d has more than 3 columns. Will discard extra columns.",np+1);
TString item = ((TObjString*)o->At(0))->GetString();
x[np] = atof(item.Data());
item = ((TObjString*)o->At(1))->GetString();
y[np] = atof(item.Data());
if(ni>=3)
{
item = ((TObjString*)o->At(2))->GetString();
e[np] = atof(item.Data());
}
else e[np] = 0;
np++;
}
}
delete o;
}
log(10," *** read %d lines from file. Creating histogram...",np);
x[np] = x[np-1]+0.01;
hist = new TH1D(file,file,np,x);
for(i = 0;i<np;i++)
{
hist->SetBinContent(i+1,y[i]);
hist->SetBinError(i+1,e[i]);
}
return hist;
}
void PelTools::importDamm(char* file)
{
char bloco[128];
drrheader header;
drrdir dir;
size_t tmp;
TDirectory *DIR = (TDirectory*)gROOT->Get("Scan_Histograms");
if(!DIR) DIR = (TDirectory*)gROOT->Get("SPM_Histograms");
if(DIR) DIR->cd();
else gROOT->cd();
log(10,"Importing DAMM file << %s >> ",file);
mF = file;
mF.ToLower();
if(!mF.EndsWith(".his")) { message(1,"Warning","You must select a .his file"); return;}
mF = file;
mF.Remove(mF.Length()-4,4);
mFHIS = mF + ".his";
mFDRR = mF + ".drr";
FILE *fhis = fopen(mFHIS.Data(),"rb");
FILE *fdrr = fopen(mFDRR.Data(),"rb");
if(!fhis) { message(1,"Warning","Could not find .his file"); return;}
if(!fdrr) { message(1,"Warning","Could not find .drr file"); return;}
tmp = fread(bloco,128,1,fdrr);
memcpy(&header,bloco,128);
log(10,"Number of histograms in HIS = %d",header.nhis);
log(10,"Number of words in HIS = %d",2*(header.nhalfword));
for(int i = 0; i<header.nhis;i++)
{
tmp = fread(bloco,128,1,fdrr);
memcpy(&dir,bloco,128);
log(10,"Histogram number %d",i+1);
log(10," Dimension = %d",dir.histdim);
log(10," Size of bin = %d",dir.nhalfwordperchannel);
for(int j = 0; j<dir.histdim && j<4; j++)
{
log(10," Paramenter %d = %d",j+1,dir.histpar[j]);
log(10," Length RAW = %d",dir.lengthraw[j]);
log(10," Length Scaled = %d",dir.lengthscaled[j]);
}
log(10," Offset = %d",dir.offset);
if(dir.histdim==1)
{
int size = dir.lengthscaled[0];
int raw = dir.lengthraw[0];
int nbytes = 2*size*dir.nhalfwordperchannel;
log(10," Bytes read = %d",nbytes);
fseek(fhis,dir.offset*2,0);
TH1F *h = new TH1F(Form("HIST_%d_PX_%d",i,dir.histpar[0]),
Form("Histogram for PX = %d",dir.histpar[0]),
size,0,raw);
if(dir.nhalfwordperchannel==1)
{
unsigned short *data = new unsigned short[size];
tmp = fread((char*)data,nbytes,1,fhis);
for(int j = 0; j<size;j++) h->SetBinContent(j+1,data[j]);
delete [] data;
}
else
{
unsigned int *data = new unsigned int[size];
tmp = fread((char*)data,nbytes,1,fhis);
for(int j = 0; j<size;j++) h->SetBinContent(j+1,data[j]);
delete [] data;
}
}
else if(dir.histdim==2)
{
int sizeX = dir.lengthscaled[0];
int rawX = dir.lengthraw[0];
int sizeY = dir.lengthscaled[1];
int rawY = dir.lengthraw[1];
int nbytes = 2*(sizeX*sizeY)*dir.nhalfwordperchannel;
int nbytesX = 2*sizeX*dir.nhalfwordperchannel;
log(10," Bytes read = %d",nbytes);
fseek(fhis,dir.offset*2,0);
TH2F *h = new TH2F(Form("HIST_%d_PX_%d_PY_%d",i,dir.histpar[0],dir.histpar[1]),
Form("Histogram for PX = %d PY = %d",dir.histpar[0],dir.histpar[1]),
sizeX,0,rawX,
sizeY,0,rawY);
if(dir.nhalfwordperchannel==1)
{
unsigned short *data = new unsigned short[sizeX];
for(int binY = 1; binY <= sizeY; binY++)
{
tmp = fread((char*)data,nbytesX,1,fhis);
for(int j = 0; j<sizeX; j++) h->SetBinContent(j + 1, binY, data[j]);
}
delete [] data;
}
else
{
unsigned int *data = new unsigned int[sizeX];
for(int binY = 1; binY <= sizeY; binY++)
{
tmp = fread((char*)data,nbytesX,1,fhis);
for(int j = 0; j<sizeX; j++) h->SetBinContent(j + 1, binY, data[j]);
}
delete [] data;
}
}
else log(10,"This dimension is not supported by the conversion filter. Sorry!");
log(10," ");
}
log(10,"*** Finished DAMM conversion");
fclose(fhis);
fclose(fdrr);
return;
}
void PelTools::createCut()
{
mCut = NULL;
gROOT->SetEditorMode("CutG");
}
TGTextButton* PelTools::addButton(TGCompositeFrame* frame,
char* label, char* tip,
int x, int y, int w, int h,
int textColor, int backColor)
{
TGTextButton *button = new TGTextButton(frame,label);
button->SetTextJustify(36);
button->MoveResize(x,y,w,h);
button->SetToolTipText(tip);
frame->AddFrame(button, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
button->SetTextColor(textColor);
button->SetBackgroundColor(backColor);
return button;
}
void PelTools::dynamicalProjGUI(int mode)
{
int n;
TList *l = makeList("TH2");
if(l)
{
n = l->GetSize();
if(n>0)
{
TH2D* hh = (TH2D*)l->At(0);
if(hh)
{
new TDynamicSlice((TH2*)hh, (TPad*)gPad, mode);
} else { message(1,"Warning","There is no 2D histogram in the canvas"); return;}
} else { message(1,"Warning","There is no 2D histogram in the canvas"); return;}
} else { message(1,"Warning","There is no 2D histogram in the canvas"); return;}
return;
}
void PelTools::closeMenu()
{
isGUIActive = false;
if(fMainFrame1186)
{
fMainFrame1186->Cleanup();
delete fMainFrame1186;
fMainFrame1186 = 0;
}
}
void PelTools::menu()
{
if(isGUIActive) return;
isGUIActive = true;
fMainFrame1186 = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
fMainFrame1186->SetLayoutBroken(kTRUE);
TGCompositeFrame *fMainFrame656 = new TGCompositeFrame(fMainFrame1186,200,635,kVerticalFrame);
fMainFrame656->SetLayoutBroken(kTRUE);
TGCompositeFrame *fCompositeFrame657 = new TGCompositeFrame(fMainFrame656,203,637,kVerticalFrame);
fCompositeFrame657->SetLayoutBroken(kTRUE);
TGFont *ufont;
ufont = gClient->GetFont("-*-helvetica-bold-r-*-*-14-*-*-*-*-*-*-*");
TGGC *uGC;
GCValues_t valButton658;
valButton658.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
gClient->GetColorByName("#0000ff",valButton658.fForeground);
gClient->GetColorByName("#c0c0c0",valButton658.fBackground);
valButton658.fFillStyle = kFillSolid;
valButton658.fFont = ufont->GetFontHandle();
valButton658.fGraphicsExposures = kFALSE;
uGC = gClient->GetGC(&valButton658, kTRUE);
TGTextButton *fTextButton658 = new TGTextButton(fCompositeFrame657,"Browser",-1,uGC->GetGC(),ufont->GetFontStruct());
fTextButton658->SetTextJustify(36);
fTextButton658->Resize(88,40);
fTextButton658->SetToolTipText("Opens a new TBrowser");
fCompositeFrame657->AddFrame(fTextButton658, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
fTextButton658->MoveResize(8,8,88,40);
ufont = gClient->GetFont("-*-helvetica-bold-r-*-*-14-*-*-*-*-*-*-*");
GCValues_t valButton661;
valButton661.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
gClient->GetColorByName("#0000ff",valButton661.fForeground);
gClient->GetColorByName("#c0c0c0",valButton661.fBackground);
valButton661.fFillStyle = kFillSolid;
valButton661.fFont = ufont->GetFontHandle();
valButton661.fGraphicsExposures = kFALSE;
uGC = gClient->GetGC(&valButton661, kTRUE);
TGTextButton *fTextButton661 = new TGTextButton(fCompositeFrame657,"Canvas",-1,uGC->GetGC(),ufont->GetFontStruct());
fTextButton661->SetTextJustify(36);
fTextButton661->Resize(88,40);
fTextButton661->SetToolTipText("Opens a new TCanvas");
fCompositeFrame657->AddFrame(fTextButton661, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
fTextButton661->MoveResize(104,8,88,40);
TGShutter *fShutter666 = new TGShutter(fCompositeFrame657,kSunkenFrame);
TGShutterItem *fShutterItem667 = new TGShutterItem(fShutter666, new TGHotString("Import/export"),1000,kVerticalFrame);
TGCompositeFrame *fVerticalFrame679 = (TGCompositeFrame *)fShutterItem667->GetContainer();
fVerticalFrame679->SetLayoutBroken(kTRUE);
int i = 0;
int j = 0;
TGTextButton *fTextButton1001 = addButton(fVerticalFrame679,"Import ASCII","Import 1D data from an ASCII file into a TH1F histogram",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton1003 = addButton(fVerticalFrame679,"Export to ASCII","Export a TH1 histogram to ASCII file",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton1005 = addButton(fVerticalFrame679,"Import from DAMM/HIS file","Import histograms from DAMM/HIS files",10,5+i*30+10*j,164,25); i++;
fShutter666->AddItem(fShutterItem667);
TGShutterItem *fShutterItem692 = new TGShutterItem(fShutter666, new TGHotString("Graphical cuts"),1001,kVerticalFrame);
TGCompositeFrame *fVerticalFrame704 = (TGCompositeFrame *)fShutterItem692->GetContainer();
fVerticalFrame704->SetLayoutBroken(kTRUE);
i = 0;
j = 0;
TGTextButton *fTextButton2000 = addButton(fVerticalFrame704,"Create cut file","Create a cut file for writing",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton2001 = addButton(fVerticalFrame704,"Open cut file","Open a cut file for read/write",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton2002 = addButton(fVerticalFrame704,"Close cut file","Close cut file",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton2003 = addButton(fVerticalFrame704,"List cut file","List the contents of a cut file",10,5+i*30+10*j,164,25); i++;
j++;
TGTextButton *fTextButton2004 = addButton(fVerticalFrame704,"Create cut","Create a new cut and keep in the memory",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton2005 = addButton(fVerticalFrame704,"Save current cut","Save the current cut in a open file",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton2006 = addButton(fVerticalFrame704,"Load cut","Load a cut from file and set as current",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton2007 = addButton(fVerticalFrame704,"Print cut","Print the coordinates of the current cut",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton2008 = addButton(fVerticalFrame704,"Draw Cut","Draw the current cut in the current pad",10,5+i*30+10*j,164,25); i++;
fShutter666->AddItem(fShutterItem692);
TGShutterItem *fShutterItem711 = new TGShutterItem(fShutter666, new TGHotString("analysis tools"),1002,kVerticalFrame);
TGCompositeFrame *fVerticalFrame723 = (TGCompositeFrame *)fShutterItem711->GetContainer();
fVerticalFrame723->SetLayoutBroken(kTRUE);
i = 0;
j = 0;
TGTextButton *fTextButton3001 = addButton(fVerticalFrame723,"Draw TH2 (Cut)","Draw TH2 data within the cut (from current pad) ",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton3002 = addButton(fVerticalFrame723,"Draw PX (Cut)","Draw projection-X of TH2 data within the cut (from current pad) ",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton3003 = addButton(fVerticalFrame723,"Draw PY (Cut)","Draw projection-Y of TH2 data within the cut (from current pad) ",10,5+i*30+10*j,164,25); i++;
j++;
TGTextButton *fTextButton3004 = addButton(fVerticalFrame723,"Dynamical PX","Dynamical (mouse) projection-X",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton3005 = addButton(fVerticalFrame723,"Dynamical PY","Dynamical (mouse) projection-Y",10,5+i*30+10*j,164,25); i++;
j++;
TGTextButton *fTextButton3006 = addButton(fVerticalFrame723,"Integral","Integral of histograms (1 and 2D) from current pad",10,5+i*30+10*j,164,25); i++;
TGTextButton *fTextButton3007 = addButton(fVerticalFrame723,"Integral TH2 (Cut)","Integral of 2D histograms within cut (from current pad)",10,5+i*30+10*j,164,25); i++;
j++;
TGTextButton *fTextButton3008 = addButton(fVerticalFrame723,"Fit peaks","Fit 1D gaussian peaks (histograms within pad)",10,5+i*30+10*j,164,25); i++;
fShutter666->AddItem(fShutterItem711);
fShutter666->SetSelectedItem(fShutterItem711);
fShutter666->Resize(186,568);
fCompositeFrame657->AddFrame(fShutter666, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
fShutter666->MoveResize(8,56,186,568);
fMainFrame1186->SetWindowName("PelTools");
fMainFrame1186->SetIconName("PelTools");
fMainFrame656->AddFrame(fCompositeFrame657, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fCompositeFrame657->MoveResize(0,0,203,637);
fMainFrame1186->AddFrame(fMainFrame656, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
fMainFrame656->MoveResize(0,0,200,635);
fMainFrame1186->MapSubwindows();
fMainFrame1186->Resize(fMainFrame1186->GetDefaultSize());
fMainFrame1186->MapWindow();
fMainFrame1186->Resize(204,635);
fMainFrame1186->Connect("CloseWindow()","PelTools",this,"closeMenu()");
fTextButton658->Connect("Clicked()","PelTools",this,"browser()");
fTextButton661->Connect("Clicked()","PelTools",this,"canvas()");
fTextButton1001->Connect("Clicked()","PelTools",this,"importAsciiGUI()");
fTextButton1003->Connect("Clicked()","PelTools",this,"exportAsciiGUI()");
fTextButton1005->Connect("Clicked()","PelTools",this,"importDammGUI()");
fTextButton2000->Connect("Clicked()","PelTools",this,"createFileGUI()");
fTextButton2001->Connect("Clicked()","PelTools",this,"openFileGUI()");
fTextButton2002->Connect("Clicked()","PelTools",this,"closeFile()");
fTextButton2003->Connect("Clicked()","PelTools",this,"listFile()");
fTextButton2004->Connect("Clicked()","PelTools",this,"createCut()");
fTextButton2005->Connect("Clicked()","PelTools",this,"saveCutGUI()");
fTextButton2006->Connect("Clicked()","PelTools",this,"getCutGUI()");
fTextButton2007->Connect("Clicked()","PelTools",this,"printCurrCut()");
fTextButton2008->Connect("Clicked()","PelTools",this,"drawCurrCut()");
fTextButton3001->Connect("Clicked()","PelTools",this,"drawTH2Cut()");
fTextButton3002->Connect("Clicked()","PelTools",this,"drawProjectionCut(=0)");
fTextButton3003->Connect("Clicked()","PelTools",this,"drawProjectionCut(=1)");
fTextButton3004->Connect("Clicked()","PelTools",this,"dynamicalProjGUI(=0)");
fTextButton3005->Connect("Clicked()","PelTools",this,"dynamicalProjGUI(=1)");
fTextButton3006->Connect("Clicked()","PelTools",this,"integralGUI()");
fTextButton3007->Connect("Clicked()","PelTools",this,"integralCutGUI()");
fTextButton3008->Connect("Clicked()","PelTools",this,"fitGUI()");
return;
}