BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
BesMucSD Class Reference

#include <BesMucSD.hh>

+ Inheritance diagram for BesMucSD:

Public Member Functions

 BesMucSD (G4String, BesMucConstruction *)
 
 ~BesMucSD ()
 
void Initialize (G4HCofThisEvent *)
 
G4bool ProcessHits (G4Step *, G4TouchableHistory *)
 
void EndOfEvent (G4HCofThisEvent *)
 
void BeginOfTruthEvent (const G4Event *)
 
void EndOfTruthEvent (const G4Event *)
 
- Public Member Functions inherited from BesSensitiveDetector
 BesSensitiveDetector (const G4String name)
 
virtual ~BesSensitiveDetector ()
 
virtual void BeginOfTruthEvent (const G4Event *)
 
virtual void EndOfTruthEvent (const G4Event *)
 
virtual void BeginOfTrack (const G4Track *)
 
virtual void EndOfTrack (const G4Track *)
 

Additional Inherited Members

- Protected Member Functions inherited from BesSensitiveDetector
void GetCurrentTrackIndex (G4int &trackIndex, G4int &g4TrackId) const
 

Detailed Description

Definition at line 34 of file BesMucSD.hh.

Constructor & Destructor Documentation

◆ BesMucSD()

BesMucSD::BesMucSD ( G4String  name,
BesMucConstruction Det 
)

Definition at line 40 of file BesMucSD.cc.

41:BesSensitiveDetector(name),detector(Det)
42{
43 collectionName.insert("BesMucHitsCollection");
44 collectionName.insert("BesMucHitsList");
45 HitID = new G4int[500];
46
47 //liangyt 2006.3.1 initialize muc-efficiency;
48 G4String GeometryPath = ReadBoostRoot::GetBoostRoot();
49 G4String GeometryPath2 = GeometryPath;
50 if(!GeometryPath){
51 G4Exception("BOOST environment not set!");
52 }
53 GeometryPath += "/dat/muc-effi.dat";
54 GeometryPath2 += "/dat/muc-noise.dat";
55
57 // m_effi->Initialize(GeometryPath);
58
59 //retrieve G4Svc
60 ISvcLocator* svcLocator = Gaudi::svcLocator();
61 IG4Svc* iG4Svc;
62 StatusCode sc=svcLocator->service("G4Svc", iG4Svc);
63 m_G4Svc = dynamic_cast<G4Svc *>(iG4Svc);
64 m_noiseMode = m_G4Svc->MucNoiseMode();
65 G4cout << "MucNoiseMode:\t"<<m_noiseMode<<G4endl;
66
67 if( m_noiseMode != 0 )
68 {
69 m_noise=BesMucNoise::Instance();
70 G4LogicalVolume* logicalMuc = detector->GetPhysicalMuc()->GetLogicalVolume();
71 m_noise->Initialize(GeometryPath2,logicalMuc);
72 //m_noise->Initialize(GeometryPath2,logicalMuc,"ROOT");
73 }
74
75 m_PreviousPrimaryTrackG4Id = 0;
76 m_CurEvent = 0;
77 m_TrackCon = 0;
78
79}
G4VPhysicalVolume * GetPhysicalMuc()
static BesMucEfficiency * Instance(void)
static BesMucNoise * Instance(void)
Definition: BesMucNoise.cc:31
void Initialize(G4String filename, G4LogicalVolume *logicalMuc)
Definition: BesMucNoise.cc:84
Definition: G4Svc.h:32
int MucNoiseMode()
Definition: G4Svc.h:133
Definition: IG4Svc.h:30
static G4String GetBoostRoot()

◆ ~BesMucSD()

BesMucSD::~BesMucSD ( )

Definition at line 81 of file BesMucSD.cc.

81 {
82 delete [] HitID;
83}

Member Function Documentation

◆ BeginOfTruthEvent()

void BesMucSD::BeginOfTruthEvent ( const G4Event *  )
virtual

Reimplemented from BesSensitiveDetector.

Definition at line 93 of file BesMucSD.cc.

94{
95 MucHitList = new BesMucHitsCollection(SensitiveDetectorName, collectionName[1]);
96 m_trackIndex = -99;
97 m_trackIndexes.clear();
98 m_prePart = -99;
99 m_preSeg = -99;
100 m_preGap = -99;
101 m_preStrip = -99;
102 //G4cout<<"---in BesMucSD::BeginOfTruthEvent()---"<<MucHitCollection->entries()<<" "<<MucHitList->entries()<<G4endl;
103
104 //add oise
105 if(m_noiseMode != 0) m_noise->AddNoise(m_noiseMode, MucHitCollection, MucHitList); //commen out 2006.10.21
106}
G4THitsCollection< BesMucHit > BesMucHitsCollection
Definition: BesMucHit.hh:104
G4int AddNoise(int model, BesMucHitsCollection *MucHitCollection, BesMucHitsCollection *MucHitList)
Definition: BesMucNoise.cc:220

◆ EndOfEvent()

void BesMucSD::EndOfEvent ( G4HCofThisEvent *  HCE)

Definition at line 348 of file BesMucSD.cc.

349 {
350 static G4int HCID=-1;
351 if(HCID<0)
352 {HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); }
353 HCE->AddHitsCollection(HCID, MucHitCollection);
354 }

◆ EndOfTruthEvent()

void BesMucSD::EndOfTruthEvent ( const G4Event *  evt)
virtual

Reimplemented from BesSensitiveDetector.

Definition at line 108 of file BesMucSD.cc.

109{
110 static G4int HLID=-1;
111 if(HLID<0)
112 HLID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[1]);
113 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
114 HCE->AddHitsCollection(HLID,MucHitList);
115}

◆ Initialize()

void BesMucSD::Initialize ( G4HCofThisEvent *  )

Definition at line 85 of file BesMucSD.cc.

86{
87 MucHitCollection = new BesMucHitsCollection(SensitiveDetectorName, collectionName[0]);
88 // for (G4int j=0;j<detector->GetBesMucNbOfTraps();j++) {HitID[j] = -1;};
89 TotEneDeposit = 0;
90 // G4cout<<"----------in SD::Init()--- "<<detector->GetPhysicalMuc()->GetLogicalVolume()->GetName()<<G4endl;
91}

◆ ProcessHits()

G4bool BesMucSD::ProcessHits ( G4Step *  aStep,
G4TouchableHistory *   
)

Definition at line 117 of file BesMucSD.cc.

118{
119 G4Track *curTrack = aStep->GetTrack();
120
121 m_CurEvent = G4EventManager::GetEventManager()->GetConstCurrentEvent();
122 // if(m_CurEvent->GetEventID()<19565)return true; // ---del
123 if (m_CurEvent) {
124 m_TrackCon = m_CurEvent->GetTrajectoryContainer();
125
126 // if (!m_TrackCon) G4cout << "m_TrackCon does not exist " << G4endl;
127 // else {
128 // G4cout << "m_TrackCon size " << m_TrackCon->size() << G4endl;
129 // for (int i = 0; i < (int)m_TrackCon->size(); i++) {
130 // G4cout << "track " << i << " g4TrackId " << (*m_TrackCon)[i]->GetTrackID() << " parent ID " << (*m_TrackCon)[i]->GetParentID() << G4endl;
131 // }
132 // }
133 }
134
135
136 if (curTrack->GetDefinition()->GetPDGCharge() == 0.) return false;
137
138 G4double edep = aStep->GetTotalEnergyDeposit();
139 //if(edep == 0.) return false;
140
141 //TotEneDeposit+=edep;
142 G4int trackIndex = -99, g4TrackId = -99;
143 GetCurrentTrackIndex(trackIndex, g4TrackId);
144
145 G4TouchableHistory* theTouchable
146 = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
147
148 BesMucHit *newHit = new BesMucHit();
149
150 G4int trackID = curTrack->GetTrackID(); //G4 track ID of current track.
151 G4int parentID = curTrack->GetParentID(); //G4 track ID of parent track.
152 newHit->SetTrackID(trackID);
153 newHit->SetTrackIndex(trackIndex); // MC truth track index
154
155 G4int pdg = curTrack->GetDefinition()->GetPDGEncoding();
156 newHit->SetPDGCode(pdg);
157
158 newHit->SetEdep(edep);
159
160 G4ThreeVector pos = 0.5*( aStep->GetPostStepPoint()->GetPosition()
161 + aStep->GetPreStepPoint()->GetPosition() );
162 newHit->SetPos(pos);
163
164 G4ThreeVector posInGas = theTouchable->GetHistory()->GetTopTransform().TransformPoint(pos);
165 G4int stackDepth = theTouchable->GetHistory()->GetDepth();
166 G4ThreeVector posInBox = theTouchable->GetHistory()->GetTransform(stackDepth-1).TransformPoint(pos);
167 newHit->SetPosLocal(posInBox);
168
169 G4ThreeVector posInGap = theTouchable->GetHistory()->GetTransform(stackDepth-2).TransformPoint(pos);
170 // cout<<" pos "<<pos.x()<<" "<<pos.y()<<" "<<pos.z()<<"depth= "<<stackDepth<<endl
171 // <<" posInBox(3)"<<posInBox.x()<<" "<<posInBox.y()<<" "<<posInBox.z()<<endl
172 // <<" posInGap(2)"<<posInGap.x()<<" "<<posInGap.y()<<" "<<posInGap.z()<<endl;
173
174 G4double energy = aStep->GetPreStepPoint()->GetKineticEnergy();
175 newHit->SetEnergy(energy);
176
177 G4ThreeVector dir = aStep->GetPreStepPoint()->GetMomentumDirection();
178 newHit->SetDir(dir);
179
180 G4ThreeVector momentum = aStep->GetPreStepPoint()->GetMomentum();
181 newHit->SetMomentum(momentum);
182
183 G4double GlobalTime = aStep->GetPostStepPoint()->GetGlobalTime();
184 newHit->SetTime(GlobalTime);
185
186 G4VPhysicalVolume* vl = theTouchable->GetVolume(0);
187 newHit->SetVolume(vl);
188
189 //G4cout<<"in SD "<<newHit->GetPart()<<" "<<newHit->GetSeg()<<" "<<newHit->GetGap()<<" "<<newHit->GetGasChamber()<<" "<<newHit->GetPanel()<<endl;
190
191 newHit->Draw();
192 //newHit->Print();
193 //MucHitCollection->insert(newHit);
194 m_PreviousPrimaryTrackG4Id = g4TrackId;
195
196 //-----------add by liangyt for efficiency
197
198 //for MC Truth
199 if (MucHitList) {
200
201 // cout <<"g4TrackId " << g4TrackId << " trackID " << trackID << " parentID " << parentID << "trackIndex " << trackIndex << endl;
202 // g4TrackId: G4 track ID of previous primary track in trackList,
203 // trackID: G4 track ID of current track.
204 // parentID: G4 track ID of parent track of current track.
205 // trackIndex: track ID in MC truth
206
207 // no longer necessary to find the track's ancestor primary track,
208 // it is kept in trackIndex untill next primary track generated. So IsChildof is uncessary
209 //if ( g4TrackId == trackID ) { //|| IsChildOf(curTrack, g4TrackId) ) { // This track is the primary track & will appear in MC truth
210 G4int newTrackFlag = 0;
211 newHit->SetTrackIndex(trackIndex);
212 if(m_trackIndex != trackIndex) {
213 m_trackIndex = trackIndex;
214 G4int size = m_trackIndexes.size();
215 newTrackFlag = 1;
216 if (size > 0) {
217 for(G4int i=0;i<size;i++)
218 if(m_trackIndexes[i] == trackIndex ) {
219 newTrackFlag = 0;
220 break;
221 }
222 }
223 }
224
225 if (newTrackFlag) {
226 m_trackIndexes.push_back(trackIndex);
227 m_prePart = -99;
228 m_preSeg = -99;
229 m_preGap = -99;
230 m_preStrip = -99;
231 }
232 BesMucHit* truHit = new BesMucHit();
233 *truHit = *newHit;
234 if (g4TrackId != trackID) {
235 // trackIndex += 1000; // a sencondary track
236 trackIndex += 0; //2006.12.22 do not indicate secondary track now
237 truHit->SetTrackIndex(trackIndex);
238 }
239 //cout << "trackIndex " << trackIndex << endl;
240
241 BesMucDigit aDigit;
242 aDigit.SetHit(truHit);
243 G4int curPart, curSeg, curGap, curStrip;
244 curPart = aDigit.GetPart();
245 curSeg = aDigit.GetSeg();
246 curGap = aDigit.GetGap();
247 curStrip = aDigit.GetNearestStripNo();
248
249 m_effi->CheckCalibSvc();
250 m_effi->SetHit(truHit);
251 G4double need_eff = m_effi->GetEfficiency();
252
253 //G4cout<<"in SD effi= "<<need_eff<<endl;
254 //need_eff = 1.0; //2006.12.28
255 if (curPart == m_prePart && curSeg == m_preSeg &&
256 curGap == m_preGap && curStrip == m_preStrip) {
257 //cout<<MucHitList->entries()<<" "<<MucHitCollection->entries()<<" "<<need_eff<<"---if----curPart "<<curPart<<"curSeg "<<curSeg<<"curGap "<<curGap<<"curStrip "<<curStrip<<" momentum "<<momentum.x()<<" "<<momentum.y()<<" "<<momentum.z()<<" "<<endl;
258 delete truHit;delete newHit;
259 }
260 else {
261 //cout<<MucHitList->entries()<<"----else--Part "<<curPart<<" Seg "<<curSeg<<" Gap "<<curGap<<" Strip "<<curStrip<<endl;
262 truHit->SetPart(curPart);
263 truHit->SetSeg(curSeg);
264 truHit->SetGap(curGap);
265 truHit->SetStrip(curStrip);
266
267 // if a truHit with the same id(part, seg, gap, strip) and trackIndex(%1000) exist,
268 // they belong to the same primary track,(maybe one is primary, the other is secondary), dont add.
269 bool truHitExist = false;
270 G4int n_hit = MucHitList->entries();
271 for(G4int iTru=0;iTru<n_hit;iTru++) {
272 BesMucHit* aTruHit = (*MucHitList)[iTru];
273 if ( aTruHit->GetTrackIndex()%1000 == truHit->GetTrackIndex()%1000 &&
274 aTruHit->GetPart() == truHit->GetPart() &&
275 aTruHit->GetSeg() == truHit->GetSeg() &&
276 aTruHit->GetGap() == truHit->GetGap() &&
277 aTruHit->GetStrip() == truHit->GetStrip() )
278 {
279 truHitExist = true;
280 break;
281 }
282 }
283 G4float random=G4UniformRand(); //*** use other random
284 // G4float random=(rand()%100000)/100000.0;
285 // G4cout<<"---in SD---"<<random<<endl;
286 if (random<=need_eff){ MucHitCollection->insert(newHit);}
287 else delete newHit;
288 if (!truHitExist&&random<=need_eff)
289 { MucHitList->insert(truHit);}
290 else delete truHit;
291 m_prePart = curPart;
292 m_preSeg = curSeg;
293 m_preGap = curGap;
294 m_preStrip = curStrip;
295 }
296 //}
297 }
298
299 return true;
300 }
**********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
************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
Definition: KK2f.h:50
G4int GetGap()
Definition: BesMucDigit.hh:40
G4int GetPart()
Definition: BesMucDigit.hh:38
G4int GetNearestStripNo()
Definition: BesMucDigit.cc:63
G4int GetSeg()
Definition: BesMucDigit.hh:39
void SetHit(BesMucHit *hit)
Definition: BesMucDigit.cc:29
void SetHit(BesMucHit *hit)
G4double GetEfficiency()
void SetPos(G4ThreeVector xyz)
Definition: BesMucHit.hh:51
G4int GetTrackIndex()
Definition: BesMucHit.hh:63
void SetGap(G4int gap)
Definition: BesMucHit.hh:58
void SetTime(G4double t)
Definition: BesMucHit.hh:50
void SetPosLocal(G4ThreeVector xyzLocal)
Definition: BesMucHit.hh:52
G4int GetSeg()
Definition: BesMucHit.hh:75
void SetVolume(G4VPhysicalVolume *pv)
Definition: BesMucHit.cc:92
void SetPart(G4int part)
Definition: BesMucHit.hh:56
void SetDir(G4ThreeVector dir)
Definition: BesMucHit.hh:53
G4int GetStrip()
Definition: BesMucHit.hh:77
G4int GetPart()
Definition: BesMucHit.hh:74
void SetSeg(G4int seg)
Definition: BesMucHit.hh:57
void Draw()
Definition: BesMucHit.cc:139
void SetPDGCode(G4int pdg)
Definition: BesMucHit.hh:47
void SetEnergy(G4double energy)
Definition: BesMucHit.hh:49
void SetTrackID(G4int track)
Definition: BesMucHit.hh:45
void SetEdep(G4double de)
Definition: BesMucHit.hh:48
void SetStrip(G4int strip)
Definition: BesMucHit.hh:59
void SetMomentum(G4ThreeVector momentum)
Definition: BesMucHit.hh:54
void SetTrackIndex(G4int index)
Definition: BesMucHit.hh:46
G4int GetGap()
Definition: BesMucHit.hh:76
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const

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