// File: /workspace/github_cpp_makefile_star2_O2/kebwi[P]Trifid/src/ImageProcs.cpp
// Function: luxToPPFD(double, double, double, double, double)
Float_t luxToPPFD(
	Float_t lux,
	Float_t lensFocalLength,	//Unused in the current PPFD calculation, remnant of an earlier version
	Float_t lensFnumber,
	Float_t pixelPitchMicrons,
	Float_t fullWellCapacity
)
{
	cout.precision(15);
	
	cout << setw(40) << left << "  lux:" << lux << endl;
	Float_t luxAfterLensTransmission = lux * .9;
	cout << setw(40) << left << "  luxAfterLensTransmission:" << luxAfterLensTransmission << endl;
	cout << setw(40) << left << "  lensFnumber:" << lensFnumber << endl;
	Float_t luxAtImagePlane = luxAfterLensTransmission / pow(lensFnumber, 2);
	cout << setw(40) << left << "  luxAtImagePlane:" << luxAtImagePlane << endl;
	Float_t photoSensitivePixelPitchMicrons = pixelPitchMicrons - .25;	// half of a .5u width dead zone between pixels
	cout << setw(40) << left << "  photoSensitivePixelPitchMicrons:" << photoSensitivePixelPitchMicrons << endl;
	Float_t photoSensitivePixelAreaM = pow((photoSensitivePixelPitchMicrons / 1000000), 2);
	cout << setw(40) << left << "  photoSensitivePixelAreaM:" << photoSensitivePixelAreaM << endl;
	Float_t lumensPerPixel = luxAtImagePlane * photoSensitivePixelAreaM;
	cout << setw(40) << left << "  lumensPerPixel:" << lumensPerPixel << endl;
	Float_t ppfdPerPixel = lumensPerPixel * .0185;
	cout << setw(40) << left << "  ppfdPerPixel:" << ppfdPerPixel << endl;
	Float_t photonsPerPixelPerSec = ppfdPerPixel * 6.0221415e17;
	cout << setw(40) << left << "  photonsPerPixelPerSec:" << photonsPerPixelPerSec << endl;
	
	Float_t saturationTime = fullWellCapacity / photonsPerPixelPerSec;
	cout << setw(40) << left << "  saturationTime at 100% reflectance:" << saturationTime << endl;
	
	cout.precision(6);
	return photonsPerPixelPerSec;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x20, %rsp
movsd %xmm4, 0x10(%rsp)
movsd %xmm3, (%rsp)
movsd %xmm2, 0x18(%rsp)
movsd %xmm0, 0x8(%rsp)
movq 0x1fd8c(%rip), %rbx     # 0x2ffd0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq $0xf, 0x8(%rbx,%rcx)
movq -0x18(%rax), %rcx
pushq $0x28
popq %r14
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl $0xffffff4f, %ebp       # imm = 0xFFFFFF4F
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13cc8(%rip), %rsi     # 0x23f46
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movsd 0x8(%rsp), %xmm0
mulsd 0x13946(%rip), %xmm0    # 0x23bf0
movsd %xmm0, 0x8(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13c79(%rip), %rsi     # 0x23f4d
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13c53(%rip), %rsi     # 0x23f69
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd 0x18(%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movsd 0x18(%rsp), %xmm1
mulsd %xmm1, %xmm1
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13c06(%rip), %rsi     # 0x23f78
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movsd (%rsp), %xmm0
addsd 0x1385b(%rip), %xmm0    # 0x23bf8
movsd %xmm0, (%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13bc5(%rip), %rsi     # 0x23f8b
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movsd (%rsp), %xmm0
divsd 0x13810(%rip), %xmm0    # 0x23c00
mulsd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13b91(%rip), %rsi     # 0x23fae
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movsd (%rsp), %xmm0
mulsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13b5c(%rip), %rsi     # 0x23fca
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movsd (%rsp), %xmm0
mulsd 0x13770(%rip), %xmm0    # 0x23c08
movsd %xmm0, (%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13b1b(%rip), %rsi     # 0x23fdc
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movsd (%rsp), %xmm0
mulsd 0x13725(%rip), %xmm0    # 0x23c10
movsd %xmm0, (%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
movl 0x18(%rbx,%rax), %ecx
andl %ebp, %ecx
orl $0x20, %ecx
movl %ecx, 0x18(%rbx,%rax)
leaq 0x13ad8(%rip), %rsi     # 0x23fec
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movsd 0x10(%rsp), %xmm0
divsd (%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movq %r14, 0x10(%rbx,%rcx)
movq -0x18(%rax), %rax
andl 0x18(%rbx,%rax), %ebp
orl $0x20, %ebp
movl %ebp, 0x18(%rbx,%rax)
leaq 0x13aa1(%rip), %rsi     # 0x24005
movq %rbx, %rdi
callq 0x32c0
movq %rax, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x3460
movq %rax, %rdi
callq 0x3120
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0x6, 0x8(%rbx,%rax)
movsd (%rsp), %xmm0
addq $0x20, %rsp
popq %rbx
popq %r14
popq %rbp
retq