BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesRootIO Class Reference

#include <BesRootIO.hh>

Public Member Functions

 BesRootIO (G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4String)
 ~BesRootIO ()
void SetMdcDigiFlag (G4int flag)
void SaveEmcDigiRootEvent ()
void SaveHitRootEvent (G4int, const G4Event *)
void SaveMdcHitRoot ()
void SaveTofHitRoot ()

Public Attributes

TFile * f
TTree * HitTree

Detailed Description

Definition at line 16 of file BesRootIO.hh.

Constructor & Destructor Documentation

◆ BesRootIO()

BesRootIO::BesRootIO ( G4int mdcTruFlag,
G4int mdcDigiFlag,
G4int tofTruFlag,
G4int tofDigiFlag,
G4int emcTruFlag,
G4int emcDigiFlag,
G4int mucTruFlag,
G4int mucDigiFlag,
G4String name )

Definition at line 40 of file BesRootIO.cc.

43 : m_mdcTruFlag( mdcTruFlag )
44 , m_mdcDigiFlag( mdcDigiFlag )
45 , m_tofTruFlag( tofTruFlag )
46 , m_tofDigiFlag( tofDigiFlag )
47 , m_emcTruFlag( emcTruFlag )
48 , m_emcDigiFlag( emcDigiFlag )
49 , m_mucTruFlag( mucTruFlag )
50 , m_mucDigiFlag( mucDigiFlag )
51 , m_rootFile( name ) {
52 m_DigiMan = G4DigiManager::GetDMpointer();
53
54 f = new TFile( m_rootFile, "RECREATE" );
55 // create a MdcHit TTree
56 m_TMcHitEvent = new TMcHitEvent();
57 HitTree = new TTree( "HitTree", "staff data from HitCollection" );
58
59 HitTree->Branch( "TMcHitEvent", "TMcHitEvent", &m_TMcHitEvent, 32000, 99 );
60}
TFile * f
Definition BesRootIO.hh:20
TTree * HitTree
Definition BesRootIO.hh:21

◆ ~BesRootIO()

BesRootIO::~BesRootIO ( )

Definition at line 62 of file BesRootIO.cc.

62{ f->Write(); }

Member Function Documentation

◆ SaveEmcDigiRootEvent()

void BesRootIO::SaveEmcDigiRootEvent ( )

Definition at line 75 of file BesRootIO.cc.

75 {
76 // std::cout << "SaveEmcDigiRootEvent" << std::endl;
77 G4int emcDigiCollID = -1;
78 emcDigiCollID = m_DigiMan->GetDigiCollectionID( "BesEmcDigitsCollection" );
79 if ( emcDigiCollID >= 0 )
80 {
82 (BesEmcDigitsCollection*)m_DigiMan->GetDigiCollection( emcDigiCollID );
83 G4int nHits = emcDC->entries();
84 // std::cout << "nHits: " << nHits << std::endl;
85
86 if ( nHits > 0 )
87 {
88 BesEmcDigi* emcDigi;
89 for ( int i = 0; i < nHits; i++ )
90 {
91 emcDigi = ( *emcDC )[i];
92 TMcDigiEmc* tEmcDigi = new TMcDigiEmc();
93
94 tEmcDigi->SetPartId( emcDigi->GetPartId() );
95 tEmcDigi->SetThetaNb( emcDigi->GetThetaNb() );
96 tEmcDigi->SetPhiNb( emcDigi->GetPhiNb() );
97 tEmcDigi->SetEnergy( emcDigi->GetEnergy() );
98 tEmcDigi->SetTime( emcDigi->GetTime() );
99 tEmcDigi->SetTrackIndex( emcDigi->GetTrackIndex() );
100 // emcDigi->Print();
101 // std::cout << "SetEnergy" << emcDigi->GetEnergy() << std::endl;
102
103 m_TMcHitEvent->addMcDigiEmc( tEmcDigi );
104 // std::cout << "addMcDigiEmc" << std::endl;
105 }
106 }
107 }
108}
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection

Referenced by SaveHitRootEvent().

◆ SaveHitRootEvent()

void BesRootIO::SaveHitRootEvent ( G4int runId,
const G4Event * evt )

Definition at line 64 of file BesRootIO.cc.

64 {
65 // std::cout << "Save Hit Root Event" << std::endl;
66 if ( m_mdcDigiFlag ) { SaveMdcHitRoot(); }
67 if ( m_tofDigiFlag ) { SaveTofHitRoot(); }
68 if ( m_emcDigiFlag ) { SaveEmcDigiRootEvent(); }
69
70 HitTree->Fill();
71
72 m_TMcHitEvent->Clear();
73}
void SaveMdcHitRoot()
Definition BesRootIO.cc:110
void SaveEmcDigiRootEvent()
Definition BesRootIO.cc:75
void SaveTofHitRoot()
Definition BesRootIO.cc:149

Referenced by BesEventAction::EndOfEventAction().

◆ SaveMdcHitRoot()

void BesRootIO::SaveMdcHitRoot ( )

Definition at line 110 of file BesRootIO.cc.

110 {
111 // std::cout << "SaveMdcHitRoot" << std::endl;
112 G4int THCID = -1;
113 THCID = m_DigiMan->GetHitsCollectionID( "BesMdcHitsCollection" );
114 if ( THCID >= 0 )
115 {
116 BesMdcHitsCollection* mdcDC =
117 (BesMdcHitsCollection*)( m_DigiMan->GetHitsCollection( THCID ) );
118 G4int nHits = mdcDC->entries();
119 // std::cout << "nHits: " << nHits << std::endl;
120 if ( nHits > 0 )
121 {
122 BesMdcHit* mdcHit;
123 for ( int i = 0; i < nHits; i++ )
124 {
125 mdcHit = ( *mdcDC )[i];
126 TMcHitMdc* tMdcHit = new TMcHitMdc();
127 tMdcHit->SetTrackID( mdcHit->GetTrackID() );
128 tMdcHit->SetLayerNo( mdcHit->GetLayerNo() );
129 tMdcHit->SetCellNo( mdcHit->GetCellNo() );
130 tMdcHit->SetEdep( mdcHit->GetEdep() );
131 tMdcHit->SetDriftD( mdcHit->GetDriftD() );
132 tMdcHit->SetDriftT( mdcHit->GetDriftT() );
133 tMdcHit->SetGlobalT( mdcHit->GetGlobalT() );
134 tMdcHit->SetTheta( mdcHit->GetTheta() );
135 tMdcHit->SetEnterAngle( mdcHit->GetEnterAngle() );
136 tMdcHit->SetPosFlag( mdcHit->GetPosFlag() );
137
138 G4ThreeVector gTemp = mdcHit->GetPos();
139 TVector3 tTemp = TVector3( gTemp.x(), gTemp.y(), gTemp.z() );
140 tMdcHit->SetPos( tTemp );
141
142 // mdcHit->Print();
143 m_TMcHitEvent->addMcHitMdc( tMdcHit );
144 }
145 }
146 }
147}
G4THitsCollection< BesMdcHit > BesMdcHitsCollection

Referenced by SaveHitRootEvent().

◆ SaveTofHitRoot()

void BesRootIO::SaveTofHitRoot ( )

Definition at line 149 of file BesRootIO.cc.

149 {
150 // retrieve G4Svc
151 ISvcLocator* svcLocator = Gaudi::svcLocator();
152 IG4Svc* tmpSvc;
153 StatusCode sc = svcLocator->service( "G4Svc", tmpSvc );
154 // G4Svc *m_G4Svc = dynamic_cast<G4Svc *>(tmpSvc);
155 IG4Svc* m_G4Svc = tmpSvc;
156 double m_beamTime = m_G4Svc->GetBeamTime() * ns;
157 m_TMcHitEvent->setBeamTime( m_beamTime );
158 // std::cout << "beamtime: " << m_beamTime << std::endl;
159
160 G4int THCID = -1;
161 THCID = m_DigiMan->GetHitsCollectionID( "BesTofHitsCollection" );
162 if ( THCID >= 0 )
163 {
164 BesTofHitsCollection* tofDC =
165 (BesTofHitsCollection*)( m_DigiMan->GetHitsCollection( THCID ) );
166 G4int nHits = tofDC->entries();
167 // std::cout << "nHits: " << nHits << std::endl;
168 if ( nHits > 0 )
169 {
170 BesTofHit* tofHit;
171 for ( int i = 0; i < nHits; i++ )
172 {
173 tofHit = ( *tofDC )[i];
174 TMcHitTof* tTofHit = new TMcHitTof();
175 tTofHit->SetTrackIndex( tofHit->GetTrackIndex() );
176 tTofHit->SetG4Index( tofHit->GetG4Index() );
177 tTofHit->SetPartId( tofHit->GetPartId() );
178 tTofHit->SetScinNb( tofHit->GetScinNb() );
179 tTofHit->SetEdep( tofHit->GetEdep() );
180 tTofHit->SetStepL( tofHit->GetStepL() );
181 tTofHit->SetTrackL( tofHit->GetTrackL() );
182 tTofHit->SetTime( tofHit->GetTime() );
183 tTofHit->SetDeltaT( tofHit->GetDeltaT() );
184 tTofHit->SetCharge( tofHit->GetCharge() );
185
186 G4ThreeVector gTemp = tofHit->GetPos();
187 TVector3 tTemp( gTemp.x(), gTemp.y(), gTemp.z() );
188 tTofHit->SetPos( tTemp );
189
190 gTemp = tofHit->GetPDirection();
191 tTemp = TVector3( gTemp.x(), gTemp.y(), gTemp.z() );
192 tTofHit->SetPDirection( tTemp );
193
194 gTemp = tofHit->GetMomentum();
195 tTemp = TVector3( gTemp.x(), gTemp.y(), gTemp.z() );
196 tTofHit->SetMomentum( tTemp );
197
198 // tofHit->Print();
199 m_TMcHitEvent->addMcHitTof( tTofHit );
200 }
201 }
202 }
203}
G4THitsCollection< BesTofHit > BesTofHitsCollection
virtual double GetBeamTime()=0
#define ns(x)
Definition xmltok.c:1355

Referenced by SaveHitRootEvent().

◆ SetMdcDigiFlag()

void BesRootIO::SetMdcDigiFlag ( G4int flag)
inline

Definition at line 26 of file BesRootIO.hh.

26{ m_mdcDigiFlag = flag; }

Member Data Documentation

◆ f

TFile* BesRootIO::f

Definition at line 20 of file BesRootIO.hh.

Referenced by BesRootIO(), and ~BesRootIO().

◆ HitTree

TTree* BesRootIO::HitTree

Definition at line 21 of file BesRootIO.hh.

Referenced by BesRootIO(), and SaveHitRootEvent().


The documentation for this class was generated from the following files: