diff --git a/Software/Tools/.svn/entries b/Software/Tools/.svn/entries new file mode 100644 index 0000000..a345830 --- /dev/null +++ b/Software/Tools/.svn/entries @@ -0,0 +1,130 @@ +10 + +dir +60 +svn+ssh://svn.cern.ch/reps/uttestbeamsoft/Tools +svn+ssh://svn.cern.ch/reps/uttestbeamsoft + + + +2014-09-13T19:43:52.995165Z +52 +sblusk + + + + + + + + + + + + + + +4525493e-7705-40b1-a816-d608a930855b + +Style.C +file + + + + +2014-08-03T11:17:54.000000Z +0be0e0f8bcfd7e79cbd71d60812b1549 +2014-08-03T11:21:24.848936Z +26 +flionett + + + + + + + + + + + + + + + + + + + + + +16996 + +Par.C +file + + + + +2014-10-07T12:28:11.000000Z +1269628c0011a747b8f6a5e8ea5c0903 +2014-09-13T19:43:52.995165Z +52 +sblusk + + + + + + + + + + + + + + + + + + + + + +1138 + +Lib.C +file + + + + +2014-08-01T15:31:31.000000Z +1899e94f064639f31cec6eb12e72c8ad +2014-08-01T15:34:51.448282Z +4 +flionett + + + + + + + + + + + + + + + + + + + + + +1010 + diff --git a/Software/Tools/.svn/text-base/Lib.C.svn-base b/Software/Tools/.svn/text-base/Lib.C.svn-base new file mode 100644 index 0000000..cb09c0f --- /dev/null +++ b/Software/Tools/.svn/text-base/Lib.C.svn-base @@ -0,0 +1,54 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 06/27/2014 +//************************************************ + +/* +List of useful libraries. +*/ + +// Header guard. +#ifndef __LIB_C_INCLUDED__ +#define __LIB_C_INCLUDED__ + +#include "TAxis.h" +#include "TBenchmark.h" +#include "TCanvas.h" +#include "TFile.h" +#include "TF1.h" +#include "TGraph.h" +#include "TGraphErrors.h" +#include "TH1.h" +#include "TH2.h" +#include "TH3.h" +#include "TLegend.h" +#include "TLine.h" +#include "TLorentzVector.h" +#include "TMath.h" +#include "TMultiGraph.h" +#include "TNtuple.h" +#include "TPad.h" +#include "TPaveStats.h" +#include "TPaveText.h" +#include "TProfile.h" +#include "TRandom.h" +#include "TRandom3.h" +#include "TROOT.h" +#include "TString.h" +#include "TStyle.h" +#include "TSystem.h" +#include "TTree.h" +#include "TVirtualPad.h" + +#include +#include + +#include +#include +#include + +// #include "Alibava/AsciiRoot.h" + +using namespace std; + +#endif diff --git a/Software/Tools/.svn/text-base/Par.C.svn-base b/Software/Tools/.svn/text-base/Par.C.svn-base new file mode 100644 index 0000000..48a5f3d --- /dev/null +++ b/Software/Tools/.svn/text-base/Par.C.svn-base @@ -0,0 +1,42 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 07/21/2014 +//************************************************ + +/* +List of useful variables. +*/ + +// Header guard. +#ifndef __PAR_C_INCLUDED__ +#define __PAR_C_INCLUDED__ + +// Number of Beetle channels. +const int N = 256; + +// Only Beetle channels from 128 to 255 are wirebonded to the sensor. +const int firstChannel = 128; + +const double minH = 5.0; +const double maxH = 15.0; +const double maxDH = 2.0; +const double minSizeStep = 3; + + +const double minSeed = 20.0; // Min Threshold for Seed of Cluster +const double minSide = 8.0; // Min Threshold for Side strips in cluster +const int minSize = 1; // Min cluster size +const int minChannelInWindow = 50; // No. channels within 9 ADC counts to define pathological events +const int largePulseSize = 150; // Large pulse size for pathological events + +int nCluster = 0; +std::vector clusterSize; +std::vector clusterCharge; +std::vector clusterPosY; + +const int maxADC_Pass1 = 15; +const int maxADC_Pass2 = 15; + +const int debug = 3; + +#endif diff --git a/Software/Tools/.svn/text-base/Style.C.svn-base b/Software/Tools/.svn/text-base/Style.C.svn-base new file mode 100644 index 0000000..d2c4aa1 --- /dev/null +++ b/Software/Tools/.svn/text-base/Style.C.svn-base @@ -0,0 +1,524 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 06/27/2014 +//************************************************ + +/* +List of useful functions. +*/ + +// Header guard. +#ifndef __STYLE_C_INCLUDED__ +#define __STYLE_C_INCLUDED__ + +#include "Lib.C" + +//************************************************ +// +// Declarations. +// + +void dca(); + +void InitHist(TH1 *hist, TString title = "", TString x = "", TString y = ""); + +void InitHist2(TH2 *hist, TString title = "", TString x = "", TString y = "", TString z = ""); + +void DrawHist(TCanvas *canvas, TH1 *hist, TString option = "", TString folder = ""); + +void DrawHistCompare(TCanvas *canvas, TH1 *hist1, TH1 *hist2, TLegend *leg, TString folder = ""); + +void DrawHistCompare3(TCanvas *canvas, TH1 *hist1, TH1 *hist2, TH1 *hist3, TLegend *leg, TString folder = ""); + +void DrawHist2(TCanvas *canvas, TH2 *hist, TString option = "", TString folder = ""); + +void DrawHistStats(TCanvas *canvas, TH1 *hist, TPaveStats *stats, TString option = "", TString folder = ""); + +void DrawHistStats2(TCanvas *canvas, TH2 *hist, TPaveStats *stats, TString option = "", TString folder = ""); + +void InitGraph(TGraph *graph, TString title = "", TString x = "", TString y = ""); + +void DrawGraph(TCanvas *canvas, TGraph *graph, TString option = "APC", TString folder = ""); + +TLegend *CreateLegend2(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TString option = "lpfw", Double_t x1 = 0.64, Double_t y1 = 0.59, Double_t x2 = 0.94, Double_t y2 = 0.89); + +TLegend *CreateLegend3(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TObject *obj3, TString lab3, TString option = "lpfw", Double_t x1 = 0.64, Double_t y1 = 0.59, Double_t x2 = 0.94, Double_t y2 = 0.89); + +TLegend *CreateLegend4(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TObject *obj3, TString lab3, TObject *obj4, TString lab4, TString option = "lpfw", Double_t x1 = 0.64, Double_t y1 = 0.59, Double_t x2 = 0.94, Double_t y2 = 0.89); + +TPaveStats *CreateStats(TH1 *hist, TString option = ""); + +//************************************************ +// +// Definitions. +// + +// Thanks to Angelo Di Canto. +void dca() +{ + TStyle *dcastyle = new TStyle("dcastyle","The real perfect style"); + + // canvas + dcastyle->SetCanvasColor(0); + dcastyle->SetCanvasBorderSize(10); + dcastyle->SetCanvasBorderMode(0); + dcastyle->SetCanvasDefW(600); + dcastyle->SetCanvasDefH(600); + + // pads + dcastyle->SetPadColor(0); + dcastyle->SetPadBorderSize(10); + dcastyle->SetPadBorderMode(0); + dcastyle->SetPadLeftMargin(.18); + dcastyle->SetPadRightMargin(.05); + dcastyle->SetPadBottomMargin(.12); + dcastyle->SetPadTopMargin(.1); + //dcastyle->SetPadGridX(1); + //dcastyle->SetPadGridY(1); + dcastyle->SetPadTickX(0); + dcastyle->SetPadTickY(0); + + // frame + dcastyle->SetFrameBorderMode(0); + dcastyle->SetFrameBorderSize(10); + dcastyle->SetFrameFillStyle(0); + dcastyle->SetFrameFillColor(0); + dcastyle->SetFrameLineColor(1); + dcastyle->SetFrameLineStyle(0); + dcastyle->SetFrameLineWidth(1); + + // histogram + dcastyle->SetHistFillColor(0); + dcastyle->SetHistFillStyle(1001);// solid + dcastyle->SetHistLineColor(1); + dcastyle->SetHistLineStyle(0); + dcastyle->SetHistLineWidth(1.5); +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,16,0) + dcastyle->SetHistMinimumZero(); +#endif + dcastyle->SetOptStat(0); + dcastyle->SetOptFit(0); + dcastyle->SetStatColor(0); + dcastyle->SetStatBorderSize(1); + dcastyle->SetStatFontSize(.05); + + // graph + dcastyle->SetEndErrorSize(0); + dcastyle->SetErrorX(0.5); + + // marker + dcastyle->SetMarkerStyle(20); + dcastyle->SetMarkerColor(kBlack); + dcastyle->SetMarkerSize(0.6); + + // title + dcastyle->SetOptTitle(1); +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,16,0) + dcastyle->SetTitleAlign(33); + dcastyle->SetTitleX(.95); +#else + dcastyle->SetTitleX(.15); +#endif + dcastyle->SetTitleFillColor(0); + dcastyle->SetTitleBorderSize(0); + dcastyle->SetTitleStyle(0); + + // axes + dcastyle->SetNdivisions(505,"X"); + dcastyle->SetNdivisions(505,"Y"); + + dcastyle->SetTitleSize(.05,"X");//.055 + dcastyle->SetTitleOffset(1.,"X");//1.2,0.9 + dcastyle->SetLabelOffset(0.003,"X"); + dcastyle->SetLabelSize(.05,"X"); + dcastyle->SetLabelFont(42,"X"); + + dcastyle->SetTitleSize(.05,"Y");//.055 + dcastyle->SetTitleOffset(1.8,"Y"); + dcastyle->SetLabelOffset(0.008,"Y"); + dcastyle->SetLabelSize(.05,"Y"); + dcastyle->SetLabelFont(42,"Y"); + + dcastyle->SetStripDecimals(kFALSE); + + dcastyle->SetTitleSize(0.05,"Z"); + dcastyle->SetTitleOffset(1.800,"Z"); + dcastyle->SetLabelOffset(0.008,"Z"); + dcastyle->SetLabelSize(0.05,"Z"); + dcastyle->SetLabelFont(42,"Z"); + + // fonts + dcastyle->SetTextSize(.05);//.055 + dcastyle->SetTextFont(42); + dcastyle->SetStatFont(42); + dcastyle->SetTitleFont(42,""); + dcastyle->SetTitleFont(42,"Z"); + dcastyle->SetTitleFont(42,"X"); + dcastyle->SetTitleFont(42,"Y"); + + // function + dcastyle->SetFuncColor(kBlue); + dcastyle->SetFuncStyle(0); + dcastyle->SetFuncWidth(1); + + // legend +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,16,0) + dcastyle->SetLegendBorderSize(1); +#endif + + // palette + dcastyle->SetPalette(1); + dcastyle->SetNumberContours(20); + + // set dcastyle as current style + gROOT->SetStyle("dcastyle"); + + gSystem->ProcessEvents(); +} + +// InitHist defines some attributes of the "hist" histogram: the title "title" and the x-axis and y-axis labels "x" and "y". +void InitHist(TH1 *hist, TString title, TString x, TString y) { + hist->UseCurrentStyle(); + gStyle->SetTitleFontSize(0.1); + hist->SetTitle(title); + hist->GetXaxis()->SetTitle(x); + if (y == "") + hist->GetYaxis()->SetTitle(Form("Events / %g",hist->GetBinWidth(1))); + else + hist->GetYaxis()->SetTitle(y); + + return; +} + +// InitHist2 defines some attributes of the "hist" histogram: the title "title" and the x-axis, y-axis, and z-axis labels "x", "y", and "z". +void InitHist2(TH2 *hist, TString title, TString x, TString y, TString z) { + hist->UseCurrentStyle(); + gStyle->SetTitleFontSize(0.1); + hist->SetTitle(title); + hist->GetXaxis()->SetTitle(x); + hist->GetYaxis()->SetTitle(y); + if (z == "") + hist->GetZaxis()->SetTitle(Form("Events / (%g*%g)",hist->GetXaxis()->GetBinWidth(1),hist->GetYaxis()->GetBinWidth(1))); + else + hist->GetZaxis()->SetTitle(z); + + return; +} + +// DrawHist draws the "hist" histogram in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +void DrawHist(TCanvas *canvas, TH1 *hist, TString option, TString folder) { + TString path; + /* + if (folder == "") + path = "Figures/"; + else + path = folder + "/" + "Figures/"; + */ + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist->Draw(option); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHistCompare draws the "hist1" and "hist2" histograms in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +void DrawHistCompare(TCanvas *canvas, TH1 *hist1, TH1 *hist2, TLegend *leg, TString folder) { + TString path; + /* + if (folder == "") + path = "Figures/"; + else + path = folder + "/" + "Figures/"; + */ + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist1->SetMarkerColor(kMagenta); + hist2->SetMarkerColor(kOrange); + hist1->SetLineColor(kMagenta); + hist2->SetLineColor(kOrange); + if (hist1->GetMaximum() > hist2->GetMaximum()) { + hist1->Draw(""); + hist2->Draw("ESAME"); + } + else { + hist2->Draw("E"); + hist1->Draw("SAME"); + } + leg->Draw(); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHistCompare3 draws the "hist1", "hist2", and "hist3" histograms in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +void DrawHistCompare3(TCanvas *canvas, TH1 *hist1, TH1 *hist2, TH1 *hist3, TLegend *leg, TString folder) { + TString path; + /* + if (folder == "") + path = "Figures/"; + else + path = folder + "/" + "Figures/"; + */ + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist1->SetMarkerColor(kMagenta); + hist2->SetMarkerColor(kOrange); + hist3->SetMarkerColor(kRed); + hist1->SetLineColor(kMagenta); + hist2->SetLineColor(kOrange); + hist3->SetLineColor(kRed); + if (hist1->GetMaximum() > hist2->GetMaximum()) { + if (hist1->GetMaximum() > hist3->GetMaximum()) + { + hist1->Draw("E"); + hist2->Draw("SAME"); + hist3->Draw("SAME"); + } + else + { + hist3->Draw(""); + hist1->Draw("ESAME"); + hist2->Draw("SAME"); + } + } + else + { + if (hist2->GetMaximum() > hist3->GetMaximum()) + { + hist2->Draw(""); + hist1->Draw("ESAME"); + hist3->Draw("SAME"); + } + else + { + hist3->Draw(""); + hist1->Draw("ESAME"); + hist2->Draw("SAME"); + } + } + leg->Draw(); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHist2 draws the "hist" histogram in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file names "canvas.pdf". +void DrawHist2(TCanvas *canvas, TH2 *hist, TString option, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist->Draw(option); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHistStats draws the "hist" histogram and the "stats" stats in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file names "canvas.pdf". +void DrawHistStats(TCanvas *canvas, TH1 *hist, TPaveStats *stats, TString option, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist->Draw(option); + stats->Draw("SAME"); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHistStats2 draws the "hist" histogram and the "stats" stats in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file names "canvas.pdf". +void DrawHistStats2(TCanvas *canvas, TH2 *hist, TPaveStats *stats, TString option, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist->Draw(option); + stats->Draw("SAME"); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// InitGraph defines some attributes of the "graph" graph: the title "title" and the x-axis and y-axis labels "x" and "y". +void InitGraph(TGraph *graph, TString title, TString x, TString y) { + graph->UseCurrentStyle(); + gStyle->SetTitleFontSize(0.1); + graph->SetTitle(title); + graph->GetXaxis()->SetTitle(x); + graph->GetYaxis()->SetTitle(y); + + return; +} + +// DrawGraph draws the "graph" graph in the "canvas" canvas, by default with the "APC" option, adds the "leg" legend, and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +// "A" = with axes +// "P" = with points +// "C" = with smooth curves +void DrawGraph(TCanvas *canvas, TGraph *graph, TString option, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + canvas->SetTickx(1); + canvas->SetTicky(1); + graph->Draw(option); + graph->SetMarkerSize(1); + graph->SetMarkerStyle(20); + graph->SetMarkerColor(1); + graph->SetLineWidth(2); + graph->SetLineStyle(1); + graph->SetLineColor(2); + gPad->Modified(); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// CreateLegend2 creates and returns the legend for "obj1" (with "lab1" label) and "obj2" (with "lab2" label) objects. It allows to specify the drawing options ("lpfw" by default) and the posizion and size inside the canvas. +// l = lines +// p = points +// f = filled +// w = white +TLegend *CreateLegend2(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TString option, Double_t x1, Double_t y1, Double_t x2, Double_t y2) { + TLegend *leg = new TLegend(x1,y1,x2,y2); + leg->AddEntry(obj1,lab1,option.Data()); + leg->AddEntry(obj2,lab2,option.Data()); + leg->SetTextSize(.02); + if(option.Contains("w")) + leg->SetFillColor(kWhite); + + return leg; +} + +// CreateLegend3 creates and returns the legend for "obj1" (with "lab1" label), "obj2" (with "lab2" label), and "obj3" (with "lab3" label) objects. It allows to specify the drawing options ("lpfw" by default) and the posizion and size inside the canvas. +// l = lines +// p = points +// f = filled +// w = white +TLegend *CreateLegend3(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TObject *obj3, TString lab3, TString option, Double_t x1, Double_t y1, Double_t x2, Double_t y2) { + TLegend *leg = new TLegend(x1,y1,x2,y2); + leg->AddEntry(obj1,lab1,option.Data()); + leg->AddEntry(obj2,lab2,option.Data()); + leg->AddEntry(obj3,lab3,option.Data()); + leg->SetTextSize(.02); + if(option.Contains("w")) + leg->SetFillColor(kWhite); + + return leg; +} + +// CreateLegend4 creates and returns the legend for "obj1" (with "lab1" label), "obj2" (with "lab2" label), "obj3" (with "lab3" label), and "obj4" (with "lab4" label) objects. It allows to specify the drawing options ("lpfw" by default) and the posizion and size inside the canvas. +// l = lines +// p = points +// f = filled +// w = white +TLegend *CreateLegend4(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TObject *obj3, TString lab3, TObject *obj4, TString lab4, TString option, Double_t x1, Double_t y1, Double_t x2, Double_t y2) { + TLegend *leg = new TLegend(x1,y1,x2,y2); + leg->AddEntry(obj1,lab1,option.Data()); + leg->AddEntry(obj2,lab2,option.Data()); + leg->AddEntry(obj3,lab3,option.Data()); + leg->AddEntry(obj4,lab4,option.Data()); + leg->SetTextSize(.02); + if(option.Contains("w")) + leg->SetFillColor(kWhite); + + return leg; +} + +// CreateStats creates and returns the stats for "hist" histogram. It allows to specify the drawing options ("" by default). +// I = integral +// S = skewness +// K = kurtosis +// U = underflow +// O = overflow +TPaveStats *CreateStats(TH1 *hist, TString option) { + TPaveStats *stats = new TPaveStats(0.629396,0.657343,0.932953,0.879860,"brNDC"); + stats->SetName("stats"); + stats->SetBorderSize(1); + stats->SetFillColor(0); + stats->SetTextAlign(12); + TText *text = stats->AddText(Form("Entries = %g",hist->GetEntries())); + if(option.Contains("I")) + text = stats->AddText(Form("Integral = %g",hist->Integral())); + Int_t N = hist->GetDimension(); + if (N==1) { + text = stats->AddText(Form("Mean = %g",hist->GetMean())); + text = stats->AddText(Form("RMS = %g",hist->GetRMS())); + if(option.Contains("S")) + text = stats->AddText(Form("Skewness = %g",hist->GetSkewness())); + if(option.Contains("K")) + text = stats->AddText(Form("Kurtosis = %g",hist->GetKurtosis())); + if(option.Contains("U")) + text = stats->AddText(Form("Underflow = %f",hist->GetBinContent(0))); + if(option.Contains("O")) { + Int_t over = hist->GetNbinsX()+1; + text = stats->AddText(Form("Overflow = %f",hist->GetBinContent(over))); + } + } else { + text = stats->AddText(Form("Mean x = %g",hist->GetMean(1))); + text = stats->AddText(Form("Mean y = %g",hist->GetMean(2))); + text = stats->AddText(Form("RMS x = %g",hist->GetRMS(1))); + text = stats->AddText(Form("RMS y = %g",hist->GetRMS(2))); + if(option.Contains("S")) { + text = stats->AddText(Form("Skewness x = %g",hist->GetSkewness(1))); + text = stats->AddText(Form("Skewness y = %g",hist->GetSkewness(2))); + } + if(option.Contains("K")) { + text = stats->AddText(Form("Kurtosis x = %g",hist->GetKurtosis(1))); + text = stats->AddText(Form("Kurtosis y = %g",hist->GetKurtosis(2))); + } + if(option.Contains("U") || option.Contains("O")) { + Int_t nbinsX = hist->GetNbinsX(); + Int_t nbinsY = hist->GetNbinsY(); + Double_t bl = hist->GetBinContent(0,0); + Double_t bc = 0; for(int i=1; i<=nbinsX; i++) bc += hist->GetBinContent(i,0); + Double_t br = hist->GetBinContent(nbinsX+1,0); + Double_t cl = 0; for(int i=1; i<=nbinsY; i++) cl += hist->GetBinContent(0,i); + Double_t cc = hist->GetEffectiveEntries(); + Double_t cr = 0; for(int i=1; i<=nbinsX; i++) cr += hist->GetBinContent(nbinsX+1,i); + Double_t tl = hist->GetBinContent(0,nbinsY+1); + Double_t tc = 0; for(int i=1; i<=nbinsX; i++) tc += hist->GetBinContent(i,nbinsY+1); + Double_t tr = hist->GetBinContent(nbinsX+1,nbinsY+1); + text = stats->AddText(Form("%g| %g| %g",tl,tc,tr)); + text = stats->AddText(Form("%g| %g| %g",cl,cc,cr)); + text = stats->AddText(Form("%g| %g| %g",bl,bc,br)); + } + } + + return stats; +} + +#endif diff --git a/Software/Tools/Lib.C b/Software/Tools/Lib.C new file mode 100644 index 0000000..cb09c0f --- /dev/null +++ b/Software/Tools/Lib.C @@ -0,0 +1,54 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 06/27/2014 +//************************************************ + +/* +List of useful libraries. +*/ + +// Header guard. +#ifndef __LIB_C_INCLUDED__ +#define __LIB_C_INCLUDED__ + +#include "TAxis.h" +#include "TBenchmark.h" +#include "TCanvas.h" +#include "TFile.h" +#include "TF1.h" +#include "TGraph.h" +#include "TGraphErrors.h" +#include "TH1.h" +#include "TH2.h" +#include "TH3.h" +#include "TLegend.h" +#include "TLine.h" +#include "TLorentzVector.h" +#include "TMath.h" +#include "TMultiGraph.h" +#include "TNtuple.h" +#include "TPad.h" +#include "TPaveStats.h" +#include "TPaveText.h" +#include "TProfile.h" +#include "TRandom.h" +#include "TRandom3.h" +#include "TROOT.h" +#include "TString.h" +#include "TStyle.h" +#include "TSystem.h" +#include "TTree.h" +#include "TVirtualPad.h" + +#include +#include + +#include +#include +#include + +// #include "Alibava/AsciiRoot.h" + +using namespace std; + +#endif diff --git a/Software/Tools/Par.C b/Software/Tools/Par.C new file mode 100644 index 0000000..f8b0278 --- /dev/null +++ b/Software/Tools/Par.C @@ -0,0 +1,17 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 07/21/2014 +//************************************************ + +/* +List of useful variables. +*/ + +// Header guard. +#ifndef __PAR_C_INCLUDED__ +#define __PAR_C_INCLUDED__ + +// Number of Beetle channels. +const int N = 256; + +#endif diff --git a/Software/Tools/Style.C b/Software/Tools/Style.C new file mode 100644 index 0000000..d2c4aa1 --- /dev/null +++ b/Software/Tools/Style.C @@ -0,0 +1,524 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 06/27/2014 +//************************************************ + +/* +List of useful functions. +*/ + +// Header guard. +#ifndef __STYLE_C_INCLUDED__ +#define __STYLE_C_INCLUDED__ + +#include "Lib.C" + +//************************************************ +// +// Declarations. +// + +void dca(); + +void InitHist(TH1 *hist, TString title = "", TString x = "", TString y = ""); + +void InitHist2(TH2 *hist, TString title = "", TString x = "", TString y = "", TString z = ""); + +void DrawHist(TCanvas *canvas, TH1 *hist, TString option = "", TString folder = ""); + +void DrawHistCompare(TCanvas *canvas, TH1 *hist1, TH1 *hist2, TLegend *leg, TString folder = ""); + +void DrawHistCompare3(TCanvas *canvas, TH1 *hist1, TH1 *hist2, TH1 *hist3, TLegend *leg, TString folder = ""); + +void DrawHist2(TCanvas *canvas, TH2 *hist, TString option = "", TString folder = ""); + +void DrawHistStats(TCanvas *canvas, TH1 *hist, TPaveStats *stats, TString option = "", TString folder = ""); + +void DrawHistStats2(TCanvas *canvas, TH2 *hist, TPaveStats *stats, TString option = "", TString folder = ""); + +void InitGraph(TGraph *graph, TString title = "", TString x = "", TString y = ""); + +void DrawGraph(TCanvas *canvas, TGraph *graph, TString option = "APC", TString folder = ""); + +TLegend *CreateLegend2(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TString option = "lpfw", Double_t x1 = 0.64, Double_t y1 = 0.59, Double_t x2 = 0.94, Double_t y2 = 0.89); + +TLegend *CreateLegend3(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TObject *obj3, TString lab3, TString option = "lpfw", Double_t x1 = 0.64, Double_t y1 = 0.59, Double_t x2 = 0.94, Double_t y2 = 0.89); + +TLegend *CreateLegend4(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TObject *obj3, TString lab3, TObject *obj4, TString lab4, TString option = "lpfw", Double_t x1 = 0.64, Double_t y1 = 0.59, Double_t x2 = 0.94, Double_t y2 = 0.89); + +TPaveStats *CreateStats(TH1 *hist, TString option = ""); + +//************************************************ +// +// Definitions. +// + +// Thanks to Angelo Di Canto. +void dca() +{ + TStyle *dcastyle = new TStyle("dcastyle","The real perfect style"); + + // canvas + dcastyle->SetCanvasColor(0); + dcastyle->SetCanvasBorderSize(10); + dcastyle->SetCanvasBorderMode(0); + dcastyle->SetCanvasDefW(600); + dcastyle->SetCanvasDefH(600); + + // pads + dcastyle->SetPadColor(0); + dcastyle->SetPadBorderSize(10); + dcastyle->SetPadBorderMode(0); + dcastyle->SetPadLeftMargin(.18); + dcastyle->SetPadRightMargin(.05); + dcastyle->SetPadBottomMargin(.12); + dcastyle->SetPadTopMargin(.1); + //dcastyle->SetPadGridX(1); + //dcastyle->SetPadGridY(1); + dcastyle->SetPadTickX(0); + dcastyle->SetPadTickY(0); + + // frame + dcastyle->SetFrameBorderMode(0); + dcastyle->SetFrameBorderSize(10); + dcastyle->SetFrameFillStyle(0); + dcastyle->SetFrameFillColor(0); + dcastyle->SetFrameLineColor(1); + dcastyle->SetFrameLineStyle(0); + dcastyle->SetFrameLineWidth(1); + + // histogram + dcastyle->SetHistFillColor(0); + dcastyle->SetHistFillStyle(1001);// solid + dcastyle->SetHistLineColor(1); + dcastyle->SetHistLineStyle(0); + dcastyle->SetHistLineWidth(1.5); +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,16,0) + dcastyle->SetHistMinimumZero(); +#endif + dcastyle->SetOptStat(0); + dcastyle->SetOptFit(0); + dcastyle->SetStatColor(0); + dcastyle->SetStatBorderSize(1); + dcastyle->SetStatFontSize(.05); + + // graph + dcastyle->SetEndErrorSize(0); + dcastyle->SetErrorX(0.5); + + // marker + dcastyle->SetMarkerStyle(20); + dcastyle->SetMarkerColor(kBlack); + dcastyle->SetMarkerSize(0.6); + + // title + dcastyle->SetOptTitle(1); +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,16,0) + dcastyle->SetTitleAlign(33); + dcastyle->SetTitleX(.95); +#else + dcastyle->SetTitleX(.15); +#endif + dcastyle->SetTitleFillColor(0); + dcastyle->SetTitleBorderSize(0); + dcastyle->SetTitleStyle(0); + + // axes + dcastyle->SetNdivisions(505,"X"); + dcastyle->SetNdivisions(505,"Y"); + + dcastyle->SetTitleSize(.05,"X");//.055 + dcastyle->SetTitleOffset(1.,"X");//1.2,0.9 + dcastyle->SetLabelOffset(0.003,"X"); + dcastyle->SetLabelSize(.05,"X"); + dcastyle->SetLabelFont(42,"X"); + + dcastyle->SetTitleSize(.05,"Y");//.055 + dcastyle->SetTitleOffset(1.8,"Y"); + dcastyle->SetLabelOffset(0.008,"Y"); + dcastyle->SetLabelSize(.05,"Y"); + dcastyle->SetLabelFont(42,"Y"); + + dcastyle->SetStripDecimals(kFALSE); + + dcastyle->SetTitleSize(0.05,"Z"); + dcastyle->SetTitleOffset(1.800,"Z"); + dcastyle->SetLabelOffset(0.008,"Z"); + dcastyle->SetLabelSize(0.05,"Z"); + dcastyle->SetLabelFont(42,"Z"); + + // fonts + dcastyle->SetTextSize(.05);//.055 + dcastyle->SetTextFont(42); + dcastyle->SetStatFont(42); + dcastyle->SetTitleFont(42,""); + dcastyle->SetTitleFont(42,"Z"); + dcastyle->SetTitleFont(42,"X"); + dcastyle->SetTitleFont(42,"Y"); + + // function + dcastyle->SetFuncColor(kBlue); + dcastyle->SetFuncStyle(0); + dcastyle->SetFuncWidth(1); + + // legend +#if ROOT_VERSION_CODE >= ROOT_VERSION(5,16,0) + dcastyle->SetLegendBorderSize(1); +#endif + + // palette + dcastyle->SetPalette(1); + dcastyle->SetNumberContours(20); + + // set dcastyle as current style + gROOT->SetStyle("dcastyle"); + + gSystem->ProcessEvents(); +} + +// InitHist defines some attributes of the "hist" histogram: the title "title" and the x-axis and y-axis labels "x" and "y". +void InitHist(TH1 *hist, TString title, TString x, TString y) { + hist->UseCurrentStyle(); + gStyle->SetTitleFontSize(0.1); + hist->SetTitle(title); + hist->GetXaxis()->SetTitle(x); + if (y == "") + hist->GetYaxis()->SetTitle(Form("Events / %g",hist->GetBinWidth(1))); + else + hist->GetYaxis()->SetTitle(y); + + return; +} + +// InitHist2 defines some attributes of the "hist" histogram: the title "title" and the x-axis, y-axis, and z-axis labels "x", "y", and "z". +void InitHist2(TH2 *hist, TString title, TString x, TString y, TString z) { + hist->UseCurrentStyle(); + gStyle->SetTitleFontSize(0.1); + hist->SetTitle(title); + hist->GetXaxis()->SetTitle(x); + hist->GetYaxis()->SetTitle(y); + if (z == "") + hist->GetZaxis()->SetTitle(Form("Events / (%g*%g)",hist->GetXaxis()->GetBinWidth(1),hist->GetYaxis()->GetBinWidth(1))); + else + hist->GetZaxis()->SetTitle(z); + + return; +} + +// DrawHist draws the "hist" histogram in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +void DrawHist(TCanvas *canvas, TH1 *hist, TString option, TString folder) { + TString path; + /* + if (folder == "") + path = "Figures/"; + else + path = folder + "/" + "Figures/"; + */ + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist->Draw(option); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHistCompare draws the "hist1" and "hist2" histograms in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +void DrawHistCompare(TCanvas *canvas, TH1 *hist1, TH1 *hist2, TLegend *leg, TString folder) { + TString path; + /* + if (folder == "") + path = "Figures/"; + else + path = folder + "/" + "Figures/"; + */ + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist1->SetMarkerColor(kMagenta); + hist2->SetMarkerColor(kOrange); + hist1->SetLineColor(kMagenta); + hist2->SetLineColor(kOrange); + if (hist1->GetMaximum() > hist2->GetMaximum()) { + hist1->Draw(""); + hist2->Draw("ESAME"); + } + else { + hist2->Draw("E"); + hist1->Draw("SAME"); + } + leg->Draw(); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHistCompare3 draws the "hist1", "hist2", and "hist3" histograms in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +void DrawHistCompare3(TCanvas *canvas, TH1 *hist1, TH1 *hist2, TH1 *hist3, TLegend *leg, TString folder) { + TString path; + /* + if (folder == "") + path = "Figures/"; + else + path = folder + "/" + "Figures/"; + */ + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist1->SetMarkerColor(kMagenta); + hist2->SetMarkerColor(kOrange); + hist3->SetMarkerColor(kRed); + hist1->SetLineColor(kMagenta); + hist2->SetLineColor(kOrange); + hist3->SetLineColor(kRed); + if (hist1->GetMaximum() > hist2->GetMaximum()) { + if (hist1->GetMaximum() > hist3->GetMaximum()) + { + hist1->Draw("E"); + hist2->Draw("SAME"); + hist3->Draw("SAME"); + } + else + { + hist3->Draw(""); + hist1->Draw("ESAME"); + hist2->Draw("SAME"); + } + } + else + { + if (hist2->GetMaximum() > hist3->GetMaximum()) + { + hist2->Draw(""); + hist1->Draw("ESAME"); + hist3->Draw("SAME"); + } + else + { + hist3->Draw(""); + hist1->Draw("ESAME"); + hist2->Draw("SAME"); + } + } + leg->Draw(); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHist2 draws the "hist" histogram in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file names "canvas.pdf". +void DrawHist2(TCanvas *canvas, TH2 *hist, TString option, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist->Draw(option); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHistStats draws the "hist" histogram and the "stats" stats in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file names "canvas.pdf". +void DrawHistStats(TCanvas *canvas, TH1 *hist, TPaveStats *stats, TString option, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist->Draw(option); + stats->Draw("SAME"); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// DrawHistStats2 draws the "hist" histogram and the "stats" stats in the "canvas" canvas, by default with the "" option, and saves the result in the "folder" folder, in a pdf file names "canvas.pdf". +void DrawHistStats2(TCanvas *canvas, TH2 *hist, TPaveStats *stats, TString option, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + hist->Draw(option); + stats->Draw("SAME"); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// InitGraph defines some attributes of the "graph" graph: the title "title" and the x-axis and y-axis labels "x" and "y". +void InitGraph(TGraph *graph, TString title, TString x, TString y) { + graph->UseCurrentStyle(); + gStyle->SetTitleFontSize(0.1); + graph->SetTitle(title); + graph->GetXaxis()->SetTitle(x); + graph->GetYaxis()->SetTitle(y); + + return; +} + +// DrawGraph draws the "graph" graph in the "canvas" canvas, by default with the "APC" option, adds the "leg" legend, and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +// "A" = with axes +// "P" = with points +// "C" = with smooth curves +void DrawGraph(TCanvas *canvas, TGraph *graph, TString option, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + canvas->SetTickx(1); + canvas->SetTicky(1); + graph->Draw(option); + graph->SetMarkerSize(1); + graph->SetMarkerStyle(20); + graph->SetMarkerColor(1); + graph->SetLineWidth(2); + graph->SetLineStyle(1); + graph->SetLineColor(2); + gPad->Modified(); + canvas->Update(); + canvas->Write(); + name = path + "/" + name + ".pdf"; + canvas->SaveAs(name); + canvas->Close(); + + return; +} + +// CreateLegend2 creates and returns the legend for "obj1" (with "lab1" label) and "obj2" (with "lab2" label) objects. It allows to specify the drawing options ("lpfw" by default) and the posizion and size inside the canvas. +// l = lines +// p = points +// f = filled +// w = white +TLegend *CreateLegend2(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TString option, Double_t x1, Double_t y1, Double_t x2, Double_t y2) { + TLegend *leg = new TLegend(x1,y1,x2,y2); + leg->AddEntry(obj1,lab1,option.Data()); + leg->AddEntry(obj2,lab2,option.Data()); + leg->SetTextSize(.02); + if(option.Contains("w")) + leg->SetFillColor(kWhite); + + return leg; +} + +// CreateLegend3 creates and returns the legend for "obj1" (with "lab1" label), "obj2" (with "lab2" label), and "obj3" (with "lab3" label) objects. It allows to specify the drawing options ("lpfw" by default) and the posizion and size inside the canvas. +// l = lines +// p = points +// f = filled +// w = white +TLegend *CreateLegend3(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TObject *obj3, TString lab3, TString option, Double_t x1, Double_t y1, Double_t x2, Double_t y2) { + TLegend *leg = new TLegend(x1,y1,x2,y2); + leg->AddEntry(obj1,lab1,option.Data()); + leg->AddEntry(obj2,lab2,option.Data()); + leg->AddEntry(obj3,lab3,option.Data()); + leg->SetTextSize(.02); + if(option.Contains("w")) + leg->SetFillColor(kWhite); + + return leg; +} + +// CreateLegend4 creates and returns the legend for "obj1" (with "lab1" label), "obj2" (with "lab2" label), "obj3" (with "lab3" label), and "obj4" (with "lab4" label) objects. It allows to specify the drawing options ("lpfw" by default) and the posizion and size inside the canvas. +// l = lines +// p = points +// f = filled +// w = white +TLegend *CreateLegend4(TObject *obj1, TString lab1, TObject *obj2, TString lab2, TObject *obj3, TString lab3, TObject *obj4, TString lab4, TString option, Double_t x1, Double_t y1, Double_t x2, Double_t y2) { + TLegend *leg = new TLegend(x1,y1,x2,y2); + leg->AddEntry(obj1,lab1,option.Data()); + leg->AddEntry(obj2,lab2,option.Data()); + leg->AddEntry(obj3,lab3,option.Data()); + leg->AddEntry(obj4,lab4,option.Data()); + leg->SetTextSize(.02); + if(option.Contains("w")) + leg->SetFillColor(kWhite); + + return leg; +} + +// CreateStats creates and returns the stats for "hist" histogram. It allows to specify the drawing options ("" by default). +// I = integral +// S = skewness +// K = kurtosis +// U = underflow +// O = overflow +TPaveStats *CreateStats(TH1 *hist, TString option) { + TPaveStats *stats = new TPaveStats(0.629396,0.657343,0.932953,0.879860,"brNDC"); + stats->SetName("stats"); + stats->SetBorderSize(1); + stats->SetFillColor(0); + stats->SetTextAlign(12); + TText *text = stats->AddText(Form("Entries = %g",hist->GetEntries())); + if(option.Contains("I")) + text = stats->AddText(Form("Integral = %g",hist->Integral())); + Int_t N = hist->GetDimension(); + if (N==1) { + text = stats->AddText(Form("Mean = %g",hist->GetMean())); + text = stats->AddText(Form("RMS = %g",hist->GetRMS())); + if(option.Contains("S")) + text = stats->AddText(Form("Skewness = %g",hist->GetSkewness())); + if(option.Contains("K")) + text = stats->AddText(Form("Kurtosis = %g",hist->GetKurtosis())); + if(option.Contains("U")) + text = stats->AddText(Form("Underflow = %f",hist->GetBinContent(0))); + if(option.Contains("O")) { + Int_t over = hist->GetNbinsX()+1; + text = stats->AddText(Form("Overflow = %f",hist->GetBinContent(over))); + } + } else { + text = stats->AddText(Form("Mean x = %g",hist->GetMean(1))); + text = stats->AddText(Form("Mean y = %g",hist->GetMean(2))); + text = stats->AddText(Form("RMS x = %g",hist->GetRMS(1))); + text = stats->AddText(Form("RMS y = %g",hist->GetRMS(2))); + if(option.Contains("S")) { + text = stats->AddText(Form("Skewness x = %g",hist->GetSkewness(1))); + text = stats->AddText(Form("Skewness y = %g",hist->GetSkewness(2))); + } + if(option.Contains("K")) { + text = stats->AddText(Form("Kurtosis x = %g",hist->GetKurtosis(1))); + text = stats->AddText(Form("Kurtosis y = %g",hist->GetKurtosis(2))); + } + if(option.Contains("U") || option.Contains("O")) { + Int_t nbinsX = hist->GetNbinsX(); + Int_t nbinsY = hist->GetNbinsY(); + Double_t bl = hist->GetBinContent(0,0); + Double_t bc = 0; for(int i=1; i<=nbinsX; i++) bc += hist->GetBinContent(i,0); + Double_t br = hist->GetBinContent(nbinsX+1,0); + Double_t cl = 0; for(int i=1; i<=nbinsY; i++) cl += hist->GetBinContent(0,i); + Double_t cc = hist->GetEffectiveEntries(); + Double_t cr = 0; for(int i=1; i<=nbinsX; i++) cr += hist->GetBinContent(nbinsX+1,i); + Double_t tl = hist->GetBinContent(0,nbinsY+1); + Double_t tc = 0; for(int i=1; i<=nbinsX; i++) tc += hist->GetBinContent(i,nbinsY+1); + Double_t tr = hist->GetBinContent(nbinsX+1,nbinsY+1); + text = stats->AddText(Form("%g| %g| %g",tl,tc,tr)); + text = stats->AddText(Form("%g| %g| %g",cl,cc,cr)); + text = stats->AddText(Form("%g| %g| %g",bl,bc,br)); + } + } + + return stats; +} + +#endif