diff --git a/Software/AttenuationScan/AttenuationScan.C b/Software/AttenuationScan/AttenuationScan.C new file mode 100644 index 0000000..1e34a86 --- /dev/null +++ b/Software/AttenuationScan/AttenuationScan.C @@ -0,0 +1,327 @@ +//================================================ +// Author: Federica Lionetto +// Created on: 21/07/2014 +//================================================ + +#include "../Tools/Lib.C" +#include "../Tools/Par.C" +#include "../Tools/Style.C" + +// Input: /home/hep/flionett/TestStand/Data//AttenuationScan/RootFiles/-dB-las.root +// Output: /home/hep/flionett/TestStand/AnalysisResults//AttenuationScan/AttenuationScan--dB-las.root + +void AttenuationScan(char *sensor, char *filename, char *externalPath = 0); + +int main(int argc, char *argv[]) +{ + dca(); + + 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! Type of sensor or filename missing..." << endl; + cout << "Please use the following format:" << endl; + cout << "./AttenuationScan [1] [2] [3]" << endl; + cout << "with:" << endl; + cout << "[1] = Type of sensor (Hans410, ...);" << endl; + cout << "[2] = Filename, excluding the attenuation value and the run type;" << endl; + cout << "[3] = Additional folder, optional." << endl; + cout << "Type ./AttenuationScan --info for more information." << endl; + + cout << "**************************************************" << endl; + + return 0; + } + else + { + cout << "Type of sensor: " << argv[1] << endl; + cout << "Filename: " << argv[2] << endl; + if (argc == 3) + AttenuationScan(argv[1],argv[2]); + else if (argc == 4) + AttenuationScan(argv[1],argv[2],argv[3]); + else + { + cout << "Error! Too many arguments given..." << endl; + + return 0; + } + + return 0; + } +} + + + +// Input: /home/hep/flionett/TestStand/Data//AttenuationScan/RootFiles/-dB-las.root +// Output: /home/hep/flionett/TestStand/AnalysisResults//AttenuationScan/AttenuationScan-.root + +void AttenuationScan(char *sensor, char *filename, char *externalPath) +{ + cout << "**************************************************" << endl; + cout << "Performing attenuation scan..." << endl; + cout << "**************************************************" << endl; + + // Do not comment this line. + gROOT->ProcessLine("#include "); + + // Do some fanciness to get the directory right. + string inputDirectory = "~/TestStand/Data/"+string(sensor)+"/AttenuationScan/RootFiles"; + string outputDirectory = "~/TestStand/AnalysisResults/"+string(sensor)+"/AttenuationScan"; + if (externalPath!=0) + outputDirectory = string(outputDirectory+"/"+externalPath); + cout << "The input directory is: " << inputDirectory << endl; + cout << "The output directory is: " << outputDirectory << endl; + + // Create the outputDirectory directory if it does not exist. + string path_to_make = "mkdir -p "+outputDirectory; + system(path_to_make.c_str()); + + cout << "Figures stored in: " << outputDirectory+"/Figures/"+filename << endl; + + // Create a directory named Figures inside the directory named outputDirectory if it does not exist. + string path_to_make_figures = "mkdir -p "+outputDirectory+"/Figures/"+filename; + system(path_to_make_figures.c_str()); + + TString path_to_figures = (string(path_to_make_figures)).substr((string(path_to_make_figures)).find_last_of(' ')+1); + + // Execute findStrip. + int strip; + string direction; + + string input_findStrip = inputDirectory+"/"+string(filename)+"-15.5dB-las.root"; + + // findStrip(input_findStrip,&strip,&direction); + + string input_ROOT; + string output_ROOT = outputDirectory+"/AttenuationScan-"+filename+".root"; + + const Float_t mindB = 10.0; + const Float_t maxdB = 20.0; + const Float_t stepdB = 0.5; + const Int_t steps = (Int_t)((maxdB-mindB)/stepdB+1); + Float_t dB[steps]; + + // Open input data ROOT files. + input_ROOT = inputDirectory+"/"+string(filename)+"-"+"15.5"+"dB-las.root"; + TFile *input = TFile::Open(TString(input_ROOT)); + + // Close input data ROOT files. + input->Close(); + + // Open output ROOT file. + TFile *output = TFile::Open(TString(output_ROOT),"RECREATE"); + + // Write output ROOT file. + output->Write(); + + // Close output ROOT file. + output->Close(); + + return; +} + + + + + + + + + + + + + + + +/* + +The main performs an attenuation scan by reading the files in the "folder" folder. It first executes findStrip on the file given as argument 2 and then uses this information for performing the scan. + +Still to do: +- use the sum of the ADC counts; +- remove outliers and get the mean and the RMS again. + +*/ + +/* + + //================================================================== + // + // Perform scan. + // + + const Float_t mindB = 10.0; + const Float_t maxdB = 20.0; + const Float_t stepdB = 0.5; + const Int_t steps = (Int_t)((maxdB-mindB)/stepdB+1); + Float_t dB[steps]; + + char inFile[200]; + char outFile[200]; + + sprintf(outFile,"%s/attenuationScan-%s.root",analysis.c_str(),date.c_str()); + std::cout << "Output file: " << outFile << std::endl; + + TFile *output = TFile::Open(outFile,"RECREATE"); + + TH1F *hADC[steps]; + TH1F *hsumADC[steps]; + + TCanvas *cADC[steps]; + TCanvas *csumADC[steps]; + + Float_t meanADC[steps]; + Float_t rmsADC[steps]; + + Float_t meanSumADC[steps]; + Float_t rmsSumADC[steps]; + + // Continue from here!!! + + for (int step=0;stepGet("tree"); + Int_t evts = (Int_t)tree->GetEntries(); + std::cout << "Number of events: " << evts << std::endl; + + std::vector *vec_adc = 0; + TBranch *b = 0; + tree->SetBranchAddress("vec_adc",&vec_adc,&b); + + //================================================================== + // + // Save information from trees. + // + + for (int i=0;iGetEntry(i); + hADC[step]->Fill(vec_adc->at(strip)); + // std::cout << i << ", " << (vec_adc->at(strip-2*skip))+(vec_adc->at(strip-skip))+(vec_adc->at(strip))+(vec_adc->at(strip+skip)) << std::endl; + // std::cout << i << ", " << (vec_adc->at(strip-skip))+(vec_adc->at(strip))+(vec_adc->at(strip+skip))+(vec_adc->at(strip+2*skip)) << std::endl; + if (direction == "left") + { + // std::cout << "left" << std::endl; + hsumADC[step]->Fill((vec_adc->at(strip-2*skip))+(vec_adc->at(strip-skip))+(vec_adc->at(strip))+(vec_adc->at(strip+skip))); + } + else + { + // std::cout << "right" << std::endl; + hsumADC[step]->Fill((vec_adc->at(strip-skip))+(vec_adc->at(strip))+(vec_adc->at(strip+skip))+(vec_adc->at(strip+2*skip))); + } + } + + //================================================================== + // + // Close input file. + // + + input->Close(); + + //================================================================== + // + // Select output file. + // + + output->cd(); + + //================================================================== + // + // Get mean and RMS. + // + + meanADC[step] = hADC[step]->GetMean(); + rmsADC[step] = hADC[step]->GetRMS(); + std::cout << "Mean of the ADC counts distribution: " << meanADC[step] << std::endl; + std::cout << "RMS of the ADC counts distribution: " << rmsADC[step] << std::endl; + + meanSumADC[step] = hsumADC[step]->GetMean(); + rmsSumADC[step] = hsumADC[step]->GetRMS(); + std::cout << "Mean of the sum of the ADC counts of four adjacent strips distribution: " << meanSumADC[step] << std::endl; + std::cout << "RMS of the sum of the ADC counts of four adjacent strips distribution: " << rmsSumADC[step] << std::endl; + + //================================================================== + // + // Plot useful information. + // + + DrawHist(cADC[step],hADC[step],"",analysis); + DrawHist(csumADC[step],hsumADC[step],"",analysis); + + //================================================================== + // + // Write output file. + // + + output->Write(); + } + + //================================================================== + // + // Select output file. + // + + output->cd(); + + TGraph *gattenuationScan = new TGraph(steps,dB,meanADC); + + InitGraph(gattenuationScan,"Attenuation scan","Attenuation (dB)","ADC counts"); + + TCanvas *cattenuationScan = new TCanvas(Form("cattenuationScan-%s",date.c_str()),"",700,700); + + DrawGraph(cattenuationScan,gattenuationScan,"APC",analysis); + + //================================================================== + // + // Write output file. + // + + output->Write(); + + //================================================================== + // + // Close output file. + // + + output->Close(); + + return 0; +} + +*/ diff --git a/Software/AttenuationScan/Makefile b/Software/AttenuationScan/Makefile new file mode 100755 index 0000000..65bcf03 --- /dev/null +++ b/Software/AttenuationScan/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: AttenuationScan + +AttenuationScan: AttenuationScan.C + c++ -I$(OPT) $(CXXFLAGS) $(ROOTC) -o $@ $^ $(LDLIBS) $(ROOTL) $(gliblibs) + + +clean: + rm -f *.o AttenuationScan + rm -rf *.dSYM + diff --git a/Software/ComputePedestals/ComputePedestals.C b/Software/ComputePedestals/ComputePedestals.C index 833c22c..3bc6417 100644 --- a/Software/ComputePedestals/ComputePedestals.C +++ b/Software/ComputePedestals/ComputePedestals.C @@ -39,8 +39,8 @@ */ #include "../Tools/Lib.C" -#include "../Tools/Style.C" #include "../Tools/Par.C" +#include "../Tools/Style.C" void ComputePedestals(char *filename, char *externalPath = 0); @@ -132,7 +132,7 @@ gROOT->ProcessLine("#include "); // Do some fanciness to get the directory right. - string analysis = "../../AnalysisResults"; + string analysis = "/home/hep/flionett/TestStand/AnalysisResults"; if (externalPath!=0) analysis = string(analysis+"/"+externalPath); @@ -276,7 +276,7 @@ // Draw histograms. sADC[ch] = CreateStats(hADC[ch],"IUO"); - DrawHistStats(cADC[ch],hADC[ch],sADC[ch],"",path_to_figures); + // DrawHistStats(cADC[ch],hADC[ch],sADC[ch],"",path_to_figures); // Get mean and RMS (that is, pedestal and noise). pedestal[ch] = hADC[ch]->GetMean();