Files
JFCalibration/JFMC_CalibWriter_wBP.cpp

656 lines
26 KiB
C++

// file to combine the four sets of results
// to write the calibration constants for the junfgrau module
#include "../sls_detector_calibration/jungfrauCommonHeader.h"
#include "../sls_detector_calibration/jungfrauCommonFunctions.h"
#include "TCanvas.h"
#include "TFile.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TPaveText.h"
#include <fstream>
#include <iomanip>
struct GainMaps
{
static double g0VALs[NCH]; // declaration, incomplete type
static double g1VALs[NCH];
static double g2VALs[NCH];
static double hg0VALs[NCH];
};
double GainMaps::g0VALs[NCH]; // definition, complete type
double GainMaps::g1VALs[NCH];
double GainMaps::g2VALs[NCH];
double GainMaps::hg0VALs[NCH];
int main(int argc, char* argv[]) {
jungfrauStyle();
if (argc != 2) {
cout << "Correct usage:" << endl;
cout << "arg 1: specify module number" << endl;
cout << " " << endl;
exit(1);
}
string module_str = argv[1];
char savename[128];
// CuFluo HG0 dataset
sprintf(savename,"data/M%s/CuFluo_gain_HG0_M%s.root", module_str.c_str(), module_str.c_str());
TFile* FL_HG0_file = new TFile((char*)savename,"READ");
TH2F* FL_HG0_gain_map = 0;
TH2F* FL_HG0_gainer_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");
FL_HG0_gainer_map = (TH2F*)FL_HG0_file->Get("gainerr_ADUper1keV_2d");
}
// CuFluo G0 dataset
sprintf(savename,"data/M%s/CuFluo_gain_G0_M%s.root", module_str.c_str(), module_str.c_str());
TFile* FL_G0_file = new TFile((char*)savename,"READ");
TH2F* FL_G0_gain_map = 0;
TH2F* FL_G0_gainer_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");
FL_G0_gainer_map = (TH2F*)FL_G0_file->Get("gainerr_ADUper1keV_2d");
}
// Backplane pulsing dataset
sprintf(savename,"data/M%s/BP_ratio_M%s.root", module_str.c_str(), module_str.c_str());
TFile* DB_file = new TFile((char*)savename,"READ");
TH2F* DB_ratio_map = 0;
TH2F* DB_ratioer_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", module_str.c_str(), module_str.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");
DB_ratioer_map = (TH2F*)DB_file->Get("g0overg1ermap");
}
} else {
cout << "loading G0/G1 from BP" << endl;
DB_ratio_map = (TH2F*)DB_file->Get("g0overg1_map");
DB_ratioer_map = (TH2F*)DB_file->Get("g0overg1er_map");
}
// Current source dataset
sprintf(savename,"data/M%s/CS_ratio_M%s.root", module_str.c_str(), module_str.c_str());
TFile* CS_file = new TFile((char*)savename,"READ");
TH2F* CS_ratio_map = 0;
TH2F* CS_ratioer_map = 0;
if (CS_file->IsZombie()) {
cout << "didn't find CS file" << endl;
} else {
CS_ratio_map = (TH2F*)CS_file->Get("g1overg2map");
CS_ratioer_map = (TH2F*)CS_file->Get("g1overg2ermap");
}
// Now write binary maps
// units of ADU/keV
// one output file per module with four maps in
GainMaps *mapsObject = new GainMaps;
// start out with all calibration constants zero
for (int i = 0; i < NCH; i++) {
mapsObject->hg0VALs[i] = 0.;
mapsObject->g0VALs[i] = 0.;
mapsObject->g1VALs[i] = 0.;
mapsObject->g2VALs[i] = 0.;
}
TH1F* hg0histall = new TH1F("hg0histall","",100,80,120);
TH1F* g0histall = new TH1F("g0histall","",100,20,60);
TH1F* g1histall = new TH1F("g1histall","",100,-3,0);
TH1F* g2histall = new TH1F("g2histall","",100,-0.2,0);
TH1F* hg0ferhistall = new TH1F("hg0ferhistall","",100,0,0.005);
TH1F* g0ferhistall = new TH1F("g0ferhistall","",100,0,0.005);
TH1F* g1ferhistall = new TH1F("g1ferhistall","",100,0,0.01);
TH1F* g2ferhistall = new TH1F("g2ferhistall","",100,0,0.05);
TH1F* hg0histcut = new TH1F("hg0histcut","",100,80,120);
TH1F* g0histcut = new TH1F("g0histcut","",100,20,60);
TH1F* g1histcut = new TH1F("g1histcut","",100,-3,0);
TH1F* g2histcut = new TH1F("g2histcut","",100,-0.2,0);
TH2F* hg0mapall = new TH2F("hg0mapall","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g0mapall = new TH2F("g0mapall","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g1mapall = new TH2F("g1mapall","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g2mapall = new TH2F("g2mapall","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* hg0fermapall = new TH2F("hg0fermapall","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g0fermapall = new TH2F("g0fermapall","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g1fermapall = new TH2F("g1fermapall","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g2fermapall = new TH2F("g2fermapall","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* hg0mapcut = new TH2F("hg0mapcut","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g0mapcut = new TH2F("g0mapcut","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g1mapcut = new TH2F("g1mapcut","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* g2mapcut = new TH2F("g2mapcut","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* defaultvalmap_hg0 = new TH2F("defaultvalmap_hg0","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* defaultvalmap_g0 = new TH2F("defaultvalmap_g0","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* defaultvalmap_g1 = new TH2F("defaultvalmap_g1","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* defaultvalmap_g2 = new TH2F("defaultvalmap_g2","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* missingvalmap_hg0 = new TH2F("missingvalmap_hg0","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* missingvalmap_g0 = new TH2F("missingvalmap_g0","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* missingvalmap_g1 = new TH2F("missingvalmap_g1","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
TH2F* missingvalmap_g2 = new TH2F("missingvalmap_g2","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
sprintf(savename,"data/M%s/gainMaps_M%s.bin", module_str.c_str(), module_str.c_str());
fstream outfile;
outfile.open(savename, ios::binary | ios::out);
for (int i = 0; i < NCH; i++) {
// load existing values into maps
// if the map doesn't exist, put the global default value
if (FL_HG0_gain_map) {
mapsObject->hg0VALs[i] = FL_HG0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1);
if (FL_HG0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1) == 0) {
missingvalmap_hg0->Fill(i%NC,i/NC,1);
}
} else {
mapsObject->hg0VALs[i] = 100.;
defaultvalmap_hg0->Fill(i%NC,i/NC,1);
missingvalmap_hg0->Fill(i%NC,i/NC,1);
}
if (FL_G0_gain_map) {
mapsObject->g0VALs[i] = FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1);
if (FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1) == 0) {
missingvalmap_g0->Fill(i%NC,i/NC,1);
}
} else {
mapsObject->g0VALs[i] = 40;
defaultvalmap_g0->Fill(i%NC,i/NC,1);
missingvalmap_g0->Fill(i%NC,i/NC,1);
}
if (DB_ratio_map) {
if (DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0) {
mapsObject->g1VALs[i] = mapsObject->g0VALs[i] / DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1);
} else {
missingvalmap_g1->Fill(i%NC,i/NC,1);
}
} else {
mapsObject->g1VALs[i] = -1.4;
defaultvalmap_g1->Fill(i%NC,i/NC,1);
missingvalmap_g1->Fill(i%NC,i/NC,1);
}
if (CS_ratio_map) {
if (CS_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0) {
mapsObject->g2VALs[i] = mapsObject->g1VALs[i] / CS_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1);
} else {
missingvalmap_g2->Fill(i%NC,i/NC,1);
}
} else {
mapsObject->g2VALs[i] = -0.1;
defaultvalmap_g2->Fill(i%NC,i/NC,1);
missingvalmap_g2->Fill(i%NC,i/NC,1);
}
hg0histall->Fill(mapsObject->hg0VALs[i]);
g0histall->Fill(mapsObject->g0VALs[i]);
g1histall->Fill(mapsObject->g1VALs[i]);
g2histall->Fill(mapsObject->g2VALs[i]);
hg0mapall->SetBinContent((i%NC)+1,(i/NC)+1,mapsObject->hg0VALs[i]);
g0mapall->SetBinContent((i%NC)+1,(i/NC)+1,mapsObject->g0VALs[i]);
g1mapall->SetBinContent((i%NC)+1,(i/NC)+1,mapsObject->g1VALs[i]);
g2mapall->SetBinContent((i%NC)+1,(i/NC)+1,mapsObject->g2VALs[i]);
// uncertainties
if (FL_HG0_gain_map) {
if (FL_HG0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0) {
hg0fermapall->SetBinContent((i%NC)+1,(i/NC)+1,FL_HG0_gainer_map->GetBinContent((i%NC)+1,(i/NC)+1)/FL_HG0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1));
hg0ferhistall->Fill(FL_HG0_gainer_map->GetBinContent((i%NC)+1,(i/NC)+1)/FL_HG0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1));
}
}
if (FL_G0_gain_map) {
if (FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0) {
g0fermapall->SetBinContent((i%NC)+1,(i/NC)+1,FL_G0_gainer_map->GetBinContent((i%NC)+1,(i/NC)+1)/FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1));
g0ferhistall->Fill(FL_G0_gainer_map->GetBinContent((i%NC)+1,(i/NC)+1)/FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1));
}
}
if (FL_G0_gain_map && DB_ratio_map) {
if (FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0 && DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0) {
g1fermapall->SetBinContent((i%NC)+1,(i/NC)+1, sqrt(pow((FL_G0_gainer_map->GetBinContent((i%NC)+1,(i/NC)+1)/FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1)),2) + pow((DB_ratioer_map->GetBinContent((i%NC)+1,(i/NC)+1)/DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1)),2)));
g1ferhistall->Fill(sqrt(pow((FL_G0_gainer_map->GetBinContent((i%NC)+1,(i/NC)+1)/FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1)),2) + pow((DB_ratioer_map->GetBinContent((i%NC)+1,(i/NC)+1)/DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1)),2)));
}
}
if (FL_G0_gain_map && DB_ratio_map && CS_ratio_map) {
if (FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0 &&
DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0 &&
CS_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1) != 0) {
g2fermapall->SetBinContent((i%NC)+1,(i/NC)+1, sqrt(pow((FL_G0_gainer_map->GetBinContent((i%NC)+1,(i/NC)+1)/FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1)),2) + pow((DB_ratioer_map->GetBinContent((i%NC)+1,(i/NC)+1)/DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1)),2) + pow((CS_ratioer_map->GetBinContent((i%NC)+1,(i/NC)+1)/CS_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1)),2)));
g2ferhistall->Fill(sqrt(pow((FL_G0_gainer_map->GetBinContent((i%NC)+1,(i/NC)+1)/FL_G0_gain_map->GetBinContent((i%NC)+1,(i/NC)+1)),2) + pow((DB_ratioer_map->GetBinContent((i%NC)+1,(i/NC)+1)/DB_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1)),2) + pow((CS_ratioer_map->GetBinContent((i%NC)+1,(i/NC)+1)/CS_ratio_map->GetBinContent((i%NC)+1,(i/NC)+1)),2)));
}
}
}
float defaultHG0 = 0;
if (FL_HG0_gain_map) {
defaultHG0 = hg0histall->GetBinCenter(hg0histall->GetMaximumBin());
}
float defaultG0 = 0;
if (FL_G0_gain_map) {
defaultG0 = g0histall->GetBinCenter(g0histall->GetMaximumBin());
}
float defaultG1 = 0;
if (DB_ratio_map) {
defaultG1 = g1histall->GetBinCenter(g1histall->GetMaximumBin());
}
float defaultG2 = 0;
if (CS_ratio_map) {
defaultG2 = g2histall->GetBinCenter(g2histall->GetMaximumBin());
}
cout << setprecision(4) << fixed << "default values for module " << module_str << " " << defaultHG0 << " " << defaultG0 << " " << defaultG1 << " " << defaultG2 << endl;
for (int i = 0; i < NCH; i++) {
// crazy and missing value check: replace with module default
// think of a way to get the limits better
if (mapsObject->hg0VALs[i] < 80 || mapsObject->hg0VALs[i] > 120) {
mapsObject->hg0VALs[i] = defaultHG0;
defaultvalmap_hg0->Fill(i%NC,i/NC,1);
}
if (mapsObject->g0VALs[i] < 30 || mapsObject->g0VALs[i] > 48) {
mapsObject->g0VALs[i] = defaultG0;
defaultvalmap_g0->Fill(i%NC,i/NC,1);
}
if (mapsObject->g1VALs[i] < -2.0 || mapsObject->g1VALs[i] > -0.5) {
mapsObject->g1VALs[i] = defaultG1;
defaultvalmap_g1->Fill(i%NC,i/NC,1);
}
if (mapsObject->g2VALs[i] < -0.2 || mapsObject->g2VALs[i] > -0.02) {
mapsObject->g2VALs[i] = defaultG2;
defaultvalmap_g2->Fill(i%NC,i/NC,1);
}
hg0histcut->Fill(mapsObject->hg0VALs[i]);
g0histcut->Fill(mapsObject->g0VALs[i]);
g1histcut->Fill(mapsObject->g1VALs[i]);
g2histcut->Fill(mapsObject->g2VALs[i]);
hg0mapcut->SetBinContent((i%NC)+1,(i/NC)+1,mapsObject->hg0VALs[i]);
g0mapcut->SetBinContent((i%NC)+1,(i/NC)+1,mapsObject->g0VALs[i]);
g1mapcut->SetBinContent((i%NC)+1,(i/NC)+1,mapsObject->g1VALs[i]);
g2mapcut->SetBinContent((i%NC)+1,(i/NC)+1,mapsObject->g2VALs[i]);
}
outfile.write((char*)mapsObject->g0VALs, sizeof(mapsObject->g0VALs));
outfile.write((char*)mapsObject->g1VALs, sizeof(mapsObject->g1VALs));
outfile.write((char*)mapsObject->g2VALs, sizeof(mapsObject->g2VALs));
outfile.write((char*)mapsObject->hg0VALs, sizeof(mapsObject->hg0VALs));
outfile.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);
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);
cout << setprecision(4) << fixed << "mean values for module " << module_str << " " << hg0histcut->GetMean() << " " << g0histcut->GetMean() << " " << g1histcut->GetMean() << " " << g2histcut->GetMean() << endl;
hg0mapall->GetXaxis()->SetTitle("Column");
hg0mapall->GetYaxis()->SetTitle("Row");
hg0mapall->GetYaxis()->SetTitleOffset(0.7);
hg0mapall->Draw("colz");
pave->AddText("HG0 [ADU/keV]");
pave->Draw();
hg0mapall->GetZaxis()->SetRangeUser(90,110);
sprintf(savename,"plots/M%s/hgain0_all_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
hg0fermapall->GetXaxis()->SetTitle("Column");
hg0fermapall->GetYaxis()->SetTitle("Row");
hg0fermapall->GetYaxis()->SetTitleOffset(0.7);
hg0fermapall->Draw("colz");
hg0fermapall->GetZaxis()->SetRangeUser(0.,0.005);
sprintf(savename,"plots/M%s/hgain0fer_all_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g0mapall->GetXaxis()->SetTitle("Column");
g0mapall->GetYaxis()->SetTitle("Row");
g0mapall->GetYaxis()->SetTitleOffset(0.7);
g0mapall->Draw("colz");
pave->Clear();
pave->AddText("G0 [ADU/keV]");
pave->Draw();
g0mapall->GetZaxis()->SetRangeUser(38,46);
sprintf(savename,"plots/M%s/gain0_all_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g0fermapall->GetXaxis()->SetTitle("Column");
g0fermapall->GetYaxis()->SetTitle("Row");
g0fermapall->GetYaxis()->SetTitleOffset(0.7);
g0fermapall->Draw("colz");
g0fermapall->GetZaxis()->SetRangeUser(0.,0.005);
sprintf(savename,"plots/M%s/gain0fer_all_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g1mapall->GetXaxis()->SetTitle("Column");
g1mapall->GetYaxis()->SetTitle("Row");
g1mapall->GetYaxis()->SetTitleOffset(0.7);
g1mapall->Draw("colz");
pave->Clear();
pave->AddText("G1 [ADU/keV]");
pave->Draw();
g1mapall->GetZaxis()->SetRangeUser(-1.56,-1.36);
sprintf(savename,"plots/M%s/gain1_all_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g1fermapall->GetXaxis()->SetTitle("Column");
g1fermapall->GetYaxis()->SetTitle("Row");
g1fermapall->GetYaxis()->SetTitleOffset(0.7);
g1fermapall->Draw("colz");
g1fermapall->GetZaxis()->SetRangeUser(0,0.005);
sprintf(savename,"plots/M%s/gain1fer_all_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g2mapall->GetXaxis()->SetTitle("Column");
g2mapall->GetYaxis()->SetTitle("Row");
g2mapall->GetYaxis()->SetTitleOffset(0.7);
g2mapall->Draw("colz");
pave->Clear();
pave->AddText("G2 [ADU/keV]");
pave->Draw();
g2mapall->GetZaxis()->SetRangeUser(-0.122,-0.108);
sprintf(savename,"plots/M%s/gain2_all_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g2fermapall->GetXaxis()->SetTitle("Column");
g2fermapall->GetYaxis()->SetTitle("Row");
g2fermapall->GetYaxis()->SetTitleOffset(0.7);
g2fermapall->Draw("colz");
g2fermapall->GetZaxis()->SetRangeUser(0,0.1);
sprintf(savename,"plots/M%s/gain2fer_all_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
hg0mapcut->GetXaxis()->SetTitle("Column");
hg0mapcut->GetYaxis()->SetTitle("Row");
hg0mapcut->GetYaxis()->SetTitleOffset(0.7);
hg0mapcut->Draw("colz");
pave->Clear();
pave->AddText("HG0 [ADU/keV]");
pave->Draw();
hg0mapcut->GetZaxis()->SetRangeUser(90,110);
sprintf(savename,"plots/M%s/hgain0_cut_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g0mapcut->GetXaxis()->SetTitle("Column");
g0mapcut->GetYaxis()->SetTitle("Row");
g0mapcut->GetYaxis()->SetTitleOffset(0.7);
g0mapcut->Draw("colz");
pave->Clear();
pave->AddText("G0 [ADU/keV]");
pave->Draw();
g0mapcut->GetZaxis()->SetRangeUser(38,46);
sprintf(savename,"plots/M%s/gain0_cut_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g1mapcut->GetXaxis()->SetTitle("Column");
g1mapcut->GetYaxis()->SetTitle("Row");
g1mapcut->GetYaxis()->SetTitleOffset(0.7);
g1mapcut->Draw("colz");
pave->Clear();
pave->AddText("G1 [ADU/keV]");
pave->Draw();
g1mapcut->GetZaxis()->SetRangeUser(-1.56,-1.36);
sprintf(savename,"plots/M%s/gain1_cut_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
g2mapcut->GetXaxis()->SetTitle("Column");
g2mapcut->GetYaxis()->SetTitle("Row");
g2mapcut->GetYaxis()->SetTitleOffset(0.7);
g2mapcut->Draw("colz");
pave->Clear();
pave->AddText("G2 [ADU/keV]");
pave->Draw();
g2mapcut->GetZaxis()->SetRangeUser(-0.122,-0.108);
sprintf(savename,"plots/M%s/gain2_cut_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
defaultvalmap_hg0->GetXaxis()->SetTitle("Column");
defaultvalmap_hg0->GetYaxis()->SetTitle("Row");
defaultvalmap_hg0->GetYaxis()->SetTitleOffset(0.7);
defaultvalmap_hg0->Draw("colz");
pave->Clear();
sprintf(savename,"%d pixels default", int(defaultvalmap_hg0->GetEntries()));
pave->AddText(savename);
pave->Draw();
defaultvalmap_hg0->GetZaxis()->SetRangeUser(0,1);
sprintf(savename,"plots/M%s/defaultvalmap_hg0_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
defaultvalmap_g0->GetXaxis()->SetTitle("Column");
defaultvalmap_g0->GetYaxis()->SetTitle("Row");
defaultvalmap_g0->GetYaxis()->SetTitleOffset(0.7);
defaultvalmap_g0->Draw("colz");
pave->Clear();
sprintf(savename,"%d pixels default", int(defaultvalmap_g0->GetEntries()));
pave->AddText(savename);
pave->Draw();
defaultvalmap_g0->GetZaxis()->SetRangeUser(0,1);
sprintf(savename,"plots/M%s/defaultvalmap_g0_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
defaultvalmap_g1->GetXaxis()->SetTitle("Column");
defaultvalmap_g1->GetYaxis()->SetTitle("Row");
defaultvalmap_g1->GetYaxis()->SetTitleOffset(0.7);
defaultvalmap_g1->Draw("colz");
pave->Clear();
sprintf(savename,"%d pixels default", int(defaultvalmap_g1->GetEntries()));
pave->AddText(savename);
pave->Draw();
defaultvalmap_g1->GetZaxis()->SetRangeUser(0,1);
sprintf(savename,"plots/M%s/defaultvalmap_g1_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
defaultvalmap_g2->GetXaxis()->SetTitle("Column");
defaultvalmap_g2->GetYaxis()->SetTitle("Row");
defaultvalmap_g2->GetYaxis()->SetTitleOffset(0.7);
defaultvalmap_g2->Draw("colz");
pave->Clear();
sprintf(savename,"%d pixels default", int(defaultvalmap_g2->GetEntries()));
pave->AddText(savename);
pave->Draw();
defaultvalmap_g2->GetZaxis()->SetRangeUser(0,1);
sprintf(savename,"plots/M%s/defaultvalmap_g2_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
missingvalmap_hg0->GetXaxis()->SetTitle("Column");
missingvalmap_hg0->GetYaxis()->SetTitle("Row");
missingvalmap_hg0->GetYaxis()->SetTitleOffset(0.7);
missingvalmap_hg0->Draw("colz");
pave->Clear();
sprintf(savename,"%d pixels missing", int(missingvalmap_hg0->GetEntries()));
pave->AddText(savename);
pave->Draw();
missingvalmap_hg0->GetZaxis()->SetRangeUser(0,1);
sprintf(savename,"plots/M%s/missingvalmap_hg0_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
missingvalmap_g0->GetXaxis()->SetTitle("Column");
missingvalmap_g0->GetYaxis()->SetTitle("Row");
missingvalmap_g0->GetYaxis()->SetTitleOffset(0.7);
missingvalmap_g0->Draw("colz");
pave->Clear();
sprintf(savename,"%d pixels missing", int(missingvalmap_g0->GetEntries()));
pave->AddText(savename);
pave->Draw();
missingvalmap_g0->GetZaxis()->SetRangeUser(0,1);
sprintf(savename,"plots/M%s/missingvalmap_g0_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
missingvalmap_g1->GetXaxis()->SetTitle("Column");
missingvalmap_g1->GetYaxis()->SetTitle("Row");
missingvalmap_g1->GetYaxis()->SetTitleOffset(0.7);
missingvalmap_g1->Draw("colz");
pave->Clear();
sprintf(savename,"%d pixels missing", int(missingvalmap_g1->GetEntries()));
pave->AddText(savename);
pave->Draw();
missingvalmap_g1->GetZaxis()->SetRangeUser(0,1);
sprintf(savename,"plots/M%s/missingvalmap_g1_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
missingvalmap_g2->GetXaxis()->SetTitle("Column");
missingvalmap_g2->GetYaxis()->SetTitle("Row");
missingvalmap_g2->GetYaxis()->SetTitleOffset(0.7);
missingvalmap_g2->Draw("colz");
pave->Clear();
sprintf(savename,"%d pixels missing", int(missingvalmap_g2->GetEntries()));
pave->AddText(savename);
pave->Draw();
missingvalmap_g2->GetZaxis()->SetRangeUser(0,1);
sprintf(savename,"plots/M%s/missingvalmap_g2_M%s.png", module_str.c_str(), module_str.c_str());
mapcanvas->SaveAs((const char *)(savename));
TCanvas* c1 = new TCanvas("c1","");
hg0histcut->SetLineColor(kRed);
g0histcut->SetLineColor(kRed);
g1histcut->SetLineColor(kRed);
g2histcut->SetLineColor(kRed);
hg0histall->GetXaxis()->SetTitle("Gain HG0 [ADU / keV]");
hg0histall->Draw();
sprintf(savename,"plots/M%s/hg0hist_all_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
hg0histcut->GetXaxis()->SetTitle("Gain HG0 [ADU / keV]");
hg0histcut->Draw();
sprintf(savename,"plots/M%s/hg0hist_cut_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
hg0histcut->Draw();
hg0histall->Draw("same");
sprintf(savename,"plots/M%s/hg0hist_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
c1->SetLogy();
sprintf(savename,"plots/M%s/hg0hist_log_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
c1->SetLogy(0);
g0histall->GetXaxis()->SetTitle("Gain G0 [ADU / keV]");
g0histall->Draw();
sprintf(savename,"plots/M%s/g0hist_all_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
g0histcut->GetXaxis()->SetTitle("Gain G0 [ADU / keV]");
g0histcut->Draw();
sprintf(savename,"plots/M%s/g0hist_cut_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
g0histcut->Draw();
g0histall->Draw("same");
sprintf(savename,"plots/M%s/g0hist_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
c1->SetLogy();
sprintf(savename,"plots/M%s/g0hist_log_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
c1->SetLogy(0);
g1histall->GetXaxis()->SetTitle("Gain G1 [ADU / keV]");
g1histall->Draw();
sprintf(savename,"plots/M%s/g1hist_all_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
g1histcut->GetXaxis()->SetTitle("Gain G1 [ADU / keV]");
g1histcut->Draw();
sprintf(savename,"plots/M%s/g1hist_cut_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
g1histcut->Draw();
g1histall->Draw("same");
sprintf(savename,"plots/M%s/g1hist_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
c1->SetLogy();
sprintf(savename,"plots/M%s/g1hist_log_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
c1->SetLogy(0);
g2histall->GetXaxis()->SetTitle("Gain G2 [ADU / keV]");
g2histall->Draw();
sprintf(savename,"plots/M%s/g2hist_all_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
g2histcut->GetXaxis()->SetTitle("Gain G2 [ADU / keV]");
g2histcut->Draw();
sprintf(savename,"plots/M%s/g2hist_cut_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
g2histcut->Draw();
g2histall->Draw("same");
sprintf(savename,"plots/M%s/g2hist_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
c1->SetLogy();
sprintf(savename,"plots/M%s/g2hist_log_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
c1->SetLogy(0);
g0ferhistall->GetXaxis()->SetTitle("Gain G0 frac uncert");
g0ferhistall->Draw();
sprintf(savename,"plots/M%s/g0ferhist_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
g1ferhistall->GetXaxis()->SetTitle("Gain G1 frac uncert");
g1ferhistall->Draw();
sprintf(savename,"plots/M%s/g1ferhist_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
g2ferhistall->GetXaxis()->SetTitle("Gain G2 frac uncert");
g2ferhistall->Draw();
sprintf(savename,"plots/M%s/g2ferhist_M%s.png", module_str.c_str(), module_str.c_str());
c1->SaveAs((const char *)(savename));
}