Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 27 #include <typeinfo> 28 29 #include "G4CollisionManager.hh" 30 #include "G4SystemOfUnits.hh" 31 #include "G4HadronicException.hh" 32 #include "G4CollisionInitialState.hh" 33 #include "G4BCAction.hh" 34 35 G4CollisionManager::G4CollisionManager() 36 { 37 theCollisionList = new G4ListOfCollisions; 38 } 39 40 41 G4CollisionManager::~G4CollisionManager() 42 { 43 ClearAndDestroy(); 44 delete theCollisionList; 45 } 46 47 48 void G4CollisionManager::AddCollision(G4double 49 G4KineticTrack * target) 50 51 { 52 if ( time < DBL_MAX ) 53 { 54 G4CollisionInitialState * 55 collision = new G4CollisionInitialState 56 theCollisionList->push_back(collision 57 } else { 58 G4cerr << "G4Scatterer invalid TimeTo 59 G4cerr <<" projectile "<<proj->Get 60 <<proj->Get 61 if (target) G4cerr <<" target 62 <<target->Get4Momentum()<<" " 63 <<target->GetD 64 G4cerr <<"G4Scatterer error message e 65 throw G4HadronicException(__FILE__, __LINE_ 66 } 67 } 68 69 70 void G4CollisionManager::RemoveCollision(G4Col 71 { 72 theCollisionList->erase(std::find(theCollisi 73 theCollisionList->end(), 74 collision)); 75 delete collision; 76 collision = NULL; // prevent future use of t 77 } 78 79 80 void G4CollisionManager::RemoveTracksCollision 81 { 82 if(toBeCaned == NULL) 83 return; 84 if(toBeCaned->empty()) 85 return; 86 87 G4CollisionInitialState * collision; 88 std::vector<G4CollisionInitialState *>::iter 89 std::vector<G4KineticTrack *>::iterator trac 90 G4ListOfCollisions toRemove; 91 92 for(collIter = theCollisionList->begin(); 93 collIter != theCollisionList->end(); col 94 { 95 collision = *collIter; 96 G4KineticTrackVector & targets = collision 97 G4bool getNextCollision = false; 98 for(trackIter = toBeCaned->begin(); trackI 99 { 100 if((collision->GetTarget() == *trackIter 101 (collision->GetPrimary() == *trackIter)) 102 { // cannot remove the collision from t 103 toRemove.push_back(collision); 104 break; // exit from the "trackIter" loop 105 } 106 for(size_t tcount=0; tcount<targets.size 107 { 108 if(targets[tcount] == *trackIter) 109 { 110 toRemove.push_back(collision); 111 getNextCollision = true; 112 break; 113 } 114 } 115 if(getNextCollision) break; 116 } 117 } 118 119 // now remove the collisions 120 for(collIter = toRemove.begin(); collIter != 121 { 122 collision = *collIter; 123 collIter2 = std::find(theCollisionList->be 124 theCollisionList->end(), collision); 125 theCollisionList->erase(collIter2); // re 126 delete collision; // .. 127 } 128 } 129 130 131 void G4CollisionManager::ClearAndDestroy() 132 { 133 std::vector<G4CollisionInitialState *>::iter 134 for(i = theCollisionList->begin(); i != theC 135 delete *i; 136 theCollisionList->clear(); 137 } 138 139 140 G4CollisionInitialState * G4CollisionManager:: 141 { 142 G4CollisionInitialState * theNext=0; 143 G4double nextTime = DBL_MAX; 144 std::vector<G4CollisionInitialState *>::iter 145 for(i = theCollisionList->begin(); i != theC 146 { 147 if(nextTime > (*i)->GetCollisionTime()) 148 { 149 nextTime = (*i)->GetCollisionTime(); 150 theNext = *i; 151 } 152 } 153 #ifdef debug_G4CollisionManager 154 if(theNext == 0 && theCollisionList->size()! 155 { 156 G4double debugTime = DBL_MAX; 157 G4cerr <<"G4CollisionManager::GetNextColli 158 G4cerr <<" number of collisions left "<<th 159 for(i = theCollisionList->begin(); i != th 160 { 161 G4cerr <<" Time to collision "<<(*i)->Ge 162 G4cerr <<" projectile "<<(*i)->GetPri 163 <<(*i)->GetPri 164 if ((*i)->GetTarget()) G4cerr <<" tar 165 <<(*i)->GetTar 166 } 167 G4cerr <<"G4CollisionManager::GetNextColli 168 } 169 #endif 170 171 return theNext; 172 } 173 174 175 void G4CollisionManager::Print() 176 { 177 std::vector<G4CollisionInitialState *>::iter 178 179 G4cout << "CollisionManager: " << theCollisi 180 << " entries at " << theCollisionList << G4 181 G4CollisionInitialState * collision; 182 for(i = theCollisionList->begin(); i != theC 183 { 184 collision = *i; 185 G4int tgtPdg=collision->GetTarget() ? 186 collision->GetTarget()->GetDefinition()-> 187 const G4BCAction &action= *collision->GetGe 188 G4cout << " collision " << collision << " 189 << collision->GetCollisionTime()/second < 190 << collision->GetPrimary() << "/pdg=" 191 << collision->GetPrimary()->GetDefinition 192 << " trgt: " 193 << collision->GetTarget() << "/pdg=" 194 << tgtPdg 195 << " Collision type: "<< typeid(action).n 196 << G4endl; 197 } 198 } 199