#include #include #include using namespace std; void readData(const char* filename, vector& x, vector& y, vector& c, int col1, int col2, int col3) { ifstream infile(filename); if (!infile.is_open()) { cerr << "Error opening file: " << filename << endl; return; } string line; bool firstLine = true; // Flag to skip the first line (header) while (getline(infile, line)) { if (firstLine) { firstLine = false; continue; // Skip header line } // Use a stringstream to parse each line into values double value; istringstream iss(line); int column = 1; while (iss >> value) { if (column == col1) { x.push_back(value); // Store column 6 in vector x } else if (column == col2) { y.push_back(value); // Store column 10 in vector y } else if (column == col3) { c.push_back(value); // Store column 11 in vector c } // Move to the next column column++; } } infile.close(); } void scatter() { gStyle->SetPalette(kBird, 0, 0.7); // define a transparent palette gStyle->SetTextFont(132); auto canvas = new TCanvas("canvas", "Scatter Plot", 800, 600); // Set logarithmic scale for Y-axis canvas->SetLogy(); canvas->SetTickx(); canvas->SetTicky(); canvas->SetTopMargin(0.050); canvas->SetRightMargin(0.160); // Read data from file const char* filename = "file.txt"; const char* filename2 = "file2.txt"; vector x, y, c, x2, y2, c2; readData(filename, x, c, y, 6, 10, 11); int n = x.size(); // or y.size() or c.size() // Convert vectors to arrays Double_t* x_array = x.data(); Double_t* y_array = y.data(); Double_t* c_array = c.data(); // Create TScatter object and set properties auto scatter = new TScatter(n, x_array, y_array, c_array); scatter->SetMarkerSize(0.6); scatter->SetMarkerStyle(8); scatter->SetMarkerColor(kBlack); // scatter->SetTitle("Scatter plot;X;Y"); // scatter->GetZaxis()->SetTitle("Color Bar Title"); scatter->GetHistogram()->GetXaxis()->SetTitleFont(132); scatter->GetHistogram()->GetYaxis()->SetTitleFont(132); scatter->GetHistogram()->GetXaxis()->SetTitle("X-axis Title"); scatter->GetHistogram()->GetYaxis()->SetTitle("Y-axis Title"); scatter->GetHistogram()->GetZaxis()->SetTitle("Color Bar Title"); scatter->GetHistogram()->GetXaxis()->CenterTitle(); scatter->GetHistogram()->GetYaxis()->CenterTitle(); // scatter->GetHistogram()->GetZaxis()->SetTitleOffset(10.); // scatter->GetHistogram()->GetZaxis()->SetTitleSize(.04); scatter->GetHistogram()->GetXaxis()->SetLimits(650.,1400.); scatter->GetHistogram()->GetYaxis()->SetLimits(0.015,0.35); scatter->GetHistogram()->GetZaxis()->SetLimits(30,100); // Draw the scatter plot on the canvas canvas->cd(); // Activate the canvas scatter->Draw("A"); // Create a line plot (TGraph) TGraph* graph = new TGraph(filename2,"%lg %lg"); graph->SetLineColor(kBlack); graph->SetLineWidth(2); // graph->GetHistogram()->GetYaxis()->SetMinimum(0.015); graph->Draw("LP"); // Draw the line plot with lines and points // Update the canvas canvas->SetTickx(); canvas->SetTicky(); gPad->Modified(); gPad->Update(); canvas->Update(); canvas->SaveAs(".pdf"); }