Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:21:02

0001 TH2F* DivideColumnsByAverage(TH2F* hist) {
0002     // Get the number of bins along x and y axes
0003     int numBinsX = hist->GetNbinsX();
0004     int numBinsY = hist->GetNbinsY();
0005 
0006     // Create a new TH2F histogram for storing the result
0007     TH2F* dividedHistogram = new TH2F("dividedHistogram", "Histogram with Columns Divided by Average",
0008                                       numBinsX, hist->GetXaxis()->GetXmin(), hist->GetXaxis()->GetXmax(),
0009                                       numBinsY, hist->GetYaxis()->GetXmin(), hist->GetYaxis()->GetXmax());
0010 
0011     // Loop over all columns
0012     for (int binX = 1; binX <= numBinsX; binX++) {
0013         // Calculate the average bin content for the current column
0014         double sum = 0.0;
0015         for (int binY = 1; binY <= numBinsY; binY++) {
0016             sum += hist->GetBinContent(binX, binY);
0017         }
0018         double average = (numBinsY > 0) ? sum / numBinsY : 0.0;
0019 
0020         // Divide each bin content in the column by the average
0021         for (int binY = 1; binY <= numBinsY; binY++) {
0022             double content = hist->GetBinContent(binX, binY);
0023             double dividedContent = (average != 0.0) ? content / average : 0.0;
0024             dividedHistogram->SetBinContent(binX, binY, dividedContent);
0025         }
0026     }
0027 
0028     return dividedHistogram;
0029 }
0030 
0031 
0032 void quickPlot(){
0033 
0034   TFile* fin = new TFile("combine_out/out_23727.root");
0035   TH2F* h_ohcal_hit = (TH2F*) fin->Get("h_ohcal_etaphi_wQA");
0036   TH2F* h_ihcal_hit = (TH2F*) fin->Get("h_ihcal_etaphi_wQA");
0037   //TH2F* h_ihcal_hit = (TH2F*) fin->Get("h_ihcal_etaphi_wQA");
0038   
0039 
0040   TH2F*  h_ohcal_hit_avg = DivideColumnsByAverage(h_ohcal_hit);
0041   TH2F*  h_ihcal_hit_avg = DivideColumnsByAverage(h_ihcal_hit);
0042 
0043   TCanvas* c1 = new TCanvas("c1","c1",600,600);
0044   h_ohcal_hit_avg->Draw("COLZ");
0045   h_ohcal_hit_avg->SetXTitle("ohcal ieta");
0046   h_ohcal_hit_avg->SetYTitle("ohcal iphi");
0047 
0048   TCanvas* c2 = new TCanvas("c2","c2",600,600);
0049   h_ihcal_hit_avg->Draw("COLZ");
0050   h_ihcal_hit_avg->SetXTitle("ihcal ieta");
0051   h_ihcal_hit_avg->SetYTitle("ihcal iphi");
0052   
0053 
0054   TFile* fout = new TFile("quickPlotSave.root","recreate");
0055   h_ohcal_hit_avg->Write("h_ohcal_hit_avg");
0056   h_ihcal_hit_avg->Write("h_ihcal_hit_avg");
0057    
0058   gStyle->SetOptStat(0);
0059 
0060   h_ohcal_hit->Write();
0061   h_ihcal_hit->Write();
0062 
0063 
0064 }