Superimposing histograms & mutual information

Hi. ROTer. I encountered some problem in laying 3 histogram on top of one another and finding the mutual information between 2 of the histograms. I wonder if you guys can help point me to the right direction.

Problem One: I can’t overlay them on top of one another. Only the first one show up. and when I comment out the c1->update part in histogram 1, the second one, but only the second one showed up. i used draw(“SAME”) for all of them.

Problem Two: I drew a histogram TH2 that is the projection of 2 TH1F histograms on a canvas c2. but I don’t see a new window at all

Problem Three: the mutual information value fail to show.
I got the source of the function from here: root.cern.ch/root/html524/src/TM … tml#FGG.RE

Thanks in advance for helping me look at this.

[code]#include “Riostream.h”
#include “TCanvas.h”
#include “TStyle.h”
#include “TH1.h”
#include “TGaxis.h”

void seasonaldependenceoverlay() {
// Read data from an ascii file and create a root file with an histogram and an ntuple.

double MI;

// this file has 1 column of float data

TCanvas *c1 = new TCanvas(“c1”,“MPV distribution”,600,400);
// first histogram
ifstream in;
in.open(“year1.txt”);
Float_t x;
Int_t nlines = 0;
TFile *f = new TFile(“SeasonalDependenceOverlay.root”,“RECREATE”);
TH1F *h1 = new TH1F(“h1”,“Multiplied Charges Distribution”,93,20,50);

while (1) {
in >> x;
if (!in.good()) break;
if (nlines < 22) cout<<x<<endl;
h1->Fill(x);
nlines++;
}
printf(" found %d points\n",nlines);
//h1->Draw();
TH1F *h2 = h1->Rebin(3.5,“Rebinned1”);
h2->SetLineColor(kRed);
h2->Draw();
h2.Fit(“gaus”);
h2->GetFunction(“gaus”)->SetLineColor(kRed);
c1->update();
in.close();

//second histogram
ifstream in2;
in2.open(“year2.txt”);
Float_t x2;
Int_t nlines2 = 0;
// TFile *f = new TFile(“onedhist.root”,“RECREATE”);
TH1F *h3 = new TH1F(“h3”,“Multiplied Charges Distribution”,93,20,50);

while (1) {
in2 >> x2;
if (!in2.good()) break;
if (nlines2 < 22) cout<<x2<<endl;
h3->Fill(x2);
nlines2++;
}
c1->cd();
printf(" found %d points\n",nlines2);
//h3->Draw(“SAME”);
TH1F *h4 = h3->Rebin(5,“Rebinned2”);
h4->SetLineColor(kBlue);
h4->Draw(“SAME”);
h4.Fit(“gaus”);
h4->GetFunction(“gaus”)->SetLineColor(kBlue);
c1->update();
in2.close();

//third histogram
ifstream in3;
in3.open(“year3.txt”);
Float_t x3;
Int_t nlines3 = 0;
// TFile *f = new TFile(“onedhist.root”,“RECREATE”);
TH1F *h5 = new TH1F(“h5”,“Multiplied Charges Distribution”,93,20,50);

while (1) {
in3 >> x3;
if (!in3.good()) break;
if (nlines3 < 10) cout<<x3<<endl;
h5->Fill(x3);
nlines3++;
}
c1->cd();
printf(" found %d points\n",nlines3);
//h3->Draw(“SAME”);
TH1F *h6 = h5->Rebin(3,“Rebinned3”);
h6->SetLineColor(kGreen);
h6->Draw(“SAME”);
h6.Fit(“gaus”);
h6->GetFunction(“gaus”)->SetLineColor(kGreen);
c1->update();
in3.close();

TCanvas *c2 = new TCanvas(“c2”,“MPV distribution”,600,400);
TH2F *h7 = new TH2F(“h7”, “h7 title”, 40, 25, 45, 30, 25, 45);
TH1F *h2= h7->ProjectionX();
TH1F *h4= h7->ProjectionY();
c2->cd();
h7->Draw(“SAME”);
c2->update();

MI=GetMutualInformation(h7);
printf("mutual information:", MI);

}[/code]

Error message:
root [6] .x seasonaldependenceoverlay.c
35.79
36.37
36.37
35.7
35.04
33.24
32.82
30.96
35.18
35.63
29.87
35.89
36.46
31.3
31.46
33.52
36.45
31.09
35
36.37
33.97
35.25
found 22 points
Warning: wrong member access operator ‘.’ seasonaldependenceoverlay.c:30:
FCN=9.04533 FROM MIGRAD STATUS=CONVERGED 174 CALLS 175 TOTAL
EDM=1.25657e-08 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 Constant 2.20464e+00 7.84597e-01 9.48101e-04 -1.06702e-04
2 Mean 3.37547e+01 1.84954e+00 2.82392e-03 5.22433e-05
3 Sigma 3.74355e+00 2.49735e+00 3.85021e-04 5.39771e-04
36.91
41.42
36.16
38.04
36.08
34.17
32.35
32.42
31.03
34.61
35.26
29.28
28.74
32.19
35.3
35.27
30.78
31.69
33.46
35.4
30.09
33.97
found 23 points
Warning in TH1F::Rebin: ngroup=5 is not an exact divider of nbins=93.
Warning: wrong member access operator ‘.’ seasonaldependenceoverlay.c:51:
FCN=2.47561 FROM MIGRAD STATUS=CONVERGED 78 CALLS 79 TOTAL
EDM=2.81037e-09 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 Constant 4.10556e+00 1.32621e+00 8.24922e-04 5.44549e-05
2 Mean 3.31043e+01 1.06707e+00 9.07969e-04 5.53294e-05
3 Sigma 3.61691e+00 1.37193e+00 8.27061e-05 7.12627e-04
Error: Can’t call TCanvas::update() in current scope seasonaldependenceoverlay.c:53:
Possible candidates are…
(in TCanvas)
(in TPad)
*** Interpreter error recovered ***
root [7]

Edit1: added in the error message.
year3.txt (105 Bytes)
year2.txt (166 Bytes)
year1.txt (154 Bytes)

Your code is full of errors … I am fixing them and the file back … you will do the diff to see … it is too long to explain … #-o

Here it is:

#include "Riostream.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TH1.h"
#include "TGaxis.h"

void seasonaldependenceoverlay() {
// Read data from an ascii file and create a root file with an histogram and an ntuple.

    double MI;
// this file has 1 column of float data

TCanvas *c1 = new TCanvas("c1","MPV distribution",600,400);
// first histogram
ifstream in;
in.open("year1.txt");
Float_t x;
Int_t nlines = 0;
TFile *f = new TFile("SeasonalDependenceOverlay.root","RECREATE");
TH1F *h1 = new TH1F("h1","Multiplied Charges Distribution",93,20,50);


while (1) {
in >> x;
if (!in.good()) break;
if (nlines < 22) cout<<x<<endl;
h1->Fill(x);
nlines++;
}
printf(" found %d points\n",nlines);
//h1->Draw();

/// Rebin first param is an Int_t !!!!!!
///TH1F *h2 = (TH1F *)h1->Rebin(3.5,"Rebinned1");

TH1F *h2 = (TH1F *)h1->Rebin(3,"Rebinned1");

h2->SetLineColor(kRed);
h2->Draw();
h2->Fit("gaus");
h2->GetFunction("gaus")->SetLineColor(kRed);
   c1->Update();
in.close();

//second histogram
ifstream in2;
in2.open("year2.txt");
Float_t x2;
Int_t nlines2 = 0;
// TFile *f = new TFile("onedhist.root","RECREATE");
TH1F *h3 = new TH1F("h3","Multiplied Charges Distribution",93,20,50);

while (1) {
in2 >> x2;
if (!in2.good()) break;
if (nlines2 < 22) cout<<x2<<endl;
h3->Fill(x2);
nlines2++;
}
c1->cd();
printf(" found %d points\n",nlines2);
//h3->Draw("SAME");
TH1F *h4 = (TH1F *)h3->Rebin(5,"Rebinned2");
h4->SetLineColor(kBlue);
h4->Draw("SAME");
h4->Fit("gaus");
h4->GetFunction("gaus")->SetLineColor(kBlue);
   c1->Update();
in2.close();

//third histogram
ifstream in3;
in3.open("year3.txt");
Float_t x3;
Int_t nlines3 = 0;
// TFile *f = new TFile("onedhist.root","RECREATE");
TH1F *h5 = new TH1F("h5","Multiplied Charges Distribution",93,20,50);

while (1) {
in3 >> x3;
if (!in3.good()) break;
if (nlines3 < 10) cout<<x3<<endl;
h5->Fill(x3);
nlines3++;
}
c1->cd();
printf(" found %d points\n",nlines3);
//h3->Draw("SAME");
TH1F *h6 = (TH1F *)h5->Rebin(3,"Rebinned3");
h6->SetLineColor(kGreen);
h6->Draw("SAME");
h6->Fit("gaus");
h6->GetFunction("gaus")->SetLineColor(kGreen);
   c1->Update();
in3.close();

TCanvas *c2 = new TCanvas("c2","MPV distribution",600,400);
TH2F *h7 = new TH2F("h7", "h7 title", 40, 25, 45, 30, 25, 45);
    ////TH1F *h2= h7->ProjectionX(); // <<< already defined before ....
    ////TH1F *h4= h7->ProjectionY(); // <<< already defined before .
    c2->cd();
    h7->Draw("SAME");
    c2->Update();

   /// What is GetMutualInformation ?????????
    /// MI=GetMutualInformation(h7);
    /// printf("mutual information: %f", MI);

}

Next time do the cleaning job before posting … Thanks.

update != Update

Your “h7” histogram is completely empty (you do not fill it at all).

TCanvas *c2 = new TCanvas("c2","MPV distribution",600,400); TH2F *h7 = new TH2F("h7", "h7 title", 40, 25, 45, 30, 25, 45); ////TH1F *h2= h7->ProjectionX(); // <<< already defined before .... ////TH1F *h4= h7->ProjectionY(); // <<< already defined before . c2->cd(); h7->Draw("SAME"); c2->Update();

I guess what i really meant to do is to project h2 and h4 which are th1fs onto h7( th2f)

/// What is GetMutualInformation ????????? /// MI=GetMutualInformation(h7); /// printf("mutual information: %f", MI);

Mutual information:
en.wikipedia.org/wiki/Mutual_information
root.cern.ch/root/html524/src/TM … tml#FGG.RE

Thanks for your help.

Please the bugs before going further … [-o<

  • the histograms h2 an h4 are declared twice in your macro

  • the function GetMutualInformation is not defined…

  • etc …

and read the doc … As Wile said Update != update … TH1F::Rebin 1st parameter is an int …