Skip to content

Commit

Permalink
Merge pull request #46 from rest-for-physics/lobis-degree-unit
Browse files Browse the repository at this point in the history
Using `<filesystem>` to improve prints, updating examples with new `deg` angular unit
  • Loading branch information
lobis authored May 25, 2022
2 parents 2ebfb2f + 207f539 commit ab18992
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ add_executable(${PROJECT_NAME} restG4.cxx ${sources} ${headers})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${INCLUDE_DIRS})

# Copy scripts to the build directory
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/examples
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples/
DESTINATION ./examples/restG4/
COMPONENT install
Expand All @@ -80,7 +83,6 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mac
COMPONENT install
)

# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
install(TARGETS ${PROJECT_NAME} DESTINATION bin)

if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
Expand Down
28 changes: 14 additions & 14 deletions examples/04.MuonScan/CosmicMuonsFromCircle.rml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<!--
First concept author G. Luzón (16-11-2020) -->

<restG4>

<TRestRun name="CosmicMuonRun" title="A basic muon test with 2 active volumes">
Expand All @@ -21,16 +18,19 @@ First concept author G. Luzón (16-11-2020) -->
<parameter name="gdmlFile" value="setup.gdml"/>
<parameter name="subEventTimeDelay" value="100us"/>

<parameter name="nEvents" value="1000"/>
<parameter name="nEvents" value="5000"/>

<parameter name="seed" value="17021981"/>
<parameter name="saveAllEvents" value="false"/>
<parameter name="printProgress" value="true"/>

<generator type="surface" shape="circle" position="(0,0,50)cm" size="(15,0,0)cm" rotationAngle="0"
rotationAxis="(1,0,0)">
<!-- From planar surface above detector (cosmic rays) -->
<generator type="surface" shape="circle"
position="(0,100,0)mm" size="(400,0,0)mm"
rotationAngle="90deg" rotationAxis="(1,0,0)">
<source particle="mu-" excitedLevel="0.0" fullChain="on">
<energyDist type="TH1D" file="Muons.root" spctName="cosmicmuon"/>
<angularDist type="TH1D" file="CosmicAngles.root" spctName="Theta2" direction="(0,0,-1)"/>
<angularDist type="TH1D" file="CosmicAngles.root" spctName="Theta2" direction="(0,-1,0)"/>
</source>
</generator>

Expand All @@ -52,24 +52,24 @@ First concept author G. Luzón (16-11-2020) -->
<parameter name="maxEnergyRangeProductionCuts" value="1" units="GeV"/>

<!-- EM Physics lists -->
<physicsList name="G4EmLivermorePhysics"></physicsList>
<physicsList name="G4EmLivermorePhysics"/>
<!-- <physicsList name="G4EmPenelopePhysics"> </physicsList> -->
<!-- <physicsList name="G4EmStandardPhysics_option3"> </physicsList> -->

<!-- Decay physics lists -->
<physicsList name="G4DecayPhysics"></physicsList>
<physicsList name="G4RadioactiveDecayPhysics"></physicsList>
<physicsList name="G4DecayPhysics"/>
<physicsList name="G4RadioactiveDecayPhysics"/>
<physicsList name="G4RadioactiveDecay">
<option name="ICM" value="true"/>
<option name="ARM" value="true"/>
</physicsList>

<!-- Hadron physics lists -->

<physicsList name="G4HadronElasticPhysicsHP"></physicsList>
<physicsList name="G4IonBinaryCascadePhysics"></physicsList>
<physicsList name="G4HadronPhysicsQGSP_BIC_HP"></physicsList>
<physicsList name="G4EmExtraPhysics"></physicsList>
<physicsList name="G4HadronElasticPhysicsHP"/>
<physicsList name="G4IonBinaryCascadePhysics"/>
<physicsList name="G4HadronPhysicsQGSP_BIC_HP"/>
<physicsList name="G4EmExtraPhysics"/>

</TRestGeant4PhysicsLists>

Expand Down
16 changes: 8 additions & 8 deletions examples/04.MuonScan/ValidateCircle.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

Int_t ValidateWall(string fname) {
Int_t ValidateCircle(string fname) {
gSystem->Load("/usr/local/rest-for-physics/lib/libRestFramework.so");
gSystem->Load("/usr/local/rest-for-physics/lib/libRestGeant4.so");

Expand All @@ -18,9 +18,9 @@ Int_t ValidateWall(string fname) {
for (Int_t n = 0; n < run.GetEntries(); n++) {
run.GetEntry(n);
Double_t x = event->GetPrimaryEventOrigin().X();
Double_t y = event->GetPrimaryEventOrigin().Y();
Double_t z = event->GetPrimaryEventOrigin().Z();

const auto r = TMath::Sqrt(x * x + y * y) / 100; // cm
const auto r = TMath::Sqrt(x * x + z * z) / 100; // cm

rMean += r / run.GetEntries();
if (r < rMin) {
Expand All @@ -31,27 +31,27 @@ Int_t ValidateWall(string fname) {
}
}

if (rMean < 0.8 || rMean > 1.2) {
if (rMean < 2.75 || rMean > 3.25) {
cout << "The average radius of the distribution is wrong!" << endl;
cout << "R_mean (cm): " << rMean << endl;
return 5;
}

if (rMin > 0.15) {
if (rMin > 0.5) {
cout << "The minimum radius of the distribution is wrong!" << endl;
cout << "R_min (cm): " << rMin << endl;
return 6;
}

if (rMax > 1.5 || rMax < 1.35) {
if (rMax > 4.0 || rMax < 3.75) {
cout << "The maximum radius of the distribution is wrong!" << endl;
cout << "R_max (cm): " << rMax << endl;
return 7;
}

cout << "Run entries: " << run.GetEntries() << endl;
if (run.GetEntries() < 350 || run.GetEntries() > 450) {
cout << "The number of entries is not between 350 and 450!" << endl;
if (run.GetEntries() < 600 || run.GetEntries() > 750) {
cout << "The number of entries is wrong!" << endl;
cout << "Number of entries : " << run.GetEntries() << endl;
return 8;
}
Expand Down
7 changes: 4 additions & 3 deletions restG4.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <filesystem>

#include "CommandLineSetup.h"
#include "DetectorConstruction.h"
Expand Down Expand Up @@ -384,7 +385,7 @@ int main(int argc, char** argv) {

systime = time(nullptr);
restRun->SetEndTimeStamp((Double_t)systime);
TString Filename = restRun->GetOutputFileName();
TString filename = TString(filesystem::weakly_canonical(restRun->GetOutputFileName().Data()));

restRun->UpdateOutputFile();
restRun->CloseFile();
Expand Down Expand Up @@ -414,7 +415,7 @@ int main(int argc, char** argv) {
sleep(5);

// Then we just add the geometry
auto file = new TFile(Filename, "update");
auto file = new TFile(filename, "update");
TGeoManager* geoManager = gdml->CreateGeoManager();

file->cd();
Expand All @@ -431,7 +432,7 @@ int main(int argc, char** argv) {
printf("Writing geometry ... \n");
}

cout << "============== Generated file: " << Filename << " ==============" << endl;
cout << "============== Generated file: " << filename << " ==============" << endl;
auto end_time = chrono::steady_clock::now();
cout << "Elapsed time: " << chrono::duration_cast<chrono::seconds>(end_time - start_time).count()
<< " seconds" << endl;
Expand Down
2 changes: 1 addition & 1 deletion src/RunAction.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void RunAction::EndOfRunAction(const G4Run* run) {
// G4double eprimary = fPrimary->GetParticleGun()->GetParticleEnergy();

G4cout << "======================== run summary ======================";
G4cout << "\n" << nbEvents << " Events simulated, " << restRun->GetEntries() << "Events stored\n";
G4cout << "\n" << nbEvents << " Events simulated, " << restRun->GetEntries() << " Events stored\n";
G4cout << "===========================================================";
G4cout << G4endl;

Expand Down

0 comments on commit ab18992

Please sign in to comment.