Logo ROOT   6.08/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 #include "RooStats/ToyMCStudy.h"
12 
13 #include "RooStats/ToyMCSampler.h"
14 
15 
16 #ifndef ROO_MSG_SERVICE
17 #include "RooMsgService.h"
18 #endif
19 
20 #include "RooRandom.h"
21 #include "TRandom2.h"
22 #include "TMath.h"
23 
24 #include "TEnv.h"
25 
26 
27 
29 
31 
32 using namespace std;
33 
34 
35 namespace RooStats {
36 
37 // _____________________________________________________________________________
39  coutP(Generation) << "initialize" << endl;
40 
41  if(!fToyMCSampler) {
42  coutE(InputArguments) << "Need an instance of ToyMCSampler to run." << endl;
43  return kFALSE;
44  }else{
45  coutI(InputArguments) << "Using given ToyMCSampler." << endl;
46  }
47 
48 
49  TString worknumber = gEnv->GetValue("ProofServ.Ordinal","undef");
50  int iworker = -1;
51  if (worknumber != "undef") {
52  iworker = int( worknumber.Atof()*10 + 0.1);
53 
54  // generate a seed using
55  std::cout << "Current global seed is " << fRandomSeed << std::endl;
56  TRandom2 r(fRandomSeed );
57  // get a seed using the iworker-value
58  unsigned int seed = r.Integer(TMath::Limits<unsigned int>::Max() );
59  for (int i = 0; i< iworker; ++i)
61 
62  // initialize worker using seed from ToyMCSampler
64  }
65 
66  coutI(InputArguments) << "Worker " << iworker << " seed is: " << RooRandom::randomGenerator()->GetSeed() << endl;
67 
68  return kFALSE;
69 }
70 
71 // _____________________________________________________________________________
72 Bool_t ToyMCStudy::execute(void) {
73 
74  coutP(Generation) << "ToyMCStudy::execute - run with seed " << RooRandom::randomGenerator()->Integer(TMath::Limits<unsigned int>::Max() ) << std::endl;
75  RooDataSet* sd = fToyMCSampler->GetSamplingDistributionsSingleWorker(fParamPoint);
76  ToyMCPayload *sdw = new ToyMCPayload(sd);
77  storeDetailedOutput(*sdw);
78 
79  return kFALSE;
80 }
81 
82 // _____________________________________________________________________________
83 Bool_t ToyMCStudy::finalize(void) {
84  coutP(Generation) << "ToyMCStudy::finalize" << endl;
85 
86  if(fToyMCSampler) delete fToyMCSampler;
87  fToyMCSampler = NULL;
88 
89  return kFALSE;
90 }
91 
92 
93 RooDataSet* ToyMCStudy::merge() {
94 
95  RooDataSet* samplingOutput = NULL;
96 
97  if(!detailedData()) {
98  coutE(Generation) << "ToyMCStudy::merge No detailed output present." << endl;
99  return NULL;
100  }
101 
102  RooLinkedListIter iter = detailedData()->iterator();
103  TObject *o = NULL;
104  int i = 0;
105  while((o = iter.Next())) {
106  ToyMCPayload *oneWorker = dynamic_cast< ToyMCPayload* >(o);
107  if(!oneWorker) {
108  coutW(Generation) << "Merging Results problem: not correct type" << endl;
109  continue;
110  }
111 
112  if( !samplingOutput ) samplingOutput = new RooDataSet(*oneWorker->GetSamplingDistributions());
113 
114  else samplingOutput->append( *oneWorker->GetSamplingDistributions() );
115 
116  i++;
117  //delete oneWorker;
118  }
119  coutP(Generation) << "Merged data from nworkers # " << i << "- merged data size is " << samplingOutput->numEntries() << std::endl;
120 
121 
122  return samplingOutput;
123 }
124 
125 
126 } // end namespace RooStats
#define coutE(a)
Definition: RooMsgService.h:35
#define coutI(a)
Definition: RooMsgService.h:32
Random number generator class based on the maximally quidistributed combined Tausworthe generator by ...
Definition: TRandom2.h:29
RooDataSet * GetSamplingDistributions()
Definition: ToyMCStudy.h:110
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
STL namespace.
#define coutW(a)
Definition: RooMsgService.h:34
#define coutP(a)
Definition: RooMsgService.h:33
ToyMCStudy is an implementation of RooAbsStudy for toy Monte Carlo sampling.
Definition: ToyMCStudy.h:50
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
Definition: TRandom.cxx:568
virtual UInt_t Integer(UInt_t imax)
Returns a random integer on [ 0, imax-1 ].
Definition: TRandom.cxx:320
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Definition: RooRandom.cxx:54
virtual TObject * Next()
TRandom2 r(17)
virtual Int_t GetValue(const char *name, Int_t dflt)
Returns the integer value for a resource.
Definition: TEnv.cxx:496
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
Namespace for the RooStats classes.
Definition: Asimov.h:20
#define ClassImp(name)
Definition: Rtypes.h:279
void append(RooDataSet &data)
Add all data points of given data set to this data set.
R__EXTERN TEnv * gEnv
Definition: TEnv.h:174
Mother of all ROOT objects.
Definition: TObject.h:37
#define NULL
Definition: Rtypes.h:82
void initialize(typename Architecture_t::Matrix_t &A, EInitialization m)
Definition: Functions.h:257
virtual UInt_t GetSeed() const
Definition: TRandom.h:44
RooLinkedListIter is the TIterator implementation for RooLinkedList.
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:269