diff --git a/Software/IVScan/IVScan b/Software/IVScan/IVScan new file mode 100755 index 0000000..8c511c8 --- /dev/null +++ b/Software/IVScan/IVScan Binary files differ diff --git a/Software/IVScan/IVScan.C b/Software/IVScan/IVScan.C new file mode 100644 index 0000000..c951be3 --- /dev/null +++ b/Software/IVScan/IVScan.C @@ -0,0 +1,309 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 20/11/2014 +//************************************************ + +/* +IVScan reads two text files (containing the bias voltage and the current values) and creates a ROOT file with the following information: +- current as a function of the bias voltage. + +Compile with: + +make + +Run with: + +./IVScan [input text file 1] [input text file 2] [additional folder] + +where + +- [input text file 1] is the complete path, including the folder and the filename, of the text file one wants to process (increasing bias voltage); +- [input text file 2] is the complete path, including the folder and the filename, of the text file one wants to process (decreasing bias voltage); +- [additional folder] is the optional additional folder where the output will be saved. + +A folder named AnalysisResults will be created in a fixed location and a ROOT file will be saved in there. A folder named Figures will be created inside the folder named AnalysisResults, with some monitoring plots. + +If needed, an additional folder can be specified, that will be created inside the folder named AnalysisResults. +*/ + +#include "../Tools/Lib.C" +#include "../Tools/lhcbStyle.C" +#include "../Tools/Style.C" +#include "../Tools/Useful.C" + +#include "../Tools/Par.C" + +void IVScan(char *filename1, char *filename2, char *externalPath=0); + +int main(int argc, char *argv[]) +{ + getLHCbStyle(); + PersonalStyle(); + + if ((argc ==2) && (string(argv[1]) == "--info")) + { + cout << "**************************************************" << endl; + + cout << "Some comments." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else if (argc < 3) + { + cout << "**************************************************" << endl; + + cout << "Error! Input files missing..." << endl; + cout << "Please use the following format:" << endl; + cout << "./IVScan [1] [2] [3]" << endl; + cout << "with:" << endl; + cout << "[1] = Input text file 1, complete path (increasing bias voltage);" << endl; + cout << "[2] = Input text file 2, complete path (decreasing bias voltage);" << endl; + cout << "[3] = Additional folder, optional." << endl; + cout << "Type ./IVScan --info for more information." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else + { + cout << "File 1 to process: " << argv[1] << endl; + cout << "File 2 to process: " << argv[2] << endl; + if (argc == 3) + IVScan(argv[1],argv[2]); + else if (argc == 4) + IVScan(argv[1],argv[2],argv[3]); + else + { + cout << "Error! Too many arguments given..." << endl; + + return 0; + } + + return 0; + } +} + +void IVScan(char *filename1, char *filename2, char *externalPath) +{ + cout << "**************************************************" << endl; + cout << "Working on the IV scan..." << endl; + cout << "**************************************************" << endl; + + // Do not comment this line. + gROOT->ProcessLine("#include "); + + int found; + + string filename1_as_string = string(filename1); + // Check that the filename provided corresponds to a text file. + found = filename1_as_string.find(".dat"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a text file." << endl; + return; + } + + string filename2_as_string = string(filename2); + // Check that the filename provided corresponds to a text file. + found = filename2_as_string.find(".dat"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a text file." << endl; + return; + } + + // Open input text file. + ifstream datFile; + std::string line; + + // Number of rows to be read from the text files. + int rows1; + int rows2; + + // Open file 1. + // Determine number of rows to be read from the text file. + datFile.open(filename1_as_string.c_str()); + if (datFile.is_open()) { + rows1 = 0; + while (getline(datFile,line)) + rows1++; + cout << "Number of rows in the input text file 1: " << rows1 << endl; + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + // Open file 2. + // Determine number of rows to be read from the text file. + datFile.open(filename2_as_string.c_str()); + if (datFile.is_open()) { + rows2 = 0; + while (getline(datFile,line)) + rows2++; + cout << "Number of rows in the input text file 2: " << rows2 << endl; + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + // Read the text file. + // Remember that the first row must be skipped. + float V; + float I; + float IErr; + + Int_t i; + + // Read text file 1. + vector vV1; + vector vI1; + vector vVErr1; + vector vIErr1; + + // Save information. + datFile.open(filename1_as_string.c_str()); + if (datFile.is_open()) { + i = 0; + while (getline(datFile,line)) { + if (i>0) { + // cout << line << endl; + istringstream iss(line); + iss >> V >> I >> IErr; + vV1.push_back(V); + vI1.push_back(I); + vVErr1.push_back(0.); + vIErr1.push_back(IErr); + } + i++; + } + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + float *aV1 = &vV1[0]; + float *aI1 = &vI1[0]; + float *aVErr1 = &vVErr1[0]; + float *aIErr1 = &vIErr1[0]; + + /* + cout << aV1[0] << endl; + cout << aV1[1] << endl; + cout << aI1[0] << endl; + cout << aI1[1] << endl; + cout << aVErr1[0] << endl; + cout << aVErr1[1] << endl; + cout << aIErr1[0] << endl; + cout << aIErr1[1] << endl; + */ + + // Read text file 2. + vector vV2; + vector vI2; + vector vVErr2; + vector vIErr2; + + // Save information. + datFile.open(filename2_as_string.c_str()); + if (datFile.is_open()) { + i = 0; + while (getline(datFile,line)) { + if (i>0) { + // cout << line << endl; + istringstream iss(line); + iss >> V >> I >> IErr; + vV2.push_back(V); + vI2.push_back(I); + vVErr2.push_back(0.); + vIErr2.push_back(IErr); + } + i++; + } + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + float *aV2 = &vV2[0]; + float *aI2 = &vI2[0]; + float *aVErr2 = &vVErr2[0]; + float *aIErr2 = &vIErr2[0]; + + /* + cout << aV2[0] << endl; + cout << aV2[1] << endl; + cout << aI2[0] << endl; + cout << aI2[1] << endl; + cout << aVErr2[0] << endl; + cout << aVErr2[1] << endl; + cout << aIErr2[0] << endl; + cout << aIErr2[1] << endl; + */ + + // Do some fanciness to get the directory right. + string analysis = "/home/hep/flionett/TestStand/AnalysisResults"; + if (externalPath!=0) + analysis = string(analysis+"/"+externalPath); + + string filename_as_string_no_path = filename1_as_string.substr(filename1_as_string.find_last_of('/')+1); + string filename_as_string_no_path_no_extension = filename_as_string_no_path.substr(0,filename_as_string_no_path.length()-18); + + // Create a folder named AnalysisResults. Do not worry, nothing bad is going to happen if the folder already exists. + string path_to_make = "mkdir -p "+analysis; + system(path_to_make.c_str()); + cout << "Setting output to: " << path_to_make << endl; + + // Create a folder named Figures inside the folder named AnalysisResults. + string path_to_make_figures = "mkdir "+analysis+"/Figures"; + system(path_to_make_figures.c_str()); + path_to_make_figures = "mkdir "+analysis+"/Figures"+"/IVScan"; + system(path_to_make_figures.c_str()); + path_to_make_figures = "mkdir "+analysis+"/Figures"+"/IVScan"+"/"+filename_as_string_no_path_no_extension; + system(path_to_make_figures.c_str()); + cout << "Setting figures to: " << path_to_make_figures << endl; + + TString path_to_figures = (string(path_to_make_figures)).substr((string(path_to_make_figures)).find_last_of(' ')+1); + + // Open output ROOT file. + TFile *output = TFile::Open(analysis+"/IVScan-"+TString(filename_as_string_no_path_no_extension)+".root","RECREATE"); + + TCanvas *cIVScan = new TCanvas("cIVScan","",400,300); + + int rowsData1 = rows1-1; + int rowsData2 = rows2-1; + + TMultiGraph *mgIVScan = new TMultiGraph(); + + TGraphErrors *gIVScan1 = new TGraphErrors(rowsData1,aV1,aI1,aVErr1,aIErr1); + TGraphErrors *gIVScan2 = new TGraphErrors(rowsData2,aV2,aI2,aVErr2,aIErr2); + + InitGraphErrors(gIVScan1,"IV scan","Bias voltage (V)","Current (#muA)"); + InitGraphErrors(gIVScan2,"IV scan","Bias voltage (V)","Current (#muA)"); + + gIVScan1->SetMarkerColor(kMagenta); + gIVScan2->SetMarkerColor(kOrange); + + TLegend *legIVScan = CreateLegend2(gIVScan1,"increasing V",gIVScan2,"decreasing V","epw",0.2,0.6,0.5,0.9); + + mgIVScan->Add(gIVScan1); + mgIVScan->Add(gIVScan2); + + DrawGraphCompare(cIVScan,mgIVScan,legIVScan,"IV scan","Bias voltage (V)","Current (#muA)",path_to_figures); + + output->Close(); + + return; +} diff --git a/Software/IVScan/IVScan.C~ b/Software/IVScan/IVScan.C~ new file mode 100644 index 0000000..cbe4171 --- /dev/null +++ b/Software/IVScan/IVScan.C~ @@ -0,0 +1,305 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 20/11/2014 +//************************************************ + +/* +IVScan reads two text files (containing the bias voltage and the current values) and creates a ROOT file with the following information: +- current as a function of the bias voltage. + +Compile with: + +make + +Run with: + +./IVScan [input text file 1] [input text file 2] [additional folder] + +where + +- [input text file 1] is the complete path, including the folder and the filename, of the text file one wants to process (increasing bias voltage); +- [input text file 2] is the complete path, including the folder and the filename, of the text file one wants to process (decreasing bias voltage); +- [additional folder] is the optional additional folder where the output will be saved. + +A folder named AnalysisResults will be created in a fixed location and a ROOT file will be saved in there. A folder named Figures will be created inside the folder named AnalysisResults, with some monitoring plots. + +If needed, an additional folder can be specified, that will be created inside the folder named AnalysisResults. +*/ + +#include "../Tools/Lib.C" +#include "../Tools/lhcbStyle.C" +#include "../Tools/Style.C" +#include "../Tools/Useful.C" + +#include "../Tools/Par.C" + +void IVScan(char *filename1, char *filename2, char *externalPath=0); + +int main(int argc, char *argv[]) +{ + getLHCbStyle(); + PersonalStyle(); + + if ((argc ==2) && (string(argv[1]) == "--info")) + { + cout << "**************************************************" << endl; + + cout << "Some comments." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else if (argc < 3) + { + cout << "**************************************************" << endl; + + cout << "Error! Input files missing..." << endl; + cout << "Please use the following format:" << endl; + cout << "./IVScan [1] [2] [3]" << endl; + cout << "with:" << endl; + cout << "[1] = Input text file 1, complete path (increasing bias voltage);" << endl; + cout << "[2] = Input text file 2, complete path (decreasing bias voltage);" << endl; + cout << "[3] = Additional folder, optional." << endl; + cout << "Type ./IVScan --info for more information." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else + { + cout << "File 1 to process: " << argv[1] << endl; + cout << "File 2 to process: " << argv[2] << endl; + if (argc == 3) + IVScan(argv[1],argv[2]); + else if (argc == 4) + IVScan(argv[1],argv[2],argv[3]); + else + { + cout << "Error! Too many arguments given..." << endl; + + return 0; + } + + return 0; + } +} + +void IVScan(char *filename1, char *filename2, char *externalPath) +{ + cout << "**************************************************" << endl; + cout << "Working on the IV scan..." << endl; + cout << "**************************************************" << endl; + + // Do not comment this line. + gROOT->ProcessLine("#include "); + + int found; + + string filename1_as_string = string(filename1); + // Check that the filename provided corresponds to a text file. + found = filename1_as_string.find(".dat"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a text file." << endl; + return; + } + + string filename2_as_string = string(filename2); + // Check that the filename provided corresponds to a text file. + found = filename2_as_string.find(".dat"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a text file." << endl; + return; + } + + // Open input text file. + ifstream datFile; + std::string line; + + // Number of rows to be read from the text files. + int rows1; + int rows2; + + // Open file 1. + // Determine number of rows to be read from the text file. + datFile.open(filename1_as_string.c_str()); + if (datFile.is_open()) { + rows1 = 0; + while (getline(datFile,line)) + rows1++; + cout << "Number of rows in the input text file 1: " << rows1 << endl; + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + // Open file 2. + // Determine number of rows to be read from the text file. + datFile.open(filename2_as_string.c_str()); + if (datFile.is_open()) { + rows2 = 0; + while (getline(datFile,line)) + rows2++; + cout << "Number of rows in the input text file 2: " << rows2 << endl; + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + // Read the text file. + // Remember that the first row must be skipped. + float V; + float I; + float IErr; + + Int_t i; + + // Read text file 1. + vector vV1; + vector vI1; + vector vVErr1; + vector vIErr1; + + // Save information. + datFile.open(filename1_as_string.c_str()); + if (datFile.is_open()) { + i = 0; + while (getline(datFile,line)) { + if (i>0) { + // cout << line << endl; + istringstream iss(line); + iss >> V >> I >> IErr; + vV1.push_back(V); + vI1.push_back(I); + vVErr1.push_back(0.); + vIErr1.push_back(IErr); + } + i++; + } + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + float *aV1 = &vV1[0]; + float *aI1 = &vI1[0]; + float *aVErr1 = &vVErr1[0]; + float *aIErr1 = &vIErr1[0]; + + /* + cout << aV1[0] << endl; + cout << aV1[1] << endl; + cout << aI1[0] << endl; + cout << aI1[1] << endl; + cout << aVErr1[0] << endl; + cout << aVErr1[1] << endl; + cout << aIErr1[0] << endl; + cout << aIErr1[1] << endl; + */ + + // Read text file 2. + vector vV2; + vector vI2; + vector vVErr2; + vector vIErr2; + + // Save information. + datFile.open(filename2_as_string.c_str()); + if (datFile.is_open()) { + i = 0; + while (getline(datFile,line)) { + if (i>0) { + // cout << line << endl; + istringstream iss(line); + iss >> V >> I >> IErr; + vV2.push_back(V); + vI2.push_back(I); + vVErr2.push_back(0.); + vIErr2.push_back(IErr); + } + i++; + } + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + float *aV2 = &vV2[0]; + float *aI2 = &vI2[0]; + float *aVErr2 = &vVErr2[0]; + float *aIErr2 = &vIErr2[0]; + + /* + cout << aV2[0] << endl; + cout << aV2[1] << endl; + cout << aI2[0] << endl; + cout << aI2[1] << endl; + cout << aVErr2[0] << endl; + cout << aVErr2[1] << endl; + cout << aIErr2[0] << endl; + cout << aIErr2[1] << endl; + */ + + // Do some fanciness to get the directory right. + string analysis = "/home/hep/flionett/TestStand/AnalysisResults"; + if (externalPath!=0) + analysis = string(analysis+"/"+externalPath); + + string filename_as_string_no_path = filename1_as_string.substr(filename1_as_string.find_last_of('/')+1); + string filename_as_string_no_path_no_extension = filename_as_string_no_path.substr(0,filename_as_string_no_path.length()-18); + + // Create a folder named AnalysisResults. Do not worry, nothing bad is going to happen if the folder already exists. + string path_to_make = "mkdir -p "+analysis; + system(path_to_make.c_str()); + cout << "Setting output to: " << path_to_make << endl; + + // Create a folder named Figures inside the folder named AnalysisResults. + string path_to_make_figures = "mkdir "+analysis+"/Figures"; + system(path_to_make_figures.c_str()); + path_to_make_figures = "mkdir "+analysis+"/Figures"+"/IVScan"; + system(path_to_make_figures.c_str()); + path_to_make_figures = "mkdir "+analysis+"/Figures"+"/IVScan"+"/"+filename_as_string_no_path_no_extension; + system(path_to_make_figures.c_str()); + cout << "Setting figures to: " << path_to_make_figures << endl; + + TString path_to_figures = (string(path_to_make_figures)).substr((string(path_to_make_figures)).find_last_of(' ')+1); + + // Open output ROOT file. + TFile *output = TFile::Open(analysis+"/IVScan-"+TString(filename_as_string_no_path_no_extension)+".root","RECREATE"); + + TCanvas *cIVScan = new TCanvas("cIVScan","",400,300); + + int rowsData1 = rows1-1; + int rowsData2 = rows2-1; + + TGraphErrors *gIVScan1 = new TGraphErrors(rowsData1,aV1,aI1,aVErr1,aIErr1); + + InitGraphErrors(gIVScan1,"IV scan","Bias voltage (V)","Current (#muA)"); + DrawGraphErrors(cIVScan,gIVScan1,"AP",path_to_figures); + + output->Close(); + + // Add 2 and TMultiGraph. + + + + + + + + + return; +} diff --git a/Software/IVScan/Makefile b/Software/IVScan/Makefile new file mode 100755 index 0000000..a7a2392 --- /dev/null +++ b/Software/IVScan/Makefile @@ -0,0 +1,34 @@ +# +CC=$(CXX) +glib_cflags=$(shell pkg-config --cflags glib-2.0 gio-2.0) +glib_libs=$(shell pkg-config --libs glib-2.0 gio-2.0) + +ROOTC=$(shell root-config --cflags) +ROOTL=$(shell root-config --libs) +OPT=-g -fno-inline #-std=c++11 +CppFLAGS=$(OPT) -I. $(glib_cflags) +CXXFLAGS=-fPIC $(CppFLAGS) + + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + SO=so + SO_FLAGS=-shared + CXXFLAGS += -D LINUX +endif +ifeq ($(UNAME_S),Darwin) + SO=dylib + SO_FLAGS=-dynamiclib -undefined dynamic_lookup -install_name @rpath/$@ + CXXFLAGS += -D OSX +endif + +all: IVScan + +IVScan: IVScan.C + c++ -I$(OPT) $(CXXFLAGS) $(ROOTC) -o $@ $^ $(LDLIBS) $(ROOTL) $(gliblibs) + + +clean: + rm -f *.o IVScan + rm -rf *.dSYM + diff --git a/Software/IVScan/Makefile~ b/Software/IVScan/Makefile~ new file mode 100755 index 0000000..47be985 --- /dev/null +++ b/Software/IVScan/Makefile~ @@ -0,0 +1,34 @@ +# +CC=$(CXX) +glib_cflags=$(shell pkg-config --cflags glib-2.0 gio-2.0) +glib_libs=$(shell pkg-config --libs glib-2.0 gio-2.0) + +ROOTC=$(shell root-config --cflags) +ROOTL=$(shell root-config --libs) +OPT=-g -fno-inline #-std=c++11 +CppFLAGS=$(OPT) -I. $(glib_cflags) +CXXFLAGS=-fPIC $(CppFLAGS) + + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + SO=so + SO_FLAGS=-shared + CXXFLAGS += -D LINUX +endif +ifeq ($(UNAME_S),Darwin) + SO=dylib + SO_FLAGS=-dynamiclib -undefined dynamic_lookup -install_name @rpath/$@ + CXXFLAGS += -D OSX +endif + +all: IV + +IV: IV.C + c++ -I$(OPT) $(CXXFLAGS) $(ROOTC) -o $@ $^ $(LDLIBS) $(ROOTL) $(gliblibs) + + +clean: + rm -f *.o IV + rm -rf *.dSYM + diff --git a/Software/PulseShapevsV/Makefile b/Software/PulseShapevsV/Makefile new file mode 100755 index 0000000..bf7dd8f --- /dev/null +++ b/Software/PulseShapevsV/Makefile @@ -0,0 +1,34 @@ +# +CC=$(CXX) +glib_cflags=$(shell pkg-config --cflags glib-2.0 gio-2.0) +glib_libs=$(shell pkg-config --libs glib-2.0 gio-2.0) + +ROOTC=$(shell root-config --cflags) +ROOTL=$(shell root-config --libs) +OPT=-g -fno-inline #-std=c++11 +CppFLAGS=$(OPT) -I. $(glib_cflags) +CXXFLAGS=-fPIC $(CppFLAGS) + + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + SO=so + SO_FLAGS=-shared + CXXFLAGS += -D LINUX +endif +ifeq ($(UNAME_S),Darwin) + SO=dylib + SO_FLAGS=-dynamiclib -undefined dynamic_lookup -install_name @rpath/$@ + CXXFLAGS += -D OSX +endif + +all: PulseShapevsV + +PulseShapevsV: PulseShapevsV.C + c++ -I$(OPT) $(CXXFLAGS) $(ROOTC) -o $@ $^ $(LDLIBS) $(ROOTL) $(gliblibs) + + +clean: + rm -f *.o PulseShapevsV + rm -rf *.dSYM + diff --git a/Software/PulseShapevsV/Makefile~ b/Software/PulseShapevsV/Makefile~ new file mode 100755 index 0000000..a212d07 --- /dev/null +++ b/Software/PulseShapevsV/Makefile~ @@ -0,0 +1,34 @@ +# +CC=$(CXX) +glib_cflags=$(shell pkg-config --cflags glib-2.0 gio-2.0) +glib_libs=$(shell pkg-config --libs glib-2.0 gio-2.0) + +ROOTC=$(shell root-config --cflags) +ROOTL=$(shell root-config --libs) +OPT=-g -fno-inline #-std=c++11 +CppFLAGS=$(OPT) -I. $(glib_cflags) +CXXFLAGS=-fPIC $(CppFLAGS) + + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + SO=so + SO_FLAGS=-shared + CXXFLAGS += -D LINUX +endif +ifeq ($(UNAME_S),Darwin) + SO=dylib + SO_FLAGS=-dynamiclib -undefined dynamic_lookup -install_name @rpath/$@ + CXXFLAGS += -D OSX +endif + +all: ComputePedestals + +ComputePedestals: ComputePedestals.C + c++ -I$(OPT) $(CXXFLAGS) $(ROOTC) -o $@ $^ $(LDLIBS) $(ROOTL) $(gliblibs) + + +clean: + rm -f *.o ComputePedestals + rm -rf *.dSYM + diff --git a/Software/PulseShapevsV/PulseShapevsV b/Software/PulseShapevsV/PulseShapevsV new file mode 100755 index 0000000..699dffb --- /dev/null +++ b/Software/PulseShapevsV/PulseShapevsV Binary files differ diff --git a/Software/PulseShapevsV/PulseShapevsV.C b/Software/PulseShapevsV/PulseShapevsV.C new file mode 100644 index 0000000..7db37f7 --- /dev/null +++ b/Software/PulseShapevsV/PulseShapevsV.C @@ -0,0 +1,320 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 20/11/2014 +//************************************************ + +/* +PulseShapevsV reads two text files (containing the bias voltage and the current values) and creates a ROOT file with the following information: +- laser delay at the peak of the Beetle pulse shape (float laserDelayAtPeak) as a function of the bias voltage; +- average ADC signal at the peak of the Beetle pulse shape (float averageADCSignalAtPeak) as a function of the bias voltage. + +Compile with: + +make + +Run with: + +./PulseShapevsV [input text file 1] [input text file 2] [additional folder] + +where + +- [input text file 1] is the complete path, including the folder and the filename, of the text file one wants to process (increasing bias voltage); +- [input text file 2] is the complete path, including the folder and the filename, of the text file one wants to process (decreasing bias voltage); +- [additional folder] is the optional additional folder where the output will be saved. + +A folder named AnalysisResults will be created in a fixed location and a ROOT file will be saved in there. A folder named Figures will be created inside the folder named AnalysisResults, with some monitoring plots. + +If needed, an additional folder can be specified, that will be created inside the folder named AnalysisResults. +*/ + +#include "../Tools/Lib.C" +#include "../Tools/lhcbStyle.C" +#include "../Tools/Style.C" +#include "../Tools/Useful.C" + +#include "../Tools/Par.C" + +void PulseShapevsV(char *filename1, char *filename2, char *externalPath=0); + +int main(int argc, char *argv[]) +{ + getLHCbStyle(); + PersonalStyle(); + + if ((argc ==2) && (string(argv[1]) == "--info")) + { + cout << "**************************************************" << endl; + + cout << "Some comments." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else if (argc < 3) + { + cout << "**************************************************" << endl; + + cout << "Error! Input files missing..." << endl; + cout << "Please use the following format:" << endl; + cout << "./PulseShapevsV [1] [2] [3]" << endl; + cout << "with:" << endl; + cout << "[1] = Input text file 1, complete path (increasing bias voltage);" << endl; + cout << "[2] = Input text file 2, complete path (decreasing bias voltage);" << endl; + cout << "[3] = Additional folder, optional." << endl; + cout << "Type ./PulseShapevsV --info for more information." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else + { + cout << "File 1 to process: " << argv[1] << endl; + cout << "File 2 to process: " << argv[2] << endl; + if (argc == 3) + PulseShapevsV(argv[1],argv[2]); + else if (argc == 4) + PulseShapevsV(argv[1],argv[2],argv[3]); + else + { + cout << "Error! Too many arguments given..." << endl; + + return 0; + } + + return 0; + } +} + +void PulseShapevsV(char *filename1, char *filename2, char *externalPath) +{ + cout << "**************************************************" << endl; + cout << "Showing the pulse shape changes as a function of the bias voltage..." << endl; + cout << "**************************************************" << endl; + + // Do not comment this line. + gROOT->ProcessLine("#include "); + + int found; + + string filename1_as_string = string(filename1); + // Check that the filename provided corresponds to a text file. + found = filename1_as_string.find(".dat"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a text file." << endl; + return; + } + + string filename2_as_string = string(filename2); + // Check that the filename provided corresponds to a text file. + found = filename2_as_string.find(".dat"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a text file." << endl; + return; + } + + // Open input text file. + ifstream datFile; + std::string line; + + // Number of rows to be read from the text files. + int rows1; + int rows2; + + // Open file 1. + // Determine number of rows to be read from the text file. + datFile.open(filename1_as_string.c_str()); + if (datFile.is_open()) { + rows1 = 0; + while (getline(datFile,line)) + rows1++; + cout << "Number of rows in the input text file 1: " << rows1 << endl; + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + // Open file 2. + // Determine number of rows to be read from the text file. + datFile.open(filename2_as_string.c_str()); + if (datFile.is_open()) { + rows2 = 0; + while (getline(datFile,line)) + rows2++; + cout << "Number of rows in the input text file 2: " << rows2 << endl; + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + // Read the text file. + // Remember that the first row must be skipped. + float V; + float trash2; + float trash3; + float laserDelayAtPeak; + float averageADCSignalAtPeak; + + Int_t i; + + // Read text file 1. + vector vV1; + vector vlaserDelayAtPeak1; + vector vaverageADCSignalAtPeak1; + + // Save information. + datFile.open(filename1_as_string.c_str()); + if (datFile.is_open()) { + i = 0; + while (getline(datFile,line)) { + if (i>0) { + // cout << line << endl; + istringstream iss(line); + iss >> V >> trash2 >> trash3 >> laserDelayAtPeak >> averageADCSignalAtPeak; + vV1.push_back(V); + vlaserDelayAtPeak1.push_back(laserDelayAtPeak); + vaverageADCSignalAtPeak1.push_back(averageADCSignalAtPeak); + } + i++; + } + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + float *aV1 = &vV1[0]; + float *alaserDelayAtPeak1 = &vlaserDelayAtPeak1[0]; + float *aaverageADCSignalAtPeak1 = &vaverageADCSignalAtPeak1[0]; + + /* + cout << aV1[0] << endl; + cout << aV1[1] << endl; + cout << alaserDelayAtPeak1[0] << endl; + cout << alaserDelayAtPeak1[1] << endl; + cout << aaverageADCSignalAtPeak1[0] << endl; + cout << aaverageADCSignalAtPeak1[1] << endl; + */ + + // Read text file 2. + vector vV2; + vector vlaserDelayAtPeak2; + vector vaverageADCSignalAtPeak2; + + // Save information. + datFile.open(filename2_as_string.c_str()); + if (datFile.is_open()) { + i = 0; + while (getline(datFile,line)) { + if (i>0) { + // cout << line << endl; + istringstream iss(line); + iss >> V >> trash2 >> trash3 >> laserDelayAtPeak >> averageADCSignalAtPeak; + vV2.push_back(V); + vlaserDelayAtPeak2.push_back(laserDelayAtPeak); + vaverageADCSignalAtPeak2.push_back(averageADCSignalAtPeak); + } + i++; + } + datFile.close(); + } + else + { + cout << "Unable to open file." << endl; + return; + } + + float *aV2 = &vV2[0]; + float *alaserDelayAtPeak2 = &vlaserDelayAtPeak2[0]; + float *aaverageADCSignalAtPeak2 = &vaverageADCSignalAtPeak2[0]; + + /* + cout << aV2[0] << endl; + cout << aV2[1] << endl; + cout << alaserDelayAtPeak2[0] << endl; + cout << alaserDelayAtPeak2[1] << endl; + cout << aaverageADCSignalAtPeak2[0] << endl; + cout << aaverageADCSignalAtPeak2[1] << endl; + */ + + // Do some fanciness to get the directory right. + string analysis = "/home/hep/flionett/TestStand/AnalysisResults"; + if (externalPath!=0) + analysis = string(analysis+"/"+externalPath); + + string filename_as_string_no_path = filename1_as_string.substr(filename1_as_string.find_last_of('/')+1); + string filename_as_string_no_path_no_extension = filename_as_string_no_path.substr(0,filename_as_string_no_path.length()-18); + + // Create a folder named AnalysisResults. Do not worry, nothing bad is going to happen if the folder already exists. + string path_to_make = "mkdir -p "+analysis; + system(path_to_make.c_str()); + cout << "Setting output to: " << path_to_make << endl; + + // Create a folder named Figures inside the folder named AnalysisResults. + string path_to_make_figures = "mkdir "+analysis+"/Figures"; + system(path_to_make_figures.c_str()); + path_to_make_figures = "mkdir "+analysis+"/Figures"+"/PulseShapevsV"; + system(path_to_make_figures.c_str()); + path_to_make_figures = "mkdir "+analysis+"/Figures"+"/PulseShapevsV"+"/"+filename_as_string_no_path_no_extension; + system(path_to_make_figures.c_str()); + cout << "Setting figures to: " << path_to_make_figures << endl; + + TString path_to_figures = (string(path_to_make_figures)).substr((string(path_to_make_figures)).find_last_of(' ')+1); + + // Open output ROOT file. + TFile *output = TFile::Open(analysis+"/PulseShapevsV-"+TString(filename_as_string_no_path_no_extension)+".root","RECREATE"); + + TCanvas *claserDelayAtPeakvsV = new TCanvas("cLaserDelayAtPeakvsV","",400,300); + TCanvas *caverageADCSignalAtPeakvsV = new TCanvas("caverageADCSignalAtPeakvsV","",400,300); + + int rowsData1 = rows1-1; + int rowsData2 = rows2-1; + + TMultiGraph *mglaserDelayAtPeakvsV = new TMultiGraph(); + TMultiGraph *mgaverageADCSignalAtPeakvsV = new TMultiGraph(); + + TGraph *glaserDelayAtPeakvsV1 = new TGraph(rowsData1,aV1,alaserDelayAtPeak1); + TGraph *glaserDelayAtPeakvsV2 = new TGraph(rowsData2,aV2,alaserDelayAtPeak2); + + TGraph *gaverageADCSignalAtPeakvsV1 = new TGraph(rowsData1,aV1,aaverageADCSignalAtPeak1); + TGraph *gaverageADCSignalAtPeakvsV2 = new TGraph(rowsData2,aV2,aaverageADCSignalAtPeak2); + + InitGraph(glaserDelayAtPeakvsV1,"Laser delay","Bias voltage (V)","Laser delay (ns)"); + InitGraph(glaserDelayAtPeakvsV2,"Laser delay","Bias voltage (V)","Laser delay (ns)"); + + InitGraph(gaverageADCSignalAtPeakvsV1,"Average ADC signal","Bias voltage (V)"," (ADC counts)"); + InitGraph(gaverageADCSignalAtPeakvsV2,"Average ADC signal","Bias voltage (V)"," (ADC counts)"); + + glaserDelayAtPeakvsV1->SetMarkerColor(kMagenta); + glaserDelayAtPeakvsV2->SetMarkerColor(kOrange); + + gaverageADCSignalAtPeakvsV1->SetMarkerColor(kMagenta); + gaverageADCSignalAtPeakvsV2->SetMarkerColor(kOrange); + + TLegend *leglaserDelayAtPeakvsV = CreateLegend2(glaserDelayAtPeakvsV1,"increasing V",glaserDelayAtPeakvsV2,"decreasing V","pw"); + + TLegend *legaverageADCSignalAtPeakvsV = CreateLegend2(gaverageADCSignalAtPeakvsV1,"increasing V",gaverageADCSignalAtPeakvsV2,"decreasing V","pw",0.45,0.25,0.90,0.50); + + mglaserDelayAtPeakvsV->Add(glaserDelayAtPeakvsV1); + mglaserDelayAtPeakvsV->Add(glaserDelayAtPeakvsV2); + + mgaverageADCSignalAtPeakvsV->Add(gaverageADCSignalAtPeakvsV1); + mgaverageADCSignalAtPeakvsV->Add(gaverageADCSignalAtPeakvsV2); + + DrawGraphCompare(claserDelayAtPeakvsV,mglaserDelayAtPeakvsV,leglaserDelayAtPeakvsV,"Laser delay","Bias voltage (V)","Laser delay (ns)",path_to_figures); + + DrawGraphCompare(caverageADCSignalAtPeakvsV,mgaverageADCSignalAtPeakvsV,legaverageADCSignalAtPeakvsV,"Average ADC signal","Bias voltage (V)"," (ADC counts)",path_to_figures); + + output->Close(); + + return; +} diff --git a/Software/PulseShapevsV/PulseShapevsV.C~ b/Software/PulseShapevsV/PulseShapevsV.C~ new file mode 100644 index 0000000..26ae795 --- /dev/null +++ b/Software/PulseShapevsV/PulseShapevsV.C~ @@ -0,0 +1,105 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 20/11/2014 +//************************************************ + +/* +PulseShapevsV reads two text files (containing the bias voltage and the current values) and creates a ROOT file with the following information: +- laser delay at the peak of the Beetle pulse shape (float laserDelayAtPeak) as a function of the bias voltage; +- average ADC signal at the peak of the Beetle pulse shape (float float averageADCSignalAtPeak) as a function of the bias voltage. + +Compile with: + +make + +Run with: + +./PulseShapevsV [input text file 1] [input text file 2] [additional folder] + +where + +- [input text file 1] is the complete path, including the folder and the filename, of the text file one wants to process (increasing bias voltage); +- [input text file 2] is the complete path, including the folder and the filename, of the text file one wants to process (decreasing bias voltage); +- [additional folder] is the optional additional folder where the output will be saved. + +A folder named AnalysisResults will be created in a fixed location and a ROOT file will be saved in there. A folder named Figures will be created inside the folder named AnalysisResults, with some monitoring plots. + +If needed, an additional folder can be specified, that will be created inside the folder named AnalysisResults. +*/ + +#include "../Tools/Lib.C" +#include "../Tools/lhcbStyle.C" +#include "../Tools/Style.C" +#include "../Tools/Useful.C" + +#include "../Tools/Par.C" + +void PulseShapevsV(char *filename1, char *filename2, char *externalPath=0); + +int main(int argc, char *argv[]) +{ + getLHCbStyle(); + PersonalStyle(); + + if ((argc ==2) && (string(argv[1]) == "--info")) + { + cout << "**************************************************" << endl; + + cout << "Some comments." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else if (argc < 3) + { + cout << "**************************************************" << endl; + + cout << "Error! Input files missing..." << endl; + cout << "Please use the following format:" << endl; + cout << "./PulseShapevsV [1] [2] [3]" << endl; + cout << "with:" << endl; + cout << "[1] = Input text file 1, complete path (increasing bias voltage);" << endl; + cout << "[2] = Input text file 2, complete path (decreasing bias voltage);" << endl; + cout << "[3] = Additional folder, optional." << endl; + cout << "Type ./PulseShapevsV --info for more information." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else + { + cout << "File 1 to process: " << argv[1] << endl; + cout << "File 2 to process: " << argv[2] << endl; + if (argc == 3) + PulseShapevsV(argv[1],argv[2]); + else if (argc == 4) + PulseShapevsV(argv[1],argv[2],argv[3]); + else + { + cout << "Error! Too many arguments given..." << endl; + + return 0; + } + + return 0; + } +} + +void IVScan(char *filename1, char *filename2, char *externalPath) +{ + cout << "**************************************************" << endl; + cout << "Showing the pulse shape changes as a function of the bias voltage..." << endl; + cout << "**************************************************" << endl; + + // Do not comment this line. + gROOT->ProcessLine("#include "); + + + + + + +return; +} diff --git a/Software/Tools/Style.C b/Software/Tools/Style.C index c2a7c2e..7c8921a 100644 --- a/Software/Tools/Style.C +++ b/Software/Tools/Style.C @@ -47,6 +47,8 @@ void DrawGraphErrors(TCanvas *canvas, TGraphErrors *graph, TString option = "APC", TString folder = ""); +void DrawGraphCompare(TCanvas *canvas, TMultiGraph *graph, TLegend *leg, TString title = "", TString x = "", TString y = "", 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); @@ -389,6 +391,7 @@ graph->SetTitle(title); graph->GetXaxis()->SetTitle(x); graph->GetYaxis()->SetTitle(y); + graph->SetFillColor(kWhite); return; } @@ -398,6 +401,7 @@ graph->SetTitle(title); graph->GetXaxis()->SetTitle(x); graph->GetYaxis()->SetTitle(y); + graph->SetFillColor(kWhite); return; } @@ -460,6 +464,37 @@ return; } +// DrawGraphCompare draws the "graph" graph in the "canvas" canvas and saves the result in the "folder" folder, in a pdf file named "canvas.pdf". +void DrawGraphCompare(TCanvas *canvas, TMultiGraph *graph, TLegend *leg, TString title, TString x, TString y, TString folder) { + TString path; + path = folder; + TString name = canvas->GetName(); + canvas->cd(); + canvas->SetTickx(1); + canvas->SetTicky(1); + graph->Draw("APE"); + leg->Draw(); + // graph->SetFillColor(38); + // graph->SetMarkerSize(1); + // graph->SetMarkerStyle(20); + // graph->SetMarkerColor(1); + // graph->SetLineWidth(2); + // graph->SetLineStyle(1); + // graph->SetLineColor(2); + graph->GetYaxis()->SetTitleOffset(0.8); + gPad->Modified(); + graph->SetTitle(title); + graph->GetXaxis()->SetTitle(x); + graph->GetYaxis()->SetTitle(y); + 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 @@ -469,7 +504,7 @@ TLegend *leg = new TLegend(x1,y1,x2,y2); leg->AddEntry(obj1,lab1,option.Data()); leg->AddEntry(obj2,lab2,option.Data()); - // leg->SetTextSize(.02); + leg->SetTextSize(0.05); if(option.Contains("w")) leg->SetFillColor(kWhite); @@ -486,7 +521,7 @@ leg->AddEntry(obj1,lab1,option.Data()); leg->AddEntry(obj2,lab2,option.Data()); leg->AddEntry(obj3,lab3,option.Data()); - // leg->SetTextSize(.02); + leg->SetTextSize(0.05); if(option.Contains("w")) leg->SetFillColor(kWhite); @@ -504,7 +539,7 @@ leg->AddEntry(obj2,lab2,option.Data()); leg->AddEntry(obj3,lab3,option.Data()); leg->AddEntry(obj4,lab4,option.Data()); - // leg->SetTextSize(.02); + leg->SetTextSize(0.05); if(option.Contains("w")) leg->SetFillColor(kWhite);