From eab04d984bc8ea894928ecc446517b2ba75255bf Mon Sep 17 00:00:00 2001 From: redford_s Date: Wed, 23 Jan 2019 09:16:27 +0100 Subject: [PATCH] To analyse the number of bad pixels per calibrated module. --- .gitignore | 1 + JFMC_BadPixels.cpp | 443 +++++++++++++++++++++++++++++++++++++++++++++ makefile | 2 + 3 files changed, 446 insertions(+) create mode 100644 JFMC_BadPixels.cpp diff --git a/.gitignore b/.gitignore index e2205cd..516178b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ CuFluo_Ka_KaKb_Comp JFMC_ModuleComp BP_analysis JFMC_CalibWriter_wBP +JFMC_BadPixels data/ plots/ diff --git a/JFMC_BadPixels.cpp b/JFMC_BadPixels.cpp new file mode 100644 index 0000000..5c67649 --- /dev/null +++ b/JFMC_BadPixels.cpp @@ -0,0 +1,443 @@ +// to count missing and crazy calibration constants for all modules and compare + +#include "../sls_detector_calibration/jungfrauCommonHeader.h" +#include "../sls_detector_calibration/jungfrauCommonFunctions.h" + +#include "TCanvas.h" +#include "TFile.h" +#include "TH2F.h" +#include "TGraph.h" +#include "TF1.h" + +int main(int argc, char* argv[]) { + + jungfrauStyle(); + + vector modules; + modules.push_back(6); + modules.push_back(8); + modules.push_back(11); + modules.push_back(21); + modules.push_back(22); + modules.push_back(27); + modules.push_back(28); + modules.push_back(32); + modules.push_back(35); + modules.push_back(39); + modules.push_back(40); + modules.push_back(43); + modules.push_back(44); + modules.push_back(45); + modules.push_back(46); + modules.push_back(48); + modules.push_back(49); + modules.push_back(50); + modules.push_back(51); + modules.push_back(53); + modules.push_back(54); + modules.push_back(55); + modules.push_back(57); + modules.push_back(58); + modules.push_back(59); + modules.push_back(60); + modules.push_back(61); + modules.push_back(62); + modules.push_back(63); + modules.push_back(64); + modules.push_back(65); + modules.push_back(66); + modules.push_back(67); + modules.push_back(68); + modules.push_back(69); + modules.push_back(70); + modules.push_back(71); + modules.push_back(72); + modules.push_back(73); + modules.push_back(74); + modules.push_back(75); + modules.push_back(76); + modules.push_back(79); + modules.push_back(80); + modules.push_back(86); + modules.push_back(88); + modules.push_back(89); + modules.push_back(90); + modules.push_back(91); + modules.push_back(92); + modules.push_back(93); + modules.push_back(94); + modules.push_back(95); + modules.push_back(97); + modules.push_back(98); + modules.push_back(99); + modules.push_back(100); + modules.push_back(102); + modules.push_back(103); + modules.push_back(104); + modules.push_back(106); + modules.push_back(107); + modules.push_back(108); + modules.push_back(109); + modules.push_back(110); + modules.push_back(111); + modules.push_back(112); + modules.push_back(113); + modules.push_back(114); + modules.push_back(115); + modules.push_back(116); + modules.push_back(117); + modules.push_back(118); + modules.push_back(119); + modules.push_back(120); + modules.push_back(121); + modules.push_back(122); + modules.push_back(123); + modules.push_back(124); + modules.push_back(125); + modules.push_back(126); + modules.push_back(129); + modules.push_back(130); + modules.push_back(131); + modules.push_back(132); + modules.push_back(133); + modules.push_back(134); + modules.push_back(135); + modules.push_back(200); + modules.push_back(201); + modules.push_back(202); + modules.push_back(203); + modules.push_back(204); + modules.push_back(205); + modules.push_back(206); + modules.push_back(208); + modules.push_back(209); + modules.push_back(210); + modules.push_back(212); + modules.push_back(214); + modules.push_back(215); + modules.push_back(216); + modules.push_back(217); + modules.push_back(218); + modules.push_back(219); + modules.push_back(221); + modules.push_back(222); + modules.push_back(223); + modules.push_back(224); + modules.push_back(226); + modules.push_back(227); + modules.push_back(229); + modules.push_back(231); + modules.push_back(232); + modules.push_back(233); + modules.push_back(234); + modules.push_back(235); + modules.push_back(236); + + vector modules_d; + vector hg0_missing; + vector hg0_crazy; + vector g0_missing; + vector g0_crazy; + vector g1_missing; + vector g1_crazy; + vector g2_missing; + vector g2_crazy; + vector anygain_missing_or_crazy; + + char savename[128]; + + for (size_t j = 0; j < modules.size(); j++) { + + int this_hg0_missing = 0; + int this_hg0_crazy = 0; + int this_g0_missing = 0; + int this_g0_crazy = 0; + int this_g1_missing = 0; + int this_g1_crazy = 0; + int this_g2_missing = 0; + int this_g2_crazy = 0; + int this_anygain_missing_or_crazy = 0; + + // CuFluo HG0 dataset + sprintf(savename,"data/M%3.3d/CuFluo_gain_HG0_M%3.3d.root", modules[j], modules[j]); + 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"); + } + + // CuFluo G0 dataset + sprintf(savename,"data/M%3.3d/CuFluo_gain_G0_M%3.3d.root", modules[j], modules[j]); + 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%3.3d/BP_ratio_M%3.3d.root", modules[j], modules[j]); + 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%3.3d/DB_ratio_M%3.3d.root", modules[j], modules[j]); + 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%3.3d/CS_ratio_M%3.3d.root", modules[j], modules[j]); + 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"); + } + + for (int i = 0; i < NCH; i++) { + + double this_hg0 = 0; + double this_g0 = 0; + double this_g0overg1 = 0; + double this_g1 = 0; + double this_g1overg2 = 0; + double this_g2 = 0; + bool this_flag = false; + + // HG0 + if (FL_HG0_gain_map) { + this_hg0 = FL_HG0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1); + if (this_hg0 == 0) { + this_hg0_missing++; + this_flag = true; + } else if (this_hg0 < 80 || this_hg0 > 120) { + this_hg0_crazy++; + this_flag = true; + } + } else { + this_hg0_missing++; + this_flag = true; + } + + // G0 + if (FL_G0_gain_map) { + this_g0 = FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1); + if (this_g0 == 0) { + this_g0_missing++; + this_flag = true; + } else if (this_g0 < 30 || this_g0 > 48) { + this_g0_crazy++; + this_flag = true; + } + } else { + this_g0_missing++; + this_flag = true; + } + + // G1 + if (DB_ratio_map) { + this_g0overg1 = DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1); + this_g1 = this_g0 / this_g0overg1; + if (this_g0overg1 == 0) { + this_g1_missing++; + this_flag = true; + } else if (this_g0 != 0 && (this_g1 < -2.0 || this_g1 > -0.5)) { + this_g1_crazy++; + this_flag = true; + } + } else { + this_g1_missing++; + this_flag = true; + } + + // G2 + if (CS_ratio_map) { + this_g1overg2 = CS_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1); + this_g2 = this_g1 / this_g1overg2; + if (this_g1overg2 == 0) { + this_g2_missing++; + this_flag = true; + } else if (this_g0 != 0 && this_g1 != 0 && (this_g2 < -0.2 || this_g2 > -0.02)) { + this_g2_crazy++; + this_flag = true; + } + } else { + this_g2_missing++; + this_flag = true; + } + + if (this_flag == true) { + this_anygain_missing_or_crazy++; + } + + } + + modules_d.push_back(modules[j]); + hg0_missing.push_back(this_hg0_missing); + hg0_crazy.push_back(this_hg0_crazy); + g0_missing.push_back(this_g0_missing); + g0_crazy.push_back(this_g0_crazy); + g1_missing.push_back(this_g1_missing); + g1_crazy.push_back(this_g1_crazy); + g2_missing.push_back(this_g2_missing); + g2_crazy.push_back(this_g2_crazy); + anygain_missing_or_crazy.push_back(this_anygain_missing_or_crazy); + + } // end of modules + + TCanvas *c1 = new TCanvas("c1","",150,10,800,400); + c1->SetLeftMargin(0.12); + c1->SetRightMargin(0.03); + c1->SetTopMargin(0.08); + c1->SetBottomMargin(0.15); + + c1->SetLogy(); + + TF1* flat_module = new TF1("flat_module","[0]",modules_d.front(),modules_d.back()); + flat_module->SetParameter(0,524288); + TF1* flat_chip = new TF1("flat_chip","[0]",modules_d.front(),modules_d.back()); + flat_chip->SetParameter(0,65536); + TF1* flat_column = new TF1("flat_column","[0]",modules_d.front(),modules_d.back()); + flat_column->SetParameter(0,256); + + // HG0 + TGraph* grap_hg0_missing = new TGraph(modules_d.size(), &(modules_d[0]), &(hg0_missing[0])); + grap_hg0_missing->SetMarkerStyle(20); + grap_hg0_missing->GetXaxis()->SetTitle("Module"); + grap_hg0_missing->GetYaxis()->SetTitle("Pixels missing HG0 calibration"); + grap_hg0_missing->GetYaxis()->SetTitleOffset(0.9); + grap_hg0_missing->SetMinimum(1); + grap_hg0_missing->SetMaximum(1E6); + grap_hg0_missing->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_hg0_missing.png"); + + TGraph* grap_hg0_crazy = new TGraph(modules_d.size(), &(modules_d[0]), &(hg0_crazy[0])); + grap_hg0_crazy->SetMarkerStyle(20); + grap_hg0_crazy->GetXaxis()->SetTitle("Module"); + grap_hg0_crazy->GetYaxis()->SetTitle("Pixels bad HG0 calibration"); + grap_hg0_crazy->GetYaxis()->SetTitleOffset(0.9); + grap_hg0_crazy->SetMinimum(1); + grap_hg0_crazy->SetMaximum(1E6); + grap_hg0_crazy->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_hg0_crazy.png"); + + // G0 + TGraph* grap_g0_missing = new TGraph(modules_d.size(), &(modules_d[0]), &(g0_missing[0])); + grap_g0_missing->SetMarkerStyle(20); + grap_g0_missing->GetXaxis()->SetTitle("Module"); + grap_g0_missing->GetYaxis()->SetTitle("Pixels missing G0 calibration"); + grap_g0_missing->GetYaxis()->SetTitleOffset(0.9); + grap_g0_missing->SetMinimum(1); + grap_g0_missing->SetMaximum(1E6); + grap_g0_missing->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_g0_missing.png"); + + TGraph* grap_g0_crazy = new TGraph(modules_d.size(), &(modules_d[0]), &(g0_crazy[0])); + grap_g0_crazy->SetMarkerStyle(20); + grap_g0_crazy->GetXaxis()->SetTitle("Module"); + grap_g0_crazy->GetYaxis()->SetTitle("Pixels bad G0 calibration"); + grap_g0_crazy->GetYaxis()->SetTitleOffset(0.9); + grap_g0_crazy->SetMinimum(1); + grap_g0_crazy->SetMaximum(1E6); + grap_g0_crazy->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_g0_crazy.png"); + + // G1 + TGraph* grap_g1_missing = new TGraph(modules_d.size(), &(modules_d[0]), &(g1_missing[0])); + grap_g1_missing->SetMarkerStyle(20); + grap_g1_missing->GetXaxis()->SetTitle("Module"); + grap_g1_missing->GetYaxis()->SetTitle("Pixels missing G1 calibration"); + grap_g1_missing->GetYaxis()->SetTitleOffset(0.9); + grap_g1_missing->SetMinimum(1); + grap_g1_missing->SetMaximum(1E6); + grap_g1_missing->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_g1_missing.png"); + + TGraph* grap_g1_crazy = new TGraph(modules_d.size(), &(modules_d[0]), &(g1_crazy[0])); + grap_g1_crazy->SetMarkerStyle(20); + grap_g1_crazy->GetXaxis()->SetTitle("Module"); + grap_g1_crazy->GetYaxis()->SetTitle("Pixels bad G1 calibration"); + grap_g1_crazy->GetYaxis()->SetTitleOffset(0.9); + grap_g1_crazy->SetMinimum(1); + grap_g1_crazy->SetMaximum(1E6); + grap_g1_crazy->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_g1_crazy.png"); + + // G2 + TGraph* grap_g2_missing = new TGraph(modules_d.size(), &(modules_d[0]), &(g2_missing[0])); + grap_g2_missing->SetMarkerStyle(20); + grap_g2_missing->GetXaxis()->SetTitle("Module"); + grap_g2_missing->GetYaxis()->SetTitle("Pixels missing G2 calibration"); + grap_g2_missing->GetYaxis()->SetTitleOffset(0.9); + grap_g2_missing->SetMinimum(1); + grap_g2_missing->SetMaximum(1E6); + grap_g2_missing->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_g2_missing.png"); + + TGraph* grap_g2_crazy = new TGraph(modules_d.size(), &(modules_d[0]), &(g2_crazy[0])); + grap_g2_crazy->SetMarkerStyle(20); + grap_g2_crazy->GetXaxis()->SetTitle("Module"); + grap_g2_crazy->GetYaxis()->SetTitle("Pixels bad G2 calibration"); + grap_g2_crazy->GetYaxis()->SetTitleOffset(0.9); + grap_g2_crazy->SetMinimum(1); + grap_g2_crazy->SetMaximum(1E6); + grap_g2_crazy->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_g2_crazy.png"); + + // any + TGraph* grap_any = new TGraph(modules_d.size(), &(modules_d[0]), &(anygain_missing_or_crazy[0])); + grap_any->SetMarkerStyle(20); + grap_any->GetXaxis()->SetTitle("Module"); + grap_any->GetYaxis()->SetTitle("Pixels anything wrong"); + grap_any->GetYaxis()->SetTitleOffset(0.9); + grap_any->SetMinimum(1); + grap_any->SetMaximum(1E6); + grap_any->Draw("AP"); + flat_module->Draw("same"); + flat_chip->Draw("same"); + flat_column->Draw("same"); + c1->SaveAs("plots/BadPixels_anythingwrong.png"); + +} diff --git a/makefile b/makefile index bcf6169..443f91f 100644 --- a/makefile +++ b/makefile @@ -26,3 +26,5 @@ BP_analysis: BP_analysis.cpp JFMC_CalibWriter_wBP: JFMC_CalibWriter_wBP.cpp g++ -Wall -O3 -m64 -I$(ROOTSYS)/include -L$(ROOTSYS)/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic JFMC_CalibWriter_wBP.cpp -o JFMC_CalibWriter_wBP +JFMC_BadPixels: JFMC_BadPixels.cpp + g++ -Wall -O3 -m64 -I$(ROOTSYS)/include -L$(ROOTSYS)/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic JFMC_BadPixels.cpp -o JFMC_BadPixels