Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
UnigenEventInterface.cxx
1/*
2 * NicaUnigenSource.cxx
3 *
4 * Created on: 2 sie 2017
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "UnigenEventInterface.h"
11#include "UEvent.h"
12#include "UParticle.h"
13#include "UnigenTrackInterface.h"
14
15#include "DataManager.h"
16#include "TrackInterface.h"
17
18#include <iostream>
19#include <vector>
20
21#include <RtypesCore.h>
22#include <TCollection.h>
23#include <TList.h>
24#include <TLorentzVector.h>
25#include <TNamed.h>
26#include <TObjString.h>
27#include <TString.h>
28
29namespace HalUni {
30 UnigenEventInterface::UnigenEventInterface() : Hal::EventInterfaceAdvanced(new UnigenTrackInterface()), fEvent(nullptr) {
31 fEvent = new UEvent();
32 }
33
34 void UnigenEventInterface::Compress(Int_t* map, Int_t map_size) {
35 Int_t track_pos = 0;
36 for (int i = 0; i < map_size; i++) {
37 Int_t good_track = map[i];
38 for (int j = track_pos; j < good_track; j++) {
39 fEvent->RemoveAt(j);
40 }
41 track_pos = good_track + 1;
42 }
43 }
44
45 void UnigenEventInterface::CopyData(Hal::EventInterface* s) {
46#ifdef UNIGEN_OLD
47 CopyUnigen(((HalCbmUnigenEventInterface*) s)->fEvent, fEvent);
48#else
49 *fEvent = *((UnigenEventInterface*) s)->fEvent;
50#endif
51 }
52
53 void UnigenEventInterface::CopyAndCompress(Hal::EventInterface* s, Int_t* map, Int_t map_size) {
55 fEvent->SetB(ev->fEvent->GetB());
56 fEvent->SetPhi(ev->fEvent->GetPhi());
57 fEvent->SetNes(ev->fEvent->GetNes());
58 fEvent->SetStepNr(ev->fEvent->GetStepNr());
59 fEvent->SetStepT(ev->fEvent->GetStepT());
60#ifdef UNIGEN_OLD
61 fEvent->GetParticleList()->Clear();
62#else
63 TString comment;
64 ev->fEvent->GetComment(comment);
65 fEvent->SetComment(comment);
66 fEvent->Clear();
67#endif
68 for (int i = 0; i < map_size; i++) {
69 fEvent->AddParticle(*ev->fEvent->GetParticle(map[i]));
70 }
71 }
72
73 void UnigenEventInterface::Boost(Double_t vx, Double_t vy, Double_t vz) {
74 for (int i = 0; i < fEvent->GetNpa(); i++) {
75 UParticle* p = fEvent->GetParticle(i);
76 TLorentzVector mom = p->GetMomentum();
77 TLorentzVector pos = p->GetPosition();
78 mom.Boost(vx, vy, vz);
79 pos.Boost(vx, vy, vz);
80 p->SetMomentum(mom);
81 p->SetPosition(pos);
82 }
83 }
84
85 UnigenEventInterface::~UnigenEventInterface() {
86 if (fCanDeleteEvent && fEvent) {
87 if (fEvent) delete fEvent;
88 }
89 }
90
91 void UnigenEventInterface::Register(Bool_t write) {
92 if (fEvent == nullptr) fEvent = new UEvent();
93 Hal::DataManager* manager = Hal::DataManager::Instance();
94 manager->Register("UEvent.", "", (TNamed*) fEvent, write);
95 }
96
97 void UnigenEventInterface::FillTrackInterface(Hal::TrackInterface* track, Int_t index) {
98 track->SetRawTrack(fEvent->GetParticle(index));
99 }
100
101 void UnigenEventInterface::ConnectToTreeInternal(eMode mode) {
102 Hal::DataManager* manager = Hal::DataManager::Instance();
103
104 switch (mode) {
105 case Hal::EventInterface::eMode::kRead: {
106 std::vector<TString> names;
107 names.push_back("UEvent.");
108 names.push_back("UEvent");
109 names.push_back("event");
110 names.push_back("events");
111 for (auto i : names) {
112 fEvent = dynamic_cast<UEvent*>(manager->GetObject(i));
113 if (fEvent != nullptr) { return; }
114 }
115 } break;
116 case Hal::EventInterface::eMode::kWrite: {
117 fEvent = new UEvent();
118 manager->Register("UEvent.", "unigen", (TNamed*) fEvent, kTRUE);
119 } break;
120 case Hal::EventInterface::eMode::kWriteVirtual: {
121 fEvent = new UEvent();
122 manager->Register("UEvent.", "unigen", (TNamed*) fEvent, kFALSE);
123 fCanDeleteEvent = kTRUE;
124
125 } break;
126 }
127 }
128
129} // namespace HalUni
void Register(const char *name, const char *folderName, TNamed *obj, Bool_t toFile)
void SetRawTrack(TObject *source, Int_t obj=0)