Comparing of data file

I was trying to construct a histogram to compare two different data set but the plot is not as expected or as even it shows through new TBrowser
Can some one help me out please?


void current_data(TString file1, TString file2)
{
    TFile f1(file1); 
    TTree* t1 = (TTree*) f1.Get("current_ntuple"); 
    Float_t Current_ntuple1; 
    t1->SetBranchAddress("Current",&Current_ntuple1); 
    ULong64_t n = t1->GetEntries();
    Double_t MinBound = 0;
    Double_t MaxBound = 100;
    Int_t Numbins = 100;
    TH1D* Raw_data = new TH1D("Raw data","Current Comparision", Numbins, MinBound, MaxBound);
    Raw_data -> GetXaxis() ->SetTitle("Current[#muA]");
    Raw_data -> GetYaxis() ->SetTitle("Frequency");

    for (Int_t f = 0; f<n;f++)
    {
        t1 -> GetEntry(f);
        Raw_data -> Fill(Current_ntuple1);
    }
    Raw_data ->SetName("February Raw Data");
    Raw_data -> SetDirectory(0);
f1.Close();

      TFile f2(file2);
        TTree* t2 = (TTree*) f2.Get("current_ntuple");
        Float_t Current_ntuple2;
        t2->SetBranchAddress("Current",&Current_ntuple2);

        ULong64_t m = t2->GetEntries();
        TH1D* stable_data = new TH1D("Stable_data.txt", "", Numbins, MinBound, MaxBound);
        stable_data -> GetXaxis()-> SetTitle("Current [#muA] ");
        stable_data -> GetYaxis()-> SetTitle("Frequency");
        stable_data -> SetLineColor(kRed);
        stable_data -> SetMarkerStyle(7);
        stable_data->SetName("February Stable Current");
        
          for(Int_t g = 0; g < m; g++)
          {
              t2->GetEntry(g);
              stable_data->Fill(Current_ntuple2);
          }
        
             stable_data->SetDirectory(0);
      
f2.Close();
TCanvas* c1 = new TCanvas();
    Raw_data->Draw();
    stable_data->Draw();
    c1 ->SetLogy();
    gStyle -> SetOptStat(0);
    c1->Update();
    
    TFile outputFile("Comparing Raw and Stable Data");
    Raw_data->Write("Current Distribution");
    stable_data->Write("Stable Current Distribution");
outputFile.Close();


}

BTW. Note that ``` is not the same as "’ nor ‘’’

Try:

gStyle->SetOptStat(0);
TCanvas *c1 = new TCanvas("c1", "c1");
c1->Divide(1, 2);
c1->cd(1);
Raw_data->Draw();
gPad->SetLogy();
c1->cd(2);
stable_data->Draw();
gPad->SetLogy();
c1->cd(0);
1 Like

Thank you it worked,
but it gave me two different histogram
I tried using (same) but it didn’t worked.
Thank You.

THStack

I tried using THStack as, but it didn’t worked
‘’’
THStack *hs = new THStack(“hs”, “”);
TText T; T.SetTextFont(42); T.SetTextAlign(21);
c1->Divide(1, 2);
c1->cd(1); hs->Draw(""); T.DrawTextNDC(.5,.95,“Comparing dataset”);
‘’’

You haven’t added any histograms to your THStack (see also drawing options usage in the examples).

1 Like

Thank you for such quick reply,
It worked the histogram are stacked.

Can you please look into my question about irregular plot, I had posted?