BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
BesRootIO.cc
Go to the documentation of this file.
1#include "RootEventData/TMcHitTof.h"
2#include "RootEventData/TMcHitEvent.h"
3#include "RootEventData/TMcDigiEmc.h"
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"
11#include "BesSensitiveManager.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
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
~BesRootIO()
Definition: BesRootIO.cc:60
void SaveMdcHitRoot()
Definition: BesRootIO.cc:117
void SaveHitRootEvent(G4int, const G4Event *)
Definition: BesRootIO.cc:65
void SaveEmcDigiRootEvent()
Definition: BesRootIO.cc:85
void SaveTofHitRoot()
Definition: BesRootIO.cc:158
BesRootIO(G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4String)
Definition: BesRootIO.cc:40
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
#define ns(x)
Definition: xmltok.c:1504