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

#include <BesTuningIO.hh>

Public Member Functions

 BesTuningIO (std::vector< std::string >)
 ~BesTuningIO ()
void GetNextEvents (void)
void GetMdcHits (void)
void GetTofHits (void)
void GetEmcDigi (void)
void GetMucHits (void)
void GetRootEvent (int evtID)
void GetMdcRootHits ()
void GetTofRootHits ()
void GetEmcRootDigi ()

Public Attributes

TFile * f
TTree * HitTree
TChain * HitChain

Detailed Description

Definition at line 32 of file BesTuningIO.hh.

Constructor & Destructor Documentation

◆ BesTuningIO()

BesTuningIO::BesTuningIO ( std::vector< std::string > name)

Definition at line 38 of file BesTuningIO.cc.

38 : m_tuningFile( name ), m_evt( 0 ) {
39 m_DigiMan = G4DigiManager::GetDMpointer();
40 m_inputFileStream = new std::ifstream();
41
43 {
44 // tuning input root file
45 // TFile *f = new TFile(m_tuningFile);
46 // HitTree = (TTree*)f->Get("HitTree");
47 // m_TMcHitEvent = new TMcHitEvent();
48 // TBranch *branch = HitTree->GetBranch("TMcHitEvent");
49 // begin change from TTree to TChain
50 HitChain = new TChain( "HitTree" );
51 if ( m_tuningFile.size() == 0 ) { std::cout << "there is no tuning file" << std::endl; }
52 std::cout << "file number: " << m_tuningFile.size() << std::endl;
53 for ( int i = 0; i < m_tuningFile.size(); i++ )
54 {
55
56 // std::cout <<
57 // "________________________________________________________________________________fileName
58 // : " << m_tuningFile[i] << std::endl; HitChain->Add(&m_tuningFile[i]);
59 HitChain->Add( m_tuningFile[i].c_str() );
60 }
61 m_TMcHitEvent = new TMcHitEvent();
62 TBranch* branch = HitChain->GetBranch( "TMcHitEvent" );
63
64 // end change from TTree to TChain
65 branch->SetAddress( &m_TMcHitEvent );
66 std::cout << "HitChain entries: " << HitChain->GetEntries() << std::endl;
67 }
68 else
69 { // tuning input ascii file
70 // m_inputFileStream->open(m_tuningFile.c_str());
71 // if ((*m_inputFileStream).good()) {
72 // try {
73 // (*m_inputFileStream) >> m_version;
74 // } catch (AsciiDumpException& ) {
75 // std::cerr << "BesTuningIO::Got AsciiDumpException eror while reading VERSION
76 // block !!!" << std::endl;
77 // }
78 // }else{
79 // std::cerr << "BesTuningIO::Open tuning input file error!!!" << std::endl;
80 // }
81 }
82}
TChain * HitChain
char * c_str(Index i)

◆ ~BesTuningIO()

BesTuningIO::~BesTuningIO ( )

Definition at line 84 of file BesTuningIO.cc.

84 {
85 if ( m_inputFileStream ) delete m_inputFileStream;
86 if ( m_evt ) delete m_evt;
87}

Member Function Documentation

◆ GetEmcDigi()

void BesTuningIO::GetEmcDigi ( void )

Definition at line 159 of file BesTuningIO.cc.

159 {
160 G4int THCID = -1;
161 THCID = m_DigiMan->GetDigiCollectionID( "BesEmcDigitsCollection" );
162 if ( THCID >= 0 )
163 {
165 new BesEmcDigitsCollection( "BesEmcDigitizer", "BesEmcDigitsCollection" );
166 m_DigiMan->SetDigiCollection( THCID, emcDC );
167 }
168}
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection

Referenced by GetNextEvents().

◆ GetEmcRootDigi()

void BesTuningIO::GetEmcRootDigi ( )

Definition at line 184 of file BesTuningIO.cc.

184 {
185 G4int THCID = -1;
186 THCID = m_DigiMan->GetDigiCollectionID( "BesEmcDigitsCollection" );
187 // cout << "THCID " << THCID << endl;
188 if ( THCID >= 0 )
189 {
191 new BesEmcDigitsCollection( "BesEmcDigitizer", "BesEmcDigitsCollection" );
192
193 // std::cout << "GetEmcRootDigi " << emcDC << std::endl;
194 if ( emcDC )
195 {
196 int nHit = emcDC->entries();
197 // std::cout << "nHit: " << nHit << std::endl;
198 if ( nHit > 0 )
199 {
200 for ( int i = 0; i < nHit; i++ ) { delete ( *emcDC )[i]; }
201 emcDC->GetVector()->clear();
202 }
203 }
204
205 int nHits = m_TMcHitEvent->getMcDigiEmcCol()->GetEntries();
206 // std::cout << "nHits: " << nHits << std::endl;
207 for ( int i = 0; i < nHits; i++ )
208 {
209 m_TMcDigiEmc = m_TMcHitEvent->getMcDigiEmc( i );
210
211 BesEmcDigi* emcDigi = new BesEmcDigi();
212
213 emcDigi->SetPartId( m_TMcDigiEmc->GetPartId() );
214 emcDigi->SetThetaNb( m_TMcDigiEmc->GetThetaNb() );
215 emcDigi->SetPhiNb( m_TMcDigiEmc->GetPhiNb() );
216 emcDigi->SetEnergy( m_TMcDigiEmc->GetEnergy() );
217 emcDigi->SetTime( m_TMcDigiEmc->GetTime() );
218 emcDigi->SetTrackIndex( m_TMcDigiEmc->GetTrackIndex() );
219 // emcDigi->Print();
220 // std::cout << "SetEnergy" << emcDigi->GetEnergy() << std::endl;
221
222 emcDC->insert( emcDigi );
223 delete m_TMcDigiEmc;
224 }
225
226 // std::cout << "insert" << std::endl;
227 m_DigiMan->SetDigiCollection( THCID, emcDC );
228 }
229}

Referenced by GetRootEvent().

◆ GetMdcHits()

void BesTuningIO::GetMdcHits ( void )

Definition at line 117 of file BesTuningIO.cc.

117 {
118 G4int mdcHitCollID = -1;
119 mdcHitCollID = m_DigiMan->GetHitsCollectionID( "BesMdcHitsCollection" );
120 if ( mdcHitCollID >= 0 )
121 {
122 BesMdcHitsCollection* mdcDC =
123 (BesMdcHitsCollection*)m_DigiMan->GetHitsCollection( mdcHitCollID );
124 if ( mdcDC )
125 {
126 G4int nHit = mdcDC->entries();
127 if ( nHit > 0 )
128 {
129 for ( G4int i = 0; i < nHit; i++ ) { delete ( *mdcDC )[i]; }
130 mdcDC->GetVector()->clear();
131 }
132
133 std::vector<MdcHitType>::iterator iter;
134 iter = ( m_evt->mdcHit ).hitCol.begin();
135 // Loop over mdc hits
136 for ( ; iter != ( m_evt->mdcHit ).hitCol.end(); iter++ )
137 {
138 BesMdcHit* newHit = new BesMdcHit();
139 newHit->SetTrackID( ( *iter ).trackIndex );
140 newHit->SetLayerNo( ( *iter ).layerNo );
141 newHit->SetCellNo( ( *iter ).cellNo );
142 newHit->SetEdep( ( *iter ).energyDeposit );
143 newHit->SetPos( G4ThreeVector( ( *iter ).posX, ( *iter ).posY, ( *iter ).posZ ) );
144 newHit->SetDriftD( ( *iter ).driftDistance );
145 newHit->SetTheta( ( *iter ).theta );
146 newHit->SetPosFlag( ( *iter ).posFlag );
147 newHit->SetEnterAngle( ( *iter ).enterAngle );
148 newHit->SetDriftT( 0. );
149 newHit->SetGlobalT( ( *iter ).globalT );
150 mdcDC->insert( newHit );
151 }
152 // mdcDC->PrintAllHits();
153 }
154 else { std::cerr << "BesTuningIO::can't get mdcHitsCollection" << std::endl; }
155 }
156 else { std::cerr << "BesTuningIO::can't get mdcHitCollID" << std::endl; }
157}
EvtStreamInputIterator< typename Generator::result_type > iter(Generator gen, int N=0)
G4THitsCollection< BesMdcHit > BesMdcHitsCollection

Referenced by GetNextEvents().

◆ GetMdcRootHits()

void BesTuningIO::GetMdcRootHits ( )

Definition at line 231 of file BesTuningIO.cc.

231 {
232
233 G4int THCID = -1;
234 THCID = m_DigiMan->GetHitsCollectionID( "BesMdcHitsCollection" );
235 if ( THCID >= 0 )
236 {
237 BesMdcHitsCollection* mdcDC =
238 (BesMdcHitsCollection*)( m_DigiMan->GetHitsCollection( THCID ) );
239 if ( mdcDC )
240 {
241 int nHit = mdcDC->entries();
242 if ( nHit > 0 )
243 {
244 for ( int i = 0; i < nHit; i++ ) { delete ( *mdcDC )[i]; }
245 mdcDC->GetVector()->clear();
246 }
247 }
248
249 int nHits = m_TMcHitEvent->getMcHitMdcCol()->GetEntries();
250 // std::cout << "nHits: " << nHits << std::endl;
251 for ( int i = 0; i < nHits; i++ )
252 {
253 m_TMcHitMdc = m_TMcHitEvent->getMcHitMdc( i );
254
255 BesMdcHit* mdcHit = new BesMdcHit();
256
257 mdcHit->SetTrackID( m_TMcHitMdc->GetTrackID() );
258 mdcHit->SetLayerNo( m_TMcHitMdc->GetLayerNo() );
259 mdcHit->SetCellNo( m_TMcHitMdc->GetCellNo() );
260 mdcHit->SetEdep( m_TMcHitMdc->GetEdep() );
261 mdcHit->SetDriftD( m_TMcHitMdc->GetDriftD() );
262 mdcHit->SetDriftT( m_TMcHitMdc->GetDriftT() );
263 mdcHit->SetGlobalT( m_TMcHitMdc->GetGlobalT() );
264 mdcHit->SetTheta( m_TMcHitMdc->GetTheta() );
265 mdcHit->SetEnterAngle( m_TMcHitMdc->GetEnterAngle() );
266 mdcHit->SetPosFlag( m_TMcHitMdc->GetPosFlag() );
267
268 TVector3 tTemp = m_TMcHitMdc->GetPos();
269 G4ThreeVector gTemp = G4ThreeVector( tTemp.X(), tTemp.Y(), tTemp.Z() );
270 mdcHit->SetPos( gTemp );
271 // mdcHit->Print();
272
273 mdcDC->insert( mdcHit );
274 delete m_TMcHitMdc;
275 }
276 }
277}

Referenced by GetRootEvent().

◆ GetMucHits()

void BesTuningIO::GetMucHits ( void )
inline

Definition at line 43 of file BesTuningIO.hh.

43{};

Referenced by GetNextEvents(), and GetRootEvent().

◆ GetNextEvents()

void BesTuningIO::GetNextEvents ( void )

Definition at line 89 of file BesTuningIO.cc.

89 {
90 if ( m_evt ) delete m_evt;
91
92 m_evt = new HitEVENT;
93 try
94 { ( *m_inputFileStream ) >> *m_evt; } catch ( AsciiWrongTag& ex )
95 {
96 std::cerr << "wrong tag, got " << ex.got() << " expected: " << ex.expected() << std::endl;
97 delete m_evt;
98 m_evt = 0;
99 return;
100 } catch ( AsciiDumpException& )
101 {
102 std::cerr << "BesTuningIO: Reach file end!" << std::endl;
103 delete m_evt;
104 m_evt = 0;
105 return;
106 }
107
109
111
113
115}
void GetMdcHits(void)
void GetEmcDigi(void)
void GetMucHits(void)
void GetTofHits(void)

Referenced by BesEventAction::EndOfEventAction().

◆ GetRootEvent()

void BesTuningIO::GetRootEvent ( int evtID)

Definition at line 173 of file BesTuningIO.cc.

173 {
174 // std::cout << "evtID: " << evtID << std::endl;
175 // HitTree->GetEntry(evtID);
176 HitChain->GetEntry( evtID );
177 // std::cout << "HitChain" << std::endl;
182}
void GetEmcRootDigi()
void GetTofRootHits()
void GetMdcRootHits()

Referenced by BesEventAction::EndOfEventAction().

◆ GetTofHits()

void BesTuningIO::GetTofHits ( void )
inline

Definition at line 41 of file BesTuningIO.hh.

41{};

Referenced by GetNextEvents().

◆ GetTofRootHits()

void BesTuningIO::GetTofRootHits ( )

Definition at line 279 of file BesTuningIO.cc.

279 {
280
281 // retrieve G4Svc
282 ISvcLocator* svcLocator = Gaudi::svcLocator();
283 IG4Svc* tmpSvc;
284 StatusCode sc = svcLocator->service( "G4Svc", tmpSvc );
285 // G4Svc* m_G4Svc = dynamic_cast<G4Svc *>(tmpSvc);
286 IG4Svc* m_G4Svc = tmpSvc;
287
288 const double m_beamTime = m_TMcHitEvent->getBeamTime();
289 m_G4Svc->SetBeamTime( m_beamTime );
290 // std::cout << "beamtime: " << m_beamTime << std::endl;
291
292 G4int THCID = -1;
293 THCID = m_DigiMan->GetHitsCollectionID( "BesTofHitsCollection" );
294 if ( THCID >= 0 )
295 {
296 BesTofHitsCollection* tofDC =
297 (BesTofHitsCollection*)( m_DigiMan->GetHitsCollection( THCID ) );
298 if ( tofDC )
299 {
300 int nHit = tofDC->entries();
301 if ( nHit > 0 )
302 {
303 for ( int i = 0; i < nHit; i++ ) { delete ( *tofDC )[i]; }
304 tofDC->GetVector()->clear();
305 }
306 }
307
308 int nHits = m_TMcHitEvent->getMcHitTofCol()->GetEntries();
309 // std::cout << "nHits: " << nHits << std::endl;
310 for ( int i = 0; i < nHits; i++ )
311 {
312 m_TMcHitTof = m_TMcHitEvent->getMcHitTof( i );
313
314 BesTofHit* tofHit = new BesTofHit();
315
316 tofHit->SetTrackIndex( m_TMcHitTof->GetTrackIndex() );
317 tofHit->SetG4Index( m_TMcHitTof->GetG4Index() );
318 tofHit->SetPartId( m_TMcHitTof->GetPartId() );
319 tofHit->SetScinNb( m_TMcHitTof->GetScinNb() );
320 tofHit->SetEdep( m_TMcHitTof->GetEdep() );
321 tofHit->SetStepL( m_TMcHitTof->GetStepL() );
322 tofHit->SetTrackL( m_TMcHitTof->GetTrackL() );
323 tofHit->SetTime( m_TMcHitTof->GetTime() );
324 tofHit->SetDeltaT( m_TMcHitTof->GetDeltaT() );
325 tofHit->SetCharge( m_TMcHitTof->GetCharge() );
326
327 TVector3 tTemp = m_TMcHitTof->GetPos();
328 G4ThreeVector gTemp( tTemp.X(), tTemp.Y(), tTemp.Z() );
329 tofHit->SetPos( gTemp );
330
331 tTemp = m_TMcHitTof->GetPDirection();
332 gTemp = G4ThreeVector( tTemp.X(), tTemp.Y(), tTemp.Z() );
333 tofHit->SetPDirection( gTemp );
334
335 tTemp = m_TMcHitTof->GetMomentum();
336 gTemp = G4ThreeVector( tTemp.X(), tTemp.Y(), tTemp.Z() );
337 tofHit->SetMomentum( gTemp );
338
339 // tofHit->Print();
340
341 tofDC->insert( tofHit );
342 delete m_TMcHitTof;
343 }
344
345 // std::cout << "tofDC: " << tofDC->entries() << std::endl;
346 }
347}
G4THitsCollection< BesTofHit > BesTofHitsCollection
virtual void SetBeamTime(double value)=0

Referenced by GetRootEvent().

Member Data Documentation

◆ f

TFile* BesTuningIO::f

Definition at line 45 of file BesTuningIO.hh.

◆ HitChain

TChain* BesTuningIO::HitChain

Definition at line 47 of file BesTuningIO.hh.

Referenced by BesTuningIO(), and GetRootEvent().

◆ HitTree

TTree* BesTuningIO::HitTree

Definition at line 46 of file BesTuningIO.hh.


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