Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Root
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
为了安全,强烈建议开启2FA双因子认证:User Settings -> Account -> Enable two-factor authentication!!!
Show more breadcrumbs
cxwx
Root
Commits
caf3e243
Commit
caf3e243
authored
3 years ago
by
Stephan Hageboeck
Browse files
Options
Downloads
Patches
Plain Diff
[RF] Convert ToyMCSampler to using unique_ptr.
parent
e485b289
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
roofit/roostats/inc/RooStats/ToyMCSampler.h
+14
-21
14 additions, 21 deletions
roofit/roostats/inc/RooStats/ToyMCSampler.h
roofit/roostats/src/ToyMCSampler.cxx
+26
-63
26 additions, 63 deletions
roofit/roostats/src/ToyMCSampler.cxx
with
40 additions
and
84 deletions
roofit/roostats/inc/RooStats/ToyMCSampler.h
+
14
−
21
View file @
caf3e243
...
...
@@ -13,14 +13,6 @@
#ifndef ROOSTATS_ToyMCSampler
#define ROOSTATS_ToyMCSampler
#include
"Rtypes.h"
#include
<vector>
#include
<list>
#include
<string>
#include
<sstream>
#include
"RooStats/TestStatSampler.h"
#include
"RooStats/SamplingDistribution.h"
#include
"RooStats/TestStatistic.h"
...
...
@@ -33,6 +25,10 @@
#include
"RooRealVar.h"
#include
"RooDataSet.h"
#include
<vector>
#include
<list>
#include
<string>
#include
<sstream>
#include
<memory>
namespace
RooStats
{
...
...
@@ -47,14 +43,11 @@ class NuisanceParametersSampler {
fParams
(
parameters
),
fNToys
(
nToys
),
fExpected
(
asimov
),
fPoints
(
NULL
),
fIndex
(
0
)
{
if
(
prior
)
Refresh
();
}
virtual
~
NuisanceParametersSampler
()
{
if
(
fPoints
)
{
delete
fPoints
;
fPoints
=
NULL
;
}
}
virtual
~
NuisanceParametersSampler
()
=
default
;
void
NextPoint
(
RooArgSet
&
nuisPoint
,
Double_t
&
weight
);
...
...
@@ -67,7 +60,7 @@ class NuisanceParametersSampler {
Int_t
fNToys
;
Bool_t
fExpected
;
RooAbsData
*
fPoints
;
// generated nuisance parameter points
std
::
unique_ptr
<
RooAbsData
>
fPoints
;
// generated nuisance parameter points
Int_t
fIndex
;
// current index in fPoints array
};
...
...
@@ -283,14 +276,14 @@ class ToyMCSampler: public TestStatSampler {
mutable
NuisanceParametersSampler
*
fNuisanceParametersSampler
;
//!
// objects below cache information and are mutable and non-persistent
mutable
RooArgSet
*
_allVars
;
//!
mutable
std
::
list
<
RooAbsPdf
*>
_pdfList
;
//!
mutable
std
::
list
<
RooArgSet
*
>
_obsList
;
//!
mutable
std
::
list
<
RooAbsPdf
::
GenSpec
*
>
_gsList
;
//!
mutable
RooAbsPdf
::
GenSpec
*
_gs1
;
//! GenSpec #1
mutable
RooAbsPdf
::
GenSpec
*
_gs2
;
//! GenSpec #2
mutable
RooAbsPdf
::
GenSpec
*
_gs3
;
//! GenSpec #3
mutable
RooAbsPdf
::
GenSpec
*
_gs4
;
//! GenSpec #4
mutable
std
::
unique_ptr
<
RooArgSet
>
_allVars
;
//!
mutable
std
::
vector
<
RooAbsPdf
*>
_pdfList
;
//!
We don't own those objects
mutable
std
::
vector
<
std
::
unique_ptr
<
RooArgSet
>
>
_obsList
;
//!
mutable
std
::
vector
<
std
::
unique_ptr
<
RooAbsPdf
::
GenSpec
>
>
_gsList
;
//!
mutable
std
::
unique_ptr
<
RooAbsPdf
::
GenSpec
>
_gs1
;
//! GenSpec #1
mutable
std
::
unique_ptr
<
RooAbsPdf
::
GenSpec
>
_gs2
;
//! GenSpec #2
mutable
std
::
unique_ptr
<
RooAbsPdf
::
GenSpec
>
_gs3
;
//! GenSpec #3
mutable
std
::
unique_ptr
<
RooAbsPdf
::
GenSpec
>
_gs4
;
//! GenSpec #4
static
Bool_t
fgAlwaysUseMultiGen
;
// Use PrepareMultiGen always
Bool_t
fUseMultiGen
;
// Use PrepareMultiGen?
...
...
This diff is collapsed.
Click to expand it.
roofit/roostats/src/ToyMCSampler.cxx
+
26
−
63
View file @
caf3e243
...
...
@@ -93,8 +93,6 @@ void NuisanceParametersSampler::Refresh() {
if
(
!
fPrior
||
!
fParams
)
return
;
if
(
fPoints
)
delete
fPoints
;
if
(
fExpected
)
{
// UNDER CONSTRUCTION
oocoutI
((
TObject
*
)
NULL
,
InputArguments
)
<<
"Using expected nuisance parameters."
<<
endl
;
...
...
@@ -110,12 +108,12 @@ void NuisanceParametersSampler::Refresh() {
}
fPoints
=
fPrior
->
generate
(
fPoints
.
reset
(
fPrior
->
generate
(
*
fParams
,
AllBinned
(),
ExpectedData
(),
NumEvents
(
1
)
// for Asimov set, this is only a scale factor
);
)
);
if
(
fPoints
->
numEntries
()
!=
fNToys
)
{
fNToys
=
fPoints
->
numEntries
();
oocoutI
((
TObject
*
)
NULL
,
InputArguments
)
<<
...
...
@@ -137,7 +135,7 @@ void NuisanceParametersSampler::Refresh() {
}
else
{
oocoutI
((
TObject
*
)
NULL
,
InputArguments
)
<<
"Using randomized nuisance parameters."
<<
endl
;
fPoints
=
fPrior
->
generate
(
*
fParams
,
fNToys
);
fPoints
.
reset
(
fPrior
->
generate
(
*
fParams
,
fNToys
)
)
;
}
}
...
...
@@ -176,12 +174,6 @@ ToyMCSampler::ToyMCSampler() : fSamplingDistName("SD"), fNToys(1)
fProofConfig
=
NULL
;
fNuisanceParametersSampler
=
NULL
;
_allVars
=
NULL
;
_gs1
=
NULL
;
_gs2
=
NULL
;
_gs3
=
NULL
;
_gs4
=
NULL
;
//suppress messages for num integration of Roofit
RooMsgService
::
instance
().
getStream
(
1
).
removeTopic
(
RooFit
::
NumIntegration
);
...
...
@@ -215,12 +207,6 @@ ToyMCSampler::ToyMCSampler(TestStatistic &ts, Int_t ntoys) : fSamplingDistName(t
fProofConfig
=
NULL
;
fNuisanceParametersSampler
=
NULL
;
_allVars
=
NULL
;
_gs1
=
NULL
;
_gs2
=
NULL
;
_gs3
=
NULL
;
_gs4
=
NULL
;
//suppress messages for num integration of Roofit
RooMsgService
::
instance
().
getStream
(
1
).
removeTopic
(
RooFit
::
NumIntegration
);
...
...
@@ -488,7 +474,7 @@ void ToyMCSampler::GenerateGlobalObservables(RooAbsPdf& pdf) const {
const
RooArgSet
*
values
=
one
->
get
(
0
);
if
(
!
_allVars
)
{
_allVars
=
pdf
.
getVariables
();
_allVars
.
reset
(
pdf
.
getVariables
()
)
;
}
*
_allVars
=
*
values
;
delete
one
;
...
...
@@ -505,18 +491,15 @@ void ToyMCSampler::GenerateGlobalObservables(RooAbsPdf& pdf) const {
RooArgSet
*
globtmp
=
pdftmp
->
getObservables
(
*
fGlobalObservables
);
RooAbsPdf
::
GenSpec
*
gs
=
pdftmp
->
prepareMultiGen
(
*
globtmp
,
NumEvents
(
1
));
_pdfList
.
push_back
(
pdftmp
);
_obsList
.
push
_back
(
globtmp
);
_gsList
.
push
_back
(
gs
);
_obsList
.
emplace
_back
(
globtmp
);
_gsList
.
emplace
_back
(
gs
);
}
}
list
<
RooArgSet
*>::
iterator
oiter
=
_obsList
.
begin
();
list
<
RooAbsPdf
::
GenSpec
*>::
iterator
giter
=
_gsList
.
begin
();
for
(
list
<
RooAbsPdf
*>::
iterator
iter
=
_pdfList
.
begin
();
iter
!=
_pdfList
.
end
();
++
iter
,
++
giter
,
++
oiter
)
{
//RooDataSet* tmp = (*iter)->generate(**oiter,1) ;
RooDataSet
*
tmp
=
(
*
iter
)
->
generate
(
**
giter
);
**
oiter
=
*
tmp
->
get
(
0
);
delete
tmp
;
// Assign generated values to the observables in _obsList
for
(
unsigned
int
i
=
0
;
i
<
_pdfList
.
size
();
++
i
)
{
std
::
unique_ptr
<
RooDataSet
>
tmp
(
_pdfList
[
i
]
->
generate
(
*
_gsList
[
i
])
);
*
_obsList
[
i
]
=
*
tmp
->
get
(
0
);
}
}
...
...
@@ -631,14 +614,14 @@ RooAbsData* ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const
}
else
{
if
(
protoData
)
{
if
(
useMultiGen
)
{
if
(
!
_gs2
)
{
_gs2
=
pdf
.
prepareMultiGen
(
observables
,
Extended
(),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
),
ProtoData
(
*
protoData
,
true
,
true
))
;
}
if
(
!
_gs2
)
_gs2
.
reset
(
pdf
.
prepareMultiGen
(
observables
,
Extended
(),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
),
ProtoData
(
*
protoData
,
true
,
true
))
)
;
data
=
pdf
.
generate
(
*
_gs2
)
;
}
else
{
data
=
pdf
.
generate
(
observables
,
Extended
(),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
),
ProtoData
(
*
protoData
,
true
,
true
));
}
}
else
{
if
(
useMultiGen
)
{
if
(
!
_gs1
)
{
_gs1
=
pdf
.
prepareMultiGen
(
observables
,
Extended
(),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
)
)
;
}
if
(
!
_gs1
)
_gs1
.
reset
(
pdf
.
prepareMultiGen
(
observables
,
Extended
(),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
))
)
;
data
=
pdf
.
generate
(
*
_gs1
)
;
}
else
{
data
=
pdf
.
generate
(
observables
,
Extended
(),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
)
);
...
...
@@ -658,14 +641,14 @@ RooAbsData* ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const
}
else
{
if
(
protoData
)
{
if
(
useMultiGen
)
{
if
(
!
_gs3
)
{
_gs3
=
pdf
.
prepareMultiGen
(
observables
,
NumEvents
(
events
),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
),
ProtoData
(
*
protoData
,
true
,
true
))
;
}
if
(
!
_gs3
)
_gs3
.
reset
(
pdf
.
prepareMultiGen
(
observables
,
NumEvents
(
events
),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
),
ProtoData
(
*
protoData
,
true
,
true
))
);
data
=
pdf
.
generate
(
*
_gs3
)
;
}
else
{
data
=
pdf
.
generate
(
observables
,
NumEvents
(
events
),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
),
ProtoData
(
*
protoData
,
true
,
true
));
}
}
else
{
if
(
useMultiGen
)
{
if
(
!
_gs4
)
{
_gs4
=
pdf
.
prepareMultiGen
(
observables
,
NumEvents
(
events
),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
))
;
}
if
(
!
_gs4
)
_gs4
.
reset
(
pdf
.
prepareMultiGen
(
observables
,
NumEvents
(
events
),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
))
);
data
=
pdf
.
generate
(
*
_gs4
)
;
}
else
{
data
=
pdf
.
generate
(
observables
,
NumEvents
(
events
),
AutoBinned
(
fGenerateAutoBinned
),
GenBinned
(
fGenerateBinnedTag
));
...
...
@@ -674,12 +657,6 @@ RooAbsData* ToyMCSampler::Generate(RooAbsPdf &pdf, RooArgSet &observables, const
}
}
// in case of number counting print observables
// if (data->numEntries() == 1) {
// std::cout << "generate observables : ";
// RooStats::PrintListContent(*data->get(0), std::cout);
// }
return
data
;
}
...
...
@@ -710,32 +687,18 @@ SamplingDistribution* ToyMCSampler::AppendSamplingDistribution(
/// needs to be called every time the model pdf (fPdf) changes
void
ToyMCSampler
::
ClearCache
()
{
if
(
_gs1
)
delete
_gs1
;
_gs1
=
0
;
if
(
_gs2
)
delete
_gs2
;
_gs2
=
0
;
if
(
_gs3
)
delete
_gs3
;
_gs3
=
0
;
if
(
_gs4
)
delete
_gs4
;
_gs4
=
0
;
// no need to delete the _pdfList since it is managed by the RooSimultaneous object
if
(
_pdfList
.
size
()
>
0
)
{
std
::
list
<
RooArgSet
*>::
iterator
oiter
=
_obsList
.
begin
();
for
(
std
::
list
<
RooAbsPdf
::
GenSpec
*>::
iterator
giter
=
_gsList
.
begin
();
giter
!=
_gsList
.
end
();
++
giter
,
++
oiter
)
{
delete
*
oiter
;
delete
*
giter
;
}
_pdfList
.
clear
();
_obsList
.
clear
();
_gsList
.
clear
();
}
//LM: is this set really needed ??
if
(
_allVars
)
delete
_allVars
;
_allVars
=
0
;
_gs1
=
nullptr
;
_gs2
=
nullptr
;
_gs3
=
nullptr
;
_gs4
=
nullptr
;
_allVars
=
nullptr
;
// no need to delete the _pdfList since it is managed by the RooSimultaneous object
if
(
_pdfList
.
size
()
>
0
)
{
_pdfList
.
clear
();
_obsList
.
clear
();
_gsList
.
clear
();
}
}
}
// end namespace RooStats
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment