#include "TFile.h" #include "TCanvas.h" #include "TStyle.h" #include "TH1.h" #include "TH2.h" #include "TH3.h" #include "TGaxis.h" #include "TRandom.h" #include "TLegend.h" #include "TPaveStats.h" #include "TGraph.h" #include "TSystem.h" #include "TTree.h" #include "TTreePlayer.h" #include "TF1.h" #include "TCut.h" #include "TPaletteAxis.h" #include "stdio.h" #include "stdlib.h" #include "string.h" void scorelemma() { double R; //R coordinate double phi; //phi coordinate double z; //z coordinate double relen; //Released energy double relenq; //Released energy double ev; //Events double w; int Rmin=0; int Rmax=25; int n=3; int i=0; int entry=1; int c_YTitleSize=25; int c_YTitleFont=43; int c_YLabelFont=43; int c_YLabelSize=25; int c_XTitleSize=25; int c_XTitleFont=43; int c_XLabelFont=43; int c_XLabelSize=25; double c_XTitleOffsetTH3=1.; double c_YTitleOffsetTH3=1.; double c_ZTitleOffsetTH3=0.5; float fillcolor=0.35; char dirin[50];//Directory where there is the input root file char dirout[50];//Main Directory where to save the output files char dirname[50]; char title[50]; char titleX[50]; char titleY[50]; char titleZ[50]; char titlecanv[50]; char informat[50]; char outformat[50]; char inname[50]; char scorname[50]; char volume[50]; sprintf(dirin, "C:/"); sprintf(dirout, "C:/"); sprintf(dirname, "scoring/"); sprintf(inname, "boxMesh_1"); //sprintf(inname, "boxMesh_2"); sprintf(informat, "txt"); sprintf(outformat, "pdf"); sprintf(scorname, "scoring"); sprintf(volume, "Target_1"); // sprintf(volume, "Target 2"); sprintf(title, "Energy density"); sprintf(titleX, "R (mm)"); //sprintf(titleY, "#phi"); sprintf(titleY, "z (mm)"); sprintf(titleZ, "Energy Density (Mev/mm^3)"); /*gSystem->mkdir(TString::Format("%s%s", dirout,dirname), kTRUE); TString outfolder=TString::Format("%s%s",dirout,dirname); TString myfile=TString::Format("%s%s.%s",dirin,inname,informat);*/ TString cdname = TString::Format("%s",title); TString cdXname = TString::Format("%s",titleX); TString cdYname = TString::Format("%s",titleY); TString cdZname = TString::Format("%s",titleZ); TString canvtitle = TString::Format("%s",titlecanv); // TString myplot = TString::Format("%s%s-%s.%s",outfolder.Data(), scorname, volume,outformat); TString myplot = TString::Format("C:/simulazione/Ene_dens.png"); TGaxis::SetMaxDigits(n); // FILE * infile=fopen(myfile, "r"); // FILE * infile=fopen("C:/scoring/boxMesh_1.txt", "r"); FILE * infile=fopen("C:/data.txt", "r"); if(infile==NULL) { printf("Error opening file"); exit(1); } TCanvas *c0 = new TCanvas("c0",canvtitle,1280,1024); // TH3F *hscoring = new TH3F("hscoring","Released energy",300,0.,300.,1,0.,1.,10,0.,10.); TH2F *hscoring = new TH2F("hscoring","Energy Density",10,-5,5.,4,-1,3); // TH2F *hscoring = new TH2F("hscoring","Released energy",300,0.,300.,5,0.,5.); while( fscanf(infile,"%lf %lf %lf",&R,&z,&relen)==3) { //hscoring->Fill(R,z,relen); std::cout << "entry = " << entry << "\t R = " << R << "\t z = " << z << "\t Rel en = " << relen << std::endl; entry=entry+1; // if (R>=Rmin && R<=Rmax){ hscoring->Fill(R,z,relen); // } } const Int_t Number = 3; Double_t Red[Number] = { 1.00, 0.00, 0.00}; Double_t Green[Number] = { 0.00, 1.00, 0.00}; Double_t Blue[Number] = { 1.00, 0.00, 1.00}; Double_t Length[Number] = { 0.00, 20000., 40000. }; Int_t nb=50; TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb); hscoring->SetTitle(cdname); hscoring->GetXaxis()->SetTitle(cdXname); hscoring->GetYaxis()->SetTitle(cdYname); hscoring->GetZaxis()->SetTitle(cdZname); hscoring->GetYaxis()->SetTitleSize(c_YTitleSize); hscoring->GetYaxis()->SetTitleFont(c_YTitleFont); hscoring->GetYaxis()->SetTitleOffset(c_YTitleOffsetTH3); hscoring->GetYaxis()->SetLabelFont(c_YLabelFont); hscoring->GetYaxis()->SetLabelSize(c_YLabelSize); hscoring->GetXaxis()->SetTitleSize(c_XTitleSize); hscoring->GetXaxis()->SetTitleFont(c_XTitleFont); hscoring->GetXaxis()->SetTitleOffset(c_XTitleOffsetTH3); hscoring->GetXaxis()->SetLabelFont(c_XLabelFont); hscoring->GetXaxis()->SetLabelSize(c_XLabelSize); hscoring->GetZaxis()->SetTitleSize(c_XTitleSize); hscoring->GetZaxis()->SetTitleFont(c_XTitleFont); hscoring->GetZaxis()->SetTitleOffset(c_ZTitleOffsetTH3); hscoring->GetZaxis()->SetLabelFont(c_XLabelFont); hscoring->GetZaxis()->SetLabelSize(c_XLabelSize); //hscoring->Project3D("XZ")->Draw("COLZ") hscoring->Draw("CONT4Z"); // hscoring->Draw("SURF1"); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn /* TPaveStats *statshscoring = (TPaveStats*)hscoring->GetListOfFunctions()->FindObject("stats"); statshscoring->SetTextColor(kBlue); statshscoring->SetX1NDC(0.80); statshscoring->SetX2NDC(0.98); statshscoring->SetY1NDC(0.77); statshscoring->SetY2NDC(0.92); gPad->Update();*/ c0->Print(myplot); }