//script for calibration of each pixel of MAPMT //#include using namespace std; void cal1ePeaks() { TString location = "../data/WPT_tests"; // TString suffix = "_nonLin"; TString suffix = ""; //name of input root file TString iFile; iFile.Form("%s/680pF_11okt_measure_with_opt_grease/HV1000_Sci_mounted_Am241in_front_10cm_thr32_nxtrim1_11oct_30min_0000%s.root", location.Data(), suffix.Data()); // iFile.Form("%s/680pF_11okt_measure_with_opt_grease/HV950_Sci_mounted_Am241in_front_10cm_thr32_nxtrim1_11oct_30min_0000.root", location.Data()); // iFile.Form("%s/680pF_11okt_measure_with_opt_grease/HV900_Sci_mounted_Am241in_front_10cm_thr28_nxtrim1_11oct_30min_0000.root", location.Data()); //name of file with calibration parameters TString oFile = "parameters/cal1e_HV1000_nonLin.par"; // TString oFile = "cal1e_HV950.par"; // TString oFile = "cal1e_HV900.par"; //name of file with peak ranges TString pFile = "../parameters/peaksRange1000HV.par"; // TString pFile = "../parameters/peaksRange950HV.par"; // TString pFile = ""; //2D histogram to be calibrated // TString histName = "adcAllWoBaseline"; TString histName = "fhAdcAllWoBaselineNLcorr"; ofstream calFile; calFile.open(oFile.Data()); if (calFile.is_open()) { Info("cal1ePeaks.cxx", "Calibration parameters will be saved in %s.", oFile.Data()); } else { Error("cal1ePeaks.cxx", "File %s was not open.", oFile.Data()); return; } //xaxis range const Double_t xmin = 0; const Double_t xmax = 600.; Bool_t useParFile = 1; if ( pFile.Length() == 0 ) useParFile = 0; ifstream parFile; if (useParFile) { parFile.open(pFile.Data()); if (!parFile.is_open()) { Error("cal1ePeaks.cxx", "File with input parameters %s was not open.", pFile.Data()); return; } Info("calPeaks", "File with peak ranges %s will be loaded.", pFile.Data()); } /////////////////////////////////////////////////////////// TFile *fr = new TFile(iFile.Data()); if (fr->IsZombie()) { Error("cal1ePeaks.cxx", "Files %s was not open.", iFile.Data()); return; } TH2D *h2 = (TH2D*)fr->Get(histName.Data()); TCanvas *c1 = new TCanvas(); c1->Divide(2,2); c1->cd(1); h2->Draw(); c1->cd(2); TH1D *h1 = h2->ProjectionY("ch1", 64, 64); h1->Draw(); c1->cd(4); TH1D *h1 = h2->ProjectionY("ch2", 1, 1); h1->Draw(); c1->cd(3); // h2->SetShowProjection(); TH1D *hTemp; TString hName; TString hTitle; //canvases for calibration TString cName; TString cTitle; const Int_t pads = 9; const Int_t noCanvas = 64/pads+1; TCanvas *cWork[noCanvas]; for (Int_t i = 0; i < noCanvas; i++) { cName.Form("can%d", i); cTitle.Form("canvas %d", i); cWork[i] = new TCanvas(cName.Data(), cTitle.Data(), 0, 0, 960, 700); // cWork[i]->SetName(cName.Data()); // cWork[i]->SetTitle(cTitle.Data()); if (pads == 6) cWork[i]->Divide(2, 3); if (pads == 9) cWork[i]->Divide(3, 3); cWork[i]->cd(1); } string line; Int_t ch = 0, min = 0, max = 0; for (Int_t i = 0; i < 64; i++) { hName.Form("ch%d", i); hTitle.Form("channel %d", i); hTemp = h2->ProjectionY(hName.Data(), i+1, i+1); hTemp->SetTitle(hTitle.Data()); hTemp->GetXaxis()->SetRangeUser(0, 2000); Int_t cNumber = i/pads; cWork[cNumber]->cd(i-pads*cNumber+1); hTemp->Draw(); hTemp->GetXaxis()->SetRangeUser(xmin, xmax); hTemp->GetXaxis()->CenterTitle(); hTemp->GetXaxis()->SetTitle("A*"); hTemp->GetXaxis()->SetTitleSize(0.06); hTemp->GetXaxis()->SetTitleOffset(0.75); hTemp->GetYaxis()->SetTitle("counts"); if (useParFile) { std::getline(parFile, line); std::istringstream(line,ios_base::in) >> ch >> min >> max; cout << i << "\t" << min << "\t" << max << endl; hTemp->Fit("gaus", "q", "", min, max); } else hTemp->Fit("gaus", "q", "", 100, 400); calFile << i << "\t" << gaus->GetParameter(1) << endl; } calFile.close(); // cWork[0]->SaveAs("figures/cal1e.png"); } void fillParFilePreliminary(Int_t noChannels, Int_t min, Int_t max) { ofstream parFile; parFile.open("parTemplate.par"); for (Int_t i = 0; i < noChannels; i++) { parFile << i << "\t" << min << "\t" << max << endl; } parFile.close(); }