new file: BP_analysis_M431.cpp

new file:   BP_analysis_thinSensors.cpp
	new file:   BP_fit.cpp
	new file:   BP_fit_M431.cpp
	new file:   BP_fit_thin.cpp
	new file:   BP_scan_both_speeds.sh
	new file:   BP_scan_thinSensor.sh
	new file:   CS_analysis_M431.cpp
	new file:   CS_analysis_M439.cpp
	new file:   CS_fit.cpp
	new file:   CS_fit_M431
	new file:   CS_fit_M431.cpp
	new file:   CS_scan_both_speeds.sh
	new file:   CuFluo_exposure_both_speeds.sh
	new file:   CuFluo_fit.cpp
	new file:   Default_pixels_arrays.cpp
This commit is contained in:
2025-06-27 11:16:26 +02:00
parent ed18504809
commit 73938aad04
16 changed files with 12176 additions and 0 deletions

1119
BP_analysis_M431.cpp Normal file

File diff suppressed because it is too large Load Diff

1110
BP_analysis_thinSensors.cpp Normal file

File diff suppressed because it is too large Load Diff

520
BP_fit.cpp Normal file
View File

@ -0,0 +1,520 @@
// to analyse the backplane pulsing data per module
// changes by VH 210906: to eliminate hardcoded absolute paths, uses location of the analysis root files as additional input argument (accordingly changed in filename_creator.sh)
#include "TApplication.h"
#include "sls_detector_calibration/jungfrauCommonHeader.h"
#include "sls_detector_calibration/jungfrauCommonFunctions.h"
#include "sls_detector_calibration/jungfrauFile.C"
#include "sls_detector_calibration/jungfrauPedestal.C"
#include "TGraphErrors.h"
#include "TF1.h"
#include "TStyle.h"
#include "TPaveStats.h"
#include "TFile.h"
#include "TLegend.h"
#include "TPaveText.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
#include "TSystem.h"
#include "TF2.h"
#include <sys/stat.h>
#include <sstream>
//#define NB_ENABLE 1
//void nonblock(int state);
//#define NB_DISABLE 0
//TApplication* rootapp;
//TCanvas *A2;
//TCanvas *A3;
//TCanvas *A4;
//TCanvas *A5;
//TCanvas *A6;
TGraphErrors *grap_g0;
TGraphErrors *grap_g1;
TF1 *fit_g0=0;
TF1 *fit_g1=0;
TGraphErrors *norm_g0=0;
TGraphErrors *norm_g1=0;
TF1 *flat_g0;
TF1 *flat_g1;
TF1 *lin_g0_p1pc;
TF1 *lin_g0_p05pc;
TF1 *lin_g0_p02pc;
TF1 *lin_g0_m1pc;
TF1 *lin_g0_m05pc;
TF1 *lin_g0_m02pc;
TF1 *lin_g1_p02pc;
TF1 *lin_g1_p01pc;
TF1 *lin_g1_m02pc;
TF1 *lin_g1_m01pc;
//TPaveStats *st0;
//void PlotCanvas(void);
double checkRangeMaxForAmplifierPlateau(double range_max) {
// check that the range maximum is no more than 6.4 V
// to avoid non-linearity coming from amplifier plateau
if (range_max > 6400) {
return 6400;
} else {
return range_max;
}
}
bool isHGX=false;
int main(int argc, char* argv[]) {
//nonblock(NB_ENABLE);
cout <<"opening the rootapp" <<endl;
TApplication rootapp("example",&argc, argv);
jungfrauStyle();
//gROOT->SetBatch(1);
gStyle->SetOptFit(11);
/*
if (argc != 3) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "arg 2: specify data location" << endl;
cout << "arg 3: specify column (x)" << endl;
cout << "arg 4: specify row (y)" << endl;
exit(1);
}
*/ //uncomment for SR
if (argc != 4) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "arg 2: specify pixel x position" << endl;
cout << "arg 3: specify pixel y position" << endl;
exit(1);
} //uncomment for VH 210906
string module_str = argv[1];
string str2 =("HG0G1G2");
string str3 =("HGOG1G2"); //filename creator had this bug
string C = argv[2];
string R = argv[3];
int column;
int row;
std::stringstream(C) >> column;
std::stringstream(R) >> row;
int pixel = column+row*1024;
char data_loc[256];
sprintf(data_loc,"/mnt/sls_det_storage/jungfrau_calib/jungfrau_ana_sophie/M%s_CalibAna/", module_str.c_str());
cout << data_loc << endl;
std::string folder_path(data_loc);
if (folder_path.find(str2) != string::npos) isHGX=true;
if (folder_path.find(str3) != string::npos) isHGX=true;
// cout << data_loc.find(str2)<<" " << string::npos << " " << str2 << " " << data_loc <<endl;
if (isHGX) {
cout << " HG0->HG1->HG2 sequence - dynamicHG0" <<endl;
// plotfolder_str="BackplanePulsing_HG0G1G2";
}
else {
cout << " G0->G1->G2 sequence - dynamicG0" <<endl;
// plotfolder_str="BackplanePulsing";
}
std::vector<double> G0_pixel(220, 0);
std::vector<double> G0_err_pixel(220, 0);
std::vector<double> G1_pixel(220, 0);
std::vector<double> G1_err_pixel(220, 0);
//char savename[128]; //uncomment for SR
//char filename[128]; //uncomment for SR
char filename[256]; //uncomment for VH 210902
// create necessary directories with permissions drwxrwxr-x
// data/Mxxx
//sprintf(savename,"data/M%s", module_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// plots/Mxxx
//sprintf(savename,"plots/M%s", module_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// plots/Mxxx/BackplanePulsing
//sprintf(savename,"plots/M%s/%s", module_str.c_str(), plotfolder_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// /mnt/pcmoench_jungfrau_data/jungfrau_ana_sophie/Mxxx_CalibAna
//sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna", module_str.c_str()); //uncomment for SR
//sprintf(savename,"%s", anadata_loc.c_str()); //uncomment for VH 210906
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
double xs[220];
for (int i = 0; i < 100; i++) {
xs[i] = (i+1)*10.;
}
for (int i = 0; i < 120; i++) {
xs[i+100] = 1000+((i+1)*50);
}
TCanvas *A2 = new TCanvas("A2","Plot scan",150,10,800,400);
TCanvas *A3 = new TCanvas("A3","Plot G0 fit",150,10,800,400);
TCanvas *A4 = new TCanvas("A4","Plot G0 residuals",150,10,800,400);
TCanvas *A5 = new TCanvas("A5","Plot G1 fit",150,10,800,400);
TCanvas *A6 = new TCanvas("A6","Plot G1 residuals",150,10,800,400);
//file name
sprintf(filename,"%sBP_histos_M%s.root",folder_path.c_str(), module_str.c_str());
cout << "Loading file " << filename << endl;
TFile* f = new TFile((const char *)(filename),"READ");
for (int j = 0; j < 220; j++) {
TH2F* hist0=(TH2F*)f->Get(Form("avg_adcG0_map_%d",j));
G0_pixel[j]=hist0->GetBinContent((column+1),(row+1));
TH2F* hist0er=(TH2F*)f->Get(Form("avg_adcG0er_map_%d",j));
G0_err_pixel[j]=hist0er->GetBinContent((column+1),(row+1));
TH2F* hist1=(TH2F*)f->Get(Form("avg_adcG1_map_%d",j));
G1_pixel[j]=hist1->GetBinContent((column+1),(row+1));
TH2F* hist1er=(TH2F*)f->Get(Form("avg_adcG1er_map_%d",j));
G1_err_pixel[j]=hist1er->GetBinContent((column+1),(row+1));
//cout << "Data for pixel "<< pixel << "is loaded" << endl;
}
A2->SetLeftMargin(0.13);
A2->SetRightMargin(0.05);
vector<double> r0_adc;
vector<double> r0_filter;
vector<double> r0_adcerr;
vector<double> r0_ferr;
vector<double> r1_adc;
vector<double> r1_filter;
vector<double> r1_adcerr;
vector<double> r1_ferr;
for (int j = 0; j < 220; j++) {
if (G0_pixel[j] != 0) {
r0_filter.push_back(xs[j]);
r0_ferr.push_back(0.);
r0_adc.push_back(G0_pixel[j]);
r0_adcerr.push_back(G0_err_pixel[j]);
}
if (G1_pixel[j] != 0) {
r1_filter.push_back(xs[j]);
r1_ferr.push_back(0.);
r1_adc.push_back(G1_pixel[j]);
r1_adcerr.push_back(G1_err_pixel[j]);
}
cout << "Filter array is loaded" << endl;
}
//TGraphErrors *grap_g0 = 0;
//TGraphErrors *grap_g1 = 0;
//TF1 *fit_g0 = 0;
//TF1 *fit_g1 = 0;
double rangemin_g0 = 0;
double rangemax_g0 = 0;
double rangemin_g1 = 0;
double rangemax_g1 = 0;
A2->cd();
// define graphs
if (r0_adc.size() > 1) {
grap_g0 = new TGraphErrors(r0_adc.size(),&(r0_filter[0]),&(r0_adc[0]),&(r0_ferr[0]),&(r0_adcerr[0]));
grap_g0->SetMarkerStyle(20);
grap_g0->SetMarkerColor(kBlue);
grap_g0->SetLineColor(kBlue);
}
if (r1_adc.size() > 1) {
grap_g1 = new TGraphErrors(r1_adc.size(),&(r1_filter[0]),&(r1_adc[0]),&(r1_ferr[0]),&(r1_adcerr[0]));
grap_g1->SetMarkerStyle(20);
grap_g1->SetMarkerColor(kGreen+2);
grap_g1->SetLineColor(kGreen+2);
}
//debug
// cout << i <<" r0size= "<< r0_adc.size()<< " r1size= "<< r1_adc.size()<< endl;
// plot the datapoints
if (r1_adc.size() > 1) {
grap_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g1->GetYaxis()->SetTitle("ADC [ADU]");
grap_g1->GetYaxis()->SetTitleOffset(0.9);
grap_g1->SetMinimum(1000);
grap_g1->SetMaximum(15000);
grap_g1->GetXaxis()->SetLimits(0,7200);
grap_g1->Draw("AP");
if (r0_adc.size() > 1) {
grap_g0->Draw("P");
A2->Update();
}
//cout << "Number of point in g1 =" << r1_adc.size() << endl;
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_M%s.png", module_str.c_str(), plotfolder_str.c_str(),pixel_type.c_str(), i,module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
}
// define fit ranges and fit
if (r0_adc.size() > 1) {
A3->cd();
rangemin_g0 = *min_element(r0_filter.begin(),r0_filter.end());
rangemax_g0 = highestPointBeforeSwitching(r0_filter,r1_filter);
if (rangemax_g0 > rangemin_g0) {
grap_g0->Fit("pol1","QRC","",rangemin_g0,rangemax_g0);
fit_g0 = (TF1*) grap_g0->GetFunction("pol1");
if (fit_g0) {
fit_g0->SetLineColor(kBlue);
fit_g0->SetParName(0,"G0 const");
fit_g0->SetParName(1,"G0 grad");
grap_g0->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g0->GetYaxis()->SetTitle("ADC [ADU]");
grap_g0->GetYaxis()->SetTitleOffset(0.9);
grap_g0->SetMinimum(1000);
grap_g0->SetMaximum(15000);
grap_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end()));
// TPaveStats *st0 = (TPaveStats*)grap_g0->FindObject("stats");
// st0->SetX1NDC(0.2);
// st0->SetX2NDC(0.54);
// st0->SetY1NDC(0.18);
// st0->SetY2NDC(0.37);
// st0->SetBorderSize(0);
// st0->SetTextColor(kBlue);
grap_g0->Draw("AP");
fit_g0->Draw("same");
A3->Update();
//PlotCanvas();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g0_M%s.png", module_str.c_str(),plotfolder_str.c_str(), pixel_type.c_str(), i,module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
A4->cd();
vector<double> r0_adc_norm;
for (size_t j = 0; j < r0_adc.size(); j++) {
r0_adc_norm.push_back(r0_adc[j] - fit_g0->Eval(r0_filter[j]));
}
TGraphErrors *norm_g0 = new TGraphErrors(r0_adc.size(),&(r0_filter[0]),&(r0_adc_norm[0]),&(r0_ferr[0]),&(r0_adcerr[0]));
norm_g0->SetMarkerColor(kBlue);
norm_g0->SetLineColor(kBlue);
TF1* flat_g0 = new TF1("flat_g0","0",rangemin_g0,rangemax_g0);
flat_g0->SetLineColor(kBlue);
TF1* lin_g0_p1pc = new TF1("lin_g0_p1pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p1pc->SetParameter(0,fit_g0->GetParameter(0)/100.);
lin_g0_p1pc->SetParameter(1,fit_g0->GetParameter(1)/100.);
lin_g0_p1pc->SetLineColor(kRed);
TF1* lin_g0_p05pc = new TF1("lin_g0_p05pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p05pc->SetParameter(0,fit_g0->GetParameter(0)/200.);
lin_g0_p05pc->SetParameter(1,fit_g0->GetParameter(1)/200.);
lin_g0_p05pc->SetLineColor(kOrange+1);
TF1* lin_g0_p02pc = new TF1("lin_g0_p02pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p02pc->SetParameter(0,fit_g0->GetParameter(0)/500.);
lin_g0_p02pc->SetParameter(1,fit_g0->GetParameter(1)/500.);
lin_g0_p02pc->SetLineColor(kOrange);
TF1* lin_g0_m1pc = new TF1("lin_g0_m1pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m1pc->SetParameter(0,fit_g0->GetParameter(0)/-100.);
lin_g0_m1pc->SetParameter(1,fit_g0->GetParameter(1)/-100.);
lin_g0_m1pc->SetLineColor(kRed);
TF1* lin_g0_m05pc = new TF1("lin_g0_m05pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m05pc->SetParameter(0,fit_g0->GetParameter(0)/-200.);
lin_g0_m05pc->SetParameter(1,fit_g0->GetParameter(1)/-200.);
lin_g0_m05pc->SetLineColor(kOrange+1);
TF1* lin_g0_m02pc = new TF1("lin_g0_m02pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m02pc->SetParameter(0,fit_g0->GetParameter(0)/-500.);
lin_g0_m02pc->SetParameter(1,fit_g0->GetParameter(1)/-500.);
lin_g0_m02pc->SetLineColor(kOrange);
norm_g0->GetXaxis()->SetRangeUser(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end()));
norm_g0->SetMinimum(1.5*lin_g0_m02pc->Eval(rangemax_g0));
norm_g0->SetMaximum(1.5*lin_g0_p02pc->Eval(rangemax_g0));
if (isHGX) {
norm_g0->SetMinimum(3*lin_g0_m02pc->Eval(rangemax_g0));
norm_g0->SetMaximum(3*lin_g0_p02pc->Eval(rangemax_g0));
}
norm_g0->GetXaxis()->SetTitle("Signal generator voltage [mV]");
norm_g0->GetYaxis()->SetTitle("Normalised ADC [ADU]");
norm_g0->GetYaxis()->SetTitleOffset(0.9);
norm_g0->Draw("AP");
flat_g0->Draw("same");
lin_g0_p1pc->Draw("same");
lin_g0_p05pc->Draw("same");
lin_g0_p02pc->Draw("same");
lin_g0_m1pc->Draw("same");
lin_g0_m05pc->Draw("same");
lin_g0_m02pc->Draw("same");
norm_g0->Draw("P");
A4->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g0norm_M%s.png", module_str.c_str(), plotfolder_str.c_str(),pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
//delete norm_g0;
}
}
}
A5->cd();
if (r1_adc.size() > 1) {
rangemin_g1 = lowestPointAfterSwitching(r1_filter,r0_filter);
rangemax_g1 = *max_element(r1_filter.begin(),r1_filter.end());
rangemax_g1 = checkRangeMaxForAmplifierPlateau(rangemax_g1);
if (rangemax_g1 > rangemin_g1) {
grap_g1->Fit("pol1","QRC","",rangemin_g1,rangemax_g1);
fit_g1 = (TF1*) grap_g1->GetFunction("pol1");
if (fit_g1) {
fit_g1->SetLineColor(kGreen+2);
fit_g1->SetParName(0,"G1 const");
fit_g1->SetParName(1,"G1 grad");
grap_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g1->GetYaxis()->SetTitle("ADC [ADU]");
grap_g1->GetYaxis()->SetTitleOffset(0.9);
grap_g1->SetMinimum(1000);
grap_g1->SetMaximum(15000);
grap_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end()));
// TPaveStats *st0 = (TPaveStats*)grap_g1->FindObject("stats");
// st0->SetX1NDC(0.6);
// st0->SetX2NDC(0.94);
// st0->SetY1NDC(0.18);
// st0->SetY2NDC(0.37);
// st0->SetBorderSize(0);
// st0->SetTextColor(kGreen+2);
grap_g1->Draw("AP");
fit_g1->Draw("same");
A5->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g1_M%s.png", module_str.c_str(), plotfolder_str.c_str(), pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
vector<double> r1_adc_norm;
for (size_t j = 0; j < r1_adc.size(); j++) {
r1_adc_norm.push_back(r1_adc[j] - fit_g1->Eval(r1_filter[j]));
}
A6->cd();
TGraphErrors *norm_g1 = new TGraphErrors(r1_adc.size(),&(r1_filter[0]),&(r1_adc_norm[0]),&(r1_ferr[0]),&(r1_adcerr[0]));
norm_g1->SetMarkerColor(kGreen+2);
norm_g1->SetLineColor(kGreen+2);
TF1* flat_g1 = new TF1("flat_gi","0",rangemin_g1,rangemax_g1);
flat_g1->SetLineColor(kGreen+2);
TF1* lin_g1_p02pc = new TF1("lin_g1_p02pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_p02pc->SetParameter(0,fit_g1->GetParameter(0)/500.);
lin_g1_p02pc->SetParameter(1,fit_g1->GetParameter(1)/500.);
lin_g1_p02pc->SetLineColor(kOrange);
TF1* lin_g1_p01pc = new TF1("lin_g1_p01pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_p01pc->SetParameter(0,fit_g1->GetParameter(0)/1000.);
lin_g1_p01pc->SetParameter(1,fit_g1->GetParameter(1)/1000.);
lin_g1_p01pc->SetLineColor(kYellow);
TF1* lin_g1_m02pc = new TF1("lin_g1_m02pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_m02pc->SetParameter(0,fit_g1->GetParameter(0)/-500.);
lin_g1_m02pc->SetParameter(1,fit_g1->GetParameter(1)/-500.);
lin_g1_m02pc->SetLineColor(kOrange);
TF1* lin_g1_m01pc = new TF1("lin_g1_m01pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_m01pc->SetParameter(0,fit_g1->GetParameter(0)/-1000.);
lin_g1_m01pc->SetParameter(1,fit_g1->GetParameter(1)/-1000.);
lin_g1_m01pc->SetLineColor(kYellow);
norm_g1->GetXaxis()->SetRangeUser(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end()));
norm_g1->SetMinimum(1.5*lin_g1_m02pc->Eval(rangemin_g1));
norm_g1->SetMaximum(1.5*lin_g1_p02pc->Eval(rangemin_g1));
norm_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
norm_g1->GetYaxis()->SetTitle("Normalised ADC [ADU]");
norm_g1->GetYaxis()->SetTitleOffset(0.9);
norm_g1->Draw("AP");
flat_g1->Draw("same");
lin_g1_p02pc->Draw("same");
lin_g1_p01pc->Draw("same");
lin_g1_m02pc->Draw("same");
lin_g1_m01pc->Draw("same");
norm_g1->Draw("P");
A6->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g1norm_M%s.png", module_str.c_str(),plotfolder_str.c_str(), pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
//delete norm_g1;
}
}
}
// get ratio measurements
// if (fit_g0 && fit_g1) {
// double this_g0overg1 = fit_g0->GetParameter(1)/fit_g1->GetParameter(1);
// double this_g0overg1er = sqrt(pow(fit_g0->GetParError(1)/fit_g0->GetParameter(1),2) + pow(fit_g1->GetParError(1)/fit_g1->GetParameter(1),2));
// cout << "G0overG1 =" << this_g0overg1 << "+/-" << this_g0overg1er << endl;
// }
rootapp.Run();
return 0;
}

550
BP_fit_M431.cpp Normal file
View File

@ -0,0 +1,550 @@
// to analyse the backplane pulsing data per module
// changes by VH 210906: to eliminate hardcoded absolute paths, uses location of the analysis root files as additional input argument (accordingly changed in filename_creator.sh)
#include "TApplication.h"
#include "sls_detector_calibration/jungfrauCommonHeader.h"
#include "sls_detector_calibration/jungfrauCommonFunctions.h"
#include "sls_detector_calibration/jungfrauFile.C"
#include "sls_detector_calibration/jungfrauPedestal.C"
#include "TGraphErrors.h"
#include "TF1.h"
#include "TStyle.h"
#include "TPaveStats.h"
#include "TFile.h"
#include "TLegend.h"
#include "TPaveText.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
#include "TSystem.h"
#include "TF2.h"
#include "TGaxis.h"
#include <sys/stat.h>
#include <sstream>
#include <algorithm>
//#define NB_ENABLE 1
//void nonblock(int state);
//#define NB_DISABLE 0
//TApplication* rootapp;
//TCanvas *A2;
//TCanvas *A3;
//TCanvas *A4;
//TCanvas *A5;
//TCanvas *A6;
TGraphErrors *grap_g0;
TGraphErrors *grap_g1;
TF1 *fit_g0=0;
TF1 *fit_g1=0;
TGraphErrors *norm_g0=0;
TGraphErrors *norm_g1=0;
TF1 *flat_g0;
TF1 *flat_g1;
TF1 *lin_g0_p1pc;
TF1 *lin_g0_p05pc;
TF1 *lin_g0_p02pc;
TF1 *lin_g0_m1pc;
TF1 *lin_g0_m05pc;
TF1 *lin_g0_m02pc;
TF1 *lin_g1_p02pc;
TF1 *lin_g1_p01pc;
TF1 *lin_g1_m02pc;
TF1 *lin_g1_m01pc;
//TPaveStats *st0;
//void PlotCanvas(void);
double checkRangeMaxForAmplifierPlateau(double range_max) {
// check that the range maximum is no more than 6.4 V
// to avoid non-linearity coming from amplifier plateau
if (range_max > 6400) {
return 6400;
} else {
return range_max;
}
}
bool isHGX=false;
int main(int argc, char* argv[]) {
//nonblock(NB_ENABLE);
cout <<"opening the rootapp" <<endl;
TApplication rootapp("example",&argc, argv);
jungfrauStyle();
//gROOT->SetBatch(1);
gStyle->SetOptFit(11);
/*
if (argc != 3) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "arg 2: specify data location" << endl;
cout << "arg 3: specify column (x)" << endl;
cout << "arg 4: specify row (y)" << endl;
exit(1);
}
*/ //uncomment for SR
if (argc != 4) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "arg 2: specify pixel x position" << endl;
cout << "arg 3: specify pixel y position" << endl;
exit(1);
} //uncomment for VH 210906
string module_str = argv[1];
string str2 =("HG0G1G2");
string str3 =("HGOG1G2"); //filename creator had this bug
string C = argv[2];
string R = argv[3];
int column;
int row;
std::stringstream(C) >> column;
std::stringstream(R) >> row;
int pixel = column+row*1024;
char data_loc[256];
sprintf(data_loc,"/mnt/sls_det_storage/jungfrau_calib/jungfrau_ana_sophie/M%s_CalibAna/", module_str.c_str());
cout << data_loc << endl;
std::string folder_path(data_loc);
if (folder_path.find(str2) != string::npos) isHGX=true;
if (folder_path.find(str3) != string::npos) isHGX=true;
// cout << data_loc.find(str2)<<" " << string::npos << " " << str2 << " " << data_loc <<endl;
if (isHGX) {
cout << " HG0->HG1->HG2 sequence - dynamicHG0" <<endl;
// plotfolder_str="BackplanePulsing_HG0G1G2";
}
else {
cout << " G0->G1->G2 sequence - dynamicG0" <<endl;
// plotfolder_str="BackplanePulsing";
}
std::vector<double> G0_pixel(220, 0);
std::vector<double> G0_err_pixel(220, 0);
std::vector<double> G1_pixel(220, 0);
std::vector<double> G1_err_pixel(220, 0);
//char savename[128]; //uncomment for SR
//char filename[128]; //uncomment for SR
char filename[256]; //uncomment for VH 210902
// create necessary directories with permissions drwxrwxr-x
// data/Mxxx
//sprintf(savename,"data/M%s", module_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// plots/Mxxx
//sprintf(savename,"plots/M%s", module_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// plots/Mxxx/BackplanePulsing
//sprintf(savename,"plots/M%s/%s", module_str.c_str(), plotfolder_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// /mnt/pcmoench_jungfrau_data/jungfrau_ana_sophie/Mxxx_CalibAna
//sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna", module_str.c_str()); //uncomment for SR
//sprintf(savename,"%s", anadata_loc.c_str()); //uncomment for VH 210906
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
double xs[220];
for (int i = 0; i < 100; i++) {
//for (int i = 0; i < 220; i++) {
xs[i] = (i+1)*10.;
}
for (int i = 0; i < 120; i++) {
xs[i+100] = 1000+((i+1)*50);
}
TCanvas *A2 = new TCanvas("A2","Plot scan",150,10,800,400);
TCanvas *A3 = new TCanvas("A3","Plot G0 fit",150,10,800,400);
TCanvas *A4 = new TCanvas("A4","Plot G0 residuals",150,10,800,400);
TCanvas *A5 = new TCanvas("A5","Plot G1 fit",150,10,800,400);
TCanvas *A6 = new TCanvas("A6","Plot G1 residuals",150,10,800,400);
TCanvas *A7 = new TCanvas("A7","G0 linearity",150,10,800,400);
//file name
sprintf(filename,"%sBP_histos_M%s.root",folder_path.c_str(), module_str.c_str());
cout << "Loading file " << filename << endl;
TFile* f = new TFile((const char *)(filename),"READ");
for (int j = 0; j < 220; j++) {
TH2F* hist0=(TH2F*)f->Get(Form("avg_adcG0_map_%d",j));
G0_pixel[j]=hist0->GetBinContent((column+1),(row+1));
TH2F* hist0er=(TH2F*)f->Get(Form("avg_adcG0er_map_%d",j));
G0_err_pixel[j]=hist0er->GetBinContent((column+1),(row+1));
TH2F* hist1=(TH2F*)f->Get(Form("avg_adcG1_map_%d",j));
G1_pixel[j]=hist1->GetBinContent((column+1),(row+1));
TH2F* hist1er=(TH2F*)f->Get(Form("avg_adcG1er_map_%d",j));
G1_err_pixel[j]=hist1er->GetBinContent((column+1),(row+1));
//cout << "Data for pixel "<< pixel << "is loaded" << endl;
}
A2->SetLeftMargin(0.13);
A2->SetRightMargin(0.05);
vector<double> r0_adc;
vector<double> r0_filter;
vector<double> r0_adcerr;
vector<double> r0_ferr;
vector<double> r1_adc;
vector<double> r1_filter;
vector<double> r1_adcerr;
vector<double> r1_ferr;
for (int j = 0; j < 220; j++) {
//cout << "Pixel G0: " << G0_pixel[j] << ", pixel G1: " << G1_pixel[j] << endl;
if (G0_pixel[j] != 0) {
r0_filter.push_back(xs[j]);
r0_ferr.push_back(0.);
r0_adc.push_back(G0_pixel[j]);
r0_adcerr.push_back(G0_err_pixel[j]);
}
if (G1_pixel[j] != 0) {
r1_filter.push_back(xs[j]);
r1_ferr.push_back(0.);
r1_adc.push_back(G1_pixel[j]);
r1_adcerr.push_back(G1_err_pixel[j]);
}
//cout << "Filter array is loaded" << endl;
}
//TGraphErrors *grap_g0 = 0;
//TGraphErrors *grap_g1 = 0;
//TF1 *fit_g0 = 0;
//TF1 *fit_g1 = 0;
double rangemin_g0 = 0;
double rangemax_g0 = 0;
double rangemin_g1 = 0;
double rangemax_g1 = 0;
A2->cd();
// define graphs
if (r0_adc.size() > 1) {
grap_g0 = new TGraphErrors(r0_adc.size(),&(r0_filter[0]),&(r0_adc[0]),&(r0_ferr[0]),&(r0_adcerr[0]));
grap_g0->SetMarkerStyle(20);
grap_g0->SetMarkerColor(kBlue);
grap_g0->SetLineColor(kBlue);
}
if (r1_adc.size() > 1) {
grap_g1 = new TGraphErrors(r1_adc.size(),&(r1_filter[0]),&(r1_adc[0]),&(r1_ferr[0]),&(r1_adcerr[0]));
grap_g1->SetMarkerStyle(20);
grap_g1->SetMarkerColor(kGreen+2);
grap_g1->SetLineColor(kGreen+2);
}
//debug
cout <<" r0size= "<< r0_adc.size()<< " r1size= "<< r1_adc.size()<< endl;
// plot the datapoints
if (r1_adc.size() > 1) {
grap_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g1->GetYaxis()->SetTitle("ADC [ADU]");
grap_g1->GetYaxis()->SetTitleOffset(0.9);
grap_g1->SetMinimum(1000);
grap_g1->SetMaximum(20000);
grap_g1->GetXaxis()->SetLimits(0,7200);
grap_g1->Draw("AP");
if (r0_adc.size() > 1) {
grap_g0->Draw("P");
A2->Update();
}
//cout << "Number of point in g1 =" << r1_adc.size() << endl;
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_M%s.png", module_str.c_str(), plotfolder_str.c_str(),pixel_type.c_str(), i,module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
}
// define fit ranges and fit
if (r0_adc.size() > 1) {
A3->cd();
rangemin_g0 = *min_element(r0_filter.begin(),r0_filter.end());
rangemax_g0 = highestPointBeforeSwitching(r0_filter,r1_filter);
cout << "Switch point: " << rangemax_g0 << endl;
if (rangemax_g0 > rangemin_g0) {
grap_g0->Fit("pol1","QRC","",rangemin_g0,rangemax_g0);
fit_g0 = (TF1*) grap_g0->GetFunction("pol1");
if (fit_g0) {
fit_g0->SetLineColor(kBlue);
fit_g0->SetParName(0,"G0 const");
fit_g0->SetParName(1,"G0 grad");
grap_g0->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g0->GetYaxis()->SetTitle("ADC [ADU]");
grap_g0->GetYaxis()->SetTitleOffset(0.9);
grap_g0->SetMinimum(1000);
grap_g0->SetMaximum(15000);
grap_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end()));
// TPaveStats *st0 = (TPaveStats*)grap_g0->FindObject("stats");
// st0->SetX1NDC(0.2);
// st0->SetX2NDC(0.54);
// st0->SetY1NDC(0.18);
// st0->SetY2NDC(0.37);
// st0->SetBorderSize(0);
// st0->SetTextColor(kBlue);
grap_g0->Draw("AP");
fit_g0->Draw("same");
A3->Update();
//PlotCanvas();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g0_M%s.png", module_str.c_str(),plotfolder_str.c_str(), pixel_type.c_str(), i,module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
A4->cd();
vector<double> r0_adc_norm;
for (size_t j = 0; j < r0_adc.size(); j++) {
r0_adc_norm.push_back(r0_adc[j] - fit_g0->Eval(r0_filter[j]));
}
TGraphErrors *norm_g0 = new TGraphErrors(r0_adc.size(),&(r0_filter[0]),&(r0_adc_norm[0]),&(r0_ferr[0]),&(r0_adcerr[0]));
norm_g0->SetMarkerColor(kBlue);
norm_g0->SetLineColor(kBlue);
TF1* flat_g0 = new TF1("flat_g0","0",rangemin_g0,rangemax_g0);
flat_g0->SetLineColor(kBlue);
TF1* lin_g0_p1pc = new TF1("lin_g0_p1pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p1pc->SetParameter(0,fit_g0->GetParameter(0)/100.);
lin_g0_p1pc->SetParameter(1,fit_g0->GetParameter(1)/100.);
lin_g0_p1pc->SetLineColor(kRed);
TF1* lin_g0_p05pc = new TF1("lin_g0_p05pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p05pc->SetParameter(0,fit_g0->GetParameter(0)/200.);
lin_g0_p05pc->SetParameter(1,fit_g0->GetParameter(1)/200.);
lin_g0_p05pc->SetLineColor(kOrange+1);
TF1* lin_g0_p02pc = new TF1("lin_g0_p02pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p02pc->SetParameter(0,fit_g0->GetParameter(0)/500.);
lin_g0_p02pc->SetParameter(1,fit_g0->GetParameter(1)/500.);
lin_g0_p02pc->SetLineColor(kOrange);
TF1* lin_g0_m1pc = new TF1("lin_g0_m1pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m1pc->SetParameter(0,fit_g0->GetParameter(0)/-100.);
lin_g0_m1pc->SetParameter(1,fit_g0->GetParameter(1)/-100.);
lin_g0_m1pc->SetLineColor(kRed);
TF1* lin_g0_m05pc = new TF1("lin_g0_m05pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m05pc->SetParameter(0,fit_g0->GetParameter(0)/-200.);
lin_g0_m05pc->SetParameter(1,fit_g0->GetParameter(1)/-200.);
lin_g0_m05pc->SetLineColor(kOrange+1);
TF1* lin_g0_m02pc = new TF1("lin_g0_m02pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m02pc->SetParameter(0,fit_g0->GetParameter(0)/-500.);
lin_g0_m02pc->SetParameter(1,fit_g0->GetParameter(1)/-500.);
lin_g0_m02pc->SetLineColor(kOrange);
norm_g0->GetXaxis()->SetRangeUser(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end()));
norm_g0->SetMinimum(1.5*lin_g0_m02pc->Eval(rangemax_g0));
norm_g0->SetMaximum(1.5*lin_g0_p02pc->Eval(rangemax_g0));
if (isHGX) {
norm_g0->SetMinimum(3*lin_g0_m02pc->Eval(rangemax_g0));
norm_g0->SetMaximum(3*lin_g0_p02pc->Eval(rangemax_g0));
}
norm_g0->GetXaxis()->SetTitle("Signal generator voltage [mV]");
norm_g0->GetYaxis()->SetTitle("Normalised ADC [ADU]");
norm_g0->GetYaxis()->SetTitleOffset(0.9);
norm_g0->Draw("AP");
flat_g0->Draw("same");
lin_g0_p1pc->Draw("same");
lin_g0_p05pc->Draw("same");
lin_g0_p02pc->Draw("same");
lin_g0_m1pc->Draw("same");
lin_g0_m05pc->Draw("same");
lin_g0_m02pc->Draw("same");
norm_g0->Draw("P");
A4->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g0norm_M%s.png", module_str.c_str(), plotfolder_str.c_str(),pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
//delete norm_g0;
}
}
}
A5->cd();
if (r1_adc.size() > 1) {
rangemin_g1 = lowestPointAfterSwitching(r1_filter,r0_filter);
rangemax_g1 = *max_element(r1_filter.begin(),r1_filter.end());
// Added to fit first linear range, JF1.2
//rangemax_g1 = std::min(rangemax_g1, 2200.);
rangemax_g1 = checkRangeMaxForAmplifierPlateau(rangemax_g1);
if (rangemax_g1 > rangemin_g1) {
grap_g1->Fit("pol1","QRC","",rangemin_g1,rangemax_g1);
fit_g1 = (TF1*) grap_g1->GetFunction("pol1");
if (fit_g1) {
fit_g1->SetLineColor(kGreen+2);
fit_g1->SetParName(0,"G1 const");
fit_g1->SetParName(1,"G1 grad");
grap_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g1->GetYaxis()->SetTitle("ADC [ADU]");
grap_g1->GetYaxis()->SetTitleOffset(0.9);
grap_g1->SetMinimum(1000);
grap_g1->SetMaximum(15000);
grap_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end()));
// TPaveStats *st0 = (TPaveStats*)grap_g1->FindObject("stats");
// st0->SetX1NDC(0.6);
// st0->SetX2NDC(0.94);
// st0->SetY1NDC(0.18);
// st0->SetY2NDC(0.37);
// st0->SetBorderSize(0);
// st0->SetTextColor(kGreen+2);
grap_g1->Draw("AP");
fit_g1->Draw("same");
A5->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g1_M%s.png", module_str.c_str(), plotfolder_str.c_str(), pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
vector<double> r1_adc_norm;
for (size_t j = 0; j < r1_adc.size(); j++) {
r1_adc_norm.push_back(r1_adc[j] - fit_g1->Eval(r1_filter[j]));
}
A6->cd();
TGraphErrors *norm_g1 = new TGraphErrors(r1_adc.size(),&(r1_filter[0]),&(r1_adc_norm[0]),&(r1_ferr[0]),&(r1_adcerr[0]));
norm_g1->SetMarkerColor(kGreen+2);
norm_g1->SetLineColor(kGreen+2);
TF1* flat_g1 = new TF1("flat_gi","0",rangemin_g1,rangemax_g1);
flat_g1->SetLineColor(kGreen+2);
TF1* lin_g1_p02pc = new TF1("lin_g1_p02pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_p02pc->SetParameter(0,fit_g1->GetParameter(0)/500.);
lin_g1_p02pc->SetParameter(1,fit_g1->GetParameter(1)/500.);
lin_g1_p02pc->SetLineColor(kOrange);
TF1* lin_g1_p01pc = new TF1("lin_g1_p01pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_p01pc->SetParameter(0,fit_g1->GetParameter(0)/1000.);
lin_g1_p01pc->SetParameter(1,fit_g1->GetParameter(1)/1000.);
lin_g1_p01pc->SetLineColor(kYellow);
TF1* lin_g1_m02pc = new TF1("lin_g1_m02pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_m02pc->SetParameter(0,fit_g1->GetParameter(0)/-500.);
lin_g1_m02pc->SetParameter(1,fit_g1->GetParameter(1)/-500.);
lin_g1_m02pc->SetLineColor(kOrange);
TF1* lin_g1_m01pc = new TF1("lin_g1_m01pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_m01pc->SetParameter(0,fit_g1->GetParameter(0)/-1000.);
lin_g1_m01pc->SetParameter(1,fit_g1->GetParameter(1)/-1000.);
lin_g1_m01pc->SetLineColor(kYellow);
norm_g1->GetXaxis()->SetRangeUser(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end()));
norm_g1->SetMinimum(1.5*lin_g1_m02pc->Eval(rangemin_g1));
norm_g1->SetMaximum(1.5*lin_g1_p02pc->Eval(rangemin_g1));
norm_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
norm_g1->GetYaxis()->SetTitle("Normalised ADC [ADU]");
norm_g1->GetYaxis()->SetTitleOffset(0.9);
norm_g1->Draw("AP");
flat_g1->Draw("same");
lin_g1_p02pc->Draw("same");
lin_g1_p01pc->Draw("same");
lin_g1_m02pc->Draw("same");
lin_g1_m01pc->Draw("same");
norm_g1->Draw("P");
A6->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g1norm_M%s.png", module_str.c_str(),plotfolder_str.c_str(), pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
//delete norm_g1;
//
}
}
}
if(fit_g1){
A7->cd();
TGraph* linearityGraph = new TGraph();
double x, y;
for(size_t i = 0; i < grap_g1->GetN(); i++){
grap_g1->GetPoint(i, x, y);
auto ADU = y;
auto fitADU = fit_g1->Eval(x);
linearityGraph->SetPoint(i, ADU, fitADU - ADU);
}
//linearityGraph->GetXaxis()->SetTitle("Injected signal [mV]");
linearityGraph->GetXaxis()->SetTitle("Injected signal [ADU]");
linearityGraph->GetYaxis()->SetTitle("fit - signal [ADU]");
linearityGraph->SetMarkerStyle(20);
linearityGraph->SetMarkerColor(kGreen+2);
linearityGraph->SetLineColor(kGreen+2);
linearityGraph->Draw("AP");
A7->Update();
}
// get ratio measurements
// if (fit_g0 && fit_g1) {
// double this_g0overg1 = fit_g0->GetParameter(1)/fit_g1->GetParameter(1);
// double this_g0overg1er = sqrt(pow(fit_g0->GetParError(1)/fit_g0->GetParameter(1),2) + pow(fit_g1->GetParError(1)/fit_g1->GetParameter(1),2));
// cout << "G0overG1 =" << this_g0overg1 << "+/-" << this_g0overg1er << endl;
// }
rootapp.Run();
return 0;
}

520
BP_fit_thin.cpp Normal file
View File

@ -0,0 +1,520 @@
// to analyse the backplane pulsing data per module
// changes by VH 210906: to eliminate hardcoded absolute paths, uses location of the analysis root files as additional input argument (accordingly changed in filename_creator.sh)
#include "TApplication.h"
#include "sls_detector_calibration/jungfrauCommonHeader.h"
#include "sls_detector_calibration/jungfrauCommonFunctions.h"
#include "sls_detector_calibration/jungfrauFile.C"
#include "sls_detector_calibration/jungfrauPedestal.C"
#include "TGraphErrors.h"
#include "TF1.h"
#include "TStyle.h"
#include "TPaveStats.h"
#include "TFile.h"
#include "TLegend.h"
#include "TPaveText.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
#include "TSystem.h"
#include "TF2.h"
#include <sys/stat.h>
#include <sstream>
//#define NB_ENABLE 1
//void nonblock(int state);
//#define NB_DISABLE 0
//TApplication* rootapp;
//TCanvas *A2;
//TCanvas *A3;
//TCanvas *A4;
//TCanvas *A5;
//TCanvas *A6;
TGraphErrors *grap_g0;
TGraphErrors *grap_g1;
TF1 *fit_g0=0;
TF1 *fit_g1=0;
TGraphErrors *norm_g0=0;
TGraphErrors *norm_g1=0;
TF1 *flat_g0;
TF1 *flat_g1;
TF1 *lin_g0_p1pc;
TF1 *lin_g0_p05pc;
TF1 *lin_g0_p02pc;
TF1 *lin_g0_m1pc;
TF1 *lin_g0_m05pc;
TF1 *lin_g0_m02pc;
TF1 *lin_g1_p02pc;
TF1 *lin_g1_p01pc;
TF1 *lin_g1_m02pc;
TF1 *lin_g1_m01pc;
//TPaveStats *st0;
//void PlotCanvas(void);
double checkRangeMaxForAmplifierPlateau(double range_max) {
// check that the range maximum is no more than 6.4 V
// to avoid non-linearity coming from amplifier plateau
if (range_max > 6400) {
return 6400;
} else {
return range_max;
}
}
bool isHGX=false;
int main(int argc, char* argv[]) {
//nonblock(NB_ENABLE);
cout <<"opening the rootapp" <<endl;
TApplication rootapp("example",&argc, argv);
jungfrauStyle();
//gROOT->SetBatch(1);
gStyle->SetOptFit(11);
/*
if (argc != 3) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "arg 2: specify data location" << endl;
cout << "arg 3: specify column (x)" << endl;
cout << "arg 4: specify row (y)" << endl;
exit(1);
}
*/ //uncomment for SR
if (argc != 4) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "arg 2: specify pixel x position" << endl;
cout << "arg 3: specify pixel y position" << endl;
exit(1);
} //uncomment for VH 210906
string module_str = argv[1];
string str2 =("HG0G1G2");
string str3 =("HGOG1G2"); //filename creator had this bug
string C = argv[2];
string R = argv[3];
int column;
int row;
std::stringstream(C) >> column;
std::stringstream(R) >> row;
int pixel = column+row*1024;
char data_loc[256];
sprintf(data_loc,"/mnt/sls_det_storage/jungfrau_calib/jungfrau_ana_sophie/M%s_CalibAna/", module_str.c_str());
cout << data_loc << endl;
std::string folder_path(data_loc);
if (folder_path.find(str2) != string::npos) isHGX=true;
if (folder_path.find(str3) != string::npos) isHGX=true;
// cout << data_loc.find(str2)<<" " << string::npos << " " << str2 << " " << data_loc <<endl;
if (isHGX) {
cout << " HG0->HG1->HG2 sequence - dynamicHG0" <<endl;
// plotfolder_str="BackplanePulsing_HG0G1G2";
}
else {
cout << " G0->G1->G2 sequence - dynamicG0" <<endl;
// plotfolder_str="BackplanePulsing";
}
std::vector<double> G0_pixel(245, 0);
std::vector<double> G0_err_pixel(245, 0);
std::vector<double> G1_pixel(245, 0);
std::vector<double> G1_err_pixel(245, 0);
//char savename[128]; //uncomment for SR
//char filename[128]; //uncomment for SR
char filename[256]; //uncomment for VH 210902
// create necessary directories with permissions drwxrwxr-x
// data/Mxxx
//sprintf(savename,"data/M%s", module_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// plots/Mxxx
//sprintf(savename,"plots/M%s", module_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// plots/Mxxx/BackplanePulsing
//sprintf(savename,"plots/M%s/%s", module_str.c_str(), plotfolder_str.c_str());
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
// /mnt/pcmoench_jungfrau_data/jungfrau_ana_sophie/Mxxx_CalibAna
//sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna", module_str.c_str()); //uncomment for SR
//sprintf(savename,"%s", anadata_loc.c_str()); //uncomment for VH 210906
//mkdir(savename, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
double xs[245];
for (int i = 0; i < 139; i++) {
xs[i] = 10+i*5.;
}
for (int i = 0; i < 106; i++) {
xs[i+139] = 700+((i+1)*50);
}
TCanvas *A2 = new TCanvas("A2","Plot scan",150,10,800,400);
TCanvas *A3 = new TCanvas("A3","Plot G0 fit",150,10,800,400);
TCanvas *A4 = new TCanvas("A4","Plot G0 residuals",150,10,800,400);
TCanvas *A5 = new TCanvas("A5","Plot G1 fit",150,10,800,400);
TCanvas *A6 = new TCanvas("A6","Plot G1 residuals",150,10,800,400);
//file name
sprintf(filename,"%sBP_histos_M%s.root",folder_path.c_str(), module_str.c_str());
cout << "Loading file " << filename << endl;
TFile* f = new TFile((const char *)(filename),"READ");
for (int j = 0; j < 245; j++) {
TH2F* hist0=(TH2F*)f->Get(Form("avg_adcG0_map_%d",j));
G0_pixel[j]=hist0->GetBinContent((column+1),(row+1));
TH2F* hist0er=(TH2F*)f->Get(Form("avg_adcG0er_map_%d",j));
G0_err_pixel[j]=hist0er->GetBinContent((column+1),(row+1));
TH2F* hist1=(TH2F*)f->Get(Form("avg_adcG1_map_%d",j));
G1_pixel[j]=hist1->GetBinContent((column+1),(row+1));
TH2F* hist1er=(TH2F*)f->Get(Form("avg_adcG1er_map_%d",j));
G1_err_pixel[j]=hist1er->GetBinContent((column+1),(row+1));
//cout << "Data for pixel "<< pixel << "is loaded" << endl;
}
A2->SetLeftMargin(0.13);
A2->SetRightMargin(0.05);
vector<double> r0_adc;
vector<double> r0_filter;
vector<double> r0_adcerr;
vector<double> r0_ferr;
vector<double> r1_adc;
vector<double> r1_filter;
vector<double> r1_adcerr;
vector<double> r1_ferr;
for (int j = 0; j < 245; j++) {
if (G0_pixel[j] != 0) {
r0_filter.push_back(xs[j]);
r0_ferr.push_back(0.);
r0_adc.push_back(G0_pixel[j]);
r0_adcerr.push_back(G0_err_pixel[j]);
}
if (G1_pixel[j] != 0) {
r1_filter.push_back(xs[j]);
r1_ferr.push_back(0.);
r1_adc.push_back(G1_pixel[j]);
r1_adcerr.push_back(G1_err_pixel[j]);
}
cout << "Filter array is loaded" << endl;
}
//TGraphErrors *grap_g0 = 0;
//TGraphErrors *grap_g1 = 0;
//TF1 *fit_g0 = 0;
//TF1 *fit_g1 = 0;
double rangemin_g0 = 0;
double rangemax_g0 = 0;
double rangemin_g1 = 0;
double rangemax_g1 = 0;
A2->cd();
// define graphs
if (r0_adc.size() > 1) {
grap_g0 = new TGraphErrors(r0_adc.size(),&(r0_filter[0]),&(r0_adc[0]),&(r0_ferr[0]),&(r0_adcerr[0]));
grap_g0->SetMarkerStyle(20);
grap_g0->SetMarkerColor(kBlue);
grap_g0->SetLineColor(kBlue);
}
if (r1_adc.size() > 1) {
grap_g1 = new TGraphErrors(r1_adc.size(),&(r1_filter[0]),&(r1_adc[0]),&(r1_ferr[0]),&(r1_adcerr[0]));
grap_g1->SetMarkerStyle(20);
grap_g1->SetMarkerColor(kGreen+2);
grap_g1->SetLineColor(kGreen+2);
}
//debug
// cout << i <<" r0size= "<< r0_adc.size()<< " r1size= "<< r1_adc.size()<< endl;
// plot the datapoints
if (r1_adc.size() > 1) {
grap_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g1->GetYaxis()->SetTitle("ADC [ADU]");
grap_g1->GetYaxis()->SetTitleOffset(0.9);
grap_g1->SetMinimum(1000);
grap_g1->SetMaximum(15000);
grap_g1->GetXaxis()->SetLimits(0,7200);
grap_g1->Draw("AP");
if (r0_adc.size() > 1) {
grap_g0->Draw("P");
A2->Update();
}
//cout << "Number of point in g1 =" << r1_adc.size() << endl;
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_M%s.png", module_str.c_str(), plotfolder_str.c_str(),pixel_type.c_str(), i,module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
}
// define fit ranges and fit
if (r0_adc.size() > 1) {
A3->cd();
rangemin_g0 = *min_element(r0_filter.begin(),r0_filter.end());
rangemax_g0 = highestPointBeforeSwitching(r0_filter,r1_filter);
if (rangemax_g0 > rangemin_g0) {
grap_g0->Fit("pol1","QRC","",rangemin_g0,rangemax_g0);
fit_g0 = (TF1*) grap_g0->GetFunction("pol1");
if (fit_g0) {
fit_g0->SetLineColor(kBlue);
fit_g0->SetParName(0,"G0 const");
fit_g0->SetParName(1,"G0 grad");
grap_g0->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g0->GetYaxis()->SetTitle("ADC [ADU]");
grap_g0->GetYaxis()->SetTitleOffset(0.9);
grap_g0->SetMinimum(1000);
grap_g0->SetMaximum(15000);
grap_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end()));
// TPaveStats *st0 = (TPaveStats*)grap_g0->FindObject("stats");
// st0->SetX1NDC(0.2);
// st0->SetX2NDC(0.54);
// st0->SetY1NDC(0.18);
// st0->SetY2NDC(0.37);
// st0->SetBorderSize(0);
// st0->SetTextColor(kBlue);
grap_g0->Draw("AP");
fit_g0->Draw("same");
A3->Update();
//PlotCanvas();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g0_M%s.png", module_str.c_str(),plotfolder_str.c_str(), pixel_type.c_str(), i,module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
A4->cd();
vector<double> r0_adc_norm;
for (size_t j = 0; j < r0_adc.size(); j++) {
r0_adc_norm.push_back(r0_adc[j] - fit_g0->Eval(r0_filter[j]));
}
TGraphErrors *norm_g0 = new TGraphErrors(r0_adc.size(),&(r0_filter[0]),&(r0_adc_norm[0]),&(r0_ferr[0]),&(r0_adcerr[0]));
norm_g0->SetMarkerColor(kBlue);
norm_g0->SetLineColor(kBlue);
TF1* flat_g0 = new TF1("flat_g0","0",rangemin_g0,rangemax_g0);
flat_g0->SetLineColor(kBlue);
TF1* lin_g0_p1pc = new TF1("lin_g0_p1pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p1pc->SetParameter(0,fit_g0->GetParameter(0)/100.);
lin_g0_p1pc->SetParameter(1,fit_g0->GetParameter(1)/100.);
lin_g0_p1pc->SetLineColor(kRed);
TF1* lin_g0_p05pc = new TF1("lin_g0_p05pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p05pc->SetParameter(0,fit_g0->GetParameter(0)/200.);
lin_g0_p05pc->SetParameter(1,fit_g0->GetParameter(1)/200.);
lin_g0_p05pc->SetLineColor(kOrange+1);
TF1* lin_g0_p02pc = new TF1("lin_g0_p02pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_p02pc->SetParameter(0,fit_g0->GetParameter(0)/500.);
lin_g0_p02pc->SetParameter(1,fit_g0->GetParameter(1)/500.);
lin_g0_p02pc->SetLineColor(kOrange);
TF1* lin_g0_m1pc = new TF1("lin_g0_m1pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m1pc->SetParameter(0,fit_g0->GetParameter(0)/-100.);
lin_g0_m1pc->SetParameter(1,fit_g0->GetParameter(1)/-100.);
lin_g0_m1pc->SetLineColor(kRed);
TF1* lin_g0_m05pc = new TF1("lin_g0_m05pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m05pc->SetParameter(0,fit_g0->GetParameter(0)/-200.);
lin_g0_m05pc->SetParameter(1,fit_g0->GetParameter(1)/-200.);
lin_g0_m05pc->SetLineColor(kOrange+1);
TF1* lin_g0_m02pc = new TF1("lin_g0_m02pc","[0]+[1]*x",rangemin_g0,rangemax_g0);
lin_g0_m02pc->SetParameter(0,fit_g0->GetParameter(0)/-500.);
lin_g0_m02pc->SetParameter(1,fit_g0->GetParameter(1)/-500.);
lin_g0_m02pc->SetLineColor(kOrange);
norm_g0->GetXaxis()->SetRangeUser(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end()));
norm_g0->SetMinimum(1.5*lin_g0_m02pc->Eval(rangemax_g0));
norm_g0->SetMaximum(1.5*lin_g0_p02pc->Eval(rangemax_g0));
if (isHGX) {
norm_g0->SetMinimum(3*lin_g0_m02pc->Eval(rangemax_g0));
norm_g0->SetMaximum(3*lin_g0_p02pc->Eval(rangemax_g0));
}
norm_g0->GetXaxis()->SetTitle("Signal generator voltage [mV]");
norm_g0->GetYaxis()->SetTitle("Normalised ADC [ADU]");
norm_g0->GetYaxis()->SetTitleOffset(0.9);
norm_g0->Draw("AP");
flat_g0->Draw("same");
lin_g0_p1pc->Draw("same");
lin_g0_p05pc->Draw("same");
lin_g0_p02pc->Draw("same");
lin_g0_m1pc->Draw("same");
lin_g0_m05pc->Draw("same");
lin_g0_m02pc->Draw("same");
norm_g0->Draw("P");
A4->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g0norm_M%s.png", module_str.c_str(), plotfolder_str.c_str(),pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
//delete norm_g0;
}
}
}
A5->cd();
if (r1_adc.size() > 1) {
rangemin_g1 = lowestPointAfterSwitching(r1_filter,r0_filter);
rangemax_g1 = *max_element(r1_filter.begin(),r1_filter.end());
rangemax_g1 = checkRangeMaxForAmplifierPlateau(rangemax_g1);
if (rangemax_g1 > rangemin_g1) {
grap_g1->Fit("pol1","QRC","",rangemin_g1,rangemax_g1);
fit_g1 = (TF1*) grap_g1->GetFunction("pol1");
if (fit_g1) {
fit_g1->SetLineColor(kGreen+2);
fit_g1->SetParName(0,"G1 const");
fit_g1->SetParName(1,"G1 grad");
grap_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
grap_g1->GetYaxis()->SetTitle("ADC [ADU]");
grap_g1->GetYaxis()->SetTitleOffset(0.9);
grap_g1->SetMinimum(1000);
grap_g1->SetMaximum(15000);
grap_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end()));
// TPaveStats *st0 = (TPaveStats*)grap_g1->FindObject("stats");
// st0->SetX1NDC(0.6);
// st0->SetX2NDC(0.94);
// st0->SetY1NDC(0.18);
// st0->SetY2NDC(0.37);
// st0->SetBorderSize(0);
// st0->SetTextColor(kGreen+2);
grap_g1->Draw("AP");
fit_g1->Draw("same");
A5->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g1_M%s.png", module_str.c_str(), plotfolder_str.c_str(), pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
vector<double> r1_adc_norm;
for (size_t j = 0; j < r1_adc.size(); j++) {
r1_adc_norm.push_back(r1_adc[j] - fit_g1->Eval(r1_filter[j]));
}
A6->cd();
TGraphErrors *norm_g1 = new TGraphErrors(r1_adc.size(),&(r1_filter[0]),&(r1_adc_norm[0]),&(r1_ferr[0]),&(r1_adcerr[0]));
norm_g1->SetMarkerColor(kGreen+2);
norm_g1->SetLineColor(kGreen+2);
TF1* flat_g1 = new TF1("flat_gi","0",rangemin_g1,rangemax_g1);
flat_g1->SetLineColor(kGreen+2);
TF1* lin_g1_p02pc = new TF1("lin_g1_p02pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_p02pc->SetParameter(0,fit_g1->GetParameter(0)/500.);
lin_g1_p02pc->SetParameter(1,fit_g1->GetParameter(1)/500.);
lin_g1_p02pc->SetLineColor(kOrange);
TF1* lin_g1_p01pc = new TF1("lin_g1_p01pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_p01pc->SetParameter(0,fit_g1->GetParameter(0)/1000.);
lin_g1_p01pc->SetParameter(1,fit_g1->GetParameter(1)/1000.);
lin_g1_p01pc->SetLineColor(kYellow);
TF1* lin_g1_m02pc = new TF1("lin_g1_m02pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_m02pc->SetParameter(0,fit_g1->GetParameter(0)/-500.);
lin_g1_m02pc->SetParameter(1,fit_g1->GetParameter(1)/-500.);
lin_g1_m02pc->SetLineColor(kOrange);
TF1* lin_g1_m01pc = new TF1("lin_g1_m01pc","[0]+[1]*x",rangemin_g1,rangemax_g1);
lin_g1_m01pc->SetParameter(0,fit_g1->GetParameter(0)/-1000.);
lin_g1_m01pc->SetParameter(1,fit_g1->GetParameter(1)/-1000.);
lin_g1_m01pc->SetLineColor(kYellow);
norm_g1->GetXaxis()->SetRangeUser(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end()));
norm_g1->SetMinimum(1.5*lin_g1_m02pc->Eval(rangemin_g1));
norm_g1->SetMaximum(1.5*lin_g1_p02pc->Eval(rangemin_g1));
norm_g1->GetXaxis()->SetTitle("Signal generator voltage [mV]");
norm_g1->GetYaxis()->SetTitle("Normalised ADC [ADU]");
norm_g1->GetYaxis()->SetTitleOffset(0.9);
norm_g1->Draw("AP");
flat_g1->Draw("same");
lin_g1_p02pc->Draw("same");
lin_g1_p01pc->Draw("same");
lin_g1_m02pc->Draw("same");
lin_g1_m01pc->Draw("same");
norm_g1->Draw("P");
A6->Update();
//sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g1norm_M%s.png", module_str.c_str(),plotfolder_str.c_str(), pixel_type.c_str(), i, module_str.c_str());
//mapcanvas->SaveAs((const char *)(savename));
//delete norm_g1;
}
}
}
// get ratio measurements
// if (fit_g0 && fit_g1) {
// double this_g0overg1 = fit_g0->GetParameter(1)/fit_g1->GetParameter(1);
// double this_g0overg1er = sqrt(pow(fit_g0->GetParError(1)/fit_g0->GetParameter(1),2) + pow(fit_g1->GetParError(1)/fit_g1->GetParameter(1),2));
// cout << "G0overG1 =" << this_g0overg1 << "+/-" << this_g0overg1er << endl;
// }
rootapp.Run();
return 0;
}

236
BP_scan_both_speeds.sh Normal file
View File

@ -0,0 +1,236 @@
#!/bin/bash
# to run do: bash BP_scan.sh
# prerequisites:
# - setup_env.sh souced
# - the hostname is set
# - detector is on
# - source pccalib.sh with pc (pc-jungfrau-01/pc-jungfrau-test/pc-jungfrau-02)
# - waveform generator is on
# - amplifier board is powered and unconnected.
# - last file should be 2097184000 bytes big.
# connect to pc10773 (RH7 machine connected to the pulser and, after klog, run the command
# nc -k -n -v -l -p 5555 -e /bin/bash
# last data file (000002.dat) should be 2097184000 bytes
KILLRCV="killall ju_udp_receiver_3threads_2_0"
$KILLRCV
if [[ "$0" == *"BP_scan_both_speeds.sh"* ]]; then
echo "script changes env. variables: should be invoked with source, not sh "
exit
fi
if [ ! -v $1 ]; then
echo $0
echo "printing filenames for module " $1
source filename_creator.sh $1 Y
sls_detector_put stop #just in case
sls_detector_put powerchip 1
sls_detector_put delay 0
sls_detector_put triggers 1
sls_detector_put frames 100
sls_detector_put period 0.005
sls_detector_put exptime 0.00004
sls_detector_put highvoltage 0
# configure for receiver on pc-jungfrau-01/pc-jungfrau-test/pc-jungfrau-02
# source pccalib.sh with pc (pc-jungfrau-01/pc-jungfrau-test/pc-jungfrau-02)
sls_detector_put udp_dstport 32410
sls_detector_put udp_dstip $DSTIP #10.1.4.105
sls_detector_put udp_dstmac $DSTMAC #3C:FD:FE:A2:14:D8
sls_detector_put udp_srcip $SRCIP #10.1.4.9
sls_detector_put udp_srcmac 00:ab:be:cc:dd:e2
#sls_detector_put configuremac 0
sls_detector_put readoutspeed half_speed
#sls_detector_put readoutspeed full_speed
sls_detector_put gainmode dynamic
CLI=/afs/psi.ch/project/sls_det_software/serial_control_software/minidelay/minidelay
# prepare the AGILENT 33250A
echo $CLI" OUTP OFF " | nc pc10773 5555
sleep 0.2
#remember to put High-Z load!
#Change load to Infinity
echo $CLI" OUTP:LOAD INF " | nc pc10773 5555
# Polarity normal
echo $CLI" OUTP:POL NORM" | nc pc10773 5555
# pulse
echo $CLI" FUNC PULS" | nc pc10773 5555
sleep 0.2
# frequency 1kHz
echo $CLI" FREQ 1000" | nc pc10773 5555
sleep 0.2
# width 40 us
echo $CLI" PULS:WIDT 0.000040" | nc pc10773 5555
sleep 0.2
# amplitude 0.1 V" | nc pc10773 5555
echo $CLI" VOLT 0.1" | nc pc10773 5555
# offset 0 V echo $CLI" VOLT:OFFS 0" | nc pc8830 5555
sleep 0.2
# VLOW 0 V
echo $CLI" VOLT:LOW 0" | nc pc10773 5555
sleep 0.2
# edge 50 ns
echo $CLI" PULS:TRAN 0.000000050" | nc pc10773 5555
sleep 0.2
# triggered burst
echo $CLI" BURS:MODE TRIG" | nc pc10773 5555
sleep 0.2
# cycles 1
echo $CLI" BURS:NCYC 1" | nc pc10773 5555
sleep 0.2
# external trigger source
echo $CLI" TRIG:SOUR EXT" | nc pc10773 5555
sleep 0.2
# delay 1 us
echo $CLI" TRIG:DEL 0.000001" | nc pc10773 5555
# delay 40 us
#echo $CLI" TRIG:DEL 0.000040" | nc pc10773 5555
sleep 0.2
# slope positive
echo $CLI" TRIG:SLOP POS" | nc pc10773 5555
sleep 0.2
# turn on burst mode
echo $CLI" BURS:STAT ON" | nc pc10773 5555
sleep 0.2
if [ "$1" == 'Y' ]; then
echo "started with Y argument, skipping manual checks"
else
echo "It is now safe to connect the cable between the amplifier board and the readout board"
echo "Please do so and press any key to continue, or press q to exit this script"
read -n 1 -s input
if [[ $input = "q" ]]; then
echo "Exiting script"
exit 1
fi
fi
# high voltage
# sls_detector_put highvoltage 200 #because it seemed more stable, we are using external HV 230V
# output on
echo $CLI" OUTP ON" | nc pc10773 5555
sleep 0.2
if [ "$1" == 'Y' ]; then
echo "started with Y argument, skipping manual checks"
else
echo "The current on the amplifier board should be ~0.035 A"
echo "Please check and press any key to continue, or press q to exit this script"
read -n 1 -s input
if [[ $input = "q" ]]; then
echo "Exiting script"
exit 1
fi
fi
$TKBPG0 &
sleep 1
# the scan
for ivpulse in {10..1000..10}
do
vpulse=$(printf %.3f $(echo "$ivpulse/1000" | bc -l))
echo $CLI" VOLT:HIGH "$vpulse | nc pc10773 5555
sleep 1
sls_detector_put start
sleep 1
done
for ivpulse in {1050..6000..50}
do
vpulse=$(printf %.3f $(echo "$ivpulse/1000" | bc -l))
echo $CLI" VOLT:HIGH "$vpulse | nc pc10773 5555
sleep 1
sls_detector_put start
sleep 1
done
# Kill receiver
sls_detector_put stop
echo $CLI" VOLT:HIGH 0.010" | nc pc10773 5555
sleep 20
$KILLRCV
# source filename creator to save data in fullspeed folder
source filename_creator.sh $1"_fullspeed" N
# set detector for full speed
sls_detector_put readoutspeed full_speed
$TKBPG0 &
sleep 1
# the scan
for ivpulse in {10..1000..10}
do
vpulse=$(printf %.3f $(echo "$ivpulse/1000" | bc -l))
echo $CLI" VOLT:HIGH "$vpulse | nc pc10773 5555
sleep 1
sls_detector_put start
sleep 1
done
for ivpulse in {1050..6000..50}
do
vpulse=$(printf %.3f $(echo "$ivpulse/1000" | bc -l))
echo $CLI" VOLT:HIGH "$vpulse | nc pc10773 5555
sleep 1
sls_detector_put start
sleep 1
done
# high voltage
# sls_detector_put highvoltage 0
# output off
echo $CLI" OUTP OFF " | nc pc10773 5555
$KILLRCV
echo "Finished scan, please wait for capacitor to discharge"
sleep 20
echo "It is now safe to disconnect the cable between the amplifier board and the readout board"
echo "Script finished"
else
echo "Specify module number as a first argument"
echo "Script finished"
fi

175
BP_scan_thinSensor.sh Normal file
View File

@ -0,0 +1,175 @@
#!/bin/bash
# to run do: bash BP_scan.sh
# prerequisites:
# - setup_env.sh souced
# - the hostname is set
# - detector is on
# - Filename_creator has been run (with correct module #)
# - source pccalib.sh with pc (pc-jungfrau-01/pc-jungfrau-test/pc-jungfrau-02)
# - waveform generator is on
# - amplifier board is powered and unconnected.
# - last file should be 2097184000 bytes big.
# connect to pc10773 (RH7 machine connected to the pulser and, after klog, run the command
# nc -k -n -v -l -p 5555 -e /bin/bash
# last data file (000002.dat) should be 2097184000 bytes
KILLRCV="killall ju_udp_receiver_3threads_2_0"
$KILLRCV
sls_detector_put stop #just in case
sls_detector_put powerchip 1
sls_detector_put delay 0
sls_detector_put triggers 1
sls_detector_put frames 100
sls_detector_put period 0.005
sls_detector_put exptime 0.00004
#sls_detector_put highvoltage 0
# configure for receiver on pc-jungfrau-01/pc-jungfrau-test/pc-jungfrau-02
# source pccalib.sh with pc (pc-jungfrau-01/pc-jungfrau-test/pc-jungfrau-02)
sls_detector_put udp_dstport 32410
sls_detector_put udp_dstip $DSTIP #10.1.4.105
sls_detector_put udp_dstmac $DSTMAC #3C:FD:FE:A2:14:D8
sls_detector_put udp_srcip $SRCIP #10.1.4.9
sls_detector_put udp_srcmac 00:ab:be:cc:dd:e2
#sls_detector_put configuremac 0
#sls_detector_put readoutspeed half_speed
sls_detector_put readoutspeed full_speed
sls_detector_put gainmode dynamic
CLI=/afs/psi.ch/project/sls_det_software/serial_control_software/minidelay/minidelay
# prepare the AGILENT 33250A
echo $CLI" OUTP OFF " | nc pc10773 5555
sleep 0.2
#remember to put High-Z load!
#Change load to Infinity
echo $CLI" OUTP:LOAD INF " | nc pc10773 5555
# Polarity normal
echo $CLI" OUTP:POL NORM" | nc pc10773 5555
# pulse
echo $CLI" FUNC PULS" | nc pc10773 5555
sleep 0.2
# frequency 1kHz
echo $CLI" FREQ 1000" | nc pc10773 5555
sleep 0.2
# width 40 us
echo $CLI" PULS:WIDT 0.000040" | nc pc10773 5555
sleep 0.2
# amplitude 0.1 V" | nc pc10773 5555
echo $CLI" VOLT 0.1" | nc pc10773 5555
# offset 0 V echo $CLI" VOLT:OFFS 0" | nc pc8830 5555
sleep 0.2
# VLOW 0 V
echo $CLI" VOLT:LOW 0" | nc pc10773 5555
sleep 0.2
# edge 50 ns
echo $CLI" PULS:TRAN 0.000000050" | nc pc10773 5555
sleep 0.2
# triggered burst
echo $CLI" BURS:MODE TRIG" | nc pc10773 5555
sleep 0.2
# cycles 1
echo $CLI" BURS:NCYC 1" | nc pc10773 5555
sleep 0.2
# external trigger source
echo $CLI" TRIG:SOUR EXT" | nc pc10773 5555
sleep 0.2
# delay 1 us
echo $CLI" TRIG:DEL 0.000001" | nc pc10773 5555
# delay 40 us
#echo $CLI" TRIG:DEL 0.000040" | nc pc10773 5555
sleep 0.2
# slope positive
echo $CLI" TRIG:SLOP POS" | nc pc10773 5555
sleep 0.2
# turn on burst mode
echo $CLI" BURS:STAT ON" | nc pc10773 5555
sleep 0.2
if [ "$1" == 'Y' ]; then
echo "started with Y argument, skipping manual checks"
else
echo "It is now safe to connect the cable between the amplifier board and the readout board"
echo "Please do so and press any key to continue, or press q to exit this script"
read -n 1 -s input
if [[ $input = "q" ]]; then
echo "Exiting script"
exit 1
fi
fi
# high voltage
# sls_detector_put highvoltage 200 #because it seemed more stable, we are using external HV 230V
# output on
echo $CLI" OUTP ON" | nc pc10773 5555
sleep 0.2
if [ "$1" == 'Y' ]; then
echo "started with Y argument, skipping manual checks"
else
echo "The current on the amplifier board should be ~0.035 A"
echo "Please check and press any key to continue, or press q to exit this script"
read -n 1 -s input
if [[ $input = "q" ]]; then
echo "Exiting script"
exit 1
fi
fi
$TKBPG0 &
# the scan
for ivpulse in {10..700..5}
do
vpulse=$(printf %.3f $(echo "$ivpulse/1000" | bc -l))
echo $CLI" VOLT:HIGH "$vpulse | nc pc10773 5555
sleep 1
sls_detector_put start
sleep 1
done
for ivpulse in {750..6000..50}
do
vpulse=$(printf %.3f $(echo "$ivpulse/1000" | bc -l))
echo $CLI" VOLT:HIGH "$vpulse | nc pc10773 5555
sleep 1
sls_detector_put start
sleep 1
done
# high voltage
# sls_detector_put highvoltage 0
# output off
echo $CLI" OUTP OFF " | nc pc10773 5555
$KILLRCV
echo "Finished scan, please wait for capacitor to discharge"
sleep 20
echo "It is now safe to disconnect the cable between the amplifier board and the readout board"
echo "Script finished"

2202
CS_analysis_M431.cpp Normal file

File diff suppressed because it is too large Load Diff

2171
CS_analysis_M439.cpp Normal file

File diff suppressed because it is too large Load Diff

1240
CS_fit.cpp Normal file

File diff suppressed because it is too large Load Diff

BIN
CS_fit_M431 Executable file

Binary file not shown.

1187
CS_fit_M431.cpp Normal file

File diff suppressed because it is too large Load Diff

347
CS_scan_both_speeds.sh Normal file
View File

@ -0,0 +1,347 @@
#!/bin/bash
# to run do: bash CS_scan.sh
# prerequisites:
# - setup_env.sh souced
# - the hostname is set
# - detector is on
# - fileneame script has been sourced
# - source pccalib.sh [pc] (pc-jungfrau-01/pc-jungfrau-02/pc-jungfrau-test)
# last file should have exactly 4194368000 byte in it.
KILLRCV="killall ju_udp_receiver_3threads_2_0"
$KILLRCV
if [[ "$0" == *"CS_scan_both_speeds.sh"* ]]; then
echo "script changes env. variables: should be invoked with source, not sh "
exit
fi
if [ ! -v $1 ]; then
echo $0
echo "printing filenames for module " $1
source filename_creator.sh $1 N
sls_detector_put stop #just in case
sls_detector_put powerchip 1
sls_detector_put frames 640
sls_detector_put period 0.005
sls_detector_put exptime 0.000010
sls_detector_put highvoltage 200
# configure for receiver on pc-jungfrau-01/pc-jungfrau-02/pc-jungfrau-test
# source pccalib.sh [pc] (pc-jungfrau-01/pc-jungfrau-02/pc-jungfrau-test)
sls_detector_put udp_dstport 32410
sls_detector_put udp_dstip $DSTIP #10.1.4.105
sls_detector_put udp_dstmac $DSTMAC #3C:FD:FE:A2:14:D8
sls_detector_put udp_srcip $SRCIP #10.1.4.9
sls_detector_put udp_srcmac 00:ab:be:cc:dd:e2
sls_detector_put readoutspeed half_speed
#sls_detector_put readoutspeed full_speed
#sls_detector_put dbitphase 125
sleep 3
sls_detector_put frames 10000
sls_detector_put start
sleep 70
sls_detector_put stop
sls_detector_put frames 640
$TKCSG0 &
sleep 3
echo "recording G0 pede"
sls_detector_put start
sleep 4
echo "recording G1 pede"
sls_detector_put gainmode forceswitchg1
sls_detector_put start
sleep 4
echo "recording G2 pede"
sls_detector_put gainmode forceswitchg2
sls_detector_put start
sleep 4
sls_detector_put gainmode dynamic
# turn on current source
# bit 16 high bit 17 low = automatic cal col sweep
# bit 16 high bit 17 high = cal col selected with bits 26-20
sls_detector_put currentsource 1 nofix 0
sleep 1
# loop 1
for tint in {50..450..50} # 25 is too small here, 50 min
do
tint_sec=$(printf %.9f $(echo "$tint/1000000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 2a
for tint in {50..100..5}
do
tint_sec=$(printf %.8f $(echo "$tint/100000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 2b
for tint in {110..200..10}
do
tint_sec=$(printf %.8f $(echo "$tint/100000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 2c
for tint in {225..450..25}
do
tint_sec=$(printf %.8f $(echo "$tint/100000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 3a
for tint in {50..100..5}
do
tint_sec=$(printf %.7f $(echo "$tint/10000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 3b
for tint in {110..200..10}
do
tint_sec=$(printf %.7f $(echo "$tint/10000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 3c
for tint in {225..450..25}
do
tint_sec=$(printf %.7f $(echo "$tint/10000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 4a
for tint in {50..100..5}
do
tint_sec=$(printf %.7f $(echo "$tint/1000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 4b
for tint in {110..250..10}
do
tint_sec=$(printf %.7f $(echo "$tint/1000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
echo "Finished scan at halfspeed"
sls_detector_put exptime 0.000010
sleep 4
$KILLRCV
# source filename creator to save data in fullspeed folder
source filename_creator.sh $1"_fullspeed" N
sls_detector_put readoutspeed full_speed
sleep 2
sls_detector_put currentsource 0
sleep 2
$TKCSG0 &
sleep 3
echo "recording G0 pede"
sls_detector_put start
sleep 4
echo "recording G1 pede"
sls_detector_put gainmode forceswitchg1
sls_detector_put start
sleep 4
echo "recording G2 pede"
sls_detector_put gainmode forceswitchg2
sls_detector_put start
sleep 4
sls_detector_put gainmode dynamic
# turn on current source
# bit 16 high bit 17 low = automatic cal col sweep
# bit 16 high bit 17 high = cal col selected with bits 26-20
sls_detector_put currentsource 1 nofix 0
sleep 1
# loop 1
for tint in {50..450..50} # 25 is too small here, 50 min
do
tint_sec=$(printf %.9f $(echo "$tint/1000000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 2a
for tint in {50..100..5}
do
tint_sec=$(printf %.8f $(echo "$tint/100000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 2b
for tint in {110..200..10}
do
tint_sec=$(printf %.8f $(echo "$tint/100000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 2c
for tint in {225..450..25}
do
tint_sec=$(printf %.8f $(echo "$tint/100000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 3a
for tint in {50..100..5}
do
tint_sec=$(printf %.7f $(echo "$tint/10000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 3b
for tint in {110..200..10}
do
tint_sec=$(printf %.7f $(echo "$tint/10000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 3c
for tint in {225..450..25}
do
tint_sec=$(printf %.7f $(echo "$tint/10000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 4a
for tint in {50..100..5}
do
tint_sec=$(printf %.7f $(echo "$tint/1000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
# loop 4b
for tint in {110..250..10}
do
tint_sec=$(printf %.7f $(echo "$tint/1000000" | bc -l))
echo "setting integration time to (s) " $tint_sec
sls_detector_put exptime $tint_sec
sls_detector_put start
sleep 4
done
echo "Finished scan at fullspeed"
sls_detector_put exptime 0.000010
sls_detector_put period 0.002
sls_detector_put frames 1000000
sls_detector_put currentsource 0
sls_detector_put highvoltage 0
echo "Script finished"
sleep 4
$KILLRCV
else
echo "Specify module number as a first argument"
echo "Script finished"
fi

View File

@ -0,0 +1,238 @@
#!/bin/bash
# to run do: bash CuFluo_exposure.sh
# prerequisites:
# - the hostname is set
# - export PATH=/afs/psi.ch/project/sls_det_software/latest_slsDetectorPackage/build/bin:$PATH
# - export LD_LIBRARY_PATH=/afs/psi.ch/project/sls_det_software/latest_slsDetectorPackage/build/bin:$LD_LIBRARY_PATH
# - detector is on
# - source filename_creator.sh #
# - source pccalib.sh [pc] (mpc2012/pc-jungfrau-test)
# - xray tube is on and ramped for 40 kV, 60 mA, set to Cu
if [[ "$0" == *"CuFluo_exposure_both_speeds.sh"* ]]; then
echo "script changes env. variables: should be invoked with source, not sh "
exit
fi
if [ ! -v $1 ]; then
echo $0
echo "printing filenames for module " $1
source filename_creator.sh $1 N
shutter=1
sls_detector_put stop #just in case
sls_detector_put powerchip 1
sls_detector_put period 0.002
sls_detector_put exptime 0.000010
sls_detector_put highvoltage 200
# configure for receiver on mpc2012/pc-jungfrau-test/mpc2198/mpc3282
# source pccalib.sh [pc] (mpc2012/pc-jungfrau-test/mpc2198/mpc3282)
sls_detector_put udp_dstport 32410
sls_detector_put udp_dstip $DSTIP #10.1.4.105
sls_detector_put udp_dstmac $DSTMAC #3C:FD:FE:A2:14:D8
sls_detector_put udp_srcip $SRCIP #10.1.4.9
sls_detector_put udp_srcmac 00:ab:be:cc:dd:e2
sls_detector_put readoutspeed half_speed #half_speed
#sls_detector_put reg 0x59 0x1310 #0001 0011 0001 0000
#sls_detector_put readoutspeed 0
#sls_detector_put reg 0x59 0x0100 #0000 0001 0000 0000
KILLRCV="killall ju_udp_receiver_3threads_2_0"
$KILLRCV
#CLI=/afs/psi.ch/project/sls_det_software/bin/sl7_binaries_to_be_removed_soon/xrayClient_sl7 #/vacuumClient_sl7
CLI=/afs/psi.ch/project/sls_det_software/bin/xrayClient_sl8 #/vacuumClient_sl7
$CLI setv 40
$CLI setc 60
$CLI HV on
sls_detector_put clearbit 0x5d 0
#sls_detector_put vref_prech 1000
#sls_detector_put vref_ds 1100
$CLI shutter $shutter off #$CLI shutter 1 off
echo "warmin up the board"
sls_detector_put frames 40000
sls_detector_put start
sleep 81
sls_detector_put stop
echo "end of board warm up"
sls_detector_put frames 1000
$KILLRCV
sleep 1
$TKPG0 &
sleep 5
echo "recording G0 pede"
sls_detector_put start
sleep 3
# 1000 frames at 500 frames per second takes 2s
echo "recording G1 pede"
sls_detector_put gainmode forceswitchg1
sls_detector_put start
sleep 3
echo "recording G2 pede"
sls_detector_put gainmode forceswitchg2
sls_detector_put start
sleep 3
sls_detector_put gainmode dynamic
$KILLRCV
echo "closed G0 pede file and open the G0 CuFluo file"
sleep 1
$TKFG0 &
sleep 5
sls_detector_put frames 230000
$CLI shutter $shutter on #$CLI shutter 1 on
sleep 1
sls_detector_put start
sleep 470
# 200k frames at 500 frames per second takes 400s
$CLI shutter $shutter off #$CLI shutter 1 off
$KILLRCV
echo "closed G0 CuFluo file and open HG0 pede file"
sleep 1
$TKPHG0 &
sleep 3
sls_detector_put settings highgain0
#sls_detector_put vref_prech 1000
#sls_detector_put vref_ds 1100
sls_detector_put frames 1000
echo "recording HG0 pede"
sls_detector_put start
sleep 3
# 1000 frames at 500 frames per second takes 2s
$KILLRCV
echo "closed HG0 pede file and open the HG0 CuFluo file"
sleep 1
$TKFHG0 &
sleep 5
sls_detector_put frames 230000
$CLI shutter $shutter on #$CLI shutter 1 on
sleep 1
sls_detector_put start
sleep 470
echo "finish exposure at half speed"
# 200k frames at 500 frames per second takes 400s
$CLI shutter $shutter off #$CLI shutter 1 off
sleep 2
echo "close shutter"
$KILLRCV
sleep 1
# source filename creator to save data in fullspeed folder
source filename_creator.sh $1"_fullspeed" N
# set detector for full speed
sls_detector_put readoutspeed full_speed
sleep 1
sls_detector_put clearbit 0x5d 0
#sls_detector_put vref_prech 1000
#sls_detector_put vref_ds 1100
sls_detector_put frames 1000
$TKPG0 &
sleep 5
echo "recording G0 pede"
sls_detector_put start
sleep 3
# 1000 frames at 500 frames per second takes 2s
echo "recording G1 pede"
sls_detector_put gainmode forceswitchg1
sls_detector_put start
sleep 3
echo "recording G2 pede"
sls_detector_put gainmode forceswitchg2
sls_detector_put start
sleep 3
sls_detector_put gainmode dynamic
$KILLRCV
echo "closed G0 pede file and open the G0 CuFluo file"
sleep 1
$TKFG0 &
sleep 5
sls_detector_put frames 230000
$CLI shutter $shutter on #$CLI shutter 1 on
sleep 1
sls_detector_put start
sleep 470
# 200k frames at 500 frames per second takes 400s
$CLI shutter $shutter off #$CLI shutter 1 off
$KILLRCV
echo "closed G0 CuFluo file and open HG0 pede file"
sleep 1
$TKPHG0 &
sleep 5
sls_detector_put settings highgain0
#sls_detector_put vref_prech 1000
#sls_detector_put vref_ds 1100
sls_detector_put frames 1000
echo "recording HG0 pede"
sls_detector_put start
sleep 3
# 1000 frames at 500 frames per second takes 2s
$KILLRCV
echo "closed HG0 pede file and open the HG0 CuFluo file"
sleep 1
$TKFHG0 &
sleep 5
sls_detector_put frames 230000
$CLI shutter $shutter on #$CLI shutter 1 on
sleep 1
sls_detector_put start
sleep 470
# 200k frames at 500 frames per second takes 400s
$CLI shutter $shutter off #$CLI shutter 1 off
sleep 2
$KILLRCV
sls_detector_put highvoltage 0
sls_detector_put clearbit 0x5d 0
echo "Script finished"
else
echo "Specify module number as a first argument"
echo "Script finished"
fi

322
CuFluo_fit.cpp Executable file
View File

@ -0,0 +1,322 @@
// to analyse the backplane pulsing data per module
// changes by VH 210906: to eliminate hardcoded absolute paths, uses location of the analysis root files as additional input argument (accordingly changed in filename_creator.sh)
#include "TApplication.h"
#include "sls_detector_calibration/jungfrauCommonHeader.h"
#include "sls_detector_calibration/jungfrauCommonFunctions.h"
#include "sls_detector_calibration/jungfrauFile.C"
#include "sls_detector_calibration/jungfrauPixelMask.C"
#include "sls_detector_calibration/jungfrauPedestal.C"
#include "sls_detector_calibration/energyCalibration.h"
#include "sls_detector_calibration/energyCalibration.cpp"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TF1.h"
#include "TFile.h"
#include "TPaveStats.h"
#include "TLegend.h"
#include "TPaveText.h"
#include <sys/stat.h>
//#include <sstream>
//#define NB_ENABLE 1
//void nonblock(int state);
//#define NB_DISABLE 0
//TApplication* rootapp;
//TCanvas *A2;
//TCanvas *A3;
//TCanvas *A4;
//TCanvas *A5;
//TCanvas *A6;
//TPaveStats *st0;
//void PlotCanvas(void);
double checkRangeMaxForAmplifierPlateau(double range_max) {
// check that the range maximum is no more than 6.4 V
// to avoid non-linearity coming from amplifier plateau
if (range_max > 6400) {
return 6400;
} else {
return range_max;
}
}
bool isHGX=false;
int main(int argc, char* argv[]) {
//nonblock(NB_ENABLE);
cout <<"opening the rootapp" <<endl;
TApplication rootapp("example",&argc, argv);
jungfrauStyle();
//gROOT->SetBatch(1);
gStyle->SetOptFit(11);
/*
if (argc != 3) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "arg 2: specify data location" << endl;
cout << "arg 3: specify column (x)" << endl;
cout << "arg 4: specify row (y)" << endl;
exit(1);
}
*/ //uncomment for SR
if (argc != 5) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "arg 2: gain settings" << endl;
cout << "arg 3: specify pixel x position" << endl;
cout << "arg 4: specify pixel y position" << endl;
exit(1);
} //uncomment for VH 210906
string module_str = argv[1];
string gain_str = argv[2];
string str2 =("HG0G1G2");
string str3 =("HGOG1G2"); //filename creator had this bug
int column = atoi(argv[3]);
int row = atoi(argv[4]);
int pixel = column+row*1024;
char data_loc[256];
sprintf(data_loc,"/mnt/sls_det_storage/jungfrau_calib/jungfrau_ana_sophie/M%s_CalibAna/", module_str.c_str());
cout << data_loc << endl;
std::string folder_path(data_loc);
if (folder_path.find(str2) != string::npos) isHGX=true;
if (folder_path.find(str3) != string::npos) isHGX=true;
bool isJF11=false;
if (gain_str == "HG0JF11") {
gain_str = "HG0";
isJF11=true;
}
// cout << data_loc.find(str2)<<" " << string::npos << " " << str2 << " " << data_loc <<endl;
if (isHGX) {
cout << " HG0->HG1->HG2 sequence - dynamicHG0" <<endl;
// plotfolder_str="BackplanePulsing_HG0G1G2";
}
else {
cout << " G0->G1->G2 sequence - dynamicG0" <<endl;
// plotfolder_str="BackplanePulsing";
}
//char savename[128]; //uncomment for SR
//char filename[128]; //uncomment for SR
char filename[256]; //uncomment for VH 210902
int low_ADU_peak = 0;
int high_ADU_peak = 0;
if (gain_str == "HG0") {
low_ADU_peak = 700;
high_ADU_peak = 900;
if (isJF11) {
low_ADU_peak = 850;
high_ADU_peak = 1350;
}
} else if (gain_str == "G0") {
low_ADU_peak = 250;
high_ADU_peak = 400;
}
int low_bin_noise = 101;
int high_bin_noise = 301;
int low_bin_peak = 0;
int high_bin_peak = 0;
if (gain_str == "HG0") {
low_bin_peak = 701;
high_bin_peak = 1200;
if (isJF11) {
low_bin_peak = 801;
high_bin_peak = 1451;
}
} else if (gain_str == "G0") {
low_bin_peak = 301;
high_bin_peak = 651;
}
TCanvas *A2 = new TCanvas("A2","Plot histogram",150,10,800,400);
TCanvas *A3 = new TCanvas("A3","Plot noise",150,10,800,400);
A2->SetLeftMargin(0.1);
A2->SetRightMargin(0.13);
A2->SetTopMargin(0.08);
A2->SetBottomMargin(0.15);
A3->SetLeftMargin(0.1);
A3->SetRightMargin(0.13);
A3->SetTopMargin(0.08);
A3->SetBottomMargin(0.15);
//file name
sprintf(filename,"%sCuFluo_%s_file0to19.root",folder_path.c_str(), gain_str.c_str());
cout << "Loading file " << filename << endl;
TFile* f = new TFile((const char *)(filename),"READ");
int chip;
int CH = row*1024+column;
if (CH < (65536*1)) {
chip = 1;
} else if (CH < (65536*2)) {
chip = 2;
} else if (CH < (65536*3)) {
chip = 3;
} else if (CH < (65536*4)) {
chip = 4;
} else if (CH < (65536*5)) {
chip = 5;
} else if (CH < (65536*6)) {
chip = 6;
} else if (CH < (65536*7)) {
chip = 7;
} else if (CH < (65536*8)){
chip = 8;
}
cout<< "Chip "<< chip << " Channel number " << CH << endl;
TH2I* hist0=(TH2I*)f->Get(Form("adc2d_%d",chip));
cout << "Creating histogram for " << Form("adc2d_%d",chip) << endl;
TH1D* proj = hist0->ProjectionX("bin1",CH-(65536*(chip-1))+1,CH-(65536*(chip-1))+1);
cout << "Data for pixel "<< pixel << " is loaded" << endl;
if (proj->Integral(low_bin_noise,high_bin_noise)!=0 && proj->Integral(low_bin_peak,high_bin_peak)!=0) {
A2->cd();
cout << "Canvas Noise" << endl;
// noise
TH1D *proj_noise = dynamic_cast<TH1D*>(proj->Rebin(4,"proj_noise"));
proj_noise->SetStats(kTRUE);
proj_noise->GetXaxis()->SetRangeUser(proj->GetBinLowEdge(low_bin_noise),proj->GetBinLowEdge(high_bin_noise+1));
proj_noise->Fit("gaus","Q");
TF1 *fit = proj_noise->GetFunction("gaus");
proj_noise->Draw();
A2->Update();
proj_noise->GetXaxis()->SetTitle("Pedestal corrected ADC [ADU]");
proj_noise->GetXaxis()->SetRangeUser(-100,150);
fit->SetParNames("N_{#gamma}", "Peak pos", "Noise RMS");
TPaveStats *st0 = (TPaveStats*)proj_noise->FindObject("stats");
st0->SetX1NDC(0.53);
st0->SetX2NDC(0.94);
st0->SetY1NDC(0.75);
st0->SetY2NDC(0.94);
st0->SetBorderSize(0);
st0->SetTextSize(0.04);
A2->Modified();
A2->Update();
A3->cd();
// peak
TH1D *proj_peak = dynamic_cast<TH1D*>(proj->Rebin(4,"proj_peak"));
proj_peak->SetStats(kTRUE);
proj_peak->GetXaxis()->SetRangeUser(proj->GetBinLowEdge(low_bin_peak),proj->GetBinLowEdge(high_bin_peak+1));
Double_t mypar[8];
mypar[0] = 0.0;
mypar[1] = 0.0;
mypar[2] = proj_peak->GetBinCenter(proj_peak->GetMaximumBin());
if (gain_str == "G0") {
mypar[3] = 16.;
} else if (gain_str == "HG0") {
mypar[3] = 29.;
}
mypar[4] = proj_peak->GetBinContent(proj_peak->GetMaximumBin());
if (gain_str == "G0") {
mypar[5] = 0.17;
} else if (gain_str == "HG0") {
mypar[5] = 0.14;
}
mypar[6] = 1.12;
if (gain_str == "G0") {
mypar[7] = 0.12;
} else if (gain_str == "HG0") {
mypar[7] = 0.14;
}
Double_t emypar[8];
energyCalibration *thiscalibration = new energyCalibration();
thiscalibration->setScanSign(1);
thiscalibration->setStartParametersKb(mypar);
thiscalibration->fixParameter(0,0.); // no background
thiscalibration->fixParameter(1,0.);
TF1* fittedfun = thiscalibration->fitSpectrumKb(proj_peak,mypar,emypar);
TF1 *gaus_Ka = new TF1("gaus_Ka","gaus",proj->GetBinLowEdge(low_bin_peak),proj->GetBinLowEdge(high_bin_peak+1));
gaus_Ka->SetParameters(mypar[4],mypar[2],mypar[3]);
gaus_Ka->SetLineColor(kBlue);
TF1 *erfc_Ka = new TF1("erfc_Ka","[0]/2.*(TMath::Erfc(([1]*(x-[2])/[3])/(TMath::Sqrt(2.))))",proj->GetBinLowEdge(low_bin_peak),proj->GetBinLowEdge(high_bin_peak+1));
erfc_Ka->SetParameters(mypar[4]*mypar[5], 1, mypar[2], mypar[3]);
erfc_Ka->SetLineColor(kOrange);
TF1 *gaus_Kb = new TF1("gaus_Kb","gaus",proj->GetBinLowEdge(low_bin_peak),proj->GetBinLowEdge(high_bin_peak+1));
gaus_Kb->SetParameters(mypar[4]*mypar[7],mypar[6]*mypar[2],mypar[3]);
gaus_Kb->SetLineColor(kGreen+2);
TF1 *erfc_Kb = new TF1("erfc_Kb","[0]/2.*(TMath::Erfc(([1]*(x-[2])/[3])/(TMath::Sqrt(2.))))",proj->GetBinLowEdge(low_bin_peak),proj->GetBinLowEdge(high_bin_peak+1));
erfc_Kb->SetParameters(mypar[4]*mypar[7]*mypar[5], 1, mypar[6]*mypar[2], mypar[3]);
erfc_Kb->SetLineColor(kOrange+7);
proj_peak->Draw();
A3->Update();
erfc_Kb->Draw("same");
erfc_Ka->Draw("same");
gaus_Kb->Draw("same");
gaus_Ka->Draw("same");
fittedfun->Draw("same");
A3->Update();
proj_peak->GetXaxis()->SetTitle("Pedestal corrected ADC [ADU]");
fittedfun->SetParNames("Bkg height", "Bkg grad", "K_{#alpha} pos", "Noise RMS", "K_{#alpha} height", "CS", "K_{#beta}/K_{#alpha} pos", "K_{#beta} frac");
TPaveStats *st = (TPaveStats*)proj_peak->FindObject("stats");
st->SetX1NDC(0.15);
st->SetX2NDC(0.55);
st->SetY1NDC(0.7);
st->SetY2NDC(0.94);
st->SetBorderSize(0);
st->SetTextSize(0.04);
A3->Modified();
A3->Update();
} else {
std::cout << "Masked pixel";
}
rootapp.Run();
return 0;
}

239
Default_pixels_arrays.cpp Normal file
View File

@ -0,0 +1,239 @@
// file to create the hg0, g0, g1,and g2 bin files of default pixels for a list of modules past as an argument
// Each file contains the default pixels map for the list of modules past as an argument
// It save 4 files. One for each gain stage.
#include "../sls_detector_calibration/jungfrauCommonHeader.h"
#include "../sls_detector_calibration/jungfrauCommonFunctions.h"
#include <fstream>
#include <dirent.h>
#include "TCanvas.h"
#include "TFile.h"
#include "TH2F.h"
#include "TGraph.h"
#include "TF1.h"
int main(int argc, char* argv[]) {
jungfrauStyle();
if (argc == 1) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << "Number of arguments "<< argc << endl;
cout << " " << endl;
exit(1);
} else {
char savename[256];
char savename_hg0[256];
char savename_g0[256];
char savename_g1[256];
char savename_g2[256];
// today's date
time_t rawtime;
tm* timeinfo;
char date[80];
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(date,80,"%Y-%m-%d",timeinfo);
sprintf(savename_hg0,"/afs/psi.ch/user/c/carulla_m/JFProjects/defaultMaps_HG0_%s.bin", date);
fstream outfile_hg0;
outfile_hg0.open(savename_hg0, ios::binary | ios::out);
sprintf(savename_g0,"/afs/psi.ch/user/c/carulla_m/JFProjects/defaultMaps_G0_%s.bin", date);
fstream outfile_g0;
outfile_g0.open(savename_g0, ios::binary | ios::out);
sprintf(savename_g1,"/afs/psi.ch/user/c/carulla_m/JFProjects/defaultMaps_G1_%s.bin", date);
fstream outfile_g1;
outfile_g1.open(savename_g1, ios::binary | ios::out);
sprintf(savename_g2,"/afs/psi.ch/user/c/carulla_m/JFProjects/defaultMaps_G2_%s.bin", date);
fstream outfile_g2;
outfile_g2.open(savename_g2, ios::binary | ios::out);
for (int j=1; j<argc; j++) {
cout << j << endl;
string this_module = argv[j];
cout << "Processing module "<< this_module << endl;
std::vector<short> this_g0_default_pixels(NCH,0);
std::vector<short> this_g1_default_pixels(NCH,0);
std::vector<short> this_g2_default_pixels(NCH,0);
std::vector<short> this_hg0_default_pixels(NCH,0);
// // CuFluo HG0 dataset
sprintf(savename,"data/M%s/CuFluo_gain_HG0_M%s.root", this_module.c_str(), this_module.c_str());
TFile* FL_HG0_file = new TFile((char*)savename,"READ");
TH2F* FL_HG0_gain_map = 0;
if (FL_HG0_file->IsZombie()) {
cout << "didn't find HG0 file" << endl;
} else {
FL_HG0_gain_map = (TH2F*)FL_HG0_file->Get("gain_ADUper1keV_2d");
cout << "The HG0 map is loaded" << endl;
}
// CuFluo G0 dataset
sprintf(savename,"data/M%s/CuFluo_gain_G0_M%s.root", this_module.c_str(), this_module.c_str());
TFile* FL_G0_file = new TFile((char*)savename,"READ");
TH2F* FL_G0_gain_map = 0;
if (FL_G0_file->IsZombie()) {
cout << "didn't find G0 file" << endl;
} else {
FL_G0_gain_map = (TH2F*)FL_G0_file->Get("gain_ADUper1keV_2d");
}
// Backplane pulsing dataset
sprintf(savename,"data/M%s/BP_ratio_M%s.root", this_module.c_str(), this_module.c_str());
TFile* DB_file = new TFile((char*)savename,"READ");
TH2F* DB_ratio_map = 0;
if (DB_file->IsZombie()) {
cout << "didn't find BP file" << endl;
// look for a direct beam dataset
sprintf(savename,"data/M%s/DB_ratio_M%s.root", this_module.c_str(), this_module.c_str());
DB_file = new TFile((char*)savename,"READ");
if (DB_file->IsZombie()) {
cout << "also didn't find DB file" << endl;
} else {
cout << "loading G0/G1 from DB" << endl;
DB_ratio_map = (TH2F*)DB_file->Get("g0overg1map");
}
} else {
cout << "loading G0/G1 from BP" << endl;
DB_ratio_map = (TH2F*)DB_file->Get("g0overg1_map");
}
// Current source dataset
sprintf(savename,"data/M%s/CS_ratio_M%s.root", this_module.c_str(), this_module.c_str());
TFile* CS_file = new TFile((char*)savename,"READ");
TH2F* CS_ratio_map = 0;
if (CS_file->IsZombie()) {
cout << "didn't find CS file" << endl;
} else {
CS_ratio_map = (TH2F*)CS_file->Get("g1overg2map");
cout << "loading G1/G2 map" << endl;
}
for (int i=0; i<NCH; i++) {
double this_hg0 = 0;
double this_g0 = 0;
double this_g0overg1 = 0;
double this_g1 = 0;
double this_g1overg2 = 0;
double this_g2 = 0;
// HG0
if (FL_HG0_gain_map) {
this_hg0 = FL_HG0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1);
//cout << "Gain value is " << this_hg0 << endl;
//this_hg0_default_pixels[i] = 0;
if (this_hg0 == 0) {
this_hg0_default_pixels[i] = 1;
} else if (this_hg0 < 80 || this_hg0 > 200) {
this_hg0_default_pixels[i] = 1;
}
} else {
this_hg0_default_pixels[i] = 1;
}
// G0
if (FL_G0_gain_map) {
this_g0 = FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1);
this_g0_default_pixels[i] = 0;
if (this_g0 == 0) {
this_g0_default_pixels[i] = 1;
} else if (this_g0 < 30 || this_g0 > 56) {
this_g0_default_pixels[i] = 1;
}
} else {
this_g0_default_pixels[i] = 1;
}
// G1
if (DB_ratio_map) {
this_g0overg1 = DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1);
this_g1 = this_g0 / this_g0overg1;
this_g1_default_pixels[i] = 0;
if (this_g0overg1 == 0) {
this_g1_default_pixels[i] = 1;
} else if (this_g0 != 0 && (this_g1 < -2.5 || this_g1 > -0.4)) {
this_g1_default_pixels[i] = 1;
}
} else {
this_g1_default_pixels[i] = 1;
}
// G2
if (CS_ratio_map) {
this_g1overg2 = CS_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1);
this_g2 = this_g1 / this_g1overg2;
this_g2_default_pixels[i] = 0;
if (this_g1overg2 == 0) {
this_g2_default_pixels[i] = 1;
} else if (this_g0 != 0 && this_g1 != 0 && (this_g2 < -0.3 || this_g2 > -0.015)) {
this_g2_default_pixels[i] = 1;
}
} else {
this_g2_default_pixels[i] = 1;
}
if (this_module == "586") {
if ( (i/NC) > 0 && (i/NC)<256 && (i%NC)> 768 && (i%NC)<1024 ) {
this_g2_default_pixels[i]=1;
this_g1_default_pixels[i]=1;
}
}
if (this_module == "454") {
if ( (i/NC) > 0 && (i/NC)<256 && (i%NC)> 768 && (i%NC)<1024 ) {
this_g2_default_pixels[i]=1;
}
}
//hg0_default_pixels.push_back(this_hg0_default_pixels[i]);
outfile_hg0.write(reinterpret_cast<const char *>(&this_hg0_default_pixels[i]), sizeof(short));
// g0_default_pixels.push_back(this_g0_default_pixels[i]);
outfile_g0.write(reinterpret_cast<const char *>(&this_g0_default_pixels[i]), sizeof(short));
// g1_default_pixels.push_back(this_g1_default_pixels[i]);
outfile_g1.write(reinterpret_cast<const char *>(&this_g1_default_pixels[i]), sizeof(short));
// g2_default_pixels.push_back(this_g2_default_pixels[i]);
outfile_g2.write(reinterpret_cast<const char *>(&this_g2_default_pixels[i]), sizeof(short));
}
// //Modules_d.push_back(this_module);
// cout << "Module loop after push_back" << endl;
// cout << j << endl;
cout << "Pixels number " << this_hg0_default_pixels.size() << endl;
}
outfile_hg0.close();
outfile_g0.close();
outfile_g1.close();
outfile_g2.close();
cout << "Files closed" << endl;
// outfile_g0.close();
// outfile_g1.close();
// outfile_g2.close();
// cout<< "Number of words "<< sizeof(hg0_default_pixels)<< endl;
// cout<< "Size of HG0 map"<< hg0_default_pixels.size() * sizeof(int)<< endl;
}
}