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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/radioactivedecay/rdecay01/src/TrackingAction.cc (Version 11.3.0) and /examples/extended/radioactivedecay/rdecay01/src/TrackingAction.cc (Version 9.5)


  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 /// \file TrackingAction.cc                    << 
 27 /// \brief Implementation of the TrackingActio << 
 28 //                                                 26 //
 29 //                                             <<  27 // $Id: TrackingAction.cc,v 1.2 2010-10-11 14:31:39 maire Exp $
 30 //....oooOO0OOooo........oooOO0OOooo........oo <<  28 // GEANT4 tag $Name: not supported by cvs2svn $
                                                   >>  29 // 
 31 //....oooOO0OOooo........oooOO0OOooo........oo     30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >>  31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 
 32                                                    32 
 33 #include "TrackingAction.hh"                       33 #include "TrackingAction.hh"
 34                                                <<  34 #include "RunAction.hh"
 35 #include "EventAction.hh"                      << 
 36 #include "HistoManager.hh"                         35 #include "HistoManager.hh"
 37 #include "Run.hh"                              <<  36 #include "RunAction.hh"
                                                   >>  37 #include "EventAction.hh"
 38 #include "TrackingMessenger.hh"                    38 #include "TrackingMessenger.hh"
 39                                                    39 
 40 #include "G4IonTable.hh"                       <<  40 #include "G4Track.hh"
 41 #include "G4ParticleTypes.hh"                      41 #include "G4ParticleTypes.hh"
 42 #include "G4RunManager.hh"                         42 #include "G4RunManager.hh"
 43 #include "G4SystemOfUnits.hh"                  << 
 44 #include "G4Track.hh"                          << 
 45 #include "G4UnitsTable.hh"                     << 
 46                                                    43 
 47 //....oooOO0OOooo........oooOO0OOooo........oo     44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 48                                                    45 
 49 TrackingAction::TrackingAction(EventAction* ev <<  46 TrackingAction::TrackingAction(HistoManager* histo,
 50                                                <<  47                                RunAction* RA, EventAction* EA)
                                                   >>  48 :histoManager(histo),run(RA),event(EA)
 51 {                                                  49 {
 52   fTrackMessenger = new TrackingMessenger(this <<  50   fullChain = false;
                                                   >>  51   trackMessenger = new TrackingMessenger(this);   
 53 }                                                  52 }
 54                                                    53 
 55 //....oooOO0OOooo........oooOO0OOooo........oo     54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 56                                                    55 
 57 TrackingAction::~TrackingAction()                  56 TrackingAction::~TrackingAction()
 58 {                                                  57 {
 59   delete fTrackMessenger;                      <<  58   delete trackMessenger;
 60 }                                              << 
 61                                                << 
 62 //....oooOO0OOooo........oooOO0OOooo........oo << 
 63                                                << 
 64 void TrackingAction::SetTimeWindow(G4double t1 << 
 65 {                                              << 
 66   fTimeWindow1 = t1;                           << 
 67   fTimeWindow2 = fTimeWindow1 + dt;            << 
 68 }                                                  59 }
 69                                                    60 
 70 //....oooOO0OOooo........oooOO0OOooo........oo     61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 71                                                    62 
 72 void TrackingAction::PreUserTrackingAction(con     63 void TrackingAction::PreUserTrackingAction(const G4Track* track)
 73 {                                                  64 {
 74   Run* run = static_cast<Run*>(G4RunManager::G << 
 75                                                << 
 76   G4ParticleDefinition* particle = track->GetD     65   G4ParticleDefinition* particle = track->GetDefinition();
 77   G4String name = particle->GetParticleName(); <<  66   G4String name   = particle->GetParticleName();
 78   fCharge = particle->GetPDGCharge();          <<  67   charge = particle->GetPDGCharge();
 79   fMass = particle->GetPDGMass();              <<  68   mass   = particle->GetPDGMass();  
 80                                                <<  69     
 81   G4double Ekin = track->GetKineticEnergy();       70   G4double Ekin = track->GetKineticEnergy();
 82   G4int ID = track->GetTrackID();              <<  71   G4int ID      = track->GetTrackID();
 83                                                <<  72   
 84   G4bool condition = false;                    <<  73   G4bool condition = false;  
 85                                                <<  74 
 86   // check LifeTime                            <<  75   //count particles
 87   //                                           <<  76   //
 88   G4double meanLife = particle->GetPDGLifeTime <<  77   run->ParticleCount(name, Ekin);
 89                                                <<  78   
 90   // count particles                           <<  79   //energy spectrum
 91   //                                           << 
 92   run->ParticleCount(name, Ekin, meanLife);    << 
 93                                                << 
 94   // energy spectrum                           << 
 95   //                                               80   //
 96   G4int ih = 0;                                    81   G4int ih = 0;
 97   if (particle == G4Electron::Electron() || pa <<  82   if (particle == G4Electron::Electron()||
 98     ih = 1;                                    <<  83       particle == G4Positron::Positron())  ih = 1;
 99   else if (particle == G4NeutrinoE::NeutrinoE( <<  84   else if (particle == G4NeutrinoE::NeutrinoE()||
100     ih = 2;                                    <<  85            particle == G4AntiNeutrinoE::AntiNeutrinoE()) ih = 2;
101   else if (particle == G4Gamma::Gamma())       <<  86   else if (particle == G4Gamma::Gamma()) ih = 3;
102     ih = 3;                                    <<  87   else if (particle == G4Alpha::Alpha()) ih = 4;
103   else if (particle == G4Alpha::Alpha())       <<  88   else if (charge > 2.) ih = 5;
104     ih = 4;                                    <<  89   if (ih) histoManager->FillHisto(ih, Ekin);
105   else if (fCharge > 2.)                       <<  90   
106     ih = 5;                                    <<  91   //fullChain: stop ion and print decay chain
107   if (ih) G4AnalysisManager::Instance()->FillH <<  92   //
108                                                <<  93   if (charge > 2.) {
109   // Ion                                       <<  94     G4Track* tr = (G4Track*) track;
110   //                                           <<  95     if (fullChain) tr->SetTrackStatus(fStopButAlive);
111   if (fCharge > 2.) {                          <<  96     if (ID == 1) event->AddDecayChain(name);
112     // build decay chain                       <<  97       else       event->AddDecayChain(" ---> " + name); 
113     if (ID == 1)                               << 
114       fEvent->AddDecayChain(name);             << 
115     else                                       << 
116       fEvent->AddDecayChain(" ---> " + name);  << 
117     //                                         << 
118     // full chain: put at rest; if not: kill s << 
119     G4Track* tr = (G4Track*)track;             << 
120     if (fFullChain) {                          << 
121       tr->SetKineticEnergy(0.);                << 
122       tr->SetTrackStatus(fStopButAlive);       << 
123     }                                          << 
124     else if (ID > 1)                           << 
125       tr->SetTrackStatus(fStopAndKill);        << 
126     //                                         << 
127     fTimeBirth = track->GetGlobalTime();       << 
128   }                                                98   }
129                                                <<  99   
130   // example of saving random number seed of t << 100   //example of saving random number seed of this event, under condition
131   //                                              101   //
132   ////condition = (ih == 3);                      102   ////condition = (ih == 3);
133   if (condition) G4RunManager::GetRunManager()    103   if (condition) G4RunManager::GetRunManager()->rndmSaveThisEvent();
134 }                                                 104 }
135                                                   105 
136 //....oooOO0OOooo........oooOO0OOooo........oo    106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
137                                                   107 
138 void TrackingAction::PostUserTrackingAction(co    108 void TrackingAction::PostUserTrackingAction(const G4Track* track)
139 {                                                 109 {
140   // keep only ions                            << 110   //keep only ions
141   //                                              111   //
142   if (fCharge < 3.) return;                    << 112   if (charge < 3. ) return;
143                                                << 
144   Run* run = static_cast<Run*>(G4RunManager::G << 
145                                                << 
146   G4AnalysisManager* analysis = G4AnalysisMana << 
147                                                   113 
148   // get time                                  << 114   //get time
149   //                                           << 115   //   
150   G4double time = track->GetGlobalTime();         116   G4double time = track->GetGlobalTime();
151   G4int ID = track->GetTrackID();                 117   G4int ID = track->GetTrackID();
152   if (ID == 1) run->PrimaryTiming(time);  // t << 118   if (ID == 1) run->PrimaryTiming(time);  //time of life of primary ion  
153   fTimeEnd = time;                             << 119       
154                                                << 120   //energy and momentum balance (from secondaries)
155   // energy and momentum balance (from seconda << 
156   //                                              121   //
157   const std::vector<const G4Track*>* secondari << 122   G4TrackVector* secondaries = fpTrackingManager->GimmeSecondaries();
158   size_t nbtrk = (*secondaries).size();           123   size_t nbtrk = (*secondaries).size();
159   if (nbtrk) {                                    124   if (nbtrk) {
160     // there are secondaries --> it is a decay << 125     //there are secondaries --> it is a decay
                                                   >> 126     //
                                                   >> 127     //force 'single' decay
                                                   >> 128     if ((!fullChain)&&(ID > 1)) G4RunManager::GetRunManager()->AbortEvent();
161     //                                            129     //
162     // balance                                 << 130     //balance    
163     G4double EkinTot = 0., EkinVis = 0.;       << 131     G4double EkinTot = 0.;
164     G4ThreeVector Pbalance = -track->GetMoment << 132     G4ThreeVector Pbalance = - track->GetMomentum();
165     for (size_t itr = 0; itr < nbtrk; itr++) { << 133     for (size_t itr=0; itr<nbtrk; itr++) {
166       const G4Track* trk = (*secondaries)[itr] << 134        G4Track* trk = (*secondaries)[itr];
167       G4ParticleDefinition* particle = trk->Ge << 135        EkinTot += trk->GetKineticEnergy();
168       G4double Ekin = trk->GetKineticEnergy(); << 136        //exclude gamma desexcitation from momentum balance
169       EkinTot += Ekin;                         << 137        if (trk->GetDefinition() != G4Gamma::Gamma())   
170       G4bool visible =                         << 138          Pbalance += trk->GetMomentum();           
171         !((particle == G4NeutrinoE::NeutrinoE( << 
172       if (visible) EkinVis += Ekin;            << 
173       // exclude gamma desexcitation from mome << 
174       if (particle != G4Gamma::Gamma()) Pbalan << 
175     }                                             139     }
176     G4double Pbal = Pbalance.mag();            << 140     G4double Pbal = Pbalance.mag();  
177     run->Balance(EkinTot, Pbal);               << 141     run->Balance(EkinTot,Pbal);  
178     analysis->FillH1(6, EkinTot);              << 142     histoManager->FillHisto(6,EkinTot);
179     analysis->FillH1(7, Pbal);                 << 143     histoManager->FillHisto(7,Pbal);
180     fEvent->AddEvisible(EkinVis);              << 
181   }                                               144   }
182                                                << 145   
183   // no secondaries --> end of chain           << 146   //no secondaries --> end of chain    
184   //                                           << 147   //  
185   if (!nbtrk) {                                   148   if (!nbtrk) {
186     run->EventTiming(time);  // total time of  << 149     run->EventTiming(time);   //total time of life
187     G4double weight = track->GetWeight();      << 150     histoManager->FillHisto(8,time);
188     analysis->FillH1(8, time, weight);         << 
189     ////    analysis->FillH1(8,time);          << 
190     fTimeEnd = DBL_MAX;                        << 
191   }                                               151   }
192                                                << 
193   // count activity in time window             << 
194   //                                           << 
195   run->SetTimeWindow(fTimeWindow1, fTimeWindow << 
196                                                << 
197   G4String name = track->GetDefinition()->GetP << 
198   G4bool life1(false), life2(false), decay(fal << 
199   if ((fTimeBirth <= fTimeWindow1) && (fTimeEn << 
200   if ((fTimeBirth <= fTimeWindow2) && (fTimeEn << 
201   if ((fTimeEnd > fTimeWindow1) && (fTimeEnd < << 
202   if (life1 || life2 || decay) run->CountInTim << 
203 }                                                 152 }
204                                                   153 
205 //....oooOO0OOooo........oooOO0OOooo........oo    154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 155 
206                                                   156