CbmRoot
CbmConverterManager.cxx
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include "AnalysisTree/DataHeader.hpp"
4 #include "AnalysisTree/TaskManager.hpp"
5 
6 #include "TGeoBBox.h"
7 #include "TGeoManager.h"
8 
9 #include "CbmConverterManager.h"
10 #include "CbmConverterTask.h"
11 
13 
14  InitStatus CbmConverterManager::Init() {
15  assert(!out_file_name_.empty() && !out_tree_name_.empty());
16 
17  out_file_ = TFile::Open(out_file_name_.c_str(), "RECREATE");
18  out_file_->cd();
19  out_tree_ = new TTree(out_tree_name_.c_str(), "Analysis Tree");
20 
22 
23  std::map<std::string, void*> unused_map {};
24 
25  out_config_ = new AnalysisTree::Configuration;
26  for (auto* task : tasks_) {
27  task->SetOutTree(out_tree_);
28  task->SetOutConfiguration(out_config_);
29  task->SetDataHeader(data_header_);
30  task->Init(unused_map);
31  }
32 
33  out_config_->Write("Configuration");
34 
35  return kSUCCESS;
36 }
37 
38 void CbmConverterManager::Exec(Option_t* /*opt*/) {
39  index_map_.clear();
40  for (auto* task : tasks_) {
41  task->SetIndexesMap(&index_map_);
42  task->Exec();
43  // if(!task->GetOutIndexesMap().empty()) {
44  index_map_.insert(
45  std::make_pair(task->GetOutputBranchName(), task->GetOutIndexesMap()));
46  // }
47  }
48  out_tree_->Fill();
49 }
50 
52  TDirectory* old_dir = gDirectory;
53 
54  out_file_->cd();
55  for (auto* task : tasks_) {
56  task->Finish();
57  }
58  out_tree_->Write();
59  out_file_->Close();
60 
61  old_dir->cd();
62 }
63 
65 
66  assert(
67  !system_.empty()
68  && beam_mom_); // Force user to write data info //TODO is there a way to
69  // read it from a file automatically?
70 
71  data_header_ = new AnalysisTree::DataHeader;
72 
73  std::cout << "ReadDataHeader" << std::endl;
74  data_header_->SetSystem(system_);
75  data_header_->SetBeamMomentum(beam_mom_);
76 
77  auto& psd_mod_pos = data_header_->AddDetector();
78  const int psd_node_id = 6;
79  const char* module_name_prefix = "module";
80 
81  auto* geoMan = gGeoManager;
82  auto* caveNode = geoMan->GetTopNode();
83  auto* psdNode = caveNode->GetDaughter(psd_node_id);
84  std::cout << "-I- " << psdNode->GetName() << std::endl;
85 
86  auto psdGeoMatrix = psdNode->GetMatrix();
87  auto psdBox = (TGeoBBox*) psdNode->GetVolume()->GetShape();
88  TVector3 frontFaceLocal(0, 0, -psdBox->GetDZ());
89 
90  TVector3 frontFaceGlobal;
91  psdGeoMatrix->LocalToMaster(&frontFaceLocal[0], &frontFaceGlobal[0]);
92 
93  for (int i_d = 0; i_d < psdNode->GetNdaughters(); ++i_d) {
94  auto* daughter = psdNode->GetDaughter(i_d);
95  TString daughterName(daughter->GetName());
96  if (daughterName.BeginsWith(module_name_prefix)) {
97 
98  auto geoMatrix = daughter->GetMatrix();
99  TVector3 translation(geoMatrix->GetTranslation());
100 
101  int modID = daughter->GetNumber();
102  double x = translation.X();
103  double y = translation.Y();
104 
105  std::cout << "mod" << modID << " : " << Form("(%.3f, %3f)", x, y)
106  << std::endl;
107 
108  auto* module = psd_mod_pos.AddChannel();
109  module->SetPosition(x, y, frontFaceGlobal[2]);
110  }
111  }
112 
113  TDirectory* curr = gDirectory; // TODO check why this is needed
114  TFile* currentFile = gFile;
115 
116  out_file_->cd();
117  data_header_->Write("DataHeader");
118 
119  gFile = currentFile;
120  gDirectory = curr;
121 }
123  delete out_config_;
124  delete data_header_;
125  delete out_tree_;
126  delete out_file_;
127 }
CbmConverterManager::~CbmConverterManager
~CbmConverterManager() override
Definition: CbmConverterManager.cxx:122
CbmConverterManager::system_
std::string system_
Definition: CbmConverterManager.h:38
CbmConverterManager::out_file_name_
std::string out_file_name_
Definition: CbmConverterManager.h:35
CbmConverterManager::out_tree_name_
std::string out_tree_name_
Definition: CbmConverterManager.h:36
CbmConverterManager::index_map_
std::map< std::string, std::map< int, int > > index_map_
map CbmRoot to AT of indexes for a given branch
Definition: CbmConverterManager.h:46
CbmConverterManager::tasks_
std::vector< CbmConverterTask * > tasks_
Definition: CbmConverterManager.h:43
CbmConverterTask.h
CbmConverterManager::Exec
void Exec(Option_t *opt) override
Definition: CbmConverterManager.cxx:38
CbmConverterManager::FillDataHeader
void FillDataHeader()
Definition: CbmConverterManager.cxx:64
CbmConverterManager::data_header_
AnalysisTree::DataHeader * data_header_
Definition: CbmConverterManager.h:42
CbmConverterManager::out_file_
TFile * out_file_
Definition: CbmConverterManager.h:33
task
@ task
Definition: CbmMvdSensorPlugin.h:22
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmConverterManager::out_config_
AnalysisTree::Configuration * out_config_
Definition: CbmConverterManager.h:41
CbmConverterManager.h
CbmConverterManager::out_tree_
TTree * out_tree_
Definition: CbmConverterManager.h:34
CbmConverterManager::Init
InitStatus Init() override
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmConverterManager
Definition: CbmConverterManager.h:13
CbmConverterManager::beam_mom_
float beam_mom_
Definition: CbmConverterManager.h:39
CbmConverterManager::Finish
void Finish() override
Definition: CbmConverterManager.cxx:51