CGEM BOSS 6.6.5.h
BESIII Offline Software System
Loading...
Searching...
No Matches
BesSensitiveManager Class Reference

#include <BesSensitiveManager.hh>

Public Member Functions

 BesSensitiveManager ()
 
 ~BesSensitiveManager ()
 
void AddSensitiveDetector (BesSensitiveDetector *detector)
 
G4int GetCurrentTrackIndex () const
 
std::vector< BesTruthTrack * > * GetTrackList ()
 
std::vector< BesTruthVertex * > * GetVertexList ()
 
void BeginOfTruthEvent (const G4Event *)
 
void EndOfTruthEvent (const G4Event *)
 
G4int CheckType (const HepMC::GenEvent *hepmcevt)
 
void SaveParticlesFromGenerator ()
 
void SetVertex0 (const G4Event *)
 
void UpdatePrimaryTrack (const G4Track *)
 
G4bool CheckDecayTrack (const G4Track *)
 
void UpdateVertex (BesTStats, const G4Track *)
 
G4bool MatchDaughterTrack (const G4Track *)
 
void GetDaughterVertexes (BesTruthTrack *pTrack, std::vector< int > *vDau)
 
G4bool MatchVertex (G4int vIndex, std::vector< int > *vDau)
 
void BeginOfTrack (const G4Track *track)
 
void EndOfTrack (const G4Track *track, G4TrackingManager *)
 
G4int GetNumberTracks () const
 
G4int GetNumberVertices () const
 
void ClearEvent ()
 
void SetLogLevel (G4int level)
 

Static Public Member Functions

static BesSensitiveManagerGetSensitiveManager ()
 

Protected Member Functions

void MakeNewTrack (BesTStats &stat, const G4Track *track)
 
BesTStats FollowTrack (const G4Track *track)
 

Protected Attributes

std::vector< BesSensitiveDetector * >::iterator iter
 
std::vector< BesSensitiveDetector * >::iterator iter_end
 
G4int m_trackIndex
 
G4int m_trackFlag
 
std::vector< BesTruthTrack * > * m_trackList
 
std::vector< BesTruthVertex * > * m_vertexList
 
std::vector< BesSensitiveDetector * > clients
 
std::vector< BesTStatschain
 
G4int m_count
 
G4ThreeVector m_pos0
 
G4double m_t0
 
G4int m_logLevel
 
HepMC::GenEvent * m_hepmcevt
 

Static Protected Attributes

static BesSensitiveManagerm_sensitiveManager =0
 

Detailed Description

Definition at line 73 of file BesSensitiveManager.hh.

Constructor & Destructor Documentation

◆ BesSensitiveManager()

BesSensitiveManager::BesSensitiveManager ( )
inline

Definition at line 75 of file BesSensitiveManager.hh.

76 {
77 m_hepmcevt = 0;
79 G4Exception("BesSensitiveManager constructed twice.");
80 m_sensitiveManager = this ;
81 }
HepMC::GenEvent * m_hepmcevt
static BesSensitiveManager * m_sensitiveManager

◆ ~BesSensitiveManager()

BesSensitiveManager::~BesSensitiveManager ( )
inline

Definition at line 83 of file BesSensitiveManager.hh.

83{;}

Member Function Documentation

◆ AddSensitiveDetector()

void BesSensitiveManager::AddSensitiveDetector ( BesSensitiveDetector * detector)
inline

Definition at line 88 of file BesSensitiveManager.hh.

89 {
90 clients.push_back( detector );
91 }
std::vector< BesSensitiveDetector * > clients

Referenced by BesSensitiveDetector::BesSensitiveDetector().

◆ BeginOfTrack()

void BesSensitiveManager::BeginOfTrack ( const G4Track * track)

Definition at line 252 of file BesSensitiveManager.cc.

253{
254 m_trackFlag = 0; //if m_trackFlag=1, this track is from generator
255
256 // Append our track in the parentage history
257 chain.push_back(FollowTrack(track));
258
259 // Get TruthTrack index
260 //int i = chain.size();
261
262 /*for(;;)
263 {
264 if(--i<0) G4cerr<<"::parents are corrupted"<<G4endl;
265 m_trackIndex = chain[i].trackIndex;
266 if (m_trackIndex != -1) break;
267 }*/
268
269 // Invoke clients
270 //
271 iter=clients.begin();
272 iter_end=clients.end();
273 while(iter!=iter_end)
274 {
275 (*iter)->BeginOfTrack( track );
276 iter++;
277 }
278}
BesTStats FollowTrack(const G4Track *track)
std::vector< BesSensitiveDetector * >::iterator iter_end
std::vector< BesTStats > chain
std::vector< BesSensitiveDetector * >::iterator iter

Referenced by BesTrackingAction::PreUserTrackingAction().

◆ BeginOfTruthEvent()

void BesSensitiveManager::BeginOfTruthEvent ( const G4Event * evt)

Definition at line 43 of file BesSensitiveManager.cc.

44{
45 // Allocate our lists. We'll own these until EndOfEvent
46
47 m_trackList = new std::vector<BesTruthTrack*>;
48 m_vertexList = new std::vector<BesTruthVertex*>;
49
50 SetVertex0(evt);
51
52 m_count = 0;
54 m_count += m_trackList->size();
55
56 // Tell clients
57 iter=clients.begin();
58 iter_end=clients.end();
59 while( iter != iter_end )
60 {
61 (*iter)->BeginOfTruthEvent(evt);
62 iter++;
63 }
64}
void SetVertex0(const G4Event *)
std::vector< BesTruthTrack * > * m_trackList
std::vector< BesTruthVertex * > * m_vertexList

Referenced by BesEventAction::BeginOfEventAction().

◆ CheckDecayTrack()

G4bool BesSensitiveManager::CheckDecayTrack ( const G4Track * track)

Definition at line 590 of file BesSensitiveManager.cc.

591{
592 G4int flag = 0;
593 G4int trackID = track->GetTrackID();
594 G4int parentID = track->GetParentID();
595 G4int pdgcode = track->GetDefinition()->GetPDGEncoding();
596 G4ThreeVector p3 = track->GetMomentum();
597 if(m_logLevel<=4)
598 G4cout<<"CheckDecayTrack p3: "<<p3<<" "<<track->GetTotalEnergy()<<G4endl;
599
600 //HepLorentzVector p4(track->GetMomentum(), track->GetTotalEnergy());
601
602 BesTruthTrack* truthTrack=0;
603 G4int nTrack = m_trackList->size();
604 G4int parentTrackIndex=-99;
605 G4int terminalVertexIndex=-99;
606 BesTruthTrack* pTrack;
607 for(int i=0;i<nTrack;i++)
608 {
609 truthTrack = (*m_trackList)[i];
610 if(truthTrack->GetG4TrackId() == parentID)
611 {
612 //parentTrackIndex = i;
613 parentTrackIndex = truthTrack->GetIndex();
614 if(truthTrack->GetTerminalVertex())
615 {
616 terminalVertexIndex = truthTrack->GetTerminalVertex()->GetIndex();
617 pTrack = truthTrack;
618 if(m_logLevel<=4)
619 {
620 G4cout<<"parentTrackIndex:"<<parentTrackIndex<<" "
621 <<"parent terminate at vertex: "<<terminalVertexIndex<<G4endl;
622 if(parentTrackIndex != i)
623 G4cout<<"i: "<<i<<std::endl;
624 }
625 break;
626 }
627 }
628 }
629 if(parentTrackIndex==-99 || terminalVertexIndex==-99)
630 {
631 G4cout<<"MatchDecayError!"<<G4endl;
632 //return false;
633 exit(1);
634 }
635
636 //match decayed track with p3
637 /*G4bool matchDauFlag=false;
638 if(terminalVertexIndex>0)
639 matchDauFlag = MatchDaughterTrack(track);
640 if(matchDauFlag)
641 return true;*/
642
643 //match decayed track with vertex index
644 G4double minDiffP=1e99;
645 G4int truthI=-9;
646 /*for(int i=0;i<nTrack;i++)
647 {
648 truthTrack = (*m_trackList)[i];
649 G4String source = truthTrack->GetSource();
650 G4int pdgcode_tru = truthTrack->GetPDGCode();
651 if(pdgcode_tru==-22) pdgcode_tru = 22;
652 if(truthTrack->GetVertex()->GetIndex() == terminalVertexIndex &&
653 pdgcode_tru == pdgcode &&source=="FromGenerator"&&truthTrack->NotFound())
654 {
655 HepLorentzVector tp4 = truthTrack->GetP4();
656 G4ThreeVector tp3(tp4.x(), tp4.y(), tp4.z());
657 G4double diffP = (p3-tp3).mag2();
658 if(m_logLevel<=4)
659 G4cout<<"diffP: "<<diffP<<G4endl;
660 if(diffP<minDiffP )
661 { minDiffP = diffP; truthI = i; }
662 }
663 }*/
664
665 /*if(truthI!=-9)
666 {
667 if(m_logLevel<=4)
668 G4cout<<"MatchDecayedTrackWithVertexIndex, trackIndex:"<<truthI<<G4endl;
669 m_trackIndex = truthI;
670 truthTrack=(*m_trackList)[truthI];
671 //truthTrack->SetP4(p4);
672 truthTrack->SetPDGCharge(track->GetDefinition()->GetPDGCharge());
673 truthTrack->SetParticleName(track->GetDefinition()->GetParticleName());
674 truthTrack->SetG4TrackId(track->GetTrackID());
675 truthTrack->Found();
676 G4int size = truthTrack->GetDaughterIndexes().size();
677 if(size>0)
678 {
679 G4int minDau = (truthTrack->GetDaughterIndexes())[0];
680 G4int maxDau = (truthTrack->GetDaughterIndexes())[size-1];
681 if(m_logLevel<=4)
682 G4cout<<"daughters: "<<minDau<<" "<<maxDau<<G4endl;
683 }
684 else
685 {
686 if(m_logLevel<=4)
687 G4cout<<G4endl;
688 }
689 return true;
690 }*/ //match decay track with vertex index
691
692 //match decay track
693
694 if(m_logLevel<=4)
695 std::cout<<"chain.back().vertices.size(): "<<chain.back().vertices.size()<<std::endl;
696 //if particle is from generator, chain.back().vertices.size()=0;
697 //if particle is not from generator, but decayed during flight in Geant4, chain.back().vertices.size()=1;
698 if(chain.back().vertices.size()<1)
699 {
700 if(m_logLevel<=4)
701 std::cout<<"trackList size: "<<m_trackList->size()<<std::endl;
702 std::vector<int>* vDau = new std::vector<int>;
703 GetDaughterVertexes(pTrack, vDau);
704 G4int sizev = vDau->size();
705 if(sizev>0)
706 {
707 for(int i=0;i<nTrack;i++)
708 {
709 truthTrack = (*m_trackList)[i];
710 G4int vIndex = truthTrack->GetVertex()->GetIndex();
711 G4int pdgT = truthTrack->GetPDGCode();
712 if(pdgT==-22) pdgT = 22;
713 if(pdgT == pdgcode)
714 {
715 G4bool matchFlag = MatchVertex(vIndex, vDau);
716 if(matchFlag)
717 {
718 HepLorentzVector tp4 = truthTrack->GetP4();
719 G4ThreeVector tp3(tp4.x(), tp4.y(), tp4.z());
720 G4double diffP = (p3-tp3).mag2();
721 if(m_logLevel<=4)
722 {
723 G4cout<<"index: "<<truthTrack->GetIndex()<<"tp3: "<<tp3<<G4endl;
724 G4cout<<"diffP: "<<diffP<<G4endl;
725 }
726 if(diffP<minDiffP)
727 {
728 minDiffP = diffP; truthI = i;
729 if(m_logLevel<=4)
730 G4cout<<"truthI: "<<i<<G4endl;
731 }
732 }
733 }
734 }
735 if(vDau)
736 delete vDau;
737 }
738 }
739
740 if(truthI!=-9)
741 {
742 m_trackIndex = truthI;
743 if(m_logLevel<=4)
744 {
745 G4cout<<"MatchDecayedTrackWithTrueMother"<<G4endl;
746 G4cout<<"MatchWithTrueMother m_trackIndex: "<<m_trackIndex<<G4endl;
747 if(minDiffP>1e-9)
748 G4cout<<"large minDiffP: "<<minDiffP<<G4endl;
749 }
750 truthTrack=(*m_trackList)[truthI];
751 G4double mass = truthTrack->GetP4().m();
752 G4double E = sqrt(mass*mass+p3.x()*p3.x()+p3.y()*p3.y()+p3.z()*p3.z());
753 truthTrack->GetP4().setX(p3.x());
754 truthTrack->GetP4().setY(p3.y());
755 truthTrack->GetP4().setZ(p3.z());
756 truthTrack->GetP4().setE(E);
757 HepLorentzVector p4 = truthTrack->GetP4();
758 if(m_logLevel<=4)
759 {
760 G4cout<<"primary p: "<<p4.x()<<" "<<p4.y()<<" "<<p4.z()<<" "<<p4.m()<<G4endl;
761 }
762 truthTrack->SetPDGCharge(track->GetDefinition()->GetPDGCharge());
763 truthTrack->SetParticleName(track->GetDefinition()->GetParticleName());
764 truthTrack->SetG4TrackId(track->GetTrackID());
765 truthTrack->Found();
766 //truthTrack->GetVertex()->SetPosition(track->GetPosition());
767 //truthTrack->GetVertex()->SetTime(track->GetGlobalTime());
768 return true;
769 }
770 return false;
771}
double mass
G4bool MatchVertex(G4int vIndex, std::vector< int > *vDau)
void GetDaughterVertexes(BesTruthTrack *pTrack, std::vector< int > *vDau)
G4int GetPDGCode() const
HepLorentzVector GetP4() const
BesTruthVertex * GetTerminalVertex() const
BesTruthVertex * GetVertex() const
G4int GetG4TrackId() const
void SetParticleName(G4String name)
G4int GetIndex() const
void SetG4TrackId(G4int trackId)
void SetPDGCharge(G4double charge)
G4int GetIndex() const

Referenced by FollowTrack().

◆ CheckType()

G4int BesSensitiveManager::CheckType ( const HepMC::GenEvent * hepmcevt)

Definition at line 79 of file BesSensitiveManager.cc.

80{
81 G4int flag =0;
82 for(HepMC::GenEvent::vertex_const_iterator vitr= hepmcevt->vertices_begin();
83 vitr != hepmcevt->vertices_end(); ++vitr ) { // loop for vertex ...
84 for (HepMC::GenVertex::particle_iterator
85 pitr= (*vitr)->particles_begin(HepMC::children);
86 pitr != (*vitr)->particles_end(HepMC::children); ++pitr) {
87 if((*pitr)->end_vertex())
88 {flag = 1; break;}
89 }
90 if(flag) break;
91 }
92 if(m_logLevel <= 4)
93 {
94 if(flag == 0)
95 G4cout<<G4endl<<"generator is GENBES!"<<G4endl;
96 else
97 G4cout<<G4endl<<"generator is not GENBES!"<<G4endl;
98 }
99 return flag;
100}

Referenced by SaveParticlesFromGenerator().

◆ ClearEvent()

void BesSensitiveManager::ClearEvent ( )

Definition at line 234 of file BesSensitiveManager.cc.

235{
236 if(m_trackList)
237 {
238 for(size_t i=0;i<m_trackList->size();i++)
239 delete (*m_trackList)[i];
240 m_trackList->clear();
241 delete m_trackList;
242 }
243 if(m_vertexList)
244 {
245 for(size_t i=0;i<m_vertexList->size();i++)
246 delete (*m_vertexList)[i];
247 m_vertexList->clear();
248 delete m_vertexList;
249 }
250}

Referenced by BesEventAction::EndOfEventAction().

◆ EndOfTrack()

void BesSensitiveManager::EndOfTrack ( const G4Track * track,
G4TrackingManager * trackingManager )

Definition at line 279 of file BesSensitiveManager.cc.

280{
281 if(chain.back().savedByDefault==true)
282 {
283 BesTStats &stat = chain.back();
284 G4int endVtxFlag = 0;
285 if(m_trackFlag==1)
286 {
287 BesTruthTrack* truthTrack = (*m_trackList)[m_trackIndex];
288 if(truthTrack->GetTerminalVertex())
289 {
290 UpdateVertex(stat,track); endVtxFlag = 1;}
291 }
292 if(endVtxFlag == 0)
293 {
294 // Tracks saved to BesTruthTrack require additional work
295 G4StepPoint *finalStep = track->GetStep()->GetPostStepPoint();
296 G4StepStatus stepStatus = finalStep->GetStepStatus();
297 if (track->GetNextVolume() != 0 ||
298 (stepStatus != fGeomBoundary && stepStatus != fWorldBoundary) )
299 {
300 if(m_logLevel<=4)
301 G4cout<<"Particle died. make a terminal vertex: ";
302 // Particle died. We always make a terminal vertex
303 const G4ThreeVector pos(finalStep->GetPosition());
304 G4int vindex = m_vertexList->size();
305 if(m_logLevel<=4)
306 G4cout<<vindex<<G4endl;
307 stat.vertices.push_back(vindex);
308 BesTruthVertex *newVertex = new BesTruthVertex();
309 newVertex->SetPosition(pos);
310 newVertex->SetTime( finalStep->GetGlobalTime());
311 if(m_trackFlag==1)
312 newVertex->SetParentTrack( (*m_trackList)[m_trackIndex] );
313 else
314 newVertex->SetParentTrack( m_trackList->back() );
315 newVertex->SetTerminal( true );
316 newVertex->SetIndex( vindex );
317
318 //set minDaughter index equal to m_count
319 newVertex->SetMinDau(m_count);
320
321 //Get how many decayed daughters this track has, if no, 0 is set.
322 G4TrackVector* trackVector = trackingManager->GimmeSecondaries();
323 G4int nSecon = trackVector->size();
324 G4Track* seconTrack;
325 G4int nDau=0;
326 if(nSecon>0)
327 {
328 for(G4int i=0;i<nSecon;i++)
329 {
330 seconTrack = (*trackVector)[i];
331 G4String processName = seconTrack->GetCreatorProcess()->GetProcessName();
332 if(processName == "Decay")
333 nDau++;
334 }
335 }
336 m_vertexList->push_back( newVertex );
337
338 m_count += nDau;
339
340 // Give this terminal vertex to the track
341 //(*m_trackList)[stat.trackIndex]->SetTerminalVertex( m_vertexList->back() );
342 // for particles from generator,
343 // m_trackList->back() may not be current track.
344
345 if(m_trackFlag==1)
346 (*m_trackList)[m_trackIndex]->SetTerminalVertex( m_vertexList->back() );
347 else
348 m_trackList->back()->SetTerminalVertex( m_vertexList->back() );
349 }
350 }
351 }
352 // Invoke clients
353 iter=clients.begin();
354 iter_end=clients.end();
355 while( iter!=iter_end) {
356 (*iter)->EndOfTrack( track );
357 iter++;
358 }
359}
void UpdateVertex(BesTStats, const G4Track *)
void SetPosition(const G4ThreeVector &p)
void SetParentTrack(BesTruthTrack *newParent)
void SetTerminal(bool wasTerminal)
void SetTime(const G4double &t)
void SetIndex(signed long newIndex)
void SetMinDau(G4int dau)

Referenced by BesTrackingAction::PostUserTrackingAction().

◆ EndOfTruthEvent()

void BesSensitiveManager::EndOfTruthEvent ( const G4Event * evt)

Definition at line 222 of file BesSensitiveManager.cc.

223{
224 // Tell clients
225 iter=clients.begin();
226 iter_end=clients.end();
227 while( iter != iter_end )
228 {
229 (*iter)->EndOfTruthEvent(evt);
230 iter++;
231 }
232}

Referenced by BesEventAction::EndOfEventAction().

◆ FollowTrack()

BesTStats BesSensitiveManager::FollowTrack ( const G4Track * track)
protected

Definition at line 505 of file BesSensitiveManager.cc.

506{
507 // Some default stats for this track
508 BesTStats stat( track->GetTrackID(),
509 HepLorentzVector( track->GetMomentum(), track->GetTotalEnergy() ),
510 track->GetGlobalTime());
511
512 // Check immediate parent
513 G4int parentId = track->GetParentID();
514 G4int pdg = track->GetDefinition()->GetPDGEncoding();
515 G4String particleName = track->GetDefinition()->GetParticleName();
516 G4ThreeVector trackPos = track->GetPosition();
517 G4double diffT = m_t0-track->GetGlobalTime();
518 G4ThreeVector diffPos = (m_pos0-trackPos).mag2();
519
520 if (parentId == 0)
521 {
522 if(m_logLevel<=4)
523 {
524 G4cout<<G4endl;
525 G4cout<<"trackId:"<<track->GetTrackID()<<" ";
526 G4cout<<"parentId:"<<parentId<<" ";
527 G4cout<<"pdg:"<<pdg<<" ";
528 G4cout<<"name:"<<particleName<<" ";
529 G4cout<<"timeDiff:"<<diffT<<" ";
530 G4cout<<"posDiff:"<<diffPos<<G4endl;
531 }
532
533 // Primary particle: wipe decay chain
534 chain.clear();
535 // Always save
536 stat.savedByDefault = true;
537 // Make TruthTrack
538 if(m_hepmcevt==0)
539 MakeNewTrack( stat, track );
540 else
541 {
542 UpdatePrimaryTrack(track);
543 m_trackFlag = 1;
544 }
545 return stat;
546 }
547
548 // Not primary particle: trim down chain until
549 // we uncover the parent. The parent must be there!
550 for(;;)
551 {
552 if (chain.back().G4index == parentId) break;
553 chain.pop_back();
554 }
555
556 // This track is a candidate for saving by default
557 // only if its parent was saved by default
558 if (chain.back().savedByDefault)
559 {
560 // There are three ways particles are saved by default:
561 // 1. if they are a primary particle
562 // 2. if they are the result of a decay
563 //
564 G4String processName = track->GetCreatorProcess()->GetProcessName();
565 if (processName=="Decay")
566 {
567 if(m_logLevel<=4)
568 {
569 G4cout<<G4endl;
570 G4cout<<"trackId: "<<track->GetTrackID()<<" ";
571 G4cout<<"parentId: "<<parentId<<" ";
572 G4cout<<"pdg: "<<pdg<<" ";
573 G4cout<<"pname: "<<particleName<<G4endl;
574 }
575 stat.savedByDefault = true;
576
577 if(CheckDecayTrack(track))
578 m_trackFlag = 1;
579 else
580 MakeNewTrack( stat, track);
581 return stat;
582 }
583 }
584
585 //now this track will not be saved as BesTruthTrack
586 stat.savedByDefault = false;
587 return stat;
588}
void UpdatePrimaryTrack(const G4Track *)
void MakeNewTrack(BesTStats &stat, const G4Track *track)
G4bool CheckDecayTrack(const G4Track *)

Referenced by BeginOfTrack().

◆ GetCurrentTrackIndex()

G4int BesSensitiveManager::GetCurrentTrackIndex ( ) const
inline

Definition at line 93 of file BesSensitiveManager.hh.

93{ return m_trackIndex; }

Referenced by BesSensitiveDetector::GetCurrentTrackIndex().

◆ GetDaughterVertexes()

void BesSensitiveManager::GetDaughterVertexes ( BesTruthTrack * pTrack,
std::vector< int > * vDau )

Definition at line 773 of file BesSensitiveManager.cc.

774{
775 G4int size = pTrack->GetDaughterIndexes().size();
776 if(size>0)
777 {
778 G4int minDau = (pTrack->GetDaughterIndexes())[0];
779 G4int maxDau = (pTrack->GetDaughterIndexes())[size-1];
780 //note! here, dau<=maxDau, not dau<maxDau
781 for(G4int dau=minDau;dau<=maxDau;dau++)
782 {
783 if(dau<m_trackList->size())
784 {
785 BesTruthTrack* truthTrack = (*m_trackList)[dau];
786 if(truthTrack->GetVertex())
787 {
788 vDau->push_back(truthTrack->GetVertex()->GetIndex());
789 GetDaughterVertexes(truthTrack,vDau);
790 }
791 }
792 }
793 }
794}
vector< int > GetDaughterIndexes() const

Referenced by CheckDecayTrack(), and GetDaughterVertexes().

◆ GetNumberTracks()

G4int BesSensitiveManager::GetNumberTracks ( ) const
inline

Definition at line 119 of file BesSensitiveManager.hh.

119{ return m_trackList ? m_trackList->size() : 0; }

◆ GetNumberVertices()

G4int BesSensitiveManager::GetNumberVertices ( ) const
inline

Definition at line 120 of file BesSensitiveManager.hh.

120{ return m_vertexList ? m_vertexList->size() : 0; }

◆ GetSensitiveManager()

◆ GetTrackList()

std::vector< BesTruthTrack * > * BesSensitiveManager::GetTrackList ( )
inline

◆ GetVertexList()

std::vector< BesTruthVertex * > * BesSensitiveManager::GetVertexList ( )
inline

◆ MakeNewTrack()

void BesSensitiveManager::MakeNewTrack ( BesTStats & stat,
const G4Track * track )
protected

Definition at line 381 of file BesSensitiveManager.cc.

382{
383 if (stat.originVertex < 0 && chain.size() > 0)
384 {
385 if(m_logLevel<=4)
386 G4cout<<"MakeNewTrack for decayed particles,";
387 //for decayed particles, there may already be a BesTruthVertex that is suitable for this track.
388 //If so, it's always the terminal vertex of its immediate parent( chain.back() ).
389
390 G4int parentVstat = chain.back().vertices.size();
391 while( --parentVstat >= 0)
392 {
393 G4int vindex = chain.back().vertices[parentVstat];
394
395 G4ThreeVector diff((*m_vertexList)[vindex]->GetPosition());
396 diff = diff - track->GetPosition();
397 if (diff.mag2() < 1E-9)
398 {
399 stat.originVertex = vindex;
400 if(m_logLevel<=4)
401 G4cout<<"find a vertex:"<<vindex;
402 (*m_vertexList)[vindex]->AddCurrentDau();
403 break;
404 }
405 }
406
407 }
408
409 if(stat.originVertex < 0 && chain.size() == 0)
410 {
411 //for primary track, check if there is already a vertex suitable for it.
412 G4int nVertex = m_vertexList->size();
413 for(G4int i=0;i<nVertex;i++)
414 {
415 G4ThreeVector diff((*m_vertexList)[i]->GetPosition());
416 diff = diff -track->GetPosition();
417 if(diff.mag2() < 1E-9)
418 {
419 stat.originVertex = i;
420 if(m_logLevel<=4)
421 G4cout<<"MakeNewTrack for primary particles,find a vertex:"
422 <<i;
423 break;
424 }
425 }
426 }
427
428 if (stat.originVertex < 0)
429 {
430 if(m_logLevel<=4)
431 G4cout<<"MakeNewTrack for primary particles,make new vertex:"
432 <<m_vertexList->size();
433 // it's a primary track(there's no vertex suitable for it)
434 // Make a new BesTruthVertex
435 const G4ThreeVector v(track->GetPosition());
436
437 stat.originVertex = m_vertexList->size();
438
439 BesTruthVertex *newVertex = new BesTruthVertex();
440 newVertex->SetPosition(v);
441 newVertex->SetTime( track->GetGlobalTime());
442
443 //if (chain.size() > 0) {
444 // G4int trackIndex = -1;
445 // G4int i = chain.size();
446 // while(--i>=0 && trackIndex < 0) trackIndex = chain[i].trackIndex;
447 // newVertex->SetParentTrack( trackIndex < 0 ? 0 : (*m_trackList)[trackIndex] );
448 //}
449
450 newVertex->SetParentTrack( 0 );
451 newVertex->SetTerminal( false );
452 newVertex->SetIndex( stat.originVertex );
453 if(track->GetCreatorProcess())
454 newVertex->SetProcessName(track->GetCreatorProcess()->GetProcessName());
455 else
456 newVertex->SetProcessName("generator");
457
458 m_vertexList->push_back( newVertex );
459 }
460
461 // Now, finally make our new BesTruthTrack
462 // We'll leave the assignment of terminalVertex until
463 // we know what happens to this track
464 BesTruthTrack *newTrack = new BesTruthTrack();
465 newTrack->SetP4( stat.p4 );
466 newTrack->SetPDGCode(track->GetDefinition()->GetPDGEncoding());
467 newTrack->SetPDGCharge(track->GetDefinition()->GetPDGCharge());
468 newTrack->SetParticleName(track->GetDefinition()->GetParticleName());
469 newTrack->SetSource("FromG4");
470 BesTruthVertex* vertex = (*m_vertexList)[stat.originVertex];
471 newTrack->SetVertex(vertex);
472
473 if(track->GetParentID()==0)
474 {
475 stat.trackIndex = m_count;
476 m_count++;
477 }
478 else
479 stat.trackIndex = vertex->GetMinDau() + vertex->GetCurrentDau()-1;
480
481 newTrack->SetIndex( stat.trackIndex );
482 m_trackIndex = stat.trackIndex;
483 if(m_logLevel<=4)
484 G4cout<<" m_trackIndex:"<<m_trackIndex<<G4endl;
485
486 newTrack->SetG4TrackId( track->GetTrackID());
487 m_trackList->push_back( newTrack );
488 //tell the parent track its daughter track index
489 BesTruthTrack* parent = newTrack->GetVertex()->GetParentTrack();
490 if(parent)
491 {
492 parent->AddDaughterIndex(stat.trackIndex);
493 if(m_logLevel<=4)
494 G4cout<<"add this daughter to:"<<parent->GetIndex()<<G4endl;
495 }
496}
**********Class see also m_nmax DOUBLE PRECISION m_amel DOUBLE PRECISION m_x2 DOUBLE PRECISION m_alfinv DOUBLE PRECISION m_Xenph INTEGER m_KeyWtm INTEGER m_idyfs DOUBLE PRECISION m_zini DOUBLE PRECISION m_q2 DOUBLE PRECISION m_Wt_KF DOUBLE PRECISION m_WtCut INTEGER m_KFfin *COMMON c_KarLud $ !Input CMS energy[GeV] $ !CMS energy after beam spread beam strahlung[GeV] $ !Beam energy spread[GeV] $ !z boost due to beam spread $ !electron beam mass *ff pair spectrum $ !minimum v
Definition KarLud.h:35
void SetSource(G4String source)
void SetPDGCode(G4int code)
void SetIndex(G4int index)
void SetVertex(BesTruthVertex *vertex)
void SetP4(const HepLorentzVector &p4)
void AddDaughterIndex(G4int index)
BesTruthTrack * GetParentTrack() const
G4int GetMinDau() const
G4int GetCurrentDau() const
void SetProcessName(const G4String name)

Referenced by FollowTrack().

◆ MatchDaughterTrack()

G4bool BesSensitiveManager::MatchDaughterTrack ( const G4Track * track)

Definition at line 810 of file BesSensitiveManager.cc.

811{
812 /*G4int flag=0;
813 G4int pdgcode = track->GetDefinition()->GetPDGEncoding();
814 G4ThreeVector p = track->GetMomentum();
815 HepLorentzVector p4(track->GetMomentum(), track->GetTotalEnergy());
816 G4ThreeVector pos = track->GetPosition();
817 G4double time = track->GetGlobalTime();
818 BesTruthTrack* truthTrack=0;
819 G4int size = m_trackList->size();
820 if(size>0)
821 {
822 for(G4int i=0;i<size;i++)
823 {
824 truthTrack=(*m_trackList)[i];
825 G4String source = truthTrack->GetSource();
826 G4int pdgcode_tru = truthTrack->GetPDGCode();
827 if(pdgcode_tru==-22) pdgcode_tru = 22;
828 HepLorentzVector tp4 = truthTrack->GetP4();
829 G4ThreeVector tp3(tp4.x(), tp4.y(), tp4.z());
830 G4double diffP = (p-tp3).mag2();
831 if(source=="FromGenerator"&&pdgcode_tru==pdgcode&&diffP<1e-9&&truthTrack->NotFound())
832 {
833 m_trackIndex = i;
834 //truthTrack->SetP4(p4);
835 truthTrack->SetPDGCharge(track->GetDefinition()->GetPDGCharge());
836 truthTrack->SetParticleName(track->GetDefinition()->GetParticleName());
837 truthTrack->SetG4TrackId(track->GetTrackID());
838 truthTrack->Found();
839 //truthTrack->GetVertex()->SetPosition(pos);
840 //truthTrack->GetVertex()->SetTime(time);
841 flag=1;
842 if(m_logLevel<=4)
843 {
844 G4cout<<"MatchDecayedTrackWithP3!"<<"trackIndex:"<<m_trackIndex
845 <<" pdgcode:"<<pdgcode<<G4endl;
846 G4cout<<"parentIndex:"<<truthTrack->GetVertex()->GetParentTrack()->GetIndex()
847 <<" PDGCode:"<<truthTrack->GetVertex()->GetParentTrack()->GetPDGCode()<<G4endl;
848 }
849 return true;
850 }
851 }
852 }
853 if(flag!=1)
854 return false;*/
855 return true;
856}

◆ MatchVertex()

G4bool BesSensitiveManager::MatchVertex ( G4int vIndex,
std::vector< int > * vDau )

Definition at line 796 of file BesSensitiveManager.cc.

797{
798 G4int size = vDau->size();
799 if(size>0)
800 {
801 for(G4int i=0;i<size;i++)
802 {
803 if(vIndex==(*vDau)[i])
804 return true;
805 }
806 }
807 return false;
808}

Referenced by CheckDecayTrack().

◆ SaveParticlesFromGenerator()

void BesSensitiveManager::SaveParticlesFromGenerator ( )

Definition at line 102 of file BesSensitiveManager.cc.

103{
104 IDataProviderSvc* p_evtSvc=0;
105 ISvcLocator* svcLocator = Gaudi::svcLocator();
106 StatusCode sc=svcLocator->service("EventDataSvc", p_evtSvc);
107 if (sc.isFailure())
108 std::cout<<"BesHepMCInterface could not access EventDataSvc!!"<<std::endl;
109
110 SmartDataPtr<McGenEventCol> mcCollptr( p_evtSvc, "/Event/Gen");
111
112 if ( mcCollptr == 0 )
113 std::cout << "no McGenEventCollection found." << std::endl;
114
115 else
116 {
117 McGenEventCol::const_iterator it = mcCollptr->begin();
118 McGenEvent* mcEvent = (McGenEvent* ) (*it);
119 m_hepmcevt = mcEvent->getGenEvt();
120 G4int typeFlag = CheckType(m_hepmcevt);
121
122
123 for(HepMC::GenEvent::vertex_const_iterator vitr= m_hepmcevt->vertices_begin();
124 vitr != m_hepmcevt->vertices_end(); ++vitr )
125 {
126 G4int barcodeVtx = (*vitr)->barcode();
127 if(m_logLevel<=4)
128 G4cout<<G4endl<<"barcodeVtx:"<<barcodeVtx<<" ";
129
130 G4LorentzVector xvtx((*vitr)->position().x(),(*vitr)->position().y(),(*vitr)->position().z(),(*vitr)->position().t());
131 G4ThreeVector v(xvtx.x(), xvtx.y(), xvtx.z());
132 BesTruthVertex* newVertex = new BesTruthVertex();
133 newVertex->SetPosition(v);
134 newVertex->SetTime(xvtx.t()*mm/c_light);
135 if(m_logLevel<=4)
136 G4cout<<"xyzt:"<<xvtx.x()<<" "<<xvtx.y()<<" "
137 <<xvtx.z()<<" "<<xvtx.t()*mm/c_light<<" ";
138 G4int nTrack = m_trackList->size();
139 BesTruthTrack* parentTrack=0;
140 G4int parentTrackIndex= -99;
141 for(int i=0;i<nTrack;i++)
142 {
143 parentTrack = (*m_trackList)[i];
144 if(parentTrack->GetBarcodeEndVtx() == barcodeVtx)
145 {
146 newVertex->SetParentTrack(parentTrack);
147 parentTrackIndex = parentTrack->GetIndex();
148 if(m_logLevel<=4)
149 G4cout<<"parentTrack:"<<parentTrackIndex<<" ";
150 parentTrack->SetTerminalVertex(newVertex);
151 //break;
152 }
153 }
154
155 G4int vtxFlag=0;
156 G4int pOut = (*vitr)->particles_out_size();
157 HepMC::GenVertex::particle_iterator pitr = (*vitr)->particles_begin(HepMC::children);
158 G4int pdgcode= (*pitr)-> pdg_id();
159 if(pOut == 1 && pdgcode == -11 && typeFlag==1)
160 vtxFlag=1;
161
162 if(vtxFlag==0)
163 {
164 m_vertexList->push_back(newVertex);
165 newVertex->SetIndex(m_vertexList->size()-1);
166 if(m_logLevel<=4)
167 G4cout<<"vindex:"<<m_vertexList->size()-1<<G4endl;
168
169 for (HepMC::GenVertex::particle_iterator pitr= (*vitr)->particles_begin(HepMC::children); pitr != (*vitr)->particles_end(HepMC::children); ++pitr)
170 {
171 G4LorentzVector p((*pitr)->momentum().x(), (*pitr)->momentum().y(),(*pitr)->momentum().z(),(*pitr)->momentum().t());
172 G4LorentzVector pGeV(p.x()*GeV,p.y()*GeV,p.z()*GeV,p.t()*GeV);
173 G4int pdgcode = (*pitr)->pdg_id();
174
175 BesTruthTrack* newTrack = new BesTruthTrack;
176 newTrack->SetP4(pGeV);
177 newTrack->SetPDGCode(pdgcode);
178 if(m_logLevel<=4)
179 {
180 G4cout<<"pdg:"<<pdgcode<<" ";
181 G4cout<<"p:"<<p.x()<<" "<<p.y()<<" "<<p.z()<<" "<<p.t()<<" ";
182 G4double mass = sqrt(p.t()*p.t()-p.x()*p.x()-p.y()*p.y()-p.z()*p.z());
183 G4cout<<mass<<" ";
184 }
185 newTrack->SetPDGCharge(99);
186 newTrack->SetParticleName("unknown");
187 newTrack->SetVertex(newVertex);
188 newTrack->SetTerminalVertex(0);
189 newTrack->SetSource("FromGenerator");
190
191 G4int barcodeEndVtx=0;
192 if((*pitr)->end_vertex())
193 {
194 barcodeEndVtx = (*pitr)->end_vertex()->barcode();
195 if(m_logLevel<=4)
196 G4cout<<"endVtx:"<<barcodeEndVtx<<" ";
197 }
198 newTrack->SetBarcodeEndVtx(barcodeEndVtx);
199
200 m_trackList->push_back(newTrack);
201 newTrack->SetIndex(m_trackList->size()-1);
202 if(m_logLevel<=4)
203 G4cout<<"index:"<<m_trackList->size()-1<<" ";
204 //here, parentTrack->GetIndex can't be used,
205 //use parentTrackIndex instead
206 if(parentTrackIndex>=0)
207 {
208 if(m_logLevel<=4)
209 G4cout<<"mother:"<<parentTrackIndex;
210 (*m_trackList)[parentTrackIndex]->AddDaughterIndex(m_trackList->size()-1);
211 }
212 if(m_logLevel<=4)
213 G4cout<<G4endl;
214 }
215 }
216 }
217 }
218}
G4int CheckType(const HepMC::GenEvent *hepmcevt)
void SetTerminalVertex(BesTruthVertex *vertex)
void SetBarcodeEndVtx(G4int vtx)
G4int GetBarcodeEndVtx()
GenEvent * getGenEvt() const

Referenced by BeginOfTruthEvent().

◆ SetLogLevel()

void BesSensitiveManager::SetLogLevel ( G4int level)
inline

Definition at line 124 of file BesSensitiveManager.hh.

124{m_logLevel = level;}

Referenced by BesSim::initialize().

◆ SetVertex0()

void BesSensitiveManager::SetVertex0 ( const G4Event * anEvent)

Definition at line 66 of file BesSensitiveManager.cc.

67{
68 //G4int n_vertex = anEvent->GetNumberOfPrimaryVertex();
69 for( G4int i=0; i<1; i++ )
70 {
71 G4PrimaryVertex* primaryVertex = anEvent->GetPrimaryVertex(i);
72 m_pos0 = primaryVertex->GetPosition();
73 m_t0 = primaryVertex->GetT0();
74 }
75 if(m_logLevel<=4)
76 G4cout<<"pos0:"<<m_pos0<<" t0:"<<m_t0<<G4endl;
77}

Referenced by BeginOfTruthEvent().

◆ UpdatePrimaryTrack()

void BesSensitiveManager::UpdatePrimaryTrack ( const G4Track * track)

Definition at line 858 of file BesSensitiveManager.cc.

859{
860 if(m_logLevel<=4)
861 {
862 G4cout<<"UpdatePrimaryTrack! ";
863 G4cout<<"position: "<<track->GetPosition()<<G4endl;
864 G4cout<<"time: "<<track->GetGlobalTime()<<G4endl;
865 G4cout<<"momentum: "<<track->GetMomentum()<<" "<<track->GetTotalEnergy()<<G4endl;
866 }
867 G4int pdgcode = track->GetDefinition()->GetPDGEncoding();
868 G4ThreeVector p = track->GetMomentum();
869 //HepLorentzVector p4(track->GetMomentum(), track->GetTotalEnergy());
870 G4int nTrack = m_trackList->size();
871 BesTruthTrack* truthTrack;
872 G4int flag = 0;
873 G4double minDiffP=1e99;
874 for(int i=0;i<nTrack;i++)
875 {
876 truthTrack = (*m_trackList)[i];
877 HepLorentzVector tp4 = truthTrack->GetP4();
878 G4ThreeVector tp3(tp4.x(), tp4.y(), tp4.z());
879 G4double diffP=(p-tp3).mag2();
880 G4int pdgT = truthTrack->GetPDGCode();
881 if(pdgT==-22) pdgT=22;
882 if(pdgcode == pdgT && diffP<minDiffP)
883 minDiffP = diffP;
884 if(pdgcode == pdgT && diffP < 1E-9 &&
885 truthTrack->NotFound())
886 {
887 m_trackIndex = truthTrack->GetIndex();
888 if(m_logLevel<=4)
889 G4cout<<"m_trackIndex: "<<m_trackIndex<<" "<<G4endl;
890 truthTrack->SetPDGCharge(track->GetDefinition()->GetPDGCharge());
891 truthTrack->SetParticleName(track->GetDefinition()->GetParticleName());
892 truthTrack->SetG4TrackId(track->GetTrackID());
893 truthTrack->Found();
894 G4double mass = truthTrack->GetP4().m();
895 G4double E = sqrt(mass*mass+p.x()*p.x()+p.y()*p.y()+p.z()*p.z());
896 truthTrack->GetP4().setX(p.x());
897 truthTrack->GetP4().setY(p.y());
898 truthTrack->GetP4().setZ(p.z());
899 truthTrack->GetP4().setT(E);
900 if(m_logLevel<=4)
901 {
902 HepLorentzVector p4 = truthTrack->GetP4();
903 G4cout<<"primary p: "<<p4.x()<<" "<<p4.y()<<" "<<p4.z()<<" "<<p4.m()<<G4endl;
904 }
905 G4int size = truthTrack->GetDaughterIndexes().size();
906 if(size>0)
907 {
908 G4double minDau = (truthTrack->GetDaughterIndexes())[0];
909 G4double maxDau = (truthTrack->GetDaughterIndexes())[size-1];
910 if(m_logLevel<=4)
911 G4cout<<"daughters: "<<minDau<<" "<<maxDau<<G4endl;
912 }
913 else
914 {
915 if(m_logLevel<=4)
916 G4cout<<G4endl;
917 }
918 flag = 1; break;
919 }
920 }
921 if(flag==0)
922 {
923 G4cout<<"MatchError! parentID=0, but match no track in trackList"<<G4endl;
924 G4cout<<"pdgcode: "<<pdgcode<<" min p diff: "<<minDiffP<<G4endl;
925 exit(1);
926 }
927}
G4bool NotFound()

Referenced by FollowTrack().

◆ UpdateVertex()

void BesSensitiveManager::UpdateVertex ( BesTStats stat,
const G4Track * track )

Definition at line 361 of file BesSensitiveManager.cc.

362{
363 BesTruthTrack* truthTrack = (*m_trackList)[m_trackIndex];
364 G4int terminalIndex = truthTrack->GetTerminalVertex()->GetIndex();
365 if(m_logLevel<=4)
366 G4cout<<"updateVertex:"<<terminalIndex<<" ";
367 BesTruthVertex* vertex = (*m_vertexList)[terminalIndex];
368 G4StepPoint *finalStep = track->GetStep()->GetPostStepPoint();
369 const G4ThreeVector pos(finalStep->GetPosition());
370 G4double time = finalStep->GetGlobalTime();
371 if(m_logLevel<=4)
372 G4cout<<"newPos:"<<pos<<" "<<"newTime:"<<time<<G4endl;
373 vertex->SetPosition(pos);
374 vertex->SetTime(time);
375 vertex->SetTerminal( true );
376 //G4int vindex = m_vertexList->size();
377 //stat.vertices.push_back(terminalIndex);
378
379}
Double_t time

Referenced by EndOfTrack().

Member Data Documentation

◆ chain

std::vector<BesTStats> BesSensitiveManager::chain
protected

◆ clients

std::vector<BesSensitiveDetector*> BesSensitiveManager::clients
protected

◆ iter

std::vector<BesSensitiveDetector*>::iterator BesSensitiveManager::iter
protected

◆ iter_end

std::vector<BesSensitiveDetector*>::iterator BesSensitiveManager::iter_end
protected

◆ m_count

G4int BesSensitiveManager::m_count
protected

Definition at line 158 of file BesSensitiveManager.hh.

Referenced by BeginOfTruthEvent(), EndOfTrack(), and MakeNewTrack().

◆ m_hepmcevt

HepMC::GenEvent* BesSensitiveManager::m_hepmcevt
protected

◆ m_logLevel

◆ m_pos0

G4ThreeVector BesSensitiveManager::m_pos0
protected

Definition at line 160 of file BesSensitiveManager.hh.

Referenced by FollowTrack(), and SetVertex0().

◆ m_sensitiveManager

BesSensitiveManager * BesSensitiveManager::m_sensitiveManager =0
staticprotected

Definition at line 128 of file BesSensitiveManager.hh.

Referenced by BesSensitiveManager(), and GetSensitiveManager().

◆ m_t0

G4double BesSensitiveManager::m_t0
protected

Definition at line 161 of file BesSensitiveManager.hh.

Referenced by FollowTrack(), and SetVertex0().

◆ m_trackFlag

G4int BesSensitiveManager::m_trackFlag
protected

Definition at line 135 of file BesSensitiveManager.hh.

Referenced by BeginOfTrack(), EndOfTrack(), and FollowTrack().

◆ m_trackIndex

G4int BesSensitiveManager::m_trackIndex
protected

◆ m_trackList

◆ m_vertexList

std::vector<BesTruthVertex*>* BesSensitiveManager::m_vertexList
protected

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