10#ifndef CbmCaMCModule_h
11#define CbmCaMCModule_h 1
37#include "TClonesArray.h"
38#include "TDatabasePDG.h"
107 template<ca::EDetectorID DetId>
174 template<ca::EDetectorID DetID>
195 template<ca::EDetectorID DetID>
206 template<ca::EDetectorID DetID>
207 std::optional<tools::MCPoint>
FillMCPoint(
int iExtId,
int iEvent,
int iFile);
260 const std::array<int, constants::size::MaxNdetectors + 1>*
fpvFstHitId =
nullptr;
270 template<ca::EDetectorID DetID>
274 std::vector<int> vPoints;
277 LOG(warn) <<
"Hit match with index " << iHitExt <<
" is missing for " <<
kDetName[DetID];
278 if constexpr (ca::EDetectorID::kMvd == DetID) {
281 else if constexpr (ca::EDetectorID::kSts == DetID) {
284 else if constexpr (ca::EDetectorID::kMuch == DetID) {
287 else if constexpr (ca::EDetectorID::kTrd == DetID) {
290 else if constexpr (ca::EDetectorID::kTof == DetID) {
293 return std::tuple(iPoint, vPoints);
296 for (
int iLink = 0; iLink < pHitMatch->GetNofLinks(); ++iLink) {
297 const auto& link = pHitMatch->GetLink(iLink);
298 int iPointExt = link.GetIndex();
299 int iEvent = link.GetEntry();
300 int iFile = link.GetFile();
301 if (iPointExt < 0)
continue;
303 vPoints.push_back(
id);
306 if (pHitMatch->GetNofLinks() > 0) {
307 const auto& link = pHitMatch->GetMatchedLink();
308 if (link.GetIndex() > -1) {
309 int index = link.GetIndex();
310 int event = link.GetEntry();
311 int file = link.GetFile();
316 return std::tuple(iPoint, vPoints);
321 template<ca::EDetectorID DetID>
324 auto oPoint = std::make_optional<tools::MCPoint>();
336 LOG(warn) <<
"CbmCaMCModule: " <<
kDetName[DetID] <<
" MC point with iExtId = " << iExtId
337 <<
", iEvent = " << iEvent <<
", iFile = " << iFile <<
" does not exist";
340 if constexpr (ca::EDetectorID::kMvd == DetID) {
341 pExtPoint->Position(posIn);
342 pExtPoint->PositionOut(posOut);
343 pExtPoint->Momentum(momIn);
344 pExtPoint->MomentumOut(momOut);
347 else if constexpr (ca::EDetectorID::kSts == DetID) {
348 pExtPoint->Position(posIn);
349 pExtPoint->PositionOut(posOut);
350 pExtPoint->Momentum(momIn);
351 pExtPoint->MomentumOut(momOut);
354 else if constexpr (ca::EDetectorID::kMuch == DetID) {
355 pExtPoint->Position(posIn);
356 pExtPoint->PositionOut(posOut);
357 pExtPoint->Momentum(momIn);
358 pExtPoint->Momentum(momOut);
361 else if constexpr (ca::EDetectorID::kTrd == DetID) {
362 pExtPoint->Position(posIn);
363 pExtPoint->PositionOut(posOut);
364 pExtPoint->Momentum(momIn);
365 pExtPoint->MomentumOut(momOut);
368 else if constexpr (ca::EDetectorID::kTof == DetID) {
369 pExtPoint->Position(posIn);
370 pExtPoint->Position(posOut);
371 pExtPoint->Momentum(momIn);
372 pExtPoint->Momentum(momOut);
374 double time = pExtPoint->GetTime();
375 int iTmcExt = pExtPoint->GetTrackID();
378 LOG(warn) <<
"CbmCaMCModule: For MC point with iExtId = " << iExtId <<
", iEvent = " << iEvent
379 <<
", iFile = " << iFile <<
" MC track is undefined (has ID = " << iTmcExt <<
')';
382 TVector3 posMid = 0.5 * (posIn + posOut);
383 TVector3 momMid = 0.5 * (momIn + momOut);
386 int iStLoc =
fvpDetInterface[DetID]->GetTrackingStationIndex(pExtPoint);
391 int stationID =
fpParameters->GetStationIndexActive(iStLoc, DetID);
392 if (stationID == -1) {
401 if constexpr (DetID != ca::EDetectorID::kMvd) {
406 if ((startT > 0. && time < startT) || (endT > 0. && time > endT)) {
407 LOG(warn) <<
"CbmCaMCModule: MC point with iExtId = " << iExtId <<
", iEvent = " << iEvent
408 <<
", iFile = " << iFile <<
" and det id " << int(DetID) <<
" fell out of the TS duration [" << startT
409 <<
", " << endT <<
"] with measured time = " << time <<
" [ns]";
416 oPoint->SetEventId(iEvent);
417 oPoint->SetFileId(iFile);
418 oPoint->SetTime(time);
419 oPoint->SetX(posMid.X());
420 oPoint->SetY(posMid.Y());
421 oPoint->SetZ(posMid.Z());
422 oPoint->SetXIn(posIn.X());
423 oPoint->SetYIn(posIn.Y());
424 oPoint->SetZIn(posIn.Z());
425 oPoint->SetXOut(posOut.X());
426 oPoint->SetYOut(posOut.Y());
427 oPoint->SetZOut(posOut.Z());
428 oPoint->SetPx(momMid.X());
429 oPoint->SetPy(momMid.Y());
430 oPoint->SetPz(momMid.Z());
431 oPoint->SetPxIn(momIn.X());
432 oPoint->SetPyIn(momIn.Y());
433 oPoint->SetPzIn(momIn.Z());
434 oPoint->SetPxOut(momOut.X());
435 oPoint->SetPyOut(momOut.Y());
436 oPoint->SetPzOut(momOut.Z());
444 oPoint->SetTrackId(iTmcInt);
449 oPoint->SetStationId(stationID);
450 oPoint->SetDetectorId(DetID);
454 LOG(warn) <<
"CbmCaMCModule: MC track with iTmcExt = " << iTmcExt <<
", iEvent = " << iEvent
455 <<
", iFile = " << iFile <<
" MC track is undefined (nullptr)";
458 oPoint->SetPdgCode(pExtTrk->GetPdgCode());
461 auto* pPdgDB = TDatabasePDG::Instance()->GetParticle(oPoint->GetPdgCode());
462 oPoint->SetMass(pPdgDB ? pPdgDB->Mass() : 0.);
463 oPoint->SetCharge(pPdgDB ? pPdgDB->Charge() / 3. : 0.);
470 template<ca::EDetectorID DetID>
477 for (
int iH = (*
fpvFstHitId)[
static_cast<int>(DetID)]; iH < (*fpvFstHitId)[static_cast<int>(DetID) + 1]; ++iH) {
478 auto& hit = (*fpvQaHits)[iH];
481 hit.SetBestMcPointId(iBestP);
483 for (
auto iP : vAllP) {
485 hit.AddMcPointId(iP);
493 template<ca::EDetectorID DetID>
500 int nPointsEvent =
fvpBrPoints[DetID]->Size(iFile, iEvent);
501 for (
int iP = 0; iP < nPointsEvent; ++iP) {
CA Tracking monitor class.
Implementation of L1DetectorID enum class for CBM.
Class characterising one event by a collection of links (indices) to data objects,...
Access to a MC data branch for time-based analysis.
TObject * Get(const CbmLink *lnk)
Access to a MC data branch for time-based analysis.
Container class for MC events with number, file and start time.
double GetEventTime(uint32_t event, uint32_t file)
Event start time.
void SetMotherId(int32_t id)
Bookkeeping of time-slice content.
double GetEndTime() const
double GetStartTime() const
Monitor class for the CA tracking.
void IncrementCounter(ECounterKey key)
Increments key counter by 1.
A container for all external parameters of the CA tracking algorithm.
Class CbmCaPerformance is an interface to communicate between.
std::tuple< int, std::vector< int > > MatchHitWithMc(int iHitExt)
Matches hit with MC point.
DetIdArr_t< CbmTrackingDetectorInterfaceBase * > fvpDetInterface
Tracking detector interface.
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.
int fBestMcFile
Index of bestly matched MC file.
void ProcessEvent(CbmEvent *pEvent)
Processes event.
ca::Vector< CbmL1HitId > * fpvHitIds
Pointer to hit index container.
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.
const tools::MCData * GetMCData() const
Gets a pointer to MC data object.
int GetVerbosity() const
Gets verbosity level.
DetIdArr_t< bool > fvbUseDet
Flag: is detector subsystem used.
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.
int fVerbose
Verbosity level.
tools::MCData * fpMCData
MC information (hits and tracks) instance.
~MCModule()=default
Destructor.
DetIdArr_t< CbmMCDataArray * > fvpBrPoints
Array of points vs. detector.
void RegisterMCData(tools::MCData &mcData)
Registers MC data object.
void MatchRecoAndMCTracks()
Matches reconstructed tracks with MC tracks.
CbmMCDataObject * fpMCEventHeader
MC event header.
void ReadMCPointsForDetector()
Reads MC points in particular detector.
std::optional< tools::MCPoint > FillMCPoint(int iExtId, int iEvent, int iFile)
Fills a single detector-specific MC point.
@ 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.
void MatchPointsAndHits()
Match sets of MC points and reconstructed hits for a given detector.
ca::Vector< CbmL1HitDebugInfo > * fpvQaHits
Pointer to QA hit container.
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.
void RegisterQaHitContainer(ca::Vector< CbmL1HitDebugInfo > &vQaHits)
Registers debug hit container.
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.
CbmMCDataArray * fpMCTracks
MC tracks input.
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.
void MatchTracks()
Match reconstructed and MC data.
int fPerformanceMode
Mode of performance.
void RegisterParameters(std::shared_ptr< ca::Parameters< float > > &pParameters)
Registers CA parameters object.
void InitTrackInfo()
Initializes MC track.
std::shared_ptr< ca::Parameters< float > > fpParameters
Pointer to tracking parameters object.
TODO: SZh 8.11.2022: add selection of parameterisation.
EDetectorID
Enumeration for the tracking detector subsystems in CBM-CA.
constexpr DetIdArr_t< const char * > kDetName
Names of detector subsystems.
std::tuple_element_t< static_cast< std::size_t >(DetID), std::tuple< Types... > > at