cal1ePeaks.cxx 3.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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
//script for calibration of each pixel of MAPMT
//#include

using namespace std;

void cal1ePeaks()
{

	TString location = "../data/WPT_tests";

	//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.root", location.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 = "cal1e_HV1000.par";
//	TString oFile = "cal1e_HV950.par";
//	TString oFile = "cal1e_HV900.par";

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

	ofstream calFile;
	calFile.open(oFile.Data());
	if (calFile.is_open()) {
		Info("calPeaks", "Calibration parameters will be saved in %s.", oFile.Data());
	} else {
		Error("calPeaks", "File %s was not open.", oFile.Data());
		return;
	}

	//2D histogram to be calibrated
	TString histName = "adcAllWoBaseline";

	//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("calPeaks", "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());

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

}