BOSS 7.0.9
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 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 27 of file BesEmcSD.hh.

Constructor & Destructor Documentation

◆ BesEmcSD()

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

Definition at line 29 of file BesEmcSD.cc.

33 ,Detector(det),fBesEmcGeometry(besEMCGeometry)
34{
35 collectionName.insert("BesEmcHitsCollection"); //for digitization
36 collectionName.insert("BesEmcHitsList"); //for MC truth
37 collectionName.insert("BesEmcTruthHitsList");
38 HitID = new G4int[40000];
39}

◆ ~BesEmcSD()

BesEmcSD::~BesEmcSD ( )

Definition at line 43 of file BesEmcSD.cc.

44{
45 delete [] HitID;
46}

Member Function Documentation

◆ BeginOfTruthEvent()

void BesEmcSD::BeginOfTruthEvent ( const G4Event *  )
virtual

Reimplemented from BesSensitiveDetector.

Definition at line 61 of file BesEmcSD.cc.

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

◆ clear()

void BesEmcSD::clear ( )

Definition at line 482 of file BesEmcSD.cc.

483{}

◆ ComputeEndCopyNb()

G4int BesEmcSD::ComputeEndCopyNb ( G4int  num)

Definition at line 444 of file BesEmcSD.cc.

445{
446 G4int copyNb;
447 switch(num){
448 case 30:
449 copyNb = 5;
450 break;
451 case 31:
452 copyNb = 6;
453 break;
454 case 32:
455 copyNb = 14;
456 break;
457 case 33:
458 copyNb = 15;
459 break;
460 case 34:
461 copyNb = 16;
462 break;
463 default:
464 copyNb = num;
465 break;
466 }
467 return copyNb;
468}

Referenced by ProcessHits().

◆ ComputeThetaPhi()

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

Definition at line 311 of file BesEmcSD.cc.

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

Referenced by ProcessHits().

◆ DrawAll()

void BesEmcSD::DrawAll ( )

Definition at line 487 of file BesEmcSD.cc.

488{}

◆ EndOfEvent()

void BesEmcSD::EndOfEvent ( G4HCofThisEvent *  HCE)

Definition at line 472 of file BesEmcSD.cc.

473{
474 static G4int HCID = -1;
475 if(HCID<0)
476 { HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); }
477 HCE->AddHitsCollection(HCID,CalCollection);
478}

◆ EndOfTruthEvent()

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

Reimplemented from BesSensitiveDetector.

Definition at line 70 of file BesEmcSD.cc.

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

◆ EndPhiNumberForGDML()

G4int BesEmcSD::EndPhiNumberForGDML ( G4int  copyNb)

Definition at line 427 of file BesEmcSD.cc.

428{
429 if(copyNb<0||copyNb>15) {
430 G4Exception("Wrong copy number of EMC Endcap Phi Volume!");
431 }
432
433 if(copyNb==0||copyNb==1) {
434 return 15-copyNb*8;
435 } else if(copyNb==2||copyNb==3) {
436 return 30-copyNb*8;
437 } else if(copyNb<=9) {
438 return 17-copyNb;
439 } else {
440 return 15-copyNb;
441 }
442}

Referenced by ProcessHits().

◆ Initialize()

void BesEmcSD::Initialize ( G4HCofThisEvent *  )

Definition at line 50 of file BesEmcSD.cc.

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

◆ PrintAll()

void BesEmcSD::PrintAll ( )

Definition at line 492 of file BesEmcSD.cc.

493{}

◆ ProcessHits()

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

Definition at line 85 of file BesEmcSD.cc.

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