forked from sultamehr/MAT_IncPions
-
Notifications
You must be signed in to change notification settings - Fork 9
/
runEventLoop.cpp
515 lines (438 loc) · 22.1 KB
/
runEventLoop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
#define MC_OUT_FILE_NAME "runEventLoopMC.root"
#define DATA_OUT_FILE_NAME "runEventLoopData.root"
#define USAGE \
"\n*** USAGE ***\n"\
"runEventLoop <dataPlaylist.txt> <mcPlaylist.txt>\n\n"\
"*** Explanation ***\n"\
"Reduce MasterAnaDev AnaTuples to event selection histograms to extract a\n"\
"single-differential inclusive cross section for the 2021 MINERvA 101 tutorial.\n\n"\
"*** The Input Files ***\n"\
"Playlist files are plaintext files with 1 file name per line. Filenames may be\n"\
"xrootd URLs or refer to the local filesystem. The first playlist file's\n"\
"entries will be treated like data, and the second playlist's entries must\n"\
"have the \"Truth\" tree to use for calculating the efficiency denominator.\n\n"\
"*** Output ***\n"\
"Produces a two files, " MC_OUT_FILE_NAME " and " DATA_OUT_FILE_NAME ", with\n"\
"all histograms needed for the ExtractCrossSection program also built by this\n"\
"package. You'll need a .rootlogon.C that loads ROOT object definitions from\n"\
"PlotUtils to access systematics information from these files.\n\n"\
"*** Environment Variables ***\n"\
"Setting up this package appends to PATH and LD_LIBRARY_PATH. PLOTUTILSROOT,\n"\
"MPARAMFILESROOT, and MPARAMFILES must be set according to the setup scripts in\n"\
"those packages for systematics and flux reweighters to function.\n"\
"If MNV101_SKIP_SYST is defined at all, output histograms will have no error bands.\n"\
"This is useful for debugging the CV and running warping studies.\n\n"\
"*** Return Codes ***\n"\
"0 indicates success. All histograms are valid only in this case. Any other\n"\
"return code indicates that histograms should not be used. Error messages\n"\
"about what went wrong will be printed to stderr. So, they'll end up in your\n"\
"terminal, but you can separate them from everything else with something like:\n"\
"\"runEventLoop data.txt mc.txt 2> errors.txt\"\n"
enum ErrorCodes
{
success = 0,
badCmdLine = 1,
badInputFile = 2,
badFileRead = 3,
badOutputFile = 4
};
//PlotUtils includes
//No junk from PlotUtils please! I already
//know that MnvH1D does horrible horrible things.
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverloaded-virtual"
//Includes from this package
#include "event/CVUniverse.h"
#include "event/MichelEvent.h"
#include "systematics/Systematics.h"
#include "cuts/MaxPzMu.h"
#include "util/Variable.h"
#include "util/Variable2D.h"
#include "util/GetFluxIntegral.h"
#include "util/GetPlaylist.h"
#include "cuts/SignalDefinition.h"
#include "cuts/q3RecoCut.h"
#include "studies/Study.h"
//#include "Binning.h" //TODO: Fix me
//PlotUtils includes
#include "PlotUtils/makeChainWrapper.h"
#include "PlotUtils/HistWrapper.h"
#include "PlotUtils/Hist2DWrapper.h"
#include "PlotUtils/MacroUtil.h"
#include "PlotUtils/MnvPlotter.h"
#include "PlotUtils/CCInclusiveCuts.h"
#include "PlotUtils/CCInclusiveSignal.h"
#include "PlotUtils/CrashOnROOTMessage.h" //Sets up ROOT's debug callbacks by itself
#include "PlotUtils/Cutter.h"
#include "PlotUtils/Model.h"
#include "PlotUtils/FluxAndCVReweighter.h"
#include "PlotUtils/GENIEReweighter.h"
#include "PlotUtils/LowRecoil2p2hReweighter.h"
#include "PlotUtils/RPAReweighter.h"
#include "PlotUtils/MINOSEfficiencyReweighter.h"
#include "PlotUtils/TargetUtils.h"
#pragma GCC diagnostic pop
//ROOT includes
#include "TParameter.h"
//c++ includes
#include <iostream>
#include <cstdlib> //getenv()
//==============================================================================
// Loop and Fill
//==============================================================================
void LoopAndFillEventSelection(
PlotUtils::ChainWrapper* chain,
std::map<std::string, std::vector<CVUniverse*> > error_bands,
std::vector<Variable*> vars,
std::vector<Variable2D*> vars2D,
std::vector<Study*> studies,
PlotUtils::Cutter<CVUniverse, MichelEvent>& michelcuts,
PlotUtils::Model<CVUniverse, MichelEvent>& model)
{
assert(!error_bands["cv"].empty() && "\"cv\" error band is empty! Can't set Model weight.");
auto& cvUniv = error_bands["cv"].front();
std::cout << "Starting MC reco loop...\n";
const int nEntries = chain->GetEntries();
for (int i=0; i<nEntries; ++i)
{
if(i%1000==0) std::cout << i << " / " << nEntries << "\r" <<std::flush;
MichelEvent cvEvent;
cvUniv->SetEntry(i);
model.SetEntry(*cvUniv, cvEvent);
const double cvWeight = model.GetWeight(*cvUniv, cvEvent);
//=========================================
// Systematics loop(s)
//=========================================
for (auto band : error_bands)
{
std::vector<CVUniverse*> error_band_universes = band.second;
for (auto universe : error_band_universes)
{
MichelEvent myevent; // make sure your event is inside the error band loop.
// Tell the Event which entry in the TChain it's looking at
universe->SetEntry(i);
// This is where you would Access/create a Michel
//weight is ignored in isMCSelected() for all but the CV Universe.
if (!michelcuts.isMCSelected(*universe, myevent, cvWeight).all()) continue; //all is another function that will later help me with sidebands
const double weight = model.GetWeight(*universe, myevent); //Only calculate the per-universe weight for events that will actually use it.
for(auto& var: vars) var->selectedMCReco->FillUniverse(universe, var->GetRecoValue(*universe), weight); //"Fake data" for closure
const bool isSignal = michelcuts.isSignal(*universe, weight);
if(isSignal)
{
for(auto& study: studies) study->SelectedSignal(*universe, myevent, weight);
for(auto& var: vars)
{
//Cross section components
var->efficiencyNumerator->FillUniverse(universe, var->GetTrueValue(*universe), weight);
var->migration->FillUniverse(universe, var->GetRecoValue(*universe), var->GetTrueValue(*universe), weight);
var->selectedSignalReco->FillUniverse(universe, var->GetRecoValue(*universe), weight); //Efficiency numerator in reco variables. Useful for warping studies.
}
for(auto& var: vars2D)
{
var->efficiencyNumerator->FillUniverse(universe, var->GetTrueValueX(*universe), var->GetTrueValueY(*universe), weight);
}
}
else
{
int bkgd_ID = -1;
if (universe->GetCurrent()==2)bkgd_ID=0;
else bkgd_ID=1;
for(auto& var: vars) (*var->m_backgroundHists)[bkgd_ID].FillUniverse(universe, var->GetRecoValue(*universe), weight);
for(auto& var: vars2D) (*var->m_backgroundHists)[bkgd_ID].FillUniverse(universe, var->GetRecoValueX(*universe), var->GetRecoValueY(*universe), weight);
}
} // End band's universe loop
} // End Band loop
} //End entries loop
std::cout << "Finished MC reco loop.\n";
}
void LoopAndFillData( PlotUtils::ChainWrapper* data,
std::vector<CVUniverse*> data_band,
std::vector<Variable*> vars,
std::vector<Variable2D*> vars2D,
std::vector<Study*> studies,
PlotUtils::Cutter<CVUniverse, MichelEvent>& michelcuts)
{
std::cout << "Starting data loop...\n";
const int nEntries = data->GetEntries();
for (int i=0; i<data->GetEntries(); ++i) {
for (auto universe : data_band) {
universe->SetEntry(i);
if(i%1000==0) std::cout << i << " / " << nEntries << "\r" << std::flush;
MichelEvent myevent;
if (!michelcuts.isDataSelected(*universe, myevent).all()) continue;
for(auto& study: studies) study->Selected(*universe, myevent, 1);
for(auto& var: vars)
{
var->dataHist->FillUniverse(universe, var->GetRecoValue(*universe, myevent.m_idx), 1);
}
for(auto& var: vars2D)
{
var->dataHist->FillUniverse(universe, var->GetRecoValueX(*universe), var->GetRecoValueY(*universe), 1);
}
}
}
std::cout << "Finished data loop.\n";
}
void LoopAndFillEffDenom( PlotUtils::ChainWrapper* truth,
std::map<std::string, std::vector<CVUniverse*> > truth_bands,
std::vector<Variable*> vars,
std::vector<Variable2D*> vars2D,
PlotUtils::Cutter<CVUniverse, MichelEvent>& michelcuts,
PlotUtils::Model<CVUniverse, MichelEvent>& model)
{
assert(!truth_bands["cv"].empty() && "\"cv\" error band is empty! Could not set Model entry.");
auto& cvUniv = truth_bands["cv"].front();
std::cout << "Starting efficiency denominator loop...\n";
const int nEntries = truth->GetEntries();
for (int i=0; i<nEntries; ++i)
{
if(i%1000==0) std::cout << i << " / " << nEntries << "\r" << std::flush;
MichelEvent cvEvent;
cvUniv->SetEntry(i);
model.SetEntry(*cvUniv, cvEvent);
const double cvWeight = model.GetWeight(*cvUniv, cvEvent);
//=========================================
// Systematics loop(s)
//=========================================
for (auto band : truth_bands)
{
std::vector<CVUniverse*> truth_band_universes = band.second;
for (auto universe : truth_band_universes)
{
MichelEvent myevent; //Only used to keep the Model happy
// Tell the Event which entry in the TChain it's looking at
universe->SetEntry(i);
if (!michelcuts.isEfficiencyDenom(*universe, cvWeight)) continue; //Weight is ignored for isEfficiencyDenom() in all but the CV universe
const double weight = model.GetWeight(*universe, myevent); //Only calculate the weight for events that will use it
//Fill efficiency denominator now:
for(auto var: vars)
{
var->efficiencyDenominator->FillUniverse(universe, var->GetTrueValue(*universe), weight);
}
for(auto var: vars2D)
{
var->efficiencyDenominator->FillUniverse(universe, var->GetTrueValueX(*universe), var->GetTrueValueY(*universe), weight);
}
}
}
}
std::cout << "Finished efficiency denominator loop.\n";
}
//Returns false if recoTreeName could not be inferred
bool inferRecoTreeNameAndCheckTreeNames(const std::string& mcPlaylistName, const std::string& dataPlaylistName, std::string& recoTreeName)
{
const std::vector<std::string> knownTreeNames = {"Truth", "Meta"};
bool areFilesOK = false;
std::ifstream playlist(mcPlaylistName);
std::string firstFile = "";
playlist >> firstFile;
auto testFile = TFile::Open(firstFile.c_str());
if(!testFile)
{
std::cerr << "Failed to open the first MC file at " << firstFile << "\n";
return false;
}
//Does the MC playlist have the Truth tree? This is needed for the efficiency denominator.
const auto truthTree = testFile->Get("Truth");
if(truthTree == nullptr || !truthTree->IsA()->InheritsFrom(TClass::GetClass("TTree")))
{
std::cerr << "Could not find the \"Truth\" tree in MC file named " << firstFile << "\n";
return false;
}
//Figure out what the reco tree name is
for(auto key: *testFile->GetListOfKeys())
{
if(static_cast<TKey*>(key)->ReadObj()->IsA()->InheritsFrom(TClass::GetClass("TTree"))
&& std::find(knownTreeNames.begin(), knownTreeNames.end(), key->GetName()) == knownTreeNames.end())
{
recoTreeName = key->GetName();
areFilesOK = true;
}
}
delete testFile;
testFile = nullptr;
//Make sure the data playlist's first file has the same reco tree
playlist.open(dataPlaylistName);
playlist >> firstFile;
testFile = TFile::Open(firstFile.c_str());
if(!testFile)
{
std::cerr << "Failed to open the first data file at " << firstFile << "\n";
return false;
}
const auto recoTree = testFile->Get(recoTreeName.c_str());
if(recoTree == nullptr || !recoTree->IsA()->InheritsFrom(TClass::GetClass("TTree")))
{
std::cerr << "Could not find the \"" << recoTreeName << "\" tree in data file named " << firstFile << "\n";
return false;
}
return areFilesOK;
}
//==============================================================================
// Main
//==============================================================================
int main(const int argc, const char** argv)
{
TH1::AddDirectory(false);
//Validate input.
//I expect a data playlist file name and an MC playlist file name which is exactly 2 arguments.
const int nArgsExpected = 2;
if(argc != nArgsExpected + 1) //argc is the size of argv. I check for number of arguments + 1 because
//argv[0] is always the path to the executable.
{
std::cerr << "Expected " << nArgsExpected << " arguments, but got " << argc - 1 << "\n" << USAGE << "\n";
return badCmdLine;
}
//One playlist must contain only MC files, and the other must contain only data files.
//Only checking the first file in each playlist because opening each file an extra time
//remotely (e.g. through xrootd) can get expensive.
//TODO: Look in INSTALL_DIR if files not found?
const std::string mc_file_list = argv[2],
data_file_list = argv[1];
//Check that necessary TTrees exist in the first file of mc_file_list and data_file_list
std::string reco_tree_name;
if(!inferRecoTreeNameAndCheckTreeNames(mc_file_list, data_file_list, reco_tree_name))
{
std::cerr << "Failed to find required trees in MC playlist " << mc_file_list << " and/or data playlist " << data_file_list << ".\n" << USAGE << "\n";
return badInputFile;
}
const bool doCCQENuValidation = (reco_tree_name == "CCQENu"); //Enables extra histograms and might influence which systematics I use.
//const bool is_grid = false; //TODO: Are we going to put this back? Gonzalo needs it iirc.
PlotUtils::MacroUtil options(reco_tree_name, mc_file_list, data_file_list, "minervame1A", true);
options.m_plist_string = util::GetPlaylist(*options.m_mc, true); //TODO: Put GetPlaylist into PlotUtils::MacroUtil
// You're required to make some decisions
PlotUtils::MinervaUniverse::SetNuEConstraint(true);
PlotUtils::MinervaUniverse::SetPlaylist(options.m_plist_string); //TODO: Infer this from the files somehow?
PlotUtils::MinervaUniverse::SetAnalysisNuPDG(14);
PlotUtils::MinervaUniverse::SetNFluxUniverses(100);
PlotUtils::MinervaUniverse::SetZExpansionFaReweight(false);
PlotUtils::MinervaUniverse::RPAMaterials(true);
//Now that we've defined what a cross section is, decide which sample and model
//we're extracting a cross section for.
PlotUtils::Cutter<CVUniverse, MichelEvent>::reco_t sidebands, preCuts;
PlotUtils::Cutter<CVUniverse, MichelEvent>::truth_t signalDefinition, phaseSpace;
//const double minZ = 5980, maxZ = 8422, apothem = 850; //All in mm
const double minZ = 4305, maxZ = 5980, apothem = 850; //All in mm
preCuts.emplace_back(new reco::ZRange<CVUniverse, MichelEvent>("Target", minZ, maxZ));
preCuts.emplace_back(new reco::Apothem<CVUniverse, MichelEvent>(apothem));
preCuts.emplace_back(new reco::MaxMuonAngle<CVUniverse, MichelEvent>(20.));
preCuts.emplace_back(new reco::HasMINOSMatch<CVUniverse, MichelEvent>());
preCuts.emplace_back(new reco::NoDeadtime<CVUniverse, MichelEvent>(1, "Deadtime"));
preCuts.emplace_back(new reco::IsNeutrino<CVUniverse, MichelEvent>());
signalDefinition.emplace_back(new truth::IsNeutrino<CVUniverse>());
signalDefinition.emplace_back(new truth::IsCC<CVUniverse>());
phaseSpace.emplace_back(new truth::ZRange<CVUniverse>("Tracker", minZ, maxZ));
phaseSpace.emplace_back(new truth::Apothem<CVUniverse>(apothem));
phaseSpace.emplace_back(new truth::MuonAngle<CVUniverse>(20.));
phaseSpace.emplace_back(new truth::PZMuMin<CVUniverse>(1500.));
PlotUtils::Cutter<CVUniverse, MichelEvent> mycuts(std::move(preCuts), std::move(sidebands) , std::move(signalDefinition),std::move(phaseSpace));
std::vector<std::unique_ptr<PlotUtils::Reweighter<CVUniverse, MichelEvent>>> MnvTunev1;
MnvTunev1.emplace_back(new PlotUtils::FluxAndCVReweighter<CVUniverse, MichelEvent>());
MnvTunev1.emplace_back(new PlotUtils::GENIEReweighter<CVUniverse, MichelEvent>(true, false));
MnvTunev1.emplace_back(new PlotUtils::LowRecoil2p2hReweighter<CVUniverse, MichelEvent>());
MnvTunev1.emplace_back(new PlotUtils::MINOSEfficiencyReweighter<CVUniverse, MichelEvent>());
MnvTunev1.emplace_back(new PlotUtils::RPAReweighter<CVUniverse, MichelEvent>());
PlotUtils::Model<CVUniverse, MichelEvent> model(std::move(MnvTunev1));
// Make a map of systematic universes
// Leave out systematics when making validation histograms
const bool doSystematics = (getenv("MNV101_SKIP_SYST") == nullptr);
if(!doSystematics){
std::cout << "Skipping systematics (except 1 flux universe) because environment variable MNV101_SKIP_SYST is set.\n";
PlotUtils::MinervaUniverse::SetNFluxUniverses(2); //Necessary to get Flux integral later... Doesn't work with just 1 flux universe though because _that_ triggers "spread errors".
}
std::map< std::string, std::vector<CVUniverse*> > error_bands;
if(doSystematics) error_bands = GetStandardSystematics(options.m_mc);
else{
std::map<std::string, std::vector<CVUniverse*> > band_flux = PlotUtils::GetFluxSystematicsMap<CVUniverse>(options.m_mc, CVUniverse::GetNFluxUniverses());
error_bands.insert(band_flux.begin(), band_flux.end()); //Necessary to get flux integral later...
}
error_bands["cv"] = {new CVUniverse(options.m_mc)};
std::map< std::string, std::vector<CVUniverse*> > truth_bands;
if(doSystematics) truth_bands = GetStandardSystematics(options.m_truth);
truth_bands["cv"] = {new CVUniverse(options.m_truth)};
std::vector<double> dansPTBins = {0, 0.075, 0.15, 0.25, 0.325, 0.4, 0.475, 0.55, 0.7, 0.85, 1, 1.25, 1.5, 2.5, 4.5},
dansPzBins = {1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 6, 7, 8, 9, 10, 15, 20, 40, 60},
robsEmuBins = {0,1,2,3,4,5,7,9,12,15,18,22,36,50,75,100,120},
robsRecoilBins;
const double robsRecoilBinWidth = 50; //MeV
for(int whichBin = 0; whichBin < 100 + 1; ++whichBin) robsRecoilBins.push_back(robsRecoilBinWidth * whichBin);
std::vector<Variable*> vars = {
new Variable("pTmu", "p_{T, #mu} [GeV/c]", dansPTBins, &CVUniverse::GetMuonPT, &CVUniverse::GetMuonPTTrue),
};
std::vector<Variable2D*> vars2D;
if(doCCQENuValidation)
{
std::cerr << "Detected that tree name is CCQENu. Making validation histograms.\n";
vars.push_back(new Variable("pzmu", "p_{||, #mu} [GeV/c]", dansPzBins, &CVUniverse::GetMuonPz, &CVUniverse::GetMuonPzTrue));
vars.push_back(new Variable("Emu", "E_{#mu} [GeV]", robsEmuBins, &CVUniverse::GetEmuGeV, &CVUniverse::GetElepTrueGeV));
vars.push_back(new Variable("Erecoil", "E_{recoil}", robsRecoilBins, &CVUniverse::GetRecoilE, &CVUniverse::Getq0True)); //TODO: q0 is not the same as recoil energy without a spline correction
vars2D.push_back(new Variable2D(*vars[1], *vars[0]));
}
std::vector<Study*> studies;
CVUniverse* data_universe = new CVUniverse(options.m_data);
std::vector<CVUniverse*> data_band = {data_universe};
std::map<std::string, std::vector<CVUniverse*> > data_error_bands;
data_error_bands["cv"] = data_band;
std::vector<Study*> data_studies;
for(auto& var: vars) var->InitializeMCHists(error_bands, truth_bands);
for(auto& var: vars) var->InitializeDATAHists(data_band);
for(auto& var: vars2D) var->InitializeMCHists(error_bands, truth_bands);
for(auto& var: vars2D) var->InitializeDATAHists(data_band);
// Loop entries and fill
try
{
CVUniverse::SetTruth(false);
LoopAndFillEventSelection(options.m_mc, error_bands, vars, vars2D, studies, mycuts, model);
CVUniverse::SetTruth(true);
LoopAndFillEffDenom(options.m_truth, truth_bands, vars, vars2D, mycuts, model);
options.PrintMacroConfiguration(argv[0]);
std::cout << "MC cut summary:\n" << mycuts << "\n";
mycuts.resetStats();
CVUniverse::SetTruth(false);
LoopAndFillData(options.m_data, data_band, vars, vars2D, data_studies, mycuts);
std::cout << "Data cut summary:\n" << mycuts << "\n";
//Write MC results
TFile* mcOutDir = TFile::Open(MC_OUT_FILE_NAME, "RECREATE");
if(!mcOutDir)
{
std::cerr << "Failed to open a file named " << MC_OUT_FILE_NAME << " in the current directory for writing histograms.\n";
return badOutputFile;
}
for(auto& study: studies) study->SaveOrDraw(*mcOutDir);
for(auto& var: vars) var->WriteMC(*mcOutDir);
for(auto& var: vars2D) var->Write(*mcOutDir);
//Protons On Target
auto mcPOT = new TParameter<double>("POTUsed", options.m_mc_pot);
mcPOT->Write();
PlotUtils::TargetUtils targetInfo;
assert(error_bands["cv"].size() == 1 && "List of error bands must contain a universe named \"cv\" for the flux integral.");
for(const auto& var: vars)
{
//Flux integral only if systematics are being done (temporary solution)
util::GetFluxIntegral(*error_bands["cv"].front(), var->efficiencyNumerator->hist)->Write((var->GetName() + "_reweightedflux_integrated").c_str());
//Always use MC number of nucleons for cross section
auto nNucleons = new TParameter<double>((var->GetName() + "_fiducial_nucleons").c_str(), targetInfo.GetTrackerNNucleons(minZ, maxZ, true, apothem));
nNucleons->Write();
}
//Write data results
TFile* dataOutDir = TFile::Open(DATA_OUT_FILE_NAME, "RECREATE");
if(!dataOutDir)
{
std::cerr << "Failed to open a file named " << DATA_OUT_FILE_NAME << " in the current directory for writing histograms.\n";
return badOutputFile;
}
for(auto& var: vars) var->WriteData(*dataOutDir);
//Protons On Target
auto dataPOT = new TParameter<double>("POTUsed", options.m_data_pot);
dataPOT->Write();
std::cout << "Success" << std::endl;
}
catch(const ROOT::exception& e)
{
std::cerr << "Ending on a ROOT error message. No histograms will be produced.\n"
<< "If the message talks about \"TNetXNGFile\", this could be a problem with dCache. The message is:\n"
<< e.what() << "\n" << USAGE << "\n";
return badFileRead;
}
return success;
}