Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
DbgReader.cxx
1/*
2 * DbgReader.cxx
3 *
4 * Created on: 28 maj 2022
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "DbgReader.h"
11#include "DbgMcEvent.h"
12#include "DbgRecoEvent.h"
13
14#include "Cout.h"
15#include "DataManager.h"
16#include "DbgData.h"
17#include "Event.h"
18#include "McTrack.h"
19#include "Std.h"
20
21#include <TDatabasePDG.h>
22#include <TLorentzVector.h>
23#include <TMath.h>
24#include <TMathBase.h>
25#include <TParticlePDG.h>
26#include <TRandom.h>
27#include <TString.h>
28
29namespace HalDbg {
30 Reader::Reader() {}
31
32 Hal::Task::EInitFlag Reader::Init() {
33 fMcEvent = new Dbg::McEvent();
34 fRecoEvent = new Dbg::RecoEvent();
35 if (!fSpectras) {
36 fSpectras = new TH2D("spec", "spec", 1, 0, 1, 1, -1, 1);
37 fSpectras->SetBinContent(1, 1, 1);
38 }
39 Hal::DataManager* mng = Hal::DataManager::Instance();
40 if (mng->GetObject("Dbg::McEvent.")) { // branch exists
41 fMcEvent = (Dbg::McEvent*) mng->GetObject("Dbg::McEvent.");
42 fRecoEvent = (Dbg::RecoEvent*) mng->GetObject("Dbg::RecoEvent.");
43 } else {
44 fOwner = kTRUE;
45 mng->Register("Dbg::McEvent.", "HalEvents", fMcEvent, fRegister);
46 mng->Register("Dbg::RecoEvent.", "HalEvents", fRecoEvent, fRegister);
47 }
48 return Hal::Task::EInitFlag::kSUCCESS;
49 }
50
51 void Reader::SetSpiecies(const TH2D& h, Int_t pid, Double_t w) {
52 TH2D* copy = (TH2D*) h.Clone();
53 TDatabasePDG* pdg = TDatabasePDG::Instance();
54 TParticlePDG* part = pdg->GetParticle(pid);
55 if (part == nullptr) {
56 Hal::Cout::PrintInfo(Form("Cannot add particle with PID = %i", pid), Hal::EInfo::kWarning);
57 return;
58 }
59 copy->SetDirectory(nullptr);
60 fSpectras = copy;
61 fPids = pid;
62 fMass = part->Mass();
63 fMultiplicity = w;
64 fCharge = part->Charge() * 3;
65 }
66
67 void Reader::Exec(Option_t* /*opt*/) {
68 fCount++;
69 if (fOwner) {
70 fRecoEvent->Clear();
71 fMcEvent->Clear();
72 Int_t runId = fCount % fModuloCount;
73 fRecoEvent->SetEventId(runId);
74 fMcEvent->SetEventId(runId);
75 }
76
77 Int_t shift = fMcEvent->GetNTracks();
78 for (int i = 0; i < fMultiplicity; i++) {
79 Double_t pt, y;
80 fSpectras->GetRandom2(y, pt);
81 Double_t mt = TMath::Sqrt(pt * pt + fMass * fMass);
82 Double_t phi = gRandom->Uniform(-TMath::Pi(), TMath::Pi());
83 Double_t px = pt * TMath::Cos(phi);
84 Double_t py = pt * TMath::Sin(phi);
85 Double_t pz = mt * TMath::SinH(y);
86
87 Dbg::McTrack tr;
88 TLorentzVector p;
89 p.SetXYZM(px, py, pz, fMass);
90 tr.SetMomentum(p);
91 tr.SetPdgCode(fPids);
92 TLorentzVector xr(gRandom->Gaus(0, 1), gRandom->Gaus(0, 1), gRandom->Gaus(0), 0);
93 tr.SetFreezout(xr);
94 fMcEvent->AddTrack(tr);
95
97 px = px + gRandom->Gaus(0, fSmear) * px;
98 py = py + gRandom->Gaus(0, fSmear) * py;
99 pz = pz + gRandom->Gaus(0, fSmear) * pz;
100 Double_t e = TMath::Sqrt(px * px + py * py + pz * pz + fMass * fMass);
101 rtr.SetMom(px, py, pz, e);
102 rtr.SetNHits(5);
103 rtr.SetCharge(fCharge);
104 rtr.SetMcIndex(i + shift);
105 fRecoEvent->AddTrack(rtr);
106 }
107 }
108
109 Reader::~Reader() {
110 if (fSpectras) delete fSpectras;
111 if (fOwner && !fRegister) {
112 if (fMcEvent) delete fMcEvent;
113 if (fRecoEvent) delete fRecoEvent;
114 }
115 }
116} // namespace HalDbg
void SetSpiecies(const TH2D &h, Int_t pid, Double_t multiplicity)
Definition DbgReader.cxx:51
virtual Hal::Task::EInitFlag Init()
Definition DbgReader.cxx:32
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
void Register(const char *name, const char *folderName, TNamed *obj, Bool_t toFile)