opentrees.cxx 3.19 KB
Newer Older
Vratislav Chudoba's avatar
Vratislav Chudoba committed
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
#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include "TF1.h"
#include "TH1F.h"

void opentrees()
{



//	TFile *fr1 = new TFile("simevents-1.root");
	TFile *fr1 = new TFile("simeventsNew.root");
	TFile *fr2 = new TFile("simevents-2.root");
	TFile *fr = new TFile("simevents.root");

	TTree *tr1 = (TTree*)fr1->Get("simevents");
	TTree *tr2 = (TTree*)fr2->Get("simevents");
	TTree *tr = (TTree*)fr->Get("simevents");

	TCanvas *c1 = new TCanvas("name1", "title of canvas");
	c1->Divide(2,2);

	c1->cd(1);
	tr->Draw("E", "E>0");

	c1->cd(2);
	tr1->Draw("E", "E>0");

	c1->cd(3);
	tr2->Draw("E", "E>0");


	c1->cd(4);
	tr->Draw("E", "E>0.95");
	tr1->SetLineColor(kRed);
	tr1->Draw("E", "E>0", "same");
	tr2->SetLineColor(kBlue);
	tr2->Draw("E", "E>0", "same");

	TCanvas *c2 = new TCanvas("name2", "title of canvas");
	c2->Divide(2,2);

	c2->cd(1);
	tr->Draw("E", "E>0.95");
	TH1F *h = (TH1F*)gPad->GetPrimitive("htemp");

	c2->cd(2);
//	fr.cd();
	TH1F *hE = new TH1F("hE", "histogram title", 100, 0.95, 1.4);
	hE->Draw();
	tr->Draw("E >> hE", "", "");

	TF1 *g1 = new TF1("m1","gaus",1.,1.15);
	TF1 *g2 = new TF1("m2","gaus",1.2,1.3);
	// The total is the sum of the three, each has 3 parameters
	TF1 *total = new TF1("mstotal","gaus(0)+gaus(3)",1.,1.3);


	Double_t par[6];

	// Fit each function and add it to the list of functions
	hE->Fit(g1,"R");
	hE->Fit(g2,"R+");


	c2->cd(3);
	TH1F *hEtot = new TH1F("hEtot", "histogram title", 100, 0.95, 1.4);
	hEtot->Draw();
	tr->Draw("E >> hEtot", "", "");
	// Get the parameters from the fit
	g1->GetParameters(&par[0]);
	g2->GetParameters(&par[3]);

	// Use the parameters on the sum
	total->SetParameters(par);
	hEtot->Fit(total,"R+");

		TCanvas *c3 = new TCanvas("name3", "title of canvas 3");
		c3->Divide(2,2);

		c3->cd(1);
		tr1->Draw("E", "E>0.95");
//		TH1F *h = (TH1F*)gPad->GetPrimitive("htemp");

		c3->cd(2);
	//	fr.cd();
		TH1F *hE1 = new TH1F("hE1", "histogram title", 100, 0.95, 1.4);
		hE1->Draw();
		tr1->Draw("E >> hE1", "", "");

		TF1 *g11 = new TF1("m11","gaus",1.,1.15);
		TF1 *g21 = new TF1("m21","gaus",1.2,1.3);
		// The total is the sum of the three, each has 3 parameters
		TF1 *total1 = new TF1("mstotal1","gaus(0)+gaus(3)",1.,1.3);


		Double_t par1[6];

		// Fit each function and add it to the list of functions
		hE1->Fit(g11,"R");
		hE1->Fit(g21,"R+");


		c3->cd(3);
		TH1F *hEtot1 = new TH1F("hEtot1", "histogram title", 100, 0.95, 1.4);
		hEtot1->Draw();
		tr1->Draw("E >> hEtot1", "", "");
		// Get the parameters from the fit
		g11->GetParameters(&par1[0]);
		g21->GetParameters(&par1[3]);

		// Use the parameters on the sum
		total1->SetParameters(par1);
		hEtot1->Fit(total1,"R+");


		c3->cd(4);
		TH1F *hEtot11 = new TH1F("hEtot11", "histogram title", 100, 0.95, 1.4);
		tr1->Draw("E >> hEtot11", "", "");

		Double_t par12[6];
		total1->GetParameters(&par12[0]);
		TF1 *gLow = new TF1("mLow","gaus",0.95,1.2);
		TF1 *gHigh = new TF1("mHigh","gaus",1.0,1.4);
		gHigh->SetLineColor(kGreen);

		gLow->SetParameter(0, par12[0]);
		gLow->SetParameter(1, par12[1]);
		gLow->SetParameter(2, par12[2]);

		gHigh->SetParameter(0, par12[3]);
		gHigh->SetParameter(1, par12[4]);
		gHigh->SetParameter(2, par12[5]);

		gLow->Draw("same");
		gHigh->Draw("same");




}