29#include <boost/filesystem.hpp>
41#include "FairRunAna.h"
45#include "TGeoBoolNode.h"
46#include "TGeoCompositeShape.h"
47#include "TGeoManager.h"
51#include "TProfile2D.h"
94 case 1: LOG(info) <<
"CbmL1: input data will be written for a standalone usage";
break;
95 case 2: LOG(info) <<
"CbmL1: input data will be read from external files";
break;
96 default: LOG(info) <<
"CbmL1: tracking will be run without external data R/W";
break;
133 char y[20] =
" [0;33;44m";
134 char Y[20] =
" [1;33;44m";
135 char W[20] =
" [1;37;44m";
136 char o[20] =
" [0m\n";
137 Y[0] =
y[0] = W[0] = o[0] = 0x1B;
138 std::stringstream ss;
141 ss <<
" " << W <<
" " << o;
142 ss <<
" " << W <<
" ===////====================================================== " << o;
143 ss <<
" " << W <<
" = = " << o;
144 ss <<
" " << W <<
" = " << Y <<
"L1 on-line finder" << W <<
" = " << o;
145 ss <<
" " << W <<
" = = " << o;
146 ss <<
" " << W <<
" = " << W <<
"Cellular Automaton 3.1 Vector" <<
y <<
" with " << W <<
"KF Quadro" <<
y
147 <<
" technology" << W <<
" = " << o;
148 ss <<
" " << W <<
" = = " << o;
149 ss <<
" " << W <<
" = " <<
y <<
"Designed for CBM collaboration" << W <<
" = " << o;
150 ss <<
" " << W <<
" = " <<
y <<
"All rights reserved" << W <<
" = " << o;
151 ss <<
" " << W <<
" = = " << o;
152 ss <<
" " << W <<
" ========================================================////= " << o;
153 ss <<
" " << W <<
" " << o;
156 LOG(info) << ss.str();
172 std::shared_ptr<const ca::Parameters<double>> pParameters{
nullptr};
181 std::string mainConfig = std::string(gSystem->Getenv(
"VMCWORKDIR")) +
"/macro/L1/configs/";
187 parBuilder.SetMainConfig(mainConfig);
193 for (
int locId : locIds) {
194 parBuilder.DisableStation(detId, locId);
199 if (
auto* pTrackFinderTask =
dynamic_cast<CbmStsFindTracks*
>(FairRunAna::Instance()->GetTask(
"STSFindTracks"))) {
200 if (!pTrackFinderTask->MvdUsage()) {
206 pParameters = std::make_shared<const ca::Parameters<double>>(
220 LOG(info) <<
'\n' << pParameters->ToString(1);
239 const auto& rSetup = pParameters->GetSetup();
241 bUsed[detId] = rSetup.GetNofActStations(detId) > 0;
245 fpTSReader = std::make_unique<TimeSliceReader>();
274 LOG(info) << pParameters->ToString(1);
275 LOG(info) <<
"----- Numbers of stations active in tracking -----";
281 LOG(info) <<
" Total: " << pParameters->GetNstationsActive();
283 fNStations = pParameters->GetNstationsActive();
289 const auto& activeSetup = pParameters->GetActiveSetup();
290 for (
int iSt = 0; iSt < activeSetup.GetNofLayers(); ++iSt) {
291 fMaterialMonitor.emplace_back(&(activeSetup.GetMaterial(iSt)), Form(
"Station %d", iSt));
305catch (
const std::exception& err) {
306 LOG(error) <<
"CbmL1: initialization failed. Reason: " << err.what();
315 LOG(warning) <<
"CbmL1::Reconstruct called";
325 LOG(warning) <<
"CbmL1::Reconstruct: after ReceiveInputData";
329 for (
const auto& hit :
fpAlgo->GetInputData().GetHits()) {
336 fpAlgo->SetMonitorData(monitorData);
338 if (
nullptr != event) {
339 LOG_IF(debug, fVerbose > 0) <<
"\n======= Ca Track finder: processing event " <<
event->GetNumber() <<
" ...";
342 LOG_IF(debug, fVerbose > 0) <<
"\n======= Ca Track finder: processing timeslice ...";
344 LOG(warning) <<
"CbmL1::Reconstruct: before FindTracks";
346 LOG(warning) <<
"CbmL1::Reconstruct: after FindTracks";
350 LOG_IF(debug, fVerbose > 0) <<
"Ca Track Finder finished, found " <<
fpAlgo->fRecoTracks.size() <<
" tracks";
353 monitorData =
fpAlgo->GetMonitorData();
360 int trackFirstHit = 0;
363 for (
const auto& caTrk :
fpAlgo->fRecoTracks) {
365 t.
Set(caTrk.fParFirst);
370 for (
int i = 0; i < caTrk.fNofHits; i++) {
371 int caHitId =
fpAlgo->fRecoHits[trackFirstHit + i];
372 int cbmHitID =
fpAlgo->GetInputData().GetHit(caHitId).Id();
373 t.
Hits.push_back(cbmHitID);
376 trackFirstHit += caTrk.fNofHits;
381 LOG(warning) <<
"CA Track Finder: " <<
fpAlgo->fCaRecoTime <<
" s/sub-ts";
385 LOG_IF(info, fVerbose) <<
"Performance...";
405 LOG_IF(info, fVerbose > 1) <<
"Tracking performance... done";
407 LOG(warning) <<
"End of CA";
410 fMonitor.AddMonitorData(monitorData);
424 std::stringstream msg;
426 msg <<
"\033[31;1m ***************************\033[0m\n";
427 msg <<
"\033[31;1m ** CA Tracking monitor **\033[0m\n";
428 msg <<
"\033[31;1m ***************************\033[0m\n";
433 msg <<
" ----- Material budget map monitoring: active setup -----\n";
435 msg << monitor.ToString() <<
'\n';
437 msg <<
" --------------------------------------------------------\n";
442 LOG(info) << msg.str();
445 TDirectory* curr = gDirectory;
446 TFile* currentFile = gFile;
450 boost::filesystem::path p = (FairRunAna::Instance()->GetUserOutputFileName()).
Data();
451 std::string dir = p.parent_path().string();
452 if (dir.empty()) dir =
".";
454 std::string histoOutName = dir +
"/L1_histo_" + p.filename().string();
455 LOG(info) <<
"\033[31;1mL1 performance histograms will be saved to: \033[0m" << histoOutName;
456 TFile* outfile =
new TFile(histoOutName.c_str(),
"RECREATE");
463 std::string tablesOutName = dir +
"/L1_perftable_" + p.filename().string();
464 LOG(info) <<
"\033[31;1mL1 performance tables will be saved to: \033[0m" << tablesOutName;
465 TFile* outfile =
new TFile(tablesOutName.c_str(),
"RECREATE");
490 if (!obj->IsFolder())
493 TDirectory* cur = gDirectory;
494 TDirectory* sub = cur->mkdir(obj->GetName());
496 TList* listSub = (
dynamic_cast<TDirectory*
>(obj))->GetList();
498 while (TObject* obj1 = it())
508 fpAlgo->fRecoTracks.clear();
509 fpAlgo->fRecoHits.clear();
511 for (
auto& MC :
fMCData.GetTrackContainer()) {
512 if (!MC.IsReconstructable())
continue;
513 if (!(MC.GetId() >= 0))
continue;
515 if (MC.GetNofHits() < 4)
continue;
522 for (
unsigned int iH : MC.GetHitIndexes()) {
525 if (iStation >= 0) hitIndices[iStation] = iH;
529 for (
int iH = 0; iH <
fpAlgo->GetParameters().GetNstationsActive(); iH++) {
530 const int hitI = hitIndices[iH];
531 if (hitI < 0)
continue;
540 for (
int iH = 0; iH <
fpAlgo->GetParameters().GetNstationsActive(); iH++) {
541 const int hitI = hitIndices[iH];
542 if (hitI < 0)
continue;
543 fpAlgo->fRecoHits.push_back(hitI);
551 algoTr.
fParFirst.
Qp() = MC.GetCharge() / MC.GetP();
553 fpAlgo->fRecoTracks.push_back(algoTr);
565 namespace bfs = boost::filesystem;
572 bfs::path pathToRecoOutput = FairRunAna::Instance()->GetUserOutputFileName().Data();
589 LOG(info) <<
"CbmL1: STAP data root directory is \033[1;32m" << bfs::system_complete(
fSTAPDataDir.Data())
598 if (!bfs::exists(sInputDataDir.Data())) {
599 LOG(warn) <<
"CbmL1: directory for tracking input data does not exist. It will be created";
600 bfs::create_directories(sInputDataDir.Data());
602 LOG(info) <<
"CbmL1: STAP tracking input jobs directory is \033[1;32m" << bfs::system_complete(sInputDataDir.Data())
621 LOG(fatal) <<
"CbmL1: Running in standalone mode is not available at the moment. It will be updated soon...";
639 LOG(fatal) <<
"CbmL1: Running in standalone mode is not available at the moment. It will be updated soon...";
646 auto* currentFile = gFile;
647 TFile f = TFile{fileName,
"RECREATE"};
651 const auto& activeTrackingSetup = par->GetActiveSetup();
652 for (
int iSt = 0; iSt < activeTrackingSetup.GetNofLayers(); ++iSt) {
653 const auto& material = activeTrackingSetup.GetMaterial(iSt);
654 TString name = Form(
"tracking_station%d", iSt);
655 TString title = Form(
"Tracking station %d: Rad. thickness in %%. Z region [%.2f, %.2f] cm.", iSt,
656 material.GetZmin(), material.GetZmax());
658 title +=
" Horizontal projection.";
661 title +=
" Radial projection.";
A generic hit for the CA tracker (header)
Target property initialization and access in CBM (source)
cbm::algo::ca::Track CaTrack
Data class for a reconstructed hit in the STS.
Common constant definitions for the Kalman Filter library.
Different ROOT utility functions for the KF-framework (header)
Generates beam ions for transport simulation.
Class characterising one event by a collection of links (indices) to data objects,...
cbm::algo::kf::TrackParamD TLast
Track parameters in the end of the track.
std::vector< int > Hits
Indexes of hits of this track.
cbm::algo::kf::TrackParamD Tpv
Track parameters at primary vertex.
@ Param
Parameter initialization (when algorithm execution is not required)
std::shared_ptr< ca::DataManager > fpIODataManager
Input-output data manager.
bool fMatBudgetParallelProjection
int fNStations
number of total active detector stations
void Reconstruct(CbmEvent *event=nullptr)
double fTrackingTime
time of track finding procedure
std::vector< cbm::algo::kf::MaterialMonitor > fMaterialMonitor
Material monitors for each material budget map.
void DefineSTAPNames()
Defines names for output in STAP mode.
void EfficienciesPerformance(bool doFinish=kFALSE)
Calculates tracking efficiencies (counters)
TTree * fpMcTripletsTree
Tree to save MC-triplets.
std::string fsMcTripletsOutputFilename
Name of file to save MC-triplets tree.
void ReadSTAPPerfInputData()
static CbmL1 * fpInstance
Instance of CbmL1.
cbm::algo::ca::McData fMCData
MC Data object.
virtual InitStatus Init()
Defines action in the beginning of the run (initialization)
cbm::ca::DetIdArr_t< std::set< int > > fvmDisabledStationIDs
CbmL1()
Default constructor.
void WriteSTAPAlgoInputData(int iJob=0)
void DisableTrackingStation(ca::EDetectorID detID, int iSt)
Disables tracking station for a given detector subsystem.
std::unique_ptr< cbm::ca::MCModule > fpMCModule
MC module.
void ReadSTAPAlgoInputData(int iJob=0)
int fSTAPDataMode
Option to work with files for the standalone mode.
ca::Vector< CbmL1HitId > fvExternalHits
Array of hits.
Int_t fPerformance
performance mode: 0 - w\o perf. 1 - L1-Efficiency definition. 2 - QA-Eff.definition
int fEventNo
Current number of event/TS.
ca::Framework * fpAlgo
Pointer to the L1 track finder algorithm.
ca::TrackingMonitor fMonitor
Tracking monitor.
std::string fsUserConfig
User config path.
void WriteSTAPPerfInputData()
static constexpr std::string_view kSTAPParamSuffix
Extension for IO of the L1Parameters object.
EInitMode fInitMode
Initialization mode.
ca::Vector< CbmL1Track > fvRecoTracks
Reconstructed tracks container.
static constexpr std::string_view kSTAPAlgoIDataDir
Name of subdirectory for handling ca::InputData objects.
void IdealTrackFinder()
Runs ideal track finder: copies all MC-tracks into reconstructed tracks.
void TrackFitPerformance()
TString fSTAPParamFile
Name of the parameter file (generated automatically, if not provided manually)
void Finish()
Defines action in the end of the run (saves results)
TString fSTAPDataPrefix
Name of input/output file prefix. The prefix is defined by output TTree file.
void DumpMaterialToFile(TString fileName, std::shared_ptr< const cbm::algo::ca::Parameters< double > > par)
ca::TrackingMode fTrackingMode
Tracking mode.
void DumpMCTripletsToTree()
std::unique_ptr< cbm::ca::TimeSliceReader > fpTSReader
event/TS reader
void HistoPerformance()
Fills performance histograms.
TString fSTAPDataDir
Name of input/output directory for running in a STAP mode.
ca::Vector< cbm::algo::ca::McHitInfo > fvHitDebugInfo
Container of hits with extended information.
static void writedir2current(TObject *obj)
static constexpr std::string_view kSTAPAlgoIDataSuffix
virtual InitStatus ReInit()
Reruns the initialization.
TFile * fpMcTripletsOutFile
File to save MC-triplets tree.
Class to handle QA-objects in the online reconstruction.
int GetStationId() const
Gets global index of active tracking station.
A container for all external parameters of the CA tracking algorithm.
Class representing an output track in the CA tracking algorithm.
TrackParam_t fParFirst
Track parameters on the first station.
int fNofHits
Number of hits in track.
static Debugger & Instance()
Instance.
virtual void Write()=0
Write ntuples to the file.
T Tx() const
Gets slope along x-axis.
T X() const
Gets x position [cm].
T Y() const
Gets y position [cm].
T Qp() const
Gets charge over momentum [ec/GeV].
T Z() const
Gets z position [cm].
T Time() const
Gets time [ns].
void Set(const TrackParamBase< T1 > &Tb)
T Ty() const
Gets slope along y-axis.
Class CbmCaPerformance is an interface to communicate between.
Builds parameters for CBM CA tracking.
void SetRequireHitPresence(bool requireHitPresence)
Sets hit presence requirement.
A reader of time slice for CA tracker.
MonitorData< ECounter, ETimer > TrackingMonitorData
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
EFieldMode
Enumiration for the magnetic field representation variants in the track fitting algorithm.
cbm::core::EnumArray< ca::EDetectorID, T > DetIdArr_t
Alias to array, indexed by L1DetectorID enum.
constexpr DetIdArr_t< ca::EDetectorID > kDetIds
List of detector.
static void Store(const Parameters< double > ¶meters, const std::string &fileName)
Stores parameter to file.
static Parameters< Float > Load(const std::string &fileName)
Loads parameters from file.
A floating-point tag for tag dispatching.