diff --git a/macro/mcbm/CMakeLists.txt b/macro/mcbm/CMakeLists.txt index 0dba18688193ce4876ab88215e520fe3b204dee1..d51041866bb702c9225ecd2cc1c869290e6c3f8f 100644 --- a/macro/mcbm/CMakeLists.txt +++ b/macro/mcbm/CMakeLists.txt @@ -4,6 +4,7 @@ GENERATE_ROOT_TEST_SCRIPT(${CBMROOT_SOURCE_DIR}/macro/mcbm/mcbm_digi.C) GENERATE_ROOT_TEST_SCRIPT(${CBMROOT_SOURCE_DIR}/macro/mcbm/mcbm_reco_event.C) GENERATE_ROOT_TEST_SCRIPT(${CBMROOT_SOURCE_DIR}/macro/mcbm/mcbm_hadron_analysis.C) GENERATE_ROOT_TEST_SCRIPT(${CBMROOT_SOURCE_DIR}/macro/mcbm/mcbm_check_overlaps.C) +GENERATE_ROOT_TEST_SCRIPT(${CBMROOT_SOURCE_DIR}/macro/mcbm/mcbm_qa.C) #GENERATE_ROOT_TEST_SCRIPT(${CBMROOT_SOURCE_DIR}/macro/mcbm/mcbm_check_materials.C) Set(MACRO_DIR ${CMAKE_CURRENT_BINARY_DIR}) @@ -65,6 +66,18 @@ ForEach(setup IN LISTS cbm_setup) Set_Tests_Properties(${testname} PROPERTIES TIMEOUT "300") Set_Tests_Properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "Test Passed;All ok") set_tests_properties(${testname} PROPERTIES FIXTURES_REQUIRED ${fixture_digi_tb}) + Set(fixture_qa_event_mc fixture_qa_event_mc_${testname}) + set_tests_properties(${testname} PROPERTIES FIXTURES_SETUP ${fixture_qa_event_mc}) + + Set(testname mcbm_qa_event_mc_${setup}) + Add_Test(${testname} ${CBMROOT_BINARY_DIR}/macro/mcbm/mcbm_qa.sh ${NumEvents} \"data/${setup}_test\" \"${setup}\") + Set_Tests_Properties(${testname} PROPERTIES TIMEOUT "300") + Set_Tests_Properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "Test Passed;All ok") + Set_Tests_Properties(${testname} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR") + Set_Tests_Properties(${testname} PROPERTIES FAIL_REGULAR_EXPRESSION "FATAL") + Set_Tests_properties(${testname} PROPERTIES FIXTURES_REQUIRED ${fixture_qa_event_mc}) + Set(fixture_overlap fixture_overlap_${testname}) + set_tests_properties(${testname} PROPERTIES FIXTURES_SETUP ${fixture_overlap}) #Set(testname mcbm_reco_${setup}) #Add_Test(${testname} ${CBMROOT_BINARY_DIR}/macro/mcbm/mcbm_reco.sh ${NumEvents} ${BeamAngle} \"${setup}\") @@ -74,12 +87,11 @@ ForEach(setup IN LISTS cbm_setup) #Set(_FileName_Dependency data/mcbm_mc_${setup}_ok) #Set_Tests_Properties(${testname} PROPERTIES REQUIRED_FILES ${_FileName_Dependency}) - Set(testname mcbm_overlap_${setup}) Add_Test(${testname} ${CBMROOT_BINARY_DIR}/macro/mcbm/mcbm_check_overlaps.sh \"data/${setup}_test\") Set_Tests_Properties(${testname} PROPERTIES TIMEOUT "600") Set_Tests_Properties(${testname} PROPERTIES PASS_REGULAR_EXPRESSION "Test Passed;All ok") - set_tests_properties(${testname} PROPERTIES FIXTURES_REQUIRED ${fixture_digi_event}) + set_tests_properties(${testname} PROPERTIES FIXTURES_REQUIRED ${fixture_overlap}) Set(fixture_mcbm_overlap fixture_mcbm_overlap_${testname}) set_tests_properties(${testname} PROPERTIES FIXTURES_SETUP ${fixture_mcbm_overlap}) diff --git a/macro/mcbm/mcbm_qa.C b/macro/mcbm/mcbm_qa.C new file mode 100644 index 0000000000000000000000000000000000000000..a447c508a062ff25e44aa40eab3776a5a1ed4f4f --- /dev/null +++ b/macro/mcbm/mcbm_qa.C @@ -0,0 +1,220 @@ +// -------------------------------------------------------------------------- +// +// Macro for simulation & reconstruction QA +// +// The following naming conventions are assumed: +// Raw data file: [dataset].event.raw.root +// Transport file: [dataset].tra.root +// Parameter file: [dataset].par.root +// Reconstruction file: [dataset].rec.root +// +// S. Gorbunov 28/09/2020 +// +// -------------------------------------------------------------------------- + +// Includes needed for IDE +#if !defined(__CLING__) +#include <FairFileSource.h> +#include <FairMonitor.h> +#include <FairParAsciiFileIo.h> +#include <FairParRootFileIo.h> +#include <FairRootFileSink.h> +#include <FairRunAna.h> +#include <FairRuntimeDb.h> +#include <FairSystemInfo.h> + +#include "CbmDefs.h" +#include "CbmMCDataManager.h" +#include "CbmMuchTransportQa.h" +#include "CbmSetup.h" + +#include <TStopwatch.h> +#endif + +void mcbm_qa(Int_t nEvents = 0, + TString dataset = "data/mcbm_beam_2020_03_test", + TString setup = "mcbm_beam_2020_03") { + + // ======================================================================== + // Adjust this part according to your requirements + + // ----- Logger settings ---------------------------------------------- + FairLogger::GetLogger()->SetLogScreenLevel("INFO"); + FairLogger::GetLogger()->SetLogVerbosityLevel("LOW"); + // ------------------------------------------------------------------------ + + // ----- Environment -------------------------------------------------- + TString myName = "mcbm_qa"; // this macro's name for screen output + TString srcDir = gSystem->Getenv("VMCWORKDIR"); // top source directory + // ------------------------------------------------------------------------ + + // ----- In- and output file names ------------------------------------ + TString rawFile = dataset + ".event.raw.root"; + TString traFile = dataset + ".tra.root"; + TString parFile = dataset + ".par.root"; + TString recFile = dataset + ".rec.root"; + TString sinkFile = dataset + ".qa.root"; + // ------------------------------------------------------------------------ + + // ----- Load the geometry setup ------------------------------------- + std::cout << std::endl; + std::cout << "-I- " << myName << ": Loading setup " << setup << std::endl; + CbmSetup::Instance()->LoadSetup(setup); + // You can modify the pre-defined setup by using + // CbmSetup::Instance()->RemoveModule(ESystemId) or + // CbmSetup::Instance()->SetModule(ESystemId, const char*, Bool_t) or + // CbmSetup::Instance()->SetActive(ESystemId, Bool_t) + // See the class documentation of CbmSetup. + // ------------------------------------------------------------------------ + + // ----- Parameter files as input to the runtime database ------------- + std::cout << std::endl; + std::cout << "-I- " << myName << ": Defining parameter files " << std::endl; + TList* parFileList = new TList(); + TString geoTag; + + // - MUCH digitisation parameters + if (CbmSetup::Instance()->GetGeoTag(ECbmModuleId::kMuch, geoTag)) { + bool mcbmFlag = geoTag.Contains("mcbm", TString::kIgnoreCase); + TString parFile = srcDir + "/parameters/much/much_"; + parFile += (mcbmFlag) ? geoTag : geoTag(0, 4); + parFile += "_digi_sector.root"; + { // init geometry from the file + TFile* f = new TFile(parFile, "R"); + TObjArray* stations = (TObjArray*) f->Get("stations"); + CbmMuchGeoScheme::Instance()->Init(stations, mcbmFlag); + } + } + + // - TRD digitisation parameters + if (CbmSetup::Instance()->GetGeoTag(ECbmModuleId::kTrd, geoTag)) { + const Char_t* npar[4] = {"asic", "digi", "gas", "gain"}; + TObjString* trdParFile(NULL); + for (Int_t i(0); i < 4; i++) { + trdParFile = new TObjString(srcDir + "/parameters/trd/trd_" + geoTag + "." + + npar[i] + ".par"); + parFileList->Add(trdParFile); + std::cout << "-I- " << myName << ": Using parameter file " + << trdParFile->GetString() << std::endl; + } + } + + // - TOF digitisation parameters + if (CbmSetup::Instance()->GetGeoTag(ECbmModuleId::kTof, geoTag)) { + TObjString* tofFile = + new TObjString(srcDir + "/parameters/tof/tof_" + geoTag + ".digi.par"); + parFileList->Add(tofFile); + std::cout << "-I- " << myName << ": Using parameter file " + << tofFile->GetString() << std::endl; + TObjString* tofBdfFile = + new TObjString(srcDir + "/parameters/tof/tof_" + geoTag + ".digibdf.par"); + parFileList->Add(tofBdfFile); + std::cout << "-I- " << myName << ": Using parameter file " + << tofBdfFile->GetString() << std::endl; + } + // ------------------------------------------------------------------------ + + // In general, the following parts need not be touched + // ======================================================================== + + // ----- Timer -------------------------------------------------------- + TStopwatch timer; + timer.Start(); + // ------------------------------------------------------------------------ + + // ---- Debug option ------------------------------------------------- + gDebug = 0; + // ------------------------------------------------------------------------ + + // ----- FairRunAna --------------------------------------------------- + FairFileSource* inputSource = new FairFileSource(rawFile); + inputSource->AddFriend(traFile); + inputSource->AddFriend(recFile); + + FairRunAna* run = new FairRunAna(); + run->SetSource(inputSource); + run->SetGenerateRunInfo(kFALSE); + + FairRootFileSink* sink = new FairRootFileSink(sinkFile); + run->SetSink(sink); + + TString monitorFile {sinkFile}; + monitorFile.ReplaceAll("qa", "qa.monitor"); + FairMonitor::GetMonitor()->EnableMonitor(kTRUE, monitorFile); + // ------------------------------------------------------------------------ + + // ----- MCDataManager (legacy mode) ----------------------------------- + CbmMCDataManager* mcManager = new CbmMCDataManager("MCDataManager", 1); + mcManager->AddFile(traFile); + run->AddTask(mcManager); + // ------------------------------------------------------------------------ + + // ----- MUCH QA --------------------------------- + if (CbmSetup::Instance()->IsActive(ECbmModuleId::kMuch)) { + run->AddTask(new CbmMuchTransportQa()); + run->AddTask(new CbmMuchDigitizerQa()); + } + // ------------------------------------------------------------------------ + + // ----- Parameter database -------------------------------------------- + std::cout << std::endl << std::endl; + std::cout << "-I- " << myName << ": Set runtime DB" << std::endl; + FairRuntimeDb* rtdb = run->GetRuntimeDb(); + FairParRootFileIo* parIo1 = new FairParRootFileIo(); + parIo1->open(parFile.Data(), "in"); + rtdb->setFirstInput(parIo1); + if (!parFileList->IsEmpty()) { + FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo(); + parIo2->open(parFileList, "in"); + rtdb->setSecondInput(parIo2); + } + rtdb->print(); + // ------------------------------------------------------------------------ + + // ----- Run initialisation ------------------------------------------- + std::cout << std::endl; + std::cout << "-I- " << myName << ": Initialise run" << std::endl; + run->Init(); + + // ----- Start run ---------------------------------------------------- + std::cout << std::endl << std::endl; + std::cout << "-I- " << myName << ": Starting run" << std::endl; + run->Run(0, nEvents); + // ------------------------------------------------------------------------ + + // ----- Finish ------------------------------------------------------- + timer.Stop(); + + FairMonitor::GetMonitor()->Print(); + Double_t rtime = timer.RealTime(); + Double_t ctime = timer.CpuTime(); + std::cout << std::endl << std::endl; + std::cout << "Macro finished successfully." << std::endl; + std::cout << "Output file is " << sinkFile << std::endl; + std::cout << "Parameter file is " << parFile << std::endl; + std::cout << "Real time " << rtime << " s, CPU time " << ctime << " s" + << std::endl; + std::cout << std::endl; + std::cout << " Test passed" << std::endl; + std::cout << " All ok " << std::endl; + // ------------------------------------------------------------------------ + + // ----- Resource monitoring ------------------------------------------ + // Extract the maximal used memory an add is as Dart measurement + // This line is filtered by CTest and the value send to CDash + FairSystemInfo sysInfo; + Float_t maxMemory = sysInfo.GetMaxMemory(); + std::cout << "<DartMeasurement name=\"MaxMemory\" type=\"numeric/double\">"; + std::cout << maxMemory; + std::cout << "</DartMeasurement>" << std::endl; + + Float_t cpuUsage = ctime / rtime; + std::cout << "<DartMeasurement name=\"CpuLoad\" type=\"numeric/double\">"; + std::cout << cpuUsage; + std::cout << "</DartMeasurement>" << std::endl; + // ------------------------------------------------------------------------ + + // ----- Function needed for CTest runtime dependency ----------------- + RemoveGeoManager(); + // ------------------------------------------------------------------------ +} diff --git a/macro/run/run_qa.C b/macro/run/run_qa.C index 3aa12ef371968530d39c2db86b864b641ffb2bd9..35d1c4dcf712dfdc39256e41229f238a2615dd3e 100644 --- a/macro/run/run_qa.C +++ b/macro/run/run_qa.C @@ -39,7 +39,6 @@ void run_qa(Int_t nEvents = 0, // Adjust this part according to your requirements // ----- Logger settings ---------------------------------------------- - FairLogger::GetLogger()->SetLogScreenLevel("INFO"); FairLogger::GetLogger()->SetLogVerbosityLevel("LOW"); // ------------------------------------------------------------------------ @@ -55,7 +54,6 @@ void run_qa(Int_t nEvents = 0, TString parFile = dataset + ".par.root"; TString recFile = dataset + ".rec.root"; TString sinkFile = dataset + ".qa.root"; - // ------------------------------------------------------------------------ // ----- Load the geometry setup ------------------------------------- @@ -129,11 +127,11 @@ void run_qa(Int_t nEvents = 0, // ------------------------------------------------------------------------ // ----- FairRunAna --------------------------------------------------- - FairRunAna* run = new FairRunAna(); - FairFileSource* inputSource = new FairFileSource(rawFile); inputSource->AddFriend(traFile); inputSource->AddFriend(recFile); + + FairRunAna* run = new FairRunAna(); run->SetSource(inputSource); run->SetGenerateRunInfo(kFALSE); @@ -141,7 +139,6 @@ void run_qa(Int_t nEvents = 0, run->SetSink(sink); TString monitorFile {sinkFile}; - monitorFile.ReplaceAll("qa", "qa.monitor"); FairMonitor::GetMonitor()->EnableMonitor(kTRUE, monitorFile); // ------------------------------------------------------------------------ @@ -152,31 +149,27 @@ void run_qa(Int_t nEvents = 0, run->AddTask(mcManager); // ------------------------------------------------------------------------ - - // ----- MUCH hit finder QA --------------------------------- - + // ----- MUCH QA --------------------------------- if (CbmSetup::Instance()->IsActive(ECbmModuleId::kMuch)) { run->AddTask(new CbmMuchTransportQa()); run->AddTask(new CbmMuchDigitizerQa()); } - // ------------------------------------------------------------------------ // ----- Parameter database -------------------------------------------- - { - std::cout << std::endl << std::endl; - std::cout << "-I- " << myName << ": Set runtime DB" << std::endl; - FairRuntimeDb* rtdb = run->GetRuntimeDb(); - FairParRootFileIo* parIo1 = new FairParRootFileIo(); - parIo1->open(parFile.Data(), "in"); - rtdb->setFirstInput(parIo1); - if (!parFileList->IsEmpty()) { - FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo(); - parIo2->open(parFileList, "in"); - rtdb->setSecondInput(parIo2); - } - rtdb->print(); + std::cout << std::endl << std::endl; + std::cout << "-I- " << myName << ": Set runtime DB" << std::endl; + FairRuntimeDb* rtdb = run->GetRuntimeDb(); + FairParRootFileIo* parIo1 = new FairParRootFileIo(); + parIo1->open(parFile.Data(), "in"); + rtdb->setFirstInput(parIo1); + if (!parFileList->IsEmpty()) { + FairParAsciiFileIo* parIo2 = new FairParAsciiFileIo(); + parIo2->open(parFileList, "in"); + rtdb->setSecondInput(parIo2); } + rtdb->print(); + // ------------------------------------------------------------------------ // ----- Run initialisation ------------------------------------------- std::cout << std::endl; @@ -189,8 +182,6 @@ void run_qa(Int_t nEvents = 0, run->Run(0, nEvents); // ------------------------------------------------------------------------ - //std::cout<< "Test failed" << std::endl; - // ----- Finish ------------------------------------------------------- timer.Stop(); @@ -208,7 +199,6 @@ void run_qa(Int_t nEvents = 0, std::cout << " All ok " << std::endl; // ------------------------------------------------------------------------ - // ----- Resource monitoring ------------------------------------------ // Extract the maximal used memory an add is as Dart measurement // This line is filtered by CTest and the value send to CDash