Files
JFCalibration/Default_pixels_arrays.cpp
hinger_v 73938aad04 new file: BP_analysis_M431.cpp
new file:   BP_analysis_thinSensors.cpp
	new file:   BP_fit.cpp
	new file:   BP_fit_M431.cpp
	new file:   BP_fit_thin.cpp
	new file:   BP_scan_both_speeds.sh
	new file:   BP_scan_thinSensor.sh
	new file:   CS_analysis_M431.cpp
	new file:   CS_analysis_M439.cpp
	new file:   CS_fit.cpp
	new file:   CS_fit_M431
	new file:   CS_fit_M431.cpp
	new file:   CS_scan_both_speeds.sh
	new file:   CuFluo_exposure_both_speeds.sh
	new file:   CuFluo_fit.cpp
	new file:   Default_pixels_arrays.cpp
2025-06-27 11:16:26 +02:00

240 lines
8.4 KiB
C++

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