Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:18

0001 #include <calobase/TowerInfoDefs.h>
0002 R__LOAD_LIBRARY(libcalo_io.so)
0003 
0004 void display(const string& inputFile="output/test.root", const string& outputDir="output", const string& run = "0", bool do_waveforms = false) {
0005    TFile input(inputFile.c_str());
0006 
0007    bool style_eta_phi = true;
0008    auto c1 = new TCanvas();
0009 
0010    c1->cd();
0011    c1->SetTickx();
0012    c1->SetTicky();
0013 
0014    c1->SetCanvasSize(1500, 1000);
0015 
0016    c1->SetLeftMargin(.1);
0017    c1->SetRightMargin(.05);
0018    // gPad->SetLogz();
0019 
0020    string outputFile = outputDir + "/plots-" + run + ".pdf";
0021    c1->Print((outputFile + "[").c_str(), "pdf portrait");
0022    // ------------------------------------------------------------
0023 
0024    gPad->SetLogy();
0025    auto h1 = (TH1D*)(input.Get("hTime"))->Clone();
0026    h1->SetTitle(("Run: " + run + ", Peak Location").c_str());
0027    // h1->SetStats(0);
0028    // h1->GetYaxis()->SetRangeUser(9e3,1e7);
0029    h1->Draw();
0030    gPad->Update();
0031 
0032    auto st = (TPaveStats*)h1->GetListOfFunctions()->FindObject("stats");
0033    st->SetX1NDC(0.65); //new x start position
0034    st->SetX2NDC(0.95); //new x end position
0035 
0036    st->SetY1NDC(0.6); //new y start position
0037    st->SetY2NDC(0.90); //new y end position
0038 
0039    c1->Print((outputFile).c_str(), "pdf portrait");
0040 
0041    // ------------------------------------------------------------
0042 
0043    h1 = (TH1D*)(input.Get("hADC"))->Clone();
0044    h1->SetTitle(("Run: " + run + ", ADC").c_str());
0045    h1->SetStats(0);
0046    // h1->GetYaxis()->SetRangeUser(5e-1,1e7);
0047    h1->Draw();
0048    c1->Print((outputFile).c_str(), "pdf portrait");
0049 
0050    // ------------------------------------------------------------
0051 
0052    h1 = (TH1D*)(input.Get("hadc"))->Clone();
0053    h1->SetTitle(("Run: " + run + ", adc").c_str());
0054    h1->SetStats(0);
0055    // h1->GetYaxis()->SetRangeUser(5e-1,1e7);
0056    h1->Draw();
0057    c1->Print((outputFile).c_str(), "pdf portrait");
0058 
0059    // ------------------------------------------------------------
0060 
0061    h1 = (TH1D*)(input.Get("hPed"))->Clone();
0062    h1->SetTitle(("Run: " + run + ", Pedestal").c_str());
0063    h1->SetStats(0);
0064    // h1->GetYaxis()->SetRangeUser(5e-1,1e7);
0065    h1->Draw();
0066    c1->Print((outputFile).c_str(), "pdf portrait");
0067 
0068    // ------------------------------------------------------------
0069 
0070    // c1->SetLeftMargin(.1);
0071    // c1->SetRightMargin(.1);
0072    gPad->SetLogy(0);
0073 
0074    // auto h2 = (TH2D*)(input.Get("scat/h2TimeVsChannel_scat"))->Clone();
0075    // h2->SetStats(0);
0076    // h2->SetMarkerStyle(8);
0077    // h2->SetMarkerColor(kRed);
0078    // h2->SetFillColor(kRed);
0079    // h2->GetXaxis()->SetRangeUser(1400,3200);
0080    // h2->Draw();
0081    // c1->Print((outputFile).c_str(), "pdf portrait");
0082 
0083    // ------------------------------------------------------------
0084 
0085    c1->SetLeftMargin(.11);
0086    c1->SetRightMargin(.03);
0087    // h2 = (TH2D*)(input.Get("scat/h2ADCVsChannel_scat"))->Clone();
0088    auto h2 = (TH2D*)(input.Get("h2ADCVsChannel"))->Clone();
0089    h2->SetStats(0);
0090    // h2->SetMarkerStyle(8);
0091    // h2->SetMarkerColor(kRed);
0092    // h2->SetFillColor(kRed);
0093    // h2->GetXaxis()->SetRangeUser(1400,3200);
0094    // h2->Draw();
0095    // c1->Print((outputFile).c_str(), "pdf portrait");
0096 
0097    // h2->GetYaxis()->SetRangeUser(0,4e3);
0098    // c1->Print((outputFile).c_str(), "pdf portrait");
0099 
0100    h1 = (TH1D*)h2->ProfileX()->Clone();
0101    h1->SetTitle(("Run: " + run + ", Average ADC vs Channel; Channel; ADC").c_str());
0102    h1->SetMarkerStyle(6);
0103    h1->SetMarkerColor(kRed);
0104    h1->SetStats(0);
0105    h1->Draw();
0106    c1->Print((outputFile).c_str(), "pdf portrait");
0107 
0108    // h1 = (TH1D*)((TH2*)input.Get("scat/h2ADCVsChannel_scat"))->ProfileX();
0109    h1 = (TH1D*)((TH2*)input.Get("h2ADCVsChannel"))->ProfileX();
0110    TH2D* h2_missing;
0111    if(style_eta_phi) {
0112       h2 = new TH2D("h2AvgAdc", "Average ADC; Towerid #eta; Towerid #phi", 96, 0-0.5, 96-0.5, 256, 0-0.5, 256-0.5);
0113       h2_missing = new TH2D("h2AvgAdcMissing", "Average ADC (Zeros); Towerid #eta; Towerid #phi", 96, 0-0.5, 96-0.5, 256, 0-0.5, 256-0.5);
0114    }
0115    else {
0116       h2 = new TH2D("h2AvgAdc", "Average ADC; Towerid #phi; Towerid #eta", 256, 0-0.5, 256-0.5, 96, 0-0.5, 96-0.5);
0117       h2_missing = new TH2D("h2AvgAdcMissing", "Average ADC (Zeros); Towerid #phi; Towerid #eta", 256, 0-0.5, 256-0.5, 96, 0-0.5, 96-0.5);
0118    }
0119 
0120    for (Int_t channel = 0; channel < 24576; ++channel) {
0121       Int_t key = TowerInfoDefs::encode_emcal(channel);
0122       Int_t etabin = TowerInfoDefs::getCaloTowerEtaBin(key);
0123       Int_t phibin = TowerInfoDefs::getCaloTowerPhiBin(key);
0124 
0125       Double_t avg_adc = h1->GetBinContent(channel+1);
0126 
0127       //h2->SetBinContent(etabin+1, phibin+1, avg_adc);
0128       if(style_eta_phi) {
0129          h2->SetBinContent(etabin+1, phibin+1, avg_adc);
0130          if(avg_adc == 0) h2_missing->SetBinContent(etabin+1, phibin+1, 1);
0131       }
0132       else {
0133          h2->SetBinContent(phibin+1, etabin+1, avg_adc);
0134          if(avg_adc == 0) h2_missing->SetBinContent(phibin+1, etabin+1, 1);
0135       }
0136       // if(avg_adc != 0) cout << "etabin: " << etabin << ", phibin: " << phibin << ", " << " channel: " << channel << ", avg_adc: " << avg_adc << endl;
0137    }
0138 
0139    c1->SetRightMargin(.12);
0140    h2->SetStats(0);
0141    h2->SetTitle(("Run: " + run + ", Average ADC").c_str());
0142    // h2->SetMaximum(5e3);
0143    h2->Draw("COLZ1");
0144 
0145    auto tline = new TLine();
0146 
0147    if(style_eta_phi) {
0148       for (UInt_t i = 0; i < 32; ++i) {
0149          tline->DrawLine(-0.5, 8*i-0.5, 95.5, 8*i-0.5);
0150       }
0151       for (UInt_t i = 0; i < 12; ++i) {
0152          tline->DrawLine(8*i-0.5, -0.5, 8*i-0.5, 255.5);
0153       }
0154    }
0155    else {
0156       for (UInt_t i = 0; i < 32; ++i) {
0157          tline->DrawLine(8*i-0.5, -0.5, 8*i-0.5, 95.5);
0158       }
0159       for (UInt_t i = 0; i < 12; ++i) {
0160          tline->DrawLine(-0.5, 8*i-0.5, 255.5, 8*i-0.5);
0161       }
0162    }
0163 
0164    c1->Print((outputFile).c_str(), "pdf portrait");
0165 
0166    // h2->GetYaxis()->SetRangeUser(0,50);
0167    // c1->Print((outputFile).c_str(), "pdf portrait");
0168 
0169    h2_missing->SetStats(0);
0170    h2_missing->SetTitle(("Run: " + run + ", Average ADC (zeros)").c_str());
0171    // h2->SetMaximum(4e3);
0172    h2_missing->Draw("COLZ1");
0173 
0174    tline = new TLine();
0175 
0176    if(style_eta_phi) {
0177       for (UInt_t i = 0; i < 32; ++i) {
0178          tline->DrawLine(-0.5, 8*i-0.5, 95.5, 8*i-0.5);
0179       }
0180       for (UInt_t i = 0; i < 12; ++i) {
0181          tline->DrawLine(8*i-0.5, -0.5, 8*i-0.5, 255.5);
0182       }
0183    }
0184    else {
0185       for (UInt_t i = 0; i < 32; ++i) {
0186          tline->DrawLine(8*i-0.5, -0.5, 8*i-0.5, 95.5);
0187       }
0188       for (UInt_t i = 0; i < 12; ++i) {
0189          tline->DrawLine(-0.5, 8*i-0.5, 255.5, 8*i-0.5);
0190       }
0191    }
0192 
0193    c1->Print((outputFile).c_str(), "pdf portrait");
0194 
0195    c1->SetRightMargin(.1);
0196    c1->SetLeftMargin(.1);
0197 
0198    // ------------------------------------------------------------
0199 
0200    c1->SetLeftMargin(.12);
0201    c1->SetRightMargin(.04);
0202    h2 = (TH2D*)(input.Get("h2PedVsChannel"))->Clone();
0203    h2->SetStats(0);
0204    h2->SetMarkerStyle(8);
0205    h2->SetMarkerColor(kRed);
0206    h2->SetFillColor(kRed);
0207    // h2->GetXaxis()->SetRangeUser(1400,3200);
0208    h2->Draw();
0209    // c1->Print((outputFile).c_str(), "pdf portrait");
0210 
0211    h1 = (TH1D*)h2->ProfileX()->Clone();
0212    h1->SetTitle(("Run: " + run + ", Average Pedestal vs Channel; Channel; Pedestal").c_str());
0213    h1->SetStats(0);
0214    h1->Draw();
0215    c1->Print((outputFile).c_str(), "pdf portrait");
0216 
0217    // ------------------------------------------------------------
0218 
0219    c1->SetLeftMargin(.1);
0220 
0221    h2 = (TH2D*)(input.Get("h2PedVsChannel"))->Clone();
0222    h1 = (TH1D*)h2->ProfileX()->Clone();
0223 
0224    if(style_eta_phi) {
0225       h2 = new TH2D("h2AvgPed", "Average Pedestal; Towerid #eta; Towerid #phi", 96, 0-0.5, 96-0.5, 256, 0-0.5, 256-0.5);
0226    }
0227    else {
0228       h2 = new TH2D("h2AvgPed", "Average Pedestal; Towerid #phi; Towerid #eta", 256, 0-0.5, 256-0.5, 96, 0-0.5, 96-0.5);
0229    }
0230 
0231    for (Int_t channel = 0; channel < 24576; ++channel) {
0232       Int_t key = TowerInfoDefs::encode_emcal(channel);
0233       Int_t etabin = TowerInfoDefs::getCaloTowerEtaBin(key);
0234       Int_t phibin = TowerInfoDefs::getCaloTowerPhiBin(key);
0235 
0236       Double_t avg_ped = h1->GetBinContent(channel+1);
0237 
0238       if(style_eta_phi) h2->SetBinContent(etabin+1, phibin+1, avg_ped);
0239       else              h2->SetBinContent(phibin+1, etabin+1, avg_ped);
0240       // if(avg_adc != 0) cout << "etabin: " << etabin << ", phibin: " << phibin << ", " << " channel: " << channel << ", avg_adc: " << avg_adc << endl;
0241    }
0242 
0243    c1->SetRightMargin(.12);
0244    h2->SetStats(0);
0245    h2->SetTitle(("Run: " + run + ", Average Pedestal").c_str());
0246    h2->SetMaximum(3e3);
0247    h2->Draw("COLZ1");
0248 
0249    tline = new TLine();
0250 
0251    if(style_eta_phi) {
0252       for (UInt_t i = 0; i < 32; ++i) {
0253          tline->DrawLine(-0.5, 8*i-0.5, 95.5, 8*i-0.5);
0254       }
0255       for (UInt_t i = 0; i < 12; ++i) {
0256          tline->DrawLine(8*i-0.5, -0.5, 8*i-0.5, 255.5);
0257       }
0258    }
0259    else {
0260       for (UInt_t i = 0; i < 32; ++i) {
0261          tline->DrawLine(8*i-0.5, -0.5, 8*i-0.5, 95.5);
0262       }
0263       for (UInt_t i = 0; i < 12; ++i) {
0264          tline->DrawLine(-0.5, 8*i-0.5, 255.5, 8*i-0.5);
0265       }
0266    }
0267 
0268    c1->Print((outputFile).c_str(), "pdf portrait");
0269 
0270    // ------------------------------------------------------------
0271 
0272    // c1->SetLeftMargin(.11);
0273    // h2 = (TH2D*)(input.Get("scat/h2ADCVsTime_scat"))->Clone();
0274    // h2->SetStats(0);
0275    // h2->SetMarkerStyle(8);
0276    // h2->SetMarkerColor(kRed);
0277    // h2->SetFillColor(kRed);
0278    // h2->Draw();
0279    // c1->Print((outputFile).c_str(), "pdf portrait");
0280    // c1->SetLeftMargin(.1);
0281 
0282    // ------------------------------------------------------------
0283 
0284    // h2 = (TH2D*)(input.Get("scat/h2PedVsTime_scat"))->Clone();
0285    // h2->SetStats(0);
0286    // h2->SetMarkerStyle(8);
0287    // h2->SetMarkerColor(kRed);
0288    // h2->SetFillColor(kRed);
0289    // h2->Draw();
0290    // c1->Print((outputFile).c_str(), "pdf portrait");
0291 
0292    // ------------------------------------------------------------
0293 
0294    // c1->SetLeftMargin(.13);
0295    // h2 = (TH2D*)(input.Get("scat/h2ADCVsPed_scat"))->Clone();
0296    // h2->SetStats(0);
0297    // h2->SetMarkerStyle(8);
0298    // h2->SetMarkerColor(kRed);
0299    // h2->SetFillColor(kRed);
0300    // h2->Draw();
0301    // c1->Print((outputFile).c_str(), "pdf portrait");
0302    // c1->SetLeftMargin(.1);
0303 
0304    c1->Print((outputFile + "]").c_str(), "pdf portrait");
0305    // ------------------------------------------------------------
0306 
0307    if(do_waveforms) {
0308 
0309       gStyle->SetPalette(kThermometer);
0310 
0311       outputFile = outputDir + "/adcVsTime-" + run + ".pdf";
0312       // Total channels 24576
0313       Int_t i_max = 12; // 12
0314       Int_t j_max = 32; // 32
0315 
0316       // auto h2_pos_global = new TH2F("h2_pos_global", "Towers; Towerid #eta; Towerid #phi", 96, 0-0.5, 96-0.5, 256, 0-0.5, 256-0.5);
0317       auto h2_pos_global = new TH2F("h2_pos_global", "Towers; Towerid #phi; Towerid #eta", 256, 0-0.5, 256-0.5, 96, 0-0.5, 96-0.5);
0318       h2_pos_global->SetFillColor(kGreen);
0319       for(Int_t i = 0; i < i_max; ++i) {
0320          for (Int_t j = 0; j < j_max; ++j) {
0321             for (Int_t etabin = i*8+7; etabin >= i*8; --etabin) {
0322                for (Int_t phibin = j*8; phibin < j*8+8; ++phibin) {
0323                   UInt_t key = TowerInfoDefs::encode_emcal(etabin, phibin);
0324                   UInt_t channel = TowerInfoDefs::decode_emcal(key);
0325                   h2 = (TH2D*)(input.Get(("adcVsTime/h2adcVsTime_"+to_string(channel)).c_str()));
0326                   if(h2) h2_pos_global->SetBinContent(phibin+1,etabin+1, 1);
0327                   // if(h2) h2_pos_global->SetBinContent(phibin+1,etabin+1, 1);
0328                }
0329             }
0330          }
0331       }
0332 
0333       // c1->Print("output/adcVsTime.pdf[", "pdf portrait");
0334       c1->Print((outputFile + "[").c_str(), "pdf portrait");
0335       for(Int_t i = 0; i < i_max; ++i) {
0336          for (Int_t j = 0; j < j_max; ++j) {
0337             if((i*j_max+j)%3 == 0) cout << "Progress: " << (i*j_max+j)*100./(i_max*j_max) << " %" << endl;
0338 
0339             c1 = new TCanvas();
0340             c1->SetCanvasSize(1500, 1000);
0341             auto pad1 = new TPad("pad1", "pad1", 0.01, 0.01, 0.8, 1);
0342             auto pad2 = new TPad("pad2", "pad2", 0.8, 0.8, 1, 1);
0343             // auto h2_pos = new TH2F("h2_pos", "Towers; Towerid #eta; Towerid #phi", 96, 0-0.5, 96-0.5, 256, 0-0.5, 256-0.5);
0344             auto h2_pos = new TH2F("h2_pos", "Towers; Towerid #phi; Towerid #eta", 256, 0-0.5, 256-0.5, 96, 0-0.5, 96-0.5);
0345             pad1->DivideSquare(64,0,0);
0346             pad1->Draw();
0347             pad2->Draw();
0348 
0349             bool contains_channels = false;
0350             UInt_t pad = 1;
0351             for (Int_t etabin = i*8+7; etabin >= i*8; --etabin) {
0352                for (Int_t phibin = j*8; phibin < j*8+8; ++phibin) {
0353                   UInt_t key = TowerInfoDefs::encode_emcal(etabin, phibin);
0354                   UInt_t channel = TowerInfoDefs::decode_emcal(key);
0355                   h2 = (TH2D*)(input.Get(("adcVsTime/h2adcVsTime_"+to_string(channel)).c_str()));
0356                   if(h2) {
0357                      h2_pos->SetBinContent(phibin+1,etabin+1, 1);
0358                      // h2_pos->SetBinContent(phibin+1,etabin+1, 1);
0359                      pad1->cd(pad);
0360                      contains_channels = true;
0361 
0362                      h2 = (TH2D*)h2->Clone();
0363                      // h1 = (TH1D*)h2->ProfileX()->Clone();
0364                      gPad->SetTickx();
0365                      gPad->SetTicky();
0366                      // h1->SetTitle("");
0367                      // h1->SetStats(0);
0368                      // h1->GetYaxis()->SetRangeUser(0,17e3);
0369                      // h1->SetMarkerStyle(8);
0370                      // h1->SetMarkerSize(0.3);
0371                      // h1->SetMarkerColor(kRed);
0372                      h2->SetTitle("");
0373                      h2->SetStats(0);
0374                      // h2->GetYaxis()->SetRangeUser(0,17e3);
0375                      // h2->SetMarkerStyle(8);
0376                      // h2->SetMarkerSize(0.3);
0377                      // h2->SetMarkerColor(kRed);
0378                      h2->Draw("COL");
0379                      // h2->Draw();
0380 
0381                      auto pt = new TPaveText(.7,.7,.95,.9, "NDC");
0382                      pt->AddText((to_string(phibin) + ", " + to_string(etabin)).c_str());
0383                      // pt->AddText((to_string(phibin) + ", " + to_string(etabin)).c_str());
0384                      pt->Draw();
0385                   }
0386                   // cout << "etabin: " << etabin << ", phibin: " << phibin << ", channel: " << channel << ", pad: " << pad << endl;
0387                   ++pad;
0388                }
0389             }
0390             if(contains_channels) {
0391                pad2->cd();
0392                pad2->SetTickx();
0393                pad2->SetTicky();
0394 
0395                h2_pos_global->SetStats(0);
0396                h2_pos_global->Draw("BOX");
0397                h2_pos->Draw("BOX same");
0398                // c1->Print("output/adcVsTime.pdf", "pdf portrait");
0399                c1->Print((outputFile).c_str(), "pdf portrait");
0400                // c1->Print(("output/adcVsTime-"+to_string(i) + "-" + to_string(j) + ".png").c_str(), "png portrait");
0401                // ++pages;
0402             }
0403             delete h2_pos;
0404             delete pad1;
0405             delete pad2;
0406          }
0407       }
0408       // c1->Print("output/adcVsTime.pdf]", "pdf portrait");
0409       c1->Print((outputFile + "]").c_str(), "pdf portrait");
0410    }
0411 
0412    input.Close();
0413 }