# Error of \*\*\*Break\*\*\*Segmentation-violation

**URL:** <https://root-forum.cern.ch/t/error-of-break-segmentation-violation/49678>\
**Category:** Newbie\
**Created:** [April 21, 2022, 6:53pm UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/49678 "2022-04-21T18:53:56Z")\
**Posts on this page:** 2\
**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 21, 2022, 6:53pm UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/49678/1 "2022-04-21T18:53:56Z")

</div>

My program has been giving the error of break segmentation violation but if I try running the code in chunk it works fine.  
‘’'void Percent\_beyond\_threshold(TString file1, TString file2)  
{

```
TH1D* beyondthreshold_stable =new TH1D("Beyond Threshold", "Threshold", Numbins, MinBound, MaxBound);
beyondthreshold_stable->GetXaxis()->SetTitle("Current[#muA]");
beyondthreshold_stable->GetYaxis()->SetTitle("Percentage");
beyondthreshold_stable->SetLineColor(kRed);
beyondthreshold_stable->SetMarkerStyle(7);
beyondthreshold_stable->SetName("Stable Current Distribution");
beyondthreshold_stable->Sumw2(kTRUE);
for (ULong64_t i = 0; i< Numbins;i++)
{
    threshold1 = i;
    Int_t abovee=0;
    for(ULong64_t e=0; e<n;e++)
    {
        t1->GetEntry(e);
        if(abs(curr2)>=threshold1)
        {
            abovee++;
        }
        np = (1.0*abovee)/(1*n);
        beyondthreshold_stable->SetBinContent(i+1,np);
    }
    /*if(i)
        beyondthreshold_stable->SetBinError(i+1, sqrt(np*(1-np)/m));
    else   
        beyondthreshold_stable->SetBinError(i+1,0.0);*/
}
hs.Add(beyondthreshold);

TCanvas* c1= new TCanvas();
TText T; T.SetTextFont(42); T.SetTextAlign(21);
beyondthreshold->Draw();
beyondthreshold_stable->Draw("same");
c1->Divide(1,1);
c1->cd(1);
gStyle->SetOptStat(0);
hs.Draw(); 
hs.DrawClone("nostack");
return c1;
TFile outputFile("Decvsjan.root", "recreate");
    curr_vals_raw->Write("Current December");
    curr_vals_stable->Write("Current January");
outputFile.Close();

```

}’’’

---

<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 21, 2022, 6:59pm UTC](https://root-forum.cern.ch/t/error-of-break-segmentation-violation/49678/2 "2022-04-21T18:59:43Z")

</div>

See “triple backticks” in: [About the Newbie category](https://root-forum.cern.ch/t/about-the-newbie-category/30794)

BTW. The “`f1.Close();`” call automatically deletes the “`t1`” tree (i.e., this pointer is “invalidated”).
