24#include <FairRootManager.h>
77 throw std::logic_error(
"Tracking parameters object was not defined");
80 throw std::logic_error(
"Hit index container was not defined");
89 throw std::logic_error(std::string(
kDetName[iDet]) +
" hits branch is not found");
96 throw std::logic_error(
"StsTrack branch is unavailable");
101 throw std::logic_error(
"GlobalTrack branch is unavailable");
104 throw std::logic_error(
"StsTrack branch is not found");
107 throw std::logic_error(
"MuchTrack branch is not found");
110 throw std::logic_error(
"TrdTrack branch is not found");
113 throw std::logic_error(
"TofTrack branch is not found");
123 LOG(info) <<
"TimeSliceReader: initializing run ... ";
127 auto* pFairManager = FairRootManager::Instance();
128 LOG_IF(fatal, !pFairManager) <<
"TimeSliceReader: FairRootManager was not defined";
133 auto InitHitBranch = [&](
ca::EDetectorID detID,
const char* branchName) ->
bool {
135 fvpBrHits[detID] =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(branchName));
137 return static_cast<bool>(
fvpBrHits[detID]);
145 LOG(warn) <<
"TimeSliceReader: TofCalHit branch not found, trying to get TofHit branch of uncalibrated hits";
154 fpBrRecoTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"StsTrack"));
157 fpBrRecoTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"GlobalTrack"));
159 fpBrStsTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"StsTrack"));
162 fpBrMuchTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"MuchTrack"));
165 fpBrTrdTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"TrdTrack"));
168 fpBrTofTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"TofTrack"));
176 if (!pRecoSetupMan->IsInitialized()) {
182 throw std::runtime_error(fmt::format(
"Det ID {} is not in RecoSetup",
static_cast<int>(detId)));
199 LOG(info) <<
"TimeSliceReader: initializing run ... " <<
clrs::GNb <<
"done" <<
clrs::CL;
202catch (
const std::logic_error& error) {
203 LOG(info) <<
"TimeSliceReader: initializing run ... " <<
clrs::RDb <<
"failed" <<
clrs::CL
204 <<
"\nReason: " << error.what();
231 for (
int iT = 0; iT < nTracks; ++iT) {
234 auto& track = (*fpvTracks)[iT];
238 track.ChiSq() = pInputTrack->GetChiSq();
239 track.Ndf() = pInputTrack->GetNDF();
240 track.Tpv.Time() = pInputTrack->GetStartTime();
241 track.Tpv.C55() = pInputTrack->GetStartTimeError();
242 track.Time() = pInputTrack->GetFirstHitTime();
243 track.C55() = pInputTrack->GetFirstHitTimeError();
244 track.TLast.Time() = pInputTrack->GetLastHitTime();
245 track.TLast.C55() = pInputTrack->GetLastHitTimeError();
247 track.Hits.reserve(pInputTrack->GetTotalNofHits());
248 for (
int iH = 0; iH < pInputTrack->GetNofMvdHits(); ++iH) {
249 int iHext = pInputTrack->GetMvdHitIndex(iH);
251 track.Hits.push_back(iHint);
253 for (
int iH = 0; iH < pInputTrack->GetNofStsHits(); ++iH) {
254 int iHext = pInputTrack->GetStsHitIndex(iH);
256 track.Hits.push_back(iHint);
265 for (
int iT = 0; iT < nTracks; ++iT) {
268 auto& track = (*fpvTracks)[iT];
271 track.ChiSq() = pInputTrack->GetChi2();
272 track.Ndf() = pInputTrack->GetNDF();
277 int iStsTrkId = pInputTrack->GetStsTrackIndex();
278 if (iStsTrkId > -1) {
281 for (
int iH = 0; iH < pStsTrack->GetNofMvdHits(); ++iH) {
282 int iHext = pStsTrack->GetMvdHitIndex(iH);
284 track.Hits.push_back(iHint);
287 for (
int iH = 0; iH < pStsTrack->GetNofStsHits(); ++iH) {
288 int iHext = pStsTrack->GetStsHitIndex(iH);
290 track.Hits.push_back(iHint);
297 int iMuchTrkId = pInputTrack->GetMuchTrackIndex();
298 if (iMuchTrkId > -1) {
300 for (
int iH = 0; iH < pMuchTrack->GetNofHits(); ++iH) {
301 int iHext = pMuchTrack->GetHitIndex(iH);
303 track.Hits.push_back(iHint);
310 int iTrdTrkId = pInputTrack->GetTrdTrackIndex();
311 if (iTrdTrkId > -1) {
313 for (
int iH = 0; iH < pTrdTrack->GetNofHits(); ++iH) {
314 int iHext = pTrdTrack->GetHitIndex(iH);
316 track.Hits.push_back(iHint);
323 int iTofTrkId = pInputTrack->GetTofTrackIndex();
324 if (iTofTrkId > -1) {
326 for (
int iH = 0; iH < pTofTrack->GetNofHits(); ++iH) {
327 int iHext = pTofTrack->GetHitIndex(iH);
329 track.Hits.push_back(iHint);
342 LOG_IF(fatal, !pIODataManager.get()) <<
"TimeSliceReader: passed null pointer as a ca::DataManager instance";
350 int nStationsActive =
fpParameters->GetNstationsActive();
352 std::vector<int> vHitFstIndexes(nStationsActive + 1, 0);
353 std::vector<int> vNofHitsStored(nStationsActive, 0);
357 std::for_each(
fpvQaHits->begin(),
fpvQaHits->end(), [&](
const auto&
h) { ++vHitFstIndexes[h.GetStationId() + 1]; });
358 for (
int iSt = 0; iSt < nStationsActive; ++iSt) {
359 vHitFstIndexes[iSt + 1] += vHitFstIndexes[iSt];
362 int iSt = hit.GetStationId();
363 vNewHits[vHitFstIndexes[iSt] + (vNofHitsStored[iSt]++)] = hit;
374template<ca::EDetectorID DetID>
389 for (
int iH = 0; iH < nHitsTot; ++iH) {
392 LOG(warn) <<
"TimeSliceReader: hit index stored in the event is negative: " << iHext;
397 auto* pHit =
static_cast<Hit_t*
>(
fvpBrHits[DetID]->At(iHext));
398 int iStGeom = pDetInterface->GetTrackingStationId(pHit->GetAddress());
416 int iStActive =
fpParameters->GetStationIndexActive(iStGeom, DetID);
422 hitRecord.
fStaId = iStActive;
423 hitRecord.
fX = pHit->GetX();
424 hitRecord.
fY = pHit->GetY();
425 hitRecord.
fZ = pHit->GetZ();
426 hitRecord.
fDx2 = pHit->GetDx() * pHit->GetDx();
427 hitRecord.
fDy2 = pHit->GetDy() * pHit->GetDy();
428 hitRecord.
fDxy = pHit->GetDxy();
429 hitRecord.
fT = pHit->GetTime();
430 hitRecord.
fDt2 = pHit->GetTimeError() * pHit->GetTimeError();
433 auto misalignmentTolerance =
fpParameters->GetConfig().GetMisalignmentTolerance(DetID);
434 hitRecord.
fDx2 += misalignmentTolerance.GetXsq();
435 hitRecord.
fDy2 += misalignmentTolerance.GetYsq();
436 hitRecord.
fDt2 += misalignmentTolerance.GetTimeSq();
438 auto hitRange = pDetInterface->GetHitRange(*pHit);
439 hitRecord.
fRangeX = hitRange.x;
440 hitRecord.
fRangeY = hitRange.y;
441 hitRecord.
fRangeT = hitRange.t;
442 hitRecord.
fDet =
static_cast<int>(DetID);
450 const auto& station =
fpParameters->GetActiveSetup().GetActiveLayer(iStActive);
451 if (pHit->GetX() < station.GetXmin() * 1.2 || pHit->GetX() > station.GetXmax() * 1.2
452 || pHit->GetY() < station.GetYmin() * 1.2 || pHit->GetY() > station.GetYmax() * 1.2
453 || fabs(pHit->GetZ() - station.GetZref()) > 150) {
455 <<
" hit is outside of the station boundaries: " << hitRecord.
ToString() <<
"; station X "
456 << station.GetXmin() <<
".." << station.GetXmax() <<
" Y " << station.GetYmin() <<
".."
457 << station.GetYmax() <<
" Z " << station.GetZref();
529 for (uint32_t iDet = 0; iDet <
fvNofHitsUsed.size(); ++iDet) {
535 LOG(debug) <<
"CA: N hits used/tot = " <<
fNofHits <<
"/" << nHitsTot;
550 auto ResetIndexMap = [&](
auto& m)
mutable { m.clear(); };
552 for (
int iH = 0; iH <
fNofHits; ++iH) {
553 const auto& hit = (*fpvQaHits)[iH];
597 aHitQa.
x = hitRecord.
fX;
598 aHitQa.
y = hitRecord.
fY;
599 aHitQa.
z = hitRecord.
fZ;
603 aHitQa.
time = hitRecord.
fT;
Compile-time constants definition for the CA tracking algorithm.
Time-slice/event reader for CA tracker in CBM (header)
@ kMCBM
Global tracking in mCBM (STS, MuCh, TRD, TOF), results stored to GlobalTrack branch.
@ kSTS
Local tracking in CBM (STS + MVD), results stored to the StsTrack branch.
A manager for setup representation in CBM reconstruction.
Data class for STS tracks.
friend fvec sqrt(const fvec &a)
Generates beam ions for transport simulation.
Class characterising one event by a collection of links (indices) to data objects,...
static constexpr const char * GetDetectorName(ca::EDetectorID detectorID)
Utility to map the L1DetectorID items into detector names.
static int32_t GetSmType(uint32_t address)
void Clear()
Clears class content.
const algo::RecoSetup & GetSetup() const
Setup accessor.
static RecoSetupManager * Instance()
Instance access.
const RecoSetupUnit_t< ModuleId > * Get() const
Access to a reconstruction setup unit.
ca::Hit class describes a generic hit for the CA tracker
void SetX(fscal x)
Set the X coordinate.
void SetRangeT(fscal rangeT)
Set the +/- range of uncertainty of time.
void SetDt2(fscal dt2)
Set the uncertainty of time.
void SetDy2(fscal dy2)
Set the uncertainty of Y coordinate.
void SetRangeY(fscal rangeY)
Set the +/- range of uncertainty of Y coordinate.
void SetStation(int station)
Set the station index.
void SetDx2(fscal dx2)
Set the uncertainty of X coordinate.
void SetRangeX(fscal rangeX)
Set the +/- range of uncertainty of X coordinate.
void SetZ(fscal z)
Set the Z coordinate.
void SetBackKey(HitKeyIndex_t key)
Set the back key index.
void SetFrontKey(HitKeyIndex_t key)
Set the front key index.
void SetId(HitIndex_t id)
Set the hit id.
void SetT(fscal t)
Set the time.
void SetDxy(fscal dxy)
Set the X/Y covariance.
void SetY(fscal y)
Set the Y coordinate.
double dy
y coordinate error [cm]
int Det
detector subsystem ID
double y
y coordinate of position [cm]
int IntIndex
index of hit in the internal array
int iStation
index of station in active stations array
double z
z coordinate of position [cm]
double dx
x coordinate error [cm]
double dxy
covariance between x and y [cm2]
double x
x coordinate of position [cm]
int ExtIndex
index of hit in the external branch
A reader of time slice for CA tracker.
TClonesArray * fpBrTrdTracks
Input branch for reconstructed TRD tracks ("TrdTrack")
std::shared_ptr< const ca::Parameters< double > > fpParameters
Pointer to tracking parameters object.
ca::Vector< CbmL1Track > * fpvTracks
Pointer to array of reconstructed tracks.
int fFirstHitKey
First index of hit key for the detector subsystem.
void ReadRecoTracks()
Reads reconstructed tracks.
std::shared_ptr< ca::DataManager > fpIODataManager
Pointer to input data manager.
void ReadHits()
Reads hits.
void StoreHitRecord(const tools::HitRecord &hitRecord)
Saves hit to data structures.
TClonesArray * fpBrRecoTracks
Input branch for reconstructed tracks ("GlobalTrack", "StsTrack")
TClonesArray * fpBrTofTracks
Input branch for reconstructed TOF tracks ("TofTrack")
TClonesArray * fpBrStsTracks
Input branch for reconstructed STS tracks ("StsTrack")
int fNofHitKeys
Recorded number of hit keys.
DetIdArr_t< bool > fvbUseDet
Flag: is detector subsystem used.
DetIdArr_t< TClonesArray * > fvpBrHits
Input branch for hits.
void ReadEvent(CbmEvent *pEvent=nullptr)
Reads time slice.
void SortQaHits()
Sorts QA hit objects by stations.
ECbmCaTrackingMode fTrackingMode
Tracking mode.
ca::Vector< cbm::algo::ca::McHitInfo > * fpvQaHits
Pointer to array of debug hits.
std::array< int, constants::size::MaxNdetectors+1 > fvHitFirstIndexDet
First hit index in detector.
DetIdArr_t< int > fvNofHitsUsed
Number of used hits in detector.
CbmEvent * fpEvent
Pointer to the event object.
TClonesArray * fpBrMuchTracks
Input branch for reconstructed MuCh tracks ("MuchTrack")
int ReadHitsForDetector()
Reads hits for a given detector subsystem.
int fNofHits
Stored number of hits.
void RegisterIODataManager(std::shared_ptr< ca::DataManager > &ioDataManager)
Registers the CA IO data manager instance.
DetIdArr_t< std::unordered_map< int, int > > fvmHitExtToIntIndexMap
Hit index map ext -> int.
bool InitRun()
Run initializer function.
ca::Vector< CbmL1HitId > * fpvHitIds
Pointer to array of hit index objects.
bool fbSortQaHits
Flag, if the QA hits must be sorted after reading.
void CheckInit() const
Check class initialization.
DetIdArr_t< int > fvNofHitsTotal
Total hit number in detector.
constexpr char RDb[]
bold red
constexpr char GNb[]
bold green
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
constexpr ECbmModuleId ToCbmModuleId(EDetectorID detID)
Conversion map from EDetectorID to ECbmModuleId.
constexpr DetIdArr_t< ECbmDataType > kCbmHitType
Data type of hits (for CbmEvent)
constexpr DetIdArr_t< const char * > kDetName
Names of detector subsystems.
constexpr DetIdArr_t< uint32_t > kCbmDatastreamBitmask
Bit-masks to define a data-stream (within this HW level the hits must be sorted in time) FIXME: Put i...
cbm::algo::kf::TrackParamD ConvertTrackParam(const FairTrackParam &par)
copy fair track param to Ca track param
std::tuple_element_t< static_cast< std::size_t >(DetID), std::tuple< Types... > > at