cal1ePeaks.cxx 4.04 KB
Newer Older
1 2 3 4 5 6 7 8 9
//script for calibration of each pixel of MAPMT
//#include

using namespace std;

void cal1ePeaks()
{

	TString location = "../data/WPT_tests";
10 11
//	TString suffix = "_nonLin";
	TString suffix = "";
12 13 14

	//name of input root file
	TString iFile;
15 16
//	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());
17 18 19
//	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
20
	TString oFile = "parameters/cal1e_HV1000_nonLin.par";
21
	TString oFile = "parameters/cal1e_HV950_nonLin.par";
22 23 24
//	TString oFile = "cal1e_HV900.par";

	//name of file with peak ranges
25 26
//	TString pFile = "../parameters/peaksRange1000HV.par";
	TString pFile = "../parameters/peaksRange950HV.par";
27 28
//	TString pFile = "";

29 30
	//2D histogram to be calibrated
//	TString histName = "adcAllWoBaseline";
31
	TString histName = "fhAdcAllWoBaselineNLcorr";
32

33 34 35
	ofstream calFile;
	calFile.open(oFile.Data());
	if (calFile.is_open()) {
36
		Info("cal1ePeaks.cxx", "Calibration parameters will be saved in %s.", oFile.Data());
37
	} else {
38
		Error("cal1ePeaks.cxx", "File %s was not open.", oFile.Data());
39 40 41 42 43 44 45 46 47 48 49 50 51 52
		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()) {
53
			Error("cal1ePeaks.cxx", "File with input parameters %s was not open.", pFile.Data());
54 55 56 57 58 59 60 61
			return;
		}
		Info("calPeaks", "File with peak ranges %s will be loaded.", pFile.Data());
	}


///////////////////////////////////////////////////////////	
	TFile *fr = new TFile(iFile.Data());
62 63 64 65
	if (fr->IsZombie()) {
		Error("cal1ePeaks.cxx", "Files %s was not open.", iFile.Data());
		return;
	}
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

	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);
125 126 127 128 129
		hTemp->GetXaxis()->CenterTitle();
		hTemp->GetXaxis()->SetTitle("A*");
		hTemp->GetXaxis()->SetTitleSize(0.06);
		hTemp->GetXaxis()->SetTitleOffset(0.75);
		hTemp->GetYaxis()->SetTitle("counts");
130 131 132 133 134 135 136 137 138 139 140 141
		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();	

142 143
//	cWork[0]->SaveAs("figures/cal1e.png");

144 145 146 147 148 149 150 151 152 153 154 155 156
}

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();

}