BOSS 7.0.2
BESIII Offline Software System
Loading...
Searching...
No Matches
BesAsciiIO.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2//// BOOST --- BESIII Object_Oriented Simulation Tool //
3////---------------------------------------------------------------------------//
4////Description:
5////Author: Dengzy
6////Created: Mar, 2004
7////Modified:
8////Comment:
9//
10#include "BesMdcHit.hh"
11#include "BesMdcDigi.hh"
12#include "BesTofHit.hh"
13#include "BesTofDigi.hh"
14#include "BesEmcHit.hh"
15#include "BesEmcDigi.hh"
16#include "BesMucHit.hh"
17#include "BesMucDigi.hh"
18#include "BesEventAction.hh"
19#include "G4RunManager.hh"
20#include "BesTruthTrack.hh"
21#include "BesTruthVertex.hh"
22#include "BesSensitiveManager.hh"
23#include "G4HCofThisEvent.hh"
24#include "G4SDManager.hh"
25#include "G4PrimaryVertex.hh"
26#include "G4PrimaryParticle.hh"
27
28#include "BesAsciiIO.hh"
29#include "AsciiDmp/dmplib.hh"
30#include "G4DigiManager.hh"
31#include <iostream>
32using namespace std;
33
34#include "GaudiKernel/IDataProviderSvc.h"
35#include "GaudiKernel/ISvcLocator.h"
36#include "GaudiKernel/Bootstrap.h"
37#include "GaudiKernel/RegistryEntry.h"
38#include "GaudiKernel/MsgStream.h"
39#include "GaudiKernel/SmartDataPtr.h"
40#include "McTruth/DecayMode.h"
41
43 G4int mdcTruFlag,G4int mdcDigiFlag,
44 G4int tofTruFlag, G4int tofDigiFlag,
45 G4int emcTruFlag, G4int emcDigiFlag,
46 G4int mucTruFlag, G4int mucDigiFlag,
47 G4String name)
48:m_mdcTruFlag(mdcTruFlag),m_mdcDigiFlag(mdcDigiFlag),
49 m_tofTruFlag(tofTruFlag),m_tofDigiFlag(tofDigiFlag),
50 m_emcTruFlag(emcTruFlag),m_emcDigiFlag(emcDigiFlag),
51 m_mucTruFlag(mucTruFlag),m_mucDigiFlag(mucDigiFlag),
52 m_asciiFile(name)
53{
54 m_DigiMan = G4DigiManager::GetDMpointer();
55}
56
58{
59}
60
61void BesAsciiIO::SaveAsciiEvents(G4int runId, const G4Event* evt)
62{
63 EVENT asciiEvt;
64
65 asciiEvt.set_initialized();
66 asciiEvt.header.set_initialized();
67 asciiEvt.header.eventNo=evt->GetEventID();
68 asciiEvt.header.runNo= runId;
69 asciiEvt.decayMode.set_initialized();
70 SaveDecayMode(asciiEvt);
71
72 asciiEvt.trackTruth.set_initialized();
74 SaveTrackTruth(asciiEvt);
75 SaveVertexTruth(asciiEvt);
76
77 if(m_mdcTruFlag)
78 {
79 asciiEvt.mdcTruth.set_initialized();
80 SaveMdcTruth(asciiEvt);
81 }
82
83 if(m_mdcDigiFlag)
84 {
85 asciiEvt.mdcDigi.set_initialized();
86 SaveMdcDigits(asciiEvt);
87 }
88
89 if(m_tofTruFlag)
90 {
91 asciiEvt.tofTruth.set_initialized();
92 SaveTofTruth(asciiEvt);
93 }
94
95 if(m_tofDigiFlag)
96 {
97 asciiEvt.tofDigi.set_initialized();
98 SaveTofDigits(asciiEvt);
99 }
100
101 if(m_emcTruFlag)
102 {
103 asciiEvt.emcTruth.set_initialized();
104 SaveEmcTruth(asciiEvt);
105 }
106
107 if(m_emcDigiFlag)
108 {
109 asciiEvt.emcDigi.set_initialized();
110 SaveEmcDigits(asciiEvt);
111 }
112
113 if(m_mucTruFlag)
114 {
115 asciiEvt.mucTruth.set_initialized();
116 SaveMucTruth(asciiEvt);
117 }
118
119 if(m_mucDigiFlag)
120 {
121 asciiEvt.mucDigi.set_initialized();
122 SaveMucDigits(asciiEvt);
123 }
124
125 ofstream os;
126 if(evt->GetEventID()==0)
127 {
128 os.open(m_asciiFile);
129 FRMTVERSION version;
130 version.set_initialized();
131 version.major = 1;
132 version.minor = 0;
133 os << version;
134 }
135 else
136 os.open(m_asciiFile,ios::out|ios::app);
137
138 try {
139 os << asciiEvt;
140 }
141 catch (AsciiWrongTag& ex) {
142 std::cerr << "wrong tag, got " << ex.got()
143 << " expected: " << ex.expected()
144 << std::endl;
145 } catch (AsciiDumpException& ) {
146 std::cerr << "AsciiDumpException was caught!" << std::endl;
147 }
148 os.close();
149}
150
152{
153 asciiEvt.decayMode.size=10;
154 //interface to event data service
155 ISvcLocator* svcLocator = Gaudi::svcLocator();
156 IDataProviderSvc* evtSvc;
157 StatusCode sc=svcLocator->service("EventDataSvc", evtSvc);
158 if (sc.isFailure())
159 G4cout<<"Could not accesss EventDataSvc!"<<G4endl;
160
161 SmartDataPtr<DecayMode> decayMode(evtSvc,"/Event/MC/DecayMode");
162 if(!decayMode)
163 {
164 for(int i=0;i<10;i++)
165 asciiEvt.decayMode.data[i]=0;
166 }
167 else
168 {
169 int dm[10]={0,0,0,0,0,0,0,0,0,0};
170 decayMode->getData(dm,10);
171 for(int i=0;i<10;i++)
172 asciiEvt.decayMode.data[i]=dm[i];
173 }
174}
175
177{
178
180
181 vector<BesTruthTrack*>* trackList = sensitiveManager->GetTrackList();
182
183 //arrange TruthTrack in trackList in order of trackIndex
184 G4int nTrack = trackList->size();
185 BesTruthTrack* track;
186 for(int i=0;i<nTrack-1;i++)
187 for(int j=i+1;j<nTrack;j++)
188 if((*trackList)[i]->GetIndex()>(*trackList)[j]->GetIndex())
189 {
190 track=(*trackList)[i];
191 (*trackList)[i]=(*trackList)[j];
192 (*trackList)[j]=track;
193 }
194
195 for(int i=0;i<nTrack;i++)
196 {
197 TrackTruthType trackTruth;
198 track = (*(sensitiveManager->GetTrackList())) [i];
199 trackTruth.trackIndex = track->GetIndex();
200 if(track->GetIndex()<0)
201 G4cout<<"trackIndex<0!"<<G4endl;
202 trackTruth.PDGCode = track->GetPDGCode();
203 trackTruth.PDGCharge = track->GetPDGCharge();
204 trackTruth.v0Index = track->GetVertex()->GetIndex();
205 if( track->GetTerminalVertex() )
206 trackTruth.v1Index = track->GetTerminalVertex()->GetIndex();
207 else
208 trackTruth.v1Index = -99;
209 trackTruth.px = track->GetP4().x()/1000.;
210 trackTruth.py = track->GetP4().y()/1000.;
211 trackTruth.pz = track->GetP4().z()/1000.;
212 trackTruth.E = track->GetP4().t()/1000.;
213
214 G4int size = track->GetDaughterIndexes().size();
215 if(size>0)
216 {
217 trackTruth.minDaughterIndex = (track->GetDaughterIndexes())[0];
218 trackTruth.maxDaughterIndex = (track->GetDaughterIndexes())[size-1];
219 }
220 else
221 {
222 trackTruth.minDaughterIndex = -99;
223 trackTruth.maxDaughterIndex = -99;
224 }
225
226
227 asciiEvt.trackTruth.truthCol.push_back(trackTruth);
228 }
229
230 asciiEvt.trackTruth.nTruth=asciiEvt.trackTruth.truthCol.size();
231}
232
234{
236
237 vector<BesTruthVertex*>* vertexList = sensitiveManager->GetVertexList();
238
239 G4int nVertex = vertexList->size();
240 BesTruthVertex* vertex;
241 for(int i=0;i<nVertex;i++)
242 {
243 VertexTruthType vertexTruth;
244 vertex = (*vertexList) [i];
245 vertexTruth.vertexIndex = vertex->GetIndex();
246 if(vertex->GetParentTrack())
247 vertexTruth.parentTrackIndex = vertex->GetParentTrack()->GetIndex();
248 else
249 vertexTruth.parentTrackIndex = -99;
250
251 vertexTruth.posX = vertex->GetPosition().x()/10.;
252 vertexTruth.posY = vertex->GetPosition().y()/10.;
253 vertexTruth.posZ = vertex->GetPosition().z()/10.;
254 vertexTruth.time = vertex->GetTime();
255 asciiEvt.vertexTruth.truthCol.push_back(vertexTruth);
256 }
257 asciiEvt.vertexTruth.nTruth = asciiEvt.vertexTruth.truthCol.size();
258}
259
261{
262 G4int HCID = -1;
263 HCID = m_DigiMan->GetHitsCollectionID("BesMdcTruthCollection");
264 if(HCID>0)
265 {
266 BesMdcHitsCollection* HC = 0;
267 HC = (BesMdcHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
268 G4int n_hit = HC->entries();
269 if(n_hit>0)
270 {
271 //arrange hits in hits collection in order of trackIndex
272 BesMdcHit* hit;
273 vector<BesMdcHit*>* vecHC = HC->GetVector();
274 for(int i=0;i<n_hit-1;i++)
275 for(int j=i+1;j<n_hit;j++)
276 if((*vecHC)[i]->GetTrackID()>(*vecHC)[j]->GetTrackID())
277 {
278 hit = (*vecHC)[i];
279 (*vecHC)[i] = (*vecHC)[j];
280 (*vecHC)[j] = hit;
281 }
282
283 for(G4int i=0;i<n_hit;i++)
284 {
285 hit = (*HC)[i];
286 MdcTruthType mdcTruth;
287 mdcTruth.trackIndex = hit->GetTrackID();
288 mdcTruth.layerNo = hit->GetLayerNo();
289 mdcTruth.cellNo = hit->GetCellNo();
290 mdcTruth.edep = hit->GetEdep();
291 mdcTruth.driftD = hit->GetDriftD();
292 mdcTruth.posX = hit->GetPos().x();
293 mdcTruth.posY = hit->GetPos().y();
294 mdcTruth.posZ = hit->GetPos().z();
295 mdcTruth.posFlag = hit->GetPosFlag();
296
297 asciiEvt.mdcTruth.truthCol.push_back(mdcTruth);
298 }
299 }
300 }
301 asciiEvt.mdcTruth.nTruth = asciiEvt.mdcTruth.truthCol.size();
302}
303
305{
306 G4int HCID = -1;
307 HCID = m_DigiMan->GetHitsCollectionID("BesTofHitsList");
308 if(HCID>0)
309 {
310 BesTofHitsCollection* HC = 0;
311 HC = (BesTofHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
312 G4int n_hit = HC->entries();
313 if(n_hit>0)
314 {
315 //arrange hits in hits collection in order of trackIndex
316 BesTofHit* hit;
317 vector<BesTofHit*>* vecHC = HC->GetVector();
318 for(int i=0;i<n_hit-1;i++)
319 for(int j=i+1;j<n_hit;j++)
320 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
321 {
322 hit = (*vecHC)[i];
323 (*vecHC)[i] = (*vecHC)[j];
324 (*vecHC)[j] = hit;
325 }
326
327 for(G4int i=0;i<n_hit;i++)
328 {
329 hit = (*HC)[i];
330 TofTruthType tofTruth;
331 tofTruth.trackIndex = hit->GetTrackIndex();
332 tofTruth.partId = hit->GetPartId();
333 tofTruth.scinNb = hit->GetScinNb();
334 tofTruth.posX = hit->GetPos().x();
335 tofTruth.posY = hit->GetPos().y();
336 tofTruth.posZ = hit->GetPos().z();
337 tofTruth.px = hit->GetMomentum().x();
338 tofTruth.py = hit->GetMomentum().y();
339 tofTruth.pz = hit->GetMomentum().z();
340 tofTruth.trackL = hit->GetTrackL();
341 tofTruth.time = hit->GetTime();
342
343 asciiEvt.tofTruth.truthCol.push_back(tofTruth);
344 }
345 }
346 }
347 asciiEvt.tofTruth.nTruth=asciiEvt.tofTruth.truthCol.size();
348}
349
351{
352 G4int HCID = -1;
353 HCID = m_DigiMan->GetHitsCollectionID("BesEmcHitsList");
354 if(HCID>0)
355 {
356 BesEmcHitsCollection* HC = 0;
357 HC = (BesEmcHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
358 G4int n_hit = HC->entries();
359 if(n_hit>0)
360 {
361 //arrange hits in hits collection in order of trackIndex
362 BesEmcHit* hit;
363 vector<BesEmcHit*>* vecHC = HC->GetVector();
364 for(int i=0;i<n_hit-1;i++)
365 for(int j=i+1;j<n_hit;j++)
366 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
367 {
368 hit = (*vecHC)[i];
369 (*vecHC)[i] = (*vecHC)[j];
370 (*vecHC)[j] = hit;
371 }
372
373 for(G4int i=0;i<n_hit;i++)
374 {
375 hit = (*HC)[i];
376 EmcTruthType emcTruth;
377 emcTruth.trackIndex = hit->GetTrackIndex();
378 emcTruth.partId = hit->GetPartId();
379 emcTruth.numTheta = hit->GetNumThetaCrystal();
380 emcTruth.numPhi = hit->GetNumPhiCrystal();
381 emcTruth.posX = hit->GetPosCrystal().x();
382 emcTruth.posY = hit->GetPosCrystal().y();
383 emcTruth.posZ = hit->GetPosCrystal().z();
384 emcTruth.px = hit->GetMomentum().x();
385 emcTruth.py = hit->GetMomentum().y();
386 emcTruth.pz = hit->GetMomentum().z();
387 emcTruth.totalEdep = hit->GetEdepCrystal();
388
389 asciiEvt.emcTruth.truthCol.push_back(emcTruth);
390 }
391 }
392 }
393 asciiEvt.emcTruth.nTruth=asciiEvt.emcTruth.truthCol.size();
394}
395
397{
398 G4int HCID = -1;
399 HCID = m_DigiMan->GetHitsCollectionID("BesMucHitsList");
400 if(HCID>0)
401 {
402 BesMucHitsCollection* HC = 0;
403 HC = (BesMucHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
404 G4int n_hit = HC->entries();
405 if(n_hit>0)
406 {
407 //arrange hits in hits collection in order of trackIndex
408 BesMucHit* hit;
409 vector<BesMucHit*>* vecHC = HC->GetVector();
410 for(int i=0;i<n_hit-1;i++)
411 for(int j=i+1;j<n_hit;j++)
412 if((*vecHC)[i]->GetTrackIndex()>(*vecHC)[j]->GetTrackIndex())
413 {
414 hit = (*vecHC)[i];
415 (*vecHC)[i] = (*vecHC)[j];
416 (*vecHC)[j] = hit;
417 }
418
419 for(G4int i=0;i<n_hit;i++)
420 {
421 hit = (*HC)[i];
422 MucTruthType mucTruth;
423 mucTruth.trackIndex = hit->GetTrackIndex();
424 mucTruth.partId = hit->GetPart();
425 mucTruth.segId = hit->GetSeg();
426 mucTruth.gapId = hit->GetGap();
427 mucTruth.stripId = hit->GetStrip();
428 mucTruth.posX = hit->GetPos().x();
429 mucTruth.posY = hit->GetPos().y();
430 mucTruth.posZ = hit->GetPos().z();
431 mucTruth.px = hit->GetMomentum().x();
432 mucTruth.py = hit->GetMomentum().y();
433 mucTruth.pz = hit->GetMomentum().z();
434 asciiEvt.mucTruth.truthCol.push_back(mucTruth);
435 }
436 }
437 }
438 asciiEvt.mucTruth.nTruth=asciiEvt.mucTruth.truthCol.size();
439}
440
442{
443 G4int mdcDigiCollID = -1;
444 mdcDigiCollID = m_DigiMan->GetDigiCollectionID("BesMdcDigisCollection");
445 if(mdcDigiCollID>=0){
446 BesMdcDigisCollection* mdcDC = (BesMdcDigisCollection*)m_DigiMan->GetDigiCollection(mdcDigiCollID);
447 G4int nDigi = mdcDC->entries();
448 if(nDigi>0)
449 {
450 BesMdcDigi* mdcDigi;
451 for(int i=0;i<nDigi;i++)
452 {
453 MdcDigiType mdcData;
454 mdcDigi=(*mdcDC)[i];
455 mdcData.trackIndex = mdcDigi->GetTrackID();
456 mdcData.layerNo = mdcDigi->GetLayerNo();
457 mdcData.cellNo = mdcDigi->GetCellNo();
458 mdcData.energyDeposit = mdcDigi->GetEdep();
459 mdcData.driftTime = mdcDigi->GetDriftT();
460 asciiEvt.mdcDigi.digiCol.push_back(mdcData);
461 }
462 }
463 }
464 asciiEvt.mdcDigi.nDigi=asciiEvt.mdcDigi.digiCol.size();
465}
466
467
469{
470
471 G4int tofDigiCollID = -1;
472 tofDigiCollID = m_DigiMan->GetDigiCollectionID("BesTofDigitsCollection");
473
474 if(tofDigiCollID>=0)
475 {
476 BesTofDigitsCollection* tofDC = (BesTofDigitsCollection*)m_DigiMan->GetDigiCollection(tofDigiCollID);
477 G4int nDigi = tofDC->entries();
478 if(nDigi>0)
479 {
480 //arrange digis in digitsCollection in order of trackIndex
481 BesTofDigi* digi;
482 vector<BesTofDigi*>* vecDC = tofDC->GetVector();
483 for(int i=0;i<nDigi-1;i++)
484 for(int j=i+1;j<nDigi;j++)
485 if((*vecDC)[i]->GetTrackIndex()>(*vecDC)[j]->GetTrackIndex())
486 {
487 digi = (*vecDC)[i];
488 (*vecDC)[i] = (*vecDC)[j];
489 (*vecDC)[j] = digi;
490 }
491
492 for(int i=0;i<nDigi;i++)
493 {
494 TofDigiType tofData;
495 digi = (*tofDC)[i];
496 tofData.trackIndex = digi->GetTrackIndex();
497 tofData.partId = digi->GetPartId();
498 tofData.scinNb = digi->GetScinNb();
499 tofData.forwADC = digi->GetForwADC();
500 tofData.forwTDC = digi->GetForwTDC();
501 tofData.backADC = digi->GetBackADC();
502 tofData.backTDC = digi->GetBackTDC();
503
504 asciiEvt.tofDigi.digiCol.push_back(tofData);
505 }
506 }
507 }
508 asciiEvt.tofDigi.nDigi=asciiEvt.tofDigi.digiCol.size();
509}
510
512{
513 G4int emcDigiCollID = -1;
514 emcDigiCollID = m_DigiMan->GetDigiCollectionID("BesEmcDigitsCollection");
515 if(emcDigiCollID>=0)
516 {
517 BesEmcDigitsCollection* emcDC = (BesEmcDigitsCollection*)m_DigiMan->GetDigiCollection(emcDigiCollID);
518 G4int nDigi = emcDC->entries();
519 if(nDigi>0)
520 {
521 //arrange digis in digitsCollection in order of trackIndex
522 BesEmcDigi* digi;
523 vector<BesEmcDigi*>* vecDC = emcDC->GetVector();
524 for(int i=0;i<nDigi-1;i++)
525 for(int j=i+1;j<nDigi;j++)
526 if((*vecDC)[i]->GetTrackIndex()>(*vecDC)[j]->GetTrackIndex())
527 {
528 digi = (*vecDC)[i];
529 (*vecDC)[i] = (*vecDC)[j];
530 (*vecDC)[j] = digi;
531 }
532 for(int i=0;i<nDigi;i++)
533 {
534 EmcDigiType emcData;
535 digi = (*emcDC)[i];
536 emcData.trackIndex = digi->GetTrackIndex();
537 emcData.partId = digi->GetPartId();
538 emcData.numTheta = digi->GetThetaNb();
539 emcData.numPhi = digi->GetPhiNb();
540 emcData.energyDeposit = digi->GetEnergy();
541 emcData.hitTime = (G4double)digi->GetTime();
542 asciiEvt.emcDigi.digiCol.push_back(emcData);
543 }
544 }
545 }
546 asciiEvt.emcDigi.nDigi=asciiEvt.emcDigi.digiCol.size();
547}
548
550{
551 G4int mucDigiCollID =-1;
552 mucDigiCollID = m_DigiMan->GetDigiCollectionID("BesMucDigisCollection");
553 if(mucDigiCollID>=0)
554 {
555 BesMucDigisCollection* mucDC = (BesMucDigisCollection*)m_DigiMan->GetDigiCollection(mucDigiCollID);
556 G4int nDigi = mucDC->entries();
557 if(nDigi > 0) {
558 BesMucDigi* mucDigi;
559 for(int i = 0; i < nDigi; i++)
560 {
561 MucDigiType mucData;
562 mucDigi = (*mucDC)[i];
563 mucData.trackIndex = mucDigi->GetTrackIndex();
564 mucData.partNo = mucDigi->GetPartId();
565 mucData.segNo = mucDigi->GetSegId();
566 mucData.gapNo = mucDigi->GetGapId();
567 mucData.stripNo = mucDigi->GetStripId();
568
569 asciiEvt.mucDigi.digiCol.push_back(mucData);
570 }
571 }
572 }
573 asciiEvt.mucDigi.nDigi=asciiEvt.mucDigi.digiCol.size();
574}
575
576//Below used when output hits not digis
577void BesAsciiIO::SaveHitAsciiEvents(G4int runId, const G4Event* evt){
578 HitEVENT asciiEvt;
579
580 asciiEvt.set_initialized();
581 asciiEvt.header.set_initialized();
582 asciiEvt.header.eventNo=evt->GetEventID();
583 asciiEvt.header.runNo= runId;
584 asciiEvt.decayMode.set_initialized();
585 SaveDecayMode(asciiEvt);
586
587 asciiEvt.trackTruth.set_initialized();
588 asciiEvt.vertexTruth.set_initialized();
589 SaveTrackTruth(asciiEvt);
590 SaveVertexTruth(asciiEvt);
591
592 if(m_mdcTruFlag)
593 {
594 asciiEvt.mdcTruth.set_initialized();
595 SaveMdcTruth(asciiEvt);
596 }
597
598 if(m_mdcDigiFlag)
599 {
600 asciiEvt.mdcHit.set_initialized();
601 SaveMdcHits(asciiEvt);
602 }
603 /*
604 if(m_tofTruFlag)
605 {
606 asciiEvt.tofTruth.set_initialized();
607 SaveTofTruth(asciiEvt);
608 }
609
610 if(m_tofDigiFlag)
611 {
612 asciiEvt.tofHit.set_initialized();
613 SaveTofHits(asciiEvt);
614 }
615
616 if(m_emcTruFlag)
617 {
618 asciiEvt.emcTruth.set_initialized();
619 SaveEmcTruth(asciiEvt);
620 }
621
622 if(m_emcDigiFlag)
623 {
624 asciiEvt.emcHit.set_initialized();
625 SaveEmcHits(asciiEvt);
626 }
627
628 if(m_mucTruFlag)
629 {
630 asciiEvt.mucTruth.set_initialized();
631 SaveMucTruth(asciiEvt);
632 }
633
634 if(m_mucDigiFlag)
635 {
636 asciiEvt.mucHit.set_initialized();
637 SaveMucHits(asciiEvt);
638 }
639 */
640 ofstream os;
641 if(evt->GetEventID()==0){
642 os.open(m_asciiFile);
643 FRMTVERSION version;
644 version.set_initialized();
645 version.major = 1;
646 version.minor = 0;
647 os << version;
648 }
649 else
650 os.open(m_asciiFile,ios::out|ios::app);
651
652 try {
653 os << asciiEvt;
654 }catch (AsciiWrongTag& ex) {
655 std::cerr << "wrong tag, got " << ex.got()
656 << " expected: " << ex.expected()
657 << std::endl;
658 } catch (AsciiDumpException& ) {
659 std::cerr << "AsciiDumpException was caught!" << std::endl;
660 }
661
662 os.close();
663}
664
666{
667 asciiEvt.decayMode.size=10;
668 //interface to event data service
669 ISvcLocator* svcLocator = Gaudi::svcLocator();
670 IDataProviderSvc* evtSvc;
671 StatusCode sc=svcLocator->service("EventDataSvc", evtSvc);
672 if (sc.isFailure())
673 G4cout<<"Could not accesss EventDataSvc!"<<G4endl;
674
675 SmartDataPtr<DecayMode> decayMode(evtSvc,"/Event/MC/DecayMode");
676 if(!decayMode)
677 {
678 for(int i=0;i<10;i++)
679 asciiEvt.decayMode.data[i]=0;
680 }
681 else
682 {
683 int dm[10]={0,0,0,0,0,0,0,0,0,0};
684 decayMode->getData(dm,10);
685 for(int i=0;i<10;i++)
686 asciiEvt.decayMode.data[i]=dm[i];
687 }
688}
689
691{
692
694
695 vector<BesTruthTrack*>* trackList = sensitiveManager->GetTrackList();
696
697 //arrange TruthTrack in trackList in order of trackIndex
698 G4int nTrack = trackList->size();
699 BesTruthTrack* track;
700 for(int i=0;i<nTrack-1;i++)
701 for(int j=i+1;j<nTrack;j++)
702 if((*trackList)[i]->GetIndex()>(*trackList)[j]->GetIndex())
703 {
704 track=(*trackList)[i];
705 (*trackList)[i]=(*trackList)[j];
706 (*trackList)[j]=track;
707 }
708
709 for(int i=0;i<nTrack;i++)
710 {
711 TrackTruthType trackTruth;
712 track = (*(sensitiveManager->GetTrackList())) [i];
713 trackTruth.trackIndex = track->GetIndex();
714 trackTruth.PDGCode = track->GetPDGCode();
715 trackTruth.PDGCharge = track->GetPDGCharge();
716 trackTruth.v0Index = track->GetVertex()->GetIndex();
717 if( track->GetTerminalVertex() )
718 trackTruth.v1Index = track->GetTerminalVertex()->GetIndex();
719 else
720 trackTruth.v1Index = -99;
721 trackTruth.px = track->GetP4().x();
722 trackTruth.py = track->GetP4().y();
723 trackTruth.pz = track->GetP4().z();
724 trackTruth.E = track->GetP4().t();
725
726 G4int size = track->GetDaughterIndexes().size();
727 if(size>0)
728 {
729 trackTruth.minDaughterIndex = (track->GetDaughterIndexes())[0];
730 trackTruth.maxDaughterIndex = (track->GetDaughterIndexes())[size-1];
731 }
732 else
733 {
734 trackTruth.minDaughterIndex = -99;
735 trackTruth.maxDaughterIndex = -99;
736 }
737
738
739 asciiEvt.trackTruth.truthCol.push_back(trackTruth);
740 }
741
742 asciiEvt.trackTruth.nTruth=asciiEvt.trackTruth.truthCol.size();
743}
744
746{
748
749 vector<BesTruthVertex*>* vertexList = sensitiveManager->GetVertexList();
750
751 G4int nVertex = vertexList->size();
752 BesTruthVertex* vertex;
753 for(int i=0;i<nVertex;i++)
754 {
755 VertexTruthType vertexTruth;
756 vertex = (*vertexList) [i];
757 vertexTruth.vertexIndex = vertex->GetIndex();
758 if(vertex->GetParentTrack())
759 vertexTruth.parentTrackIndex = vertex->GetParentTrack()->GetIndex();
760 else
761 vertexTruth.parentTrackIndex = -99;
762
763 vertexTruth.posX = vertex->GetPosition().x();
764 vertexTruth.posY = vertex->GetPosition().y();
765 vertexTruth.posZ = vertex->GetPosition().z();
766 vertexTruth.time = vertex->GetTime();
767 asciiEvt.vertexTruth.truthCol.push_back(vertexTruth);
768 }
769 asciiEvt.vertexTruth.nTruth = asciiEvt.vertexTruth.truthCol.size();
770}
771
773{
774 G4int HCID = -1;
775 HCID = m_DigiMan->GetHitsCollectionID("BesMdcTruthCollection");
776 if(HCID>0)
777 {
778 BesMdcHitsCollection* HC = 0;
779 HC = (BesMdcHitsCollection*) (m_DigiMan->GetHitsCollection(HCID));
780 G4int n_hit = HC->entries();
781 if(n_hit>0)
782 {
783 //arrange hits in hits collection in order of trackIndex
784 BesMdcHit* hit;
785 vector<BesMdcHit*>* vecHC = HC->GetVector();
786 for(int i=0;i<n_hit-1;i++)
787 for(int j=i+1;j<n_hit;j++)
788 if((*vecHC)[i]->GetTrackID()>(*vecHC)[j]->GetTrackID())
789 {
790 hit = (*vecHC)[i];
791 (*vecHC)[i] = (*vecHC)[j];
792 (*vecHC)[j] = hit;
793 }
794
795 for(G4int i=0;i<n_hit;i++)
796 {
797 hit = (*HC)[i];
798 MdcTruthType mdcTruth;
799 mdcTruth.trackIndex = hit->GetTrackID();
800 mdcTruth.layerNo = hit->GetLayerNo();
801 mdcTruth.cellNo = hit->GetCellNo();
802 mdcTruth.edep = hit->GetEdep();
803 mdcTruth.driftD = hit->GetDriftD();
804 mdcTruth.posX = hit->GetPos().x();
805 mdcTruth.posY = hit->GetPos().y();
806 mdcTruth.posZ = hit->GetPos().z();
807 mdcTruth.posFlag = hit->GetPosFlag();
808
809 asciiEvt.mdcTruth.truthCol.push_back(mdcTruth);
810 }
811 }
812 }
813 asciiEvt.mdcTruth.nTruth = asciiEvt.mdcTruth.truthCol.size();
814}
815
817{
818 G4int mdcHitCollID = -1;
819 mdcHitCollID = m_DigiMan->GetHitsCollectionID("BesMdcHitsCollection");
820 if(mdcHitCollID>=0)
821 {
822 BesMdcHitsCollection* mdcDC = (BesMdcHitsCollection*)m_DigiMan->GetHitsCollection(mdcHitCollID);
823 G4int nHit = mdcDC->entries();
824 if(nHit>0)
825 {
826 BesMdcHit* mdcHit;
827 for(int i=0;i<nHit;i++)
828 {
829 MdcHitType mdcData;
830 mdcHit=(*mdcDC)[i];
831 mdcData.trackIndex = mdcHit->GetTrackID();
832 mdcData.layerNo = mdcHit->GetLayerNo();
833 mdcData.cellNo = mdcHit->GetCellNo();
834 mdcData.posX = mdcHit->GetPos().x();
835 mdcData.posY = mdcHit->GetPos().y();
836 mdcData.posZ = mdcHit->GetPos().z();
837 mdcData.energyDeposit = mdcHit->GetEdep();
838 mdcData.driftDistance = mdcHit->GetDriftD();
839 mdcData.globalT = mdcHit->GetGlobalT();
840 mdcData.theta = mdcHit->GetTheta();
841 mdcData.enterAngle = mdcHit->GetEnterAngle();
842 mdcData.posFlag = mdcHit->GetPosFlag();
843
844 asciiEvt.mdcHit.hitCol.push_back(mdcData);
845 }
846 }
847 }
848 asciiEvt.mdcHit.nHit=asciiEvt.mdcHit.hitCol.size();
849}
850
G4TDigiCollection< BesEmcDigi > BesEmcDigitsCollection
G4THitsCollection< BesEmcHit > BesEmcHitsCollection
G4TDigiCollection< BesMdcDigi > BesMdcDigisCollection
G4THitsCollection< BesMdcHit > BesMdcHitsCollection
G4TDigiCollection< BesMucDigi > BesMucDigisCollection
G4THitsCollection< BesMucHit > BesMucHitsCollection
G4TDigiCollection< BesTofDigi > BesTofDigitsCollection
G4THitsCollection< BesTofHit > BesTofHitsCollection
void SaveMdcHits(HitEVENT &)
Definition: BesAsciiIO.cc:816
void SaveMucDigits(EVENT &)
Definition: BesAsciiIO.cc:549
void SaveTrackTruth(EVENT &)
Definition: BesAsciiIO.cc:176
void SaveDecayMode(EVENT &)
Definition: BesAsciiIO.cc:151
BesAsciiIO(G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4int, G4String)
Definition: BesAsciiIO.cc:42
void SaveMdcDigits(EVENT &)
Definition: BesAsciiIO.cc:441
void SaveMucTruth(EVENT &)
Definition: BesAsciiIO.cc:396
void SaveEmcDigits(EVENT &)
Definition: BesAsciiIO.cc:511
void SaveEmcTruth(EVENT &)
Definition: BesAsciiIO.cc:350
void SaveTofTruth(EVENT &)
Definition: BesAsciiIO.cc:304
void SaveHitAsciiEvents(G4int, const G4Event *)
Definition: BesAsciiIO.cc:577
void SaveMdcTruth(EVENT &)
Definition: BesAsciiIO.cc:260
void SaveTofDigits(EVENT &)
Definition: BesAsciiIO.cc:468
void SaveVertexTruth(EVENT &)
Definition: BesAsciiIO.cc:233
void SaveAsciiEvents(G4int, const G4Event *)
Definition: BesAsciiIO.cc:61