Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
ToyMCStudy.cxx
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Sven Kreiss and Kyle Cranmer June 2010
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11/** \class RooStats::ToyMCStudy
12 \ingroup Roostats
13
14ToyMCStudy is an implementation of RooAbsStudy for toy Monte Carlo sampling.
15This class is automatically used by ToyMCSampler when given a ProofConfig.
16This is also its intended use case.
17*/
18
19#include "RooStats/ToyMCStudy.h"
20
22
23
24#include "RooMsgService.h"
25
26#include "RooRandom.h"
27#include "TRandom2.h"
28#include "TMath.h"
29
30#include "TEnv.h"
31
33
35
36using namespace std;
37
38
39namespace RooStats {
40
41////////////////////////////////////////////////////////////////////////////////
42
44 coutP(Generation) << "initialize" << endl;
45
46 if(!fToyMCSampler) {
47 coutE(InputArguments) << "Need an instance of ToyMCSampler to run." << endl;
48 return false;
49 }else{
50 coutI(InputArguments) << "Using given ToyMCSampler." << endl;
51 }
52
53
54 TString worknumber = gEnv->GetValue("ProofServ.Ordinal","undef");
55 int iworker = -1;
56 if (worknumber != "undef") {
57 iworker = int( worknumber.Atof()*10 + 0.1);
58
59 // generate a seed using
60 std::cout << "Current global seed is " << fRandomSeed << std::endl;
62 // get a seed using the iworker-value
63 unsigned int seed = r.Integer(TMath::Limits<unsigned int>::Max() );
64 for (int i = 0; i< iworker; ++i)
65 seed = r.Integer(TMath::Limits<unsigned int>::Max() );
66
67 // initialize worker using seed from ToyMCSampler
69 }
70
71 coutI(InputArguments) << "Worker " << iworker << " seed is: " << RooRandom::randomGenerator()->GetSeed() << endl;
72
73 return false;
74}
75
76////////////////////////////////////////////////////////////////////////////////
77
79
80 coutP(Generation) << "ToyMCStudy::execute - run with seed " << RooRandom::randomGenerator()->Integer(TMath::Limits<unsigned int>::Max() ) << std::endl;
82 storeDetailedOutput(std::make_unique<ToyMCPayload>(sd));
83
84 return false;
85}
86
87////////////////////////////////////////////////////////////////////////////////
88
90 coutP(Generation) << "ToyMCStudy::finalize" << endl;
91
93 fToyMCSampler = nullptr;
94
95 return false;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99
101
102 RooDataSet* samplingOutput = nullptr;
103
104 if(!detailedData()) {
105 coutE(Generation) << "ToyMCStudy::merge No detailed output present." << endl;
106 return nullptr;
107 }
108
109 int i = 0;
110 for (auto * o : static_range_cast<TObject*>(*detailedData())) {
111 ToyMCPayload *oneWorker = dynamic_cast< ToyMCPayload* >(o);
112 if(!oneWorker) {
113 coutW(Generation) << "Merging Results problem: not correct type" << endl;
114 continue;
115 }
116
117 if( !samplingOutput ) samplingOutput = new RooDataSet(*oneWorker->GetSamplingDistributions());
118
119 else samplingOutput->append( *oneWorker->GetSamplingDistributions() );
120
121 i++;
122 //delete oneWorker;
123 }
124 coutP(Generation) << "Merged data from nworkers # " << i << "- merged data size is " << samplingOutput->numEntries() << std::endl;
125
126
127 return samplingOutput;
128}
129
130
131} // end namespace RooStats
#define coutI(a)
#define coutP(a)
#define coutW(a)
#define coutE(a)
#define ClassImp(name)
Definition Rtypes.h:377
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
void storeDetailedOutput(bool flag)
Definition RooAbsStudy.h:47
RooLinkedList * detailedData()
Definition RooAbsStudy.h:50
RooDataSet is a container class to hold unbinned data.
Definition RooDataSet.h:57
void append(RooDataSet &data)
Add all data points of given data set to this data set.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition RooRandom.cxx:51
RooDataSet * GetSamplingDistributions()
Definition ToyMCStudy.h:90
virtual RooDataSet * GetSamplingDistributionsSingleWorker(RooArgSet &paramPoint)
This is the main function for serial runs.
ToyMCStudy is an implementation of RooAbsStudy for toy Monte Carlo sampling.
Definition ToyMCStudy.h:30
unsigned int fRandomSeed
Definition ToyMCStudy.h:62
bool execute(void) override
bool finalize(void) override
ToyMCSampler * fToyMCSampler
Definition ToyMCStudy.h:63
RooArgSet fParamPoint
Definition ToyMCStudy.h:64
RooDataSet * merge()
bool initialize(void) override
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
Definition TRandom2.h:27
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition TRandom.cxx:608
virtual UInt_t GetSeed() const
Get the random generator seed.
Definition TRandom.cxx:641
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition TRandom.cxx:360
Basic string class.
Definition TString.h:139
Double_t Atof() const
Return floating-point value contained in string.
Definition TString.cxx:2032
Namespace for the RooStats classes.
Definition Asimov.h:19