ROOT logo
/*
 *  CalcET.C
 */

void CalcET(const char* fileName, const char* fileNameMC)
{
	// open the input file
	TFile *file = new TFile(fileName);
	
	// ********************************************
	// parameters to check before running the macro
	// ********************************************
	
	const Int_t NCUTS = 3; // Choose the number of cuts to check
	Float_t eCut[NCUTS] = {0.25,0.5,0.75}; // Choose the value of the cuts
	Float_t ptCut[NCUTS] = {0.25,0.5,0.75}; // Choose the value of the cuts
	Double_t matchCut = 0.02;
	
	const Int_t fgNumOfEBins = 78; // Check the number of eta bins in the histograms
	const Int_t fgNumOfEtaBins = 16; // Check the number of E bins in the histograms
	const Int_t fgNumOfPtBins = 111; // Check the number of pT bins in the histograms
	
	// declare histograms and graphs
	TGraphErrors *graph[NCUTS];
	
	// retrieve the input list of histogram. Check the TList name in the input file.
	TList *list = (TList*) file->Get("out1");
	
	// retrieve the histograms in the list. Check the name of the histograms
	THnSparseD* histAll = (THnSparseD*)list->FindObject("fHistAllRec_ETDep_EmcalRec");

	THnSparseD* hnSparse = (THnSparseD*)list->FindObject("fHistMuon_ETDep_EmcalRec");
	hnSparse->GetAxis(6)->SetRangeUser(0.,matchCut);
	TH3D* histMuon = hnSparse->Projection(2,0,1);
	
	hnSparse = (THnSparseD*)list->FindObject("fHistMuon_ETDep_EmcalRec");
	hnSparse->GetAxis(6)->SetRangeUser(0.,matchCut);
	
	hnSparse = (THnSparseD*)list->FindObject("fHistMuon_ETDep_EmcalRec");
	hnSparse->GetAxis(6)->SetRangeUser(0.,matchCut);
	TH3D* histPion = ((THnSparseD*)list->FindObject("fHistPion_ETDep_EmcalRec"))->Projection(2,0,1);
	
	hnSparse = (THnSparseD*)list->FindObject("fHistMuon_ETDep_EmcalRec");
	hnSparse->GetAxis(6)->SetRangeUser(0.,matchCut);
	TH3D* histKaon = ((THnSparseD*)list->FindObject("fHistKaon_ETDep_EmcalRec"))->Projection(2,0,1);
	
	hnSparse = (THnSparseD*)list->FindObject("fHistMuon_ETDep_EmcalRec");
	hnSparse->GetAxis(6)->SetRangeUser(0.,matchCut);
	TH3D* histProton = ((THnSparseD*)list->FindObject("fHistProton_ETDep_EmcalRec"))->Projection(2,0,1);
	
	TH3D* histCharged = new TH3D(*histMuon);
	histCharged->Add(histPion);
	histCharged->Add(histKaon);
	histCharged->Add(histProton);
	
	TEfficiency *efficClu = CalcEffic(fileNameMC);
	TEfficiency *efficChHad = CalcEfficHadrons(fileNameMC);
	Double_t f_acc = CalcCorrAcc(fileNameMC);
	Double_t f_Ecut = CalcCorrEcut(fileNameMC);
	Double_t f_neutral = CalcCorrNeutral(fileNameMC);
	
	// ********************************************
	
	Float_t x[fgNumOfEtaBins]={0}, ex[fgNumOfEtaBins]={0};
	Float_t y[fgNumOfEtaBins]={0}, ey[fgNumOfEtaBins]={0};
	
	// loop over different E cuts
	for (int iCut=0; iCut<NCUTS; iCut++)
	{
		// loop over eta bins
		for (int iy=0; iy<fgNumOfEtaBins; iy++)
		{
			// initialize ET variables for a new particle species
			Float_t E=0, pt=0, ET=0, ET_All=0, ET_Had=0, errorSqET_All=0, errorSqET_Had=0;
			x[iy]=0;
			y[iy]=0;
			ex[iy]=0;
			ey[iy]=0;
			
			// loop over E bins
			for (int ix=0; ix<fgNumOfEBins; ix++)
			{
				E = histAll->GetXaxis()->GetBinCenter(ix+1);
				if (E > eCut[iCut])
				{
					ET = histAll->GetBinContent(ix+1,iy+1); // sum over all E bins in order to get total ET
					errorSqET_All += pow(E_err(E)*(ET/E),2);
					ET_All += ET/efficClu->GetEfficiency(ix);
										
				}				
				
				// loop over pt bins
				for (int iz=0; iz<fgNumOfPtBins; iz++)
				{
					pt = histCharged->GetZaxis()->GetBinCenter(iz+1);
					if (pt > ptCut[iCut])
					{
						ET = histCharged->GetBinContent(ix+1,iy+1,iz+1); // sum over all pt bins in order to get total ET
						errorSqET_Had += pow(E_err(E)*(ET/E),2);
						ET_Had += ET/efficChHad->GetEfficiency(iz);
					}				
				} // end of loop over pt bins
				
			} // end of loop over E bins

			x[iy] = histChHad->GetYaxis()->GetBinCenter(iy+1); // x coordinate of eta bin
			
			y[iy] = (ET_All-(ET_Had/f_neutral))/(f_acc*f_Ecut); // y coordinate of eta bin (for a given particle species)
			
			ey[iy]=(sqrt(errorSqET_AllHad + errorSqET_Had/pow(f_neutral,2))/(f_acc*f_Ecut);
			
		} // end of loop over eta bins
		
		graph[iCut] = new TGraphErrors(fgNumOfEtaBins,x,y,ex,ey); // graphic of ET(>E_cut)/ET(total) for a given E cut (all particle species combined)
	} // end of loop over different E cuts
	
	
	// Draw the plot
	
	gStyle->SetOptTitle(0);
	gStyle->SetOptStat(0);
	gStyle->SetOptFit(0);	
	
	TCanvas *c = new TCanvas("c","c",500,400);
	//c->SetTopMargin(0.04);
	//c->SetRightMargin(0.04);
	//c->SetLeftMargin(0.181452);
	//c->SetBottomMargin(0.134409);
	c->SetBorderSize(0);
	c->SetFillColor(0);
	c->SetBorderMode(0);
	c->SetFrameFillColor(0);
	c->SetFrameBorderMode(0);
	
	Int_t style[NCUTS] = {20,21,22};
	Int_t color[NCUTS] = {2,3,4};
	
	for (int i=0; i<NCUTS; i++)
	{
		graph[i]->SetMarkerStyle(style[i]);
		graph[i]->SetMarkerColor(color[i]);
		graph[i]->SetLineColor(color[i]);
		graph[i]->SetFillColor(0);
		if (i == 0) 
		{
			graph[i]->GetXaxis()->SetTitle("#eta");
			graph[i]->GetYaxis()->SetTitle("E_{T}^{Neutral+Charged Hadrons}/E_{T}^{Charged hadrons}");
			//graph[i]->SetMaximum(1.0);
			graph[i]->SetMinimum(0.0);
			graph[i]->Draw("AP");
		}
		else
			graph[i]->Draw("P");
	}
	
	TLegend *leg = new TLegend(0.65,0.2,0.95,0.5);
	leg->AddEntry(graph[0],"E>250 MeV");
	leg->AddEntry(graph[1],"E>500 MeV");
	leg->AddEntry(graph[2],"E>750 MeV");
	leg->SetFillStyle(0);
	leg->SetFillColor(0);
	leg->SetBorderSize(0);
	leg->SetTextSize(0.03);
	leg->Draw();	
}

Float_t E_err(Float_t E)
{
	return (E*sqrt(pow(4.35/E,2)+pow(9.07,2)/E+pow(1.63,2)))/100;	
}
 CalcET.C:1
 CalcET.C:2
 CalcET.C:3
 CalcET.C:4
 CalcET.C:5
 CalcET.C:6
 CalcET.C:7
 CalcET.C:8
 CalcET.C:9
 CalcET.C:10
 CalcET.C:11
 CalcET.C:12
 CalcET.C:13
 CalcET.C:14
 CalcET.C:15
 CalcET.C:16
 CalcET.C:17
 CalcET.C:18
 CalcET.C:19
 CalcET.C:20
 CalcET.C:21
 CalcET.C:22
 CalcET.C:23
 CalcET.C:24
 CalcET.C:25
 CalcET.C:26
 CalcET.C:27
 CalcET.C:28
 CalcET.C:29
 CalcET.C:30
 CalcET.C:31
 CalcET.C:32
 CalcET.C:33
 CalcET.C:34
 CalcET.C:35
 CalcET.C:36
 CalcET.C:37
 CalcET.C:38
 CalcET.C:39
 CalcET.C:40
 CalcET.C:41
 CalcET.C:42
 CalcET.C:43
 CalcET.C:44
 CalcET.C:45
 CalcET.C:46
 CalcET.C:47
 CalcET.C:48
 CalcET.C:49
 CalcET.C:50
 CalcET.C:51
 CalcET.C:52
 CalcET.C:53
 CalcET.C:54
 CalcET.C:55
 CalcET.C:56
 CalcET.C:57
 CalcET.C:58
 CalcET.C:59
 CalcET.C:60
 CalcET.C:61
 CalcET.C:62
 CalcET.C:63
 CalcET.C:64
 CalcET.C:65
 CalcET.C:66
 CalcET.C:67
 CalcET.C:68
 CalcET.C:69
 CalcET.C:70
 CalcET.C:71
 CalcET.C:72
 CalcET.C:73
 CalcET.C:74
 CalcET.C:75
 CalcET.C:76
 CalcET.C:77
 CalcET.C:78
 CalcET.C:79
 CalcET.C:80
 CalcET.C:81
 CalcET.C:82
 CalcET.C:83
 CalcET.C:84
 CalcET.C:85
 CalcET.C:86
 CalcET.C:87
 CalcET.C:88
 CalcET.C:89
 CalcET.C:90
 CalcET.C:91
 CalcET.C:92
 CalcET.C:93
 CalcET.C:94
 CalcET.C:95
 CalcET.C:96
 CalcET.C:97
 CalcET.C:98
 CalcET.C:99
 CalcET.C:100
 CalcET.C:101
 CalcET.C:102
 CalcET.C:103
 CalcET.C:104
 CalcET.C:105
 CalcET.C:106
 CalcET.C:107
 CalcET.C:108
 CalcET.C:109
 CalcET.C:110
 CalcET.C:111
 CalcET.C:112
 CalcET.C:113
 CalcET.C:114
 CalcET.C:115
 CalcET.C:116
 CalcET.C:117
 CalcET.C:118
 CalcET.C:119
 CalcET.C:120
 CalcET.C:121
 CalcET.C:122
 CalcET.C:123
 CalcET.C:124
 CalcET.C:125
 CalcET.C:126
 CalcET.C:127
 CalcET.C:128
 CalcET.C:129
 CalcET.C:130
 CalcET.C:131
 CalcET.C:132
 CalcET.C:133
 CalcET.C:134
 CalcET.C:135
 CalcET.C:136
 CalcET.C:137
 CalcET.C:138
 CalcET.C:139
 CalcET.C:140
 CalcET.C:141
 CalcET.C:142
 CalcET.C:143
 CalcET.C:144
 CalcET.C:145
 CalcET.C:146
 CalcET.C:147
 CalcET.C:148
 CalcET.C:149
 CalcET.C:150
 CalcET.C:151
 CalcET.C:152
 CalcET.C:153
 CalcET.C:154
 CalcET.C:155
 CalcET.C:156
 CalcET.C:157
 CalcET.C:158
 CalcET.C:159
 CalcET.C:160
 CalcET.C:161
 CalcET.C:162
 CalcET.C:163
 CalcET.C:164
 CalcET.C:165
 CalcET.C:166
 CalcET.C:167
 CalcET.C:168
 CalcET.C:169
 CalcET.C:170
 CalcET.C:171