BOSS 7.0.9
BESIII Offline Software System
Loading...
Searching...
No Matches
BesRootIO.cc
Go to the documentation of this file.
4#include "BesMdcHit.hh"
5#include "BesTofHit.hh"
6#include "BesEmcDigi.hh"
7#include "BesEventAction.hh"
8#include "G4RunManager.hh"
9#include "BesTruthTrack.hh"
10#include "BesTruthVertex.hh"
12#include "G4HCofThisEvent.hh"
13#include "G4SDManager.hh"
14#include "G4PrimaryVertex.hh"
15#include "G4PrimaryParticle.hh"
16
17#include "TFile.h"
18#include "TTree.h"
19#include "BesRootIO.hh"
20
21#include "G4ThreeVector.hh"
22
23#include "AsciiDmp/AsciiData.hh"
24#include "G4DigiManager.hh"
25#include <iostream>
26//#include <vector>
27using namespace std;
28//using std::vector;
29
30#include "GaudiKernel/IDataProviderSvc.h"
31#include "GaudiKernel/ISvcLocator.h"
32#include "GaudiKernel/Bootstrap.h"
33#include "GaudiKernel/RegistryEntry.h"
34#include "GaudiKernel/MsgStream.h"
35#include "GaudiKernel/SmartDataPtr.h"
36
37#include "G4Svc/IG4Svc.h"
38#include "G4Svc/G4Svc.h"
39
41 G4int mdcTruFlag,G4int mdcDigiFlag,
42 G4int tofTruFlag, G4int tofDigiFlag,
43 G4int emcTruFlag, G4int emcDigiFlag,
44 G4int mucTruFlag, G4int mucDigiFlag,G4String name)
45 :m_mdcTruFlag(mdcTruFlag),m_mdcDigiFlag(mdcDigiFlag),
46 m_tofTruFlag(tofTruFlag),m_tofDigiFlag(tofDigiFlag),
47 m_emcTruFlag(emcTruFlag),m_emcDigiFlag(emcDigiFlag),
48 m_mucTruFlag(mucTruFlag),m_mucDigiFlag(mucDigiFlag),m_rootFile(name)
49{
50 m_DigiMan = G4DigiManager::GetDMpointer();
51
52 f = new TFile(m_rootFile,"RECREATE");
53 //create a MdcHit TTree
54 m_TMcHitEvent = new TMcHitEvent();
55 HitTree = new TTree("HitTree","staff data from HitCollection");
56
57 HitTree->Branch("TMcHitEvent", "TMcHitEvent", &m_TMcHitEvent, 32000, 99);
58}
59
61{
62 f->Write();
63}
64
65void BesRootIO::SaveHitRootEvent(G4int runId, const G4Event* evt)
66{
67 //std::cout << "Save Hit Root Event" << std::endl;
68 if (m_mdcDigiFlag)
69 {
71 }
72 if (m_tofDigiFlag)
73 {
75 }
76 if (m_emcDigiFlag){
78 }
79
80 HitTree->Fill();
81
82 m_TMcHitEvent->Clear();
83}
84
86 //std::cout << "SaveEmcDigiRootEvent" << std::endl;
87 G4int emcDigiCollID = -1;
88 emcDigiCollID = m_DigiMan->GetDigiCollectionID("BesEmcDigitsCollection");
89 if(emcDigiCollID>=0)
90 {
91 BesEmcDigitsCollection* emcDC = (BesEmcDigitsCollection*)m_DigiMan->GetDigiCollection(emcDigiCollID);
92 G4int nHits = emcDC->entries();
93 //std::cout << "nHits: " << nHits << std::endl;
94
95 if(nHits>0){
96 BesEmcDigi* emcDigi;
97 for (int i = 0; i < nHits; i++) {
98 emcDigi=(*emcDC)[i];
99 TMcDigiEmc* tEmcDigi = new TMcDigiEmc();
100
101 tEmcDigi->SetPartId(emcDigi->GetPartId());
102 tEmcDigi->SetThetaNb(emcDigi->GetThetaNb());
103 tEmcDigi->SetPhiNb(emcDigi->GetPhiNb());
104 tEmcDigi->SetEnergy(emcDigi->GetEnergy());
105 tEmcDigi->SetTime(emcDigi->GetTime());
106 tEmcDigi->SetTrackIndex(emcDigi->GetTrackIndex());
107 //emcDigi->Print();
108 //std::cout << "SetEnergy" << emcDigi->GetEnergy() << std::endl;
109
110 m_TMcHitEvent->addMcDigiEmc(tEmcDigi);
111 //std::cout << "addMcDigiEmc" << std::endl;
112 }
113 }
114 }
115}
116
118{
119 //std::cout << "SaveMdcHitRoot" << std::endl;
120 G4int THCID = -1;
121 THCID = m_DigiMan->GetHitsCollectionID("BesMdcHitsCollection");
122 if (THCID>=0)
123 {
124 BesMdcHitsCollection* mdcDC = (BesMdcHitsCollection*) (m_DigiMan->GetHitsCollection(THCID));
125 G4int nHits = mdcDC->entries();
126 //std::cout << "nHits: " << nHits << std::endl;
127 if (nHits>0)
128 {
129 BesMdcHit* mdcHit;
130 for (int i=0;i<nHits;i++)
131 {
132 mdcHit=(*mdcDC)[i];
133 TMcHitMdc* tMdcHit = new TMcHitMdc();
134 tMdcHit->SetTrackID(mdcHit->GetTrackID());
135 tMdcHit->SetLayerNo(mdcHit->GetLayerNo());
136 tMdcHit->SetCellNo(mdcHit->GetCellNo());
137 tMdcHit->SetEdep(mdcHit->GetEdep());
138 tMdcHit->SetDriftD(mdcHit->GetDriftD());
139 tMdcHit->SetDriftT(mdcHit->GetDriftT());
140 tMdcHit->SetGlobalT(mdcHit->GetGlobalT());
141 tMdcHit->SetTheta(mdcHit->GetTheta());
142 tMdcHit->SetEnterAngle(mdcHit->GetEnterAngle());
143 tMdcHit->SetPosFlag(mdcHit->GetPosFlag());
144
145 G4ThreeVector gTemp = mdcHit->GetPos();
146 TVector3 tTemp = TVector3(gTemp.x(), gTemp.y(), gTemp.z());
147 tMdcHit->SetPos(tTemp);
148
149 //mdcHit->Print();
150 m_TMcHitEvent->addMcHitMdc(tMdcHit);
151 }
152 }
153 }
154
155
156}
157
159{
160 //retrieve G4Svc
161 ISvcLocator* svcLocator = Gaudi::svcLocator();
162 IG4Svc* tmpSvc;
163 StatusCode sc = svcLocator->service("G4Svc", tmpSvc);
164 G4Svc* m_G4Svc = dynamic_cast<G4Svc *>(tmpSvc);
165 double m_beamTime = m_G4Svc->GetBeamTime() * ns;
166 m_TMcHitEvent->setBeamTime(m_beamTime);
167 //std::cout << "beamtime: " << m_beamTime << std::endl;
168
169 G4int THCID = -1;
170 THCID = m_DigiMan->GetHitsCollectionID("BesTofHitsCollection");
171 if (THCID>=0)
172 {
173 BesTofHitsCollection* tofDC = (BesTofHitsCollection*) (m_DigiMan->GetHitsCollection(THCID));
174 G4int nHits = tofDC->entries();
175 //std::cout << "nHits: " << nHits << std::endl;
176 if (nHits>0)
177 {
178 BesTofHit* tofHit;
179 for (int i=0;i<nHits;i++)
180 {
181 tofHit=(*tofDC)[i];
182 TMcHitTof* tTofHit = new TMcHitTof();
183 tTofHit->SetTrackIndex(tofHit->GetTrackIndex());
184 tTofHit->SetG4Index(tofHit->GetG4Index());
185 tTofHit->SetPartId(tofHit->GetPartId());
186 tTofHit->SetScinNb(tofHit->GetScinNb());
187 tTofHit->SetEdep(tofHit->GetEdep());
188 tTofHit->SetStepL(tofHit->GetStepL());
189 tTofHit->SetTrackL(tofHit->GetTrackL());
190 tTofHit->SetTime(tofHit->GetTime());
191 tTofHit->SetDeltaT(tofHit->GetDeltaT());
192 tTofHit->SetCharge(tofHit->GetCharge());
193
194 G4ThreeVector gTemp = tofHit->GetPos();
195 TVector3 tTemp(gTemp.x(), gTemp.y(), gTemp.z());
196 tTofHit->SetPos(tTemp);
197
198 gTemp = tofHit->GetPDirection();
199 tTemp = TVector3(gTemp.x(), gTemp.y(), gTemp.z());
200 tTofHit->SetPDirection(tTemp);
201
202 gTemp = tofHit->GetMomentum();
203 tTemp = TVector3(gTemp.x(), gTemp.y(), gTemp.z());
204 tTofHit->SetMomentum(tTemp);
205
206 //tofHit->Print();
207 m_TMcHitEvent->addMcHitTof(tTofHit);
208 }
209 }
210 }
211
212}
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection
Definition: BesEmcDigi.hh:69
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
Definition: BesMdcHit.hh:78
G4THitsCollection< BesTofHit > BesTofHitsCollection
Definition: BesTofHit.hh:116
G4int GetTrackIndex()
Definition: BesEmcDigi.hh:54
G4int GetThetaNb()
Definition: BesEmcDigi.hh:50
G4double GetEnergy()
Definition: BesEmcDigi.hh:52
G4int GetPhiNb()
Definition: BesEmcDigi.hh:51
G4double GetTime()
Definition: BesEmcDigi.hh:53
G4int GetPartId()
Definition: BesEmcDigi.hh:49
G4double GetEdep()
Definition: BesMdcHit.hh:53
G4double GetTheta()
Definition: BesMdcHit.hh:58
G4int GetTrackID()
Definition: BesMdcHit.hh:50
G4int GetPosFlag()
Definition: BesMdcHit.hh:60
G4double GetGlobalT()
Definition: BesMdcHit.hh:57
G4double GetEnterAngle()
Definition: BesMdcHit.hh:59
G4int GetLayerNo()
Definition: BesMdcHit.hh:51
G4double GetDriftD()
Definition: BesMdcHit.hh:55
G4double GetDriftT()
Definition: BesMdcHit.hh:56
G4ThreeVector GetPos()
Definition: BesMdcHit.hh:54
G4int GetCellNo()
Definition: BesMdcHit.hh:52
~BesRootIO()
Definition: BesRootIO.cc:60
TFile * f
Definition: BesRootIO.hh:23
void SaveMdcHitRoot()
Definition: BesRootIO.cc:117
void SaveHitRootEvent(G4int, const G4Event *)
Definition: BesRootIO.cc:65
void SaveEmcDigiRootEvent()
Definition: BesRootIO.cc:85
TTree * HitTree
Definition: BesRootIO.hh:24
void SaveTofHitRoot()
Definition: BesRootIO.cc:158
BesRootIO(G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4String)
Definition: BesRootIO.cc:40
G4double GetDeltaT()
Definition: BesTofHit.hh:75
G4ThreeVector GetPDirection()
Definition: BesTofHit.hh:76
G4double GetStepL()
Definition: BesTofHit.hh:71
G4double GetCharge()
Definition: BesTofHit.hh:80
G4double GetTime()
Definition: BesTofHit.hh:74
G4double GetEdep()
Definition: BesTofHit.hh:70
G4ThreeVector GetPos()
Definition: BesTofHit.hh:73
G4int GetScinNb()
Definition: BesTofHit.hh:69
G4int GetPartId()
Definition: BesTofHit.hh:68
G4double GetTrackL()
Definition: BesTofHit.hh:72
G4int GetG4Index()
Definition: BesTofHit.hh:67
G4ThreeVector GetMomentum()
Definition: BesTofHit.hh:77
G4int GetTrackIndex()
Definition: BesTofHit.hh:66
Definition: G4Svc.h:32
double GetBeamTime()
Definition: G4Svc.h:85
Definition: IG4Svc.h:30
void SetThetaNb(Int_t nTheta)
Definition: TMcDigiEmc.h:17
void SetPhiNb(Int_t nPhi)
Definition: TMcDigiEmc.h:18
void SetPartId(Int_t id)
Definition: TMcDigiEmc.h:16
void SetTime(Double_t time)
Definition: TMcDigiEmc.h:20
void SetTrackIndex(Int_t index)
Definition: TMcDigiEmc.h:21
void SetEnergy(Double_t energy)
Definition: TMcDigiEmc.h:19
void addMcHitTof(TMcHitTof *hit)
Add a McHitTof into the TOF Data collection.
Definition: TMcHitEvent.cxx:63
void addMcDigiEmc(TMcDigiEmc *digi)
Add a McHitMdc into the Mdc Data collection.
Definition: TMcHitEvent.cxx:52
void addMcHitMdc(TMcHitMdc *hit)
Add a McHitMdc into the Mdc Data collection.
Definition: TMcHitEvent.cxx:74
void Clear(Option_t *option="")
Definition: TMcHitEvent.cxx:33
void setBeamTime(Double_t time)
Definition: TMcHitEvent.h:49
void SetDriftT(Double_t time)
Definition: TMcHitMdc.h:22
void SetDriftD(Double_t distance)
Definition: TMcHitMdc.h:21
void SetPosFlag(Int_t flag)
Definition: TMcHitMdc.h:26
void SetGlobalT(Double_t time)
Definition: TMcHitMdc.h:23
void SetTheta(Double_t angle)
Definition: TMcHitMdc.h:24
void SetCellNo(Int_t cell)
Definition: TMcHitMdc.h:18
void SetEnterAngle(Double_t angle)
Definition: TMcHitMdc.h:25
void SetPos(TVector3 xyz)
Definition: TMcHitMdc.h:20
void SetTrackID(Int_t track)
Definition: TMcHitMdc.h:16
void SetEdep(Double_t de)
Definition: TMcHitMdc.h:19
void SetLayerNo(Int_t layer)
Definition: TMcHitMdc.h:17
void SetStepL(Double_t stepL)
Definition: TMcHitTof.h:22
void SetTime(Double_t time)
Definition: TMcHitTof.h:25
void SetTrackIndex(Int_t trackIndex)
Definition: TMcHitTof.h:17
void SetG4Index(Int_t index)
Definition: TMcHitTof.h:18
void SetPos(TVector3 pos)
Definition: TMcHitTof.h:24
void SetMomentum(TVector3 momentum)
Definition: TMcHitTof.h:28
void SetDeltaT(Double_t deltaT)
Definition: TMcHitTof.h:26
void SetEdep(Double_t edep)
Definition: TMcHitTof.h:21
void SetPartId(Int_t partId)
Definition: TMcHitTof.h:19
void SetPDirection(TVector3 pDirection)
Definition: TMcHitTof.h:27
void SetCharge(Int_t charge)
Definition: TMcHitTof.h:29
void SetTrackL(Double_t length)
Definition: TMcHitTof.h:23
void SetScinNb(Int_t scinNb)
Definition: TMcHitTof.h:20
#define ns(x)
Definition: xmltok.c:1504