CbmRoot
Loading...
Searching...
No Matches
CbmSimEventHeaderConverter.cxx
Go to the documentation of this file.
1/* Copyright (C) 2020-2021 Physikalisches Institut, Eberhard Karls Universitaet Tuebingen, Tuebingen
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Viktor Klochkov [committer] */
4
6
7#include "CbmEvent.h"
8#include "CbmMCDataArray.h"
9#include "CbmMCDataManager.h"
10#include "CbmMCDataObject.h"
11
12#include "FairMCEventHeader.h"
13#include "FairRootManager.h"
14
15#include "TClonesArray.h"
16
17#include <AnalysisTree/TaskManager.hpp>
18
19#include "cassert"
20#include "iostream"
21
23
25{
26 assert(!out_branch_.empty());
27 auto* ioman = FairRootManager::Instance();
28 assert(ioman != nullptr);
29
30 cbm_mc_manager_ = dynamic_cast<CbmMCDataManager*>(ioman->GetObject("MCDataManager"));
31 cbm_header_obj_ = cbm_mc_manager_->GetObject("MCEventHeader.");
32 cbm_mc_event_list_ = (CbmMCEventList*) ioman->GetObject("MCEventList.");
33 if (!cbm_mc_event_list_) { throw std::runtime_error("CbmSimEventHeaderConverter::Init - ERROR! No fMCEventList!"); }
34
35 // ***** SimEventHeader *******
36 AnalysisTree::BranchConfig SimEventHeaderBranch("SimEventHeader", AnalysisTree::DetType::kEventHeader);
37 SimEventHeaderBranch.AddField<float>("psi_RP", "reaction plane orientation");
38 SimEventHeaderBranch.AddField<float>("b", "fm, impact parameter");
39 SimEventHeaderBranch.AddFields<float>({"start_time", "end_time"}, "ns (?), event time");
40 SimEventHeaderBranch.AddField<int>("run_id", "run identifier");
41 SimEventHeaderBranch.AddField<int>("event_id", "event identifier");
42 SimEventHeaderBranch.AddField<float>("T0", "MC event time, ns");
43
44 ipsi_RP_ = SimEventHeaderBranch.GetFieldId("psi_RP");
45 ib_ = SimEventHeaderBranch.GetFieldId("b");
46 istart_time_ = SimEventHeaderBranch.GetFieldId("start_time");
47 iend_time_ = SimEventHeaderBranch.GetFieldId("end_time");
48 irun_id_ = SimEventHeaderBranch.GetFieldId("run_id");
49 ievent_id_ = SimEventHeaderBranch.GetFieldId("event_id");
50 iT0_ = SimEventHeaderBranch.GetFieldId("T0");
51
52 auto* man = AnalysisTree::TaskManager::GetInstance();
53 man->AddBranch(sim_event_header_, SimEventHeaderBranch);
54 sim_event_header_->Init(SimEventHeaderBranch);
55}
56
58{
59 FairMCEventHeader* cbm_header {nullptr};
60 int file_id {0}, event_id {0};
61
62 if (event && event->GetMatch() && event->GetMatch()->GetNofLinks() > 0) {
63 const auto& link = event->GetMatch()->GetMatchedLink();
64 file_id = event->GetMatch()->GetMatchedLink().GetFile();
65 event_id = event->GetMatch()->GetMatchedLink().GetEntry();
66 cbm_header = (FairMCEventHeader*) (cbm_header_obj_->Get(link));
67 }
68 else {
69 cbm_header = (FairMCEventHeader*) (cbm_header_obj_->Get(0, FairRootManager::Instance()->GetEntryNr()));
70 }
71
72 if (!cbm_header) { throw std::runtime_error("CbmSimEventHeaderConverter::Exec - ERROR! No fHeader!"); }
73
74 LOG(info) << "MCEvent " << cbm_header->GetEventID() << " with T0 "
75 << cbm_mc_event_list_->GetEventTime(event_id, file_id);
76
77 TVector3 pos {cbm_header->GetX(), cbm_header->GetY(), cbm_header->GetZ()};
78 sim_event_header_->SetVertexPosition3(pos);
79
80 sim_event_header_->SetField(float(cbm_header->GetRotZ()), ipsi_RP_);
81 sim_event_header_->SetField(float(cbm_header->GetB()), ib_);
82 sim_event_header_->SetField(int(cbm_header->GetEventID()), ievent_id_);
83 sim_event_header_->SetField(int(cbm_header->GetRunID()), irun_id_);
84 sim_event_header_->SetField(float(cbm_mc_event_list_->GetEventTime(event_id, file_id)), iT0_);
85
86 if (event) {
87 LOG(info) << "TIME: " << event->GetStartTime() << " " << event->GetEndTime();
88 sim_event_header_->SetField(float(event->GetStartTime()), istart_time_);
89 sim_event_header_->SetField(float(event->GetEndTime()), iend_time_);
90 }
91}
ClassImp(CbmSimEventHeaderConverter)
std::string out_branch_
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
double GetStartTime() const
Definition CbmEvent.h:140
double GetEndTime() const
Definition CbmEvent.h:134
CbmMatch * GetMatch() const
Definition CbmEvent.h:98
Task class creating and managing CbmMCDataArray objects.
CbmMCDataObject * GetObject(const char *name)
TObject * Get(const CbmLink *lnk)
Container class for MC events with number, file and start time.
double GetEventTime(uint32_t event, uint32_t file)
Event start time.
int32_t GetNofLinks() const
Definition CbmMatch.h:42
void ProcessData(CbmEvent *event) final
AnalysisTree::EventHeader * sim_event_header_