A method for calibrating an electron beam, said method comprising the steps of: positioning a patterned aperture resolver (140, 240, 240', 515, 525, 630, 740) having at least one opening (145, 241-243, 241'-243', 745) in front of at least one X-ray detector, such that said at least one opening is facing towards said at least one X-ray detector (150, 250, 510, 525, 650, 750), positioning a patterned aperture modulator (130, 230, 230', 530, 540, 640, 730) between said patterned aperture resolver and a substrate (170, 270, 570, 670, 770) and at a predetermined distance from said patterned aperture resolver (B, P) and said substrate (A, R), where said patterned aperture modulator has a plurality of openings (131-137, 231-236, 231'-233', 735) oriented in at least a first direction; scanning an electron beam in at least a first direction on said substrate for generating X-rays to be received by said at least one X-ray detector; detecting said X-rays (121-127, 511, 521) emanating from said surface produced by said scanning electron beam with said patterned aperture modulator and said patterned aperture resolver, wherein a map of position, size and shape of said electron beam is achieved by mapping an intensity modulation of said X-ray signal from said detector with settings for controlling the electron beam; adjusting said settings for controlling said electron beam if at least one of the shape or the size of the electron beam is deviating more than a predetermined value from at least one of a corresponding reference beam shape or a reference beam size; and repeating said scanning, detecting, and adjusting steps until at least one of the shape or the size of the electron beam is deviating less than a predetermined value from at least one of said reference beam shape or said reference beam size. positioning a patterned aperture resolver (140, 240, 240', 515, 525, 630, 740) having at least one opening (145, 241-243, 241'-243', 745) in front of at least one X-ray detector, such that said at least one opening is facing towards said at least one X-ray detector (150, 250, 510, 525, 650, 750), positioning a patterned aperture modulator (130, 230, 230', 530, 540, 640, 730) between said patterned aperture resolver and a substrate (170, 270, 570, 670, 770) and at a predetermined distance from said patterned aperture resolver (B, P) and said substrate (A, R), where said patterned aperture modulator has a plurality of openings (131-137, 231-236, 231'-233', 735) oriented in at least a first direction; scanning an electron beam in at least a first direction on said substrate for generating X-rays to be received by said at least one X-ray detector; detecting said X-rays (121-127, 511, 521) emanating from said surface produced by said scanning electron beam with said patterned aperture modulator and said patterned aperture resolver, wherein a map of position, size and shape of said electron beam is achieved by mapping an intensity modulation of said X-ray signal from said detector with settings for controlling the electron beam; adjusting said settings for controlling said electron beam if at least one of the shape or the size of the electron beam is deviating more than a predetermined value from at least one of a corresponding reference beam shape or a reference beam size; and repeating said scanning, detecting, and adjusting steps until at least one of the shape or the size of the electron beam is deviating less than a predetermined value from at least one of said reference beam shape or said reference beam size.