258{
259 bool printFlag=false;
260
262 Gaudi::svcLocator() -> service(
"MessageSvc",
msgSvc);
263 MsgStream log(
msgSvc,
"BesCgemSD::ProcessHits()");
264
265
266 G4Track *lv_track = f_step->GetTrack();
267
268
269
270 G4double charge = lv_track->GetDefinition()->GetPDGCharge();
271 if (charge == 0.)
272 {
273 if(printFlag)
274 log<< MSG::WARNING << "CgemSim::BesCgemSD::ProcessHits(), Track is neutral, skip the track" << endreq;
275 return false;
276 }
277 G4int lvi_pdg_code = lv_track->GetDefinition()->GetPDGEncoding();
278
279
280 G4double lvd_global_time = lv_track->GetGlobalTime();
281 if (isnan(lvd_global_time))
282 {
283 if(printFlag)
284 log<< MSG::WARNING << "CgemSim::BesCgemSD::ProcessHits(), Gloabal time is nan" << endreq;
285 return false;
286 }
287
288 if (lvd_global_time > 2000)
289 {
290 if(printFlag)
291 log<< MSG::WARNING << "CgemSim::BesCgemSD::ProcessHits(), Time window is >2000" << endreq;
292 return false;
293 }
294
295
296
297
298
299
300
301
302
303
304 G4double lvd_L_step = f_step->GetStepLength();
305 if (lvd_L_step == 0.)
306 {
307 if(printFlag)
308 log<< MSG::WARNING << "CgemSim::BesCgemSD::ProcessHits(), Step length is 0, skip track" << endreq;
309 return false;
310 }
311
312
313 G4StepPoint *lv_step_pre = f_step->GetPreStepPoint();
314 G4StepPoint *lv_step_post = f_step->GetPostStepPoint();
315 G4TrackStatus currentTrackStatus = lv_track->GetTrackStatus();
316
317
318 G4int lvi_RdtElectron = 0;
319 G4String process_name="Generator";
320 if (NULL != lv_track->GetCreatorProcess()){
321 process_name = lv_track->GetCreatorProcess()->GetProcessName();
322 if (process_name == "hIoni" || process_name == "ionIoni" || process_name == "conv" || process_name == "compt" || process_name == "muIoni" || process_name == "eIoni" || process_name == "phot" || process_name == "muMinusCaptureAtRest" ) lvi_RdtElectron = 1;
323
324
325
326
327
328 }
329 if(lvi_RdtElectron) return false;
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347 G4int lvi_ID_track = 0;
348 G4int lvi_ID_truth = 0;
349 G4int lvi_ID_G4Track = 0;
350
351
352
353
354
355
356 lvi_ID_truth = lv_track->GetTrackID();
358
359
360
361 G4int lvi_ID_layer = 0;
362
363 G4int lvi_ID_parent = lv_track->GetParentID();
364 G4double lvd_E_deposit = f_step->GetTotalEnergyDeposit();
365
366 G4ThreeVector lv3_XYZ_pre = lv_step_pre ->GetPosition();
367 G4ThreeVector lv3_XYZ_post = lv_step_post->GetPosition();
368
369 G4ThreeVector lv3_P_pre = lv_step_pre ->GetMomentum();
370 G4ThreeVector lv3_P_post = lv_step_post->GetMomentum();
371
372 if(printFlag) {
373 log<< MSG::INFO << "..............................................................................." << endreq;
374 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Process a hit at track="
375 << lvi_ID_track << endreq;
376 }
377
378
379
380
381
382
383 G4StepStatus lv_status_pre = lv_step_pre ->GetStepStatus();
384 G4StepStatus lv_status_post = lv_step_post->GetStepStatus();
385
386
387 const G4VTouchable *lv_TOUCHABLE = lv_step_pre ->GetTouchable();
388
389 G4String lvs_volume_name = lv_TOUCHABLE ->GetVolume(0)->GetLogicalVolume()->GetName();
390
391
392
393
394
395
396 if (lvs_volume_name == "Gap_D_logic0" or lvs_volume_name == "Gap_D_logic1" or lvs_volume_name == "Gap_D_logic2")
397 {
398
399 lvi_ID_layer = lv_TOUCHABLE->GetVolume(1)->GetCopyNo();
400
401 if(printFlag) {
402
403 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Track enters the SD volume: "
404 << lvs_volume_name << endreq;
405
406
407
408
409
410
411 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Create a hit at layer="
412 << lvi_ID_layer << " track=" << lvi_ID_track << endreq;
413 }
414
416
417
418 l_new_hit->
SetRdtEl ( lvi_RdtElectron );
420
433
434 m_collection_hit->insert(l_new_hit);
435
436
437 hit_ID_vector.push_back(lvi_ID_hit);
438 lvi_ID_hit++;
439
440
441
442
443
444
445
446
447
448
449
450 KeyType lv_key(lvi_ID_track, lvi_ID_layer);
451
452 if (m_collection_truth)
453 {
454 int newVer=1;
455
456 if(newVer==0) {
457 m_map_truth_it = m_map_truth.find(lv_key);
458 if (m_map_truth_it == m_map_truth.end())
459 {
460 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Create a Truth at layer="
461 << lvi_ID_layer << " track=" << lvi_ID_track << endreq;
462
464
476
477
478 int tmp[2000];
479 for(int ii =0; ii < hit_ID_vector.size();ii++){
480 tmp[ii] = hit_ID_vector[ii];
481 }
483 hit_ID_vector.clear();
484
485
486
487 m_collection_truth->insert(l_new_truth);
488
489 m_map_truth[lv_key] = m_collection_truth->entries() - 1;
490
491 if (lv_step_pre->GetStepStatus() == fGeomBoundary)
492 {
493 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Truth starts from boundry!!!"
494 << endreq;
495 }
496 else
497 {
498 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Truth doesn't start from boundry!!!"
499 << endreq;
500 }
501 }
502 else
503 {
504 if(printFlag)
505 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Add a step to Truth at layer="
506 << lvi_ID_layer << " track=" << lvi_ID_track << endreq;
507
508 G4int lvi_ID_truth = (*m_map_truth_it).second;
509 G4int lvi_ID_track_pre = (*m_collection_truth)[lvi_ID_truth]->GetTrackID();
510 G4double lvd_E_pre = (*m_collection_truth)[lvi_ID_truth]->GetTotalEnergyDeposit();
511 G4double lvd_L_step_pre = (*m_collection_truth)[lvi_ID_truth]->GetStepLength();
512
513 (*m_collection_truth)[lvi_ID_truth]->SetTotalEnergyDeposit(lvd_E_deposit + lvd_E_pre);
514 (*m_collection_truth)[lvi_ID_truth]->SetStepLength(lvd_L_step + lvd_L_step_pre);
515 (*m_collection_truth)[lvi_ID_truth]->SetPositionOfPostPoint(lv3_XYZ_post);
516 (*m_collection_truth)[lvi_ID_truth]->SetMomentumOfPostPoint(lv3_P_post);
517 }
518
519
520
521 if(printFlag)
522 if (lv_step_post->GetStepStatus() == fGeomBoundary)
523 {
524 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Finish a Truth at layer="
525 << lvi_ID_layer << " track=" << lvi_ID_track << endreq;
526 }
527 }
528 else
529 {
530 if(myCgemTruth==NULL)
531 {
533 if(printFlag)
534 cout<<"creat a new myCgemTruth, prePos is Boundary: "<<(lv_status_pre==fGeomBoundary)<<" trkID="<<lvi_ID_track<<", LayerID="<<lvi_ID_layer<<endl;
535
548 double dphi=lv3_XYZ_pre.phi()-lv3_XYZ_post.phi();
549 double dX=dphi*87.5;
550
551 }
552 else
553 {
558
559
564 if(printFlag)
565 cout<<"update myCgemTruth: prePos is Boundary: "<<(lv_status_pre==fGeomBoundary)<<", postPos is Boundary:"<<(lv_status_post==fGeomBoundary)<<", trkID="<<lvi_ID_track<<", LayerID="<<lvi_ID_layer<<endl;
566 }
567 if( myCgemTruth && (currentTrackStatus==fStopAndKill || lv_status_post==fGeomBoundary) )
568 {
569
570 int tmp[2000];
571 for(int ii =0; ii < hit_ID_vector.size();ii++){
572 tmp[ii] = hit_ID_vector[ii];
573 }
575
576
577
578 m_collection_truth->insert(myCgemTruth);
579 myCgemTruth=NULL;
580
581
582 hit_ID_vector.clear();
583
584
585 if(printFlag)
586 cout<<"save a myCgemTruth: prePos is Boundary: "<<(lv_status_pre==fGeomBoundary)<<", postPos is Boundary:"<<(lv_status_post==fGeomBoundary)<<", trkID="<<lvi_ID_track<<", LayerID="<<lvi_ID_layer<<endl;
587 }
588 }
589 }
590 }
591
592 return true;
593}
void SetTotalEnergyDeposit(G4double f_E_deposit)
void SetGlobalTime(G4double f_global_time)
void AddIdentifier(G4int f_ID_Identifier[2000], G4int N_dim)
void SetMomentumOfPostPoint(G4ThreeVector f_P_post)
void SetHitID(G4int f_ID_hit)
void SetPDGCode(G4int f_pdg_code)
G4double GetStepLength() const
void SetLayerID(G4int f_ID_layer)
void SetRdtEl(G4int f_RdtElectron)
void SetParentID(G4int f_ID_parent)
void SetTrackID(G4int f_ID_track)
void SetPositionOfPrePoint(G4ThreeVector f_XYZ_pre)
void SetMomentumOfPrePoint(G4ThreeVector f_P_pre)
void SetCreatorProcess(G4String proName)
void SetPositionOfPostPoint(G4ThreeVector f_XYZ_post)
void SetStepLength(G4double f_L_step)
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const