307 lines
10 KiB
C++
307 lines
10 KiB
C++
// file to calculate pedestal correction of fluo data
|
|
// make correction and save spectrum per pixel
|
|
|
|
#include "/afs/psi.ch/project/mythen/sophie/sls_detector_calibration/jungfrauCommonHeader.h"
|
|
#include "/afs/psi.ch/project/mythen/sophie/sls_detector_calibration/jungfrauCommonFunctions.h"
|
|
|
|
#include "/afs/psi.ch/project/mythen/sophie/sls_detector_calibration/jungfrauFile.C"
|
|
#include "/afs/psi.ch/project/mythen/sophie/sls_detector_calibration/jungfrauPixelMask.C"
|
|
#include "/afs/psi.ch/project/mythen/sophie/sls_detector_calibration/jungfrauPedestal.C"
|
|
|
|
#include "TGraph.h"
|
|
#include "TGraphErrors.h"
|
|
#include "TF1.h"
|
|
#include "TFile.h"
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
jungfrauStyle();
|
|
|
|
if (argc != 5) {
|
|
cout << "Correct usage:" << endl;
|
|
cout << "arg 1: specify module number" << endl;
|
|
cout << "arg 2: specify data location" << endl;
|
|
cout << "arg 3: specify pede file" << endl;
|
|
cout << "arg 4: specify data file" << endl;
|
|
cout << "eg: ./JFMC_FluoCalibFit 006 /data_pool/Module_006_161116 10us_500Hz_QS_allgain_pede 10us_500Hz_QS_G0_Cu" << endl;
|
|
cout << " " << endl;
|
|
exit(1);
|
|
}
|
|
|
|
string module_str = argv[1];
|
|
string data_loc = argv[2];
|
|
string pede_file = argv[3];
|
|
string data_file = argv[4];
|
|
|
|
jungfrauFile *thisfile = new jungfrauFile();
|
|
|
|
jungfrauPixelMask *pixelMaskObject = new jungfrauPixelMask();
|
|
static int pixel_mask [NCH];
|
|
|
|
jungfrauPedestal *pedestalObject = new jungfrauPedestal();
|
|
pedestalObject->pedestalSetNFrames(1000); // using 1000 frames, rolling window
|
|
static uint16_t pedestals16_G0[NCH];
|
|
|
|
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* pedeRMSG1 = new TH2F("pedeRMSG1","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
|
|
TH2F* pedeRMSG2 = new TH2F("pedeRMSG2","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5);
|
|
|
|
TH1D* adcpc_spec = new TH1D("adcpc_spec","",300,0,3000);
|
|
|
|
TH2I* adc2d_1 = new TH2I("adc2d_1","",1000,-200-0.5,800-0.5,65536,(65536*0-0.5),(65536*1-0.5));
|
|
TH2I* adc2d_2 = new TH2I("adc2d_2","",1000,-200-0.5,800-0.5,65536,(65536*1-0.5),(65536*2-0.5));
|
|
TH2I* adc2d_3 = new TH2I("adc2d_3","",1000,-200-0.5,800-0.5,65536,(65536*2-0.5),(65536*3-0.5));
|
|
TH2I* adc2d_4 = new TH2I("adc2d_4","",1000,-200-0.5,800-0.5,65536,(65536*3-0.5),(65536*4-0.5));
|
|
TH2I* adc2d_5 = new TH2I("adc2d_5","",1000,-200-0.5,800-0.5,65536,(65536*4-0.5),(65536*5-0.5));
|
|
TH2I* adc2d_6 = new TH2I("adc2d_6","",1000,-200-0.5,800-0.5,65536,(65536*5-0.5),(65536*6-0.5));
|
|
TH2I* adc2d_7 = new TH2I("adc2d_7","",1000,-200-0.5,800-0.5,65536,(65536*6-0.5),(65536*7-0.5));
|
|
TH2I* adc2d_8 = new TH2I("adc2d_8","",1000,-200-0.5,800-0.5,65536,(65536*7-0.5),(65536*8-0.5));
|
|
|
|
char savename[128];
|
|
|
|
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);
|
|
|
|
// open pede file
|
|
sprintf(savename,"%s/%s_%%6.6d.dat", data_loc.c_str(), pede_file.c_str());
|
|
thisfile->open((char*)savename, 0);
|
|
|
|
// calculate pixel mask
|
|
pixelMaskObject->initialisePixelMask(pixel_mask);
|
|
if (module_str == "006") {
|
|
pixelMaskObject->maskChip(6, pixel_mask);
|
|
pixelMaskObject->maskSupercolumn(4,1, pixel_mask);
|
|
pixelMaskObject->maskSupercolumn(4,2, pixel_mask);
|
|
} else if (module_str == "040") {
|
|
pixelMaskObject->maskSupercolumn(4,2, pixel_mask);
|
|
} else if (module_str == "065") {
|
|
pixelMaskObject->maskChip(5, pixel_mask);
|
|
}
|
|
|
|
int nevents = 0;
|
|
while (thisfile->readNextFrame()) {
|
|
nevents++;
|
|
}
|
|
thisfile->rewind();
|
|
cout << "read " << nevents << " events" << endl;
|
|
|
|
if (nevents == 2999 || nevents == 3000) {
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
thisfile->readNextFrame();
|
|
pixelMaskObject->maskIfGainNot(0, thisfile->getFrameDataHandle(), (int*)(&pixel_mask));
|
|
}
|
|
for (int i = 0; i < 1000; i++) {
|
|
thisfile->readNextFrame();
|
|
pixelMaskObject->maskIfGainNot(1, thisfile->getFrameDataHandle(), (int*)(&pixel_mask));
|
|
}
|
|
for (int i = 0; i < 999; i++) {
|
|
thisfile->readNextFrame();
|
|
pixelMaskObject->maskIfGainNot(3, thisfile->getFrameDataHandle(), (int*)(&pixel_mask));
|
|
}
|
|
|
|
} else {
|
|
|
|
while (thisfile->readNextFrame()) {
|
|
pixelMaskObject->maskIfGainNot(0, thisfile->getFrameDataHandle(), (int*)(&pixel_mask));
|
|
}
|
|
}
|
|
|
|
thisfile->rewind();
|
|
|
|
sprintf(savename,"plots/M%s/CuFluo/pixelmask.png", module_str.c_str());
|
|
pixelMaskObject->plotPixelMask(pixel_mask,savename);
|
|
cout << "after chip mask, n masked pixels is " << pixelMaskObject->getNMasked(pixel_mask) << endl;
|
|
|
|
// caluclate pedestals
|
|
if (nevents == 2999 || nevents == 3000) {
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
thisfile->readNextFrame();
|
|
pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle());
|
|
}
|
|
for (int i = 0; i < NCH; i++) {
|
|
if (pixel_mask[i] == 1) {
|
|
pedestalsG0->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i));
|
|
pedeRMSG0->Fill(i%NC,i/NC,pedestalObject->rmsOfChannel(i));
|
|
}
|
|
}
|
|
pedestalObject->pedestalData((uint16_t*)(&pedestals16_G0));
|
|
pedestalObject->pedestalClear();
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
thisfile->readNextFrame();
|
|
pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle());
|
|
}
|
|
for (int i = 0; i < NCH; i++) {
|
|
if (pixel_mask[i] == 1) {
|
|
pedestalsG1->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i));
|
|
pedeRMSG1->Fill(i%NC,i/NC,pedestalObject->rmsOfChannel(i));
|
|
}
|
|
}
|
|
pedestalObject->pedestalClear();
|
|
|
|
for (int i = 0; i < 999; i++) {
|
|
thisfile->readNextFrame();
|
|
pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle());
|
|
}
|
|
for (int i = 0; i < NCH; i++) {
|
|
if (pixel_mask[i] == 1) {
|
|
pedestalsG2->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i));
|
|
pedeRMSG2->Fill(i%NC,i/NC,pedestalObject->rmsOfChannel(i));
|
|
}
|
|
}
|
|
pedestalObject->pedestalClear();
|
|
|
|
} else {
|
|
|
|
while (thisfile->readNextFrame()) {
|
|
pedestalObject->addFrameToPedestalCalculation(thisfile->getFrameDataHandle());
|
|
}
|
|
for (int i = 0; i < NCH; i++) {
|
|
if (pixel_mask[i] == 1) {
|
|
pedestalsG0->Fill(i%NC,i/NC,pedestalObject->pedestalOfChannel(i));
|
|
pedeRMSG0->Fill(i%NC,i/NC,pedestalObject->rmsOfChannel(i));
|
|
}
|
|
}
|
|
pedestalObject->pedestalData((uint16_t*)(&pedestals16_G0));
|
|
pedestalObject->pedestalClear();
|
|
}
|
|
|
|
thisfile->close();
|
|
|
|
pedestalsG0->GetXaxis()->SetTitle("Column");
|
|
pedestalsG0->GetYaxis()->SetTitle("Row");
|
|
pedestalsG0->GetYaxis()->SetTitleOffset(0.7);
|
|
pedestalsG0->Draw("colz");
|
|
sprintf(savename,"plots/M%s/CuFluo/pedeG0.png", 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/CuFluo/pedeG1.png", 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/CuFluo/pedeG2.png", module_str.c_str());
|
|
mapcanvas->SaveAs((const char *)(savename));
|
|
|
|
pedeRMSG0->GetXaxis()->SetTitle("Column");
|
|
pedeRMSG0->GetYaxis()->SetTitle("Row");
|
|
pedeRMSG0->GetYaxis()->SetTitleOffset(0.7);
|
|
pedeRMSG0->GetZaxis()->SetRangeUser(0,30);
|
|
pedeRMSG0->Draw("colz");
|
|
sprintf(savename,"plots/M%s/CuFluo/pedeRMSG0.png", module_str.c_str());
|
|
mapcanvas->SaveAs((const char *)(savename));
|
|
|
|
pedeRMSG1->GetXaxis()->SetTitle("Column");
|
|
pedeRMSG1->GetYaxis()->SetTitle("Row");
|
|
pedeRMSG1->GetYaxis()->SetTitleOffset(0.7);
|
|
pedeRMSG1->GetZaxis()->SetRangeUser(0,100);
|
|
pedeRMSG1->Draw("colz");
|
|
sprintf(savename,"plots/M%s/CuFluo/pedeRMSG1.png", module_str.c_str());
|
|
mapcanvas->SaveAs((const char *)(savename));
|
|
|
|
pedeRMSG2->GetXaxis()->SetTitle("Column");
|
|
pedeRMSG2->GetYaxis()->SetTitle("Row");
|
|
pedeRMSG2->GetYaxis()->SetTitleOffset(0.7);
|
|
pedeRMSG2->GetZaxis()->SetRangeUser(0,300);
|
|
pedeRMSG2->Draw("colz");
|
|
sprintf(savename,"plots/M%s/CuFluo/pedeRMSG2.png", module_str.c_str());
|
|
mapcanvas->SaveAs((const char *)(savename));
|
|
|
|
pedestalsG0->Reset();
|
|
pedestalsG1->Reset();
|
|
pedestalsG2->Reset();
|
|
pedeRMSG0->Reset();
|
|
pedeRMSG1->Reset();
|
|
pedeRMSG2->Reset();
|
|
|
|
for (int filen = 0; filen < 20; filen++) {
|
|
|
|
// open data file
|
|
sprintf(savename,"%s/%s_%%6.6d.dat", data_loc.c_str(), data_file.c_str());
|
|
thisfile->open((char*)savename, filen);
|
|
|
|
while (thisfile->readNextFrame()) {
|
|
|
|
uint16_t* imagedptr = thisfile->getFrameDataHandle();
|
|
|
|
for (int i = 0; i < NCH; i++) {
|
|
if (pixel_mask[i] == 1) {
|
|
|
|
uint16_t gain = (imagedptr[i]&0xc000) >> 14;
|
|
|
|
if (gain == 0) {
|
|
|
|
int adcpc = (imagedptr[i]&0x3fff) - pedestals16_G0[i];
|
|
adcpc_spec->Fill(adcpc);
|
|
|
|
if (i < (65536*1)) {
|
|
adc2d_1->Fill(adcpc,i);
|
|
} else if (i < (65536*2)) {
|
|
adc2d_2->Fill(adcpc,i);
|
|
} else if (i < (65536*3)) {
|
|
adc2d_3->Fill(adcpc,i);
|
|
} else if (i < (65536*4)) {
|
|
adc2d_4->Fill(adcpc,i);
|
|
} else if (i < (65536*5)) {
|
|
adc2d_5->Fill(adcpc,i);
|
|
} else if (i < (65536*6)) {
|
|
adc2d_6->Fill(adcpc,i);
|
|
} else if (i < (65536*7)) {
|
|
adc2d_7->Fill(adcpc,i);
|
|
} else if (i < (65536*8)) {
|
|
adc2d_8->Fill(adcpc,i);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
thisfile->close();
|
|
|
|
sprintf(savename,"/mnt/pcmoench_jungfrau_data1_ib/jungfrau_ana_sophie/M%s_CalibAna/Fluo_file%d.root", module_str.c_str(), filen);
|
|
TFile* saved_file = new TFile((const char *)(savename),"RECREATE");
|
|
adc2d_1->Write();
|
|
adc2d_2->Write();
|
|
adc2d_3->Write();
|
|
adc2d_4->Write();
|
|
adc2d_5->Write();
|
|
adc2d_6->Write();
|
|
adc2d_7->Write();
|
|
adc2d_8->Write();
|
|
saved_file->Close();
|
|
|
|
adcpc_spec->GetXaxis()->SetTitle("Pedestal corrected ADC [ADU]");
|
|
adcpc_spec->Draw();
|
|
mapcanvas->SetLogy();
|
|
sprintf(savename,"plots/M%s/CuFluo/adcpc_spec_file%d.png",module_str.c_str(), filen);
|
|
mapcanvas->SaveAs((const char *)(savename));
|
|
mapcanvas->SetLogy(0);
|
|
|
|
adc2d_1->Reset();
|
|
adc2d_2->Reset();
|
|
adc2d_3->Reset();
|
|
adc2d_4->Reset();
|
|
adc2d_5->Reset();
|
|
adc2d_6->Reset();
|
|
adc2d_7->Reset();
|
|
adc2d_8->Reset();
|
|
adcpc_spec->Reset();
|
|
|
|
} // end of file loop
|
|
|
|
}
|