Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:11:39

0001 #pragma once
0002 
0003 #include <calobase/TowerInfoDefs.h>
0004 
0005 #include <cdbobjects/CDBTTree.h>
0006 #include <ffamodules/CDBInterface.h>
0007 
0008 #include <phool/recoConsts.h>
0009 
0010 #include <TH2.h>
0011 #include <TCanvas.h>
0012 #include <TString.h>
0013 
0014 #include <iostream>
0015 #include <string>
0016 
0017 R__LOAD_LIBRARY(libcalo_reco.so)
0018 
0019 void EMCalDeadmap()
0020 {
0021     // this convenience library knows all our i/o objects so you don't
0022     // have to figure out what is in each dst type
0023     gSystem->Load("libg4dst.so");
0024 
0025 
0026     recoConsts *rc = recoConsts::instance();
0027     rc->set_StringFlag("CDB_GLOBALTAG", "2023p003");
0028 
0029     const int nRuns = 6;
0030     // these are the pre-QM runs with all 8 EMCal SEBs
0031     int runList[] = {21796, 21615, 21599, 21598, 21518, 21520};
0032     // set up histograms and canvas for plotting
0033     TH2F* hists[nRuns];
0034     int etabins = 96;
0035     int phibins = 256;
0036     TCanvas *c = new TCanvas("c1", "c1",0,50,1400,1000);
0037     c->Divide(3, 2);
0038     TPad** pad_arr = new TPad*[nRuns];
0039     TPad* pad;
0040     for (int i=0; i<nRuns; i++)
0041     {
0042     c->cd(i+1);
0043     pad = (TPad*)gPad;
0044     pad_arr[i] = pad;
0045     }
0046 
0047     // loop over runs and grab the dead tower map from the CDB
0048     for (int i=0; i<nRuns; i++)
0049     {
0050     int runnumber = runList[i];
0051     std::cout << "Starting run " << runnumber << "; setting recoConsts\n";
0052     rc->set_uint64Flag("TIMESTAMP", runnumber);
0053 
0054     std::string url = CDBInterface::instance()->getUrl("CEMC_BadTowerMap");
0055     if(url.empty())
0056     {
0057         std::cout << "Could not get Dead Map for CDB. Detector: " << "CEMC" << std::endl;
0058         return;
0059     }
0060 
0061     CDBTTree* m_CDBTTree = new CDBTTree(url);
0062     if(!m_CDBTTree)
0063     {
0064         std::cout << "No CDB TTree found from url " << url << std::endl;
0065         return;
0066     }
0067 
0068     std::cout << "Creating hist " << Form("h_deadmap_%d", runnumber) << "\n";
0069     hists[i] = new TH2F(Form("h_deadmap_%d", runnumber),
0070         Form("Dead Tower Map - Run %d;i#phi;i#eta", runnumber),
0071         phibins, -0.5, 255.5, etabins, -0.5, 95.5);
0072     hists[i]->SetStats(0);
0073 
0074     // loop over towers, grab status of each tower
0075     for (int j=0; j<etabins*phibins; j++)
0076     {
0077         unsigned int key = TowerInfoDefs::encode_emcal(j);
0078         int ieta = TowerInfoDefs::getCaloTowerEtaBin(key);
0079         int iphi = TowerInfoDefs::getCaloTowerPhiBin(key);
0080         int status = m_CDBTTree->GetIntValue(j,"status");
0081         float isDead = 0.001;  // if you fill the histogram with 0 the bin won't be plotted because root thinks it's empty
0082         if (status > 0) isDead = 1.0;
0083         hists[i]->Fill(iphi, ieta, isDead);
0084     }
0085 
0086     pad_arr[i]->cd();
0087     std::cout << "Drawing hist " << Form("h_deadmap_%d", runnumber) << "\n";
0088     hists[i]->Draw("colz");
0089     }
0090 
0091     std::cout << "Final plotting, saving plot\n";
0092     c->Modified();
0093     c->SaveAs("emcal_deadmaps_QMruns.pdf(");
0094 
0095     // make some maps of how many runs a given channel was dead in
0096     TH2F* h_nDeadRuns = new TH2F("h_nDeadRuns",
0097         "Number of Bad Runs by Tower;i#phi;i#eta",
0098         phibins, -0.5, 255.5, etabins, -0.5, 95.5);
0099     h_nDeadRuns->SetStats(0);
0100     for (int i=0; i<nRuns; i++) {
0101     h_nDeadRuns->Add(hists[i]);
0102     }
0103     c->Clear();
0104     c->cd();
0105     h_nDeadRuns->Draw("colz");
0106     c->Modified();
0107     c->SaveAs("emcal_deadmaps_QMruns.pdf");
0108 
0109     TH2F* morehists[3];
0110     for (int i=0; i<3; i++) {
0111     morehists[i] = new TH2F(Form("h_more_%d", (i+1)),
0112         Form("Towers Dead in %d or More Runs;i#phi;i#eta", (i+2)),
0113         phibins, -0.5, 255.5, etabins, -0.5, 95.5);
0114     morehists[i]->SetStats(0);
0115     for (int j=0; j<phibins; j++) {
0116         for (int k=0; k<etabins; k++) {
0117         int globalbin = h_nDeadRuns->GetBin(j, k);
0118         float fillvalue = 0.001;
0119         if (h_nDeadRuns->GetBinContent(globalbin) >= (i+2)) fillvalue = 1;
0120         morehists[i]->Fill(j, k, fillvalue);
0121         }
0122     }
0123     }
0124 
0125     c->Clear();
0126     morehists[0]->Draw("colz");
0127     c->SaveAs("emcal_deadmaps_QMruns.pdf");
0128     c->Clear();
0129     morehists[1]->Draw("colz");
0130     c->SaveAs("emcal_deadmaps_QMruns.pdf");
0131     c->Clear();
0132     morehists[2]->Draw("colz");
0133     c->SaveAs("emcal_deadmaps_QMruns.pdf)");
0134 
0135     gSystem->Exit(0);
0136 }
0137