Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
draw_corr.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file draw_corr.C
1 #include "TFile.h"
2 #include "TTree.h"
3 
4 #include "TStyle.h"
5 #include "TLatex.h"
6 #include "TH1D.h"
7 #include "TH2D.h"
8 #include "TCanvas.h"
9 
10 #include <iostream>
11 #include <iomanip>
12 #include <vector>
13 #include <tuple>
14 #include <string>
15 #include <cmath>
16 #include <algorithm>
17 
18 
19 int round8(float num) {
20  int inum = static_cast<int>(num);
21  return inum - inum % 8;
22 }
23 
24 void draw_corr() {
25  const char * run = "../9613-0000.root";
26  const char * runNum = "EMCal run 9613";
27 
28  // Are your tree variables named correctly??
29 
30  TFile *f = new TFile(run,"READ");
31 
32  f->ls();
33 
34  TTree *t = (TTree*) f->Get("towerntup");
35  const int entries = t->GetEntries();
36 
37 
38  t->Show(0);
39 
40  std::vector<float> *emcTowE = 0;
41  std::vector<float> *emciEta = 0;
42  std::vector<float> *emciPhi = 0;
43 
44  t->SetBranchAddress("energy",&emcTowE);
45  t->SetBranchAddress("etabin",&emciEta);
46  t->SetBranchAddress("phibin",&emciPhi);
47 
48  TH2D *EDist = new TH2D("EDist",";EMCal tower phi;EMCal tower eta",256,-.5,255.5,96,-.5,95.5);
49  TH2D *EDist_gap = new TH2D("EDist_gap",";EMCal tower phi;EMCal tower eta",256,-.5,255.5,96,-.5,95.5);
50  TH2D* packet_corrs[128][128];
51  for (int i = 0; i < 128; i++) {
52  for (int j = 0; j < 128; j++) {
53  std::string corrIndex = std::to_string(i) + "-" + std::to_string(j);
54  const char * ccorrIndex = corrIndex.c_str();
55  packet_corrs[i][j] = new TH2D(ccorrIndex,";Energy;Energy",256,0,20000,256,0,20000);
56  }
57  }
58 
59  auto packetE = new float[entries][128];
60  TH2D *correlations = new TH2D("correlations",";packets",128,0,128,128,0,128);
61 
62  float tower_E[256 * 96] = { 0 }; // variables used for average energies
63  float tower_ET[256 * 96] = { 0 };
64 
65  TCanvas *tc = new TCanvas();
66  gStyle->SetOptStat(0);
67  TLatex l;
68  l.SetNDC();
69  l.SetTextSize(0.03);
70 
71 
72 
73  std::cout << "I see " << entries << " events!" << std::endl;
74 
75  for (int e = 0 ; e < entries; e++ ) {
76  t->GetEntry( e );
77 
78  for (unsigned i = 0; i < emcTowE->size(); i++) {
79  tower_E[i] += emcTowE->at(i);
80  }
81 
82  if ( e % 1000 == 0 ) {
83  std::cout << "\r" << static_cast<int>(static_cast<float>(e) / entries * 100) << "%" << std::flush;
84  }
85  }
86  std::cout << endl;
87 
88  // Find the various hot/cold spots
89  std::cout << endl << "Finding hot/cold spots..." << endl;
90 
91  TH1D *h_tower_E = new TH1D("h_tower_E",";Tower energy;counts",200,0,200000);
92  TH1D *h_tower_E_top = new TH1D("h_tower_E_top",";Tower energy;counts",200,0,200000);
93 
94  float sumE = 0.0;
95  float hottest = 0.0;
96  for (int i = 0; i < 256 * 96; i++) {
97  if (emciEta->at(i) >= 80) {
98  h_tower_E_top->Fill(tower_E[i]);
99  }
100  h_tower_E->Fill(tower_E[i]);
101  sumE += tower_E[i];
102  if (tower_E[i] > hottest) {
103  hottest = tower_E[i];
104  }
105  }
106  float aveE = sumE / (256 * 96);
107  float stdDev = h_tower_E->GetStdDev();
108 
109  std::vector<int> hot_spots;
110  std::vector<int> warm_spots;
111  std::vector<int> cold_spots;
112  std::vector<int> cool_spots;
113  std::vector<int> normal_spots;
114 
115  float cool_tol = 0.65;
116 
117  for (int i = 0; i < 256 * 96; i++) {
118 
119  if (tower_E[i] > (aveE+stdDev*3) && tower_E[i + 1] < (aveE+stdDev*3) && tower_E[i - 1] < (aveE+stdDev*3)) {
120  hot_spots.push_back(i);
121  }
122  else if (tower_E[i] > (aveE + stdDev*3)) {
123  warm_spots.push_back(i);
124  }
125  else if (tower_E[i] < aveE * cool_tol && tower_E[i + 1] > aveE * cool_tol && tower_E[i - 1] > aveE * cool_tol) {
126  cold_spots.push_back(i);
127  }
128  else if (tower_E[i] < aveE * cool_tol) {
129  cool_spots.push_back(i);
130  }
131  else {
132  normal_spots.push_back(i);
133  }
134  }
135 
136  gPad->SetLogy(1);
137  h_tower_E->Draw();
138  l.DrawLatex(0.15,0.95,"sPHENIX Internal");
139  l.DrawLatex(0.15,0.91,runNum);
140  tc->Print("tower_E_1D.pdf");
141 
142  h_tower_E_top->Draw();
143  l.DrawLatex(0.15,0.95,"sPHENIX Internal");
144  l.DrawLatex(0.15,0.91,runNum);
145  tc->Print("tower_E_top_1D.pdf");
146  gPad->SetLogy(0);
147 
148 
149  // Print out the locations of the very hot/cold spots
150 
151  std::cout << "hot spots" << endl;
152  for (unsigned i = 0; i < hot_spots.size(); i++) {
153  std::cout << "(ieta, iphi) = (";
154  std::cout << emciEta->at(hot_spots.at(i)) << ", " << emciPhi->at(hot_spots.at(i)) << ") " << endl;
155  }
156  std::cout << endl << "warm spots" << endl;
157  for (unsigned i = 0; i < warm_spots.size(); i++ ) {
158  std::cout << "(ieta, iphi) = (";
159  std::cout << emciEta->at(warm_spots.at(i)) << ", " << emciPhi->at(warm_spots.at(i)) << ") " << endl;
160  }
161  std::cout << endl << "cold spots" << endl;
162  for (unsigned i = 0; i < cold_spots.size(); i++) {
163  std::cout << "(ieta, iphi) = (";
164  std::cout << emciEta->at(cold_spots.at(i)) << ", " << emciPhi->at(cold_spots.at(i)) << ") " << endl;
165  }
166  std::cout << endl << "cool spots" << endl;
167  std::vector<std::tuple<int,int>> cool_points;
168 
169  for (unsigned i = 0; i < cool_spots.size(); i++) {
170  int rEta = round8(emciEta->at(cool_spots.at(i)));
171  int rPhi = round8(emciPhi->at(cool_spots.at(i)));
172 
173  if (rEta != 0 &&
174  std::find(cool_points.begin(), cool_points.end(), std::make_tuple(rEta,rPhi)) == cool_points.end()) {
175  cool_points.push_back(std::make_tuple(rEta, rPhi));
176  std::cout << "(ieta, iphi) = (" << rEta << ", " << rPhi << ")" << endl;
177  }
178  }
179 
180  bool skip = false;
181  for (unsigned i = 0; i < emcTowE->size(); i++ ) {
182 
183  EDist->Fill( emciPhi->at(i), emciEta->at(i), tower_E[i] );
184 
185  for (unsigned j = 0; j < hot_spots.size(); j++ ) {
186  if (i == static_cast<unsigned>(hot_spots.at(j))) {
187  skip = true;
188  }
189  }
190  for (unsigned j = 0; j < warm_spots.size(); j++ ) {
191  if (i == static_cast<unsigned>(warm_spots.at(j))) {
192  skip = true;
193  }
194  }
195 
196  if (!skip) {
197  EDist_gap->Fill(emciPhi->at(i), emciEta->at(i), tower_E[i]);
198  }
199  skip = false;
200  }
201 
202  gPad->SetLogz(1);
203  EDist->Draw("colz");
204  l.DrawLatex(0.15,0.95,"sPHENIX Internal");
205  l.DrawLatex(0.15,0.91,runNum);
206  l.SetTextSize(0.035);
207  l.DrawLatex(0.65,0.92,"#Sigma_{evt} ADC");
208  l.SetTextSize(0.03);
209  tc->Print("EDist.pdf");
210  gPad->SetLogz(0);
211 
212  EDist_gap->Draw("colz");
213  l.DrawLatex(0.15,0.95,"sPHENIX Internal");
214  l.DrawLatex(0.15,0.91,runNum);
215  l.SetTextSize(0.035);
216  l.DrawLatex(0.65,0.92,"#Sigma_{evt} ADC");
217  l.SetTextSize(0.03);
218  tc->Print("EDistGap.pdf");
219 
220 
221  // packet correlations
222 
223  std::cout << endl << "Finding packet energies..." << endl;
224  bool hot = false;
225  int ieta = 0;
226  int iphi = 0;
227  int packet = 0;
228  for (int e = 0; e < entries; e++) {
229 
230  t->GetEntry(e);
231 
232  for (unsigned i = 0; i < emcTowE->size(); i++) {
233  ieta = emciEta->at(i);
234  iphi = emciPhi->at(i);
235  for (unsigned j = 0; j < hot_spots.size(); j++ ){
236  if (ieta == emciEta->at(hot_spots.at(j)) && iphi == emciPhi->at(hot_spots.at(j))) {
237  hot = true;
238  }
239  }
240  for (unsigned j = 0; j < warm_spots.size(); j++ ) {
241  if (ieta == emciEta->at(warm_spots.at(j)) && iphi == emciPhi->at(warm_spots.at(j))) {
242  hot = true;
243  }
244  }
245 
246  packet += iphi / 8 * 4;
247  if (ieta / 24 == 0) { packet += ieta / 24 + 1; }
248  else if (ieta / 24 == 1) { packet += ieta / 24 - 1; }
249  else { packet += ieta / 24; }
250 
251  if (!hot) { packetE[e][packet] += emcTowE->at(i); } // 24 = 96/4 and 8 = 256/32
252  hot = false;
253  packet = 0;
254  }
255  if ( e % 1000 == 0 ) {
256  std::cout << "\r" << static_cast<int>(static_cast<float>(e) / entries * 100) << "%" << std::flush;
257  }
258  }
259  std::cout << endl;
260 
261  std::cout << endl << "Finding correlations..." << endl;
262 
263  for (int e = 0; e < entries; e++ ) {
264  for (int i = 0; i < 128; i++) {
265  for (int j = 0; j < 128; j++) {
266  packet_corrs[i][j]->Fill(packetE[e][i],packetE[e][j]);
267  correlations->Fill(i,j,packet_corrs[i][j]->GetCorrelationFactor() / entries);
268  }
269  }
270  if ( e % 1000 == 0 ) {
271  std::cout << "\r" << static_cast<int>(static_cast<float>(e) / entries * 100) << "%" << std::flush;
272  }
273  }
274  std::cout << endl;
275 
276 
277  correlations->SetMinimum(.7);
278  correlations->Draw("colz");
279  l.DrawLatex(0.15,0.95,"sPHENIX Internal");
280  l.DrawLatex(0.15,0.91,runNum);
281  l.SetTextSize(0.035);
282  l.DrawLatex(0.65,0.92,"Packet Correlations");
283  l.SetTextSize(0.03);
284  tc->Print("packet_correlations.pdf");
285 
286  bool stop = false;
287  std::string quit = "";
288  std::cout << "Would you like to see a specific correlation? (yes/no)" << endl;
289  std::cin >> quit;
290  if (quit == "no") { stop = true; }
291  while (!stop) {
292  std::cout << "Which correlation would you like to see? (i j)" << endl;
293  int ans1 = 0;
294  int ans2 = 0;
295  std::cin >> ans1 >> ans2;
296 
297  std::string title = "Packet Correlations " + std::to_string(ans1) + "-" + std::to_string(ans2);
298  std::cout << title << endl;
299  const char * ctitle = title.c_str();
300 
301  packet_corrs[ans1][ans2]->Draw("colz");
302  l.DrawLatex(0.15,0.95,"sPHENIX Internal");
303  l.DrawLatex(0.15,0.91,runNum);
304  l.SetTextSize(0.035);
305  l.DrawLatex(0.65,0.92,ctitle);
306  l.SetTextSize(0.03);
307  tc->Print("specific_correlation.pdf");
308 
309  std::cout << "Would you like to keep going? (yes/no) " << endl;
310  std::cin >> quit;
311  if (quit == "no") {
312  stop = true;
313  }
314  }
315 }