# Problem getting mean and sigma of the TH2F object created by calling tntuple-\>Draw()

**URL:** <https://root-forum.cern.ch/t/problem-getting-mean-and-sigma-of-the-th2f-object-created-by-calling-tntuple-draw/36350>\
**Category:** Newbie\
**Created:** [October 15, 2019, 9:23am UTC](https://root-forum.cern.ch/t/problem-getting-mean-and-sigma-of-the-th2f-object-created-by-calling-tntuple-draw/36350 "2019-10-15T09:23:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thuwang-xz18](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e274bd/32.png) [@thuwang-xz18](https://root-forum.cern.ch/u/thuwang-xz18)\
**Post date:** [October 15, 2019, 9:23am UTC](https://root-forum.cern.ch/t/problem-getting-mean-and-sigma-of-the-th2f-object-created-by-calling-tntuple-draw/36350/1 "2019-10-15T09:23:33Z")

</div>

hi, guys  
I used a tntuple object to store data of charges (X,Y,Z,Q) and drawn a 2-D distribution of X vs Y.  
but when I tried to get the Mean and the StdDev of the distribution, I got all “0” values and I dont know why.  
my code is as follows:

```auto
    gROOT->cd();
    TNtuple* npc=new TNtuple("n","n","x:y:z:charge");
    npc->SetMarkerStyle(20);
    npc->SetMarkerSize(0.1);
    unsigned long pc_total_charge_count=0;
    for(int i=0;i<10;i++)//PropagatedCharge_tree->GetEntries();++i)
    {
        PropagatedCharge_tree->GetEntry(i);
        float x,y,z; //local position
        unsigned long q; //charge
        unsigned long pc_event_charge_count=0;
        for(auto& propagated_charge:propagated_charges)
        {
                x=propagated_charge->getLocalPosition().X();
                y=propagated_charge->getLocalPosition().Y();
                z=propagated_charge->getLocalPosition().Z();
                q=propagated_charge->getCharge();
                npc->Fill(x*1000.0,y*1000.0,z*1000.0,q);//convert to um
                pc_total_charge_count+=q;
                pc_event_charge_count+=q;
        }
        cpc_2d->cd();
        npc->Draw("y:x");
        TH2F* htemp=(TH2F*)gPad->GetPrimitive("htemp");
        htemp->GetXaxis()->SetLimits(-1000,1000);
        std::cout<<"sigma x:"<<htemp->GetStdDev(1)<<" sigma y:"<<htemp->GetStdDev(2)<<"mean :"<<htemp->GetMean(1)<<htemp->GetMean(2)<<htemp->GetMean(3)<<std::endl;
    }

```

Can someone help me with this? Thanks~  
[data\_gene\_simple\_1\_1s.root](https://root-forum.cern.ch/uploads/short-url/zNNYRItbX7OLPkrcwX5rxRNXiXl.root) (56.9 KB) [readpc2d.C](https://root-forum.cern.ch/uploads/short-url/7SpzgGz4trUHCf6tbg9S9pcmiP7.C) (4.4 KB)

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 15, 2019, 9:46am UTC](https://root-forum.cern.ch/t/problem-getting-mean-and-sigma-of-the-th2f-object-created-by-calling-tntuple-draw/36350/2 "2019-10-15T09:46:12Z")

</div>

Please provide the minimal code (and data) to be able to understand what the problem is…

---

<div class="post-metadata">

**Author:** ![thuwang-xz18](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/e274bd/32.png) [@thuwang-xz18](https://root-forum.cern.ch/u/thuwang-xz18)\
**Post date:** [October 15, 2019, 11:36am UTC](https://root-forum.cern.ch/t/problem-getting-mean-and-sigma-of-the-th2f-object-created-by-calling-tntuple-draw/36350/3 "2019-10-15T11:36:36Z")

</div>

I just uploaded my code and data. Thanks for reminding.  
😀

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [October 15, 2019, 11:58am UTC](https://root-forum.cern.ch/t/problem-getting-mean-and-sigma-of-the-th2f-object-created-by-calling-tntuple-draw/36350/4 "2019-10-15T11:58:51Z")

</div>

OK, I can’t use your code, since I don’t have `allpix-squared`, but this simple test properly generate a 2D plot…

```auto
C:\Users\bellenot\rootdev\forum\thuwang-xz18>root -l
root [0] auto f = TFile::Open("data_gene_simple_1_1s.root", "READ");
Warning in <TClass::Init>: no dictionary for class allpix::SensorCharge is available
Warning in <TClass::Init>: no dictionary for class allpix::Object is available
Warning in <TClass::Init>: no dictionary for class allpix::PropagatedCharge is available
root [1] TTree *t = 0;
root [2] f->GetObject("PropagatedCharge", t);
root [3] t->Draw("detector1.local_position_.fCoordinates.fY:detector1.local_position_.fCoordinates.fX", "", "COLZ");
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
root [4]

```

You could also try to use ACLiC (`.x readpc2d.C++`) and debug your code to see where it fails…

Cheers, Bertrand.
