Help me plz! I can't get correct hit number in sensitive detector! :<

Greeting! Gods and Goddess of Geant4!
Now I stucked, so sad :sob:.

Program based on B5
Carbon Ion through 2 sensitive detectors ( SD refine based on B5EmCalorimeterοΌ‰

But I only got 1 hit in each detector.

图片


ProcessHits like below

G4bool B5EmCalorimeterSD::ProcessHits(G4Step*step, G4TouchableHistory*)
{
  auto edep = step->GetTotalEnergyDeposit();
  if (edep==0.) return true;
  auto touchable = step->GetPreStepPoint()->GetTouchable();
  auto motherPhysical = touchable->GetVolume(1); // 2022 5 11  mother 
  auto physical = touchable->GetVolume();
  auto copyNo = physical->GetCopyNo();

  auto motherCopyNo = touchable->GetVolume(1)->GetCopyNo();
  


  auto hit = (*fHitsCollection)[copyNo];
  G4int hit_num = 0;


  // check if it is first touch 
  if (!(hit->GetLogV())) {
    // fill volume information
    hit->SetLogV(physical->GetLogicalVolume());
    G4AffineTransform transform = touchable->GetHistory()->GetTopTransform();
    transform.Invert();
    hit->SetRot(transform.NetRotation());
    hit->SetPos(transform.NetTranslation());

      hit->SetPreEdep(edepPre_new);
      hit->CalPreEdep(edepPre_new); // put in some compare num
 auto worldPos = PreStep->GetPosition(); // absoluted position
    auto localPos = touchable->GetHistory()->GetTopTransform().TransformPoint(worldPos); // relative coordinates


      auto firstTouch_z = worldPos.z();
      auto firstTouch_x = worldPos.x();
      auto firstTouch_y = worldPos.y();

    


    
      hit->SetWorldPos(worldPos);
      hit->SetLocalPos(localPos);
    
 }
  // add energy deposition
  hit->AddEdep(edep); // increment

  return true;
}

My EventAction.cc like below
Now I cal nhit based on deposited, if deposited energy >0 , nhit + 1
But why the hit is only 1 ??

  // tracker11 get data and write data
  for (G4int iDet = 0; iDet < 1; ++iDet)
  {
    auto hc = GetHC(event, fCh_11_DigCal[0]);
    if (!hc)
      return;
    G4cout << "hc : " << hc << G4endl;
    // β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
    // 2022 4 27 
    // nhit and deposited Energy - Init
    // β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
    totalCalHit[iDet] = 0;
    totalCalEdep[iDet] = 0.;
    // β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
    for (unsigned long i = 0; i < hc->GetSize(); ++i)
    {
      G4double edep = 0.; // Init
      G4double edepPre = 0.;
      G4ThreeVector Primary_worldPos;
      G4int count = 0;
      // The EM and Had calorimeter hits are of different types
        auto hit = static_cast<B5EmCalorimeterHit *>(hc->GetHit(i));
        edepPre = hit->GetPreEdep();
        edep = hit->GetEdep(); // deposited Energy
          // β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
          // 2022 4 27 
          // Energy > 0 ++
          // β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
          if ( edep > 0.)
          {
            totalCalHit[iDet]++; // nhit++
            totalCalEdep[iDet] += edep; // depostied Energy
          }
          // β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”

          if ((edepPre > 0.))
            {
              Primary_worldPos = hit->GetECWorldPos();
              auto nhit = hc->GetSize();

              if (kPrintEventAction){
                //  开关打开就打印
                  G4cout << "====================" << G4endl
                          << " = Tracker 11 = " << G4endl
                          // << " Hits : " << hc->GetSize() << G4endl
                          << " Input Energy (Ideal.)/MeV : " << edepPre << G4endl
                          << " --- World (x,y,z) " << Primary_worldPos.x() << ", " << Primary_worldPos.y() << ", " << Primary_worldPos.z() << G4endl
                          << "====================" << G4endl;
                 }

              Ide_Edep_Tra11 = edepPre;

              analysisManager->FillNtupleDColumn(5, (edepPre / MeV));
              analysisManager->FillNtupleDColumn(6, Primary_worldPos.x());
              analysisManager->FillNtupleDColumn(7, Primary_worldPos.y());
              analysisManager->FillNtupleDColumn(8, Primary_worldPos.z());
            }
    }
  // β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
  // 2022 4 27 
  // nhits and deposited Energy
  // β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
  if (kPrintEventAction){
    G4cout << "====================" << G4endl
          << " = Tracker11 Accumulation Record = " << G4endl
          << " Hits : " << totalCalHit[0] << G4endl
          << " Deposit Edep/MeV : " << totalCalEdep[0]/MeV << " MeV"<< G4endl
          << "====================" << G4endl;
      }

  Dep_Edep_Tra11 = totalCalEdep[0]/MeV;
  nhit_Tra11 = totalCalHit[0];

  analysisManager->FillNtupleDColumn(9, totalCalEdep[0]/MeV);
  analysisManager->FillNtupleIColumn(10, totalCalHit[0]);


  }



My problem is :
I wanna get total hits number in a detector, even include secondary particle.
that is to say, I wanna get the nhit of all cell of the sensitive detector

Help me plz!

Sincerely Thank Gods and Goddess of Geant4!
:pray::pray::pray:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.