diff --git a/examples/SimFitCoordinator_Bd2Dpipi.cc b/examples/SimFitCoordinator_Bd2Dpipi.cc index 9ced8c5..cc7c8d9 100644 --- a/examples/SimFitCoordinator_Bd2Dpipi.cc +++ b/examples/SimFitCoordinator_Bd2Dpipi.cc @@ -1,165 +1,169 @@ /* Copyright 2013 University of Warwick Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* Laura++ package authors: John Back Paul Harrison Thomas Latham */ #include #include #include #include "TFile.h" #include "TMatrixD.h" #include "TRandom.h" #include "TString.h" #include "TSystem.h" #include "TVectorD.h" #include "LauJsonTools.hh" #include "LauSimFitCoordinator.hh" void usage( std::ostream& out, const TString& progName ) { out<<"Usage:\n"; out< [firstExpt = 0] [numTasks = 2] [port = 0] [refFitDir] \n"; } int main(const int argc, const char ** argv) { if ( argc < 3 ) { usage( std::cerr, argv[0] ); return EXIT_FAILURE; } UInt_t iFit = atoi( argv[1] ); UInt_t nExpt = atoi( argv[2] ); UInt_t firstExpt = 0; UInt_t nTasks = 2; UInt_t port = 0; TString refDirName = ""; Bool_t useAsymmErrors = kFALSE; Bool_t twoStageFit = kFALSE; TString ntupleName = ""; if ( argc > 3 ) { firstExpt = atoi( argv[3] ); if ( argc > 4 ) { nTasks = atoi( argv[4] ); if ( argc > 5 ) { port = atoi( argv[5] ); if ( argc > 6 ) { refDirName = argv[6]; ntupleName += refDirName; ntupleName += "/"; } } } } UInt_t lastExpt = firstExpt + nExpt - 1; ntupleName += "coordinator-ntuple_expts"; ntupleName += firstExpt; ntupleName += "-"; ntupleName += lastExpt; ntupleName += "_fit"; ntupleName += iFit; ntupleName += ".root"; LauSimFitCoordinator coordinator( nTasks, port ); const std::string signalYieldsJsonFile { "Bd2D0pipi_SignalYields.json" }; const std::string bkgndsJsonFile { "Bd2D0pipi_Bkgnds.json" }; const nlohmann::json signalYieldsJson = LauJsonTools::readJsonFile( signalYieldsJsonFile, "", LauJsonTools::JsonType::Object ); if ( signalYieldsJson.is_null() ) { std::cerr << "ERROR : unable to retrieve root JSON object from file \"" << signalYieldsJsonFile << "\"" << std::endl; return EXIT_FAILURE; } const nlohmann::json bkgndsJson = LauJsonTools::readJsonFile( bkgndsJsonFile, "", LauJsonTools::JsonType::Object ); if ( bkgndsJson.is_null() ) { std::cerr << "ERROR : unable to retrieve root JSON object from file \"" << bkgndsJsonFile << "\"" << std::endl; return EXIT_FAILURE; } const std::array runs {"Run1", "Run2"}; const std::array modes {"Kpi", "KK", "pipi"}; const std::map bkgndIndex { { "comb" , 1 }, { "Bd2DKpi" , 2 }, { "Bs2DKpi" , 3 }, { "Lb2Dppi" , 4 }, { "Bu2Dstpi_Dpi0" , 5 }, { "Bu2Dstpi" , 6 }, { "Bd2Dstpi" , 7 } }; const std::size_t nComponents{bkgndIndex.size()+1}; for ( auto& run : runs ) { for ( auto& mode : modes ) { + if ( nTasks < 3 && mode != "Kpi" ) { + continue; + } + const std::string dir { "B2Dhh_" + mode }; std::vector parNames; parNames.resize( nComponents ); TVectorD means( nComponents ); parNames[0] = Form( "signalEvents_%s_%s", dir.c_str(), run.c_str() ); const auto& nSigJson { signalYieldsJson.at(run).at(dir) }; if ( nSigJson.is_number() ) { means[0] = nSigJson.get(); } else { means[0] = LauJsonTools::getValue( nSigJson, "value" ); } for ( auto& [ bkgndName, bkgndJson ] : bkgndsJson.items() ) { std::size_t iBkgnd{ bkgndIndex.at(bkgndName) }; std::cout << "Processing background " << iBkgnd << " called " << bkgndName << std::endl; parNames[iBkgnd] = Form( "%sEvents_%s_%s", bkgndName.c_str(), dir.c_str(), run.c_str() ); const auto& yieldJson { bkgndJson.at("yields").at(run).at(dir) }; if ( yieldJson.is_number() ) { means[iBkgnd] = yieldJson.get(); } else { means[iBkgnd] = LauJsonTools::getValue( yieldJson, "value" ); } } std::unique_ptr file { TFile::Open( Form( "root://eoslhcb.cern.ch//eos/lhcb/wg/b2oc/B2D0pipi/timedep_fit_histos/Overall_fitResult_%s_%s.root", run.c_str(), mode.c_str() ) ) }; TMatrixD * covMat { static_cast( file->Get("covariance_sigRegion") ) }; coordinator.addMultiDimConstraint( parNames, means, *covMat ); file->Close(); } } coordinator.runSimFit( ntupleName, nExpt, firstExpt, useAsymmErrors, twoStageFit ); return EXIT_SUCCESS; }