CbmRoot
Loading...
Searching...
No Matches
HalCbmMCEvent.cxx
Go to the documentation of this file.
1/* Copyright (C) 2023-2023 Warsaw University of Technology, Warsaw
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Daniel Wielanek [committer] */
4#include "HalCbmMCEvent.h"
5
6#include "AnalysisTree/EventHeader.hpp"
7#include "AnalysisTree/Particle.hpp"
8#include "CbmAnaTreeSource.h"
9#include "CbmMCTrack.h"
11#include "HalCbmMCTrack.h"
12
13#include <FairMCEventHeader.h>
14
15HalCbmMCEvent::HalCbmMCEvent() : Hal::McEvent("HalCbmMCTrack") {}
16
17HalCbmMCEvent::HalCbmMCEvent(const HalCbmMCEvent& other) : Hal::McEvent(other) {}
18
19void HalCbmMCEvent::Update(Hal::EventInterface* interface)
20{
21 HalCbmMCEventInterface* s = static_cast<HalCbmMCEventInterface*>(interface);
22 fTotalTracksNo = s->GetTotalTrackNo();
23 fTracks->Clear();
24 fTracks->ExpandCreateFast(fTotalTracksNo);
25 switch (s->fFormatType) {
28 } break;
30 UpdateDst(s);
31 } break;
33 //Do nothing
34 } break;
35 }
36}
37
39{
40 Bool_t exist = CheckBranches(1, "CbmAnaTreeMcSourceContainer.");
41 Bool_t exist2 = CheckBranches(1, "CbmMCTrack");
42 if (exist || exist2) return kTRUE;
43 return kFALSE;
44}
45
47
48void HalCbmMCEvent::ShallowCopyTracks(Hal::Event* event)
49{
50 fTracks->Clear();
51 Hal::McEvent* mc_event = (Hal::McEvent*) event;
52 fTotalTracksNo = mc_event->GetTotalTrackNo();
53 for (int i = 0; i < fTotalTracksNo; i++) {
54 Hal::McTrack* to = (Hal::McTrack*) fTracks->ConstructedAt(i);
55 Hal::McTrack* from = (Hal::McTrack*) mc_event->GetTrack(i);
56 to->ResetTrack(i, this);
57 to->CopyData(from);
58 }
59}
60
61void HalCbmMCEvent::UpdateAnalysisTree(Hal::EventInterface* source)
62{
63 HalCbmMCEventInterface* s = static_cast<HalCbmMCEventInterface*>(source);
65 AnaTreeMcIds conf = data->GetFieldIds();
66 Bool_t UseFreez = kTRUE;
67 if (conf.freezX == AnalysisTree::UndefValueShort) {
68 UseFreez = kFALSE;
69 }
70 fB = data->GetEventHeader()->GetField<Float_t>(conf.event_b);
71 fPhi = data->GetEventHeader()->GetField<Float_t>(conf.event_psi);
72
73 for (int i = 0; i < fTotalTracksNo; i++) {
74 HalCbmMCTrack* track = (HalCbmMCTrack*) fTracks->UncheckedAt(i);
75 track->ResetTrack(i, this);
76 AnalysisTree::Particle particle = data->GetParticles()->GetChannel(i);
77 Double_t px = particle.GetField<float>(conf.px);
78 Double_t py = particle.GetField<float>(conf.py);
79 Double_t pz = particle.GetField<float>(conf.pz);
80 Double_t mass = particle.GetField<float>(conf.mass);
81
82 Int_t mother_id = particle.GetField<int>(conf.motherId);
83 Int_t pid = particle.GetField<int>(conf.pdg);
84 Double_t e = TMath::Sqrt(px * px + py * py + pz * pz + mass * mass);
85 track->SetMomentum(px, py, pz, e);
86 track->SetPdg(pid);
87 if (UseFreez) {
88 Double_t x = particle.GetField<float>(conf.freezX);
89 Double_t y = particle.GetField<float>(conf.freezY);
90 Double_t z = particle.GetField<float>(conf.freezZ);
91 Double_t t = particle.GetField<float>(conf.freezT);
92 track->SetFreezoutPosition(x, y, z, t);
93 }
94
95 if (mother_id == -1) {
96 track->SetPrimary();
97 }
98 else {
99 track->SetMotherIndex(track->GetMotherIndex());
100 }
101 track->SetCharge(CalculateCharge(pid));
102 }
103}
104
105void HalCbmMCEvent::UpdateDst(Hal::EventInterface* source)
106{
107 HalCbmMCEventInterface* s = static_cast<HalCbmMCEventInterface*>(source);
108 TClonesArray* mcTracks = s->fCbmMCtracks;
109 fB = s->fEventHeader->GetB();
110 for (int i = 0; i < fTotalTracksNo; i++) {
111 HalCbmMCTrack* track = (HalCbmMCTrack*) fTracks->UncheckedAt(i);
112 track->ResetTrack(i, this);
113 CbmMCTrack* mc = (CbmMCTrack*) mcTracks->UncheckedAt(i);
114 track->SetMomentum(mc->GetPx(), mc->GetPy(), mc->GetPz(), mc->GetEnergy());
115 track->SetMotherIndex(mc->GetMotherId());
116 track->SetPdg(mc->GetPdgCode());
117 track->SetCharge(mc->GetCharge());
118 }
119}
120
121Hal::EventInterface* HalCbmMCEvent::CreateInterface() const { return new HalCbmMCEventInterface(); }
static vector< vector< QAMCTrack > > mcTracks
AnalysisTree::EventHeader * GetEventHeader() const
AnalysisTree::Particles * GetParticles() const
double GetPz() const
Definition CbmMCTrack.h:72
double GetCharge() const
Charge of the associated particle.
double GetPx() const
Definition CbmMCTrack.h:70
int32_t GetMotherId() const
Definition CbmMCTrack.h:69
int32_t GetPdgCode() const
Definition CbmMCTrack.h:68
double GetPy() const
Definition CbmMCTrack.h:71
double GetEnergy() const
Definition CbmMCTrack.h:162
FairMCEventHeader * fEventHeader
virtual Int_t GetTotalTrackNo() const
virtual TObject * GetRawEventPointer() const
void UpdateAnalysisTree(Hal::EventInterface *interface)
virtual Hal::EventInterface * CreateInterface() const
virtual void ShallowCopyTracks(Hal::Event *event)
virtual Bool_t ExistInTree() const
virtual ~HalCbmMCEvent()
void UpdateDst(Hal::EventInterface *interface)
virtual void Update(Hal::EventInterface *interface)