Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/processes/hadronic/models/im_r_matrix/src/G4Scatterer.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 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/G4Scatterer.cc (Version 11.3.0) and /processes/hadronic/models/im_r_matrix/src/G4Scatterer.cc (Version 9.0.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 // $Id: G4Scatterer.cc,v 1.13.2.4 2006/06/29 20:40:31 gunter Exp $ //
 26 //                                                 27 //
 27                                                    28 
 28 #include <vector>                              << 
 29                                                << 
 30 #include "globals.hh"                              29 #include "globals.hh"
 31 #include "G4PhysicalConstants.hh"              <<  30 #include <vector>
 32 #include "G4SystemOfUnits.hh"                  << 
 33 #include "G4ios.hh"                                31 #include "G4ios.hh"
 34 #include "G4Scatterer.hh"                          32 #include "G4Scatterer.hh"
 35 #include "G4KineticTrack.hh"                       33 #include "G4KineticTrack.hh"
 36 #include "G4ThreeVector.hh"                        34 #include "G4ThreeVector.hh"
 37 #include "G4LorentzRotation.hh"                    35 #include "G4LorentzRotation.hh"
 38 #include "G4LorentzVector.hh"                      36 #include "G4LorentzVector.hh"
 39                                                    37 
 40 #include "G4CollisionNN.hh"                        38 #include "G4CollisionNN.hh"
 41 #include "G4CollisionPN.hh"                        39 #include "G4CollisionPN.hh"
 42 #include "G4CollisionMesonBaryon.hh"               40 #include "G4CollisionMesonBaryon.hh"
 43                                                    41 
 44 #include "G4CollisionInitialState.hh"              42 #include "G4CollisionInitialState.hh"
 45 #include "G4HadTmpUtil.hh"                         43 #include "G4HadTmpUtil.hh"
 46 #include "G4Pair.hh"                               44 #include "G4Pair.hh"
 47 #include "G4AutoLock.hh"                       << 
 48                                                    45 
 49 //Mutex for control of shared resource         << 
 50 namespace  {                                   << 
 51     G4Mutex collisions_mutex = G4MUTEX_INITIAL << 
 52     G4bool setupDone = false;                  << 
 53 }                                              << 
 54                                                    46 
 55 // Declare the categories of collisions the Sc     47 // Declare the categories of collisions the Scatterer can handle
 56 typedef GROUP2(G4CollisionNN, G4CollisionMeson     48 typedef GROUP2(G4CollisionNN, G4CollisionMesonBaryon) theChannels;
 57                                                    49 
 58 G4CollisionVector G4Scatterer::collisions;     << 
 59                                                << 
 60 //-------------------------------------------- << 
 61                                                    50 
 62 G4Scatterer::G4Scatterer()                         51 G4Scatterer::G4Scatterer()
 63 {                                                  52 {
 64   G4AutoLock l(&collisions_mutex);             <<  53   Register aR;
 65   if ( ! setupDone )                           <<  54   G4ForEach<theChannels>::Apply(&aR, &collisions);
 66   {                                            << 
 67       Register aR;                             << 
 68       G4ForEach<theChannels>::Apply(&aR, &coll << 
 69       setupDone = true;                        << 
 70   }                                            << 
 71 }                                                  55 }
 72                                                    56 
 73 //-------------------------------------------- << 
 74                                                    57 
 75 G4Scatterer::~G4Scatterer()                        58 G4Scatterer::~G4Scatterer()
 76 {                                                  59 {
 77   G4AutoLock l(&collisions_mutex);             << 
 78   std::for_each(collisions.begin(), collisions     60   std::for_each(collisions.begin(), collisions.end(), G4Delete());
 79   collisions.clear();                              61   collisions.clear();
 80 }                                                  62 }
 81                                                    63 
 82 //-------------------------------------------- <<  64 G4double G4Scatterer::GetTimeToInteraction(const G4KineticTrack& trk1, 
 83                                                <<  65              const G4KineticTrack& trk2)
 84 G4double G4Scatterer::GetTimeToInteraction(con << 
 85              const G4KineticTrack& trk2) const << 
 86 {                                                  66 {
 87   G4double time = DBL_MAX;                         67   G4double time = DBL_MAX;
 88     G4double distance_fast;                        68     G4double distance_fast;
 89   G4LorentzVector mom1 = trk1.GetTrackingMomen     69   G4LorentzVector mom1 = trk1.GetTrackingMomentum();
 90 //  G4cout << "zcomp=" << std::abs(mom1.vect()     70 //  G4cout << "zcomp=" << std::abs(mom1.vect().unit().z() -1 ) << G4endl;
 91   G4double collisionTime;                          71   G4double collisionTime;
 92                                                <<  72   
 93   if ( std::abs(mom1.vect().unit().z() -1 ) <  <<  73   if ( std::abs(mom1.vect().unit().z() -1 ) < 1e-6 ) 
 94   {                                                74   {
 95      G4ThreeVector position = trk2.GetPosition     75      G4ThreeVector position = trk2.GetPosition() - trk1.GetPosition();
 96      G4double deltaz=position.z();                 76      G4double deltaz=position.z();
 97      G4double velocity = mom1.z()/mom1.e() * c     77      G4double velocity = mom1.z()/mom1.e() * c_light;
 98                                                <<  78      
 99      collisionTime=deltaz/velocity;                79      collisionTime=deltaz/velocity;
100      distance_fast=position.x()*position.x() +     80      distance_fast=position.x()*position.x() + position.y()*position.y();
101   } else {                                         81   } else {
102                                                <<  82   
103     //  The nucleons of the nucleus are FROZEN     83     //  The nucleons of the nucleus are FROZEN, ie. do not move..
104                                                    84 
105     G4ThreeVector position = trk2.GetPosition( <<  85     G4ThreeVector position = trk2.GetPosition() - trk1.GetPosition();    
106                                                    86 
107     G4ThreeVector velocity = mom1.vect()/mom1.     87     G4ThreeVector velocity = mom1.vect()/mom1.e() * c_light;  // mom1.boostVector() will exit on slightly negative mass
108     collisionTime = (position * velocity) / ve     88     collisionTime = (position * velocity) / velocity.mag2();    // can't divide by /c_light;
109     position -= velocity * collisionTime;          89     position -= velocity * collisionTime;
110     distance_fast=position.mag2();                 90     distance_fast=position.mag2();
111                                                <<  91     
112 //    if ( collisionTime>0 ) G4cout << " dis1/     92 //    if ( collisionTime>0 ) G4cout << " dis1/2 square" << dis1 <<" "<< dis2 << G4endl;
113 //     collisionTime = GetTimeToClosestApproac     93 //     collisionTime = GetTimeToClosestApproach(trk1,trk2);
114   }                                                94   }
115      if (collisionTime > 0)                        95      if (collisionTime > 0)
116   {                                            <<  96   { 
117      static const G4double maxCrossSection = 5     97      static const G4double maxCrossSection = 500*millibarn;
118      if(0.7*pi*distance_fast>maxCrossSection)      98      if(0.7*pi*distance_fast>maxCrossSection) return time;
119                                                    99 
120                                                << 100        
121            G4LorentzVector mom2(0,0,0,trk2.Get    101            G4LorentzVector mom2(0,0,0,trk2.Get4Momentum().mag());
122                                                   102 
123 //     G4ThreeVector momLab = mom1.vect();// f    103 //     G4ThreeVector momLab = mom1.vect();// frozen Nucleus - mom2.vect();
124 //     G4ThreeVector posLab = trk1.GetPosition    104 //     G4ThreeVector posLab = trk1.GetPosition() - trk2.GetPosition();
125 //     G4double disLab=posLab * posLab - (posL    105 //     G4double disLab=posLab * posLab - (posLab*momLab) * (posLab*momLab) /(momLab.mag2());
126                                                   106 
127      G4LorentzRotation toCMSFrame((-1)*(mom1 +    107      G4LorentzRotation toCMSFrame((-1)*(mom1 + mom2).boostVector());
128      mom1 = toCMSFrame * mom1;                    108      mom1 = toCMSFrame * mom1;
129      mom2 = toCMSFrame * mom2;                    109      mom2 = toCMSFrame * mom2;
130                                                   110 
131      G4LorentzVector coordinate1(trk1.GetPosit    111      G4LorentzVector coordinate1(trk1.GetPosition(), 100.);
132      G4LorentzVector coordinate2(trk2.GetPosit    112      G4LorentzVector coordinate2(trk2.GetPosition(), 100.);
133      G4ThreeVector pos = ((toCMSFrame * coordi << 113      G4ThreeVector pos = ((toCMSFrame * coordinate1).vect() - 
134         (toCMSFrame * coordinate2).vect());       114         (toCMSFrame * coordinate2).vect());
135                                                   115 
136      G4ThreeVector mom = mom1.vect() - mom2.ve    116      G4ThreeVector mom = mom1.vect() - mom2.vect();
137                                                   117 
138     // Calculate the impact parameter             118     // Calculate the impact parameter
139                                                   119 
140      G4double distance = pos * pos - (pos*mom)    120      G4double distance = pos * pos - (pos*mom) * (pos*mom) / (mom.mag2());
141                                                   121 
142 //     G4cout << " disDiff " << distance-disLa << 122 //     G4cout << " disDiff " << distance-disLab << " " << disLab 
143 //            << " " << std::abs(distance-disL    123 //            << " " << std::abs(distance-disLab)/distance << G4endl
144 //      << " mom/Lab " << mom << " " << momLab    124 //      << " mom/Lab " << mom << " " << momLab << G4endl
145 //      << " pos/Lab " << pos << " " << posLab << 125 //      << " pos/Lab " << pos << " " << posLab 
146 //      << G4endl;                                126 //      << G4endl;
147                                                   127 
                                                   >> 128      // global optimization
                                                   >> 129 //     static const G4double maxCrossSection = 500*millibarn;
148      if(pi*distance>maxCrossSection) return ti    130      if(pi*distance>maxCrossSection) return time;
149                                                << 131      
150      // charged particles special                 132      // charged particles special
151      static const G4double maxChargedCrossSect    133      static const G4double maxChargedCrossSection = 200*millibarn;
152      if(std::abs(trk1.GetDefinition()->GetPDGC << 134      if(std::abs(trk1.GetDefinition()->GetPDGCharge())>0.1 && 
153         std::abs(trk2.GetDefinition()->GetPDGC    135         std::abs(trk2.GetDefinition()->GetPDGCharge())>0.1 &&
154         pi*distance>maxChargedCrossSection) re    136         pi*distance>maxChargedCrossSection) return time;
155                                                << 137         
156            G4double sqrtS = (trk1.Get4Momentum    138            G4double sqrtS = (trk1.Get4Momentum() + trk2.Get4Momentum()).mag();
157      // neutrons special  pn is largest cross- << 139      // neutrons special   
158      if(( trk1.GetDefinition() == G4Neutron::N    140      if(( trk1.GetDefinition() == G4Neutron::Neutron() ||
159           trk2.GetDefinition() == G4Neutron::N << 141           trk1.GetDefinition() == G4Neutron::Neutron() ) &&
160          sqrtS>1.91*GeV && pi*distance>maxChar << 142     sqrtS>1.91*GeV && pi*distance>maxChargedCrossSection) return time;
161                                                   143 
162 /*                                                144 /*
163  *    if(distance <= sqr(1.14*fermi))             145  *    if(distance <= sqr(1.14*fermi))
164  *    {                                           146  *    {
165  *      time = collisionTime;                     147  *      time = collisionTime;
166  *                                             << 148  *    
167  * *                                              149  * *
168  *  *        G4cout << "Scatter distance/time:    150  *  *        G4cout << "Scatter distance/time: " << std::sqrt(distance)/fermi <<
169  *  *            " / "<< time/ns << G4endl;       151  *  *            " / "<< time/ns << G4endl;
170  *  *         G4ThreeVector pos1=trk1.GetPosit << 152  *  *         G4ThreeVector pos1=trk1.GetPosition(); 
171  *  *         G4ThreeVector pos2=trk2.GetPosit    153  *  *         G4ThreeVector pos2=trk2.GetPosition();
172  *  *         G4LorentzVector xmom1 = trk1.Get    154  *  *         G4LorentzVector xmom1 = trk1.Get4Momentum();
173  *  *         G4LorentzVector xmom2 = trk2.Get << 155  *  *         G4LorentzVector xmom2 = trk2.Get4Momentum();  
174  *  *         G4cout << "position1: " <<  pos1    156  *  *         G4cout << "position1: " <<  pos1.x() << " " << pos1.y() << " "
175  *  *             << pos1.z();                 << 157  *  *             << pos1.z(); 
176  *  *         pos1+=(collisionTime*c_light/xmo    158  *  *         pos1+=(collisionTime*c_light/xmom1.e())*xmom1.vect();
177  *  *         G4cout << " straight line trprt:    159  *  *         G4cout << " straight line trprt: "
178  *  *             <<  pos1.x() << " " << pos1.    160  *  *             <<  pos1.x() << " " << pos1.y() << " "
179  *  *       <<  pos1.z()  << G4endl;              161  *  *       <<  pos1.z()  << G4endl;
180  *  *         G4cout << "position2: " <<  pos2    162  *  *         G4cout << "position2: " <<  pos2.x() << " " << pos2.y() << " "
181  *  *             << pos2.z()  << G4endl;         163  *  *             << pos2.z()  << G4endl;
182  *  *         G4cout << "straight line distanc    164  *  *         G4cout << "straight line distance 2 fixed:" << (pos1-pos2).mag()/fermi << G4endl;
183  *  *         pos2+= (collisionTime*c_light/xm    165  *  *         pos2+= (collisionTime*c_light/xmom2.e())*xmom2.vect();
184  *  *         G4cout<< " straight line trprt:     166  *  *         G4cout<< " straight line trprt: "
185  *  *             <<  pos2.x() << " " << pos2.    167  *  *             <<  pos2.x() << " " << pos2.y() << " "
186  *  *       <<  pos2.z() << G4endl;               168  *  *       <<  pos2.z() << G4endl;
187  *  *         G4cout << "straight line distanc    169  *  *         G4cout << "straight line distance :" << (pos1-pos2).mag()/fermi << G4endl;
188  *  *                                             170  *  *
189  *    }                                           171  *    }
190  *                                             << 172  *    
191  *    if(1)                                       173  *    if(1)
192  *      return time;                              174  *      return time;
193  */                                               175  */
194                                                << 176      
195      if ((trk1.GetActualMass()+trk2.GetActualM    177      if ((trk1.GetActualMass()+trk2.GetActualMass()) > sqrtS) return time;
196                                                   178 
197                                                << 179       
198                                                << 180     
199     const G4VCollision* collision = FindCollis << 181     G4VCollision* collision = FindCollision(trk1,trk2);
200     G4double totalCrossSection;                   182     G4double totalCrossSection;
201     // The cross section is interpreted geomet    183     // The cross section is interpreted geometrically as an area
202     // Two particles are assumed to collide if    184     // Two particles are assumed to collide if their distance is < (totalCrossSection/pi)
203                                                   185 
204     if (collision != 0)                           186     if (collision != 0)
205       {                                           187       {
206         totalCrossSection = collision->CrossSe    188         totalCrossSection = collision->CrossSection(trk1,trk2);
207         if ( totalCrossSection > 0 )              189         if ( totalCrossSection > 0 )
208           {                                       190           {
209 /*        G4cout << " totalCrossection = "<< t    191 /*        G4cout << " totalCrossection = "<< totalCrossSection << ", trk1/2, s, e-m: "
210  *               << trk1.GetDefinition()->GetP    192  *               << trk1.GetDefinition()->GetParticleName()
211  *         << " / "                               193  *         << " / "
212  *               << trk2.GetDefinition()->GetP    194  *               << trk2.GetDefinition()->GetParticleName()
213  *         << ", "                                195  *         << ", "
214  *         << (trk1.Get4Momentum()+trk2.Get4Mo    196  *         << (trk1.Get4Momentum()+trk2.Get4Momentum()).mag()
215  *         << ", "                                197  *         << ", "
216  *         << (trk1.Get4Momentum()+trk2.Get4Mo    198  *         << (trk1.Get4Momentum()+trk2.Get4Momentum()).mag()-
217  *             trk1.Get4Momentum().mag() - trk    199  *             trk1.Get4Momentum().mag() - trk2.Get4Momentum().mag()
218  *         << G4endl;                             200  *         << G4endl;
219  */                                               201  */
220      if (distance <= totalCrossSection / pi)      202      if (distance <= totalCrossSection / pi)
221        {                                          203        {
222          time = collisionTime;                    204          time = collisionTime;
223        }                                          205        }
224           } else                                  206           } else
225     {                                             207     {
226                                                   208 
227      // For debugging...                          209      // For debugging...
228  //       G4cout << " totalCrossection = 0, tr    210  //       G4cout << " totalCrossection = 0, trk1/2, s, e-m: "
229  //              << trk1.GetDefinition()->GetP    211  //              << trk1.GetDefinition()->GetParticleName()
230  //        << " / "                               212  //        << " / "
231  //              << trk2.GetDefinition()->GetP    213  //              << trk2.GetDefinition()->GetParticleName()
232  //        << ", "                                214  //        << ", "
233  //        << (trk1.Get4Momentum()+trk2.Get4Mo    215  //        << (trk1.Get4Momentum()+trk2.Get4Momentum()).mag()
234  //        << ", "                                216  //        << ", "
235  //        << (trk1.Get4Momentum()+trk2.Get4Mo    217  //        << (trk1.Get4Momentum()+trk2.Get4Momentum()).mag()-
236  //            trk1.Get4Momentum().mag() - trk    218  //            trk1.Get4Momentum().mag() - trk2.Get4Momentum().mag()
237  //        << G4endl;                             219  //        << G4endl;
238                                                   220 
239     }                                             221     }
240 /*                                                222 /*
241  *        if(distance <= sqr(5.*fermi))           223  *        if(distance <= sqr(5.*fermi))
242  *         {                                      224  *         {
243  *      G4cout << " distance,xsect, std::sqrt(    225  *      G4cout << " distance,xsect, std::sqrt(xsect/pi) : " << std::sqrt(distance)/fermi
244  *       << " " << totalCrossSection/sqr(fermi    226  *       << " " << totalCrossSection/sqr(fermi)
245  *       << " " << std::sqrt(totalCrossSection    227  *       << " " << std::sqrt(totalCrossSection / pi)/fermi << G4endl;
246  *         }                                      228  *         }
247  */                                               229  */
248                                                   230 
249       }                                           231       }
250     else                                          232     else
251       {                                           233       {
252         time = DBL_MAX;                           234         time = DBL_MAX;
253 //        /*                                      235 //        /*
254         // For debugging                          236         // For debugging
255 //hpw               G4cout << "G4Scatterer - c    237 //hpw               G4cout << "G4Scatterer - collision not found: "
256 //hpw        << trk1.GetDefinition()->GetParti    238 //hpw        << trk1.GetDefinition()->GetParticleName()
257 //hpw        << " - "                             239 //hpw        << " - "
258 //hpw        << trk2.GetDefinition()->GetParti    240 //hpw        << trk2.GetDefinition()->GetParticleName()
259 //hpw        << G4endl;                           241 //hpw        << G4endl;
260         // End of debugging                       242         // End of debugging
261 //        */                                      243 //        */
262       }                                           244       }
263   }                                               245   }
264                                                   246 
265       else                                        247       else
266   {                                               248   {
267         /*                                        249         /*
268     // For debugging                              250     // For debugging
269     G4cout << "G4Scatterer - negative collisio    251     G4cout << "G4Scatterer - negative collisionTime"
270      << ": collisionTime = " << collisionTime     252      << ": collisionTime = " << collisionTime
271      << ", position = " << position               253      << ", position = " << position
272      << ", velocity = " << velocity               254      << ", velocity = " << velocity
273      << G4endl;                                   255      << G4endl;
274     // End of debugging                           256     // End of debugging
275         */                                        257         */
276   }                                               258   }
277                                                   259 
278   return time;                                    260   return time;
279 }                                                 261 }
280                                                   262 
281 //-------------------------------------------- << 263 G4KineticTrackVector* G4Scatterer::Scatter(const G4KineticTrack& trk1, 
282                                                << 264                 const G4KineticTrack& trk2)  
283 G4KineticTrackVector* G4Scatterer::Scatter(con << 
284                 const G4KineticTrack& trk2) co << 
285 {                                                 265 {
286 //   G4double sqrtS = (trk1.Get4Momentum() + t    266 //   G4double sqrtS = (trk1.Get4Momentum() + trk2.Get4Momentum()).mag();
287    G4LorentzVector pInitial=trk1.Get4Momentum(    267    G4LorentzVector pInitial=trk1.Get4Momentum() + trk2.Get4Momentum();
288    G4double energyBalance = pInitial.t();         268    G4double energyBalance = pInitial.t();
289    G4double pxBalance = pInitial.vect().x();      269    G4double pxBalance = pInitial.vect().x();
290    G4double pyBalance = pInitial.vect().y();      270    G4double pyBalance = pInitial.vect().y();
291    G4double pzBalance = pInitial.vect().z();      271    G4double pzBalance = pInitial.vect().z();
292    G4int chargeBalance = G4lrint(trk1.GetDefin    272    G4int chargeBalance = G4lrint(trk1.GetDefinition()->GetPDGCharge()
293                        + trk2.GetDefinition()-    273                        + trk2.GetDefinition()->GetPDGCharge());
294    G4int baryonBalance = trk1.GetDefinition()-    274    G4int baryonBalance = trk1.GetDefinition()->GetBaryonNumber()
295                        + trk2.GetDefinition()-    275                        + trk2.GetDefinition()->GetBaryonNumber();
296                                                << 276    
297    const G4VCollision* collision = FindCollisi << 277    G4VCollision* collision = FindCollision(trk1,trk2);
298    if (collision != 0)                            278    if (collision != 0)
299    {                                              279    {
300      G4double aCrossSection = collision->Cross    280      G4double aCrossSection = collision->CrossSection(trk1,trk2);
301      if (aCrossSection > 0.0)                  << 281      if (aCrossSection > 0.0) 
302      {                                            282      {
303                                                   283 
304                                                   284 
305     #ifdef debug_G4Scatterer                      285     #ifdef debug_G4Scatterer
306   G4cout << "be4 FinalState 1(p,e,m): "           286   G4cout << "be4 FinalState 1(p,e,m): "
307         << trk1.Get4Momentum() << " "             287         << trk1.Get4Momentum() << " "
308         << trk1.Get4Momentum().mag()              288         << trk1.Get4Momentum().mag()
309   << ", 2: "                                      289   << ", 2: "
310         << trk2.Get4Momentum()<< " "              290         << trk2.Get4Momentum()<< " "
311         << trk2.Get4Momentum().mag() << " "       291         << trk2.Get4Momentum().mag() << " "
312         << G4endl;                                292         << G4endl;
313   #endif                                          293   #endif
314                                                   294 
315                                                   295 
316        G4KineticTrackVector* products = collis    296        G4KineticTrackVector* products = collision->FinalState(trk1,trk2);
317        if(!products || products->size() == 0)     297        if(!products || products->size() == 0) return products;
318                                                   298 
319     #ifdef debug_G4Scatterer                      299     #ifdef debug_G4Scatterer
320        G4cout << "size of FS: "<<products->siz << 300        G4cout << "size of FS: "<<products->size()<<G4endl; 
321   #endif                                          301   #endif
322                                                   302 
323        G4KineticTrack *final= products->operat    303        G4KineticTrack *final= products->operator[](0);
324                                                   304 
325                                                   305 
326     #ifdef debug_G4Scatterer                      306     #ifdef debug_G4Scatterer
327         G4cout << "    FinalState 1: "            307         G4cout << "    FinalState 1: "
328     << final->Get4Momentum()<< " "                308     << final->Get4Momentum()<< " "
329     << final->Get4Momentum().mag() ;              309     << final->Get4Momentum().mag() ;
330   #endif                                          310   #endif
331                                                   311 
332         if(products->size() == 1) return produ    312         if(products->size() == 1) return products;
333   final=products->operator[](1);                  313   final=products->operator[](1);
334     #ifdef debug_G4Scatterer                      314     #ifdef debug_G4Scatterer
335   G4cout << ", 2: "                               315   G4cout << ", 2: "
336     << final->Get4Momentum() << " "               316     << final->Get4Momentum() << " "
337           << final->Get4Momentum().mag() << "     317           << final->Get4Momentum().mag() << " " << G4endl;
338   #endif                                          318   #endif
339                                                   319 
340        final= products->operator[](0);            320        final= products->operator[](0);
341        G4LorentzVector pFinal=final->Get4Momen    321        G4LorentzVector pFinal=final->Get4Momentum();
342        if(products->size()==2)                    322        if(products->size()==2)
343        {                                          323        {
344          final=products->operator[](1);           324          final=products->operator[](1);
345          pFinal +=final->Get4Momentum();          325          pFinal +=final->Get4Momentum();
346        }                                          326        }
347                                                   327 
348        #ifdef debug_G4Scatterer                   328        #ifdef debug_G4Scatterer
349        if ( (pInitial-pFinal).mag() > 0.1*MeV     329        if ( (pInitial-pFinal).mag() > 0.1*MeV )
350        {                                          330        {
351           G4cout << "G4Scatterer: momentum imb    331           G4cout << "G4Scatterer: momentum imbalance, pInitial= " <<pInitial << " pFinal= " <<pFinal<< G4endl;
352        }                                          332        }
353        G4cout << "Scatterer costh= " << trk1.G    333        G4cout << "Scatterer costh= " << trk1.Get4Momentum().vect().unit() *(products->operator[](0))->Get4Momentum().vect().unit()<< G4endl;
354        #endif                                     334        #endif
355                                                << 335        
356        for(size_t hpw=0; hpw<products->size();    336        for(size_t hpw=0; hpw<products->size(); hpw++)
357        {                                          337        {
358          energyBalance-=products->operator[](h    338          energyBalance-=products->operator[](hpw)->Get4Momentum().t();
359          pxBalance-=products->operator[](hpw)-    339          pxBalance-=products->operator[](hpw)->Get4Momentum().vect().x();
360          pyBalance-=products->operator[](hpw)-    340          pyBalance-=products->operator[](hpw)->Get4Momentum().vect().y();
361          pzBalance-=products->operator[](hpw)-    341          pzBalance-=products->operator[](hpw)->Get4Momentum().vect().z();
362    chargeBalance-=G4lrint(products->operator[]    342    chargeBalance-=G4lrint(products->operator[](hpw)->GetDefinition()->GetPDGCharge());
363          baryonBalance-=products->operator[](h    343          baryonBalance-=products->operator[](hpw)->GetDefinition()->GetBaryonNumber();
364        }                                          344        }
365        if(std::getenv("ScattererEnergyBalanceC << 345        if(getenv("ScattererEnergyBalanceCheck"))
366          std::cout << "DEBUGGING energy balanc    346          std::cout << "DEBUGGING energy balance A: "
367              <<energyBalance<<" "                 347              <<energyBalance<<" "
368              <<pxBalance<<" "                     348              <<pxBalance<<" "
369              <<pyBalance<<" "                     349              <<pyBalance<<" "
370              <<pzBalance<<" "                     350              <<pzBalance<<" "
371        <<chargeBalance<<" "                       351        <<chargeBalance<<" "
372        <<baryonBalance<<" "                       352        <<baryonBalance<<" "
373        <<G4endl;                                  353        <<G4endl;
374        if(chargeBalance !=0 )                     354        if(chargeBalance !=0 )
375        {                                          355        {
376          G4cout << "track 1"<<trk1.GetDefiniti    356          G4cout << "track 1"<<trk1.GetDefinition()->GetParticleName()<<G4endl;
377          G4cout << "track 2"<<trk2.GetDefiniti    357          G4cout << "track 2"<<trk2.GetDefinition()->GetParticleName()<<G4endl;
378          for(size_t hpw=0; hpw<products->size(    358          for(size_t hpw=0; hpw<products->size(); hpw++)
379          {                                        359          {
380             G4cout << products->operator[](hpw << 360      G4cout << products->operator[](hpw)->GetDefinition()->GetParticleName()<<G4endl;
381          }                                        361          }
382          G4Exception("G4Scatterer", "im_r_matr << 362    G4Exception("We have the problem");
383              "Problem in ChargeBalance");      << 
384        }                                          363        }
385        return products;                           364        return products;
386      }                                         << 365      } 
387    }                                           << 366    } 
388                                                << 367    
389    return NULL;                                   368    return NULL;
390 }                                                 369 }
391                                                   370 
392 //-------------------------------------------- << 
393                                                   371 
394 const G4VCollision* G4Scatterer::FindCollision << 372 G4VCollision* G4Scatterer::FindCollision(const G4KineticTrack& trk1, 
395            const G4KineticTrack& trk2) const   << 373            const G4KineticTrack& trk2)
396 {                                                 374 {
397   G4VCollision* collisionInCharge = 0;            375   G4VCollision* collisionInCharge = 0;
398                                                   376 
399   size_t i;                                       377   size_t i;
400   for (i=0; i<collisions.size(); i++)             378   for (i=0; i<collisions.size(); i++)
401     {                                             379     {
402       G4VCollision* component = collisions[i];    380       G4VCollision* component = collisions[i];
403       if (component->IsInCharge(trk1,trk2))       381       if (component->IsInCharge(trk1,trk2))
404   {                                               382   {
405     collisionInCharge = component;                383     collisionInCharge = component;
406     break;                                        384     break;
407   }                                               385   }
408     }                                             386     }
409 //    if(collisionInCharge)                       387 //    if(collisionInCharge)
410 //    {                                           388 //    {
411 //      G4cout << "found collision : "         << 389 //      G4cout << "found collision : " 
412 //         << collisionInCharge->GetName()<< "    390 //         << collisionInCharge->GetName()<< " "
413 //  << "for "                                     391 //  << "for "
414 //  << trk1.GetDefinition()->GetParticleName()    392 //  << trk1.GetDefinition()->GetParticleName()<<" + "
415 //  << trk2.GetDefinition()->GetParticleName()    393 //  << trk2.GetDefinition()->GetParticleName()<<" "
416 //  << G4endl;;                                   394 //  << G4endl;;
417 //    }                                           395 //    }
418   return collisionInCharge;                       396   return collisionInCharge;
419 }                                                 397 }
420                                                << 398   
421 //-------------------------------------------- << 399 G4double G4Scatterer::GetCrossSection(const G4KineticTrack& trk1, 
422                                                << 400               const G4KineticTrack& trk2)  
423 G4double G4Scatterer::GetCrossSection(const G4 << 
424               const G4KineticTrack& trk2) cons << 
425 {                                                 401 {
426    const G4VCollision* collision = FindCollisi << 402    G4VCollision* collision = FindCollision(trk1,trk2);
427    G4double aCrossSection = 0;                    403    G4double aCrossSection = 0;
428    if (collision != 0)                            404    if (collision != 0)
429    {                                              405    {
430      aCrossSection = collision->CrossSection(t    406      aCrossSection = collision->CrossSection(trk1,trk2);
431    }                                              407    }
432    return aCrossSection;                          408    return aCrossSection;
433 }                                                 409 }
434                                                   410 
435 //-------------------------------------------- << 
436                                                   411 
437 const std::vector<G4CollisionInitialState *> &    412 const std::vector<G4CollisionInitialState *> & G4Scatterer::
438 GetCollisions(G4KineticTrack * aProjectile,    << 413 GetCollisions(G4KineticTrack * aProjectile, 
439               std::vector<G4KineticTrack *> &     414               std::vector<G4KineticTrack *> & someCandidates,
440         G4double aCurrentTime)                    415         G4double aCurrentTime)
441 {                                                 416 {
442   theCollisions.clear();                          417   theCollisions.clear();
443   std::vector<G4KineticTrack *>::iterator j=so    418   std::vector<G4KineticTrack *>::iterator j=someCandidates.begin();
444   for(; j != someCandidates.end(); ++j)           419   for(; j != someCandidates.end(); ++j)
445   {                                               420   {
446     G4double collisionTime = GetTimeToInteract    421     G4double collisionTime = GetTimeToInteraction(*aProjectile, **j);
447     if(collisionTime == DBL_MAX)  // no collis    422     if(collisionTime == DBL_MAX)  // no collision
448     {                                             423     {
449       continue;                                   424       continue;
450     }                                             425     }
451     G4KineticTrackVector aTarget;                 426     G4KineticTrackVector aTarget;
452     aTarget.push_back(*j);                        427     aTarget.push_back(*j);
453     theCollisions.push_back(                      428     theCollisions.push_back(
454       new G4CollisionInitialState(collisionTim    429       new G4CollisionInitialState(collisionTime+aCurrentTime, aProjectile, aTarget, this) );
455 //      G4cerr <<" !!!!!! debug collisions "<< << 430 //      G4cerr <<" !!!!!! debug collisions "<<collisionTime<<" "<<pkt->GetDefinition()->GetParticleName()<<G4endl;      
456    }                                              431    }
457    return theCollisions;                          432    return theCollisions;
458 }                                                 433 }
459                                                   434 
460                                                   435 
461 G4KineticTrackVector * G4Scatterer::              436 G4KineticTrackVector * G4Scatterer::
462 GetFinalState(G4KineticTrack * aProjectile,    << 437 GetFinalState(G4KineticTrack * aProjectile, 
463         std::vector<G4KineticTrack *> & theTar    438         std::vector<G4KineticTrack *> & theTargets)
464 {                                                 439 {
465     G4KineticTrack target_reloc(*(theTargets[0    440     G4KineticTrack target_reloc(*(theTargets[0]));
466     return Scatter(*aProjectile, target_reloc)    441     return Scatter(*aProjectile, target_reloc);
467 }                                                 442 }
468 //-------------------------------------------- << 
469                                                   443