Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

GeoSwimApplication.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // GeoSwimApplication
00004 //
00005 // January 20, 2006  M.Ishitsuka First version for GeoSwimmer
00006 //                   ref. PTSimApplication.cxx by S. Kasahara 05/04
00007 //
00009 
00010 #include <iostream>
00011 #include <fstream>
00012 using namespace std;
00013 
00014 #include <TGeoManager.h>
00015 #include <TGeoTrack.h>
00016 #include <TVirtualMC.h>
00017 #include <TParticlePDG.h>
00018 #include <TLorentzVector.h>
00019 #include <TVector3.h>
00020 #include <TDatabasePDG.h>
00021 #include <TClonesArray.h>
00022 #include <TArrayI.h>
00023 #include <TMCProcess.h>
00024 #include <TNtuple.h>
00025 #include <TH1D.h>
00026 #include <TMath.h>
00027 
00028 #include "GeoSwimmer/GeoSwimApplication.h"
00029 #include "GeoSwimmer/GeoSwimZCondition.h"
00030 #include "MCApplication/MCApplication.h"
00031 #include "MessageService/MsgService.h"
00032 #include "Conventions/Munits.h"
00033 
00034 # define g3ekbin  g3ekbin_
00035 # define gcomad gcomad_
00036 # define type_of_call
00037 # define DEFCHARD     const char* 
00038 # define DEFCHARL   , const int 
00039 # define PASSCHARD(string) string 
00040 # define PASSCHARL(string) , strlen(string) 
00041 
00042 extern "C"
00043 {
00044   void type_of_call g3ekbin();
00045   void type_of_call gcomad(DEFCHARD, Int_t*& DEFCHARL);
00046 }
00047 
00048 CVSID("$Id: GeoSwimApplication.cxx,v 1.8 2008/08/01 04:23:12 ishi Exp $");
00049 
00050 ClassImp(GeoSwimApplication)
00051 
00052 //......................................................................
00053 
00054 //__________________________________________________________
00055 GeoSwimApplication::GeoSwimApplication(const char* name, const char* title) 
00056   : MCAppUser(name,title),fGeoSwimStack(0),
00057     fExitLiner(false)
00058 {
00059   // Normal constructor
00060 
00061   MSG("GeoSwim",Msg::kDebug) << "GeoSwimApplication normal ctor @ " 
00062                                << this << endl;
00063   fGeoSwimStack = new GeoSwimStack();
00064 
00065   MSG("GeoSwim",Msg::kDebug) << "Get address of common GCTRAK"  << endl;
00066   gcomad(PASSCHARD("GCTRAK"),(int*&) fGctrak  PASSCHARL("GCTRAK"));
00067   MSG("GeoSwim",Msg::kDebug) << "Get address of common GCFLAG"  << endl;
00068   gcomad(PASSCHARD("GCFLAG"),(int*&) fGcflag  PASSCHARL("GCFLAG"));
00069 
00070 }
00071 
00072 //__________________________________________________________
00073 GeoSwimApplication::~GeoSwimApplication() {
00074   // delete all the owned sub-objects
00075 
00076   MSG("GeoSwim",Msg::kDebug) << "GeoSwimApplication dtor @ " 
00077                                << this << endl;
00078  
00079   if ( fGeoSwimStack ) delete fGeoSwimStack; fGeoSwimStack = 0;
00080 
00081 }
00082 
00083 //_____________________________________________________________________________
00084 void GeoSwimApplication::BeginEvent() {    
00085 
00086 
00087   bool toswim = true;
00088   const_cast<MCApplication&>(MCApplication::Instance()).SwitchMedia(toswim);
00089 
00090   MSG("GeoSwim",Msg::kDebug) << "GeoSwimApplication::BeginEvent " 
00091                            << endl;
00092 
00093 }
00094 
00095 //_____________________________________________________________________________
00096 void GeoSwimApplication::BeginPrimary() {    
00097   gGeoManager->SetTminTmax(999999,-999999); // sec
00098   
00099 }
00100 
00101 //_____________________________________________________________________________
00102 void GeoSwimApplication::PreTrack() {    
00103   //
00104   // User actions at beginning of each track
00105   // Called by TGeant3gu::gutrak() before calling g3track.
00106   gMC->TrackPosition(fInitPosition);
00107   gMC->TrackMomentum(fInitMomentum);
00108   fGcflag->nrndm[0] = 0;
00109   fGcflag->nrndm[1] = 0;
00110   fStep = 0;
00111   fS = 0.;
00112   fRange = 0.;
00113 }
00114 
00115 //_____________________________________________________________________________
00116 void GeoSwimApplication::Stepping() {    
00117   //
00118   // User actions at each step
00119   // Called by TGeant3gu::gustep 
00120 
00121   TLorentzVector pos;
00122   gMC->TrackPosition(pos);
00123   TLorentzVector mom;
00124   gMC->TrackMomentum(mom);
00125   Float_t a=0.,z=0.,dens=0.,radl=0.,absl=0.;
00126   Float_t small = 1e-04;
00127   Int_t curmat;
00128   curmat = gMC->CurrentMaterial(a,z,dens,radl,absl);
00129 
00130   // Increasing energy in case of backward swimming: E' = E - dE + 2*dE.
00131   if(fDir==-1){
00132     fGctrak->gekin = fGctrak->gekin + 2.*fGctrak->destep;
00133     fGctrak->getot = fGctrak->gekin + gMC->TrackMass();
00134     fGctrak->vect[6] = sqrt((fGctrak->getot+gMC->TrackMass())*fGctrak->gekin);
00135     g3ekbin();
00136   }
00137 
00138   fS += gMC->TrackStep();
00139   fRange += dens*gMC->TrackStep();
00140 
00141   if((fInitPosition.Z() < fZCondition && pos.Z() >= fZCondition)
00142      || (fInitPosition.Z() > fZCondition  && pos.Z() <= fZCondition)) {
00143 
00144     MSG("GeoSwim",Msg::kDebug) << "Condition satisfied" << endl;
00145     fSatisfied = true;
00146 
00147     // Correction of position, energy and direction.
00148     float frac = (TMath::Abs(pos.Z()-fPreVect[2]) > small) ?
00149       (fZCondition-fPreVect[2])/(pos.Z()-fPreVect[2]):
00150       0.;
00151     // Position
00152     fGctrak->vect[0] = fPreVect[0]+(fGctrak->vect[0]-fPreVect[0])*frac;
00153     fGctrak->vect[1] = fPreVect[1]+(fGctrak->vect[1]-fPreVect[1])*frac;
00154     fGctrak->vect[2] = fPreVect[2]+(fGctrak->vect[2]-fPreVect[2])*frac;
00155     // Direction
00156     TVector3 direction(fGctrak->vect[3]*frac + fPreVect[3]*(1.-frac),
00157                        fGctrak->vect[4]*frac + fPreVect[4]*(1.-frac),
00158                        fGctrak->vect[5]*frac + fPreVect[5]*(1.-frac));
00159     direction = direction.Unit();
00160     fGctrak->vect[3] = direction.x();
00161     fGctrak->vect[4] = direction.y();
00162     fGctrak->vect[5] = direction.z();
00163     // Momentum and energy
00164     fGctrak->vect[6] = (fGctrak->vect[6]*frac + fPreVect[6]*(1.-frac));
00165     fGctrak->getot = pow(fGctrak->vect[6],2) + pow(gMC->TrackMass(),2);
00166 
00167     // Strop Run and return "satisfied"
00168     gMC->StopTrack();
00169     return;
00170   }
00171 
00172   if ( IsExiting() ) {
00173     MSG("GeoSwim",Msg::kDebug) 
00174       << "Track is entering MARS from LINR, call StopTrack" << endl;
00175     fSatisfied = false;
00176     gMC -> StopTrack();  
00177     return;
00178   }
00179 
00180   if(fInitMomentum.Z()*mom.Z()<0.){
00181     MSG("GeoSwim",Msg::kDebug)
00182       << "Negative Momentum\n";
00183     fSatisfied = false;
00184     gMC->StopTrack();
00185     return;
00186   }    
00187 
00188   fStep++;
00189   if(fStep>10000){
00190     MSG("GeoSwim",Msg::kWarning)
00191       << "GeoSwimApplication::Stepping more than 10000 steps"
00192       << fInitPosition.X() << " " << fInitPosition.Y() << " "
00193       << fInitPosition.Z() << " " << fInitMomentum.X() << " "
00194       << fInitMomentum.Y() << " " << fInitMomentum.Z() << " "
00195       << pos.X() << " " << pos.Y() << " " << pos.Z() << " "
00196       << fZCondition << endl;
00197     fSatisfied = false;
00198     gMC->StopTrack();
00199     return;
00200   }    
00201 
00202   if (pos.X() > fHallMax.X()/Munits::cm ||
00203       pos.X() < fHallMin.X()/Munits::cm ||
00204       pos.Y() > fHallMax.Y()/Munits::cm ||
00205       pos.Y() < fHallMin.Y()/Munits::cm ||
00206       pos.Z() > fHallMax.Z()/Munits::cm ||
00207       pos.Z() < fHallMin.Z()/Munits::cm) {
00208     MSG("GeoSwim",Msg::kDebug)
00209       << "GeoSwimmer::Swim Out of hall"
00210       << pos.X() << " " << pos.Y() << " " << pos.Z() << "\n";
00211     fSatisfied = false;
00212     gMC -> StopTrack();  
00213     return;
00214   }
00215 
00216   // Store /GCTRAK/VECT(7) as the status of previous step
00217   for(int i=0;i<7;i++){
00218       fPreVect[i]=fGctrak->vect[i];
00219   }
00220 }
00221 
00222 //_____________________________________________________________________________
00223 bool GeoSwimApplication::IsExiting() {    
00224   if ( gMC -> IsTrackExiting() ) {
00225     if ( std::string(gMC -> CurrentVolName() ) == "LINR" ) {
00226       fExitLiner = true;
00227     }
00228   }
00229   else if ( gMC -> IsTrackEntering() && fExitLiner ) {
00230     if ( std::string(gMC -> CurrentVolName() ) == "MARS" ) {
00231       return true;
00232     }
00233   }
00234 
00235   return false;
00236   
00237 }
00238 
00239 //_____________________________________________________________________________
00240 void GeoSwimApplication::PostTrack() {    
00241   fExitLiner = false; // reset exit flag
00242   
00243   MSG("GeoSwim",Msg::kDebug) << "GeoSwimApplication::PostTrack" << endl;
00244 
00245 }
00246 
00247 //_____________________________________________________________________________
00248 void GeoSwimApplication::FinishPrimary() {    
00249 
00250   MSG("GeoSim",Msg::kDebug) << "GeoSwimApplication::FinishPrimary " << endl;
00251 
00252 } 
00253 
00254 //_____________________________________________________________________________
00255 void GeoSwimApplication::FinishEvent() {    
00256 
00257   MSG("GeoSim",Msg::kDebug) << "GeoSwimApplication::FinishEvent " << endl;
00258 
00259   fGeoSwimStack -> Reset();
00260 
00261 } 
00262 
00263 //......................................................................
00264 
00265 void GeoSwimApplication::SetZCondition(GeoSwimZCondition &c) 
00266 { 
00267   fSatisfied = false;
00268   fZCondition = c.GetZFinal()/Munits::cm;
00269 }
00270 
00271 //......................................................................
00272 
00273 void GeoSwimApplication::SetDirection(Int_t idir) 
00274 { 
00275   fDir = idir;
00276 }
00277 
00278 //......................................................................
00279 
00280 void GeoSwimApplication::SetHallSize(TVector3 min, TVector3 max) 
00281 { 
00282   fHallMin = min;
00283   fHallMax = max;
00284 }
00285 
00286 //......................................................................
00287 
00288 bool GeoSwimApplication::GetSatisfied() 
00289 { 
00290   return fSatisfied;
00291 }
00292 
00293 //......................................................................
00294 
00295 Double_t GeoSwimApplication::GetS() 
00296 { 
00297   return fS;
00298 }
00299 
00300 //......................................................................
00301 
00302 Double_t GeoSwimApplication::GetRange() 
00303 { 
00304   return fRange;
00305 }
00306 
00307 //_____________________________________________________________________________

Generated on Mon Feb 15 11:06:45 2010 for loon by  doxygen 1.3.9.1