Skip to content

Commit fd34a52

Browse files
klendathu2kplexoos
andauthored
[g4star] Miscellaneous updates to StarAgmlLib (#308)
* Add map of GEANT3 paramaters and cuts associated to volumes. * AgMLExtension inherits from TGeoExtension, which allows user and/or framework information to be attached to TGeoVolumes. The VMC framework utlizes the "framework" extensions, so we will utilize the "user" extensions in AgML. - Attach user-defined hit scoring functions to sensitive volumes. When the MC application's hit scoring is invoked in a given volume, the general hit scoring function can invoke any user functions stored on the volume. - Store the number of volume branchings for each volume, allowing us to define a unique volume ID to each volume defined within an AgML module. * Cleanup memory. * General cleanup, and moving mixture component to protected. * AgML: Introduce a namespace, and uncomment a few trig functions AgMath provides math functions used by AgML codes. A few of these are functions defined in FORtran. A few defines have been made to prevent AgML variables from being mistaken for c-math routines. * Attach AgMLExtensions to the modules * Cleanup and replace ROOT types with basic types * WARN: Disables misalignment when run under ROOT6. Still enabled under ROOT5. * We don't even need a classdef here... * We don't need to access most of this interactively... so comment out pragmas... * Responsible for setting up the AgMLExtensions in the TGeoVolumes, which connect user codes and volume IDs from the AgML source code to the TGeo geometry model. * Back to standard StMessMgr... ENDL-->endm * Back to standard StMessMgr... ENDL-->endm * The sanity check on the main branch is newer than the geant4star version. * Expose pi to geoemtry modules * Cleanup linkdef * There is a pretty strong guarentee that table entries are not null here b/c AgML would not be filling / creating null entries. Plus... it should be safe to delete a nullptr... * Cautionary comments for future code maintainers... * Rid ourselves of that commented-out classdef... * Update StarVMC/StarAgmlLib/AgMath.h * Apply suggestions from code review * Fix memory leak in AgMLExtension * Let's confirm the problem with ROOT6 first and then fix https://github.com/star-bnl/star-sw/pull/308/files#r882223665 Co-authored-by: Dmitri Smirnov <[email protected]>
1 parent 3f94c79 commit fd34a52

16 files changed

+198
-215
lines changed

StarVMC/StarAgmlLib/AgBlock.cxx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ ClassImp(AgBlock);
55
#include <iostream>
66
#include "AgMaterial.h"
77
#include "AgShape.h"
8-
//#include "AgMedium.h"
98
#include "AgModule.h"
109
#include "AgPlacement.h"
10+
#include "AgMath.h"
1111

1212
#include "StarAgmlStacker.h"
13-
#include "StMessMgr.h"
13+
#include "StMessMgr.h"
1414

1515
// Setup static members
1616
AgBlock *AgBlock::mCurrent=0;
@@ -51,7 +51,8 @@ AgBlock::AgBlock(const Char_t *name, const Char_t *title)
5151
mNicknames(),
5252
mGroups(),
5353
mMakeAssembly(0),
54-
mNumberBranches(0)
54+
mNumberBranches(0),
55+
mGstpar()
5556
{
5657
addNickname(name); // ensure that the vector is populated
5758
_valid = true;
@@ -210,13 +211,3 @@ void AgBlock::List(Option_t *opts)
210211

211212
}
212213

213-
// ---------------------------------------------------------------------------------------------------
214-
// --
215-
//Bool_t AgBlock::isSame( const AgAttribute &attr )
216-
//{
217-
// Bool_t same = true;
218-
// same &= attr("serial") == _attribute("serial");
219-
// return same;
220-
//
221-
//}
222-

StarVMC/StarAgmlLib/AgBlock.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class AgMixture;
1414
class AgVolume;
1515
class AgModule;
1616
#include "AgPlacement.h"
17-
#include "AgMath.h"
1817
#include "AgAttribute.h"
1918
#include "AgCreate.h"
2019

@@ -154,6 +153,9 @@ class AgBlock : public TNamed
154153
int numberBranches() const { return mNumberBranches; }
155154
void branch(){ mNumberBranches++; }
156155

156+
void AddCut( TString cut, double value ){ mGstpar[cut] = value; }
157+
std::map<TString, double>& GetCuts() { return mGstpar; }
158+
157159
private:
158160
protected:
159161

@@ -186,6 +188,8 @@ class AgBlock : public TNamed
186188
/// Counts the number of volume branchings
187189
int mNumberBranches;
188190

191+
std::map<TString, double> mGstpar; // GSTPAR cuts and parameters
192+
189193
friend class _AgBlockDummy;
190194

191195
ClassDef(AgBlock,0);
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
#include "AgMLExtension.h"
22

3-
AgMLExtension::AgMLExtension() : TGeoRCExtension(), mModuleName("none"), mFamilyName("none"), mVolumeName("none"), mSensitive(0), mTracking(0)
3+
AgMLExtension::AgMLExtension() : TGeoRCExtension(),
4+
mModuleName("none"),
5+
mFamilyName("none"),
6+
mVolumeName("none"),
7+
mSensitive(0),
8+
mTracking(0),
9+
mBranchings(0),
10+
mVolumeId( new AgMLVolumeId ),
11+
mHitScoring(),
12+
mGstpar()
413
{
514
Grab();
615
}

StarVMC/StarAgmlLib/AgMLExtension.h

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,63 @@
33

44
#include <TGeoExtension.h>
55
#include <TString.h>
6+
#include <TMath.h>
7+
#include <vector>
8+
#include <map>
9+
10+
// Volume ID functor (for sensitive volumes)
11+
class AgMLVolumeId {
12+
public:
13+
virtual int id( int* numbv ) const { return 0; }
14+
};
15+
16+
// User-defined hit scoring functor (for sensitive volumes)
17+
class AgMLScoring {
18+
public:
19+
virtual float hit() const { return 0; }
20+
};
621

722
class AgMLExtension : public TGeoRCExtension {
823

924
public:
1025

1126
AgMLExtension();
12-
virtual ~AgMLExtension(){ /* nada */ };
27+
virtual ~AgMLExtension() { delete mVolumeId; mVolumeId = nullptr; }
1328

1429
void SetModuleName( const char* name ){ mModuleName = name; }
1530
void SetFamilyName( const char* name ){ mFamilyName = name; }
1631
void SetVolumeName( const char* name ){ mVolumeName = name; }
1732
void SetSensitive( bool flag ) { mSensitive = flag; }
18-
void SetTracking( short track ) { mTracking = track; }
33+
void SetTracking( short track ) {
34+
if ( mVolumeName == "CAVE" ) {
35+
mTracking = 2;
36+
}
37+
else {
38+
mTracking = track;
39+
};
40+
}
41+
42+
void SetBranchings( int b ) { mBranchings=b; }
43+
44+
void SetVolumeIdentifier( AgMLVolumeId* identifier ){ delete mVolumeId; mVolumeId = identifier; }
45+
void AddHitScoring( AgMLScoring* sc ){ mHitScoring.push_back( sc ); }
46+
1947

2048
TString GetModuleName(){ return mModuleName; }
2149
TString GetFamilyName(){ return mFamilyName; }
2250
TString GetVolumeName(){ return mVolumeName; }
51+
52+
int GetVolumeId( int* numbv ){ return mVolumeId ? mVolumeId->id( numbv ) : 0; }
53+
54+
bool GetSensitive() { return mSensitive; }
55+
short GetTracking() { return mTracking; }
56+
int GetBranchings(){ return mBranchings; }
57+
58+
std::vector<AgMLScoring*> GetUserHits(){ return mHitScoring; }
59+
60+
void AddCut( TString cut, double value ){ mGstpar[cut] = value; }
61+
std::map<TString,double>& GetCuts() { return mGstpar; }
62+
2363

2464
private:
2565
protected:
@@ -30,6 +70,12 @@ class AgMLExtension : public TGeoRCExtension {
3070

3171
bool mSensitive; // volume sensitivity
3272
short mTracking; // 0=blackhole, 1=calorimeter, 2=tracking region
73+
int mBranchings; // number of branchings (placed family members)
74+
75+
AgMLVolumeId* mVolumeId; // Functor to calculate volume ID given reduced numbering scheme
76+
77+
std::vector<AgMLScoring*> mHitScoring; // Vector of functors for hit scoring
78+
std::map<TString, double> mGstpar; // GSTPAR tracking cuts for this volume
3379

3480
ClassDef(AgMLExtension,0);
3581

StarVMC/StarAgmlLib/AgMLStructure.h

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,12 @@ class AgMLStructure : public AgMLStructureBase
220220
public:
221221

222222
AgMLStructure( const char *_name ) : AgMLStructureBase(), name(_name) { };
223-
223+
~AgMLStructure() {
224+
for ( auto t : table ) { // cleanup the table
225+
delete (t);
226+
}
227+
};
228+
224229
void fill() {
225230
table.push_back( new T( current ) );
226231
int index = table.size() - 1; // current FILL index
@@ -261,30 +266,6 @@ class AgMLStructure : public AgMLStructureBase
261266
return false;
262267
};
263268

264-
265-
// //
266-
// // Could simplify selextion by using c++11 lambdas...
267-
// //
268-
// // HEXG.use( []( hexg_t h ){ return h.type == 1; } )
269-
// //
270-
// template<class Struct>
271-
// bool use2( std::function<bool(Struct)> predicate ) {
272-
// auto x = std::find_if( table.begin(), table.end(), predicate );
273-
// if ( x == table.end() ) return false;
274-
275-
// if ( *x ) {
276-
// current = *(*x);
277-
// return true;
278-
// };
279-
280-
// return false;
281-
// };
282-
283-
284-
285-
286-
287-
288269
/// Cast to a refence to the current version
289270
operator T&(){ return current; }
290271

StarVMC/StarAgmlLib/AgMaterial.cxx

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,13 @@ ClassImp(AgMaterial);
55
#include <assert.h>
66
#include "AgBlock.h"
77
#include "AgModule.h"
8-
#include "StMessMgr.h"
8+
#include "StMessMgr.h"
99

10-
//std::vector< TString > AgMaterial::mParameterList;
1110
std::map< TString, AgMaterial * > AgMaterial::mMaterialTable;
1211
std::vector< TString > AgMaterial::mMaterialList;
1312

1413
struct _MaterialDummy { // Initializes material database
1514
_MaterialDummy(){
16-
/* lifted
17-
AgMaterial::mParameterList.push_back("a");
18-
AgMaterial::mParameterList.push_back("z");
19-
AgMaterial::mParameterList.push_back("dens");
20-
AgMaterial::mParameterList.push_back("radl");
21-
AgMaterial::mParameterList.push_back("absl");
22-
AgMaterial::mParameterList.push_back("isvol");
23-
AgMaterial::mParameterList.push_back("nelem");
24-
*/
2515

2616
AgMaterial &h = AgMaterial::Get("Hydrogen");
2717
h.par("a")=1.010; h.par("z")=1.000; h.par("dens")=0.071; h.par("radl")=0.865E+03; h.par("absl")=0.790E+03; h.lock();
@@ -105,8 +95,6 @@ struct _MaterialDummy { // Initializes material database
10595
si.par("absl")=0.455E+02;
10696
si.lock();
10797

108-
// 18 LIQUID_ARGON 39.950 18.000 1.400 0.140E+02 0.837E+02 1
109-
11098
AgMaterial &ar = AgMaterial::Get("Argon_gas");
11199
ar.par("a")=39.950;
112100
ar.par("z")=18.000;
@@ -150,8 +138,6 @@ struct _MaterialDummy { // Initializes material database
150138
mylar.Component("O",16.0,8.0,0.333);
151139
mylar.lock();
152140

153-
//$$$ AgMaterial::List();
154-
155141
};
156142

157143
} _material_dummy;
@@ -187,23 +173,6 @@ Double_t &AgMaterial::par( const Char_t *name ){
187173
return mParameters[name];
188174
}
189175

190-
#if 0
191-
Bool_t AgMaterial::isSet( const Char_t *par ) const
192-
{
193-
TString key=par;
194-
return ( mParameters.find(key) != mParameters.end() );
195-
}
196-
197-
Bool_t AgMaterial::hasPar(const Char_t *par ) const
198-
{
199-
const char* key=par;
200-
std::vector<std::string> parlist = mParameterList;
201-
for ( UInt_t i=0;i<parlist.size();i++ )
202-
if ( parlist[i] == key ) return true;
203-
return false;
204-
}
205-
#endif
206-
207176
Bool_t AgMaterial::hasComponent( const Char_t *comp )const
208177
{
209178
if ( mType == AgMaterial::kMaterial )
@@ -216,7 +185,6 @@ void AgMaterial::Print( Option_t *opts ) const
216185
{
217186
TString name = GetName();
218187
TString output = "";
219-
//LOG_INFO << "["<< ((mLock)?"-":"+") << "] " << Form("%20s:",name.Data()) << " ";
220188
output = TString("[") + TString((mLock)?"-":"+") + TString("] ") + Form("%20s:",name.Data()) + TString(" ");
221189
std::map<std::string, Double_t > mypar=mParameters;
222190
for ( UInt_t j=0;j<mParameterList.size();j++ )
@@ -257,8 +225,6 @@ AgMaterial &AgMaterial::Get( const Char_t *name )
257225
TString modname="None";
258226
if ( module ) modname = module->GetName();
259227

260-
// std::cout << "Info in <AgMaterial::Get(name)>: module="<<modname.Data()<<" material="<<name<<std::endl;
261-
262228
//////////////////////////////////////////////////////////////
263229
//
264230
// If there is no module, probably being intialized above.
@@ -322,23 +288,16 @@ AgMaterial &AgMaterial::Get( const Char_t *name )
322288
//
323289
//////////////////////////////////////////////////////////////
324290

325-
//std::cout << "Returning new material " << matname.Data() << std::endl;
326-
327291
material = new AgMaterial(matname);
328292

329293
if ( AgBlock::previous() ) // Inherit from creating block
330294
material->Inherit( AgBlock::previous() );
331295
else if ( AgBlock::module() ) // Or from the current material loaded in module
332296
material->Inherit( AgBlock::module() );
333297

334-
//std::cout << "++ After inheritance from mother block" << std::endl;
335-
336298
if ( AgBlock::active() ) // And finally the active block
337299
material->Inherit( AgBlock::active() );
338300

339-
//std::cout << "++ After inheritance from active block" << std::endl;
340-
//material->Print();
341-
342301
material->SetName(matname);
343302
mMaterialTable[matname]=material;
344303
mMaterialList.push_back(matname);
@@ -360,9 +319,6 @@ AgMaterial AgMaterial::CopyMaterial( const Char_t *name )
360319
if ( module ) modname = module->GetName();
361320
if ( current ) volname = current->GetName();
362321

363-
364-
// std::cout << "Info in <AgMaterial::Get(name)>: module="<<modname.Data()<<" material="<<name<<std::endl;
365-
366322
//////////////////////////////////////////////////////////////
367323
//
368324
// If there is no module, probably being intialized above.

StarVMC/StarAgmlLib/AgMaterial.h

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <map>
88
#include <vector>
99

10-
//#include "AgParameterList.h"
1110
#include <StarVMC/StarAgmlUtil/AgParameterList.h>
1211
class AgMaterial;
1312
class AgBlock;
@@ -23,17 +22,9 @@ class AgMaterial : public TNamed, public AgParameterList<double>
2322

2423
enum { kUnknown=0, kMaterial, kMixture, kCompound };
2524

26-
2725
/// Returns a reference to the named parameter.
2826
Double_t &par( const Char_t *name );
2927

30-
#if 0 // lifted
31-
/// Tests whether the named parameter is set for this shape
32-
Bool_t isSet( const Char_t *par ) const;
33-
/// Tests whether the named parameter is valid for this shape
34-
Bool_t hasPar( const Char_t *par ) const;
35-
#endif
36-
3728
/// Tests wether the mixture has the named component. Returns false
3829
/// if this is a material.
3930
Bool_t hasComponent( const Char_t *comp ) const;
@@ -75,7 +66,6 @@ class AgMaterial : public TNamed, public AgParameterList<double>
7566

7667
/// Returns (by reference) the name, A, Z and Weight of each component
7768
void Component( Int_t ic, TString &name, Double_t &a, Double_t &z, Double_t &weight );
78-
7969

8070
Bool_t locked(){ return mLock; }
8171

@@ -85,6 +75,13 @@ class AgMaterial : public TNamed, public AgParameterList<double>
8575
void lock(){ mLock=true; }
8676

8777
Double_t sumWeights();
78+
79+
struct MyComponent {
80+
Double_t a;
81+
Double_t z;
82+
Double_t w;
83+
};
84+
8885

8986
private:
9087
protected:
@@ -98,12 +95,6 @@ class AgMaterial : public TNamed, public AgParameterList<double>
9895
std::vector< TString > mC;
9996
std::vector< Double_t > mA, mZ, mW;
10097

101-
struct MyComponent {
102-
Double_t a;
103-
Double_t z;
104-
Double_t w;
105-
};
106-
10798
std::map< TString, MyComponent > mComponentTable; // Table storing already defined components
10899

109100
static std::map< TString, AgMaterial * > mMaterialTable; // List of existing materials

0 commit comments

Comments
 (0)