//////////////////////////////////////////////////////////////////////////////// // Description: // This is a primitive scorer class for scoring energy deposit. // // Created: 2005-11-14 Tsukasa ASO, Akinori Kimura. // 2010-07-22 Introduce Unit specification. // /////////////////////////////////////////////////////////////////////////////// /** * @file SolidPSTimeEnd.cc * @author: (modified by) Ibrahin Pinera * @date 2016 SoLid - University of Antwerp */ #include "SolidPSTimeEnd.hh" // G4PSEnergyDeposit #include "G4UnitsTable.hh" SolidPSTimeEnd::SolidPSTimeEnd(G4String name, G4int depth) :G4VPrimitiveScorer(name,depth),HCID(-1) { SetUnit("ns"); } SolidPSTimeEnd::SolidPSTimeEnd(G4String name, const G4String& unit, G4int depth) :G4VPrimitiveScorer(name,depth),HCID(-1) { SetUnit(unit); } SolidPSTimeEnd::~SolidPSTimeEnd() {;} G4bool SolidPSTimeEnd::ProcessHits(G4Step* aStep,G4TouchableHistory*) { G4double edep = aStep->GetTotalEnergyDeposit(); G4StepPoint* thePrePoint = aStep->GetPreStepPoint(); G4double time = thePrePoint->GetGlobalTime(); if ( edep == 0. ) return FALSE; //edep *= aStep->GetPreStepPoint()->GetWeight(); // (Particle Weight) G4int index = GetIndex(aStep); // Calculate average time for multiple hits in a same cube // Use m_counter[index] to check number of hits // It updates average time for each time adding a hit std::map evtMap = *(EvtMap->GetMap()); // If it is first hit if (evtMap.find(index) == evtMap.end()) { m_counter[index] = 1; EvtMap->add(index,time); // It it is not first hit, update average time } else { G4int n = m_counter[index]; // n: number of entries before adding new time m_counter[index] += 1; // update counter G4double old_val = *evtMap[index]; // old average G4double val = (old_val * n + time) / (1.0*n+1); // Update average EvtMap->set(index,val); // Set new average time to the map } return TRUE; } void SolidPSTimeEnd::Initialize(G4HCofThisEvent* HCE) { EvtMap = new G4THitsMap(GetMultiFunctionalDetector()->GetName(), GetName()); if(HCID < 0) {HCID = GetCollectionID(0);} HCE->AddHitsCollection(HCID, (G4VHitsCollection*)EvtMap); } void SolidPSTimeEnd::EndOfEvent(G4HCofThisEvent*) {;} void SolidPSTimeEnd::clear() { EvtMap->clear(); } void SolidPSTimeEnd::DrawAll() {;} void SolidPSTimeEnd::PrintAll() { G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl; G4cout << " PrimitiveScorer " << GetName() << G4endl; G4cout << " Number of entries " << EvtMap->entries() << G4endl; std::map::iterator itr = EvtMap->GetMap()->begin(); for(; itr != EvtMap->GetMap()->end(); itr++) { G4cout << " copy no.: " << itr->first << " time: " << *(itr->second)/GetUnitValue() << " [" << GetUnit()<<"]" << G4endl; } } void SolidPSTimeEnd::SetUnit(const G4String& unit) { CheckAndSetUnit(unit,"Time"); } G4int SolidPSTimeEnd::GetIndex(G4Step* aStep) { G4StepPoint* preStep = aStep->GetPreStepPoint(); G4TouchableHistory* th = (G4TouchableHistory*)(preStep->GetTouchable()); // G4int index= th->GetReplicaNumber(indexDepth) + (th->GetReplicaNumber(indexDepth+1))*10000; G4int index= th->GetReplicaNumber(indexDepth) + (th->GetReplicaNumber(indexDepth+1) + 10*th->GetReplicaNumber(indexDepth+2))*10000; // G4cout << "The id is: " << index <