#include #include #include #include #include #include #include #include #include #include "TStyle.h" #include #include #include #include #include using namespace std; void drawzx() { ifstream in; in.open("cellfluxeminus.txt",ios_base::in); //read data string line; double x; double y; double z; double a,b,c; string str; int nlines = 0; double mass_array[200]; double neutron_array[200]; for (int i = 0; i < 200; i++) { mass_array[i] =neutron_array[i]=0; } gStyle->SetOptTitle(3); //3 is display title gStyle->SetOptStat(1); // gStyle->SetPalette(1); //二维数据图例设置 gStyle->SetPaintTextFormat("1.1e"); TCanvas *c1 = new TCanvas("c1","test1",1500,1000); //画布 TH2F *h1 = new TH2F("HIST","Electron fluence", 80, -20, 100,80, -1, 1); getline(in,str); getline(in,str); getline(in,str); //c1->SetLogy(); while (getline(in, line)) { std::istringstream iss(line); // double x, y, z, a, b, c; char comma; if (!(iss >> x >> comma >> y >> comma >> z >> comma >> a >> comma >> b >> comma >> c)) { std::cerr << "Failed to parse line: " << line << std::endl; continue; } h1->Fill(z*120/100-20,x*2/100-1,a); //除100是因为y方向上划分为100格,是100个bin叠加起来的通量,因此要除100(这里没有对粒子数量归一化) //但是画二维图好像是个相对量,不理解 } //const Int_t Number = 6; //Double_t Red[Number] = { 1.00, 0.00, 0.00,0.00, 0.50, 1.00}; //Double_t Green[Number] = { 0.00, 1.00, 0.00,0.00, 0.00, 1.00}; //Double_t Blue[Number] = { 1.00, 0.00, 1.00,1.00, 1.00, 1.00}; //Double_t Length[Number] = { 0, 1.0E-02, 1.0,10.0,100,1000}; //Int_t nb=100; //TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb); h1 -> SetStats(0); h1->SetXTitle("Z [cm]"); h1->SetYTitle("X [cm]"); h1->GetXaxis()->CenterTitle(); h1->GetYaxis()->CenterTitle(); h1->GetXaxis()->SetTitleOffset(1.2); TPaletteAxis *paletteAxis = (TPaletteAxis*)h1->GetListOfFunctions()->FindObject("palette"); if (paletteAxis) { // 设置标题 paletteAxis->SetTitle("cm^{-2} per primary"); } //h1->SetMaximum(1000000); //Double_t zcontours[6] = {0,0.02,0.03,0.04,0.05,0.06}; //h1->SetContour(6, zcontours); h1->GetZaxis()->SetTickSize(0.01); h1->GetZaxis()->SetLabelOffset(0.01); c1->SetRightMargin(0.2); // h1->Draw("COLZ CJUST"); //h1->Draw("colz2 CJUST"); h1->Draw("COLZ"); ///////////////////////////////////////////Draw Style///////////////////////////////////////////// //h1 Style h1 -> SetYTitle("x [cm] ");//Set Y Title h1 -> SetXTitle("z [cm] ");//Set X Title h1 -> SetLineColor(kRed+1);//Set line color h1 -> SetLineWidth(2);//Set line width, always seted as 2 h1 -> Scale((double)(1)/(h1->GetEntries()));//Scale h1 -> SetTitleOffset(1.15); h1->GetXaxis()->CenterTitle();//标题居中 h1->GetYaxis()->CenterTitle(); h1->GetXaxis()->SetTitleSize(.05);//设置标题字号 h1->GetYaxis()->SetTitleSize(.05); in.close(); }