# Comparing of data file

**URL:** <https://root-forum.cern.ch/t/comparing-of-data-file/49591>\
**Category:** Newbie\
**Created:** [April 15, 2022, 8:01am UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591 "2022-04-15T08:01:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 15, 2022, 8:01am UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591/1 "2022-04-15T08:01:13Z")

</div>

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?

```cpp

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 ‘’’

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 15, 2022, 8:27am UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591/2 "2022-04-15T08:27:55Z")

</div>

Try:

```cpp
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);

```

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 15, 2022, 8:59am UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591/3 "2022-04-15T08:59:01Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> ```auto
> 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);
> 
> ```

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

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 15, 2022, 9:09am UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591/4 "2022-04-15T09:09:03Z")

</div>

[THStack](https://root.cern/doc/master/classTHStack.html)

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 15, 2022, 3:46pm UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591/5 "2022-04-15T15:46:08Z")

</div>

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”);  
‘’’

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [April 15, 2022, 4:23pm UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591/6 "2022-04-15T16:23:33Z")

</div>

You haven’t added any histograms to your [THStack](https://root.cern/doc/master/classTHStack.html) (see also [drawing options usage in the examples](https://root.cern/doc/master/classTHStack.html)).

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 15, 2022, 4:40pm UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591/7 "2022-04-15T16:40:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Roy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/roy/32/30362_2.png) [@Roy](https://root-forum.cern.ch/u/Roy)\
**Post date:** [April 15, 2022, 5:10pm UTC](https://root-forum.cern.ch/t/comparing-of-data-file/49591/8 "2022-04-15T17:10:24Z")

</div>

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