diff --git a/CS_analysis_M371.cpp b/CS_analysis_M371.cpp new file mode 100644 index 0000000..3503442 --- /dev/null +++ b/CS_analysis_M371.cpp @@ -0,0 +1,2143 @@ +// 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 + + 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,0,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,-500,0); + TH1F *g0overg1erhist = new TH1F("g0overg1erhist","",100,0,2); + + TH1F *g1overg2hist = new TH1F("g1overg2hist","",100,9,12); + TH1F *g1overg2erhist = new TH1F("g1overg2erhist","",100,0,1); + + TH1F *g0overg1_isEdge = new TH1F("g0overg1_isEdge","",100,-500,0); + TH1F *g0overg1_isInnerEdge = new TH1F("g0overg1_isInnerEdge","",100,-500,0); + TH1F *g0overg1_isDouble = new TH1F("g0overg1_isDouble","",100,-500,0); + TH1F *g0overg1_isNextToDouble = new TH1F("g0overg1_isNextToDouble","",100,-500,0); + TH1F *g0overg1_isQuad = new TH1F("g0overg1_isQuad","",100,-500,0); + TH1F *g0overg1_isBulk = new TH1F("g0overg1_isBulk","",100,-500,0); + + TH1F *g1overg2_isEdge = new TH1F("g1overg2_isEdge","",100,9,12); + TH1F *g1overg2_isInnerEdge = new TH1F("g1overg2_isInnerEdge","",100,9,12); + TH1F *g1overg2_isDouble = new TH1F("g1overg2_isDouble","",100,9,12); + TH1F *g1overg2_isNextToDouble = new TH1F("g1overg2_isNextToDouble","",100,9,12); + TH1F *g1overg2_isQuad = new TH1F("g1overg2_isQuad","",100,9,12); + TH1F *g1overg2_isBulk = new TH1F("g1overg2_isBulk","",100,9,12); + + 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++) { + + 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+0.1, rangemax_g0-0.1); + fit_g0->SetParameter(0, 3000.); + fit_g0->SetParameter(1, 10000.); + 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+0.1, rangemax_g0-0.1); + 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+7,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+3, rangemax_g1); + flat_g1->SetLineColor(kGreen+2); + + TF1* lin_g1_p02pc = new TF1("lin_g1_p02pc","[0]+[1]*x",rangemin_g1+3,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+3,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+3,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+3,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+3)); + norm_g1->SetMaximum(1.5*lin_g1_p05pc->Eval(rangemin_g1+3)); + 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(0,50000); + 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(-500,50); + } + 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,2); + 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(8,12); +#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(); + +}