Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <TApplication.h>
- #include <TF1.h>
- #include <TMath.h>
- #include <string>
- #include <TCanvas.h>
- #include <TGraph.h>
- #include <TAxis.h>
- #include <TGraphErrors.h>
- #include <TLegend.h>
- #include <TStyle.h>
- #include <vector>
- #include <algorithm>
- #include <fstream>
- #include <sstream>
- using namespace std;
- template<typename T>
- T StringToNumber(const std::string& numberAsString)
- {
- T valor;
- std::stringstream stream(numberAsString);
- stream >> valor;
- if (stream.fail()) {
- std::runtime_error e(numberAsString);
- throw e;
- }
- return valor;
- }
- double Boltzmann(double* x, double* par){
- // Boltzmann equation
- Double_t xx = x[0];
- Double_t A1 = par[0];
- Double_t A2 = par[1];
- Double_t x0 = par[2];
- Double_t dx = par[3];
- return (par[0] - par[1])/(1+exp(xx-par[2])/par[3]) + par[1];
- }
- struct data
- {
- int rows;
- int colunms;
- vector<string> items;
- };
- data readData(string fileloc){
- cout << "Read in Date from File: " << fileloc << endl;
- ifstream inputFile(fileloc);
- string line;
- string temp;
- stringstream iss;
- vector<string> items;
- int rows = 0;
- int colnms = 0;
- while (getline(inputFile, line, '\n')) // Standard is \n...
- {
- iss << line;
- while (getline(iss, temp, '\t')){
- items.push_back(temp);
- colnms++;
- }
- iss.clear();
- rows++;
- }
- colnms = colnms/rows;
- cout << "Reihen: " << rows << endl;
- cout << "Spalten: " << colnms << endl << endl;
- data retVal = {rows, colnms, items};
- return retVal;
- }
- int main(int argc, char **argv){
- /*
- Read in DATA - tab is delimiter, be careful with your data (there has to be a \t before \n)
- */
- data Data = readData("data.dat");
- vector<double> tempature;
- vector<double> R_s;
- vector<double> sigR_s;
- tempature.reserve(Data.rows);
- R_s.reserve(Data.rows);
- sigR_s.reserve(Data.rows);
- double temp1,temp2,temp3 = 0;
- for(unsigned int i = 0; i < Data.items.size(); ++i){
- if((i % 3) == 0){
- temp1 = StringToNumber<double>(Data.items[i]);
- //cout << "temp1: " << temp1 << endl;
- tempature.push_back(temp1);
- } else if ((i % 3) == 1){
- temp2 = StringToNumber<double>(Data.items[i]);
- //cout << "temp2: " << temp2 << endl;
- R_s.push_back(temp2);
- } else if ((i % 3) == 2) {
- temp3 = StringToNumber<double>(Data.items[i]);
- //cout << "temp3: " << temp3 << endl;
- sigR_s.push_back(temp3);
- } else {
- cout << "Something weird happens!";
- }
- temp1, temp2, temp3 = 0;
- }
- /*
- Plot and Fit data
- */
- double* Atemperature = &tempature[0];
- double* AR_s = &R_s[0];
- double* AsigR_s = &sigR_s[0];
- TApplication theApp("App",&argc,argv);
- TCanvas* can1 = new TCanvas("Squid Resistance", "Squid Resistance",0 ,0 ,900 , 650);
- can1->SetGridx(1);
- can1->SetGridy(1);
- TGraphErrors* errorgraph1 = new TGraphErrors(R_s.size(), Atemperature, AR_s, NULL, AsigR_s);
- errorgraph1->SetTitle("Squid Resistance");
- errorgraph1->GetXaxis()->SetTitle("Temperature [K]");
- errorgraph1->GetYaxis()->SetTitle("Squid Resistance");
- errorgraph1->SetMarkerStyle(kFullCircle);
- errorgraph1->SetMarkerColor(kMagenta);
- TF1* frenMittel = new TF1("BoltzmannEq", Boltzmann, 70, 150, 4);
- frenMittel->SetLineColor(kRed);
- frenMittel->SetParameters(12.19297,67.16567,98.93677,0.59634);
- frenMittel->SetParNames("A1", "A2", "x0", "dx");
- errorgraph1->Fit("BoltzmannEq");
- errorgraph1->Draw("AP");
- gStyle->SetOptFit(1111);
- //TLegend* leg = new TLegend(0, 1, 0.3, 0.8);
- //leg->SetHeader("Legend");
- //leg->AddEntry(errorgraph1, "Data", "ep");
- //leg->AddEntry(frenMittel, "Fit", "l");
- //leg->Draw();
- can1->Update();
- theApp.Run();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement