Logo ROOT   6.12/07
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 
14 ToyMCStudy is an implementation of RooAbsStudy for toy Monte Carlo sampling.
15 This class is automatically used by ToyMCSampler when given a ProofConfig.
16 This is also its intended use case.
17 */
18 
19 #include "RooStats/ToyMCStudy.h"
20 
21 #include "RooStats/ToyMCSampler.h"
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 
36 using namespace std;
37 
38 
39 namespace 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;
61  TRandom2 r(fRandomSeed );
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)
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 
78 Bool_t ToyMCStudy::execute(void) {
79 
80  coutP(Generation) << "ToyMCStudy::execute - run with seed " << RooRandom::randomGenerator()->Integer(TMath::Limits<unsigned int>::Max() ) << std::endl;
81  RooDataSet* sd = fToyMCSampler->GetSamplingDistributionsSingleWorker(fParamPoint);
82  ToyMCPayload *sdw = new ToyMCPayload(sd);
83  storeDetailedOutput(*sdw);
84 
85  return kFALSE;
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 
90 Bool_t ToyMCStudy::finalize(void) {
91  coutP(Generation) << "ToyMCStudy::finalize" << endl;
92 
93  if(fToyMCSampler) delete fToyMCSampler;
94  fToyMCSampler = NULL;
95 
96  return kFALSE;
97 }
98 
99 ////////////////////////////////////////////////////////////////////////////////
100 
101 RooDataSet* ToyMCStudy::merge() {
102 
103  RooDataSet* samplingOutput = NULL;
104 
105  if(!detailedData()) {
106  coutE(Generation) << "ToyMCStudy::merge No detailed output present." << endl;
107  return NULL;
108  }
109 
110  RooLinkedListIter iter = detailedData()->iterator();
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
#define coutE(a)
Definition: RooMsgService.h:34
#define coutI(a)
Definition: RooMsgService.h:31
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
Definition: TRandom2.h:27
RooDataSet * GetSamplingDistributions()
Definition: ToyMCStudy.h:92
bool Bool_t
Definition: RtypesCore.h:59
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:33
#define coutP(a)
Definition: RooMsgService.h:32
ToyMCStudy is an implementation of RooAbsStudy for toy Monte Carlo sampling.
Definition: ToyMCStudy.h:32
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:589
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
Definition: TRandom.cxx:341
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:54
virtual TObject * Next()
ROOT::R::TRInterface & r
Definition: Object.C:4
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
const Bool_t kFALSE
Definition: RtypesCore.h:88
Namespace for the RooStats classes.
Definition: Asimov.h:20
#define ClassImp(name)
Definition: Rtypes.h:359
void append(RooDataSet &data)
Add all data points of given data set to this data set.
R__EXTERN TEnv * gEnv
Definition: TEnv.h:171
Mother of all ROOT objects.
Definition: TObject.h:37
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition: TEnv.cxx:491
void initialize(typename Architecture_t::Matrix_t &A, EInitialization m)
Definition: Functions.h:249
virtual UInt_t GetSeed() const
Definition: TRandom.h:40
RooLinkedListIter is the TIterator implementation for RooLinkedList.
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:285