program intersection;

const
	step = 0.01;
	r_end = 10.0;
	r_min = 1.818;
	r_max = 2.200;
	z_min = 13.6;
	z_max = 14.6;
	electron_id = 3;
	positron_id = 4;
	photon_id = 7;
	neutron_id = 8;

var
	f,g:text;
	total,count,en,id,gn,vn:integer;
	ke,xp,yp,zp,xd,yd,zd,ta,r,intersect:real;
	num_photons,num_electrons,num_positrons,num_neutrons,num_other:integer;
	
begin
	writeln('Particle Intersection Calculator');
	reset(f,'MDT_EI.txt');
	rewrite(g,'Intersect.txt');
	total:=0;
	count:=0;
	num_photons:=0;
	num_electrons:=0;
	num_positrons:=0;
	num_neutrons:=0;
	num_other:=0;
	while not eof(f) do begin
		inc(total);
		readln(f,en,id,gn,ke,xp,yp,zp,xd,yd,zd,ta,vn,r);
		intersect:=0;
		while (r<r_end) do begin
			if (r>r_min) and (r<r_max) and (abs(zp)>z_min) and (abs(zp)<z_max) then begin
				if intersect=0 then begin
					write(g,en:1,' ',id:1,' ',gn:1,' ',ke:1:3,' ',xp:1:3,' ',
						yp:1:3,' ',zp:1:3,' ',xd:1:3,' ',yd:1:3,' ',zd:1:3,' ',
						ta:1,' ',vn:1,' ',r:1:3,' ');
					inc(count);
					if id=photon_id then inc(num_photons)
					else if id=neutron_id then inc(num_neutrons)
					else if id=positron_id then inc(num_positrons)
					else if id=electron_id then inc(num_electrons)
					else inc(num_other);
				end;
				intersect:=intersect+step;
			end;
			xp:=xp+step*xd;
			yp:=yp+step*yd;
			zp:=zp+step*zd;
			r:=sqrt(sqr(xp)+sqr(yp));
		end;
		if (intersect>0) then begin
			writeln(g,intersect:1:3);
		end;
	end;
	writeln('Found ',count:1,' intersectiong particles in set of ',total:1,'.');
	writeln('Photons: ',num_photons);
	writeln('Electorns: ',num_electrons);
	writeln('Positrons: ',num_positrons);
	writeln('Neutrons: ',num_neutrons);
	close(g);
	close(f);
end.