Skip to content

Commit 51be778

Browse files
committed
Make unfold tutorials ready for implicit object ownership=off.
1 parent 8f4e7f6 commit 51be778

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

tutorials/analysis/unfold/testUnfold5c.C

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ void testUnfold5c()
104104

105105
TUnfoldBinning *detectorBinning,*generatorBinning;
106106

107-
outputFile->cd();
108-
109107
// read binning schemes in XML format
110108
#ifndef READ_BINNING_CINT
111109
TDOMParser parser;
@@ -122,8 +120,8 @@ void testUnfold5c()
122120

123121
delete binningSchemes;
124122
#endif
125-
detectorBinning->Write();
126-
generatorBinning->Write();
123+
outputFile->WriteTObject(detectorBinning);
124+
outputFile->WriteTObject(generatorBinning);
127125

128126
if(detectorBinning) {
129127
detectorBinning->PrintStream(cout);
@@ -154,10 +152,10 @@ void testUnfold5c()
154152
Float_t etaRec,ptRec,discr,etaGen,ptGen;
155153
Int_t istriggered,issignal;
156154

157-
outputFile->cd();
158-
159155
TH1 *histDataReco=detectorBinning->CreateHistogram("histDataReco");
160156
TH1 *histDataTruth=generatorBinning->CreateHistogram("histDataTruth");
157+
histDataReco->SetDirectory(outputFile);
158+
histDataTruth->SetDirectory(outputFile);
161159

162160
TFile *dataFile=new TFile("testUnfold5_data.root");
163161
TTree *dataTree=(TTree *) dataFile->Get("data");
@@ -208,10 +206,9 @@ void testUnfold5c()
208206
// Step 4: book and fill histogram of migrations
209207
// it receives events from both signal MC and background MC
210208

211-
outputFile->cd();
212-
213209
TH2 *histMCGenRec=TUnfoldBinning::CreateHistogramOfMigrations
214210
(generatorBinning,detectorBinning,"histMCGenRec");
211+
histMCGenRec->SetDirectory(outputFile);
215212

216213
TFile *signalFile=new TFile("testUnfold5_signal.root");
217214
TTree *signalTree=(TTree *) signalFile->Get("signal");

tutorials/analysis/unfold/testUnfold7b.C

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ void testUnfold7b()
110110

111111
TUnfoldBinning *fineBinningRoot,*coarseBinningRoot;
112112

113-
outputFile->cd();
114-
115113
// read binning schemes in XML format
116114

117115
TDOMParser parser;
@@ -164,6 +162,10 @@ void testUnfold7b()
164162
TH1 *histDataBgrC=coarseBinning->CreateHistogram("histDataBgrC");
165163
TH1 *histDataGen=coarseBinning->CreateHistogram("histDataGen");
166164

165+
for (auto histo : {histDataRecF, histDataRecC, histDataBgrF, histDataBgrC, histDataGen}) {
166+
histo->SetDirectory(outputFile);
167+
}
168+
167169
TFile *dataFile=new TFile("testUnfold7_data.root");
168170
TTree *dataTree=(TTree *) dataFile->Get("data");
169171

@@ -213,15 +215,16 @@ void testUnfold7b()
213215
// Step 4: book and fill histogram of migrations
214216
// it receives events from both signal MC and background MC
215217

216-
outputFile->cd();
217-
218218
TH2 *histMcsigGenRecF=TUnfoldBinning::CreateHistogramOfMigrations
219219
(coarseBinning,fineBinning,"histMcsigGenRecF");
220220
TH2 *histMcsigGenRecC=TUnfoldBinning::CreateHistogramOfMigrations
221221
(coarseBinning,coarseBinning,"histMcsigGenRecC");
222222
TH1 *histMcsigRecF=fineBinning->CreateHistogram("histMcsigRecF");
223223
TH1 *histMcsigRecC=coarseBinning->CreateHistogram("histMcsigRecC");
224224
TH1 *histMcsigGen=coarseBinning->CreateHistogram("histMcsigGen");
225+
for (auto histo : std::initializer_list<TH1*>{histMcsigGenRecF, histMcsigGenRecC, histMcsigRecF, histMcsigRecC, histMcsigGen}) {
226+
histo->SetDirectory(outputFile);
227+
}
225228

226229
TFile *signalFile=new TFile("testUnfold7_signal.root");
227230
TTree *signalTree=(TTree *) signalFile->Get("signal");
@@ -259,10 +262,10 @@ void testUnfold7b()
259262
delete signalTree;
260263
delete signalFile;
261264

262-
outputFile->cd();
263-
264265
TH1 *histMcbgrRecF=fineBinning->CreateHistogram("histMcbgrRecF");
265266
TH1 *histMcbgrRecC=coarseBinning->CreateHistogram("histMcbgrRecC");
267+
histMcbgrRecF->SetDirectory(outputFile);
268+
histMcbgrRecC->SetDirectory(outputFile);
266269

267270
TFile *bgrFile=new TFile("testUnfold7_background.root");
268271
TTree *bgrTree=(TTree *) bgrFile->Get("background");

0 commit comments

Comments
 (0)