Plotting of 1D distribution for Max Energy in Z

Dear Experts
I need to plot 1D distribution for max energy in Z (separate histogram in the following macro) Can You suggest How it can be done? Thanks a lot in advance


void fiber_dep()
{
    // *************************************************************************
    // Rootfile and Tree
   TFile* f = new TFile("lumi_fiber_calMay10.edm4hep.root");
    f->cd();

    //TTree* t = (TTree*)f->Get("events");
    TTreeReader myReader("events", f);                     // name of tree and file

    TTreeReaderArray<Float_t> energy(myReader, "LumiDirectPCALHits.energy");
    TTreeReaderArray<Float_t> x(myReader, "LumiDirectPCALHits.position.x");
    TTreeReaderArray<Float_t> y(myReader, "LumiDirectPCALHits.position.y");
    TTreeReaderArray<Float_t> z(myReader, "LumiDirectPCALHits.position.z");
    // Rootfile and Tree
    // *************************************************************************
    // *************************************************************************
    // Histograms
    
    
    
    map<string,TH3*> h3;

    float xmin = -50;
    float xmax = 50;
    int nx = 100;
    float ymin = -50;
    float ymax = 50;
    int ny = 100;
    float zmin = 66150;
    float zmax = 66350;
    int nz = 200;


    h3["energy"] = new TH3F("energy", "Total Energy Deposit;x;y;z", nx, xmin, xmax, ny, ymin, ymax, nz, 0, zmax - zmin);

   /* 
    map<string,vector<TH1*>> h1;

    for (int i = 0; i < h3["hits"]->GetNbinsX()*h3["hits"]->GetNbinsY()*h3["hits"]->GetNbinsZ(); i++)
    {
        ss.str(""); ss << "h1_cell_energy_" << i;
        h1["energy"].push_back(new TH1F(TString(ss.str()), "", 100, 0, 0.001));
        ss.str(""); ss << "Cell " << i << ";E_{#gamma} (GeV); Entries";
        h1["energy"][i]->SetTitle(TString(ss.str()));
    }
    */
    TRandom3 *rndm = new TRandom3();
    int nev = 0;
    vector<int> nphoton;
    float xxx = 0;
    float yyy = 0;
    float zzz = 0;
    while (myReader.Next())
    {
        nev++;
        cout << "Event: " << nev << endl;
        nphoton.push_back(0);
        float tot_e = 0;

        for (int i = 0; i < energy.GetSize(); i++)
        {
            nphoton.back()++;
            tot_e += energy[i];
           // h3["energy"]->Fill(x[i],y[i],abs(z[i]) - zmin,energy[i]);
            h3["energy"]->Fill(x[i]+rndm->Gaus(0,1) ,y[i] + rndm->Gaus(0,1) , abs(z[i]) - zmin,energy[i] );
            xxx = max(abs(x[i]), xxx);
            yyy = max(abs(y[i]), yyy);
            zzz = max(abs(z[i]), zzz);
        }
    }

    cout << "Max-X: " << xxx << endl;
    cout << "Max-Y: " << yyy << endl;
    cout << "Max-Z: " << zzz << endl;
    // Fill Histograms
    // *************************************************************************

    // *************************************************************************
    // Draw Histograms
    for (map<string,TH3*>::const_iterator itr = h3.begin(); itr != h3.end(); itr++)
    {
        //gStyle->SetOptStat(0);

        string hname = itr->first;
        TH3* h = (TH3*)itr->second->Clone();
        h->Scale(1.0/float(h->Integral()));

        TCanvas* c = new TCanvas("c", "", 1000, 1000);

        
      //  c->cd();
       // h->Draw("BOX2Z");
       // h->Draw();
       // gPad->SetLogx(0);
       // gPad->SetLogy(0);
       // gPad->SetLogz(0);
       // ss.str(""); ss << "test_" << hname << ".png";
       // c->SaveAs(TString(ss.str()));
        

        TH2* h2yx = (TH2*)h->Project3D("yx")->Clone();
        TH2* h2zx = (TH2*)h->Project3D("zx")->Clone();
        TH2* h2zy = (TH2*)h->Project3D("zy")->Clone();
        TH1* h1x = (TH1*)h->Project3D("x")->Clone();
        TH1* h1y = (TH1*)h->Project3D("y")->Clone();
        TH1* h1z = (TH1*)h->Project3D("z")->Clone();
       
      
        c->cd();
        h2yx->Draw("colz");
        gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
        ss.str(""); ss << "test2D_yx_" << hname << ".png";
        c->SaveAs(TString(ss.str()));

        h2zx->Draw("colz");
        gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
        ss.str(""); ss << "test2D_zx_" << hname << ".png";
        c->SaveAs(TString(ss.str()));

        h2zy->Draw("colz");
        gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
        ss.str(""); ss << "test2D_zy_" << hname << ".png";
        c->SaveAs(TString(ss.str()));

        h1x->Draw("colz");
        gPad->SetLogx(0); gPad->SetLogy(1); gPad->SetLogz(0);
        ss.str(""); ss << "test1D_x_" << hname << ".png";
        c->SaveAs(TString(ss.str()));

        h1y->Draw("colz");
        gPad->SetLogx(0); gPad->SetLogy(1); gPad->SetLogz(0);
        ss.str(""); ss << "test1D_y_" << hname << ".png";
        c->SaveAs(TString(ss.str()));

        h1z->Draw("colz");
        gPad->SetLogx(0); gPad->SetLogy(1); gPad->SetLogz(0);
        ss.str(""); ss << "test1D_z_" << hname << ".png";
        c->SaveAs(TString(ss.str()));

        
        c->Close();

    }
    // Draw Histograms
    // *************************************************************************


}

Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


You are, somehow, already plotting histograms in png files, What is wrong with that? what do you want to get?

Thanks for the response actually these are the energy depositions in the center of the fiber calorimeter i wanted to plot distribution for single given fiber in z. Distribution will show energy deposition in hottest fiber with maximum energy as a function of Z

Sorry, I thought you had an issue with the plotting itself. I am not sure who can help you with that. May be @moneta

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.