Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /geant4/examples/advanced/underground_physics/src/DMXSteppingAction.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // --------------------------------------------------------------
0028 //   GEANT 4 - Underground Dark Matter Detector Advanced Example
0029 //
0030 //      For information related to this code contact: Alex Howard
0031 //      e-mail: alexander.howard@cern.ch
0032 // --------------------------------------------------------------
0033 // Comments
0034 //
0035 //                  Underground Advanced
0036 //               by A. Howard and H. Araujo 
0037 //                    (27th November 2001)
0038 //
0039 // History:
0040 // 21 Feb 2002 AH: Added Analysis
0041 //
0042 // SteppingAction program
0043 // --------------------------------------------------------------
0044 
0045 #include "DMXSteppingAction.hh"
0046 #include "DMXSteppingActionMessenger.hh"
0047 
0048 #include "DMXEventAction.hh"
0049 
0050 #include "G4AnalysisManager.hh"
0051 #include "G4RunManager.hh"
0052 #include "G4Track.hh"
0053 #include "G4Step.hh"
0054 #include "G4StepPoint.hh"
0055 #include "G4TrackStatus.hh"
0056 #include "G4ParticleDefinition.hh"
0057 #include "G4ParticleTypes.hh"
0058 #include "G4VVisManager.hh"
0059 #include "G4Colour.hh"
0060 #include "G4Polyline.hh" 
0061 #include "G4VisAttributes.hh"
0062 #include "globals.hh"
0063 #include "G4ios.hh"
0064 
0065 
0066 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0067 
0068 DMXSteppingAction::DMXSteppingAction()
0069   : evtAction(0)  {
0070 
0071   steppingMessenger = new DMXSteppingActionMessenger(this);
0072 
0073   // defaults for messenger
0074   colourNeutronFlag      = "magenta";
0075   colourGammaFlag        = "cyan";
0076   colourOpticalFlag      = "white";
0077   colourChargedPlusFlag  = "red";
0078   colourChargedMinusFlag = "blue";
0079 
0080 }
0081 
0082 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0083 
0084 DMXSteppingAction::~DMXSteppingAction()
0085 {
0086 
0087   delete steppingMessenger;
0088 
0089 }
0090 
0091 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
0092 
0093 void DMXSteppingAction::UserSteppingAction(const G4Step* fStep)
0094 {
0095   if (!evtAction)
0096     evtAction = 
0097       dynamic_cast<const DMXEventAction*>
0098       (G4RunManager::GetRunManager()->GetUserEventAction());
0099 
0100 
0101   // removed 28/11/01 - unnecessary unless program "freezes"
0102   // kill track if too many steps
0103   // NB: This is set to DBL_MAX - therefore may cause program to "hang"
0104   //  G4int MaxNoSteps = DBL_MAX;
0105   //  G4int StepNo = fStep->GetTrack()->GetCurrentStepNumber();
0106   //  if(StepNo >= MaxNoSteps) fStep->GetTrack()->SetTrackStatus(fStopAndKill);
0107 
0108   G4int StepNo = fStep->GetTrack()->GetCurrentStepNumber();
0109   if(StepNo == 1) 
0110     { 
0111       G4double partEnergy = fStep->GetPreStepPoint()->GetKineticEnergy();
0112       G4ParticleDefinition* particleType = fStep->GetTrack()->GetDefinition();
0113      
0114       G4AnalysisManager* man = G4AnalysisManager::Instance();
0115       if (particleType == G4Gamma::Definition())
0116     man->FillH1(8,partEnergy);
0117       else if (particleType == G4Neutron::Definition())
0118     man->FillH1(9,partEnergy);
0119       else if (particleType == G4Electron::Definition())
0120     man->FillH1(10,partEnergy);
0121       else if (particleType == G4Positron::Definition())
0122     man->FillH1(11,partEnergy);
0123       else
0124     man->FillH1(12,partEnergy);
0125     }
0126 
0127 
0128   // check what is to be drawn from EventAction/EventActionMessenger
0129   G4String drawColsFlag = evtAction->GetDrawColsFlag();
0130   G4String drawTrksFlag = evtAction->GetDrawTrksFlag();
0131 
0132   // draw by step (here) instead of by event (event action)
0133   if (drawColsFlag=="custom" && drawTrksFlag!="none") {
0134 
0135     // check that VisManager exists
0136     G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
0137     if(pVVisManager) {
0138 
0139       // particle colour in a string
0140       G4String name = fStep->GetTrack()->GetDefinition()->GetParticleName();
0141       G4String strColour;
0142       if(name=="neutron") {
0143     if(drawTrksFlag=="charged") return;
0144     strColour = colourNeutronFlag;
0145       } else if (name=="gamma") {
0146     if(drawTrksFlag=="charged") return;
0147     strColour = colourGammaFlag;
0148       } else if (name=="opticalphoton") {
0149     if(drawTrksFlag!="all") return;
0150     strColour = colourOpticalFlag;
0151       }
0152       else if (name=="alpha" || name=="e+")
0153     strColour = colourChargedPlusFlag;
0154       else
0155     strColour = colourChargedMinusFlag;
0156 
0157       // convert string to G4Colour
0158       G4Colour colour;
0159       if     (strColour=="white")    colour=G4Colour(1.0, 1.0, 1.0);
0160       else if(strColour=="grey" )    colour=G4Colour(0.5, 0.5, 0.5);
0161       else if(strColour=="lgrey")    colour=G4Colour(.75, .75, .75);
0162       else if(strColour=="black")    colour=G4Colour(0.0, 0.0, 0.0);
0163       else if(strColour=="red")      colour=G4Colour(1.0, 0.0, 0.0);
0164       else if(strColour=="green")    colour=G4Colour(0.0, 1.0, 0.0);
0165       else if(strColour=="blue")     colour=G4Colour(0.0, 0.0, 1.0);
0166       else if(strColour=="cyan")     colour=G4Colour(0.0, 1.0, 1.0);
0167       else if(strColour=="magenta")  colour=G4Colour(1.0, 0.0, 1.0);
0168       else if(strColour=="yellow")   colour=G4Colour(1.0, 1.0, 0.0);
0169       else if(strColour=="lgreen")   colour=G4Colour(0.0, .75, 0.0);
0170       else if(strColour=="lblue")    colour=G4Colour(0.0, 0.0, .75);
0171       else                           colour=G4Colour(1.0, 1.0, 1.0);
0172 
0173       // create line with colour
0174       G4VisAttributes attribs(colour);
0175       G4Polyline polyline;
0176       polyline.SetVisAttributes(attribs);
0177 
0178       // draw line
0179       G4Point3D start(fStep->GetPreStepPoint()->GetPosition());
0180       G4Point3D end(fStep->GetPostStepPoint()->GetPosition());
0181       polyline.push_back(start);
0182       polyline.push_back(end);
0183       pVVisManager->Draw(polyline);
0184     }
0185     
0186   }
0187   
0188 }
0189 
0190