CbmRoot
CbmSimTracksConverter.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 "CbmMCTrack.h"
10 
12 
13  void CbmSimTracksConverter::Init(std::map<std::string, void*>&) {
14 
15  assert(!in_branches_.empty() && !out_branch_.empty() && out_config_
16  && out_tree_);
17  auto* ioman = FairRootManager::Instance();
18  cbm_mc_tracks_ = (TClonesArray*) ioman->GetObject(in_branches_[0].c_str());
19 
20  AnalysisTree::BranchConfig SimTracksBranch(out_branch_,
21  AnalysisTree::DetType::kParticle);
22  SimTracksBranch.AddField<int>("mother_id");
23  out_config_->AddBranchConfig(std::move(SimTracksBranch));
24  sim_tracks_ = new AnalysisTree::Particles(out_config_->GetLastId());
25  out_tree_->Branch(
26  out_branch_.c_str(), "AnalysisTree::Particles", &sim_tracks_);
27 }
28 
30  assert(cbm_mc_tracks_);
31  out_indexes_map_.clear();
32 
33  std::cout << "ReadMcTracks" << std::endl;
34  sim_tracks_->ClearChannels();
35 
36  const int nMcTracks = cbm_mc_tracks_->GetEntries();
37  const int imother_id =
38  out_config_->GetBranchConfig(sim_tracks_->GetId()).GetFieldId("mother_id");
39  sim_tracks_->Reserve(nMcTracks);
40 
41  for (int iMcTrack = 0; iMcTrack < nMcTracks; ++iMcTrack) {
42  const auto* mctrack = (CbmMCTrack*) cbm_mc_tracks_->At(iMcTrack);
43  if (mctrack->GetStartZ() > 200.)
44  continue; // to exclude shower in PSD etc //TODO check if better cut can
45  // be applied.
46 
47  auto* Track = sim_tracks_->AddChannel();
48  Track->Init(out_config_->GetBranchConfig(sim_tracks_->GetId()));
49 
50  out_indexes_map_.insert(std::make_pair(iMcTrack, Track->GetId()));
51 
52  Track->SetMomentum(mctrack->GetPx(), mctrack->GetPy(), mctrack->GetPz());
53  Track->SetMass(float(mctrack->GetMass()));
54  Track->SetPid(int(mctrack->GetPdgCode()));
55 
56  if (mctrack->GetMotherId()
57  == -1) { // mother id should < than track id, so we can do it here
58  Track->SetField(int(-1), imother_id);
59  } else {
60  auto p = out_indexes_map_.find(mctrack->GetMotherId());
61  if (p == out_indexes_map_.end()) // match is not found
62  Track->SetField(int(-999), imother_id);
63  else
64  Track->SetField(int(p->second), imother_id);
65  }
66  }
67 }
ClassImp
ClassImp(CbmSimTracksConverter) void CbmSimTracksConverter
Definition: CbmSimTracksConverter.cxx:11
CbmSimTracksConverter::Exec
void Exec() final
Definition: CbmSimTracksConverter.cxx:29
CbmSimTracksConverter
Definition: CbmSimTracksConverter.h:10
CbmSimTracksConverter::~CbmSimTracksConverter
~CbmSimTracksConverter() final
Definition: CbmSimTracksConverter.cxx:68
CbmSimTracksConverter::cbm_mc_tracks_
TClonesArray * cbm_mc_tracks_
Definition: CbmSimTracksConverter.h:26
CbmSimTracksConverter::Init
void Init(std::map< std::string, void * > &) final
CbmSimTracksConverter.h
CbmConverterTask::out_indexes_map_
std::map< int, int > out_indexes_map_
Definition: CbmConverterTask.h:31
CbmMCTrack.h
CbmMCTrack
Definition: CbmMCTrack.h:34
CbmSimTracksConverter::sim_tracks_
AnalysisTree::Particles * sim_tracks_
Definition: CbmSimTracksConverter.h:25