Presentation is loading. Please wait.

Presentation is loading. Please wait.

2006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT 1 Scorer and Sensitive Detector Filter Tsukasa Aso Toyama National College of Maritime Technology,

Similar presentations


Presentation on theme: "2006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT 1 Scorer and Sensitive Detector Filter Tsukasa Aso Toyama National College of Maritime Technology,"— Presentation transcript:

1 2006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT 1 Scorer and Sensitive Detector Filter Tsukasa Aso Toyama National College of Maritime Technology, JST CREST

2 22006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT How should we do for scoring efficiently? What object does have particle information? G4Step object has a particle information of particular step G4Step object has a particle information of particular step G4Step object has a pointer to G4Track G4Step object has a pointer to G4Track Where can we pick the particle information up? (Where is G4Step/G4Track object accessible?) (Where is G4Step/G4Track object accessible?) G4UserTrackingAction (G4Track) Not recommended Called every time when a track starts and ends Called every time when a track starts and ends G4UserSteppingActtion (G4Step) Not recommended Called every time when a track makes a step Called every time when a track makes a step G4VSensitiveDetector (G4Step) Recommended Called only when a track is in an assigned logical volume Called only when a track is in an assigned logical volume Geant4 offers two kinds of scorers using G4VSensitiveDetector Develop your own SensitiveDetector/Hits/HitsCollection classes Develop your own SensitiveDetector/Hits/HitsCollection classes Use Primitive Scorers and Sensitive Detector Filters Use Primitive Scorers and Sensitive Detector Filters ROI

3 32006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Basic Geant4 scoring functionality Geant4 provides two abstract base classes and one template class for user to define his/her own detector sensitivity. G4VSensitiveDetector G4VSensitiveDetector The user has to provide his/her own implementation of the detector response to create hit(s) using the information of G4Step. G4VHit G4VHit Hit is a snapshot of the physical interaction of a track or an accumulation of interactions of tracks in the sensitive region of your detector. G4THitsCollection (G4VHitsCollection) G4THitsCollection (G4VHitsCollection) Hit Collection is a container for storing G4VHit objects. G4THitsCollection uses a STL vector.

4 42006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT How to setup? Implements your own G4VSensitiveDetector class and G4VHits class G4VSensitiveDetector G4VSensitiveDetector Define your Scoring class derived from G4VSensitiveDetector class Implements bool processHits(G4Step* aStep,G4TouchabkeHistory*) method to create ( or update ) your Hit object and store the Hit in HitsCollection object G4VHit G4VHit Define your Hit class derived from G4VHit class Declare member variables and access methods which you want to score Assign G4VSensitiveDetector to a particular logical volume The G4VSensitiveDetector is automatically called in the particular logical volume by kernel The G4VSensitiveDetector is automatically called in the particular logical volume by kernel The HitsCollection is automatically stored in G4Event The HitsCollection is automatically stored in G4Event Get Event or Run Summary Use user hooks G4UserEventAction, G4UserRunAction classes

5 52006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Feature of Primitive Scorer based on G4VSensitiveDetector Concrete Primitive scorer classes (v.8.0~) A set of classes for getting physical quantities rather than hits (snapshot of interaction) A set of classes for getting physical quantities rather than hits (snapshot of interaction) Physical quantity is sampled and scored for each geometrical cell. Include both of an algorithm and a hit collection Users can skip over implementing sensitive detector and hit classes. I do not need to do this!!

6 62006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Primitive Scorer Classes There are three types of classes, G4MultiFunctionalDetector G4MultiFunctionalDetector G4VPrimitiveScorer G4VPrimitiveScorer G4THitsMap = Hits collection for storing physical quantity G4VSDFilter G4VSDFilter Enable to filter particle information for scoring G4VSensitiveDetector G4MultiFunctionalDetectoruserSensitiveDetector G4VPrimitiveScrer G4PSDoseScorer G4VSDFilter G4SDParticleFilter userFilter G4SDParticleFilter

7 72006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT G4MultiFunctionalDetector G4MultiFunctionalDetector is a concrete class derived from G4VSensitiveDetector It should be set to a logical volume as a kind of sensitive detector. It should be set to a logical volume as a kind of sensitive detector. It takes arbitrary number of G4VPrimitiveScorer classes. It takes arbitrary number of G4VPrimitiveScorer classes. By registering G4VPrimitiveScorer classes, you can define the scoring detector of your need. Each G4VPrimitiveScorer class accumulates one physics quantity for each physical volume. Each G4VPrimitiveScorer class accumulates one physics quantity for each physical volume. For example, G4PSDoseScorer (a concrete class of G4VPrimitiveScorer provided by Geant4) accumulates dose for each cell. By using G4MultiFunctionalDetector and provided concrete G4VPrimitiveScorer classes, you do not need to know how to implement sensitive detector and hit classes.

8 82006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT List of provided primitive scorers Concrete Primitive Scorers ( See Application Developers Guide 4.4.6 ) Track length Track length G4PSTrackLength, G4PSPassageTrackLength Deposited energy Deposited energy G4PSEnergyDepsit, G4PSDoseDeposit Current/Flux Current/Flux G4PSFlatSurfaceCurrent, G4PSSphereSurfaceCurrent, G4PSPassageCurrent, G4PSFlatSurfaceFlux, G4PSCellFlux, G4PSPassageCellFlux Others Others G4PSMinKinEAtGeneration, G4PSNofSecondary, G4PSNofStep, G4PSCellCharge angle V : Volume L : Total step length in the cell. SurfaceCurrent : Count number of injecting particles at defined surface. SurfaceFlux : Sum up 1/cos(angle) of injecting particles at defined surface CellFlux : Sum of L / V of injecting particles in the geometrical cell.

9 92006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT List of SD Filter classes G4VSDFilter can be attached to G4VSensitiveDetector and/or G4VPrimitiveSensitivity to define which kinds of tracks are to be scored. E.g., surface flux of protons can be scored by G4PSFlatSurfaceFlux with a filter that accepts protons only. G4SDChargedFilter, G4SDNeutralFilter Accept only charged/neutral tracks, respectively Accept only charged/neutral tracks, respectivelyG4SDKineticEnergyFilter Accepts tracks within the defined range of kinetic energy Accepts tracks within the defined range of kinetic energyG4SDParticleFilter Accepts tracks of registered particle types Accepts tracks of registered particle typesG4SDParticleWithEnergyFilter Accepts tracks of registered particle types within the defined range of kinetic energy Accepts tracks of registered particle types within the defined range of kinetic energyG4VSDFilter Abstract base class which you can use to make your own filter Abstract base class which you can use to make your own filter

10 102006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT For example … MyDetectorConstruction::Construct() { … snippet … G4LogicalVolume* myCellLog = new G4LogicalVolume( … ); G4VPhysicalVolume* myCellPhys = new G4PVParametrised( … ); G4MultiFunctionalDetector* myScorer = new G4MultiFunctionalDetector( “ myCellScorer ” ); G4SDManager::GetSDMpointer()->AddNewDetector(myScorer); myCellLog->SetSensitiveDetector(myScorer); G4VPrimitiveScorer* totalSurfFlux = new G4PSFlatSurfaceFlux( “ TotalSurfFlux ” ); myScorer->RegisterPrimitive(totalSurfFlux); G4VPrimitiveScorer* protonSufFlux = new G4PSFlatSurfaceFlux( “ ProtonSurfFlux ” ); G4VSDFilter* protonFilter = new G4SDParticleFilter( “ protonFilter ” ); protonFilter->Add( “ proton ” ); protonSurfFlux->SetFilter(protonFilter); myScorer->RegisterPrimitive(protonSurfFlux); } See example “novice/N07”

11 112006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT for example If you need to get spectrum …. snippet G4MultiFunctionalDetector* MFDet = new G4MultiFunctionalDetector(…); ….. //--- Surface Current for gamma with energy bin. // This example creates four primitive scorers. // 4 bins with energy --- Primitive Scorer Name // 1. to 10 KeV, gammaSurfCurr000 // 10 keV to 100 KeV, gammaSurfCurr001 // 100 keV to 1 MeV, gammaSurfCurr002 // 1 MeV to 10 MeV. gammaSurfCurr003 // char name[16]; for ( G4int i = 0; i < 4; i++){ std::sprintf(name,"gammaSurfCurr%03d",i); G4String psgName(name); G4double kmin = std::pow(10.,(G4double)i)*keV; G4double kmax = std::pow(10.,(G4double)(i+1))*keV; //-- Particle with kinetic energy filter. G4SDParticleWithEnergyFilter* pkinEFilter = new G4SDParticleWithEnergyFilter(fltName="gammaE filter",kmin,kmax); pkinEFilter->add("gamma"); // Accept only gamma. pkinEFilter->show(); // Show accepting condition to stdout. //-- Surface Current Scorer which scores number of tracks in unit area. G4PSFlatSurfaceCurrent* scorer = new G4PSFlatSurfaceCurrent(psgName,fCurrent_InOut); scorer->SetFilter(pkinEFilter); // Assign filter. MFDet->RegisterPrimitive(scorer); // Register it to MultiFunctionalDetector. } … snippet …. See example “extended/runAndEvent/RE02

12 122006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Creating your own scorer Though we provide most commonly-used scorers, you may want to create your own. If you believe your requirement is quite common, just let us know, so that we will add a new scorer. If you believe your requirement is quite common, just let us know, so that we will add a new scorer. G4VPrimitiveScorer is the abstract base class. class G4VPrimitiveScorer { public: G4VPrimitiveScorer(G4String name, G4int depth=0); virtual ~G4VPrimitiveScorer(); protected: virtual G4bool ProcessHits(G4Step*, G4TouchableHistory*) = 0; virtual G4int GetIndex(G4Step*); public: virtual void Initialize(G4HCofThisEvent*); virtual void EndOfEvent(G4HCofThisEvent*); virtual void clear(); … };

13 132006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Creating your own SDFilter G4VSDFilter is the abstract base class class G4VSDFilter { public: G4VSDFilter(G4String name); virtual ~G4VSDFilter(); public: virtual G4bool Accept(const G4Step*) const = 0; …

14 142006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Sensitive detector vs. primitive scorer Sensitive detector You have to implement your own detector and hit classes. One hit class can contain many quantities. A hit can be made for each individual step, or accumulate quantities. Basically one hits collection is made per one detector. Hits collection is relatively compact. Primitive scorer Many scorers are provided by Geant4. You can add your own. Each scorer accumulates one quantity for an event. G4MultiFunctionalDetector creates many collections (maps), i.e. one collection per one scorer. Keys of maps are redundant for scorers of same volume. I would suggest to : Use primitive scorers if you are not interested in recording each individual step but accumulating some physics quantities for an event for a run, and if you are not interested in recording each individual step but accumulating some physics quantities for an event for a run, and if you do not have to have too many scorers. if you do not have to have too many scorers. Otherwise, consider implementing your own sensitive detector.

15 2006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT 15 Accumulating scores for a run BeginOfRunAction EndOfRunAction BeginOfEventAction EndOfEventAction G4Run G4EventEvent Summary Accumulate event data Run Summary

16 162006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT A tip for scoring For scoring purposes, you need to accumulate a physical quantity (e.g. energy deposition of a step) for entire run of many events. In such a case, do NOT sum up individual energy deposition of each step directly to a variable for entire run. Compared to the total sum for entire run, each energy deposition of single step is too tiny. Rounding error problem may easily happen. Compared to the total sum for entire run, each energy deposition of single step is too tiny. Rounding error problem may easily happen. Total energy deposition of 1 million events of 1 GeV incident particle ends up to 1 PeV (10 15 eV), while energy deposition of each single step is O(1 keV) or even smaller. Create your own Run class derived from G4Run, and implement RecordEvent(const G4Event*) virtual method. Here you can get all output of the event so that you can accumulate the sum of an event to a variable for entire run. RecordEvent(const G4Event*) is automatically invoked by G4RunManager. RecordEvent(const G4Event*) is automatically invoked by G4RunManager. Your run class object should be instantiated in GenerateRun() method of your UserRunAction. Your run class object should be instantiated in GenerateRun() method of your UserRunAction.

17 172006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Customized run class #include “ G4Run.hh ” #include “ G4Event.hh ” #include “ G4THitsMap.hh ” Class MyRun : public G4Run { public: public: MyRun(); MyRun(); virtual ~MyRun(); virtual ~MyRun(); virtual void RecordEvent(const G4Event*); virtual void RecordEvent(const G4Event*); private: private: G4int nEvent; G4int nEvent; G4int totalSurfFluxID, protonSurfFluxID, totalDoseID; G4int totalSurfFluxID, protonSurfFluxID, totalDoseID; G4THitsMap totalSurfFlux; G4THitsMap totalSurfFlux; G4THitsMap protonSurfFlux; G4THitsMap protonSurfFlux; G4THitsMap totalDose; G4THitsMap totalDose; G4THitsMap * eventTotalSurfFlux; G4THitsMap * eventTotalSurfFlux; G4THitsMap * eventProtonSurfFlux; G4THitsMap * eventProtonSurfFlux; G4THitsMap * eventTotalDose G4THitsMap * eventTotalDose public: public: … access methods … … access methods …}; Implement how you accumulate event data

18 182006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Customized run class MyRun::MyRun() : nEvent(0) { G4SDManager* SDM = G4SDManager::GetSDMpointer(); G4SDManager* SDM = G4SDManager::GetSDMpointer(); totalSurfFluxID = SDM->GetCollectionID("myCellScorer/"); totalSurfFluxID = SDM->GetCollectionID("myCellScorer/TotalSurfFlux"); protonSurfFluxID = SDM->GetCollectionID("myCellScorer/Proton"); protonSurfFluxID = SDM->GetCollectionID("myCellScorer/ProtonSurfFlux"); totalDoseID = SDM->GetCollectionID("myCellScorer/"); totalDoseID = SDM->GetCollectionID("myCellScorer/TotalDose");} void MyRun::RecordEvent(const G4Event* evt) { nEvent++; nEvent++; G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); eventTotalSurfFlux = (G4THitsMap *)(HCE->GetHC(totalSurfFluxID)); eventTotalSurfFlux = (G4THitsMap *)(HCE->GetHC(totalSurfFluxID)); eventProtonSurfFlux = (G4THitsMap *)(HCE->GetHC(protonSurfFluxID)); eventProtonSurfFlux = (G4THitsMap *)(HCE->GetHC(protonSurfFluxID)); eventTotalDose = (G4THitsMap *)(HCE->GetHC(totalDose)); eventTotalDose = (G4THitsMap *)(HCE->GetHC(totalDose)); totalSurfFlux += *eventTotalSurfFlux; totalSurfFlux += *eventTotalSurfFlux; protonSurfFlux += *eventProtonSurfFlux; protonSurfFlux += *eventProtonSurfFlux; totalDose += *eventTotalDose; totalDose += *eventTotalDose;} name of G4MultiFunctionalDetector object name of G4VPrimitiveScorer object No need of loops. += operator is provided !

19 192006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT RunAction with customized run G4Run* MyRunAction::GenerateRun() { return (new MyRun()); } void MyRunAction::EndOfRunAction(const G4Run* aRun) { MyRun* theRun = (MyRun*)aRun; MyRun* theRun = (MyRun*)aRun; // … analyze / record / print-out your run summary // … analyze / record / print-out your run summary // MyRun object has everything you need … // MyRun object has everything you need …} As you have seen, to accumulate event data, you do NOT need Event / tracking / stepping action classes Event / tracking / stepping action classes All you need are your Run and RunAction classes. With newly introducing concrete sensitivity classes, you do NOT even need Sensitive detector implementation Sensitive detector implementation Refer to exampleN07

20 202006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Accessing to a hits map for Run/Event Summary G4THitsMap is an STL map, mapping a key (G4int) to a pointer to a double value, i.e. equivalent to. G4THitsMap is an STL map, mapping a key (G4int) to a pointer to a double value, i.e. equivalent to std::map. G4HCofThisEvent* HCE = evt->GetHCofThisEvent(); G4THitsMap * evtMap = (G4THitsMap *)(HCE->GetHC(colID)); To get number of entries G4int n = evtMap->entries(); To access to each entry sequentially std::map ::iterator itr = evtMap->GetMap()->begin(); for( ; itr!=evtMap->GetMap()->end(); itr++ ) { G4int key = (itr->first); G4double val = *(itr->second); } To access to a double value with a key G4double* pVal = (*evtMap)[key]; If(pVal) val = *pVal; Null pointer is returned if the key does not exist in the map. Pointer is returned.

21 212006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Summary Geant4 offers G4VSensitiveDetector scorer. There are two sort of choice for users, There are two sort of choice for users, Base classes for user developments Primitive scorer classes for rapid developments A part of this development was supported by JST CREST. A part of this development was supported by JST CREST. User can make a choice according to the needs, E.g. life cycle of application, developing skill, etc.. Future works We are still working to improve primitive scorers for more efficient scoring. We are still working to improve primitive scorers for more efficient scoring. Requirements from users are very welcome. We will involve it to future release. Requirements from users are very welcome. We will involve it to future release.

22 222006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT Keys of G4THitsMap All provided primitive scorer classes use G4THitsMap. By default, the copy number is taken from the physical volume to which G4MultiFunctionalDetector is assigned. If the physical volume is placed only once, but its (grand-)mother volume is replicated, use the second argument of the constructor of the primitive scorer to indicate the level where the copy number should be taken. If the physical volume is placed only once, but its (grand-)mother volume is replicated, use the second argument of the constructor of the primitive scorer to indicate the level where the copy number should be taken. e.g. G4PSCellFlux(G4Steing name, G4int depth=0) See exampleN07 If your indexing scheme is more complicated (e.g. utilizing copy numbers of more than one hierarchies), you can override the virtual method GetIndex() provided for all the primitive scorers. (v8.x example RE02 will show you.) If your indexing scheme is more complicated (e.g. utilizing copy numbers of more than one hierarchies), you can override the virtual method GetIndex() provided for all the primitive scorers. (v8.x example RE02 will show you.) CopyNo 0 Copy No 0 CopyNo 0 Copy No 0 CopyNo 0 Copy No 0 Copy No 0 Copy No 1Copy No 2 Scorer A Scorer B Key should be taken from upper geometry hierarchy


Download ppt "2006/11/10 Pasadena GEANT4-SPENVIS, Tsukasa Aso, TNCMT 1 Scorer and Sensitive Detector Filter Tsukasa Aso Toyama National College of Maritime Technology,"

Similar presentations


Ads by Google