17 #include "TDirectory.h"
26 gErrorIgnoreLevel = kError;
27 cout <<
"\n Beginning quick tree plotting..." << endl;
30 const TString sOutput =
"newMatcher.allVsWeirdVsNormal.pt020n15pim.d24m8y2023.root";
31 const TString sInput =
"input/merged/sPhenixG4_testingNewMatcher_newMatcher_run0.pt020n15pim.d14m8y2023.root";
32 const TString sInTree =
"T";
35 const vector<TString> vecCutsToApply = {
40 const vector<TString> vecCutLabels = {
47 const vector<TString> vecToDraw1D = {
52 const vector<TString> vecHistNames1D = {
59 const vector<TString> vecToDraw2D = {
64 const vector<TString> vecHistNames2D = {
66 "hDeltaPtOverPtVsFracPt",
69 const vector<TString> vecHistOpts2D = {
76 const Ssiz_t nToDraw1D = vecToDraw1D.size();
77 const Ssiz_t nToDraw2D = vecToDraw2D.size();
78 const Ssiz_t nCutsToApply = vecCutsToApply.size();
80 TString sHistToDraw1D;
81 TString sHistToDraw2D;
82 vector<TString> vecHistToDraw1D;
83 vector<TString> vecHistToDraw2D;
84 for (Ssiz_t iCutToApply = 0; iCutToApply < nCutsToApply; iCutToApply++) {
85 for (Ssiz_t iToDraw1D = 0; iToDraw1D < nToDraw1D; iToDraw1D++) {
88 sHistToDraw1D = vecHistNames1D[iToDraw1D].Data();
89 sHistToDraw1D.Append(
"_");
90 sHistToDraw1D.Append(vecCutLabels[iCutToApply].
Data());
93 vecHistToDraw1D.push_back(sHistToDraw1D.Data());
95 for (Ssiz_t iToDraw2D = 0; iToDraw2D < nToDraw2D; iToDraw2D++) {
98 sHistToDraw2D = vecHistNames2D[iToDraw2D].Data();
99 sHistToDraw2D.Append(
"_");
100 sHistToDraw2D.Append(vecCutLabels[iCutToApply].
Data());
103 vecHistToDraw2D.push_back(sHistToDraw2D.Data());
106 cout <<
" Constructed histogram lists." << endl;
109 TFile* fOutput =
new TFile(sOutput.Data(),
"recreate");
110 TFile* fInput =
new TFile(sInput.Data(),
"read");
111 if (!fOutput || !fInput) {
112 cerr <<
"PANIC: couldn't open a file!\n"
113 <<
" fOutput = " << fOutput <<
", fInput = " << fInput <<
"\n"
117 cout <<
" Opened files." << endl;
120 TTree* tToDrawFrom = (TNtuple*) fInput ->
Get(sInTree.Data());
122 cerr <<
"PANIC: couldn't grab input tuple!\n" << endl;
125 cout <<
" Grabbed input tuple.\n"
126 <<
" Beginning draw loop..."
130 Ssiz_t iHistToDraw1D = 0;
131 Ssiz_t iHistToDraw2D = 0;
132 TString sDrawArg1D =
"";
133 TString sDrawArg2D =
"";
134 for (Ssiz_t iCutToApply = 0; iCutToApply < nCutsToApply; iCutToApply++) {
135 for (Ssiz_t iToDraw1D = 0; iToDraw1D < nToDraw1D; iToDraw1D++) {
138 sDrawArg1D = vecToDraw1D[iToDraw1D].Data();
139 sDrawArg1D.Append(
">>");
140 sDrawArg1D.Append(vecHistToDraw1D[iHistToDraw1D].
Data());
141 cout <<
" Drawing '" << sDrawArg1D.Data() <<
"'..." << endl;
144 tToDrawFrom ->
Draw(sDrawArg1D.Data(), vecCutsToApply[iCutToApply].Data());
147 for (Ssiz_t iToDraw2D = 0; iToDraw2D < nToDraw2D; iToDraw2D++) {
150 sDrawArg2D = vecToDraw2D[iToDraw2D].Data();
151 sDrawArg2D.Append(
">>");
152 sDrawArg2D.Append(vecHistToDraw2D[iHistToDraw2D].
Data());
153 cout <<
" Drawing '" << sDrawArg2D.Data() <<
"'..." << endl;
156 tToDrawFrom ->
Draw(sDrawArg2D.Data(), vecCutsToApply[iCutToApply].Data());
160 cout <<
" Drew histograms from tuple." << endl;
163 const Ssiz_t nHistToDraw1D = vecHistToDraw1D.size();
164 const Ssiz_t nHistToDraw2D = vecHistToDraw2D.size();
166 TH1D* hHistToDraw1D[nHistToDraw1D];
167 TH2D* hHistToDraw2D[nHistToDraw2D];
168 for (Ssiz_t iHist1D = 0; iHist1D < nHistToDraw1D; iHist1D++) {
172 hHistToDraw1D[iHist1D] = (TH1D*) gDirectory ->
Get(vecHistToDraw1D[iHist1D].
Data());
176 hHistToDraw1D[iHist1D] ->
Write();
178 for (Ssiz_t iHist2D = 0; iHist2D < nHistToDraw2D; iHist2D++) {
182 hHistToDraw2D[iHist2D] = (TH2D*) gDirectory ->
Get(vecHistToDraw2D[iHist2D].
Data());
186 hHistToDraw2D[iHist2D] ->
Write();
188 cout <<
" Saved histograms." << endl;
195 cout <<
" Closed files." << endl;
198 cout <<
" Finished quick tree plotting!\n" << endl;