CGEM BOSS 6.6.5.f
BESIII Offline Software System
Loading...
Searching...
No Matches
bak_BesSim-00-04-14/src/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 "BesCgemHit.hh"
6#include "BesTofHit.hh"
7#include "BesEmcDigi.hh"
8#include "BesEventAction.hh"
9#include "G4RunManager.hh"
10#include "BesTruthTrack.hh"
11#include "BesTruthVertex.hh"
12#include "BesSensitiveManager.hh"
13#include "G4HCofThisEvent.hh"
14#include "G4SDManager.hh"
15#include "G4PrimaryVertex.hh"
16#include "G4PrimaryParticle.hh"
17
18#include "TFile.h"
19#include "TTree.h"
20#include "BesRootIO.hh"
21
22#include "G4ThreeVector.hh"
23
24#include "AsciiDmp/AsciiData.hh"
25#include "G4DigiManager.hh"
26#include <iostream>
27//#include <vector>
28using namespace std;
29//using std::vector;
30
31#include "GaudiKernel/IDataProviderSvc.h"
32#include "GaudiKernel/ISvcLocator.h"
33#include "GaudiKernel/Bootstrap.h"
34#include "GaudiKernel/RegistryEntry.h"
35#include "GaudiKernel/MsgStream.h"
36#include "GaudiKernel/SmartDataPtr.h"
37
38#include "G4Svc/IG4Svc.h"
39#include "G4Svc/G4Svc.h"
40
42 G4int mdcTruFlag,G4int mdcDigiFlag,
43 G4int cgemTruFlag,G4int cgemDigiFlag,
44 G4int tofTruFlag, G4int tofDigiFlag,
45 G4int emcTruFlag, G4int emcDigiFlag,
46 G4int mucTruFlag, G4int mucDigiFlag,G4String name)
47 :m_mdcTruFlag(mdcTruFlag),m_mdcDigiFlag(mdcDigiFlag),
48 m_cgemTruFlag(cgemTruFlag),m_cgemDigiFlag(cgemDigiFlag),
49 m_tofTruFlag(tofTruFlag),m_tofDigiFlag(tofDigiFlag),
50 m_emcTruFlag(emcTruFlag),m_emcDigiFlag(emcDigiFlag),
51 m_mucTruFlag(mucTruFlag),m_mucDigiFlag(mucDigiFlag),m_rootFile(name)
52{
53 m_DigiMan = G4DigiManager::GetDMpointer();
54
55 f = new TFile(m_rootFile,"RECREATE");
56 //create a MdcHit TTree
57 m_TMcHitEvent = new TMcHitEvent();
58 HitTree = new TTree("HitTree","staff data from HitCollection");
59
60 HitTree->Branch("TMcHitEvent", "TMcHitEvent", &m_TMcHitEvent, 32000, 99);
61}
62
64{
65 f->Write();
66}
67
68void BesRootIO::SaveHitRootEvent(G4int runId, const G4Event* evt)
69{
70 //std::cout << "Save Hit Root Event" << std::endl;
71 if (m_mdcDigiFlag)
72 {
74 }
75 if (m_cgemDigiFlag)
76 {
78 }
79 if (m_tofDigiFlag)
80 {
82 }
83 if (m_emcDigiFlag){
85 }
86
87 HitTree->Fill();
88
89 m_TMcHitEvent->Clear();
90}
91
93 //std::cout << "SaveEmcDigiRootEvent" << std::endl;
94 G4int emcDigiCollID = -1;
95 emcDigiCollID = m_DigiMan->GetDigiCollectionID("BesEmcDigitsCollection");
96 if(emcDigiCollID>=0)
97 {
98 BesEmcDigitsCollection* emcDC = (BesEmcDigitsCollection*)m_DigiMan->GetDigiCollection(emcDigiCollID);
99 G4int nHits = emcDC->entries();
100 //std::cout << "nHits: " << nHits << std::endl;
101
102 if(nHits>0){
103 BesEmcDigi* emcDigi;
104 for (int i = 0; i < nHits; i++) {
105 emcDigi=(*emcDC)[i];
106 TMcDigiEmc* tEmcDigi = new TMcDigiEmc();
107
108 tEmcDigi->SetPartId(emcDigi->GetPartId());
109 tEmcDigi->SetThetaNb(emcDigi->GetThetaNb());
110 tEmcDigi->SetPhiNb(emcDigi->GetPhiNb());
111 tEmcDigi->SetEnergy(emcDigi->GetEnergy());
112 tEmcDigi->SetTime(emcDigi->GetTime());
113 tEmcDigi->SetTrackIndex(emcDigi->GetTrackIndex());
114 //emcDigi->Print();
115 //std::cout << "SetEnergy" << emcDigi->GetEnergy() << std::endl;
116
117 m_TMcHitEvent->addMcDigiEmc(tEmcDigi);
118 //std::cout << "addMcDigiEmc" << std::endl;
119 }
120 }
121 }
122}
123
125{
126 //std::cout << "SaveMdcHitRoot" << std::endl;
127 G4int THCID = -1;
128 THCID = m_DigiMan->GetHitsCollectionID("BesMdcHitsCollection");
129 if (THCID>=0)
130 {
131 BesMdcHitsCollection* mdcDC = (BesMdcHitsCollection*) (m_DigiMan->GetHitsCollection(THCID));
132 G4int nHits = mdcDC->entries();
133 //std::cout << "nHits: " << nHits << std::endl;
134 if (nHits>0)
135 {
136 BesMdcHit* mdcHit;
137 for (int i=0;i<nHits;i++)
138 {
139 mdcHit=(*mdcDC)[i];
140 TMcHitMdc* tMdcHit = new TMcHitMdc();
141 tMdcHit->SetTrackID(mdcHit->GetTrackID());
142 tMdcHit->SetLayerNo(mdcHit->GetLayerNo());
143 tMdcHit->SetCellNo(mdcHit->GetCellNo());
144 tMdcHit->SetEdep(mdcHit->GetEdep());
145 tMdcHit->SetDriftD(mdcHit->GetDriftD());
146 tMdcHit->SetDriftT(mdcHit->GetDriftT());
147 tMdcHit->SetGlobalT(mdcHit->GetGlobalT());
148 tMdcHit->SetTheta(mdcHit->GetTheta());
149 tMdcHit->SetEnterAngle(mdcHit->GetEnterAngle());
150 tMdcHit->SetPosFlag(mdcHit->GetPosFlag());
151
152 G4ThreeVector gTemp = mdcHit->GetPos();
153 TVector3 tTemp = TVector3(gTemp.x(), gTemp.y(), gTemp.z());
154 tMdcHit->SetPos(tTemp);
155
156 //mdcHit->Print();
157 m_TMcHitEvent->addMcHitMdc(tMdcHit);
158 }
159 }
160 }
161
162
163}
164
166{
167 //std::cout << "SaveCgemHitRoot" << std::endl;
168 G4int THCID = -1;
169 THCID = m_DigiMan->GetHitsCollectionID("BesCgemHitsCollection");
170 if (THCID>=0)
171 {
172 BesCgemHitsCollection *cgemDC=(BesCgemHitsCollection*)(m_DigiMan->GetHitsCollection(THCID));
173 G4int nHits = cgemDC->entries();
174 //std::cout << "nHits: " << nHits << std::endl;
175 if (nHits>0)
176 {
177 BesCgemHit* cgemHit;
178 for (int i=0;i<nHits;i++)
179 {
180 cgemHit=(*cgemDC)[i];
181 TMcHitCgem* tCgemHit = new TMcHitCgem();
182
183 tCgemHit->SetTrackID (cgemHit->GetTrackID ());
184 tCgemHit->SetLayerID (cgemHit->GetLayerID ());
185 tCgemHit->SetPDGCode (cgemHit->GetPDGCode ());
186 tCgemHit->SetGlobalTime (cgemHit->GetGlobalTime ());
187 tCgemHit->SetTotalEnergyDeposit (cgemHit->GetTotalEnergyDeposit ());
188 tCgemHit->SetStepLength (cgemHit->GetStepLength ());
189
190 G4ThreeVector XYZ_pre = cgemHit->GetPositionOfPrePoint ();
191 G4ThreeVector XYZ_post = cgemHit->GetPositionOfPostPoint();
192 G4ThreeVector P_pre = cgemHit->GetMomentumOfPrePoint ();
193 G4ThreeVector P_post = cgemHit->GetMomentumOfPostPoint();
194
195 TVector3 tmp_XYZ_pre = TVector3(XYZ_pre.x() , XYZ_pre.y() , XYZ_pre.z() );
196 TVector3 tmp_XYZ_post = TVector3(XYZ_post.x() , XYZ_post.y() , XYZ_post.z() );
197 TVector3 tmp_P_pre = TVector3(P_pre.x() , P_pre.y() , P_pre.z() );
198 TVector3 tmp_P_post = TVector3(P_post.x() , P_post.y() , P_post.z() );
199
200 tCgemHit->SetPositionOfPrePoint ( tmp_XYZ_pre );
201 tCgemHit->SetPositionOfPostPoint ( tmp_XYZ_post );
202 tCgemHit->SetMomentumOfPrePoint ( tmp_P_pre );
203 tCgemHit->SetMomentumOfPostPoint ( tmp_P_post );
204 /*
205// ******************************************************************
206 G4ThreeVector Cu_pre = cgemHit->GetPrePositionInCu ();
207 G4ThreeVector Cu_post = cgemHit->GetPostPositionInCu();
208 G4ThreeVector P_Cu_pre = cgemHit->GetMomentumOfCuPre ();
209 G4ThreeVector P_Cu_post = cgemHit->GetMomentumOfCuPost();
210
211 TVector3 tmp_Cu_pre = TVector3(Cu_pre.x() , Cu_pre.y() , Cu_pre.z() );
212 TVector3 tmp_Cu_post = TVector3(Cu_post.x() , Cu_post.y() , Cu_post.z() );
213 TVector3 tmp_P_Cu_pre = TVector3(P_Cu_pre.x() ,P_Cu_pre.y() , P_Cu_pre.z() );
214 TVector3 tmp_P_Cu_post = TVector3(P_Cu_post.x() ,P_Cu_post.y() , P_Cu_post.z() );
215
216 tCgemHit->SetPrePositionInCu ( tmp_Cu_pre );
217 tCgemHit->SetPostPositionInCu ( tmp_Cu_post );
218 tCgemHit->SetMomentumOfCuPre ( tmp_P_Cu_pre );
219 tCgemHit->SetMomentumOfCuPost ( tmp_P_Cu_post );
220// ******************************************************************************************
221 */
222 //cgemHit->Print();
223 m_TMcHitEvent->addMcHitCgem(tCgemHit);
224
225 } /* End of 'for (int i=0;i<nHits;i++)' */
226 } /* End of 'if (nHits>0)' */
227 } /* End of 'if (THCID>=0)' */
228} /* End of 'void BesRootIO::SaveCgemHitRoot()' */
229
231{
232 //retrieve G4Svc
233 ISvcLocator* svcLocator = Gaudi::svcLocator();
234 IG4Svc* tmpSvc;
235 StatusCode sc = svcLocator->service("G4Svc", tmpSvc);
236 G4Svc* m_G4Svc = dynamic_cast<G4Svc *>(tmpSvc);
237 double m_beamTime = m_G4Svc->GetBeamTime() * ns;
238 m_TMcHitEvent->setBeamTime(m_beamTime);
239 //std::cout << "beamtime: " << m_beamTime << std::endl;
240
241 G4int THCID = -1;
242 THCID = m_DigiMan->GetHitsCollectionID("BesTofHitsCollection");
243 if (THCID>=0)
244 {
245 BesTofHitsCollection* tofDC = (BesTofHitsCollection*) (m_DigiMan->GetHitsCollection(THCID));
246 G4int nHits = tofDC->entries();
247 //std::cout << "nHits: " << nHits << std::endl;
248 if (nHits>0)
249 {
250 BesTofHit* tofHit;
251 for (int i=0;i<nHits;i++)
252 {
253 tofHit=(*tofDC)[i];
254 TMcHitTof* tTofHit = new TMcHitTof();
255 tTofHit->SetTrackIndex(tofHit->GetTrackIndex());
256 tTofHit->SetG4Index(tofHit->GetG4Index());
257 tTofHit->SetPartId(tofHit->GetPartId());
258 tTofHit->SetScinNb(tofHit->GetScinNb());
259 tTofHit->SetEdep(tofHit->GetEdep());
260 tTofHit->SetStepL(tofHit->GetStepL());
261 tTofHit->SetTrackL(tofHit->GetTrackL());
262 tTofHit->SetTime(tofHit->GetTime());
263 tTofHit->SetDeltaT(tofHit->GetDeltaT());
264 tTofHit->SetCharge(tofHit->GetCharge());
265
266 G4ThreeVector gTemp = tofHit->GetPos();
267 TVector3 tTemp(gTemp.x(), gTemp.y(), gTemp.z());
268 tTofHit->SetPos(tTemp);
269
270 gTemp = tofHit->GetPDirection();
271 tTemp = TVector3(gTemp.x(), gTemp.y(), gTemp.z());
272 tTofHit->SetPDirection(tTemp);
273
274 gTemp = tofHit->GetMomentum();
275 tTemp = TVector3(gTemp.x(), gTemp.y(), gTemp.z());
276 tTofHit->SetMomentum(tTemp);
277
278 //tofHit->Print();
279 m_TMcHitEvent->addMcHitTof(tTofHit);
280 }
281 }
282 }
283
284}
G4THitsCollection< BesCgemHit > BesCgemHitsCollection
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
void SaveHitRootEvent(G4int, const G4Event *)
BesRootIO(G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4String)
void addMcHitCgem(TMcHitCgem *hit)
Add a McHitCgem into the Cgem Data collection.
void addMcHitTof(TMcHitTof *hit)
Add a McHitTof into the TOF Data collection.
void addMcDigiEmc(TMcDigiEmc *digi)
Add a McHitMdc into the Mdc Data collection.
void addMcHitMdc(TMcHitMdc *hit)
Add a McHitMdc into the Mdc Data collection.
#define ns(x)
Definition: xmltok.c:1504