extract1DHists47.cxx 1.55 KB
Newer Older
1 2 3 4 5 6
void extract1DHists47()
{

	//output in channel units
	TString outputFile = "objects/histOutput47.root";

7
	TString histName = "fhAdcAllWoBaselineNLcorr";
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

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

	TString f0, f1;

	f0.Form("%s/4.7nF_11okt_chargeCalib/TestTriggerMode_chargeCalib_3V_100ns_4.7nF_11oct_0000.root", location.Data());
	f1.Form("%s/4.7nF_11okt_chargeCalib/TestTriggerMode_chargeCalib_3V_100ns_4.7nF_11oct_0001.root", location.Data());

	TFile *fr0 = new TFile(f0.Data());
	TFile *fr1 = new TFile(f1.Data());

	if (fr0->IsZombie() || fr1->IsZombie()) {
		Error("extract1DHists47.cxx", "One of files was not open.");
		return;
	}

	TH2D *hraw0 = (TH2D*)fr0->Get(histName.Data());
	TH2D *hraw1 = (TH2D*)fr1->Get(histName.Data());

29 30 31 32 33
	if (!hraw0 || !hraw1) {
		Error("extract1DHists47.cxx", "At least one of histograms was not found.");
		return;
	}

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
	TH2D *hSum = new TH2D(*hraw0);
	hSum->Add(hraw1);

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

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

	c1->cd(2);


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

	for (Int_t i = 0; i < 64; i++) {
		hch[i] = extractHist(hSum, 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());

	return hTemp;

}