/// \file B2/B2a/src/TrackerSD.cc /// \brief Implementation of the B2::TrackerSD class #include "SipmSD.hh" #include "G4HCofThisEvent.hh" #include "G4Step.hh" #include "G4ThreeVector.hh" #include "G4SDManager.hh" #include "G4ios.hh" #include "G4AnalysisManager.hh" #include "G4SystemOfUnits.hh" namespace B1 { //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... SipmSD::SipmSD(const G4String& name, const G4String& hitsCollectionName) : G4VSensitiveDetector(name) { collectionName.insert(hitsCollectionName); h = 4.13566733e-15*eV*s; c = 299792458.*m/s; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void SipmSD::Initialize(G4HCofThisEvent* hce) { // Create hits collection fHitsCollection = new SipmHitsCollection(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 SipmSD::ProcessHits(G4Step* aStep,G4TouchableHistory*) { // energy deposit if(aStep->GetTrack()->GetDefinition()->GetParticleName() != (G4String)"opticalphoton") return false; //idea stolen from: LXePMTSD.cc G4StepPoint* preStepPoint = aStep->GetPreStepPoint(); G4TouchableHistory* touchable = (G4TouchableHistory*)(preStepPoint->GetTouchable()); if(touchable->GetVolume()->GetName() != "Sipm1")return false; G4double edep = aStep->GetTotalEnergyDeposit(); G4double totalEn = aStep->GetTrack()->GetTotalEnergy(); G4double wavelength = (h*c)/totalEn; G4double time = aStep->GetPreStepPoint()->GetGlobalTime(); //G4cout << 1 << G4endl; //if (edep==0.) return false; auto newHit = new SipmHit(); newHit->SetTrackID (aStep->GetTrack()->GetTrackID()); G4int number=-1; G4int copyno=-1; if(collectionName[0] == "DetCollection1") number=0; //if(collectionName[0] == "DetCollection2") number=1; //if(collectionName[0] == "DetCollection3") number=2; //copyno = aStep->GetPreStepPoint()->GetTouchableHandle()->GetCopyNumber(); newHit->SetChamberNb(number); newHit->SetEdep(edep); //newHit->SetCopyNumber(copyno); newHit->SetPos (aStep->GetPostStepPoint()->GetPosition()); newHit->SetTime(time); newHit->SetWavelength(wavelength); newHit->SetTotalEnergy(totalEn); fHitsCollection->insert( newHit ); aStep->GetTrack()->SetTrackStatus(fStopAndKill); return true; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... void SipmSD::EndOfEvent(G4HCofThisEvent*) { auto analysisManager = G4AnalysisManager::Instance(); G4double trackenergy; G4int nofHits = fHitsCollection->entries(); G4double deposition[3] = {0.0}; G4int chamberno = -1; //G4int copynumber = -1; G4double newTime[3] = {0.0}; G4double Time = 0.; G4double wavelength = 0.; G4double totalEn = 0.; for( G4int jcount = 0; jcount < nofHits; jcount++) { //deposition += (*fHitsCollection)[jcount]->GetEdep(); //G4cout << "deposition:" << deposition << G4endl; G4int newchamberno = (*fHitsCollection)[jcount]->GetChamberNb(); //bu önceden newchamberno idi G4int track = (*fHitsCollection)[jcount]->GetTrackID(); chamberno = newchamberno; wavelength = (*fHitsCollection)[jcount]->GetWavelength(); totalEn = (*fHitsCollection)[jcount]->GetTotalEnergy(); deposition[chamberno] += (*fHitsCollection)[jcount]->GetEdep(); //if (newTime[chamberno] == 0) newTime[chamberno] += (*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; }*/ /* if(newTime[0]!= 0.0 && newTime[2]!=0.0 ) G4cout << "newchamberno:" << newchamberno << " " << "time:" << newTime[0] <<" - " << newTime[2] << " " << "Time Diff:" << Time <GetTrackID() <GetCopyNumber(); //bu önceden newcopynumber idi /*if(newcopynumber != copynumber && copynumber >-1) { G4cout << jcount << " chamberno: " << chamberno << "->" << newchamberno << G4endl; } copynumber = newcopynumber;*/ } //biri 0 dan farklı ise yazdır /*analysisManager->FillNtupleDColumn(0, 0, deposition[0]); analysisManager->FillNtupleDColumn(0, 1, totalEn); analysisManager->FillNtupleDColumn(0, 2, wavelength); analysisManager->FillNtupleDColumn(0, 3, newTime[0]/(double)nofHits/CLHEP::ns); //analysisManager->FillNtupleDColumn(0, 4, newTime[1]/(double)nofHits/CLHEP::ns); //analysisManager->FillNtupleDColumn(0, 5, newTime[2]/(double)nofHits/CLHEP::ns); //analysisManager->FillNtupleDColumn(0, 4, copynumber); analysisManager->AddNtupleRow(0);*/ //G4cout << 5 << G4endl; //G4ThreeVector position = (*fHitsCollection)->GetPos(); //analysisManager->FillNtupleDColumn(0, 1, position.getX()); //analysisManager->FillNtupleDColumn(0, 2, position.getY()); //analysisManager->FillNtupleDColumn(0, 3, position.getZ()); /////////////////////////////// if ( verboseLevel>1 ) { //G4int nofHits = fHitsCollection->entries(); G4cout << G4endl << "-------->Hits Collection: in this event they are " << nofHits << " hits in the Sipm chambers: " << G4endl; for ( G4int icount=0; icountPrint(); G4cout << (*fHitsCollection)[icount] << G4endl;} } //G4cout << 6 << G4endl; } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... }