]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
check for max number of steps moved from AliSteppingAction here
authorivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 7 Feb 2001 14:38:06 +0000 (14:38 +0000)
committerivana <ivana@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 7 Feb 2001 14:38:06 +0000 (14:38 +0000)
TGeant4/TG4SteppingAction.cxx
TGeant4/TG4SteppingAction.h

index 6c8a3d4365a28fa28f59255e8c2899fe323419e3..07dcaec197570be1f247ef012c0602129e24833a 100644 (file)
@@ -7,7 +7,15 @@
 #include "TG4VSensitiveDetector.h"
 #include "TG4Globals.h"
 
 #include "TG4VSensitiveDetector.h"
 #include "TG4Globals.h"
 
-TG4SteppingAction::TG4SteppingAction() {
+#include <G4Track.hh>
+#include <G4SteppingManager.hh>
+
+TG4SteppingAction::TG4SteppingAction() 
+  : fMaxNofSteps(kMaxNofSteps),
+    fStandardVerboseLevel(0),
+    fLoopVerboseLevel(1),
+    fLoopStepCounter(0)
+ {
 //
 }
 
 //
 }
 
@@ -33,6 +41,59 @@ TG4SteppingAction::operator=(const TG4SteppingAction &right)
   return *this;
 }
 
   return *this;
 }
 
+// protected methods
+
+void TG4SteppingAction::PrintTrackInfo(const G4Track* track) const
+{
+// Prints the track info
+// - taken from private G4TrackingManager::Verbose()
+// and the standard header for verbose tracking
+// - taken from G4SteppingVerbose::TrackingStarted().
+// ---
+
+  // print track info
+  G4cout << G4endl;
+  G4cout << "*******************************************************"
+         << "**************************************************"
+         << G4endl;
+  G4cout << "* G4Track Information: " 
+         << "  Particle = " << track->GetDefinition()->GetParticleName() 
+         << "," 
+        << "   Track ID = " << track->GetTrackID() 
+         << "," 
+        << "   Parent ID = " << track->GetParentID() 
+         << G4endl;
+  G4cout << "*******************************************************"
+         << "**************************************************"
+         << G4endl;
+  G4cout << G4endl;
+      
+  // print header    
+#ifdef G4_USE_G4BESTUNIT_FOR_VERBOSE
+    G4cout << G4std::setw( 5) << "Step#"  << " "
+           << G4std::setw( 8) << "X"      << "     "
+          << G4std::setw( 8) << "Y"      << "     "  
+          << G4std::setw( 8) << "Z"      << "     "
+          << G4std::setw( 9) << "KineE"  << "     "
+          << G4std::setw( 8) << "dE"     << "     "  
+          << G4std::setw(12) << "StepLeng"   << " "  
+          << G4std::setw(12) << "TrackLeng"  << " "
+          << G4std::setw(12) << "NextVolume" << " "
+          << G4std::setw( 8) << "ProcName"   << G4endl;             
+#else
+    G4cout << G4std::setw( 5) << "Step#"      << " "
+          << G4std::setw( 8) << "X(mm)"      << " "
+          << G4std::setw( 8) << "Y(mm)"      << " "  
+          << G4std::setw( 8) << "Z(mm)"      << " "
+          << G4std::setw( 9) << "KinE(MeV)"  << " "
+          << G4std::setw( 8) << "dE(MeV)"    << " "  
+          << G4std::setw( 8) << "StepLeng"   << " "  
+          << G4std::setw( 9) << "TrackLeng"  << " "
+          << G4std::setw(11) << "NextVolume" << " "
+          << G4std::setw( 8) << "ProcName"   << G4endl;             
+#endif
+}
+
 // public methods
 
 void TG4SteppingAction::UserSteppingAction(const G4Step* step)
 // public methods
 
 void TG4SteppingAction::UserSteppingAction(const G4Step* step)
@@ -40,6 +101,43 @@ void TG4SteppingAction::UserSteppingAction(const G4Step* step)
 // Called by G4 kernel at the end of each step.
 // ---
 
 // Called by G4 kernel at the end of each step.
 // ---
 
+  G4Track* track = step->GetTrack();  
+
+  // reset parameters at beginning of tracking
+  G4int stepNumber = track->GetCurrentStepNumber();
+  if (stepNumber == 1) { 
+    fStandardVerboseLevel = fpSteppingManager->GetverboseLevel();
+    fLoopStepCounter = 0;
+  }  
+  else if (fLoopStepCounter) {
+      // count steps after detecting looping track
+      fLoopStepCounter++;
+      if (fLoopStepCounter == kMaxNofLoopSteps) {
+
+        // stop the looping track
+        track->SetTrackStatus(fStopAndKill);      
+
+        // reset back parameters
+        fpSteppingManager->SetVerboseLevel(fStandardVerboseLevel);
+        fLoopStepCounter = 0;
+      } 
+    }  
+    else if (stepNumber> fMaxNofSteps) { 
+      
+       // print looping info
+       if (fLoopVerboseLevel > 0) {
+          G4cout << "*** Particle reached max step number ("
+                << fMaxNofSteps << "). ***" << G4endl;
+         if (fStandardVerboseLevel == 0) PrintTrackInfo(track);
+       }       
+
+       // set loop verbose level 
+       fpSteppingManager->SetVerboseLevel(fLoopVerboseLevel);
+      
+       // start looping counter
+       fLoopStepCounter++;
+    }
+      
   // call stepping action of derived class
   SteppingAction(step);
 
   // call stepping action of derived class
   SteppingAction(step);
 
index 7ba8377b1e99e4d94fc82da84287e100c376d077..110ecc8a441d40b8799acc1c081763013ecf0adc 100644 (file)
@@ -9,10 +9,18 @@
 
 #include <G4UserSteppingAction.hh>
 
 
 #include <G4UserSteppingAction.hh>
 
+#include <globals.hh>
+
+class G4Track;
 class G4Step;
 
 class TG4SteppingAction : public G4UserSteppingAction 
 {
 class G4Step;
 
 class TG4SteppingAction : public G4UserSteppingAction 
 {
+  enum { 
+    kMaxNofSteps = 10000,
+    kMaxNofLoopSteps = 5
+  };
+
   public:
     TG4SteppingAction();
     // --> protected
   public:
     TG4SteppingAction();
     // --> protected
@@ -25,12 +33,43 @@ class TG4SteppingAction : public G4UserSteppingAction
                  // be overwritten in a derived class
     virtual void UserSteppingAction(const G4Step* step);
 
                  // be overwritten in a derived class
     virtual void UserSteppingAction(const G4Step* step);
 
+    // set methods
+    void SetLoopVerboseLevel(G4int level);
+    void SetMaxNofSteps(G4int number);
+
+    // get methods
+    G4int GetLoopVerboseLevel() const;
+    G4int GetMaxNofSteps() const;
 
   protected:
     TG4SteppingAction(const TG4SteppingAction& right);
 
     // operators
     TG4SteppingAction& operator=(const TG4SteppingAction& right);
 
   protected:
     TG4SteppingAction(const TG4SteppingAction& right);
 
     // operators
     TG4SteppingAction& operator=(const TG4SteppingAction& right);
+    
+    // methods
+    void PrintTrackInfo(const G4Track* track) const;
+
+    // data members
+    G4int  fMaxNofSteps;          //max number of steps allowed
+    G4int  fStandardVerboseLevel; //standard tracking verbose level
+    G4int  fLoopVerboseLevel;     //tracking verbose level                                           //for looping particles
+                                  //for looping particles
+    G4int  fLoopStepCounter;      //loop steps counter    
 };
 
 };
 
+// inline methods
+
+inline void TG4SteppingAction::SetLoopVerboseLevel(G4int level)
+{ fLoopVerboseLevel = level; }
+
+inline void TG4SteppingAction::SetMaxNofSteps(G4int number)
+{ fMaxNofSteps = number; }
+
+inline G4int TG4SteppingAction::GetMaxNofSteps() const
+{ return fMaxNofSteps; }
+
+inline G4int TG4SteppingAction::GetLoopVerboseLevel() const
+{ return fLoopVerboseLevel; }
+
 #endif //TG4_STEPPING_ACTION_H
 #endif //TG4_STEPPING_ACTION_H