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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 9.4.p2)


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