@@ -19,25 +19,27 @@ using namespace RooStats;
1919using namespace HistFactory ;
2020
2121namespace {
22- constexpr bool verbose = false ;
22+ constexpr bool verbose = false ;
2323
24- // test matrix configuration
25- const std::vector<int > nChannelsVector = {1 , 2 , 3 };
26- const std::vector<int > nBinsVector {5 , 10 , 15 };
27- const int nBinsForChannelScan = 10 ;
28- const int nChannelsForBinScan = 1 ;
29- const std::vector<int > nCPUVector { 1 , 2 , 3 };
24+ // test matrix configuration
25+ const std::vector<int > nChannelsVector = {1 , 2 , 3 };
26+ const std::vector<int > nBinsVector{5 , 10 , 15 };
27+ const int nBinsForChannelScan = 10 ;
28+ const int nChannelsForBinScan = 1 ;
29+ const std::vector<int > nCPUVector{ 1 };
3030
31- constexpr auto evalBackend = RooFit::EvalBackend::Value::Cpu;
31+ // //default evaluation backend
32+ std::string evalBackend = " cpu" ;
3233
33- auto const timeUnit = benchmark::kMillisecond ;
34+ auto const timeUnit = benchmark::kMillisecond ;
3435
35- void setupRooMsgService () {
36- RooMsgService::instance ().setGlobalKillBelow (RooFit::FATAL);
37- RooMsgService::instance ().getStream (1 ).removeTopic (RooFit::Minimization);
38- RooMsgService::instance ().getStream (1 ).removeTopic (RooFit::NumIntegration);
39- RooMsgService::instance ().getStream (1 ).removeTopic (RooFit::Eval);
40- }
36+ void setupRooMsgService ()
37+ {
38+ RooMsgService::instance ().setGlobalKillBelow (RooFit::FATAL);
39+ RooMsgService::instance ().getStream (1 ).removeTopic (RooFit::Minimization);
40+ RooMsgService::instance ().getStream (1 ).removeTopic (RooFit::NumIntegration);
41+ RooMsgService::instance ().getStream (1 ).removeTopic (RooFit::Eval);
42+ }
4143
4244} // namespace
4345
@@ -48,9 +50,9 @@ Sample addVariations(Sample asample, int nnps, bool channel_crosstalk, int chann
4850 Double_t random = R->Rndm ();
4951 double uncertainty_up = (1 + random) / sqrt (100 );
5052 double uncertainty_down = (1 - random) / sqrt (100 );
51- if (verbose) {
52- std::cout << " in channel " << channel << " nuisance +/- [" << uncertainty_up << " ," << uncertainty_down << " ]"
53- << std::endl;
53+ if (verbose) {
54+ std::cout << " in channel " << channel << " nuisance +/- [" << uncertainty_up << " ," << uncertainty_down << " ]"
55+ << std::endl;
5456 }
5557 std::string nuis_name = " norm_uncertainty_" + std::to_string (nuis);
5658 if (!channel_crosstalk) {
@@ -101,8 +103,8 @@ std::unique_ptr<RooStats::HistFactory::Channel> makeChannel(int channel, int nbi
101103
102104void buildBinnedTest (int n_channels = 1 , int nbins = 10 , int nnps = 1 , const char *name_rootfile = " " )
103105{
104- if (verbose) {
105- std::cout << " in build binned test with output" << name_rootfile << std::endl;
106+ if (verbose) {
107+ std::cout << " in build binned test with output" << name_rootfile << std::endl;
106108 }
107109 Measurement meas (" meas" , " meas" );
108110 meas.SetPOI (" SignalStrength" );
@@ -121,19 +123,20 @@ void buildBinnedTest(int n_channels = 1, int nbins = 10, int nnps = 1, const cha
121123 } else {
122124 ws = std::unique_ptr<RooWorkspace>{hist2workspace.MakeCombinedModel (meas)};
123125 }
124- for (RooAbsArg * arg : ws->components ()) {
126+ for (RooAbsArg *arg : ws->components ()) {
125127 if (arg->IsA () == RooRealSumPdf::Class ()) {
126128 arg->setAttribute (" BinnedLikelihood" );
127- if (verbose) std::cout << " component " << arg->GetName () << " is a binned likelihood" << std::endl;
129+ if (verbose)
130+ std::cout << " component " << arg->GetName () << " is a binned likelihood" << std::endl;
128131 }
129132 }
130133 ws->SetName (" BinnedWorkspace" );
131134 ws->writeToFile (name_rootfile);
132135}
133136
134- // ############## End of Base Algorithms ##############################
135- // ####################################################################
136- // ############## Start Of # Tests #############################
137+ // ############## End of Base Algorithms ##############################
138+ // ####################################################################
139+ // ############## Start Of # Tests #############################
137140
138141static void BM_RooFit_BinnedTestMigrad (benchmark::State &state)
139142{
@@ -145,7 +148,8 @@ static void BM_RooFit_BinnedTestMigrad(benchmark::State &state)
145148 auto infile = std::make_unique<TFile>(" workspace.root" , " RECREATE" );
146149 // if (infile->IsZombie()) {
147150 buildBinnedTest (chan, nbins, 2 , " workspace.root" );
148- if (verbose) std::cout << " Workspace for tests was created!" << std::endl;
151+ if (verbose)
152+ std::cout << " Workspace for tests was created!" << std::endl;
149153 // }
150154 infile.reset (TFile::Open (" workspace.root" ));
151155 RooWorkspace *w = static_cast <RooWorkspace *>(infile->Get (" BinnedWorkspace" ));
@@ -174,7 +178,8 @@ static void BM_RooFit_BinnedTestHesse(benchmark::State &state)
174178 TFile *infile = new TFile (" workspace.root" );
175179 // if (infile->IsZombie()) {
176180 buildBinnedTest (chan, nbins, 2 , " workspace.root" );
177- if (verbose) std::cout << " Workspace for tests was created!" << std::endl;
181+ if (verbose)
182+ std::cout << " Workspace for tests was created!" << std::endl;
178183 // }
179184 infile = TFile::Open (" workspace.root" );
180185 RooWorkspace *w = static_cast <RooWorkspace *>(infile->Get (" BinnedWorkspace" ));
@@ -211,7 +216,8 @@ static void BM_RooFit_BinnedTestMinos(benchmark::State &state)
211216 auto infile = std::make_unique<TFile>(" workspace.root" );
212217 // if (infile->IsZombie()) {
213218 buildBinnedTest (chan, nbins, 2 , " workspace.root" );
214- if (verbose) std::cout << " Workspace for tests was created!" << std::endl;
219+ if (verbose)
220+ std::cout << " Workspace for tests was created!" << std::endl;
215221 // }
216222 infile.reset (TFile::Open (" workspace.root" ));
217223 RooWorkspace *w = static_cast <RooWorkspace *>(infile->Get (" BinnedWorkspace" ));
@@ -235,11 +241,11 @@ static void BM_RooFit_BinnedTestMinos(benchmark::State &state)
235241 }
236242}
237243
238- // ############## Run # Tests ###############################
244+ // ############## Run # Tests ###############################
239245
240246static void ChanArguments (benchmark::internal::Benchmark *b)
241247{
242- // channel scan
248+ // channel scan
243249 for (int nChannels : nChannelsVector) {
244250 for (int nCPU : nCPUVector) {
245251 b->Args ({nChannels, nBinsForChannelScan, nCPU});
@@ -254,24 +260,26 @@ static void ChanArguments(benchmark::internal::Benchmark *b)
254260 }
255261}
256262
257- BENCHMARK (BM_RooFit_BinnedTestMigrad)
258- ->Apply(ChanArguments)
259- ->UseRealTime()
260- ->Unit(timeUnit)
261- ->Iterations(1 );
262- BENCHMARK (BM_RooFit_BinnedTestHesse)
263- ->Apply(ChanArguments)
264- ->UseRealTime()
265- ->Unit(timeUnit)
266- ->Iterations(1 );
267- BENCHMARK (BM_RooFit_BinnedTestMinos)
268- ->Apply(ChanArguments)
269- ->UseRealTime()
270- ->Unit(timeUnit)
271- ->Iterations(1 );
263+ BENCHMARK (BM_RooFit_BinnedTestMigrad)->Apply(ChanArguments)->UseRealTime()->Unit(timeUnit)->Iterations(1 );
264+ BENCHMARK (BM_RooFit_BinnedTestHesse)->Apply(ChanArguments)->UseRealTime()->Unit(timeUnit)->Iterations(1 );
265+ BENCHMARK (BM_RooFit_BinnedTestMinos)->Apply(ChanArguments)->UseRealTime()->Unit(timeUnit)->Iterations(1 );
266+
267+ // ############## End Of Tests ########################################
268+ // ####################################################################
269+ // ############## RUN #################################################
270+
271+ int main (int argc, char **argv)
272+ {
272273
273- // ############## End Of Tests ########################################
274- // ####################################################################
275- // ############## RUN #################################################
274+ benchmark::Initialize (&argc, argv);
276275
277- BENCHMARK_MAIN ();
276+ for (int i = 1 ; i < argc; ++i) {
277+ if (std::string (argv[i]) == " -b" ) {
278+ if (i + 1 < argc) {
279+ // Set the evalBackend value from the next command-line argument
280+ evalBackend = argv[i + 1 ];
281+ }
282+ }
283+ }
284+ benchmark::RunSpecifiedBenchmarks ();
285+ }
0 commit comments