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.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 /run/src/G4MaterialScanner.cc (Version 11.3.0) and /run/src/G4MaterialScanner.cc (Version 10.0)


  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 // G4MaterialScanner implementation            << 
 27 //                                                 26 //
 28 // Author: M.Asai, May 2006                    <<  27 // $Id: G4MaterialScanner.cc 66892 2013-01-17 10:57:59Z gunter $
 29 // ------------------------------------------- <<  28 //
                                                   >>  29 //
                                                   >>  30 //
 30                                                    31 
 31 #include "G4MaterialScanner.hh"                    32 #include "G4MaterialScanner.hh"
 32                                                    33 
 33 #include "G4Event.hh"                          <<  34 #include "G4SystemOfUnits.hh"
 34 #include "G4EventManager.hh"                       35 #include "G4EventManager.hh"
 35 #include "G4GeometryManager.hh"                << 
 36 #include "G4MSSteppingAction.hh"               << 
 37 #include "G4MatScanMessenger.hh"                   36 #include "G4MatScanMessenger.hh"
 38 #include "G4ProcessManager.hh"                 << 
 39 #include "G4ProcessVector.hh"                  << 
 40 #include "G4RayShooter.hh"                         37 #include "G4RayShooter.hh"
                                                   >>  38 #include "G4MSSteppingAction.hh"
                                                   >>  39 #include "G4GeometryManager.hh"
                                                   >>  40 #include "G4StateManager.hh"
                                                   >>  41 #include "G4Event.hh"
                                                   >>  42 #include "G4TransportationManager.hh"
                                                   >>  43 #include "G4RunManagerKernel.hh"
 41 #include "G4Region.hh"                             44 #include "G4Region.hh"
 42 #include "G4RegionStore.hh"                        45 #include "G4RegionStore.hh"
 43 #include "G4RunManagerKernel.hh"               <<  46 #include "G4ProcessManager.hh"
                                                   >>  47 #include "G4ProcessVector.hh"
 44 #include "G4SDManager.hh"                          48 #include "G4SDManager.hh"
 45 #include "G4StateManager.hh"                   << 
 46 #include "G4SystemOfUnits.hh"                  << 
 47 #include "G4TransportationManager.hh"          << 
 48                                                    49 
 49 // ------------------------------------------- <<  50 
 50 G4MaterialScanner::G4MaterialScanner()             51 G4MaterialScanner::G4MaterialScanner()
 51 {                                                  52 {
 52   theRayShooter = new G4RayShooter();              53   theRayShooter = new G4RayShooter();
 53   theMessenger = new G4MatScanMessenger(this);     54   theMessenger = new G4MatScanMessenger(this);
 54   theEventManager = G4EventManager::GetEventMa     55   theEventManager = G4EventManager::GetEventManager();
 55                                                    56 
 56   eyePosition = G4ThreeVector(0., 0., 0.);     <<  57   theUserEventAction = 0;
 57   thetaSpan = 90. * deg;                       <<  58   theUserStackingAction = 0;
 58   phiSpan = 360. * deg;                        <<  59   theUserTrackingAction = 0;
                                                   >>  60   theUserSteppingAction = 0;
                                                   >>  61 
                                                   >>  62   theMatScannerEventAction = 0;
                                                   >>  63   theMatScannerStackingAction = 0;
                                                   >>  64   theMatScannerTrackingAction = 0;
                                                   >>  65   theMatScannerSteppingAction = 0;
                                                   >>  66 
                                                   >>  67   eyePosition = G4ThreeVector(0.,0.,0.);
                                                   >>  68   nTheta = 91;
                                                   >>  69   thetaMin = 0.*deg;
                                                   >>  70   thetaSpan = 90.*deg;
                                                   >>  71   nPhi = 37;
                                                   >>  72   phiMin = 0.*deg;
                                                   >>  73   phiSpan = 360.*deg;
                                                   >>  74 
                                                   >>  75   regionSensitive = false;
                                                   >>  76   regionName = "notDefined";
                                                   >>  77   theRegion = 0;
 59 }                                                  78 }
 60                                                    79 
 61 // ------------------------------------------- << 
 62 G4MaterialScanner::~G4MaterialScanner()            80 G4MaterialScanner::~G4MaterialScanner()
 63 {                                                  81 {
 64   delete theRayShooter;                            82   delete theRayShooter;
 65   delete theMatScannerSteppingAction;              83   delete theMatScannerSteppingAction;
 66   delete theMessenger;                             84   delete theMessenger;
 67 }                                                  85 }
 68                                                    86 
 69 // ------------------------------------------- << 
 70 void G4MaterialScanner::Scan()                     87 void G4MaterialScanner::Scan()
 71 {                                                  88 {
 72   G4StateManager* theStateMan = G4StateManager     89   G4StateManager* theStateMan = G4StateManager::GetStateManager();
 73   G4ApplicationState currentState = theStateMa     90   G4ApplicationState currentState = theStateMan->GetCurrentState();
 74   if (currentState != G4State_Idle) {          <<  91   if(currentState!=G4State_Idle)
                                                   >>  92   {
 75     G4cerr << "Illegal application state - Sca     93     G4cerr << "Illegal application state - Scan() ignored." << G4endl;
 76     return;                                        94     return;
 77   }                                                95   }
 78                                                    96 
 79   if (theMatScannerSteppingAction == nullptr)  <<  97   if(!theMatScannerSteppingAction)
 80     theMatScannerSteppingAction = new G4MSStep <<  98   { theMatScannerSteppingAction = new G4MSSteppingAction(); }
 81   }                                            << 
 82   StoreUserActions();                              99   StoreUserActions();
 83   DoScan();                                       100   DoScan();
 84   RestoreUserActions();                           101   RestoreUserActions();
 85 }                                                 102 }
 86                                                   103 
 87 // ------------------------------------------- << 
 88 void G4MaterialScanner::StoreUserActions()        104 void G4MaterialScanner::StoreUserActions()
 89 {                                              << 105 { 
 90   theUserEventAction = theEventManager->GetUse    106   theUserEventAction = theEventManager->GetUserEventAction();
 91   theUserStackingAction = theEventManager->Get    107   theUserStackingAction = theEventManager->GetUserStackingAction();
 92   theUserTrackingAction = theEventManager->Get    108   theUserTrackingAction = theEventManager->GetUserTrackingAction();
 93   theUserSteppingAction = theEventManager->Get    109   theUserSteppingAction = theEventManager->GetUserSteppingAction();
 94                                                   110 
 95   theEventManager->SetUserAction(theMatScanner    111   theEventManager->SetUserAction(theMatScannerEventAction);
 96   theEventManager->SetUserAction(theMatScanner    112   theEventManager->SetUserAction(theMatScannerStackingAction);
 97   theEventManager->SetUserAction(theMatScanner    113   theEventManager->SetUserAction(theMatScannerTrackingAction);
 98   theEventManager->SetUserAction(theMatScanner    114   theEventManager->SetUserAction(theMatScannerSteppingAction);
 99                                                   115 
100   G4SDManager* theSDMan = G4SDManager::GetSDMp    116   G4SDManager* theSDMan = G4SDManager::GetSDMpointerIfExist();
101   if (theSDMan != nullptr) {                   << 117   if(theSDMan)
102     theSDMan->Activate("/", false);            << 118   { theSDMan->Activate("/",false); }
103   }                                            << 
104                                                   119 
105   G4GeometryManager* theGeomMan = G4GeometryMa    120   G4GeometryManager* theGeomMan = G4GeometryManager::GetInstance();
106   theGeomMan->OpenGeometry();                     121   theGeomMan->OpenGeometry();
107   theGeomMan->CloseGeometry(true);                122   theGeomMan->CloseGeometry(true);
108 }                                                 123 }
109                                                   124 
110 // ------------------------------------------- << 
111 void G4MaterialScanner::RestoreUserActions()      125 void G4MaterialScanner::RestoreUserActions()
112 {                                                 126 {
113   theEventManager->SetUserAction(theUserEventA    127   theEventManager->SetUserAction(theUserEventAction);
114   theEventManager->SetUserAction(theUserStacki    128   theEventManager->SetUserAction(theUserStackingAction);
115   theEventManager->SetUserAction(theUserTracki    129   theEventManager->SetUserAction(theUserTrackingAction);
116   theEventManager->SetUserAction(theUserSteppi    130   theEventManager->SetUserAction(theUserSteppingAction);
117                                                   131 
118   G4SDManager* theSDMan = G4SDManager::GetSDMp    132   G4SDManager* theSDMan = G4SDManager::GetSDMpointerIfExist();
119   if (theSDMan != nullptr) {                   << 133   if(theSDMan)
120     theSDMan->Activate("/", true);             << 134   { theSDMan->Activate("/",true); }
121   }                                            << 
122 }                                                 135 }
123                                                   136 
124 // ------------------------------------------- << 
125 void G4MaterialScanner::DoScan()                  137 void G4MaterialScanner::DoScan()
126 {                                                 138 {
127   // Confirm material table is updated         << 139 // Confirm material table is updated
128   G4RunManagerKernel::GetRunManagerKernel()->U    140   G4RunManagerKernel::GetRunManagerKernel()->UpdateRegion();
129                                                   141 
130   // Close geometry and set the application st << 142 /////  // Make sure Geantino has been initialized
                                                   >> 143 /////  G4ProcessVector* pVector
                                                   >> 144 /////    = G4Geantino::GeantinoDefinition()->GetProcessManager()->GetProcessList();
                                                   >> 145 /////  for (G4int j=0; j < pVector->size(); ++j) {
                                                   >> 146 /////      (*pVector)[j]->BuildPhysicsTable(*(G4Geantino::GeantinoDefinition()));
                                                   >> 147 /////  }
                                                   >> 148 
                                                   >> 149 // Close geometry and set the application state
131   G4GeometryManager* geomManager = G4GeometryM    150   G4GeometryManager* geomManager = G4GeometryManager::GetInstance();
132   geomManager->OpenGeometry();                    151   geomManager->OpenGeometry();
133   geomManager->CloseGeometry(true, false);     << 152   geomManager->CloseGeometry(1,0);
134                                                << 153   
135   G4ThreeVector center(0, 0, 0);               << 154   G4ThreeVector center(0,0,0);
136   G4Navigator* navigator =                        155   G4Navigator* navigator =
137     G4TransportationManager::GetTransportation << 156       G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
138   navigator->LocateGlobalPointAndSetup(center, << 157   navigator->LocateGlobalPointAndSetup(center,0,false);
139                                                   158 
140   G4StateManager* theStateMan = G4StateManager    159   G4StateManager* theStateMan = G4StateManager::GetStateManager();
141   theStateMan->SetNewState(G4State_GeomClosed) << 160   theStateMan->SetNewState(G4State_GeomClosed); 
142                                                   161 
143   // Event loop                                << 162 // Event loop
144   G4int iEvent = 0;                               163   G4int iEvent = 0;
145   for (G4int iTheta = 0; iTheta < nTheta; ++iT << 164   for(G4int iTheta=0;iTheta<nTheta;iTheta++)
146     G4double theta = thetaMin;                 << 165   {
147     if (iTheta > 0) theta += G4double(iTheta)  << 166    G4double theta = thetaMin;
148     G4double aveLength = 0.;                   << 167    if(iTheta>0) theta += G4double(iTheta)*thetaSpan/G4double(nTheta-1);
149     G4double aveX0 = 0.;                       << 168    G4double aveLength = 0.;
150     G4double aveLambda = 0.;                   << 169    G4double aveX0 = 0.;
151     G4cout << G4endl;                          << 170    G4double aveLambda = 0.;
152     G4cout << "         Theta(deg)    Phi(deg) << 171    G4cout << G4endl;
                                                   >> 172    G4cout << "         Theta(deg)    Phi(deg)  Length(mm)          x0     lambda0" << G4endl;
                                                   >> 173    G4cout << G4endl;
                                                   >> 174    for(G4int iPhi=0;iPhi<nPhi;iPhi++)
                                                   >> 175    {
                                                   >> 176     G4Event* anEvent = new G4Event(iEvent++);
                                                   >> 177     G4double phi = phiMin;
                                                   >> 178     if(iPhi>0) phi += G4double(iPhi)*phiSpan/G4double(nPhi-1);
                                                   >> 179     eyeDirection = G4ThreeVector(std::cos(theta)*std::cos(phi),
                                                   >> 180                                  std::cos(theta)*std::sin(phi),
                                                   >> 181                                  std::sin(theta));
                                                   >> 182     theRayShooter->Shoot(anEvent,eyePosition,eyeDirection);
                                                   >> 183     theMatScannerSteppingAction->Initialize(regionSensitive,theRegion);
                                                   >> 184     theEventManager->ProcessOneEvent(anEvent);
                                                   >> 185     G4double length = theMatScannerSteppingAction->GetTotalStepLength();
                                                   >> 186     G4double x0 = theMatScannerSteppingAction->GetX0();
                                                   >> 187     G4double lambda = theMatScannerSteppingAction->GetLambda0();
                                                   >> 188 
                                                   >> 189     G4cout << "        "
                                                   >> 190            << std::setw(11) << theta/deg << " "
                                                   >> 191            << std::setw(11) << phi/deg << " "
                                                   >> 192            << std::setw(11) << length/mm << " "
                                                   >> 193            << std::setw(11) << x0 << " "
                                                   >> 194            << std::setw(11) << lambda << G4endl;
                                                   >> 195     aveLength += length/mm;
                                                   >> 196     aveX0 += x0;
                                                   >> 197     aveLambda += lambda;
                                                   >> 198    }
                                                   >> 199    if(nPhi>1)
                                                   >> 200    {
153     G4cout << G4endl;                             201     G4cout << G4endl;
154     for (G4int iPhi = 0; iPhi < nPhi; ++iPhi)  << 202     G4cout << " ave. for theta = " << std::setw(11) << theta/deg << " : "
155       auto anEvent = new G4Event(iEvent++);    << 203            << std::setw(11) << aveLength/nPhi << " "
156       G4double phi = phiMin;                   << 204            << std::setw(11) << aveX0/nPhi << " "
157       if (iPhi > 0) phi += G4double(iPhi) * ph << 205            << std::setw(11) << aveLambda/nPhi << G4endl;
158       eyeDirection = G4ThreeVector(std::cos(th << 206    }
159                                    std::sin(th << 
160       theRayShooter->Shoot(anEvent, eyePositio << 
161       theMatScannerSteppingAction->Initialize( << 
162       theEventManager->ProcessOneEvent(anEvent << 
163       G4double length = theMatScannerSteppingA << 
164       G4double x0 = theMatScannerSteppingActio << 
165       G4double lambda = theMatScannerSteppingA << 
166                                                << 
167       G4cout << "        " << std::setw(11) << << 
168              << " " << std::setw(11) << length << 
169              << std::setw(11) << lambda;       << 
170       if(1 == verbosity)                       << 
171       {                                        << 
172         theMatScannerSteppingAction->PrintInte << 
173       }                                        << 
174       else if(2 == verbosity)                  << 
175       {                                        << 
176         theMatScannerSteppingAction->PrintEach << 
177       }                                        << 
178       G4cout << G4endl;                        << 
179       aveLength += length / mm;                << 
180       aveX0 += x0;                             << 
181       aveLambda += lambda;                     << 
182     }                                          << 
183     if (nPhi > 1) {                            << 
184       G4cout << G4endl;                        << 
185       G4cout << " ave. for theta = " << std::s << 
186              << aveLength / nPhi << " " << std << 
187              << aveLambda / nPhi << G4endl;    << 
188     }                                          << 
189   }                                               207   }
190                                                   208 
191   theStateMan->SetNewState(G4State_Idle);      << 209   theStateMan->SetNewState(G4State_Idle); 
192   return;                                         210   return;
193 }                                                 211 }
194                                                   212 
195 // ------------------------------------------- << 
196 G4bool G4MaterialScanner::SetRegionName(const     213 G4bool G4MaterialScanner::SetRegionName(const G4String& val)
197 {                                                 214 {
198   G4Region* aRegion = G4RegionStore::GetInstan    215   G4Region* aRegion = G4RegionStore::GetInstance()->GetRegion(val);
199   if (aRegion != nullptr) {                    << 216   if(aRegion)
                                                   >> 217   {
200     theRegion = aRegion;                          218     theRegion = aRegion;
201     regionName = val;                             219     regionName = val;
202     return true;                                  220     return true;
203   }                                               221   }
204                                                << 222   else
205   G4cerr << "Region <" << val << "> not found. << 223   {
206   G4cerr << "Defined regions are : " << G4endl << 224     G4cerr << "Region <" << val << "> not found. Command ignored." << G4endl;
207   for (const auto& i : *G4RegionStore::GetInst << 225     G4cerr << "Defined regions are : " << G4endl;
208     G4cerr << " " << i->GetName();             << 226     for(size_t i=0;i<G4RegionStore::GetInstance()->size();i++)
                                                   >> 227     { G4cerr << " " << (*(G4RegionStore::GetInstance()))[i]->GetName(); }
                                                   >> 228     G4cerr << G4endl;
                                                   >> 229     return false;
209   }                                               230   }
210   G4cerr << G4endl;                            << 
211   return false;                                << 
212 }                                                 231 }
213                                                   232