ROOT  6.06/09
Reference Guide
AsymptoticCalculator.cxx
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Author: Kyle Cranmer, Sven Kreiss 23/05/10
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 /**
12  Performs hypothesis tests using aysmptotic formula for the profile likelihood and
13  Asimov data set
14 */
15 
16 
18 #include "RooStats/ToyMCSampler.h"
19 #include "RooStats/ModelConfig.h"
21 #include "RooStats/RooStatsUtils.h"
22 
23 #include "RooArgSet.h"
24 #include "RooArgList.h"
25 #include "RooProdPdf.h"
26 #include "RooSimultaneous.h"
27 #include "RooDataSet.h"
28 #include "RooCategory.h"
29 #include "RooRealVar.h"
30 #include "RooMinimizer.h"
31 #include "RooFitResult.h"
32 #include "RooNLLVar.h"
33 #include "Math/MinimizerOptions.h"
34 #include "RooPoisson.h"
35 #include "RooUniform.h"
36 #include "RooGamma.h"
37 #include "RooGaussian.h"
38 #include "RooBifurGauss.h"
39 #include "RooLognormal.h"
40 #include "RooDataHist.h"
41 #include <cmath>
42 #include <typeinfo>
43 
44 #include "Math/BrentRootFinder.h"
45 #include "Math/WrappedFunction.h"
46 
47 #include "TStopwatch.h"
48 
49 using namespace RooStats;
50 using namespace std;
51 
52 
54 
56 
57 
59  // set print level (static function)
60  // 0 minimal, 1 normal, 2 debug
61  fgPrintLevel = level;
62 }
63 
64 
66  RooAbsData &data,
67  const ModelConfig &altModel,
68  const ModelConfig &nullModel, bool nominalAsimov) :
69  HypoTestCalculatorGeneric(data, altModel, nullModel, 0),
70  fOneSided(false), fOneSidedDiscovery(false), fNominalAsimov(nominalAsimov),
71  fUseQTilde(-1),
72  fNLLObs(0), fNLLAsimov(0),
73  fAsimovData(0)
74 {
75  // constructor for asymptotic calculator from Data set and ModelConfig
76  if (!Initialize()) return;
77 
78  int verbose = fgPrintLevel;
79  // try to guess default configuration
80  // (this part should be only in constructor because the null snapshot might change during HypoTestInversion
81  const RooArgSet * nullSnapshot = GetNullModel()->GetSnapshot();
82  assert(nullSnapshot);
83  RooRealVar * muNull = dynamic_cast<RooRealVar*>( nullSnapshot->first() );
84  assert(muNull);
85  if (muNull->getVal() == muNull->getMin()) {
86  fOneSidedDiscovery = true;
87  if (verbose > 0)
88  oocoutI((TObject*)0,InputArguments) << "AsymptotiCalculator: Minimum of POI is " << muNull->getMin() << " corresponds to null snapshot - default configuration is one-sided discovery formulae " << std::endl;
89  }
90 
91 }
92 
93 
95  // Initialize the calculator
96  // The initialization will perform a global fit of the model to the data
97  // and build an Asimov data set.
98  // It will then also fit the model to the Asimov data set to find the likelihood value
99  // of the Asimov data set
100  // nominalAsimov is an option for using Asimov data set obtained using nominal nuisance parameter values
101  // By default the nuisance parameters are fitted to the data
102  // NOTE: If a fit has been done before, one for speeding up could set all the initial prameters
103  // to the fit value and in addition set the null snapshot to the best fit
104 
105  int verbose = fgPrintLevel;
106  if (verbose >= 0)
107  oocoutP((TObject*)0,Eval) << "AsymptoticCalculator::Initialize...." << std::endl;
108 
109 
110  RooAbsPdf * nullPdf = GetNullModel()->GetPdf();
111  if (!nullPdf) {
112  oocoutE((TObject*)0,InputArguments) << "AsymptoticCalculator::Initialize - ModelConfig has not a pdf defined" << std::endl;
113  return false;
114  }
115  RooAbsData * obsData = const_cast<RooAbsData *>(GetData() );
116  if (!obsData ) {
117  oocoutE((TObject*)0,InputArguments) << "AsymptoticCalculator::Initialize - data set has not been defined" << std::endl;
118  return false;
119  }
120  RooAbsData & data = *obsData;
121 
122 
123 
124  const RooArgSet * poi = GetNullModel()->GetParametersOfInterest();
125  if (!poi || poi->getSize() == 0) {
126  oocoutE((TObject*)0,InputArguments) << "AsymptoticCalculator::Initialize - ModelConfig has not POI defined." << endl;
127  return false;
128  }
129  if (poi->getSize() > 1) {
130  oocoutW((TObject*)0,InputArguments) << "AsymptoticCalculator::Initialize - ModelConfig has more than one POI defined \n\t"
131  << "The asymptotic calculator works for only one POI - consider as POI only the first parameter"
132  << std::endl;
133  }
134 
135 
136  // This will set the poi value to the null snapshot value in the ModelConfig
137  const RooArgSet * nullSnapshot = GetNullModel()->GetSnapshot();
138  if(nullSnapshot == NULL || nullSnapshot->getSize() == 0) {
139  oocoutE((TObject*)0,InputArguments) << "AsymptoticCalculator::Initialize - Null model needs a snapshot. Set using modelconfig->SetSnapshot(poi)." << endl;
140  return false;
141  }
142 
143  // GetNullModel()->Print();
144  // printf("ASymptotic calc: null snapshot\n");
145  // nullSnapshot->Print("v");
146  // printf("PDF variables " );
147  // nullPdf->getVariables()->Print("v");
148 
149  // keep snapshot for the initial parameter values (need for nominal Asimov)
150  RooArgSet nominalParams;
151  RooArgSet * allParams = nullPdf->getParameters(data);
152  RemoveConstantParameters(allParams);
153  if (fNominalAsimov) {
154  allParams->snapshot(nominalParams);
155  }
159 
160  // evaluate the unconditional nll for the full model on the observed data
161  if (verbose >= 0)
162  oocoutP((TObject*)0,Eval) << "AsymptoticCalculator::Initialize - Find best unconditional NLL on observed data" << endl;
163  fNLLObs = EvaluateNLL( *nullPdf, data, GetNullModel()->GetConditionalObservables());
164  // fill also snapshot of best poi
165  poi->snapshot(fBestFitPoi);
166  RooRealVar * muBest = dynamic_cast<RooRealVar*>(fBestFitPoi.first());
167  assert(muBest);
168  if (verbose >= 0)
169  oocoutP((TObject*)0,Eval) << "Best fitted POI value = " << muBest->getVal() << " +/- " << muBest->getError() << std::endl;
170  // keep snapshot of all best fit parameters
171  allParams->snapshot(fBestFitParams);
172  delete allParams;
173 
174  // compute Asimov data set for the background (alt poi ) value
175  const RooArgSet * altSnapshot = GetAlternateModel()->GetSnapshot();
176  if(altSnapshot == NULL || altSnapshot->getSize() == 0) {
177  oocoutE((TObject*)0,InputArguments) << "Alt (Background) model needs a snapshot. Set using modelconfig->SetSnapshot(poi)." << endl;
178  return false;
179  }
180 
181  RooArgSet poiAlt(*altSnapshot); // this is the poi snapshot of B (i.e. for mu=0)
182 
183  oocoutP((TObject*)0,Eval) << "AsymptoticCalculator: Building Asimov data Set" << endl;
184 
185  // check that in case of binned models th ennumber of bins of the observables are consistent
186  // with the number of bins in the observed data
187  // This number will be used for making the Asimov data set so it will be more consistent with the
188  // observed data
189  int prevBins = 0;
190  RooRealVar * xobs = 0;
191  if (GetNullModel()->GetObservables() && GetNullModel()->GetObservables()->getSize() == 1 ) {
192  xobs = (RooRealVar*) (GetNullModel()->GetObservables())->first();
193  if (data.IsA() == RooDataHist::Class() ) {
194  if (data.numEntries() != xobs->getBins() ) {
195  prevBins = xobs->getBins();
196  oocoutW((TObject*)0,InputArguments) << "AsymptoticCalculator: number of bins in " << xobs->GetName() << " are different than data bins "
197  << " set the same data bins " << data.numEntries() << " in range "
198  << " [ " << xobs->getMin() << " , " << xobs->getMax() << " ]" << std::endl;
199  xobs->setBins(data.numEntries());
200  }
201  }
202  }
203 
204  if (!fNominalAsimov) {
205  if (verbose >= 0)
206  oocoutI((TObject*)0,InputArguments) << "AsymptoticCalculator: Asimov data will be generated using fitted nuisance parameter values" << endl;
207  RooArgSet * tmp = (RooArgSet*) poiAlt.snapshot();
208  fAsimovData = MakeAsimovData( data, *GetNullModel(), poiAlt, fAsimovGlobObs,tmp);
209  }
210 
211  else {
212  // assume use current value of nuisance as nominal ones
213  if (verbose >= 0)
214  oocoutI((TObject*)0,InputArguments) << "AsymptoticCalculator: Asimovdata set will be generated using nominal (current) nuisance parameter values" << endl;
215  nominalParams = poiAlt; // set poi to alt value but keep nuisance at the nominal one
216  fAsimovData = MakeAsimovData( *GetNullModel(), nominalParams, fAsimovGlobObs);
217  }
218 
219  if (!fAsimovData) {
220  oocoutE((TObject*)0,InputArguments) << "AsymptoticCalculator: Error : Asimov data set could not be generated " << endl;
221  return false;
222  }
223 
224  // set global observables to their Asimov values
225  RooArgSet globObs;
226  RooArgSet globObsSnapshot;
227  if (GetNullModel()->GetGlobalObservables() ) {
228  globObs.add(*GetNullModel()->GetGlobalObservables());
229  assert(globObs.getSize() == fAsimovGlobObs.getSize() );
230  // store previous snapshot value
231  globObs.snapshot(globObsSnapshot);
232  globObs = fAsimovGlobObs;
233  }
234 
235 
236  // evaluate the likelihood. Since we use on Asimov data , conditional and unconditional values should be the same
237  // do conditional fit since is faster
238 
239  RooRealVar * muAlt = (RooRealVar*) poiAlt.first();
240  assert(muAlt);
241  if (verbose>=0)
242  oocoutP((TObject*)0,Eval) << "AsymptoticCalculator::Initialize Find best conditional NLL on ASIMOV data set for given alt POI ( " <<
243  muAlt->GetName() << " ) = " << muAlt->getVal() << std::endl;
244 
245  fNLLAsimov = EvaluateNLL( *nullPdf, *fAsimovData, GetNullModel()->GetConditionalObservables(), &poiAlt );
246  // for unconditional fit
247  //fNLLAsimov = EvaluateNLL( *nullPdf, *fAsimovData);
248  //poi->Print("v");
249 
250  // restore previous value
251  globObs = globObsSnapshot;
252 
253  // restore number of bins
254  if (prevBins > 0 && xobs) xobs->setBins(prevBins);
255 
256  fIsInitialized = true;
257  return true;
258 }
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 
262 Double_t AsymptoticCalculator::EvaluateNLL(RooAbsPdf & pdf, RooAbsData& data, const RooArgSet * condObs, const RooArgSet *poiSet) {
263  int verbose = fgPrintLevel;
264 
265 
268 
269 
270  RooArgSet* allParams = pdf.getParameters(data);
272  // add constraint terms for all non-constant parameters
273 
274  RooArgSet conditionalObs;
275  if (condObs) conditionalObs.add(*condObs);
276 
277  // need to call constrain for RooSimultaneous until stripDisconnected problem fixed
279 
280  RooArgSet* attachedSet = nll->getVariables();
281 
282  // if poi are specified - do a conditional fit
283  RooArgSet paramsSetConstant;
284  // support now only one POI
285  if (poiSet && poiSet->getSize() > 0) {
286  RooRealVar * muTest = (RooRealVar*) (poiSet->first());
287  RooRealVar * poiVar = dynamic_cast<RooRealVar*>( attachedSet->find( muTest->GetName() ) );
288  if (poiVar && !poiVar->isConstant() ) {
289  poiVar->setVal( muTest->getVal() );
290  poiVar->setConstant();
291  paramsSetConstant.add(*poiVar);
292  }
293  if (poiSet->getSize() > 1)
294  std::cout << "Model with more than one POI are not supported - ignore extra parameters, consider only first one" << std::endl;
295 
296 
297 
298  // This for more than one POI (not yet supported)
299  //
300  // RooLinkedListIter it = poiSet->iterator();
301  // RooRealVar* tmpPar = NULL, *tmpParA=NULL;
302  // while((tmpPar = (RooRealVar*)it.Next())){
303  // tmpParA = ((RooRealVar*)attachedSet->find(tmpPar->GetName()));
304  // tmpParA->setVal( tmpPar->getVal() );
305  // if (!tmpParA->isConstant() ) {
306  // tmpParA->setConstant();
307  // paramsSetConstant.add(*tmpParA);
308  // }
309  // }
310 
311  // check if there are non-const parameters so it is worth to do the minimization
312 
313  }
314 
315  TStopwatch tw;
316  tw.Start();
317  double val = -1;
318 
319  //check if needed to skip the fit
320  RooArgSet nllParams(*attachedSet);
322  delete attachedSet;
323  bool skipFit = (nllParams.getSize() == 0);
324 
325  if (skipFit)
326  val = nll->getVal(); // just evaluate nll in conditional fits with model without nuisance params
327  else {
328 
329 
330  int minimPrintLevel = verbose;
331 
332  RooMinimizer minim(*nll);
334  minim.setStrategy( strategy);
335  // use tolerance - but never smaller than 1 (default in RooMinimizer)
337  tol = std::max(tol,1.0); // 1.0 is the minimum value used in RooMinimizer
338  minim.setEps( tol );
339  //LM: RooMinimizer.setPrintLevel has +1 offset - so subtruct here -1
340  minim.setPrintLevel(minimPrintLevel-1);
341  int status = -1;
342  minim.optimizeConst(2);
345 
346  if (verbose > 0 )
347  std::cout << "AsymptoticCalculator::EvaluateNLL ........ using " << minimizer << " / " << algorithm
348  << " with strategy " << strategy << " and tolerance " << tol << std::endl;
349 
350 
351  for (int tries = 1, maxtries = 4; tries <= maxtries; ++tries) {
352  // status = minim.minimize(fMinimizer, ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str());
353  status = minim.minimize(minimizer, algorithm);
354  if (status%1000 == 0) { // ignore erros from Improve
355  break;
356  } else {
357  if (tries == 1) {
358  printf(" ----> Doing a re-scan first\n");
359  minim.minimize(minimizer,"Scan");
360  }
361  if (tries == 2) {
363  printf(" ----> trying with strategy = 1\n");
364  minim.setStrategy(1);
365  }
366  else
367  tries++; // skip this trial if stratehy is already 1
368  }
369  if (tries == 3) {
370  printf(" ----> trying with improve\n");
371  minimizer = "Minuit";
372  algorithm = "migradimproved";
373  }
374  }
375  }
376 
377  RooFitResult * result = 0;
378 
379 
380  if (status%100 == 0) { // ignore errors in Hesse or in Improve
381  result = minim.save();
382  }
383  if (result){
384  if (!RooStats::IsNLLOffset() )
385  val = result->minNll();
386  else {
387  bool previous = RooAbsReal::hideOffset();
389  val = nll->getVal();
390  if (!previous) RooAbsReal::setHideOffset(kFALSE) ;
391  }
392 
393  }
394  else {
395  oocoutE((TObject*)0,Fitting) << "FIT FAILED !- return a NaN NLL " << std::endl;
396  val = TMath::QuietNaN();
397  }
398 
399  minim.optimizeConst(false);
400  if (result) delete result;
401 
402 
403  }
404 
405  double muTest = 0;
406  if (verbose > 0) {
407  std::cout << "AsymptoticCalculator::EvaluateNLL - value = " << val;
408  if (poiSet) {
409  muTest = ( (RooRealVar*) poiSet->first() )->getVal();
410  std::cout << " for poi fixed at = " << muTest;
411  }
412  if (!skipFit) {
413  std::cout << "\tfit time : ";
414  tw.Print();
415  }
416  else
417  std::cout << std::endl;
418  }
419 
420  // reset the parameter free which where set as constant
421  if (poiSet && paramsSetConstant.getSize() > 0) SetAllConstant(paramsSetConstant,false);
422 
423 
424  if (verbose < 2) RooMsgService::instance().setGlobalKillBelow(msglevel);
425 
426  delete allParams;
427  delete nll;
428 
429  return val;
430 }
431 
432 ////////////////////////////////////////////////////////////////////////////////
433 /// It performs an hypothesis tests using the likelihood function
434 /// and computes the p values for the null and the alternate using the asymptotic
435 /// formulae for the profile likelihood ratio.
436 /// See G. Cowan, K. Cranmer, E. Gross and O. Vitells.
437 /// Asymptotic formulae for likelihood- based tests of new physics. Eur. Phys. J., C71:1–19, 2011.
438 /// The formulae are valid only for one POI. If more than one POI exists consider as POI only the
439 /// first one
440 
442  int verbose = fgPrintLevel;
443 
444  // re-initialized the calculator in case it is needed (pdf or data modifided)
445  if (!fIsInitialized) {
446  if (!Initialize() ) {
447  oocoutE((TObject*)0,InputArguments) << "AsymptoticCalculator::GetHypoTest - Error initializing Asymptotic calculator - return NULL result " << endl;
448  return 0;
449  }
450  }
451 
452  if (!fAsimovData) {
453  oocoutE((TObject*)0,InputArguments) << "AsymptoticCalculator::GetHypoTest - Asimov data set has not been generated - return NULL result " << endl;
454  return 0;
455  }
456 
457  assert(GetNullModel() );
458  assert(GetData() );
459 
460  RooAbsPdf * nullPdf = GetNullModel()->GetPdf();
461  assert(nullPdf);
462 
463  // make conditional fit on null snapshot of poi
464 
465  const RooArgSet * nullSnapshot = GetNullModel()->GetSnapshot();
466  assert(nullSnapshot && nullSnapshot->getSize() > 0);
467 
468  // use as POI the nullSnapshot
469  // if more than one POI exists, consider only the first one
470  RooArgSet poiTest(*nullSnapshot);
471 
472  if (poiTest.getSize() > 1) {
473  oocoutW((TObject*)0,InputArguments) << "AsymptoticCalculator::GetHypoTest: snapshot has more than one POI - assume as POI first parameter " << std::endl;
474  }
475 
476  RooArgSet * allParams = nullPdf->getParameters(*GetData() );
477  *allParams = fBestFitParams;
478  delete allParams;
479 
480  // set the one-side condition
481  // (this works when we have only one params of interest
482  RooRealVar * muHat = dynamic_cast<RooRealVar*> ( fBestFitPoi.first() );
483  assert(muHat && "no best fit parameter defined");
484  RooRealVar * muTest = dynamic_cast<RooRealVar*> ( nullSnapshot->find(muHat->GetName() ) );
485  assert(muTest && "poi snapshot is not existing");
486 
487 
488 
489  if (verbose> 0) {
490  std::cout << std::endl;
491  oocoutI((TObject*)0,Eval) << "AsymptoticCalculator::GetHypoTest: - perform an hypothesis test for POI ( " << muTest->GetName() << " ) = " << muTest->getVal() << std::endl;
492  oocoutP((TObject*)0,Eval) << "AsymptoticCalculator::GetHypoTest - Find best conditional NLL on OBSERVED data set ..... " << std::endl;
493  }
494 
495  // evaluate the conditional NLL on the observed data for the snapshot value
496  double condNLL = EvaluateNLL( *nullPdf, const_cast<RooAbsData&>(*GetData()), GetNullModel()->GetConditionalObservables(), &poiTest);
497 
498  double qmu = 2.*(condNLL - fNLLObs);
499 
500 
501 
502  if (verbose > 0)
503  oocoutP((TObject*)0,Eval) << "\t OBSERVED DATA : qmu = " << qmu << " condNLL = " << condNLL << " uncond " << fNLLObs << std::endl;
504 
505 
506  // this tolerance is used to avoid having negative qmu due to numerical errors
508  if (qmu < -tol || TMath::IsNaN(fNLLObs) ) {
509 
510  if (qmu < 0)
511  oocoutW((TObject*)0,Minimization) << "AsymptoticCalculator: Found a negative value of the qmu - retry to do the unconditional fit "
512  << std::endl;
513  else
514  oocoutW((TObject*)0,Minimization) << "AsymptoticCalculator: unconditional fit failed before - retry to do it now "
515  << std::endl;
516 
517 
518  double nll = EvaluateNLL( *nullPdf, const_cast<RooAbsData&>(*GetData()),GetNullModel()->GetConditionalObservables());
519 
520  if (nll < fNLLObs || (TMath::IsNaN(fNLLObs) && !TMath::IsNaN(nll) ) ) {
521  oocoutW((TObject*)0,Minimization) << "AsymptoticCalculator: Found a better unconditional minimum "
522  << " old NLL = " << fNLLObs << " old muHat " << muHat->getVal() << std::endl;
523 
524  // update values
525  fNLLObs = nll;
526  const RooArgSet * poi = GetNullModel()->GetParametersOfInterest();
527  assert(poi);
529  poi->snapshot(fBestFitPoi);
530  // restore also muHad since previous pointr has been deleted
531  muHat = dynamic_cast<RooRealVar*> ( fBestFitPoi.first() );
532  assert(muHat);
533 
534  oocoutW((TObject*)0,Minimization) << "AsymptoticCalculator: New minimum found for "
535  << " NLL = " << fNLLObs << " muHat " << muHat->getVal() << std::endl;
536 
537 
538  qmu = 2.*(condNLL - fNLLObs);
539 
540  if (verbose > 0)
541  oocoutP((TObject*)0,Eval) << "After unconditional refit, new qmu value is " << qmu << std::endl;
542 
543  }
544  }
545 
546  if (qmu < -tol ) {
547  oocoutE((TObject*)0,Minimization) << "AsymptoticCalculator: qmu is still < 0 for mu = "
548  << muTest->getVal() << " return a dummy result "
549  << std::endl;
550  return new HypoTestResult();
551  }
552  if (TMath::IsNaN(qmu) ) {
553  oocoutE((TObject*)0,Minimization) << "AsymptoticCalculator: failure in fitting for qmu or qmuA "
554  << muTest->getVal() << " return a dummy result "
555  << std::endl;
556  return new HypoTestResult();
557  }
558 
559 
560 
561 
562 
563  // compute conditional ML on Asimov data set
564  // (need to const cast because it uses fitTo which is a non const method
565  // RooArgSet asimovGlobObs;
566  // RooAbsData * asimovData = (const_cast<AsymptoticCalculator*>(this))->MakeAsimovData( poi, asimovGlobObs);
567  // set global observables to their Asimov values
568  RooArgSet globObs;
569  RooArgSet globObsSnapshot;
570  if (GetNullModel()->GetGlobalObservables() ) {
571  globObs.add(*GetNullModel()->GetGlobalObservables());
572  // store previous snapshot value
573  globObs.snapshot(globObsSnapshot);
574  globObs = fAsimovGlobObs;
575  }
576 
577 
578  if (verbose > 0) oocoutP((TObject*)0,Eval) << "AsymptoticCalculator::GetHypoTest -- Find best conditional NLL on ASIMOV data set .... " << std::endl;
579 
580  double condNLL_A = EvaluateNLL( *nullPdf, *fAsimovData, GetNullModel()->GetConditionalObservables(), &poiTest);
581 
582 
583  double qmu_A = 2.*(condNLL_A - fNLLAsimov );
584 
585  if (verbose > 0)
586  oocoutP((TObject*)0,Eval) << "\t ASIMOV data qmu_A = " << qmu_A << " condNLL = " << condNLL_A << " uncond " << fNLLAsimov << std::endl;
587 
588  if (qmu_A < -tol || TMath::IsNaN(fNLLAsimov) ) {
589 
590  if (qmu_A < 0)
591  oocoutW((TObject*)0,Minimization) << "AsymptoticCalculator: Found a negative value of the qmu Asimov- retry to do the unconditional fit "
592  << std::endl;
593  else
594  oocoutW((TObject*)0,Minimization) << "AsymptoticCalculator: Fit failed for unconditional the qmu Asimov- retry unconditional fit "
595  << std::endl;
596 
597 
598  double nll = EvaluateNLL( *nullPdf, *fAsimovData, GetNullModel()->GetConditionalObservables() );
599 
600  if (nll < fNLLAsimov || (TMath::IsNaN(fNLLAsimov) && !TMath::IsNaN(nll) )) {
601  oocoutW((TObject*)0,Minimization) << "AsymptoticCalculator: Found a better unconditional minimum for Asimov data set"
602  << " old NLL = " << fNLLAsimov << std::endl;
603 
604  // update values
605  fNLLAsimov = nll;
606 
607  oocoutW((TObject*)0,Minimization) << "AsymptoticCalculator: New minimum found for "
608  << " NLL = " << fNLLAsimov << std::endl;
609  qmu_A = 2.*(condNLL_A - fNLLAsimov);
610 
611  if (verbose > 0)
612  oocoutP((TObject*)0,Eval) << "After unconditional Asimov refit, new qmu_A value is " << qmu_A << std::endl;
613 
614  }
615  }
616 
617  if (qmu_A < - tol) {
618  oocoutE((TObject*)0,Minimization) << "AsymptoticCalculator: qmu_A is still < 0 for mu = "
619  << muTest->getVal() << " return a dummy result "
620  << std::endl;
621  return new HypoTestResult();
622  }
623  if (TMath::IsNaN(qmu) ) {
624  oocoutE((TObject*)0,Minimization) << "AsymptoticCalculator: failure in fitting for qmu or qmuA "
625  << muTest->getVal() << " return a dummy result "
626  << std::endl;
627  return new HypoTestResult();
628  }
629 
630 
631  // restore previous value of global observables
632  globObs = globObsSnapshot;
633 
634  // now we compute p-values using the asumptotic formulae
635  // described in the paper
636  // Cowan et al, Eur.Phys.J. C (2011) 71:1554
637 
638  // first try to guess autoatically if needed to use qtilde (or ttilde in case of two sided)
639  // if explicitly fUseQTilde this was not set
640  // qtilde is in this case used if poi is bounded at the value of the alt hypothesis
641  // for Qtilde (need to distinguish case when qmu > qmuA = mu^2/ sigma^2)
642  // (see Cowan et al, Eur.Phys.J. C(2011) 71:1554 paper equations 64 and 65
643  // (remember qmu_A = mu^2/sigma^2 )
644  bool useQTilde = false;
645  // default case (check if poi is limited or not to a zero value)
646  if (!fOneSidedDiscovery) { // qtilde is not a discovery test
647  if (fUseQTilde == -1 && !fOneSidedDiscovery) {
648  // alternate snapshot is value for which background is zero (for limits)
649  RooRealVar * muAlt = dynamic_cast<RooRealVar*>( GetAlternateModel()->GetSnapshot()->first() );
650  // null snapshot is value for which background is zero (for discovery)
651  //RooRealVar * muNull = dynamic_cast<RooRealVar*>( GetNullModel()->GetSnapshot()->first() );
652  assert(muAlt != 0 );
653  if (muTest->getMin() == muAlt->getVal() ) {
654  fUseQTilde = 1;
655  oocoutI((TObject*)0,InputArguments) << "Minimum of POI is " << muTest->getMin() << " corresponds to alt snapshot - using qtilde asymptotic formulae " << std::endl;
656  } else {
657  fUseQTilde = 0;
658  oocoutI((TObject*)0,InputArguments) << "Minimum of POI is " << muTest->getMin() << " is different to alt snapshot " << muAlt->getVal()
659  << " - using standard q asymptotic formulae " << std::endl;
660  }
661  }
662  useQTilde = fUseQTilde;
663  }
664 
665 
666  //check for one side condition (remember this is valid only for one poi)
667  if (fOneSided ) {
668  if ( muHat->getVal() > muTest->getVal() ) {
669  oocoutI((TObject*)0,Eval) << "Using one-sided qmu - setting qmu to zero muHat = " << muHat->getVal()
670  << " muTest = " << muTest->getVal() << std::endl;
671  qmu = 0;
672  }
673  }
674  if (fOneSidedDiscovery ) {
675  if ( muHat->getVal() < muTest->getVal() ) {
676  oocoutI((TObject*)0,Eval) << "Using one-sided discovery qmu - setting qmu to zero muHat = " << muHat->getVal()
677  << " muTest = " << muTest->getVal() << std::endl;
678  qmu = 0;
679  }
680  }
681 
682  // fix for negative qmu values due to numerical errors
683  if (qmu < 0 && qmu > -tol) qmu = 0;
684  if (qmu_A < 0 && qmu_A > -tol) qmu_A = 0;
685 
686  // asymptotic formula for pnull and from paper Eur.Phys.J C 2011 71:1554
687  // we have 4 different cases:
688  // t(mu), t_tilde(mu) for the 2-sided
689  // q(mu) and q_tilde(mu) for the one -sided test statistics
690 
691  double pnull = -1, palt = -1;
692 
693  // asymptotic formula for pnull (for only one POI)
694  // From fact that qmu is a chi2 with ndf=1
695 
696  double sqrtqmu = (qmu > 0) ? std::sqrt(qmu) : 0;
697  double sqrtqmu_A = (qmu_A > 0) ? std::sqrt(qmu_A) : 0;
698 
699 
700  if (fOneSided || fOneSidedDiscovery) {
701  // for one-sided PL (q_mu : equations 56,57)
702  if (verbose>2) {
703  if (fOneSided)
704  oocoutI((TObject*)0,Eval) << "Using one-sided limit asymptotic formula (qmu)" << endl;
705  else
706  oocoutI((TObject*)0,Eval) << "Using one-sided discovery asymptotic formula (q0)" << endl;
707  }
708  pnull = ROOT::Math::normal_cdf_c( sqrtqmu, 1.);
709  palt = ROOT::Math::normal_cdf( sqrtqmu_A - sqrtqmu, 1.);
710  }
711  else {
712  // for 2-sided PL (t_mu : equations 35,36 in asymptotic paper)
713  if (verbose > 2) oocoutI((TObject*)0,Eval) << "Using two-sided asimptotic formula (tmu)" << endl;
714  pnull = 2.*ROOT::Math::normal_cdf_c( sqrtqmu, 1.);
715  palt = ROOT::Math::normal_cdf_c( sqrtqmu + sqrtqmu_A, 1.) +
716  ROOT::Math::normal_cdf_c( sqrtqmu - sqrtqmu_A, 1.);
717 
718  }
719 
720  if (useQTilde ) {
721  if (fOneSided) {
722  // for bounded one-sided (q_mu_tilde: equations 64,65)
723  if ( qmu > qmu_A && (qmu_A > 0 || qmu > tol) ) { // to avoid case 0/0
724  if (verbose > 2) oocoutI((TObject*)0,Eval) << "Using qmu_tilde (qmu is greater than qmu_A)" << endl;
725  pnull = ROOT::Math::normal_cdf_c( (qmu + qmu_A)/(2 * sqrtqmu_A), 1.);
726  palt = ROOT::Math::normal_cdf_c( (qmu - qmu_A)/(2 * sqrtqmu_A), 1.);
727  }
728  }
729  else {
730  // for 2 sided bounded test statistic (N.B there is no one sided discovery qtilde)
731  // t_mu_tilde: equations 43,44 in asymptotic paper
732  if ( qmu > qmu_A && (qmu_A > 0 || qmu > tol) ) {
733  if (verbose > 2) oocoutI((TObject*)0,Eval) << "Using tmu_tilde (qmu is greater than qmu_A)" << endl;
734  pnull = ROOT::Math::normal_cdf_c(sqrtqmu,1.) +
735  ROOT::Math::normal_cdf_c( (qmu + qmu_A)/(2 * sqrtqmu_A), 1.);
736  palt = ROOT::Math::normal_cdf_c( sqrtqmu_A + sqrtqmu, 1.) +
737  ROOT::Math::normal_cdf_c( (qmu - qmu_A)/(2 * sqrtqmu_A), 1.);
738  }
739  }
740  }
741 
742 
743 
744  // create an HypoTest result but where the sampling distributions are set to zero
745  string resultname = "HypoTestAsymptotic_result";
746  HypoTestResult* res = new HypoTestResult(resultname.c_str(), pnull, palt);
747 
748  if (verbose > 0)
749  //std::cout
750  oocoutP((TObject*)0,Eval)
751  << "poi = " << muTest->getVal() << " qmu = " << qmu << " qmu_A = " << qmu_A
752  << " sigma = " << muTest->getVal()/sqrtqmu_A
753  << " CLsplusb = " << pnull << " CLb = " << palt << " CLs = " << res->CLs() << std::endl;
754 
755  return res;
756 
757 }
758 
759 struct PaltFunction {
760  PaltFunction( double offset, double pval, int icase) :
761  fOffset(offset), fPval(pval), fCase(icase) {}
762  double operator() (double x) const {
763  return ROOT::Math::normal_cdf_c(x + fOffset) + ROOT::Math::normal_cdf_c(fCase*(x - fOffset)) - fPval;
764  }
765  double fOffset;
766  double fPval;
767  int fCase;
768 };
769 
770 double AsymptoticCalculator::GetExpectedPValues(double pnull, double palt, double nsigma, bool useCls, bool oneSided ) {
771  // function given the null and the alt p value - return the expected one given the N - sigma value
772  if (oneSided) {
773  double sqrtqmu = ROOT::Math::normal_quantile_c( pnull,1.);
774  double sqrtqmu_A = ROOT::Math::normal_quantile( palt,1.) + sqrtqmu;
775  double clsplusb = ROOT::Math::normal_cdf_c( sqrtqmu_A - nsigma, 1.);
776  if (!useCls) return clsplusb;
777  double clb = ROOT::Math::normal_cdf( nsigma, 1.);
778  return (clb == 0) ? -1 : clsplusb / clb;
779  }
780 
781  // case of 2 sided test statistic
782  // need to compute numerically
783  double sqrttmu = ROOT::Math::normal_quantile_c( 0.5*pnull,1.);
784  if (sqrttmu == 0) {
785  // here cannot invert the function - skip the point
786  return -1;
787  }
788  // invert formula for palt to get sqrttmu_A
789  PaltFunction f( sqrttmu, palt, -1);
792  brf.SetFunction( wf, 0, 20);
793  bool ret = brf.Solve();
794  if (!ret) {
795  oocoutE((TObject*)0,Eval) << "Error finding expected p-values - return -1" << std::endl;
796  return -1;
797  }
798  double sqrttmu_A = brf.Root();
799 
800  // now invert for expected value
801  PaltFunction f2( sqrttmu_A, ROOT::Math::normal_cdf( nsigma, 1.), 1);
803  brf.SetFunction(wf2,0,20);
804  ret = brf.Solve();
805  if (!ret) {
806  oocoutE((TObject*)0,Eval) << "Error finding expected p-values - return -1" << std::endl;
807  return -1;
808  }
809  return 2*ROOT::Math::normal_cdf_c( brf.Root(),1.);
810 }
811 
812 // void GetExpectedLimit(double nsigma, double alpha, double &clsblimit, double &clslimit) {
813 // // get expected limit
814 // double
815 // }
816 
817 
818 void AsymptoticCalculator::FillBins(const RooAbsPdf & pdf, const RooArgList &obs, RooAbsData & data, int &index, double &binVolume, int &ibin) {
819  /// fill bins by looping recursivly on observables
820 
821  bool debug = (fgPrintLevel >= 2);
822 
823  RooRealVar * v = dynamic_cast<RooRealVar*>( &(obs[index]) );
824  if (!v) return;
825 
826  RooArgSet obstmp(obs);
827  double expectedEvents = pdf.expectedEvents(obstmp);
828  // if (debug) {
829  // std::cout << "expected events = " << expectedEvents << std::endl;
830  // }
831 
832  if (debug) cout << "looping on observable " << v->GetName() << endl;
833  for (int i = 0; i < v->getBins(); ++i) {
834  v->setBin(i);
835  if (index < obs.getSize() -1) {
836  index++; // increase index
837  double prevBinVolume = binVolume;
838  binVolume *= v->getBinWidth(i); // increase bin volume
839  FillBins(pdf, obs, data, index, binVolume, ibin);
840  index--; // decrease index
841  binVolume = prevBinVolume; // decrease also bin volume
842  }
843  else {
844 
845  // this is now a new bin - compute the pdf in this bin
846  double totBinVolume = binVolume * v->getBinWidth(i);
847  double fval = pdf.getVal(&obstmp)*totBinVolume;
848 
849  //if (debug) std::cout << "pdf value in the bin " << fval << " bin volume = " << totBinVolume << " " << fval*expectedEvents << std::endl;
850  if (fval*expectedEvents <= 0)
851  {
852  if (fval*expectedEvents < 0)
853  cout << "WARNING::Detected a bin with negative expected events! Please check your inputs." << endl;
854  else
855  cout << "WARNING::Detected a bin with zero expected events- skip it" << endl;
856  }
857  // have a cut off for overflows ??
858  else
859  data.add(obs, fval*expectedEvents);
860 
861  if (debug) {
862  cout << "bin " << ibin << "\t";
863  for (int j=0; j < obs.getSize(); ++j) { cout << " " << ((RooRealVar&) obs[j]).getVal(); }
864  cout << " w = " << fval*expectedEvents;
865  cout << endl;
866  }
867  // RooArgSet xxx(obs);
868  // h3->Fill(((RooRealVar&) obs[0]).getVal(), ((RooRealVar&) obs[1]).getVal(), ((RooRealVar&) obs[2]).getVal() ,
869  // pdf->getVal(&xxx) );
870  ibin++;
871  }
872  }
873  //reset bin values
874  if (debug)
875  cout << "ending loop on .. " << v->GetName() << endl;
876 
877  v->setBin(0);
878 
879 }
880 
881 
883 {
884  // iterate a Prod pdf to find all the Poisson or Gaussian part to set the observed value to expected one
886  bool ret = false;
887  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
888  if (!a->dependsOn(obs)) continue;
889  RooPoisson *pois = 0;
890  RooGaussian * gaus = 0;
891  if ((pois = dynamic_cast<RooPoisson *>(a)) != 0) {
892  SetObsToExpected(*pois, obs);
893  pois->setNoRounding(true); //needed since expecteed value is not an integer
894  } else if ((gaus = dynamic_cast<RooGaussian *>(a)) != 0) {
895  SetObsToExpected(*gaus, obs);
896  } else {
897  // should try to add also lognormal case ?
898  RooProdPdf *subprod = dynamic_cast<RooProdPdf *>(a);
899  if (subprod)
900  return SetObsToExpected(*subprod, obs);
901  else {
902  oocoutE((TObject*)0,InputArguments) << "Illegal term in counting model: depends on observables, but not Poisson or Gaussian or Product"
903  << endl;
904  return false;
905  }
906  }
907  ret = (pois != 0 || gaus != 0 );
908  }
909  return ret;
910 }
911 
913 {
914  // set observed value to the expected one
915  // works for Gaussian, Poisson or LogNormal
916  // assumes mean parameter value is the argument not constant and not depoending on observables
917  // (if more than two arguments are not constant will use first one but printr a warning !)
918  // need to iterate on the components of the POisson to get n and nu (nu can be a RooAbsReal)
919  // (code from G. Petrucciani and extended by L.M.)
920  RooRealVar *myobs = 0;
921  RooAbsReal *myexp = 0;
922  const char * pdfName = pdf.IsA()->GetName();
924  for (RooAbsArg *a = iter.next(); a != 0; a = iter.next()) {
925  if (obs.contains(*a)) {
926  if (myobs != 0) {
927  oocoutF((TObject*)0,Generation) << "AsymptoticCalculator::SetObsExpected( " << pdfName << " ) : Has two observables ?? " << endl;
928  return false;
929  }
930  myobs = dynamic_cast<RooRealVar *>(a);
931  if (myobs == 0) {
932  oocoutF((TObject*)0,Generation) << "AsymptoticCalculator::SetObsExpected( " << pdfName << " ) : Observable is not a RooRealVar??" << endl;
933  return false;
934  }
935  } else {
936  if (!a->isConstant() ) {
937  if (myexp != 0) {
938  oocoutE((TObject*)0,Generation) << "AsymptoticCalculator::SetObsExpected( " << pdfName << " ) : Has two non-const arguments " << endl;
939  return false;
940  }
941  myexp = dynamic_cast<RooAbsReal *>(a);
942  if (myexp == 0) {
943  oocoutF((TObject*)0,Generation) << "AsymptoticCalculator::SetObsExpected( " << pdfName << " ) : Expected is not a RooAbsReal??" << endl;
944  return false;
945  }
946  }
947  }
948  }
949  if (myobs == 0) {
950  oocoutF((TObject*)0,Generation) << "AsymptoticCalculator::SetObsExpected( " << pdfName << " ) : No observable?" << endl;
951  return false;
952  }
953  if (myexp == 0) {
954  oocoutF((TObject*)0,Generation) << "AsymptoticCalculator::SetObsExpected( " << pdfName << " ) : No observable?" << endl;
955  return false;
956  }
957 
958  myobs->setVal(myexp->getVal());
959 
960  if (fgPrintLevel > 2) {
961  std::cout << "SetObsToExpected : setting " << myobs->GetName() << " to expected value " << myexp->getVal() << " of " << myexp->GetName() << std::endl;
962  }
963 
964  return true;
965 }
966 
967 
969  // generate counting Asimov data for the case when the pdf cannot be extended
970  // assume pdf is a RooPoisson or can be decomposed in a product of RooPoisson,
971  // otherwise we cannot know how to make the Asimov data sets in the other cases
972  RooArgSet obs(observables);
973  RooProdPdf *prod = dynamic_cast<RooProdPdf *>(&pdf);
974  RooPoisson *pois = 0;
975  RooGaussian *gaus = 0;
976 
977  if (fgPrintLevel > 1)
978  std::cout << "generate counting Asimov data for pdf of type " << pdf.IsA()->GetName() << std::endl;
979 
980  bool r = false;
981  if (prod != 0) {
982  r = SetObsToExpected(*prod, observables);
983  } else if ((pois = dynamic_cast<RooPoisson *>(&pdf)) != 0) {
984  r = SetObsToExpected(*pois, observables);
985  // we need in this case to set Poisson to real values
986  pois->setNoRounding(true);
987  } else if ((gaus = dynamic_cast<RooGaussian *>(&pdf)) != 0) {
988  r = SetObsToExpected(*gaus, observables);
989  } else {
990  oocoutE((TObject*)0,InputArguments) << "A counting model pdf must be either a RooProdPdf or a RooPoisson or a RooGaussian" << endl;
991  }
992  if (!r) return 0;
993  int icat = 0;
994  if (channelCat) {
995  icat = channelCat->getIndex();
996  }
997 
998  RooDataSet *ret = new RooDataSet(TString::Format("CountingAsimovData%d",icat),TString::Format("CountingAsimovData%d",icat), obs);
999  ret->add(obs);
1000  return ret;
1001 }
1002 
1003 RooAbsData * AsymptoticCalculator::GenerateAsimovDataSinglePdf(const RooAbsPdf & pdf, const RooArgSet & allobs, const RooRealVar & weightVar, RooCategory * channelCat) {
1004  // compute the asimov data set for an observable of a pdf
1005  // use the number of bins sets in the observables
1006  // to do : (possibility to change number of bins)
1007  // implement integration over bin content
1008 
1009  int printLevel = fgPrintLevel;
1010 
1011  // Get observables defined by the pdf associated with this state
1012  std::unique_ptr<RooArgSet> obs(pdf.getObservables(allobs) );
1013 
1014 
1015  // if pdf cannot be extended assume is then a counting experiment
1016  if (!pdf.canBeExtended() ) return GenerateCountingAsimovData(const_cast<RooAbsPdf&>(pdf), *obs, weightVar, channelCat);
1017 
1018  RooArgSet obsAndWeight(*obs);
1019  obsAndWeight.add(weightVar);
1020 
1021  RooDataSet* asimovData = 0;
1022  if (channelCat) {
1023  int icat = channelCat->getIndex();
1024  asimovData = new RooDataSet(TString::Format("AsimovData%d",icat),TString::Format("combAsimovData%d",icat),
1025  RooArgSet(obsAndWeight,*channelCat),RooFit::WeightVar(weightVar));
1026  }
1027  else
1028  asimovData = new RooDataSet("AsimovData","AsimovData",RooArgSet(obsAndWeight),RooFit::WeightVar(weightVar));
1029 
1030  // This works ony for 1D observables
1031  //RooRealVar* thisObs = ((RooRealVar*)obstmp->first());
1032 
1033  RooArgList obsList(*obs);
1034 
1035  // loop on observables and on the bins
1036  if (printLevel >= 2) {
1037  cout << "Generating Asimov data for pdf " << pdf.GetName() << endl;
1038  cout << "list of observables " << endl;
1039  obsList.Print();
1040  }
1041 
1042  int obsIndex = 0;
1043  double binVolume = 1;
1044  int nbins = 0;
1045  FillBins(pdf, obsList, *asimovData, obsIndex, binVolume, nbins);
1046  if (printLevel >= 2)
1047  cout << "filled from " << pdf.GetName() << " " << nbins << " nbins " << " volume is " << binVolume << endl;
1048 
1049  // for (int iobs = 0; iobs < obsList.getSize(); ++iobs) {
1050  // RooRealVar * thisObs = dynamic_cast<RooRealVar*> &obsList[i];
1051  // if (thisObs == 0) continue;
1052  // // loop on the bin contents
1053  // for(int ibin=0; ibin<thisObs->numBins(); ++ibin){
1054  // thisObs->setBin(ibin);
1055 
1056  // thisNorm=pdftmp->getVal(obstmp)*thisObs->getBinWidth(jj);
1057  // if (thisNorm*expectedEvents <= 0)
1058  // {
1059  // cout << "WARNING::Detected bin with zero expected events! Please check your inputs." << endl;
1060  // }
1061  // // have a cut off for overflows ??
1062  // obsDataUnbinned->add(*mc->GetObservables(), thisNorm*expectedEvents);
1063  // }
1064 
1065  if (printLevel >= 1)
1066  {
1067  asimovData->Print();
1068  //cout <<"sum entries "<< asimovData->sumEntries()<<endl;
1069  }
1070  if( TMath::IsNaN(asimovData->sumEntries()) ){
1071  cout << "sum entries is nan"<<endl;
1072  assert(0);
1073  delete asimovData;
1074  asimovData = 0;
1075  }
1076 
1077  return asimovData;
1078 
1079 }
1080 
1082  // generate the asimov data for the observables (not the global ones)
1083  // need to deal with the case of a sim pdf
1084 
1085  int printLevel = fgPrintLevel;
1086 
1087  RooRealVar * weightVar = new RooRealVar("binWeightAsimov", "binWeightAsimov", 1, 0, 1.E30 );
1088 
1089  if (printLevel > 1) cout <<" Generate Asimov data for observables"<<endl;
1090  //RooDataSet* simData=NULL;
1091  const RooSimultaneous* simPdf = dynamic_cast<const RooSimultaneous*>(&pdf);
1092  if (!simPdf) {
1093  // generate data for non sim pdf
1094  return GenerateAsimovDataSinglePdf( pdf, observables, *weightVar, 0);
1095  }
1096 
1097  std::map<std::string, RooDataSet*> asimovDataMap;
1098 
1099  //look at category of simpdf
1100  RooCategory& channelCat = (RooCategory&)simPdf->indexCat();
1101  int nrIndices = channelCat.numTypes();
1102  if( nrIndices == 0 ) {
1103  oocoutW((TObject*)0,Generation) << "Simultaneous pdf does not contain any categories." << endl;
1104  }
1105  for (int i=0;i<nrIndices;i++){
1106  channelCat.setIndex(i);
1107  //iFrame++;
1108  // Get pdf associated with state from simpdf
1109  RooAbsPdf* pdftmp = simPdf->getPdf(channelCat.getLabel()) ;
1110  assert(pdftmp != 0);
1111 
1112  if (printLevel > 1)
1113  {
1114  cout << "on type " << channelCat.getLabel() << " " << channelCat.getIndex() << endl;
1115  }
1116 
1117  RooAbsData * dataSinglePdf = GenerateAsimovDataSinglePdf( *pdftmp, observables, *weightVar, &channelCat);
1118  //((RooRealVar*)obstmp->first())->Print();
1119  //cout << "expected events " << pdftmp->expectedEvents(*obstmp) << endl;
1120  if (!dataSinglePdf) {
1121  oocoutE((TObject*)0,Generation) << "Error generating an Asimov data set for pdf " << pdftmp->GetName() << endl;
1122  return 0;
1123  }
1124 
1125 
1126  asimovDataMap[string(channelCat.getLabel())] = (RooDataSet*) dataSinglePdf;
1127 
1128  if (printLevel > 1)
1129  {
1130  cout << "channel: " << channelCat.getLabel() << ", data: ";
1131  dataSinglePdf->Print();
1132  cout << endl;
1133  }
1134  }
1135 
1136  RooArgSet obsAndWeight(observables);
1137  obsAndWeight.add(*weightVar);
1138 
1139 
1140  RooDataSet* asimovData = new RooDataSet("asimovDataFullModel","asimovDataFullModel",RooArgSet(obsAndWeight,channelCat),
1141  RooFit::Index(channelCat),RooFit::Import(asimovDataMap),RooFit::WeightVar(*weightVar));
1142 
1143  delete weightVar;
1144  return asimovData;
1145 
1146 }
1147 
1148 ////////////////////////////////////////////////////////////////////////////////
1149 /// static function to the an Asimov data set
1150 /// given an observed dat set, a model and a snapshot of poi.
1151 /// Return the asimov data set + global observables set to values satisfying the constraints
1152 
1153 RooAbsData * AsymptoticCalculator::MakeAsimovData(RooAbsData & realData, const ModelConfig & model, const RooArgSet & paramValues, RooArgSet & asimovGlobObs, const RooArgSet * genPoiValues ) {
1154 
1155  int verbose = fgPrintLevel;
1156 
1157 
1158  RooArgSet poi(*model.GetParametersOfInterest());
1159  poi = paramValues;
1160  //RooRealVar *r = dynamic_cast<RooRealVar *>(poi.first());
1161  // set poi constant for conditional MLE
1162  // need to fit nuisance parameters at their conditional MLE value
1163  RooLinkedListIter it = poi.iterator();
1164  RooRealVar* tmpPar = NULL;
1165  RooArgSet paramsSetConstant;
1166  while((tmpPar = (RooRealVar*)it.Next())){
1167  tmpPar->setConstant();
1168  if (verbose>0)
1169  std::cout << "MakeAsimov: Setting poi " << tmpPar->GetName() << " to a constant value = " << tmpPar->getVal() << std::endl;
1170  paramsSetConstant.add(*tmpPar);
1171  }
1172 
1173  // find conditional value of the nuisance parameters
1174  bool hasFloatParams = false;
1175  RooArgSet constrainParams;
1176  if (model.GetNuisanceParameters()) {
1177  constrainParams.add(*model.GetNuisanceParameters());
1178  RooStats::RemoveConstantParameters(&constrainParams);
1179  if (constrainParams.getSize() > 0) hasFloatParams = true;
1180 
1181  } else {
1182  // Do we have free parameters anyway that need fitting?
1183  std::unique_ptr<RooArgSet> params(model.GetPdf()->getParameters(realData));
1184  RooLinkedListIter iter(params->iterator());
1185  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
1186  RooRealVar *rrv = dynamic_cast<RooRealVar *>(a);
1187  if ( rrv != 0 && rrv->isConstant() == false ) { hasFloatParams = true; break; }
1188  }
1189  }
1190  if (hasFloatParams) {
1191  // models need to be fitted to find best nuisance parameter values
1192 
1193  TStopwatch tw2; tw2.Start();
1194  int minimPrintLevel = ROOT::Math::MinimizerOptions::DefaultPrintLevel();
1195  if (verbose>0) {
1196  std::cout << "MakeAsimov: doing a conditional fit for finding best nuisance values " << std::endl;
1197  minimPrintLevel = verbose;
1198  if (verbose>1) {
1199  std::cout << "POI values:\n"; poi.Print("v");
1200  if (verbose > 2) {
1201  std::cout << "Nuis param values:\n";
1202  constrainParams.Print("v");
1203  }
1204  }
1205  }
1208 
1209  RooArgSet conditionalObs;
1210  if (model.GetConditionalObservables()) conditionalObs.add(*model.GetConditionalObservables());
1211 
1212  std::string minimizerType = ROOT::Math::MinimizerOptions::DefaultMinimizerType();
1213  std::string minimizerAlgo = ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo();
1214  model.GetPdf()->fitTo(realData, RooFit::Minimizer(minimizerType.c_str(),minimizerAlgo.c_str()),
1216  RooFit::PrintLevel(minimPrintLevel-1), RooFit::Hesse(false),
1218  if (verbose>0) { std::cout << "fit time "; tw2.Print();}
1219  if (verbose > 1) {
1220  // after the fit the nuisance parameters will have their best fit value
1221  if (model.GetNuisanceParameters() ) {
1222  std::cout << "Nuisance parameters after fit for asimov dataset: " << std::endl;
1223  model.GetNuisanceParameters()->Print("V");
1224  }
1225  }
1226 
1227  if (verbose < 2) RooMsgService::instance().setGlobalKillBelow(msglevel);
1228 
1229  }
1230 
1231  // restore the parameters which were set constant
1232  SetAllConstant(paramsSetConstant, false);
1233 
1234 
1235  RooArgSet * allParams = model.GetPdf()->getParameters(realData);
1237 
1238  // if a RooArgSet of poi is passed , different poi will be used for generating the Asimov data set
1239  if (genPoiValues) *allParams = *genPoiValues;
1240 
1241  // now do the actual generation of the AsimovData Set
1242  // no need to pass parameters values since we have set them before
1243  RooAbsData * asimovData = MakeAsimovData(model, *allParams, asimovGlobObs);
1244 
1245  delete allParams;
1246 
1247  return asimovData;
1248 
1249 }
1250 
1251 ////////////////////////////////////////////////////////////////////////////////
1252 /// static function to the an Asimov data set
1253 /// given the model and the values of all parameters including the nuisance
1254 /// Return the asimov data set + global observables set to values satisfying the constraints
1255 
1256 RooAbsData * AsymptoticCalculator::MakeAsimovData(const ModelConfig & model, const RooArgSet & allParamValues, RooArgSet & asimovGlobObs) {
1257 
1258  int verbose = fgPrintLevel;
1259 
1260  TStopwatch tw;
1261  tw.Start();
1262 
1263  // set the parameter values (do I need the poi to be constant ? )
1264  // the nuisance parameter values could be set at their fitted value (the MLE)
1265  if (allParamValues.getSize() > 0) {
1266  RooArgSet * allVars = model.GetPdf()->getVariables();
1267  *allVars = allParamValues;
1268  delete allVars;
1269  }
1270 
1271 
1272  // generate the Asimov data set for the observables
1273  RooAbsData * asimov = GenerateAsimovData(*model.GetPdf() , *model.GetObservables() );
1274 
1275  if (verbose>0) {
1276  std::cout << "Generated Asimov data for observables "; (model.GetObservables() )->Print();
1277  if (verbose > 1) {
1278  if (asimov->numEntries() == 1 ) {
1279  std::cout << "--- Asimov data values \n";
1280  asimov->get()->Print("v");
1281  }
1282  else {
1283  std::cout << "--- Asimov data numEntries = " << asimov->numEntries() << " sumOfEntries = " << asimov->sumEntries() << std::endl;
1284  }
1285  std::cout << "\ttime for generating : "; tw.Print();
1286  }
1287  }
1288 
1289 
1290  // Now need to have in ASIMOV the data sets also the global observables
1291  // Their values must be the one satisfying the constraint.
1292  // to do it make a nuisance pdf with all product of constraints and then
1293  // assign to each constraint a glob observable value = to the current fitted nuisance parameter value
1294  // IN general one should solve in general the system of equations f( gobs| nuispar ) = 0 where f are the
1295  // derivatives of the constraint with respect the nuisance parameter and they are evaluated at the best fit nuisance
1296  // parameter points
1297  // As simple solution assume that constrain has a direct dependence on the nuisance parameter, i.e.
1298  // Constraint (gobs, func( nuispar) ) and the condifion is satisfied for
1299  // gobs = func( nuispar) where nunispar is at the MLE value
1300 
1301 
1302  if (model.GetGlobalObservables() && model.GetGlobalObservables()->getSize() > 0) {
1303 
1304  if (verbose>1) {
1305  std::cout << "Generating Asimov data for global observables " << std::endl;
1306  }
1307 
1308  RooArgSet gobs(*model.GetGlobalObservables());
1309 
1310  // snapshot data global observables
1311  RooArgSet snapGlobalObsData;
1312  SetAllConstant(gobs, true);
1313  gobs.snapshot(snapGlobalObsData);
1314 
1315 
1316  RooArgSet nuis;
1317  if (model.GetNuisanceParameters()) nuis.add(*model.GetNuisanceParameters());
1318  if (nuis.getSize() == 0) {
1319  oocoutW((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData: model does not have nuisance parameters but has global observables"
1320  << " set global observales to model values " << endl;
1321  asimovGlobObs = gobs;
1322  return asimov;
1323  }
1324 
1325  // part 1: create the nuisance pdf
1326  std::unique_ptr<RooAbsPdf> nuispdf(RooStats::MakeNuisancePdf(model,"TempNuisPdf") );
1327  if (nuispdf.get() == 0) {
1328  oocoutF((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData: model has nuisance parameters and global obs but no nuisance pdf "
1329  << std::endl;
1330  }
1331  // unfold the nuisance pdf if it is a prod pdf
1332  RooArgList pdfList;
1333  RooProdPdf *prod = dynamic_cast<RooProdPdf *>(nuispdf.get());
1334  if (prod ) {
1335  pdfList.add(prod->pdfList());
1336  }
1337  else
1338  // nothing to unfold - just use the pdf
1339  pdfList.add(*nuispdf.get());
1340 
1341  RooLinkedListIter iter(pdfList.iterator());
1342  for (RooAbsArg *a = (RooAbsArg *) iter.Next(); a != 0; a = (RooAbsArg *) iter.Next()) {
1343  RooAbsPdf *cterm = dynamic_cast<RooAbsPdf *>(a);
1344  assert(cterm && "AsimovUtils: a factor of the nuisance pdf is not a Pdf!");
1345  if (!cterm->dependsOn(nuis)) continue; // dummy constraints
1346  // skip also the case of uniform components
1347  if (typeid(*cterm) == typeid(RooUniform)) continue;
1348 
1349  std::unique_ptr<RooArgSet> cpars(cterm->getParameters(&gobs));
1350  std::unique_ptr<RooArgSet> cgobs(cterm->getObservables(&gobs));
1351  if (cgobs->getSize() > 1) {
1352  oocoutE((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData: constraint term " << cterm->GetName()
1353  << " has multiple global observables -cannot generate - skip it" << std::endl;
1354  continue;
1355  }
1356  else if (cgobs->getSize() == 0) {
1357  oocoutW((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData: constraint term " << cterm->GetName()
1358  << " has no global observables - skip it" << std::endl;
1359  continue;
1360  }
1361  // the variable representing the global observable
1362  RooRealVar &rrv = dynamic_cast<RooRealVar &>(*cgobs->first());
1363 
1364  // remove the constant parameters in cpars
1366  if (cpars->getSize() != 1) {
1367  oocoutE((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData:constraint term "
1368  << cterm->GetName() << " has multiple floating params - cannot generate - skip it " << std::endl;
1369  continue;
1370  }
1371 
1372  bool foundServer = false;
1373  // note : this will work only for this type of constraints
1374  // expressed as RooPoisson, RooGaussian, RooLognormal, RooGamma
1375  TClass * cClass = cterm->IsA();
1376  if (verbose > 2) std::cout << "Constraint " << cterm->GetName() << " of type " << cClass->GetName() << std::endl;
1377  if ( cClass != RooGaussian::Class() && cClass != RooPoisson::Class() &&
1378  cClass != RooGamma::Class() && cClass != RooLognormal::Class() &&
1379  cClass != RooBifurGauss::Class() ) {
1380  TString className = (cClass) ? cClass->GetName() : "undefined";
1381  oocoutW((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData:constraint term "
1382  << cterm->GetName() << " of type " << className
1383  << " is a non-supported type - result might be not correct " << std::endl;
1384  }
1385 
1386  // in case of a Poisson constraint make sure the rounding is not set
1387  if (cClass == RooPoisson::Class() ) {
1388  RooPoisson * pois = dynamic_cast<RooPoisson*>(cterm);
1389  assert(pois);
1390  pois->setNoRounding(true);
1391  }
1392 
1393  // look at server of the constraint term and check if the global observable is part of the server
1394  RooAbsArg * arg = cterm->findServer(rrv);
1395  if (!arg) {
1396  // special case is for the Gamma where one might define the global observable n and you have a Gamma(b, n+1, ...._
1397  // in this case n+1 is the server and we don;t have a direct dependency, but we want to set n to the b value
1398  // so in case of the Gamma ignore this test
1399  if ( cClass != RooGamma::Class() ) {
1400  oocoutE((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData:constraint term "
1401  << cterm->GetName() << " has no direct dependence on global observable- cannot generate it " << std::endl;
1402  continue;
1403  }
1404  }
1405 
1406  // loop on the server of the constraint term
1407  // neeed to treat the Gamma as a special case
1408  // the mode of the Gamma is (k-1)*theta where theta is the inverse of the rate parameter.
1409  // we assume that the global observable is defined as ngobs = k-1 and the theta parameter has the name theta otherwise we use other procedure which might be wrong
1410  RooAbsReal * thetaGamma = 0;
1411  if ( cClass == RooGamma::Class() ) {
1412  RooFIter itc(cterm->serverMIterator() );
1413  for (RooAbsArg *a2 = itc.next(); a2 != 0; a2 = itc.next()) {
1414  if (TString(a2->GetName()).Contains("theta") ) {
1415  thetaGamma = dynamic_cast<RooAbsReal*>(a2);
1416  break;
1417  }
1418  }
1419  if (thetaGamma == 0) {
1420  oocoutI((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData:constraint term "
1421  << cterm->GetName() << " is a Gamma distribution and no server named theta is found. Assume that the Gamma scale is 1 " << std::endl;
1422  }
1423  else {
1424  if (verbose>2)
1425  std::cout << "Gamma constraint has a scale " << thetaGamma->GetName() << " = " << thetaGamma->getVal() << std::endl;
1426  }
1427  }
1428  RooFIter iter2(cterm->serverMIterator() );
1429  for (RooAbsArg *a2 = iter2.next(); a2 != 0; a2 = iter2.next()) {
1430  RooAbsReal * rrv2 = dynamic_cast<RooAbsReal *>(a2);
1431  if (verbose > 2) std::cout << "Loop on constraint server term " << a2->GetName() << std::endl;
1432  if (rrv2 && rrv2->dependsOn(nuis) ) {
1433 
1434 
1435  // found server depending on nuisance
1436  if (foundServer) {
1437  oocoutE((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData:constraint term "
1438  << cterm->GetName() << " constraint term has more server depending on nuisance- cannot generate it " <<
1439  std::endl;
1440  foundServer = false;
1441  break;
1442  }
1443  if (thetaGamma && thetaGamma->getVal() > 0)
1444  rrv.setVal( rrv2->getVal() / thetaGamma->getVal() );
1445  else
1446  rrv.setVal( rrv2->getVal() );
1447  foundServer = true;
1448 
1449  if (verbose>2)
1450  std::cout << "setting global observable "<< rrv.GetName() << " to value " << rrv.getVal()
1451  << " which comes from " << rrv2->GetName() << std::endl;
1452  }
1453  }
1454 
1455  if (!foundServer) {
1456  oocoutE((TObject*)0,Generation) << "AsymptoticCalculator::MakeAsimovData - can't find nuisance for constraint term - global observales will not be set to Asimov value " << cterm->GetName() << std::endl;
1457  std::cerr << "Parameters: " << std::endl;
1458  cpars->Print("V");
1459  std::cerr << "Observables: " << std::endl;
1460  cgobs->Print("V");
1461  }
1462 // rrv.setVal(match->getVal());
1463  }
1464 
1465  // make a snapshot of global observables
1466  // needed this ?? (LM)
1467 
1468  asimovGlobObs.removeAll();
1469  SetAllConstant(gobs, true);
1470  gobs.snapshot(asimovGlobObs);
1471 
1472  // revert global observables to the data value
1473  gobs = snapGlobalObsData;
1474 
1475  if (verbose>0) {
1476  std::cout << "Generated Asimov data for global observables ";
1477  if (verbose == 1) gobs.Print();
1478  }
1479 
1480  if (verbose > 1) {
1481  std::cout << "\nGlobal observables for data: " << std::endl;
1482  gobs.Print("V");
1483  std::cout << "\nGlobal observables for asimov: " << std::endl;
1484  asimovGlobObs.Print("V");
1485  }
1486 
1487 
1488  }
1489 
1490  return asimov;
1491 
1492 }
1493 
1494 
1495 
1496 
1497 
1498 
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:777
virtual Double_t sumEntries() const =0
double normal_quantile(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the lower tail of the normal (Gaussian) distri...
static RooAbsData * GenerateAsimovData(const RooAbsPdf &pdf, const RooArgSet &observables)
virtual void setBin(Int_t ibin, const char *rangeName=0)
Set value to center of bin 'ibin' of binning 'rangeName' (or of default binning if no range is specif...
bool Initialize() const
initialize the calculator by performin g a global fit and make the Asimov data set ...
RooCmdArg Offset(Bool_t flag=kTRUE)
void Print(Option_t *option="") const
Print the real and cpu time passed between the start and stop events.
Definition: TStopwatch.cxx:217
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
virtual Int_t getIndex() const
Return index number of current state.
Definition: RooCategory.h:35
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
ModelConfig is a simple class that holds configuration information specifying how a model should be u...
Definition: ModelConfig.h:52
RooAbsPdf * GetPdf() const
get model PDF (return NULL if pdf has not been specified or does not exist)
Definition: ModelConfig.h:244
virtual HypoTestResult * GetHypoTest() const
re-implement HypoTest computation using the asymptotic
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:56
bool Solve(int maxIter=100, double absTol=1E-8, double relTol=1E-10)
Returns the X value corresponding to the function value fy for (xmin
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
static double GetExpectedPValues(double pnull, double palt, double nsigma, bool usecls, bool oneSided=true)
function given the null and the alt p value - return the expected one given the N - sigma value ...
RooAbsPdf * MakeNuisancePdf(RooAbsPdf &pdf, const RooArgSet &observables, const char *name)
const RooArgSet * GetConditionalObservables() const
get RooArgSet for conditional observables (return NULL if not existing)
Definition: ModelConfig.h:262
virtual Double_t CLs() const
CLs is simply CLs+b/CLb (not a method, but a quantity)
const RooArgSet * GetGlobalObservables() const
get RooArgSet for global observables (return NULL if not existing)
Definition: ModelConfig.h:265
double normal_quantile_c(double z, double sigma)
Inverse ( ) of the cumulative distribution function of the upper tail of the normal (Gaussian) distri...
RooCmdArg CloneData(Bool_t flag)
Double_t QuietNaN()
Definition: TMath.h:635
RooCmdArg PrintLevel(Int_t code)
virtual Bool_t setIndex(Int_t index, Bool_t printError=kTRUE)
Set value by specifying the index code of the desired state.
#define oocoutF(o, a)
Definition: RooMsgService.h:49
#define assert(cond)
Definition: unittest.h:542
RooArgSet * getObservables(const RooArgSet &set, Bool_t valueOnly=kTRUE) const
Definition: RooAbsArg.h:194
virtual void Print(Option_t *options=0) const
Print TNamed name and title.
Definition: RooAbsData.h:157
const RooAbsCategoryLValue & indexCat() const
Bool_t contains(const RooAbsArg &var) const
#define oocoutI(o, a)
Definition: RooMsgService.h:45
HypoTestResult is a base class for results from hypothesis tests.
RooCmdArg Strategy(Int_t code)
Basic string class.
Definition: TString.h:137
virtual Double_t getMin(const char *name=0) const
TAlienJobStatus * status
Definition: TAlienJob.cxx:51
TArc * a
Definition: textangle.C:12
const Bool_t kFALSE
Definition: Rtypes.h:92
int nbins[3]
static RooMsgService & instance()
Return reference to singleton instance.
STL namespace.
AsymptoticCalculator(RooAbsData &data, const ModelConfig &altModel, const ModelConfig &nullModel, bool nominalAsimov=false)
virtual Double_t getBinWidth(Int_t i, const char *rangeName=0) const
RooAbsPdf * getPdf(const char *catName) const
Return the p.d.f associated with the given index category name.
virtual Double_t expectedEvents(const RooArgSet *nset) const
Return expected number of events from this p.d.f for use in extended likelihood calculations.
Definition: RooAbsPdf.cxx:2930
ClassImp(TIterator) Bool_t TIterator return false
Compare two iterator objects.
Definition: TIterator.cxx:20
static void setHideOffset(Bool_t flag)
Definition: RooAbsReal.cxx:118
const RooArgSet * GetNuisanceParameters() const
get RooArgSet containing the nuisance parameters (return NULL if not existing)
Definition: ModelConfig.h:250
ClassDef(AsymptoticCalculator, 2) private bool fOneSidedDiscovery
void setEps(Double_t eps)
Change MINUIT epsilon.
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
Template class to wrap any C++ callable object which takes one argument i.e.
static void SetPrintLevel(int level)
static RooAbsData * GenerateCountingAsimovData(RooAbsPdf &pdf, const RooArgSet &obs, const RooRealVar &weightVar, RooCategory *channelCat=0)
RooAbsArg * first() const
Common base class for the Hypothesis Test Calculators.
double sqrt(double)
static RooAbsData * MakeAsimovData(RooAbsData &data, const ModelConfig &model, const RooArgSet &poiValues, RooArgSet &globObs, const RooArgSet *genPoiValues=0)
make the asimov data from the ModelConfig and list of poi - return data set annd snapshoot of global ...
#define oocoutP(o, a)
Definition: RooMsgService.h:46
Double_t x[n]
Definition: legend1.C:17
static void FillBins(const RooAbsPdf &pdf, const RooArgList &obs, RooAbsData &data, int &index, double &binVolume, int &ibin)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2334
void Class()
Definition: Class.C:29
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
RooArgSet * getVariables(Bool_t stripDisconnected=kTRUE) const
Return RooArgSet with all variables (tree leaf nodes of expresssion tree)
Definition: RooAbsArg.cxx:2081
#define oocoutE(o, a)
Definition: RooMsgService.h:48
double normal_cdf(double x, double sigma=1, double x0=0)
Cumulative distribution function of the normal (Gaussian) distribution (lower tail).
Int_t numTypes(const char *=0) const
virtual Int_t getBins(const char *name=0) const
std::map< std::string, std::string >::const_iterator iter
Definition: TAlienJob.cxx:54
virtual TObject * Next()
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
void setBins(Int_t nBins, const char *name=0)
Definition: RooRealVar.h:78
virtual void add(const RooArgSet &row, Double_t weight=1, Double_t weightError=0)=0
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Definition: RooAbsArg.cxx:559
virtual const RooArgSet * get() const
Definition: RooAbsData.h:77
const ModelConfig * GetAlternateModel(void) const
double Root() const
Returns root value.
RooFit::MsgLevel globalKillBelow() const
virtual void setVal(Double_t value)
Set value of variable to 'value'.
Definition: RooRealVar.cxx:202
static double EvaluateNLL(RooAbsPdf &pdf, RooAbsData &data, const RooArgSet *condObs, const RooArgSet *poiSet=0)
const ModelConfig * GetNullModel(void) const
const double tol
ROOT::R::TRInterface & r
Definition: Object.C:4
RooAbsArg * find(const char *name) const
Find object with given name in list.
static const std::string & DefaultMinimizerType()
SVector< double, 2 > v
Definition: Dict.h:5
void setConstant(Bool_t value=kTRUE)
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snaphot of current minimizer status.
RooCmdArg Minimizer(const char *type, const char *alg=0)
virtual void Print(Option_t *options=0) const
This method must be overridden when a class wants to print itself.
virtual Int_t numEntries() const
Definition: RooAbsData.cxx:291
bool verbose
void setGlobalKillBelow(RooFit::MsgLevel level)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
static bool SetObsToExpected(RooAbsPdf &pdf, const RooArgSet &obs)
void setNoRounding(bool flag=kTRUE)
Definition: RooPoisson.h:33
double normal_cdf_c(double x, double sigma=1, double x0=0)
Complement of the cumulative distribution function of the normal (Gaussian) distribution (upper tail)...
static Bool_t hideOffset()
Definition: RooAbsReal.cxx:119
virtual void add(const RooArgSet &row, Double_t weight=1.0, Double_t weightError=0)
Add a data point, with its coordinates specified in the 'data' argset, to the data set...
virtual Double_t sumEntries() const
Bool_t isConstant() const
Definition: RooAbsArg.h:266
Class for finding the root of a one dimensional function using the Brent algorithm.
RooCmdArg Import(const char *state, TH1 &histo)
const RooArgSet * GetObservables() const
get RooArgSet for observables (return NULL if not existing)
Definition: ModelConfig.h:259
static const std::string & DefaultMinimizerAlgo()
RooCmdArg Index(RooCategory &icat)
TRObject operator()(const T1 &t1) const
Namespace for the RooStats classes.
Definition: Asimov.h:20
RooCmdArg Hesse(Bool_t flag=kTRUE)
double f(double x)
void Print(std::ostream &os, const OptionType &opt)
double Double_t
Definition: RtypesCore.h:55
Double_t minNll() const
Definition: RooFitResult.h:97
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
Bool_t canBeExtended() const
Definition: RooAbsPdf.h:216
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
int fUseQTilde
flag to check if calculator is initialized
RooCmdArg WeightVar(const char *name, Bool_t reinterpretAsWeight=kFALSE)
bool SetAllConstant(const RooAbsCollection &coll, bool constant=true)
Definition: RooStatsUtils.h:93
const RooArgSet * GetSnapshot() const
get RooArgSet for parameters for a particular hypothesis (return NULL if not existing) ...
RooFIter serverMIterator() const
Definition: RooAbsArg.h:119
Int_t minimize(const char *type, const char *alg=0)
const RooAbsData * GetData(void) const
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
bool IsNLLOffset()
#define oocoutW(o, a)
Definition: RooMsgService.h:47
Mother of all ROOT objects.
Definition: TObject.h:58
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
virtual Double_t getMax(const char *name=0) const
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:73
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
double f2(const double *x)
Int_t IsNaN(Double_t x)
Definition: TMath.h:617
Bool_t dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=0, Bool_t valueOnly=kFALSE) const
Test whether we depend on (ie, are served by) any object in the specified collection.
Definition: RooAbsArg.cxx:743
#define NULL
Definition: Rtypes.h:82
bool debug
virtual RooFitResult * fitTo(RooAbsData &data, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none())
Fit PDF to given dataset.
Definition: RooAbsPdf.cxx:1056
const RooArgSet * GetParametersOfInterest() const
get RooArgSet containing the parameter of interest (return NULL if not existing)
Definition: ModelConfig.h:247
double result[121]
const int strategy
Definition: testNdimFit.cxx:46
bool SetFunction(const ROOT::Math::IGenFunction &f, double xlow, double xup)
Sets the function for the rest of the algorithms.
RooLinkedListIter iterator(Bool_t dir=kIterForward) const
Int_t getSize() const
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
Definition: RooAbsArg.h:66
const RooArgList & pdfList() const
Definition: RooProdPdf.h:69
RooCmdArg ConditionalObservables(const RooArgSet &set)
const Bool_t kTRUE
Definition: Rtypes.h:91
ClassImp(RooStats::AsymptoticCalculator)
Hypothesis Test Calculator based on the asymptotic formulae for the profile likelihood ratio...
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448
RooCmdArg Constrain(const RooArgSet &params)
virtual const char * getLabel() const
Return label string of current state.
Definition: RooCategory.h:40
RooAbsArg * findServer(const char *name) const
Definition: RooAbsArg.h:122
Double_t getError() const
Definition: RooRealVar.h:54
Stopwatch class.
Definition: TStopwatch.h:30
static RooAbsData * GenerateAsimovDataSinglePdf(const RooAbsPdf &pdf, const RooArgSet &obs, const RooRealVar &weightVar, RooCategory *channelCat=0)