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