Recording energy deposition with RULL or energy loss

Dear professors,
I’m recording the energy deposition of the source particles and all the secondaries for each event. The variable RULL in mgdraw.f seems to perfectly satisfy my purpose. On the other hand, some people suppose that I can also record the energy loss of each primary after and before it enters certain region. So I write the following codes to check whether it is consistent.

ENTRY ENDRAW ( ICODE, MREG, RULL, XSCO, YSCO, ZSCO )
      IF (MREG .EQ. 6 ) THEN
          ENEDEPLS = ENEDEPLS + RULL
      END IF

where ENEDEPLS is refreshed every time a new primary enters and recorded during ENTRY EEDRAW.

ENTRY BXDRAW ( ICODE, MREG, NEWREG, XSCO, YSCO, ZSCO )
	  IF ( JTRACK .EQ. 11 .OR. JTRACK .EQ. 10 ) THEN
		IF ( MREG .EQ. 7 .AND. NEWREG .EQ. 6 ) THEN
			ENTELS = .TRUE.
			ENEBEF = ETRACK
		END IF
		IF ( MREG .EQ. 6 .AND. NEWREG .EQ. 7) THEN
			EXITLS = .TRUE.
			ENEAFT = ETRACK
		END IF
	  END IF

where the primary is muon-/muon+, the interested region 6 is surrounded by region 7 and the difference between ENEBEF and ENEAFT is recorded as ENELOS during ENTRY EENRAW according to this line.
WRITE(98,'(A15, 2ES15.3)') "eneLS", ENEDEPLS, ENELOS
The expectation is that if my interpretation to RULL and the codes are right, the value of RULL should be larger than that of ENELOS. Because sometimes a primary could deposit energy in region 6 without crossing it when some secondaries may “help” it. However, it turns out that the latter is much larger for the most of time. I’m wondering where the mistake lies.
mgdraw.f (8.6 KB)
output.txt (354.5 KB)
Best regards,
Hechong Han

Dear @hanhechong ,

I think that the underlying problem in your code is a misconception on the variable RULL: ENDRAW is called for point-like energy deposition events. You are completely neglecting the continuous energy losses which give a far greater contribution: you would intercept these at the MGDRAW entry in mgdraw.f by summing the continuous energy deposition events along the track (sum of DTRACK (I), with I = 1, MTRACK). You can consult the manual for USERDUMP or have a look at trackr.inc.

That being said, I am not fully convinced that with your code you would get the correct total energy deposited in the region of interest (but maybe I am mistaken). I believe that for your needs there is a much simpler and (most importantly) less error prone solution to get the total energy deposition in a given region for each primary event: you can use EVENTBIN as in the example below (assuming it is the same input file as in you previous post on the Forum). Note that with AUXSCORE you can even filter by particle types, while ROTPRBIN is used only to limit the output to non-zero energy deposition events.

Best,
Davide

Dear @dbozzato
Thank you for your instructions and examples! I have tried your codes and it works well!
Best regards,
Hechong Han