diff --git a/JFMC_CuFluoPeakFit.cpp b/JFMC_CuFluoPeakFit.cpp index 5230325..c80f985 100644 --- a/JFMC_CuFluoPeakFit.cpp +++ b/JFMC_CuFluoPeakFit.cpp @@ -39,6 +39,10 @@ int main(int argc, char* argv[]) { 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); @@ -61,8 +65,10 @@ int main(int argc, char* argv[]) { TH1F* gain_fit_isQuad = new TH1F("gain_fit_isQuad","",100,250,400); TH1F* gain_fit_isBulk = new TH1F("gain_fit_isBulk","",100,250,400); - float noise_pos; - float noise_err; + 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; @@ -76,67 +82,30 @@ int main(int argc, char* argv[]) { if (i%10000==0){cout << "another 10k" << endl;} TH1D* proj = adc2d_j->ProjectionX("bin1",i-(65536*(j-1))+1,i-(65536*(j-1))+1); - proj->Draw(); - - if (proj->Integral(100,300)!=0 && proj->Integral(300,600)!=0) { - proj->Rebin(4); - proj->SetStats(kTRUE); + if (proj->Integral(low_bin_noise,high_bin_noise)!=0 && proj->Integral(low_bin_peak,high_bin_peak)!=0) { // noise - proj->GetXaxis()->SetRangeUser(-100,100); - proj->Fit("gaus","Q","",-50,50); - proj->Draw(); - c1->Update(); - TF1 *fit = proj->GetFunction("gaus"); - noise_pos = fit->GetParameter(1); - noise_err = fit->GetParError(1); - noise_fit_pos->Fill(noise_pos); - noise_fit_pos_2d->Fill(i%NC,i/NC,noise_pos); - noise_fit_poserr->Fill(noise_err); - noise_fit_poserr_2d->Fill(i%NC,i/NC,noise_err); + 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"); - 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->GetXaxis()->SetTitle("Pedestal corrected ADC [ADU]"); - TPaveStats *st0 = (TPaveStats*)proj->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)); - } + 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 - proj->GetXaxis()->SetRangeUser(100,400); + 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->GetBinCenter(proj->GetMaximumBin()); + mypar[2] = proj_peak->GetBinCenter(proj_peak->GetMaximumBin()); mypar[3] = 19.; mypar[4] = 60.; mypar[5] = 0.18; @@ -147,7 +116,7 @@ int main(int argc, char* argv[]) { thiscalibration->setStartParametersKb(mypar); thiscalibration->fixParameter(0,0.); // no background thiscalibration->fixParameter(1,0.); - TF1* fittedfun = thiscalibration->fitSpectrum(proj,mypar,emypar); + TF1* fittedfun = thiscalibration->fitSpectrum(proj_peak,mypar,emypar); peak_fit_pos->Fill(mypar[2]); peak_fit_poserr->Fill(emypar[2]); @@ -177,11 +146,23 @@ int main(int argc, char* argv[]) { pixel_type = "q"; } - proj->Draw(); + 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->GetXaxis()->SetTitle("Pedestal corrected ADC [ADU]"); - TPaveStats *st = (TPaveStats*)proj->FindObject("stats"); + 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); @@ -192,36 +173,44 @@ int main(int argc, char* argv[]) { } // gain - gain_fit->Fill(mypar[2] - noise_pos); - gain_fiterr->Fill(sqrt(pow(emypar[2],2) + pow(noise_err,2))); - gain_fit_2d->Fill(i%NC,i/NC,mypar[2] - noise_pos); - gain_fiterr_2d->Fill(i%NC,i/NC,sqrt(pow(emypar[2],2) + pow(noise_err,2))); + 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))); if (isEdge(i)) { - gain_fit_isEdge->Fill(mypar[2] - noise_pos); + gain_fit_isEdge->Fill(mypar[2] - fit->GetParameter(1)); } if (isInnerEdge(i)) { - gain_fit_isInnerEdge->Fill(mypar[2] - noise_pos); + gain_fit_isInnerEdge->Fill(mypar[2] - fit->GetParameter(1)); } if (isDouble(i)) { - gain_fit_isDouble->Fill(mypar[2] - noise_pos); + gain_fit_isDouble->Fill(mypar[2] - fit->GetParameter(1)); } if (isNextToDouble(i)) { - gain_fit_isNextToDouble->Fill(mypar[2] - noise_pos); + gain_fit_isNextToDouble->Fill(mypar[2] - fit->GetParameter(1)); } if (isQuad(i)) { - gain_fit_isQuad->Fill(mypar[2] - noise_pos); + gain_fit_isQuad->Fill(mypar[2] - fit->GetParameter(1)); } if (isBulk(i)) { - gain_fit_isBulk->Fill(mypar[2] - noise_pos); + 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); diff --git a/run_JFModuleCalib_CuFBDCS.txt b/run_JFModuleCalib_CuFBDCS.txt index 3cff3be..1eca76e 100644 --- a/run_JFModuleCalib_CuFBDCS.txt +++ b/run_JFModuleCalib_CuFBDCS.txt @@ -35,10 +35,12 @@ Module 022 - 1M bottom LCLS, PX Module 027 - old HDI (no current source scan). sent to ESRF with Paolo ./JFMC_CuFluoPeak 027 /data_pool/Module_027_Calib FCu_40kvp_60mA_10us_500Hz_QS_pede FCu_40kvp_60mA_10us_500Hz_QS_beam +./JFMC_CuFluoPeakFit 027 Module 040 - partly etched. sent to ESRF with Paolo ./JFMC_CuFluoPeak 040 /data_pool/Module_040_Calib Cu_FLuo_240317_500Hz_10us_QS_pede Cu_FLuo_240317_500Hz_10us_QS_beam +./JFMC_CuFluoPeakFit 040 ./JFMC_CurrentSourceScan 040 /data_pool/Module_040_Calib CS_240322_scan