diff --git a/BP_analysis_M431.cpp b/BP_analysis_M431.cpp new file mode 100644 index 0000000..1e6b224 --- /dev/null +++ b/BP_analysis_M431.cpp @@ -0,0 +1,1119 @@ +// 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) +// works for single chip only (chip 5) + +#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 "TPaveStats.h" +#include "TFile.h" +#include "TLegend.h" +#include "TPaveText.h" + +#include + +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[]) { + + 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; + exit(1); + } + */ //uncomment for SR + + if (argc != 4) { + cout << "Correct usage:" << endl; + cout << "arg 1: specify module number" << endl; + cout << "arg 2: specify data location (folder + data file prefix)" << endl; + cout << "arg 3: specify location of analysis root files" << endl; + exit(1); + } //uncomment for VH 210906 + + string module_str = argv[1]; + + string str2 =("HG0G1G2"); + string str3 =("HGOG1G2"); //filename creator had this bug + + string data_loc = argv[2]; + string anadata_loc = argv[3]; //uncomment for VH 210906 + string plotfolder_str; + + + if (data_loc.find(str2) != string::npos) isHGX=true; + if (data_loc.find(str3) != string::npos) isHGX=true; + + + // cout << data_loc.find(str2)<<" " << string::npos << " " << str2 << " " << data_loc <HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" <pedestalSetNFrames(100); // using 100 frames, rolling window + jungfrauPedestal *pedestalObjectG1 = new jungfrauPedestal(); + pedestalObjectG1->pedestalSetNFrames(100); // using 100 frames, rolling window + + TH2F* avg_adcG0_map [220]; + TH2F* avg_adcG0er_map [220]; + TH2F* avg_adcG1_map [220]; + TH2F* avg_adcG1er_map [220]; + + //char savename[128]; //uncomment for SR + //char filename[128]; //uncomment for SR + char savename[256]; //uncomment for VH 210902 + 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 *mapcanvas = new TCanvas("mapcanvas","",150,10,800,400); + mapcanvas->SetLeftMargin(0.1); + mapcanvas->SetRightMargin(0.13); + mapcanvas->SetTopMargin(0.08); + mapcanvas->SetBottomMargin(0.15); + + TCanvas* c1 = new TCanvas("c1",""); + + mapcanvas->cd(); + + TH1F* g0_grad_hist = 0; + if (module_str == "351" || + module_str == "351_fullspeed" || + module_str == "352" || + module_str == "352_fullspeed" || + module_str == "261" || + module_str == "261_fullspeed" || + module_str == "310" || + module_str == "310_fullspeed" || + module_str == "312" || + module_str == "312_fullspeed" || + module_str == "264" || + module_str == "264_fullspeed" || + module_str == "253" || + module_str == "253_fullspeed" || + module_str == "307" || + module_str == "307_fullspeed" || + module_str == "272_halfspeedtest" || + module_str == "272_fullspeedtest") { + g0_grad_hist = new TH1F("g0_grad_hist","",100,3,8); + } else { + g0_grad_hist = new TH1F("g0_grad_hist","",100,5,10); + } + TH1F* g0_grader_hist = new TH1F("g0_grader_hist","",100,0,0.002); + + TH1F* g1_grad_hist = 0; + if (module_str == "351" || + module_str == "351_fullspeed" || + module_str == "352" || + module_str == "352_fullspeed" || + module_str == "261" || + module_str == "261_fullspeed" || + module_str == "310" || + module_str == "310_fullspeed" || + module_str == "312" || + module_str == "312_fullspeed" || + module_str == "264" || + module_str == "264_fullspeed" || + module_str == "253" || + module_str == "253_fullspeed" || + module_str == "307" || + module_str == "307_fullspeed" || + module_str == "272_halfspeedtest" || + module_str == "272_fullspeedtest") { + g1_grad_hist = new TH1F("g1_grad_hist","",100,-0.25,-0.1); + } else { + g1_grad_hist = new TH1F("g1_grad_hist","",100,-0.3,-0.15); + } + TH1F* g1_grader_hist = 0; + if (module_str == "006") { + g1_grader_hist = new TH1F("g1_grader_hist","",100,0,0.001); + } else { + g1_grader_hist = new TH1F("g1_grader_hist","",100,0,0.0001); + } + + TH2F* no_g0g1_calib_map = new TH2F("no_g0g1_calib_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* g0_grad_map = new TH2F("g0_grad_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g0_grader_map = new TH2F("g0_grader_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* g1_grad_map = new TH2F("g1_grad_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g1_grader_map = new TH2F("g1_grader_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH1F* g0_const_hist = new TH1F("g0_const_hist","",100,1000,4000); + TH1F* g0_conster_hist = new TH1F("g0_conster_hist","",100,0,0.5); + + TH1F* g1_const_hist = new TH1F("g1_const_hist","",100,10000,15000); + TH1F* g1_conster_hist = 0; + if (module_str == "006") { + g1_conster_hist = new TH1F("g1_conster_hist","",100,0,10); + } else { + g1_conster_hist = new TH1F("g1_conster_hist","",100,0,1); + } + + TH2F* g0_const_map = new TH2F("g0_const_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g0_conster_map = new TH2F("g0_conster_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* g1_const_map = new TH2F("g1_const_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g1_conster_map = new TH2F("g1_conster_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + //TH1F* g0overg1_hist = new TH1F("g0overg1_hist","",100,-34,-24); original range + TH1F* g0overg1_hist = new TH1F("g0overg1_hist","",200,-45,-25); + TH1F* g0overg1er_hist = 0; + if (module_str == "006") { + g0overg1er_hist = new TH1F("g0overg1er_hist","",100,0,0.01); + } else { + g0overg1er_hist = new TH1F("g0overg1er_hist","",100,0,0.001); + } + + TH1F* g0overg1_hist_isEdge = new TH1F("g0overg1_hist_isEdge","",100,-34,-24); + TH1F* g0overg1_hist_isInnerEdge = new TH1F("g0overg1_hist_isInnerEdge","",100,-34,-24); + TH1F* g0overg1_hist_isDouble = new TH1F("g0overg1_hist_isDouble","",100,-34,-24); + TH1F* g0overg1_hist_isNextToDouble = new TH1F("g0overg1_hist_isNextToDouble","",100,-34,-24); + TH1F* g0overg1_hist_isQuad = new TH1F("g0overg1_hist_isQuad","",100,-34,-24); + TH1F* g0overg1_hist_isBulk = new TH1F("g0overg1_hist_isBulk","",100,-34,-24); + + TH2F* g0overg1_map = new TH2F("g0overg1_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g0overg1er_map = new TH2F("g0overg1er_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + if (createHistos == 1) { + + for (int j = 0; j < 220; j++) { + sprintf(savename,"avg_adcG0_map_%d", j); + avg_adcG0_map[j] = new TH2F(savename,"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + sprintf(savename,"avg_adcG0er_map_%d", j); + avg_adcG0er_map[j] = new TH2F(savename,"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + sprintf(savename,"avg_adcG1_map_%d", j); + avg_adcG1_map[j] = new TH2F(savename,"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + sprintf(savename,"avg_adcG1er_map_%d", j); + avg_adcG1er_map[j] = new TH2F(savename,"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + } + + // data file + sprintf(filename,"%s_%%6.6d.dat", data_loc.c_str()); + + // total frame number check + int totalFrames = 0; + + for (int filei = 0; filei < 2; filei++) { + + thisfile->open((char*)filename, filei); + + while(thisfile->readNextFrame()) { + totalFrames++; + } + + thisfile->close(); + } + + if (totalFrames == 19999 || totalFrames == 20000) { + cout << "expected number of frames " << totalFrames << endl; + } else { + cout << "unexpected number of frames " << totalFrames << endl; + cout << "code expected 21999/22000 frames" << endl; + cout << "exiting to make sure you notice" << endl; + //exit(1); + } + + int framecounter = 0; + + for (int filei = 0; filei < 3; filei++) { // was 3 before + + thisfile->open((char*)filename, filei); + + while(thisfile->readNextFrame()) { + + pedestalObjectG0->addG0FrameToPedestalCalculation(thisfile->getFrameDataHandle()); + pedestalObjectG1->addG1FrameToPedestalCalculation(thisfile->getFrameDataHandle()); + + if (((framecounter+1)%100 == 0) || ((totalFrames == 21999) && (framecounter == 21998))) { + if ((totalFrames == 21999) && (framecounter == 21998)) { + framecounter++; + } + + for (int i = 0; i < NCH; i++) { + + if((i/NC<256 || i/NC>511) || (i%NC<256 || i%NC>511)){ + continue; + } + + avg_adcG0_map[framecounter/100]->SetBinContent((i%NC)+1,(i/NC)+1,pedestalObjectG0->pedestalOfChannel(i)); + avg_adcG0er_map[framecounter/100]->SetBinContent((i%NC)+1,(i/NC)+1,pedestalObjectG0->semOfChannel(i)); + + avg_adcG1_map[framecounter/100]->SetBinContent((i%NC)+1,(i/NC)+1,pedestalObjectG1->pedestalOfChannel(i)); + avg_adcG1er_map[framecounter/100]->SetBinContent((i%NC)+1,(i/NC)+1,pedestalObjectG1->semOfChannel(i)); + + } + + pedestalObjectG0->pedestalClear(); + pedestalObjectG1->pedestalClear(); + + if (createPerStepHistos == 1) { + avg_adcG0_map[framecounter/100]->GetXaxis()->SetTitle("Column"); + avg_adcG0_map[framecounter/100]->GetYaxis()->SetTitle("Row"); + avg_adcG0_map[framecounter/100]->GetYaxis()->SetTitleOffset(0.7); + avg_adcG0_map[framecounter/100]->GetZaxis()->SetRangeUser(0,17000); + avg_adcG0_map[framecounter/100]->Draw("colz"); + sprintf(savename,"plots/M%s/BackplanePulsing/perStep/adc_g0_map_%d_M%s.png", module_str.c_str(), framecounter/100, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + avg_adcG0er_map[framecounter/100]->GetXaxis()->SetTitle("Column"); + avg_adcG0er_map[framecounter/100]->GetYaxis()->SetTitle("Row"); + avg_adcG0er_map[framecounter/100]->GetYaxis()->SetTitleOffset(0.7); + avg_adcG0er_map[framecounter/100]->GetZaxis()->SetRangeUser(0,5); + avg_adcG0er_map[framecounter/100]->Draw("colz"); + sprintf(savename,"plots/M%s/BackplanePulsing/perStep/adcer_g0_map_%d_M%s.png", module_str.c_str(), framecounter/100, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + avg_adcG1_map[framecounter/100]->GetXaxis()->SetTitle("Column"); + avg_adcG1_map[framecounter/100]->GetYaxis()->SetTitle("Row"); + avg_adcG1_map[framecounter/100]->GetYaxis()->SetTitleOffset(0.7); + avg_adcG1_map[framecounter/100]->GetZaxis()->SetRangeUser(0,17000); + avg_adcG1_map[framecounter/100]->Draw("colz"); + sprintf(savename,"plots/M%s/BackplanePulsing/perStep/adc_g1_map_%d_M%s.png", module_str.c_str(), framecounter/100, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + avg_adcG1er_map[framecounter/100]->GetXaxis()->SetTitle("Column"); + avg_adcG1er_map[framecounter/100]->GetYaxis()->SetTitle("Row"); + avg_adcG1er_map[framecounter/100]->GetYaxis()->SetTitleOffset(0.7); + avg_adcG1er_map[framecounter/100]->GetZaxis()->SetRangeUser(0,20); + avg_adcG1er_map[framecounter/100]->Draw("colz"); + sprintf(savename,"plots/M%s/BackplanePulsing/perStep/adcer_g1_map_%d_M%s.png", module_str.c_str(), framecounter/100, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + } + + framecounter++; + } + thisfile->close(); + } // end of files + + // save histograms + //sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna/BP_histos_M%s.root", module_str.c_str(), module_str.c_str()); //uncomment for SR + sprintf(savename,"%s/BP_histos_M%s.root", anadata_loc.c_str(), module_str.c_str()); //uncomment for VH 210906 + TFile* saved_file = new TFile((const char *)(savename),"RECREATE"); + + for (int i = 0; i < 220; i++) { + avg_adcG0_map[i]->Write(); + avg_adcG1_map[i]->Write(); + avg_adcG0er_map[i]->Write(); + avg_adcG1er_map[i]->Write(); + } + saved_file->Close(); + + } else { + // load histos + cout << "LOADING HISTOS" << endl; + //sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna/BP_histos_M%s.root", module_str.c_str(), module_str.c_str()); //uncomment for SR + sprintf(savename,"%s/BP_histos_M%s.root", anadata_loc.c_str(), module_str.c_str()); //uncomment for VH 210906 + TFile* saved_file = new TFile((const char *)(savename),"READ"); + + for (int i = 0; i < 220; i++) { + sprintf(savename,"avg_adcG0_map_%d", i); + avg_adcG0_map[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"avg_adcG1_map_%d", i); + avg_adcG1_map[i] = (TH2F*)saved_file->Get((const char *)(savename)); + + sprintf(savename,"avg_adcG0er_map_%d", i); + avg_adcG0er_map[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"avg_adcG1er_map_%d", i); + avg_adcG1er_map[i] = (TH2F*)saved_file->Get((const char *)(savename)); + } + } + + mapcanvas->SetLeftMargin(0.13); + mapcanvas->SetRightMargin(0.05); + + for (int i = 0; i < NCH; i++) { + if((i/NC<256 || i/NC>511) || (i%NC<256 || i%NC>511)){ + continue; + } + + vector r0_adc; + vector r0_filter; + + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector r1_ferr; + + for (int j = 0; j < 220; j++) { + + double this_g0avg = avg_adcG0_map[j]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g1avg = avg_adcG1_map[j]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g0avger = avg_adcG0er_map[j]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g1avger = avg_adcG1er_map[j]->GetBinContent((i%NC)+1,(i/NC)+1); + + if (this_g0avg != 0) { + r0_filter.push_back(xs[j]); + r0_ferr.push_back(0.); + r0_adc.push_back(this_g0avg); + r0_adcerr.push_back(this_g0avger); + } + if (this_g1avg != 0) { + r1_filter.push_back(xs[j]); + r1_ferr.push_back(0.); + r1_adc.push_back(this_g1avg); + r1_adcerr.push_back(this_g1avger); + } + } + + 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; + + // 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) { + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + //|| (i >= (325*1024+902) && i < (325*1024+902)+10) // addon VH "high" G1 in Module 352 + //|| (i >= (331*1024+902) && i < (331*1024+902)+10) // addon VH "low" G1 in Module 352 + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + 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"); + } + mapcanvas->Update(); + 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) { + + 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"); + + g0_grad_hist->Fill(fit_g0->GetParameter(1)); + g0_grader_hist->Fill(fit_g0->GetParError(1)); + g0_grad_map->Fill(i%NC,i/NC,fit_g0->GetParameter(1)); + g0_grader_map->Fill(i%NC,i/NC,fit_g0->GetParError(1)); + g0_const_hist->Fill(fit_g0->GetParameter(0)); + g0_conster_hist->Fill(fit_g0->GetParError(0)); + g0_const_map->Fill(i%NC,i/NC,fit_g0->GetParameter(0)); + g0_conster_map->Fill(i%NC,i/NC,fit_g0->GetParError(0)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + //|| (i >= (325*1024+902) && i < (325*1024+902)+10) // addon VH "high" G1 in Module 352 + //|| (i >= (331*1024+902) && i < (331*1024+902)+10) // addon VH "low" G1 in Module 352 + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + 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())); + grap_g0->Draw("AP"); + fit_g0->Draw("same"); + mapcanvas->Update(); + // Added by Vadym to save empty fits too as discussed with Mar + if(grap_g0->FindObject("stats")){ 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); + } + 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)); + + vector 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"); + 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; + } + } + } + } + + 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"); + + g1_grad_hist->Fill(fit_g1->GetParameter(1)); + g1_grader_hist->Fill(fit_g1->GetParError(1)); + g1_grad_map->Fill(i%NC,i/NC,fit_g1->GetParameter(1)); + g1_grader_map->Fill(i%NC,i/NC,fit_g1->GetParError(1)); + g1_const_hist->Fill(fit_g1->GetParameter(0)); + g1_conster_hist->Fill(fit_g1->GetParError(0)); + g1_const_map->Fill(i%NC,i/NC,fit_g1->GetParameter(0)); + g1_conster_map->Fill(i%NC,i/NC,fit_g1->GetParError(0)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + //|| (i >= (325*1024+902) && i < (325*1024+902)+10) // addon VH "high" G1 in Module 352 + //|| (i >= (331*1024+902) && i < (331*1024+902)+10) // addon VH "low" G1 in Module 352 + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + 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())); + grap_g1->Draw("AP"); + fit_g1->Draw("same"); + mapcanvas->Update(); + 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); + 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 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])); + } + + 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"); + 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)); + + g0overg1_map->Fill(i%NC,i/NC,this_g0overg1); + g0overg1_hist->Fill(this_g0overg1); + g0overg1er_map->Fill(i%NC,i/NC,this_g0overg1er); + g0overg1er_hist->Fill(this_g0overg1er); + + if (isEdge(i)) { + g0overg1_hist_isEdge->Fill(this_g0overg1); + } + if (isInnerEdge(i)) { + g0overg1_hist_isInnerEdge->Fill(this_g0overg1); + } + if (isDouble(i)) { + g0overg1_hist_isDouble->Fill(this_g0overg1); + } + if (isNextToDouble(i)) { + g0overg1_hist_isNextToDouble->Fill(this_g0overg1); + } + if (isQuad(i)) { + g0overg1_hist_isQuad->Fill(this_g0overg1); + } + if (isBulk(i)) { + g0overg1_hist_isBulk->Fill(this_g0overg1); + } + } else { + no_g0g1_calib_map->Fill(i%NC,i/NC,1); + } + + delete grap_g0; + delete grap_g1; + } + + mapcanvas->SetLeftMargin(0.1); + mapcanvas->SetRightMargin(0.13); + + c1->cd(); + + g0_grad_hist->GetXaxis()->SetTitle("G0 gradient"); + g0_grad_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0_grad_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0_grader_hist->GetXaxis()->SetTitle("#sigma_{G0 gradient}"); + g0_grader_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0_grader_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1_grad_hist->GetXaxis()->SetTitle("G1 gradient"); + g1_grad_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1_grad_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1_grader_hist->GetXaxis()->SetTitle("#sigma_{G1 gradient}"); + g1_grader_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1_grader_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0_const_hist->GetXaxis()->SetTitle("G0 intercept"); + g0_const_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0_const_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0_conster_hist->GetXaxis()->SetTitle("#sigma_{G0 intercept}"); + g0_conster_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0_conster_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1_const_hist->GetXaxis()->SetTitle("G1 intercept"); + g1_const_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1_const_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1_conster_hist->GetXaxis()->SetTitle("#sigma_{G1 intercept}"); + g1_conster_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1_conster_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + mapcanvas->cd(); + + TPaveText *pave = new TPaveText(0.86,0.95,0.91,0.98,"blNDC"); + pave->SetBorderSize(0); + pave->SetFillStyle(0); + pave->SetTextSize(0.06); + pave->SetTextAlign(32); + + g0_grad_map->GetXaxis()->SetTitle("Column"); + g0_grad_map->GetYaxis()->SetTitle("Row"); + g0_grad_map->GetYaxis()->SetTitleOffset(0.7); + g0_grad_map->Draw("colz"); + pave->AddText("G0 [ADU/mV]"); + pave->Draw(); + if (module_str == "351" || + module_str == "351_fullspeed" || + module_str == "352" || + module_str == "352_fullspeed" || + module_str == "261" || + module_str == "261_fullspeed" || + module_str == "310" || + module_str == "310_fullspeed" || + module_str == "312" || + module_str == "312_fullspeed" || + module_str == "264" || + module_str == "264_fullspeed" || + module_str == "253" || + module_str == "253_fullspeed" || + module_str == "307" || + module_str == "307_fullspeed" || + module_str == "272_halfspeedtest" || + module_str == "272_fullspeedtest") { + g0_grad_map->GetZaxis()->SetRangeUser(3,4); + } else { + g0_grad_map->GetZaxis()->SetRangeUser(5,10); + } + if (isHGX) g0_grad_map->GetZaxis()->SetRangeUser(10,15); + + + sprintf(savename,"plots/M%s/%s/g0_grad_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0_grader_map->GetXaxis()->SetTitle("Column"); + g0_grader_map->GetYaxis()->SetTitle("Row"); + g0_grader_map->GetYaxis()->SetTitleOffset(0.7); + g0_grader_map->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G0}"); + pave->Draw(); + g0_grader_map->GetZaxis()->SetRangeUser(0.0,0.001); + sprintf(savename,"plots/M%s/%s/g0_grader_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1_grad_map->GetXaxis()->SetTitle("Column"); + g1_grad_map->GetYaxis()->SetTitle("Row"); + g1_grad_map->GetYaxis()->SetTitleOffset(0.7); + g1_grad_map->Draw("colz"); + pave->Clear(); + pave->AddText("G1 [ADU/mV]"); + pave->Draw(); + if (module_str == "006") { + g1_grad_map->GetZaxis()->SetRangeUser(-0.3,-0.1); + } else if (module_str == "021" || module_str == "022" || module_str == "044") { + g1_grad_map->GetZaxis()->SetRangeUser(-0.3,-0.23); + } else if (module_str == "351" || + module_str == "351_fullspeed" || + module_str == "352" || + module_str == "352_fullspeed" || + module_str == "261" || + module_str == "261_fullspeed" || + module_str == "310" || + module_str == "310_fullspeed" || + module_str == "312" || + module_str == "312_fullspeed" || + module_str == "264" || + module_str == "264_fullspeed" || + module_str == "253" || + module_str == "253_fullspeed" || + module_str == "307" || + module_str == "307_fullspeed" || + module_str == "272_halfspeedtest" || + module_str == "272_fullspeedtest") { + g1_grad_map->GetZaxis()->SetRangeUser(-0.15,-0.1); + } else { + g1_grad_map->GetZaxis()->SetRangeUser(-0.25,-0.2); + } + + if (isHGX) g1_grad_map->GetZaxis()->SetRangeUser(-0.2,-0.1); + sprintf(savename,"plots/M%s/%s/g1_grad_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1_grader_map->GetXaxis()->SetTitle("Column"); + g1_grader_map->GetYaxis()->SetTitle("Row"); + g1_grader_map->GetYaxis()->SetTitleOffset(0.7); + g1_grader_map->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G1}"); + pave->Draw(); + if (module_str == "006") { + g1_grader_map->GetZaxis()->SetRangeUser(0.0,0.002); + } else { + g1_grader_map->GetZaxis()->SetRangeUser(0.0,0.0002); + } + sprintf(savename,"plots/M%s/%s/g1_grader_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0_const_map->GetXaxis()->SetTitle("Column"); + g0_const_map->GetYaxis()->SetTitle("Row"); + g0_const_map->GetYaxis()->SetTitleOffset(0.7); + g0_const_map->Draw("colz"); + g0_const_map->GetZaxis()->SetRangeUser(1500,3500); + sprintf(savename,"plots/M%s/%s/g0_const_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0_conster_map->GetXaxis()->SetTitle("Column"); + g0_conster_map->GetYaxis()->SetTitle("Row"); + g0_conster_map->GetYaxis()->SetTitleOffset(0.7); + g0_conster_map->Draw("colz"); + g0_conster_map->GetZaxis()->SetRangeUser(0.0,0.5); + sprintf(savename,"plots/M%s/%s/g0_conster_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1_const_map->GetXaxis()->SetTitle("Column"); + g1_const_map->GetYaxis()->SetTitle("Row"); + g1_const_map->GetYaxis()->SetTitleOffset(0.7); + g1_const_map->Draw("colz"); + if (module_str == "006") { + g1_const_map->GetZaxis()->SetRangeUser(10000,15000); + } else { + g1_const_map->GetZaxis()->SetRangeUser(13000,15000); + } + sprintf(savename,"plots/M%s/%s/g1_const_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1_conster_map->GetXaxis()->SetTitle("Column"); + g1_conster_map->GetYaxis()->SetTitle("Row"); + g1_conster_map->GetYaxis()->SetTitleOffset(0.7); + g1_conster_map->Draw("colz"); + if (module_str == "006") { + g1_conster_map->GetZaxis()->SetRangeUser(0.0,10.); + } else { + g1_conster_map->GetZaxis()->SetRangeUser(0.0,1.); + } + sprintf(savename,"plots/M%s/%s/g1_conster_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + c1->cd(); + + g0overg1_hist->GetXaxis()->SetTitle("G0 / G1"); + g0overg1_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + TPaveText *pave2 = new TPaveText(0.6,0.8,0.94,0.94,"blNDC"); + pave2->SetBorderSize(0); + pave2->SetFillStyle(0); + pave2->SetTextSize(0.04); + pave2->SetTextAlign(32); + g0overg1_hist->Fit("gaus"); + g0overg1_hist->Draw(); + c1->Update(); + TF1* g0overg1hist_gaus = g0overg1_hist->GetFunction("gaus"); + if (g0overg1hist_gaus) { + sprintf(savename,"Mean %0.4f #pm %0.4f", g0overg1hist_gaus->GetParameter(1), g0overg1hist_gaus->GetParError(1)); + pave2->AddText((const char *)(savename)); + sprintf(savename,"Sigma %0.4f #pm %0.4f", g0overg1hist_gaus->GetParameter(2), g0overg1hist_gaus->GetParError(2)); + pave2->AddText((const char *)(savename)); + pave2->Draw(); + } + g0overg1_hist->SetStats(kFALSE); + sprintf(savename,"plots/M%s/%s/g0overg1_histfit_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0overg1er_hist->GetXaxis()->SetTitle("#sigma_{G0 / G1}"); + g0overg1er_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1er_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0overg1_hist_isEdge->SetLineColor(kBlue); + g0overg1_hist_isInnerEdge->SetLineColor(kCyan); + g0overg1_hist_isDouble->SetLineColor(kGreen+2); + g0overg1_hist_isNextToDouble->SetLineColor(kRed); + g0overg1_hist_isQuad->SetLineColor(kOrange); + + g0overg1_hist_isEdge->Scale(1./g0overg1_hist_isEdge->GetEntries()); + g0overg1_hist_isInnerEdge->Scale(1./g0overg1_hist_isInnerEdge->GetEntries()); + g0overg1_hist_isDouble->Scale(1./g0overg1_hist_isDouble->GetEntries()); + g0overg1_hist_isNextToDouble->Scale(1./g0overg1_hist_isNextToDouble->GetEntries()); + g0overg1_hist_isQuad->Scale(1./g0overg1_hist_isQuad->GetEntries()); + g0overg1_hist_isBulk->Scale(1./g0overg1_hist_isBulk->GetEntries()); + + TLegend *leg = new TLegend(0.62,0.6,0.93,0.93); + leg->AddEntry(g0overg1_hist_isBulk, "Normal", "l"); + leg->AddEntry(g0overg1_hist_isDouble, "Double", "l"); + leg->AddEntry(g0overg1_hist_isNextToDouble, "Next to D", "l"); + leg->AddEntry(g0overg1_hist_isEdge, "Edge", "l"); + leg->AddEntry(g0overg1_hist_isInnerEdge, "Inner E", "l"); + + if (module_str == "006") { + g0overg1_hist_isEdge->GetXaxis()->SetTitle("G0 / G1"); + g0overg1_hist_isEdge->GetYaxis()->SetTitle("Normalised"); + g0overg1_hist_isEdge->GetYaxis()->SetTitleOffset(1.3); + g0overg1_hist_isEdge->Draw(); + g0overg1_hist_isDouble->Draw("same"); + } else { + g0overg1_hist_isDouble->GetXaxis()->SetTitle("G0 / G1"); + g0overg1_hist_isDouble->GetYaxis()->SetTitle("Normalised"); + g0overg1_hist_isDouble->GetYaxis()->SetTitleOffset(1.3); + g0overg1_hist_isDouble->Draw(); + g0overg1_hist_isEdge->Draw("same"); + } + g0overg1_hist_isInnerEdge->Draw("same"); + g0overg1_hist_isNextToDouble->Draw("same"); + g0overg1_hist_isBulk->Draw("same"); + leg->Draw("same"); + sprintf(savename,"plots/M%s/%s/g0overg1_hist_perType_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + mapcanvas->cd(); + + g0overg1_map->GetXaxis()->SetTitle("Column"); + g0overg1_map->GetYaxis()->SetTitle("Row"); + g0overg1_map->GetYaxis()->SetTitleOffset(0.7); + g0overg1_map->Draw("colz"); + pave->Clear(); + pave->AddText("G0/G1"); + pave->Draw(); + + if (isHGX) { + g0overg1_map->GetZaxis()->SetRangeUser(-110,-70); + } + else { + //g0overg1_map->GetZaxis()->SetRangeUser(-31,-27); + g0overg1_map->GetZaxis()->SetRangeUser(-55,-25); + } + + sprintf(savename,"plots/M%s/%s/g0overg1_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0overg1er_map->GetXaxis()->SetTitle("Column"); + g0overg1er_map->GetYaxis()->SetTitle("Row"); + g0overg1er_map->GetYaxis()->SetTitleOffset(0.7); + g0overg1er_map->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G0/G1}"); + pave->Draw(); + if (module_str == "006") { + g0overg1er_map->GetZaxis()->SetRangeUser(0,0.01); + } else { + g0overg1er_map->GetZaxis()->SetRangeUser(0,0.001); + } + sprintf(savename,"plots/M%s/%s/g0overg1er_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + no_g0g1_calib_map->GetXaxis()->SetTitle("Column"); + no_g0g1_calib_map->GetYaxis()->SetTitle("Row"); + no_g0g1_calib_map->GetYaxis()->SetTitleOffset(0.7); + no_g0g1_calib_map->Draw("colz"); + sprintf(savename,"plots/M%s/%s/no_g0g1_calib_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + + if (isHGX) { + sprintf(savename,"data/M%s/BP_ratio_M%s_HG0G1G2.root", module_str.c_str(), module_str.c_str()); + } + else + { + sprintf(savename,"data/M%s/BP_ratio_M%s.root", module_str.c_str(), module_str.c_str()); + } + + + TFile* saved_file2 = new TFile((const char *)(savename),"RECREATE"); + g0overg1_map->Write(); + g0overg1er_map->Write(); + g0_grad_map->Write(); + g1_grad_map->Write(); + saved_file2->Close(); + +} diff --git a/BP_analysis_thinSensors.cpp b/BP_analysis_thinSensors.cpp new file mode 100644 index 0000000..d734b7d --- /dev/null +++ b/BP_analysis_thinSensors.cpp @@ -0,0 +1,1110 @@ +// 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 "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 "TPaveStats.h" +#include "TFile.h" +#include "TLegend.h" +#include "TPaveText.h" + +#include + +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[]) { + + 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; + exit(1); + } + */ //uncomment for SR + + if (argc != 4) { + cout << "Correct usage:" << endl; + cout << "arg 1: specify module number" << endl; + cout << "arg 2: specify data location (folder + data file prefix)" << endl; + cout << "arg 3: specify location of analysis root files" << endl; + exit(1); + } //uncomment for VH 210906 + + string module_str = argv[1]; + + string str2 =("HG0G1G2"); + string str3 =("HGOG1G2"); //filename creator had this bug + + string data_loc = argv[2]; + string anadata_loc = argv[3]; //uncomment for VH 210906 + string plotfolder_str; + + + if (data_loc.find(str2) != string::npos) isHGX=true; + if (data_loc.find(str3) != string::npos) isHGX=true; + + + // cout << data_loc.find(str2)<<" " << string::npos << " " << str2 << " " << data_loc <HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" <pedestalSetNFrames(100); // using 100 frames, rolling window + jungfrauPedestal *pedestalObjectG1 = new jungfrauPedestal(); + pedestalObjectG1->pedestalSetNFrames(100); // using 100 frames, rolling window + + TH2F* avg_adcG0_map [245]; + TH2F* avg_adcG0er_map [245]; + TH2F* avg_adcG1_map [245]; + TH2F* avg_adcG1er_map [245]; + + //char savename[128]; //uncomment for SR + //char filename[128]; //uncomment for SR + char savename[256]; //uncomment for VH 210902 + 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 *mapcanvas = new TCanvas("mapcanvas","",150,10,800,400); + mapcanvas->SetLeftMargin(0.1); + mapcanvas->SetRightMargin(0.13); + mapcanvas->SetTopMargin(0.08); + mapcanvas->SetBottomMargin(0.15); + + TCanvas* c1 = new TCanvas("c1",""); + + mapcanvas->cd(); + + TH1F* g0_grad_hist = 0; + if (module_str == "351" || + module_str == "351_fullspeed" || + module_str == "352" || + module_str == "352_fullspeed" || + module_str == "261" || + module_str == "261_fullspeed" || + module_str == "310" || + module_str == "310_fullspeed" || + module_str == "312" || + module_str == "312_fullspeed" || + module_str == "264" || + module_str == "264_fullspeed" || + module_str == "253" || + module_str == "253_fullspeed" || + module_str == "307" || + module_str == "307_fullspeed" || + module_str == "272_halfspeedtest" || + module_str == "272_fullspeedtest") { + g0_grad_hist = new TH1F("g0_grad_hist","",100,3,8); + } else { + g0_grad_hist = new TH1F("g0_grad_hist","",100,5,10); + } + TH1F* g0_grader_hist = new TH1F("g0_grader_hist","",100,0,0.002); + + TH1F* g1_grad_hist = 0; + if (module_str == "351" || + module_str == "351_fullspeed" || + module_str == "352" || + module_str == "352_fullspeed" || + module_str == "261" || + module_str == "261_fullspeed" || + module_str == "310" || + module_str == "310_fullspeed" || + module_str == "312" || + module_str == "312_fullspeed" || + module_str == "264" || + module_str == "264_fullspeed" || + module_str == "253" || + module_str == "253_fullspeed" || + module_str == "307" || + module_str == "307_fullspeed" || + module_str == "272_halfspeedtest" || + module_str == "272_fullspeedtest") { + g1_grad_hist = new TH1F("g1_grad_hist","",100,-0.25,-0.1); + } else { + g1_grad_hist = new TH1F("g1_grad_hist","",100,-0.3,-0.15); + } + TH1F* g1_grader_hist = 0; + if (module_str == "006") { + g1_grader_hist = new TH1F("g1_grader_hist","",100,0,0.001); + } else { + g1_grader_hist = new TH1F("g1_grader_hist","",100,0,0.0001); + } + + TH2F* no_g0g1_calib_map = new TH2F("no_g0g1_calib_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* g0_grad_map = new TH2F("g0_grad_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g0_grader_map = new TH2F("g0_grader_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* g1_grad_map = new TH2F("g1_grad_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g1_grader_map = new TH2F("g1_grader_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH1F* g0_const_hist = new TH1F("g0_const_hist","",100,1000,4000); + TH1F* g0_conster_hist = new TH1F("g0_conster_hist","",100,0,0.5); + + TH1F* g1_const_hist = new TH1F("g1_const_hist","",100,10000,15000); + TH1F* g1_conster_hist = 0; + if (module_str == "006") { + g1_conster_hist = new TH1F("g1_conster_hist","",100,0,10); + } else { + g1_conster_hist = new TH1F("g1_conster_hist","",100,0,1); + } + + TH2F* g0_const_map = new TH2F("g0_const_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g0_conster_map = new TH2F("g0_conster_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* g1_const_map = new TH2F("g1_const_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g1_conster_map = new TH2F("g1_conster_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH1F* g0overg1_hist = new TH1F("g0overg1_hist","",100,-34,-24); + TH1F* g0overg1er_hist = 0; + if (module_str == "006") { + g0overg1er_hist = new TH1F("g0overg1er_hist","",100,0,0.01); + } else { + g0overg1er_hist = new TH1F("g0overg1er_hist","",100,0,0.001); + } + + TH1F* g0overg1_hist_isEdge = new TH1F("g0overg1_hist_isEdge","",100,-34,-24); + TH1F* g0overg1_hist_isInnerEdge = new TH1F("g0overg1_hist_isInnerEdge","",100,-34,-24); + TH1F* g0overg1_hist_isDouble = new TH1F("g0overg1_hist_isDouble","",100,-34,-24); + TH1F* g0overg1_hist_isNextToDouble = new TH1F("g0overg1_hist_isNextToDouble","",100,-34,-24); + TH1F* g0overg1_hist_isQuad = new TH1F("g0overg1_hist_isQuad","",100,-34,-24); + TH1F* g0overg1_hist_isBulk = new TH1F("g0overg1_hist_isBulk","",100,-34,-24); + + TH2F* g0overg1_map = new TH2F("g0overg1_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* g0overg1er_map = new TH2F("g0overg1er_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + if (createHistos == 1) { + + for (int j = 0; j < 245; j++) { + sprintf(savename,"avg_adcG0_map_%d", j); + avg_adcG0_map[j] = new TH2F(savename,"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + sprintf(savename,"avg_adcG0er_map_%d", j); + avg_adcG0er_map[j] = new TH2F(savename,"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + sprintf(savename,"avg_adcG1_map_%d", j); + avg_adcG1_map[j] = new TH2F(savename,"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + sprintf(savename,"avg_adcG1er_map_%d", j); + avg_adcG1er_map[j] = new TH2F(savename,"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + } + + // data file + sprintf(filename,"%s_%%6.6d.dat", data_loc.c_str()); + + // total frame number check + int totalFrames = 0; + + for (int filei = 0; filei < 2; filei++) { + + thisfile->open((char*)filename, filei); + + while(thisfile->readNextFrame()) { + totalFrames++; + } + + thisfile->close(); + } + + if (totalFrames == 19999 || totalFrames == 20000) { + cout << "expected number of frames " << totalFrames << endl; + } else { + cout << "unexpected number of frames " << totalFrames << endl; + cout << "code expected 21999/22000 frames" << endl; + cout << "exiting to make sure you notice" << endl; + exit(1); + } + + int framecounter = 0; + + for (int filei = 0; filei < 3; filei++) { + + thisfile->open((char*)filename, filei); + + while(thisfile->readNextFrame()) { + + pedestalObjectG0->addG0FrameToPedestalCalculation(thisfile->getFrameDataHandle()); + pedestalObjectG1->addG1FrameToPedestalCalculation(thisfile->getFrameDataHandle()); + + if (((framecounter+1)%100 == 0) || ((totalFrames == 21999) && (framecounter == 21998))) { + if ((totalFrames == 21999) && (framecounter == 21998)) { + framecounter++; + } + + for (int i = 0; i < NCH; i++) { + + avg_adcG0_map[framecounter/100]->SetBinContent((i%NC)+1,(i/NC)+1,pedestalObjectG0->pedestalOfChannel(i)); + avg_adcG0er_map[framecounter/100]->SetBinContent((i%NC)+1,(i/NC)+1,pedestalObjectG0->semOfChannel(i)); + + avg_adcG1_map[framecounter/100]->SetBinContent((i%NC)+1,(i/NC)+1,pedestalObjectG1->pedestalOfChannel(i)); + avg_adcG1er_map[framecounter/100]->SetBinContent((i%NC)+1,(i/NC)+1,pedestalObjectG1->semOfChannel(i)); + + } + + pedestalObjectG0->pedestalClear(); + pedestalObjectG1->pedestalClear(); + + if (createPerStepHistos == 1) { + avg_adcG0_map[framecounter/100]->GetXaxis()->SetTitle("Column"); + avg_adcG0_map[framecounter/100]->GetYaxis()->SetTitle("Row"); + avg_adcG0_map[framecounter/100]->GetYaxis()->SetTitleOffset(0.7); + avg_adcG0_map[framecounter/100]->GetZaxis()->SetRangeUser(0,17000); + avg_adcG0_map[framecounter/100]->Draw("colz"); + sprintf(savename,"plots/M%s/BackplanePulsing/perStep/adc_g0_map_%d_M%s.png", module_str.c_str(), framecounter/100, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + avg_adcG0er_map[framecounter/100]->GetXaxis()->SetTitle("Column"); + avg_adcG0er_map[framecounter/100]->GetYaxis()->SetTitle("Row"); + avg_adcG0er_map[framecounter/100]->GetYaxis()->SetTitleOffset(0.7); + avg_adcG0er_map[framecounter/100]->GetZaxis()->SetRangeUser(0,5); + avg_adcG0er_map[framecounter/100]->Draw("colz"); + sprintf(savename,"plots/M%s/BackplanePulsing/perStep/adcer_g0_map_%d_M%s.png", module_str.c_str(), framecounter/100, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + avg_adcG1_map[framecounter/100]->GetXaxis()->SetTitle("Column"); + avg_adcG1_map[framecounter/100]->GetYaxis()->SetTitle("Row"); + avg_adcG1_map[framecounter/100]->GetYaxis()->SetTitleOffset(0.7); + avg_adcG1_map[framecounter/100]->GetZaxis()->SetRangeUser(0,17000); + avg_adcG1_map[framecounter/100]->Draw("colz"); + sprintf(savename,"plots/M%s/BackplanePulsing/perStep/adc_g1_map_%d_M%s.png", module_str.c_str(), framecounter/100, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + avg_adcG1er_map[framecounter/100]->GetXaxis()->SetTitle("Column"); + avg_adcG1er_map[framecounter/100]->GetYaxis()->SetTitle("Row"); + avg_adcG1er_map[framecounter/100]->GetYaxis()->SetTitleOffset(0.7); + avg_adcG1er_map[framecounter/100]->GetZaxis()->SetRangeUser(0,20); + avg_adcG1er_map[framecounter/100]->Draw("colz"); + sprintf(savename,"plots/M%s/BackplanePulsing/perStep/adcer_g1_map_%d_M%s.png", module_str.c_str(), framecounter/100, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + } + + framecounter++; + } + thisfile->close(); + } // end of files + + // save histograms + //sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna/BP_histos_M%s.root", module_str.c_str(), module_str.c_str()); //uncomment for SR + sprintf(savename,"%s/BP_histos_M%s.root", anadata_loc.c_str(), module_str.c_str()); //uncomment for VH 210906 + TFile* saved_file = new TFile((const char *)(savename),"RECREATE"); + + for (int i = 0; i < 245; i++) { + avg_adcG0_map[i]->Write(); + avg_adcG1_map[i]->Write(); + avg_adcG0er_map[i]->Write(); + avg_adcG1er_map[i]->Write(); + } + saved_file->Close(); + + } else { + // load histos + cout << "LOADING HISTOS" << endl; + //sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna/BP_histos_M%s.root", module_str.c_str(), module_str.c_str()); //uncomment for SR + sprintf(savename,"%s/BP_histos_M%s.root", anadata_loc.c_str(), module_str.c_str()); //uncomment for VH 210906 + TFile* saved_file = new TFile((const char *)(savename),"READ"); + + for (int i = 0; i < 245; i++) { + sprintf(savename,"avg_adcG0_map_%d", i); + avg_adcG0_map[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"avg_adcG1_map_%d", i); + avg_adcG1_map[i] = (TH2F*)saved_file->Get((const char *)(savename)); + + sprintf(savename,"avg_adcG0er_map_%d", i); + avg_adcG0er_map[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"avg_adcG1er_map_%d", i); + avg_adcG1er_map[i] = (TH2F*)saved_file->Get((const char *)(savename)); + } + } + + mapcanvas->SetLeftMargin(0.13); + mapcanvas->SetRightMargin(0.05); + + for (int i = 0; i < NCH; i++) { + + vector r0_adc; + vector r0_filter; + + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector r1_ferr; + + for (int j = 0; j < 245; j++) { + + double this_g0avg = avg_adcG0_map[j]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g1avg = avg_adcG1_map[j]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g0avger = avg_adcG0er_map[j]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g1avger = avg_adcG1er_map[j]->GetBinContent((i%NC)+1,(i/NC)+1); + + if (this_g0avg != 0) { + r0_filter.push_back(xs[j]); + r0_ferr.push_back(0.); + r0_adc.push_back(this_g0avg); + r0_adcerr.push_back(this_g0avger); + } + if (this_g1avg != 0) { + r1_filter.push_back(xs[j]); + r1_ferr.push_back(0.); + r1_adc.push_back(this_g1avg); + r1_adcerr.push_back(this_g1avger); + } + } + + 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; + + // 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) { + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + //|| (i >= (325*1024+902) && i < (325*1024+902)+10) // addon VH "high" G1 in Module 352 + //|| (i >= (331*1024+902) && i < (331*1024+902)+10) // addon VH "low" G1 in Module 352 + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + 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"); + } + mapcanvas->Update(); + 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) { + + 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"); + + g0_grad_hist->Fill(fit_g0->GetParameter(1)); + g0_grader_hist->Fill(fit_g0->GetParError(1)); + g0_grad_map->Fill(i%NC,i/NC,fit_g0->GetParameter(1)); + g0_grader_map->Fill(i%NC,i/NC,fit_g0->GetParError(1)); + g0_const_hist->Fill(fit_g0->GetParameter(0)); + g0_conster_hist->Fill(fit_g0->GetParError(0)); + g0_const_map->Fill(i%NC,i/NC,fit_g0->GetParameter(0)); + g0_conster_map->Fill(i%NC,i/NC,fit_g0->GetParError(0)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + //|| (i >= (325*1024+902) && i < (325*1024+902)+10) // addon VH "high" G1 in Module 352 + //|| (i >= (331*1024+902) && i < (331*1024+902)+10) // addon VH "low" G1 in Module 352 + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + 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())); + grap_g0->Draw("AP"); + fit_g0->Draw("same"); + mapcanvas->Update(); + // Added by Vadym to save empty fits too as discussed with Mar + if(grap_g0->FindObject("stats")){ 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); + } + 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)); + + vector 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"); + 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; + } + } + } + } + + 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"); + + g1_grad_hist->Fill(fit_g1->GetParameter(1)); + g1_grader_hist->Fill(fit_g1->GetParError(1)); + g1_grad_map->Fill(i%NC,i/NC,fit_g1->GetParameter(1)); + g1_grader_map->Fill(i%NC,i/NC,fit_g1->GetParError(1)); + g1_const_hist->Fill(fit_g1->GetParameter(0)); + g1_conster_hist->Fill(fit_g1->GetParError(0)); + g1_const_map->Fill(i%NC,i/NC,fit_g1->GetParameter(0)); + g1_conster_map->Fill(i%NC,i/NC,fit_g1->GetParError(0)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + //|| (i >= (325*1024+902) && i < (325*1024+902)+10) // addon VH "high" G1 in Module 352 + //|| (i >= (331*1024+902) && i < (331*1024+902)+10) // addon VH "low" G1 in Module 352 + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + 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())); + grap_g1->Draw("AP"); + fit_g1->Draw("same"); + mapcanvas->Update(); + 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); + 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 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])); + } + + 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"); + 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)); + + g0overg1_map->Fill(i%NC,i/NC,this_g0overg1); + g0overg1_hist->Fill(this_g0overg1); + g0overg1er_map->Fill(i%NC,i/NC,this_g0overg1er); + g0overg1er_hist->Fill(this_g0overg1er); + + if (isEdge(i)) { + g0overg1_hist_isEdge->Fill(this_g0overg1); + } + if (isInnerEdge(i)) { + g0overg1_hist_isInnerEdge->Fill(this_g0overg1); + } + if (isDouble(i)) { + g0overg1_hist_isDouble->Fill(this_g0overg1); + } + if (isNextToDouble(i)) { + g0overg1_hist_isNextToDouble->Fill(this_g0overg1); + } + if (isQuad(i)) { + g0overg1_hist_isQuad->Fill(this_g0overg1); + } + if (isBulk(i)) { + g0overg1_hist_isBulk->Fill(this_g0overg1); + } + } else { + no_g0g1_calib_map->Fill(i%NC,i/NC,1); + } + + delete grap_g0; + delete grap_g1; + } + + mapcanvas->SetLeftMargin(0.1); + mapcanvas->SetRightMargin(0.13); + + c1->cd(); + + g0_grad_hist->GetXaxis()->SetTitle("G0 gradient"); + g0_grad_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0_grad_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0_grader_hist->GetXaxis()->SetTitle("#sigma_{G0 gradient}"); + g0_grader_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0_grader_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1_grad_hist->GetXaxis()->SetTitle("G1 gradient"); + g1_grad_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1_grad_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1_grader_hist->GetXaxis()->SetTitle("#sigma_{G1 gradient}"); + g1_grader_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1_grader_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0_const_hist->GetXaxis()->SetTitle("G0 intercept"); + g0_const_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0_const_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0_conster_hist->GetXaxis()->SetTitle("#sigma_{G0 intercept}"); + g0_conster_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0_conster_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1_const_hist->GetXaxis()->SetTitle("G1 intercept"); + g1_const_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1_const_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1_conster_hist->GetXaxis()->SetTitle("#sigma_{G1 intercept}"); + g1_conster_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1_conster_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + mapcanvas->cd(); + + TPaveText *pave = new TPaveText(0.86,0.95,0.91,0.98,"blNDC"); + pave->SetBorderSize(0); + pave->SetFillStyle(0); + pave->SetTextSize(0.06); + pave->SetTextAlign(32); + + g0_grad_map->GetXaxis()->SetTitle("Column"); + g0_grad_map->GetYaxis()->SetTitle("Row"); + g0_grad_map->GetYaxis()->SetTitleOffset(0.7); + g0_grad_map->Draw("colz"); + pave->AddText("G0 [ADU/mV]"); + pave->Draw(); + if (module_str == "351" || + module_str == "351_fullspeed" || + module_str == "352" || + module_str == "352_fullspeed" || + module_str == "261" || + module_str == "261_fullspeed" || + module_str == "310" || + module_str == "310_fullspeed" || + module_str == "312" || + module_str == "312_fullspeed" || + module_str == "264" || + module_str == "264_fullspeed" || + module_str == "253" || + module_str == "253_fullspeed" || + module_str == "307" || + module_str == "307_fullspeed" || + module_str == "272_halfspeedtest" || + module_str == "272_fullspeedtest") { + g0_grad_map->GetZaxis()->SetRangeUser(3,4); + } else { + g0_grad_map->GetZaxis()->SetRangeUser(5,10); + } + if (isHGX) g0_grad_map->GetZaxis()->SetRangeUser(10,15); + + + sprintf(savename,"plots/M%s/%s/g0_grad_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0_grader_map->GetXaxis()->SetTitle("Column"); + g0_grader_map->GetYaxis()->SetTitle("Row"); + g0_grader_map->GetYaxis()->SetTitleOffset(0.7); + g0_grader_map->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G0}"); + pave->Draw(); + g0_grader_map->GetZaxis()->SetRangeUser(0.0,0.001); + sprintf(savename,"plots/M%s/%s/g0_grader_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1_grad_map->GetXaxis()->SetTitle("Column"); + g1_grad_map->GetYaxis()->SetTitle("Row"); + g1_grad_map->GetYaxis()->SetTitleOffset(0.7); + g1_grad_map->Draw("colz"); + pave->Clear(); + pave->AddText("G1 [ADU/mV]"); + pave->Draw(); + if (module_str == "006") { + g1_grad_map->GetZaxis()->SetRangeUser(-0.3,-0.1); + } else if (module_str == "021" || module_str == "022" || module_str == "044") { + g1_grad_map->GetZaxis()->SetRangeUser(-0.3,-0.23); + } else if (module_str == "351" || + module_str == "351_fullspeed" || + module_str == "352" || + module_str == "352_fullspeed" || + module_str == "261" || + module_str == "261_fullspeed" || + module_str == "310" || + module_str == "310_fullspeed" || + module_str == "312" || + module_str == "312_fullspeed" || + module_str == "264" || + module_str == "264_fullspeed" || + module_str == "253" || + module_str == "253_fullspeed" || + module_str == "307" || + module_str == "307_fullspeed" || + module_str == "272_halfspeedtest" || + module_str == "272_fullspeedtest") { + g1_grad_map->GetZaxis()->SetRangeUser(-0.15,-0.1); + } else { + g1_grad_map->GetZaxis()->SetRangeUser(-0.25,-0.2); + } + + if (isHGX) g1_grad_map->GetZaxis()->SetRangeUser(-0.2,-0.1); + sprintf(savename,"plots/M%s/%s/g1_grad_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1_grader_map->GetXaxis()->SetTitle("Column"); + g1_grader_map->GetYaxis()->SetTitle("Row"); + g1_grader_map->GetYaxis()->SetTitleOffset(0.7); + g1_grader_map->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G1}"); + pave->Draw(); + if (module_str == "006") { + g1_grader_map->GetZaxis()->SetRangeUser(0.0,0.002); + } else { + g1_grader_map->GetZaxis()->SetRangeUser(0.0,0.0002); + } + sprintf(savename,"plots/M%s/%s/g1_grader_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0_const_map->GetXaxis()->SetTitle("Column"); + g0_const_map->GetYaxis()->SetTitle("Row"); + g0_const_map->GetYaxis()->SetTitleOffset(0.7); + g0_const_map->Draw("colz"); + g0_const_map->GetZaxis()->SetRangeUser(1500,3500); + sprintf(savename,"plots/M%s/%s/g0_const_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0_conster_map->GetXaxis()->SetTitle("Column"); + g0_conster_map->GetYaxis()->SetTitle("Row"); + g0_conster_map->GetYaxis()->SetTitleOffset(0.7); + g0_conster_map->Draw("colz"); + g0_conster_map->GetZaxis()->SetRangeUser(0.0,0.5); + sprintf(savename,"plots/M%s/%s/g0_conster_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1_const_map->GetXaxis()->SetTitle("Column"); + g1_const_map->GetYaxis()->SetTitle("Row"); + g1_const_map->GetYaxis()->SetTitleOffset(0.7); + g1_const_map->Draw("colz"); + if (module_str == "006") { + g1_const_map->GetZaxis()->SetRangeUser(10000,15000); + } else { + g1_const_map->GetZaxis()->SetRangeUser(13000,15000); + } + sprintf(savename,"plots/M%s/%s/g1_const_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1_conster_map->GetXaxis()->SetTitle("Column"); + g1_conster_map->GetYaxis()->SetTitle("Row"); + g1_conster_map->GetYaxis()->SetTitleOffset(0.7); + g1_conster_map->Draw("colz"); + if (module_str == "006") { + g1_conster_map->GetZaxis()->SetRangeUser(0.0,10.); + } else { + g1_conster_map->GetZaxis()->SetRangeUser(0.0,1.); + } + sprintf(savename,"plots/M%s/%s/g1_conster_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + c1->cd(); + + g0overg1_hist->GetXaxis()->SetTitle("G0 / G1"); + g0overg1_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + TPaveText *pave2 = new TPaveText(0.6,0.8,0.94,0.94,"blNDC"); + pave2->SetBorderSize(0); + pave2->SetFillStyle(0); + pave2->SetTextSize(0.04); + pave2->SetTextAlign(32); + g0overg1_hist->Fit("gaus"); + g0overg1_hist->Draw(); + c1->Update(); + TF1* g0overg1hist_gaus = g0overg1_hist->GetFunction("gaus"); + if (g0overg1hist_gaus) { + sprintf(savename,"Mean %0.4f #pm %0.4f", g0overg1hist_gaus->GetParameter(1), g0overg1hist_gaus->GetParError(1)); + pave2->AddText((const char *)(savename)); + sprintf(savename,"Sigma %0.4f #pm %0.4f", g0overg1hist_gaus->GetParameter(2), g0overg1hist_gaus->GetParError(2)); + pave2->AddText((const char *)(savename)); + pave2->Draw(); + } + g0overg1_hist->SetStats(kFALSE); + sprintf(savename,"plots/M%s/%s/g0overg1_histfit_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0overg1er_hist->GetXaxis()->SetTitle("#sigma_{G0 / G1}"); + g0overg1er_hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1er_hist_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0overg1_hist_isEdge->SetLineColor(kBlue); + g0overg1_hist_isInnerEdge->SetLineColor(kCyan); + g0overg1_hist_isDouble->SetLineColor(kGreen+2); + g0overg1_hist_isNextToDouble->SetLineColor(kRed); + g0overg1_hist_isQuad->SetLineColor(kOrange); + + g0overg1_hist_isEdge->Scale(1./g0overg1_hist_isEdge->GetEntries()); + g0overg1_hist_isInnerEdge->Scale(1./g0overg1_hist_isInnerEdge->GetEntries()); + g0overg1_hist_isDouble->Scale(1./g0overg1_hist_isDouble->GetEntries()); + g0overg1_hist_isNextToDouble->Scale(1./g0overg1_hist_isNextToDouble->GetEntries()); + g0overg1_hist_isQuad->Scale(1./g0overg1_hist_isQuad->GetEntries()); + g0overg1_hist_isBulk->Scale(1./g0overg1_hist_isBulk->GetEntries()); + + TLegend *leg = new TLegend(0.62,0.6,0.93,0.93); + leg->AddEntry(g0overg1_hist_isBulk, "Normal", "l"); + leg->AddEntry(g0overg1_hist_isDouble, "Double", "l"); + leg->AddEntry(g0overg1_hist_isNextToDouble, "Next to D", "l"); + leg->AddEntry(g0overg1_hist_isEdge, "Edge", "l"); + leg->AddEntry(g0overg1_hist_isInnerEdge, "Inner E", "l"); + + if (module_str == "006") { + g0overg1_hist_isEdge->GetXaxis()->SetTitle("G0 / G1"); + g0overg1_hist_isEdge->GetYaxis()->SetTitle("Normalised"); + g0overg1_hist_isEdge->GetYaxis()->SetTitleOffset(1.3); + g0overg1_hist_isEdge->Draw(); + g0overg1_hist_isDouble->Draw("same"); + } else { + g0overg1_hist_isDouble->GetXaxis()->SetTitle("G0 / G1"); + g0overg1_hist_isDouble->GetYaxis()->SetTitle("Normalised"); + g0overg1_hist_isDouble->GetYaxis()->SetTitleOffset(1.3); + g0overg1_hist_isDouble->Draw(); + g0overg1_hist_isEdge->Draw("same"); + } + g0overg1_hist_isInnerEdge->Draw("same"); + g0overg1_hist_isNextToDouble->Draw("same"); + g0overg1_hist_isBulk->Draw("same"); + leg->Draw("same"); + sprintf(savename,"plots/M%s/%s/g0overg1_hist_perType_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + mapcanvas->cd(); + + g0overg1_map->GetXaxis()->SetTitle("Column"); + g0overg1_map->GetYaxis()->SetTitle("Row"); + g0overg1_map->GetYaxis()->SetTitleOffset(0.7); + g0overg1_map->Draw("colz"); + pave->Clear(); + pave->AddText("G0/G1"); + pave->Draw(); + + if (isHGX) { + g0overg1_map->GetZaxis()->SetRangeUser(-110,-70); + } + else { + //g0overg1_map->GetZaxis()->SetRangeUser(-31,-27); + g0overg1_map->GetZaxis()->SetRangeUser(-32,-28); + } + + sprintf(savename,"plots/M%s/%s/g0overg1_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0overg1er_map->GetXaxis()->SetTitle("Column"); + g0overg1er_map->GetYaxis()->SetTitle("Row"); + g0overg1er_map->GetYaxis()->SetTitleOffset(0.7); + g0overg1er_map->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G0/G1}"); + pave->Draw(); + if (module_str == "006") { + g0overg1er_map->GetZaxis()->SetRangeUser(0,0.01); + } else { + g0overg1er_map->GetZaxis()->SetRangeUser(0,0.001); + } + sprintf(savename,"plots/M%s/%s/g0overg1er_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + no_g0g1_calib_map->GetXaxis()->SetTitle("Column"); + no_g0g1_calib_map->GetYaxis()->SetTitle("Row"); + no_g0g1_calib_map->GetYaxis()->SetTitleOffset(0.7); + no_g0g1_calib_map->Draw("colz"); + sprintf(savename,"plots/M%s/%s/no_g0g1_calib_map_M%s.png", module_str.c_str(), plotfolder_str.c_str(),module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + + if (isHGX) { + sprintf(savename,"data/M%s/BP_ratio_M%s_HG0G1G2.root", module_str.c_str(), module_str.c_str()); + } + else + { + sprintf(savename,"data/M%s/BP_ratio_M%s.root", module_str.c_str(), module_str.c_str()); + } + + + TFile* saved_file2 = new TFile((const char *)(savename),"RECREATE"); + g0overg1_map->Write(); + g0overg1er_map->Write(); + g0_grad_map->Write(); + g1_grad_map->Write(); + saved_file2->Close(); + +} diff --git a/BP_fit.cpp b/BP_fit.cpp new file mode 100644 index 0000000..e90e334 --- /dev/null +++ b/BP_fit.cpp @@ -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 +#include + +//#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" <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 <HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" < G0_pixel(220, 0); + std::vector G0_err_pixel(220, 0); + std::vector G1_pixel(220, 0); + std::vector 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 r0_adc; + vector r0_filter; + + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector 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 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 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; + +} + diff --git a/BP_fit_M431.cpp b/BP_fit_M431.cpp new file mode 100644 index 0000000..a7cc864 --- /dev/null +++ b/BP_fit_M431.cpp @@ -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 +#include +#include + +//#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" <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 <HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" < G0_pixel(220, 0); + std::vector G0_err_pixel(220, 0); + std::vector G1_pixel(220, 0); + std::vector 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 r0_adc; + vector r0_filter; + + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector 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 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 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; + +} + diff --git a/BP_fit_thin.cpp b/BP_fit_thin.cpp new file mode 100644 index 0000000..76474a6 --- /dev/null +++ b/BP_fit_thin.cpp @@ -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 +#include + +//#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" <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 <HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" < G0_pixel(245, 0); + std::vector G0_err_pixel(245, 0); + std::vector G1_pixel(245, 0); + std::vector 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 r0_adc; + vector r0_filter; + + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector 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 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 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; + +} + diff --git a/BP_scan_both_speeds.sh b/BP_scan_both_speeds.sh new file mode 100644 index 0000000..f55eeb2 --- /dev/null +++ b/BP_scan_both_speeds.sh @@ -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 diff --git a/BP_scan_thinSensor.sh b/BP_scan_thinSensor.sh new file mode 100644 index 0000000..947470f --- /dev/null +++ b/BP_scan_thinSensor.sh @@ -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" diff --git a/CS_analysis_M431.cpp b/CS_analysis_M431.cpp new file mode 100644 index 0000000..c09e4a5 --- /dev/null +++ b/CS_analysis_M431.cpp @@ -0,0 +1,2202 @@ +// file to take current source scan files, analyse and plot them. +// 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 "sls_detector_calibration/jungfrauCommonHeader.h" +#include "sls_detector_calibration/jungfrauCommonFunctions.h" + +#include "sls_detector_calibration/jungfrauFile.C" +#include "sls_detector_calibration/jungfrauPedestal.C" +#include "sls_detector_calibration/jungfrauPixelMask.C" + +#include "TGraph.h" +#include "TGraphErrors.h" +#include "TF1.h" +#include "TFile.h" +#include "TPaveStats.h" +#include "TLegend.h" +#include "TPaveText.h" + +#include +#include +#include +#include + +double checkRangeMinForRCEffect(double range_min) { + + // check that the range minimum is at least 2 us, to avoid non-linearity of RC effect + if (range_min < 2.0) { + return 2.0; + } else { + return range_min; + } + +} + + +bool isHGX=false; +int main(int argc, char* argv[]) { + + jungfrauStyle(); + gROOT->SetBatch(1); + gStyle->SetOptFit(11); + + /* + if (argc != 4) { + cout << "Correct usage:" << endl; + cout << "arg 1: specify module number" << endl; + cout << "arg 2: specify data location" << endl; + cout << "arg 3: specify data file" << endl; + cout << " " << endl; + exit(1); + } + */ //uncomment for SR + + if (argc != 5) { + cout << "Correct usage:" << endl; + cout << "arg 1: specify module number" << endl; + cout << "arg 2: specify data location folder" << endl; + cout << "arg 3: specify data file prefix" << endl; + cout << "arg 4: specify location of analysis root files" << endl; + cout << " " << endl; + exit(1); + } //uncomment for VH 210906 + + + + string plotfolder_str; + string str2 ("HG0G1G2"); + string str3 =("HGOG1G2"); //filename creator had this bug + string module_str = argv[1]; + string data_loc = argv[2]; + string data_file = argv[3]; + string anadata_loc = argv[4]; //uncomment for VH 210906 + + +if (data_file.find(str2) != string::npos) isHGX=true; +if (data_file.find(str3) != string::npos) isHGX=true; + +if (isHGX) { + cout << " HG0->HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" < scan_v1; + scan_v1.push_back("002"); + scan_v1.push_back("003"); + + vector scan_v2; + scan_v2.push_back("032"); + + vector scan_v3; + + vector scan_v4; + scan_v4.push_back("040"); + scan_v4.push_back("044"); + + vector scan_v5; + scan_v5.push_back("006"); + scan_v5.push_back("022"); + scan_v5.push_back("055"); + scan_v5.push_back("065"); + scan_v5.push_back("066"); + scan_v5.push_back("068"); + scan_v5.push_back("069"); + scan_v5.push_back("088"); + scan_v5.push_back("094"); + + vector scan_v6; + scan_v6.push_back("008"); + scan_v6.push_back("011"); + scan_v6.push_back("021"); + scan_v6.push_back("023"); + scan_v6.push_back("025"); + scan_v6.push_back("029"); + scan_v6.push_back("035"); + scan_v6.push_back("039"); + scan_v6.push_back("043"); + scan_v6.push_back("045"); + scan_v6.push_back("046"); + scan_v6.push_back("048"); + scan_v6.push_back("049"); + scan_v6.push_back("050"); + scan_v6.push_back("051"); + scan_v6.push_back("053"); + scan_v6.push_back("054"); + scan_v6.push_back("057"); + scan_v6.push_back("058"); + scan_v6.push_back("059"); + scan_v6.push_back("060"); + scan_v6.push_back("061"); + scan_v6.push_back("062"); + scan_v6.push_back("063"); + scan_v6.push_back("064"); + scan_v6.push_back("067"); + scan_v6.push_back("070"); + scan_v6.push_back("071"); + scan_v6.push_back("072"); + scan_v6.push_back("073"); + scan_v6.push_back("074"); + scan_v6.push_back("075"); + scan_v6.push_back("076"); + scan_v6.push_back("079"); + scan_v6.push_back("080"); + scan_v6.push_back("086"); + scan_v6.push_back("089"); + scan_v6.push_back("090"); + scan_v6.push_back("091"); + scan_v6.push_back("092"); + scan_v6.push_back("093"); + scan_v6.push_back("095"); + scan_v6.push_back("097"); + scan_v6.push_back("098"); + scan_v6.push_back("099"); + scan_v6.push_back("100"); + scan_v6.push_back("102"); + scan_v6.push_back("103"); + scan_v6.push_back("104"); + scan_v6.push_back("106"); + scan_v6.push_back("107"); + scan_v6.push_back("108"); + scan_v6.push_back("109"); + scan_v6.push_back("110"); + scan_v6.push_back("111"); + scan_v6.push_back("112"); + scan_v6.push_back("113"); + scan_v6.push_back("114"); + scan_v6.push_back("115"); + scan_v6.push_back("116"); + scan_v6.push_back("117"); + scan_v6.push_back("118"); + scan_v6.push_back("119"); + scan_v6.push_back("120"); + scan_v6.push_back("121"); + scan_v6.push_back("122"); + scan_v6.push_back("123"); + scan_v6.push_back("124"); + scan_v6.push_back("125"); + scan_v6.push_back("126"); + scan_v6.push_back("129"); + scan_v6.push_back("130"); + scan_v6.push_back("131"); + scan_v6.push_back("132"); + scan_v6.push_back("133"); + scan_v6.push_back("134"); + scan_v6.push_back("135"); + scan_v6.push_back("200"); + scan_v6.push_back("201"); + scan_v6.push_back("202"); + scan_v6.push_back("203"); + scan_v6.push_back("204"); + scan_v6.push_back("205"); + scan_v6.push_back("206"); + scan_v6.push_back("208"); + scan_v6.push_back("209"); + scan_v6.push_back("210"); + scan_v6.push_back("212"); + scan_v6.push_back("214"); + scan_v6.push_back("215"); + scan_v6.push_back("216"); + scan_v6.push_back("217"); + scan_v6.push_back("218"); + scan_v6.push_back("219"); + scan_v6.push_back("221"); + scan_v6.push_back("222"); + scan_v6.push_back("223"); + scan_v6.push_back("224"); + scan_v6.push_back("225"); + scan_v6.push_back("226"); + scan_v6.push_back("227"); + scan_v6.push_back("228"); + scan_v6.push_back("229"); + scan_v6.push_back("232"); + scan_v6.push_back("233"); + scan_v6.push_back("234"); + scan_v6.push_back("235"); + scan_v6.push_back("236"); + scan_v6.push_back("242"); + scan_v6.push_back("244"); + scan_v6.push_back("245"); + scan_v6.push_back("246"); + scan_v6.push_back("248"); + scan_v6.push_back("249"); + scan_v6.push_back("250"); + scan_v6.push_back("251"); + scan_v6.push_back("252"); + scan_v6.push_back("253"); + scan_v6.push_back("254"); + scan_v6.push_back("255"); + scan_v6.push_back("260"); + scan_v6.push_back("261"); + scan_v6.push_back("263"); + scan_v6.push_back("264"); + scan_v6.push_back("265"); + scan_v6.push_back("266"); + scan_v6.push_back("267"); + scan_v6.push_back("269"); + scan_v6.push_back("270"); + scan_v6.push_back("272"); + scan_v6.push_back("273"); + scan_v6.push_back("274"); + scan_v6.push_back("275"); + scan_v6.push_back("276"); + scan_v6.push_back("277"); + scan_v6.push_back("278"); + scan_v6.push_back("279"); + scan_v6.push_back("281"); + scan_v6.push_back("282"); + scan_v6.push_back("283"); + scan_v6.push_back("285"); + scan_v6.push_back("286"); + scan_v6.push_back("287"); + scan_v6.push_back("288"); + scan_v6.push_back("289"); + scan_v6.push_back("290"); + scan_v6.push_back("291"); + scan_v6.push_back("292"); + scan_v6.push_back("294"); + scan_v6.push_back("296"); + scan_v6.push_back("298"); + scan_v6.push_back("299"); + scan_v6.push_back("301"); + scan_v6.push_back("307"); + scan_v6.push_back("312"); + scan_v6.push_back("351"); + scan_v6.push_back("352"); + scan_v6.push_back("354"); + scan_v6.push_back("360"); + scan_v6.push_back("373"); + scan_v6.push_back("380"); + scan_v6.push_back("304"); + scan_v6.push_back("321"); + scan_v6.push_back("346"); + scan_v6.push_back("375"); + scan_v6.push_back("381"); + scan_v6.push_back("383"); + scan_v6.push_back("310"); + scan_v6.push_back("313"); + scan_v6.push_back("314"); + scan_v6.push_back("334"); + scan_v6.push_back("337"); + scan_v6.push_back("347"); + scan_v6.push_back("361"); + scan_v6.push_back("362"); + scan_v6.push_back("355"); + scan_v6.push_back("364"); + scan_v6.push_back("366"); + scan_v6.push_back("243"); + scan_v6.push_back("339"); + scan_v6.push_back("341"); + scan_v6.push_back("368"); + scan_v6.push_back("376"); + scan_v6.push_back("379"); + + scan_v6.push_back("359"); + scan_v6.push_back("363"); + scan_v6.push_back("365"); + scan_v6.push_back("347"); + scan_v6.push_back("366"); + + + scan_v6.push_back("268"); + scan_v6.push_back("300"); + scan_v6.push_back("302"); + scan_v6.push_back("303"); + scan_v6.push_back("309"); + scan_v6.push_back("326"); + + scan_v6.push_back("308"); + scan_v6.push_back("322"); + scan_v6.push_back("328"); + scan_v6.push_back("332"); + scan_v6.push_back("335"); + scan_v6.push_back("353"); + scan_v6.push_back("335_FW2_2"); + scan_v6.push_back("353_FW2_2"); + + scan_v6.push_back("262_FWcheck_1_1_1"); + scan_v6.push_back("262_FWcheck_1_1_1_test"); + scan_v6.push_back("262_FWcheck_1_2_rc210831"); + scan_v6.push_back("262_FWcheck_1_2_defdacs"); + + scan_v6.push_back("311"); + scan_v6.push_back("316"); + scan_v6.push_back("318"); + scan_v6.push_back("319"); + scan_v6.push_back("320"); + scan_v6.push_back("324"); + + scan_v6.push_back("272_fullspeedtest"); + scan_v6.push_back("272_halfspeedtest"); + + scan_v6.push_back("352_fullspeed"); //jf4mb2-00 (SLS) + scan_v6.push_back("307_fullspeed"); //jf4mb2-01 (SLS) + scan_v6.push_back("264_fullspeed"); //jf4mb2-02 (SLS) + scan_v6.push_back("253_fullspeed"); //jf4mb2-03 (SLS) + scan_v6.push_back("351_fullspeed"); //jf4mb2-04 (SLS) + scan_v6.push_back("312_fullspeed"); //jf4mb2-05 (SLS) + scan_v6.push_back("261_fullspeed"); //jf4mb2-06 (SLS) + scan_v6.push_back("310_fullspeed"); //jf4mb2-07 (SLS) + + scan_v6.push_back("384"); //jfcalib-5 + scan_v6.push_back("510"); //jfcalib-0 + scan_v6.push_back("511"); //jfcalib-1 + scan_v6.push_back("512"); //jfcalib-2 + scan_v6.push_back("556"); //jfcalib-3 + scan_v6.push_back("572"); //jfcalib-4 + + scan_v6.push_back("329"); //jfcalib-0 + scan_v6.push_back("331"); //jfcalib-1 + scan_v6.push_back("333"); //jfcalib-2 + scan_v6.push_back("336"); //jfcalib-3 + scan_v6.push_back("356"); //jfcalib-4 + scan_v6.push_back("377"); //jfcalib-5 + + scan_v6.push_back("387"); //jfcalib-0 + scan_v6.push_back("388"); //jfcalib-1 + scan_v6.push_back("389"); //jfcalib-2 + scan_v6.push_back("396"); //jfcalib-3 + scan_v6.push_back("397"); //jfcalib-4 + scan_v6.push_back("398"); //jfcalib-5 + + scan_v6.push_back("390"); //jfcalib-0 + scan_v6.push_back("391"); //jfcalib-1 + scan_v6.push_back("393"); //jfcalib-2 + scan_v6.push_back("399"); //jfcalib-3 + scan_v6.push_back("516"); //jfcalib-4 + scan_v6.push_back("517"); //jfcalib-5 + + scan_v6.push_back("519"); //jfcalib-0 + scan_v6.push_back("520"); //jfcalib-1 + scan_v6.push_back("532"); //jfcalib-2 + scan_v6.push_back("539"); //jfcalib-3 + scan_v6.push_back("555"); //jfcalib-4 + + //Calib for VELA beamtime in March 2022 + scan_v6.push_back("262"); //jfcalib-0 + scan_v6.push_back("231"); //jfcalib-1 + scan_v6.push_back("305"); //jfcalib-2 + + scan_v6.push_back("392"); //jfcalib-1 + scan_v6.push_back("394"); //jfcalib-2 + scan_v6.push_back("513"); //jfcalib-3 + scan_v6.push_back("514"); //jfcalib-4 + scan_v6.push_back("515"); //jfcalib-5 + + scan_v6.push_back("239"); //jfcalib-0 //bad + //scan_v6.push_back("064"); //jfcalib-1 //bad //already added above + //scan_v6.push_back("023"); //jfcalib-2 //bad //already added above + scan_v6.push_back("349"); //jfcalib-3 //bad + scan_v6.push_back("518"); //jfcalib-4 + scan_v6.push_back("521"); //jfcalib-5 + + scan_v6.push_back("523"); //jfcalib-0 + scan_v6.push_back("526"); //jfcalib-1 + scan_v6.push_back("529"); //jfcalib-2 + scan_v6.push_back("530"); //jfcalib-3 + scan_v6.push_back("531"); //jfcalib-4 + scan_v6.push_back("533"); //jfcalib-5 + + scan_v6.push_back("524"); //1M for ESRF + scan_v6.push_back("525"); //1M for ESRF + + scan_v6.push_back("306"); //jfcalib-0 (strixel) + scan_v6.push_back("350"); //jfcalib-1 (strixel) + + scan_v6.push_back("534"); //jfcalib-0 + scan_v6.push_back("537"); //jfcalib-1 + scan_v6.push_back("538"); //jfcalib-2 + scan_v6.push_back("542"); //jfcalib-3 + scan_v6.push_back("543"); //jfcalib-4 + scan_v6.push_back("544"); //jfcalib-5 + + scan_v6.push_back("402"); //jfcalib-0 + scan_v6.push_back("404"); //jfcalib-1 + scan_v6.push_back("407"); //jfcalib-2 + scan_v6.push_back("409"); //jfcalib-3 + scan_v6.push_back("410"); //jfcalib-4 + scan_v6.push_back("411"); //jfcalib-5 + + //scan_v6.push_back("008"); //jfcalib-0 //already in the list from previous calibration + scan_v6.push_back("433"); //jfcalib-1 + scan_v6.push_back("550"); //jfcalib-2 + scan_v6.push_back("545"); //jfcalib-3 + scan_v6.push_back("546"); //jfcalib-4 + scan_v6.push_back("547"); //jfcalib-5 + + //scan_v6.push_back("416"); //jfcalib-0 //destroyed, machanical sample + scan_v6.push_back("417"); //jfcalib-1 + scan_v6.push_back("418"); //jfcalib-2 + scan_v6.push_back("420"); //jfcalib-3 + scan_v6.push_back("421"); //jfcalib-4 + scan_v6.push_back("430"); //jfcalib-5 + + scan_v6.push_back("417_fullspeed"); //jfcalib-1 + scan_v6.push_back("418_fullspeed"); //jfcalib-2 + scan_v6.push_back("420_fullspeed"); //jfcalib-3 + scan_v6.push_back("421_fullspeed"); //jfcalib-4 + scan_v6.push_back("430_fullspeed"); //jfcalib-5 + + scan_v6.push_back("434"); //jfcalib-0 + scan_v6.push_back("437"); //jfcalib-1 + scan_v6.push_back("480"); //jfcalib-2 + scan_v6.push_back("464"); //jfcalib-3 + scan_v6.push_back("473"); //jfcalib-4 + scan_v6.push_back("474"); //jfcalib-5 + + scan_v6.push_back("076"); //jfcalib-0 + scan_v6.push_back("089"); //jfcalib-3 + scan_v6.push_back("207"); //jfcalib-5 + + scan_v6.push_back("244"); //jfcalib-3 + + scan_v6.push_back("474_fullspeed"); //jfcalib-0 + scan_v6.push_back("437_fullspeed"); //jfcalib-1 + scan_v6.push_back("480_fullspeed"); //jfcalib-2 + scan_v6.push_back("482_fullspeed"); //jfcalib-3 + scan_v6.push_back("487_fullspeed"); //jfcalib-5 + + scan_v6.push_back("482"); //jfcalib-3 + scan_v6.push_back("487"); //jfcalib-5 + + scan_v6.push_back("499_fullspeed"); //jfcalib-0 + scan_v6.push_back("548_fullspeed"); //jfcalib-1 + scan_v6.push_back("549_fullspeed"); //jfcalib-2 + scan_v6.push_back("427_fullspeed"); //jfcalib-3 + + scan_v6.push_back("499"); //jfcalib-0 + scan_v6.push_back("548"); //jfcalib-1 + scan_v6.push_back("549"); //jfcalib-2 + scan_v6.push_back("427"); //jfcalib-3 + scan_v6.push_back("435"); //jfcalib-5 + + scan_v6.push_back("403"); //jfcalib-0 + scan_v6.push_back("406"); //jfcalib-1 + scan_v6.push_back("423"); //jfcalib-2 + scan_v6.push_back("436"); //jfcalib-3 + scan_v6.push_back("479"); //jfcalib-5 + + // Calibration 450 um sensor for ESRF + + scan_v6.push_back("583"); //jfcalib-0 + scan_v6.push_back("593"); //jfcalib-1 + scan_v6.push_back("601"); //jfcalib-2 + scan_v6.push_back("604"); //jfcalib-3 + scan_v6.push_back("605"); //jfcalib-5 + + // Calibration 320 um sensors + + scan_v6.push_back("441"); //jfcalib-0 + scan_v6.push_back("460"); //jfcalib-1 + scan_v6.push_back("463"); //jfcalib-2 + scan_v6.push_back("476"); //jfcalib-3 + scan_v6.push_back("371"); //jfcalib-4 + + scan_v6.push_back("429"); //jfcalib-0 + scan_v6.push_back("442"); //jfcalib-1 + scan_v6.push_back("444"); //jfcalib-2 + scan_v6.push_back("446"); //jfcalib-3 + scan_v6.push_back("447"); //jfcalib-4 + + scan_v6.push_back("428"); //jfcalib-0 + scan_v6.push_back("439"); //jfcalib-1 + scan_v6.push_back("443"); //jfcalib-2 + scan_v6.push_back("445"); //jfcalib-3 + + scan_v6.push_back("448"); //jfcalib-0 + scan_v6.push_back("454"); //jfcalib-1 + scan_v6.push_back("455"); //jfcalib-2 + scan_v6.push_back("456"); //jfcalib-3 + scan_v6.push_back("466"); //jfcalib-4 + scan_v6.push_back("471"); //jfcalib-5 + + scan_v6.push_back("481"); //jfcalib-0 + scan_v6.push_back("488"); //jfcalib-1 + scan_v6.push_back("490"); //jfcalib-2 + scan_v6.push_back("491"); //jfcalib-3 + scan_v6.push_back("492"); //jfcalib-4 + scan_v6.push_back("493"); //jfcalib-5 + + scan_v6.push_back("494"); //jfcalib-0 + scan_v6.push_back("495"); //jfcalib-1 + scan_v6.push_back("497"); //jfcalib-2 + scan_v6.push_back("498"); //jfcalib-3 + scan_v6.push_back("501"); //jfcalib-4 + scan_v6.push_back("502"); //jfcalib-5 + + scan_v6.push_back("036"); //jfcalib-0 + scan_v6.push_back("560"); //jfcalib-1 + scan_v6.push_back("536"); //jfcalib-2 + scan_v6.push_back("535"); //jfcalib-3 + scan_v6.push_back("527"); //jfcalib-4 + scan_v6.push_back("522"); //jfcalib-5 + + scan_v6.push_back("037"); //jfcalib-1 + + scan_v6.push_back("571"); //jfcalib-0 + scan_v6.push_back("571_fullspeed"); //jfcalib-0 + scan_v6.push_back("573"); //jfcalib-1 + scan_v6.push_back("573_fullspeed"); //jfcalib-1 + scan_v6.push_back("574"); //jfcalib-2 + scan_v6.push_back("574_fullspeed"); //jfcalib-2 + scan_v6.push_back("575"); //jfcalib-3 + scan_v6.push_back("575_fullspeed"); //jfcalib-3 + scan_v6.push_back("576"); //jfcalib-4 + scan_v6.push_back("576_fullspeed"); //jfcalib-4 + scan_v6.push_back("577"); //jfcalib-5 + scan_v6.push_back("577_fullspeed"); //jfcalib-5 + + scan_v6.push_back("431_JF12"); + + + jungfrauFile *thisfile = new jungfrauFile(); + + jungfrauPixelMask *pixelMaskObject = new jungfrauPixelMask(); + bool pixel_mask [NCH]; + + bool saturation_mask [NCH]; + std::fill_n(saturation_mask, NCH, true); + + jungfrauPedestal *pedestalObject = new jungfrauPedestal(); + pedestalObject->pedestalSetNFrames(640); + + TH2F* pedestalsG0 = new TH2F("pedestalsG0","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* pedestalsG1 = new TH2F("pedestalsG1","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* pedestalsG2 = new TH2F("pedestalsG2","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* pedeRMSG0 = new TH2F("pedeRMSG0","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* no_g0g1_calib_map = new TH2F("no_g0g1_calib_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* no_g1g2_calib_map = new TH2F("no_g1g2_calib_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + //char savename[128]; + char savename[256]; // VH 210902 + int createHistoFile = 1; //set 0 for a fit-only run + int createPerStepHistos = 0; //debug + +#ifdef JF11 + cout << "COMPILED for JF11 !!!" << endl; +#endif + + // 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/CurrentSource + 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); + + // open first file + sprintf(savename,"%s/%s_%%6.6d.dat", data_loc.c_str(), data_file.c_str()); //VH: note, this adds a double slash in the filepath + thisfile->open((char*)savename, 0); + + // calculate pixel mask + pixelMaskObject->initialisePixelMask(pixel_mask); + + for (int i = 0; i < 640; i++) { + thisfile->readNextFrame(); + pixelMaskObject->maskIfGainNot(0, thisfile->getFrameDataHandle(), pixel_mask); + } + cout << "after G0, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl; + + for (int i = 0; i < 640; i++) { + thisfile->readNextFrame(); + pixelMaskObject->maskIfGainNot(1, thisfile->getFrameDataHandle(), pixel_mask); // change to Not(2 to fix FW error during JF11 FW develop. needed for modules 243-379 + } + cout << "after G1, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl; + + for (int i = 0; i < 640; i++) { + thisfile->readNextFrame(); + pixelMaskObject->maskIfGainNot(3, thisfile->getFrameDataHandle(), pixel_mask); + } + cout << "after G2, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl; + + thisfile->rewind(); + + sprintf(savename,"plots/M%s/%s/pixelmask_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + pixelMaskObject->plotPixelMask(pixel_mask,savename); + cout << "after chip mask, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl; + + // calculate pedestals + for (int j = 0; j < 640; j++) { + thisfile->readNextFrame(); + pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle()); + } + for (int i = 0; i < NCH; i++) { + if (pixel_mask[i] == true) { + pedestalsG0->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i)); + pedeRMSG0->Fill(i%NC,i/NC,pedestalObject->rmsOfChannel(i)); + } + } + pedestalObject->pedestalClear(); + + for (int j = 0; j < 640; j++) { + thisfile->readNextFrame(); + pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle()); + } + for (int i = 0; i < NCH; i++) { + if (pixel_mask[i] == true) { + pedestalsG1->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i)); + } + } + pedestalObject->pedestalClear(); + + for (int j = 0; j < 640; j++) { + thisfile->readNextFrame(); + pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle()); + } + for (int i = 0; i < NCH; i++) { + if (pixel_mask[i] == true) { + pedestalsG2->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i)); + } + } + pedestalObject->pedestalClear(); + + thisfile->close(); + + TCanvas *mapcanvas = new TCanvas("mapcanvas","",150,10,800,400); + mapcanvas->SetLeftMargin(0.1); + mapcanvas->SetRightMargin(0.13); + mapcanvas->SetTopMargin(0.08); + mapcanvas->SetBottomMargin(0.15); + + TCanvas *c1 = new TCanvas("c1",""); + + mapcanvas->cd(); + + pedestalsG0->GetXaxis()->SetTitle("Column"); + pedestalsG0->GetYaxis()->SetTitle("Row"); + pedestalsG0->GetYaxis()->SetTitleOffset(0.7); + pedestalsG0->Draw("colz"); + sprintf(savename,"plots/M%s/%s/pedeG0_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + pedestalsG1->GetXaxis()->SetTitle("Column"); + pedestalsG1->GetYaxis()->SetTitle("Row"); + pedestalsG1->GetYaxis()->SetTitleOffset(0.7); + pedestalsG1->Draw("colz"); + sprintf(savename,"plots/M%s/%s/pedeG1_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + pedestalsG2->GetXaxis()->SetTitle("Column"); + pedestalsG2->GetYaxis()->SetTitle("Row"); + pedestalsG2->GetYaxis()->SetTitleOffset(0.7); + pedestalsG2->Draw("colz"); + sprintf(savename,"plots/M%s/%s/pedeG2_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + pedeRMSG0->GetXaxis()->SetTitle("Column"); + pedeRMSG0->GetYaxis()->SetTitle("Row"); + pedeRMSG0->GetYaxis()->SetTitleOffset(0.7); + if (module_str == "006") { + pedeRMSG0->GetZaxis()->SetRangeUser(0,50); + } else { + pedeRMSG0->GetZaxis()->SetRangeUser(0,25); + } + pedeRMSG0->Draw("colz"); + sprintf(savename,"plots/M%s/%s/pedeRMSG0_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + TH2F *adcmap_avg_g0 [97]; + TH2F *adcmap_avg_g1 [97]; + TH2F *adcmap_avg_g2 [97]; + TH2F *adcermap_avg_g0 [97]; + TH2F *adcermap_avg_g1 [97]; + TH2F *adcermap_avg_g2 [97]; + + // creating the histograms + if (createHistoFile) { + + for(int i = 0; i < 97; i++) { + ostringstream histogramNameStreamg0; + histogramNameStreamg0 << "adcmap_avg_g0_" << i; + adcmap_avg_g0[i] = new TH2F(histogramNameStreamg0.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg1; + histogramNameStreamg1 << "adcmap_avg_g1_" << i; + adcmap_avg_g1[i] = new TH2F(histogramNameStreamg1.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg2; + histogramNameStreamg2 << "adcmap_avg_g2_" << i; + adcmap_avg_g2[i] = new TH2F(histogramNameStreamg2.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg5; + histogramNameStreamg5 << "adcermap_avg_g0_" << i; + adcermap_avg_g0[i] = new TH2F(histogramNameStreamg5.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg3; + histogramNameStreamg3 << "adcermap_avg_g1_" << i; + adcermap_avg_g1[i] = new TH2F(histogramNameStreamg3.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg4; + histogramNameStreamg4 << "adcermap_avg_g2_" << i; + adcermap_avg_g2[i] = new TH2F(histogramNameStreamg4.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + } + + TH2F *gainmap_all = new TH2F("gainmap_all","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *adcmap_all = new TH2F("adcmap_all","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *gainmap_sel = new TH2F("gainmap_sel","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *adcmap_sel = new TH2F("adcmap_sel","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH1F *gain_avg = new TH1F("gain_avg","",100,-1,4); + TH2F *gainmap_avg = new TH2F("gainmap_avg","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH1F *adc_avg_g0 = new TH1F("adc_avg_g0","",100,0,17000); + TH1F *adc_avg_g1 = new TH1F("adc_avg_g1","",100,0,17000); + TH1F *adc_avg_g2 = new TH1F("adc_avg_g2","",100,0,17000); + + static TH1I *adc_histos_g0 [NCH]; + static TH1I *adc_histos_g1 [NCH]; + static TH1I *adc_histos_g2 [NCH]; + static TH1I *gain_histos [NCH]; + + for(int i = 0; i < NCH; i++) { + ostringstream histogramNameStreamg0; + histogramNameStreamg0 << "adc_histos_g0_" << i; + adc_histos_g0[i] = new TH1I(histogramNameStreamg0.str().c_str(),"",100,0,17000); + ostringstream histogramNameStreamg1; + histogramNameStreamg1 << "adc_histos_g1_" << i; + adc_histos_g1[i] = new TH1I(histogramNameStreamg1.str().c_str(),"",100,0,17000); + ostringstream histogramNameStreamg2; + histogramNameStreamg2 << "adc_histos_g2_" << i; + adc_histos_g2[i] = new TH1I(histogramNameStreamg2.str().c_str(),"",100,0,17000); + ostringstream histogramNameStream2; + histogramNameStream2 << "gain_histos_" << i; + gain_histos[i] = new TH1I(histogramNameStream2.str().c_str(),"",4,-0.5,3.5); + } + + int j = 0; + int nfiles = 0; + if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + nfiles = 2; + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end() || find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + nfiles = 3; + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + nfiles = 4; + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + nfiles = 7; + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + nfiles = 6; + } + + // total frame number check + int expected_totalFrames = 0; + if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + expected_totalFrames = 19199; + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + expected_totalFrames = 24319; + } else if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + expected_totalFrames = 21759; + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + expected_totalFrames = 34560; + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + expected_totalFrames = 64000; + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + expected_totalFrames = 59519; + } + + int totalFrames = 0; + + for (int filei = 0; filei < nfiles; filei++) { + + sprintf(savename,"%s/%s_%%6.6d.dat", data_loc.c_str(), data_file.c_str()); //VH: note, this adds a double slash in the filepath + thisfile->open((char*)savename, filei); + + while(thisfile->readNextFrame()) { + totalFrames++; + } + + thisfile->close(); + } + + if (totalFrames == expected_totalFrames) { + cout << "got expected number of frames " << totalFrames << endl; + } else { + cout << "got unexpected number of frames " << totalFrames << endl; + cout << "code expected frames " << expected_totalFrames << endl; + cout << "exiting to make sure you notice" << endl; + //exit(1); + } + + for (int filei = 0; filei < nfiles; filei++) { + + sprintf(savename,"%s/%s_%%6.6d.dat", data_loc.c_str(), data_file.c_str()); //VH: note, this adds a double slash in the filepath + thisfile->open((char*)savename, filei); + + if (filei == 0) { + for (int k = 0; k < (640*3); k++) { + thisfile->readNextFrame(); + } + } + + while (thisfile->readNextFrame()) { + j++; + + uint16_t* imagedptr = thisfile->getFrameDataHandle(); + for (int i = 0; i < NCH; i++) { + if ((j-1) < 10 || (j > 8075 && j < 8085)) { + uint16_t adc = imagedptr[i]&0x3fff; + uint16_t gain = (imagedptr[i]&0xc000) >> 14; + adcmap_all->Fill(i%NC,i/NC,adc); + gainmap_all->Fill(i%NC,i/NC,gain); + } +#ifdef NONSERVE //in reality it is shift in the right direction 0x5b=80000000 and 0x5a=00000000 + if (((i/NC <= 255) && (((i%64)) == 63-(j-1)%64)) || + ((i/NC >= 256) &&( ((-1*(i-524287))%64) == 63-(j-1)%64))) { //scanning on "+-i") +#else + if (((i/NC <= 255) && (i%64 == (j-1)%64)) || + ((i/NC >= 256) &&((-1*(i-524287))%64 == (j-1)%64))) { // j - 1 +#endif + + uint16_t adc = imagedptr[i]&0x3fff; + uint16_t gain = (imagedptr[i]&0xc000) >> 14; + + gain_histos[i]->Fill(gain); + if (gain == 0) { + adc_histos_g0[i]->Fill(adc); + } else if ((gain == 1)||(gain == 2)) { //(gain == 2) to fix FW error during JF11 FW develop. needed for modules 243-379 + adc_histos_g1[i]->Fill(adc); + } else if (gain == 3) { + adc_histos_g2[i]->Fill(adc); + if (adc == 0) { + saturation_mask[i] = false; + } + } + + if ((j-1) < 10 || (j > 8075 && j < 8085)) { + adcmap_sel->Fill(i%NC,i/NC,adc); + gainmap_sel->Fill(i%NC,i/NC,gain); + } + + } + } + if (createPerStepHistos && ((j-1) < 10 || (j > 8075 && j < 8085))) { + mapcanvas->cd(); + adcmap_sel->GetXaxis()->SetTitle("Column"); + adcmap_sel->GetYaxis()->SetTitle("Row"); + adcmap_sel->GetYaxis()->SetTitleOffset(0.7); + adcmap_sel->Draw("colz"); + sprintf(savename,"plots/M%s/%s/adcmap_%i_sel_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j-1, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + adcmap_all->GetXaxis()->SetTitle("Column"); + adcmap_all->GetYaxis()->SetTitle("Row"); + adcmap_all->GetYaxis()->SetTitleOffset(0.7); + adcmap_all->Draw("colz"); + sprintf(savename,"plots/M%s/%s/adcmap_%i_all_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j-1, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + gainmap_sel->GetXaxis()->SetTitle("Column"); + gainmap_sel->GetYaxis()->SetTitle("Row"); + gainmap_sel->GetYaxis()->SetTitleOffset(0.7); + gainmap_sel->Draw("colz"); + sprintf(savename,"plots/M%s/%s/gainmap_%i_sel_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j-1, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + gainmap_all->GetXaxis()->SetTitle("Column"); + gainmap_all->GetYaxis()->SetTitle("Row"); + gainmap_all->GetYaxis()->SetTitleOffset(0.7); + gainmap_all->Draw("colz"); + sprintf(savename,"plots/M%s/%s/gainmap_%i_all_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j-1, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + adcmap_sel->Reset(); + adcmap_all->Reset(); + gainmap_sel->Reset(); + gainmap_all->Reset(); + } + + // catch the last frame (bad ctrl-c exit) + // new receiver doesn't have this problem + int last_frame = 0; + if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end() || + find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end() || + find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end() || + find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + last_frame = expected_totalFrames - 1920; + } + + if (j%640 == 0 || j == last_frame) { + if (j == last_frame) { + j = last_frame+1; + cout << "catching on last_frame" << endl; + } + + for (int i = 0; i < NCH; i++) { + + gainmap_avg->Fill(i%NC,i/NC,gain_histos[i]->GetMean()); + adcmap_avg_g0[j/640-1]->Fill(i%NC,i/NC,adc_histos_g0[i]->GetMean()); + adcermap_avg_g0[j/640-1]->Fill(i%NC,i/NC,adc_histos_g0[i]->GetMeanError()); + adcmap_avg_g1[j/640-1]->Fill(i%NC,i/NC,adc_histos_g1[i]->GetMean()); + adcermap_avg_g1[j/640-1]->Fill(i%NC,i/NC,adc_histos_g1[i]->GetMeanError()); + if (saturation_mask[i] == true) { + adcmap_avg_g2[j/640-1]->Fill(i%NC,i/NC,adc_histos_g2[i]->GetMean()); + adcermap_avg_g2[j/640-1]->Fill(i%NC,i/NC,adc_histos_g2[i]->GetMeanError()); + } + + if (gain_histos[i]->GetEntries() > 0) { + gain_avg->Fill(gain_histos[i]->GetMean()); + } + if (adc_histos_g0[i]->GetEntries() > 0) { + adc_avg_g0->Fill(adc_histos_g0[i]->GetMean()); + } + if (adc_histos_g1[i]->GetEntries() > 0) { + adc_avg_g1->Fill(adc_histos_g1[i]->GetMean()); + } + if (adc_histos_g2[i]->GetEntries() > 0) { + if (saturation_mask[i] == true) { + adc_avg_g2->Fill(adc_histos_g2[i]->GetMean()); + } + } + + gain_histos[i]->Reset(); + adc_histos_g0[i]->Reset(); + adc_histos_g1[i]->Reset(); + adc_histos_g2[i]->Reset(); + } + + if (createPerStepHistos == 1) { + c1->cd(); + gain_avg->GetXaxis()->SetTitle("Average gain"); + gain_avg->GetXaxis()->SetTitleOffset(1.1); + gain_avg->GetYaxis()->SetTitleOffset(1.5); + gain_avg->Draw(); + sprintf(savename,"plots/M%s/%s/perStep/gain_avg_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + c1->SaveAs((const char *)(savename)); + mapcanvas->cd(); + gainmap_avg->GetXaxis()->SetTitle("Column"); + gainmap_avg->GetYaxis()->SetTitle("Row"); + gainmap_avg->GetYaxis()->SetTitleOffset(0.7); + gainmap_avg->Draw("colz"); + sprintf(savename,"plots/M%s/%s/perStep/gainmap_avg_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + c1->cd(); + adc_avg_g0->GetXaxis()->SetTitle("Average G0 ADC"); + adc_avg_g0->GetXaxis()->SetTitleOffset(1.1); + adc_avg_g0->GetYaxis()->SetTitleOffset(1.5); + adc_avg_g0->Draw(); + sprintf(savename,"plots/M%s/%s/perStep/adc_avg_g0_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + c1->SaveAs((const char *)(savename)); + mapcanvas->cd(); + adcmap_avg_g0[j/640-1]->GetXaxis()->SetTitle("Column"); + adcmap_avg_g0[j/640-1]->GetYaxis()->SetTitle("Row"); + adcmap_avg_g0[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcmap_avg_g0[j/640-1]->Draw("colz"); + mapcanvas->Update(); + sprintf(savename,"plots/M%s/%s/perStep/adcmap_avg_g0_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + adcermap_avg_g0[j/640-1]->GetXaxis()->SetTitle("Column"); + adcermap_avg_g0[j/640-1]->GetYaxis()->SetTitle("Row"); + adcermap_avg_g0[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcermap_avg_g0[j/640-1]->Draw("colz"); + mapcanvas->Update(); + sprintf(savename,"plots/M%s/%s/perStep/adcermap_avg_g0_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + c1->cd(); + adc_avg_g1->GetXaxis()->SetTitle("Average G1 ADC"); + adc_avg_g1->GetXaxis()->SetTitleOffset(1.1); + adc_avg_g1->GetYaxis()->SetTitleOffset(1.5); + adc_avg_g1->Draw(); + sprintf(savename,"plots/M%s/%s/perStep/adc_avg_g1_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + c1->SaveAs((const char *)(savename)); + mapcanvas->cd(); + adcmap_avg_g1[j/640-1]->GetXaxis()->SetTitle("Column"); + adcmap_avg_g1[j/640-1]->GetYaxis()->SetTitle("Row"); + adcmap_avg_g1[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcmap_avg_g1[j/640-1]->Draw("colz"); + mapcanvas->Update(); + sprintf(savename,"plots/M%s/%s/perStep/adcmap_avg_g1_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + adcermap_avg_g1[j/640-1]->GetXaxis()->SetTitle("Column"); + adcermap_avg_g1[j/640-1]->GetYaxis()->SetTitle("Row"); + adcermap_avg_g1[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcermap_avg_g1[j/640-1]->Draw("colz"); + mapcanvas->Update(); + sprintf(savename,"plots/M%s/%s/perStep/adcermap_avg_g1_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + c1->cd(); + adc_avg_g2->GetXaxis()->SetTitle("Average G2 ADC"); + adc_avg_g2->GetXaxis()->SetTitleOffset(1.1); + adc_avg_g2->GetYaxis()->SetTitleOffset(1.5); + adc_avg_g2->Draw(); + sprintf(savename,"plots/M%s/%s/perStep/adc_avg_g2_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + c1->SaveAs((const char *)(savename)); + mapcanvas->cd(); + adcmap_avg_g2[j/640-1]->GetXaxis()->SetTitle("Column"); + adcmap_avg_g2[j/640-1]->GetYaxis()->SetTitle("Row"); + adcmap_avg_g2[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcmap_avg_g2[j/640-1]->Draw("colz"); + sprintf(savename,"plots/M%s/%s/perStep/adcmap_avg_g2_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + adcermap_avg_g2[j/640-1]->GetXaxis()->SetTitle("Column"); + adcermap_avg_g2[j/640-1]->GetYaxis()->SetTitle("Row"); + adcermap_avg_g2[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcermap_avg_g2[j/640-1]->Draw("colz"); + sprintf(savename,"plots/M%s/%s/perStep/adcermap_avg_g2_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + gain_avg->Reset(); + gainmap_avg->Reset(); + adc_avg_g0->Reset(); + adc_avg_g1->Reset(); + adc_avg_g2->Reset(); + std::fill_n(saturation_mask, NCH, true); + } + } // end of while + + thisfile->close(); + + } // end of files + + for (int i = 0; i < NCH; i++) { + delete gain_histos[i]; + delete adc_histos_g0[i]; + delete adc_histos_g1[i]; + delete adc_histos_g2[i]; + } + + // save histograms + //sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna/CS_histos_M%s.root", module_str.c_str(), module_str.c_str()); //uncomment for SR + sprintf(savename,"%s/CS_histos_M%s.root", anadata_loc.c_str(), module_str.c_str()); //uncomment for VH 210906 + TFile* saved_file = new TFile((const char *)(savename),"RECREATE"); + + for (int i = 0; i < 97; i++) { + adcmap_avg_g0[i]->Write(); + adcmap_avg_g1[i]->Write(); + adcmap_avg_g2[i]->Write(); + adcermap_avg_g0[i]->Write(); + adcermap_avg_g1[i]->Write(); + adcermap_avg_g2[i]->Write(); + } + saved_file->Close(); + } else { + // load histos + cout << "LOADING HISTOS" << endl; + //sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna/CS_histos_M%s.root", module_str.c_str(), module_str.c_str()); //uncomment for SR + sprintf(savename,"%s/CS_histos_M%s.root", anadata_loc.c_str(), module_str.c_str()); //uncomment for VH 210906 + TFile* saved_file = new TFile((const char *)(savename),"READ"); + + for (int i = 0; i < 97; i++) { + sprintf(savename,"adcmap_avg_g0_%d", i); + adcmap_avg_g0[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"adcmap_avg_g1_%d", i); + adcmap_avg_g1[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"adcmap_avg_g2_%d", i); + adcmap_avg_g2[i] = (TH2F*)saved_file->Get((const char *)(savename)); + + sprintf(savename,"adcermap_avg_g0_%d", i); + adcermap_avg_g0[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"adcermap_avg_g1_%d", i); + adcermap_avg_g1[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"adcermap_avg_g2_%d", i); + adcermap_avg_g2[i] = (TH2F*)saved_file->Get((const char *)(savename)); + } + } + + TH2F *g0map = new TH2F("g0map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g0ermap = new TH2F("g0ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F *g1map = new TH2F("g1map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g1ermap = new TH2F("g1ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F *g2map = new TH2F("g2map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g2ermap = new TH2F("g2ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F *g0overg1map = new TH2F("g0overg1map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g0overg1ermap = new TH2F("g0overg1ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F *g1overg2map = new TH2F("g1overg2map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g1overg2ermap = new TH2F("g1overg2ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH1F *g0hist = new TH1F("g0hist","",100,10000,50000); + TH1F *g0erhist = new TH1F("g0erhist","",100,0,200); + + TH1F *g1hist = new TH1F("g1hist","",100,-3000,0); + TH1F *g1erhist = new TH1F("g1erhist","",100,0,50); + + TH1F *g2hist = 0; + if (module_str == "032") { + g2hist = new TH1F("g2hist","",100,-1000,-200); + } else { + g2hist = new TH1F("g2hist","",100,-300,0); + } + TH1F *g2erhist = new TH1F("g2erhist","",100,0,10); + + TH1F *g0overg1hist = new TH1F("g0overg1hist","",100,-50,0); + TH1F *g0overg1erhist = new TH1F("g0overg1erhist","",100,0,1); + + TH1F *g1overg2hist = new TH1F("g1overg2hist","",100,11,15); + TH1F *g1overg2erhist = new TH1F("g1overg2erhist","",100,0,1); + + TH1F *g0overg1_isEdge = new TH1F("g0overg1_isEdge","",100,-50,0); + TH1F *g0overg1_isInnerEdge = new TH1F("g0overg1_isInnerEdge","",100,-50,0); + TH1F *g0overg1_isDouble = new TH1F("g0overg1_isDouble","",100,-50,0); + TH1F *g0overg1_isNextToDouble = new TH1F("g0overg1_isNextToDouble","",100,-50,0); + TH1F *g0overg1_isQuad = new TH1F("g0overg1_isQuad","",100,-50,0); + TH1F *g0overg1_isBulk = new TH1F("g0overg1_isBulk","",100,-50,0); + + TH1F *g1overg2_isEdge = new TH1F("g1overg2_isEdge","",100,11,15); + TH1F *g1overg2_isInnerEdge = new TH1F("g1overg2_isInnerEdge","",100,11,15); + TH1F *g1overg2_isDouble = new TH1F("g1overg2_isDouble","",100,11,15); + TH1F *g1overg2_isNextToDouble = new TH1F("g1overg2_isNextToDouble","",100,11,15); + TH1F *g1overg2_isQuad = new TH1F("g1overg2_isQuad","",100,11,15); + TH1F *g1overg2_isBulk = new TH1F("g1overg2_isBulk","",100,11,15); + + double filter[97]; + if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + for (int i = 0; i < 5; i++) { + filter[i] = 0.05+(i*0.05); + } + for (int i = 0; i < 9; i++) { + filter[i+5] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+5+9] = 5.+(i*2.5); + } + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.05); + } + for (int i = 0; i < 17; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+9+17] = 5.+(i*2.5); + } + for (int i = 0; i < 8; i++) { + filter[i+9+17+17] = 50.+(i*10.); + } + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + // loop 1 + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.05); + } + // loop 2a + for (int i = 0; i < 11; i++) { + filter[i+9] = 0.5+(i*0.05); + } + // loop 2b + for (int i = 0; i < 10; i++) { + filter[i+9+11] = 1.10+(i*0.10); + } + // loop 2c + for (int i = 0; i < 10; i++) { + filter[i+9+11+10] = 2.25+(i*0.25); + } + // loop 3a + for (int i = 0; i < 11; i++) { + filter[i+9+11+10+10] = 5.+(i*0.5); + } + // loop 3b + for (int i = 0; i < 10; i++) { + filter[i+9+11+10+10+11] = 11.+(i*1.0); + } + // loop 3c + for (int i = 0; i < 10; i++) { + filter[i+9+11+10+10+11+10] = 22.5+(i*2.5); + } + // loop 4a + for (int i = 0; i < 11; i++) { + filter[i+9+11+10+10+11+10+10] = 50.+(i*5.); + } + // loop 4b + for (int i = 0; i < 15; i++) { + filter[i+9+11+10+10+11+10+10+11] = 110.+(i*10.); + } + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + for (int i = 0; i < 10; i++) { + filter[i] = 0.2+(i*0.2); + } + for (int i = 0; i < 8; i++) { + filter[i+10] = 3+(i*1); + } + for (int i = 0; i < 25; i++) { + filter[i+10+8] = 12+(i*2); + } + for (int i = 0; i < 47; i++) { + filter[i+10+8+25] = 80+(i*20); + } + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.025); + } + for (int i = 0; i < 9; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+9+9] = 5.+(i*2.5); + } + } else if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.025); + } + for (int i = 0; i < 9; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 9; i++) { + filter[i+9+9] = 5.+(i*2.5); + } + } + + mapcanvas->cd(); + mapcanvas->SetLeftMargin(0.13); + mapcanvas->SetRightMargin(0.05); + + for (int i = 0; i < NCH; i++) { + //if(i/NC < 256 || (i%NC > 256 && i%NC < 512)) + //continue; + + vector r0_adc; + vector r0_filter; + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector r1_ferr; + + vector r2_adc; + vector r2_filter; + vector r2_adcerr; + vector r2_ferr; + + // filter out points at zero and points with 0 error (mean taken from one entry in hist) + int m_max = 0; + if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + m_max = 27; + } else if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + m_max = 31; + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + m_max = 35; + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + m_max = 51; + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + m_max = 97; + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + m_max = 90; + } + + for (int m = 0; m < m_max; m++) { + + double this_g0avg = adcmap_avg_g0[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g1avg = adcmap_avg_g1[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g2avg = adcmap_avg_g2[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g0avger = adcermap_avg_g0[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g1avger = adcermap_avg_g1[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g2avger = adcermap_avg_g2[m]->GetBinContent((i%NC)+1,(i/NC)+1); + + if (this_g0avg != 0) { + r0_filter.push_back(filter[m]); + r0_ferr.push_back(0.); + r0_adc.push_back(this_g0avg); + r0_adcerr.push_back(this_g0avger); + } + if (this_g1avg != 0) { + r1_filter.push_back(filter[m]); + r1_ferr.push_back(0.); + r1_adc.push_back(this_g1avg); + r1_adcerr.push_back(this_g1avger); + } + if (this_g2avg != 0) { + r2_filter.push_back(filter[m]); + r2_ferr.push_back(0.); + r2_adc.push_back(this_g2avg); + r2_adcerr.push_back(this_g2avger); + } + } + + TGraphErrors *grap_g0 = 0; + TGraphErrors *grap_g1 = 0; + TGraphErrors *grap_g2 = 0; + + TF1 *fit_g0 = 0; + TF1 *fit_g1 = 0; + TF1 *fit_g2 = 0; + + double rangemin_g0 = 0; + double rangemax_g0 = 0; + double rangemin_g1 = 0; + double rangemax_g1 = 0; + double rangemin_g2 = 0; + double rangemax_g2 = 0; + + // 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); + } + + if (r2_adc.size() > 1) { + grap_g2 = new TGraphErrors(r2_adc.size(),&(r2_filter[0]),&(r2_adc[0]),&(r2_ferr[0]),&(r2_adcerr[0])); + grap_g2->SetMarkerStyle(20); + grap_g2->SetMarkerColor(kRed); + grap_g2->SetLineColor(kRed); + } + + // plot the datapoints + if (r1_adc.size() > 1) { + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + grap_g1->GetXaxis()->SetLimits(0.009,5E2); + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + grap_g1->GetXaxis()->SetLimits(0.09,1.1E3); + } else { + grap_g1->GetXaxis()->SetLimits(0.009,1.1E2); + } + grap_g1->SetMinimum(0); + grap_g1->SetMaximum(16000); + grap_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g1->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g1->GetYaxis()->SetTitleOffset(0.9); + grap_g1->Draw("AP"); + if (r2_adc.size() > 1) { + grap_g2->Draw("P"); + } + if (r0_adc.size() > 1) { + grap_g0->Draw("P"); + } + mapcanvas->SetLogx(); + 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)); + mapcanvas->SetLogx(0); + + } + } + + + // define fit ranges and fit + if (r0_adc.size() > 1) { + + + + rangemin_g0 = *min_element(r0_filter.begin(),r0_filter.end()); + rangemin_g0 = checkRangeMinForRCEffect(rangemin_g0); + + rangemax_g0 = highestPointBeforeSwitching(r0_filter, r1_filter); + + if (rangemax_g0 > rangemin_g0) { + + fit_g0 = new TF1("fit_g0","[0]+[1]*x",rangemin_g0, rangemax_g0); + fit_g0->SetParameter(0, 3000.); + fit_g0->SetParameter(1, 30000.); + fit_g0->SetLineColor(kBlue); + fit_g0->SetParName(0,"G0 const"); + fit_g0->SetParName(1,"G0 grad"); + grap_g0->Fit(fit_g0,"QR+",""); + + + + g0hist->Fill(fit_g0->GetParameter(1)); + g0map->Fill(i%NC,i/NC,fit_g0->GetParameter(1)); + g0erhist->Fill(fit_g0->GetParError(1)); + g0ermap->Fill(i%NC,i/NC,fit_g0->GetParError(1)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + grap_g0->SetMinimum(0); + grap_g0->SetMaximum(16000); + grap_g0->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g0->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g0->GetYaxis()->SetTitleOffset(0.9); + grap_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end())); + grap_g0->Draw("AP"); + fit_g0->Draw("same"); + mapcanvas->Update(); + if (grap_g0->FindObject("stats")) {TPaveStats *st0 = (TPaveStats*)grap_g0->FindObject("stats"); + cout<<"here8"<SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.71); + st0->SetY2NDC(0.90); + st0->SetBorderSize(0); + st0->SetTextColor(kBlue); + } + + mapcanvas->SetLogx(); + 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)); + mapcanvas->SetLogx(0); + + vector 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])); + } + cout<<"here85"<SetMarkerColor(kBlue); + norm_g0->SetLineColor(kBlue); + + TF1* flat_g0 = new TF1("flat_g0","0",rangemin_g0, rangemax_g0); + flat_g0->SetLineColor(kBlue); + + norm_g0->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g0->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g0->GetYaxis()->SetTitleOffset(0.9); + norm_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end())); + norm_g0->SetMinimum(-100); + norm_g0->SetMaximum(100); + norm_g0->Draw("AP"); + flat_g0->Draw("same"); + 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; + delete flat_g0; + } + } + } + + if (r1_adc.size() > 1) { + + rangemin_g1 = lowestPointAfterSwitching(r1_filter, r0_filter); + rangemin_g1 = checkRangeMinForRCEffect(rangemin_g1); + + rangemax_g1 = highestPointBeforeSwitching(r1_filter, r2_filter); + + if (rangemax_g1 > rangemin_g1) { + + fit_g1 = new TF1("fit_g1","[0]+[1]*x",rangemin_g1,rangemax_g1); + fit_g1->SetParameter(0, 10000.); + fit_g1->SetParameter(1, -0.1); + fit_g1->SetLineColor(kGreen+2); + fit_g1->SetParName(0,"G1 const"); + fit_g1->SetParName(1,"G1 grad"); + grap_g1->Fit(fit_g1,"QR",""); + + + + g1hist->Fill(fit_g1->GetParameter(1)); + g1map->Fill(i%NC,i/NC,fit_g1->GetParameter(1)); + g1erhist->Fill(fit_g1->GetParError(1)); + g1ermap->Fill(i%NC,i/NC,fit_g1->GetParError(1)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + grap_g1->SetMinimum(0); + grap_g1->SetMaximum(16000); + grap_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g1->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g1->GetYaxis()->SetTitleOffset(0.9); + grap_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end())); + grap_g1->Draw("AP"); + fit_g1->Draw("same"); + mapcanvas->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g1->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.17); + st0->SetY2NDC(0.36); + st0->SetBorderSize(0); + st0->SetTextColor(kGreen+2); + mapcanvas->SetLogx(); + 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)); + mapcanvas->SetLogx(0); + + vector 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])); + } + + 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_g1","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_p05pc = new TF1("lin_g1_p05pc","[0]+[1]*x",rangemin_g1,rangemax_g1); + lin_g1_p05pc->SetParameter(0,fit_g1->GetParameter(0)/200.); + lin_g1_p05pc->SetParameter(1,fit_g1->GetParameter(1)/200.); + lin_g1_p05pc->SetLineColor(kOrange+1); + + 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_m05pc = new TF1("lin_g1_m05pc","[0]+[1]*x",rangemin_g1,rangemax_g1); + lin_g1_m05pc->SetParameter(0,fit_g1->GetParameter(0)/-200.); + lin_g1_m05pc->SetParameter(1,fit_g1->GetParameter(1)/-200.); + lin_g1_m05pc->SetLineColor(kOrange+1); + + norm_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g1->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g1->GetYaxis()->SetTitleOffset(0.9); + norm_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end())); + norm_g1->SetMinimum(1.5*lin_g1_m05pc->Eval(rangemin_g1)); + norm_g1->SetMaximum(1.5*lin_g1_p05pc->Eval(rangemin_g1)); + norm_g1->Draw("AP"); + flat_g1->Draw("same"); + lin_g1_p02pc->Draw("same"); + lin_g1_p05pc->Draw("same"); + lin_g1_m02pc->Draw("same"); + lin_g1_m05pc->Draw("same"); + norm_g1->Draw("P"); + 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; + delete flat_g1; + } + } + } + + if (r2_adc.size() > 1) { + + rangemin_g2 = lowestPointAfterSwitching(r2_filter, r1_filter); + rangemin_g2 = checkRangeMinForRCEffect(rangemin_g2); + + rangemax_g2 = *max_element(r2_filter.begin(),r2_filter.end()); + + if (rangemax_g2 > rangemin_g2) { + + fit_g2 = new TF1("fit_g2","[0]+[1]*x",rangemin_g2, rangemax_g2); + fit_g2->SetParameter(0, 10000.); + fit_g2->SetParameter(1, -0.01); + fit_g2->SetLineColor(kRed); + fit_g2->SetParName(0,"G2 const"); + fit_g2->SetParName(1,"G2 grad"); + grap_g2->Fit(fit_g2,"QR+",""); + + g2hist->Fill(fit_g2->GetParameter(1)); + g2map->Fill(i%NC,i/NC,fit_g2->GetParameter(1)); + g2erhist->Fill(fit_g2->GetParError(1)); + g2ermap->Fill(i%NC,i/NC,fit_g2->GetParError(1)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + grap_g2->SetMinimum(0); + grap_g2->SetMaximum(16000); + grap_g2->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g2->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g2->GetYaxis()->SetTitleOffset(0.9); + grap_g2->GetXaxis()->SetLimits(*min_element(r2_filter.begin(),r2_filter.end()),*max_element(r2_filter.begin(),r2_filter.end())); + grap_g2->Draw("AP"); + fit_g2->Draw("same"); + mapcanvas->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g2->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.17); + st0->SetY2NDC(0.36); + st0->SetBorderSize(0); + st0->SetTextColor(kRed); + mapcanvas->SetLogx(); + sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g2_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)); + mapcanvas->SetLogx(0); + + vector r2_adc_norm; + for (size_t j = 0; j < r2_adc.size(); j++) { + r2_adc_norm.push_back(r2_adc[j] - fit_g2->Eval(r2_filter[j])); + } + + TGraphErrors *norm_g2 = new TGraphErrors(r2_adc.size(),&(r2_filter[0]),&(r2_adc_norm[0]),&(r2_ferr[0]),&(r2_adcerr[0])); + norm_g2->SetMarkerColor(kRed); + norm_g2->SetLineColor(kRed); + + TF1* flat_g2 = new TF1("flat_g2","0",rangemin_g2, rangemax_g2); + flat_g2->SetLineColor(kRed); + + TF1* lin_g2_p02pc = new TF1("lin_g2_p02pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_p02pc->SetParameter(0,fit_g2->GetParameter(0)/500.); + lin_g2_p02pc->SetParameter(1,fit_g2->GetParameter(1)/500.); + lin_g2_p02pc->SetLineColor(kOrange); + + TF1* lin_g2_p05pc = new TF1("lin_g2_p05pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_p05pc->SetParameter(0,fit_g2->GetParameter(0)/200.); + lin_g2_p05pc->SetParameter(1,fit_g2->GetParameter(1)/200.); + lin_g2_p05pc->SetLineColor(kOrange+1); + + TF1* lin_g2_m02pc = new TF1("lin_g2_m02pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_m02pc->SetParameter(0,fit_g2->GetParameter(0)/-500.); + lin_g2_m02pc->SetParameter(1,fit_g2->GetParameter(1)/-500.); + lin_g2_m02pc->SetLineColor(kOrange); + + TF1* lin_g2_m05pc = new TF1("lin_g2_m05pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_m05pc->SetParameter(0,fit_g2->GetParameter(0)/-200.); + lin_g2_m05pc->SetParameter(1,fit_g2->GetParameter(1)/-200.); + lin_g2_m05pc->SetLineColor(kOrange+1); + + norm_g2->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g2->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g2->GetYaxis()->SetTitleOffset(0.9); + norm_g2->GetXaxis()->SetLimits(*min_element(r2_filter.begin(),r2_filter.end()),*max_element(r2_filter.begin(),r2_filter.end())); + norm_g2->SetMinimum(1.5*lin_g2_m05pc->Eval(rangemin_g2)); + norm_g2->SetMaximum(1.5*lin_g2_p05pc->Eval(rangemin_g2)); + norm_g2->Draw("AP"); + flat_g2->Draw("same"); + lin_g2_p02pc->Draw("same"); + lin_g2_p05pc->Draw("same"); + lin_g2_m02pc->Draw("same"); + lin_g2_m05pc->Draw("same"); + norm_g2->Draw("P"); + sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g2norm_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_g2; + delete flat_g2; + } + } + } + + + + // get ratio measurements + if (rangemax_g0 > rangemin_g0 && rangemax_g1 > rangemin_g1) { + + double this_g0overg1 = fit_g0->GetParameter(1)/fit_g1->GetParameter(1); + double this_g0overg1er = abs(fit_g0->GetParameter(1)/fit_g1->GetParameter(1))*sqrt(pow((fit_g0->GetParError(1)/fit_g0->GetParameter(1)),2) + pow((fit_g1->GetParError(1)/fit_g1->GetParameter(1)),2)); + + g0overg1map->Fill(i%NC,i/NC,this_g0overg1); + g0overg1hist->Fill(this_g0overg1); + g0overg1ermap->Fill(i%NC,i/NC,this_g0overg1er); + g0overg1erhist->Fill(this_g0overg1er); + + if (isEdge(i)) { + g0overg1_isEdge->Fill(this_g0overg1); + } + if (isInnerEdge(i)) { + g0overg1_isInnerEdge->Fill(this_g0overg1); + } + if (isDouble(i)) { + g0overg1_isDouble->Fill(this_g0overg1); + } + if (isNextToDouble(i)) { + g0overg1_isNextToDouble->Fill(this_g0overg1); + } + if (isQuad(i)) { + g0overg1_isQuad->Fill(this_g0overg1); + } + if (isBulk(i)) { + g0overg1_isBulk->Fill(this_g0overg1); + } + } else { + no_g0g1_calib_map->Fill(i%NC,i/NC,1); + } + + if (rangemax_g1 > rangemin_g1 && rangemax_g2 > rangemin_g2) { + + double this_g1overg2 = fit_g1->GetParameter(1)/fit_g2->GetParameter(1); + double this_g1overg2er = abs(fit_g1->GetParameter(1)/fit_g2->GetParameter(1))*sqrt(pow((fit_g1->GetParError(1)/fit_g1->GetParameter(1)),2) + pow((fit_g2->GetParError(1)/fit_g2->GetParameter(1)),2)); + + g1overg2map->Fill(i%NC,i/NC,this_g1overg2); + g1overg2hist->Fill(this_g1overg2); + g1overg2ermap->Fill(i%NC,i/NC,this_g1overg2er); + g1overg2erhist->Fill(this_g1overg2er); + + if (isEdge(i)) { + g1overg2_isEdge->Fill(this_g1overg2); + } + if (isInnerEdge(i)) { + g1overg2_isInnerEdge->Fill(this_g1overg2); + } + if (isDouble(i)) { + g1overg2_isDouble->Fill(this_g1overg2); + } + if (isNextToDouble(i)) { + g1overg2_isNextToDouble->Fill(this_g1overg2); + } + if (isQuad(i)) { + g1overg2_isQuad->Fill(this_g1overg2); + } + if (isBulk(i)) { + g1overg2_isBulk->Fill(this_g1overg2); + } + } else { + no_g1g2_calib_map->Fill(i%NC,i/NC,1); + } + + delete fit_g0; + delete fit_g1; + delete fit_g2; + delete grap_g0; + delete grap_g1; + delete grap_g2; + } + + mapcanvas->SetLeftMargin(0.1); + mapcanvas->SetRightMargin(0.13); + + c1->cd(); + + TPaveText *pave = new TPaveText(0.86,0.95,0.91,0.98,"blNDC"); + pave->SetBorderSize(0); + pave->SetFillStyle(0); + pave->SetTextSize(0.06); + pave->SetTextAlign(32); + + if (g0hist->GetEntries() > 0) { + g0hist->GetXaxis()->SetTitle("G0 gradient"); + g0hist->GetXaxis()->SetTitleOffset(1.1); + g0hist->GetYaxis()->SetTitleOffset(1.5); + g0hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0erhist->GetXaxis()->SetTitle("Fitted G0 uncert"); + g0erhist->GetXaxis()->SetTitleOffset(1.1); + g0erhist->GetYaxis()->SetTitleOffset(1.5); + g0erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g0erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + if (g1hist->GetEntries() > 0) { + g1hist->GetXaxis()->SetTitle("G1 gradient"); + g1hist->GetXaxis()->SetTitleOffset(1.1); + g1hist->GetYaxis()->SetTitleOffset(1.5); + g1hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1erhist->GetXaxis()->SetTitle("Fitted G1 uncert"); + g1erhist->GetXaxis()->SetTitleOffset(1.1); + g1erhist->GetYaxis()->SetTitleOffset(1.5); + g1erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g1erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + if (g2hist->GetEntries() > 0) { + g2hist->GetXaxis()->SetTitle("G2 gradient"); + g2hist->GetXaxis()->SetTitleOffset(1.1); + g2hist->GetYaxis()->SetTitleOffset(1.5); + g2hist->Draw(); + sprintf(savename,"plots/M%s/%s/g2hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g2erhist->GetXaxis()->SetTitle("Fitted G2 uncert"); + g2erhist->GetXaxis()->SetTitleOffset(1.1); + g2erhist->GetYaxis()->SetTitleOffset(1.5); + g2erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g2erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + if (g0overg1hist->GetEntries() > 0) { + g0overg1hist->GetXaxis()->SetTitle("G0 / G1"); + g0overg1hist->GetXaxis()->SetTitleOffset(1.1); + g0overg1hist->GetYaxis()->SetTitleOffset(1.5); + g0overg1hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + TPaveText *pave2 = new TPaveText(0.6,0.8,0.94,0.94,"blNDC"); + pave2->SetBorderSize(0); + pave2->SetFillStyle(0); + pave2->SetTextSize(0.04); + pave2->SetTextAlign(32); + g0overg1hist->Fit("gaus"); + g0overg1hist->Draw(); + c1->Update(); + TF1* g0overg1hist_gaus = g0overg1hist->GetFunction("gaus"); + if (g0overg1hist_gaus) { + sprintf(savename,"Mean %0.4f #pm %0.4f", g0overg1hist_gaus->GetParameter(1), g0overg1hist_gaus->GetParError(1)); + pave2->AddText((const char *)(savename)); + sprintf(savename,"Sigma %0.4f #pm %0.4f", g0overg1hist_gaus->GetParameter(2), g0overg1hist_gaus->GetParError(2)); + pave2->AddText((const char *)(savename)); + pave2->Draw(); + g0overg1hist->SetStats(kFALSE); + sprintf(savename,"plots/M%s/%s/g0overg1hist_fit_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + g0overg1erhist->GetXaxis()->SetTitle("G0 / G1 uncert"); + g0overg1erhist->GetXaxis()->SetTitleOffset(1.1); + g0overg1erhist->GetYaxis()->SetTitleOffset(1.5); + g0overg1erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0overg1_isEdge->SetLineColor(kBlue); + g0overg1_isInnerEdge->SetLineColor(kCyan); + g0overg1_isDouble->SetLineColor(kGreen+2); + g0overg1_isNextToDouble->SetLineColor(kRed); + g0overg1_isQuad->SetLineColor(kOrange); + + g0overg1_isEdge->Scale(1./g0overg1_isEdge->GetEntries()); + g0overg1_isInnerEdge->Scale(1./g0overg1_isInnerEdge->GetEntries()); + g0overg1_isDouble->Scale(1./g0overg1_isDouble->GetEntries()); + g0overg1_isNextToDouble->Scale(1./g0overg1_isNextToDouble->GetEntries()); + g0overg1_isQuad->Scale(1./g0overg1_isQuad->GetEntries()); + g0overg1_isBulk->Scale(1./g0overg1_isBulk->GetEntries()); + + TLegend *leg1 = new TLegend(0.62,0.6,0.93,0.93); + leg1->AddEntry(g0overg1_isBulk, "Normal", "l"); + leg1->AddEntry(g0overg1_isDouble, "Double", "l"); + leg1->AddEntry(g0overg1_isNextToDouble, "Next to D", "l"); + leg1->AddEntry(g0overg1_isEdge, "Edge", "l"); + leg1->AddEntry(g0overg1_isInnerEdge, "Inner E", "l"); + + g0overg1_isDouble->GetXaxis()->SetTitle("G0 / G1"); + g0overg1_isDouble->GetYaxis()->SetTitle("Normalised"); + g0overg1_isDouble->GetYaxis()->SetTitleOffset(1.3); + g0overg1_isDouble->SetMinimum(0.0); + g0overg1_isDouble->SetMaximum(0.16); + g0overg1_isDouble->Draw(); + g0overg1_isEdge->Draw("same"); + g0overg1_isInnerEdge->Draw("same"); + g0overg1_isNextToDouble->Draw("same"); + g0overg1_isBulk->Draw("same"); + leg1->Draw("same"); + sprintf(savename,"plots/M%s/%s/g0overg1_perType_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + if (g1overg2hist->GetEntries() > 0) { + g1overg2hist->GetXaxis()->SetTitle("G1 / G2"); + g1overg2hist->GetXaxis()->SetTitleOffset(1.1); + g1overg2hist->GetYaxis()->SetTitleOffset(1.5); + g1overg2hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1overg2hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + TPaveText *pave2 = new TPaveText(0.6,0.8,0.94,0.94,"blNDC"); + pave2->SetBorderSize(0); + pave2->SetFillStyle(0); + pave2->SetTextSize(0.04); + pave2->SetTextAlign(32); + g1overg2hist->Fit("gaus"); + g1overg2hist->Draw(); + c1->Update(); + TF1* g1overg2hist_gaus = g1overg2hist->GetFunction("gaus"); + if (g1overg2hist_gaus) { + sprintf(savename,"Mean %0.4f #pm %0.4f", g1overg2hist_gaus->GetParameter(1), g1overg2hist_gaus->GetParError(1)); + pave2->AddText((const char *)(savename)); + sprintf(savename,"Sigma %0.4f #pm %0.4f", g1overg2hist_gaus->GetParameter(2), g1overg2hist_gaus->GetParError(2)); + pave2->AddText((const char *)(savename)); + pave2->Draw(); + g1overg2hist->SetStats(kFALSE); + sprintf(savename,"plots/M%s/%s/g1overg2hist_fit_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + g1overg2erhist->GetXaxis()->SetTitle("G1 / G2 uncert"); + g1overg2erhist->GetXaxis()->SetTitleOffset(1.1); + g1overg2erhist->GetYaxis()->SetTitleOffset(1.5); + g1overg2erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g1overg2erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1overg2_isEdge->SetLineColor(kBlue); + g1overg2_isInnerEdge->SetLineColor(kCyan); + g1overg2_isDouble->SetLineColor(kGreen+2); + g1overg2_isNextToDouble->SetLineColor(kRed); + g1overg2_isQuad->SetLineColor(kOrange); + + g1overg2_isEdge->Scale(1./g1overg2_isEdge->GetEntries()); + g1overg2_isInnerEdge->Scale(1./g1overg2_isInnerEdge->GetEntries()); + g1overg2_isDouble->Scale(1./g1overg2_isDouble->GetEntries()); + g1overg2_isNextToDouble->Scale(1./g1overg2_isNextToDouble->GetEntries()); + g1overg2_isQuad->Scale(1./g1overg2_isQuad->GetEntries()); + g1overg2_isBulk->Scale(1./g1overg2_isBulk->GetEntries()); + + TLegend *leg = new TLegend(0.62,0.6,0.93,0.93); + leg->AddEntry(g1overg2_isBulk, "Normal", "l"); + leg->AddEntry(g1overg2_isDouble, "Double", "l"); + leg->AddEntry(g1overg2_isNextToDouble, "Next to D", "l"); + leg->AddEntry(g1overg2_isEdge, "Edge", "l"); + leg->AddEntry(g1overg2_isInnerEdge, "Inner E", "l"); + + g1overg2_isDouble->GetXaxis()->SetTitle("G1 / G2"); + g1overg2_isDouble->GetYaxis()->SetTitle("Normalised"); + g1overg2_isDouble->GetYaxis()->SetTitleOffset(1.3); + g1overg2_isDouble->SetMinimum(0.0); + g1overg2_isDouble->SetMaximum(0.16); + g1overg2_isDouble->Draw(); + g1overg2_isEdge->Draw("same"); + g1overg2_isInnerEdge->Draw("same"); + g1overg2_isNextToDouble->Draw("same"); + g1overg2_isBulk->Draw("same"); + leg->Draw("same"); + sprintf(savename,"plots/M%s/%s/g1overg2_perType_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + mapcanvas->cd(); + + if (g0map->GetEntries() > 0) { + g0map->GetXaxis()->SetTitle("Column"); + g0map->GetYaxis()->SetTitle("Row"); + g0map->GetYaxis()->SetTitleOffset(0.7); + g0map->GetZaxis()->SetRangeUser(20000,40000); + g0map->Draw("colz"); + pave->AddText("G0 [ADU/#mus]"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g0map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0ermap->GetXaxis()->SetTitle("Column"); + g0ermap->GetYaxis()->SetTitle("Row"); + g0ermap->GetYaxis()->SetTitleOffset(0.7); + g0ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G0}"); + pave->Draw(); + g0ermap->GetZaxis()->SetRangeUser(0,200); + sprintf(savename,"plots/M%s/%s/g0ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + if (g1map->GetEntries() > 0) { + g1map->GetXaxis()->SetTitle("Column"); + g1map->GetYaxis()->SetTitle("Row"); + g1map->GetYaxis()->SetTitleOffset(0.7); + if (module_str == "002") { + g1map->GetZaxis()->SetRangeUser(-400,-100); + } else { + g1map->GetZaxis()->SetRangeUser(-3000,0); + } + g1map->Draw("colz"); + pave->Clear(); + pave->AddText("G1 [ADU/#mus]"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g1map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1ermap->GetXaxis()->SetTitle("Column"); + g1ermap->GetYaxis()->SetTitle("Row"); + g1ermap->GetYaxis()->SetTitleOffset(0.7); + g1ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G1}"); + pave->Draw(); + g1ermap->GetZaxis()->SetRangeUser(0,50); + sprintf(savename,"plots/M%s/%s/g1ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + if (g1map->GetEntries() > 0) { + g2map->GetXaxis()->SetTitle("Column"); + g2map->GetYaxis()->SetTitle("Row"); + g2map->GetYaxis()->SetTitleOffset(0.7); + if (module_str == "032") { + g2map->GetZaxis()->SetRangeUser(-800,-400); + } else if (module_str == "002") { + g2map->GetZaxis()->SetRangeUser(-35,-10); + } else { + g2map->GetZaxis()->SetRangeUser(-200,-50); + } + g2map->Draw("colz"); + pave->Clear(); + pave->AddText("G2 [ADU/#mus]"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g2map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g2ermap->GetXaxis()->SetTitle("Column"); + g2ermap->GetYaxis()->SetTitle("Row"); + g2ermap->GetYaxis()->SetTitleOffset(0.7); + g2ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G2}"); + pave->Draw(); + g2ermap->GetZaxis()->SetRangeUser(0,5); + sprintf(savename,"plots/M%s/%s/g2ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + if (g0overg1map->GetEntries()) { + g0overg1map->GetXaxis()->SetTitle("Column"); + g0overg1map->GetYaxis()->SetTitle("Row"); + g0overg1map->GetYaxis()->SetTitleOffset(0.7); + if (module_str == "003") { + g0overg1map->GetZaxis()->SetRangeUser(-35,-30); + } else { + g0overg1map->GetZaxis()->SetRangeUser(-50,0); + } + g0overg1map->Draw("colz"); + pave->Clear(); + pave->AddText("G0/G1"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0overg1ermap->GetXaxis()->SetTitle("Column"); + g0overg1ermap->GetYaxis()->SetTitle("Row"); + g0overg1ermap->GetYaxis()->SetTitleOffset(0.7); + g0overg1ermap->GetZaxis()->SetRangeUser(0,0.5); + g0overg1ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G0/G1}"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + if (g1overg2map->GetEntries()) { + g1overg2map->GetXaxis()->SetTitle("Column"); + g1overg2map->GetYaxis()->SetTitle("Row"); + g1overg2map->GetYaxis()->SetTitleOffset(0.7); + +#ifdef JF11 + //g1overg2map->GetZaxis()->SetRangeUser(11,12.5); +#else + g1overg2map->GetZaxis()->SetRangeUser(12,13.2); +#endif + + g1overg2map->Draw("colz"); + pave->Clear(); + pave->AddText("G1/G2"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g1overg2map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1overg2ermap->GetXaxis()->SetTitle("Column"); + g1overg2ermap->GetYaxis()->SetTitle("Row"); + g1overg2ermap->GetYaxis()->SetTitleOffset(0.7); + g1overg2ermap->GetZaxis()->SetRangeUser(0,0.5); + g1overg2ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G1/G2}"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g1overg2ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + no_g0g1_calib_map->GetXaxis()->SetTitle("Column"); + no_g0g1_calib_map->GetYaxis()->SetTitle("Row"); + no_g0g1_calib_map->GetYaxis()->SetTitleOffset(0.7); + no_g0g1_calib_map->Draw("colz"); + sprintf(savename,"plots/M%s/%s/no_g0g1_calib_map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + no_g1g2_calib_map->GetXaxis()->SetTitle("Column"); + no_g1g2_calib_map->GetYaxis()->SetTitle("Row"); + no_g1g2_calib_map->GetYaxis()->SetTitleOffset(0.7); + no_g1g2_calib_map->Draw("colz"); + sprintf(savename,"plots/M%s/%s/no_g1g2_calib_map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + +if (isHGX) { + sprintf(savename,"data/M%s/CS_ratio_M%s_HG0G1G2.root", module_str.c_str(), module_str.c_str()); + + } + else + { + sprintf(savename,"data/M%s/CS_ratio_M%s.root", module_str.c_str(), module_str.c_str()); + } + + + TFile* saved_file2 = new TFile((const char *)(savename),"RECREATE"); + g1overg2map->Write(); + g1overg2ermap->Write(); + saved_file2->Close(); + +} diff --git a/CS_analysis_M439.cpp b/CS_analysis_M439.cpp new file mode 100644 index 0000000..a75e3da --- /dev/null +++ b/CS_analysis_M439.cpp @@ -0,0 +1,2171 @@ +// file to take current source scan files, analyse and plot them. +// 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 "sls_detector_calibration/jungfrauCommonHeader.h" +#include "sls_detector_calibration/jungfrauCommonFunctions.h" + +#include "sls_detector_calibration/jungfrauFile.C" +#include "sls_detector_calibration/jungfrauPedestal.C" +#include "sls_detector_calibration/jungfrauPixelMask.C" + +#include "TGraph.h" +#include "TGraphErrors.h" +#include "TF1.h" +#include "TFile.h" +#include "TPaveStats.h" +#include "TLegend.h" +#include "TPaveText.h" + +#include +#include +#include + +double checkRangeMinForRCEffect(double range_min) { + + // check that the range minimum is at least 2 us, to avoid non-linearity of RC effect + if (range_min < 2.0) { + return 2.0; + } else { + return range_min; + } + +} + + +bool isHGX=false; +int main(int argc, char* argv[]) { + + jungfrauStyle(); + gROOT->SetBatch(1); + gStyle->SetOptFit(11); + + /* + if (argc != 4) { + cout << "Correct usage:" << endl; + cout << "arg 1: specify module number" << endl; + cout << "arg 2: specify data location" << endl; + cout << "arg 3: specify data file" << endl; + cout << " " << endl; + exit(1); + } + */ //uncomment for SR + + if (argc != 5) { + cout << "Correct usage:" << endl; + cout << "arg 1: specify module number" << endl; + cout << "arg 2: specify data location folder" << endl; + cout << "arg 3: specify data file prefix" << endl; + cout << "arg 4: specify location of analysis root files" << endl; + cout << " " << endl; + exit(1); + } //uncomment for VH 210906 + + + + string plotfolder_str; + string str2 ("HG0G1G2"); + string str3 =("HGOG1G2"); //filename creator had this bug + string module_str = argv[1]; + string data_loc = argv[2]; + string data_file = argv[3]; + string anadata_loc = argv[4]; //uncomment for VH 210906 + + +if (data_file.find(str2) != string::npos) isHGX=true; +if (data_file.find(str3) != string::npos) isHGX=true; + +if (isHGX) { + cout << " HG0->HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" < scan_v1; + scan_v1.push_back("002"); + scan_v1.push_back("003"); + + vector scan_v2; + scan_v2.push_back("032"); + + vector scan_v3; + + vector scan_v4; + scan_v4.push_back("040"); + scan_v4.push_back("044"); + + vector scan_v5; + scan_v5.push_back("006"); + scan_v5.push_back("022"); + scan_v5.push_back("055"); + scan_v5.push_back("065"); + scan_v5.push_back("066"); + scan_v5.push_back("068"); + scan_v5.push_back("069"); + scan_v5.push_back("088"); + scan_v5.push_back("094"); + + vector scan_v6; + scan_v6.push_back("008"); + scan_v6.push_back("011"); + scan_v6.push_back("021"); + scan_v6.push_back("023"); + scan_v6.push_back("025"); + scan_v6.push_back("029"); + scan_v6.push_back("035"); + scan_v6.push_back("039"); + scan_v6.push_back("043"); + scan_v6.push_back("045"); + scan_v6.push_back("046"); + scan_v6.push_back("048"); + scan_v6.push_back("049"); + scan_v6.push_back("050"); + scan_v6.push_back("051"); + scan_v6.push_back("053"); + scan_v6.push_back("054"); + scan_v6.push_back("057"); + scan_v6.push_back("058"); + scan_v6.push_back("059"); + scan_v6.push_back("060"); + scan_v6.push_back("061"); + scan_v6.push_back("062"); + scan_v6.push_back("063"); + scan_v6.push_back("064"); + scan_v6.push_back("067"); + scan_v6.push_back("070"); + scan_v6.push_back("071"); + scan_v6.push_back("072"); + scan_v6.push_back("073"); + scan_v6.push_back("074"); + scan_v6.push_back("075"); + scan_v6.push_back("076"); + scan_v6.push_back("079"); + scan_v6.push_back("080"); + scan_v6.push_back("086"); + scan_v6.push_back("089"); + scan_v6.push_back("090"); + scan_v6.push_back("091"); + scan_v6.push_back("092"); + scan_v6.push_back("093"); + scan_v6.push_back("095"); + scan_v6.push_back("097"); + scan_v6.push_back("098"); + scan_v6.push_back("099"); + scan_v6.push_back("100"); + scan_v6.push_back("102"); + scan_v6.push_back("103"); + scan_v6.push_back("104"); + scan_v6.push_back("106"); + scan_v6.push_back("107"); + scan_v6.push_back("108"); + scan_v6.push_back("109"); + scan_v6.push_back("110"); + scan_v6.push_back("111"); + scan_v6.push_back("112"); + scan_v6.push_back("113"); + scan_v6.push_back("114"); + scan_v6.push_back("115"); + scan_v6.push_back("116"); + scan_v6.push_back("117"); + scan_v6.push_back("118"); + scan_v6.push_back("119"); + scan_v6.push_back("120"); + scan_v6.push_back("121"); + scan_v6.push_back("122"); + scan_v6.push_back("123"); + scan_v6.push_back("124"); + scan_v6.push_back("125"); + scan_v6.push_back("126"); + scan_v6.push_back("129"); + scan_v6.push_back("130"); + scan_v6.push_back("131"); + scan_v6.push_back("132"); + scan_v6.push_back("133"); + scan_v6.push_back("134"); + scan_v6.push_back("135"); + scan_v6.push_back("200"); + scan_v6.push_back("201"); + scan_v6.push_back("202"); + scan_v6.push_back("203"); + scan_v6.push_back("204"); + scan_v6.push_back("205"); + scan_v6.push_back("206"); + scan_v6.push_back("208"); + scan_v6.push_back("209"); + scan_v6.push_back("210"); + scan_v6.push_back("212"); + scan_v6.push_back("214"); + scan_v6.push_back("215"); + scan_v6.push_back("216"); + scan_v6.push_back("217"); + scan_v6.push_back("218"); + scan_v6.push_back("219"); + scan_v6.push_back("221"); + scan_v6.push_back("222"); + scan_v6.push_back("223"); + scan_v6.push_back("224"); + scan_v6.push_back("225"); + scan_v6.push_back("226"); + scan_v6.push_back("227"); + scan_v6.push_back("228"); + scan_v6.push_back("229"); + scan_v6.push_back("232"); + scan_v6.push_back("233"); + scan_v6.push_back("234"); + scan_v6.push_back("235"); + scan_v6.push_back("236"); + scan_v6.push_back("242"); + scan_v6.push_back("244"); + scan_v6.push_back("245"); + scan_v6.push_back("246"); + scan_v6.push_back("248"); + scan_v6.push_back("249"); + scan_v6.push_back("250"); + scan_v6.push_back("251"); + scan_v6.push_back("252"); + scan_v6.push_back("253"); + scan_v6.push_back("254"); + scan_v6.push_back("255"); + scan_v6.push_back("260"); + scan_v6.push_back("261"); + scan_v6.push_back("263"); + scan_v6.push_back("264"); + scan_v6.push_back("265"); + scan_v6.push_back("266"); + scan_v6.push_back("267"); + scan_v6.push_back("269"); + scan_v6.push_back("270"); + scan_v6.push_back("272"); + scan_v6.push_back("273"); + scan_v6.push_back("274"); + scan_v6.push_back("275"); + scan_v6.push_back("276"); + scan_v6.push_back("277"); + scan_v6.push_back("278"); + scan_v6.push_back("279"); + scan_v6.push_back("281"); + scan_v6.push_back("282"); + scan_v6.push_back("283"); + scan_v6.push_back("285"); + scan_v6.push_back("286"); + scan_v6.push_back("287"); + scan_v6.push_back("288"); + scan_v6.push_back("289"); + scan_v6.push_back("290"); + scan_v6.push_back("291"); + scan_v6.push_back("292"); + scan_v6.push_back("294"); + scan_v6.push_back("296"); + scan_v6.push_back("298"); + scan_v6.push_back("299"); + scan_v6.push_back("301"); + scan_v6.push_back("307"); + scan_v6.push_back("312"); + scan_v6.push_back("351"); + scan_v6.push_back("352"); + scan_v6.push_back("354"); + scan_v6.push_back("360"); + scan_v6.push_back("373"); + scan_v6.push_back("380"); + scan_v6.push_back("304"); + scan_v6.push_back("321"); + scan_v6.push_back("346"); + scan_v6.push_back("375"); + scan_v6.push_back("381"); + scan_v6.push_back("383"); + scan_v6.push_back("310"); + scan_v6.push_back("313"); + scan_v6.push_back("314"); + scan_v6.push_back("334"); + scan_v6.push_back("337"); + scan_v6.push_back("347"); + scan_v6.push_back("361"); + scan_v6.push_back("362"); + scan_v6.push_back("355"); + scan_v6.push_back("364"); + scan_v6.push_back("366"); + scan_v6.push_back("243"); + scan_v6.push_back("339"); + scan_v6.push_back("341"); + scan_v6.push_back("368"); + scan_v6.push_back("376"); + scan_v6.push_back("379"); + + scan_v6.push_back("359"); + scan_v6.push_back("363"); + scan_v6.push_back("365"); + scan_v6.push_back("347"); + scan_v6.push_back("366"); + + + scan_v6.push_back("268"); + scan_v6.push_back("300"); + scan_v6.push_back("302"); + scan_v6.push_back("303"); + scan_v6.push_back("309"); + scan_v6.push_back("326"); + + scan_v6.push_back("308"); + scan_v6.push_back("322"); + scan_v6.push_back("328"); + scan_v6.push_back("332"); + scan_v6.push_back("335"); + scan_v6.push_back("353"); + scan_v6.push_back("335_FW2_2"); + scan_v6.push_back("353_FW2_2"); + + scan_v6.push_back("262_FWcheck_1_1_1"); + scan_v6.push_back("262_FWcheck_1_1_1_test"); + scan_v6.push_back("262_FWcheck_1_2_rc210831"); + scan_v6.push_back("262_FWcheck_1_2_defdacs"); + + scan_v6.push_back("311"); + scan_v6.push_back("316"); + scan_v6.push_back("318"); + scan_v6.push_back("319"); + scan_v6.push_back("320"); + scan_v6.push_back("324"); + + scan_v6.push_back("272_fullspeedtest"); + scan_v6.push_back("272_halfspeedtest"); + + scan_v6.push_back("352_fullspeed"); //jf4mb2-00 (SLS) + scan_v6.push_back("307_fullspeed"); //jf4mb2-01 (SLS) + scan_v6.push_back("264_fullspeed"); //jf4mb2-02 (SLS) + scan_v6.push_back("253_fullspeed"); //jf4mb2-03 (SLS) + scan_v6.push_back("351_fullspeed"); //jf4mb2-04 (SLS) + scan_v6.push_back("312_fullspeed"); //jf4mb2-05 (SLS) + scan_v6.push_back("261_fullspeed"); //jf4mb2-06 (SLS) + scan_v6.push_back("310_fullspeed"); //jf4mb2-07 (SLS) + + scan_v6.push_back("384"); //jfcalib-5 + scan_v6.push_back("510"); //jfcalib-0 + scan_v6.push_back("511"); //jfcalib-1 + scan_v6.push_back("512"); //jfcalib-2 + scan_v6.push_back("556"); //jfcalib-3 + scan_v6.push_back("572"); //jfcalib-4 + + scan_v6.push_back("329"); //jfcalib-0 + scan_v6.push_back("331"); //jfcalib-1 + scan_v6.push_back("333"); //jfcalib-2 + scan_v6.push_back("336"); //jfcalib-3 + scan_v6.push_back("356"); //jfcalib-4 + scan_v6.push_back("377"); //jfcalib-5 + + scan_v6.push_back("387"); //jfcalib-0 + scan_v6.push_back("388"); //jfcalib-1 + scan_v6.push_back("389"); //jfcalib-2 + scan_v6.push_back("396"); //jfcalib-3 + scan_v6.push_back("397"); //jfcalib-4 + scan_v6.push_back("398"); //jfcalib-5 + + scan_v6.push_back("390"); //jfcalib-0 + scan_v6.push_back("391"); //jfcalib-1 + scan_v6.push_back("393"); //jfcalib-2 + scan_v6.push_back("399"); //jfcalib-3 + scan_v6.push_back("516"); //jfcalib-4 + scan_v6.push_back("517"); //jfcalib-5 + + scan_v6.push_back("519"); //jfcalib-0 + scan_v6.push_back("520"); //jfcalib-1 + scan_v6.push_back("532"); //jfcalib-2 + scan_v6.push_back("539"); //jfcalib-3 + scan_v6.push_back("555"); //jfcalib-4 + + //Calib for VELA beamtime in March 2022 + scan_v6.push_back("262"); //jfcalib-0 + scan_v6.push_back("231"); //jfcalib-1 + scan_v6.push_back("305"); //jfcalib-2 + + scan_v6.push_back("392"); //jfcalib-1 + scan_v6.push_back("394"); //jfcalib-2 + scan_v6.push_back("513"); //jfcalib-3 + scan_v6.push_back("514"); //jfcalib-4 + scan_v6.push_back("515"); //jfcalib-5 + + scan_v6.push_back("239"); //jfcalib-0 //bad + //scan_v6.push_back("064"); //jfcalib-1 //bad //already added above + //scan_v6.push_back("023"); //jfcalib-2 //bad //already added above + scan_v6.push_back("349"); //jfcalib-3 //bad + scan_v6.push_back("518"); //jfcalib-4 + scan_v6.push_back("521"); //jfcalib-5 + + scan_v6.push_back("523"); //jfcalib-0 + scan_v6.push_back("526"); //jfcalib-1 + scan_v6.push_back("529"); //jfcalib-2 + scan_v6.push_back("530"); //jfcalib-3 + scan_v6.push_back("531"); //jfcalib-4 + scan_v6.push_back("533"); //jfcalib-5 + + scan_v6.push_back("524"); //1M for ESRF + scan_v6.push_back("525"); //1M for ESRF + + scan_v6.push_back("306"); //jfcalib-0 (strixel) + scan_v6.push_back("350"); //jfcalib-1 (strixel) + + scan_v6.push_back("534"); //jfcalib-0 + scan_v6.push_back("537"); //jfcalib-1 + scan_v6.push_back("538"); //jfcalib-2 + scan_v6.push_back("542"); //jfcalib-3 + scan_v6.push_back("543"); //jfcalib-4 + scan_v6.push_back("544"); //jfcalib-5 + + scan_v6.push_back("402"); //jfcalib-0 + scan_v6.push_back("404"); //jfcalib-1 + scan_v6.push_back("407"); //jfcalib-2 + scan_v6.push_back("409"); //jfcalib-3 + scan_v6.push_back("410"); //jfcalib-4 + scan_v6.push_back("411"); //jfcalib-5 + + //scan_v6.push_back("008"); //jfcalib-0 //already in the list from previous calibration + scan_v6.push_back("433"); //jfcalib-1 + scan_v6.push_back("550"); //jfcalib-2 + scan_v6.push_back("545"); //jfcalib-3 + scan_v6.push_back("546"); //jfcalib-4 + scan_v6.push_back("547"); //jfcalib-5 + + //scan_v6.push_back("416"); //jfcalib-0 //destroyed, machanical sample + scan_v6.push_back("417"); //jfcalib-1 + scan_v6.push_back("418"); //jfcalib-2 + scan_v6.push_back("420"); //jfcalib-3 + scan_v6.push_back("421"); //jfcalib-4 + scan_v6.push_back("430"); //jfcalib-5 + + scan_v6.push_back("417_fullspeed"); //jfcalib-1 + scan_v6.push_back("418_fullspeed"); //jfcalib-2 + scan_v6.push_back("420_fullspeed"); //jfcalib-3 + scan_v6.push_back("421_fullspeed"); //jfcalib-4 + scan_v6.push_back("430_fullspeed"); //jfcalib-5 + + scan_v6.push_back("434"); //jfcalib-0 + scan_v6.push_back("437"); //jfcalib-1 + scan_v6.push_back("480"); //jfcalib-2 + scan_v6.push_back("464"); //jfcalib-3 + scan_v6.push_back("473"); //jfcalib-4 + scan_v6.push_back("474"); //jfcalib-5 + + scan_v6.push_back("076"); //jfcalib-0 + scan_v6.push_back("089"); //jfcalib-3 + scan_v6.push_back("207"); //jfcalib-5 + + scan_v6.push_back("244"); //jfcalib-3 + + scan_v6.push_back("474_fullspeed"); //jfcalib-0 + scan_v6.push_back("437_fullspeed"); //jfcalib-1 + scan_v6.push_back("480_fullspeed"); //jfcalib-2 + scan_v6.push_back("482_fullspeed"); //jfcalib-3 + scan_v6.push_back("487_fullspeed"); //jfcalib-5 + + scan_v6.push_back("482"); //jfcalib-3 + scan_v6.push_back("487"); //jfcalib-5 + + scan_v6.push_back("499_fullspeed"); //jfcalib-0 + scan_v6.push_back("548_fullspeed"); //jfcalib-1 + scan_v6.push_back("549_fullspeed"); //jfcalib-2 + scan_v6.push_back("427_fullspeed"); //jfcalib-3 + + scan_v6.push_back("499"); //jfcalib-0 + scan_v6.push_back("548"); //jfcalib-1 + scan_v6.push_back("549"); //jfcalib-2 + scan_v6.push_back("427"); //jfcalib-3 + scan_v6.push_back("435"); //jfcalib-5 + + scan_v6.push_back("403"); //jfcalib-0 + scan_v6.push_back("406"); //jfcalib-1 + scan_v6.push_back("423"); //jfcalib-2 + scan_v6.push_back("436"); //jfcalib-3 + scan_v6.push_back("479"); //jfcalib-5 + + // Calibration 450 um sensor for ESRF + + scan_v6.push_back("583"); //jfcalib-0 + scan_v6.push_back("593"); //jfcalib-1 + scan_v6.push_back("601"); //jfcalib-2 + scan_v6.push_back("604"); //jfcalib-3 + scan_v6.push_back("605"); //jfcalib-5 + + // Calibration 320 um sensors + + scan_v6.push_back("441"); //jfcalib-0 + scan_v6.push_back("460"); //jfcalib-1 + scan_v6.push_back("463"); //jfcalib-2 + scan_v6.push_back("476"); //jfcalib-3 + scan_v6.push_back("371"); //jfcalib-4 + + scan_v6.push_back("429"); //jfcalib-0 + scan_v6.push_back("442"); //jfcalib-1 + scan_v6.push_back("444"); //jfcalib-2 + scan_v6.push_back("446"); //jfcalib-3 + scan_v6.push_back("447"); //jfcalib-4 + + scan_v6.push_back("428"); //jfcalib-0 + scan_v6.push_back("439"); //jfcalib-1 + scan_v6.push_back("443"); //jfcalib-2 + scan_v6.push_back("445"); //jfcalib-3 + + scan_v6.push_back("448"); //jfcalib-0 + scan_v6.push_back("454"); //jfcalib-1 + scan_v6.push_back("455"); //jfcalib-2 + scan_v6.push_back("456"); //jfcalib-3 + scan_v6.push_back("466"); //jfcalib-4 + scan_v6.push_back("471"); //jfcalib-5 + + scan_v6.push_back("481"); //jfcalib-0 + scan_v6.push_back("488"); //jfcalib-1 + scan_v6.push_back("490"); //jfcalib-2 + scan_v6.push_back("491"); //jfcalib-3 + scan_v6.push_back("492"); //jfcalib-4 + scan_v6.push_back("493"); //jfcalib-5 + + scan_v6.push_back("494"); //jfcalib-0 + scan_v6.push_back("495"); //jfcalib-1 + scan_v6.push_back("497"); //jfcalib-2 + scan_v6.push_back("498"); //jfcalib-3 + scan_v6.push_back("501"); //jfcalib-4 + scan_v6.push_back("502"); //jfcalib-5 + + scan_v6.push_back("036"); //jfcalib-0 + scan_v6.push_back("560"); //jfcalib-1 + scan_v6.push_back("536"); //jfcalib-2 + scan_v6.push_back("535"); //jfcalib-3 + scan_v6.push_back("527"); //jfcalib-4 + scan_v6.push_back("522"); //jfcalib-5 + + + jungfrauFile *thisfile = new jungfrauFile(); + + jungfrauPixelMask *pixelMaskObject = new jungfrauPixelMask(); + bool pixel_mask [NCH]; + + bool saturation_mask [NCH]; + std::fill_n(saturation_mask, NCH, true); + + jungfrauPedestal *pedestalObject = new jungfrauPedestal(); + pedestalObject->pedestalSetNFrames(640); + + TH2F* pedestalsG0 = new TH2F("pedestalsG0","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* pedestalsG1 = new TH2F("pedestalsG1","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* pedestalsG2 = new TH2F("pedestalsG2","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* pedeRMSG0 = new TH2F("pedeRMSG0","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F* no_g0g1_calib_map = new TH2F("no_g0g1_calib_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F* no_g1g2_calib_map = new TH2F("no_g1g2_calib_map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + //char savename[128]; + char savename[256]; // VH 210902 + int createHistoFile = 1; //set 0 for a fit-only run + int createPerStepHistos = 0; //debug + +#ifdef JF11 + cout << "COMPILED for JF11 !!!" << endl; +#endif + + // 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/CurrentSource + 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); + + // open first file + sprintf(savename,"%s/%s_%%6.6d.dat", data_loc.c_str(), data_file.c_str()); //VH: note, this adds a double slash in the filepath + thisfile->open((char*)savename, 0); + + // calculate pixel mask + pixelMaskObject->initialisePixelMask(pixel_mask); + + for (int i = 0; i < 640; i++) { + thisfile->readNextFrame(); + pixelMaskObject->maskIfGainNot(0, thisfile->getFrameDataHandle(), pixel_mask); + } + cout << "after G0, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl; + + for (int i = 0; i < 640; i++) { + thisfile->readNextFrame(); + pixelMaskObject->maskIfGainNot(1, thisfile->getFrameDataHandle(), pixel_mask); // change to Not(2 to fix FW error during JF11 FW develop. needed for modules 243-379 + } + cout << "after G1, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl; + + for (int i = 0; i < 640; i++) { + thisfile->readNextFrame(); + pixelMaskObject->maskIfGainNot(3, thisfile->getFrameDataHandle(), pixel_mask); + } + cout << "after G2, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl; + + thisfile->rewind(); + + sprintf(savename,"plots/M%s/%s/pixelmask_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + pixelMaskObject->plotPixelMask(pixel_mask,savename); + cout << "after chip mask, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl; + + // calculate pedestals + for (int j = 0; j < 640; j++) { + thisfile->readNextFrame(); + pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle()); + } + for (int i = 0; i < NCH; i++) { + if (pixel_mask[i] == true) { + pedestalsG0->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i)); + pedeRMSG0->Fill(i%NC,i/NC,pedestalObject->rmsOfChannel(i)); + } + } + pedestalObject->pedestalClear(); + + for (int j = 0; j < 640; j++) { + thisfile->readNextFrame(); + pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle()); + } + for (int i = 0; i < NCH; i++) { + if (pixel_mask[i] == true) { + pedestalsG1->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i)); + } + } + pedestalObject->pedestalClear(); + + for (int j = 0; j < 640; j++) { + thisfile->readNextFrame(); + pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle()); + } + for (int i = 0; i < NCH; i++) { + if (pixel_mask[i] == true) { + pedestalsG2->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i)); + } + } + pedestalObject->pedestalClear(); + + thisfile->close(); + + TCanvas *mapcanvas = new TCanvas("mapcanvas","",150,10,800,400); + mapcanvas->SetLeftMargin(0.1); + mapcanvas->SetRightMargin(0.13); + mapcanvas->SetTopMargin(0.08); + mapcanvas->SetBottomMargin(0.15); + + TCanvas *c1 = new TCanvas("c1",""); + + mapcanvas->cd(); + + pedestalsG0->GetXaxis()->SetTitle("Column"); + pedestalsG0->GetYaxis()->SetTitle("Row"); + pedestalsG0->GetYaxis()->SetTitleOffset(0.7); + pedestalsG0->Draw("colz"); + sprintf(savename,"plots/M%s/%s/pedeG0_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + pedestalsG1->GetXaxis()->SetTitle("Column"); + pedestalsG1->GetYaxis()->SetTitle("Row"); + pedestalsG1->GetYaxis()->SetTitleOffset(0.7); + pedestalsG1->Draw("colz"); + sprintf(savename,"plots/M%s/%s/pedeG1_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + pedestalsG2->GetXaxis()->SetTitle("Column"); + pedestalsG2->GetYaxis()->SetTitle("Row"); + pedestalsG2->GetYaxis()->SetTitleOffset(0.7); + pedestalsG2->Draw("colz"); + sprintf(savename,"plots/M%s/%s/pedeG2_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + pedeRMSG0->GetXaxis()->SetTitle("Column"); + pedeRMSG0->GetYaxis()->SetTitle("Row"); + pedeRMSG0->GetYaxis()->SetTitleOffset(0.7); + if (module_str == "006") { + pedeRMSG0->GetZaxis()->SetRangeUser(0,50); + } else { + pedeRMSG0->GetZaxis()->SetRangeUser(0,25); + } + pedeRMSG0->Draw("colz"); + sprintf(savename,"plots/M%s/%s/pedeRMSG0_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + TH2F *adcmap_avg_g0 [97]; + TH2F *adcmap_avg_g1 [97]; + TH2F *adcmap_avg_g2 [97]; + TH2F *adcermap_avg_g0 [97]; + TH2F *adcermap_avg_g1 [97]; + TH2F *adcermap_avg_g2 [97]; + + // creating the histograms + if (createHistoFile) { + + for(int i = 0; i < 97; i++) { + ostringstream histogramNameStreamg0; + histogramNameStreamg0 << "adcmap_avg_g0_" << i; + adcmap_avg_g0[i] = new TH2F(histogramNameStreamg0.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg1; + histogramNameStreamg1 << "adcmap_avg_g1_" << i; + adcmap_avg_g1[i] = new TH2F(histogramNameStreamg1.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg2; + histogramNameStreamg2 << "adcmap_avg_g2_" << i; + adcmap_avg_g2[i] = new TH2F(histogramNameStreamg2.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg5; + histogramNameStreamg5 << "adcermap_avg_g0_" << i; + adcermap_avg_g0[i] = new TH2F(histogramNameStreamg5.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg3; + histogramNameStreamg3 << "adcermap_avg_g1_" << i; + adcermap_avg_g1[i] = new TH2F(histogramNameStreamg3.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + ostringstream histogramNameStreamg4; + histogramNameStreamg4 << "adcermap_avg_g2_" << i; + adcermap_avg_g2[i] = new TH2F(histogramNameStreamg4.str().c_str(),"",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + } + + TH2F *gainmap_all = new TH2F("gainmap_all","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *adcmap_all = new TH2F("adcmap_all","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *gainmap_sel = new TH2F("gainmap_sel","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *adcmap_sel = new TH2F("adcmap_sel","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH1F *gain_avg = new TH1F("gain_avg","",100,-1,4); + TH2F *gainmap_avg = new TH2F("gainmap_avg","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH1F *adc_avg_g0 = new TH1F("adc_avg_g0","",100,0,17000); + TH1F *adc_avg_g1 = new TH1F("adc_avg_g1","",100,0,17000); + TH1F *adc_avg_g2 = new TH1F("adc_avg_g2","",100,0,17000); + + static TH1I *adc_histos_g0 [NCH]; + static TH1I *adc_histos_g1 [NCH]; + static TH1I *adc_histos_g2 [NCH]; + static TH1I *gain_histos [NCH]; + + for(int i = 0; i < NCH; i++) { + ostringstream histogramNameStreamg0; + histogramNameStreamg0 << "adc_histos_g0_" << i; + adc_histos_g0[i] = new TH1I(histogramNameStreamg0.str().c_str(),"",100,0,17000); + ostringstream histogramNameStreamg1; + histogramNameStreamg1 << "adc_histos_g1_" << i; + adc_histos_g1[i] = new TH1I(histogramNameStreamg1.str().c_str(),"",100,0,17000); + ostringstream histogramNameStreamg2; + histogramNameStreamg2 << "adc_histos_g2_" << i; + adc_histos_g2[i] = new TH1I(histogramNameStreamg2.str().c_str(),"",100,0,17000); + ostringstream histogramNameStream2; + histogramNameStream2 << "gain_histos_" << i; + gain_histos[i] = new TH1I(histogramNameStream2.str().c_str(),"",4,-0.5,3.5); + } + + int j = 0; + int nfiles = 0; + if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + nfiles = 2; + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end() || find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + nfiles = 3; + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + nfiles = 4; + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + nfiles = 7; + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + nfiles = 6; + } + + // total frame number check + int expected_totalFrames = 0; + if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + expected_totalFrames = 19199; + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + expected_totalFrames = 24319; + } else if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + expected_totalFrames = 21759; + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + expected_totalFrames = 34560; + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + expected_totalFrames = 64000; + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + expected_totalFrames = 59519; + } + + int totalFrames = 0; + + for (int filei = 0; filei < nfiles; filei++) { + + sprintf(savename,"%s/%s_%%6.6d.dat", data_loc.c_str(), data_file.c_str()); //VH: note, this adds a double slash in the filepath + thisfile->open((char*)savename, filei); + + while(thisfile->readNextFrame()) { + totalFrames++; + } + + thisfile->close(); + } + + if (totalFrames == expected_totalFrames) { + cout << "got expected number of frames " << totalFrames << endl; + } else { + cout << "got unexpected number of frames " << totalFrames << endl; + cout << "code expected frames " << expected_totalFrames << endl; + cout << "exiting to make sure you notice" << endl; + exit(1); + } + + for (int filei = 0; filei < nfiles; filei++) { + + sprintf(savename,"%s/%s_%%6.6d.dat", data_loc.c_str(), data_file.c_str()); //VH: note, this adds a double slash in the filepath + thisfile->open((char*)savename, filei); + + if (filei == 0) { + for (int k = 0; k < (640*3); k++) { + thisfile->readNextFrame(); + } + } + + while (thisfile->readNextFrame()) { + j++; + + uint16_t* imagedptr = thisfile->getFrameDataHandle(); + for (int i = 0; i < NCH; i++) { + + if ((j-1) < 10 || (j > 8075 && j < 8085)) { + uint16_t adc = imagedptr[i]&0x3fff; + uint16_t gain = (imagedptr[i]&0xc000) >> 14; + adcmap_all->Fill(i%NC,i/NC,adc); + gainmap_all->Fill(i%NC,i/NC,gain); + } +#ifdef NONSERVE //in reality it is shift in the right direction 0x5b=80000000 and 0x5a=00000000 + if (((i/NC <= 255) && (((i%64)) == 63-(j-1)%64)) || + ((i/NC >= 256) &&( ((-1*(i-524287))%64) == 63-(j-1)%64))) { //scanning on "+-i") +#else + if (((i/NC <= 255) && (i%64 == (j-1)%64)) || + ((i/NC >= 256) &&((-1*(i-524287))%64 == (j-1)%64))) { +#endif + + uint16_t adc = imagedptr[i]&0x3fff; + uint16_t gain = (imagedptr[i]&0xc000) >> 14; + + gain_histos[i]->Fill(gain); + if (gain == 0) { + adc_histos_g0[i]->Fill(adc); + } else if ((gain == 1)||(gain == 2)) { //(gain == 2) to fix FW error during JF11 FW develop. needed for modules 243-379 + adc_histos_g1[i]->Fill(adc); + } else if (gain == 3) { + adc_histos_g2[i]->Fill(adc); + if (adc == 0) { + saturation_mask[i] = false; + } + } + + if ((j-1) < 10 || (j > 8075 && j < 8085)) { + adcmap_sel->Fill(i%NC,i/NC,adc); + gainmap_sel->Fill(i%NC,i/NC,gain); + } + + } + } + if (createPerStepHistos && ((j-1) < 10 || (j > 8075 && j < 8085))) { + mapcanvas->cd(); + adcmap_sel->GetXaxis()->SetTitle("Column"); + adcmap_sel->GetYaxis()->SetTitle("Row"); + adcmap_sel->GetYaxis()->SetTitleOffset(0.7); + adcmap_sel->Draw("colz"); + sprintf(savename,"plots/M%s/%s/adcmap_%i_sel_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j-1, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + adcmap_all->GetXaxis()->SetTitle("Column"); + adcmap_all->GetYaxis()->SetTitle("Row"); + adcmap_all->GetYaxis()->SetTitleOffset(0.7); + adcmap_all->Draw("colz"); + sprintf(savename,"plots/M%s/%s/adcmap_%i_all_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j-1, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + gainmap_sel->GetXaxis()->SetTitle("Column"); + gainmap_sel->GetYaxis()->SetTitle("Row"); + gainmap_sel->GetYaxis()->SetTitleOffset(0.7); + gainmap_sel->Draw("colz"); + sprintf(savename,"plots/M%s/%s/gainmap_%i_sel_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j-1, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + gainmap_all->GetXaxis()->SetTitle("Column"); + gainmap_all->GetYaxis()->SetTitle("Row"); + gainmap_all->GetYaxis()->SetTitleOffset(0.7); + gainmap_all->Draw("colz"); + sprintf(savename,"plots/M%s/%s/gainmap_%i_all_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j-1, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + adcmap_sel->Reset(); + adcmap_all->Reset(); + gainmap_sel->Reset(); + gainmap_all->Reset(); + } + + // catch the last frame (bad ctrl-c exit) + // new receiver doesn't have this problem + int last_frame = 0; + if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end() || + find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end() || + find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end() || + find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + last_frame = expected_totalFrames - 1920; + } + + if (j%640 == 0 || j == last_frame) { + if (j == last_frame) { + j = last_frame+1; + cout << "catching on last_frame" << endl; + } + + for (int i = 0; i < NCH; i++) { + + gainmap_avg->Fill(i%NC,i/NC,gain_histos[i]->GetMean()); + adcmap_avg_g0[j/640-1]->Fill(i%NC,i/NC,adc_histos_g0[i]->GetMean()); + adcermap_avg_g0[j/640-1]->Fill(i%NC,i/NC,adc_histos_g0[i]->GetMeanError()); + adcmap_avg_g1[j/640-1]->Fill(i%NC,i/NC,adc_histos_g1[i]->GetMean()); + adcermap_avg_g1[j/640-1]->Fill(i%NC,i/NC,adc_histos_g1[i]->GetMeanError()); + if (saturation_mask[i] == true) { + adcmap_avg_g2[j/640-1]->Fill(i%NC,i/NC,adc_histos_g2[i]->GetMean()); + adcermap_avg_g2[j/640-1]->Fill(i%NC,i/NC,adc_histos_g2[i]->GetMeanError()); + } + + if (gain_histos[i]->GetEntries() > 0) { + gain_avg->Fill(gain_histos[i]->GetMean()); + } + if (adc_histos_g0[i]->GetEntries() > 0) { + adc_avg_g0->Fill(adc_histos_g0[i]->GetMean()); + } + if (adc_histos_g1[i]->GetEntries() > 0) { + adc_avg_g1->Fill(adc_histos_g1[i]->GetMean()); + } + if (adc_histos_g2[i]->GetEntries() > 0) { + if (saturation_mask[i] == true) { + adc_avg_g2->Fill(adc_histos_g2[i]->GetMean()); + } + } + + gain_histos[i]->Reset(); + adc_histos_g0[i]->Reset(); + adc_histos_g1[i]->Reset(); + adc_histos_g2[i]->Reset(); + } + + if (createPerStepHistos == 1) { + c1->cd(); + gain_avg->GetXaxis()->SetTitle("Average gain"); + gain_avg->GetXaxis()->SetTitleOffset(1.1); + gain_avg->GetYaxis()->SetTitleOffset(1.5); + gain_avg->Draw(); + sprintf(savename,"plots/M%s/%s/perStep/gain_avg_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + c1->SaveAs((const char *)(savename)); + mapcanvas->cd(); + gainmap_avg->GetXaxis()->SetTitle("Column"); + gainmap_avg->GetYaxis()->SetTitle("Row"); + gainmap_avg->GetYaxis()->SetTitleOffset(0.7); + gainmap_avg->Draw("colz"); + sprintf(savename,"plots/M%s/%s/perStep/gainmap_avg_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + c1->cd(); + adc_avg_g0->GetXaxis()->SetTitle("Average G0 ADC"); + adc_avg_g0->GetXaxis()->SetTitleOffset(1.1); + adc_avg_g0->GetYaxis()->SetTitleOffset(1.5); + adc_avg_g0->Draw(); + sprintf(savename,"plots/M%s/%s/perStep/adc_avg_g0_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + c1->SaveAs((const char *)(savename)); + mapcanvas->cd(); + adcmap_avg_g0[j/640-1]->GetXaxis()->SetTitle("Column"); + adcmap_avg_g0[j/640-1]->GetYaxis()->SetTitle("Row"); + adcmap_avg_g0[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcmap_avg_g0[j/640-1]->Draw("colz"); + mapcanvas->Update(); + sprintf(savename,"plots/M%s/%s/perStep/adcmap_avg_g0_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + adcermap_avg_g0[j/640-1]->GetXaxis()->SetTitle("Column"); + adcermap_avg_g0[j/640-1]->GetYaxis()->SetTitle("Row"); + adcermap_avg_g0[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcermap_avg_g0[j/640-1]->Draw("colz"); + mapcanvas->Update(); + sprintf(savename,"plots/M%s/%s/perStep/adcermap_avg_g0_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + c1->cd(); + adc_avg_g1->GetXaxis()->SetTitle("Average G1 ADC"); + adc_avg_g1->GetXaxis()->SetTitleOffset(1.1); + adc_avg_g1->GetYaxis()->SetTitleOffset(1.5); + adc_avg_g1->Draw(); + sprintf(savename,"plots/M%s/%s/perStep/adc_avg_g1_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + c1->SaveAs((const char *)(savename)); + mapcanvas->cd(); + adcmap_avg_g1[j/640-1]->GetXaxis()->SetTitle("Column"); + adcmap_avg_g1[j/640-1]->GetYaxis()->SetTitle("Row"); + adcmap_avg_g1[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcmap_avg_g1[j/640-1]->Draw("colz"); + mapcanvas->Update(); + sprintf(savename,"plots/M%s/%s/perStep/adcmap_avg_g1_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + adcermap_avg_g1[j/640-1]->GetXaxis()->SetTitle("Column"); + adcermap_avg_g1[j/640-1]->GetYaxis()->SetTitle("Row"); + adcermap_avg_g1[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcermap_avg_g1[j/640-1]->Draw("colz"); + mapcanvas->Update(); + sprintf(savename,"plots/M%s/%s/perStep/adcermap_avg_g1_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + c1->cd(); + adc_avg_g2->GetXaxis()->SetTitle("Average G2 ADC"); + adc_avg_g2->GetXaxis()->SetTitleOffset(1.1); + adc_avg_g2->GetYaxis()->SetTitleOffset(1.5); + adc_avg_g2->Draw(); + sprintf(savename,"plots/M%s/%s/perStep/adc_avg_g2_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + c1->SaveAs((const char *)(savename)); + mapcanvas->cd(); + adcmap_avg_g2[j/640-1]->GetXaxis()->SetTitle("Column"); + adcmap_avg_g2[j/640-1]->GetYaxis()->SetTitle("Row"); + adcmap_avg_g2[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcmap_avg_g2[j/640-1]->Draw("colz"); + sprintf(savename,"plots/M%s/%s/perStep/adcmap_avg_g2_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + adcermap_avg_g2[j/640-1]->GetXaxis()->SetTitle("Column"); + adcermap_avg_g2[j/640-1]->GetYaxis()->SetTitle("Row"); + adcermap_avg_g2[j/640-1]->GetYaxis()->SetTitleOffset(0.7); + adcermap_avg_g2[j/640-1]->Draw("colz"); + sprintf(savename,"plots/M%s/%s/perStep/adcermap_avg_g2_%i_M%s.png", module_str.c_str(),plotfolder_str.c_str(), j/640, module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + gain_avg->Reset(); + gainmap_avg->Reset(); + adc_avg_g0->Reset(); + adc_avg_g1->Reset(); + adc_avg_g2->Reset(); + std::fill_n(saturation_mask, NCH, true); + } + } // end of while + + thisfile->close(); + + } // end of files + + for (int i = 0; i < NCH; i++) { + delete gain_histos[i]; + delete adc_histos_g0[i]; + delete adc_histos_g1[i]; + delete adc_histos_g2[i]; + } + + // save histograms + //sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna/CS_histos_M%s.root", module_str.c_str(), module_str.c_str()); //uncomment for SR + sprintf(savename,"%s/CS_histos_M%s.root", anadata_loc.c_str(), module_str.c_str()); //uncomment for VH 210906 + TFile* saved_file = new TFile((const char *)(savename),"RECREATE"); + + for (int i = 0; i < 97; i++) { + adcmap_avg_g0[i]->Write(); + adcmap_avg_g1[i]->Write(); + adcmap_avg_g2[i]->Write(); + adcermap_avg_g0[i]->Write(); + adcermap_avg_g1[i]->Write(); + adcermap_avg_g2[i]->Write(); + } + saved_file->Close(); + } else { + // load histos + cout << "LOADING HISTOS" << endl; + //sprintf(savename,"/mnt/sls_det_storage/jungfrau_data1/jungfrau_ana_sophie/M%s_CalibAna/CS_histos_M%s.root", module_str.c_str(), module_str.c_str()); //uncomment for SR + sprintf(savename,"%s/CS_histos_M%s.root", anadata_loc.c_str(), module_str.c_str()); //uncomment for VH 210906 + TFile* saved_file = new TFile((const char *)(savename),"READ"); + + for (int i = 0; i < 97; i++) { + sprintf(savename,"adcmap_avg_g0_%d", i); + adcmap_avg_g0[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"adcmap_avg_g1_%d", i); + adcmap_avg_g1[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"adcmap_avg_g2_%d", i); + adcmap_avg_g2[i] = (TH2F*)saved_file->Get((const char *)(savename)); + + sprintf(savename,"adcermap_avg_g0_%d", i); + adcermap_avg_g0[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"adcermap_avg_g1_%d", i); + adcermap_avg_g1[i] = (TH2F*)saved_file->Get((const char *)(savename)); + sprintf(savename,"adcermap_avg_g2_%d", i); + adcermap_avg_g2[i] = (TH2F*)saved_file->Get((const char *)(savename)); + } + } + + TH2F *g0map = new TH2F("g0map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g0ermap = new TH2F("g0ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F *g1map = new TH2F("g1map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g1ermap = new TH2F("g1ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F *g2map = new TH2F("g2map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g2ermap = new TH2F("g2ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F *g0overg1map = new TH2F("g0overg1map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g0overg1ermap = new TH2F("g0overg1ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH2F *g1overg2map = new TH2F("g1overg2map","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + TH2F *g1overg2ermap = new TH2F("g1overg2ermap","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); + + TH1F *g0hist = new TH1F("g0hist","",100,10000,50000); + TH1F *g0erhist = new TH1F("g0erhist","",100,0,200); + + TH1F *g1hist = new TH1F("g1hist","",100,-3000,0); + TH1F *g1erhist = new TH1F("g1erhist","",100,0,50); + + TH1F *g2hist = 0; + if (module_str == "032") { + g2hist = new TH1F("g2hist","",100,-1000,-200); + } else { + g2hist = new TH1F("g2hist","",100,-300,0); + } + TH1F *g2erhist = new TH1F("g2erhist","",100,0,10); + + TH1F *g0overg1hist = new TH1F("g0overg1hist","",100,-50,0); + TH1F *g0overg1erhist = new TH1F("g0overg1erhist","",100,0,1); + + TH1F *g1overg2hist = new TH1F("g1overg2hist","",100,11,15); + TH1F *g1overg2erhist = new TH1F("g1overg2erhist","",100,0,1); + + TH1F *g0overg1_isEdge = new TH1F("g0overg1_isEdge","",100,-50,0); + TH1F *g0overg1_isInnerEdge = new TH1F("g0overg1_isInnerEdge","",100,-50,0); + TH1F *g0overg1_isDouble = new TH1F("g0overg1_isDouble","",100,-50,0); + TH1F *g0overg1_isNextToDouble = new TH1F("g0overg1_isNextToDouble","",100,-50,0); + TH1F *g0overg1_isQuad = new TH1F("g0overg1_isQuad","",100,-50,0); + TH1F *g0overg1_isBulk = new TH1F("g0overg1_isBulk","",100,-50,0); + + TH1F *g1overg2_isEdge = new TH1F("g1overg2_isEdge","",100,11,15); + TH1F *g1overg2_isInnerEdge = new TH1F("g1overg2_isInnerEdge","",100,11,15); + TH1F *g1overg2_isDouble = new TH1F("g1overg2_isDouble","",100,11,15); + TH1F *g1overg2_isNextToDouble = new TH1F("g1overg2_isNextToDouble","",100,11,15); + TH1F *g1overg2_isQuad = new TH1F("g1overg2_isQuad","",100,11,15); + TH1F *g1overg2_isBulk = new TH1F("g1overg2_isBulk","",100,11,15); + + double filter[97]; + if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + for (int i = 0; i < 5; i++) { + filter[i] = 0.05+(i*0.05); + } + for (int i = 0; i < 9; i++) { + filter[i+5] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+5+9] = 5.+(i*2.5); + } + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.05); + } + for (int i = 0; i < 17; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+9+17] = 5.+(i*2.5); + } + for (int i = 0; i < 8; i++) { + filter[i+9+17+17] = 50.+(i*10.); + } + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + // loop 1 + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.05); + } + // loop 2a + for (int i = 0; i < 11; i++) { + filter[i+9] = 0.5+(i*0.05); + } + // loop 2b + for (int i = 0; i < 10; i++) { + filter[i+9+11] = 1.10+(i*0.10); + } + // loop 2c + for (int i = 0; i < 10; i++) { + filter[i+9+11+10] = 2.25+(i*0.25); + } + // loop 3a + for (int i = 0; i < 11; i++) { + filter[i+9+11+10+10] = 5.+(i*0.5); + } + // loop 3b + for (int i = 0; i < 10; i++) { + filter[i+9+11+10+10+11] = 11.+(i*1.0); + } + // loop 3c + for (int i = 0; i < 10; i++) { + filter[i+9+11+10+10+11+10] = 22.5+(i*2.5); + } + // loop 4a + for (int i = 0; i < 11; i++) { + filter[i+9+11+10+10+11+10+10] = 50.+(i*5.); + } + // loop 4b + for (int i = 0; i < 15; i++) { + filter[i+9+11+10+10+11+10+10+11] = 110.+(i*10.); + } + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + for (int i = 0; i < 10; i++) { + filter[i] = 0.2+(i*0.2); + } + for (int i = 0; i < 8; i++) { + filter[i+10] = 3+(i*1); + } + for (int i = 0; i < 25; i++) { + filter[i+10+8] = 12+(i*2); + } + for (int i = 0; i < 47; i++) { + filter[i+10+8+25] = 80+(i*20); + } + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.025); + } + for (int i = 0; i < 9; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+9+9] = 5.+(i*2.5); + } + } else if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.025); + } + for (int i = 0; i < 9; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 9; i++) { + filter[i+9+9] = 5.+(i*2.5); + } + } + + mapcanvas->cd(); + mapcanvas->SetLeftMargin(0.13); + mapcanvas->SetRightMargin(0.05); + + for (int i = 0; i < NCH; i++) { + cout << i << endl; + vector r0_adc; + vector r0_filter; + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector r1_ferr; + + vector r2_adc; + vector r2_filter; + vector r2_adcerr; + vector r2_ferr; + + // filter out points at zero and points with 0 error (mean taken from one entry in hist) + int m_max = 0; + if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + m_max = 27; + } else if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + m_max = 31; + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + m_max = 35; + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + m_max = 51; + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + m_max = 97; + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + m_max = 90; + } + + for (int m = 0; m < m_max; m++) { + + double this_g0avg = adcmap_avg_g0[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g1avg = adcmap_avg_g1[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g2avg = adcmap_avg_g2[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g0avger = adcermap_avg_g0[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g1avger = adcermap_avg_g1[m]->GetBinContent((i%NC)+1,(i/NC)+1); + double this_g2avger = adcermap_avg_g2[m]->GetBinContent((i%NC)+1,(i/NC)+1); + + if (this_g0avg != 0) { + r0_filter.push_back(filter[m]); + r0_ferr.push_back(0.); + r0_adc.push_back(this_g0avg); + r0_adcerr.push_back(this_g0avger); + } + if (this_g1avg != 0) { + r1_filter.push_back(filter[m]); + r1_ferr.push_back(0.); + r1_adc.push_back(this_g1avg); + r1_adcerr.push_back(this_g1avger); + } + if (this_g2avg != 0) { + r2_filter.push_back(filter[m]); + r2_ferr.push_back(0.); + r2_adc.push_back(this_g2avg); + r2_adcerr.push_back(this_g2avger); + } + } + + TGraphErrors *grap_g0 = 0; + TGraphErrors *grap_g1 = 0; + TGraphErrors *grap_g2 = 0; + + TF1 *fit_g0 = 0; + TF1 *fit_g1 = 0; + TF1 *fit_g2 = 0; + + double rangemin_g0 = 0; + double rangemax_g0 = 0; + double rangemin_g1 = 0; + double rangemax_g1 = 0; + double rangemin_g2 = 0; + double rangemax_g2 = 0; + + // 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); + } + + if (r2_adc.size() > 1) { + grap_g2 = new TGraphErrors(r2_adc.size(),&(r2_filter[0]),&(r2_adc[0]),&(r2_ferr[0]),&(r2_adcerr[0])); + grap_g2->SetMarkerStyle(20); + grap_g2->SetMarkerColor(kRed); + grap_g2->SetLineColor(kRed); + } + + // plot the datapoints + if (r1_adc.size() > 1) { + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + grap_g1->GetXaxis()->SetLimits(0.009,5E2); + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + grap_g1->GetXaxis()->SetLimits(0.09,1.1E3); + } else { + grap_g1->GetXaxis()->SetLimits(0.009,1.1E2); + } + grap_g1->SetMinimum(0); + grap_g1->SetMaximum(16000); + grap_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g1->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g1->GetYaxis()->SetTitleOffset(0.9); + grap_g1->Draw("AP"); + if (r2_adc.size() > 1) { + grap_g2->Draw("P"); + } + if (r0_adc.size() > 1) { + grap_g0->Draw("P"); + } + mapcanvas->SetLogx(); + 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)); + mapcanvas->SetLogx(0); + + } + } + + // define fit ranges and fit + if (r0_adc.size() > 1) { + + rangemin_g0 = *min_element(r0_filter.begin(),r0_filter.end()); + //rangemin_g0 = checkRangeMinForRCEffect(rangemin_g0); + + rangemax_g0 = highestPointBeforeSwitching(r0_filter, r1_filter); + + if (rangemax_g0 > rangemin_g0) { + + fit_g0 = new TF1("fit_g0","[0]+[1]*x",rangemin_g0, rangemax_g0); + fit_g0->SetParameter(0, 3000.); + fit_g0->SetParameter(1, 30000.); + fit_g0->SetLineColor(kBlue); + fit_g0->SetParName(0,"G0 const"); + fit_g0->SetParName(1,"G0 grad"); + grap_g0->Fit(fit_g0,"QR+",""); + + g0hist->Fill(fit_g0->GetParameter(1)); + g0map->Fill(i%NC,i/NC,fit_g0->GetParameter(1)); + g0erhist->Fill(fit_g0->GetParError(1)); + g0ermap->Fill(i%NC,i/NC,fit_g0->GetParError(1)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + grap_g0->SetMinimum(0); + grap_g0->SetMaximum(16000); + grap_g0->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g0->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g0->GetYaxis()->SetTitleOffset(0.9); + grap_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end())); + grap_g0->Draw("AP"); + fit_g0->Draw("same"); + mapcanvas->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g0->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.71); + st0->SetY2NDC(0.90); + st0->SetBorderSize(0); + st0->SetTextColor(kBlue); + mapcanvas->SetLogx(); + 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)); + mapcanvas->SetLogx(0); + + vector 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); + + norm_g0->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g0->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g0->GetYaxis()->SetTitleOffset(0.9); + norm_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end())); + norm_g0->SetMinimum(-100); + norm_g0->SetMaximum(100); + norm_g0->Draw("AP"); + flat_g0->Draw("same"); + 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; + delete flat_g0; + } + } + } + + if (r1_adc.size() > 1) { + + rangemin_g1 = lowestPointAfterSwitching(r1_filter, r0_filter); + rangemin_g1 = checkRangeMinForRCEffect(rangemin_g1); + + rangemax_g1 = highestPointBeforeSwitching(r1_filter, r2_filter); + + if (rangemax_g1 > rangemin_g1) { + + fit_g1 = new TF1("fit_g1","[0]+[1]*x",rangemin_g1,rangemax_g1); + fit_g1->SetParameter(0, 10000.); + fit_g1->SetParameter(1, -0.1); + fit_g1->SetLineColor(kGreen+2); + fit_g1->SetParName(0,"G1 const"); + fit_g1->SetParName(1,"G1 grad"); + grap_g1->Fit(fit_g1,"QR",""); + + g1hist->Fill(fit_g1->GetParameter(1)); + g1map->Fill(i%NC,i/NC,fit_g1->GetParameter(1)); + g1erhist->Fill(fit_g1->GetParError(1)); + g1ermap->Fill(i%NC,i/NC,fit_g1->GetParError(1)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + grap_g1->SetMinimum(0); + grap_g1->SetMaximum(16000); + grap_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g1->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g1->GetYaxis()->SetTitleOffset(0.9); + grap_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end())); + grap_g1->Draw("AP"); + fit_g1->Draw("same"); + mapcanvas->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g1->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.17); + st0->SetY2NDC(0.36); + st0->SetBorderSize(0); + st0->SetTextColor(kGreen+2); + mapcanvas->SetLogx(); + 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)); + mapcanvas->SetLogx(0); + + vector 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])); + } + + 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_g1","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_p05pc = new TF1("lin_g1_p05pc","[0]+[1]*x",rangemin_g1,rangemax_g1); + lin_g1_p05pc->SetParameter(0,fit_g1->GetParameter(0)/200.); + lin_g1_p05pc->SetParameter(1,fit_g1->GetParameter(1)/200.); + lin_g1_p05pc->SetLineColor(kOrange+1); + + 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_m05pc = new TF1("lin_g1_m05pc","[0]+[1]*x",rangemin_g1,rangemax_g1); + lin_g1_m05pc->SetParameter(0,fit_g1->GetParameter(0)/-200.); + lin_g1_m05pc->SetParameter(1,fit_g1->GetParameter(1)/-200.); + lin_g1_m05pc->SetLineColor(kOrange+1); + + norm_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g1->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g1->GetYaxis()->SetTitleOffset(0.9); + norm_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end())); + norm_g1->SetMinimum(1.5*lin_g1_m05pc->Eval(rangemin_g1)); + norm_g1->SetMaximum(1.5*lin_g1_p05pc->Eval(rangemin_g1)); + norm_g1->Draw("AP"); + flat_g1->Draw("same"); + lin_g1_p02pc->Draw("same"); + lin_g1_p05pc->Draw("same"); + lin_g1_m02pc->Draw("same"); + lin_g1_m05pc->Draw("same"); + norm_g1->Draw("P"); + 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; + delete flat_g1; + } + } + } + + if (r2_adc.size() > 1) { + + rangemin_g2 = lowestPointAfterSwitching(r2_filter, r1_filter); + rangemin_g2 = checkRangeMinForRCEffect(rangemin_g2); + + rangemax_g2 = *max_element(r2_filter.begin(),r2_filter.end()); + + if (rangemax_g2 > rangemin_g2) { + + fit_g2 = new TF1("fit_g2","[0]+[1]*x",rangemin_g2, rangemax_g2); + fit_g2->SetParameter(0, 10000.); + fit_g2->SetParameter(1, -0.01); + fit_g2->SetLineColor(kRed); + fit_g2->SetParName(0,"G2 const"); + fit_g2->SetParName(1,"G2 grad"); + grap_g2->Fit(fit_g2,"QR+",""); + + g2hist->Fill(fit_g2->GetParameter(1)); + g2map->Fill(i%NC,i/NC,fit_g2->GetParameter(1)); + g2erhist->Fill(fit_g2->GetParError(1)); + g2ermap->Fill(i%NC,i/NC,fit_g2->GetParError(1)); + + if ((i >= 58000 && i < 58000+10) || // bulk + (i >= 10 && i < 10+10) || // edge + (i >= 1024+10 && i < 1024+10+10) || // inner edge + (i >= (256*1024)+10 && i < (256*1024)+10+10) || // double + (i >= (257*1024)+10 && i < (257*1024)+10+10) || // next to double + (i == (255*1024)+255) // quad + ) { + + string pixel_type = "x"; + if (i >= 58000 && i < 58000+10) { + pixel_type = "b"; + } else if (i >= 10 && i < 10+10) { + pixel_type = "e"; + } else if (i >= 1024+10 && i < 1024+10+10) { + pixel_type = "ie"; + } else if (i >= (256*1024)+10 && i < (256*1024)+10+10) { + pixel_type = "d"; + } else if (i >= (257*1024)+10 && i < (257*1024)+10+10) { + pixel_type = "ntd"; + } else if (i == (255*1024)+255) { + pixel_type = "q"; + } + + grap_g2->SetMinimum(0); + grap_g2->SetMaximum(16000); + grap_g2->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g2->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g2->GetYaxis()->SetTitleOffset(0.9); + grap_g2->GetXaxis()->SetLimits(*min_element(r2_filter.begin(),r2_filter.end()),*max_element(r2_filter.begin(),r2_filter.end())); + grap_g2->Draw("AP"); + fit_g2->Draw("same"); + mapcanvas->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g2->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.17); + st0->SetY2NDC(0.36); + st0->SetBorderSize(0); + st0->SetTextColor(kRed); + mapcanvas->SetLogx(); + sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g2_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)); + mapcanvas->SetLogx(0); + + vector r2_adc_norm; + for (size_t j = 0; j < r2_adc.size(); j++) { + r2_adc_norm.push_back(r2_adc[j] - fit_g2->Eval(r2_filter[j])); + } + + TGraphErrors *norm_g2 = new TGraphErrors(r2_adc.size(),&(r2_filter[0]),&(r2_adc_norm[0]),&(r2_ferr[0]),&(r2_adcerr[0])); + norm_g2->SetMarkerColor(kRed); + norm_g2->SetLineColor(kRed); + + TF1* flat_g2 = new TF1("flat_g2","0",rangemin_g2, rangemax_g2); + flat_g2->SetLineColor(kRed); + + TF1* lin_g2_p02pc = new TF1("lin_g2_p02pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_p02pc->SetParameter(0,fit_g2->GetParameter(0)/500.); + lin_g2_p02pc->SetParameter(1,fit_g2->GetParameter(1)/500.); + lin_g2_p02pc->SetLineColor(kOrange); + + TF1* lin_g2_p05pc = new TF1("lin_g2_p05pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_p05pc->SetParameter(0,fit_g2->GetParameter(0)/200.); + lin_g2_p05pc->SetParameter(1,fit_g2->GetParameter(1)/200.); + lin_g2_p05pc->SetLineColor(kOrange+1); + + TF1* lin_g2_m02pc = new TF1("lin_g2_m02pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_m02pc->SetParameter(0,fit_g2->GetParameter(0)/-500.); + lin_g2_m02pc->SetParameter(1,fit_g2->GetParameter(1)/-500.); + lin_g2_m02pc->SetLineColor(kOrange); + + TF1* lin_g2_m05pc = new TF1("lin_g2_m05pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_m05pc->SetParameter(0,fit_g2->GetParameter(0)/-200.); + lin_g2_m05pc->SetParameter(1,fit_g2->GetParameter(1)/-200.); + lin_g2_m05pc->SetLineColor(kOrange+1); + + norm_g2->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g2->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g2->GetYaxis()->SetTitleOffset(0.9); + norm_g2->GetXaxis()->SetLimits(*min_element(r2_filter.begin(),r2_filter.end()),*max_element(r2_filter.begin(),r2_filter.end())); + norm_g2->SetMinimum(1.5*lin_g2_m05pc->Eval(rangemin_g2)); + norm_g2->SetMaximum(1.5*lin_g2_p05pc->Eval(rangemin_g2)); + norm_g2->Draw("AP"); + flat_g2->Draw("same"); + lin_g2_p02pc->Draw("same"); + lin_g2_p05pc->Draw("same"); + lin_g2_m02pc->Draw("same"); + lin_g2_m05pc->Draw("same"); + norm_g2->Draw("P"); + sprintf(savename,"plots/M%s/%s/pixel_%s_%d_g2norm_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_g2; + delete flat_g2; + } + } + } + + // get ratio measurements + if (rangemax_g0 > rangemin_g0 && rangemax_g1 > rangemin_g1) { + + double this_g0overg1 = fit_g0->GetParameter(1)/fit_g1->GetParameter(1); + double this_g0overg1er = abs(fit_g0->GetParameter(1)/fit_g1->GetParameter(1))*sqrt(pow((fit_g0->GetParError(1)/fit_g0->GetParameter(1)),2) + pow((fit_g1->GetParError(1)/fit_g1->GetParameter(1)),2)); + + g0overg1map->Fill(i%NC,i/NC,this_g0overg1); + g0overg1hist->Fill(this_g0overg1); + g0overg1ermap->Fill(i%NC,i/NC,this_g0overg1er); + g0overg1erhist->Fill(this_g0overg1er); + + if (isEdge(i)) { + g0overg1_isEdge->Fill(this_g0overg1); + } + if (isInnerEdge(i)) { + g0overg1_isInnerEdge->Fill(this_g0overg1); + } + if (isDouble(i)) { + g0overg1_isDouble->Fill(this_g0overg1); + } + if (isNextToDouble(i)) { + g0overg1_isNextToDouble->Fill(this_g0overg1); + } + if (isQuad(i)) { + g0overg1_isQuad->Fill(this_g0overg1); + } + if (isBulk(i)) { + g0overg1_isBulk->Fill(this_g0overg1); + } + } else { + no_g0g1_calib_map->Fill(i%NC,i/NC,1); + } + + if (rangemax_g1 > rangemin_g1 && rangemax_g2 > rangemin_g2) { + + double this_g1overg2 = fit_g1->GetParameter(1)/fit_g2->GetParameter(1); + double this_g1overg2er = abs(fit_g1->GetParameter(1)/fit_g2->GetParameter(1))*sqrt(pow((fit_g1->GetParError(1)/fit_g1->GetParameter(1)),2) + pow((fit_g2->GetParError(1)/fit_g2->GetParameter(1)),2)); + + g1overg2map->Fill(i%NC,i/NC,this_g1overg2); + g1overg2hist->Fill(this_g1overg2); + g1overg2ermap->Fill(i%NC,i/NC,this_g1overg2er); + g1overg2erhist->Fill(this_g1overg2er); + + if (isEdge(i)) { + g1overg2_isEdge->Fill(this_g1overg2); + } + if (isInnerEdge(i)) { + g1overg2_isInnerEdge->Fill(this_g1overg2); + } + if (isDouble(i)) { + g1overg2_isDouble->Fill(this_g1overg2); + } + if (isNextToDouble(i)) { + g1overg2_isNextToDouble->Fill(this_g1overg2); + } + if (isQuad(i)) { + g1overg2_isQuad->Fill(this_g1overg2); + } + if (isBulk(i)) { + g1overg2_isBulk->Fill(this_g1overg2); + } + } else { + no_g1g2_calib_map->Fill(i%NC,i/NC,1); + } + + delete fit_g0; + delete fit_g1; + delete fit_g2; + delete grap_g0; + delete grap_g1; + delete grap_g2; + } + + mapcanvas->SetLeftMargin(0.1); + mapcanvas->SetRightMargin(0.13); + + c1->cd(); + + TPaveText *pave = new TPaveText(0.86,0.95,0.91,0.98,"blNDC"); + pave->SetBorderSize(0); + pave->SetFillStyle(0); + pave->SetTextSize(0.06); + pave->SetTextAlign(32); + + if (g0hist->GetEntries() > 0) { + g0hist->GetXaxis()->SetTitle("G0 gradient"); + g0hist->GetXaxis()->SetTitleOffset(1.1); + g0hist->GetYaxis()->SetTitleOffset(1.5); + g0hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0erhist->GetXaxis()->SetTitle("Fitted G0 uncert"); + g0erhist->GetXaxis()->SetTitleOffset(1.1); + g0erhist->GetYaxis()->SetTitleOffset(1.5); + g0erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g0erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + if (g1hist->GetEntries() > 0) { + g1hist->GetXaxis()->SetTitle("G1 gradient"); + g1hist->GetXaxis()->SetTitleOffset(1.1); + g1hist->GetYaxis()->SetTitleOffset(1.5); + g1hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1erhist->GetXaxis()->SetTitle("Fitted G1 uncert"); + g1erhist->GetXaxis()->SetTitleOffset(1.1); + g1erhist->GetYaxis()->SetTitleOffset(1.5); + g1erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g1erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + if (g2hist->GetEntries() > 0) { + g2hist->GetXaxis()->SetTitle("G2 gradient"); + g2hist->GetXaxis()->SetTitleOffset(1.1); + g2hist->GetYaxis()->SetTitleOffset(1.5); + g2hist->Draw(); + sprintf(savename,"plots/M%s/%s/g2hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g2erhist->GetXaxis()->SetTitle("Fitted G2 uncert"); + g2erhist->GetXaxis()->SetTitleOffset(1.1); + g2erhist->GetYaxis()->SetTitleOffset(1.5); + g2erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g2erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + if (g0overg1hist->GetEntries() > 0) { + g0overg1hist->GetXaxis()->SetTitle("G0 / G1"); + g0overg1hist->GetXaxis()->SetTitleOffset(1.1); + g0overg1hist->GetYaxis()->SetTitleOffset(1.5); + g0overg1hist->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + TPaveText *pave2 = new TPaveText(0.6,0.8,0.94,0.94,"blNDC"); + pave2->SetBorderSize(0); + pave2->SetFillStyle(0); + pave2->SetTextSize(0.04); + pave2->SetTextAlign(32); + g0overg1hist->Fit("gaus"); + g0overg1hist->Draw(); + c1->Update(); + TF1* g0overg1hist_gaus = g0overg1hist->GetFunction("gaus"); + if (g0overg1hist_gaus) { + sprintf(savename,"Mean %0.4f #pm %0.4f", g0overg1hist_gaus->GetParameter(1), g0overg1hist_gaus->GetParError(1)); + pave2->AddText((const char *)(savename)); + sprintf(savename,"Sigma %0.4f #pm %0.4f", g0overg1hist_gaus->GetParameter(2), g0overg1hist_gaus->GetParError(2)); + pave2->AddText((const char *)(savename)); + pave2->Draw(); + g0overg1hist->SetStats(kFALSE); + sprintf(savename,"plots/M%s/%s/g0overg1hist_fit_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + g0overg1erhist->GetXaxis()->SetTitle("G0 / G1 uncert"); + g0overg1erhist->GetXaxis()->SetTitleOffset(1.1); + g0overg1erhist->GetYaxis()->SetTitleOffset(1.5); + g0overg1erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g0overg1_isEdge->SetLineColor(kBlue); + g0overg1_isInnerEdge->SetLineColor(kCyan); + g0overg1_isDouble->SetLineColor(kGreen+2); + g0overg1_isNextToDouble->SetLineColor(kRed); + g0overg1_isQuad->SetLineColor(kOrange); + + g0overg1_isEdge->Scale(1./g0overg1_isEdge->GetEntries()); + g0overg1_isInnerEdge->Scale(1./g0overg1_isInnerEdge->GetEntries()); + g0overg1_isDouble->Scale(1./g0overg1_isDouble->GetEntries()); + g0overg1_isNextToDouble->Scale(1./g0overg1_isNextToDouble->GetEntries()); + g0overg1_isQuad->Scale(1./g0overg1_isQuad->GetEntries()); + g0overg1_isBulk->Scale(1./g0overg1_isBulk->GetEntries()); + + TLegend *leg1 = new TLegend(0.62,0.6,0.93,0.93); + leg1->AddEntry(g0overg1_isBulk, "Normal", "l"); + leg1->AddEntry(g0overg1_isDouble, "Double", "l"); + leg1->AddEntry(g0overg1_isNextToDouble, "Next to D", "l"); + leg1->AddEntry(g0overg1_isEdge, "Edge", "l"); + leg1->AddEntry(g0overg1_isInnerEdge, "Inner E", "l"); + + g0overg1_isDouble->GetXaxis()->SetTitle("G0 / G1"); + g0overg1_isDouble->GetYaxis()->SetTitle("Normalised"); + g0overg1_isDouble->GetYaxis()->SetTitleOffset(1.3); + g0overg1_isDouble->SetMinimum(0.0); + g0overg1_isDouble->SetMaximum(0.16); + g0overg1_isDouble->Draw(); + g0overg1_isEdge->Draw("same"); + g0overg1_isInnerEdge->Draw("same"); + g0overg1_isNextToDouble->Draw("same"); + g0overg1_isBulk->Draw("same"); + leg1->Draw("same"); + sprintf(savename,"plots/M%s/%s/g0overg1_perType_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + if (g1overg2hist->GetEntries() > 0) { + g1overg2hist->GetXaxis()->SetTitle("G1 / G2"); + g1overg2hist->GetXaxis()->SetTitleOffset(1.1); + g1overg2hist->GetYaxis()->SetTitleOffset(1.5); + g1overg2hist->Draw(); + sprintf(savename,"plots/M%s/%s/g1overg2hist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + TPaveText *pave2 = new TPaveText(0.6,0.8,0.94,0.94,"blNDC"); + pave2->SetBorderSize(0); + pave2->SetFillStyle(0); + pave2->SetTextSize(0.04); + pave2->SetTextAlign(32); + g1overg2hist->Fit("gaus"); + g1overg2hist->Draw(); + c1->Update(); + TF1* g1overg2hist_gaus = g1overg2hist->GetFunction("gaus"); + if (g1overg2hist_gaus) { + sprintf(savename,"Mean %0.4f #pm %0.4f", g1overg2hist_gaus->GetParameter(1), g1overg2hist_gaus->GetParError(1)); + pave2->AddText((const char *)(savename)); + sprintf(savename,"Sigma %0.4f #pm %0.4f", g1overg2hist_gaus->GetParameter(2), g1overg2hist_gaus->GetParError(2)); + pave2->AddText((const char *)(savename)); + pave2->Draw(); + g1overg2hist->SetStats(kFALSE); + sprintf(savename,"plots/M%s/%s/g1overg2hist_fit_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + g1overg2erhist->GetXaxis()->SetTitle("G1 / G2 uncert"); + g1overg2erhist->GetXaxis()->SetTitleOffset(1.1); + g1overg2erhist->GetYaxis()->SetTitleOffset(1.5); + g1overg2erhist->Draw(); + sprintf(savename,"plots/M%s/%s/g1overg2erhist_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + + g1overg2_isEdge->SetLineColor(kBlue); + g1overg2_isInnerEdge->SetLineColor(kCyan); + g1overg2_isDouble->SetLineColor(kGreen+2); + g1overg2_isNextToDouble->SetLineColor(kRed); + g1overg2_isQuad->SetLineColor(kOrange); + + g1overg2_isEdge->Scale(1./g1overg2_isEdge->GetEntries()); + g1overg2_isInnerEdge->Scale(1./g1overg2_isInnerEdge->GetEntries()); + g1overg2_isDouble->Scale(1./g1overg2_isDouble->GetEntries()); + g1overg2_isNextToDouble->Scale(1./g1overg2_isNextToDouble->GetEntries()); + g1overg2_isQuad->Scale(1./g1overg2_isQuad->GetEntries()); + g1overg2_isBulk->Scale(1./g1overg2_isBulk->GetEntries()); + + TLegend *leg = new TLegend(0.62,0.6,0.93,0.93); + leg->AddEntry(g1overg2_isBulk, "Normal", "l"); + leg->AddEntry(g1overg2_isDouble, "Double", "l"); + leg->AddEntry(g1overg2_isNextToDouble, "Next to D", "l"); + leg->AddEntry(g1overg2_isEdge, "Edge", "l"); + leg->AddEntry(g1overg2_isInnerEdge, "Inner E", "l"); + + g1overg2_isDouble->GetXaxis()->SetTitle("G1 / G2"); + g1overg2_isDouble->GetYaxis()->SetTitle("Normalised"); + g1overg2_isDouble->GetYaxis()->SetTitleOffset(1.3); + g1overg2_isDouble->SetMinimum(0.0); + g1overg2_isDouble->SetMaximum(0.16); + g1overg2_isDouble->Draw(); + g1overg2_isEdge->Draw("same"); + g1overg2_isInnerEdge->Draw("same"); + g1overg2_isNextToDouble->Draw("same"); + g1overg2_isBulk->Draw("same"); + leg->Draw("same"); + sprintf(savename,"plots/M%s/%s/g1overg2_perType_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + c1->SaveAs((const char *)(savename)); + } + + mapcanvas->cd(); + + if (g0map->GetEntries() > 0) { + g0map->GetXaxis()->SetTitle("Column"); + g0map->GetYaxis()->SetTitle("Row"); + g0map->GetYaxis()->SetTitleOffset(0.7); + g0map->GetZaxis()->SetRangeUser(20000,40000); + g0map->Draw("colz"); + pave->AddText("G0 [ADU/#mus]"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g0map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0ermap->GetXaxis()->SetTitle("Column"); + g0ermap->GetYaxis()->SetTitle("Row"); + g0ermap->GetYaxis()->SetTitleOffset(0.7); + g0ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G0}"); + pave->Draw(); + g0ermap->GetZaxis()->SetRangeUser(0,200); + sprintf(savename,"plots/M%s/%s/g0ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + if (g1map->GetEntries() > 0) { + g1map->GetXaxis()->SetTitle("Column"); + g1map->GetYaxis()->SetTitle("Row"); + g1map->GetYaxis()->SetTitleOffset(0.7); + if (module_str == "002") { + g1map->GetZaxis()->SetRangeUser(-400,-100); + } else { + g1map->GetZaxis()->SetRangeUser(-3000,0); + } + g1map->Draw("colz"); + pave->Clear(); + pave->AddText("G1 [ADU/#mus]"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g1map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1ermap->GetXaxis()->SetTitle("Column"); + g1ermap->GetYaxis()->SetTitle("Row"); + g1ermap->GetYaxis()->SetTitleOffset(0.7); + g1ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G1}"); + pave->Draw(); + g1ermap->GetZaxis()->SetRangeUser(0,50); + sprintf(savename,"plots/M%s/%s/g1ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + if (g1map->GetEntries() > 0) { + g2map->GetXaxis()->SetTitle("Column"); + g2map->GetYaxis()->SetTitle("Row"); + g2map->GetYaxis()->SetTitleOffset(0.7); + if (module_str == "032") { + g2map->GetZaxis()->SetRangeUser(-800,-400); + } else if (module_str == "002") { + g2map->GetZaxis()->SetRangeUser(-35,-10); + } else { + g2map->GetZaxis()->SetRangeUser(-200,-50); + } + g2map->Draw("colz"); + pave->Clear(); + pave->AddText("G2 [ADU/#mus]"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g2map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g2ermap->GetXaxis()->SetTitle("Column"); + g2ermap->GetYaxis()->SetTitle("Row"); + g2ermap->GetYaxis()->SetTitleOffset(0.7); + g2ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G2}"); + pave->Draw(); + g2ermap->GetZaxis()->SetRangeUser(0,5); + sprintf(savename,"plots/M%s/%s/g2ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + if (g0overg1map->GetEntries()) { + g0overg1map->GetXaxis()->SetTitle("Column"); + g0overg1map->GetYaxis()->SetTitle("Row"); + g0overg1map->GetYaxis()->SetTitleOffset(0.7); + if (module_str == "003") { + g0overg1map->GetZaxis()->SetRangeUser(-35,-30); + } else { + g0overg1map->GetZaxis()->SetRangeUser(-50,0); + } + g0overg1map->Draw("colz"); + pave->Clear(); + pave->AddText("G0/G1"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g0overg1ermap->GetXaxis()->SetTitle("Column"); + g0overg1ermap->GetYaxis()->SetTitle("Row"); + g0overg1ermap->GetYaxis()->SetTitleOffset(0.7); + g0overg1ermap->GetZaxis()->SetRangeUser(0,0.5); + g0overg1ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G0/G1}"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g0overg1ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + if (g1overg2map->GetEntries()) { + g1overg2map->GetXaxis()->SetTitle("Column"); + g1overg2map->GetYaxis()->SetTitle("Row"); + g1overg2map->GetYaxis()->SetTitleOffset(0.7); + +#ifdef JF11 + g1overg2map->GetZaxis()->SetRangeUser(11,12.5); +#else + g1overg2map->GetZaxis()->SetRangeUser(12,13.2); +#endif + + g1overg2map->Draw("colz"); + pave->Clear(); + pave->AddText("G1/G2"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g1overg2map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + g1overg2ermap->GetXaxis()->SetTitle("Column"); + g1overg2ermap->GetYaxis()->SetTitle("Row"); + g1overg2ermap->GetYaxis()->SetTitleOffset(0.7); + g1overg2ermap->GetZaxis()->SetRangeUser(0,0.5); + g1overg2ermap->Draw("colz"); + pave->Clear(); + pave->AddText("#sigma_{G1/G2}"); + pave->Draw(); + sprintf(savename,"plots/M%s/%s/g1overg2ermap_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + } + + no_g0g1_calib_map->GetXaxis()->SetTitle("Column"); + no_g0g1_calib_map->GetYaxis()->SetTitle("Row"); + no_g0g1_calib_map->GetYaxis()->SetTitleOffset(0.7); + no_g0g1_calib_map->Draw("colz"); + sprintf(savename,"plots/M%s/%s/no_g0g1_calib_map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + no_g1g2_calib_map->GetXaxis()->SetTitle("Column"); + no_g1g2_calib_map->GetYaxis()->SetTitle("Row"); + no_g1g2_calib_map->GetYaxis()->SetTitleOffset(0.7); + no_g1g2_calib_map->Draw("colz"); + sprintf(savename,"plots/M%s/%s/no_g1g2_calib_map_M%s.png", module_str.c_str(),plotfolder_str.c_str(), module_str.c_str()); + mapcanvas->SaveAs((const char *)(savename)); + + +if (isHGX) { + sprintf(savename,"data/M%s/CS_ratio_M%s_HG0G1G2.root", module_str.c_str(), module_str.c_str()); + + } + else + { + sprintf(savename,"data/M%s/CS_ratio_M%s.root", module_str.c_str(), module_str.c_str()); + } + + + TFile* saved_file2 = new TFile((const char *)(savename),"RECREATE"); + g1overg2map->Write(); + g1overg2ermap->Write(); + saved_file2->Close(); + +} diff --git a/CS_fit.cpp b/CS_fit.cpp new file mode 100644 index 0000000..be69fee --- /dev/null +++ b/CS_fit.cpp @@ -0,0 +1,1240 @@ +// 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 "TGraph.h" +#include "TGraphErrors.h" +#include "TF1.h" +#include "TFile.h" +#include "TPaveStats.h" +#include "TLegend.h" +#include "TPaveText.h" +#include "TCanvas.h" +#include "TFitResultPtr.h" +#include "TFitResult.h" + +#include +#include +#include + + +TGraphErrors *grap_g0; +TGraphErrors *grap_g1; +TGraphErrors *grap_g2; + +TF1 *fit_g0=0; +TF1 *fit_g1=0; +TF1 *fit_g2=0; + +TGraphErrors *norm_g0; +TGraphErrors *norm_g1; +TGraphErrors *norm_g2; + +TF1 *flat_g0; +TF1 *flat_g2; + +TF1 *lin_g1_p02pc; +TF1 *lin_g1_p05pc; +TF1 *lin_g1_m02pc; +TF1 *lin_g1_m05pc; + +TF1 *lin_g2_p02pc; +TF1 *lin_g2_p05pc; +TF1 *lin_g2_m02pc; +TF1 *lin_g2_m05pc; + +Double_t par1; +Double_t par2; + +double checkRangeMinForRCEffect(double range_min) { + + // check that the range minimum is at least 2 us, to avoid non-linearity of RC effect + if (range_min < 2.0) { + return 2.0; + } else { + return range_min; + } + +} + + + +bool isHGX=false; +int main(int argc, char* argv[]) { + + //nonblock(NB_ENABLE); + cout <<"opening the rootapp" <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 from 0 to 1023" << endl; + cout << "arg 3: specify pixel y position from 0 to 511" << endl; + exit(1); + } //uncomment for VH 210906 + + string module_str = argv[1]; + + string str2 =("HG0G1G2"); + string str3 =("HGOG1G2"); //filename creator had this bug + + int column = atoi(argv[2]); + int row = atoi(argv[3]); + + 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 <HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" < scan_v1; + scan_v1.push_back("002"); + scan_v1.push_back("003"); + + vector scan_v2; + scan_v2.push_back("032"); + + vector scan_v3; + + vector scan_v4; + scan_v4.push_back("040"); + scan_v4.push_back("044"); + + vector scan_v5; + scan_v5.push_back("006"); + scan_v5.push_back("022"); + scan_v5.push_back("055"); + scan_v5.push_back("065"); + scan_v5.push_back("066"); + scan_v5.push_back("068"); + scan_v5.push_back("069"); + scan_v5.push_back("088"); + scan_v5.push_back("094"); + + vector scan_v6; + scan_v6.push_back("008"); + scan_v6.push_back("011"); + scan_v6.push_back("021"); + scan_v6.push_back("023"); + scan_v6.push_back("025"); + scan_v6.push_back("029"); + scan_v6.push_back("035"); + scan_v6.push_back("039"); + scan_v6.push_back("043"); + scan_v6.push_back("045"); + scan_v6.push_back("046"); + scan_v6.push_back("048"); + scan_v6.push_back("049"); + scan_v6.push_back("050"); + scan_v6.push_back("051"); + scan_v6.push_back("053"); + scan_v6.push_back("054"); + scan_v6.push_back("057"); + scan_v6.push_back("058"); + scan_v6.push_back("059"); + scan_v6.push_back("060"); + scan_v6.push_back("061"); + scan_v6.push_back("062"); + scan_v6.push_back("063"); + scan_v6.push_back("064"); + scan_v6.push_back("067"); + scan_v6.push_back("070"); + scan_v6.push_back("071"); + scan_v6.push_back("072"); + scan_v6.push_back("073"); + scan_v6.push_back("074"); + scan_v6.push_back("075"); + scan_v6.push_back("076"); + scan_v6.push_back("079"); + scan_v6.push_back("080"); + scan_v6.push_back("086"); + scan_v6.push_back("089"); + scan_v6.push_back("090"); + scan_v6.push_back("091"); + scan_v6.push_back("092"); + scan_v6.push_back("093"); + scan_v6.push_back("095"); + scan_v6.push_back("097"); + scan_v6.push_back("098"); + scan_v6.push_back("099"); + scan_v6.push_back("100"); + scan_v6.push_back("102"); + scan_v6.push_back("103"); + scan_v6.push_back("104"); + scan_v6.push_back("106"); + scan_v6.push_back("107"); + scan_v6.push_back("108"); + scan_v6.push_back("109"); + scan_v6.push_back("110"); + scan_v6.push_back("111"); + scan_v6.push_back("112"); + scan_v6.push_back("113"); + scan_v6.push_back("114"); + scan_v6.push_back("115"); + scan_v6.push_back("116"); + scan_v6.push_back("117"); + scan_v6.push_back("118"); + scan_v6.push_back("119"); + scan_v6.push_back("120"); + scan_v6.push_back("121"); + scan_v6.push_back("122"); + scan_v6.push_back("123"); + scan_v6.push_back("124"); + scan_v6.push_back("125"); + scan_v6.push_back("126"); + scan_v6.push_back("129"); + scan_v6.push_back("130"); + scan_v6.push_back("131"); + scan_v6.push_back("132"); + scan_v6.push_back("133"); + scan_v6.push_back("134"); + scan_v6.push_back("135"); + scan_v6.push_back("200"); + scan_v6.push_back("201"); + scan_v6.push_back("202"); + scan_v6.push_back("203"); + scan_v6.push_back("204"); + scan_v6.push_back("205"); + scan_v6.push_back("206"); + scan_v6.push_back("208"); + scan_v6.push_back("209"); + scan_v6.push_back("210"); + scan_v6.push_back("212"); + scan_v6.push_back("214"); + scan_v6.push_back("215"); + scan_v6.push_back("216"); + scan_v6.push_back("217"); + scan_v6.push_back("218"); + scan_v6.push_back("219"); + scan_v6.push_back("221"); + scan_v6.push_back("222"); + scan_v6.push_back("223"); + scan_v6.push_back("224"); + scan_v6.push_back("225"); + scan_v6.push_back("226"); + scan_v6.push_back("227"); + scan_v6.push_back("228"); + scan_v6.push_back("229"); + scan_v6.push_back("232"); + scan_v6.push_back("233"); + scan_v6.push_back("234"); + scan_v6.push_back("235"); + scan_v6.push_back("236"); + scan_v6.push_back("242"); + scan_v6.push_back("244"); + scan_v6.push_back("245"); + scan_v6.push_back("246"); + scan_v6.push_back("248"); + scan_v6.push_back("249"); + scan_v6.push_back("250"); + scan_v6.push_back("251"); + scan_v6.push_back("252"); + scan_v6.push_back("253"); + scan_v6.push_back("254"); + scan_v6.push_back("255"); + scan_v6.push_back("260"); + scan_v6.push_back("261"); + scan_v6.push_back("263"); + scan_v6.push_back("264"); + scan_v6.push_back("265"); + scan_v6.push_back("266"); + scan_v6.push_back("267"); + scan_v6.push_back("269"); + scan_v6.push_back("270"); + scan_v6.push_back("272"); + scan_v6.push_back("273"); + scan_v6.push_back("274"); + scan_v6.push_back("275"); + scan_v6.push_back("276"); + scan_v6.push_back("277"); + scan_v6.push_back("278"); + scan_v6.push_back("279"); + scan_v6.push_back("281"); + scan_v6.push_back("282"); + scan_v6.push_back("283"); + scan_v6.push_back("285"); + scan_v6.push_back("286"); + scan_v6.push_back("287"); + scan_v6.push_back("288"); + scan_v6.push_back("289"); + scan_v6.push_back("290"); + scan_v6.push_back("291"); + scan_v6.push_back("292"); + scan_v6.push_back("294"); + scan_v6.push_back("296"); + scan_v6.push_back("298"); + scan_v6.push_back("299"); + scan_v6.push_back("301"); + scan_v6.push_back("307"); + scan_v6.push_back("312"); + scan_v6.push_back("351"); + scan_v6.push_back("352"); + scan_v6.push_back("354"); + scan_v6.push_back("360"); + scan_v6.push_back("373"); + scan_v6.push_back("380"); + scan_v6.push_back("304"); + scan_v6.push_back("321"); + scan_v6.push_back("346"); + scan_v6.push_back("375"); + scan_v6.push_back("381"); + scan_v6.push_back("383"); + scan_v6.push_back("310"); + scan_v6.push_back("313"); + scan_v6.push_back("314"); + scan_v6.push_back("334"); + scan_v6.push_back("337"); + scan_v6.push_back("347"); + scan_v6.push_back("361"); + scan_v6.push_back("362"); + scan_v6.push_back("355"); + scan_v6.push_back("364"); + scan_v6.push_back("366"); + scan_v6.push_back("243"); + scan_v6.push_back("339"); + scan_v6.push_back("341"); + scan_v6.push_back("368"); + scan_v6.push_back("376"); + scan_v6.push_back("379"); + + scan_v6.push_back("359"); + scan_v6.push_back("363"); + scan_v6.push_back("365"); + scan_v6.push_back("347"); + scan_v6.push_back("366"); + + scan_v6.push_back("268"); + scan_v6.push_back("300"); + scan_v6.push_back("302"); + scan_v6.push_back("303"); + scan_v6.push_back("309"); + scan_v6.push_back("326"); + + scan_v6.push_back("308"); + scan_v6.push_back("322"); + scan_v6.push_back("328"); + scan_v6.push_back("332"); + scan_v6.push_back("335"); + scan_v6.push_back("353"); + scan_v6.push_back("335_FW2_2"); + scan_v6.push_back("353_FW2_2"); + + scan_v6.push_back("262_FWcheck_1_1_1"); + scan_v6.push_back("262_FWcheck_1_1_1_test"); + scan_v6.push_back("262_FWcheck_1_2_rc210831"); + scan_v6.push_back("262_FWcheck_1_2_defdacs"); + + scan_v6.push_back("311"); + scan_v6.push_back("316"); + scan_v6.push_back("318"); + scan_v6.push_back("319"); + scan_v6.push_back("320"); + scan_v6.push_back("324"); + + scan_v6.push_back("272_fullspeedtest"); + scan_v6.push_back("272_halfspeedtest"); + + scan_v6.push_back("352_fullspeed"); //jf4mb2-00 (SLS) + scan_v6.push_back("307_fullspeed"); //jf4mb2-01 (SLS) + scan_v6.push_back("264_fullspeed"); //jf4mb2-02 (SLS) + scan_v6.push_back("253_fullspeed"); //jf4mb2-03 (SLS) + scan_v6.push_back("351_fullspeed"); //jf4mb2-04 (SLS) + scan_v6.push_back("312_fullspeed"); //jf4mb2-05 (SLS) + scan_v6.push_back("261_fullspeed"); //jf4mb2-06 (SLS) + scan_v6.push_back("310_fullspeed"); //jf4mb2-07 (SLS) + + scan_v6.push_back("384"); //jfcalib-5 + scan_v6.push_back("510"); //jfcalib-0 + scan_v6.push_back("511"); //jfcalib-1 + scan_v6.push_back("512"); //jfcalib-2 + scan_v6.push_back("556"); //jfcalib-3 + scan_v6.push_back("572"); //jfcalib-4 + + scan_v6.push_back("329"); //jfcalib-0 + scan_v6.push_back("331"); //jfcalib-1 + scan_v6.push_back("333"); //jfcalib-2 + scan_v6.push_back("336"); //jfcalib-3 + scan_v6.push_back("356"); //jfcalib-4 + scan_v6.push_back("377"); //jfcalib-5 + + scan_v6.push_back("387"); //jfcalib-0 + scan_v6.push_back("388"); //jfcalib-1 + scan_v6.push_back("389"); //jfcalib-2 + scan_v6.push_back("396"); //jfcalib-3 + scan_v6.push_back("397"); //jfcalib-4 + scan_v6.push_back("398"); //jfcalib-5 + + scan_v6.push_back("390"); //jfcalib-0 + scan_v6.push_back("391"); //jfcalib-1 + scan_v6.push_back("393"); //jfcalib-2 + scan_v6.push_back("399"); //jfcalib-3 + scan_v6.push_back("516"); //jfcalib-4 + scan_v6.push_back("517"); //jfcalib-5 + + scan_v6.push_back("519"); //jfcalib-0 + scan_v6.push_back("520"); //jfcalib-1 + scan_v6.push_back("532"); //jfcalib-2 + scan_v6.push_back("539"); //jfcalib-3 + scan_v6.push_back("555"); //jfcalib-4 + + //Calib for VELA beamtime in March 2022 + scan_v6.push_back("262"); //jfcalib-0 + scan_v6.push_back("231"); //jfcalib-1 + scan_v6.push_back("305"); //jfcalib-2 + + scan_v6.push_back("392"); //jfcalib-1 + scan_v6.push_back("394"); //jfcalib-2 + scan_v6.push_back("513"); //jfcalib-3 + scan_v6.push_back("514"); //jfcalib-4 + scan_v6.push_back("515"); //jfcalib-5 + + scan_v6.push_back("239"); //jfcalib-0 //bad + scan_v6.push_back("064"); //jfcalib-1 //bad //already added above + scan_v6.push_back("023"); //jfcalib-2 //bad //already added above + scan_v6.push_back("349"); //jfcalib-3 //bad + scan_v6.push_back("518"); //jfcalib-4 + scan_v6.push_back("521"); //jfcalib-5 + + scan_v6.push_back("523"); //jfcalib-0 + scan_v6.push_back("526"); //jfcalib-1 + scan_v6.push_back("529"); //jfcalib-2 + scan_v6.push_back("530"); //jfcalib-3 + scan_v6.push_back("531"); //jfcalib-4 + scan_v6.push_back("533"); //jfcalib-5 + + scan_v6.push_back("524"); //1M for ESRF + scan_v6.push_back("525"); //1M for ESRF + + scan_v6.push_back("306"); //jfcalib-0 (strixel) + scan_v6.push_back("350"); //jfcalib-1 (strixel) + + scan_v6.push_back("534"); //jfcalib-0 + scan_v6.push_back("537"); //jfcalib-1 + scan_v6.push_back("538"); //jfcalib-2 + scan_v6.push_back("542"); //jfcalib-3 + scan_v6.push_back("543"); //jfcalib-4 + scan_v6.push_back("544"); //jfcalib-5 + + scan_v6.push_back("402"); //jfcalib-0 + scan_v6.push_back("404"); //jfcalib-1 + scan_v6.push_back("407"); //jfcalib-2 + scan_v6.push_back("409"); //jfcalib-3 + scan_v6.push_back("410"); //jfcalib-4 + scan_v6.push_back("411"); //jfcalib-5 + + //scan_v6.push_back("008"); //jfcalib-0 //already in the list from previous calibration + scan_v6.push_back("433"); //jfcalib-1 + scan_v6.push_back("550"); //jfcalib-2 + scan_v6.push_back("545"); //jfcalib-3 + scan_v6.push_back("546"); //jfcalib-4 + scan_v6.push_back("547"); //jfcalib-5 + + //scan_v6.push_back("416"); //jfcalib-0 //destroyed, machanical sample + scan_v6.push_back("417"); //jfcalib-1 + scan_v6.push_back("418"); //jfcalib-2 + scan_v6.push_back("420"); //jfcalib-3 + scan_v6.push_back("421"); //jfcalib-4 + scan_v6.push_back("430"); //jfcalib-5 + + scan_v6.push_back("417_fullspeed"); //jfcalib-1 + scan_v6.push_back("418_fullspeed"); //jfcalib-2 + scan_v6.push_back("420_fullspeed"); //jfcalib-3 + scan_v6.push_back("421_fullspeed"); //jfcalib-4 + scan_v6.push_back("430_fullspeed"); //jfcalib-5 + + scan_v6.push_back("434"); //jfcalib-0 + scan_v6.push_back("437"); //jfcalib-1 + scan_v6.push_back("480"); //jfcalib-2 + scan_v6.push_back("464"); //jfcalib-3 + scan_v6.push_back("473"); //jfcalib-4 + scan_v6.push_back("474"); //jfcalib-5 + + scan_v6.push_back("076"); //jfcalib-0 + scan_v6.push_back("089"); //jfcalib-3 + scan_v6.push_back("207"); //jfcalib-5 + + scan_v6.push_back("244"); //jfcalib-3 + + scan_v6.push_back("474_fullspeed"); //jfcalib-0 + scan_v6.push_back("437_fullspeed"); //jfcalib-1 + scan_v6.push_back("480_fullspeed"); //jfcalib-2 + scan_v6.push_back("482_fullspeed"); //jfcalib-3 + scan_v6.push_back("487_fullspeed"); //jfcalib-5 + + scan_v6.push_back("482"); //jfcalib-3 + scan_v6.push_back("487"); //jfcalib-5 + + scan_v6.push_back("499_fullspeed"); //jfcalib-0 + scan_v6.push_back("548_fullspeed"); //jfcalib-1 + scan_v6.push_back("549_fullspeed"); //jfcalib-2 + scan_v6.push_back("427_fullspeed"); //jfcalib-3 + + scan_v6.push_back("499"); //jfcalib-0 + scan_v6.push_back("548"); //jfcalib-1 + scan_v6.push_back("549"); //jfcalib-2 + scan_v6.push_back("427"); //jfcalib-3 + scan_v6.push_back("435"); //jfcalib-5 + + scan_v6.push_back("403"); //jfcalib-0 + scan_v6.push_back("406"); //jfcalib-1 + scan_v6.push_back("423"); //jfcalib-2 + scan_v6.push_back("436"); //jfcalib-3 + scan_v6.push_back("479"); //jfcalib-5 + + // Calibration 450 um sensor for ESRF + + scan_v6.push_back("583"); //jfcalib-0 + scan_v6.push_back("593"); //jfcalib-1 + scan_v6.push_back("601"); //jfcalib-2 + scan_v6.push_back("604"); //jfcalib-3 + scan_v6.push_back("605"); //jfcalib-5 + + // Calibration 320 um sensors + + scan_v6.push_back("441"); //jfcalib-0 + scan_v6.push_back("460"); //jfcalib-1 + scan_v6.push_back("463"); //jfcalib-2 + scan_v6.push_back("476"); //jfcalib-3 + scan_v6.push_back("371"); //jfcalib-4 + + scan_v6.push_back("429"); //jfcalib-0 + scan_v6.push_back("442"); //jfcalib-1 + scan_v6.push_back("444"); //jfcalib-2 + scan_v6.push_back("446"); //jfcalib-3 + scan_v6.push_back("447"); //jfcalib-4 + + scan_v6.push_back("428"); //jfcalib-0 + scan_v6.push_back("439"); //jfcalib-1 + scan_v6.push_back("443"); //jfcalib-2 + scan_v6.push_back("445"); //jfcalib-3 + + scan_v6.push_back("448"); //jfcalib-0 + scan_v6.push_back("454"); //jfcalib-1 + scan_v6.push_back("455"); //jfcalib-2 + scan_v6.push_back("456"); //jfcalib-3 + scan_v6.push_back("466"); //jfcalib-4 + scan_v6.push_back("471"); //jfcalib-5 + + scan_v6.push_back("481"); //jfcalib-0 + scan_v6.push_back("488"); //jfcalib-1 + scan_v6.push_back("490"); //jfcalib-2 + scan_v6.push_back("491"); //jfcalib-3 + scan_v6.push_back("492"); //jfcalib-4 + scan_v6.push_back("493"); //jfcalib-5 + + scan_v6.push_back("494"); //jfcalib-0 + scan_v6.push_back("495"); //jfcalib-1 + scan_v6.push_back("497"); //jfcalib-2 + scan_v6.push_back("498"); //jfcalib-3 + scan_v6.push_back("501"); //jfcalib-4 + scan_v6.push_back("502"); //jfcalib-5 + + scan_v6.push_back("036"); //jfcalib-0 + scan_v6.push_back("036_fullspeed"); //jfcalib-0 + scan_v6.push_back("560"); //jfcalib-1 + scan_v6.push_back("536"); //jfcalib-2 + scan_v6.push_back("535"); //jfcalib-3 + scan_v6.push_back("527"); //jfcalib-4 + scan_v6.push_back("522"); //jfcalib-5 + + scan_v6.push_back("571"); //jfcalib-0 + scan_v6.push_back("571_fullspeed"); //jfcalib-0 + scan_v6.push_back("573"); //jfcalib-1 + scan_v6.push_back("573_fullspeed"); //jfcalib-1 + scan_v6.push_back("574"); //jfcalib-2 + scan_v6.push_back("574_fullspeed"); //jfcalib-2 + scan_v6.push_back("575"); //jfcalib-3 + scan_v6.push_back("575_fullspeed"); //jfcalib-3 + scan_v6.push_back("576"); //jfcalib-4 + scan_v6.push_back("576_fullspeed"); //jfcalib-4 + scan_v6.push_back("577"); //jfcalib-5 + scan_v6.push_back("577_fullspeed"); //jfcalib-5 + + scan_v6.push_back("563"); //jfcalib-0 + scan_v6.push_back("563_fullspeed"); //jfcalib-0 + scan_v6.push_back("564"); //jfcalib-1 + scan_v6.push_back("564_fullspeed"); //jfcalib-1 + scan_v6.push_back("566"); //jfcalib-2 + scan_v6.push_back("566_fullspeed"); //jfcalib-2 + scan_v6.push_back("567"); //jfcalib-3 + scan_v6.push_back("567_fullspeed"); //jfcalib-3 + scan_v6.push_back("568"); //jfcalib-4 + scan_v6.push_back("568_fullspeed"); //jfcalib-4 + scan_v6.push_back("569"); //jfcalib-5 + scan_v6.push_back("569_fullspeed"); //jfcalib-5 + + scan_v6.push_back("579"); //QUAD thin + scan_v6.push_back("579_fullspeed"); //QUAD thin + + scan_v6.push_back("454_fullspeed"); //jfcalib-0 + scan_v6.push_back("466_fullspeed"); //jfcalib-1 + scan_v6.push_back("536_fullspeed"); //jfcalib-2 + scan_v6.push_back("561"); //jfcalib-4 + scan_v6.push_back("561_fullspeed"); //jfcalib-3 + scan_v6.push_back("562"); //jfcalib-4 + scan_v6.push_back("562_fullspeed"); //jfcalib-4 + scan_v6.push_back("038"); //jfcalib-5 + scan_v6.push_back("038_fullspeed"); //jfcalib-5 + + scan_v6.push_back("431_JF12"); + + + scan_v6.push_back("428_fullspeed"); //jfcalib-0 + scan_v6.push_back("443_fullspeed"); //jfcalib-1 + scan_v6.push_back("444_fullspeed"); //jfcalib-2 + scan_v6.push_back("455_fullspeed"); //jfcalib-3 + scan_v6.push_back("471_fullspeed"); //jfcalib-4 + scan_v6.push_back("493_fullspeed"); //jfcalib-5 + + scan_v6.push_back("448_fullspeed"); //jfcalib-0 + scan_v6.push_back("497_fullspeed"); //jfcalib-1 + scan_v6.push_back("498_fullspeed"); //jfcalib-2 + scan_v6.push_back("501_fullspeed"); //jfcalib-3 + scan_v6.push_back("502_fullspeed"); //jfcalib-4 + scan_v6.push_back("527_fullspeed"); //jfcalib-5 + + scan_v6.push_back("580_fullspeed"); //jfcalib-5 + scan_v6.push_back("580"); //jfcalib-5 + + scan_v6.push_back("596"); //jfcalib-0 + scan_v6.push_back("596_fullspeed"); //jfcalib-0 + scan_v6.push_back("597"); //jfcalib-1 + scan_v6.push_back("597_fullspeed"); //jfcalib-1 + scan_v6.push_back("598"); //jfcalib-2 + scan_v6.push_back("598_fullspeed"); //jfcalib-2 + scan_v6.push_back("599"); //jfcalib-3 + scan_v6.push_back("599_fullspeed"); //jfcalib-3 + scan_v6.push_back("602"); //jfcalib-4 + scan_v6.push_back("602_fullspeed"); //jfcalib-4 + scan_v6.push_back("603"); //jfcalib-5 + scan_v6.push_back("603_fullspeed"); //jfcalib-5 + + scan_v6.push_back("578"); //jfcalib-0 + scan_v6.push_back("578_fullspeed"); //jfcalib-0 + scan_v6.push_back("588"); //jfcalib-2 + scan_v6.push_back("588_fullspeed"); //jfcalib-2 + scan_v6.push_back("592"); //jfcalib-3 + scan_v6.push_back("592_fullspeed"); //jfcalib-3 + scan_v6.push_back("590"); //jfcalib-4 + scan_v6.push_back("590_fullspeed"); //jfcalib-4 + scan_v6.push_back("591"); //jfcalib-5 + scan_v6.push_back("591_fullspeed"); //jfcalib-5 + + scan_v6.push_back("594"); //jfcalib-0 + scan_v6.push_back("594_fullspeed"); //jfcalib-0 + scan_v6.push_back("595"); //jfcalib-1 + scan_v6.push_back("595_fullspeed"); //jfcalib-1 + scan_v6.push_back("606"); //jfcalib-3 + scan_v6.push_back("606_fullspeed"); //jfcalib-3 + scan_v6.push_back("608"); //jfcalib-4 + scan_v6.push_back("608_fullspeed"); //jfcalib-4 + scan_v6.push_back("589"); //jfcalib-5 + scan_v6.push_back("589_fullspeed"); //jfcalib-5 + + scan_v6.push_back("586"); //jfcalib-0 + scan_v6.push_back("586_fullspeed"); //jfcalib-0 + scan_v6.push_back("607"); //jfcalib-1 + scan_v6.push_back("607_fullspeed"); //jfcalib-1 + scan_v6.push_back("609"); //jfcalib-2 + scan_v6.push_back("609_fullspeed"); //jfcalib-2 + scan_v6.push_back("625"); //jfcalib-3 + scan_v6.push_back("625_fullspeed"); //jfcalib-3 + scan_v6.push_back("626"); //jfcalib-4 + scan_v6.push_back("626_fullspeed"); //jfcalib-4 + + scan_v6.push_back("607"); //jfcalib-1 + scan_v6.push_back("607_fullspeed"); //jfcalib-1 + scan_v6.push_back("609"); //jfcalib-2 + scan_v6.push_back("609_fullspeed"); //jfcalib-2 + scan_v6.push_back("367"); //jfcalib-4 + scan_v6.push_back("367_fullspeed"); //jfcalib-4 + scan_v6.push_back("604"); //jfcalib-5 + scan_v6.push_back("604_fullspeed"); //jfcalib-5 + + + scan_v6.push_back("367_Kirsty"); //jfcalib-4 + scan_v6.push_back("367_Kirsty_fullspeed"); //jfcalib-4 + scan_v6.push_back("604_Kirsty"); //jfcalib-5 + scan_v6.push_back("604_Kirsty_fullspeed"); //jfcalib-5 + + + scan_v6.push_back("628"); //jfcalib-0 + scan_v6.push_back("628_fullspeed"); //jfcalib-0 + scan_v6.push_back("627"); //jfcalib-1 + scan_v6.push_back("627_fullspeed"); //jfcalib-1 + scan_v6.push_back("629"); //jfcalib-5 + scan_v6.push_back("629_fullspeed"); //jfcalib-5 + scan_v6.push_back("642"); //jfcalib-3 + scan_v6.push_back("642_fullspeed"); //jfcalib-3 + scan_v6.push_back("604"); //jfcalib-4 + scan_v6.push_back("604_fullspeed"); //jfcalib-4 + scan_v6.push_back("701_Vadym"); + + + + // filter out points at zero and points with 0 error (mean taken from one entry in hist) + int m_max = 0; + if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + m_max = 27; + } else if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + m_max = 31; + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + m_max = 35; + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + m_max = 51; + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + m_max = 97; + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + m_max = 90; + } + + std::vector G0_pixel(97, 0); + std::vector G0_err_pixel(97, 0); + std::vector G1_pixel(97, 0); + std::vector G1_err_pixel(97, 0); + std::vector G2_pixel(97, 0); + std::vector G2_err_pixel(97, 0); + + + char filename[256]; //uncomment for VH 210902 + + +double filter[97]; + if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + for (int i = 0; i < 5; i++) { + filter[i] = 0.05+(i*0.05); + } + for (int i = 0; i < 9; i++) { + filter[i+5] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+5+9] = 5.+(i*2.5); + } + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.05); + } + for (int i = 0; i < 17; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+9+17] = 5.+(i*2.5); + } + for (int i = 0; i < 8; i++) { + filter[i+9+17+17] = 50.+(i*10.); + } + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + // loop 1 + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.05); + } + // loop 2a + for (int i = 0; i < 11; i++) { + filter[i+9] = 0.5+(i*0.05); + } + // loop 2b + for (int i = 0; i < 10; i++) { + filter[i+9+11] = 1.10+(i*0.10); + } + // loop 2c + for (int i = 0; i < 10; i++) { + filter[i+9+11+10] = 2.25+(i*0.25); + } + // loop 3a + for (int i = 0; i < 11; i++) { + filter[i+9+11+10+10] = 5.+(i*0.5); + } + // loop 3b + for (int i = 0; i < 10; i++) { + filter[i+9+11+10+10+11] = 11.+(i*1.0); + } + // loop 3c + for (int i = 0; i < 10; i++) { + filter[i+9+11+10+10+11+10] = 22.5+(i*2.5); + } + // loop 4a + for (int i = 0; i < 11; i++) { + filter[i+9+11+10+10+11+10+10] = 50.+(i*5.); + } + // loop 4b + for (int i = 0; i < 15; i++) { + filter[i+9+11+10+10+11+10+10+11] = 110.+(i*10.); + } + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + for (int i = 0; i < 10; i++) { + filter[i] = 0.2+(i*0.2); + } + for (int i = 0; i < 8; i++) { + filter[i+10] = 3+(i*1); + } + for (int i = 0; i < 25; i++) { + filter[i+10+8] = 12+(i*2); + } + for (int i = 0; i < 47; i++) { + filter[i+10+8+25] = 80+(i*20); + } + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.025); + } + for (int i = 0; i < 9; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+9+9] = 5.+(i*2.5); + } + } else if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.025); + } + for (int i = 0; i < 9; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 9; i++) { + filter[i+9+9] = 5.+(i*2.5); + } + } + + +TCanvas *A2 = new TCanvas("A2","Plot scan",150,10,800,400); +TCanvas *A3 = new TCanvas("A3","Plot G1 fit",150,10,800,400); +TCanvas *A4 = new TCanvas("A4","Plot G1 residuals",150,10,800,400); +TCanvas *A5 = new TCanvas("A5","Plot G2 fit",150,10,800,400); +TCanvas *A6 = new TCanvas("A6","Plot G2 residuals",150,10,800,400); +TCanvas *A7 = new TCanvas("A7","Plot G0 fit",150,10,800,400); +TCanvas *A8 = new TCanvas("A8","Plot G0 residuals",150,10,800,400); + + + + //file name + sprintf(filename,"%sCS_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 < m_max; j++) { + TH2F* hist0=(TH2F*)f->Get(Form("adcmap_avg_g0_%d",j)); + G0_pixel[j]=hist0->GetBinContent((column+1),(row+1)); + TH2F* hist0er=(TH2F*)f->Get(Form("adcermap_avg_g0_%d",j)); + G0_err_pixel[j]=hist0er->GetBinContent((column+1),(row+1)); + TH2F* hist1=(TH2F*)f->Get(Form("adcmap_avg_g1_%d",j)); + G1_pixel[j]=hist1->GetBinContent((column+1),(row+1)); + TH2F* hist1er=(TH2F*)f->Get(Form("adcermap_avg_g1_%d",j)); + G1_err_pixel[j]=hist1er->GetBinContent((column+1),(row+1)); + TH2F* hist2=(TH2F*)f->Get(Form("adcmap_avg_g2_%d",j)); + G2_pixel[j]=hist2->GetBinContent((column+1),(row+1)); + TH2F* hist2er=(TH2F*)f->Get(Form("adcermap_avg_g2_%d",j)); + G2_err_pixel[j]=hist2er->GetBinContent((column+1),(row+1)); + //cout << "Data for pixel "<< pixel << "is loaded" << endl; + } + + + A2->SetLeftMargin(0.13); + A2->SetRightMargin(0.05); + + vector r0_adc; + vector r0_filter; + + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector r1_ferr; + + vector r2_adc; + vector r2_filter; + vector r2_adcerr; + vector r2_ferr; + + for (int j = 0; j < m_max; j++) { + + if (G0_pixel[j] != 0) { + r0_filter.push_back(filter[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(filter[j]); + r1_ferr.push_back(0.); + r1_adc.push_back(G1_pixel[j]); + r1_adcerr.push_back(G1_err_pixel[j]); + } + if (G2_pixel[j] != 0) { + r2_filter.push_back(filter[j]); + r2_ferr.push_back(0.); + r2_adc.push_back(G2_pixel[j]); + r2_adcerr.push_back(G2_err_pixel[j]); + } + } + cout << "Filter array is created" << endl; + + double rangemin_g0 = 0; + double rangemax_g0 = 0; + double rangemin_g1 = 0; + double rangemax_g1 = 0; + double rangemin_g2 = 0; + double rangemax_g2 = 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); + } + + if (r2_adc.size() > 1) { + grap_g2 = new TGraphErrors(r2_adc.size(),&(r2_filter[0]),&(r2_adc[0]),&(r2_ferr[0]),&(r2_adcerr[0])); + grap_g2->SetMarkerStyle(20); + grap_g2->SetMarkerColor(kRed); + grap_g2->SetLineColor(kRed); + } + + // plot the datapoints + if (r1_adc.size() > 1) { + + if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + grap_g1->GetXaxis()->SetLimits(0.009,5E2); + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + grap_g1->GetXaxis()->SetLimits(0.09,1.1E3); + } else { + grap_g1->GetXaxis()->SetLimits(0.009,1.1E2); + } + + grap_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g1->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g1->GetYaxis()->SetTitleOffset(0.9); + grap_g1->SetMinimum(0); + grap_g1->SetMaximum(16000); + grap_g1->Draw("AP"); + if (r2_adc.size() > 1) { + grap_g2->Draw("P"); + } + if (r0_adc.size() > 1) { + grap_g0->Draw("P"); + } + A2->SetLogx(); + A2->Modified(); + A2->Update(); + + } + + // define fit ranges and fit + if (r0_adc.size() > 1) { + A7->cd(); + + rangemin_g0 = *min_element(r0_filter.begin(),r0_filter.end()); + rangemin_g0 = checkRangeMinForRCEffect(rangemin_g0); + rangemax_g0 = highestPointBeforeSwitching(r0_filter, r1_filter); + + if (rangemax_g0 > rangemin_g0) { + + fit_g0 = new TF1("fit_g0","[0]+[1]*x",rangemin_g0, rangemax_g0); + fit_g0->SetParameter(0, 3000.); + fit_g0->SetParameter(1, 30000.); + fit_g0->SetLineColor(kBlue); + fit_g0->SetParName(0,"G0 const"); + fit_g0->SetParName(1,"G0 grad"); + grap_g0->Fit(fit_g0,"QR+",""); + + grap_g0->SetMinimum(0); + grap_g0->SetMaximum(18000); + grap_g0->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g0->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g0->GetYaxis()->SetTitleOffset(0.9); + grap_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end())); + grap_g0->Draw("AP"); + fit_g0->Draw("same"); + A7->Update(); + if (TPaveStats *st0 = (TPaveStats*)grap_g0->FindObject("stats")) { + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.71); + st0->SetY2NDC(0.90); + st0->SetBorderSize(0); + st0->SetTextColor(kBlue); + A7->SetLogx(); + A7->Modified(); + A7->Update(); + + //A7->cd(); + } + vector 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])); + } + + A8->cd(); + + 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); + + norm_g0->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g0->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g0->GetYaxis()->SetTitleOffset(0.9); + norm_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end())); + norm_g0->SetMinimum(-100); + norm_g0->SetMaximum(100); + norm_g0->Draw("AP"); + flat_g0->Draw("same"); + + A8->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; + + } + } + A3->cd(); + if (r1_adc.size() > 1) { + + rangemin_g1 = lowestPointAfterSwitching(r1_filter, r0_filter); + //cout << rangemin_g1 << endl; + rangemin_g1 = checkRangeMinForRCEffect(rangemin_g1); + rangemax_g1 = highestPointBeforeSwitching(r1_filter, r2_filter); + + //cout << rangemin_g1 << endl; + //cout << rangemax_g1 << endl; + + if (rangemax_g1 > rangemin_g1) { + + fit_g1 = new TF1("fit_g1","[0]+[1]*x",rangemin_g1,rangemax_g1); + fit_g1->SetParameter(0, 10000.); + fit_g1->SetParameter(1, -0.1); + fit_g1->SetLineColor(kGreen+2); + fit_g1->SetParName(0,"G1 const"); + fit_g1->SetParName(1,"G1 grad"); + grap_g1->Fit(fit_g1,"QR",""); + TFitResultPtr r1 = grap_g1->Fit(fit_g1,"S"); + par1 = r1->Parameter(1); + grap_g1->SetMinimum(0); + grap_g1->SetMaximum(16000); + grap_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g1->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g1->GetYaxis()->SetTitleOffset(0.9); + grap_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end())); + grap_g1->Draw("AP"); + fit_g1->Draw("same"); + A3->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g1->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.17); + st0->SetY2NDC(0.36); + st0->SetBorderSize(0); + st0->SetTextColor(kGreen+2); + A3->SetLogx(); + A3->Modified(); + A3->Update(); + + + vector 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])); + } + + A4->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_g1","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_p05pc = new TF1("lin_g1_p05pc","[0]+[1]*x",rangemin_g1,rangemax_g1); + lin_g1_p05pc->SetParameter(0,fit_g1->GetParameter(0)/200.); + lin_g1_p05pc->SetParameter(1,fit_g1->GetParameter(1)/200.); + lin_g1_p05pc->SetLineColor(kOrange+1); + + 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_m05pc = new TF1("lin_g1_m05pc","[0]+[1]*x",rangemin_g1,rangemax_g1); + lin_g1_m05pc->SetParameter(0,fit_g1->GetParameter(0)/-200.); + lin_g1_m05pc->SetParameter(1,fit_g1->GetParameter(1)/-200.); + lin_g1_m05pc->SetLineColor(kOrange+1); + + norm_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g1->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g1->GetYaxis()->SetTitleOffset(0.9); + norm_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end())); + norm_g1->SetMinimum(1.5*lin_g1_m05pc->Eval(rangemin_g1)); + norm_g1->SetMaximum(1.5*lin_g1_p05pc->Eval(rangemin_g1)); + norm_g1->Draw("AP"); + flat_g1->Draw("same"); + lin_g1_p02pc->Draw("same"); + lin_g1_p05pc->Draw("same"); + lin_g1_m02pc->Draw("same"); + lin_g1_m05pc->Draw("same"); + norm_g1->Draw("P"); + A4->Modified(); + A4->Update(); + + } +} + +A5->cd(); + + if (r2_adc.size() > 1) { + + rangemin_g2 = lowestPointAfterSwitching(r2_filter, r1_filter); + rangemin_g2 = checkRangeMinForRCEffect(rangemin_g2); + + rangemax_g2 = *max_element(r2_filter.begin(),r2_filter.end()); + + if (rangemax_g2 > rangemin_g2) { + + fit_g2 = new TF1("fit_g2","[0]+[1]*x",rangemin_g2, rangemax_g2); + fit_g2->SetParameter(0, 10000.); + fit_g2->SetParameter(1, -0.01); + fit_g2->SetLineColor(kRed); + fit_g2->SetParName(0,"G2 const"); + fit_g2->SetParName(1,"G2 grad"); + grap_g2->Fit(fit_g2,"QR+",""); + TFitResultPtr r = grap_g2->Fit(fit_g2,"S"); + par2 = r->Parameter(1); + grap_g2->SetMinimum(0); + grap_g2->SetMaximum(16000); + grap_g2->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g2->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g2->GetYaxis()->SetTitleOffset(0.9); + grap_g2->GetXaxis()->SetLimits(*min_element(r2_filter.begin(),r2_filter.end()),*max_element(r2_filter.begin(),r2_filter.end())); + grap_g2->Draw("AP"); + fit_g2->Draw("same"); + A5->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g2->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.17); + st0->SetY2NDC(0.36); + st0->SetBorderSize(0); + st0->SetTextColor(kRed); + A5->SetLogx(); + A5->Modified(); + A5->Update(); + + vector r2_adc_norm; + for (size_t j = 0; j < r2_adc.size(); j++) { + r2_adc_norm.push_back(r2_adc[j] - fit_g2->Eval(r2_filter[j])); + } + + A6->cd(); + + TGraphErrors *norm_g2 = new TGraphErrors(r2_adc.size(),&(r2_filter[0]),&(r2_adc_norm[0]),&(r2_ferr[0]),&(r2_adcerr[0])); + norm_g2->SetMarkerColor(kRed); + norm_g2->SetLineColor(kRed); + + TF1* flat_g2 = new TF1("flat_g2","0",rangemin_g2, rangemax_g2); + flat_g2->SetLineColor(kRed); + + TF1* lin_g2_p02pc = new TF1("lin_g2_p02pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_p02pc->SetParameter(0,fit_g2->GetParameter(0)/500.); + lin_g2_p02pc->SetParameter(1,fit_g2->GetParameter(1)/500.); + lin_g2_p02pc->SetLineColor(kOrange); + + TF1* lin_g2_p05pc = new TF1("lin_g2_p05pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_p05pc->SetParameter(0,fit_g2->GetParameter(0)/200.); + lin_g2_p05pc->SetParameter(1,fit_g2->GetParameter(1)/200.); + lin_g2_p05pc->SetLineColor(kOrange+1); + + TF1* lin_g2_m02pc = new TF1("lin_g2_m02pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_m02pc->SetParameter(0,fit_g2->GetParameter(0)/-500.); + lin_g2_m02pc->SetParameter(1,fit_g2->GetParameter(1)/-500.); + lin_g2_m02pc->SetLineColor(kOrange); + + TF1* lin_g2_m05pc = new TF1("lin_g2_m05pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_m05pc->SetParameter(0,fit_g2->GetParameter(0)/-200.); + lin_g2_m05pc->SetParameter(1,fit_g2->GetParameter(1)/-200.); + lin_g2_m05pc->SetLineColor(kOrange+1); + + norm_g2->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g2->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g2->GetYaxis()->SetTitleOffset(0.9); + norm_g2->GetXaxis()->SetLimits(*min_element(r2_filter.begin(),r2_filter.end()),*max_element(r2_filter.begin(),r2_filter.end())); + norm_g2->SetMinimum(1.5*lin_g2_m05pc->Eval(rangemin_g2)); + norm_g2->SetMaximum(1.5*lin_g2_p05pc->Eval(rangemin_g2)); + norm_g2->Draw("AP"); + flat_g2->Draw("same"); + lin_g2_p02pc->Draw("same"); + lin_g2_p05pc->Draw("same"); + lin_g2_m02pc->Draw("same"); + lin_g2_m05pc->Draw("same"); + norm_g2->Draw("P"); + A6->Modified(); + A6->Update(); + } + } + // cout << par1/par2 << endl; + rootapp.Run(); + return 0; + +} + diff --git a/CS_fit_M431 b/CS_fit_M431 new file mode 100755 index 0000000..02f9670 Binary files /dev/null and b/CS_fit_M431 differ diff --git a/CS_fit_M431.cpp b/CS_fit_M431.cpp new file mode 100644 index 0000000..53a6670 --- /dev/null +++ b/CS_fit_M431.cpp @@ -0,0 +1,1187 @@ +// 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 "TGraph.h" +#include "TGraphErrors.h" +#include "TF1.h" +#include "TFile.h" +#include "TPaveStats.h" +#include "TLegend.h" +#include "TPaveText.h" +#include "TCanvas.h" +#include "TFitResultPtr.h" +#include "TFitResult.h" + +#include +#include +#include + + +TGraphErrors *grap_g0; +TGraphErrors *grap_g1; +TGraphErrors *grap_g2; + +TF1 *fit_g0=0; +TF1 *fit_g1=0; +TF1 *fit_g2=0; + +TGraphErrors *norm_g0; +TGraphErrors *norm_g1; +TGraphErrors *norm_g2; + +TF1 *flat_g0; +TF1 *flat_g2; + +TF1 *lin_g1_p02pc; +TF1 *lin_g1_p05pc; +TF1 *lin_g1_m02pc; +TF1 *lin_g1_m05pc; + +TF1 *lin_g2_p02pc; +TF1 *lin_g2_p05pc; +TF1 *lin_g2_m02pc; +TF1 *lin_g2_m05pc; + +Double_t par1; +Double_t par2; + +double checkRangeMinForRCEffect(double range_min) { + + // check that the range minimum is at least 2 us, to avoid non-linearity of RC effect + if (range_min < 2.0) { + return 2.0; + } else { + return range_min; + } + +} + + + +bool isHGX=false; +int main(int argc, char* argv[]) { + + //nonblock(NB_ENABLE); + cout <<"opening the rootapp" <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 from 0 to 1023" << endl; + cout << "arg 3: specify pixel y position from 0 to 511" << endl; + exit(1); + } //uncomment for VH 210906 + + string module_str = argv[1]; + + string str2 =("HG0G1G2"); + string str3 =("HGOG1G2"); //filename creator had this bug + + int column = atoi(argv[2]); + int row = atoi(argv[3]); + + 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 <HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" < scan_v1; + scan_v1.push_back("002"); + scan_v1.push_back("003"); + + vector scan_v2; + scan_v2.push_back("032"); + + vector scan_v3; + + vector scan_v4; + scan_v4.push_back("040"); + scan_v4.push_back("044"); + + vector scan_v5; + scan_v5.push_back("006"); + scan_v5.push_back("022"); + scan_v5.push_back("055"); + scan_v5.push_back("065"); + scan_v5.push_back("066"); + scan_v5.push_back("068"); + scan_v5.push_back("069"); + scan_v5.push_back("088"); + scan_v5.push_back("094"); + + vector scan_v6; + scan_v6.push_back("008"); + scan_v6.push_back("011"); + scan_v6.push_back("021"); + scan_v6.push_back("023"); + scan_v6.push_back("025"); + scan_v6.push_back("029"); + scan_v6.push_back("035"); + scan_v6.push_back("039"); + scan_v6.push_back("043"); + scan_v6.push_back("045"); + scan_v6.push_back("046"); + scan_v6.push_back("048"); + scan_v6.push_back("049"); + scan_v6.push_back("050"); + scan_v6.push_back("051"); + scan_v6.push_back("053"); + scan_v6.push_back("054"); + scan_v6.push_back("057"); + scan_v6.push_back("058"); + scan_v6.push_back("059"); + scan_v6.push_back("060"); + scan_v6.push_back("061"); + scan_v6.push_back("062"); + scan_v6.push_back("063"); + scan_v6.push_back("064"); + scan_v6.push_back("067"); + scan_v6.push_back("070"); + scan_v6.push_back("071"); + scan_v6.push_back("072"); + scan_v6.push_back("073"); + scan_v6.push_back("074"); + scan_v6.push_back("075"); + scan_v6.push_back("076"); + scan_v6.push_back("079"); + scan_v6.push_back("080"); + scan_v6.push_back("086"); + scan_v6.push_back("089"); + scan_v6.push_back("090"); + scan_v6.push_back("091"); + scan_v6.push_back("092"); + scan_v6.push_back("093"); + scan_v6.push_back("095"); + scan_v6.push_back("097"); + scan_v6.push_back("098"); + scan_v6.push_back("099"); + scan_v6.push_back("100"); + scan_v6.push_back("102"); + scan_v6.push_back("103"); + scan_v6.push_back("104"); + scan_v6.push_back("106"); + scan_v6.push_back("107"); + scan_v6.push_back("108"); + scan_v6.push_back("109"); + scan_v6.push_back("110"); + scan_v6.push_back("111"); + scan_v6.push_back("112"); + scan_v6.push_back("113"); + scan_v6.push_back("114"); + scan_v6.push_back("115"); + scan_v6.push_back("116"); + scan_v6.push_back("117"); + scan_v6.push_back("118"); + scan_v6.push_back("119"); + scan_v6.push_back("120"); + scan_v6.push_back("121"); + scan_v6.push_back("122"); + scan_v6.push_back("123"); + scan_v6.push_back("124"); + scan_v6.push_back("125"); + scan_v6.push_back("126"); + scan_v6.push_back("129"); + scan_v6.push_back("130"); + scan_v6.push_back("131"); + scan_v6.push_back("132"); + scan_v6.push_back("133"); + scan_v6.push_back("134"); + scan_v6.push_back("135"); + scan_v6.push_back("200"); + scan_v6.push_back("201"); + scan_v6.push_back("202"); + scan_v6.push_back("203"); + scan_v6.push_back("204"); + scan_v6.push_back("205"); + scan_v6.push_back("206"); + scan_v6.push_back("208"); + scan_v6.push_back("209"); + scan_v6.push_back("210"); + scan_v6.push_back("212"); + scan_v6.push_back("214"); + scan_v6.push_back("215"); + scan_v6.push_back("216"); + scan_v6.push_back("217"); + scan_v6.push_back("218"); + scan_v6.push_back("219"); + scan_v6.push_back("221"); + scan_v6.push_back("222"); + scan_v6.push_back("223"); + scan_v6.push_back("224"); + scan_v6.push_back("225"); + scan_v6.push_back("226"); + scan_v6.push_back("227"); + scan_v6.push_back("228"); + scan_v6.push_back("229"); + scan_v6.push_back("232"); + scan_v6.push_back("233"); + scan_v6.push_back("234"); + scan_v6.push_back("235"); + scan_v6.push_back("236"); + scan_v6.push_back("242"); + scan_v6.push_back("244"); + scan_v6.push_back("245"); + scan_v6.push_back("246"); + scan_v6.push_back("248"); + scan_v6.push_back("249"); + scan_v6.push_back("250"); + scan_v6.push_back("251"); + scan_v6.push_back("252"); + scan_v6.push_back("253"); + scan_v6.push_back("254"); + scan_v6.push_back("255"); + scan_v6.push_back("260"); + scan_v6.push_back("261"); + scan_v6.push_back("263"); + scan_v6.push_back("264"); + scan_v6.push_back("265"); + scan_v6.push_back("266"); + scan_v6.push_back("267"); + scan_v6.push_back("269"); + scan_v6.push_back("270"); + scan_v6.push_back("272"); + scan_v6.push_back("273"); + scan_v6.push_back("274"); + scan_v6.push_back("275"); + scan_v6.push_back("276"); + scan_v6.push_back("277"); + scan_v6.push_back("278"); + scan_v6.push_back("279"); + scan_v6.push_back("281"); + scan_v6.push_back("282"); + scan_v6.push_back("283"); + scan_v6.push_back("285"); + scan_v6.push_back("286"); + scan_v6.push_back("287"); + scan_v6.push_back("288"); + scan_v6.push_back("289"); + scan_v6.push_back("290"); + scan_v6.push_back("291"); + scan_v6.push_back("292"); + scan_v6.push_back("294"); + scan_v6.push_back("296"); + scan_v6.push_back("298"); + scan_v6.push_back("299"); + scan_v6.push_back("301"); + scan_v6.push_back("307"); + scan_v6.push_back("312"); + scan_v6.push_back("351"); + scan_v6.push_back("352"); + scan_v6.push_back("354"); + scan_v6.push_back("360"); + scan_v6.push_back("373"); + scan_v6.push_back("380"); + scan_v6.push_back("304"); + scan_v6.push_back("321"); + scan_v6.push_back("346"); + scan_v6.push_back("375"); + scan_v6.push_back("381"); + scan_v6.push_back("383"); + scan_v6.push_back("310"); + scan_v6.push_back("313"); + scan_v6.push_back("314"); + scan_v6.push_back("334"); + scan_v6.push_back("337"); + scan_v6.push_back("347"); + scan_v6.push_back("361"); + scan_v6.push_back("362"); + scan_v6.push_back("355"); + scan_v6.push_back("364"); + scan_v6.push_back("366"); + scan_v6.push_back("243"); + scan_v6.push_back("339"); + scan_v6.push_back("341"); + scan_v6.push_back("368"); + scan_v6.push_back("376"); + scan_v6.push_back("379"); + + scan_v6.push_back("359"); + scan_v6.push_back("363"); + scan_v6.push_back("365"); + scan_v6.push_back("347"); + scan_v6.push_back("366"); + + scan_v6.push_back("268"); + scan_v6.push_back("300"); + scan_v6.push_back("302"); + scan_v6.push_back("303"); + scan_v6.push_back("309"); + scan_v6.push_back("326"); + + scan_v6.push_back("308"); + scan_v6.push_back("322"); + scan_v6.push_back("328"); + scan_v6.push_back("332"); + scan_v6.push_back("335"); + scan_v6.push_back("353"); + scan_v6.push_back("335_FW2_2"); + scan_v6.push_back("353_FW2_2"); + + scan_v6.push_back("262_FWcheck_1_1_1"); + scan_v6.push_back("262_FWcheck_1_1_1_test"); + scan_v6.push_back("262_FWcheck_1_2_rc210831"); + scan_v6.push_back("262_FWcheck_1_2_defdacs"); + + scan_v6.push_back("311"); + scan_v6.push_back("316"); + scan_v6.push_back("318"); + scan_v6.push_back("319"); + scan_v6.push_back("320"); + scan_v6.push_back("324"); + + scan_v6.push_back("272_fullspeedtest"); + scan_v6.push_back("272_halfspeedtest"); + + scan_v6.push_back("352_fullspeed"); //jf4mb2-00 (SLS) + scan_v6.push_back("307_fullspeed"); //jf4mb2-01 (SLS) + scan_v6.push_back("264_fullspeed"); //jf4mb2-02 (SLS) + scan_v6.push_back("253_fullspeed"); //jf4mb2-03 (SLS) + scan_v6.push_back("351_fullspeed"); //jf4mb2-04 (SLS) + scan_v6.push_back("312_fullspeed"); //jf4mb2-05 (SLS) + scan_v6.push_back("261_fullspeed"); //jf4mb2-06 (SLS) + scan_v6.push_back("310_fullspeed"); //jf4mb2-07 (SLS) + + scan_v6.push_back("384"); //jfcalib-5 + scan_v6.push_back("510"); //jfcalib-0 + scan_v6.push_back("511"); //jfcalib-1 + scan_v6.push_back("512"); //jfcalib-2 + scan_v6.push_back("556"); //jfcalib-3 + scan_v6.push_back("572"); //jfcalib-4 + + scan_v6.push_back("329"); //jfcalib-0 + scan_v6.push_back("331"); //jfcalib-1 + scan_v6.push_back("333"); //jfcalib-2 + scan_v6.push_back("336"); //jfcalib-3 + scan_v6.push_back("356"); //jfcalib-4 + scan_v6.push_back("377"); //jfcalib-5 + + scan_v6.push_back("387"); //jfcalib-0 + scan_v6.push_back("388"); //jfcalib-1 + scan_v6.push_back("389"); //jfcalib-2 + scan_v6.push_back("396"); //jfcalib-3 + scan_v6.push_back("397"); //jfcalib-4 + scan_v6.push_back("398"); //jfcalib-5 + + scan_v6.push_back("390"); //jfcalib-0 + scan_v6.push_back("391"); //jfcalib-1 + scan_v6.push_back("393"); //jfcalib-2 + scan_v6.push_back("399"); //jfcalib-3 + scan_v6.push_back("516"); //jfcalib-4 + scan_v6.push_back("517"); //jfcalib-5 + + scan_v6.push_back("519"); //jfcalib-0 + scan_v6.push_back("520"); //jfcalib-1 + scan_v6.push_back("532"); //jfcalib-2 + scan_v6.push_back("539"); //jfcalib-3 + scan_v6.push_back("555"); //jfcalib-4 + + //Calib for VELA beamtime in March 2022 + scan_v6.push_back("262"); //jfcalib-0 + scan_v6.push_back("231"); //jfcalib-1 + scan_v6.push_back("305"); //jfcalib-2 + + scan_v6.push_back("392"); //jfcalib-1 + scan_v6.push_back("394"); //jfcalib-2 + scan_v6.push_back("513"); //jfcalib-3 + scan_v6.push_back("514"); //jfcalib-4 + scan_v6.push_back("515"); //jfcalib-5 + + scan_v6.push_back("239"); //jfcalib-0 //bad + scan_v6.push_back("064"); //jfcalib-1 //bad //already added above + scan_v6.push_back("023"); //jfcalib-2 //bad //already added above + scan_v6.push_back("349"); //jfcalib-3 //bad + scan_v6.push_back("518"); //jfcalib-4 + scan_v6.push_back("521"); //jfcalib-5 + + scan_v6.push_back("523"); //jfcalib-0 + scan_v6.push_back("526"); //jfcalib-1 + scan_v6.push_back("529"); //jfcalib-2 + scan_v6.push_back("530"); //jfcalib-3 + scan_v6.push_back("531"); //jfcalib-4 + scan_v6.push_back("533"); //jfcalib-5 + + scan_v6.push_back("524"); //1M for ESRF + scan_v6.push_back("525"); //1M for ESRF + + scan_v6.push_back("306"); //jfcalib-0 (strixel) + scan_v6.push_back("350"); //jfcalib-1 (strixel) + + scan_v6.push_back("534"); //jfcalib-0 + scan_v6.push_back("537"); //jfcalib-1 + scan_v6.push_back("538"); //jfcalib-2 + scan_v6.push_back("542"); //jfcalib-3 + scan_v6.push_back("543"); //jfcalib-4 + scan_v6.push_back("544"); //jfcalib-5 + + scan_v6.push_back("402"); //jfcalib-0 + scan_v6.push_back("404"); //jfcalib-1 + scan_v6.push_back("407"); //jfcalib-2 + scan_v6.push_back("409"); //jfcalib-3 + scan_v6.push_back("410"); //jfcalib-4 + scan_v6.push_back("411"); //jfcalib-5 + + //scan_v6.push_back("008"); //jfcalib-0 //already in the list from previous calibration + scan_v6.push_back("433"); //jfcalib-1 + scan_v6.push_back("550"); //jfcalib-2 + scan_v6.push_back("545"); //jfcalib-3 + scan_v6.push_back("546"); //jfcalib-4 + scan_v6.push_back("547"); //jfcalib-5 + + //scan_v6.push_back("416"); //jfcalib-0 //destroyed, machanical sample + scan_v6.push_back("417"); //jfcalib-1 + scan_v6.push_back("418"); //jfcalib-2 + scan_v6.push_back("420"); //jfcalib-3 + scan_v6.push_back("421"); //jfcalib-4 + scan_v6.push_back("430"); //jfcalib-5 + + scan_v6.push_back("417_fullspeed"); //jfcalib-1 + scan_v6.push_back("418_fullspeed"); //jfcalib-2 + scan_v6.push_back("420_fullspeed"); //jfcalib-3 + scan_v6.push_back("421_fullspeed"); //jfcalib-4 + scan_v6.push_back("430_fullspeed"); //jfcalib-5 + + scan_v6.push_back("434"); //jfcalib-0 + scan_v6.push_back("437"); //jfcalib-1 + scan_v6.push_back("480"); //jfcalib-2 + scan_v6.push_back("464"); //jfcalib-3 + scan_v6.push_back("473"); //jfcalib-4 + scan_v6.push_back("474"); //jfcalib-5 + + scan_v6.push_back("076"); //jfcalib-0 + scan_v6.push_back("089"); //jfcalib-3 + scan_v6.push_back("207"); //jfcalib-5 + + scan_v6.push_back("244"); //jfcalib-3 + + scan_v6.push_back("474_fullspeed"); //jfcalib-0 + scan_v6.push_back("437_fullspeed"); //jfcalib-1 + scan_v6.push_back("480_fullspeed"); //jfcalib-2 + scan_v6.push_back("482_fullspeed"); //jfcalib-3 + scan_v6.push_back("487_fullspeed"); //jfcalib-5 + + scan_v6.push_back("482"); //jfcalib-3 + scan_v6.push_back("487"); //jfcalib-5 + + scan_v6.push_back("499_fullspeed"); //jfcalib-0 + scan_v6.push_back("548_fullspeed"); //jfcalib-1 + scan_v6.push_back("549_fullspeed"); //jfcalib-2 + scan_v6.push_back("427_fullspeed"); //jfcalib-3 + + scan_v6.push_back("499"); //jfcalib-0 + scan_v6.push_back("548"); //jfcalib-1 + scan_v6.push_back("549"); //jfcalib-2 + scan_v6.push_back("427"); //jfcalib-3 + scan_v6.push_back("435"); //jfcalib-5 + + scan_v6.push_back("403"); //jfcalib-0 + scan_v6.push_back("406"); //jfcalib-1 + scan_v6.push_back("423"); //jfcalib-2 + scan_v6.push_back("436"); //jfcalib-3 + scan_v6.push_back("479"); //jfcalib-5 + + // Calibration 450 um sensor for ESRF + + scan_v6.push_back("583"); //jfcalib-0 + scan_v6.push_back("593"); //jfcalib-1 + scan_v6.push_back("601"); //jfcalib-2 + scan_v6.push_back("604"); //jfcalib-3 + scan_v6.push_back("605"); //jfcalib-5 + + // Calibration 320 um sensors + + scan_v6.push_back("441"); //jfcalib-0 + scan_v6.push_back("460"); //jfcalib-1 + scan_v6.push_back("463"); //jfcalib-2 + scan_v6.push_back("476"); //jfcalib-3 + scan_v6.push_back("371"); //jfcalib-4 + + scan_v6.push_back("429"); //jfcalib-0 + scan_v6.push_back("442"); //jfcalib-1 + scan_v6.push_back("444"); //jfcalib-2 + scan_v6.push_back("446"); //jfcalib-3 + scan_v6.push_back("447"); //jfcalib-4 + + scan_v6.push_back("428"); //jfcalib-0 + scan_v6.push_back("439"); //jfcalib-1 + scan_v6.push_back("443"); //jfcalib-2 + scan_v6.push_back("445"); //jfcalib-3 + + scan_v6.push_back("448"); //jfcalib-0 + scan_v6.push_back("454"); //jfcalib-1 + scan_v6.push_back("455"); //jfcalib-2 + scan_v6.push_back("456"); //jfcalib-3 + scan_v6.push_back("466"); //jfcalib-4 + scan_v6.push_back("471"); //jfcalib-5 + + scan_v6.push_back("481"); //jfcalib-0 + scan_v6.push_back("488"); //jfcalib-1 + scan_v6.push_back("490"); //jfcalib-2 + scan_v6.push_back("491"); //jfcalib-3 + scan_v6.push_back("492"); //jfcalib-4 + scan_v6.push_back("493"); //jfcalib-5 + + scan_v6.push_back("494"); //jfcalib-0 + scan_v6.push_back("495"); //jfcalib-1 + scan_v6.push_back("497"); //jfcalib-2 + scan_v6.push_back("498"); //jfcalib-3 + scan_v6.push_back("501"); //jfcalib-4 + scan_v6.push_back("502"); //jfcalib-5 + + scan_v6.push_back("036"); //jfcalib-0 + scan_v6.push_back("560"); //jfcalib-1 + scan_v6.push_back("536"); //jfcalib-2 + scan_v6.push_back("535"); //jfcalib-3 + scan_v6.push_back("527"); //jfcalib-4 + scan_v6.push_back("522"); //jfcalib-5 + + scan_v6.push_back("571"); //jfcalib-0 + scan_v6.push_back("571_fullspeed"); //jfcalib-0 + scan_v6.push_back("573"); //jfcalib-1 + scan_v6.push_back("573_fullspeed"); //jfcalib-1 + scan_v6.push_back("574"); //jfcalib-2 + scan_v6.push_back("574_fullspeed"); //jfcalib-2 + scan_v6.push_back("575"); //jfcalib-3 + scan_v6.push_back("575_fullspeed"); //jfcalib-3 + scan_v6.push_back("576"); //jfcalib-4 + scan_v6.push_back("576_fullspeed"); //jfcalib-4 + scan_v6.push_back("577"); //jfcalib-5 + scan_v6.push_back("577_fullspeed"); //jfcalib-5 + + scan_v6.push_back("563"); //jfcalib-0 + scan_v6.push_back("563_fullspeed"); //jfcalib-0 + scan_v6.push_back("564"); //jfcalib-1 + scan_v6.push_back("564_fullspeed"); //jfcalib-1 + scan_v6.push_back("566"); //jfcalib-2 + scan_v6.push_back("566_fullspeed"); //jfcalib-2 + scan_v6.push_back("567"); //jfcalib-3 + scan_v6.push_back("567_fullspeed"); //jfcalib-3 + scan_v6.push_back("568"); //jfcalib-4 + scan_v6.push_back("568_fullspeed"); //jfcalib-4 + scan_v6.push_back("569"); //jfcalib-5 + scan_v6.push_back("569_fullspeed"); //jfcalib-5 + + scan_v6.push_back("579"); //QUAD thin + scan_v6.push_back("579_fullspeed"); //QUAD thin + + scan_v6.push_back("454_fullspeed"); //jfcalib-0 + scan_v6.push_back("466_fullspeed"); //jfcalib-1 + scan_v6.push_back("536_fullspeed"); //jfcalib-2 + scan_v6.push_back("561"); //jfcalib-4 + scan_v6.push_back("561_fullspeed"); //jfcalib-3 + scan_v6.push_back("562"); //jfcalib-4 + scan_v6.push_back("562_fullspeed"); //jfcalib-4 + scan_v6.push_back("038"); //jfcalib-5 + scan_v6.push_back("038_fullspeed"); //jfcalib-5 + + scan_v6.push_back("431_JF12"); + + + scan_v6.push_back("428_fullspeed"); //jfcalib-0 + scan_v6.push_back("443_fullspeed"); //jfcalib-1 + scan_v6.push_back("444_fullspeed"); //jfcalib-2 + scan_v6.push_back("455_fullspeed"); //jfcalib-3 + scan_v6.push_back("471_fullspeed"); //jfcalib-4 + scan_v6.push_back("493_fullspeed"); //jfcalib-5 + + scan_v6.push_back("448_fullspeed"); //jfcalib-0 + scan_v6.push_back("497_fullspeed"); //jfcalib-1 + scan_v6.push_back("498_fullspeed"); //jfcalib-2 + scan_v6.push_back("501_fullspeed"); //jfcalib-3 + scan_v6.push_back("502_fullspeed"); //jfcalib-4 + scan_v6.push_back("527_fullspeed"); //jfcalib-5 + + scan_v6.push_back("580_fullspeed"); //jfcalib-5 + scan_v6.push_back("580"); //jfcalib-5 + + + + // filter out points at zero and points with 0 error (mean taken from one entry in hist) + int m_max = 0; + if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + m_max = 27; + } else if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + m_max = 31; + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + m_max = 35; + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + m_max = 51; + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + m_max = 97; + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + m_max = 90; + } + + std::vector G0_pixel(97, 0); + std::vector G0_err_pixel(97, 0); + std::vector G1_pixel(97, 0); + std::vector G1_err_pixel(97, 0); + std::vector G2_pixel(97, 0); + std::vector G2_err_pixel(97, 0); + + + char filename[256]; //uncomment for VH 210902 + + +double filter[97]; + if (find(scan_v4.begin(), scan_v4.end(), module_str) != scan_v4.end()) { + for (int i = 0; i < 5; i++) { + filter[i] = 0.05+(i*0.05); + } + for (int i = 0; i < 9; i++) { + filter[i+5] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+5+9] = 5.+(i*2.5); + } + } else if (find(scan_v5.begin(), scan_v5.end(), module_str) != scan_v5.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.05); + } + for (int i = 0; i < 17; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+9+17] = 5.+(i*2.5); + } + for (int i = 0; i < 8; i++) { + filter[i+9+17+17] = 50.+(i*10.); + } + } else if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + // loop 1 + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.05); + } + // loop 2a + for (int i = 0; i < 11; i++) { + filter[i+9] = 0.5+(i*0.05); + } + // loop 2b + for (int i = 0; i < 10; i++) { + filter[i+9+11] = 1.10+(i*0.10); + } + // loop 2c + for (int i = 0; i < 10; i++) { + filter[i+9+11+10] = 2.25+(i*0.25); + } + // loop 3a + for (int i = 0; i < 11; i++) { + filter[i+9+11+10+10] = 5.+(i*0.5); + } + // loop 3b + for (int i = 0; i < 10; i++) { + filter[i+9+11+10+10+11] = 11.+(i*1.0); + } + // loop 3c + for (int i = 0; i < 10; i++) { + filter[i+9+11+10+10+11+10] = 22.5+(i*2.5); + } + // loop 4a + for (int i = 0; i < 11; i++) { + filter[i+9+11+10+10+11+10+10] = 50.+(i*5.); + } + // loop 4b + for (int i = 0; i < 15; i++) { + filter[i+9+11+10+10+11+10+10+11] = 110.+(i*10.); + } + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + for (int i = 0; i < 10; i++) { + filter[i] = 0.2+(i*0.2); + } + for (int i = 0; i < 8; i++) { + filter[i+10] = 3+(i*1); + } + for (int i = 0; i < 25; i++) { + filter[i+10+8] = 12+(i*2); + } + for (int i = 0; i < 47; i++) { + filter[i+10+8+25] = 80+(i*20); + } + } else if (find(scan_v3.begin(), scan_v3.end(), module_str) != scan_v3.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.025); + } + for (int i = 0; i < 9; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 17; i++) { + filter[i+9+9] = 5.+(i*2.5); + } + } else if (find(scan_v2.begin(), scan_v2.end(), module_str) != scan_v2.end()) { + for (int i = 0; i < 9; i++) { + filter[i] = 0.05+(i*0.025); + } + for (int i = 0; i < 9; i++) { + filter[i+9] = 0.5+(i*0.25); + } + for (int i = 0; i < 9; i++) { + filter[i+9+9] = 5.+(i*2.5); + } + } + + +TCanvas *A2 = new TCanvas("A2","Plot scan",150,10,800,400); +TCanvas *A3 = new TCanvas("A3","Plot G1 fit",150,10,800,400); +TCanvas *A4 = new TCanvas("A4","Plot G1 residuals",150,10,800,400); +TCanvas *A5 = new TCanvas("A5","Plot G2 fit",150,10,800,400); +TCanvas *A6 = new TCanvas("A6","Plot G2 residuals",150,10,800,400); +TCanvas *A7 = new TCanvas("A7","Plot G0 fit",150,10,800,400); +TCanvas *A8 = new TCanvas("A8","Plot G0 residuals",150,10,800,400); +TCanvas *A9 = new TCanvas("A9","Plot G1 linearity",150,10,800,400); + + + + //file name + sprintf(filename,"%sCS_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 < m_max; j++) { + TH2F* hist0=(TH2F*)f->Get(Form("adcmap_avg_g0_%d",j)); + G0_pixel[j]=hist0->GetBinContent((column+1),(row+1)); + TH2F* hist0er=(TH2F*)f->Get(Form("adcermap_avg_g0_%d",j)); + G0_err_pixel[j]=hist0er->GetBinContent((column+1),(row+1)); + TH2F* hist1=(TH2F*)f->Get(Form("adcmap_avg_g1_%d",j)); + G1_pixel[j]=hist1->GetBinContent((column+1),(row+1)); + TH2F* hist1er=(TH2F*)f->Get(Form("adcermap_avg_g1_%d",j)); + G1_err_pixel[j]=hist1er->GetBinContent((column+1),(row+1)); + TH2F* hist2=(TH2F*)f->Get(Form("adcmap_avg_g2_%d",j)); + G2_pixel[j]=hist2->GetBinContent((column+1),(row+1)); + TH2F* hist2er=(TH2F*)f->Get(Form("adcermap_avg_g2_%d",j)); + G2_err_pixel[j]=hist2er->GetBinContent((column+1),(row+1)); + //cout << "Data for pixel "<< pixel << "is loaded" << endl; + } + + + A2->SetLeftMargin(0.13); + A2->SetRightMargin(0.05); + + vector r0_adc; + vector r0_filter; + + vector r0_adcerr; + vector r0_ferr; + + vector r1_adc; + vector r1_filter; + vector r1_adcerr; + vector r1_ferr; + + vector r2_adc; + vector r2_filter; + vector r2_adcerr; + vector r2_ferr; + + for (int j = 0; j < m_max; j++) { + + if (G0_pixel[j] != 0) { + r0_filter.push_back(filter[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(filter[j]); + r1_ferr.push_back(0.); + r1_adc.push_back(G1_pixel[j]); + r1_adcerr.push_back(G1_err_pixel[j]); + } + if (G2_pixel[j] != 0) { + r2_filter.push_back(filter[j]); + r2_ferr.push_back(0.); + r2_adc.push_back(G2_pixel[j]); + r2_adcerr.push_back(G2_err_pixel[j]); + } + } + cout << "Filter array is created" << endl; + + double rangemin_g0 = 0; + double rangemax_g0 = 0; + double rangemin_g1 = 0; + double rangemax_g1 = 0; + double rangemin_g2 = 0; + double rangemax_g2 = 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); + } + + if (r2_adc.size() > 1) { + grap_g2 = new TGraphErrors(r2_adc.size(),&(r2_filter[0]),&(r2_adc[0]),&(r2_ferr[0]),&(r2_adcerr[0])); + grap_g2->SetMarkerStyle(20); + grap_g2->SetMarkerColor(kRed); + grap_g2->SetLineColor(kRed); + } + + // plot the datapoints + if (r1_adc.size() > 1) { + + if (find(scan_v6.begin(), scan_v6.end(), module_str) != scan_v6.end()) { + grap_g1->GetXaxis()->SetLimits(0.009,5E2); + } else if (find(scan_v1.begin(), scan_v1.end(), module_str) != scan_v1.end()) { + grap_g1->GetXaxis()->SetLimits(0.09,1.1E3); + } else { + grap_g1->GetXaxis()->SetLimits(0.009,1.1E2); + } + + grap_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g1->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g1->GetYaxis()->SetTitleOffset(0.9); + grap_g1->SetMinimum(0); + grap_g1->SetMaximum(16000); + grap_g1->Draw("AP"); + if (r2_adc.size() > 1) { + grap_g2->Draw("P"); + } + if (r0_adc.size() > 1) { + grap_g0->Draw("P"); + } + A2->SetLogx(); + A2->Modified(); + A2->Update(); + + } + + // define fit ranges and fit + if (r0_adc.size() > 1) { + A7->cd(); + + rangemin_g0 = *min_element(r0_filter.begin(),r0_filter.end()); + rangemin_g0 = checkRangeMinForRCEffect(rangemin_g0); + rangemax_g0 = highestPointBeforeSwitching(r0_filter, r1_filter); + + if (rangemax_g0 > rangemin_g0) { + + fit_g0 = new TF1("fit_g0","[0]+[1]*x",rangemin_g0, rangemax_g0); + fit_g0->SetParameter(0, 3000.); + fit_g0->SetParameter(1, 30000.); + fit_g0->SetLineColor(kBlue); + fit_g0->SetParName(0,"G0 const"); + fit_g0->SetParName(1,"G0 grad"); + grap_g0->Fit(fit_g0,"QR+",""); + + grap_g0->SetMinimum(0); + grap_g0->SetMaximum(18000); + grap_g0->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g0->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g0->GetYaxis()->SetTitleOffset(0.9); + grap_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end())); + grap_g0->Draw("AP"); + fit_g0->Draw("same"); + A7->Update(); + if (TPaveStats *st0 = (TPaveStats*)grap_g0->FindObject("stats")) { + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.71); + st0->SetY2NDC(0.90); + st0->SetBorderSize(0); + st0->SetTextColor(kBlue); + A7->SetLogx(); + A7->Modified(); + A7->Update(); + + //A7->cd(); + } + vector 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])); + } + + A8->cd(); + + 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); + + norm_g0->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g0->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g0->GetYaxis()->SetTitleOffset(0.9); + norm_g0->GetXaxis()->SetLimits(*min_element(r0_filter.begin(),r0_filter.end()),*max_element(r0_filter.begin(),r0_filter.end())); + norm_g0->SetMinimum(-100); + norm_g0->SetMaximum(100); + norm_g0->Draw("AP"); + flat_g0->Draw("same"); + + A8->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; + + } + } + A3->cd(); + if (r1_adc.size() > 1) { + + rangemin_g1 = lowestPointAfterSwitching(r1_filter, r0_filter); + //cout << rangemin_g1 << endl; + rangemin_g1 = checkRangeMinForRCEffect(rangemin_g1); + rangemax_g1 = highestPointBeforeSwitching(r1_filter, r2_filter); + + //cout << rangemin_g1 << endl; + //cout << rangemax_g1 << endl; + + if (rangemax_g1 > rangemin_g1) { + + fit_g1 = new TF1("fit_g1","[0]+[1]*x",rangemin_g1,rangemax_g1); + fit_g1->SetParameter(0, 10000.); + fit_g1->SetParameter(1, -0.1); + fit_g1->SetLineColor(kGreen+2); + fit_g1->SetParName(0,"G1 const"); + fit_g1->SetParName(1,"G1 grad"); + grap_g1->Fit(fit_g1,"QR",""); + TFitResultPtr r1 = grap_g1->Fit(fit_g1,"S"); + par1 = r1->Parameter(1); + grap_g1->SetMinimum(0); + grap_g1->SetMaximum(16000); + grap_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g1->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g1->GetYaxis()->SetTitleOffset(0.9); + grap_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end())); + grap_g1->Draw("AP"); + fit_g1->Draw("same"); + A3->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g1->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.17); + st0->SetY2NDC(0.36); + st0->SetBorderSize(0); + st0->SetTextColor(kGreen+2); + A3->SetLogx(); + A3->Modified(); + A3->Update(); + + + vector 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])); + } + + A4->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_g1","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_p05pc = new TF1("lin_g1_p05pc","[0]+[1]*x",rangemin_g1,rangemax_g1); + lin_g1_p05pc->SetParameter(0,fit_g1->GetParameter(0)/200.); + lin_g1_p05pc->SetParameter(1,fit_g1->GetParameter(1)/200.); + lin_g1_p05pc->SetLineColor(kOrange+1); + + 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_m05pc = new TF1("lin_g1_m05pc","[0]+[1]*x",rangemin_g1,rangemax_g1); + lin_g1_m05pc->SetParameter(0,fit_g1->GetParameter(0)/-200.); + lin_g1_m05pc->SetParameter(1,fit_g1->GetParameter(1)/-200.); + lin_g1_m05pc->SetLineColor(kOrange+1); + + norm_g1->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g1->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g1->GetYaxis()->SetTitleOffset(0.9); + norm_g1->GetXaxis()->SetLimits(*min_element(r1_filter.begin(),r1_filter.end()),*max_element(r1_filter.begin(),r1_filter.end())); + norm_g1->SetMinimum(1.5*lin_g1_m05pc->Eval(rangemin_g1)); + norm_g1->SetMaximum(1.5*lin_g1_p05pc->Eval(rangemin_g1)); + norm_g1->Draw("AP"); + flat_g1->Draw("same"); + lin_g1_p02pc->Draw("same"); + lin_g1_p05pc->Draw("same"); + lin_g1_m02pc->Draw("same"); + lin_g1_m05pc->Draw("same"); + norm_g1->Draw("P"); + A4->Modified(); + A4->Update(); + + } +} + if(fit_g1){ + A9->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"); + A9->Update(); + } + +A5->cd(); + + if (r2_adc.size() > 1) { + + rangemin_g2 = lowestPointAfterSwitching(r2_filter, r1_filter); + rangemin_g2 = checkRangeMinForRCEffect(rangemin_g2); + + rangemax_g2 = *max_element(r2_filter.begin(),r2_filter.end()); + + if (rangemax_g2 > rangemin_g2) { + + fit_g2 = new TF1("fit_g2","[0]+[1]*x",rangemin_g2, rangemax_g2); + fit_g2->SetParameter(0, 10000.); + fit_g2->SetParameter(1, -0.01); + fit_g2->SetLineColor(kRed); + fit_g2->SetParName(0,"G2 const"); + fit_g2->SetParName(1,"G2 grad"); + grap_g2->Fit(fit_g2,"QR+",""); + TFitResultPtr r = grap_g2->Fit(fit_g2,"S"); + par2 = r->Parameter(1); + grap_g2->SetMinimum(0); + grap_g2->SetMaximum(16000); + grap_g2->GetXaxis()->SetTitle("Integration time [#mus]"); + grap_g2->GetYaxis()->SetTitle("ADC [ADU]"); + grap_g2->GetYaxis()->SetTitleOffset(0.9); + grap_g2->GetXaxis()->SetLimits(*min_element(r2_filter.begin(),r2_filter.end()),*max_element(r2_filter.begin(),r2_filter.end())); + grap_g2->Draw("AP"); + fit_g2->Draw("same"); + A5->Update(); + TPaveStats *st0 = (TPaveStats*)grap_g2->FindObject("stats"); + st0->SetX1NDC(0.2); + st0->SetX2NDC(0.54); + st0->SetY1NDC(0.17); + st0->SetY2NDC(0.36); + st0->SetBorderSize(0); + st0->SetTextColor(kRed); + A5->SetLogx(); + A5->Modified(); + A5->Update(); + + vector r2_adc_norm; + for (size_t j = 0; j < r2_adc.size(); j++) { + r2_adc_norm.push_back(r2_adc[j] - fit_g2->Eval(r2_filter[j])); + } + + A6->cd(); + + TGraphErrors *norm_g2 = new TGraphErrors(r2_adc.size(),&(r2_filter[0]),&(r2_adc_norm[0]),&(r2_ferr[0]),&(r2_adcerr[0])); + norm_g2->SetMarkerColor(kRed); + norm_g2->SetLineColor(kRed); + + TF1* flat_g2 = new TF1("flat_g2","0",rangemin_g2, rangemax_g2); + flat_g2->SetLineColor(kRed); + + TF1* lin_g2_p02pc = new TF1("lin_g2_p02pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_p02pc->SetParameter(0,fit_g2->GetParameter(0)/500.); + lin_g2_p02pc->SetParameter(1,fit_g2->GetParameter(1)/500.); + lin_g2_p02pc->SetLineColor(kOrange); + + TF1* lin_g2_p05pc = new TF1("lin_g2_p05pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_p05pc->SetParameter(0,fit_g2->GetParameter(0)/200.); + lin_g2_p05pc->SetParameter(1,fit_g2->GetParameter(1)/200.); + lin_g2_p05pc->SetLineColor(kOrange+1); + + TF1* lin_g2_m02pc = new TF1("lin_g2_m02pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_m02pc->SetParameter(0,fit_g2->GetParameter(0)/-500.); + lin_g2_m02pc->SetParameter(1,fit_g2->GetParameter(1)/-500.); + lin_g2_m02pc->SetLineColor(kOrange); + + TF1* lin_g2_m05pc = new TF1("lin_g2_m05pc","[0]+[1]*x",rangemin_g2,rangemax_g2); + lin_g2_m05pc->SetParameter(0,fit_g2->GetParameter(0)/-200.); + lin_g2_m05pc->SetParameter(1,fit_g2->GetParameter(1)/-200.); + lin_g2_m05pc->SetLineColor(kOrange+1); + + norm_g2->GetXaxis()->SetTitle("Integration time [#mus]"); + norm_g2->GetYaxis()->SetTitle("Normalised ADC [ADU]"); + norm_g2->GetYaxis()->SetTitleOffset(0.9); + norm_g2->GetXaxis()->SetLimits(*min_element(r2_filter.begin(),r2_filter.end()),*max_element(r2_filter.begin(),r2_filter.end())); + norm_g2->SetMinimum(1.5*lin_g2_m05pc->Eval(rangemin_g2)); + norm_g2->SetMaximum(1.5*lin_g2_p05pc->Eval(rangemin_g2)); + norm_g2->Draw("AP"); + flat_g2->Draw("same"); + lin_g2_p02pc->Draw("same"); + lin_g2_p05pc->Draw("same"); + lin_g2_m02pc->Draw("same"); + lin_g2_m05pc->Draw("same"); + norm_g2->Draw("P"); + A6->Modified(); + A6->Update(); + } + } + // cout << par1/par2 << endl; + rootapp.Run(); + return 0; + +} + diff --git a/CS_scan_both_speeds.sh b/CS_scan_both_speeds.sh new file mode 100644 index 0000000..e26c9d7 --- /dev/null +++ b/CS_scan_both_speeds.sh @@ -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 diff --git a/CuFluo_exposure_both_speeds.sh b/CuFluo_exposure_both_speeds.sh new file mode 100644 index 0000000..7a58a34 --- /dev/null +++ b/CuFluo_exposure_both_speeds.sh @@ -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 diff --git a/CuFluo_fit.cpp b/CuFluo_fit.cpp new file mode 100755 index 0000000..945d484 --- /dev/null +++ b/CuFluo_fit.cpp @@ -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 +//#include + +//#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" <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 <HG1->HG2 sequence - dynamicHG0" <G1->G2 sequence - dynamicG0" <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(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(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; + +} + diff --git a/Default_pixels_arrays.cpp b/Default_pixels_arrays.cpp new file mode 100644 index 0000000..e6f7c7a --- /dev/null +++ b/Default_pixels_arrays.cpp @@ -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 +#include + +#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 this_g0_default_pixels(NCH,0); + std::vector this_g1_default_pixels(NCH,0); + std::vector this_g2_default_pixels(NCH,0); + std::vector 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; iGetBinContent((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(&this_hg0_default_pixels[i]), sizeof(short)); + // g0_default_pixels.push_back(this_g0_default_pixels[i]); + outfile_g0.write(reinterpret_cast(&this_g0_default_pixels[i]), sizeof(short)); + // g1_default_pixels.push_back(this_g1_default_pixels[i]); + outfile_g1.write(reinterpret_cast(&this_g1_default_pixels[i]), sizeof(short)); + // g2_default_pixels.push_back(this_g2_default_pixels[i]); + outfile_g2.write(reinterpret_cast(&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; + } + +} +