void KVRangeYanez::AddElementalMaterial(Int_t z, Int_t a)
{
   // Adds a material composed of a single isotope of a chemical element.
   // If the isotope (a) is not specified, we create a material containing the naturally
   // occuring isotopes of the given element, weighted according to their abundance.
   // If the mass is given, the material symbol will be "AX" where X is the symbol for the element
   //    e.g. "48Ca",  "124Sn", etc.
   // and the material name will be "Xxx-A" where Xxx is the name of the element
   //    e.g. "Calcium-48", "Tin-124", etc.
   // Otherwise, we just use the element symbol and name for naturally-occurring
   // mixtures of atomic elements ("Ca", "Calcium", etc.).

   KVIonRangeTableMaterial* mat;
   if (!a) {
      mat = MakeNaturallyOccuringElementMixture(z);
   } else {
      if (!gNDTManager) {
         Error("AddElementalMaterial",
               "Nuclear data tables have not been initialised");
         return;
      }
      KVElementDensity* ed = (KVElementDensity*)gNDTManager->GetData(z, a, "ElementDensity");
      if (!ed) {
         Error("AddElementalMaterial",
               "No element found in ElementDensity NDT-table with Z=%d", z);
         return;
      }
      TString state = "solid";
      if (ed->IsGas()) state = "gas";
      mat = new KVRangeYanezMaterial(this, Form("%s-%d", ed->GetElementName(), a),
                                     Form("%d%s", a, ed->GetElementSymbol()),
                                     state, ed->GetValue(), z, a);
      mat->Initialize();
   }
   CheckMaterialsList();
   fMaterials->Add(mat);
   mat->ls();
}
KVIonRangeTableMaterial* KVRangeYanez::MakeNaturallyOccuringElementMixture(Int_t z)
{
   // create a material containing the naturally occuring isotopes of the given element,
   // weighted according to their abundance.

   if (!gNDTManager) {
      Error("MakeNaturallyOccuringElementMixture",
            "Nuclear data tables have not been initialised");
      return NULL;
   }
   KVElementDensity* ed = (KVElementDensity*)gNDTManager->GetData(z, z, "ElementDensity");
   if (!ed) {
      Error("AddElementalMaterial",
            "No element found in ElementDensity NDT-table with Z=%d", z);
      return 0x0;
   }
   TString state = "solid";
   if (ed->IsGas()) state = "gas";
   KVRangeYanezMaterial* mat =
      new KVRangeYanezMaterial(this,
                               ed->GetElementName(),
                               ed->GetElementSymbol(),
                               state, ed->GetValue());
   KVNucleus nuc(z);
   KVNumberList isotopes = nuc.GetKnownARange();
   isotopes.Begin();
   while (!isotopes.End()) {

      nuc.SetA(isotopes.Next());
      Double_t abundance = nuc.GetAbundance() / 100.;
      if (abundance > 0.) mat->AddMixtureElement(z, nuc.GetA(), 1, abundance);

   }
   mat->Initialize();
   return (KVIonRangeTableMaterial*)mat;
}