19#include "GaudiKernel/Bootstrap.h"
20#include "GaudiKernel/ISvcLocator.h"
25#include "G4HCofThisEvent.hh"
27#include "G4ThreeVector.hh"
28#include "G4SDManager.hh"
29#include "G4EventManager.hh"
31#include "G4UnitsTable.hh"
35#include "Randomize.hh"
43 collectionName.insert(
"BesMucHitsCollection");
44 collectionName.insert(
"BesMucHitsList");
45 HitID =
new G4int[500];
49 G4String GeometryPath2 = GeometryPath;
51 G4Exception(
"BOOST environment not set!");
53 GeometryPath +=
"/dat/muc-effi.dat";
54 GeometryPath2 +=
"/dat/muc-noise.dat";
60 ISvcLocator* svcLocator = Gaudi::svcLocator();
62 StatusCode sc=svcLocator->service(
"G4Svc", iG4Svc);
63 m_G4Svc =
dynamic_cast<G4Svc *
>(iG4Svc);
65 G4cout <<
"MucNoiseMode:\t"<<m_noiseMode<<G4endl;
67 if( m_noiseMode != 0 )
70 G4LogicalVolume* logicalMuc = detector->
GetPhysicalMuc()->GetLogicalVolume();
75 m_PreviousPrimaryTrackG4Id = 0;
97 m_trackIndexes.clear();
105 if(m_noiseMode != 0) m_noise->
AddNoise(m_noiseMode, MucHitCollection, MucHitList);
110 static G4int HLID=-1;
112 HLID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[1]);
113 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
114 HCE->AddHitsCollection(HLID,MucHitList);
119 G4Track *curTrack = aStep->GetTrack();
121 m_CurEvent = G4EventManager::GetEventManager()->GetConstCurrentEvent();
124 m_TrackCon = m_CurEvent->GetTrajectoryContainer();
136 if (curTrack->GetDefinition()->GetPDGCharge() == 0.)
return false;
138 G4double edep = aStep->GetTotalEnergyDeposit();
142 G4int trackIndex = -99, g4TrackId = -99;
145 G4TouchableHistory* theTouchable
146 = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
150 G4int trackID = curTrack->GetTrackID();
151 G4int parentID = curTrack->GetParentID();
155 G4int pdg = curTrack->GetDefinition()->GetPDGEncoding();
160 G4ThreeVector pos = 0.5*( aStep->GetPostStepPoint()->GetPosition()
161 + aStep->GetPreStepPoint()->GetPosition() );
164 G4ThreeVector posInGas = theTouchable->GetHistory()->GetTopTransform().TransformPoint(pos);
165 G4int stackDepth = theTouchable->GetHistory()->GetDepth();
166 G4ThreeVector posInBox = theTouchable->GetHistory()->GetTransform(stackDepth-1).TransformPoint(pos);
169 G4ThreeVector posInGap = theTouchable->GetHistory()->GetTransform(stackDepth-2).TransformPoint(pos);
174 G4double
energy = aStep->GetPreStepPoint()->GetKineticEnergy();
177 G4ThreeVector dir = aStep->GetPreStepPoint()->GetMomentumDirection();
180 G4ThreeVector
momentum = aStep->GetPreStepPoint()->GetMomentum();
183 G4double GlobalTime = aStep->GetPostStepPoint()->GetGlobalTime();
186 G4VPhysicalVolume* vl = theTouchable->GetVolume(0);
194 m_PreviousPrimaryTrackG4Id = g4TrackId;
210 G4int newTrackFlag = 0;
212 if(m_trackIndex != trackIndex) {
213 m_trackIndex = trackIndex;
214 G4int size = m_trackIndexes.size();
217 for(G4int i=0;i<size;i++)
218 if(m_trackIndexes[i] == trackIndex ) {
226 m_trackIndexes.push_back(trackIndex);
234 if (g4TrackId != trackID) {
243 G4int curPart, curSeg, curGap, curStrip;
255 if (curPart == m_prePart && curSeg == m_preSeg &&
256 curGap == m_preGap && curStrip == m_preStrip) {
258 delete truHit;
delete newHit;
269 bool truHitExist =
false;
270 G4int n_hit = MucHitList->entries();
271 for(G4int iTru=0;iTru<n_hit;iTru++) {
272 BesMucHit* aTruHit = (*MucHitList)[iTru];
283 G4float random=G4UniformRand();
286 if (random<=need_eff){ MucHitCollection->insert(newHit);}
288 if (!truHitExist&&random<=need_eff)
289 { MucHitList->insert(truHit);}
294 m_preStrip = curStrip;
302 bool BesMucSD::IsChildOf(G4Track *curTrack, G4int primaryG4TrackID)
304 G4cout <<
"IsChildof " <<
"curTrackID " << curTrack->GetTrackID() << G4endl;
306 G4VTrajectory* aTraj = GetTrajFromID(curTrack->GetParentID());
307 G4cout <<
"IsChildof " <<
"parentTrackID " << aTraj->GetTrackID() << G4endl;
309 while ( aTraj->GetTrackID() != 0 && aTraj->GetTrackID() != primaryG4TrackID ) {
311 aTraj = GetTrajFromID(aTraj->GetParentID());
314 if (aTraj->GetTrackID() == primaryG4TrackID)
return true;
318 G4VTrajectory* BesMucSD::GetTrajFromID(G4int
id)
321 G4cout <<
"begin of GetTrajFromID, id : " <<
id << G4endl;
323 if (!m_TrackCon) G4cout <<
"Trajectory not saved? Set /tracking/storeTrajectory 1" << G4endl;
325 if (m_TrackCon->size() == 0) {
326 G4cout <<
"BesMucSD::GetTrajFromID, TrackCon size 0" << G4endl;
331 while( k < (
int)m_TrackCon->size() && (*m_TrackCon)[k]->GetTrackID() !=
id ) {
332 G4cout <<
"GetTrajFromID " << k <<
" : ID " << (*m_TrackCon)[k]->GetTrackID() << G4endl;
334 if (!(*m_TrackCon)[k]) {
335 G4cout <<
"G4Track ID " << (*m_TrackCon)[k]->GetTrackID() <<
" doesnt exist in TrajContainer of this event! " << G4endl;
340 if ( k == (
int)m_TrackCon->size() ) {
341 G4cout <<
"BesMucSD::GetTrajFromID, track with ID " <<
id <<
" not found" << G4endl;
345 return (*m_TrackCon)[k];
350 static G4int HCID=-1;
352 {HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); }
353 HCE->AddHitsCollection(HCID, MucHitCollection);
**********INTEGER nmxhep !maximum number of particles DOUBLE PRECISION vhep INTEGER jdahep COMMON hepevt $ !serial number $ !number of particles $ !status code $ !particle ident KF $ !parent particles $ !childreen particles $ !four momentum
G4THitsCollection< BesMucHit > BesMucHitsCollection
************Class m_ypar INTEGER m_KeyWgt INTEGER m_nphot INTEGER m_KeyGPS INTEGER m_IsBeamPolarized INTEGER m_EvtGenInterface DOUBLE PRECISION m_Emin DOUBLE PRECISION m_sphot DOUBLE PRECISION m_Xenph DOUBLE PRECISION m_q2 DOUBLE PRECISION m_PolBeam2 DOUBLE PRECISION m_xErrPb *COMMON c_KK2f $ !CMS energy average $ !Spin Polarization vector first beam $ !Spin Polarization vector second beam $ !Beam energy spread[GeV] $ !minimum hadronization energy[GeV] $ !input READ never touch them !$ !debug facility $ !maximum weight $ !inverse alfaQED $ !minimum real photon energy
G4VPhysicalVolume * GetPhysicalMuc()
G4int GetNearestStripNo()
void SetHit(BesMucHit *hit)
void SetHit(BesMucHit *hit)
static BesMucEfficiency * Instance(void)
void SetPos(G4ThreeVector xyz)
void SetPosLocal(G4ThreeVector xyzLocal)
void SetVolume(G4VPhysicalVolume *pv)
void SetDir(G4ThreeVector dir)
void SetPDGCode(G4int pdg)
void SetEnergy(G4double energy)
void SetTrackID(G4int track)
void SetEdep(G4double de)
void SetStrip(G4int strip)
void SetMomentum(G4ThreeVector momentum)
void SetTrackIndex(G4int index)
G4int AddNoise(int model, BesMucHitsCollection *MucHitCollection, BesMucHitsCollection *MucHitList)
static BesMucNoise * Instance(void)
void Initialize(G4String filename, G4LogicalVolume *logicalMuc)
void BeginOfTruthEvent(const G4Event *)
BesMucSD(G4String, BesMucConstruction *)
G4bool ProcessHits(G4Step *, G4TouchableHistory *)
void Initialize(G4HCofThisEvent *)
void EndOfTruthEvent(const G4Event *)
void EndOfEvent(G4HCofThisEvent *)
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
static G4String GetBoostRoot()