00001
00012
00013 #ifndef BesSensitiveManager_hh
00014 #define BesSensitiveManager_hh
00015
00016 #include "BesSensitiveDetector.hh"
00017 #include "G4TrackingManager.hh"
00018 #include "globals.hh"
00019 #include "HepMC/GenEvent.h"
00020
00021 class G4Svc;
00022
00023 class G4VProcess;
00024 class G4Track;
00025 class G4Event;
00026
00027
00028 class BesTruthVertex;
00029 class BesTruthTrack;
00030
00031
00032
00033 class BesTStats {
00034
00035 friend class BesSensitiveManager;
00036
00037 public:
00038 BesTStats() :
00039 G4index(-1),
00040 p4(0),
00041 time(0),
00042 trackIndex(-1),
00043 originVertex(-1),
00044 savedByDefault(false),
00045 vertices(0) {;}
00046 BesTStats( const G4int index, const CLHEP::HepLorentzVector theP4, G4double theTime )
00047 : G4index(index),
00048 p4(theP4),
00049 time(theTime),
00050 trackIndex(-1),
00051 originVertex(-1),
00052 savedByDefault(false),
00053 vertices(0) {;}
00054 ~BesTStats() {;}
00055
00056 bool operator==( const BesTStats &other ) const { return G4index == other.G4index; }
00057
00058 private:
00059 G4int G4index;
00060 CLHEP::HepLorentzVector p4;
00061 G4double time;
00062 G4int trackIndex;
00063 G4int originVertex;
00064 bool savedByDefault;
00065
00066
00067
00068
00069 std::vector<int> vertices;
00070
00071 };
00072
00073 class BesSensitiveManager {
00074 public:
00075 BesSensitiveManager():m_trackIndex(-1),m_trackFlag(0),m_count(0)
00076 {
00077 m_hepmcevt = 0;
00078 if(m_sensitiveManager)
00079 G4Exception("BesSensitiveManager constructed twice.");
00080 m_sensitiveManager = this ;
00081 }
00082
00083 ~BesSensitiveManager() {;}
00084
00085 static BesSensitiveManager* GetSensitiveManager() {return m_sensitiveManager; }
00086
00087
00088 void AddSensitiveDetector( BesSensitiveDetector *detector )
00089 {
00090 clients.push_back( detector );
00091 }
00092
00093 G4int GetCurrentTrackIndex() const { return m_trackIndex; }
00094 std::vector<BesTruthTrack*>* GetTrackList() {return m_trackList;}
00095 std::vector<BesTruthVertex*>* GetVertexList() {return m_vertexList;}
00096
00097
00098
00099
00100 void BeginOfTruthEvent(const G4Event*);
00101 void EndOfTruthEvent(const G4Event*);
00102
00103 G4int CheckType(const HepMC::GenEvent* hepmcevt);
00104 void SaveParticlesFromGenerator();
00105 void SetVertex0(const G4Event*);
00106 void UpdatePrimaryTrack(const G4Track*);
00107 G4bool CheckDecayTrack(const G4Track*);
00108 void UpdateVertex(BesTStats, const G4Track*);
00109 G4bool MatchDaughterTrack(const G4Track*);
00110 void GetDaughterVertexes(BesTruthTrack* pTrack, std::vector<int>* vDau);
00111 G4bool MatchVertex(G4int vIndex, std::vector<int>* vDau);
00112
00113
00114
00115 void BeginOfTrack( const G4Track *track );
00116 void EndOfTrack( const G4Track *track , G4TrackingManager* );
00117
00118
00119 G4int GetNumberTracks() const { return m_trackList ? m_trackList->size() : 0; }
00120 G4int GetNumberVertices() const { return m_vertexList ? m_vertexList->size() : 0; }
00121
00122 void ClearEvent();
00123
00124 void SetLogLevel(G4int level) {m_logLevel = level;}
00125
00126 protected:
00127
00128 static BesSensitiveManager* m_sensitiveManager;
00129
00130 std::vector<BesSensitiveDetector*>::iterator iter;
00131 std::vector<BesSensitiveDetector*>::iterator iter_end;
00132
00133
00134 G4int m_trackIndex;
00135 G4int m_trackFlag;
00136
00137
00138
00139 std::vector<BesTruthTrack*> *m_trackList;
00140 std::vector<BesTruthVertex*> *m_vertexList;
00141
00142
00143
00144
00145
00146 std::vector<BesSensitiveDetector*> clients;
00147
00148 std::vector<BesTStats> chain;
00149
00150
00151 void MakeNewTrack( BesTStats &stat, const G4Track *track );
00152
00153
00154 BesTStats FollowTrack( const G4Track *track );
00155
00156
00157
00158 G4int m_count;
00159
00160 G4ThreeVector m_pos0;
00161 G4double m_t0;
00162
00163 G4int m_logLevel;
00164 HepMC::GenEvent* m_hepmcevt;
00165 };
00166
00167 #endif