G4ExcitedStringDecay.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // Historic fragment from M.Komogorov; clean-up still necessary @@@
00027 
00028 #include "G4ExcitedStringDecay.hh"
00029 #include "G4SystemOfUnits.hh"
00030 #include "G4KineticTrack.hh"
00031 
00032 G4ExcitedStringDecay::G4ExcitedStringDecay() : G4VStringFragmentation(),
00033         theStringDecay(0)
00034 {}
00035 
00036 G4ExcitedStringDecay::G4ExcitedStringDecay(G4VLongitudinalStringDecay * aStringDecay)
00037 : G4VStringFragmentation(),
00038   theStringDecay(aStringDecay)
00039 {}
00040 
00041 G4ExcitedStringDecay::G4ExcitedStringDecay(const G4ExcitedStringDecay &)
00042 : G4VStringFragmentation(),
00043   theStringDecay(0)
00044 {
00045   throw G4HadronicException(__FILE__, __LINE__, "G4ExcitedStringDecay::copy ctor not accessible");
00046 } 
00047 
00048 G4ExcitedStringDecay::~G4ExcitedStringDecay()
00049 {
00050 }
00051 
00052 const G4ExcitedStringDecay & G4ExcitedStringDecay::operator=(const G4ExcitedStringDecay &)
00053 {
00054   throw G4HadronicException(__FILE__, __LINE__, "G4ExcitedStringDecay::operator= meant to not be accessable");
00055   return *this;
00056 }
00057 
00058 int G4ExcitedStringDecay::operator==(const G4ExcitedStringDecay &) const
00059 {
00060   return 0;
00061 }
00062 
00063 int G4ExcitedStringDecay::operator!=(const G4ExcitedStringDecay &) const
00064 {
00065   return 1;
00066 }
00067 
00068 G4KineticTrackVector *G4ExcitedStringDecay::FragmentString
00069                                 (const G4ExcitedString &theString)
00070 {
00071         if ( theStringDecay == NULL ) 
00072 
00073             theStringDecay=new G4LundStringFragmentation();
00074     
00075         return theStringDecay->FragmentString(theString);
00076 }
00077         
00078 G4KineticTrackVector *G4ExcitedStringDecay::FragmentStrings
00079                                 (const G4ExcitedStringVector * theStrings)
00080 {
00081   G4LorentzVector KTsum(0.,0.,0.,0.);
00082 
00083 //G4cout<<"theStrings->size() "<<theStrings->size()<<G4endl;
00084   for ( unsigned int astring=0; astring < theStrings->size(); astring++)
00085   {
00086         KTsum+= theStrings->operator[](astring)->Get4Momentum();
00087   }
00088 
00089   G4KineticTrackVector * theResult = new G4KineticTrackVector;
00090   G4int attempts(0);
00091   G4bool success=false;
00092   G4bool NeedEnergyCorrector=false;
00093   do {
00094        //G4cout<<"Check of momentum at string fragmentations. New try."<<G4endl;
00095         std::for_each(theResult->begin() , theResult->end() , DeleteKineticTrack());
00096         theResult->clear();
00097 
00098         attempts++;
00099         //G4cout<<G4endl<<"attempts "<<attempts<<G4endl;
00100         G4LorentzVector KTsecondaries(0.,0.,0.,0.);
00101         NeedEnergyCorrector=false;
00102 
00103         for ( unsigned int astring=0; astring < theStrings->size(); astring++)
00104         {
00105           //G4cout<<"String No "<<astring+1<<" "<<theStrings->operator[](astring)->Get4Momentum().mag2()<<" "<<theStrings->operator[](astring)->GetRightParton()->GetPDGcode()<<" "<<theStrings->operator[](astring)->GetLeftParton()->GetPDGcode()<<" "<<theStrings->operator[](astring)->Get4Momentum()<<G4endl;
00106           //G4int Uzhi; G4cin >>Uzhi;
00107           G4KineticTrackVector * generatedKineticTracks = NULL;
00108           if ( theStrings->operator[](astring)->IsExcited() )
00109           {
00110            //G4cout<<"Fragment String"<<G4endl;
00111              generatedKineticTracks=FragmentString(*theStrings->operator[](astring));
00112           } else {
00113              generatedKineticTracks = new G4KineticTrackVector;
00114              generatedKineticTracks->push_back(theStrings->operator[](astring)->GetKineticTrack());
00115           }    
00116 
00117           if (generatedKineticTracks == NULL) 
00118           {
00119              G4cerr << "G4VPartonStringModel:No KineticTracks produced" << G4endl;
00120              continue;
00121           }
00122 
00123           G4LorentzVector KTsum1(0.,0.,0.,0.);
00124           for ( unsigned int aTrack=0; aTrack<generatedKineticTracks->size();aTrack++)
00125           {
00126                   //--debug-- G4cout<<"Prod part "<<(*generatedKineticTracks)[aTrack]->GetDefinition()->GetParticleName()<<" "<<(*generatedKineticTracks)[aTrack]->Get4Momentum()<<G4endl;
00127              theResult->push_back(generatedKineticTracks->operator[](aTrack));
00128              KTsum1+= (*generatedKineticTracks)[aTrack]->Get4Momentum();
00129           }
00130           KTsecondaries+=KTsum1;
00131         
00132               //--debug--G4cout << "String secondaries(" <<generatedKineticTracks->size()<< ")  momentum: "
00133               //--debug--<< theStrings->operator[](astring)->Get4Momentum() << " " << KTsum1 << G4endl;
00134           if  ( KTsum1.e() > 0 && std::abs((KTsum1.e()-theStrings->operator[](astring)->Get4Momentum().e()) / KTsum1.e()) > perMillion )
00135           {
00136                   //--debug--  G4cout << "String secondaries(" <<generatedKineticTracks->size()<< ")  momentum: "
00137                   //--debug--    << theStrings->operator[](astring)->Get4Momentum() << " " << KTsum1 << G4endl;
00138             NeedEnergyCorrector=true;
00139           }
00140 
00141 //        clean up
00142           delete generatedKineticTracks;
00143         }
00144        //--debug  G4cout << "Initial Strings / secondaries total  4 momentum " << KTsum << " " <<KTsecondaries << G4endl;
00145 
00146     success=true;
00147         //G4cout<<"success "<<success<<G4endl;
00148         if ( NeedEnergyCorrector ) success=EnergyAndMomentumCorrector(theResult, KTsum);
00149                 //G4cout<<"success after Ecorr "<<success<<G4endl;
00150   } while(!success && (attempts < 10));   // It was 100 !!! Uzhi
00151                   //G4cout<<"End frag string"<<G4endl;
00152 
00153 #ifdef debug_ExcitedStringDecay
00154   G4LorentzVector  KTsum1=0;
00155   for ( unsigned int aTrack=0; aTrack<theResult->size();aTrack++)
00156   {
00157       G4cout << " corrected tracks .. " << (*theResult)[aTrack]->GetDefinition()->GetParticleName()
00158       <<"  " << (*theResult)[aTrack]->Get4Momentum() << G4endl;
00159       KTsum1+= (*theResult)[aTrack]->Get4Momentum();
00160   }
00161 
00162   G4cout << "Needcorrector/success " << NeedEnergyCorrector << "/" << success << ", Corrected total  4 momentum " << KTsum1  << G4endl;
00163   if ( ! success ) G4cout << "failed to correct E/p" << G4endl;  
00164 #endif
00165 
00166   return theResult;
00167 }
00168 
00169 G4bool G4ExcitedStringDecay::EnergyAndMomentumCorrector
00170                 (G4KineticTrackVector* Output, G4LorentzVector& TotalCollisionMom)   
00171   {
00172     const int    nAttemptScale = 500;
00173     const double ErrLimit = 1.E-5;
00174     if (Output->empty())
00175        return TRUE;
00176     G4LorentzVector SumMom;
00177     G4double        SumMass = 0;     
00178     G4double        TotalCollisionMass = TotalCollisionMom.m();
00179 
00180 //G4cout<<G4endl<<"EnergyAndMomentumCorrector "<<Output->size()<<G4endl;
00181     // Calculate sum hadron 4-momenta and summing hadron mass
00182     unsigned int cHadron;
00183     for(cHadron = 0; cHadron < Output->size(); cHadron++)
00184     {
00185         SumMom  += Output->operator[](cHadron)->Get4Momentum();
00186         SumMass += Output->operator[](cHadron)->GetDefinition()->GetPDGMass();
00187     }
00188 
00189 //G4cout<<"SumMass TotalCollisionMass "<<SumMass<<" "<<TotalCollisionMass<<G4endl;
00190 
00191     // Cannot correct a single particle
00192     if (Output->size() < 2) return FALSE;
00193 
00194     if (SumMass > TotalCollisionMass) return FALSE;
00195     SumMass = SumMom.m2();
00196     if (SumMass < 0) return FALSE;
00197     SumMass = std::sqrt(SumMass);
00198 
00199      // Compute c.m.s. hadron velocity and boost KTV to hadron c.m.s.
00200     G4ThreeVector Beta = -SumMom.boostVector();
00201     Output->Boost(Beta);
00202 
00203     // Scale total c.m.s. hadron energy (hadron system mass).
00204     // It should be equal interaction mass
00205     G4double Scale = 1;
00206     G4int cAttempt = 0;
00207     G4double Sum = 0;
00208     G4bool success = false;
00209     for(cAttempt = 0; cAttempt < nAttemptScale; cAttempt++)
00210     {
00211       Sum = 0;
00212       for(cHadron = 0; cHadron < Output->size(); cHadron++)
00213       {
00214         G4LorentzVector HadronMom = Output->operator[](cHadron)->Get4Momentum();
00215         HadronMom.setVect(Scale*HadronMom.vect());
00216         G4double E = std::sqrt(HadronMom.vect().mag2() + sqr(Output->operator[](cHadron)->GetDefinition()->GetPDGMass()));
00217         HadronMom.setE(E);
00218         Output->operator[](cHadron)->Set4Momentum(HadronMom);
00219         Sum += E;
00220       } 
00221       Scale = TotalCollisionMass/Sum;    
00222 #ifdef debug_G4ExcitedStringDecay 
00223       G4cout << "Scale-1=" << Scale -1 
00224                 << ",  TotalCollisionMass=" << TotalCollisionMass
00225                 << ",  Sum=" << Sum
00226                 << G4endl;
00227 #endif     
00228       if (std::fabs(Scale - 1) <= ErrLimit) 
00229       {
00230         success = true;
00231         break;
00232       }
00233     }
00234 #ifdef debug_G4ExcitedStringDecay     
00235     if(!success)
00236     {
00237       G4cout << "G4ExcitedStringDecay::EnergyAndMomentumCorrector - Warning"<<G4endl;
00238       G4cout << "   Scale not unity at end of iteration loop: "<<TotalCollisionMass<<" "<<Sum<<" "<<Scale<<G4endl;
00239       G4cout << "   Number of secondaries: " << Output->size() << G4endl;
00240       G4cout << "   Wanted total energy: " <<  TotalCollisionMom.e() << G4endl; 
00241       G4cout << "   Increase number of attempts or increase ERRLIMIT"<<G4endl;
00242 //       throw G4HadronicException(__FILE__, __LINE__, "G4ExcitedStringDecay failed to correct...");
00243     }
00244 #endif     
00245     // Compute c.m.s. interaction velocity and KTV back boost   
00246     Beta = TotalCollisionMom.boostVector();
00247     Output->Boost(Beta);
00248 
00249     return success;
00250   }

Generated on Mon May 27 17:48:14 2013 for Geant4 by  doxygen 1.4.7