#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 int n=3; int i=0; int c_YTitleSize=25; int c_YTitleFont=43; double c_YTitleOffset=1.; int c_YLabelFont=43; int c_YLabelSize=25; int c_XTitleSize=25; int c_XTitleFont=43; double c_XTitleOffset=1.1; int c_XLabelFont=43; int c_XLabelSize=25; double c_XTitleOffsetTH3=2.; double c_YTitleOffsetTH3=2.; double c_ZTitleOffsetTH3=2.; 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, "Released energy %s",volume); sprintf(titleX, "R"); sprintf(titleY, "#phi"); sprintf(titleZ, "z"); 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); TGaxis::SetMaxDigits(n); FILE * infile=fopen(myfile, "r"); if(infile==NULL) { printf("Error opening file"); exit(1); } //---------------------------------------------------------------------TARGET 1 -------------------------------------------------------------// TCanvas *c0 = new TCanvas("c0",canvtitle,1280,1024); TH3F *hscoring = new TH3F("hscoring","Released energy",100,0.,0.,100,0.,0.,100,0.,0.); while( fscanf(infile,"%lf %lf %lf %lf %lf %lf",&z,&phi,&R,&relen,&relenq,&ev)!=NULL) { printf("z=%lf \t phi=%lf \t R=%lf \t E=%lf \t ev=%lf \n",z,phi,R,relen,ev); hscoring->Fill(z,phi,R); i++; } gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn 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_YTitleOffset); hscoring->GetYaxis()->SetLabelFont(c_YLabelFont); hscoring->GetYaxis()->SetLabelSize(c_YLabelSize); hscoring->GetXaxis()->SetTitleSize(c_XTitleSize); hscoring->GetXaxis()->SetTitleFont(c_XTitleFont); hscoring->GetXaxis()->SetTitleOffset(c_XTitleOffset); hscoring->GetXaxis()->SetLabelFont(c_XLabelFont); hscoring->GetXaxis()->SetLabelSize(c_XLabelSize); hscoring->GetZaxis()->SetTitleSize(c_XTitleSize); hscoring->GetZaxis()->SetTitleFont(c_XTitleFont); hscoring->GetZaxis()->SetTitleOffset(c_XTitleOffset); hscoring->GetZaxis()->SetLabelFont(c_XLabelFont); hscoring->GetZaxis()->SetLabelSize(c_XLabelSize); hscoring->SetMarkerSize(50); hscoring->Draw("COLZ"); //hscoring->SetName(htempname); gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TH1 *hscoringcopy = hscoring->DrawCopy("colz"); // creates all axes gPad->Modified(); gPad->Update(); // make sure it's really (re)drawn TPaletteAxis * palette = (TPaletteAxis *) hscoringcopy->GetListOfFunctions()->FindObject("palette"); palette->SetX1NDC(0.86); palette->SetX2NDC(0.90); palette->SetY1NDC(0.2); palette->SetY2NDC(0.8); c0->Modified(); c0->Update(); TLegend* leghscoring = new TLegend(0.65, 0.7, .75, .75); leghscoring->SetHeader("Legend"); leghscoring->SetNColumns(1); leghscoring->AddEntry(leghscoring, "MC", "l"); leghscoring->Draw(); gPad->Update(); 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); delete c0; }