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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 11.0.p2)


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