cal1ePeaks.cxx 3.76 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
	TString suffix = "_nonLin";
11 12 13

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

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

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

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


///////////////////////////////////////////////////////////	
	TFile *fr = new TFile(iFile.Data());
61 62 63 64
	if (fr->IsZombie()) {
		Error("cal1ePeaks.cxx", "Files %s was not open.", iFile.Data());
		return;
	}
65 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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

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

}

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

}