Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ScoreSpecies Class Reference

#include <ScoreSpecies.hh>

Inheritance diagram for ScoreSpecies:
Collaboration diagram for ScoreSpecies:

Classes

struct  SpeciesInfo
 

Public Member Functions

 ScoreSpecies (G4String name, G4int depth=0)
 
virtual ~ScoreSpecies ()
 
void AddTimeToRecord (double time)
 
void ClearTimeToRecord ()
 
int GetNumberOfRecordedEvents () const
 
void ASCII ()
 
void WriteWithAnalysisManager (G4VAnalysisManager *)
 
virtual void Initialize (G4HCofThisEvent *)
 
virtual void EndOfEvent (G4HCofThisEvent *)
 
virtual void clear ()
 
virtual void DrawAll ()
 
virtual void PrintAll ()
 
virtual void AbsorbResultsFromWorkerScorer (G4VPrimitiveScorer *)
 
virtual void OutputAndClear ()
 
SpeciesMap GetSpeciesInfo ()
 
- Public Member Functions inherited from G4VPrimitiveScorer
 G4VPrimitiveScorer (G4String name, G4int depth=0)
 
virtual ~G4VPrimitiveScorer ()
 
G4int GetCollectionID (G4int)
 
void SetUnit (const G4String &unit)
 
const G4StringGetUnit () const
 
G4double GetUnitValue () const
 
void SetMultiFunctionalDetector (G4MultiFunctionalDetector *d)
 
G4MultiFunctionalDetectorGetMultiFunctionalDetector () const
 
G4String GetName () const
 
void SetFilter (G4VSDFilter *f)
 
G4VSDFilterGetFilter () const
 
void SetVerboseLevel (G4int vl)
 
G4int GetVerboseLevel () const
 
void SetNijk (G4int i, G4int j, G4int k)
 

Protected Member Functions

virtual G4bool ProcessHits (G4Step *, G4TouchableHistory *)
 
- Protected Member Functions inherited from G4VPrimitiveScorer
virtual G4int GetIndex (G4Step *)
 
void CheckAndSetUnit (const G4String &unit, const G4String &category)
 

Additional Inherited Members

- Protected Attributes inherited from G4VPrimitiveScorer
G4String primitiveName
 
G4MultiFunctionalDetectordetector
 
G4VSDFilterfilter
 
G4int verboseLevel
 
G4int indexDepth
 
G4String unitName
 
G4double unitValue
 
G4int fNi
 
G4int fNj
 
G4int fNk
 

Detailed Description

This is a primitive scorer class for molecular species. The number of species is recorded for all times (predetermined or user chosen). It also scores the energy deposition in order to compute the radiochemical yields.

Definition at line 56 of file ScoreSpecies.hh.

Constructor & Destructor Documentation

ScoreSpecies::ScoreSpecies ( G4String  name,
G4int  depth = 0 
)

Definition at line 62 of file ScoreSpecies.cc.

63 : G4VPrimitiveScorer(name,depth),
64  fEdep(0),
65  fOutputToRoot(true),
66  fOutputToXml(false),
67  fOutputToCsv(false),
68  fHCID(-1),
69  fEvtMap(0)
70 {
71  fNEvent = 0;
79  fEdep = 0;
80 }
static constexpr double picosecond
void AddTimeToRecord(double time)
Definition: ScoreSpecies.hh:65
G4VPrimitiveScorer(G4String name, G4int depth=0)

Here is the call graph for this function:

ScoreSpecies::~ScoreSpecies ( )
virtual

Definition at line 84 of file ScoreSpecies.cc.

85 {;}

Member Function Documentation

void ScoreSpecies::AbsorbResultsFromWorkerScorer ( G4VPrimitiveScorer workerScorer)
virtual

Method used in multithreading mode in order to merge the results

Definition at line 198 of file ScoreSpecies.cc.

199 {
201  dynamic_cast<ScoreSpecies*>(dynamic_cast<G4VPrimitiveScorer*>(workerScorer));
202 
203  if(right == 0)
204  {
205  return;
206  }
207  if(right == this)
208  {
209  return;
210  }
211 
212  // G4cout<<"ScoreSpecies::AbsorbResultsFromWorkerScorer"<<G4endl;
213  {
214  SpeciesMap::iterator it_map1 = right->fSpeciesInfoPerTime.begin();
215  SpeciesMap::iterator end_map1 = right->fSpeciesInfoPerTime.end();
216 
217  for(; it_map1 != end_map1; ++it_map1)
218  {
219  InnerSpeciesMap& map2 = it_map1->second;
220  InnerSpeciesMap::iterator it_map2 = map2.begin();
221  InnerSpeciesMap::iterator end_map2 = map2.end();
222 
223  for(; it_map2 != end_map2; ++it_map2)
224  {
225  SpeciesInfo& molInfo =
226  fSpeciesInfoPerTime[it_map1->first][it_map2->first] ;
227  molInfo.fNumber += it_map2->second.fNumber;
228  molInfo.fG += it_map2->second.fG;
229  molInfo.fG2 += it_map2->second.fG2;
230 
231  // G4cout << "In AbsorbeResultsFromWorkerScorer: fNumber "
232  // << molInfo.fNumber
233  // << " fG "
234  // << molInfo.fG
235  // << G4endl;
236  }
237  }
238  }
239  //---------------------------------------------------------
240 #ifdef _ScoreSpecies_FOR_ALL_EVENTS
241  {
242  SpeciesMapPerEvent::iterator it_map1 = right->fSpeciesInfoPerEvent.begin();
243  SpeciesMapPerEvent::iterator end_map1 = right->fSpeciesInfoPerEvent.end();
244 
245  for(; it_map1 != end_map1; ++it_map1)
246  {
247  auto& map2 = it_map1->second;
248  InnerSpeciesMapPerEvent::iterator it_map2 = map2.begin();
249  InnerSpeciesMapPerEvent::iterator end_map2 = map2.end();
250 
251  for(; it_map2 != end_map2; ++it_map2)
252  {
253  SpeciesInfoSOA& molInfo =
254  fSpeciesInfoPerEvent[it_map1->first][it_map2->first] ;
255  molInfo.fNumber.insert(molInfo.fNumber.end(),
256  it_map2->second.fNumber.begin(),
257  it_map2->second.fNumber.end());
258  molInfo.fG.insert(molInfo.fG.end(),
259  it_map2->second.fG.begin(),
260  it_map2->second.fG.end());
261  molInfo.fG2.insert(molInfo.fG2.end(),
262  it_map2->second.fG2.begin(),
263  it_map2->second.fG2.end());
264  molInfo.fEventID.insert(molInfo.fEventID.end(),
265  it_map2->second.fEventID.begin(),
266  it_map2->second.fEventID.end());
267  // G4cout << "In AbsorbeResultsFromWorkerScorer: fNumber "
268  // << molInfo.fNumber
269  // << " fG "
270  // << molInfo.fG
271  // << G4endl;
272  }
273  }
274  right->fSpeciesInfoPerEvent.clear();
275  }
276 #endif
277 
278  fNEvent += right->fNEvent;
279  right->fNEvent = 0;
280  right->fEdep = 0.;
281 }
virtual void clear()
std::vector< double > fG
Definition: plotG.cc:149

Here is the call graph for this function:

void ScoreSpecies::AddTimeToRecord ( double  time)
inline

Add a time at which the number of species should be recorded. Default times are set up to 1 microsecond.

Definition at line 65 of file ScoreSpecies.hh.

66  {
67  fTimeToRecord.insert(time);
68  }

Here is the caller graph for this function:

void ScoreSpecies::ASCII ( )

Write results to an text file

Definition at line 319 of file ScoreSpecies.cc.

320 {
321  std::ofstream out("Species.Txt");
322  if(!out) return;
323 
324  out << "Time is in ns" << G4endl;
325 
326  for(auto it_map1: fSpeciesInfoPerTime)
327  {
328  InnerSpeciesMap& map2 = it_map1.second;
329 
330  out << it_map1.first << G4endl;
331 
332  for(auto it_map2: map2)
333  {
334  out << it_map2.first->GetName()<< " "
335  << it_map2.second.fNumber << G4endl;
336  }
337  }
338 
339  out.close();
340 }
#define G4endl
Definition: G4ios.hh:61
void ScoreSpecies::clear ( void  )
virtual

Reimplemented from G4VPrimitiveScorer.

Definition at line 285 of file ScoreSpecies.cc.

286 {
287  fEvtMap->clear();
288  fNEvent = 0;
289  fEdep = 0;
290  fSpeciesInfoPerTime.clear();
291 }
void clear()
Definition: G4THitsMap.hh:267

Here is the call graph for this function:

Here is the caller graph for this function:

void ScoreSpecies::ClearTimeToRecord ( )
inline

Remove all times to record, must be reset by user.

Definition at line 71 of file ScoreSpecies.hh.

72  {
73  fTimeToRecord.clear();
74  }
void ScoreSpecies::DrawAll ( void  )
virtual

Reimplemented from G4VPrimitiveScorer.

Definition at line 295 of file ScoreSpecies.cc.

296 {;}
void ScoreSpecies::EndOfEvent ( G4HCofThisEvent )
virtual

Reimplemented from G4VPrimitiveScorer.

Definition at line 120 of file ScoreSpecies.cc.

121 {
122  if(G4EventManager::GetEventManager()->GetConstCurrentEvent()->IsAborted())
123  {
124  fEdep = 0.;
126  return;
127  }
128 
130 
131  if(species.get() == 0 || species->size() == 0)
132  {
133  G4cout << "No molecule recorded, energy deposited= "
134  << G4BestUnit(fEdep, "Energy") << G4endl;
135  ++fNEvent;
136  fEdep = 0.;
138  return;
139  }
140 
141  // G4cout << "ScoreSpecies::EndOfEvent"<<G4endl;
142 // G4cout << "End of event, deposited energy: "
143 // << G4BestUnit(fEdep, "Energy") << G4endl;
144 
145 #ifdef _ScoreSpecies_FOR_ALL_EVENTS
146  int eventID=
148 #endif
149 
150  for(auto molecule: *species)
151  {
152  for(auto time_mol: fTimeToRecord)
153  {
154  double n_mol =
156  time_mol);
157 
158  if(n_mol < 0)
159  {
160  G4cerr << "N molecules not valid < 0 " << G4endl;
161  G4Exception("","N<0",FatalException,"");
162  }
163 
164  SpeciesInfo& molInfo =
165  fSpeciesInfoPerTime[time_mol][molecule];
166  molInfo.fNumber += n_mol;
167  double gValue = (n_mol/(fEdep/eV)) * 100.;
168  molInfo.fG += gValue;
169  molInfo.fG2 += gValue*gValue;
170 
171 #ifdef _ScoreSpecies_FOR_ALL_EVENTS
172  SpeciesInfoSOA& molInfoPerEvent =
173  fSpeciesInfoPerEvent[time_mol][molecule];
174  molInfoPerEvent.fNumber.push_back(n_mol);
175  molInfoPerEvent.fG.push_back(gValue);
176  molInfoPerEvent.fG2.push_back(gValue*gValue);
177  molInfoPerEvent.fEventID.push_back(eventID);
178 #endif
179  // G4cout << "In Save molucule: fNumber " << molInfo.fNumber
180  // << " fG " << molInfo.fG
181  // << " fEdep " << fEdep/eV
182  // << G4endl;
183  }
184  }
185 
186  ++fNEvent;
187 
188 // G4cout << "End of event " << fNEvent
189 // << ", energy deposited=" << G4BestUnit(fEdep, "Energy") << G4endl;
190 
191  fEdep = 0.;
193 }
void ResetCounter() override
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
int GetNMoleculesAtTime(G4MolecularConfiguration *molecule, double time)
G4int GetEventID() const
Definition: G4Event.hh:151
RecordedMolecules GetRecordedMolecules()
G4GLOB_DLL std::ostream G4cout
static G4MoleculeCounter * Instance()
static constexpr double eV
Definition: G4SIunits.hh:215
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4EventManager * GetEventManager()
#define G4endl
Definition: G4ios.hh:61
const G4Event * GetConstCurrentEvent()
G4GLOB_DLL std::ostream G4cerr
std::vector< double > fG
Definition: plotG.cc:149

Here is the call graph for this function:

int ScoreSpecies::GetNumberOfRecordedEvents ( ) const
inline

Get number of recorded events

Definition at line 77 of file ScoreSpecies.hh.

78  {
79  return fNEvent;
80  }
SpeciesMap ScoreSpecies::GetSpeciesInfo ( )
inline

Definition at line 181 of file ScoreSpecies.hh.

181 {return fSpeciesInfoPerTime;}
void ScoreSpecies::Initialize ( G4HCofThisEvent HCE)
virtual

Reimplemented from G4VPrimitiveScorer.

Definition at line 105 of file ScoreSpecies.cc.

106 {
108  GetName());
109 
110  if(fHCID < 0)
111  {
112  fHCID = GetCollectionID(0);
113  }
114 
115  HCE->AddHitsCollection(fHCID, (G4VHitsCollection*)fEvtMap);
116 }
G4String GetName() const
G4MultiFunctionalDetector * GetMultiFunctionalDetector() const
G4int GetCollectionID(G4int)
void AddHitsCollection(G4int HCID, G4VHitsCollection *aHC)

Here is the call graph for this function:

void ScoreSpecies::OutputAndClear ( )
virtual

Definition at line 344 of file ScoreSpecies.cc.

345 {
346  if(G4Threading::IsWorkerThread()) return;
347 
348  //----------------------------------------------------------------------------
349  // Save results
350 
351  G4VAnalysisManager* analysisManager(0);
352 
353  if(fOutputToCsv)
354  {
355  analysisManager = G4CsvAnalysisManager::Instance(); // TODO?
356  // this->ASCII(); // useful ?
357  }
358  else if (fOutputToRoot)
359  {
360  analysisManager = G4Root::G4AnalysisManager::Instance();
361  }
362  else if(fOutputToXml)
363  {
364  analysisManager = G4Xml::G4AnalysisManager::Instance();
365 
366  }
367  if(analysisManager)
368  {
369  this->WriteWithAnalysisManager(analysisManager);
370  }
371 
372  fNEvent = 0;
373  fSpeciesInfoPerTime.clear();
374 }
void WriteWithAnalysisManager(G4VAnalysisManager *)
static G4XmlAnalysisManager * Instance()
static G4CsvAnalysisManager * Instance()
G4bool IsWorkerThread()
Definition: G4Threading.cc:145
static G4RootAnalysisManager * Instance()

Here is the call graph for this function:

void ScoreSpecies::PrintAll ( void  )
virtual

Reimplemented from G4VPrimitiveScorer.

Definition at line 300 of file ScoreSpecies.cc.

301 {
302  G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
303  G4cout << " PrimitiveScorer " << GetName() << G4endl;
304  G4cout << " Number of events " << fNEvent << G4endl;
305  G4cout << " Number of energy deposition recorded "
306  << fEvtMap->entries() << G4endl;
307 
308  for(auto itr : *fEvtMap->GetMap()) {
309  G4cout << " copy no.: " << itr.first
310  << " energy deposit: "
311  << *(itr.second)/GetUnitValue()
312  << " [" << GetUnit()<<"]"
313  << G4endl;
314  }
315 }
G4String GetName() const
G4GLOB_DLL std::ostream G4cout
G4double GetUnitValue() const
G4int entries() const
Definition: G4THitsMap.hh:200
std::map< G4int, T * > * GetMap() const
Definition: G4THitsMap.hh:99
#define G4endl
Definition: G4ios.hh:61
G4MultiFunctionalDetector * detector
const G4String & GetUnit() const

Here is the call graph for this function:

G4bool ScoreSpecies::ProcessHits ( G4Step aStep,
G4TouchableHistory  
)
protectedvirtual

Implements G4VPrimitiveScorer.

Definition at line 89 of file ScoreSpecies.cc.

90 {
91  G4double edep = aStep->GetTotalEnergyDeposit();
92 
93  if ( edep == 0. ) return FALSE;
94 
95  edep *= aStep->GetPreStepPoint()->GetWeight(); // (Particle Weight)
96  G4int index = GetIndex(aStep);
97  fEvtMap->add(index,edep);
98  fEdep+=edep;
99 
100  return TRUE;
101 }
G4double GetWeight() const
int G4int
Definition: G4Types.hh:78
G4StepPoint * GetPreStepPoint() const
#define FALSE
Definition: globals.hh:52
virtual G4int GetIndex(G4Step *)
#define TRUE
Definition: globals.hh:55
G4double GetTotalEnergyDeposit() const
G4int add(const G4int &key, T *&aHit) const
Definition: G4THitsMap.hh:106
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

void ScoreSpecies::WriteWithAnalysisManager ( G4VAnalysisManager analysisManager)

Write results to whatever chosen file format

Definition at line 379 of file ScoreSpecies.cc.

380 {
381  // G4cout << "ScoreSpecies::WriteWithAnalysisManager" << G4endl;
382  analysisManager->OpenFile("Species.root");
383  int fNtupleID = analysisManager->CreateNtuple("species", "species");
384  analysisManager->CreateNtupleIColumn(fNtupleID, "speciesID");
385  analysisManager->CreateNtupleIColumn(fNtupleID, "number");
386  analysisManager->CreateNtupleIColumn(fNtupleID, "nEvent");
387  analysisManager->CreateNtupleSColumn(fNtupleID, "speciesName");
388  analysisManager->CreateNtupleDColumn(fNtupleID, "time");
389  analysisManager->CreateNtupleDColumn(fNtupleID, "sumG");
390  analysisManager->CreateNtupleDColumn(fNtupleID, "sumG2");
391  analysisManager->FinishNtuple(fNtupleID);
392 
393  for(auto it_map1: fSpeciesInfoPerTime)
394  {
395  InnerSpeciesMap& map2 = it_map1.second;
396 
397  for(auto it_map2 : map2)
398  {
399  double time = it_map1.first;
400  const Species& species = it_map2.first;
401  const G4String& name = species->GetName();
402  int molID = it_map2.first->GetMoleculeID();
403  int number = it_map2.second.fNumber;
404  double G = it_map2.second.fG;
405  double G2 = it_map2.second.fG2;
406 
407  analysisManager->FillNtupleIColumn(fNtupleID, 0, molID); // MolID
408  analysisManager->FillNtupleIColumn(fNtupleID, 1, number); // Number
409  analysisManager->FillNtupleIColumn(fNtupleID,
410  2, fNEvent); // Total nb events
411  analysisManager->FillNtupleSColumn(fNtupleID, 3, name); // molName
412  analysisManager->FillNtupleDColumn(fNtupleID, 4, time); // time
413  analysisManager->FillNtupleDColumn(fNtupleID, 5, G); // G
414  analysisManager->FillNtupleDColumn(fNtupleID, 6, G2); // G2
415  analysisManager->AddNtupleRow(fNtupleID);
416  }
417  }
418 
419  //----------------------------------------------------------------------------
420 
421 #ifdef _ScoreSpecies_FOR_ALL_EVENTS
422  fNtupleID = analysisManager->CreateNtuple("species_all", "species_all");
423  analysisManager->CreateNtupleIColumn(fNtupleID, "speciesID");
424  analysisManager->CreateNtupleIColumn(fNtupleID, "number");
425  analysisManager->CreateNtupleIColumn(fNtupleID, "nEvent");
426  analysisManager->CreateNtupleSColumn(fNtupleID, "speciesName");
427  analysisManager->CreateNtupleDColumn(fNtupleID, "time");
428  analysisManager->CreateNtupleDColumn(fNtupleID, "G");
429  analysisManager->CreateNtupleDColumn(fNtupleID, "G2");
430  analysisManager->CreateNtupleIColumn(fNtupleID, "eventID");
431  analysisManager->FinishNtuple(fNtupleID);
432 
433  for(auto it_map1: fSpeciesInfoPerEvent)
434  {
435  InnerSpeciesMapPerEvent& map2 = it_map1.second;
436 
437  for(auto it_map2 : map2)
438  {
439  double time = it_map1.first;
440  const Species& species = it_map2.first;
441  const G4String& name = species->GetName();
442  int molID = it_map2.first->GetMoleculeID();
443 
444  size_t nG = it_map2.second.fG.size();
445 
446  for(size_t i=0; i<nG;++i){
447  int number = it_map2.second.fNumber[i];
448  double G = it_map2.second.fG[i];
449  double G2 = it_map2.second.fG2[i];
450  int eventID = it_map2.second.fEventID[i];
451 
452  analysisManager->FillNtupleIColumn(fNtupleID, 0, molID); // MolID
453  analysisManager->FillNtupleIColumn(fNtupleID, 1, number); // Number
454  analysisManager->FillNtupleIColumn(fNtupleID,
455  2, fNEvent); // Total nb events
456  analysisManager->FillNtupleSColumn(fNtupleID, 3, name); // molName
457  analysisManager->FillNtupleDColumn(fNtupleID, 4, time); // time
458  analysisManager->FillNtupleDColumn(fNtupleID, 5, G); // G
459  analysisManager->FillNtupleDColumn(fNtupleID, 6, G2); // G2
460  analysisManager->FillNtupleIColumn(fNtupleID, 7, eventID); // EventID
461  analysisManager->AddNtupleRow(fNtupleID);
462  }
463  }
464  }
465 #endif
466 
467  analysisManager->Write();
468  analysisManager->CloseFile();
469 }
const XML_Char * name
Definition: expat.h:151
G4int CreateNtupleIColumn(const G4String &name)
G4bool FillNtupleSColumn(G4int id, const G4String &value)
G4int first(char) const
G4int CreateNtuple(const G4String &name, const G4String &title)
G4int CreateNtupleSColumn(const G4String &name)
G4bool OpenFile(const G4String &fileName="")
G4bool FillNtupleIColumn(G4int id, G4int value)
G4bool FillNtupleDColumn(G4int id, G4double value)
G4int CreateNtupleDColumn(const G4String &name)

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: