[834] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // $Id: MyEventAction.cc,v 1.17 2008/01/04 21:53:07 allison Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
| 29 | // |
---|
| 30 | |
---|
| 31 | #include "MyEventAction.hh" |
---|
| 32 | |
---|
| 33 | //#define DRAWTRAJHIT |
---|
| 34 | |
---|
| 35 | #ifdef DRAWTRAJHIT |
---|
| 36 | |
---|
| 37 | #include "MyTrackerHit.hh" |
---|
| 38 | #include "MyCalorimeterHit.hh" |
---|
| 39 | |
---|
| 40 | #endif |
---|
| 41 | |
---|
| 42 | #include "G4Event.hh" |
---|
| 43 | #include "G4EventManager.hh" |
---|
| 44 | #include "G4Run.hh" |
---|
| 45 | #include "G4RunManager.hh" |
---|
| 46 | #include "G4HCofThisEvent.hh" |
---|
| 47 | #include "G4VHitsCollection.hh" |
---|
| 48 | #include "G4TrajectoryContainer.hh" |
---|
| 49 | #include "G4Trajectory.hh" |
---|
| 50 | #include "G4VVisManager.hh" |
---|
| 51 | #include "G4VisAttributes.hh" |
---|
| 52 | #include "G4AttValue.hh" |
---|
| 53 | #include "G4AttDef.hh" |
---|
| 54 | #include "G4Scale.hh" |
---|
| 55 | #include "G4Text.hh" |
---|
| 56 | #include "G4Box.hh" |
---|
| 57 | #include "G4Tubs.hh" |
---|
| 58 | #include "G4Polyhedron.hh" |
---|
| 59 | #include "G4SDManager.hh" |
---|
| 60 | #include "G4UImanager.hh" |
---|
| 61 | #include "G4ios.hh" |
---|
| 62 | |
---|
| 63 | #include <sstream> |
---|
| 64 | |
---|
| 65 | MyEventAction::MyEventAction() |
---|
| 66 | { |
---|
| 67 | // G4AttDefs have to be long life... |
---|
| 68 | fTransientBoxDefs["TrBox"] = |
---|
| 69 | G4AttDef("TrBox","Transient Box","Physics","","G4String"); |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | MyEventAction::~MyEventAction() |
---|
| 73 | {;} |
---|
| 74 | |
---|
| 75 | void MyEventAction::BeginOfEventAction(const G4Event*) |
---|
| 76 | {;} |
---|
| 77 | |
---|
| 78 | void MyEventAction::EndOfEventAction(const G4Event* anEvent) |
---|
| 79 | { |
---|
| 80 | static int coutCount = 0; |
---|
| 81 | if (coutCount < 10) { |
---|
| 82 | coutCount++; |
---|
| 83 | G4cout << "MyEventAction::EndOfEventActionAction called." << G4endl; |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | const G4Event* evt = anEvent; |
---|
| 87 | |
---|
| 88 | #ifdef DRAWTRAJHIT |
---|
| 89 | |
---|
| 90 | G4SDManager * SDman = G4SDManager::GetSDMpointer(); |
---|
| 91 | G4String colNam; |
---|
| 92 | G4int trackerCollID = SDman->GetCollectionID(colNam="TrackerCollection"); |
---|
| 93 | G4int calorimeterCollID = SDman->GetCollectionID(colNam="CalCollection"); |
---|
| 94 | |
---|
| 95 | #endif |
---|
| 96 | |
---|
| 97 | if (coutCount < 10) { |
---|
| 98 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
| 99 | const G4Run* currentRun = runManager? runManager->GetCurrentRun(): 0; |
---|
| 100 | if (currentRun) G4cout << ">>> Run " << currentRun->GetRunID(); |
---|
| 101 | G4cout << " Event " << anEvent->GetEventID() << G4endl; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | #ifdef DRAWTRAJHIT |
---|
| 105 | |
---|
| 106 | G4TrajectoryContainer * trajectoryContainer = evt->GetTrajectoryContainer(); |
---|
| 107 | G4int n_trajectories = 0; |
---|
| 108 | if(trajectoryContainer) |
---|
| 109 | { n_trajectories = trajectoryContainer->entries(); } |
---|
| 110 | if (coutCount < 10) { |
---|
| 111 | G4cout << " " << n_trajectories |
---|
| 112 | << " trajectories stored in this event." << G4endl; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | G4HCofThisEvent * HCE = evt->GetHCofThisEvent(); |
---|
| 116 | G4int n_hitCollection = 0; |
---|
| 117 | if(HCE) |
---|
| 118 | { n_hitCollection = HCE->GetCapacity(); } |
---|
| 119 | if (coutCount < 10) { |
---|
| 120 | G4cout << " " << n_hitCollection |
---|
| 121 | << " hitsCollections stored in this event." << G4endl; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | #endif |
---|
| 125 | |
---|
| 126 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); |
---|
| 127 | |
---|
| 128 | if(pVVisManager) |
---|
| 129 | { |
---|
| 130 | G4Scale scale(1. * m, "Test Scale"); |
---|
| 131 | G4VisAttributes va (G4Colour(1.,0.,0.)); |
---|
| 132 | scale.SetVisAttributes(va); |
---|
| 133 | pVVisManager->Draw(scale); |
---|
| 134 | |
---|
| 135 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
| 136 | const G4Run* currentRun = runManager? runManager->GetCurrentRun(): 0; |
---|
| 137 | std::ostringstream oss; |
---|
| 138 | if (currentRun) oss << "Run " << currentRun->GetRunID(); |
---|
| 139 | oss << " Event " << anEvent->GetEventID(); |
---|
| 140 | //G4Text text(oss.str(), G4Point3D(400.*cm, 400.*cm, -400.*cm)); |
---|
| 141 | G4Text text(oss.str(), G4Point3D(0., -0.9, 0.)); |
---|
| 142 | text.SetScreenSize(18); |
---|
| 143 | G4VisAttributes textAtts(G4Colour(0.,1.,1)); |
---|
| 144 | text.SetVisAttributes(textAtts); |
---|
| 145 | pVVisManager->Draw2D(text); |
---|
| 146 | |
---|
| 147 | G4Box transientBox("transientBox",100*cm,100*cm,100*cm); |
---|
| 148 | G4VisAttributes transientBoxVisAtts(G4Colour(1.,0.,1)); |
---|
| 149 | transientBoxVisAtts.SetForceWireframe(true); |
---|
| 150 | // Create G4AttsValues... |
---|
| 151 | std::vector<G4AttValue> transientBoxAtts; |
---|
| 152 | std::ostringstream attoss; |
---|
| 153 | attoss << "A magenta box of event " << anEvent->GetEventID(); |
---|
| 154 | transientBoxAtts.push_back(G4AttValue("TrBox",attoss.str(),"")); |
---|
| 155 | transientBoxVisAtts.SetAttValues(&transientBoxAtts); |
---|
| 156 | // G4AttDefs have to be long life (see constructor)... |
---|
| 157 | transientBoxVisAtts.SetAttDefs(&fTransientBoxDefs); |
---|
| 158 | pVVisManager->Draw(transientBox, transientBoxVisAtts, |
---|
| 159 | G4Translate3D(500.*cm, 500.*cm, -500.*cm)); |
---|
| 160 | |
---|
| 161 | G4Tubs transientTube("transientTube",0.,100*cm,100*cm,0.,360.*deg); |
---|
| 162 | G4VisAttributes transientTubeAtts(G4Colour(1.,1.,0)); |
---|
| 163 | transientTubeAtts.SetForceWireframe(true); |
---|
| 164 | pVVisManager->Draw(transientTube, transientTubeAtts, |
---|
| 165 | G4Translate3D(500.*cm, 300.*cm, -500.*cm)); |
---|
| 166 | |
---|
| 167 | // A blue rectangle in fixed position on the screen |
---|
| 168 | G4PolyhedronBox rectangle(0.1, 0.2, 0.1); |
---|
| 169 | G4VisAttributes rectangleAtts(G4Colour(0., 0., 1.)); |
---|
| 170 | rectangleAtts.SetForceSolid(true); |
---|
| 171 | rectangle.SetVisAttributes(rectangleAtts); |
---|
| 172 | pVVisManager->Draw2D(rectangle, G4Translate3D(0.7, 0.5, 0.)); |
---|
| 173 | } |
---|
| 174 | } |
---|