BOSS 7.0.5
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)
 
 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 *)
 
 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
 
void GetCurrentTrackIndex (G4int &trackIndex, G4int &g4TrackId) const
 

Detailed Description

Constructor & Destructor Documentation

◆ BesEmcSD() [1/2]

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[20000];
39}

◆ ~BesEmcSD() [1/2]

BesEmcSD::~BesEmcSD ( )

Definition at line 43 of file BesEmcSD.cc.

44{
45 delete [] HitID;
46}

◆ BesEmcSD() [2/2]

BesEmcSD::BesEmcSD ( G4String  ,
BesEmcConstruction ,
BesEmcGeometry  
)

◆ ~BesEmcSD() [2/2]

BesEmcSD::~BesEmcSD ( )

Member Function Documentation

◆ BeginOfTruthEvent() [1/2]

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
G4THitsCollection< BesEmcHit > BesEmcHitsCollection

◆ BeginOfTruthEvent() [2/2]

void BesEmcSD::BeginOfTruthEvent ( const G4Event *  )
virtual

Reimplemented from BesSensitiveDetector.

◆ clear() [1/2]

void BesEmcSD::clear ( )

Definition at line 480 of file BesEmcSD.cc.

481{}

◆ clear() [2/2]

void BesEmcSD::clear ( )

◆ ComputeEndCopyNb() [1/2]

G4int BesEmcSD::ComputeEndCopyNb ( G4int  num)

Definition at line 442 of file BesEmcSD.cc.

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

Referenced by ProcessHits().

◆ ComputeEndCopyNb() [2/2]

G4int BesEmcSD::ComputeEndCopyNb ( G4int  )

◆ ComputeThetaPhi() [1/2]

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

Definition at line 309 of file BesEmcSD.cc.

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

Referenced by ProcessHits().

◆ ComputeThetaPhi() [2/2]

void BesEmcSD::ComputeThetaPhi ( G4int  ,
G4int  ,
G4int   
)

◆ DrawAll() [1/2]

void BesEmcSD::DrawAll ( )

Definition at line 485 of file BesEmcSD.cc.

486{}

◆ DrawAll() [2/2]

void BesEmcSD::DrawAll ( )

◆ EndOfEvent() [1/2]

void BesEmcSD::EndOfEvent ( G4HCofThisEvent *  HCE)

Definition at line 470 of file BesEmcSD.cc.

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

◆ EndOfEvent() [2/2]

void BesEmcSD::EndOfEvent ( G4HCofThisEvent *  )

◆ EndOfTruthEvent() [1/2]

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}

◆ EndOfTruthEvent() [2/2]

void BesEmcSD::EndOfTruthEvent ( const G4Event *  )
virtual

Reimplemented from BesSensitiveDetector.

◆ EndPhiNumberForGDML() [1/2]

G4int BesEmcSD::EndPhiNumberForGDML ( G4int  copyNb)

Definition at line 425 of file BesEmcSD.cc.

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

Referenced by ProcessHits().

◆ EndPhiNumberForGDML() [2/2]

G4int BesEmcSD::EndPhiNumberForGDML ( G4int  )

◆ Initialize() [1/2]

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<20000;j++)
55 {
56 HitID[j] = -1;
57 }
58 nHit=0;
59}

◆ Initialize() [2/2]

void BesEmcSD::Initialize ( G4HCofThisEvent *  )

◆ PrintAll() [1/2]

void BesEmcSD::PrintAll ( )

Definition at line 490 of file BesEmcSD.cc.

491{}

◆ PrintAll() [2/2]

void BesEmcSD::PrintAll ( )

◆ ProcessHits() [1/2]

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&&nHit<20000)
168 HitID[nHit]=CalCollection->insert(calHit)-1;
169 else
170 {
171 delete calHit;
172 //if(nHit==20000)
173 //G4cout << "Hits number exceed store space!!!" << G4endl;
174 }
175 nHit++;
176
177 //for MC Truth
178 if(CalList)
179 {
180 G4int trackIndex, g4TrackId;
181 GetCurrentTrackIndex(trackIndex, g4TrackId);
182 calHit->SetTrackIndex(trackIndex);
183
184 if(m_trackIndex != trackIndex) //find a new track
185 {
186 m_trackIndex = trackIndex;
187
188 G4int flag=1;
189 G4int pdg = abs(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
190 if(pdg==12 || pdg==14 || pdg==16) { //neutrino
191 flag=0;
192 }
193
194 if(flag && aStep->GetTrack()->GetTrackID()==g4TrackId ) //is primary particle
195 {
196 BesEmcHit* truHit = new BesEmcHit();
197 truHit->SetTrackIndex(trackIndex);
198 truHit->SetG4Index(trackId);
199 truHit->SetEdepCrystal(edep);
200 truHit->SetTrakCrystal(stepl);
201 truHit->SetPosCrystal(aStep->GetPreStepPoint()->GetPosition());
202 truHit->SetTimeCrystal(aStep->GetPreStepPoint()->GetGlobalTime());
203 truHit->SetMomentum(aStep->GetPreStepPoint()->GetMomentum());
204 truHit->SetNumCrystal(PartId,CryNumberTheta,CryNumberPhi);
205 CalList->insert(truHit);
206 }
207 }
208
209 else if(m_trackIndex == trackIndex)
210 {
211 G4int length = CalList->entries();
212 if(length>=1)
213 {
214 for(G4int i=0;i<length;i++)
215 {
216 BesEmcHit* oldHit =(*CalList)[i];
217 if(oldHit->GetTrackIndex()==trackIndex) //find the same trackIndex in CalList
218 {
219 oldHit->SetEdepCrystal(oldHit->GetEdepCrystal() +edep);
220 break;
221 }
222 }
223 }
224 }
225
226 }
227
228 //for full Mc Truth
229 if(CalTruthList)
230 {
231 G4int trackIndex, g4TrackId;
232 GetCurrentTrackIndex(trackIndex, g4TrackId);
233 Identifier id = EmcID::crystal_id(PartId,CryNumberTheta,CryNumberPhi);
234
235 G4int flag=1;
236 if(CalTruthList->entries()>0) {
237 for(G4int i=0;i<CalTruthList->entries();i++) {
238 BesEmcTruthHit* oldHit=(*CalTruthList)[i];
239 if(oldHit->GetTrackIndex()==trackIndex) { //find the same trackIndex in CalList
240 flag=0;
241 oldHit->SetEDep(oldHit->GetEDep()+edep); //total energy
242 if(oldHit->Find(id)!=oldHit->End()) {
243 oldHit->AddEHit(id,edep);
244 } else {
245 oldHit->Insert(id,edep);
246 }
247 break;
248 }
249 }
250 }
251
252 if(flag==1) { //new track
253 G4int pdg = abs(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
254 if(!(pdg==12 || pdg==14 || pdg==16)) { //not neutrino
255 BesEmcTruthHit* truHit=new BesEmcTruthHit;
256 truHit->SetTrackIndex(trackIndex);
257 truHit->SetG4TrackId(g4TrackId);
258 truHit->SetEDep(edep);
259 truHit->SetIdentify(id);
260 truHit->Insert(id,edep);
261
262 if(aStep->GetTrack()->GetTrackID()==g4TrackId) { //is primary particle
263 truHit->SetHitEmc(1);
264 truHit->SetPDGCode(aStep->GetTrack()->GetDefinition()->GetPDGEncoding());
265 truHit->SetPDGCharge(aStep->GetTrack()->GetDefinition()->GetPDGCharge());
266 truHit->SetParticleName(aStep->GetTrack()->GetDefinition()->GetParticleName());
267 truHit->SetTime(aStep->GetPreStepPoint()->GetGlobalTime());
268 truHit->SetPosition(aStep->GetPreStepPoint()->GetPosition());
269 truHit->SetMomentum(aStep->GetPreStepPoint()->GetMomentum());
270
271 } else { // the primary particle doesn't hit emc
272
274 std::vector<BesTruthTrack*> *trackList = sensitiveManager->GetTrackList();
275
276 for(unsigned i=0;i<trackList->size();i++) {
277 BesTruthTrack *truthTrack=(*trackList)[i];
278
279 if(trackIndex==truthTrack->GetIndex()) { //find primary particle
280 truHit->SetHitEmc(0);
281 truHit->SetPDGCode(truthTrack->GetPDGCode());
282 truHit->SetPDGCharge(truthTrack->GetPDGCharge());
283 truHit->SetParticleName(truthTrack->GetParticleName());
284
285 if(truthTrack->GetTerminalVertex()) {
286 truHit->SetTime(truthTrack->GetTerminalVertex()->GetTime());
287 truHit->SetPosition(truthTrack->GetTerminalVertex()->GetPosition());
288 } else { //have not found terminal vertex
289 truHit->SetTime(-99);
290 truHit->SetPosition(G4ThreeVector(-99,-99,-99));
291 }
292
293 break;
294 } //end if find primary particle
295
296 }
297 }
298
299 CalTruthList->insert(truHit);
300 }
301 }
302 }
303
304 return true;
305}
void SetNumCrystal(G4int id, G4int numTheta, G4int numPhi)
void SetMomentum(G4ThreeVector momen)
void SetPosCrystal(G4ThreeVector position)
G4int ComputeEndCopyNb(G4int)
Definition: BesEmcSD.cc:442
void ComputeThetaPhi(G4int, G4int, G4int)
Definition: BesEmcSD.cc:309
G4int EndPhiNumberForGDML(G4int)
Definition: BesEmcSD.cc:425
void AddEHit(Identifier, G4double)
Definition: BesEmcHit.cc:197
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 GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) 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

◆ ProcessHits() [2/2]

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

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