#include #include #include #include #include #include #include #include #include "TSystem.h" #include "TFile.h" #include "TH1.h" #include "TTree.h" #include "TClass.h" #include "TCanvas.h" #include "TPad.h" #include "TStyle.h" #include "TGaxis.h" #include "Riostream.h" #include "TGraphErrors.h" #include "TVectorD.h" void StudyData(){ gROOT->Reset(); TCanvas* canV = new TCanvas("canV", "PLOT", 800, 650); gPad->SetLogx(); gPad->SetLogy(); canV->SetFillColor(42); canV->GetFrame()->SetFillColor(21); canV->GetFrame()->SetBorderSize(12); auto mg = new TMultiGraph(); float xLeg1 = 0.62, yLeg1 = 0.75, xLeg2 = xLeg1 + 0.25, yLeg2 = yLeg1 + 0.125; auto thisLeg = new TLegend(xLeg1, yLeg1, xLeg2, yLeg2); thisLeg->SetFillColor(0); std::vector a1; std::vector a2; std::vector a3; std::vector a4; std::vector a5; std::vector a6; std::string lines; int totDataFileNum = 50; double temp1, ylow, yhi; ... ... // Read all Data File and store Data in loop for (Int_t icnt = 0; icnt < totDataFileNum; icnt++) { while(std::getline(inFile, lines)){ // Read Data // CM energy ...... ...... // YRAP Range if (lines.size() < 30 && lines.find("YRAP") != std::string::npos) { found1 = lines.find("YRAP"); found2 = lines.find("-"); int lenfound1 = found2 - (found1 + 7) - 1; int lenfound2 = lines.size() - found2 + 1; std::string dummy1 = lines.substr(found1 + 8, lenfound1); std::stringstream ss1(dummy1); ss1 >> ylow; std::string dummy2 = lines.substr(found2 + 1, lenfound2); std::stringstream ss2(dummy2); ss2 >> yhi; } if (lines.size() != 0 && lines.at(0) != '#' && !isalpha(lines.at(0))) { double temp1; char bhul; double pt, ptL, ptH, d2, statP, statM, sys1P, sys1M, sys2P, sys2M; std::istringstream ss(lines); ss >> pt >> bhul >> ptL >> bhul >> ptH >> bhul >> d2 >> bhul >> statP >> bhul >> statM >> bhul >> sys1P >> bhul >> sys1M >> bhul >> sys2P >> bhul >> sys2M; a1.push_back(pt); // XData a2.push_back(d2); // YData ..... ..... temp1 = pt - ptL; a3.push_back(temp1); // xErrM temp1 = ptH - pt; a4.push_back(temp1); // xErrP temp1 = statM + sys1M; a5.push_back(temp1); // yErrM temp1 = statP + sys1P; a6_back(temp1); // yErrP } } // ------------------------------------- while getline ends here --------------------- inFile.close(); std::stringstream ss1, ss2; ss1 << fixed << setprecision(1) << ylow; ss2 << fixed << setprecision(1) << yhi; std::string s1 = ss1.str(); std::string s2 = ss2.str(); std::string legTxt = s1 + "< |YRAP| <" + s2; TVectorD XData; TVectorD YData; TVectorD xErrM; TVectorD xErrP; TVectorD yErrM; TVectorD yErrP; XData.ResizeTo(a4.size()); XData.SetElements(&a4[0]); YData.ResizeTo(a7.size()); YData.SetElements(&a7[0]); xErrM.ResizeTo(a15.size()); xErrM.SetElements(&a15[0]); xErrP.ResizeTo(a16.size()); xErrP.SetElements(&a16[0]); yErrM.ResizeTo(a17.size()); yErrM.SetElements(&a17[0]); yErrP.ResizeTo(a18.size()); yErrP.SetElements(&a18[0]); if (ylow == 0.0 && yhi == 0.9) { TGraphAsymmErrors* gr1 = new TGraphAsymmErrors(XData, YData, xErrM, xErrP, yErrM, yErrP); gr1->SetMarkerColor(2); gr1->SetMarkerStyle(4); gr1->SetMarkerSize(1.3); gr1->SetTitle(legTxt.c_str()); thisLeg->AddEntry(gr1, legTxt.c_str(), "p"); if (icnt == 0) { gr1->Draw("ap"); } else { gr1->Draw("p same"); } mg->Add(gr1); } if (ylow == 0.9 && yhi == 1.2) { TGraphAsymmErrors* gr2 = new TGraphAsymmErrors(XData, YData, xErrM, xErrP, yErrM, yErrP); gr2->SetMarkerColor(3); gr2->SetMarkerStyle(25); gr2->SetMarkerSize(1.3); gr2->SetTitle(legTxt.c_str()); thisLeg->AddEntry(gr2, legTxt.c_str(), "p"); if (icnt == 0) { gr2->Draw("ap"); } else { gr2->Draw("p same"); } mg->Add(gr2); } if (ylow == 1.2 && yhi == 1.6 ) { TGraphAsymmErrors* gr3 = new TGraphAsymmErrors(XData, YData, xErrM, xErrP, yErrM, yErrP); gr3->SetMarkerColor(4); gr3->SetMarkerStyle(26); gr3->SetMarkerSize(1.3); gr3->SetTitle(legTxt.c_str()); thisLeg->AddEntry(gr3, legTxt.c_str(), "p"); if (icnt == 0) { gr3->Draw("ap"); } else { gr3->Draw("p same"); } mg->Add(gr3); } if (ylow == 1.6 && yhi == 2.1 ) { TGraphAsymmErrors* gr4 = new TGraphAsymmErrors(XData, YData, xErrM, xErrP, yErrM, yErrP); gr4->SetMarkerColor(7); gr4->SetMarkerStyle(27); gr4->SetMarkerSize(1.3); gr4->SetTitle(legTxt.c_str()); thisLeg->AddEntry(gr4, legTxt.c_str(), "p"); if (icnt == 0) { gr4->Draw("ap"); } else { gr4->Draw("p same"); } mg->Add(gr4); } if (ylow == 2.1 && yhi == 2.4) { TGraphAsymmErrors* gr5 = new TGraphAsymmErrors(XData, YData, xErrM, xErrP, yErrM, yErrP); gr5->SetMarkerColor(40); gr5->SetMarkerStyle(28); gr5->SetMarkerSize(1.3); gr5->SetTitle(legTxt.c_str()); thisLeg->AddEntry(gr5, legTxt.c_str(), "p"); if (icnt == 0) { gr5->Draw("ap"); } else { gr5->Draw("p same"); } mg->Add(gr5); } } //-------------------------------------------- FOR loop for reading files --------------------------- mg->Draw("ap"); thisLeg->Draw(); canV->Update(); canV->Modified(); canV->SaveAs("saveGraph.png"); canV->Close(); }