#include "PelTools.h"

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;


}
PelTools::~PelTools()
{
  if(fMainFrame1186) delete fMainFrame1186;
	if(mBackLin) delete mBackLin;
}
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();
				//cout <<"Found object "<<o<<"  clasname = "<<o->ClassName()<<endl;
        if(n.BeginsWith(name)) mList->AddLast(o);
      }
    }
  }
  n = mList->GetSize();
  if(n==0) { delete mList; mList = NULL;}
  return mList;
}  

void PelTools::del(char* name)
{
  if(gROOT->FindObjectAny(name)) delete gROOT->FindObjectAny(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();
}
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();
  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 = h->GetName();
  name+="_Cut";
  del((char*)name.Data());
  TString title = h->GetTitle();
  title+=" (Cut)";
  TH2D *hnew = new TH2D(name.Data(),title.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());
  gROOT->GetList()->RecursiveRemove(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";
          del((char*)n.Data());
          if(m==0) mP = mHC->ProjectionX();
          else mP = mHC->ProjectionY();
          mP->SetName(n.Data());
          mP->Draw();
          //gROOT->GetList()->RecursiveRemove(mP);
        }
      }
    }
  } else { message(1,"Warning","There is no 2D histogram in the canvas"); return;}
  return;
  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(); mCut = 0;}
      }
    }
  } else { message(1,"Warning","There is no 2D histogram in the canvas"); return;}
  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();
    //l->ls();
    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;

	////////////////////////////////////////////////////
	// calculating integral with NO background	

	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);

	////////////////////////////////////////////////////
	// calculating background as option S in DAMN	
	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);

	////////////////////////////////////////////////////

	////////////////////////////////////////////////////
	// calculating background as option A in DAMN, 
	// defined in a TLine object
	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);
  }
}
TH1D* PelTools::importAscii(char* file)
{
  int np = 0;
  int i,j;
  float x[4096],y[4096],e[4096];
  char line[100];
  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::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;

   // main frame
   fMainFrame1186 = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
   fMainFrame1186->SetLayoutBroken(kTRUE);

   // composite frame
   TGCompositeFrame *fMainFrame656 = new TGCompositeFrame(fMainFrame1186,200,635,kVerticalFrame);
   fMainFrame656->SetLayoutBroken(kTRUE);

   // composite frame
   TGCompositeFrame *fCompositeFrame657 = new TGCompositeFrame(fMainFrame656,203,637,kVerticalFrame);
   fCompositeFrame657->SetLayoutBroken(kTRUE);

   TGFont *ufont;         // will reflect user font changes
   ufont = gClient->GetFont("-*-helvetica-bold-r-*-*-14-*-*-*-*-*-*-*");

   TGGC   *uGC;           // will reflect user GC changes
   // graphics context changes
   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-*-*-*-*-*-*-*");

   // graphics context changes
   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);

   ///////////////////////////////////////////////////////////////////////////////////////
   // shutter
   ///////////////////////////////////////////////////////////////////////////////////////
   TGShutter *fShutter666 = new TGShutter(fCompositeFrame657,kSunkenFrame);

   ///////////////////////////////////////////////////////////////////////////////////////
   // "Import/export" shutter item 
   ///////////////////////////////////////////////////////////////////////////////////////
   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 *fTextButton1002 = addButton(fVerticalFrame679,"Import from SPK","Import single or multiple 1D histograms from a SPK file",10,5+i*30+10*j,164,25); i++;
   //j++;
	 TGTextButton *fTextButton1003 = addButton(fVerticalFrame679,"Export to ASCII","Export a TH1 histogram to ASCII file",10,5+i*30+10*j,164,25); i++;
   //TGTextButton *fTextButton1004 = addButton(fVerticalFrame679,"Export to SPK","Export single or multiple TH1 histograms to SPK file",10,5+i*30+10*j,164,25); i++;

	 fShutter666->AddItem(fShutterItem667);

   ///////////////////////////////////////////////////////////////////////////////////////
   // "Graphical cuts" shutter item 
   ///////////////////////////////////////////////////////////////////////////////////////
   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);

   ///////////////////////////////////////////////////////////////////////////////////////
   // "analysis tools" shutter item 
   ///////////////////////////////////////////////////////////////////////////////////////
   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);


   ///////////////////////////////////////////////////////////////////////////////////////
   // final 
   ///////////////////////////////////////////////////////////////////////////////////////
   fShutter666->SetSelectedItem(fShutterItem711);
   fShutter666->Resize(186,568);
   fCompositeFrame657->AddFrame(fShutter666, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2));
   fShutter666->MoveResize(8,56,186,568);

   ///////////////////////////////////////////////////////////////////////////////////////
   // final 
   ///////////////////////////////////////////////////////////////////////////////////////
	 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);

	 ////////////////////////////////////////
	 // connecting buttons to commands.

	 fMainFrame1186->Connect("CloseWindow()","PelTools",this,"closeMenu()"); // quit scanroot

	 fTextButton658->Connect("Clicked()","PelTools",this,"browser()"); // new TBrowser
	 fTextButton661->Connect("Clicked()","PelTools",this,"canvas()"); // new TCanvas

   // "Import/export" shutter item 

   fTextButton1001->Connect("Clicked()","PelTools",this,"importAsciiGUI()"); // Import ASCII
   //fTextButton1002->Connect("Clicked()","PelTools",this,"zeroGUI()"); // Import SPK
   fTextButton1003->Connect("Clicked()","PelTools",this,"exportAsciiGUI()"); // Export ASCII
   //fTextButton1004->Connect("Clicked()","PelTools",this,"zeroGUI()"); // Export SPK

   // "Graphical cuts" shutter item 

	 fTextButton2000->Connect("Clicked()","PelTools",this,"createFileGUI()"); // Create Cut file
	 fTextButton2001->Connect("Clicked()","PelTools",this,"openFileGUI()"); // Open Cut file
	 fTextButton2002->Connect("Clicked()","PelTools",this,"closeFile()"); // Close Cut file
	 fTextButton2003->Connect("Clicked()","PelTools",this,"listFile()"); // List Cut file
	 fTextButton2004->Connect("Clicked()","PelTools",this,"createCut()"); // Create cut
	 fTextButton2005->Connect("Clicked()","PelTools",this,"saveCutGUI()"); // Save Cut
	 fTextButton2006->Connect("Clicked()","PelTools",this,"getCutGUI()"); // load cut
	 fTextButton2007->Connect("Clicked()","PelTools",this,"printCurrCut()"); // print cut
	 fTextButton2008->Connect("Clicked()","PelTools",this,"drawCurrCut()"); // draw cut

   // "analysis tools" shutter item 

	 fTextButton3001->Connect("Clicked()","PelTools",this,"drawTH2Cut()"); // Draw TH2(Cut)
	 fTextButton3002->Connect("Clicked()","PelTools",this,"drawProjectionCut(=0)"); // Draw PX(Cut)
	 fTextButton3003->Connect("Clicked()","PelTools",this,"drawProjectionCut(=1)"); // Draw PY(Cut)
	 fTextButton3004->Connect("Clicked()","PelTools",this,"dynamicalProjGUI(=0)"); // Dynamical PX
	 fTextButton3005->Connect("Clicked()","PelTools",this,"dynamicalProjGUI(=1)"); // Dynamical PY
	 fTextButton3006->Connect("Clicked()","PelTools",this,"integralGUI()"); // Integral
	 fTextButton3007->Connect("Clicked()","PelTools",this,"integralCutGUI()"); // Integral TH2(Cut)
	 fTextButton3008->Connect("Clicked()","PelTools",this,"fitGUI()"); // Fit peaks

	return;
}


ROOT page - Class index - Class Hierarchy - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.