CbmRoot
NicaCbmMCEventInterface.cxx
Go to the documentation of this file.
1 /*
2  * NicaCbmMCEventInterface.cxx
3  *
4  * Created on: 20 wrz 2018
5  * Author: Daniel Wielanek
6  * E-mail: daniel.wielanek@gmail.com
7  * Warsaw University of Technology, Faculty of Physics
8  */
10 #include "CbmMCTrack.h"
11 #include "FairRootManager.h"
13 
15  fEvent = new FairMCEventHeader();
16  fCbmTracks = new TClonesArray("CbmMCTrack");
17 }
18 
20  if (fEvent == NULL) {
21  fEvent = new FairMCEventHeader();
22  fCbmTracks = new TClonesArray("CbmMCTrack", 1000);
23  }
24  FairRootManager* manager = FairRootManager::Instance();
25  TString event_name = "MCEventHeader.";
26  TString track_name = "MCTrack";
27  manager->Register(event_name, "MCEventHeader", fEvent, write);
28  manager->Register(track_name, "CbmMCTrack", fCbmTracks, write);
29 }
30 
31 void NicaCbmMCEventInterface::Clear(Option_t* opt) { fCbmTracks->Clear(opt); }
32 
33 void NicaCbmMCEventInterface::Compress(Int_t* map, Int_t map_size) {
34  Int_t track_pos = 0;
35  for (int i = 0; i < map_size; i++) {
36  Int_t good_track = map[i];
37  for (int j = track_pos; j < good_track; j++) {
38  fCbmTracks->RemoveAt(j);
39  }
40  track_pos = good_track + 1;
41  }
42  fCbmTracks->Compress();
43 }
44 
45 void NicaCbmMCEventInterface::CopyData(NicaEventInterface* s) {
46  FairMCEventHeader* header =
47  (FairMCEventHeader*) ((NicaCbmMCEventInterface*) s)->fEvent;
48  TClonesArray* tracks =
49  (TClonesArray*) ((NicaCbmMCEventInterface*) s)->fCbmTracks;
50  fEvent->SetRunID(header->GetRunID());
51  fEvent->SetEventID(header->GetEventID());
52  fEvent->SetVertex(header->GetX(), header->GetY(), header->GetZ());
53  fEvent->SetRotX(header->GetRotX());
54  fEvent->SetRotY(header->GetRotY());
55  fEvent->SetRotZ(header->GetRotZ());
56  fEvent->SetB(header->GetB());
57  fEvent->SetNPrim(header->GetNPrim());
58  fCbmTracks->Clear();
59  fCbmTracks->ExpandCreateFast(tracks->GetEntriesFast());
60  for (int i = 0; i < fCbmTracks->GetEntriesFast(); i++) {
61  CbmMCTrack* from =
62  (CbmMCTrack*) ((NicaCbmMCEventInterface*) s)->fCbmTracks->UncheckedAt(i);
63  CbmMCTrack* to = (CbmMCTrack*) fCbmTracks->UncheckedAt(i);
64  *to = *from;
65  }
66 }
67 
68 void NicaCbmMCEventInterface::CopyAndCompress(NicaEventInterface* s,
69  Int_t* map,
70  Int_t map_size) {
71  FairMCEventHeader* header =
72  (FairMCEventHeader*) ((NicaCbmMCEventInterface*) s)->fEvent;
73  fEvent->SetRunID(header->GetRunID());
74  fEvent->SetEventID(header->GetEventID());
75  fEvent->SetVertex(header->GetX(), header->GetY(), header->GetZ());
76  fEvent->SetRotX(header->GetRotX());
77  fEvent->SetRotY(header->GetRotY());
78  fEvent->SetRotZ(header->GetRotZ());
79  fEvent->SetB(header->GetB());
80  fEvent->SetNPrim(header->GetNPrim());
81  fCbmTracks->Clear();
82  for (int i = 0; i < map_size; i++) {
84  ->fCbmTracks->UncheckedAt(map[i]);
85  CbmMCTrack* to = (CbmMCTrack*) fCbmTracks->ConstructedAt(i);
86  *to = *from;
87  }
88 }
89 
90 void NicaCbmMCEventInterface::FillTrackInterface(NicaTrackInterface* track,
91  Int_t index) {
92  track->SetRawTrack(fCbmTracks->UncheckedAt(index));
93 }
94 
95 NicaTrackInterface* NicaCbmMCEventInterface::GetTrackInterface() const {
96  return new NicaCbmMCTrackInterface();
97 }
98 
99 TLorentzVector NicaCbmMCEventInterface::GetVertex() const {
100  TLorentzVector vec;
101  TVector3 vec3d;
102  fEvent->GetVertex(vec3d);
103  vec.SetXYZT(vec3d.X(), vec3d.Y(), vec3d.Z(), 0);
104  return vec;
105 }
106 
108  if (CanDeleteEvent()) {
109  if (fEvent) delete fEvent;
110  if (fCbmTracks) delete fCbmTracks;
111  }
112 }
113 
115  FairRootManager* manager = FairRootManager::Instance();
116  if (CanDeleteEvent()) {
117  if (fEvent) delete fEvent;
118  if (fCbmTracks) delete fCbmTracks;
119  }
120  fEvent = (FairMCEventHeader*) manager->GetObject("MCEventHeader.");
121  if (fEvent == NULL)
122  fEvent = (FairMCEventHeader*) manager->GetObject("EventHeader.");
123  fCbmTracks = (TClonesArray*) manager->GetObject("MCTrack");
124 }
NicaCbmMCEventInterface::FillTrackInterface
virtual void FillTrackInterface(NicaTrackInterface *track, Int_t index)
Definition: NicaCbmMCEventInterface.cxx:90
NicaCbmMCEventInterface::~NicaCbmMCEventInterface
virtual ~NicaCbmMCEventInterface()
Definition: NicaCbmMCEventInterface.cxx:107
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
NicaCbmMCEventInterface::Register
virtual void Register(Bool_t write)
Definition: NicaCbmMCEventInterface.cxx:19
NicaCbmMCEventInterface::fEvent
FairMCEventHeader * fEvent
Definition: NicaCbmMCEventInterface.h:21
NicaCbmMCTrackInterface.h
NicaCbmMCEventInterface::CopyAndCompress
virtual void CopyAndCompress(NicaEventInterface *s, Int_t *map, Int_t map_size)
Definition: NicaCbmMCEventInterface.cxx:68
NicaCbmMCEventInterface::GetTrackInterface
virtual NicaTrackInterface * GetTrackInterface() const
Definition: NicaCbmMCEventInterface.cxx:95
NicaCbmMCTrackInterface
Definition: NicaCbmMCTrackInterface.h:13
NicaCbmMCEventInterface::ConnectToTree
virtual void ConnectToTree()
Definition: NicaCbmMCEventInterface.cxx:114
tracks
TClonesArray * tracks
Definition: Analyze_matching.h:17
NicaCbmMCEventInterface.h
NicaCbmMCEventInterface::NicaCbmMCEventInterface
NicaCbmMCEventInterface()
Definition: NicaCbmMCEventInterface.cxx:14
NicaCbmMCEventInterface::Compress
virtual void Compress(Int_t *map, Int_t map_size)
Definition: NicaCbmMCEventInterface.cxx:33
NicaCbmMCEventInterface::CopyData
virtual void CopyData(NicaEventInterface *s)
Definition: NicaCbmMCEventInterface.cxx:45
NicaCbmMCEventInterface::Clear
virtual void Clear(Option_t *opt="")
Definition: NicaCbmMCEventInterface.cxx:31
CbmMCTrack.h
CbmMCTrack
Definition: CbmMCTrack.h:34
NicaCbmMCEventInterface
Definition: NicaCbmMCEventInterface.h:17
NicaCbmMCEventInterface::fCbmTracks
TClonesArray * fCbmTracks
Definition: NicaCbmMCEventInterface.h:22
NicaCbmMCEventInterface::GetVertex
virtual TLorentzVector GetVertex() const
Definition: NicaCbmMCEventInterface.cxx:99