Exemple #1
0
void rootFit(){

  TCanvas *c1 = new TCanvas("c1","",600,600);
  c1->Divide(1,2);
  TNtuple *T = new TNtuple("T","","x:y:z");
  T->ReadFile("histogramData.dat");
  T->Draw("y:x");

  Double_t *X = T->GetV1();
  Double_t *Y = T->GetV2();

  for(int loop = 0; loop < 120; loop++){
    cout << X[loop] << "  " << Y[loop] << endl;
  }

  c1->Clear();
  TGraph *graphT = new TGraph(120,Y,X);
  TGraph *graphB = new TGraph(120,Y,X);
  c1->cd(1);
  graphT->Draw("APL");
  graphT->Fit("gaus+pol2","RME");

}
Exemple #2
0
DataFile::GetData(){
  stringstream convert;
  int nameVal = 0;
  convert.str(filename);
  convert >> nameVal;
  bool success = false;
  //Find file type
  string type = "";
  size_t pos = filename.find_last_of('.');
  if(gType.compare("XS")==0){
    TNtuple newData ("newData","", cols.c_str() );
    newData.ReadFile(name.c_str());
    cout<<"TNtuple created"<<endl;
    dataTuple = (TNtuple*) newData.Clone();
    cout<<name.c_str()<<endl;
    cout<<dataTuple<<endl;
    success = true;
  }
  else{
    if(pos != string::npos){
      if(filename[pos+1] == 'r'){
        if(filename[pos-1] == 'e'){
          type.assign("ginuke");
        }
        else{
          type.assign("gst");
        }
      }
      else{
        type.assign("txt");
      }
    }
    else{
      type.assign("chain");
    }
    if(type[0]!='t'){
      if(type[0]=='g'){
        //Normal .ginuke file, Easy
        file = new TFile(name.c_str());
        if(file->IsOpen()){
          TTree* dummy = file->Get(type.c_str());
          dataTree = (TTree*)dummy->Clone(); 
          delete dummy;
          success=true;
        }
        else{
          cout<<name.c_str()<<" was not found. Skipping [GENIE] tag."<<endl;
          success=false;
        }
      }
      //Chaining together some files
      else{
        TChain chain("ginuke");
        TChain* dummy = &chain;
        //Need to have name separate from directory in order to properly construct this filename.
        string n = dir+"/gntp.*"+filename+"*.ginuke.root";
        cout<<"Making a chain called "<<n<<endl;
        chain.Add(n.c_str());
        cout<<"Chain created."<<endl;
        dataTree = (TTree*)dummy->Clone();
        cout<<"dummy cloned"<<endl;
        success=true;
      }
    }
    else{
      //Grabbing simple data from the text file
      dataTree = new TTree("textData",title.c_str());
      int nCol = this->analyzeTextFile();
      success = true;
      if(gType.compare("Energy")==0){
        if(nCol==3){dataTree->ReadFile(name.c_str(),"E/D:xsec:err1");}
        else if(nCol==2){dataTree->ReadFile(name.c_str(),"E/D:xsec");}
        else{cout<<"Published data file has an unrecognized format."<<endl;
             success=false;}
      }
      if(gType.compare("Momentum")==0){
        if(nCol==3){dataTree->ReadFile(name.c_str(),"ph/D:xsec:err1");}
        else if(nCol==2){dataTree->ReadFile(name.c_str(),"ph/D:xsec");}
        else{cout<<"Published data file has an unrecognized format."<<endl;
             success=false;}
      }
      if(gType.compare("Angle")==0){
        if(nCol==3){dataTree->ReadFile(name.c_str(),"cth/D:xsec:err1");}
        else if(nCol==2){dataTree->ReadFile(name.c_str(),"cth/D:xsec");}
        else{cout<<"Published data file has an unrecognized format."<<endl;
             success=false;}
      }
    }
  }

  return success;
}