/// \file B2/B2a/src/TrackerSD.cc /// \brief Implementation of the B2::TrackerSD class #include "TrackerHit.hh" #include "TrackerSD.hh" #include "G4HCofThisEvent.hh" #include "G4Step.hh" #include "G4ThreeVector.hh" #include "G4SDManager.hh" #include "G4ios.hh" #include "G4AnalysisManager.hh" #include "G4OpticalPhoton.hh" namespace B1 { //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... TrackerSD::TrackerSD(const G4String& name, const G4String& hitsCollectionName) : G4VSensitiveDetector(name) { collectionName.insert(hitsCollectionName); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void TrackerSD::Initialize(G4HCofThisEvent* hce) { // Create hits collection fHitsCollection = new TrackerHitsCollection(SensitiveDetectorName, collectionName[0]); // Add this collection in hce //G4cout << 0 << G4endl; G4int hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); hce->AddHitsCollection( hcID, fHitsCollection ); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... G4bool TrackerSD::ProcessHits(G4Step* aStep,G4TouchableHistory*) { if(!aStep) return false; G4Track* theTrack = aStep->GetTrack(); auto newHit = new TrackerHit(); //We must check if we are dealing with an optical photon or not if(theTrack->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition()) { return false; } G4double edep = aStep->GetTotalEnergyDeposit(); G4double time = aStep->GetPreStepPoint()->GetGlobalTime(); // Find out information regarding the hit G4StepPoint* thePostPoint = aStep->GetPostStepPoint(); G4TouchableHistory* theTouchable = (G4TouchableHistory*) (thePostPoint->GetTouchable()); newHit->SetEdep(edep); //newHit->SetCopyNumber(copyno); newHit->SetPos (aStep->GetPostStepPoint()->GetPosition()); newHit->SetTime(time); fHitsCollection->insert( newHit ); return true; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void TrackerSD::EndOfEvent(G4HCofThisEvent*) { G4int nofHits = fHitsCollection->entries(); auto analysisManager = G4AnalysisManager::Instance(); G4double deposition = 0.0; //G4int copynumber = -1; G4double newTime = 0.0; G4double Time = 0.0; for( G4int jcount = 0; jcount < nofHits; jcount++) { //G4cout << "deposition:" << deposition << G4endl; G4int track = (*fHitsCollection)[jcount]->GetTrackID(); deposition += (*fHitsCollection)[jcount]->GetEdep(); //if (newTime[chamberno] == 0) newTime += (*fHitsCollection)[jcount]->GetTime(); /* if(newchamberno == 0) { hitDetector0 = true; } else { hitDetector0 = false; continue; }*/ //if (newchamberno == 1 /*&& hitDetector0*/) //Time = newTime[1] - newTime[0]; /*if(newTime[0]!= 0.0 && newTime[1]!=0.0 ) { Time = newTime[1] - newTime[0]; // Reset the flag for the next particle hitDetector0 = false; }*/ // "trackID:"<< (*fHitsCollection)[jcount]->GetTrackID() <GetCopyNumber(); //bu önceden newcopynumber idi /*if(newcopynumber != copynumber && copynumber >-1) { G4cout << jcount << " chamberno: " << chamberno << "->" << newchamberno << G4endl; } copynumber = newcopynumber;*/ } analysisManager->FillNtupleDColumn(0, deposition); analysisManager->FillNtupleDColumn(1, newTime); analysisManager->AddNtupleRow(0); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... }