Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EMCalDeadmap.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EMCalDeadmap.C
1 #pragma once
2 
3 #include <calobase/TowerInfoDefs.h>
4 
5 #include <cdbobjects/CDBTTree.h>
7 
8 #include <phool/recoConsts.h>
9 
10 #include <TH2.h>
11 #include <TCanvas.h>
12 #include <TString.h>
13 
14 #include <iostream>
15 #include <string>
16 
17 R__LOAD_LIBRARY(libcalo_reco.so)
18 
20 {
21  // this convenience library knows all our i/o objects so you don't
22  // have to figure out what is in each dst type
23  gSystem->Load("libg4dst.so");
24 
25 
27  rc->set_StringFlag("CDB_GLOBALTAG", "2023p003");
28 
29  const int nRuns = 6;
30  // these are the pre-QM runs with all 8 EMCal SEBs
31  int runList[] = {21796, 21615, 21599, 21598, 21518, 21520};
32  // set up histograms and canvas for plotting
33  TH2F* hists[nRuns];
34  int etabins = 96;
35  int phibins = 256;
36  TCanvas *c = new TCanvas("c1", "c1",0,50,1400,1000);
37  c->Divide(3, 2);
38  TPad** pad_arr = new TPad*[nRuns];
39  TPad* pad;
40  for (int i=0; i<nRuns; i++)
41  {
42  c->cd(i+1);
43  pad = (TPad*)gPad;
44  pad_arr[i] = pad;
45  }
46 
47  // loop over runs and grab the dead tower map from the CDB
48  for (int i=0; i<nRuns; i++)
49  {
50  int runnumber = runList[i];
51  std::cout << "Starting run " << runnumber << "; setting recoConsts\n";
52  rc->set_uint64Flag("TIMESTAMP", runnumber);
53 
54  std::string url = CDBInterface::instance()->getUrl("CEMC_BadTowerMap");
55  if(url.empty())
56  {
57  std::cout << "Could not get Dead Map for CDB. Detector: " << "CEMC" << std::endl;
58  return;
59  }
60 
61  CDBTTree* m_CDBTTree = new CDBTTree(url);
62  if(!m_CDBTTree)
63  {
64  std::cout << "No CDB TTree found from url " << url << std::endl;
65  return;
66  }
67 
68  std::cout << "Creating hist " << Form("h_deadmap_%d", runnumber) << "\n";
69  hists[i] = new TH2F(Form("h_deadmap_%d", runnumber),
70  Form("Dead Tower Map - Run %d;i#phi;i#eta", runnumber),
71  phibins, -0.5, 255.5, etabins, -0.5, 95.5);
72  hists[i]->SetStats(0);
73 
74  // loop over towers, grab status of each tower
75  for (int j=0; j<etabins*phibins; j++)
76  {
77  unsigned int key = TowerInfoDefs::encode_emcal(j);
78  int ieta = TowerInfoDefs::getCaloTowerEtaBin(key);
79  int iphi = TowerInfoDefs::getCaloTowerPhiBin(key);
80  int status = m_CDBTTree->GetIntValue(j,"status");
81  float isDead = 0.001; // if you fill the histogram with 0 the bin won't be plotted because root thinks it's empty
82  if (status > 0) isDead = 1.0;
83  hists[i]->Fill(iphi, ieta, isDead);
84  }
85 
86  pad_arr[i]->cd();
87  std::cout << "Drawing hist " << Form("h_deadmap_%d", runnumber) << "\n";
88  hists[i]->Draw("colz");
89  }
90 
91  std::cout << "Final plotting, saving plot\n";
92  c->Modified();
93  c->SaveAs("emcal_deadmaps_QMruns.pdf(");
94 
95  // make some maps of how many runs a given channel was dead in
96  TH2F* h_nDeadRuns = new TH2F("h_nDeadRuns",
97  "Number of Bad Runs by Tower;i#phi;i#eta",
98  phibins, -0.5, 255.5, etabins, -0.5, 95.5);
99  h_nDeadRuns->SetStats(0);
100  for (int i=0; i<nRuns; i++) {
101  h_nDeadRuns->Add(hists[i]);
102  }
103  c->Clear();
104  c->cd();
105  h_nDeadRuns->Draw("colz");
106  c->Modified();
107  c->SaveAs("emcal_deadmaps_QMruns.pdf");
108 
109  TH2F* morehists[3];
110  for (int i=0; i<3; i++) {
111  morehists[i] = new TH2F(Form("h_more_%d", (i+1)),
112  Form("Towers Dead in %d or More Runs;i#phi;i#eta", (i+2)),
113  phibins, -0.5, 255.5, etabins, -0.5, 95.5);
114  morehists[i]->SetStats(0);
115  for (int j=0; j<phibins; j++) {
116  for (int k=0; k<etabins; k++) {
117  int globalbin = h_nDeadRuns->GetBin(j, k);
118  float fillvalue = 0.001;
119  if (h_nDeadRuns->GetBinContent(globalbin) >= (i+2)) fillvalue = 1;
120  morehists[i]->Fill(j, k, fillvalue);
121  }
122  }
123  }
124 
125  c->Clear();
126  morehists[0]->Draw("colz");
127  c->SaveAs("emcal_deadmaps_QMruns.pdf");
128  c->Clear();
129  morehists[1]->Draw("colz");
130  c->SaveAs("emcal_deadmaps_QMruns.pdf");
131  c->Clear();
132  morehists[2]->Draw("colz");
133  c->SaveAs("emcal_deadmaps_QMruns.pdf)");
134 
135  gSystem->Exit(0);
136 }
137