// file to fit fluo spectrum per pixel // and save peak position and uncertainty #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 "/afs/psi.ch/project/mythen/sophie/sls_detector_calibration/energyCalibration.h" #include "/afs/psi.ch/project/mythen/sophie/sls_detector_calibration/energyCalibration.cpp" #include "TGraph.h" #include "TGraphErrors.h" #include "TF1.h" #include "TFile.h" #include "TPaveStats.h" #include "TLegend.h" #include "TPaveText.h" int main(int argc, char* argv[]) { jungfrauStyle(); gStyle->SetOptFit(11); if (argc != 2) { cout << "Correct usage:" << endl; cout << "arg 1: specify module number" << endl; cout << "eg: ./JFMC_FluoCalibFit 006" << endl; cout << " " << endl; exit(1); } string module_str = argv[1]; char histoname[128]; char savename[128]; TCanvas* c1 = new TCanvas("c1",""); sprintf(savename,"/mnt/pcmoench_jungfrau_data/jungfrau_ana_sophie/M%s_CalibAna/Fluo_comb.root", module_str.c_str()); TFile* comb_file = new TFile((const char *)(savename),"READ"); jungfrauPixelMask *pixelMaskObject = new jungfrauPixelMask(); static int pixel_mask [NCH]; pixelMaskObject->initialisePixelMask(pixel_mask); TH1F* peak_fit_pos = new TH1F("peak_fit_pos","",100,250,400); TH1F* peak_fit_poserr = new TH1F("peak_fit_poserr","",100,0,2); TH2F* peak_fit_pos_2d = new TH2F("peak_fit_pos_2d","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); TH2F* peak_fit_poserr_2d = new TH2F("peak_fit_poserr_2d","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); TH1F* noise_fit_pos = new TH1F("noise_fit_pos","",100,-30,30); TH1F* noise_fit_poserr = new TH1F("noise_fit_poserr","",100,0,0.1); TH2F* noise_fit_pos_2d = new TH2F("noise_fit_pos_2d","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); TH2F* noise_fit_poserr_2d = new TH2F("noise_fit_poserr_2d","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); TH1F* gain_fit = new TH1F("gain_fit","",100,250,400); TH1F* gain_fiterr = new TH1F("gain_fiterr","",100,0,2); TH2F* gain_fit_2d = new TH2F("gain_fit_2d","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); TH2F* gain_fiterr_2d = new TH2F("gain_fiterr_2d","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); TH1F* gain_fit_isEdge = new TH1F("gain_fit_isEdge","",100,250,400); TH1F* gain_fit_isInnerEdge = new TH1F("gain_fit_isInnerEdge","",100,250,400); TH1F* gain_fit_isDouble = new TH1F("gain_fit_isDouble","",100,250,400); TH1F* gain_fit_isNextToDouble = new TH1F("gain_fit_isNextToDouble","",100,250,400); TH1F* gain_fit_isQuad = new TH1F("gain_fit_isQuad","",100,250,400); TH1F* gain_fit_isBulk = new TH1F("gain_fit_isBulk","",100,250,400); TH2F* gain_ADUper1keV_2d = new TH2F("gain_ADUper1keV_2d","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); TH2F* gainerr_ADUper1keV_2d = new TH2F("gainerr_ADUper1keV_2d","",NC,-0.5,NC-0.5,NR,-0.5,NR-0.5); int low_bin_noise = 101; int high_bin_noise = 301; int low_bin_peak = 301; int high_bin_peak = 601; for (int j=1; j<9; j++) { cout << "slice " << j << endl; sprintf(histoname,"adc2d_%i",j); TH2I* adc2d_j = (TH2I*)(comb_file->Get((const char *)(histoname))); cout << adc2d_j->GetEntries() << endl; adc2d_j->Draw("colz"); c1->Update(); for (int i=(65536*(j-1)); i<(65536*(j)); i++) { if (i%10000==0){cout << "another 10k" << endl;} TH1D* proj = adc2d_j->ProjectionX("bin1",i-(65536*(j-1))+1,i-(65536*(j-1))+1); if (proj->Integral(low_bin_noise,high_bin_noise)!=0 && proj->Integral(low_bin_peak,high_bin_peak)!=0) { // noise TH1D *proj_noise = dynamic_cast(proj->Rebin(4,"proj_noise")); proj_noise->SetStats(kTRUE); proj_noise->GetXaxis()->SetRangeUser(proj->GetBinLowEdge(low_bin_noise),proj->GetBinLowEdge(high_bin_noise+1)); proj_noise->Fit("gaus","Q","",-50,50); TF1 *fit = proj_noise->GetFunction("gaus"); noise_fit_pos->Fill(fit->GetParameter(1)); noise_fit_pos_2d->Fill(i%NC,i/NC,fit->GetParameter(1)); noise_fit_poserr->Fill(fit->GetParError(1)); noise_fit_poserr_2d->Fill(i%NC,i/NC,fit->GetParError(1)); // peak TH1D *proj_peak = dynamic_cast(proj->Rebin(4,"proj_peak")); proj_peak->SetStats(kTRUE); proj_peak->GetXaxis()->SetRangeUser(proj->GetBinLowEdge(low_bin_peak),proj->GetBinLowEdge(high_bin_peak+1)); Double_t mypar[6]; mypar[0] = 0.0; mypar[1] = 0.0; mypar[2] = proj_peak->GetBinCenter(proj_peak->GetMaximumBin()); mypar[3] = 19.; mypar[4] = 60.; mypar[5] = 0.18; Double_t emypar[6]; energyCalibration *thiscalibration = new energyCalibration(); thiscalibration->setScanSign(1); thiscalibration->setStartParametersKb(mypar); thiscalibration->fixParameter(0,0.); // no background thiscalibration->fixParameter(1,0.); TF1* fittedfun = thiscalibration->fitSpectrum(proj_peak,mypar,emypar); peak_fit_pos->Fill(mypar[2]); peak_fit_poserr->Fill(emypar[2]); peak_fit_pos_2d->Fill(i%NC,i/NC,mypar[2]); peak_fit_poserr_2d->Fill(i%NC,i/NC,emypar[2]); 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"; } proj_noise->Draw(); c1->Update(); proj_noise->GetXaxis()->SetTitle("Pedestal corrected ADC [ADU]"); TPaveStats *st0 = (TPaveStats*)proj_noise->FindObject("stats"); st0->SetX1NDC(0.65); st0->SetX2NDC(0.94); st0->SetY1NDC(0.75); st0->SetY2NDC(0.94); st0->SetBorderSize(0); sprintf(savename,"plots/M%s/CuFluo/proj_noise_%s_%d.png", module_str.c_str(), pixel_type.c_str(), i); c1->SaveAs((const char *)(savename)); proj_peak->Draw(); fittedfun->Draw("same"); c1->Update(); proj_peak->GetXaxis()->SetTitle("Pedestal corrected ADC [ADU]"); TPaveStats *st = (TPaveStats*)proj_peak->FindObject("stats"); st->SetX1NDC(0.22); st->SetX2NDC(0.55); st->SetY1NDC(0.55); st->SetY2NDC(0.94); st->SetBorderSize(0); sprintf(savename,"plots/M%s/CuFluo/proj_peak_%s_%d.png", module_str.c_str(), pixel_type.c_str(), i); c1->SaveAs((const char *)(savename)); } // gain gain_fit->Fill(mypar[2] - fit->GetParameter(1)); gain_fiterr->Fill(sqrt(pow(emypar[2],2) + pow(fit->GetParError(1),2))); gain_fit_2d->Fill(i%NC,i/NC,mypar[2] - fit->GetParameter(1)); gain_fiterr_2d->Fill(i%NC,i/NC,sqrt(pow(emypar[2],2) + pow(fit->GetParError(1),2))); gain_ADUper1keV_2d->Fill(i%NC,i/NC,(mypar[2] - fit->GetParameter(1)) / 8.0); gainerr_ADUper1keV_2d->Fill(i%NC,i/NC,sqrt(pow(emypar[2],2) + pow(fit->GetParError(1),2)) / 8.0); if (isEdge(i)) { gain_fit_isEdge->Fill(mypar[2] - fit->GetParameter(1)); } if (isInnerEdge(i)) { gain_fit_isInnerEdge->Fill(mypar[2] - fit->GetParameter(1)); } if (isDouble(i)) { gain_fit_isDouble->Fill(mypar[2] - fit->GetParameter(1)); } if (isNextToDouble(i)) { gain_fit_isNextToDouble->Fill(mypar[2] - fit->GetParameter(1)); } if (isQuad(i)) { gain_fit_isQuad->Fill(mypar[2] - fit->GetParameter(1)); } if (isBulk(i)) { gain_fit_isBulk->Fill(mypar[2] - fit->GetParameter(1)); } delete thiscalibration; delete proj_noise; delete proj_peak; delete proj; } else { pixel_mask[i] = 0; } } } sprintf(savename,"plots/M%s/CuFluo/pixelmask_afterfit.png", module_str.c_str()); pixelMaskObject->plotPixelMask(pixel_mask,savename); TCanvas *mapcanvas = new TCanvas("mapcanvas","",150,10,800,400); mapcanvas->SetLeftMargin(0.1); mapcanvas->SetRightMargin(0.13); mapcanvas->SetTopMargin(0.08); mapcanvas->SetBottomMargin(0.15); TPaveText *pave = new TPaveText(0.86,0.95,0.91,0.98,"blNDC"); pave->SetBorderSize(0); pave->SetFillStyle(0); pave->SetTextSize(0.06); pave->SetTextAlign(32); peak_fit_pos_2d->GetXaxis()->SetTitle("Column"); peak_fit_pos_2d->GetYaxis()->SetTitle("Row"); peak_fit_pos_2d->GetYaxis()->SetTitleOffset(0.7); peak_fit_pos_2d->Draw("colz"); peak_fit_pos_2d->GetZaxis()->SetRangeUser(250,400); sprintf(savename,"plots/M%s/CuFluo/peak_fit_pos_2d.png",module_str.c_str()); mapcanvas->SaveAs((const char *)(savename)); peak_fit_poserr_2d->GetXaxis()->SetTitle("Column"); peak_fit_poserr_2d->GetYaxis()->SetTitle("Row"); peak_fit_poserr_2d->GetYaxis()->SetTitleOffset(0.7); peak_fit_poserr_2d->Draw("colz"); peak_fit_poserr_2d->GetZaxis()->SetRangeUser(0,2); sprintf(savename,"plots/M%s/CuFluo/peak_fit_poserr_2d.png",module_str.c_str()); mapcanvas->SaveAs((const char *)(savename)); noise_fit_pos_2d->GetXaxis()->SetTitle("Column"); noise_fit_pos_2d->GetYaxis()->SetTitle("Row"); noise_fit_pos_2d->GetYaxis()->SetTitleOffset(0.7); noise_fit_pos_2d->Draw("colz"); noise_fit_pos_2d->GetZaxis()->SetRangeUser(-30,30); sprintf(savename,"plots/M%s/CuFluo/noise_fit_pos_2d.png",module_str.c_str()); mapcanvas->SaveAs((const char *)(savename)); noise_fit_poserr_2d->GetXaxis()->SetTitle("Column"); noise_fit_poserr_2d->GetYaxis()->SetTitle("Row"); noise_fit_poserr_2d->GetYaxis()->SetTitleOffset(0.7); noise_fit_poserr_2d->Draw("colz"); noise_fit_poserr_2d->GetZaxis()->SetRangeUser(0,0.05); sprintf(savename,"plots/M%s/CuFluo/noise_fit_poserr_2d.png",module_str.c_str()); mapcanvas->SaveAs((const char *)(savename)); gain_fit_2d->GetXaxis()->SetTitle("Column"); gain_fit_2d->GetYaxis()->SetTitle("Row"); gain_fit_2d->GetYaxis()->SetTitleOffset(0.7); gain_fit_2d->Draw("colz"); pave->AddText("G0 [ADU/8 keV]"); pave->Draw(); gain_fit_2d->GetZaxis()->SetRangeUser(250,400); sprintf(savename,"plots/M%s/CuFluo/gain_fit_2d.png",module_str.c_str()); mapcanvas->SaveAs((const char *)(savename)); gain_fiterr_2d->GetXaxis()->SetTitle("Column"); gain_fiterr_2d->GetYaxis()->SetTitle("Row"); gain_fiterr_2d->GetYaxis()->SetTitleOffset(0.7); gain_fiterr_2d->Draw("colz"); gain_fiterr_2d->GetZaxis()->SetRangeUser(0,2); sprintf(savename,"plots/M%s/CuFluo/gain_fiterr_2d.png",module_str.c_str()); mapcanvas->SaveAs((const char *)(savename)); gain_ADUper1keV_2d->GetXaxis()->SetTitle("Column"); gain_ADUper1keV_2d->GetYaxis()->SetTitle("Row"); gain_ADUper1keV_2d->GetYaxis()->SetTitleOffset(0.7); gain_ADUper1keV_2d->Draw("colz"); gain_ADUper1keV_2d->GetZaxis()->SetRangeUser(35,50); sprintf(savename,"plots/M%s/CuFluo/gain_ADUper1keV_2d.png",module_str.c_str()); mapcanvas->SaveAs((const char *)(savename)); gainerr_ADUper1keV_2d->GetXaxis()->SetTitle("Column"); gainerr_ADUper1keV_2d->GetYaxis()->SetTitle("Row"); gainerr_ADUper1keV_2d->GetYaxis()->SetTitleOffset(0.7); gainerr_ADUper1keV_2d->Draw("colz"); gainerr_ADUper1keV_2d->GetZaxis()->SetRangeUser(0,0.25); sprintf(savename,"plots/M%s/CuFluo/gainerr_ADUper1keV_2d.png",module_str.c_str()); mapcanvas->SaveAs((const char *)(savename)); c1->cd(); peak_fit_pos->GetXaxis()->SetTitle("Peak position [ADU]"); peak_fit_pos->Draw(); sprintf(savename,"plots/M%s/CuFluo/peak_fit_pos.png",module_str.c_str()); c1->SaveAs((const char *)(savename)); peak_fit_poserr->GetXaxis()->SetTitle("Peak position uncert [ADU]"); peak_fit_poserr->Draw(); sprintf(savename,"plots/M%s/CuFluo/peak_fit_poserr.png",module_str.c_str()); c1->SaveAs((const char *)(savename)); noise_fit_pos->GetXaxis()->SetTitle("Noise position [ADU]"); noise_fit_pos->Draw(); sprintf(savename,"plots/M%s/CuFluo/noise_fit_pos.png",module_str.c_str()); c1->SaveAs((const char *)(savename)); noise_fit_poserr->GetXaxis()->SetTitle("Noise position uncert [ADU]"); noise_fit_poserr->Draw(); sprintf(savename,"plots/M%s/CuFluo/noise_fit_poserr.png",module_str.c_str()); c1->SaveAs((const char *)(savename)); gain_fit->GetXaxis()->SetTitle("Gain G0 [ADU / 8 keV]"); gain_fit->Draw(); sprintf(savename,"plots/M%s/CuFluo/gain_fit.png",module_str.c_str()); c1->SaveAs((const char *)(savename)); gain_fit->Fit("gaus"); gain_fit->Draw(); sprintf(savename,"plots/M%s/CuFluo/gain_fit_fit.png",module_str.c_str()); c1->SaveAs((const char *)(savename)); gain_fiterr->GetXaxis()->SetTitle("Gain uncert [ADU / 8 keV]"); gain_fiterr->Draw(); sprintf(savename,"plots/M%s/CuFluo/gain_fiterr.png",module_str.c_str()); c1->SaveAs((const char *)(savename)); gain_fit_isEdge->SetLineColor(kBlue); gain_fit_isInnerEdge->SetLineColor(kCyan); gain_fit_isDouble->SetLineColor(kGreen+2); gain_fit_isNextToDouble->SetLineColor(kRed); gain_fit_isQuad->SetLineColor(kOrange); gain_fit_isEdge->Scale(1./gain_fit_isEdge->GetEntries()); gain_fit_isInnerEdge->Scale(1./gain_fit_isInnerEdge->GetEntries()); gain_fit_isDouble->Scale(1./gain_fit_isDouble->GetEntries()); gain_fit_isNextToDouble->Scale(1./gain_fit_isNextToDouble->GetEntries()); gain_fit_isQuad->Scale(1./gain_fit_isQuad->GetEntries()); gain_fit_isBulk->Scale(1./gain_fit_isBulk->GetEntries()); TLegend *leg = new TLegend(0.62,0.6,0.93,0.93); leg->AddEntry(gain_fit_isBulk, "Normal", "l"); leg->AddEntry(gain_fit_isDouble, "Double", "l"); leg->AddEntry(gain_fit_isNextToDouble, "Next to D", "l"); leg->AddEntry(gain_fit_isEdge, "Edge", "l"); leg->AddEntry(gain_fit_isInnerEdge, "Inner E", "l"); gain_fit_isDouble->GetXaxis()->SetTitle("Gain G0 [ADU / 8 keV]"); gain_fit_isDouble->GetYaxis()->SetTitle("Normalised"); gain_fit_isDouble->GetYaxis()->SetTitleOffset(1.3); gain_fit_isDouble->SetMinimum(0.0); gain_fit_isDouble->SetMaximum(0.16); gain_fit_isDouble->Draw(); gain_fit_isEdge->Draw("same"); gain_fit_isInnerEdge->Draw("same"); gain_fit_isNextToDouble->Draw("same"); gain_fit_isBulk->Draw("same"); leg->Draw("same"); sprintf(savename,"plots/M%s/CuFluo/gain_fit_perType.png", module_str.c_str()); c1->SaveAs((const char *)(savename)); sprintf(savename,"data/M%s/CuF_gain_M%s.root", module_str.c_str(), module_str.c_str()); TFile* saved_file = new TFile((const char *)(savename),"RECREATE"); gain_ADUper1keV_2d->Write(); gainerr_ADUper1keV_2d->Write(); saved_file->Close(); }