source: trunk/source/processes/hadronic/models/im_r_matrix/src/G4CollisionManager.cc@ 962

Last change on this file since 962 was 819, checked in by garnier, 17 years ago

import all except CVS

File size: 6.6 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#include "G4CollisionManager.hh"
27#include "G4HadronicException.hh"
28#include "G4CollisionInitialState.hh"
29
30G4CollisionManager::G4CollisionManager()
31{
32 theCollisionList = new G4ListOfCollisions;
33}
34
35
36G4CollisionManager::~G4CollisionManager()
37{
38 ClearAndDestroy();
39 delete theCollisionList;
40}
41
42
43void G4CollisionManager::AddCollision(G4double time, G4KineticTrack * proj,
44 G4KineticTrack * target)
45
46{
47 if ( time < DBL_MAX )
48 {
49 G4CollisionInitialState *
50 collision = new G4CollisionInitialState(time, proj, target);
51 theCollisionList->push_back(collision);
52 } else {
53 G4cerr << "G4Scatterer invalid TimeTo Interaction : " << time;
54 G4cerr <<" projectile "<<proj->Get4Momentum()<<" "
55 <<proj->GetDefinition()->GetParticleName()<<G4endl;
56 if (target) G4cerr <<" target "
57 <<target->Get4Momentum()<<" "
58 <<target->GetDefinition()->GetParticleName()<<G4endl;
59 G4cerr <<"G4Scatterer error message end"<< G4endl;
60 throw G4HadronicException(__FILE__, __LINE__, "G4Scatterer::AddCollision()");
61 }
62}
63
64
65void G4CollisionManager::RemoveCollision(G4CollisionInitialState * collision)
66{
67 theCollisionList->erase(std::find(theCollisionList->begin(),
68 theCollisionList->end(),
69 collision));
70 delete collision;
71 collision = NULL; // prevent future use of the pointer
72}
73
74
75void G4CollisionManager::RemoveTracksCollisions(G4KineticTrackVector * toBeCaned)
76{
77 if(toBeCaned == NULL)
78 return;
79 if(toBeCaned->empty())
80 return;
81
82 G4CollisionInitialState * collision;
83 std::vector<G4CollisionInitialState *>::iterator collIter, collIter2;
84 std::vector<G4KineticTrack *>::iterator trackIter;
85 G4ListOfCollisions toRemove;
86
87 for(collIter = theCollisionList->begin();
88 collIter != theCollisionList->end(); collIter++)
89 {
90 collision = *collIter;
91 G4KineticTrackVector & targets = collision->GetTargetCollection();
92 G4bool getNextCollision = false;
93 for(trackIter = toBeCaned->begin(); trackIter != toBeCaned->end(); ++trackIter)
94 {
95 if((collision->GetTarget() == *trackIter) ||
96 (collision->GetPrimary() == *trackIter))
97 { // cannot remove the collision from the list inside the loop. Save and do it later
98 toRemove.push_back(collision);
99 break; // exit from the "trackIter" loop
100 }
101 for(size_t tcount=0; tcount<targets.size(); tcount++)
102 {
103 if(targets[tcount] == *trackIter)
104 {
105 toRemove.push_back(collision);
106 getNextCollision = true;
107 break;
108 }
109 }
110 if(getNextCollision) break;
111 }
112 }
113
114 // now remove the collisions
115 for(collIter = toRemove.begin(); collIter != toRemove.end(); ++collIter)
116 {
117 collision = *collIter;
118 collIter2 = std::find(theCollisionList->begin(),
119 theCollisionList->end(), collision);
120 theCollisionList->erase(collIter2); // remove from list...
121 delete collision; // ...and delete the collision
122 }
123}
124
125
126void G4CollisionManager::ClearAndDestroy()
127{
128 std::vector<G4CollisionInitialState *>::iterator i;
129 for(i = theCollisionList->begin(); i != theCollisionList->end(); ++i)
130 delete *i;
131 theCollisionList->clear();
132}
133
134
135G4CollisionInitialState * G4CollisionManager::GetNextCollision()
136{
137 G4CollisionInitialState * theNext=0;
138 G4double nextTime = DBL_MAX;
139 std::vector<G4CollisionInitialState *>::iterator i;
140 for(i = theCollisionList->begin(); i != theCollisionList->end(); ++i)
141 {
142 if(nextTime > (*i)->GetCollisionTime())
143 {
144 nextTime = (*i)->GetCollisionTime();
145 theNext = *i;
146 }
147 }
148 #ifdef debug_G4CollisionManager
149 if(theNext == 0 && theCollisionList->size()!=0)
150 {
151 G4double debugTime = DBL_MAX;
152 G4cerr <<"G4CollisionManager::GetNextCollision - Fatal"<<G4endl;
153 G4cerr <<" number of collisions left "<<theCollisionList->size()<<G4endl;
154 for(i = theCollisionList->begin(); i != theCollisionList->end(); ++i)
155 {
156 G4cerr <<" Time to collision "<<(*i)->GetCollisionTime()<<" "<<G4endl;
157 G4cerr <<" projectile "<<(*i)->GetPrimary()->Get4Momentum()<<" "
158 <<(*i)->GetPrimary()->GetDefinition()->GetParticleName()<<G4endl;
159 if ((*i)->GetTarget()) G4cerr <<" target "<<(*i)->GetTarget()->Get4Momentum()<<" "
160 <<(*i)->GetTarget()->GetDefinition()->GetParticleName()<<G4endl;
161 }
162 G4cerr <<"G4CollisionManager::GetNextCollision - End of message"<<G4endl;
163 }
164 #endif
165
166 return theNext;
167}
168
169
170void G4CollisionManager::Print()
171{
172 std::vector<G4CollisionInitialState *>::iterator i;
173
174 G4cout << "CollisionManager: " << theCollisionList->size()
175 << " entries at " << theCollisionList << G4endl;
176 G4CollisionInitialState * collision;
177 for(i = theCollisionList->begin(); i != theCollisionList->end(); ++i)
178 {
179 collision = *i;
180 G4cout << " collision " << collision << " time: "
181 << collision->GetCollisionTime()/second << " proj: "
182 << collision->GetPrimary() << " trgt: "
183 << collision->GetTarget() << G4endl;
184 }
185}
Note: See TracBrowser for help on using the repository browser.