BOSS 7.1.1
BESIII Offline Software System
Loading...
Searching...
No Matches
BesEmcSD Class Reference

#include <BesEmcSD.hh>

+ Inheritance diagram for BesEmcSD:

Public Member Functions

 BesEmcSD (G4String, BesEmcConstruction *, BesEmcGeometry *)
 
 ~BesEmcSD ()
 
void Initialize (G4HCofThisEvent *)
 
G4bool ProcessHits (G4Step *, G4TouchableHistory *)
 
void EndOfEvent (G4HCofThisEvent *)
 
void clear ()
 
void DrawAll ()
 
void PrintAll ()
 
void BeginOfTruthEvent (const G4Event *)
 
void EndOfTruthEvent (const G4Event *)
 
void ComputeThetaPhi (G4int, G4int, G4int)
 
G4int EndPhiNumberForGDML (G4int)
 
G4int ComputeEndCopyNb (G4int)
 
- Public Member Functions inherited from BesSensitiveDetector
 BesSensitiveDetector (const G4String name)
 
virtual ~BesSensitiveDetector ()
 
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 27 of file BesEmcSD.hh.

Constructor & Destructor Documentation

◆ BesEmcSD()

BesEmcSD::BesEmcSD ( G4String name,
BesEmcConstruction * det,
BesEmcGeometry * besEMCGeometry )

Definition at line 32 of file BesEmcSD.cc.

36 ,Detector(det),fBesEmcGeometry(besEMCGeometry)
37{
38 collectionName.insert("BesEmcHitsCollection"); //for digitization
39 collectionName.insert("BesEmcHitsList"); //for MC truth
40 collectionName.insert("BesEmcTruthHitsList");
41 HitID = new G4int[40000];
42}
BesSensitiveDetector(const G4String name)

◆ ~BesEmcSD()

BesEmcSD::~BesEmcSD ( )

Definition at line 46 of file BesEmcSD.cc.

47{
48 delete [] HitID;
49}

Member Function Documentation

◆ BeginOfTruthEvent()

void BesEmcSD::BeginOfTruthEvent ( const G4Event * )
virtual

Reimplemented from BesSensitiveDetector.

Definition at line 64 of file BesEmcSD.cc.

65{
66 CalList = new BesEmcHitsCollection
67 (SensitiveDetectorName,collectionName[1]);
68 CalTruthList = new BesEmcTruthHitsCollection
69 (SensitiveDetectorName,collectionName[2]);
70 m_trackIndex = -99;
71}
G4THitsCollection< BesEmcTruthHit > BesEmcTruthHitsCollection
Definition BesEmcHit.hh:181
G4THitsCollection< BesEmcHit > BesEmcHitsCollection
Definition BesEmcHit.hh:83

◆ clear()

void BesEmcSD::clear ( )

Definition at line 490 of file BesEmcSD.cc.

491{}

◆ ComputeEndCopyNb()

G4int BesEmcSD::ComputeEndCopyNb ( G4int num)

Definition at line 452 of file BesEmcSD.cc.

453{
454 G4int copyNb;
455 switch(num){
456 case 30:
457 copyNb = 5;
458 break;
459 case 31:
460 copyNb = 6;
461 break;
462 case 32:
463 copyNb = 14;
464 break;
465 case 33:
466 copyNb = 15;
467 break;
468 case 34:
469 copyNb = 16;
470 break;
471 default:
472 copyNb = num;
473 break;
474 }
475 return copyNb;
476}

Referenced by ProcessHits().

◆ ComputeThetaPhi()

void BesEmcSD::ComputeThetaPhi ( G4int id,
G4int sector,
G4int nb )

Definition at line 317 of file BesEmcSD.cc.

318{
319 if((sector>=0)&&(sector<3))
320 sector+=16;
321 //if((sector!=7)&&(sector!=15))
322 {
323 if((nb>=0)&&(nb<4))
324 {
325 CryNumberTheta = 0;
326 CryNumberPhi = (sector-3)*4+nb;
327 }
328 else if((nb>=4)&&(nb<8))
329 {
330 CryNumberTheta = 1;
331 CryNumberPhi = (sector-3)*4+nb-4;
332 }
333 else if((nb>=8)&&(nb<13))
334 {
335 CryNumberTheta = 2;
336 CryNumberPhi = (sector-3)*5+nb-8;
337 }
338 else if((nb>=13)&&(nb<18))
339 {
340 CryNumberTheta = 3;
341 CryNumberPhi = (sector-3)*5+nb-13;
342 }
343 else if((nb>=18)&&(nb<24))
344 {
345 CryNumberTheta = 4;
346 CryNumberPhi = (sector-3)*6+nb-18;
347 }
348 else if((nb>=24)&&(nb<30))
349 {
350 CryNumberTheta = 5;
351 CryNumberPhi = (sector-3)*6+nb-24;
352 }
353 }
354 /*else// if((sector=7)||(sector==15))
355 {
356 if((nb>=0)&&(nb<4))
357 {
358 CryNumberTheta = 0;
359 CryNumberPhi = (sector-3)*4+3-nb;
360 }
361 else if((nb>=4)&&(nb<8))
362 {
363 CryNumberTheta = 1;
364 CryNumberPhi = (sector-3)*4+7-nb;
365 }
366 else if((nb>=8)&&(nb<13))
367 {
368 CryNumberTheta = 2;
369 CryNumberPhi = (sector-3)*5+12-nb;
370 }
371 else if((nb>=13)&&(nb<18))
372 {
373 CryNumberTheta = 3;
374 CryNumberPhi = (sector-3)*5+17-nb;
375 }
376 else if((nb>=18)&&(nb<24))
377 {
378 CryNumberTheta = 4;
379 CryNumberPhi = (sector-3)*6+23-nb;
380 }
381 else if((nb>=24)&&(nb<30))
382 {
383 CryNumberTheta = 5;
384 CryNumberPhi = (sector-3)*6+29-nb;
385 }
386 }*/
387
388 if(id==2)
389 {
390 switch(CryNumberTheta)
391 {
392 case 0:
393 if(CryNumberPhi<32)
394 CryNumberPhi = 31-CryNumberPhi;
395 else
396 CryNumberPhi = 95-CryNumberPhi;
397 break;
398 case 1:
399 if(CryNumberPhi<32)
400 CryNumberPhi = 31-CryNumberPhi;
401 else
402 CryNumberPhi = 95-CryNumberPhi;
403 break;
404 case 2:
405 if(CryNumberPhi<40)
406 CryNumberPhi = 39-CryNumberPhi;
407 else
408 CryNumberPhi = 119-CryNumberPhi;
409 break;
410 case 3:
411 if(CryNumberPhi<40)
412 CryNumberPhi = 39-CryNumberPhi;
413 else
414 CryNumberPhi = 119-CryNumberPhi;
415 break;
416 case 4:
417 if(CryNumberPhi<48)
418 CryNumberPhi = 47-CryNumberPhi;
419 else
420 CryNumberPhi = 143-CryNumberPhi;
421 break;
422 case 5:
423 if(CryNumberPhi<48)
424 CryNumberPhi = 47-CryNumberPhi;
425 else
426 CryNumberPhi = 143-CryNumberPhi;
427 default:
428 ;
429 }
430 }
431}

Referenced by ProcessHits().

◆ DrawAll()

void BesEmcSD::DrawAll ( )

Definition at line 495 of file BesEmcSD.cc.

496{}

◆ EndOfEvent()

void BesEmcSD::EndOfEvent ( G4HCofThisEvent * HCE)

Definition at line 480 of file BesEmcSD.cc.

481{
482 static G4int HCID = -1;
483 if(HCID<0)
484 { HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); }
485 HCE->AddHitsCollection(HCID,CalCollection);
486}

◆ EndOfTruthEvent()

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

Reimplemented from BesSensitiveDetector.

Definition at line 73 of file BesEmcSD.cc.

74{
75 static G4int HLID=-1;
76 if(HLID<0)
77 HLID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[1]);
78 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
79 HCE->AddHitsCollection(HLID,CalList);
80
81 static G4int HTID=-1;
82 if(HTID<0)
83 HTID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[2]);
84 HCE->AddHitsCollection(HTID,CalTruthList);
85}

◆ EndPhiNumberForGDML()

G4int BesEmcSD::EndPhiNumberForGDML ( G4int copyNb)

Definition at line 433 of file BesEmcSD.cc.

434{
435 if(copyNb<0||copyNb>15) {
436 //G4Exception("Wrong copy number of EMC Endcap Phi Volume!");
437 G4cout<<"Wrong copy number of EMC Endcap Phi Volume!"<<G4endl;
438 exit(-1);
439 }
440
441 if(copyNb==0||copyNb==1) {
442 return 15-copyNb*8;
443 } else if(copyNb==2||copyNb==3) {
444 return 30-copyNb*8;
445 } else if(copyNb<=9) {
446 return 17-copyNb;
447 } else {
448 return 15-copyNb;
449 }
450}

Referenced by ProcessHits().

◆ Initialize()

void BesEmcSD::Initialize ( G4HCofThisEvent * )

Definition at line 53 of file BesEmcSD.cc.

54{
55 CalCollection = new BesEmcHitsCollection
56 (SensitiveDetectorName,collectionName[0]);
57 for (G4int j=0;j<40000;j++)
58 {
59 HitID[j] = -1;
60 }
61 nHit=0;
62}

◆ PrintAll()

void BesEmcSD::PrintAll ( )

Definition at line 500 of file BesEmcSD.cc.

501{}

◆ ProcessHits()

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

Definition at line 88 of file BesEmcSD.cc.

89{
90
91//Ma Qiumei Add for removing Warning Infomations
92 gErrorIgnoreLevel = kFatal;
93
94 G4double edep = aStep->GetTotalEnergyDeposit();
95 G4double stepl = aStep->GetStepLength();
96 if ((edep==0.)&&(stepl==0.)) return false;
97
98 G4TouchableHistory* theTouchable
99 = (G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable());
100 G4VPhysicalVolume* physVol = theTouchable->GetVolume();
101
102 if(physVol->GetName().contains("physicalCrystal")) //barrel code
103 {
104 PartId=1;
105 CryNumberPhi=theTouchable->GetReplicaNumber(2);
106 CryNumberTheta=theTouchable->GetReplicaNumber(1);
107 }
108 else if(physVol->GetName().contains("logicalCrystal")) //barrel gdml
109 {
110 PartId=1;
111 std::istringstream thetaBuf((theTouchable->GetVolume(1)->GetName()).substr(16,2));
112 thetaBuf >> CryNumberTheta ;
113 CryNumberPhi = 308-theTouchable->GetCopyNumber(2);
114 }
115 else if(physVol->GetName().contains("physicalEndCrystal")) //endcap code
116 {
117 PartId=theTouchable->GetReplicaNumber(3);
118 G4int endSector=theTouchable->GetReplicaNumber(2);
119 G4int endNb=theTouchable->GetReplicaNumber(0);
120 ComputeThetaPhi(PartId,endSector,ComputeEndCopyNb(endNb));
121 }
122 else if(physVol->GetName().contains("logicalEndCrystal")) //endcap gdml
123 {
124 PartId=2-2*theTouchable->GetCopyNumber(3);
125 G4int endSector=theTouchable->GetCopyNumber(2);
126 G4int endNb,endNbGDML;
127 std::istringstream thetaBuf((theTouchable->GetVolume(0)->GetName()).substr(20,2));
128 thetaBuf >> endNb ;
129 endNbGDML=ComputeEndCopyNb(endNb);
130 G4int endSectorGDML=EndPhiNumberForGDML(endSector);
131 ComputeThetaPhi(PartId,endSectorGDML,endNbGDML);
132 }
133 else if(physVol->GetName().contains("physicalPD")) //barrel PD code
134 {
135 edep*=50.;
136 PartId=1;
137 CryNumberPhi=theTouchable->GetReplicaNumber(2);
138 CryNumberTheta=theTouchable->GetReplicaNumber(1);
139 }
140 else if(physVol->GetName().contains("logicalPD")) //barrel PD gdml
141 {
142 edep*=50.;
143 PartId=1;
144 G4int nb=theTouchable->GetCopyNumber(1);
145 if(nb==216) {
146 CryNumberTheta=0;
147 } else {
148 CryNumberTheta = 43-(nb-2)/5;
149 }
150 CryNumberPhi = 308-theTouchable->GetCopyNumber(2);
151 }
152
153 if (verboseLevel>1)
154 G4cout << "(Check ID)New EMC Hit on crystal: "
155 << CryNumberPhi << "(phi)"
156 << CryNumberTheta << "(theta)"
157 << " and the volume is " << physVol->GetName()
158 << G4endl;
159
160 //-----------------------------------------------------
161 G4int trackId = aStep->GetTrack()->GetTrackID();
162
163 BesEmcHit* calHit = new BesEmcHit();
164 calHit->SetTrackIndex(-99);
165 calHit->SetG4Index(trackId);
166 calHit->SetEdepCrystal(edep);
167 calHit->SetTrakCrystal(stepl);
168 calHit->SetPosCrystal(aStep->GetPreStepPoint()->GetPosition());
169 calHit->SetTimeCrystal(aStep->GetPreStepPoint()->GetGlobalTime());
170 calHit->SetMomentum(aStep->GetPreStepPoint()->GetMomentum());
171 calHit->SetNumCrystal(PartId,CryNumberTheta,CryNumberPhi);
172 //calHit->Print(1);
173 if(edep>0){
174 G4int idhit = CalCollection->insert(calHit)-1;
175 if(nHit<40000) HitID[nHit]=idhit;
176 nHit++;
177 }
178 else
179 {
180 delete calHit;
181 //if(nHit==40000)
182 //G4cout << "Hits number exceed store space!!!" << G4endl;
183 }
184
185 //for MC Truth
186 if(CalList)
187 {
188 G4int trackIndex, g4TrackId;
189 GetCurrentTrackIndex(trackIndex, g4TrackId);
190 calHit->SetTrackIndex(trackIndex);
191
192 if(m_trackIndex != trackIndex) //find a new track
193 {
194 m_trackIndex = trackIndex;
195
196 G4int flag=1;
197 G4int pdg = abs(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
198 if(pdg==12 || pdg==14 || pdg==16) { //neutrino
199 flag=0;
200 }
201
202 if(flag && aStep->GetTrack()->GetTrackID()==g4TrackId ) //is primary particle
203 {
204 BesEmcHit* truHit = new BesEmcHit();
205 truHit->SetTrackIndex(trackIndex);
206 truHit->SetG4Index(trackId);
207 truHit->SetEdepCrystal(edep);
208 truHit->SetTrakCrystal(stepl);
209 truHit->SetPosCrystal(aStep->GetPreStepPoint()->GetPosition());
210 truHit->SetTimeCrystal(aStep->GetPreStepPoint()->GetGlobalTime());
211 truHit->SetMomentum(aStep->GetPreStepPoint()->GetMomentum());
212 truHit->SetNumCrystal(PartId,CryNumberTheta,CryNumberPhi);
213 CalList->insert(truHit);
214 }
215 }
216
217 else if(m_trackIndex == trackIndex)
218 {
219 G4int length = CalList->entries();
220 if(length>=1)
221 {
222 for(G4int i=0;i<length;i++)
223 {
224 BesEmcHit* oldHit =(*CalList)[i];
225 if(oldHit->GetTrackIndex()==trackIndex) //find the same trackIndex in CalList
226 {
227 oldHit->SetEdepCrystal(oldHit->GetEdepCrystal() +edep);
228 break;
229 }
230 }
231 }
232 }
233
234 }
235
236 //for full Mc Truth
237 if(CalTruthList)
238 {
239 G4int trackIndex, g4TrackId;
240 GetCurrentTrackIndex(trackIndex, g4TrackId);
241 Identifier id = EmcID::crystal_id(PartId,CryNumberTheta,CryNumberPhi);
242
243 G4int flag=1;
244 if(CalTruthList->entries()>0) {
245 for(G4int i=0;i<CalTruthList->entries();i++) {
246 BesEmcTruthHit* oldHit=(*CalTruthList)[i];
247 if(oldHit->GetTrackIndex()==trackIndex) { //find the same trackIndex in CalList
248 flag=0;
249 oldHit->SetEDep(oldHit->GetEDep()+edep); //total energy
250 if(oldHit->Find(id)!=oldHit->End()) {
251 oldHit->AddEHit(id,edep);
252 } else {
253 oldHit->Insert(id,edep);
254 }
255 break;
256 }
257 }
258 }
259
260 if(flag==1) { //new track
261 G4int pdg = abs(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
262 if(!(pdg==12 || pdg==14 || pdg==16)) { //not neutrino
263 BesEmcTruthHit* truHit=new BesEmcTruthHit;
264 truHit->SetTrackIndex(trackIndex);
265 truHit->SetG4TrackId(g4TrackId);
266 truHit->SetEDep(edep);
267 truHit->SetIdentify(id);
268 truHit->Insert(id,edep);
269
270 if(aStep->GetTrack()->GetTrackID()==g4TrackId) { //is primary particle
271 truHit->SetHitEmc(1);
272 truHit->SetPDGCode(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
273 truHit->SetPDGCharge(aStep->GetTrack()->GetDefinition()->GetPDGCharge());
274 truHit->SetParticleName(aStep->GetTrack()->GetDefinition()->GetParticleName());
275 truHit->SetTime(aStep->GetPreStepPoint()->GetGlobalTime());
276 truHit->SetPosition(aStep->GetPreStepPoint()->GetPosition());
277 truHit->SetMomentum(aStep->GetPreStepPoint()->GetMomentum());
278
279 } else { // the primary particle doesn't hit emc
280
282 std::vector<BesTruthTrack*> *trackList = sensitiveManager->GetTrackList();
283
284 for(unsigned i=0;i<trackList->size();i++) {
285 BesTruthTrack *truthTrack=(*trackList)[i];
286
287 if(trackIndex==truthTrack->GetIndex()) { //find primary particle
288 truHit->SetHitEmc(0);
289 truHit->SetPDGCode(truthTrack->GetPDGCode());
290 truHit->SetPDGCharge(truthTrack->GetPDGCharge());
291 truHit->SetParticleName(truthTrack->GetParticleName());
292
293 if(truthTrack->GetTerminalVertex()) {
294 truHit->SetTime(truthTrack->GetTerminalVertex()->GetTime());
295 truHit->SetPosition(truthTrack->GetTerminalVertex()->GetPosition());
296 } else { //have not found terminal vertex
297 truHit->SetTime(-99);
298 truHit->SetPosition(G4ThreeVector(-99,-99,-99));
299 }
300
301 break;
302 } //end if find primary particle
303
304 }
305 }
306
307 CalTruthList->insert(truHit);
308 }
309 }
310 }
311
312 return true;
313}
void SetNumCrystal(G4int id, G4int numTheta, G4int numPhi)
Definition BesEmcHit.hh:49
void SetEdepCrystal(G4double de)
Definition BesEmcHit.hh:44
void SetMomentum(G4ThreeVector momen)
Definition BesEmcHit.hh:52
G4double GetEdepCrystal()
Definition BesEmcHit.hh:56
G4int GetTrackIndex()
Definition BesEmcHit.hh:64
void SetPosCrystal(G4ThreeVector position)
Definition BesEmcHit.hh:47
void SetTimeCrystal(G4double t)
Definition BesEmcHit.hh:48
void SetTrakCrystal(G4double dl)
Definition BesEmcHit.hh:46
void SetG4Index(G4int index)
Definition BesEmcHit.hh:51
void SetTrackIndex(G4int index)
Definition BesEmcHit.hh:50
G4int ComputeEndCopyNb(G4int)
Definition BesEmcSD.cc:452
void ComputeThetaPhi(G4int, G4int, G4int)
Definition BesEmcSD.cc:317
G4int EndPhiNumberForGDML(G4int)
Definition BesEmcSD.cc:433
void SetIdentify(Identifier id)
Definition BesEmcHit.hh:123
G4int GetTrackIndex() const
Definition BesEmcHit.hh:136
void SetHitEmc(G4int is)
Definition BesEmcHit.hh:126
void SetMomentum(G4ThreeVector p)
Definition BesEmcHit.hh:132
void SetPosition(G4ThreeVector pos)
Definition BesEmcHit.hh:133
void AddEHit(Identifier, G4double)
Definition BesEmcHit.cc:197
void SetPDGCode(G4int code)
Definition BesEmcHit.hh:127
void SetTrackIndex(G4int index)
Definition BesEmcHit.hh:124
std::map< Identifier, G4double >::const_iterator End() const
Definition BesEmcHit.cc:182
std::map< Identifier, G4double >::const_iterator Find(Identifier) const
Definition BesEmcHit.cc:187
void Insert(Identifier, G4double)
Definition BesEmcHit.cc:202
void SetG4TrackId(G4int trackId)
Definition BesEmcHit.hh:125
G4double GetEDep() const
Definition BesEmcHit.hh:142
void SetEDep(G4double de)
Definition BesEmcHit.hh:130
void SetParticleName(G4String name)
Definition BesEmcHit.hh:129
void SetTime(G4double time)
Definition BesEmcHit.hh:131
void SetPDGCharge(G4double charge)
Definition BesEmcHit.hh:128
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
std::vector< BesTruthTrack * > * GetTrackList()
static BesSensitiveManager * GetSensitiveManager()
G4int GetPDGCode() const
BesTruthVertex * GetTerminalVertex() const
G4double GetPDGCharge() const
G4int GetIndex() const
G4String GetParticleName() const
G4double GetTime() const
G4ThreeVector GetPosition() const
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.
Definition EmcID.cxx:71

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