Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
FemtoWeightGeneratorResidual.cxx
1/*
2 * FemtoWeightGeneratorResidual.cxx
3 *
4 * Created on: 30 sie 2021
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "FemtoWeightGeneratorResidual.h"
10
11#include "ComplexEvent.h"
12#include "ComplexTrack.h"
13#include "Cout.h"
14#include "DataFormatManager.h"
15#include "ExpEvent.h"
16#include "FemtoPair.h"
17#include "FemtoWeightGeneratorLednicky.h"
18#include "McTrack.h"
19#include "Track.h"
20
21namespace Hal {
22 FemtoWeightGeneratorResidual::FemtoWeightGeneratorResidual() :
23 fMainWeight(nullptr), fResPair(nullptr), fWeightType(eWeightType::kOther), fComplexFormat(kFALSE) {}
24
25 FemtoWeightGeneratorResidual::FemtoWeightGeneratorResidual(const FemtoWeightGenerator& w) :
26 fResPair(nullptr), fWeightType(eWeightType::kOther), fComplexFormat(kFALSE) {
27 fMainWeight = w.MakeCopy();
28 }
29
30 FemtoWeightGeneratorResidual::FemtoWeightGeneratorResidual(const FemtoWeightGeneratorResidual& other) :
31 FemtoWeightGenerator(other),
32 fMainWeight(nullptr),
33 fResPair(nullptr),
34 fWeightType(eWeightType::kOther),
35 fComplexFormat(kFALSE) {}
36
37 Double_t FemtoWeightGeneratorResidual::GenerateWeight(FemtoPair* pair) {
38 McTrack *tr1, *tr2;
39 if (fComplexFormat) {
40 ComplexTrack* z1 = (ComplexTrack*) pair->GetTrack1();
41 ComplexTrack* z2 = (ComplexTrack*) pair->GetTrack2();
42 tr1 = (McTrack*) z1->GetImgTrack();
43 tr2 = (McTrack*) z2->GetImgTrack();
44 if (tr1 == nullptr || tr2 == nullptr) return 1; // no MC tracks weight should be 1
45 } else {
46 tr1 = (McTrack*) pair->GetTrack1();
47 tr2 = (McTrack*) pair->GetTrack2();
48 }
49
50 Int_t prim = tr1->IsGoodSecondary() + 2 * tr2->IsGoodSecondary();
51 switch (prim) {
52 case 0: { // no primary particles
53 // do nothing
54 SetPairData(tr1, tr2);
55 } break;
56 case 1: { // first is seondary
57 while (tr1->IsGoodSecondary()) {
58 tr1 = (McTrack*) tr1->GetEvent()->GetTrack(tr1->GetMotherIndex());
59 }
60 SetPairData(tr1, tr2);
61 } break;
62 case 2: { // second is secondary
63 while (tr2->IsGoodSecondary()) {
64 tr2 = (McTrack*) tr2->GetEvent()->GetTrack(tr2->GetMotherIndex());
65 }
66 SetPairData(tr1, tr2);
67 } break;
68 case 3: { // both are secondary
69 while (tr1->IsGoodSecondary()) {
70 tr1 = (McTrack*) tr1->GetEvent()->GetTrack(tr1->GetMotherIndex());
71 }
72 while (tr2->IsGoodSecondary()) {
73 tr2 = (McTrack*) tr2->GetEvent()->GetTrack(tr2->GetMotherIndex());
74 }
75 SetPairData(tr1, tr2);
76 } break;
77 }
78 switch (fWeightType) {
79 case eWeightType::kLednicky: {
80 (static_cast<FemtoWeightGeneratorLednicky*>(fMainWeight))->SetPairTypeFromPairAndConfigureFSI(fResPair);
81 } break;
82 default: {
83
84 } break;
85 }
86 return fMainWeight->GenerateWeight(fResPair);
87 }
88
89 Bool_t FemtoWeightGeneratorResidual::Init(Int_t task_id, FemtoPair* pair) {
90 if (fMainWeight == nullptr) return kFALSE;
91 fMainWeight->Init(task_id, pair);
92 fResPair = pair->MakeCopy();
93 DataFormatManager* mngr = DataFormatManager::Instance();
94 const Event* event = mngr->GetFormat(task_id, EFormatDepth::kBuffered);
95 if (dynamic_cast<const ComplexEvent*>(event)) fComplexFormat = kTRUE;
96 if (dynamic_cast<const ExpEvent*>(event)) {
97 Cout::PrintInfo("Experimental format cannot be used for residual weights", EInfo::kLowWarning);
98 return kFALSE;
99 }
100 if (dynamic_cast<FemtoWeightGeneratorLednicky*>(fMainWeight)) { fWeightType = eWeightType::kLednicky; }
101 return kTRUE;
102 }
103
104 Package* FemtoWeightGeneratorResidual::Report() const {
105 Package* report = new Package(this);
106 report->AddObject(fMainWeight->Report());
107 return report;
108 }
109
110 void FemtoWeightGeneratorResidual::SetPairData(McTrack* track1, McTrack* track2) {
111 const TLorentzVector& pt1 = track1->GetMomentum();
112 const TLorentzVector& pt2 = track2->GetMomentum();
113 fResPair->SetPdg1(track1->GetPdg());
114 fResPair->SetPdg2(track2->GetPdg());
115
116 const TLorentzVector& x1 = track1->GetFreezoutPosition();
117 const TLorentzVector& x2 = track2->GetFreezoutPosition();
118 fResPair->SetFreezoutCoord1(x1.X(), x1.Y(), x1.Z(), x1.T());
119 fResPair->SetFreezoutCoord2(x2.X(), x2.Y(), x2.Z(), x2.T());
120 fResPair->SetTrueMomenta1(pt1.Px(), pt1.Py(), pt1.Pz(), pt1.E());
121 fResPair->SetTrueMomenta2(pt2.Px(), pt2.Py(), pt2.Pz(), pt2.E());
122 // fResPair->SetMomenta1(p1.Px(), p1.Py(), p1.Pz()); // currently not necessary
123 // fResPair->SetMomenta2(p2.Px(), p2.Py(), p2.Pz());
124 }
125
126 FemtoWeightGeneratorResidual::~FemtoWeightGeneratorResidual() {
127 if (fMainWeight) delete fMainWeight;
128 if (fResPair) delete fResPair;
129 }
130
131 FemtoWeightGeneratorResidual& FemtoWeightGeneratorResidual::operator=(const FemtoWeightGeneratorResidual& other) {
132 if (this == &other) return *this;
133 if (fMainWeight) {
134 delete fMainWeight;
135 fMainWeight = nullptr;
136 }
137 if (fResPair) {
138 delete fResPair;
139 fResPair = nullptr;
140 }
141 if (other.fMainWeight) { fMainWeight = other.fMainWeight->MakeCopy(); }
142 if (other.fResPair) { fResPair = other.fResPair->MakeCopy(); }
143 fWeightType = other.fWeightType;
144 fComplexFormat = other.fComplexFormat;
145 return *this;
146 }
147} // namespace Hal
const Event * GetFormat(Int_t task_id, EFormatDepth format_depth=EFormatDepth::kAll) const
Track * GetTrack(Int_t i) const
Definition Event.h:208
Track * GetTrack2() const
Definition FemtoPair.h:342
Track * GetTrack1() const
Definition FemtoPair.h:337
void AddObject(TObject *object)
Definition Package.cxx:209
Event * GetEvent() const
Definition Track.h:315
Bool_t IsGoodSecondary() const
Definition Track.h:214
Int_t GetMotherIndex() const
Definition Track.h:204