Skip to content

Commit

Permalink
Force updateGrid in expectedFromGrid HybridNew.cc (#941)
Browse files Browse the repository at this point in the history
* Force updateGrid in expectedFromGrid HybridNew.cc

if using `--noUpdateGrid` with `--expectedFromGrid` and the grid file was not produced using the same value for expectedFromGrid, then the limit will be identical to the result without `--expectedFromGrid`. 

With this change, we now *force* an update if `--expectedFromGrid` option set. Usual workflow is to produce the grid (without this option) and then calculate expected results after, so this works with this workflow if user adds `--noUpdateGrid`

* Check if really necessary to update grid with expectedFromGrid based on quantileFrom gridfile

---------

Co-authored-by: Nick Wardle <nckw@cern.ch>
  • Loading branch information
nucleosynthesis and Nick Wardle committed May 8, 2024
1 parent ec7f836 commit c5f0dfa
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/HybridNew.cc
Original file line number Diff line number Diff line change
Expand Up @@ -370,22 +370,40 @@ bool HybridNew::runLimit(RooWorkspace *w, RooStats::ModelConfig *mc_s, RooStats:
if (readHybridResults_) {
if (verbose > 0) std::cout << "Search for upper limit using pre-computed grid of p-values" << std::endl;

// need to get hold of quantileExpectedBranch
Float_t quantExpectedIn;

if (!gridFile_.empty()) {
if (grid_.empty()) {
std::unique_ptr<TFile> gridFile(TFile::Open(gridFile_.c_str()));
if (gridFile.get() == 0) throw std::runtime_error(("Can't open grid file "+gridFile_).c_str());
TDirectory *toyDir = gridFile->GetDirectory("toys");
if (!toyDir) throw std::logic_error("Cannot use readHypoTestResult: empty toy dir in input file empty");
readGrid(toyDir, rMinSet_ ? rMin : -99e99, rMaxSet_ ? rMax :+99e99);

TTree *treeIn = (TTree*) gridFile->Get("limit");
treeIn->SetBranchAddress("quantileExpected",&quantExpectedIn);
treeIn->GetEntry(0);
}
if (grid_.size() <= 1) throw std::logic_error("The grid must contain at least 2 points.");
if (noUpdateGrid_) {
if (testStat_ == "LHCFC" && rule_ == "FC" && (saveGrid_ || lowerLimit_)) {
std::cout << "Will have to re-run points for which the test statistic was set to zero" << std::endl;
updateGridDataFC(w, mc_s, mc_b, data, !fullGrid_, clsTarget);
} else {
std::cout << "Will use the test statistic that had already been computed" << std::endl;
}

// check if we will have to update since we need a new value for the "data" test stat
if (expectedFromGrid_) {
Float_t diffQE = TMath::Abs(quantExpectedIn-quantileForExpectedFromGrid_);
if (diffQE > EPS) {
updateGridData(w, mc_s, mc_b, data, !fullGrid_, clsTarget);
}
} else if ( TMath::Abs(quantExpectedIn + 1) > EPS ) {
updateGridData(w, mc_s, mc_b, data, !fullGrid_, clsTarget);
} else {
if (verbose > 0) CombineLogger::instance().log("HybridNew.cc",__LINE__,std::string("Will use the test statistic values that has already been computed when producing grid file - "+gridFile_),__func__);
}
}
} else {
updateGridData(w, mc_s, mc_b, data, !fullGrid_, clsTarget);
}
Expand Down

0 comments on commit c5f0dfa

Please sign in to comment.