source: trunk/source/processes/hadronic/models/util/src/G4DecayStrongResonances.cc @ 1350

Last change on this file since 1350 was 1350, checked in by garnier, 13 years ago

update to last version 4.9.4

File size: 6.0 KB
Line 
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// $Id: G4DecayStrongResonances.cc,v 1.2 2010/11/02 17:57:38 vnivanch Exp $
27// GEANT4 tag $Name: geant4-09-04-ref-00 $
28//
29// -------------------------------------------------------------------
30//
31// GEANT4 Class file
32//
33// File name:     G4DecayStrongResonances
34//
35// Modified: 
36// 02.11.2010 V.Ivanchenko moved constructor and destructor to source
37//
38
39#include "G4DecayStrongResonances.hh"
40
41#include "G4HadTmpUtil.hh"
42
43#include <algorithm>
44
45G4DecayStrongResonances::G4DecayStrongResonances()
46{}
47
48G4DecayStrongResonances::~G4DecayStrongResonances()
49{}
50
51G4ReactionProductVector* 
52G4DecayStrongResonances::Propagate(G4KineticTrackVector* theSecondaries, 
53                                   G4V3DNucleus* )
54{
55     // decay the strong resonances
56     //static int call_count = 0;
57     //if(call_count++<10)
58     //{
59     //  G4cout << "Security print-out: Entering G4DecayStrongResonances::Propagate";
60     //}
61     G4ReactionProductVector * theResult;
62     try
63     {
64       theResult = new G4ReactionProductVector;
65     }
66     catch(...)
67     {
68       throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: out of memory ");
69     }
70     G4KineticTrackVector *result1, *secondaries, *result;
71     if(!theSecondaries)
72     {
73       throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: 0x0 input vector ");
74     }
75     result1=theSecondaries;
76     try
77     {
78       result=new G4KineticTrackVector();
79     }
80     catch(...)
81     {
82       throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: out of memory in ");
83     }
84         
85     size_t aResult=0;
86     for (aResult=0; aResult < result1->size(); aResult++)
87     {
88       G4ParticleDefinition * pdef;
89       if(!result1->operator[](aResult))
90       {
91         throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: null pointer in input vector!!! ");
92       }
93       pdef=result1->operator[](aResult)->GetDefinition();
94       if(!pdef)
95       {
96        throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: 0x0 particle definition ");
97       }
98       secondaries=NULL;
99       if ( pdef->GetPDGWidth() > 0 && pdef->GetPDGLifeTime() < 5E-17*s )
100       {
101          try
102          {
103            secondaries = result1->operator[](aResult)->Decay();
104          }
105          catch(...)
106          {
107            throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: failing in Decay ");
108          }
109       }
110       if ( secondaries == NULL )
111       {
112          try
113          {
114            result->push_back(result1->operator[](aResult));
115          }
116          catch(...)
117          {
118            throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: push_back failed - out of memory ");
119          }
120          result1->operator[](aResult)=NULL;    //protect for clearAndDestroy
121       } 
122       else
123       {
124         for (size_t aSecondary=0; aSecondary<secondaries->size(); aSecondary++)
125         {
126           try
127           {
128             result1->push_back(secondaries->operator[](aSecondary));
129           }
130           catch(...)
131           {
132             throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: push_back  1 failed - out of mem");
133           }
134         }
135         if(secondaries) delete secondaries;
136       }
137     }
138     try
139     {
140       std::for_each(result1->begin(), result1->end(), G4Delete());
141       delete result1;
142     }
143     catch(...)
144     {
145       throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: memory corruption.");
146     }
147     
148     // translate to ReactionProducts
149     G4ReactionProduct * it = NULL;
150     for(aResult=0; aResult < result->size(); aResult++)
151     {
152       try
153       {
154         it = new G4ReactionProduct();
155       }
156       catch(...)
157       {
158          throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: out of memory ");
159       }
160       it->SetDefinition((*result)[aResult]->GetDefinition());
161       it->SetMass((*result)[aResult]->GetDefinition()->GetPDGMass());
162       it->SetTotalEnergy((*result)[aResult]->Get4Momentum().t());
163       it->SetMomentum((*result)[aResult]->Get4Momentum().vect());
164       
165       try
166       {
167         theResult->push_back(it);
168       }
169       catch(...)
170       {
171          throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: push to result failed - out of mem.");
172       }
173     }
174     try
175     {
176       std::for_each(result->begin(), result->end(), G4Delete());
177       delete result;
178     }
179     catch(...)
180     {
181       throw G4HadronicException(__FILE__, __LINE__, "DecayStrongRes: memory corruption at end.");
182     }
183     return theResult;
184}
185
186
Note: See TracBrowser for help on using the repository browser.