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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 /processes/hadronic/models/im_r_matrix/src/G4CollisionManager.cc (Version 11.3.0) and /processes/hadronic/models/im_r_matrix/src/G4CollisionManager.cc (Version 8.0)


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