diff --git a/macro/tools/HowTo_TofYaml.md b/macro/tools/HowTo_TofYaml.md new file mode 100644 index 0000000000000000000000000000000000000000..050bb5e3052f54e45d71295283fec414e919793a --- /dev/null +++ b/macro/tools/HowTo_TofYaml.md @@ -0,0 +1,25 @@ +# Generation of TOF parameter YAML files for the algo version of the TOF HitFinder/Clusterizer + +**!!! WORKING ONLY FOR mCBM RUNS !!!** + +1. Pick a run (`<RUN ID>` in later parts), check in `core/base/utils/CbmMcbmUtils.cxx` to which setup it corresponds and check in `geometry/setup` that this would load the geometries you expect (if not modify te setup file) +1. Locate where you have your custom TOF calibration file (`.....tofClust.hst.root`) +1. Locate where you have your custom geometry alignment file (typ. `AlignmentMatrices_<setup_name>.root`) and make sure it fit you (eventually custom) setup +1. Create the geo root file in `macro/run` by running + ``` + root -l -b -q 'create_mcbm_geo_setup.C(<RUN ID>)' + ``` +1. Create an unpacked file with at least 1 TS for this run (with `macro/run/run_unpack_tsa.C`) or locate an existing unpacked file and make a symlink for it called `<RUN ID>.digi.root` in `macro/run/data` +1. Go to `macro/tools` +1. Run the following command (replacing the `<....>` parts with the corresponding info) + ``` + root -l -b -q 'tof_hitfinder_run.C(<RUN ID>, 1, "../run/data/", "../run/data/", -1, "", <FULL PATH TO TOF CALIB FILE>, <FULL PATH TO ALIGNMENT FILE>, true)' + ``` +1. You should now find in the folder you are two new YAML files called `TofCalibratePar.yaml` and `TofHitfinderPar.yaml` + - If you want you can try to compare them with `diff` or `meld` to the ones in `parameters/online` +1. To test the new YAML param files + 1. Copy the files to `parameters/online` + 1. Run (using the dummy/example file made for the yaml generation) + ``` + root -l -b -q 'tof_hitfinder_run.C(<RUN ID>, 1, "./data/", "./data/", -1)' + ``` diff --git a/macro/tools/tof_hitfinder_run.C b/macro/tools/tof_hitfinder_run.C index 07e5779c0373b0f0a0eff295346c3873d9d1c0a2..cdaeeddb0e50a2e3ebbbf70e6696c48f340a398c 100644 --- a/macro/tools/tof_hitfinder_run.C +++ b/macro/tools/tof_hitfinder_run.C @@ -7,13 +7,34 @@ #include <stdio.h> #include <string.h> +template<typename TofTaskType> +void CreateTask(TofTaskType* tofCluster, FairRunAna* run, TString& myName, TString& cFname, Int_t& calMode, + Double_t& dDeadtime) +{ + tofCluster->SetCalParFileName(cFname); + tofCluster->SetCalMode(calMode); + tofCluster->SetTotMax(20.); // Tot upper limit for walk corection + tofCluster->SetTotMin(0.); //(12000.); // Tot lower limit for walk correction + tofCluster->SetTotMean(5.); // Tot calibration target value in ns + tofCluster->SetMaxTimeDist(1.0); // default cluster range in ns + tofCluster->SetChannelDeadtime(dDeadtime); // artificial deadtime in ns + tofCluster->PosYMaxScal(0.75); //in % of length + + run->AddTask(tofCluster); + std::cout << "-I- " << myName << ": Added task " << tofCluster->GetName() << std::endl; +} + /// FIXME: Disable clang formatting to keep easy parameters overview /* clang-format off */ Bool_t tof_hitfinder_run(UInt_t uRunId = 2391, - Int_t nTimeslices = 1, - TString sInpDir = "/home/dsmith/cbmroot/macro/beamtime/mcbm2022/data/", - TString sOutDir = "rec/", - Int_t iUnpFileIndex = -1) + Int_t nTimeslices = 1, + TString sInpDir = "../beamtime/mcbm2022/data/", + TString sOutDir = "rec/", + Int_t iUnpFileIndex = -1, + TString TofFileFolder = "", // Your folder with the Tof Calibration files; + TString calibFile = "", + TString alignmentMatrixFileName = "", + bool bGenerateYamlFiles = false) { /// FIXME: Re-enable clang formatting after parameters initial values setting /* clang-format on */ @@ -40,9 +61,6 @@ Bool_t tof_hitfinder_run(UInt_t uRunId = 2391, TString parFileOut = sOutDir + "/reco_event_mcbm_params_" + sRunId; TString outFile = sOutDir + "/reco_event_mcbm_" + sRunId; - // Your folder with the Tof Calibration files; - TString TofFileFolder = "/home/dsmith/cbmroot/macro/run/data/"; - /// Add index of splitting at unpacking level if needed if (0 <= iUnpFileIndex) { inFile += TString::Format("_%02u", iUnpFileIndex); @@ -82,6 +100,16 @@ Bool_t tof_hitfinder_run(UInt_t uRunId = 2391, if (uRunId >= 2391) iCalSet = 22002500; const Int_t iTofCluMode = 1; + + if (TofFileFolder.Length() != 0) { + // Use user provided path + TofFileFolder = Form("%s/%s", TofFileFolder.Data(), cCalId.Data()); + } + else { + // use default path + TofFileFolder = srcDir + "parameter/mcbm/"; + // TofFileFolder = "../run/data/" + cCalId; + } // ------------------------------------------------------------------------ // --- Load the geometry setup ---- @@ -96,7 +124,7 @@ Bool_t tof_hitfinder_run(UInt_t uRunId = 2391, return kFALSE; } - TString geoFile = srcDir + "/macro/mcbm/data/" + geoSetupTag + ".geo.root"; + TString geoFile = sInpDir + "/" + geoSetupTag + ".geo.root"; CbmSetup* geoSetup = CbmSetup::Instance(); geoSetup->LoadSetup(geoSetupTag); @@ -105,7 +133,6 @@ Bool_t tof_hitfinder_run(UInt_t uRunId = 2391, //----- Load Parameters -------------------------------------------------- TList* parFileList = new TList(); - TofFileFolder = Form("%s/%s", TofFileFolder.Data(), cCalId.Data()); // ----- TOF digitisation parameters ------------------------------------- TString geoTag; @@ -138,6 +165,39 @@ Bool_t tof_hitfinder_run(UInt_t uRunId = 2391, FairMonitor::GetMonitor()->EnableMonitor(kTRUE, monitorFile); // ------------------------------------------------------------------------ + // ========================================================================= + // === GEO Alignment === + // ========================================================================= + if (alignmentMatrixFileName.Length() != 0) { + std::cout << "-I- " << myName << ": Applying alignment for file " << alignmentMatrixFileName << std::endl; + + // Define the basic structure which needs to be filled with information + // This structure is stored in the output file and later passed to the + // FairRoot framework to do the (miss)alignment + std::map<std::string, TGeoHMatrix>* matrices{nullptr}; + + // read matrices from disk + LOG(info) << "Filename: " << alignmentMatrixFileName; + TFile* misalignmentMatrixRootfile = new TFile(alignmentMatrixFileName, "READ"); + if (misalignmentMatrixRootfile->IsOpen()) { + gDirectory->GetObject("MisalignMatrices", matrices); + misalignmentMatrixRootfile->Close(); + } + else { + LOG(error) << "Could not open file " << alignmentMatrixFileName << "\n Exiting"; + return kFALSE; + } + + if (matrices) { + run->AddAlignmentMatrices(*matrices); + } + else { + LOG(error) << "Alignment required but no matrices found." + << "\n Exiting"; + return kFALSE; + } + } + // ------------------------------------------------------------------------- // ----- Logger settings ---------------------------------------------- FairLogger::GetLogger()->SetLogScreenLevel(logLevel.Data()); @@ -151,15 +211,25 @@ Bool_t tof_hitfinder_run(UInt_t uRunId = 2391, TString cFname; switch (iTofCluMode) { case 1: { - - // For production of YAML files - //CbmTaskTofClusterizerParWrite* tofCluster = new CbmTaskTofClusterizerParWrite("Task TOF Clusterizer", 0, 1); - - // For actual processing - CbmTaskTofClusterizer* tofCluster = new CbmTaskTofClusterizer("Task TOF Clusterizer", 0, 1); - - cFname = Form("/%s_set%09d_%02d_%01dtofClust.hst.root", cCalId.Data(), iCalSet, calMode, calSel); - tofCluster->SetCalParFileName(TofFileFolder + cFname); + cFname = Form("%s/%s_set%09d_%02d_%01dtofClust.hst.root", TofFileFolder.Data(), cCalId.Data(), iCalSet, calMode, + calSel); + if (calibFile.Length() != 0) { + // Use user provided calib file, overriding the automatic determination based on run ID + cFname = calibFile; + } + + if (bGenerateYamlFiles) { + // For production of YAML files + CbmTaskTofClusterizerParWrite* tofCluster = new CbmTaskTofClusterizerParWrite("Task TOF Clusterizer", 0, 1); + CreateTask<CbmTaskTofClusterizerParWrite>(tofCluster, run, myName, cFname, calMode, dDeadtime); + } + else { + // For actual processing + CbmTaskTofClusterizer* tofCluster = new CbmTaskTofClusterizer("Task TOF Clusterizer", 0, 1); + CreateTask<CbmTaskTofClusterizer>(tofCluster, run, myName, cFname, calMode, dDeadtime); + } + /* + tofCluster->SetCalParFileName(cFname); tofCluster->SetCalMode(calMode); tofCluster->SetTotMax(20.); // Tot upper limit for walk corection tofCluster->SetTotMin(0.); //(12000.); // Tot lower limit for walk correction @@ -170,6 +240,7 @@ Bool_t tof_hitfinder_run(UInt_t uRunId = 2391, run->AddTask(tofCluster); std::cout << "-I- " << myName << ": Added task " << tofCluster->GetName() << std::endl; + */ } break; default: {