Logo ROOT   6.18/05
Reference Guide
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 kFALSE;
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 kFALSE;
74}
75
76////////////////////////////////////////////////////////////////////////////////
77
79
80 coutP(Generation) << "ToyMCStudy::execute - run with seed " << RooRandom::randomGenerator()->Integer(TMath::Limits<unsigned int>::Max() ) << std::endl;
82 ToyMCPayload *sdw = new ToyMCPayload(sd);
84
85 return kFALSE;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89
91 coutP(Generation) << "ToyMCStudy::finalize" << endl;
92
94 fToyMCSampler = NULL;
95
96 return kFALSE;
97}
98
99////////////////////////////////////////////////////////////////////////////////
100
102
103 RooDataSet* samplingOutput = NULL;
104
105 if(!detailedData()) {
106 coutE(Generation) << "ToyMCStudy::merge No detailed output present." << endl;
107 return NULL;
108 }
109
111 TObject *o = NULL;
112 int i = 0;
113 while((o = iter.Next())) {
114 ToyMCPayload *oneWorker = dynamic_cast< ToyMCPayload* >(o);
115 if(!oneWorker) {
116 coutW(Generation) << "Merging Results problem: not correct type" << endl;
117 continue;
118 }
119
120 if( !samplingOutput ) samplingOutput = new RooDataSet(*oneWorker->GetSamplingDistributions());
121
122 else samplingOutput->append( *oneWorker->GetSamplingDistributions() );
123
124 i++;
125 //delete oneWorker;
126 }
127 coutP(Generation) << "Merged data from nworkers # " << i << "- merged data size is " << samplingOutput->numEntries() << std::endl;
128
129
130 return samplingOutput;
131}
132
133
134} // end namespace RooStats
ROOT::R::TRInterface & r
Definition: Object.C:4
#define coutI(a)
Definition: RooMsgService.h:31
#define coutP(a)
Definition: RooMsgService.h:32
#define coutW(a)
Definition: RooMsgService.h:33
#define coutE(a)
Definition: RooMsgService.h:34
const Bool_t kFALSE
Definition: RtypesCore.h:88
bool Bool_t
Definition: RtypesCore.h:59
#define ClassImp(name)
Definition: Rtypes.h:365
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:306
void storeDetailedOutput(Bool_t flag)
Definition: RooAbsStudy.h:47
RooLinkedList * detailedData()
Definition: RooAbsStudy.h:50
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:31
void append(RooDataSet &data)
Add all data points of given data set to this data set.
A wrapper around TIterator derivatives.
TObject * Next() override
RooLinkedListIter iterator(Bool_t forward=kTRUE) const
Create an iterator for this list.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:54
RooDataSet * GetSamplingDistributions()
Definition: ToyMCStudy.h:92
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:32
unsigned int fRandomSeed
Definition: ToyMCStudy.h:64
virtual Bool_t finalize(void)
Definition: ToyMCStudy.cxx:90
ToyMCSampler * fToyMCSampler
Definition: ToyMCStudy.h:65
RooArgSet fParamPoint
Definition: ToyMCStudy.h:66
virtual Bool_t initialize(void)
Definition: ToyMCStudy.cxx:43
RooDataSet * merge()
Definition: ToyMCStudy.cxx:101
virtual Bool_t execute(void)
Definition: ToyMCStudy.cxx:78
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
Mother of all ROOT objects.
Definition: TObject.h:37
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:597
virtual UInt_t GetSeed() const
Definition: TRandom.h:40
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Definition: TRandom.cxx:349
Basic string class.
Definition: TString.h:131
Double_t Atof() const
Return floating-point value contained in string.
Definition: TString.cxx:1987
@ Generation
Definition: RooGlobalFunc.h:57
@ InputArguments
Definition: RooGlobalFunc.h:58
Namespace for the RooStats classes.
Definition: Asimov.h:20