10#ifndef CbmCaMCModule_h
11#define CbmCaMCModule_h 1
34#include "TClonesArray.h"
35#include "TDatabasePDG.h"
50 namespace ca = cbm::algo::ca;
104 template<ca::EDetectorID DetId>
171 template<ca::EDetectorID DetID>
241 const std::array<int, constants::size::MaxNdetectors + 1>*
fpvFstHitId =
nullptr;
251 template<ca::EDetectorID DetID>
252 std::optional<algo::ca::McPoint>
FillMCPoint(
int iExtId,
int iEvent,
int iFile);
261 template<ca::EDetectorID DetID>
272 template<ca::EDetectorID DetID>
276 std::vector<int> vPoints;
279 LOG(warn) <<
"Hit match with index " << iHitExt <<
" is missing for " <<
kDetName[DetID];
295 return std::tuple(iPoint, vPoints);
298 for (
int iLink = 0; iLink < pHitMatch->GetNofLinks(); ++iLink) {
299 const auto& link = pHitMatch->GetLink(iLink);
300 int iPointExt = link.GetIndex();
301 int iEvent = link.GetEntry();
302 int iFile = link.GetFile();
303 if (iPointExt < 0)
continue;
304 int id =
fpMcData->FindInternalPointIndex(DetID, iPointExt, iEvent, iFile);
305 vPoints.push_back(
id);
308 if (pHitMatch->GetNofLinks() > 0) {
309 const auto& link = pHitMatch->GetMatchedLink();
310 if (link.GetIndex() > -1) {
311 int index = link.GetIndex();
312 int event = link.GetEntry();
313 int file = link.GetFile();
314 iPoint =
fpMcData->FindInternalPointIndex(DetID, index, event, file);
318 return std::tuple(iPoint, vPoints);
323 template<ca::EDetectorID DetID>
326 auto oPoint = std::make_optional<ca::McPoint>();
341 LOG(warn) <<
"CbmCaMCModule: " <<
kDetName[DetID] <<
" MC point with iExtId = " << iExtId
342 <<
", iEvent = " << iEvent <<
", iFile = " << iFile <<
" does not exist";
346 pExtPoint->Position(posIn);
347 pExtPoint->PositionOut(posOut);
348 pExtPoint->Momentum(momIn);
349 pExtPoint->MomentumOut(momOut);
353 pExtPoint->Position(posIn);
354 pExtPoint->PositionOut(posOut);
355 pExtPoint->Momentum(momIn);
356 pExtPoint->MomentumOut(momOut);
360 pExtPoint->Position(posIn);
361 pExtPoint->PositionOut(posOut);
362 pExtPoint->Momentum(momIn);
363 pExtPoint->Momentum(momOut);
367 pExtPoint->Position(posIn);
368 pExtPoint->PositionOut(posOut);
369 pExtPoint->Momentum(momIn);
370 pExtPoint->MomentumOut(momOut);
374 pExtPoint->Position(posIn);
375 pExtPoint->Position(posOut);
376 pExtPoint->Momentum(momIn);
377 pExtPoint->Momentum(momOut);
379 double time = pExtPoint->GetTime();
380 int iTmcExt = pExtPoint->GetTrackID();
383 LOG(warn) <<
"CbmCaMCModule: For MC point with iExtId = " << iExtId <<
", iEvent = " << iEvent
384 <<
", iFile = " << iFile <<
" MC track is undefined (has ID = " << iTmcExt <<
')';
387 TVector3 posMid = 0.5 * (posIn + posOut);
388 TVector3 momMid = 0.5 * (momIn + momOut);
391 int iStLoc = pRecoUnit->GetTrackingStationId(pExtPoint->GetDetectorID());
396 int stationID =
fpParameters->GetStationIndexActive(iStLoc, DetID);
408 if ((startT > 0. && time < startT) || (endT > 0. && time > endT)) {
409 LOG(warn) <<
"CbmCaMCModule: MC point with iExtId = " << iExtId <<
", iEvent = " << iEvent
410 <<
", iFile = " << iFile <<
" and det id " << int(DetID) <<
" fell out of the TS duration [" << startT
411 <<
", " << endT <<
"] with measured time = " << time <<
" [ns]";
417 oPoint->SetExternalId(
fpMcData->GetPointGlobExtIndex(DetID, iExtId));
418 oPoint->SetEventId(iEvent);
419 oPoint->SetFileId(iFile);
420 oPoint->SetTime(time);
421 oPoint->SetX(posMid.X());
422 oPoint->SetY(posMid.Y());
423 oPoint->SetZ(posMid.Z());
424 oPoint->SetXIn(posIn.X());
425 oPoint->SetYIn(posIn.Y());
426 oPoint->SetZIn(posIn.Z());
427 oPoint->SetXOut(posOut.X());
428 oPoint->SetYOut(posOut.Y());
429 oPoint->SetZOut(posOut.Z());
430 oPoint->SetPx(momMid.X());
431 oPoint->SetPy(momMid.Y());
432 oPoint->SetPz(momMid.Z());
433 oPoint->SetPxIn(momIn.X());
434 oPoint->SetPyIn(momIn.Y());
435 oPoint->SetPzIn(momIn.Z());
436 oPoint->SetPxOut(momOut.X());
437 oPoint->SetPyOut(momOut.Y());
438 oPoint->SetPzOut(momOut.Z());
441 oPoint->SetId(
fpMcData->GetNofPoints());
444 int iTmcInt =
fpMcData->FindInternalTrackIndex(iTmcExt, iEvent, iFile);
446 oPoint->SetTrackId(iTmcInt);
448 fpMcData->GetTrack(iTmcInt).AddPointIndex(oPoint->GetId());
451 oPoint->SetActiveStationId(stationID);
452 oPoint->SetDetectorId(DetID);
453 oPoint->SetLocalStationId(iStLoc);
457 LOG(warn) <<
"CbmCaMCModule: MC track with iTmcExt = " << iTmcExt <<
", iEvent = " << iEvent
458 <<
", iFile = " << iFile <<
" MC track is undefined (nullptr)";
461 oPoint->SetPdgCode(pExtTrk->GetPdgCode());
464 auto* pPdgDB = TDatabasePDG::Instance()->GetParticle(oPoint->GetPdgCode());
465 oPoint->SetMass(pPdgDB ? pPdgDB->Mass() : 0.);
466 oPoint->SetCharge(pPdgDB ? pPdgDB->Charge() / 3. : 0.);
473 template<ca::EDetectorID DetID>
480 for (
int iH = (*
fpvFstHitId)[
static_cast<int>(DetID)]; iH < (*fpvFstHitId)[static_cast<int>(DetID) + 1]; ++iH) {
481 auto& hit = (*fpvQaHits)[iH];
484 hit.SetBestMcPointId(iBestP);
486 for (
auto iP : vAllP) {
488 hit.AddMcPointId(iP);
489 fpMcData->GetPoint(iP).AddHitID(iH);
496 template<ca::EDetectorID DetID>
503 int nPointsEvent =
fvpBrPoints[DetID]->Size(iFile, iEvent);
504 for (
int iP = 0; iP < nPointsEvent; ++iP) {
Data structure for internal tracking MC-information (header)
Internal class describing a MC point for CA tracking QA and performance (header)
CA Tracking monitor class.
Implementation of L1DetectorID enum class for CBM.
A manager for setup representation in CBM reconstruction.
Class characterising one event by a collection of links (indices) to data objects,...
Access to a MC data branch for time-based analysis.
Access to a MC data branch for time-based analysis.
Container class for MC events with number, file and start time.
void SetMotherId(int32_t id)
Bookkeeping of time-slice 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.
This class represents a package for tracking-related data.
Monitor class for the CA tracking.
A container for all external parameters of the CA tracking algorithm.
std::tuple< int, std::vector< int > > MatchHitWithMc(int iHitExt)
Matches hit with MC point.
void ReadMCTracks()
Reads MC tracks from external trees and saves them to MCDataObject.
MCModule & operator=(const MCModule &)=delete
Copy assignment operator.
void InitEvent(CbmEvent *pEvent)
Defines performance action in the beginning of each event or time slice.
void Finish()
Defines performance action in the end of the run.
MCModule & operator=(MCModule &&)=delete
Move assignment operator.
void CheckInit() const
Check class initialization.
CbmMCEventList * fpMCEventList
MC event list.
void RegisterQaHitContainer(ca::Vector< cbm::algo::ca::McHitInfo > &vQaHits)
Registers debug hit container.
int fBestMcFile
Index of bestly matched MC file.
void ProcessEvent(CbmEvent *pEvent)
Processes event.
ca::Vector< algo::ca::McHitInfo > * fpvQaHits
Pointer to QA hit container.
ca::Vector< CbmL1HitId > * fpvHitIds
Pointer to hit index container.
void InitMcTrackInfo()
Initializes MC track.
void ReadMCPoints()
Reads MC points from external trees and saves them to MCDataObject.
void RegisterFirstHitIndexes(const std::array< int, constants::size::MaxNdetectors+1 > &source)
Sets first hit indexes container in different detectors.
ca::Monitor< EMonitorKey > fMonitor
Monitor.
int GetVerbosity() const
Gets verbosity level.
DetIdArr_t< bool > fvbUseDet
Flag: is detector subsystem used.
std::unordered_map< uint32_t, double > fmTofRpcZpos
A map of TOF RPC reference z-position vs. address.
const std::array< int, constants::size::MaxNdetectors+1 > * fpvFstHitId
Pointer to array of first hit indexes in the detector subsystem.
void SetDetector(ca::EDetectorID detID, bool flag)
Sets used detector subsystems.
algo::ca::McData * fpMcData
MC information (hits and tracks) instance.
int fVerbose
Verbosity level.
void RegisterParameters(std::shared_ptr< const ca::Parameters< double > > &pParameters)
Registers CA parameters object.
~MCModule()=default
Destructor.
DetIdArr_t< CbmMCDataArray * > fvpBrPoints
Array of points vs. detector.
void MatchRecoAndMCTracks()
Matches reconstructed tracks with MC tracks.
CbmMCDataObject * fpMCEventHeader
MC event header.
void ReadMCPointsForDetector()
Reads MC points in particular detector.
@ kMissedMatchesMvd
Number of missed matches in MVD.
@ kMissedMatchesTof
Number of missed TOF matches.
@ kMissedMatchesTrd
Number of missed matches in TRD.
@ kMcPoint
Number of MC points.
@ kMissedMatchesMuch
Number of missed matches in MuCh.
@ kRecoNevents
Number of events.
@ kMissedMatchesSts
Number of missed matches in STS.
@ kMcTrack
Number of MC tracks.
@ kMcTrackReconstructable
Number of reconstructable MC tracks.
std::optional< algo::ca::McPoint > FillMCPoint(int iExtId, int iEvent, int iFile)
Fills a single detector-specific MC point.
void MatchPointsAndHits()
Match sets of MC points and reconstructed hits for a given detector.
std::set< std::pair< int, int > > fFileEventIDs
Set of file and event indexes: first - iFile, second - iEvent.
bool InitRun()
Defines action on the module in the beginning of the run.
int fBestMcEvent
Index of bestly matched MC event.
ca::Vector< CbmL1Track > * fpvRecoTracks
Pointer to reconstructed track container.
MCModule(const MCModule &)=delete
Copy constructor.
void RegisterRecoTrackContainer(ca::Vector< CbmL1Track > &vRecoTracks)
Registers reconstructed track container.
DetIdArr_t< TClonesArray * > fvpBrHitMatches
Array of hit match branches vs. detector.
void RegisterMcData(cbm::algo::ca::McData &mcData)
Registers MC data object.
CbmMCDataArray * fpMCTracks
MC tracks input.
std::shared_ptr< const ca::Parameters< double > > fpParameters
Pointer to tracking parameters object.
void MatchHits()
Match reconstructed hits and MC points.
MCModule(int verb=1, int perfMode=1)
Constructor.
MCModule(MCModule &&)=delete
Move constructor.
void RegisterHitIndexContainer(ca::Vector< CbmL1HitId > &vHitIds)
Registers hit index container.
const CbmTimeSlice * fpTimeSlice
Current time slice.
const cbm::algo::ca::McData * GetMcData() const
Gets a pointer to MC data object.
void MatchTracks()
Match reconstructed and MC data.
int fPerformanceMode
Mode of performance.
TODO: SZh 8.11.2022: add selection of parameterisation.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
constexpr ECbmModuleId ToCbmModuleId(EDetectorID detID)
Conversion map from EDetectorID to ECbmModuleId.
constexpr DetIdArr_t< const char * > kDetName
Names of detector subsystems.
cbm::core::EnumArray< ca::EDetectorID, T > DetIdArr_t
Alias to array, indexed by L1DetectorID enum.
std::tuple_element_t< static_cast< std::size_t >(DetID), std::tuple< Types... > > at