22#include "FairRootManager.h"
73 throw std::logic_error(
"Tracking parameters object was not defined");
76 throw std::logic_error(
"Hit index container was not defined");
83 for (
int iDet = 0; iDet < static_cast<int>(ca::EDetectorID::END); ++iDet) {
85 throw std::logic_error(std::string(
kDetName[iDet]) +
" hits branch is not found");
92 throw std::logic_error(
"StsTrack branch is unavailable");
97 throw std::logic_error(
"GlobalTrack branch is unavailable");
100 throw std::logic_error(
"StsTrack branch is not found");
103 throw std::logic_error(
"MuchTrack branch is not found");
106 throw std::logic_error(
"TrdTrack branch is not found");
109 throw std::logic_error(
"TofTrack branch is not found");
119 LOG(info) <<
"TimeSliceReader: initializing run ... ";
130 auto* pFairManager = FairRootManager::Instance();
131 LOG_IF(fatal, !pFairManager) <<
"TimeSliceReader: FairRootManager was not defined";
136 auto InitHitBranch = [&](
ca::EDetectorID detID,
const char* branchName) ->
bool {
138 fvpBrHits[detID] =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(branchName));
140 return static_cast<bool>(
fvpBrHits[detID]);
143 InitHitBranch(ca::EDetectorID::kMvd,
"MvdHit");
144 InitHitBranch(ca::EDetectorID::kSts,
"StsHit");
145 InitHitBranch(ca::EDetectorID::kMuch,
"MuchPixelHit");
146 InitHitBranch(ca::EDetectorID::kTrd,
"TrdHit");
147 if (!InitHitBranch(ca::EDetectorID::kTof,
"TofCalHit")) {
148 LOG(warn) <<
"TimeSliceReader: TofCalHit branch not found, trying to get TofHit branch of uncalibrated hits";
149 InitHitBranch(ca::EDetectorID::kTof,
"TofHit");
157 fpBrRecoTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"StsTrack"));
160 fpBrRecoTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"GlobalTrack"));
162 fpBrStsTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"StsTrack"));
165 fpBrMuchTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"MuchTrack"));
168 fpBrTrdTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"TrdTrack"));
171 fpBrTofTracks =
dynamic_cast<TClonesArray*
>(pFairManager->GetObject(
"TofTrack"));
184 LOG(info) <<
"TimeSliceReader: initializing run ... " <<
clrs::GNb <<
"done" <<
clrs::CL;
187catch (
const std::logic_error& error) {
188 LOG(info) <<
"TimeSliceReader: initializing run ... " <<
clrs::RDb <<
"failed" <<
clrs::CL
189 <<
"\nReason: " << error.what();
216 for (
int iT = 0; iT < nTracks; ++iT) {
219 auto& track = (*fpvTracks)[iT];
223 track.ChiSq() = pInputTrack->GetChiSq();
224 track.Ndf() = pInputTrack->GetNDF();
225 track.Tpv.Time() = pInputTrack->GetStartTime();
226 track.Tpv.C55() = pInputTrack->GetStartTimeError();
227 track.Time() = pInputTrack->GetFirstHitTime();
228 track.C55() = pInputTrack->GetFirstHitTimeError();
229 track.TLast.Time() = pInputTrack->GetLastHitTime();
230 track.TLast.C55() = pInputTrack->GetLastHitTimeError();
232 track.Hits.reserve(pInputTrack->GetTotalNofHits());
233 for (
int iH = 0; iH < pInputTrack->GetNofMvdHits(); ++iH) {
234 int iHext = pInputTrack->GetMvdHitIndex(iH);
236 track.Hits.push_back(iHint);
238 for (
int iH = 0; iH < pInputTrack->GetNofStsHits(); ++iH) {
239 int iHext = pInputTrack->GetStsHitIndex(iH);
241 track.Hits.push_back(iHint);
250 for (
int iT = 0; iT < nTracks; ++iT) {
253 auto& track = (*fpvTracks)[iT];
256 track.ChiSq() = pInputTrack->GetChi2();
257 track.Ndf() = pInputTrack->GetNDF();
262 int iStsTrkId = pInputTrack->GetStsTrackIndex();
263 if (iStsTrkId > -1) {
266 for (
int iH = 0; iH < pStsTrack->GetNofMvdHits(); ++iH) {
267 int iHext = pStsTrack->GetMvdHitIndex(iH);
269 track.Hits.push_back(iHint);
272 for (
int iH = 0; iH < pStsTrack->GetNofStsHits(); ++iH) {
273 int iHext = pStsTrack->GetStsHitIndex(iH);
275 track.Hits.push_back(iHint);
282 int iMuchTrkId = pInputTrack->GetMuchTrackIndex();
283 if (iMuchTrkId > -1) {
285 for (
int iH = 0; iH < pMuchTrack->GetNofHits(); ++iH) {
286 int iHext = pMuchTrack->GetHitIndex(iH);
288 track.Hits.push_back(iHint);
295 int iTrdTrkId = pInputTrack->GetTrdTrackIndex();
296 if (iTrdTrkId > -1) {
298 for (
int iH = 0; iH < pTrdTrack->GetNofHits(); ++iH) {
299 int iHext = pTrdTrack->GetHitIndex(iH);
301 track.Hits.push_back(iHint);
308 int iTofTrkId = pInputTrack->GetTofTrackIndex();
309 if (iTofTrkId > -1) {
311 for (
int iH = 0; iH < pTofTrack->GetNofHits(); ++iH) {
312 int iHext = pTofTrack->GetHitIndex(iH);
314 track.Hits.push_back(iHint);
327 LOG_IF(fatal, !pIODataManager.get()) <<
"TimeSliceReader: passed null pointer as a ca::DataManager instance";
335 int nStationsActive =
fpParameters->GetNstationsActive();
337 std::vector<int> vHitFstIndexes(nStationsActive + 1, 0);
338 std::vector<int> vNofHitsStored(nStationsActive, 0);
342 std::for_each(
fpvQaHits->begin(),
fpvQaHits->end(), [&](
const auto&
h) { ++vHitFstIndexes[h.GetStationId() + 1]; });
343 for (
int iSt = 0; iSt < nStationsActive; ++iSt) {
344 vHitFstIndexes[iSt + 1] += vHitFstIndexes[iSt];
347 int iSt = hit.GetStationId();
348 vNewHits[vHitFstIndexes[iSt] + (vNofHitsStored[iSt]++)] = hit;
359template<ca::EDetectorID DetID>
364 if (!fvbUseDet[DetID]) {
368 const auto* pDetInterface = fvpDetInterface[DetID];
369 int nHitsTot = fpEvent ? fpEvent->GetNofData(
kCbmHitType[DetID]) : fvpBrHits[DetID]->GetEntriesFast();
372 fFirstHitKey = fNofHitKeys;
374 for (
int iH = 0; iH < nHitsTot; ++iH) {
375 int iHext = fpEvent ? fpEvent->GetIndex(
kCbmHitType[DetID], iH) : iH;
377 LOG(warn) <<
"TimeSliceReader: hit index stored in the event is negative: " << iHext;
382 auto* pHit =
static_cast<Hit_t*
>(fvpBrHits[DetID]->At(iHext));
383 int iStGeom = pDetInterface->GetTrackingStationIndex(pHit);
389 if constexpr (ca::EDetectorID::kSts == DetID) {
390 hitRecord.
fStripF = fFirstHitKey + pHit->GetFrontClusterId();
391 hitRecord.
fStripB = fFirstHitKey + pHit->GetBackClusterId();
393 else if constexpr (ca::EDetectorID::kTof == DetID) {
401 int iStActive = fpParameters->GetStationIndexActive(iStGeom, DetID);
407 hitRecord.
fStaId = iStActive;
408 hitRecord.
fX = pHit->GetX();
409 hitRecord.
fY = pHit->GetY();
410 hitRecord.
fZ = pHit->GetZ();
411 hitRecord.
fDx2 = pHit->GetDx() * pHit->GetDx();
412 hitRecord.
fDy2 = pHit->GetDy() * pHit->GetDy();
413 hitRecord.
fDxy = pHit->GetDxy();
414 hitRecord.
fT = pHit->GetTime();
415 hitRecord.
fDt2 = pHit->GetTimeError() * pHit->GetTimeError();
418 hitRecord.
fDx2 += fpParameters->GetMisalignmentXsq(DetID);
419 hitRecord.
fDy2 += fpParameters->GetMisalignmentYsq(DetID);
420 hitRecord.
fDt2 += fpParameters->GetMisalignmentTsq(DetID);
422 std::tie(hitRecord.
fRangeX, hitRecord.
fRangeY, hitRecord.
fRangeT) = pDetInterface->GetHitRanges(*pHit);
424 hitRecord.
fDet =
static_cast<int>(DetID);
425 hitRecord.
fDataStream = (
static_cast<int64_t
>(hitRecord.
fDet) << 60) | pHit->GetAddress();
433 || fabs(pHit->GetZ() - station.
GetZ<
fscal>()) > 150) {
435 <<
" hit is outside of the station boundaries: " << hitRecord.
ToString() <<
"; station X "
443 if constexpr (ca::EDetectorID::kSts == DetID) {
444 if (fNofHitKeys <= hitRecord.
fStripF) {
445 fNofHitKeys = hitRecord.
fStripF + 1;
447 if (fNofHitKeys <= hitRecord.
fStripB) {
448 fNofHitKeys = hitRecord.
fStripB + 1;
452 hitRecord.
fStripF = fFirstHitKey + iHext;
454 if (fNofHitKeys <= hitRecord.
fStripF) {
455 fNofHitKeys = hitRecord.
fStripF + 1;
461 this->StoreHitRecord(hitRecord);
478 for (
int iDet = 0; iDet < static_cast<int>(ca::EDetectorID::END); ++iDet) {
509 for (uint32_t iDet = 0; iDet <
fvNofHitsUsed.size(); ++iDet) {
515 LOG(debug) <<
"CA: N hits used/tot = " <<
fNofHits <<
"/" << nHitsTot;
530 auto ResetIndexMap = [&](
auto& m)
mutable { m.clear(); };
532 for (
int iH = 0; iH <
fNofHits; ++iH) {
533 const auto& hit = (*fpvQaHits)[iH];
577 aHitQa.
x = hitRecord.
fX;
578 aHitQa.
y = hitRecord.
fY;
579 aHitQa.
z = hitRecord.
fZ;
583 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.
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,...
size_t GetNofData() const
uint32_t GetIndex(ECbmDataType type, uint32_t iData) const
int ExtIndex
index of hit in the external branch
int Det
detector subsystem ID
double dy
y coordinate error [cm]
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 dx
x coordinate error [cm]
double dxy
covariance between x and y [cm2]
double z
z coordinate of position [cm]
double x
x coordinate of position [cm]
static constexpr const char * GetDetectorName(ca::EDetectorID detectorID)
Utility to map the L1DetectorID items into detector names.
static CbmMuchTrackingInterface * Instance()
Gets pointer to the instance of the CbmMuchTrackingInterface.
static CbmMvdTrackingInterface * Instance()
Gets pointer to the instance of the CbmMvdTrackingInterface.
static CbmStsTrackingInterface * Instance()
Gets pointer to the instance of the CbmStsTrackingInterface class.
static int32_t GetSmType(uint32_t address)
static CbmTofTrackingInterface * Instance()
Gets pointer to the instance of the CbmTofTrackingInterface.
static CbmTrdTrackingInterface * Instance()
Gets pointer to the instance of the CbmTrdTrackingInterface.
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.
DataOut GetXmax() const
Gets limit of the station size in x-axis direction.
DataOut GetYmax() const
Gets limit of the station size in y-axis direction.
DataOut GetXmin() const
Gets limit of the station size in x-axis direction.
DataOut GetYmin() const
Gets limit of the station size in y-axis direction.
DataOut GetZ() const
Gets z-position of the station.
void SetName(const std::string &s)
Sets the name of the vector.
void push_back(Tinput value)
Pushes back a value to the vector.
std::string GetName() const
Gets name of the vector.
void reserve(std::size_t count)
Reserves a new size for the vector.
void reset(std::size_t count, Tinput... value)
Clears vector and resizes it to the selected size with selected values.
void emplace_back(Tinput &&... value)
Creates a parameter in the end of the vector.
A reader of time slice for CA tracker.
TClonesArray * fpBrTrdTracks
Input branch for reconstructed TRD tracks ("TrdTrack")
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.
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")
std::shared_ptr< ca::Parameters< float > > fpParameters
Pointer to tracking parameters object.
ca::Vector< CbmL1HitDebugInfo > * fpvQaHits
Pointer to array of debug hits.
DetIdArr_t< const CbmTrackingDetectorInterfaceBase * > fvpDetInterface
Pointers to the tracking detector interfaces for each subsystem.
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.
void Clear()
Clears class content.
constexpr char RDb[]
bold red
constexpr char GNb[]
bold green
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
constexpr DetIdArr_t< ECbmDataType > kCbmHitType
Data type of hits (for CbmEvent)
constexpr DetIdArr_t< const char * > kDetName
Names of detector subsystems.
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