ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
STCyclotronRun.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file STCyclotronRun.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // Author: F. Poignant, floriane.poignant@gmail.com
27 //
28 // file STCyclotronRun.cc
29 
30 #include "STCyclotronRun.hh"
31 #include "STCyclotronAnalysis.hh"
32 #include "G4RunManager.hh"
33 #include "G4Event.hh"
34 
35 #include "G4SDManager.hh"
36 #include "G4HCofThisEvent.hh"
37 #include "G4THitsMap.hh"
38 #include "G4SystemOfUnits.hh"
39 
41  : G4Run(),fTotalEnergyDepositTarget(0.),fTotalEnergyDepositFoil(0.),fParticleTarget(0),fTargetThickness(0.),fTargetDiameter(0.),fFoilThickness(0.),fTargetVolume(0.),fFoilVolume(0.),fPrimariesPerEvent(0),fTimePerEvent(0),fBeamName(""),fBeamCurrent(0.),fBeamEnergy(0.)
42 { }
43 
45 { }
46 
47 void STCyclotronRun::Merge(const G4Run* aRun)
48 {
49 
50  const STCyclotronRun* localRun = static_cast<const STCyclotronRun*>(aRun);
51 
52  //Merging cumulable variables
55  fParticleTarget += localRun->fParticleTarget;
56 
57  //Constant over the different runs
58  if(localRun->fTargetVolume!=0)fTargetVolume = localRun->fTargetVolume;
59  if(localRun->fFoilVolume!=0)fFoilVolume = localRun->fFoilVolume;
60  if(localRun->fPrimariesPerEvent!=0)fPrimariesPerEvent = localRun->fPrimariesPerEvent;
61  if(localRun->fTimePerEvent!=0)fTimePerEvent = localRun->fTimePerEvent;
62  if(localRun->fTargetThickness!=0)fTargetThickness = localRun->fTargetThickness;
63  if(localRun->fTargetDiameter!=0)fTargetDiameter = localRun->fTargetDiameter;
64  if(localRun->fFoilThickness!=0)fFoilThickness = localRun->fFoilThickness;
65  fBeamName = localRun->fBeamName;
66  if(localRun->fBeamCurrent!=0.)fBeamCurrent = localRun->fBeamCurrent;
67  if(localRun->fBeamEnergy!=0.)fBeamEnergy = localRun->fBeamEnergy;
68 
69 
70 
71  //<<<----toMerge
72  std::map<G4String,G4int>::iterator itSI;
73  std::map<G4String,G4double>::iterator itSD;
74  std::map<G4String,G4String>::iterator itSS;
75  std::map<G4int,G4String>::iterator itIS;
76 
77  //----Merging results for primary isotopes
78  std::map<G4String,G4int> locPrimaryIsotopeCountTarget = localRun->fPrimaryIsotopeCountTarget;
79  for (itSI = locPrimaryIsotopeCountTarget.begin(); itSI != locPrimaryIsotopeCountTarget.end(); itSI++)
80  {
81  G4String name = itSI->first;
82  G4int count = itSI->second;
84  }
85 
86  std::map<G4String,G4double> locPrimaryIsotopeTimeTarget = localRun->fPrimaryIsotopeTimeTarget;
87  for (itSD = locPrimaryIsotopeTimeTarget.begin(); itSD != locPrimaryIsotopeTimeTarget.end(); itSD++)
88  {
89  G4String name = itSD->first;
90  G4double time = itSD->second;
92  }
93 
94  //----Merging results for decay isotopes
95  // std::map<G4int,G4String> fIsotopeIDTarget;
96  std::map<G4String,G4String> locDecayIsotopeCountTarget = localRun->fDecayIsotopeCountTarget;
97  for (itSS = locDecayIsotopeCountTarget.begin(); itSS != locDecayIsotopeCountTarget.end(); itSS++)
98  {
99  G4String nameDaughter = itSS->first;
100  G4String mum = itSS->second;
101  fDecayIsotopeCountTarget[nameDaughter] = mum;
102  }
103  std::map<G4String,G4double> locDecayIsotopeTimeTarget = localRun->fDecayIsotopeTimeTarget;
104  for (itSD = locDecayIsotopeTimeTarget.begin(); itSD != locDecayIsotopeTimeTarget.end(); itSD++)
105  {
106  G4String nameDaughter = itSD->first;
107  G4double time = itSD->second;
108  fDecayIsotopeTimeTarget[nameDaughter] = time;
109  }
110  std::map<G4String,G4String> locParticleParent = localRun->fParticleParent;
111  for (itSS = locParticleParent.begin(); itSS != locParticleParent.end(); itSS++)
112  {
113  G4String nameDaughter = itSS->first;
114  G4String parent = itSS->second;
115  fParticleParent[nameDaughter] = parent;
116  }
117  std::map<G4int,G4String> locIsotopeIDTarget = localRun->fIsotopeIDTarget;
118  for (itIS = locIsotopeIDTarget.begin(); itIS != locIsotopeIDTarget.end(); itIS++)
119  {
120  G4int ID = itIS->first;
121  G4String name = itIS->second;
122  fIsotopeIDTarget[ID] = name;
123  }
124 
125 
126  //----Merging results for stable isotopes
127  std::map<G4String,G4int> locStableIsotopeCountTarget = localRun->fStableIsotopeCountTarget;
128  for (itSI = locStableIsotopeCountTarget.begin(); itSI != locStableIsotopeCountTarget.end(); itSI++)
129  {
130  G4String name = itSI->first;
131  G4int count = itSI->second;
133  }
134 
135  //----Merging results for particles
136  std::map<G4String,G4int> locParticleCountTarget = localRun->fParticleCountTarget;
137  for (itSI = locParticleCountTarget.begin(); itSI != locParticleCountTarget.end(); itSI++)
138  {
139  G4String name = itSI->first;
140  G4int count = itSI->second;
141  fParticleCountTarget[name] += count;
142  }
143 
144 
145  G4Run::Merge(aRun);
146 
147 }
148 
149 void STCyclotronRun::EndOfRun(G4double irradiationTime)
150 {
151 
152  G4int nbEvents = GetNumberOfEvent();
153 
154  if (nbEvents == 0) return;
155 
156  //------------------------------------------------------
157  // Opening the ASCII file
158  //------------------------------------------------------
159  fOutPut.open("Output_General.txt",std::ofstream::out);
160  fOutPut1.open("Output_ParentIsotopes.txt",std::ofstream::out);
161  fOutPut2.open("Output_DaughterIsotopes.txt",std::ofstream::out);
162  fOutPut3.open("Output_OtherParticles.txt",std::ofstream::out);
163  fOutPut4.open("Output_StableIsotopes.txt",std::ofstream::out);
164 
165  //------------------------------------------------------
166  // Calculates the equivalent time for a given run
167  //------------------------------------------------------
168  G4double timePerEvent = fTimePerEvent; //in seconds
169  G4double timeForARun = nbEvents*timePerEvent; //in seconds
170  G4double minDecay = 0.0001; //in seconds
171  G4double maxDecay = 1000000.; //in seconds
172 
173  //------------------------------------------------------
174  // Rescale the value of the beam current to account for
175  // the loss of primary particles due to the foil.
176  //------------------------------------------------------
177 
178  G4int totalPrimaries = fPrimariesPerEvent*nbEvents;
179  G4double currentFactor;
180  if(fParticleTarget>0.) currentFactor =(fParticleTarget*1.)/(totalPrimaries*1.);
181  else currentFactor = 0.;
182 
183 
184  fOutPut << "//-----------------------------------//" << G4endl;
185  fOutPut << "// Parameters of the simulation: //" << G4endl;
186  fOutPut << "//-----------------------------------//" << G4endl;
187  fOutPut << "Beam parameters: " << G4endl;
188  fOutPut << fBeamName << " - Name of beam primary particles." << G4endl;
189  fOutPut << fBeamEnergy << " - Energy of beam primary particles (MeV)." << G4endl;
190  fOutPut << fBeamCurrent << " - Beam current (Ampere)." << G4endl;
191  fOutPut << irradiationTime << " - Irradiation time in hour(s)." << G4endl;
192  fOutPut << currentFactor << " - Current factor." << G4endl;
193  fOutPut << "//-----------------------------------//" << G4endl;
194  fOutPut << "Simulation parameters: " << G4endl;
195  fOutPut << timePerEvent << " - Equivalent time per event (s)." << G4endl;
196  fOutPut << nbEvents << " - Number of events" << G4endl;
197  fOutPut << fPrimariesPerEvent << " - Primaries per event" << G4endl;
198  fOutPut << fPrimariesPerEvent*nbEvents << " - Total number of particles sent." << G4endl;
199  fOutPut << "//-----------------------------------//" << G4endl;
200  fOutPut << "Geometry parameters: " << G4endl;
201  fOutPut << fTargetThickness << " - target thickness (mm)." << G4endl;
202  fOutPut << fTargetDiameter << " - target diameter (mm)." << G4endl;
203  fOutPut << fFoilThickness << " - foil thickness (mm)." << G4endl;
204  //Add particle type, particle energy, beam diameter, beam current
205 
206  //target material???
207 
211 
212 
213  //Maps to fill
214  std::map<G4String,G4double> fPrimaryIsotopeEOBTarget;
215  std::map<G4String,G4double> fPrimaryActivityTarget;
216  std::map<G4String,G4double> fDecayIsotopeEOBTarget;
217  std::map<G4String,G4double> fDecayActivityTarget;
218 
219 
220  //----------------------------------------------
221  // CASE 1 : Parent isotopes
222  //----------------------------------------------
223 
224 
225  std::map<G4String,G4int>::iterator it;
226  G4double primaryActivityTotal = 0.;
227  G4double decayActivityTotal=0.;
228 
229  fOutPut1 << "//-----------------------------------//\n"
230  << "// Data for parent isotopes //\n"
231  << "//-----------------------------------//\n" << G4endl;
232 
233  for (it = fPrimaryIsotopeCountTarget.begin(); it != fPrimaryIsotopeCountTarget.end(); it++)
234  {
235 
236 
237  G4String name = it->first;
238  G4double count = (it->second)*currentFactor;
239  G4double halfLifeTime = fPrimaryIsotopeTimeTarget[name]*10E-10/3600.*std::log(2.);
240  G4String process = fParticleParent[name];
241 
242  //Only store isotopes with a life time between minDecay and maxDecay.
243  G4bool store;
244  if(halfLifeTime > minDecay && halfLifeTime < maxDecay) store = true;
245  else store = false;
246 
247 
248  //Calculation of the yield (s-1)
249  G4double decayConstant = 1/(fPrimaryIsotopeTimeTarget[name]*10E-10);
250 
251 
252  //----------------------------------------------
253  // Number of particles per second
254  //----------------------------------------------
255 
256  G4double particlesPerSecond = fPrimaryIsotopeCountTarget[name]*currentFactor/timeForARun;
257 
258  //----------------------------------------------
259  // Calculation yield EOB
260  //----------------------------------------------
261 
262  fPrimaryIsotopeEOBTarget[name] = particlesPerSecond/decayConstant * (1. - std::exp(-irradiationTime*3600*decayConstant));
263 
264  //----------------------------------------------
265  // Calculation of the activity
266  // conversion factor Bq to mCi
267  //----------------------------------------------
268 
269  G4double conv = 2.7E-8;
270  fPrimaryActivityTarget[name]= fPrimaryIsotopeEOBTarget[name]*decayConstant*conv;
271 
272  if(store)
273  {
274 
275  //----------------------------------------------
276  // Incrementation for total primary activity
277  //----------------------------------------------
278 
279  primaryActivityTotal = primaryActivityTotal + fPrimaryActivityTarget[name];
280  }
281 
282 
283  //---------------------------//
284  // Printing out results //
285  //---------------------------//
286 
287  if(store)
288  {
289  fOutPut1 << name << " - name of parent isotope." << G4endl;
290  fOutPut1 << count/currentFactor << " - number of isotopes created during the simulation." << G4endl;
291  fOutPut1 << decayConstant << " - decay constant in s-1." << G4endl;
292  fOutPut1 << halfLifeTime << " - half life time in hour(s)." << G4endl;
293  fOutPut1 << process << " - creation process." << G4endl;
294  fOutPut1 << particlesPerSecond << " - isotope per sec." << G4endl;
295  fOutPut1 << fPrimaryIsotopeEOBTarget[name] << " - yield EOB." << G4endl;
296  fOutPut1 << fPrimaryActivityTarget[name] << " - activity (mCi) at the EOB." << G4endl;
297  fOutPut1 << "------------------------" << G4endl;
298  }
299 
300  }
301 
302 
303  //----------------------------------------------
304  // CASE 2 : isotopes from primary isotopes decay
305  //----------------------------------------------
306 
307  fOutPut2 << "//-----------------------------------//\n"
308  << "// Data for daughter isotopes //\n"
309  << "//-----------------------------------//\n" << G4endl;
310 
311  std::map<G4String,G4String>::iterator it1;
312 
313  for (it1 = fDecayIsotopeCountTarget.begin(); it1 != fDecayIsotopeCountTarget.end(); it1++)
314  {
315 
316 
317  G4String nameDaughter = it1->first;
318  G4String nameMum = it1->second;
319 
320  G4double halfLifeTimeMum = fDecayIsotopeTimeTarget[nameDaughter]*10E10/3600;
321  G4double halfLifeTimeDaughter = fPrimaryIsotopeTimeTarget[nameMum]*10E10/3600;
322 
323  G4bool store;
324  if(halfLifeTimeMum > minDecay && halfLifeTimeMum < maxDecay &&
325  halfLifeTimeDaughter > minDecay && halfLifeTimeDaughter < maxDecay){store=true;}
326  else{store=false;}
327 
328 
329 
330  //----------------------------------------------
331  // Calculation of the yield
332  // fParticleTime[name] is the time
333  // life of the particle, divided by ln(2), in nS
334  //----------------------------------------------
335 
336  G4double decayConstantMum = 1/(fPrimaryIsotopeTimeTarget[nameMum]*10.E-10);
337  G4double decayConstantDaughter = 1/(fDecayIsotopeTimeTarget[nameDaughter]*10.E-10);
338 
339 
340  //----------------------------------------------
341  // Number of particles per second
342  //----------------------------------------------
343 
344  G4double particlesPerSecond = fPrimaryIsotopeCountTarget[nameMum]*currentFactor/timeForARun;
345 
346  //----------------------------------------------
347  // Number of particles at the EOB
348  //----------------------------------------------
349 
350  fDecayIsotopeEOBTarget[nameDaughter] = particlesPerSecond*((1 - std::exp(-irradiationTime*3600*decayConstantDaughter))/decayConstantDaughter + (std::exp(-irradiationTime*3600*decayConstantDaughter) - std::exp(-irradiationTime*3600*decayConstantMum))/(decayConstantDaughter-decayConstantMum));
351 
352 
353  //----------------------------------------------
354  // Calculation of activity
355  // conversion factor Bq to mCu
356  //----------------------------------------------
357 
358  G4double conv = 2.7E-8;
359  fDecayActivityTarget[nameDaughter]= fDecayIsotopeEOBTarget[nameDaughter]*decayConstantDaughter*conv;
360 
361  if(store)
362  {
363  decayActivityTotal = decayActivityTotal + fDecayActivityTarget[nameDaughter];
364  }
365 
366  if(store)
367  {
368  fOutPut2 << nameDaughter << " - name of daughter isotope." << G4endl;
369  fOutPut2 << nameMum << " - name of parent isotope." << G4endl;
370  fOutPut2 << decayConstantDaughter << " - decay constant of daughter in s-1." << G4endl;
371  fOutPut2 << decayConstantMum << " - decay constant of mum in s-1." << G4endl;
372  fOutPut2 << halfLifeTimeDaughter << " - half life time of daughter in hour(s)." << G4endl;
373  fOutPut2 << halfLifeTimeMum << " - half life time of mum in hour(s)." << G4endl;
374  fOutPut2 << particlesPerSecond << " - isotope per sec." << G4endl;
375  fOutPut2 << fDecayIsotopeEOBTarget[nameDaughter] << " - yield at the EOB." << G4endl;
376  fOutPut2 << fDecayActivityTarget[nameDaughter] << " - activity (mCi) at the EOB." << G4endl;
377  fOutPut2 << "------------------------" << G4endl;
378  }
379 
380  }
381 
382  //----------------------------------------------
383  // Particles created, other than nuclei
384  //----------------------------------------------
385 
386  fOutPut3 << "//-----------------------------------//\n"
387  << "// Data for other particles //\n"
388  << "//-----------------------------------//" << G4endl;
389 
390  std::map<G4String, G4int>::iterator it3;
391  for(it3=fParticleCountTarget.begin(); it3!= fParticleCountTarget.end(); it3++)
392  {
393  G4String name = it3->first;
394  G4double number = it3->second;
395  fOutPut3 << name << " - name of the particle" << G4endl;
396  fOutPut3 << number << " - number of particles" << G4endl;
397  fOutPut3 << "------------------------" << G4endl;
398  }
399 
400 
401 
402 
403  fOutPut4 << "//-----------------------------------//\n"
404  << "// Data for stable isotopes //\n"
405  << "//-----------------------------------//\n" << G4endl;
406 
407  std::map<G4String, G4int>::iterator it6;
408  for(it6=fStableIsotopeCountTarget.begin();it6!=fStableIsotopeCountTarget.end();it6++)
409  {
410  G4String isotope = it6 ->first;
411  G4int number = it6 -> second;
412  fOutPut4 << isotope << " - name of the isotope" << G4endl;
413  fOutPut4 << number << " - number of isotopes" << G4endl;
414  fOutPut4 << "------------------------" << G4endl;
415  }
416 
417 
418 
419  //Clear the maps
420  fPrimaryIsotopeEOBTarget.clear();
421  fPrimaryActivityTarget.clear();
422  fDecayIsotopeEOBTarget.clear();
423  fDecayActivityTarget.clear();
424 
425 
426  //Clear the maps
429  fDecayIsotopeCountTarget.clear();
430  fDecayIsotopeTimeTarget.clear();
431  fParticleParent.clear();
432  fParticleCountTarget.clear();
434  fIsotopeIDTarget.clear();
435 
436 
437  //-----------------------------
438  // Calculation of heat
439  //-----------------------------
440 
441  G4double totalEnergyDepositTargetEOB = fTotalEnergyDepositTarget/timeForARun * irradiationTime * 3600.;
442  G4double totalEnergyDepositTargetPerSecond = fTotalEnergyDepositTarget/timeForARun;
443  //Heat calculation in W/mm3
444  G4double heatTarget = totalEnergyDepositTargetPerSecond/fTargetVolume * 1.60E-13;
445  G4double heatFoil = fTotalEnergyDepositFoil / fFoilVolume * 1.60E-13;
446 
447 
448  //Output data in a .txt file
449  fOutPut << "//-------------------------------------------------//\n"
450  << "// Heating, total activity and process data //\n"
451  << "//-------------------------------------------------//" << G4endl;
452 
453  fOutPut << "Total heating in the target : "
454  << heatTarget << " W/mm3" << G4endl;
455  fOutPut << "The total heating during the irradiation is " << totalEnergyDepositTargetEOB << "J/mm3" << G4endl;
456  fOutPut << "Total heating in the foil : " << heatFoil << " W/mm3" << G4endl;
457 
458 
459  fOutPut.close();
460  fOutPut1.close();
461  fOutPut2.close();
462  fOutPut3.close();
463  fOutPut4.close();
464 
465 }
466 
467 
468 
469 
470 // Accumulation functions for maps used at the end of run action
471 
473 {
476 }
477 //------------------------------------
479 {
481 }
482 //------------------------------------
484 {
485  fDecayIsotopeCountTarget[nameDaughter]=mum;
486  fDecayIsotopeTimeTarget[nameDaughter]=time;
487 }
488 //------------------------------------
490 {
491  fParticleParent[isotope]=parent;
492 }
493 //
494 //-----> Count other particles
495 //------------------------------------
497 {
499 }
500 
501 
502 
503 //-------------------------------------------------------------------------------------------------------------
504 // Accumulation functions for maps used only during the run
505 //
506 //-----> Isotope ID to obtain the "mother isotope" in SensitiveTarget()
507 //------------------------------------
509 {
510  fIsotopeIDTarget[ID]=name;
511 }
512 //
513 std::map<G4int,G4String> STCyclotronRun::GetIsotopeID()
514 {
515  return fIsotopeIDTarget;
516 }
517 
518 
520 {
522 }
523 
525 {
527 }
528 
530 {
531  fParticleTarget++;
532 }
533 
535 {
536  fFoilVolume = foilVolume;
537 }
538 
540 {
541  fFoilThickness = foilThickness;
542 }
543 
545 {
546  fTargetVolume = targetVolume;
547 }
548 
550 {
551  fTargetThickness = targetThickness;
552 }
553 
555 {
556  fTargetDiameter = targetDiameter;
557 }
558 
560 {
561  fPrimariesPerEvent = primaries;
562 }
563 
565 {
566  fTimePerEvent = timePerEvent;
567 }
568 
570 {
571  fBeamName = beamName;
572 }
573 
575 {
576  fBeamCurrent = beamCurrent;
577 }
578 
580 {
581  fBeamEnergy = beamEnergy;
582 }