CbmRoot
Loading...
Searching...
No Matches
CbmUnigenSource.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 "CbmUnigenSource.h"
5
6#include "UEvent.h"
7#include "UParticle.h"
8
9#include <FairLogger.h>
10#include <FairRootManager.h>
11
12#include <TBranch.h>
13
14#include <fstream>
15#include <iostream>
16
17
18CbmUnigenSource::CbmUnigenSource() : fUnigenChain(nullptr), fEvent(nullptr), fPrintTreeInfo(kFALSE) {}
19
20CbmUnigenSource::CbmUnigenSource(TString inFile) : fUnigenChain(nullptr), fEvent(nullptr), fPrintTreeInfo(kFALSE)
21{
22 fFileName.push_back(inFile);
23}
24
26{
27 //if (fUnigenChain) delete fUnigenChain;
28 //is owned by FairRoot ?
29}
30
32{
33 FairRootManager* mngr = FairRootManager::Instance();
34 fUnigenChain = new TChain("events");
35 if (fFileName[0].EndsWith(".root")) {
36 for (auto i : fFileName) {
37 LOG(debug) << "NicaUnigenSource: opening single file" << i;
38 fUnigenChain->Add(i);
39 }
40 }
41 else { // this is long list
42 std::ifstream list;
43 list.open(fFileName[0]);
44 do {
45 TString temp;
46 list >> temp;
47 if (temp.Length() > 1) {
48 fUnigenChain->Add(temp);
49 }
50 else {
51 break;
52 }
53 LOG(debug) << "Adding file " << temp << " to chain";
54 } while (!list.eof());
55 list.close();
56 }
57
58 fEvent = new UEvent();
59 if (fUnigenChain->GetBranch("event")) {
60 if (fPrintTreeInfo) fUnigenChain->Print();
61 fUnigenChain->SetBranchStatus("event", 1);
62 fUnigenChain->SetBranchAddress("event", &fEvent);
63 }
64 else {
65 if (fPrintTreeInfo) std::cout << "Event read II" << std::endl;
66 fUnigenChain->SetBranchStatus("UEvent.", 1);
67 fUnigenChain->SetBranchAddress("UEvent.", &fEvent);
68 }
69 mngr->SetInChain(fUnigenChain, -1);
70 mngr->Register("UEvent.", "UEvent", (TNamed*) fEvent, kFALSE);
71 return kTRUE;
72}
73
74Int_t CbmUnigenSource::ReadEvent(UInt_t unsignedInt)
75{
76 //std::cout<<"READING EVENT " <<unsignedInt<<std::endl;
77 fUnigenChain->GetEntry(unsignedInt);
78 // std::cout<<"xxx"<<std::endl;
79 return 0;
80}
81
83
84void CbmUnigenSource::Boost(Double_t vx, Double_t vy, Double_t vz)
85{
86 for (int i = 0; i < fEvent->GetNpa(); i++) {
88 TLorentzVector mom = p->GetMomentum();
89 TLorentzVector pos = p->GetPosition();
90 mom.Boost(vx, vy, vz);
91 pos.Boost(vx, vy, vz);
92 p->SetMomentum(mom);
93 p->SetPosition(pos);
94 }
95}
96
97Int_t CbmUnigenSource::CheckMaxEventNo(Int_t /*int1*/) { return fUnigenChain->GetEntries(); }
98
99Bool_t CbmUnigenSource::SpecifyRunId() { return kFALSE; }
std::vector< TString > fFileName
virtual Int_t ReadEvent(UInt_t=0)
virtual void Close()
virtual void Boost(Double_t vx, Double_t vy, Double_t vz)
virtual Int_t CheckMaxEventNo(Int_t=0)
virtual ~CbmUnigenSource()
virtual Bool_t SpecifyRunId()
virtual Bool_t Init()
Int_t GetNpa() const
Definition UEvent.h:42
UParticle * GetParticle(Int_t index) const
Definition UEvent.cxx:101
void SetMomentum(Double_t px, Double_t py, Double_t pz, Double_t e)
Definition UParticle.h:89
TLorentzVector GetMomentum() const
Definition UParticle.h:62
TLorentzVector GetPosition() const
Definition UParticle.h:68
void SetPosition(Double_t x, Double_t y, Double_t z, Double_t t)
Definition UParticle.h:107