diff --git a/Software/AttenuationScan/AttenuationScan.C b/Software/AttenuationScan/AttenuationScan.C index 1e34a86..d9dcd2c 100644 --- a/Software/AttenuationScan/AttenuationScan.C +++ b/Software/AttenuationScan/AttenuationScan.C @@ -1,20 +1,32 @@ -//================================================ +//************************************************ // Author: Federica Lionetto // Created on: 21/07/2014 -//================================================ +//************************************************ + +/* +AttenuationScan reads all the ROOT files of a given attenuation scan data taking, call FindStrip to find the Beetle channel corresponding to the strip hit by the laser, and creates a ROOT file with the following information: +- a graph with the mean ADC count on the strip hit by the laser as a function of the attenuation; +- a graph with the mean of the sum of the ADC counts of four adjacent strips around that hit by the laser as a function of the attenuation. + +The attenuation scan data taking is identified by the following information: +- , that is, the type of sensor (Hans410, ...); +- , that is, the filename excluding the attenuation value and the run type. +*/ #include "../Tools/Lib.C" -#include "../Tools/Par.C" +#include "../Tools/lhcbStyle.C" #include "../Tools/Style.C" +#include "../Tools/Useful.C" -// Input: /home/hep/flionett/TestStand/Data//AttenuationScan/RootFiles/-dB-las.root -// Output: /home/hep/flionett/TestStand/AnalysisResults//AttenuationScan/AttenuationScan--dB-las.root +#include "../Tools/FindStrip.C" +#include "../Tools/Par.C" void AttenuationScan(char *sensor, char *filename, char *externalPath = 0); int main(int argc, char *argv[]) { - dca(); + getLHCbStyle(); + PersonalStyle(); if ((argc == 2) && (string(argv[1]) == "--info")) { @@ -62,10 +74,11 @@ } } - - -// Input: /home/hep/flionett/TestStand/Data//AttenuationScan/RootFiles/-dB-las.root -// Output: /home/hep/flionett/TestStand/AnalysisResults//AttenuationScan/AttenuationScan-.root +/* + If we execute AttenuationScan with ./AttenuationScan we are calling the following input and output files: + 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) { @@ -77,7 +90,7 @@ gROOT->ProcessLine("#include "); // Do some fanciness to get the directory right. - string inputDirectory = "~/TestStand/Data/"+string(sensor)+"/AttenuationScan/RootFiles"; + string inputDirectory = "~/TestStand/AnalysisResults/"+string(sensor)+"/AttenuationScan"; string outputDirectory = "~/TestStand/AnalysisResults/"+string(sensor)+"/AttenuationScan"; if (externalPath!=0) outputDirectory = string(outputDirectory+"/"+externalPath); @@ -100,10 +113,12 @@ int strip; string direction; - string input_findStrip = inputDirectory+"/"+string(filename)+"-15.5dB-las.root"; + string inputFindStrip = inputDirectory+"/"+filename+"-15.5dB-las.root"; + string outputFindStrip = outputDirectory+"/FindStrip-"+filename+"-15.5dB-las.root"; - // findStrip(input_findStrip,&strip,&direction); + FindStrip(inputFindStrip,outputFindStrip,path_to_figures,&strip,&direction); + char char_input_ROOT[200]; string input_ROOT; string output_ROOT = outputDirectory+"/AttenuationScan-"+filename+".root"; @@ -112,17 +127,69 @@ const Float_t stepdB = 0.5; const Int_t steps = (Int_t)((maxdB-mindB)/stepdB+1); Float_t dB[steps]; + Float_t meanADC[steps]; + Float_t mean4ADC[steps]; - // Open input data ROOT files. - input_ROOT = inputDirectory+"/"+string(filename)+"-"+"15.5"+"dB-las.root"; - TFile *input = TFile::Open(TString(input_ROOT)); + for (Int_t step=0;stepClose(); + // Open input data ROOT files. + // I did not find a better way to create a string containing the attenuation. + sprintf(char_input_ROOT,"%s/%s-%.1fdB-las.root",inputDirectory.c_str(),filename,dB[step]); + input_ROOT = string(char_input_ROOT); + // Check that the filename provided corresponds to a ROOT file. + int found = input_ROOT.find(".root"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a ROOT file." << endl; + return; + } + // Check that the filename provided corresponds to an existing ROOT file. + /* + if (!(boost::filesystem::exists(char_input_ROOT))) { + cout << "Error! The filename provided is not associated to an existing ROOT file." << endl; + return; + } + */ + + cout << "Open ROOT file #" << step+1 << ": " << input_ROOT << endl; + TFile *input = TFile::Open(TString(input_ROOT)); + + // Only one strip. + TH1D *hist = (TH1D *)input->Get(Form("hADCPedSub%d",strip)); + meanADC[step] = hist->GetMean(); + + // Four adjacent strips. + TH1D *hist1 = (TH1D *)input->Get(Form("hADCPedSub%d",strip)); + TH1D *hist2 = (TH1D *)input->Get(Form("hADCPedSub%d",strip+NSkip)); + TH1D *hist3 = (TH1D *)input->Get(Form("hADCPedSub%d",strip-NSkip)); + TH1D *hist4; + if (direction == "left") + hist4 = (TH1D *)input->Get(Form("hADCPedSub%d",strip-2*NSkip)); + else if (direction == "right") + hist4 = (TH1D *)input->Get(Form("hADCPedSub%d",strip+2*NSkip)); + mean4ADC[step] = hist1->GetMean()+hist2->GetMean()+hist3->GetMean()+hist4->GetMean(); + + // Close input data ROOT files. + input->Close(); + } // Open output ROOT file. TFile *output = TFile::Open(TString(output_ROOT),"RECREATE"); + // Only one strip. + TGraph *gattenuationScan = new TGraph(steps,dB,meanADC); + InitGraph(gattenuationScan,"Attenuation scan - 1 strip","Attenuation (dB)","ADC counts"); + TCanvas *cattenuationScan = new TCanvas(Form("cattenuationScan-%s",filename),"",400,300); + DrawGraph(cattenuationScan,gattenuationScan,"AB1",path_to_figures); + // DrawGraph(cattenuationScan,gattenuationScan,"APC",path_to_figures); + + // Four adjacent strips. + TGraph *gattenuationScan4 = new TGraph(steps,dB,mean4ADC); + InitGraph(gattenuationScan4,"Attenuation scan - 4 adjacent strips","Attenuation (dB)","ADC counts"); + TCanvas *cattenuationScan4 = new TCanvas(Form("cattenuationScan4-%s",filename),"",400,300); + DrawGraph(cattenuationScan4,gattenuationScan4,"AB1",path_to_figures); + // DrawGraph(cattenuationScan4,gattenuationScan4,"APC",path_to_figures); + // Write output ROOT file. output->Write(); @@ -131,197 +198,3 @@ 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 index 65bcf03..ee0c0cb 100755 --- a/Software/AttenuationScan/Makefile +++ b/Software/AttenuationScan/Makefile @@ -9,7 +9,6 @@ CppFLAGS=$(OPT) -I. $(glib_cflags) CXXFLAGS=-fPIC $(CppFLAGS) - UNAME_S := $(shell uname -s) ifeq ($(UNAME_S),Linux) SO=so diff --git a/Software/ComputePedestals/ComputePedestals.C b/Software/ComputePedestals/ComputePedestals.C index 9115412..5eb768e 100644 --- a/Software/ComputePedestals/ComputePedestals.C +++ b/Software/ComputePedestals/ComputePedestals.C @@ -41,6 +41,8 @@ #include "../Tools/Lib.C" #include "../Tools/lhcbStyle.C" #include "../Tools/Style.C" +#include "../Tools/Useful.C" + #include "../Tools/Par.C" void ComputePedestals(char *filename, char *externalPath = 0); diff --git a/Software/ProcessRawData/ProcessRawData.C b/Software/ProcessRawData/ProcessRawData.C index e2c5309..4c83b04 100644 --- a/Software/ProcessRawData/ProcessRawData.C +++ b/Software/ProcessRawData/ProcessRawData.C @@ -32,6 +32,8 @@ #include "../Tools/Lib.C" #include "../Tools/lhcbStyle.C" #include "../Tools/Style.C" +#include "../Tools/Useful.C" + #include "../Tools/Par.C" void ProcessRawData(char *filename, char *filenamePed, char *externalPath=0); diff --git a/Software/Tools/FindStrip.C b/Software/Tools/FindStrip.C new file mode 100644 index 0000000..16a48aa --- /dev/null +++ b/Software/Tools/FindStrip.C @@ -0,0 +1,157 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 21/07/2014 +//************************************************ + +/* +FindStrip reads the file called and returns the following information: +- Beetle channel corresponding to the strip hit by the laser; +- direction for finding the cluster of four adjacent strips (not Beetle channels!). +It also plots the hit map (pedestal subtracted ADC counts averaged over events as a function of the Beetle channel, for all Beetle channels and for Beetle channels connected to silicon. +*/ + +// Header guard. +#ifndef __FINDSTRIP_C_INCLUDED__ +#define __FINDSTRIP_C_INCLUDED__ + +#include "Lib.C" +#include "lhcbStyle.C" +#include "Style.C" +#include "Par.C" +#include "Useful.C" + +void FindStrip(string inputFilename, string outputFilename, TString path_to_figures, int *strip, string *direction); + +void FindStrip(string inputFilename, string outputFilename, TString path_to_figures, int *strip, string *direction) { + cout << "**************************************************" << endl; + cout << "Finding the Beetle channel corresponding to the strip hit by the laser..." << endl; + cout << "**************************************************" << endl; + + cout << "Input file: " << inputFilename << ", " << inputFilename.c_str() << endl; + cout << "Output file: " << outputFilename << endl; + + int found; + + // Check that the input filename provided corresponds to a ROOT file. + found = inputFilename.find(".root"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a ROOT file." << endl; + return; + } + + // Check that the output filename provided corresponds to a ROOT file. + found = outputFilename.find(".root"); + if (found==string::npos) { + cout << "Error! The filename provided is not associated to a ROOT file." << endl; + return; + } + + // Check that the input filename provided corresponds to an existing ROOT file. + /* + if (!(boost::filesystem::exists(inputFilename.c_str()))) { + cout << "Error! The filename provided is not associated to an existing ROOT file." << endl; + return; + } + */ + + cout << "Open input ROOT file " << inputFilename << endl; + TFile *input = TFile::Open(TString(inputFilename)); + + TTree *EventInfo = (TTree *)input->Get("EventInfo"); + int EventsEventInfo = EventInfo->GetEntries(); + + std::vector *ADCProcessed = 0; + TBranch *b_ADCProcessed = 0; + EventInfo->SetBranchAddress("ADCProcessed",&ADCProcessed,&b_ADCProcessed); + + cout << "Open output ROOT file " << outputFilename << endl; + TFile *output = TFile::Open(TString(outputFilename),"RECREATE"); + + //================================================================== + // + // Canvases. + // + + TCanvas *cmap = new TCanvas("cmap","",400,300); + TCanvas *cmapConnected = new TCanvas("cmapConnected","",400,300); + + //================================================================== + // + // Histograms. + // + + TH1F *hmap = new TH1F("hmap","",N,0,N); + TH1F *hmapConnected = new TH1F("hmapConnected","",N/4,0,N); + + InitHist(hmap,"Hit map - all Beetle channels","Beetle channel",""); + InitHist(hmapConnected,"Hit map - Beetle channels connected to Si","Beetle channel",""); + + //================================================================== + // + // Fill histograms. + // + + for (int iEvent=0;iEventGetEntry(iEvent); + for(int iChannel=0;iChannelFill(iChannel,ADCProcessed->at(iChannel)); + if (iChannel%NSkip==0) + { + hmapConnected->Fill(iChannel,ADCProcessed->at(iChannel)); + } + } + } + + hmap->Scale(1./EventsEventInfo); + hmapConnected->Scale(1./EventsEventInfo); + + *strip = hmap->GetMaximumBin()-1; + cout << "Beetle channel with the maximum ADC count: " << *strip << endl; + int max = hmap->GetMaximum(); + cout << "Maximum ADC count: " << max << endl; + int stripLeft = *strip-NSkip; + int left = hmap->GetBinContent(stripLeft+1); // The +1 is necessary to take the number scheme of the histogram into account. + int stripRight = *strip+NSkip; + int right = hmap->GetBinContent(stripRight+1); // The +1 is necessary to take the number scheme of the histogram into account. + cout << "Adjacent Beetle channel on the left: " << stripLeft << ", " << left << endl; + cout << "Adjacent Beetle channel on the right: " << stripRight << ", " << right << endl; + if (left < right) + *direction = "right"; + else + *direction = "left"; + cout << "More signal on the " << *direction << endl; + + //================================================================== + // + // Style. + // + + //================================================================== + // + // Draw histograms, stats, legends, ... and write output pdf files. + // + + DrawHist(cmap,hmap,"",path_to_figures); + DrawHist(cmapConnected,hmapConnected,"",path_to_figures); + + //================================================================== + // + // Write output ROOT files. + // + + output->Write(); + + //================================================================== + // + // Close input and output files. + // + + input->Close(); + output->Close(); + + return; +} + +#endif diff --git a/Software/Tools/Lib.C b/Software/Tools/Lib.C index d015d1c..d926473 100644 --- a/Software/Tools/Lib.C +++ b/Software/Tools/Lib.C @@ -45,6 +45,8 @@ #include #include +// #include +#include #include #include #include diff --git a/Software/Tools/Style.C b/Software/Tools/Style.C index cfbd494..168dcc1 100644 --- a/Software/Tools/Style.C +++ b/Software/Tools/Style.C @@ -398,6 +398,7 @@ canvas->SetTickx(1); canvas->SetTicky(1); graph->Draw(option); + graph->SetFillColor(38); graph->SetMarkerSize(1); graph->SetMarkerStyle(20); graph->SetMarkerColor(1); diff --git a/Software/Tools/Useful.C b/Software/Tools/Useful.C new file mode 100644 index 0000000..cbe6bf7 --- /dev/null +++ b/Software/Tools/Useful.C @@ -0,0 +1,35 @@ +//************************************************ +// Author: Federica Lionetto +// Created on: 06/11/2014 +//************************************************ + +/* +List of useful tools. +*/ + +// Header guard. +#ifndef __USEFUL_C_INCLUDED__ +#define __USEFUL_C_INCLUDED__ + +#include "Lib.C" + +//************************************************ +// +// Declarations. +// + +// bool file_exists(const char *filename); + +//************************************************ +// +// Definitions. +// + +/* +bool file_exists(const char *filename) { + ifstream ifile(filename); + return ifile; +} +*/ + +#endif