extract1DHists.cxx 4.9 KB
Newer Older
1 2 3 4 5
void extract1DHists()
{

	//output in channel units
//	TString outputFile = "histOutput.root";
6
	TString outputFile = "objects/histOutput680.root";
7 8

	//output in 1e units
9 10
//	TString outputFile = "histOutput1e_HV1000.root";
//	TString outputFile = "histOutput1e_HV950.root";
11 12

	TString histName = "adcAllWoBaseline";
13
//	TString histName = "cal1eAdcAllWoBaseline";
14 15

	TString location = "../data/WPT_tests";
16 17
	TString suffix = "";
//	TString suffix = "_HV1000";
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 143 144 145 146 147 148 149 150 151 152 153 154 155

	TString f0, f1, f2, f3, f4,
	f10, f11, f12, f13,
	f20, f21, f22;

	f0.Form("%s/680pF_10okt_chargeCalib/pedestals_10okt_withGenerator_woPMT_scan_0000%s.root", location.Data(), suffix.Data());
	f1.Form("%s/680pF_10okt_chargeCalib/pedestals_10okt_withGenerator_woPMT_scan_0001%s.root", location.Data(), suffix.Data());
	f2.Form("%s/680pF_10okt_chargeCalib/pedestals_10okt_withGenerator_woPMT_scan_0002%s.root", location.Data(), suffix.Data());
	f3.Form("%s/680pF_10okt_chargeCalib/pedestals_10okt_withGenerator_woPMT_scan_0003%s.root", location.Data(), suffix.Data());
	f4.Form("%s/680pF_10okt_chargeCalib/pedestals_10okt_withGenerator_woPMT_scan_0004%s.root", location.Data(), suffix.Data());

	f10.Form("%s/680pF_11okt_chargeCalib/pedestals_11okt_withGenerator_woPMT_scan_0000%s.root", location.Data(), suffix.Data());
	f11.Form("%s/680pF_11okt_chargeCalib/pedestals_11okt_withGenerator_woPMT_scan_0001%s.root", location.Data(), suffix.Data());
	f12.Form("%s/680pF_11okt_chargeCalib/pedestals_11okt_withGenerator_woPMT_scan_0002%s.root", location.Data(), suffix.Data());
	f13.Form("%s/680pF_11okt_chargeCalib/pedestals_11okt_withGenerator_woPMT_scan_0003%s.root", location.Data(), suffix.Data());

	f20.Form("%s/680pF_14okt_measure_chargeCalib/pedestals_14oct_Generator_thr35_woPMT_680pF_0000%s.root", location.Data(), suffix.Data());
	f21.Form("%s/680pF_14okt_measure_chargeCalib/pedestals_14oct_Generator_thr35_woPMT_680pF_0001%s.root", location.Data(), suffix.Data());
	f22.Form("%s/680pF_14okt_measure_chargeCalib/pedestals_14oct_Generator_thr35_woPMT_680pF-a_0000%s.root", location.Data(), suffix.Data());

	TFile *fr0 = new TFile(f0.Data());
	TFile *fr1 = new TFile(f1.Data());
	TFile *fr2 = new TFile(f2.Data());
	TFile *fr3 = new TFile(f3.Data());
	TFile *fr4 = new TFile(f4.Data());

	TFile *fr10 = new TFile(f10.Data());
	TFile *fr11 = new TFile(f11.Data());
	TFile *fr12 = new TFile(f12.Data());
	TFile *fr13 = new TFile(f13.Data());

	TFile *fr20 = new TFile(f20.Data());
	TFile *fr21 = new TFile(f21.Data());
	TFile *fr22 = new TFile(f22.Data());

	if (fr0->IsZombie() || fr1->IsZombie() || fr2->IsZombie() || fr3->IsZombie() || fr4->IsZombie()
			 || fr10->IsZombie() || fr12->IsZombie() || fr12->IsZombie() || fr13->IsZombie()
			 || fr20->IsZombie() || fr21->IsZombie() || fr22->IsZombie()) {
		Error("extract1DHists", "One of files was not open.");
		return;
	}

	TH2D *hraw0 = (TH2D*)fr0->Get(histName.Data());
	TH2D *hraw1 = (TH2D*)fr1->Get(histName.Data());
	TH2D *hraw2 = (TH2D*)fr2->Get(histName.Data());
	TH2D *hraw3 = (TH2D*)fr3->Get(histName.Data());
	TH2D *hraw4 = (TH2D*)fr4->Get(histName.Data());

	TH2D *hraw10 = (TH2D*)fr10->Get(histName.Data());
	TH2D *hraw11 = (TH2D*)fr11->Get(histName.Data());
	TH2D *hraw12 = (TH2D*)fr12->Get(histName.Data());
	TH2D *hraw13 = (TH2D*)fr13->Get(histName.Data());

	TH2D *hraw20 = (TH2D*)fr20->Get(histName.Data());
	TH2D *hraw21 = (TH2D*)fr21->Get(histName.Data());
	TH2D *hraw22 = (TH2D*)fr22->Get(histName.Data());
	TH2D *hSum2 = new TH2D(*hraw20);
	hSum2->Add(hraw21);
	hSum2->Add(hraw22);



//	extractHist()

//return;	

	TH2D *hSum = new TH2D(*hraw1);
	hSum->Add(hraw3);
	hSum->Add(hraw4);
	hSum->Add(hraw11);
	hSum->Add(hraw2);
	hSum->Add(hraw1);
	hSum->Add(hraw12);

	TCanvas *c1 = new TCanvas();
	c1->Divide(2,2);

	c1->cd(1);
	hSum->GetXaxis()->SetRangeUser(0, 64);
	hSum->Draw();

	c1->cd(2);
	hSum2->GetXaxis()->SetRangeUser(0, 64);
	hSum2->Draw();



	TFile *fw = new TFile(outputFile.Data(), "RECREATE");
	TH1D *hch[64];

	for (Int_t i = 0; i < 64; i++) {
		hch[i] = extractHist(hSum, i);
		//file fr10
		if (i == 17 || i == 21 || i == 25 || i == 29 || i == 33 || i == 37 || i == 41 || i == 45) {
			hch[i] = extractHist(hraw10, i);
		}
		//files fr2*
		if (i == 9 || i == 12 || i == 13 || i == 14 || i == 26 || i == 31 || /*i == 42 ||*/ i == 45 || i == 53 || i == 60) {
			hch[i] = extractHist(hSum2, i);
		}
		if (i == 42) {
			hch[i]->Add( extractHist(hSum2, i) );
		}
		fw->cd();
		hch[i]->Write();
	}

	fw->Close();
	
	return;

}

TH1D* extractHist(TH2D *hInput, Int_t channel) {

	TH1D *hTemp;
	TString hName;
	TString hTitle;
	
	hName.Form("ch%d", channel);
	hTitle.Form("channel %d", channel);
	hTemp = hInput->ProjectionY(hName.Data(), channel+1, channel+1);
	hTemp->SetTitle(hTitle.Data());
//	hTemp->GetXaxis()->SetRangeUser(0, 2000);
//	hTemp->Fit("gaus", "", "", 100, 400);
//	calFile << i << "\t" << gaus->GetParameter(1) << endl;
//	Int_t cNumber = i/6;
//	cout << cNumber << endl;
//	cWork[cNumber]->cd(i-6*cNumber+1);
//	hTemp->Draw();



	

	return hTemp;

}