Hi I tried drawing a step Function but ran into a segmentation error. I tried reducing the array number to 7( the minimum) but I can’t seem to fix it. I wonder if I have missed something or misunderstood some root convention.
Thanks in advance.
[code]#include <stdio.h>
#include “TFile.h”
#include “TF1.h”
#include
#include
#include
#include “TGraph.h”
#include “TGraphErrors.h”
#include “TCanvas.h”
#include “TMultigraph.h”
using namespace std;
void FiducialLimit(void){
TF1 *f[7];
TGraph *gr[7];
//F is the different y values of the step-wise function for this particular graph
//100 is the number of steps possible in this function
double m[7], c[7];
int i, j=0, k=1;
int n;
ifstream infile;
string fileName;
TMultiGraph *mg = new TMultiGraph;
// mg->GetXaxis()->SetLimit(0, 600);
mg->SetMaximum(10^3);
mg->SetMinimum(0.001);
std::cout<<"What is the file name(including the .txt ext)?"<<endl;
cin>>fileName;
//Declaring the size dependent/name independent variables
TFile *CrossSection = new TFile(Form("/Users/Desktop/Working_Programs/Temp_Root_Files/%s.root",fileName.c_str()), "RECREATE");
//reading in the points in the txt file.
infile.open(Form("/Users/Desktop/Working_Programs/Input_txt/Fiducial_CrossSection/%s",fileName.c_str()));
while (!infile.eof()) {
infile >>m[k]>>c[k];
cout<<m[k]<<" "<<c[k]<<endl;
k++;
}
k--;
m[0]=0;//The X-axis starts at 0
for (i=1; i<k; i++){
f[i]->SetParameter(0,c[k]);
f[i]= new TF1(Form("f%f",m[k]),"[0]",m[k-1],m[k]);
gr[i]->Fit(Form("f[%d]",i),"R");
mg->Add(gr[i]);
}
mg->SetTitle("Cross Section(pB) vs Mass(GeV),Mass (GeV),Cross Section(pB)");
//mg->GetYaxis()->SetTitle("Cross Section(pB)");
TCanvas *c1= new TCanvas();
c1->SetLogy();
mg->Draw("APL");
}[/code]
Error:
root [0] .x FiducialLimit.C+
Info in TMacOSXSystem::ACLiC: creating shared library /Users/Desktop/Working_Programs/./FiducialLimit_C.so
What is the file name(including the .txt ext)?
ePlusEPlus.txt
15 0.032
100 0.014
200 0.0053
300 0.0033
400 0.00203
500 0.0011
600 0.00102
*** Break *** segmentation violation
Generating stack trace…
0x000000010a4d58c8 in Cint::G__ExceptionWrapper(int ()(G__value, char const*, G__param*, int), G__value*, char*, G__param*, int) (in libCint.so) + 49
0x000000010a5631d8 in G__execute_call (in libCint.so) + 75
0x000000010a56363a in G__call_cppfunc (in libCint.so) + 866
0x000000010a542a0b in G__interpret_func (in libCint.so) + 3624
0x000000010a5322f1 in G__getfunction (in libCint.so) + 5802
0x000000010a527beb in G__getitem (in libCint.so) + 511
0x000000010a52360c in G__getexpr (in libCint.so) + 29988
0x000000010a51c02c in G__calc_internal (in libCint.so) + 783
0x000000010a596fdb in G__process_cmd (in libCint.so) + 15800
0x0000000109e853db in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) (in libCore.so) + 773
0x0000000109e8566c in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (in libCore.so) + 116
0x0000000109df8f7a in TApplication::ExecuteFile(char const*, int*, bool) (in libCore.so) + 2380
0x0000000109df7e45 in TApplication::ProcessLine(char const*, bool, int*) (in libCore.so) + 1509
0x000000010abbaeea in TRint::HandleTermInput() (in libRint.so) + 678
0x0000000109eb72af in TUnixSystem::CheckDescriptors() (in libCore.so) + 171
0x0000000109ec032d in TMacOSXSystem::DispatchOneEvent(bool) (in libCore.so) + 261
0x0000000109e4c894 in TSystem::InnerLoop() (in libCore.so) + 26
0x0000000109e4c7a9 in TSystem::Run() (in libCore.so) + 353
0x0000000109df91da in TApplication::Run(bool) (in libCore.so) + 36
0x000000010abba85d in TRint::Run(bool) (in libRint.so) + 1409
0x0000000109de8e1f in main (in root.exe) + 79
0x00007fff84f285fd in start (in libdyld.dylib) + 1
Root >
ePlusEPlus.txt (75 Bytes)