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 primTrackIdx = 0;
348 G4int G4TrackId = 0;
349 G4int primG4TrackId = 0;
350
351
352
353
354
355
356 G4TrackId = 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 << primTrackIdx << 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 G4double trkLen = lv_track->GetTrackLength();
399
400 lvi_ID_layer = lv_TOUCHABLE->GetVolume(1)->GetCopyNo();
401
402 if(printFlag) {
403
404 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Track enters the SD volume: "
405 << lvs_volume_name << endreq;
406
407
408
409
410
411
412 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Create a hit at layer="
413 << lvi_ID_layer << " track=" << primTrackIdx << endreq;
414 }
415
417
418
419 l_new_hit->
SetRdtEl ( lvi_RdtElectron );
421
423 G4int isSecondary = (G4TrackId==primG4TrackId)? 0:1;
424
432
433
434 double x_pre_glo = lv3_XYZ_pre.x();
435 double y_pre_glo = lv3_XYZ_pre.y();
436 double z_pre_glo = lv3_XYZ_pre.z();
437 double x_post_glo = lv3_XYZ_post.x();
438 double y_post_glo = lv3_XYZ_post.y();
439 double z_post_glo = lv3_XYZ_post.z();
440 double r_pre = sqrt(x_pre_glo*x_pre_glo+y_pre_glo*y_pre_glo);
441 double r_post = sqrt(x_post_glo*x_post_glo+y_post_glo*y_post_glo);
442
444 HepPoint3D pos_pre(x_pre_glo, y_pre_glo, z_pre_glo);
445 HepPoint3D pos_post(x_post_glo, y_post_glo, z_post_glo);
450
453
454 double distLineGlo = fabs(line_glo.dr());
455 if(fabs(distLineGlo) > rDrift_inn){
456 crossPoint_pre = line_loc.
xAtR(r_post, -1);
457 crossPoint_post = line_loc.
xAtR(r_post, 1);
458 } else if(r_pre < r_post){
459 crossPoint_pre = line_loc.
xAtR(r_pre, 1);
460 crossPoint_post = line_loc.
xAtR(r_post, 1);
461 } else{
462 crossPoint_pre = line_loc.
xAtR(r_pre, -1);
463 crossPoint_post = line_loc.
xAtR(r_post, -1);
464 }
465
466 G4ThreeVector lv3_XYZ_pre_align(crossPoint_pre.x(), crossPoint_pre.y(), crossPoint_pre.z());
467 G4ThreeVector lv3_XYZ_post_align(crossPoint_post.x(), crossPoint_post.y(), crossPoint_post.z());
468
471
472
473
480
481 m_collection_hit->insert(l_new_hit);
482
483
484 hit_ID_vector.push_back(lvi_ID_hit);
485 lvi_ID_hit++;
486
487
488
489
490
491
492
493
494
495
496
497 KeyType lv_key(primTrackIdx, lvi_ID_layer);
498
499 if (m_collection_truth)
500 {
501 int newVer=1;
502
503 if(newVer==0) {
504 m_map_truth_it = m_map_truth.find(lv_key);
505 if (m_map_truth_it == m_map_truth.end())
506 {
507 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Create a Truth at layer="
508 << lvi_ID_layer << " track=" << primTrackIdx << endreq;
509
511
516
526
527
528 int tmp[2000];
529 for(int ii =0; ii < hit_ID_vector.size();ii++){
530 tmp[ii] = hit_ID_vector[ii];
531 }
533 hit_ID_vector.clear();
534
535
536
537 m_collection_truth->insert(l_new_truth);
538
539 m_map_truth[lv_key] = m_collection_truth->entries() - 1;
540
541 if (lv_step_pre->GetStepStatus() == fGeomBoundary)
542 {
543 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Truth starts from boundry!!!"
544 << endreq;
545 }
546 else
547 {
548 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Truth doesn't start from boundry!!!"
549 << endreq;
550 }
551 }
552 else
553 {
554 if(printFlag)
555 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Add a step to Truth at layer="
556 << lvi_ID_layer << " track=" << primTrackIdx << endreq;
557
558 G4int lvi_ID_truth = (*m_map_truth_it).second;
559 G4int primTrackIdx_pre = (*m_collection_truth)[lvi_ID_truth]->GetTrackID();
560 G4double lvd_E_pre = (*m_collection_truth)[lvi_ID_truth]->GetTotalEnergyDeposit();
561 G4double lvd_L_step_pre = (*m_collection_truth)[lvi_ID_truth]->GetStepLength();
562
563 (*m_collection_truth)[lvi_ID_truth]->SetTotalEnergyDeposit(lvd_E_deposit + lvd_E_pre);
564 (*m_collection_truth)[lvi_ID_truth]->SetStepLength(lvd_L_step + lvd_L_step_pre);
565 (*m_collection_truth)[lvi_ID_truth]->SetPositionOfPostPoint(lv3_XYZ_post);
566 (*m_collection_truth)[lvi_ID_truth]->SetPositionOfPostPointAlign(lv3_XYZ_post_align);
567 (*m_collection_truth)[lvi_ID_truth]->SetMomentumOfPostPoint(lv3_P_post);
568 }
569
570
571
572 if(printFlag)
573 if (lv_step_post->GetStepStatus() == fGeomBoundary)
574 {
575 log<< MSG::INFO << "CgemSim::BesCgemSD::ProcessHits(), Finish a Truth at layer="
576 << lvi_ID_layer << " track=" << primTrackIdx << endreq;
577 }
578 }
579 else
580 {
581 if(myCgemTruth==NULL)
582 {
584 if(printFlag)
585 cout<<"creat a new myCgemTruth, prePos is Boundary: "<<(lv_status_pre==fGeomBoundary)<<" trkID="<<primTrackIdx<<", LayerID="<<lvi_ID_layer<<endl;
586
601 myCgemTruth->
SetRdtEl ( lvi_RdtElectron );
604
605
606
607 }
608 else
609 {
614
615
622 if(printFlag)
623 cout<<"update myCgemTruth: prePos is Boundary: "<<(lv_status_pre==fGeomBoundary)<<", postPos is Boundary:"<<(lv_status_post==fGeomBoundary)<<", trkID="<<primTrackIdx<<", LayerID="<<lvi_ID_layer<<endl;
624 }
625 if( myCgemTruth && (currentTrackStatus==fStopAndKill || lv_status_post==fGeomBoundary) )
626 {
627
628 int tmp[2000];
629 for(int ii =0; ii < hit_ID_vector.size();ii++){
630 tmp[ii] = hit_ID_vector[ii];
631 }
633
634
635
636 m_collection_truth->insert(myCgemTruth);
637 myCgemTruth=NULL;
638
639
640 hit_ID_vector.clear();
641
642
643 if(printFlag)
644 cout<<"save a myCgemTruth: prePos is Boundary: "<<(lv_status_pre==fGeomBoundary)<<", postPos is Boundary:"<<(lv_status_post==fGeomBoundary)<<", trkID="<<primTrackIdx<<", LayerID="<<lvi_ID_layer<<endl;
645 }
646 }
647 }
648 }
649
650 return true;
651}
void SetTotalEnergyDeposit(G4double f_E_deposit)
void SetIsSecondary(G4int isSec)
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 SetFlightLengthPostPoint(G4double len)
void SetTrackID(G4int f_ID_track)
void SetPositionOfPrePoint(G4ThreeVector f_XYZ_pre)
void SetMomentumOfPrePoint(G4ThreeVector f_P_pre)
void SetCreatorProcess(G4String proName)
void SetPositionOfPostPointAlign(G4ThreeVector f_XYZ_post)
void SetPositionOfPrePointAlign(G4ThreeVector f_XYZ_pre)
void SetPositionOfPostPoint(G4ThreeVector f_XYZ_post)
void SetStepLength(G4double f_L_step)
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
StraightLine StraightLineConversion(int layer_vir, StraightLine lineOriginal)
double getOuterROfGapD() const
double getInnerROfGapD() const
CgemGeoLayer * getCgemLayer(int i) const
CgemGeoAlign * getAlignPtr() const
HepPoint3D xAtR(double R, int direction=1) const