I am working on a 2D histogram that I have converted into a TProfile, and now I want to readout the TProfile values into a file.
Here is the file I am using:
> #include "TTree.h"
> #include "TFile.h"
> #include "TRandom.h"
> #include "TTree.h"
> #include "TCanvas.h"
> #include "TStyle.h"
> #include "TMath.h"
> #include <iostream>
> #include "TH2.h"
> #include "TChain.h"
> #include <vector>
> using namespace std;
> void ch_comp_write_v2(){
> TChain* chchain = new TChain("_compress_ch");
> chchain->Add("/a/data/riverside/afadeeva/OutSN/huff_dat_pr7_pst8_bt2_vt2_un_b_up_25_15_30.root");
> TH2D *hist = new TH2D("hist","Comp_v_Ch",16000,-1,8300,10000,0,1.1);
> Double_t _ch_compression; Int_t _ch;
> chchain->SetBranchAddress("_ch_compression",&_ch_compression);
> chchain->SetBranchAddress("_ch",&_ch);
> Long64_t chentries = chchain->GetEntries();
> cout << "amt of entries= " << chentries <<endl;
> Long64_t nb = 0, cb = 0 , cbytes = 0, nbytes = 0 ;
> ofstream myfile;
> myfile.open ("filepath/Out_ch_comp_25n_15b_30p.txt");
> for (Long64_t j=0; j< chentries; j++) { // chentries = 7768896
> Long64_t centry = chchain->LoadTree(j);
> if (centry <0 ) break;
> cb = chchain->GetEntry(j); cbytes += cb;
> myfile << _ch << " " << _ch_compression << endl;
> cout << "channel " << _ch << " compression for this event " << _ch_compression << endl;
> hist->Fill(_ch,_ch_compression);
> }
> myfile.close();
> TProfile *px = hist->ProfileX();
> // cout << "profile val " << << endl;
> ofstream oneval;
> oneval.open("~/filepath/ch_comp_25n_15b_30p.txt");
> int comp = 0;
> for(int a = 0; a<8257; a++){
> // oneval <<
> comp = px->GetBinContent(a);
> cout << "channel " << a << " profile val " << comp << endl;
> }
> oneval.close();
> TCanvas *cob = new TCanvas("cob","comp per channel v channel threshold = 30 ADC",1250,700);
> TCanvas *gary = new TCanvas("gary","profile",300,300);
> cob->Divide(1,2);
> gary->cd();
> px->Draw();
> // hprof->Draw();
> cob->cd(1);
> hist->SetXTitle("Channel");
> hist->SetYTitle("Compression");
> // hist->GetYaxis();
> // hist->GetMean();
> hist->Draw();
> cob->SaveAs("/filepath/ch_comp_canvas_all.pdf");
> }
> ~
Unfortunately, when I readout the bin values of the TProfile, I get all 0s. What am I doing wrong?