diff --git a/.github/workflows/testSciG.yml b/.github/workflows/testSciG.yml index ced0178..62db413 100644 --- a/.github/workflows/testSciG.yml +++ b/.github/workflows/testSciG.yml @@ -21,8 +21,14 @@ jobs: fail-fast: false matrix: examples: + - examples/basic_materials + - examples/cad_imports - examples/dosimeter - - examples/simple_flux + - examples/flux_detector + - examples/scintillator_array + - examples/sqlite_db + - examples/variations + steps: # GitHub Actions do not automatically checkout your projects. If you need the code # you need to check it out. diff --git a/ci/testC12.sh b/ci/testC12.sh index 85a9966..17a3bd1 100755 --- a/ci/testC12.sh +++ b/ci/testC12.sh @@ -54,6 +54,10 @@ done # notice the gemc version is the one in the container, here we are # recompiling it using the checked out glibrary ./ci/build.sh +if [ $? -ne 0 ]; then + echo glibrary / gemc build failed + exit 1 +fi # using the checked out GLIBRARY export GLIBRARY=`pwd` diff --git a/ci/testSciG.sh b/ci/testSciG.sh index 0cdeb79..f7dea09 100755 --- a/ci/testSciG.sh +++ b/ci/testSciG.sh @@ -53,7 +53,11 @@ done # build glibrary / gemc # notice the gemc version is the one in the container, here we are # recompiling it using the checked out glibrary -./ci/build.sh +./ci/build.sh # build glibrary / gemc +if [ $? -ne 0 ]; then + echo glibrary / gemc build failed + exit 1 +fi # using the checked out GLIBRARY - notice we need to set these here again export GLIBRARY=`pwd` diff --git a/eventDispenser/eventDispenserOptions.cc b/eventDispenser/eventDispenserOptions.cc index 4b8ada0..48e4b6e 100644 --- a/eventDispenser/eventDispenserOptions.cc +++ b/eventDispenser/eventDispenserOptions.cc @@ -14,8 +14,9 @@ vector defineOptions() { json jsonEDVerbosity = { {GNAME, "edistv"}, - {GDESC, GVERBOSITY_DESCRIPTION}, - {GDFLT, 0} + {GDESC, "Verbosity for eventDispenser. " + string(GVERBOSITY_DESCRIPTION)}, + + {GDFLT, 0} }; goptions.push_back(GOption(jsonEDVerbosity)); diff --git a/g4display/g4displayOptions.cc b/g4display/g4displayOptions.cc index d591c2f..8fdf69a 100644 --- a/g4display/g4displayOptions.cc +++ b/g4display/g4displayOptions.cc @@ -136,8 +136,8 @@ vector defineOptions() { // g4display verbosity json jsonMessageVerbosity = { {GNAME, "g4displayv"}, - {GDESC, GVERBOSITY_DESCRIPTION}, - {GDFLT, 0} + {GDESC, "Verbosity for g4display. " + string(GVERBOSITY_DESCRIPTION)}, + {GDFLT, 0} }; goptions.push_back(GOption(jsonMessageVerbosity)); diff --git a/g4system/g4objectsFactories/g4native/buildSolid.cc b/g4system/g4objectsFactories/g4native/buildSolid.cc index 349d012..3a61c8c 100644 --- a/g4system/g4objectsFactories/g4native/buildSolid.cc +++ b/g4system/g4objectsFactories/g4native/buildSolid.cc @@ -47,88 +47,88 @@ G4VSolid* G4NativeSystemFactory::buildSolid(GOptions* gopt, GVolume *s, mapgetType(); if(type == "G4Box") { - thisG4Volume->setSolid(new G4Box(g4name, ///< name - pars[0], ///< half length in X - pars[1], ///< half length in Y - pars[2] ///< half length in Z + thisG4Volume->setSolid(new G4Box(g4name, // name + pars[0], // half length in X + pars[1], // half length in Y + pars[2] // half length in Z ), verbosity ); return thisG4Volume->getSolid(); } else if(type == "G4Tubs") { - thisG4Volume->setSolid(new G4Tubs(g4name, ///< name - pars[0], ///< Inner radius - pars[1], ///< Outer radius - pars[2], ///< Half length in z - pars[3], ///< Starting phi angle - pars[4] ///< Delta Phi angle + thisG4Volume->setSolid(new G4Tubs(g4name, // name + pars[0], // Inner radius + pars[1], // Outer radius + pars[2], // Half length in z + pars[3], // Starting phi angle + pars[4] // Delta Phi angle ), verbosity ); return thisG4Volume->getSolid(); } else if(type == "G4Sphere") { - thisG4Volume->setSolid(new G4Sphere(g4name, ///< name - pars[0], ///< Inner radius - pars[1], ///< Outer radius - pars[2], ///< Starting phi angle - pars[3], ///< Delta Phi angle - pars[4], ///< Starting delta angle - pars[5] ///< Delta delta angle + thisG4Volume->setSolid(new G4Sphere(g4name, // name + pars[0], // Inner radius + pars[1], // Outer radius + pars[2], // Starting phi angle + pars[3], // Delta Phi angle + pars[4], // Starting delta angle + pars[5] // Delta delta angle ), verbosity ); return thisG4Volume->getSolid(); } else if(type == "G4CutTubs") { - thisG4Volume->setSolid(new G4CutTubs(g4name, ///< name - pars[0], ///< Inner radius - pars[1], ///< Outer radius - pars[2], ///< Half length in z - pars[3], ///< Starting phi angle - pars[4], ///< Delta Phi angle - G4ThreeVector(pars[5], pars[6], pars[7]), ///< Outside Normal at -z - G4ThreeVector(pars[8], pars[9], pars[10]) ///< Outside Normal at +z + thisG4Volume->setSolid(new G4CutTubs(g4name, // name + pars[0], // Inner radius + pars[1], // Outer radius + pars[2], // Half length in z + pars[3], // Starting phi angle + pars[4], // Delta Phi angle + G4ThreeVector(pars[5], pars[6], pars[7]), // Outside Normal at -z + G4ThreeVector(pars[8], pars[9], pars[10]) // Outside Normal at +z ), verbosity ); return thisG4Volume->getSolid(); } else if(type == "G4Cons") { - thisG4Volume->setSolid(new G4Cons(g4name, ///< name - pars[0], ///< Inside radius at -pDz - pars[1], ///< Outside radius at -pDz - pars[2], ///< Inside radius at +pDz - pars[3], ///< Outside radius at +pDz - pars[4], ///< Half length in z - pars[5], ///< Starting phi angle - pars[6] ///< Delta Phi angle + thisG4Volume->setSolid(new G4Cons(g4name, // name + pars[0], // Inside radius at -pDz + pars[1], // Outside radius at -pDz + pars[2], // Inside radius at +pDz + pars[3], // Outside radius at +pDz + pars[4], // Half length in z + pars[5], // Starting phi angle + pars[6] // Delta Phi angle ), verbosity ); return thisG4Volume->getSolid(); } else if(type == "G4Para") { - thisG4Volume->setSolid(new G4Para(g4name, ///< name - pars[0], ///< Half length in x - pars[1], ///< Half length in y - pars[2], ///< Half length in z - pars[3], ///< Angle formed by the y axis and by the plane joining the centre of the faces parallel to the z-x plane at -dy and +dy - pars[4], ///< Polar angle of the line joining the centres of the faces at -dz and +dz in z - pars[5] ///< Azimuthal angle of the line joining the centres of the faces at -dz and +dz in z + thisG4Volume->setSolid(new G4Para(g4name, // name + pars[0], // Half length in x + pars[1], // Half length in y + pars[2], // Half length in z + pars[3], // Angle formed by the y axis and by the plane joining the centre of the faces parallel to the z-x plane at -dy and +dy + pars[4], // Polar angle of the line joining the centres of the faces at -dz and +dz in z + pars[5] // Azimuthal angle of the line joining the centres of the faces at -dz and +dz in z ), verbosity ); return thisG4Volume->getSolid(); } else if(type == "G4Trd") { - thisG4Volume->setSolid(new G4Trd(g4name, ///< name - pars[0], ///< Half-length along x at the surface positioned at -dz - pars[1], ///< Half-length along x at the surface positioned at +dz - pars[2], ///< Half-length along y at the surface positioned at -dz - pars[3], ///< Half-length along y at the surface positioned at +dz - pars[4] ///< Half-length along z axis + thisG4Volume->setSolid(new G4Trd(g4name, // name + pars[0], // Half-length along x at the surface positioned at -dz + pars[1], // Half-length along x at the surface positioned at +dz + pars[2], // Half-length along y at the surface positioned at -dz + pars[3], // Half-length along y at the surface positioned at +dz + pars[4] // Half-length along z axis ), verbosity ); return thisG4Volume->getSolid(); @@ -142,27 +142,27 @@ G4VSolid* G4NativeSystemFactory::buildSolid(GOptions* gopt, GVolume *s, mapsetSolid(new G4Trap(g4name, ///< name - pars[0], ///< Length along Z - pars[1], ///< Length along Y - pars[2], ///< Length along X wider side - pars[3] ///< Length along X at the narrower side (plTX<=pX) + thisG4Volume->setSolid(new G4Trap(g4name, // name + pars[0], // Length along Z + pars[1], // Length along Y + pars[2], // Length along X wider side + pars[3] // Length along X at the narrower side (plTX<=pX) ), verbosity ); // general trapezoid (11 parameters) } else if ( pars.size() == 11) { - thisG4Volume->setSolid(new G4Trap(g4name, ///< name - pars[0], ///< Half Z length - distance from the origin to the bases - pars[1], ///< Polar angle of the line joining the centres of the bases at -/+pDz - pars[2], ///< Azimuthal angle of the line joining the centre of the base at -pDz to the centre of the base at +pDz - pars[3], ///< Half Y length of the base at -pDz - pars[4], ///< Half Y length of the base at +pDz - pars[5], ///< Half X length at smaller Y of the base at -pDz - pars[6], ///< Half X length at bigger Y of the base at -pDz - pars[7], ///< Half X length at smaller Y of the base at +pDz - pars[8], ///< Half X length at bigger y of the base at +pDz - pars[9], ///< Angle between the Y-axis and the centre line of the base at -pDz (lower endcap) - pars[10] ///< Angle between the Y-axis and the centre line of the base at +pDz (upper endcap) + thisG4Volume->setSolid(new G4Trap(g4name, // name + pars[0], // Half Z length - distance from the origin to the bases + pars[1], // Polar angle of the line joining the centres of the bases at -/+pDz + pars[2], // Azimuthal angle of the line joining the centre of the base at -pDz to the centre of the base at +pDz + pars[3], // Half Y length of the base at -pDz + pars[4], // Half Y length of the base at +pDz + pars[5], // Half X length at smaller Y of the base at -pDz + pars[6], // Half X length at bigger Y of the base at -pDz + pars[7], // Half X length at smaller Y of the base at +pDz + pars[8], // Half X length at bigger y of the base at +pDz + pars[9], // Angle between the Y-axis and the centre line of the base at -pDz (lower endcap) + pars[10] // Angle between the Y-axis and the centre line of the base at +pDz (upper endcap) ), verbosity ); @@ -179,8 +179,8 @@ G4VSolid* G4NativeSystemFactory::buildSolid(GOptions* gopt, GVolume *s, mapsetSolid(new G4Trap(g4name, ///< name - pt ///< Coordinates of the vertices + thisG4Volume->setSolid(new G4Trap(g4name, // name + pt // Coordinates of the vertices ), verbosity ); @@ -207,13 +207,13 @@ G4VSolid* G4NativeSystemFactory::buildSolid(GOptions* gopt, GVolume *s, mapsetSolid(new G4Polycone(g4name, ///< name - phistart, ///< Initial Phi starting angle - phitotal, ///< Total Phi angle - zplanes, ///< Number of z planes - zPlane, ///< z coordinate of corners - rInner, ///< Tangent distance to inner surface - rOuter ///< Tangent distance to outer surface, verbosity + thisG4Volume->setSolid(new G4Polycone(g4name, // name + phistart, // Initial Phi starting angle + phitotal, // Total Phi angle + zplanes, // Number of z planes + zPlane, // z coordinate of corners + rInner, // Tangent distance to inner surface + rOuter // Tangent distance to outer surface, verbosity ), verbosity ); diff --git a/g4system/g4systemOptions.cc b/g4system/g4systemOptions.cc index 264ba83..9963c68 100644 --- a/g4system/g4systemOptions.cc +++ b/g4system/g4systemOptions.cc @@ -12,8 +12,8 @@ vector defineOptions() { json jsonG4WorldVerbosity = { {GNAME, G4SYSTEMVERBOSITY}, - {GDESC, GVERBOSITY_DESCRIPTION}, - {GDFLT, 1} + {GDESC, "Verbosity for g4system. " + string(GVERBOSITY_DESCRIPTION)}, + {GDFLT, 1} }; goptions.push_back(GOption(jsonG4WorldVerbosity)); diff --git a/g4system/g4world.cc b/g4system/g4world.cc index e42696c..e3e783b 100644 --- a/g4system/g4world.cc +++ b/g4system/g4world.cc @@ -17,7 +17,6 @@ using namespace std; G4World::G4World(GWorld *gworld, GOptions* gopts) { - // instantiating volumes map g4volumesMap = new map; g4materialsMap = new map; diff --git a/gfactory/gdl.h b/gfactory/gdl.h index 5819391..1e30f62 100644 --- a/gfactory/gdl.h +++ b/gfactory/gdl.h @@ -32,7 +32,7 @@ static void close_lib(dlhandle handle); struct DynamicLib { private: - std::string dlFileName; ///< dynamic library file + std::string dlFileName; // dynamic library file int verbosity = 0; bool doesFileExists(const std::string& name) { @@ -44,7 +44,7 @@ struct DynamicLib { public: // default constructor DynamicLib() = default; - dlhandle handle = nullptr; ///< posix handle of the dynamic library + dlhandle handle = nullptr; // posix handle of the dynamic library DynamicLib(std::string path, int v = 0) : dlFileName(path), verbosity(v), handle(nullptr) { diff --git a/goptions/goptions.h b/goptions/goptions.h index 9f013dd..5da3395 100644 --- a/goptions/goptions.h +++ b/goptions/goptions.h @@ -230,13 +230,13 @@ class GOptions */ void printSettings(bool withDefaults); - int getInt(string tag); ///< gets the integer value associated with non structured option \"tag\" - float getFloat(string tag); ///< gets the float value associated with non structured option \"tag\" - double getDouble(string tag); ///< gets the double value associated with non structured option \"tag\" - string getString(string tag); ///< gets the string value associated with non structured option \"tag\" - bool getSwitch(string tag); ///< gets the bool value associated with switch \"tag\" + int getInt(string tag); // gets the integer value associated with non structured option \"tag\" + float getFloat(string tag); // gets the float value associated with non structured option \"tag\" + double getDouble(string tag); // gets the double value associated with non structured option \"tag\" + string getString(string tag); // gets the string value associated with non structured option \"tag\" + bool getSwitch(string tag); // gets the bool value associated with switch \"tag\" - string jcardFilename; ///< jcard with path, specified by the command line + string jcardFilename; // jcard with path, specified by the command line /** * @brief Get the (structured) option json values corresponding to a tag diff --git a/goptions/json.hpp b/goptions/json.hpp index 674c113..70e8175 100644 --- a/goptions/json.hpp +++ b/goptions/json.hpp @@ -3376,16 +3376,16 @@ value with the default value for a given type */ enum class value_t : std::uint8_t { - null, ///< null value - object, ///< object (unordered set of name/value pairs) - array, ///< array (ordered collection of values) - string, ///< string value - boolean, ///< boolean value - number_integer, ///< number value (signed integer) - number_unsigned, ///< number value (unsigned integer) - number_float, ///< number value (floating-point) - binary, ///< binary array (ordered collection of bytes) - discarded ///< discarded by the parser callback function + null, // null value + object, // object (unordered set of name/value pairs) + array, // array (ordered collection of values) + string, // string value + boolean, // boolean value + number_integer, // number value (signed integer) + number_unsigned, // number value (unsigned integer) + number_float, // number value (floating-point) + binary, // binary array (ordered collection of bytes) + discarded // discarded by the parser callback function }; /*! @@ -5908,23 +5908,23 @@ class lexer_base /// token types for the parser enum class token_type { - uninitialized, ///< indicating the scanner is uninitialized - literal_true, ///< the `true` literal - literal_false, ///< the `false` literal - literal_null, ///< the `null` literal - value_string, ///< a string -- use get_string() for actual value - value_unsigned, ///< an unsigned integer -- use get_number_unsigned() for actual value - value_integer, ///< a signed integer -- use get_number_integer() for actual value - value_float, ///< an floating point number -- use get_number_float() for actual value - begin_array, ///< the character for array begin `[` - begin_object, ///< the character for object begin `{` - end_array, ///< the character for array end `]` - end_object, ///< the character for object end `}` - name_separator, ///< the name separator `:` - value_separator, ///< the value separator `,` - parse_error, ///< indicating a parse error - end_of_input, ///< indicating the end of the input buffer - literal_or_value ///< a literal or the begin of a value (only for diagnostics) + uninitialized, // indicating the scanner is uninitialized + literal_true, // the `true` literal + literal_false, // the `false` literal + literal_null, // the `null` literal + value_string, // a string -- use get_string() for actual value + value_unsigned, // an unsigned integer -- use get_number_unsigned() for actual value + value_integer, // a signed integer -- use get_number_integer() for actual value + value_float, // an floating point number -- use get_number_float() for actual value + begin_array, // the character for array begin `[` + begin_object, // the character for object begin `{` + end_array, // the character for array end `]` + end_object, // the character for object end `}` + name_separator, // the name separator `:` + value_separator, // the value separator `,` + parse_error, // indicating a parse error + end_of_input, // indicating the end of the input buffer + literal_or_value // a literal or the begin of a value (only for diagnostics) }; /// return name of values of type token_type (only used for errors) @@ -7667,8 +7667,8 @@ namespace detail /// how to treat CBOR tags enum class cbor_tag_handler_t { - error, ///< throw a parse_error exception in case of a tag - ignore ///< ignore tags + error, // throw a parse_error exception in case of a tag + ignore // ignore tags }; /*! @@ -15468,9 +15468,9 @@ namespace detail /// how to treat decoding errors enum class error_handler_t { - strict, ///< throw a type_error exception in case of invalid UTF-8 - replace, ///< replace invalid UTF-8 sequences with U+FFFD - ignore ///< ignore invalid UTF-8 sequences + strict, // throw a type_error exception in case of invalid UTF-8 + replace, // replace invalid UTF-8 sequences with U+FFFD + ignore // ignore invalid UTF-8 sequences }; template diff --git a/gparticle/gparticle.cc b/gparticle/gparticle.cc index 72721e1..a23e5d3 100644 --- a/gparticle/gparticle.cc +++ b/gparticle/gparticle.cc @@ -1,5 +1,6 @@ // guts #include "gutilities.h" + using namespace gutilities; // gparticle @@ -16,46 +17,45 @@ using namespace std; Gparticle::Gparticle(gparticle::JParticle jparticle) { - name = jparticle.pname; - pid = jparticle.pid; - multiplicity = jparticle.multiplicity; - thetaModel = jparticle.thetaModel; + name = jparticle.pname; + set_pdg_id(); + multiplicity = jparticle.multiplicity; + thetaModel = jparticle.thetaModel; - p = getG4Number(jparticle.p, jparticle.punit); - theta = getG4Number(jparticle.theta, jparticle.aunit); - phi = getG4Number(jparticle.phi, jparticle.aunit); + p = getG4Number(jparticle.p, jparticle.punit); + theta = getG4Number(jparticle.theta, jparticle.aunit); + phi = getG4Number(jparticle.phi, jparticle.aunit); - delta_p = getG4Number(jparticle.delta_p, jparticle.punit); - delta_theta = getG4Number(jparticle.delta_theta, jparticle.aunit); - delta_phi = getG4Number(jparticle.delta_phi, jparticle.aunit); + delta_p = getG4Number(jparticle.delta_p, jparticle.punit); + delta_theta = getG4Number(jparticle.delta_theta, jparticle.aunit); + delta_phi = getG4Number(jparticle.delta_phi, jparticle.aunit); - if (jparticle.randomMomentumModel == "gaussian") { - momentumGaussianSpread = true; - } else { - momentumGaussianSpread = false; - } - - if (jparticle.randomVertexModel == "gaussian") { - vertexGaussianSpread = true; - } else { - vertexGaussianSpread = false; - } + if (jparticle.randomMomentumModel == "gaussian") { + momentumGaussianSpread = true; + } else { + momentumGaussianSpread = false; + } - v = G4ThreeVector( - getG4Number(jparticle.vx, jparticle.vunit), - getG4Number(jparticle.vy, jparticle.vunit), - getG4Number(jparticle.vz, jparticle.vunit) - ); + if (jparticle.randomVertexModel == "gaussian") { + vertexGaussianSpread = true; + } else { + vertexGaussianSpread = false; + } - delta_v = G4ThreeVector( - getG4Number(jparticle.delta_vx, jparticle.vunit), - getG4Number(jparticle.delta_vy, jparticle.vunit), - getG4Number(jparticle.delta_vz, jparticle.vunit) - ); + v = G4ThreeVector( + getG4Number(jparticle.vx, jparticle.vunit), + getG4Number(jparticle.vy, jparticle.vunit), + getG4Number(jparticle.vz, jparticle.vunit) + ); - delta_VR = getG4Number(jparticle.delta_VR, jparticle.vunit); + delta_v = G4ThreeVector( + getG4Number(jparticle.delta_vx, jparticle.vunit), + getG4Number(jparticle.delta_vy, jparticle.vunit), + getG4Number(jparticle.delta_vz, jparticle.vunit) + ); + delta_VR = getG4Number(jparticle.delta_VR, jparticle.vunit); } @@ -63,71 +63,71 @@ Gparticle::Gparticle(gparticle::JParticle jparticle) { // for G4GeneralParticleSource API check: // https://geant4.kek.jp/lxr/source/event/include/G4ParticleGun.hh // https://geant4.kek.jp/lxr/source/event/src/G4ParticleGun.cc -void Gparticle::shootParticle(G4ParticleGun* particleGun, G4Event* anEvent) { +void Gparticle::shootParticle(G4ParticleGun *particleGun, G4Event *anEvent, int verbosity) { - auto particleTable = G4ParticleTable::GetParticleTable(); + auto particleTable = G4ParticleTable::GetParticleTable(); - if ( particleTable ) { - auto particleDef = particleTable->FindParticle(name); + if (particleTable) { + auto particleDef = particleTable->FindParticle(name); - if ( particleDef ) { + if (particleDef) { - float mass = particleDef->GetPDGMass(); - particleGun->SetParticleDefinition(particleDef); + float mass = particleDef->GetPDGMass(); + particleGun->SetParticleDefinition(particleDef); - for ( int i=0; iSetParticleEnergy(calculateKinEnergy(mass)); + for (int i = 0; i < multiplicity; i++) { + particleGun->SetParticleEnergy(calculateKinEnergy(mass)); - particleGun->SetParticleMomentumDirection(calculateBeamDirection()); - particleGun->SetParticlePosition(calculateVertex()); - particleGun->GeneratePrimaryVertex(anEvent); - } + particleGun->SetParticleMomentumDirection(calculateBeamDirection()); + particleGun->SetParticlePosition(calculateVertex()); + particleGun->GeneratePrimaryVertex(anEvent); + } - } else { - cerr << FATALERRORL << " particle >" << name << "< not found in G4ParticleTable* " << particleTable << endl; - gexit(EC__GPARTICLENOTFOUND); - } + } else { + cerr << FATALERRORL << " particle >" << name << "< not found in G4ParticleTable* " << particleTable << endl; + gexit(EC__GPARTICLENOTFOUND); + } - } else { - cerr << FATALERRORL << "G4ParticleTable not found - G4ParticleGun*: " << particleGun << endl; - gexit(EC__GPARTICLETABLENOTFOUND); - } + } else { + cerr << FATALERRORL << "G4ParticleTable not found - G4ParticleGun*: " << particleGun << endl; + gexit(EC__GPARTICLETABLENOTFOUND); + } } float Gparticle::calculateMomentum() { - float pmev = randomize(p/CLHEP::MeV, delta_p/CLHEP::MeV, momentumGaussianSpread); + float pmev = randomize(p / CLHEP::MeV, delta_p / CLHEP::MeV, momentumGaussianSpread); - return pmev; + return pmev; } float Gparticle::calculateKinEnergy(float mass) { - - float pmev = calculateMomentum(); - - return sqrt(pmev*pmev + mass*mass) - mass ; + + float pmev = calculateMomentum(); + + return sqrt(pmev * pmev + mass * mass) - mass; } G4ThreeVector Gparticle::calculateBeamDirection() { - double thetaRad = 0; + double thetaRad = 0; - if (thetaModel == "ct") { + if (thetaModel == "ct") { - double lower = (theta - delta_theta)/CLHEP::rad; - double upper = (theta + delta_theta)/CLHEP::rad; + double lower = (theta - delta_theta) / CLHEP::rad; + double upper = (theta + delta_theta) / CLHEP::rad; - if ( lower < upper ) { + if (lower < upper) { // generate random cos(theta) in range [lower, upper] do { thetaRad = acos(1 - 2 * G4UniformRand()); } while (thetaRad < lower || thetaRad > upper); } else { - thetaRad = theta/CLHEP::rad; + thetaRad = theta / CLHEP::rad; } // notice the formula below doesn't work because cos(theta) = cos(-theta) @@ -135,62 +135,111 @@ G4ThreeVector Gparticle::calculateBeamDirection() { // thetaRad = acos(G4UniformRand()*(cos(theta - delta_theta/CLHEP::rad) - cos(theta/CLHEP::rad + delta_theta/CLHEP::rad)) // + cos(theta/CLHEP::rad + delta_theta/CLHEP::rad)) / CLHEP::rad; - } else if (thetaModel == "flat") { - thetaRad = randomize(theta/CLHEP::rad, delta_theta/CLHEP::rad, momentumGaussianSpread) ; - } else { - cerr << FATALERRORL << " thetaModel >" << thetaModel << "< not recognized." << endl; - gexit(EC__GPARTICLEWRONGTHETAMODEL); - } + } else if (thetaModel == "flat") { + thetaRad = randomize(theta / CLHEP::rad, delta_theta / CLHEP::rad, momentumGaussianSpread); + } else { + cerr << FATALERRORL << " thetaModel >" << thetaModel << "< not recognized." << endl; + gexit(EC__GPARTICLEWRONGTHETAMODEL); + } + double phiRad = randomize(phi / CLHEP::rad, delta_phi / CLHEP::rad, momentumGaussianSpread); - double phiRad = randomize(phi/CLHEP::rad, delta_phi/CLHEP::rad, momentumGaussianSpread) ; + G4ThreeVector pdir = G4ThreeVector( + cos(phiRad) * sin(thetaRad), + sin(phiRad) * sin(thetaRad), + cos(thetaRad) + ); - G4ThreeVector pdir = G4ThreeVector( - cos(phiRad)*sin(thetaRad), - sin(phiRad)*sin(thetaRad), - cos(thetaRad) - ); - - return pdir; + return pdir; } G4ThreeVector Gparticle::calculateVertex() { - float x, y, z; + float x, y, z; - if (delta_VR > 0 ) { - float radius; - do { - x = randomize(0, delta_VR, vertexGaussianSpread); - y = randomize(0, delta_VR, vertexGaussianSpread); - z = randomize(0, delta_VR, vertexGaussianSpread); - radius = x*x + y*y + z*z; - } while(radius > delta_VR); + if (delta_VR > 0) { + float radius; + do { + x = randomize(0, delta_VR, vertexGaussianSpread); + y = randomize(0, delta_VR, vertexGaussianSpread); + z = randomize(0, delta_VR, vertexGaussianSpread); + radius = x * x + y * y + z * z; + } while (radius > delta_VR); - x = x + v.x(); - y = y + v.y(); - z = z + v.z(); + x = x + v.x(); + y = y + v.y(); + z = z + v.z(); - } else { - x = randomize(v.x(), delta_v.x(), vertexGaussianSpread); - y = randomize(v.y(), delta_v.y(), vertexGaussianSpread); - z = randomize(v.z(), delta_v.z(), vertexGaussianSpread); - } + } else { + x = randomize(v.x(), delta_v.x(), vertexGaussianSpread); + y = randomize(v.y(), delta_v.y(), vertexGaussianSpread); + z = randomize(v.z(), delta_v.z(), vertexGaussianSpread); + } - G4ThreeVector vertex = G4ThreeVector(x, y, z); + G4ThreeVector vertex = G4ThreeVector(x, y, z); - return vertex; + return vertex; } - float Gparticle::randomize(float center, float delta, bool gaussianSPread) { - if (gaussianSPread) { - return G4RandGauss::shoot(center, delta); - } else { - return center + (2.0*G4UniformRand()-1.0)*delta; - } + if (gaussianSPread) { + return G4RandGauss::shoot(center, delta); + } else { + return center + (2.0 * G4UniformRand() - 1.0) * delta; + } +} + +ostream &operator<<(ostream &stream, Gparticle gparticle) { + stream << "Gparticle: " << endl; + + cout << " name: " << gparticle.name << " (pid: " << gparticle.pid << ")" << endl; + cout << " mass: " << gparticle.get_mass() << endl; + cout << " multiplicity: " << gparticle.multiplicity << endl; + cout << " thetaModel: " << gparticle.thetaModel << endl; + cout << " p: " << gparticle.p << endl; + cout << " delta_p: " << gparticle.delta_p << endl; + cout << " theta: " << gparticle.theta / CLHEP::rad << endl; + cout << " delta_theta: " << gparticle.delta_theta << endl; + cout << " phi: " << gparticle.phi << endl; + cout << " delta_phi: " << gparticle.delta_phi << endl; + cout << " momentumGaussianSpread: " << gparticle.momentumGaussianSpread << endl; + cout << " vertexGaussianSpread: " << gparticle.vertexGaussianSpread << endl; + cout << " v: " << gparticle.v << endl; + cout << " delta_v: " << gparticle.delta_v << endl; + cout << " delta_VR: " << gparticle.delta_VR << endl; + + return stream; +} + + +void Gparticle::set_pdg_id() { + auto particleTable = G4ParticleTable::GetParticleTable(); + + if (particleTable) { + auto particleDef = particleTable->FindParticle(name); + + if (particleDef) { + pid = particleDef->GetPDGEncoding(); + } + } } + +double Gparticle::get_mass() { + auto particleTable = G4ParticleTable::GetParticleTable(); + + if (particleTable) { + auto particleDef = particleTable->FindParticle(name); + + if (particleDef) { + + float mass = particleDef->GetPDGMass(); + return mass; + + } + } + return 0; +} \ No newline at end of file diff --git a/gparticle/gparticle.h b/gparticle/gparticle.h index 0e36dd4..2c485bb 100644 --- a/gparticle/gparticle.h +++ b/gparticle/gparticle.h @@ -8,56 +8,63 @@ #include "G4ThreeVector.hh" #include "G4ParticleGun.hh" +// c++ +using std::ostream; + // This class interfaces to the Geant4 General Particle Source -class Gparticle -{ +class Gparticle { public: - Gparticle(gparticle::JParticle jparticle); + Gparticle(gparticle::JParticle jparticle); private: - // PDG Monte Carlo Particle Numbering Scheme: - // https://pdg.lbl.gov/2019/reviews/rpp2019-rev-monte-carlo-numbering.pdf - string name; - int pid; - int multiplicity; - - // assigned momentum and distributions - float p; - float delta_p; - float theta; - - - float phi; - float delta_theta; - float delta_phi; - string thetaModel; // 'ct' (default): cosTheta is uniform. 'flat': theta is uniform - bool momentumGaussianSpread; // true: gaussian around values, using the deltas as sigmas. false: uniform distribution in speficied range - - // assigned vertex and distributions - G4ThreeVector v; - G4ThreeVector delta_v; - float delta_VR; - bool vertexGaussianSpread; // true: gaussian around values, using the deltas as sigmas. - // false: uniform distribution in speficied range + // PDG Monte Carlo Particle Numbering Scheme: + // https://pdg.lbl.gov/2019/reviews/rpp2019-rev-monte-carlo-numbering.pdf + string name; + int pid; + int multiplicity; + + // assigned momentum and distributions + float p; + float delta_p; + float theta; + + float phi; + float delta_theta; + float delta_phi; + string thetaModel; // 'ct' (default): cosTheta is uniform. 'flat': theta is uniform + bool momentumGaussianSpread; // true: gaussian around values, using the deltas as sigmas. false: uniform distribution in speficied range + + // assigned vertex and distributions + G4ThreeVector v; + G4ThreeVector delta_v; + float delta_VR; + bool vertexGaussianSpread; // true: gaussian around values. false: uniform distribution in specified range + int verbosity; + friend ostream &operator<<(ostream &stream, Gparticle); // Logs infos on screen. public: - void shootParticle(G4ParticleGun* particleGun, G4Event* anEvent); + void shootParticle(G4ParticleGun *particleGun, G4Event *anEvent, int verbosity = 0); - // methods that uniformly distribute the particles + // methods that uniformly distribute the particles private: - float randomize(float center, float delta, bool gaussianSPread); + float randomize(float center, float delta, bool gaussianSPread); + + float calculateMomentum(); + + float calculateKinEnergy(float mass); + + G4ThreeVector calculateBeamDirection(); - float calculateMomentum(); - float calculateKinEnergy(float mass); - G4ThreeVector calculateBeamDirection(); - G4ThreeVector calculateVertex(); + G4ThreeVector calculateVertex(); + void set_pdg_id(); + double get_mass(); }; diff --git a/gparticle/gparticleConventions.h b/gparticle/gparticleConventions.h index 82aeb7e..81fe7e2 100644 --- a/gparticle/gparticleConventions.h +++ b/gparticle/gparticleConventions.h @@ -2,11 +2,13 @@ #define GPARTICLE_H_CONVENTIONS 1 #define GPARTICLENOTDEFINED -999 +#define GPARTICLEVERBOSITY "gparticlev" // error codes in the 900s #define EC__GPARTICLENOTFOUND 901 #define EC__GPARTICLEWRONGTHETAMODEL 902 #define EC__GPARTICLETABLENOTFOUND 903 +#define GPARTICLELOGHEADER " ・ GParticle ▸ " #endif diff --git a/gparticle/gparticleOptions.cc b/gparticle/gparticleOptions.cc index d7d5794..b324a1b 100644 --- a/gparticle/gparticleOptions.cc +++ b/gparticle/gparticleOptions.cc @@ -6,243 +6,247 @@ namespace gparticle { -// JParticle -// ------ -void from_json(const json& j, JParticle& jpar) { - j.at("pname").get_to(jpar.pname); - j.at("multiplicity").get_to(jpar.multiplicity); - j.at("p").get_to(jpar.p); - j.at("theta").get_to(jpar.theta); - j.at("phi").get_to(jpar.phi); - j.at("delta_p").get_to(jpar.delta_p); - j.at("delta_theta").get_to(jpar.delta_theta); - j.at("delta_phi").get_to(jpar.delta_phi); - j.at("thetaModel").get_to(jpar.thetaModel); - j.at("randomMomentumModel").get_to(jpar.randomMomentumModel); - j.at("punit").get_to(jpar.punit); - j.at("aunit").get_to(jpar.aunit); - j.at("vx").get_to(jpar.vx); - j.at("vy").get_to(jpar.vy); - j.at("vz").get_to(jpar.vz); - j.at("delta_vx").get_to(jpar.delta_vx); - j.at("delta_vy").get_to(jpar.delta_vy); - j.at("delta_vz").get_to(jpar.delta_vz); - j.at("delta_VR").get_to(jpar.delta_VR); - j.at("randomVertexModel").get_to(jpar.randomVertexModel); - j.at("vunit").get_to(jpar.vunit); -} + // JParticle + // ------ + void from_json(const json &j, JParticle &jpar) { + j.at("pname").get_to(jpar.pname); + j.at("multiplicity").get_to(jpar.multiplicity); + j.at("p").get_to(jpar.p); + j.at("theta").get_to(jpar.theta); + j.at("phi").get_to(jpar.phi); + j.at("delta_p").get_to(jpar.delta_p); + j.at("delta_theta").get_to(jpar.delta_theta); + j.at("delta_phi").get_to(jpar.delta_phi); + j.at("thetaModel").get_to(jpar.thetaModel); + j.at("randomMomentumModel").get_to(jpar.randomMomentumModel); + j.at("punit").get_to(jpar.punit); + j.at("aunit").get_to(jpar.aunit); + j.at("vx").get_to(jpar.vx); + j.at("vy").get_to(jpar.vy); + j.at("vz").get_to(jpar.vz); + j.at("delta_vx").get_to(jpar.delta_vx); + j.at("delta_vy").get_to(jpar.delta_vy); + j.at("delta_vz").get_to(jpar.delta_vz); + j.at("delta_VR").get_to(jpar.delta_VR); + j.at("randomVertexModel").get_to(jpar.randomVertexModel); + j.at("vunit").get_to(jpar.vunit); + } -// method to return a vector of GDetectors from a structured option -vector getJParticles(GOptions *gopts) { - - vector jparticles; - - auto jpars = gopts->getStructuredOptionAssignedValues("gparticle"); - - // looking over each of the vector items - for ( const auto& jpar: jpars ) { - jparticles.push_back(jpar.get()); - } - - return jparticles; -} + // method to return a vector of GDetectors from a structured option + vector getJParticles(GOptions *gopts) { + vector jparticles; + auto jpars = gopts->getStructuredOptionAssignedValues("gparticle"); -// returns array of options definitions -vector defineOptions() { - - vector goptions; - - // gparticle - // --------- - - // gparticle is cumulative structured (groupable): can use -add - json jpname = { - {GNAME, "pname"}, - {GDESC, "Particle name, for example \"proton\""}, - {GDFLT, NODFLT} - }; - - json jmulti = { - {GNAME, "multiplicity"}, - {GDESC, "How many copies of this particle will be generated in each event"}, - {GDFLT, 1} - }; - - json jp = { - {GNAME, "p"}, - {GDESC, "Particle momentum"}, - {GDFLT, 0} - }; - - json jtheta = { - {GNAME, "theta"}, - {GDESC, "Particle polar angle. Default: 0"}, - {GDFLT, 0} - }; - - json jphi = { - {GNAME, "phi"}, - {GDESC, "Particle azimuthal angle. Default: 0"}, - {GDFLT, 0} - }; - - json jdelta_p = { - {GNAME, "delta_p"}, - {GDESC, "Particle momentum range, centered on p. Default: 0"}, - {GDFLT, 0} - }; - - json jdelta_theta = { - {GNAME, "delta_theta"}, - {GDESC, "Particle polar angle range, centered on theta. Default: 0"}, - {GDFLT, 0} - }; - - json jdelta_phi = { - {GNAME, "delta_phi"}, - {GDESC, "Particle azimuthal angle range, centered on phi. Default: 0"}, - {GDFLT, 0} - }; - - json jthetaModel = { - {GNAME, "thetaModel"}, - {GDESC, "Distribute cos(theta) or theta. 'ct' (default): cosTheta is uniform. 'flat': theta is uniform"}, - {GDFLT, "ct"} - }; - - json jrandomMomentumModel = { - {GNAME, "randomMomentumModel"}, - {GDESC, "Momentum randomization. Default: uniform distribution. 'gaussian': use deltas as sigmas"}, - {GDFLT, "uniform"} - }; - - json jpunit = { - {GNAME, "punit"}, - {GDESC, "Unit for the particle momentum. Default: \"MeV\" "}, - {GDFLT, "MeV"} - }; - - json jaunit = { - {GNAME, "aunit"}, - {GDESC, "Unit for the particle angles. Default: \"deg\" "}, - {GDFLT, "deg"} - }; - - json jvx = { - {GNAME, "vx"}, - {GDESC, "Particle vertex x component. Default: 0"}, - {GDFLT, 0} - }; - - json jvy = { - {GNAME, "vy"}, - {GDESC, "Particle vertex y component. Default: 0"}, - {GDFLT, 0} - }; - - json jvz = { - {GNAME, "vz"}, - {GDESC, "Particle vertex z component. Default: 0"}, - {GDFLT, 0} - }; - - json jdelta_vx = { - {GNAME, "delta_vx"}, - {GDESC, "Particle vertex range of the x component. Default: 0"}, - {GDFLT, 0} - }; - - json jdelta_vy = { - {GNAME, "delta_vy"}, - {GDESC, "Particle vertex range of the y component. Default: 0"}, - {GDFLT, 0} - }; - - json jdelta_vz = { - {GNAME, "delta_vz"}, - {GDESC, "Particle vertex range of the z component. Default: 0"}, - {GDFLT, 0} - }; - - json jdelta_VR = { - {GNAME, "delta_VR"}, - {GDESC, "Particle vertex is generated within a sphere of radius delta_R. Default: 0"}, - {GDFLT, 0} - }; - - json jrandomVertexModel = { - {GNAME, "randomVertexModel"}, - {GDESC, "Vertex randomization. Default: uniform distribution. 'gaussian': use deltas as sigmas"}, - {GDFLT, "uniform"} - }; - - json jvunit = { - {GNAME, "vunit"}, - {GDESC, "Unit for the particle vertex. Default: \"mm\" "}, - {GDFLT, "cm"} - }; - - json jparticleOption = { - jpname, - jmulti, - jp, - jtheta, - jphi, - jdelta_p, - jdelta_theta, - jdelta_phi, - jrandomMomentumModel, - jthetaModel, - jpunit, - jaunit, - jvx, - jvy, - jvz, - jdelta_vx, - jdelta_vy, - jdelta_vz, - jdelta_VR, - jrandomVertexModel, - jvunit - }; - - vector help; - help.push_back(""); - help.push_back("Examples"); - help.push_back(""); - help.push_back("• 5 GeV electron along z:"); - help.push_back(" +gparticle={\"pname\": \"e-\"; \"p\": 5000;}"); - help.push_back(""); - help.push_back("• a 500 MeV neutron at theta=20 deg and uniform distribution in phi:"); - help.push_back(" +gparticle={\"pname\": \"neutron\"; \"p\": 500; \"theta\": 20; \"delta_phi\": 180}"); - help.push_back(""); - help.push_back("• 150 2.1 GeV electrons at theta=3deg, uniform in phi, at z=-2mm"); - help.push_back(" +gparticle={ \"pname\": \"e-\", \"multiplicity\": 150, \"p\": 2100, \"theta\": 3.0, \"delta_phi\": 180.0, \"vz\": -2.0}"); - help.push_back(""); - help.push_back("• 250 3 GeV pions+ at theta between 5 and 15 deg (uniform in cos(theta)), phi = 180"); - help.push_back(" +gparticle={ \"pname\": \"pi+\", \"multiplicity\": 250, \"p\": 3000, \"theta\": 10.0, \"delta_theta\": 5.0, \"phi\": 180}"); - help.push_back(""); - help.push_back("• 250 3 GeV pions+ at theta between 5 and 15 deg (uniform in theta), phi = 180"); - help.push_back(" +gparticle={ \"pname\": \"pi+\", \"multiplicity\": 250, \"p\": 3000, \"theta\": 10.0, \"delta_theta\": 5.0, \"phi\": 180, \"thetaModel\": \"flat\"}"); - help.push_back(""); - help.push_back("• 400 MeV protons at theta=90deg, uniform in phi, v on a sphere of radius 0.5mm at vz=-4mm"); - help.push_back(" +gparticle={ \"pname\": \"proton\", \"multiplicity\": 400, \"p\": 150, \"theta\": 90.0, \"delta_phi\": 180.0, \"delta_VR\": 0.5, \"vz\": -4.0}"); - - - // the last argument refers to "cumulative" - goptions.push_back(GOption("gparticle", "adds a particle to the event generator", jparticleOption, help, true)); - - - - - - - - - - return goptions; -} + // looking over each of the vector items + for (const auto &jpar: jpars) { + jparticles.push_back(jpar.get()); + } + + return jparticles; + } + + + // returns array of options definitions + vector defineOptions() { + + vector goptions; + + json jsonParticleVerbosity = { + {GNAME, GPARTICLEVERBOSITY}, + {GDESC, "Verbosity for gparticle. " + string(GVERBOSITY_DESCRIPTION)}, + {GDFLT, 1} + }; + goptions.push_back(GOption(jsonParticleVerbosity)); + + + // gparticle + // --------- + + // gparticle is cumulative structured (groupable): can use -add + json jpname = { + {GNAME, "pname"}, + {GDESC, "Particle name, for example \"proton\""}, + {GDFLT, NODFLT} + }; + + json jmulti = { + {GNAME, "multiplicity"}, + {GDESC, "How many copies of this particle will be generated in each event"}, + {GDFLT, 1} + }; + + json jp = { + {GNAME, "p"}, + {GDESC, "Particle momentum"}, + {GDFLT, 0} + }; + + json jtheta = { + {GNAME, "theta"}, + {GDESC, "Particle polar angle. Default: 0"}, + {GDFLT, 0} + }; + + json jphi = { + {GNAME, "phi"}, + {GDESC, "Particle azimuthal angle. Default: 0"}, + {GDFLT, 0} + }; + + json jdelta_p = { + {GNAME, "delta_p"}, + {GDESC, "Particle momentum range, centered on p. Default: 0"}, + {GDFLT, 0} + }; + + json jdelta_theta = { + {GNAME, "delta_theta"}, + {GDESC, "Particle polar angle range, centered on theta. Default: 0"}, + {GDFLT, 0} + }; + + json jdelta_phi = { + {GNAME, "delta_phi"}, + {GDESC, "Particle azimuthal angle range, centered on phi. Default: 0"}, + {GDFLT, 0} + }; + + json jthetaModel = { + {GNAME, "thetaModel"}, + {GDESC, "Distribute cos(theta) or theta. 'ct' (default): cosTheta is uniform. 'flat': theta is uniform"}, + {GDFLT, "ct"} + }; + + json jrandomMomentumModel = { + {GNAME, "randomMomentumModel"}, + {GDESC, "Momentum randomization. Default: uniform distribution. 'gaussian': use deltas as sigmas"}, + {GDFLT, "uniform"} + }; + + json jpunit = { + {GNAME, "punit"}, + {GDESC, "Unit for the particle momentum. Default: \"MeV\" "}, + {GDFLT, "MeV"} + }; + + json jaunit = { + {GNAME, "aunit"}, + {GDESC, "Unit for the particle angles. Default: \"deg\" "}, + {GDFLT, "deg"} + }; + + json jvx = { + {GNAME, "vx"}, + {GDESC, "Particle vertex x component. Default: 0"}, + {GDFLT, 0} + }; + + json jvy = { + {GNAME, "vy"}, + {GDESC, "Particle vertex y component. Default: 0"}, + {GDFLT, 0} + }; + + json jvz = { + {GNAME, "vz"}, + {GDESC, "Particle vertex z component. Default: 0"}, + {GDFLT, 0} + }; + + json jdelta_vx = { + {GNAME, "delta_vx"}, + {GDESC, "Particle vertex range of the x component. Default: 0"}, + {GDFLT, 0} + }; + + json jdelta_vy = { + {GNAME, "delta_vy"}, + {GDESC, "Particle vertex range of the y component. Default: 0"}, + {GDFLT, 0} + }; + + json jdelta_vz = { + {GNAME, "delta_vz"}, + {GDESC, "Particle vertex range of the z component. Default: 0"}, + {GDFLT, 0} + }; + + json jdelta_VR = { + {GNAME, "delta_VR"}, + {GDESC, "Particle vertex is generated within a sphere of radius delta_R. Default: 0"}, + {GDFLT, 0} + }; + + json jrandomVertexModel = { + {GNAME, "randomVertexModel"}, + {GDESC, "Vertex randomization. Default: uniform distribution. 'gaussian': use deltas as sigmas"}, + {GDFLT, "uniform"} + }; + + json jvunit = { + {GNAME, "vunit"}, + {GDESC, "Unit for the particle vertex. Default: \"mm\" "}, + {GDFLT, "cm"} + }; + + json jparticleOption = { + jpname, + jmulti, + jp, + jtheta, + jphi, + jdelta_p, + jdelta_theta, + jdelta_phi, + jrandomMomentumModel, + jthetaModel, + jpunit, + jaunit, + jvx, + jvy, + jvz, + jdelta_vx, + jdelta_vy, + jdelta_vz, + jdelta_VR, + jrandomVertexModel, + jvunit + }; + + vector help; + help.push_back(""); + help.push_back("Examples"); + help.push_back(""); + help.push_back("• 5 GeV electron along z:"); + help.push_back(" +gparticle={\"pname\": \"e-\"; \"p\": 5000;}"); + help.push_back(""); + help.push_back("• a 500 MeV neutron at theta=20 deg and uniform distribution in phi:"); + help.push_back(" +gparticle={\"pname\": \"neutron\"; \"p\": 500; \"theta\": 20; \"delta_phi\": 180}"); + help.push_back(""); + help.push_back("• 150 2.1 GeV electrons at theta=3deg, uniform in phi, at z=-2mm"); + help.push_back( + " +gparticle={ \"pname\": \"e-\", \"multiplicity\": 150, \"p\": 2100, \"theta\": 3.0, \"delta_phi\": 180.0, \"vz\": -2.0}"); + help.push_back(""); + help.push_back("• 250 3 GeV pions+ at theta between 5 and 15 deg (uniform in cos(theta)), phi = 180"); + help.push_back( + " +gparticle={ \"pname\": \"pi+\", \"multiplicity\": 250, \"p\": 3000, \"theta\": 10.0, \"delta_theta\": 5.0, \"phi\": 180}"); + help.push_back(""); + help.push_back("• 250 3 GeV pions+ at theta between 5 and 15 deg (uniform in theta), phi = 180"); + help.push_back( + " +gparticle={ \"pname\": \"pi+\", \"multiplicity\": 250, \"p\": 3000, \"theta\": 10.0, \"delta_theta\": 5.0, \"phi\": 180, \"thetaModel\": \"flat\"}"); + help.push_back(""); + help.push_back("• 400 MeV protons at theta=90deg, uniform in phi, v on a sphere of radius 0.5mm at vz=-4mm"); + help.push_back( + " +gparticle={ \"pname\": \"proton\", \"multiplicity\": 400, \"p\": 150, \"theta\": 90.0, \"delta_phi\": 180.0, \"delta_VR\": 0.5, \"vz\": -4.0}"); + + + // the last argument refers to "cumulative" + goptions.push_back(GOption("gparticle", "adds a particle to the event generator", jparticleOption, help, true)); + + + return goptions; + } } diff --git a/gparticle/gparticleOptions.h b/gparticle/gparticleOptions.h index 668ab96..0f255cb 100644 --- a/gparticle/gparticleOptions.h +++ b/gparticle/gparticleOptions.h @@ -15,7 +15,6 @@ vector defineOptions(); struct JParticle { string pname; - int pid; int multiplicity; float p; diff --git a/gphysics/gphysicsOptions.cc b/gphysics/gphysicsOptions.cc index 74412ef..642fee1 100644 --- a/gphysics/gphysicsOptions.cc +++ b/gphysics/gphysicsOptions.cc @@ -17,7 +17,7 @@ vector defineOptions() { json jsonGPhysVerbosity = { {GNAME, GPHYSVERBOSITY}, - {GDESC, GVERBOSITY_DESCRIPTION}, + {GDESC, "Verbosity for gphysics. " + string(GVERBOSITY_DESCRIPTION)}, {GDFLT, 0} }; goptions.push_back(GOption(jsonGPhysVerbosity)); diff --git a/gstreamer/gstreamerOptions.cc b/gstreamer/gstreamerOptions.cc index 5ae1e97..53b141a 100644 --- a/gstreamer/gstreamerOptions.cc +++ b/gstreamer/gstreamerOptions.cc @@ -38,10 +38,10 @@ vector defineOptions() { vector goptions; - // two verbosities: one for events, one for streaming + // two verbosity: one for events, one for streaming json jsonGStreamerEventVerbosity = { {GNAME, "geventstreamv"}, - {GDESC, GVERBOSITY_DESCRIPTION}, + {GDESC, "Verbosity for gstreamer. " + string(GVERBOSITY_DESCRIPTION)}, {GDFLT, 0} }; goptions.push_back(GOption(jsonGStreamerEventVerbosity)); diff --git a/gsystem/gmaterial.h b/gsystem/gmaterial.h index 8fdd89c..9541137 100644 --- a/gsystem/gmaterial.h +++ b/gsystem/gmaterial.h @@ -23,9 +23,9 @@ class GMaterial GMaterial(string system, vector pars); private: - string system; ///< System of provenience - string name; ///< Name of the material - string description; ///< Volume Description, for documentation + string system; // System of provenience + string name; // Name of the material + string description; // Volume Description, for documentation // material properties // the material is recorded with a string 'components' @@ -35,29 +35,29 @@ class GMaterial // C 9 H 10 // G4_N 0.7 G4_O 0.3 // - double density; ///< Material density, in g/cm3 - vector components; ///< The list of atoms/material - vector amounts; ///< Each component quantity or fractional mass + double density; // Material density, in g/cm3 + vector components; // The list of atoms/material + vector amounts; // Each component quantity or fractional mass // optical properties - vector photonEnergy; ///< A list of photon energies with units, at which any other optical parameters will be evaluated - vector indexOfRefraction; ///< A list of the refractive index evaluated at the energies named in photonEnergy - vector absorptionLength; ///< A list of the material absorption length with units, evaluated at the energies in photonEnergy - vector reflectivity; ///< A list of reflectivity values evaluated at the energies in photonEnergy - vector efficiency; ///< A list of absorption efficiency evaluated at the energies in photonEnergy + vector photonEnergy; // A list of photon energies with units, at which any other optical parameters will be evaluated + vector indexOfRefraction; // A list of the refractive index evaluated at the energies named in photonEnergy + vector absorptionLength; // A list of the material absorption length with units, evaluated at the energies in photonEnergy + vector reflectivity; // A list of reflectivity values evaluated at the energies in photonEnergy + vector efficiency; // A list of absorption efficiency evaluated at the energies in photonEnergy // scintillation properties - vector fastcomponent; ///< A list of the fast component relative spectra values evaluated at the energies in photonEnergy - vector slowcomponent; ///< A list of the fast component relative spectra values evaluated at the energies in photonEnergy - float scintillationyield; ///< Characteristic light yield in photons/MeV e-, given as a single number - float resolutionscale; ///< Resolution scale broadens the statistical distribution of generated photons - float fasttimeconstant; ///< FIX ME believe this is related to the scintillator pulse rise time. - float slowtimeconstant; ///< FIX ME believe this is related to scintillator slow decay timefloat - float yieldratio; ///< Relative strength of the fast component as a fraction of total scintillation yield, given as a single number - float birkConstant; ///< FIX ME + vector fastcomponent; // A list of the fast component relative spectra values evaluated at the energies in photonEnergy + vector slowcomponent; // A list of the fast component relative spectra values evaluated at the energies in photonEnergy + float scintillationyield; // Characteristic light yield in photons/MeV e-, given as a single number + float resolutionscale; // Resolution scale broadens the statistical distribution of generated photons + float fasttimeconstant; // FIX ME believe this is related to the scintillator pulse rise time. + float slowtimeconstant; // FIX ME believe this is related to scintillator slow decay timefloat + float yieldratio; // Relative strength of the fast component as a fraction of total scintillation yield, given as a single number + float birkConstant; // FIX ME // other optical properties - vector rayleigh; ///< A list of the Rayleigh scattering attenuation coefficient evaluated at the energies in photonEnergy + vector rayleigh; // A list of the Rayleigh scattering attenuation coefficient evaluated at the energies in photonEnergy // load material components from DB entry void setComponentsFromString(string composition); @@ -65,7 +65,7 @@ class GMaterial // load property from DB entry based on its name void getMaterialPropertyFromString(string parameter, string propertyName); - friend ostream &operator<<(ostream &stream, GMaterial); ///< Logs infos on screen. + friend ostream &operator<<(ostream &stream, GMaterial); // Logs infos on screen. public: // getters diff --git a/gsystem/gsystemFactories/sqlite/systemSqliteFactory.cc b/gsystem/gsystemFactories/sqlite/systemSqliteFactory.cc index a7d48d1..36c3411 100644 --- a/gsystem/gsystemFactories/sqlite/systemSqliteFactory.cc +++ b/gsystem/gsystemFactories/sqlite/systemSqliteFactory.cc @@ -23,17 +23,37 @@ void GSystemSQLiteFactory::initialize_sqlite_db(GSystem *system, int verbosity) runno = system->getRunno(); sqlite_file = system->getSqliteFile(); - // sqlite3_open_v2 will return SQLITE_OK (0) on success if the file exist (note: even if it's not an sql db) + // sqlite3_open_v2 will return SQLITE_OK (0) on success if the file exist (note: even if it's not a sqlite db) int rc = sqlite3_open_v2(sqlite_file.c_str(), &db, SQLITE_OPEN_READWRITE, NULL); if( rc ) { - cerr << GSYSTEMLOGHEADER << "Sqlite database " << sqlite_file << " not found " << endl; - gexit(EC__GSETUPFILENOTOFOUND); + + rc = 0; + sqlite3_close(db); + // file not found, now trying other locations + for(auto trialLocation : possibleLocationOfFiles) { + + string newName = trialLocation + "/" + sqlite_file; + if( verbosity == GVERBOSITY_DETAILS ) { + cout << GSYSTEMLOGHEADER << "Trying sqlite file " << newName << endl; + } + rc = sqlite3_open_v2(newName.c_str(), &db, SQLITE_OPEN_READWRITE, NULL); + + if( rc == 0 ) { + if(verbosity >= GVERBOSITY_SUMMARY) { + cout << GSYSTEMLOGHEADER << "Sqlite file >" << KMAG << newName << RST << "< opened successfully" << endl; + } + return; + } + } } else { - cout << GSYSTEMLOGHEADER << "Sqlite database >" << KMAG << sqlite_file << RST << "< opened successfully" << endl; + cout << GSYSTEMLOGHEADER << "Sqlite file >" << KMAG << sqlite_file << RST << "< opened successfully" << endl; + return; } - + // If we are here, the file was not found. Exit + cerr << GSYSTEMLOGHEADER << "Sqlite database " << sqlite_file << " not found " << endl; + gexit(EC__GSETUPFILENOTOFOUND); } void GSystemSQLiteFactory::closeSystem() { diff --git a/gsystem/gsystemFactories/text/systemTextFactory.cc b/gsystem/gsystemFactories/text/systemTextFactory.cc index 38888f8..eb70d29 100644 --- a/gsystem/gsystemFactories/text/systemTextFactory.cc +++ b/gsystem/gsystemFactories/text/systemTextFactory.cc @@ -54,7 +54,7 @@ ifstream* GSystemTextFactory::gSystemTextFileStream(GSystem *system, string SYST } // at this point file was not found - // this couldl be ok if we are looking for the materials file - if the system annotation is 'mats_only' + // this coulLd be ok if we are looking for the materials file - if the system annotation is 'mats_only' if ( SYSTEMTYPE == GTEXTGEOMTYPE ) { if ( system->getAnnotations() == "mats_only" ) { if ( verbosity >= GVERBOSITY_SUMMARY ) { diff --git a/gsystem/gsystemOptions.cc b/gsystem/gsystemOptions.cc index 6369ca0..26c64fc 100644 --- a/gsystem/gsystemOptions.cc +++ b/gsystem/gsystemOptions.cc @@ -164,7 +164,7 @@ vector defineOptions() { // gsystem verbosiry json jsonVerbosityOption = { {GNAME, "gsystemv"}, - {GDESC, "verbosity for gsystem. " + string(GVERBOSITY_DESCRIPTION)}, + {GDESC, "Verbosity for gsystem. " + string(GVERBOSITY_DESCRIPTION)}, {GDFLT, 0} }; goptions.push_back(GOption(jsonVerbosityOption)); diff --git a/gsystem/gvolume.h b/gsystem/gvolume.h index 3c47177..a707598 100644 --- a/gsystem/gvolume.h +++ b/gsystem/gvolume.h @@ -21,55 +21,55 @@ class GVolume GVolume(string rootVolumeDefinition); // special constructor for root volume private: - string system; ///< System of provenience - string name; ///< Name of the volume - string motherName; ///< Mother Volume name - string description; ///< Volume Description, for documentation - string importFilename; ///< For imports, filename with path, set with the import factory + string system; // System of provenience + string name; // Name of the volume + string motherName; // Mother Volume name + string description; // Volume Description, for documentation + string importFilename; // For imports, filename with path, set with the import factory // solid parameters - string type; ///< solid type. This follows the GEANT4 definitions - string parameters; ///< vector of parameters used in the geant4 solid constructor + string type; // solid type. This follows the GEANT4 definitions + string parameters; // vector of parameters used in the geant4 solid constructor // solid visualization style - bool visible; ///< visibility of the detector: 0=invisible 1=visible - int style; ///< Visual style: 0=wireframe 1=solid - string color; ///< 6(7) digits colors in RRGGBB format. Last optional digit is transparency + bool visible; // visibility of the detector: 0=invisible 1=visible + int style; // Visual style: 0=wireframe 1=solid + string color; // 6(7) digits colors in RRGGBB format. Last optional digit is transparency // logical attributes - string material; ///< Volume Material name. - string emfield; ///< Magnetic Field. Possible choices: "inherit", "fieldName", "noField" + string material; // Volume Material name. + string emfield; // Magnetic Field. Possible choices: "inherit", "fieldName", "noField" // physical attributes - string pos; ///< Defines the position relative to the mother volume - string rot; ///< Define the rotation Matrix, defined by rotations along x,y,z axis relative to the mother volume - string shift; ///< Position modifier - string tilt; ///< Rotation modifier - bool exist; ///< Existance modifier + string pos; // Defines the position relative to the mother volume + string rot; // Define the rotation Matrix, defined by rotations along x,y,z axis relative to the mother volume + string shift; // Position modifier + string tilt; // Rotation modifier + bool exist; // Existance modifier - string digitization; ///< Assigns digitization type and collection ID - string gidentity; ///< String with identifiers in it. Example: 'sector: 2, layer: 4, wire; 33' + string digitization; // Assigns digitization type and collection ID + string gidentity; // String with identifiers in it. Example: 'sector: 2, layer: 4, wire; 33' // special cases - string copyOf; ///< name of gvolume to copy from - string replicaOf; ///< name of gvolume to replica from - string solidsOpr; ///< solids operation + string copyOf; // name of gvolume to copy from + string replicaOf; // name of gvolume to replica from + string solidsOpr; // solids operation - int pCopyNo; ///< should be set to 0 for the first volume of a given type + int pCopyNo; // should be set to 0 for the first volume of a given type // mirrors string mirror; // the map key names used in geant4 contains the system name // these are assigned by gworld after all voumes are loaded - string g4name; ///< Name of the g4volume - string g4motherName; ///< Name of the g4 Mother volume + string g4name; // Name of the g4volume + string g4motherName; // Name of the g4 Mother volume // variation and run number for this gvolume string variation; int runno; - friend ostream &operator<<(ostream &stream, GVolume); ///< Logs infos on screen. + friend ostream &operator<<(ostream &stream, GVolume); // Logs infos on screen. public: inline const string getSystem() const {return system;} diff --git a/gtouchable/gtouchable.h b/gtouchable/gtouchable.h index eb1f1d4..f891139 100644 --- a/gtouchable/gtouchable.h +++ b/gtouchable/gtouchable.h @@ -66,7 +66,7 @@ class GTouchable private: // set by sensitive detector constructor GTouchableType gType; - vector gidentity; ///< Uniquely identify a sensitive element + vector gidentity; // Uniquely identify a sensitive element bool verbosity; // set in sensitiveDetector::ProcessHit diff --git a/release_notes/1.4.md b/release_notes/1.4.md index e68962f..f2cb732 100644 --- a/release_notes/1.4.md +++ b/release_notes/1.4.md @@ -11,4 +11,8 @@ - added SQLITE support - added closeSystem virtual method to GSystemFactory - added sqlite_file to GSystem -- added variation and runno to GVolume class \ No newline at end of file +- added variation and runno to GVolume class +- added gparticle verbosity option and ostream operator +- verbosity option for glibrary classes conforms to same description +- testing all sci-g examples +- added GEMCDB_ENV to list of location for sqlite database diff --git a/release_notes/1.5.md b/release_notes/1.5.md new file mode 100644 index 0000000..68fa59c --- /dev/null +++ b/release_notes/1.5.md @@ -0,0 +1,2 @@ +## General +