About the molar mass and absorbed dose

This is fine. This will give the mass of the little box in mass units (kg, g, MeV/c2, whatever). If you want to print out the value, or save it to an N-tuple, you would divide it by the mass unit you want, for instance,

  G4cout << "Tinybox has mass " << boxmass/g << " g" << G4endl;
  G4cout << "Tinybox has mass " << boxmass/(28.3495*g) << " oz" << G4endl;

In your code, it appears that you would get the energy deposited in the box via

  G4double boxEdep = boxHit->GetEdep();

That quantity will come with units of energy, so you can print out, for instance

  G4cout << "Tinybox got energy " << boxEdep/MeV << " MeV" << G4endl;
  G4cout << "Tinybox got energy " << boxEdep/joule << " J" << G4endl;

or whatever other units of energy you like. If you’re going to save this quantity to an N-tuple, you want to decide what units are useful to you, and write your code to use that unit explicitly. For instance,

  analysisManager->FillNtupleDColumn(3,boxHit->GetEdep()/MeV);

or

  analysisManager->FillNtupleDColumn(3,boxHit->GetEdep()/joule);

In Geant4, the unit MeV has a value of 1. So if you don’t divide, you’re going to get MeV in the output. But you should not rely on that. Always put the units in your code, so that it is clear to future you what decision past you made.

You can certainly use that absorbed dose formula in your code, and print it out by dividing the units you want:

  G4double dose = boxEdep/boxmass;    // G4 has the units in here already
  G4cout << "Tinybox got dose " << dose/(MeV/g) << " MeV/g" << G4endl;
  G4cout << "Tinybox got dose " << dose/(joule/kg) << " J/kg" << G4endl;
  G4cout << "Tinybox got dose " << dose/gray << " Gy" << G4endl;

Those last two should print the same numeric value, since the Si derived unit “gray” (Gy) is defined as J kg^-1. If you decided to save the computed dose in your N-tuple, make sure you divide by the units, as I mentioned above:

  analysisManager->FillNtupleDColumn(4,dose/gray);

Some people recommend putting the units themselves in the N-tuple column name, or something like that, so the data is self documenting.