diff --git a/g4root/test/drawTracks.C b/g4root/test/drawTracks.C new file mode 100644 index 0000000000000000000000000000000000000000..91fb9bc561c66f6199b5a4103b0602330840e3ed --- /dev/null +++ b/g4root/test/drawTracks.C @@ -0,0 +1,46 @@ +void drawTracks() +{ +// Draw simulated tracks on top of the geometry. + TGeoManager::Import("ex06geom.root"); + gGeoManager->GetTopVolume()->SetVisContainers(); + gGeoManager->SetTopVisible(); + TCanvas *c1 = new TCanvas("c1", "Tank with bubble", 800,600); + TCanvas *c2 = new TCanvas("c2", "YZ plots", 800,600); + c2->Divide(2,1,0.01,0.01); + c1->cd(); + gGeoManager->GetTopVolume()->Draw("ogl"); + TFile file1("tracks_tgeo.root"); + if (file1.IsZombie()) return; + TFile file2("tracks_g4.root"); + if (file2.IsZombie()) return; + TObjArray *tracks1 = (TObjArray*)file1.Get("tracks"); + TObjArray *tracks2 = (TObjArray*)file2.Get("tracks"); + file1.Close(); + file2.Close(); + Int_t ntracks1 = tracks1->GetEntries(); + Int_t ntracks2 = tracks2->GetEntries(); + TPolyLine3D *track; + TH2F *hist1 = new TH2F("steps_tgeo", "Step coordinates TGeo", 100, -800.,800., 100, -800.,800.); + TH2F *hist2 = new TH2F("steps_g4", "Step coordinates G4", 100, -800.,800., 100, -800.,800.); + Int_t i,j,n; + Float_t *arr; + for (i=0; i<ntracks1; i++) { + track = (TPolyLine3D*)tracks1->At(i); + n = track->GetLastPoint(); + arr = track->GetP(); + for (j=0; j<=n; j++) hist1->Fill(arr[3*j+1],arr[3*j+2]); + track->Draw("SAME"); + } + for (i=0; i<ntracks2; i++) { + track = (TPolyLine3D*)tracks2->At(i); + n = track->GetLastPoint(); + arr = track->GetP(); + for (j=0; j<=n; j++) hist2->Fill(arr[3*j+1],arr[3*j+2]); + } + + c2->cd(1); + hist1->Draw(); + c2->cd(2); + hist2->Draw(); +} + diff --git a/g4root/test/ex06geom.root b/g4root/test/ex06geom.root new file mode 100644 index 0000000000000000000000000000000000000000..d1bb562076cff6c2bbda1a291ae286461f088ea8 Binary files /dev/null and b/g4root/test/ex06geom.root differ diff --git a/g4root/test/exN06.in b/g4root/test/exN06.in new file mode 100644 index 0000000000000000000000000000000000000000..782e9bdeddfedc36a97d89d8dd01582840b4b258 --- /dev/null +++ b/g4root/test/exN06.in @@ -0,0 +1,10 @@ +#/run/verbose 1 +/control/verbose 0 +/tracking/verbose 1 +/N06/phys/verbose 0 +# +#/process/inactivate Scintillation +/gun/particle e+ +/gun/energy 500 keV +/run/beamOn 10 +# diff --git a/g4root/test/exN06/Makefile b/g4root/test/exN06/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..f1074178fab8c6b36fb8bebc96f03df3d1151a71 --- /dev/null +++ b/g4root/test/exN06/Makefile @@ -0,0 +1,15 @@ +# -------------------------------------------------------------- +# Makefile for examples module +# -------------------------------------------------------------- + +name := exampleN06 +G4TARGET := $(name) +G4EXLIB := true +G4TMP = $(ROOTSYS)/g4root/test/exN06 +G4BIN = $(ROOTSYS)/g4root/test/bin + +.PHONY: all +all: lib bin + +include $(G4INSTALL)/config/binmake.gmk +include ../flags.gmk diff --git a/g4root/test/exN06/exampleN06.cc b/g4root/test/exN06/exampleN06.cc new file mode 100644 index 0000000000000000000000000000000000000000..f807e786a314bca0790487193f99af768b45826c --- /dev/null +++ b/g4root/test/exN06/exampleN06.cc @@ -0,0 +1,145 @@ +// +// ******************************************************************** +// * License and Disclaimer * +// * * +// * The Geant4 software is copyright of the Copyright Holders of * +// * the Geant4 Collaboration. It is provided under the terms and * +// * conditions of the Geant4 Software License, included in the file * +// * LICENSE and available at http://cern.ch/geant4/license . These * +// * include a list of copyright holders. * +// * * +// * Neither the authors of this software system, nor their employing * +// * institutes,nor the agencies providing financial support for this * +// * work make any representation or warranty, express or implied, * +// * regarding this software system or assume any liability for its * +// * use. Please see the license in the file LICENSE and URL above * +// * for the full disclaimer and the limitation of liability. * +// * * +// * This code implementation is the result of the scientific and * +// * technical work of the GEANT4 collaboration. * +// * By using, copying, modifying or distributing the software (or * +// * any work based on the software) you agree to acknowledge its * +// * use in resulting scientific publications, and indicate your * +// * acceptance of all terms of the Geant4 Software license. * +// ******************************************************************** +// +// +// $Id: exampleN06.cc,v 1.14 2006/06/29 17:53:52 gunter Exp $ +// GEANT4 tag $Name: geant4-08-01 $ +// +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +// +// Description: Test of Continuous Process G4Cerenkov +// and RestDiscrete Process G4Scintillation +// -- Generation Cerenkov Photons -- +// -- Generation Scintillation Photons -- +// -- Transport of optical Photons -- +// Version: 5.0 +// Created: 1996-04-30 +// Author: Juliet Armstrong +// mail: gum@triumf.ca +// +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "G4RunManager.hh" +#include "G4UImanager.hh" +#include "G4UIterminal.hh" +#include "G4UItcsh.hh" + +#include "G4ios.hh" + +#include "ExN06DetectorConstruction.hh" +#include "ExN06PhysicsList.hh" +#include "ExN06PrimaryGeneratorAction.hh" +#include "ExN06RunAction.hh" +#include "ExN06EventAction.hh" +#include "ExN06StackingAction.hh" +#include "ExN06SteppingVerbose.hh" +#include "ExN06PostDetConstruction.hh" + +#include "TGeoManager.h" +#include "TG4RootDetectorConstruction.h" +#include "TG4RootNavMgr.h" + +#include "Randomize.hh" + +#ifdef G4VIS_USE +#include "G4VisExecutive.hh" +#endif + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +int main(int argc,char** /*argv*/) +{ + // Seed the random number generator manually + // + G4long myseed = 345354; + + // User Verbose output class + // + G4VSteppingVerbose* verbosity = new ExN06SteppingVerbose; + G4VSteppingVerbose::SetInstance(verbosity); + + G4bool use_tgeo = (argc>1)?kTRUE:kFALSE; + TGeoManager *geom = 0; + TG4RootNavMgr *mgr = 0; + // Run manager + // + if (use_tgeo) { + G4cout << "Using TGeo interface ..." << G4endl; + geom = TGeoManager::Import("ex06geom.root"); + mgr = TG4RootNavMgr::GetInstance(geom); + } else { + G4cout << "Using G4 native ..." << G4endl; + } + G4RunManager* runManager = new G4RunManager; + if (use_tgeo) { + mgr->Initialize(ExN06PostDetConstruction::GetInstance()); + mgr->ConnectToG4(); + } + + // UserInitialization classes - mandatory; + // + G4VUserDetectorConstruction* detector = new ExN06DetectorConstruction; + if (!use_tgeo) runManager-> SetUserInitialization(detector); + // + G4VUserPhysicsList* physics = new ExN06PhysicsList; + runManager-> SetUserInitialization(physics); + + // UserAction classes + // + G4UserRunAction* run_action = new ExN06RunAction; + runManager->SetUserAction(run_action); + // + G4VUserPrimaryGeneratorAction* gen_action = new ExN06PrimaryGeneratorAction; + runManager->SetUserAction(gen_action); + // + G4UserEventAction* event_action = new ExN06EventAction; + runManager->SetUserAction(event_action); + // + G4UserStackingAction* stacking_action = new ExN06StackingAction; + runManager->SetUserAction(stacking_action); + + // Initialize G4 kernel + // + runManager->Initialize(); + CLHEP::HepRandom::setTheSeed(myseed); + + G4cout << *(G4Material::GetMaterialTable()) << G4endl; + // Get the pointer to the User Interface manager + // + G4UImanager* UI = G4UImanager::GetUIpointer(); + UI->ApplyCommand("/control/execute exN06.in"); + if (use_tgeo) + ExN06PostDetConstruction::GetInstance()->WriteTracks("tracks_tgeo.root"); + else + ExN06PostDetConstruction::GetInstance()->WriteTracks("tracks_g4.root"); + + delete runManager; + delete verbosity; + + return 0; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/g4root/test/exN06/include/ExN06PostDetConstruction.hh b/g4root/test/exN06/include/ExN06PostDetConstruction.hh new file mode 100644 index 0000000000000000000000000000000000000000..3d4adefac2582b56dd890b5d60195d1f2df15c00 --- /dev/null +++ b/g4root/test/exN06/include/ExN06PostDetConstruction.hh @@ -0,0 +1,32 @@ +#ifndef ExN06PostDetConstruction_h +#define ExN06PostDetConstruction_h 1 + +// Example of post detector construction user class + +#include "TG4RootDetectorConstruction.h" + +class TPolyLine3D; + +class ExN06PostDetConstruction : public TVirtualUserPostDetConstruction +{ +private: + TObjArray *fTracks; // Array of tracks + TPolyLine3D *fCurrent; // Current track + + ExN06PostDetConstruction(); + static ExN06PostDetConstruction *fgInstance; // Self pointer +public: + virtual ~ExN06PostDetConstruction(); + + static ExN06PostDetConstruction *GetInstance(); + + void NewTrack(Double_t x, Double_t y, Double_t z); + void AddPoint(Double_t x, Double_t y, Double_t z); + void WriteTracks(const char *filename); + + virtual void Initialize(TG4RootDetectorConstruction *dc); +}; +#endif + + + diff --git a/g4root/test/exN06/src/ExN06DetectorConstruction.cc b/g4root/test/exN06/src/ExN06DetectorConstruction.cc new file mode 100644 index 0000000000000000000000000000000000000000..e36289ac37aca1370a3b46d9fc7a9701c5b6019a --- /dev/null +++ b/g4root/test/exN06/src/ExN06DetectorConstruction.cc @@ -0,0 +1,268 @@ +// +// ******************************************************************** +// * License and Disclaimer * +// * * +// * The Geant4 software is copyright of the Copyright Holders of * +// * the Geant4 Collaboration. It is provided under the terms and * +// * conditions of the Geant4 Software License, included in the file * +// * LICENSE and available at http://cern.ch/geant4/license . These * +// * include a list of copyright holders. * +// * * +// * Neither the authors of this software system, nor their employing * +// * institutes,nor the agencies providing financial support for this * +// * work make any representation or warranty, express or implied, * +// * regarding this software system or assume any liability for its * +// * use. Please see the license in the file LICENSE and URL above * +// * for the full disclaimer and the limitation of liability. * +// * * +// * This code implementation is the result of the scientific and * +// * technical work of the GEANT4 collaboration. * +// * By using, copying, modifying or distributing the software (or * +// * any work based on the software) you agree to acknowledge its * +// * use in resulting scientific publications, and indicate your * +// * acceptance of all terms of the Geant4 Software license. * +// ******************************************************************** +// +// +// $Id: ExN06DetectorConstruction.cc,v 1.15 2006/06/29 17:54:17 gunter Exp $ +// GEANT4 tag $Name: geant4-08-01-patch-01 $ +// +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ExN06DetectorConstruction.hh" + +#include "G4Material.hh" +#include "G4MaterialTable.hh" +#include "G4Element.hh" +#include "G4ElementTable.hh" +#include "G4LogicalBorderSurface.hh" +#include "G4LogicalSkinSurface.hh" +#include "G4Box.hh" +#include "G4Orb.hh" +#include "G4LogicalVolume.hh" +#include "G4RotationMatrix.hh" +#include "G4ThreeVector.hh" +#include "G4Transform3D.hh" +#include "G4PVPlacement.hh" +#include "G4OpBoundaryProcess.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ExN06DetectorConstruction::ExN06DetectorConstruction() +{ + expHall_x = expHall_y = expHall_z = 10*m; + tank_x = tank_y = tank_z = 5*m; + bubble_x = bubble_y = bubble_z = 0.5*m; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ExN06DetectorConstruction::~ExN06DetectorConstruction(){;} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +G4VPhysicalVolume* ExN06DetectorConstruction::Construct() +{ + +// ------------- Materials ------------- + + G4double a, z, density; + G4int nelements; + +// Air +// + G4Element* N = new G4Element("Nitrogen", "N", z=7 , a=14.01*g/mole); + G4Element* O = new G4Element("Oxygen" , "O", z=8 , a=16.00*g/mole); + + G4Material* Air = new G4Material("Air", density=1.29*mg/cm3, nelements=2); + Air->AddElement(N, 70.*perCent); + Air->AddElement(O, 30.*perCent); + +// Water +// + G4Element* H = new G4Element("Hydrogen", "H", z=1 , a=1.01*g/mole); + + G4Material* Water = new G4Material("Water", density= 1.0*g/cm3, nelements=2); + Water->AddElement(H, 2); + Water->AddElement(O, 1); + +// +// ------------ Generate & Add Material Properties Table ------------ +// + const G4int nEntries = 32; + + G4double PhotonEnergy[nEntries] = + { 2.034*eV, 2.068*eV, 2.103*eV, 2.139*eV, + 2.177*eV, 2.216*eV, 2.256*eV, 2.298*eV, + 2.341*eV, 2.386*eV, 2.433*eV, 2.481*eV, + 2.532*eV, 2.585*eV, 2.640*eV, 2.697*eV, + 2.757*eV, 2.820*eV, 2.885*eV, 2.954*eV, + 3.026*eV, 3.102*eV, 3.181*eV, 3.265*eV, + 3.353*eV, 3.446*eV, 3.545*eV, 3.649*eV, + 3.760*eV, 3.877*eV, 4.002*eV, 4.136*eV }; +// +// Water +// + G4double RefractiveIndex1[nEntries] = + { 1.3435, 1.344, 1.3445, 1.345, 1.3455, + 1.346, 1.3465, 1.347, 1.3475, 1.348, + 1.3485, 1.3492, 1.35, 1.3505, 1.351, + 1.3518, 1.3522, 1.3530, 1.3535, 1.354, + 1.3545, 1.355, 1.3555, 1.356, 1.3568, + 1.3572, 1.358, 1.3585, 1.359, 1.3595, + 1.36, 1.3608}; + + G4double Absorption1[nEntries] = + {3.448*m, 4.082*m, 6.329*m, 9.174*m, 12.346*m, 13.889*m, + 15.152*m, 17.241*m, 18.868*m, 20.000*m, 26.316*m, 35.714*m, + 45.455*m, 47.619*m, 52.632*m, 52.632*m, 55.556*m, 52.632*m, + 52.632*m, 47.619*m, 45.455*m, 41.667*m, 37.037*m, 33.333*m, + 30.000*m, 28.500*m, 27.000*m, 24.500*m, 22.000*m, 19.500*m, + 17.500*m, 14.500*m }; + + G4double ScintilFast[nEntries] = + { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00 }; + G4double ScintilSlow[nEntries] = + { 0.01, 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, + 7.00, 8.00, 9.00, 8.00, 7.00, 6.00, 4.00, + 3.00, 2.00, 1.00, 0.01, 1.00, 2.00, 3.00, + 4.00, 5.00, 6.00, 7.00, 8.00, 9.00, 8.00, + 7.00, 6.00, 5.00, 4.00 }; + + G4MaterialPropertiesTable* myMPT1 = new G4MaterialPropertiesTable(); + myMPT1->AddProperty("RINDEX", PhotonEnergy, RefractiveIndex1,nEntries); + myMPT1->AddProperty("ABSLENGTH", PhotonEnergy, Absorption1, nEntries); + myMPT1->AddProperty("FASTCOMPONENT",PhotonEnergy, ScintilFast, nEntries); + myMPT1->AddProperty("SLOWCOMPONENT",PhotonEnergy, ScintilSlow, nEntries); + + myMPT1->AddConstProperty("SCINTILLATIONYIELD",50./MeV); + myMPT1->AddConstProperty("RESOLUTIONSCALE",1.0); + myMPT1->AddConstProperty("FASTTIMECONSTANT", 1.*ns); + myMPT1->AddConstProperty("SLOWTIMECONSTANT",10.*ns); + myMPT1->AddConstProperty("YIELDRATIO",0.8); + + Water->SetMaterialPropertiesTable(myMPT1); + +// +// Air +// + G4double RefractiveIndex2[nEntries] = + { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00 }; + + G4MaterialPropertiesTable* myMPT2 = new G4MaterialPropertiesTable(); + myMPT2->AddProperty("RINDEX", PhotonEnergy, RefractiveIndex2, nEntries); + + Air->SetMaterialPropertiesTable(myMPT2); + +// +// ------------- Volumes -------------- + +// The experimental Hall +// + G4Box* expHall_box = new G4Box("World",expHall_x,expHall_y,expHall_z); + + G4LogicalVolume* expHall_log + = new G4LogicalVolume(expHall_box,Air,"World",0,0,0); + + G4VPhysicalVolume* expHall_phys + = new G4PVPlacement(0,G4ThreeVector(),expHall_log,"World",0,false,0); + +// The Water Tank +// + G4Box* waterTank_box = new G4Box("Tank",tank_x,tank_y,tank_z); + + G4LogicalVolume* waterTank_log + = new G4LogicalVolume(waterTank_box,Water,"Tank",0,0,0); + + G4VPhysicalVolume* waterTank_phys + = new G4PVPlacement(0,G4ThreeVector(),waterTank_log,"Tank", + expHall_log,false,0); + +// The Air Bubble +// +// G4Box* bubbleAir_box = new G4Box("Bubble",bubble_x,bubble_y,bubble_z); + G4Orb* bubbleAir_box = new G4Orb("Bubble",bubble_x); + + G4LogicalVolume* bubbleAir_log + = new G4LogicalVolume(bubbleAir_box,Air,"Bubble",0,0,0); + +//G4VPhysicalVolume* bubbleAir_phys = + new G4PVPlacement(0,G4ThreeVector(3.*m,2.*m,0),bubbleAir_log,"Bubble", + waterTank_log,false,0); + +// ------------- Surfaces -------------- +// +// Water Tank +// + G4OpticalSurface* OpWaterSurface = new G4OpticalSurface("WaterSurface"); + OpWaterSurface->SetType(dielectric_dielectric); + OpWaterSurface->SetFinish(ground); + OpWaterSurface->SetModel(unified); + + G4LogicalBorderSurface* WaterSurface = + new G4LogicalBorderSurface("WaterSurface", + waterTank_phys,expHall_phys,OpWaterSurface); + + if(WaterSurface->GetVolume1() == waterTank_phys) G4cout << "Equal" << G4endl; + if(WaterSurface->GetVolume2() == expHall_phys ) G4cout << "Equal" << G4endl; + +// Air Bubble +// + G4OpticalSurface* OpAirSurface = new G4OpticalSurface("AirSurface"); + OpAirSurface->SetType(dielectric_dielectric); + OpAirSurface->SetFinish(polished); + OpAirSurface->SetModel(glisur); + + G4LogicalSkinSurface* AirSurface = + new G4LogicalSkinSurface("AirSurface", bubbleAir_log, OpAirSurface); + + if(AirSurface->GetLogicalVolume() == bubbleAir_log) G4cout << "Equal" << G4endl; + ((G4OpticalSurface*) + (AirSurface->GetSurface(bubbleAir_log)->GetSurfaceProperty()))->DumpInfo(); + +// +// Generate & Add Material Properties Table attached to the optical surfaces +// + const G4int num = 2; + G4double Ephoton[num] = {2.038*eV, 4.144*eV}; + + //OpticalWaterSurface + G4double RefractiveIndex[num] = {1.35, 1.40}; + G4double SpecularLobe[num] = {0.3, 0.3}; + G4double SpecularSpike[num] = {0.2, 0.2}; + G4double Backscatter[num] = {0.2, 0.2}; + + G4MaterialPropertiesTable* myST1 = new G4MaterialPropertiesTable(); + + myST1->AddProperty("RINDEX", Ephoton, RefractiveIndex, num); + myST1->AddProperty("SPECULARLOBECONSTANT", Ephoton, SpecularLobe, num); + myST1->AddProperty("SPECULARSPIKECONSTANT", Ephoton, SpecularSpike, num); + myST1->AddProperty("BACKSCATTERCONSTANT", Ephoton, Backscatter, num); + + OpWaterSurface->SetMaterialPropertiesTable(myST1); + + //OpticalAirSurface + G4double Reflectivity[num] = {0.3, 0.5}; + G4double Efficiency[num] = {0.8, 1.0}; + + G4MaterialPropertiesTable *myST2 = new G4MaterialPropertiesTable(); + + myST2->AddProperty("REFLECTIVITY", Ephoton, Reflectivity, num); + myST2->AddProperty("EFFICIENCY", Ephoton, Efficiency, num); + + OpAirSurface->SetMaterialPropertiesTable(myST2); + +//always return the physical World + return expHall_phys; +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/g4root/test/exN06/src/ExN06PostDetConstruction.cc b/g4root/test/exN06/src/ExN06PostDetConstruction.cc new file mode 100644 index 0000000000000000000000000000000000000000..2127ef83e902a620835edd510c51968c946b20d1 --- /dev/null +++ b/g4root/test/exN06/src/ExN06PostDetConstruction.cc @@ -0,0 +1,213 @@ +#include "G4SDManager.hh" +#include "G4LogicalVolume.hh" +#include "G4Material.hh" +#include "G4MaterialTable.hh" +#include "G4OpBoundaryProcess.hh" +#include "G4LogicalBorderSurface.hh" +#include "G4LogicalSkinSurface.hh" +#include "G4PVPlacement.hh" + +#include "TObjArray.h" +#include "TPolyLine3D.h" +#include "TFile.h" + +#include "ExN06PostDetConstruction.hh" + +ExN06PostDetConstruction *ExN06PostDetConstruction::fgInstance = 0; + +//______________________________________________________________________________ +ExN06PostDetConstruction::ExN06PostDetConstruction() +{ +// Ctor. + fTracks = new TObjArray(); + fCurrent = 0; +} + +//______________________________________________________________________________ +ExN06PostDetConstruction::~ExN06PostDetConstruction() +{ +// Dtor. + fTracks->Delete(); + delete fTracks; +} + +//______________________________________________________________________________ +ExN06PostDetConstruction *ExN06PostDetConstruction::GetInstance() +{ +// Returns self pointer. + if (fgInstance) return fgInstance; + fgInstance = new ExN06PostDetConstruction(); + return fgInstance; +} + +//______________________________________________________________________________ +void ExN06PostDetConstruction::NewTrack(Double_t x, Double_t y, Double_t z) +{ +// Add a new track and starting point. + fCurrent = new TPolyLine3D(); + fTracks->Add(fCurrent); + fCurrent->SetLineColor(2); +// fCurrent->SetLineWidth(2); + AddPoint(x,y,z); +} + +//______________________________________________________________________________ +void ExN06PostDetConstruction::AddPoint(Double_t x, Double_t y, Double_t z) +{ +// Add a new point on the current track. + if (!fCurrent) return; + fCurrent->SetNextPoint(0.1*x,0.1*y,0.1*z); +} + +//______________________________________________________________________________ +void ExN06PostDetConstruction::WriteTracks(const char *filename) +{ +// Draw the current event(s) + if (!fCurrent) return; + printf("Writing %i tracks...\n", fTracks->GetEntries()); + TFile *trfile = new TFile(filename, "RECREATE"); + fTracks->Write("tracks", TObject::kSingleKey); + trfile->Write(); + trfile->Close(); + delete trfile; +} + +//______________________________________________________________________________ +void ExN06PostDetConstruction::Initialize(TG4RootDetectorConstruction *dc) +{ + G4cout << "ExN06PostDetConstruction::Initialize() ..." << G4endl; + TGeoManager *geom = dc->GetGeometryManager(); + const G4int nEntries = 32; + + G4double PhotonEnergy[nEntries] = + { 2.034*eV, 2.068*eV, 2.103*eV, 2.139*eV, + 2.177*eV, 2.216*eV, 2.256*eV, 2.298*eV, + 2.341*eV, 2.386*eV, 2.433*eV, 2.481*eV, + 2.532*eV, 2.585*eV, 2.640*eV, 2.697*eV, + 2.757*eV, 2.820*eV, 2.885*eV, 2.954*eV, + 3.026*eV, 3.102*eV, 3.181*eV, 3.265*eV, + 3.353*eV, 3.446*eV, 3.545*eV, 3.649*eV, + 3.760*eV, 3.877*eV, 4.002*eV, 4.136*eV }; +// +// Water +// + G4double RefractiveIndex1[nEntries] = + { 1.3435, 1.344, 1.3445, 1.345, 1.3455, + 1.346, 1.3465, 1.347, 1.3475, 1.348, + 1.3485, 1.3492, 1.35, 1.3505, 1.351, + 1.3518, 1.3522, 1.3530, 1.3535, 1.354, + 1.3545, 1.355, 1.3555, 1.356, 1.3568, + 1.3572, 1.358, 1.3585, 1.359, 1.3595, + 1.36, 1.3608}; + + G4double Absorption1[nEntries] = + {3.448*m, 4.082*m, 6.329*m, 9.174*m, 12.346*m, 13.889*m, + 15.152*m, 17.241*m, 18.868*m, 20.000*m, 26.316*m, 35.714*m, + 45.455*m, 47.619*m, 52.632*m, 52.632*m, 55.556*m, 52.632*m, + 52.632*m, 47.619*m, 45.455*m, 41.667*m, 37.037*m, 33.333*m, + 30.000*m, 28.500*m, 27.000*m, 24.500*m, 22.000*m, 19.500*m, + 17.500*m, 14.500*m }; + + G4double ScintilFast[nEntries] = + { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00 }; + G4double ScintilSlow[nEntries] = + { 0.01, 1.00, 2.00, 3.00, 4.00, 5.00, 6.00, + 7.00, 8.00, 9.00, 8.00, 7.00, 6.00, 4.00, + 3.00, 2.00, 1.00, 0.01, 1.00, 2.00, 3.00, + 4.00, 5.00, 6.00, 7.00, 8.00, 9.00, 8.00, + 7.00, 6.00, 5.00, 4.00 }; + + G4MaterialPropertiesTable* myMPT1 = new G4MaterialPropertiesTable(); + myMPT1->AddProperty("RINDEX", PhotonEnergy, RefractiveIndex1,nEntries); + myMPT1->AddProperty("ABSLENGTH", PhotonEnergy, Absorption1, nEntries); + myMPT1->AddProperty("FASTCOMPONENT",PhotonEnergy, ScintilFast, nEntries); + myMPT1->AddProperty("SLOWCOMPONENT",PhotonEnergy, ScintilSlow, nEntries); + + myMPT1->AddConstProperty("SCINTILLATIONYIELD",50./MeV); + myMPT1->AddConstProperty("RESOLUTIONSCALE",1.0); + myMPT1->AddConstProperty("FASTTIMECONSTANT", 1.*ns); + myMPT1->AddConstProperty("SLOWTIMECONSTANT",10.*ns); + myMPT1->AddConstProperty("YIELDRATIO",0.8); + + G4Material *Water = dc->GetG4Material(geom->GetMaterial("Water")); + Water->SetMaterialPropertiesTable(myMPT1); +// Air +// + G4double RefractiveIndex2[nEntries] = + { 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, + 1.00, 1.00, 1.00, 1.00 }; + + G4MaterialPropertiesTable* myMPT2 = new G4MaterialPropertiesTable(); + myMPT2->AddProperty("RINDEX", PhotonEnergy, RefractiveIndex2, nEntries); + G4Material *Air = dc->GetG4Material(geom->GetMaterial("Air")); + + Air->SetMaterialPropertiesTable(myMPT2); +// ------------- Surfaces -------------- +// +// Water Tank +// + G4OpticalSurface* OpWaterSurface = new G4OpticalSurface("WaterSurface"); + OpWaterSurface->SetType(dielectric_dielectric); + OpWaterSurface->SetFinish(ground); + OpWaterSurface->SetModel(unified); + G4VPhysicalVolume *expHall_phys = dc->GetTopPV(); + G4VPhysicalVolume *waterTank_phys =expHall_phys->GetLogicalVolume()->GetDaughter(0); + G4LogicalBorderSurface* WaterSurface = + new G4LogicalBorderSurface("WaterSurface", + waterTank_phys,expHall_phys,OpWaterSurface); + + if(WaterSurface->GetVolume1() == waterTank_phys) G4cout << "Equal" << G4endl; + if(WaterSurface->GetVolume2() == expHall_phys ) G4cout << "Equal" << G4endl; +// Air Bubble +// + G4OpticalSurface* OpAirSurface = new G4OpticalSurface("AirSurface"); + OpAirSurface->SetType(dielectric_dielectric); + OpAirSurface->SetFinish(polished); + OpAirSurface->SetModel(glisur); + + G4LogicalVolume *bubbleAir_log = dc->GetG4Volume(geom->GetVolume("Bubble")); + G4LogicalSkinSurface* AirSurface = + new G4LogicalSkinSurface("AirSurface", bubbleAir_log, OpAirSurface); + + if(AirSurface->GetLogicalVolume() == bubbleAir_log) G4cout << "Equal" << G4endl; + ((G4OpticalSurface*) + (AirSurface->GetSurface(bubbleAir_log)->GetSurfaceProperty()))->DumpInfo(); +// +// Generate & Add Material Properties Table attached to the optical surfaces +// + const G4int num = 2; + G4double Ephoton[num] = {2.038*eV, 4.144*eV}; + + //OpticalWaterSurface + G4double RefractiveIndex[num] = {1.35, 1.40}; + G4double SpecularLobe[num] = {0.3, 0.3}; + G4double SpecularSpike[num] = {0.2, 0.2}; + G4double Backscatter[num] = {0.2, 0.2}; + + G4MaterialPropertiesTable* myST1 = new G4MaterialPropertiesTable(); + + myST1->AddProperty("RINDEX", Ephoton, RefractiveIndex, num); + myST1->AddProperty("SPECULARLOBECONSTANT", Ephoton, SpecularLobe, num); + myST1->AddProperty("SPECULARSPIKECONSTANT", Ephoton, SpecularSpike, num); + myST1->AddProperty("BACKSCATTERCONSTANT", Ephoton, Backscatter, num); + + OpWaterSurface->SetMaterialPropertiesTable(myST1); + + //OpticalAirSurface + G4double Reflectivity[num] = {0.3, 0.5}; + G4double Efficiency[num] = {0.8, 1.0}; + + G4MaterialPropertiesTable *myST2 = new G4MaterialPropertiesTable(); + + myST2->AddProperty("REFLECTIVITY", Ephoton, Reflectivity, num); + myST2->AddProperty("EFFICIENCY", Ephoton, Efficiency, num); + + OpAirSurface->SetMaterialPropertiesTable(myST2); +} diff --git a/g4root/test/exN06/src/ExN06SteppingVerbose.cc b/g4root/test/exN06/src/ExN06SteppingVerbose.cc new file mode 100644 index 0000000000000000000000000000000000000000..7a94b31419f009e90727ec8a6ed8fe17be4d0ae4 --- /dev/null +++ b/g4root/test/exN06/src/ExN06SteppingVerbose.cc @@ -0,0 +1,188 @@ +// +// ******************************************************************** +// * License and Disclaimer * +// * * +// * The Geant4 software is copyright of the Copyright Holders of * +// * the Geant4 Collaboration. It is provided under the terms and * +// * conditions of the Geant4 Software License, included in the file * +// * LICENSE and available at http://cern.ch/geant4/license . These * +// * include a list of copyright holders. * +// * * +// * Neither the authors of this software system, nor their employing * +// * institutes,nor the agencies providing financial support for this * +// * work make any representation or warranty, express or implied, * +// * regarding this software system or assume any liability for its * +// * use. Please see the license in the file LICENSE and URL above * +// * for the full disclaimer and the limitation of liability. * +// * * +// * This code implementation is the result of the scientific and * +// * technical work of the GEANT4 collaboration. * +// * By using, copying, modifying or distributing the software (or * +// * any work based on the software) you agree to acknowledge its * +// * use in resulting scientific publications, and indicate your * +// * acceptance of all terms of the Geant4 Software license. * +// ******************************************************************** +// +// +// $Id: ExN06SteppingVerbose.cc,v 1.4 2006/06/29 17:54:37 gunter Exp $ +// GEANT4 tag $Name: geant4-08-01-patch-01 $ +// +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +#include "ExN06SteppingVerbose.hh" +#include "ExN06PostDetConstruction.hh" + +#include "G4SteppingManager.hh" +#include "G4UnitsTable.hh" + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ExN06SteppingVerbose::ExN06SteppingVerbose() +{} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +ExN06SteppingVerbose::~ExN06SteppingVerbose() +{} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ExN06SteppingVerbose::StepInfo() +{ + CopyState(); + ExN06PostDetConstruction::GetInstance()->AddPoint(fTrack->GetPosition().x(), + fTrack->GetPosition().y(), + fTrack->GetPosition().z()); + + G4int prec = G4cout.precision(3); + + if( verboseLevel >= 2 ){ + if( verboseLevel >= 4 ) VerboseTrack(); + if( verboseLevel >= 3 ){ + G4cout << G4endl; + G4cout << std::setw( 5) << "#Step#" << " " + << std::setw( 6) << "X" << " " + << std::setw( 6) << "Y" << " " + << std::setw( 6) << "Z" << " " + << std::setw( 9) << "KineE" << " " + << std::setw( 9) << "dEStep" << " " + << std::setw(10) << "StepLeng" + << std::setw(10) << "TrakLeng" + << std::setw(10) << "Volume" << " " + << std::setw(10) << "Process" << G4endl; + } + + G4cout << std::setw(5) << fTrack->GetCurrentStepNumber() << " " + << std::setw(6) << G4BestUnit(fTrack->GetPosition().x(),"Length") + << std::setw(6) << G4BestUnit(fTrack->GetPosition().y(),"Length") + << std::setw(6) << G4BestUnit(fTrack->GetPosition().z(),"Length") + << std::setw(6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") + << std::setw(6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy") + << std::setw(6) << G4BestUnit(fStep->GetStepLength(),"Length") + << std::setw(6) << G4BestUnit(fTrack->GetTrackLength(),"Length") + << " "; + + // if( fStepStatus != fWorldBoundary){ + if( fTrack->GetNextVolume() != 0 ) { + G4cout << std::setw(10) << fTrack->GetVolume()->GetName(); + } else { + G4cout << std::setw(10) << "OutOfWorld"; + } + + if(fStep->GetPostStepPoint()->GetProcessDefinedStep() != 0){ + G4cout << " " + << std::setw(10) + << fStep->GetPostStepPoint()->GetProcessDefinedStep() + ->GetProcessName(); + } else { + G4cout << " UserLimit"; + } + + G4cout << G4endl; + + if( verboseLevel == 2 ){ + G4int tN2ndariesTot = fN2ndariesAtRestDoIt + + fN2ndariesAlongStepDoIt + + fN2ndariesPostStepDoIt; + if(tN2ndariesTot>0){ + G4cout << " :----- List of 2ndaries - " + << "#SpawnInStep=" << std::setw(3) << tN2ndariesTot + << "(Rest=" << std::setw(2) << fN2ndariesAtRestDoIt + << ",Along=" << std::setw(2) << fN2ndariesAlongStepDoIt + << ",Post=" << std::setw(2) << fN2ndariesPostStepDoIt + << "), " + << "#SpawnTotal=" << std::setw(3) << (*fSecondary).size() + << " ---------------" + << G4endl; + + for(size_t lp1=(*fSecondary).size()-tN2ndariesTot; + lp1<(*fSecondary).size(); lp1++){ + G4cout << " : " + << std::setw(6) + << G4BestUnit((*fSecondary)[lp1]->GetPosition().x(),"Length") + << std::setw(6) + << G4BestUnit((*fSecondary)[lp1]->GetPosition().y(),"Length") + << std::setw(6) + << G4BestUnit((*fSecondary)[lp1]->GetPosition().z(),"Length") + << std::setw(6) + << G4BestUnit((*fSecondary)[lp1]->GetKineticEnergy(),"Energy") + << std::setw(10) + << (*fSecondary)[lp1]->GetDefinition()->GetParticleName(); + G4cout << G4endl; + } + + G4cout << " :-----------------------------" + << "----------------------------------" + << "-- EndOf2ndaries Info ---------------" + << G4endl; + } + } + + } + G4cout.precision(prec); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... + +void ExN06SteppingVerbose::TrackingStarted() +{ + CopyState(); + ExN06PostDetConstruction::GetInstance()->NewTrack(fTrack->GetPosition().x(), + fTrack->GetPosition().y(), + fTrack->GetPosition().z()); +G4int prec = G4cout.precision(3); + if( verboseLevel > 1 ){ + + G4cout << std::setw( 5) << "Step#" << " " + << std::setw( 6) << "X" << " " + << std::setw( 6) << "Y" << " " + << std::setw( 6) << "Z" << " " + << std::setw( 9) << "KineE" << " " + << std::setw( 9) << "dEStep" << " " + << std::setw(10) << "StepLeng" + << std::setw(10) << "TrakLeng" + << std::setw(10) << "Volume" << " " + << std::setw(10) << "Process" << G4endl; + + G4cout << std::setw( 5) << fTrack->GetCurrentStepNumber() << " " + << std::setw( 6) << G4BestUnit(fTrack->GetPosition().x(),"Length") + << std::setw( 6) << G4BestUnit(fTrack->GetPosition().y(),"Length") + << std::setw( 6) << G4BestUnit(fTrack->GetPosition().z(),"Length") + << std::setw( 6) << G4BestUnit(fTrack->GetKineticEnergy(),"Energy") + << std::setw( 6) << G4BestUnit(fStep->GetTotalEnergyDeposit(),"Energy") + << std::setw( 6) << G4BestUnit(fStep->GetStepLength(),"Length") + << std::setw( 6) << G4BestUnit(fTrack->GetTrackLength(),"Length") + << " "; + + if(fTrack->GetNextVolume()){ + G4cout << std::setw(10) << fTrack->GetVolume()->GetName(); + } else { + G4cout << "OutOfWorld"; + } + G4cout << " initStep" << G4endl; + } + G4cout.precision(prec); +} + +//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... diff --git a/g4root/test/flags.gmk b/g4root/test/flags.gmk new file mode 100644 index 0000000000000000000000000000000000000000..b166c1c15d34c5bf0060b79afdd44c809f3f3bb4 --- /dev/null +++ b/g4root/test/flags.gmk @@ -0,0 +1,4 @@ +# Extra include files and library path +INCFLAGS += -I$(ROOTSYS)/include +LDLIBS += -L$(ROOTSYS)/lib -ldl -lCint -lCore -lGeom -lG4root -lMatrix \ + -lGraf -lHist -lGraf3d diff --git a/g4root/test/runtest b/g4root/test/runtest new file mode 100755 index 0000000000000000000000000000000000000000..349af4e0a56208fdef913b97333d28ed3591321c --- /dev/null +++ b/g4root/test/runtest @@ -0,0 +1,66 @@ +#!/bin/bash +# Script to compile and run tests with G4 native and via the interface +# Requires G4INSTALL, G4LIB and G4SYSTEM to be defined +# +# Simply type ./runtest to run the test +# ./runtest clean to clean + +CURDIR=$ROOTSYS/g4root/test +CPDIR=$G4INSTALL/examples/novice/N06 + +run() { + if ! [ -f $CURDIR/exN06/include/ExN06PhysicsList.hh ]; then +# Copy files from GEANT4 examples + cp -u $CPDIR/include/* $CURDIR/exN06/include + cp -u $CPDIR/src/ExN06EventAction.cc $CURDIR/exN06/src + cp -u $CPDIR/src/ExN06PhysicsList.cc $CURDIR/exN06/src + cp -u $CPDIR/src/ExN06PhysicsListMessenger.cc $CURDIR/exN06/src + cp -u $CPDIR/src/ExN06PrimaryGeneratorAction.cc $CURDIR/exN06/src + cp -u $CPDIR/src/ExN06PrimaryGeneratorMessenger.cc $CURDIR/exN06/src + cp -u $CPDIR/src/ExN06RunAction.cc $CURDIR/exN06/src + cp -u $CPDIR/src/ExN06StackingAction.cc $CURDIR/exN06/src + fi + cd exN06 + make + cd $CURDIR + cp bin/*/* $CURDIR + rm -rf bin + ./exampleN06 > exN06.out + ./exampleN06 root > exN06root.out + $ROOTSYS/bin/root.exe drawTracks.C +} + +clean() { + rm -f $CURDIR/exN06/include/ExN06DetectorConstruction.hh + rm -f $CURDIR/exN06/include/ExN06EventAction.hh + rm -f $CURDIR/exN06/include/ExN06PhysicsList.hh + rm -f $CURDIR/exN06/include/ExN06PhysicsListMessenger.hh + rm -f $CURDIR/exN06/include/ExN06PrimaryGeneratorAction.hh + rm -f $CURDIR/exN06/include/ExN06PrimaryGeneratorMessenger.hh + rm -f $CURDIR/exN06/include/ExN06RunAction.hh + rm -f $CURDIR/exN06/include/ExN06StackingAction.hh + rm -f $CURDIR/exN06/include/ExN06SteppingVerbose.hh + rm -f $CURDIR/exN06/src/ExN06EventAction.cc + rm -f $CURDIR/exN06/src/ExN06PhysicsList.cc + rm -f $CURDIR/exN06/src/ExN06PhysicsListMessenger.cc + rm -f $CURDIR/exN06/src/ExN06PrimaryGeneratorAction.cc + rm -f $CURDIR/exN06/src/ExN06PrimaryGeneratorMessenger.cc + rm -f $CURDIR/exN06/src/ExN06RunAction.cc + rm -f $CURDIR/exN06/src/ExN06StackingAction.cc + rm -rf $CURDIR/exN06/$G4SYSTEM + rm -f $CURDIR/*.out + rm -f $CURDIR/tracks_g4.root + rm -f $CURDIR/tracks_tgeo.root + rm -f $CURDIR/exampleN06 +} + +case "$1" in +run) + run + ;; +clean) + clean + ;; +*) + run +esac