CbmRoot
CbmPsdModulesConverter.cxx
Go to the documentation of this file.
1 #include <cassert>
2 #include <vector>
3 
4 #include "TClonesArray.h"
5 
6 #include "FairRootManager.h"
7 
8 #include "AnalysisTree/DataHeader.hpp"
9 #include "AnalysisTree/Detector.hpp"
10 
11 #include "CbmPsdHit.h"
12 #include "CbmPsdModulesConverter.h"
13 
15 
16  void CbmPsdModulesConverter::Init(std::map<std::string, void*>&) {
17  assert(!in_branches_.empty() && !out_branch_.empty() && out_config_
18  && out_tree_);
19  auto* ioman = FairRootManager::Instance();
20  assert(ioman != nullptr);
21  cbm_psd_hits_ = (TClonesArray*) ioman->GetObject("PsdHit");
22 
23  AnalysisTree::BranchConfig psd_branch(out_branch_,
24  AnalysisTree::DetType::kModule);
25  out_config_->AddBranchConfig(std::move(psd_branch));
26  psd_modules_ = new AnalysisTree::ModuleDetector(out_config_->GetLastId());
27  out_tree_->Branch(
28  out_branch_.c_str(), "AnalysisTree::ModuleDetector", &psd_modules_);
29 }
30 
32  assert(cbm_psd_hits_);
33  psd_modules_->ClearChannels();
34 
35  CbmPsdHit* hit {nullptr};
36  Float_t psd_energy {0.};
37 
38  // //TODO fix this logic. At the moment I don't know how to access number of
39  // PSD modules from her hit = (CbmPsdHit*) cbm_psd_hits_->At(nPsdHits-1); //
40  // last hit const int last_module_id = hit->GetModuleID()-1;
41  const int n_psd_modules =
42  data_header_->GetModulePositions(0).GetNumberOfChannels();
43  psd_modules_->Reserve(n_psd_modules);
44  for (int i = 0; i < n_psd_modules; ++i) {
45  auto* module = psd_modules_->AddChannel();
46  module->SetSignal(0.f);
47  }
48 
49  const int nPsdHits = cbm_psd_hits_->GetEntriesFast();
50  for (int i = 0; i < nPsdHits; ++i) {
51  hit = (CbmPsdHit*) cbm_psd_hits_->At(i);
52  if (hit == nullptr) continue;
53  auto& module = psd_modules_->GetChannel(hit->GetModuleID() - 1);
54  module.SetNumber(i + 1);
55  module.SetSignal(hit->GetEdep());
56  psd_energy += hit->GetEdep();
57  }
58  // rec_event_header_ -> SetField(psd_energy,
59  // config_.GetBranchConfig(rec_event_header_->GetId() ).GetFieldId("Epsd"));
60 }
61 
63  delete psd_modules_;
64  delete cbm_psd_hits_;
65 }
CbmPsdModulesConverter::Finish
void Finish() final
Definition: CbmPsdModulesConverter.cxx:62
f
float f
Definition: L1/vectors/P4_F32vec4.h:24
CbmPsdHit.h
CbmPsdModulesConverter::cbm_psd_hits_
TClonesArray * cbm_psd_hits_
Definition: CbmPsdModulesConverter.h:26
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmPsdModulesConverter::psd_modules_
AnalysisTree::ModuleDetector * psd_modules_
Definition: CbmPsdModulesConverter.h:25
CbmPsdModulesConverter::~CbmPsdModulesConverter
~CbmPsdModulesConverter() final
Definition: CbmPsdModulesConverter.cxx:66
CbmPsdModulesConverter::Exec
void Exec() final
Definition: CbmPsdModulesConverter.cxx:31
CbmPsdModulesConverter.h
CbmPsdModulesConverter
Definition: CbmPsdModulesConverter.h:9
CbmPsdModulesConverter::Init
void Init(std::map< std::string, void * > &) final
ClassImp
ClassImp(CbmPsdModulesConverter) void CbmPsdModulesConverter
Definition: CbmPsdModulesConverter.cxx:14
CbmPsdHit
Definition: CbmPsdHit.h:20