COMPOSITE design
pattern
for description of
DMGEant materials
Paola Grosso
INFN - Torino
We're starting from the need to
implement materials and tracking media in the proper way to be handled
by the GEANT interface and the DMGeant packages.
Materials forming the tracking media
can be simple compounds and composite compounds.
COMPOSITE design pattern:
The proposed way to describe material
is through the use of a base class DMMaterial and two derived classes DMSimpleMaterial
and DMCompositeMaterial.
The COMPOSITE design pattern
composes objects into tree structures to represent part-whole hierarchies.
The pattern lets the clients treat individual objects and compositions
of objects uniformly.
Creation of materials:
Creation of materials to be appended
at the list of materials is done using the two derived classes: creation
makes a distinction among simple and composite elements.
RWTPtrSlist<DMMaterial>
svtMatList =
new RWTPtrSlist<DMMaterial>()
DMSimpleMaterial* svtSilicon
= new DMSimpleMaterial(...);
svtMatList->append(svtSilicon);
DMSimpleMaterial* svtCarbon
= new DMSimpleMaterial(...);
svtMatList->append(svtCarbon);
DMCompositeMaterial* mixture
= new DMCompositeMaterial(...);
mixture->addComponent(svtSilicon,0.98);
mixture->addComponent(svtCarbon,0.02);
svtMatList->append(svtTestMixture);
Accessing already created materials:
When accessing the list of already
created meterials there's complete transparency and the base class object
of type DMMaterial can be used. According to the type of the object pointed
to, the appropriate function will be used.
DMMaterial* theMaterial =
DMMaterial::findDMMAterial(matName,
matList);
const int nComponents = theMaterial->nComponents();
double* a = new double[nComponents];
double* z = new double[nComponents];
int i(0); //first component
DMMaterial* aComponent = theMaterial->getComponent(i);
a[i] = theMaterial->aNthComponent(i);
// or a[i] = aComponent->a();
z[i] = theMaterial->zNthComponent(i);
// or z[i] = aComponent->z();