84 HistoToWorkspaceFactoryFast::Configuration
const &cfg)
86 std::unique_ptr<TFile> outFile;
91 cxcoutIHF <<
"Making Model and Measurements (Fast) for measurement: " << measurement.
GetName() << std::endl;
95 cxcoutIHF <<
"using lumi = " << measurement.
GetLumi() <<
" and lumiError = " << lumiError
96 <<
" including bins between " << measurement.
GetBinLow() <<
" and " << measurement.
GetBinHigh() << std::endl;
98 std::ostringstream parameterMessage;
99 parameterMessage <<
"fixing the following parameters:" << std::endl;
101 for (
auto const &
name : measurement.GetConstantParams()) {
102 parameterMessage <<
" " <<
name <<
'\n';
106 std::string rowTitle = measurement.
GetName();
108 std::vector<std::unique_ptr<RooWorkspace>> channel_workspaces;
109 std::vector<std::string> channel_names;
118 size_t pos = prefix.rfind(
'/');
119 if (pos != std::string::npos) {
120 std::string outputDir = prefix.substr(0,pos);
121 cxcoutDHF <<
"Checking if output directory : " << outputDir <<
" - exists" << std::endl;
123 cxcoutDHF <<
"Output directory : " << outputDir <<
" - does not exist, try to create" << std::endl;
126 std::string fullOutputDir = std::string(
gSystem->
pwd()) + std::string(
"/") + outputDir;
127 cxcoutEHF <<
"Error: Failed to make output directory: " << fullOutputDir << std::endl;
135 cxcoutIHF <<
"Creating the output file: " << outputFileName << std::endl;
136 outFile = std::make_unique<TFile>(outputFileName.c_str(),
"recreate");
138 cxcoutIHF <<
"Creating the HistoToWorkspaceFactoryFast factory" << std::endl;
139 HistoToWorkspaceFactoryFast factory{measurement, cfg};
143 cxcoutIHF <<
"Setting preprocess functions" << std::endl;
147 for(
unsigned int chanItr = 0; chanItr < measurement.
GetChannels().
size(); ++chanItr ) {
149 HistFactory::Channel& channel = measurement.
GetChannels().at( chanItr );
150 if( ! channel.CheckHistograms() ) {
151 cxcoutEHF <<
"MakeModelAndMeasurementsFast: Channel: " << channel.GetName()
152 <<
" has uninitialized histogram pointers" << std::endl;
157 std::string ch_name = channel.GetName();
158 cxcoutPHF <<
"Starting to process channel: " << ch_name << std::endl;
159 channel_names.push_back(ch_name);
160 std::unique_ptr<RooWorkspace> ws_single{factory.MakeSingleChannelModel( measurement, channel )};
162 if (cfg.createPerRegionWorkspaces) {
165 + ch_name +
"_" + rowTitle +
"_model.root";
166 cxcoutIHF <<
"Opening File to hold channel: " << ChannelFileName << std::endl;
167 std::unique_ptr<TFile> chanFile{
TFile::Open( ChannelFileName.c_str(),
"RECREATE" )};
172 meas_chan.GetChannels().clear();
173 meas_chan.GetChannels().push_back( channel );
174 cxcoutIHF <<
"About to write channel measurement to file" << std::endl;
175 meas_chan.writeToFile( chanFile.get() );
176 cxcoutPHF <<
"Successfully wrote channel to file" << std::endl;
179 channel_workspaces.emplace_back(std::move(ws_single));
189 std::unique_ptr<RooWorkspace> ws{factory.MakeCombinedModel(channel_names, channel_workspaces)};
192 HistoToWorkspaceFactoryFast::ConfigureWorkspaceForMeasurement(
"simPdf", ws.get(), measurement);
196 + rowTitle +
"_model.root";
197 cxcoutPHF <<
"Writing combined workspace to file: " << CombinedFileName << std::endl;
198 std::unique_ptr<TFile> combFile{
TFile::Open( CombinedFileName.c_str(),
"RECREATE" )};
199 if( combFile ==
nullptr ) {
200 cxcoutEHF <<
"Error: Failed to open file " << CombinedFileName << std::endl;
203 combFile->WriteTObject(ws.get());
204 cxcoutPHF <<
"Writing combined measurement to file: " << CombinedFileName << std::endl;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
R__EXTERN TSystem * gSystem
static RooMsgService & instance()
Return reference to singleton instance.
The RooStats::HistFactory::Measurement class can be used to construct a model by combining multiple R...
void writeToFile(TFile *file)
A measurement, once fully configured, can be saved into a ROOT file.
double GetLumiRelErr()
retrieve relative uncertainty on luminosity
std::vector< RooStats::HistFactory::Channel > & GetChannels()
std::string GetOutputFilePrefix()
retrieve prefix for output files
std::vector< std::string > GetPreprocessFunctions() const
Returns a list of defined preprocess function expressions.
double GetLumi()
retrieve integrated luminosity
Int_t WriteTObject(const TObject *obj, const char *name=nullptr, Option_t *option="", Int_t bufsize=0) override
Write object obj to this directory.
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.
const char * GetName() const override
Returns name of object.
virtual void * OpenDirectory(const char *name)
Open a directory. Returns 0 if directory does not exist.
virtual int MakeDirectory(const char *name)
Make a directory.
OwningPtr< T > makeOwningPtr(std::unique_ptr< T > &&ptr)
Internal helper to turn a std::unique_ptr<T> into an OwningPtr.
T * OwningPtr
An alias for raw pointers for indicating that the return type of a RooFit function is an owning point...
RooFit::OwningPtr< RooWorkspace > MakeModelAndMeasurementFast(RooStats::HistFactory::Measurement &measurement, HistoToWorkspaceFactoryFast::Configuration const &cfg={})