Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
OTFEventGeneratorDecay.cxx
1/*
2 * OTFReaderDecay.cxx
3 *
4 * Created on: 28 mar 2024
5 * Author: daniel
6 */
7
8#include "OTFEventGeneratorDecay.h"
9
10#include <TDatabasePDG.h>
11#include <TLorentzVector.h>
12#include <TMath.h>
13#include <TParticlePDG.h>
14#include <TRandom.h>
15#include <TString.h>
16#include <iostream>
17
18#include "Cout.h"
19#include "McTrack.h"
20#include "OTFEventGenerator.h"
21#include "Std.h"
22#include "Track.h"
23
24
25namespace HalOTF {
26 EventGeneratorDecay::EventGeneratorDecay() {}
27
28 Bool_t EventGeneratorDecay::Init() {
29 auto init = HalOTF::EventGenerator::Init();
30 if (!init) return init;
31 if (!fDecayer) {
32 Hal::Cout::PrintInfo("Lack of decayer", Hal::EInfo::kError);
33 return kFALSE;
34 }
35 auto stat = fDecayer->Init();
36 if (fDecayer->GetMotherPdg() != fPids) {
37 Hal::Cout::PrintInfo(Form("Wrong decayer, expected PID=%i got %i", fPids, fDecayer->GetMotherPdg()), Hal::EInfo::kError);
38 return kFALSE;
39 }
40 if (!stat) {
41 Hal::Cout::PrintInfo("Cannot initialize decayer", Hal::EInfo::kError);
42 return kFALSE;
43 }
44 for (int i = 0; i < 3; i++) {
45 fDaughters.push_back(new Hal::McTrack());
46 }
47 return init;
48 }
49
50 void EventGeneratorDecay::SetDecay(Hal::Decay decay) {
51 if (fDecayer) delete fDecayer;
52 fDecayer = new Hal::Decay(decay);
53 }
54
55 void EventGeneratorDecay::Decay() {
56 Int_t shift = fMcEvent->GetNTracks();
57 Int_t start = shift - fCurrrentMult;
58 TDatabasePDG* db = TDatabasePDG::Instance();
59
60 auto makeReco = [&](OTF::McTrack& tr) {
62 double px = tr.GetMomentum().Px();
63 double py = tr.GetMomentum().Py();
64 double pz = tr.GetMomentum().Pz();
65 px = px + gRandom->Gaus(0, fSmear) * px;
66 py = py + gRandom->Gaus(0, fSmear) * py;
67 pz = pz + gRandom->Gaus(0, fSmear) * pz;
68 Double_t e = TMath::Sqrt(px * px + py * py + pz * pz + fMass * fMass);
69 rtr.SetMom(px, py, pz, e);
70 rtr.SetNHits(5);
71
72 auto pid = db->GetParticle(tr.GetPdgCode());
73 if (pid) {
74 rtr.SetCharge(pid->Charge() / 3.0);
75 } else {
76 rtr.SetCharge(0);
77 }
78 return rtr;
79 };
80 auto makeSim = [](Hal::McTrack tr) {
81 OTF::McTrack trx;
82 trx.SetMomentum(tr.GetMomentum());
83 trx.SetFreezout(tr.GetFreezoutPosition());
84 trx.SetPdgCode(tr.GetPdg());
85 trx.SetMotherId(tr.GetMotherIndex());
86 return trx;
87 };
88
89 int indexCount = 0;
90
91 for (int i = start; i < shift; i++) {
92 auto track = fMcEvent->GetTrack(i);
93 Hal::McTrack mommy;
94 mommy.SetMomentum(track->GetMomentum().X(), track->GetMomentum().Y(), track->GetMomentum().Z(), track->GetMomentum().T());
96 track->GetFreezout().X(), track->GetFreezout().Y(), track->GetFreezout().Z(), track->GetFreezout().T());
97 mommy.SetPdg(track->GetPdgCode());
98 int nDau = fDecayer->DecayParticle(mommy, fDaughters, kFALSE);
99
100 for (int j = 0; j < nDau; j++) {
101 auto dau = fDaughters[j];
102 dau->SetMotherIndex(i);
103 auto daughter = makeSim(*dau);
104 fMcEvent->AddTrack(daughter);
105 auto reco = makeReco(daughter);
106 reco.SetMcIndex(fMcEvent->GetNTracks() - 1);
107 fRecoEvent->AddTrack(reco);
108 }
109 }
110 }
111
112 EventGeneratorDecay::~EventGeneratorDecay() {
113 for (auto i : fDaughters)
114 delete i;
115 if (fDecayer) delete fDecayer;
116 }
117
118 void EventGeneratorDecay::GenerateEvent() {
119 HalOTF::EventGenerator::GenerateEvent();
120 Decay();
121 if (fDebug) {
122 std::cout << "MC Tracks" << std::endl;
123 Hal::Cout::Database({"Idx", "Px", "Pid", "MomId"});
124 for (int i = 0; i < fMcEvent->GetNTracks(); i++) {
125 auto mcTrack = fMcEvent->GetTrack(i);
126 Hal::Cout::Database({Form("%i", i),
127 Form("%4.2f", mcTrack->GetMomentum().Px()),
128 Form("%i", mcTrack->GetPdgCode()),
129 Form("%i", mcTrack->GetMotherId())});
130 }
131 std::cout << "Reco Tracks" << std::endl;
132 Hal::Cout::Database({"Idx", "Px(reco)", "Px(sim)", "Pid", "McId"});
133 for (int i = 0; i < fRecoEvent->GetNTracks(); i++) {
134 auto recoTrack = fRecoEvent->GetTrack(i);
135 // std::cout << recoTrack->GetMcIndex() << std::endl;
136 auto simTrack = fMcEvent->GetTrack(recoTrack->GetMcIndex());
137
138 Hal::Cout::Database({Form("%i", i),
139 Form("%4.2f", recoTrack->GetMom().Px()),
140 Form("%4.2f", simTrack->GetMomentum().Px()),
141 Form("%i", simTrack->GetPdgCode()),
142 Form("%i", recoTrack->GetMcIndex())});
143 }
144 std::cout << "-----" << std::endl;
145 }
146 }
147
148} // namespace HalOTF
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
static void Database(Int_t no...)
virtual Int_t DecayParticle(McTrack &mother, std::vector< McTrack * > &daughters, Bool_t addToEvent=kFALSE) const
Definition Decay.cxx:225
Int_t GetMotherPdg() const
Definition Decay.h:107
virtual Bool_t Init()
Definition Decay.cxx:260
void SetFreezoutPosition(Double_t x, Double_t y, Double_t z, Double_t t)
Definition McTrack.h:52
void SetMomentum(Double_t px, Double_t py, Double_t pz, Double_t e)
Definition Track.h:152