Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
analyzeClusterEtIso.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file analyzeClusterEtIso.C
1 #include <sPhenixStyle.h>
2 #include <sPhenixStyle.C>
3 
4 /*
5  This file analyzes the output of the primary
6  isoCluster module, specifically the correlation
7  between the cluster tranverse energy and the
8  likelihood of clusters to be direct photons
9  based on their Et values
10 
11  Anthony Hodges, UIUC, February 15th, 2023
12 */
13 
14 void analyzeClusterEtIso(int pass)
15 {
16 
18 
19  TFile *fin = new TFile(Form("../macro/condor/aggregation/gammaJet_pass%d.root",pass));
20 
21  TTree *T = (TTree*)fin -> Get("T");
22 
23  vector<float> *clusterPhi = 0;
24  vector<float> *clusterEta = 0;
25  vector<float> *clusterE = 0;
26  vector<float> *clusterPt = 0;
27  vector<float> *clusterEtIso = 0;
28  vector<float> *clusterchisq = 0;
29  vector<float> *photonPhi = 0;
30  vector<float> *photonEta = 0;
31  vector<float> *photonE = 0;
32  vector<float> *photonPt = 0;
33 
34  T -> SetBranchAddress("clusterPhi",&clusterPhi);
35  T -> SetBranchAddress("clusterEta",&clusterEta);
36  T -> SetBranchAddress("clusterE",&clusterE);
37  T -> SetBranchAddress("clusterPt",&clusterPt);
38  T -> SetBranchAddress("clusterEtIso",&clusterEtIso);
39  T -> SetBranchAddress("photonPhi",&photonPhi);
40  T -> SetBranchAddress("photonEta",&photonEta);
41  T -> SetBranchAddress("photonE",&photonE);
42  T -> SetBranchAddress("photonPt",&photonPt);
43 
44  int nEvents = T -> GetEntries();
45 
46  std::cout << "Analyzing " << nEvents << " entries" << std::endl;
47 
48  TH2F *isoEtE = new TH2F("isoEtE","isoEtE",500,20,100,500,-10,10);
49  isoEtE -> SetTitle(";E [GeV]; E_T [GeV]");
50  TH2F *isoEtMatchFrac = new TH2F("isoEtMatchFrac","isoEtMatchFrac",500,-50,50,100,0,1);
51  isoEtMatchFrac -> SetTitle("E_T [GeV]; Purity");
52 
53  //eTIso calibration. Determine sigmalized values for Et based on clusterE
54  float eBins[] = {25,30,35,40,45,50,55,60};
55  int nBins = sizeof(eBins)/sizeof(eBins[0]);
56  float fitStart = -60; float fitEnd = 60;
57 
58  for(int i = 0; i < nEvents; i++)
59  {
60  T -> GetEntry(i);
61 
62  for(int j = 0; j < clusterEtIso -> size(); j++)
63  {
64  isoEtE -> Fill(clusterE -> at(j), clusterEtIso -> at(j));
65 
66  }
67  }
68 
69  TCanvas *c1 = new TCanvas();
70  isoEtE -> Draw("colz");
71 
72  TGraphErrors *sigma = new TGraphErrors();
73  TGraphErrors *mu = new TGraphErrors();
74 
75  for(int i = 0; i < nBins-1; i++)
76  {
77  TH1F *isoEtEProj = (TH1F*)isoEtE -> ProjectionY("projection",isoEtE -> GetXaxis() -> FindBin(eBins[i] + 0.001), isoEtE -> GetXaxis() -> FindBin(eBins[i+1] - 0.001));
78 
79  TF1 *func = new TF1("func","gaus",fitStart, fitEnd);
80  func -> SetLineColor(2);
81  isoEtEProj -> Fit(func,"Q0","",fitStart,fitEnd);
82  TCanvas *cTemp = new TCanvas();
83 
84  isoEtEProj -> Fit(func,"Q","",func -> GetParameter(1) - func -> GetParameter(2), func -> GetParameter(1) + func -> GetParameter(2));
85  sigma -> SetPoint(i, (eBins[i+1] + eBins[i])/2, func -> GetParameter(2));
86  sigma -> SetPointError(i, 0, func -> GetParError(2));
87 
88  mu -> SetPoint(i, (eBins[i+1] + eBins[i])/2, func -> GetParameter(1));
89  mu -> SetPointError(i, 0, func -> GetParError(1));
90  }
91 
92  TCanvas *c2 = new TCanvas();
93  sigma -> SetTitle(";Cluster E [GeV]; Iso E_{T} #sigma [GeV]");
94  sigma -> Draw("ap");
95  TF1 *sigmaFit = new TF1("sigmaFit","pol1",eBins[0],eBins[nBins-1]);
96  sigmaFit -> SetLineColor(2);
97  sigma -> Fit(sigmaFit,"RQ","");
98 
99  TCanvas *c3 = new TCanvas();
100  mu -> SetTitle(";Cluster E [GeV];Iso E_{T} #mu [GeV]");
101  mu -> Draw("ap");
102  //TF1 *muFit = new TF1("muFit","pol8",eBins[0],eBins[nBins-1]);
103  TF1 *muFit = new TF1("muFit","[0]*exp([1]*pow(x,[2]) + [3]) + [4]",(eBins[0] + eBins[1])/2,(eBins[nBins-2]+eBins[nBins-1])/2);
104  muFit -> SetParameter(0, 0.00017);
105 
106 
107  muFit -> SetLineColor(2);
108  mu -> Fit(muFit,"RQ","");
109  //Now we're going to go through the clusters again and assess
110  //the correlation between eT and direct photon purity
111  float sigmas[] = {0.5, 1 , 1.5, 2, 2.5, 3};
112  const int nSigmas = sizeof(sigmas)/sizeof(sigmas[0]);
113  int colors[] = {1,2,4,kGreen+2, kViolet,kCyan,kOrange+2,kMagenta+2,kAzure-2};
114 
115  TGraphErrors *gPurity[nSigmas];
116  TGraphErrors *gEfficiency[nSigmas];
117 
118  TCanvas *c4 = new TCanvas();
119  TCanvas *c5 = new TCanvas();
120  TH1F *hdrMin = new TH1F("drMin","drMin",100,0,0.6);
121  float dRMax = 0.12;
122 
123  TH1F *hEResp = new TH1F("eResp","eResp",200,0,2);
124  float respMin = 0.1;
125  TLegend *leg = new TLegend(0.5,0.5,0.9,0.9);
126  leg -> SetFillStyle(0);
127  leg -> SetBorderSize(0);
128 
129  for(int s = 0; s < nSigmas; s++)
130  {
131  gPurity[s] = new TGraphErrors();
132  gPurity[s] -> SetMarkerColor(colors[s]);
133 
134  gEfficiency[s] = new TGraphErrors();
135  gEfficiency[s] -> SetMarkerColor(colors[s]);
136  for(int e = 0; e < nBins; e++)
137  {
138 
139  int nMatch = 0;
140  int nIsoCluster = 0;
141  int nDirPhotons = 0;
142  for(int i = 0; i < nEvents; i++)
143  {
144  T -> GetEntry(i);
145 
146  if(photonE -> size() == 0) continue;
147  nDirPhotons += photonE -> size();
148  int matchIDCluster = -1;
149  int matchIDPhoton = -1;
150  int checkOnce = 0;
151  for(int k = 0; k < clusterE -> size(); k++)
152  {
153  if(clusterE -> at(k) < eBins[e] || clusterE -> at(k) > eBins[e+1]) continue;
154  if(abs(clusterEtIso -> at(k)) > muFit -> Eval(clusterE -> at(k)) + sigmas[s]*sigmaFit -> Eval(clusterE -> at(k))) continue;
155  nIsoCluster++;
156  float drMin = 1000;
157 
158  for(int l = 0; l < photonE -> size(); l++)
159  {
160  if((photonE -> at(l) < eBins[e] || photonE-> at(l) > eBins[e+1]) && !checkOnce)
161  {
162  checkOnce = 1;
163  nDirPhotons++;
164  }
165  float dPhi = clusterPhi -> at(k) - photonPhi -> at(l);
166  float dEta = clusterEta -> at(k) - photonEta -> at(l);
167 
168  while(dPhi > M_PI) dPhi -= 2*M_PI;
169  while(dPhi < -M_PI) dPhi += 2*M_PI;
170 
171  float dr = sqrt(pow(dPhi,2) + pow(dEta,2));
172 
173  if(dr < drMin)
174  {
175  drMin = dr;
176  matchIDCluster = k;
177  matchIDPhoton = l;
178  }
179  }//direct photon loop
180 
181  hdrMin -> Fill(drMin);
182 
183  if(!matchIDCluster || !matchIDPhoton) continue;
184 
185  float response = clusterE -> at(matchIDCluster)/photonE -> at(matchIDPhoton);
186  hEResp -> Fill(response);
187 
188  if(drMin < dRMax && abs(1 - response) < respMin) nMatch++;
189 
190  }//cluster loop
191 
192 
193  }//event loop
194 
195  float purity = 0;
196  if(nIsoCluster != 0) purity = (float)nMatch/(float)nIsoCluster;
197  float efficiency = (float)nMatch/(float)nDirPhotons;
198 
199 
200  // std::cout << Form("nMatch for sigma %g: %d with %d nIsoCluster",sigmas[s],nMatch,nIsoCluster) << std::endl;
201  // std::cout << "filling with purity: " << purity << std::endl;
202  gPurity[s] -> SetPoint(e, (eBins[e] + eBins[e+1])/2, purity);
203  gEfficiency[s] -> SetPoint(e, (eBins[e] + eBins[e+1])/2, efficiency);
204 
205 
206  }//energy loop
207  leg -> AddEntry(gPurity[s], Form("E_{T} Iso #sigma < %g",sigmas[s]),"p");
208  if(s == 0)
209  {
210  c4 -> cd();
211  gPurity[s] -> Draw("ap");
212  gPurity[s] -> SetTitle(";Cluster E [GeV]; Purity");
213  gPurity[s] -> GetYaxis() -> SetRangeUser(0,0.02);
214 
215  c5 -> cd();
216  gEfficiency[s] -> Draw("ap");
217  gEfficiency[s] -> SetTitle(";Cluster E [GeV]; Efficiency");
218  gEfficiency[s] -> GetYaxis() -> SetRangeUser(0,0.02);
219  }
220  else
221  {
222  c4 -> cd();
223  gPurity[s] -> Draw("samep");
224  c5 -> cd();
225  gEfficiency[s] -> Draw("samep");
226  }
227  }//sigma loop
228  leg -> Draw("same");
229 
230  TCanvas *cDrMin = new TCanvas();
231  hdrMin -> Draw("epx0");
232  hdrMin -> GetYaxis() -> SetRangeUser(1e-1, 10*hdrMin -> GetMaximum());
233  TLine *ldrMax = new TLine(dRMax, 1e-1, dRMax, hdrMin -> GetMaximum());
234  ldrMax -> SetLineStyle(7);
235  ldrMax -> SetLineColor(2);
236  ldrMax -> Draw("same");
237  gPad -> SetLogy();
238 
239  TCanvas *cResp = new TCanvas();
240  hEResp -> Draw("epx0");
241  TLine *lRespMin1 = new TLine(1-respMin, 0, 1-respMin, hEResp -> GetMaximum());
242  lRespMin1 -> SetLineStyle(7);
243  lRespMin1 -> SetLineColor(2);
244  lRespMin1 -> Draw("same");
245 
246  TLine *lRespMin2 = new TLine(1+respMin, 0, 1+respMin, hEResp -> GetMaximum());
247  lRespMin2 -> SetLineStyle(7);
248  lRespMin2 -> SetLineColor(2);
249  lRespMin2 -> Draw("same");
250 
251 }
252 
253 
254 
255 
256 
257 
258 
259 
260 
261 
262