//g++ particleGun.cxx -o particleGun `root-config --glibs --cflags` #include #include #include #include #include #include"ConfigFile.h" #include "TRandom.h" #include "TApplication.h" #include "TCanvas.h" #include "TVector3.h" #include "TMath.h" #include "TPolyLine3D.h" std::map confI; std::map confD; ConfigFile cf; TRandom myRand(0); void readConfI(std::string var) { if(!(cf.readInto(confI[var] , var) )) { std::cerr << "Reading parameter " << var << " from conf file failed ->abort" << std::endl; throw; } } void readConfD(std::string var) { if(!(cf.readInto(confD[var] , var) )) { std::cerr << "Reading parameter " << var << " from conf file failed ->abort" << std::endl; throw; } } void getXY(double z,const TVector3& pos, const TVector3& mom,double& x,double& y){ /* X=P+t*M z-component: z=Pz+t*Mz <=> t=(z-Pz)/Mz */ double t=(z-pos.Z())/mom.Z(); x=pos.X()+t*mom.X(); y=pos.Y()+t*mom.Y(); } void getXZ(double y,const TVector3& pos, const TVector3& mom,double& x,double& z){ /* X=P+t*M y-component: y=Py+t*My <=> t=(y-Py)/My */ double t=(y-pos.Y())/mom.Y(); x=pos.X()+t*mom.X(); z=pos.Z()+t*mom.Z(); } void getYZ(double x,const TVector3& pos, const TVector3& mom,double& y,double& z){ /* X=P+t*M x-component: x=Px+t*Mx <=> t=(x-Px)/Mx */ double t=(x-pos.X())/mom.X(); y=pos.Y()+t*mom.Y(); z=pos.Z()+t*mom.Z(); } bool acceptance(const TVector3& pos, const TVector3& mom){ double x,y,z; //check for hit in bottom scintillator getXY(confD["BOTZ"],pos,mom,x,y); if(xconfD["BOTXMAX"]) return false; if(yconfD["BOTYMAX"]) return false; //check for penetration of upper and lower 'endcap' of readout volume getXY(confD["TPCZMIN"],pos,mom,x,y); if(x>confD["TPCXMIN"] && xconfD["TPCYMIN"] && yconfD["TPCXMIN"] && xconfD["TPCYMIN"] && yconfD["TPCYMIN"] && yconfD["TPCZMIN"] && zconfD["TPCYMIN"] && yconfD["TPCZMIN"] && zconfD["TPCXMIN"] && xconfD["TPCZMIN"] && zconfD["TPCXMIN"] && xconfD["TPCZMIN"] && zDraw(); } for(int iev=0;ievSetPoint(0,x,y,z1Draw); getXY(z2Draw,pos,mom,x,y); lines[iev]->SetPoint(1,x,y,z2Draw); } f << "1 " << iev << " " << pos.X() << " " << pos.Y() << " " << pos.Z() << std::endl; f << confI["PDG"] << " " << mom.X() << " " << mom.Y() << " " << mom.Z() << std::endl; } f.close(); if(ROOT){ for(int iev=0;ievDraw("same"); } app->Run(); } }