104 struct RemoveTopicRAII {
109 cxcoutIHF <<
"Making Model and Measurements (Fast) for measurement: " << measurement.
GetName() << std::endl;
113 cxcoutIHF <<
"using lumi = " << measurement.
GetLumi() <<
" and lumiError = " << lumiError
114 <<
" including bins between " << measurement.
GetBinLow() <<
" and " << measurement.
GetBinHigh() << std::endl;
116 std::ostringstream parameterMessage;
117 parameterMessage <<
"fixing the following parameters:" << std::endl;
120 parameterMessage <<
" " <<
name <<
'\n';
124 std::string rowTitle = measurement.
GetName();
126 std::vector<std::unique_ptr<RooWorkspace>> channel_workspaces;
127 std::vector<std::string> channel_names;
129 auto createOutputDirectory = [](std::string
const &prefix) {
135 size_t pos = prefix.rfind(
'/');
136 if (pos == std::string::npos) {
139 std::string outputDir = prefix.substr(0,pos);
140 cxcoutDHF <<
"Checking if output directory : " << outputDir <<
" - exists" << std::endl;
141 void *outdir =
gSystem->OpenDirectory( outputDir.c_str() );
143 gSystem->FreeDirectory(outdir);
146 cxcoutDHF <<
"Output directory : " << outputDir <<
" - does not exist, try to create" << std::endl;
147 int success =
gSystem->MakeDirectory( outputDir.c_str() );
149 std::string fullOutputDir =
gSystem->pwd() + std::string(
"/") + outputDir;
150 cxcoutEHF <<
"Error: Failed to make output directory: " << fullOutputDir << std::endl;
156 cxcoutIHF <<
"Creating the HistoToWorkspaceFactoryFast factory" << std::endl;
159 cxcoutIHF <<
"Setting preprocess functions" << std::endl;
163 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().
size(); ++chanItr ) {
168 <<
" has uninitialized histogram pointers" << std::endl;
173 std::string ch_name = channel.
GetName();
174 cxcoutPHF <<
"Starting to process channel: " << ch_name << std::endl;
175 channel_names.push_back(ch_name);
180 createOutputDirectory(prefix);
182 std::string ChannelFileName = prefix +
"_"
183 + ch_name +
"_" + rowTitle +
"_model.root";
184 cxcoutIHF <<
"Opening File to hold channel: " << ChannelFileName << std::endl;
185 std::unique_ptr<TFile> chanFile{
TFile::Open( ChannelFileName.c_str(),
"RECREATE" )};
186 chanFile->WriteTObject(ws_single.get());
192 cxcoutIHF <<
"About to write channel measurement to file" << std::endl;
194 cxcoutPHF <<
"Successfully wrote channel to file" << std::endl;
197 channel_workspaces.emplace_back(std::move(ws_single));
207 std::unique_ptr<RooWorkspace> ws{factory.
MakeCombinedModel(channel_names, channel_workspaces)};
217 createOutputDirectory(prefix);
218 std::string CombinedFileName = prefix +
"_combined_"
219 + rowTitle +
"_model.root";
220 cxcoutPHF <<
"Writing combined workspace to file: " << CombinedFileName << std::endl;
221 std::unique_ptr<TFile> combFile{
TFile::Open( CombinedFileName.c_str(),
"RECREATE" )};
222 if( combFile ==
nullptr ) {
223 cxcoutEHF <<
"Error: Failed to open file " << CombinedFileName << std::endl;
226 combFile->WriteTObject(ws.get());
227 cxcoutPHF <<
"Writing combined measurement to file: " << CombinedFileName << std::endl;
static TFile * Open(const char *name, Option_t *option="", const char *ftitle="", Int_t compress=ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault, Int_t netopt=0)
Create / open a file.