Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // >> 26 // >> 27 // $Id$ >> 28 // 26 29 27 #include "AnalysisManager.hh" << 28 #include "eRositaTrackerSD.hh" 30 #include "eRositaTrackerSD.hh" 29 #include "eRositaTrackerHit.hh" << 30 << 31 #include <fstream> << 32 #include <iostream> << 33 << 34 #include "G4HCofThisEvent.hh" 31 #include "G4HCofThisEvent.hh" 35 #include "G4ios.hh" << 36 #include "G4ParticleTypes.hh" << 37 #include "G4SDManager.hh" << 38 #include "G4Step.hh" 32 #include "G4Step.hh" 39 #include "G4ThreeVector.hh" 33 #include "G4ThreeVector.hh" >> 34 #include "G4SDManager.hh" >> 35 #include "G4ios.hh" >> 36 #include "G4ParticleTypes.hh" 40 37 41 //....oooOO0OOooo........oooOO0OOooo........oo << 38 #include <iostream> >> 39 #include <fstream> >> 40 >> 41 #include "AnalysisManager.hh" 42 42 43 eRositaTrackerSD::eRositaTrackerSD(G4String na << 44 { << 45 constexpr auto TRACKER_COLLECTION_NAME = " << 46 collectionName.insert(TRACKER_COLLECTION_N << 47 } << 48 43 49 //....oooOO0OOooo........oooOO0OOooo........oo << 50 44 51 eRositaTrackerSD::~eRositaTrackerSD() << 45 eRositaTrackerSD::eRositaTrackerSD(G4String name) >> 46 :G4VSensitiveDetector(name) 52 { 47 { >> 48 G4String HCname; >> 49 collectionName.insert(HCname="trackerCollection"); 53 } 50 } 54 51 55 //....oooOO0OOooo........oooOO0OOooo........oo << 56 52 57 void eRositaTrackerSD::Initialize(G4HCofThisEv << 53 eRositaTrackerSD::~eRositaTrackerSD(){ } 58 { << 54 59 trackerCollection = new eRositaTrackerHits << 60 static G4int collectionIdentifier = -1; << 61 55 62 if (collectionIdentifier < 0) { << 56 void eRositaTrackerSD::Initialize(G4HCofThisEvent* HCE) 63 collectionIdentifier = G4SDManager::Ge << 57 { >> 58 trackerCollection = new eRositaTrackerHitsCollection >> 59 (SensitiveDetectorName,collectionName[0]); >> 60 static G4int HCID = -1; >> 61 if (HCID < 0) >> 62 { >> 63 HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); 64 } 64 } 65 collection->AddHitsCollection(collectionId << 65 HCE->AddHitsCollection( HCID, trackerCollection ); 66 } 66 } 67 67 68 //....oooOO0OOooo........oooOO0OOooo........oo << 69 68 70 auto eRositaTrackerSD::ProcessHits(G4Step* ste << 69 G4bool eRositaTrackerSD::ProcessHits(G4Step* aStep,G4TouchableHistory*) 71 { 70 { 72 if (step->GetTrack()->GetDefinition() != G << 71 if(aStep->GetTrack()->GetDefinition() != G4Gamma::GammaDefinition()) return false; 73 return false; << 74 } << 75 72 76 // auto depositedEnergy = step->GetTotalEn << 73 // G4double edep = aStep->GetTotalEnergyDeposit(); 77 auto depositedEnergy = step->GetPreStepPoi << 74 G4double edep = aStep->GetPreStepPoint()->GetKineticEnergy(); 78 if (depositedEnergy == 0.) { << 75 79 return false; << 76 if (edep == 0.) return false; 80 } << 81 77 82 auto *newHit = new eRositaTrackerHit(); << 78 eRositaTrackerHit* newHit = new eRositaTrackerHit(); 83 newHit->SetTrackIdentifier(step->GetTrack( << 79 newHit->SetTrackID (aStep->GetTrack()->GetTrackID()); 84 // newHit->SetChamberNumber(step->GetPreSt << 80 //newHit->SetChamberNb(aStep->GetPreStepPoint()->GetTouchableHandle() 85 newHit->SetDepositedEnergy(depositedEnergy << 81 // ->GetCopyNumber()); 86 newHit->SetPosition(step->GetPostStepPoint << 82 newHit->SetEdep(edep); 87 trackerCollection->insert(newHit); << 83 newHit->SetPos(aStep->GetPostStepPoint()->GetPosition()); 88 << 84 trackerCollection->insert( newHit ); 89 // newHit->Print(); << 85 90 // newHit->Draw(); << 86 //newHit->Print(); 91 << 87 //newHit->Draw(); 92 // std::ofstream dataFile("ASCII"); << 88 93 // newHit->PrintToFile(dataFile); << 89 //ofstream out("ASCII"); 94 // dataFile.close(); << 90 //newHit->PrintToFile(out); >> 91 //out.close(); 95 92 96 return true; << 93 return true; 97 } 94 } 98 95 99 //....oooOO0OOooo........oooOO0OOooo........oo << 100 96 101 void eRositaTrackerSD::EndOfEvent(G4HCofThisEv 97 void eRositaTrackerSD::EndOfEvent(G4HCofThisEvent*) 102 { 98 { 103 G4int numberOfHits = trackerCollection->en << 99 G4int NbHits = trackerCollection->entries(); >> 100 >> 101 if (verboseLevel > 0) >> 102 { >> 103 >> 104 G4cout << std::endl >> 105 << "Hits Collection: in this event they are " << NbHits >> 106 << " hits in the tracker chambers: " << G4endl; >> 107 for (G4int i=0;i<NbHits;i++) (*trackerCollection)[i]->Print(); >> 108 >> 109 } >> 110 >> 111 // ofstream out("ASCII"); >> 112 //if (!out.is_open()) >> 113 // { >> 114 // G4cout <<"...opening ASCII file failed"; >> 115 // } >> 116 >> 117 double eTot = 0.; >> 118 >> 119 for (G4int i=0; i<NbHits; i++) >> 120 { >> 121 (*trackerCollection)[i]->PrintToFile(); >> 122 eTot += (*trackerCollection)[i]->GetEdep(); >> 123 }; 104 124 105 if (verboseLevel > 0) { << 125 // if (eTot > 0.) AnalysisManager::Instance()->ScoreTot(eTot); 106 G4cout << G4endl << 107 << "Hits collection: in this event << 108 << " hits in the tracker chambers: << 109 << 110 for (G4int i = 0; i < numberOfHits; i+ << 111 (*trackerCollection)[i]->Print(); << 112 } << 113 } << 114 126 115 for (G4int i = 0; i < numberOfHits; i++) { << 127 //out.close(); 116 (*trackerCollection)[i]->PrintToFile() << 117 }; << 118 } 128 } >> 129 >> 130 >> 131 >> 132 119 133